Example usage for java.awt.event MouseEvent MOUSE_CLICKED

List of usage examples for java.awt.event MouseEvent MOUSE_CLICKED

Introduction

In this page you can find the example usage for java.awt.event MouseEvent MOUSE_CLICKED.

Prototype

int MOUSE_CLICKED

To view the source code for java.awt.event MouseEvent MOUSE_CLICKED.

Click Source Link

Document

The "mouse clicked" event.

Usage

From source file:MainClass.java

protected void processMouseEvent(MouseEvent e) {
    if (e.getID() == MouseEvent.MOUSE_CLICKED) {
        System.out.println("Status: " + pg.getStatus());
        System.out.println("Width:  " + pg.getWidth());
        System.out.println("Height: " + pg.getHeight());
        System.out.println("Pixels: " + (pg.getPixels() instanceof byte[] ? "bytes" : "ints"));
        System.out.println("Model:  " + pg.getColorModel());
    }/*  w w w . j  av  a 2  s .  c o m*/
    super.processMouseEvent(e);
}

From source file:Main.java

/**
 * Display mouse events that don't involve mouse motion. The mousemods()
 * method prints modifiers, and is defined below. The other methods return
 * additional information about the mouse event. showLine() displays a line
 * of text in the window. It is defined at the end of this class, along with
 * the paintComponent() method./*from  w  ww  .j  a  v a  2 s.c o  m*/
 */
public void processMouseEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_DRAGGED:
        type = "MOUSE_DRAGGED";
        break;
    case MouseEvent.MOUSE_RELEASED:
        type = "MOUSE_RELEASED";
        break;
    case MouseEvent.MOUSE_CLICKED:
        type = "MOUSE_CLICKED";
        break;
    case MouseEvent.MOUSE_ENTERED:
        type = "MOUSE_ENTERED";
        break;
    case MouseEvent.MOUSE_EXITED:
        type = "MOUSE_EXITED";
        break;
    }
    showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = "
            + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : ""));

    // When the mouse enters the component, request keyboard focus so
    // we can receive and respond to keyboard events
    if (e.getID() == MouseEvent.MOUSE_ENTERED)
        requestFocus();
}

From source file:EventTestPane.java

/**
 * Display mouse events that don't involve mouse motion. The mousemods()
 * method prints modifiers, and is defined below. The other methods return
 * additional information about the mouse event. showLine() displays a line
 * of text in the window. It is defined at the end of this class, along with
 * the paintComponent() method./* w  w w .ja  va  2  s  .c  o  m*/
 */
public void processMouseEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_PRESSED:
        type = "MOUSE_PRESSED";
        break;
    case MouseEvent.MOUSE_RELEASED:
        type = "MOUSE_RELEASED";
        break;
    case MouseEvent.MOUSE_CLICKED:
        type = "MOUSE_CLICKED";
        break;
    case MouseEvent.MOUSE_ENTERED:
        type = "MOUSE_ENTERED";
        break;
    case MouseEvent.MOUSE_EXITED:
        type = "MOUSE_EXITED";
        break;
    }
    showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = "
            + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : ""));

    // When the mouse enters the component, request keyboard focus so
    // we can receive and respond to keyboard events
    if (e.getID() == MouseEvent.MOUSE_ENTERED)
        requestFocus();
}

From source file:com.limegroup.gnutella.gui.tables.ActionIconAndNameEditor.java

public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row,
        int column) {
    ActionIconAndNameHolder in = (ActionIconAndNameHolder) value;
    action = in.getAction();/* w  w  w .j  a  va 2s.  c om*/

    final Component component = new ActionIconAndNameRenderer().getTableCellRendererComponent(table, value,
            isSelected, true, row, column);
    component.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                if (actionRegion == null) {
                    component_mousePressed(e);
                } else {
                    if (actionRegion.contains(e.getPoint())) {
                        component_mousePressed(e);
                    } else {
                        if (e.getClickCount() >= 2) {
                            Toolkit.getDefaultToolkit().getSystemEventQueue()
                                    .postEvent(new MouseEvent(table, MouseEvent.MOUSE_CLICKED, e.getWhen(),
                                            e.getModifiers(), component.getX() + e.getX(),
                                            component.getY() + e.getY(), e.getClickCount(), false));
                        }
                    }
                }
            } else if (e.getButton() == MouseEvent.BUTTON3) {
                Toolkit.getDefaultToolkit().getSystemEventQueue()
                        .postEvent(new MouseEvent(table, e.getID(), e.getWhen(), e.getModifiers(),
                                component.getX() + e.getX(), component.getY() + e.getY(), e.getClickCount(),
                                true));
            }
        }
    });

    return component;
}

From source file:Main.java

@Override
protected void processMouseEvent(MouseEvent e, JLayer<? extends JTabbedPane> l) {
    if (e.getID() != MouseEvent.MOUSE_CLICKED) {
        return;// w w  w  .  j a v a2s  .c  o m
    }
    pt.setLocation(e.getPoint());
    JTabbedPane tabbedPane = (JTabbedPane) l.getView();
    int index = tabbedPane.indexAtLocation(pt.x, pt.y);
    if (index >= 0) {
        Rectangle rect = tabbedPane.getBoundsAt(index);
        Dimension d = button.getPreferredSize();
        int x = rect.x + rect.width - d.width - 2;
        int y = rect.y + (rect.height - d.height) / 2;
        Rectangle r = new Rectangle(x, y, d.width, d.height);
        if (r.contains(pt)) {
            tabbedPane.removeTabAt(index);
        }
    }
    l.getView().repaint();
}

From source file:AWTInteraction.java

public void initialize() {
    criterion = new WakeupOnBehaviorPost(this, MouseEvent.MOUSE_CLICKED);
    wakeupOn(criterion);
}

From source file:AWTInteraction.java

public void actionPerformed(ActionEvent e) {
    postId(MouseEvent.MOUSE_CLICKED);
}

From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java

private JPanel createPanel() {
    EnumSet<AccountType> set = EnumSet.of(AccountType.INCOME, AccountType.EXPENSE);

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));

    startField = new DatePanel();

    endField = new DatePanel();

    showEmptyCheck = new JCheckBox(rb.getString("Label.ShowEmptyAccounts"));

    showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));

    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);

    combo = AccountListComboBox.getParentTypeInstance(engine.getRootAccount(), set);

    final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now()).minusYears(1);

    long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));

    startField.setDate(DateUtils.asLocalDate(start));

    currentAccount = combo.getSelectedAccount();
    JFreeChart chart = createPieChart(currentAccount);
    chartPanel = new ChartPanel(chart, true, true, true, false, true);
    //                         (chart, properties, save, print, zoom, tooltips)

    FormLayout layout = new FormLayout("p, 4dlu, 70dlu, 8dlu, p, 4dlu, 70dlu, 8dlu, p, 4dlu:g, left:p",
            "f:d, 3dlu, f:d, 6dlu, f:p:g");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    layout.setRowGroups(new int[][] { { 1, 3 } });

    builder.append(combo, 9);/*from  ww  w.  ja v  a  2 s . c o  m*/
    builder.append(showEmptyCheck);
    builder.nextLine();

    builder.nextLine();

    builder.append(rb.getString("Label.StartDate"), startField);
    builder.append(rb.getString("Label.EndDate"), endField);
    builder.append(refreshButton);

    builder.append(showPercentCheck);
    builder.nextLine();
    builder.nextLine();

    builder.append(chartPanel, 11);

    JPanel panel = builder.getPanel();

    combo.addActionListener(e -> {
        setCurrentAccount(combo.getSelectedAccount());
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });

    refreshButton.addActionListener(e -> {
        setCurrentAccount(currentAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });

    showEmptyCheck.addActionListener(e -> setCurrentAccount(currentAccount));

    showPercentCheck.addActionListener(e -> ((PiePlot) chartPanel.getChart().getPlot())
            .setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels));

    ChartMouseListener mouseListener = new ChartMouseListener() {

        @Override
        public void chartMouseClicked(final ChartMouseEvent event) {
            MouseEvent me = event.getTrigger();
            if (me.getID() == MouseEvent.MOUSE_CLICKED && me.getClickCount() == 1) {
                try {
                    ChartEntity entity = event.getEntity();
                    // expand sections if interesting, back out if in nothing
                    if (entity instanceof PieSectionEntity) {
                        Account a = (Account) ((PieSectionEntity) entity).getSectionKey();
                        if (a.getChildCount() > 0) {
                            setCurrentAccount(a);
                        }
                    } else if (entity == null) {
                        Account parent = currentAccount;
                        if (parent == null) {
                            return;
                        }
                        parent = parent.getParent();
                        if (parent == null || parent instanceof RootAccount) {
                            return;
                        }
                        setCurrentAccount(parent);
                    }
                } catch (final Exception e) {
                    Logger.getLogger(IncomeExpensePieChart.class.getName()).log(Level.SEVERE,
                            e.getLocalizedMessage(), e);
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            setChartCursor(chartPanel, event.getEntity(), event.getTrigger().getPoint());
        }
    };

    chartPanel.addChartMouseListener(mouseListener);

    return panel;
}

From source file:com.hp.alm.ali.idea.content.taskboard.TaskBoardPanel.java

public TaskBoardPanel(final Project project) {
    super(new BorderLayout());

    this.project = project;

    status = new EntityStatusPanel(project);
    queue = new QueryQueue(project, status, false);

    entityService = project.getComponent(EntityService.class);
    entityService.addEntityListener(this);
    sprintService = project.getComponent(SprintService.class);
    sprintService.addListener(this);

    loadTasks();//from w ww.j av a2 s.  c  o  m

    header = new Header();
    columnHeader = new ColumnHeader();

    content = new Content();
    add(content, BorderLayout.NORTH);

    header.assignedTo.reload();

    // force mouse-over task as visible (otherwise events are captured by the overlay and repaint quirks)
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing() && event.getID() == MouseEvent.MOUSE_MOVED) {
                MouseEvent m = (MouseEvent) event;
                TaskPanel currentPanel = locateContainer(m, TaskPanel.class);
                if (currentPanel != null) {
                    if (forcedTaskPanel == currentPanel) {
                        return;
                    } else if (forcedTaskPanel != null) {
                        forcedTaskPanel.removeForcedMatch(this);
                    }
                    forcedTaskPanel = currentPanel;
                    forcedTaskPanel.addForcedMatch(this);
                } else if (forcedTaskPanel != null) {
                    forcedTaskPanel.removeForcedMatch(this);
                    forcedTaskPanel = null;
                }
            }
        }
    }, AWTEvent.MOUSE_MOTION_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing()) {
                MouseEvent m = (MouseEvent) event;
                switch (event.getID()) {
                case MouseEvent.MOUSE_PRESSED:
                case MouseEvent.MOUSE_RELEASED:
                    // implement backlog item popup
                    if (m.isPopupTrigger()) {
                        final BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            ActionPopupMenu popupMenu = ActionUtil.createEntityActionPopup("taskboard");
                            Point p = SwingUtilities.convertPoint(m.getComponent(), m.getPoint(), itemPanel);
                            popupMenu.getComponent().show(itemPanel, p.x, p.y);
                        }
                    }
                    break;

                case MouseEvent.MOUSE_CLICKED:
                    // implement backlog item double click
                    if (m.getClickCount() > 1) {
                        BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            Entity backlogItem = itemPanel.getItem();
                            Entity workItem = new Entity(backlogItem.getPropertyValue("entity-type"),
                                    Integer.valueOf(backlogItem.getPropertyValue("entity-id")));
                            AliContentFactory.loadDetail(project, workItem, true, true);
                        }
                    }
                }
            }

        }
    }, AWTEvent.MOUSE_EVENT_MASK);
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void processEvent(MouseEvent e, JXLayer layer) {
    if (MouseEvent.MOUSE_DRAGGED == e.getID()) {
        return;//w  ww  . j  ava2  s .co m
    }

    if (MouseEvent.MOUSE_CLICKED == e.getID()) {
        // Transfer focus to chart if user clicks on the chart.
        this.investmentFlowChartJDialog.getChartPanel().requestFocus();
    }

    final Point mousePoint = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), layer);

    final boolean status0 = this.updateInvestPoint(mousePoint);
    final boolean status1 = this.updateROIPoint(mousePoint);

    if (status0 || status1) {
        this.setDirty(true);
    }
}