Example usage for java.awt.event MouseEvent getID

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

Introduction

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

Prototype

public int getID() 

Source Link

Document

Returns the event type.

Usage

From source file:JToggleButtonMenuItem.java

public void processMouseEvent(MouseEvent mouseEvent, MenuElement path[], MenuSelectionManager manager) {
    // For when mouse dragged over menu and button released
    if (mouseEvent.getID() == MouseEvent.MOUSE_RELEASED) {
        manager.clearSelectedPath();/* w ww.j  a  v a2 s .  c  om*/
        System.out.println("Selected: JToggleButtonMenuItem, by MouseEvent");
        doClick(0); // inherited from AbstractButton
    }
}

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.//from  ww  w  .j  a  v a2s . 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: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./*w  w  w  .  ja  va  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:ToggleSample.java

public void processMouseEvent(MouseEvent mouseEvent, MenuElement path[], MenuSelectionManager manager) {
    // For when mouse dragged over menu and button released
    if (mouseEvent.getID() == MouseEvent.MOUSE_RELEASED) {
        manager.clearSelectedPath();/* w  w  w  .  j  a v  a  2  s  .  c o m*/
        doClick(0); // inherited from AbstractButton
    }
}

From source file:AppletMenuBarDemo.java

/** Called when a mouse event happens over the menubar */
protected void processMouseEvent(MouseEvent e) {
    int type = e.getID(); // What type of event?
    int item = findItemAt(e.getX()); // Over which menu label?

    if (type == MouseEvent.MOUSE_PRESSED) {
        // If it was a mouse down event, then pop up the menu
        if (item == -1)
            return;
        Dimension size = getSize();
        PopupMenu pm = (PopupMenu) menus.elementAt(item);
        if (pm != null)
            pm.show(this, startPositions[item] - 3, size.height);

    } else if (type == MouseEvent.MOUSE_EXITED) {
        // If the mouse left the menubar, then unhighlight
        if (highlightedItem != -1) {
            highlightedItem = -1;//from   ww  w  .ja  v a  2 s. com
            if (highlightColor != null)
                repaint();
        }
    } else if ((type == MouseEvent.MOUSE_MOVED) || (type == MouseEvent.MOUSE_ENTERED)) {
        // If the mouse moved, change the highlighted item, if necessary
        if (item != highlightedItem) {
            highlightedItem = item;
            if (highlightColor != null)
                repaint();
        }
    }
}

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 w w w. ja va  2 s  .  com
    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:SwingGlassExample.java

private void redispatchMouseEvent(MouseEvent e) {
    boolean inButton = false;
    boolean inMenuBar = false;
    Point glassPanePoint = e.getPoint();
    Component component = null;/* w  ww .j a  v  a  2s.  co  m*/
    Container container = contentPane;
    Point containerPoint = SwingUtilities.convertPoint(this, glassPanePoint, contentPane);
    int eventID = e.getID();

    if (containerPoint.y < 0) {
        inMenuBar = true;
        container = menuBar;
        containerPoint = SwingUtilities.convertPoint(this, glassPanePoint, menuBar);
        testForDrag(eventID);
    }

    //XXX: If the event is from a component in a popped-up menu,
    //XXX: then the container should probably be the menu's
    //XXX: JPopupMenu, and containerPoint should be adjusted
    //XXX: accordingly.
    component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y);

    if (component == null) {
        return;
    } else {
        inButton = true;
        testForDrag(eventID);
    }

    if (inMenuBar || inButton || inDrag) {
        Point componentPoint = SwingUtilities.convertPoint(this, glassPanePoint, component);
        component.dispatchEvent(new MouseEvent(component, eventID, e.getWhen(), e.getModifiers(),
                componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger()));
    }
}

From source file:Main.java

public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) {
    Point p = SwingUtilities.convertPoint(source, new Point(sourceEvent.getX(), sourceEvent.getY()),
            destination);/*  w w  w.  j a  v a 2 s.  c  om*/
    Component newSource;

    if (destination != null)
        newSource = destination;
    else
        newSource = source;

    MouseEvent newEvent;
    if (sourceEvent instanceof MouseWheelEvent) {
        MouseWheelEvent sourceWheelEvent = (MouseWheelEvent) sourceEvent;
        newEvent = new MouseWheelEvent(newSource, sourceWheelEvent.getID(), sourceWheelEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceWheelEvent.getClickCount(), sourceWheelEvent.isPopupTrigger(),
                sourceWheelEvent.getScrollType(), sourceWheelEvent.getScrollAmount(),
                sourceWheelEvent.getWheelRotation());
    } else if (sourceEvent instanceof MenuDragMouseEvent) {
        MenuDragMouseEvent sourceMenuDragEvent = (MenuDragMouseEvent) sourceEvent;
        newEvent = new MenuDragMouseEvent(newSource, sourceMenuDragEvent.getID(), sourceMenuDragEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceMenuDragEvent.getClickCount(), sourceMenuDragEvent.isPopupTrigger(),
                sourceMenuDragEvent.getPath(), sourceMenuDragEvent.getMenuSelectionManager());
    } else {
        newEvent = new MouseEvent(newSource, sourceEvent.getID(), sourceEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceEvent.getClickCount(), sourceEvent.isPopupTrigger(), sourceEvent.getButton());
    }
    return newEvent;
}

From source file:TransferableScribblePane.java

/**
 * This method is called for mouse motion events. We don't have to detect
 * gestures that initiate a drag in this method. That is the job of the
 * DragGestureRecognizer we created in the constructor: it will notify the
 * DragGestureListener defined below./*from  w w  w.jav  a 2  s  .  c  om*/
 */
public void processMouseMotionEvent(MouseEvent e) {
    if (e.getID() == MouseEvent.MOUSE_DRAGGED && // If we're dragging
            currentLine != null) { // and a line exists
        currentLine.addSegment(e.getX(), e.getY()); // Add a line segment
        e.consume(); // Eat the event
        repaint(); // Redisplay all lines
    }
    super.processMouseMotionEvent(e); // Invoke any listeners
}

From source file:ca.phon.app.session.editor.view.session_information.SessionInfoEditorView.java

private void init() {
    setLayout(new BorderLayout());

    contentPanel = new TierDataLayoutPanel();

    dateField = createDateField();/*from   ww w  .j a va 2 s. c  o m*/
    dateField.getTextField().setColumns(10);
    dateField.setBackground(Color.white);

    mediaLocationField = new MediaSelectionField(getEditor().getProject());
    mediaLocationField.setEditor(getEditor());
    mediaLocationField.getTextField().setColumns(10);
    mediaLocationField.addPropertyChangeListener(FileSelectionField.FILE_PROP, mediaLocationListener);

    participantTable = new JXTable();
    participantTable.setVisibleRowCount(3);

    ComponentInputMap participantTableInputMap = new ComponentInputMap(participantTable);
    ActionMap participantTableActionMap = new ActionMap();

    ImageIcon deleteIcon = IconManager.getInstance().getIcon("actions/delete_user", IconSize.SMALL);
    final PhonUIAction deleteAction = new PhonUIAction(this, "deleteParticipant");
    deleteAction.putValue(PhonUIAction.SHORT_DESCRIPTION, "Delete selected participant");
    deleteAction.putValue(PhonUIAction.SMALL_ICON, deleteIcon);
    participantTableActionMap.put("DELETE_PARTICIPANT", deleteAction);
    participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "DELETE_PARTICIPANT");
    participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "DELETE_PARTICIPANT");

    removeParticipantButton = new JButton(deleteAction);

    participantTable.setInputMap(WHEN_FOCUSED, participantTableInputMap);
    participantTable.setActionMap(participantTableActionMap);

    addParticipantButton = new JButton(new NewParticipantAction(getEditor(), this));
    addParticipantButton.setFocusable(false);

    ImageIcon editIcon = IconManager.getInstance().getIcon("actions/edit_user", IconSize.SMALL);
    final PhonUIAction editParticipantAct = new PhonUIAction(this, "editParticipant");
    editParticipantAct.putValue(PhonUIAction.NAME, "Edit participant...");
    editParticipantAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Edit selected participant...");
    editParticipantAct.putValue(PhonUIAction.SMALL_ICON, editIcon);
    editParticipantButton = new JButton(editParticipantAct);
    editParticipantButton.setFocusable(false);

    final CellConstraints cc = new CellConstraints();
    FormLayout participantLayout = new FormLayout("fill:pref:grow, pref, pref, pref", "pref, pref, pref:grow");
    JPanel participantPanel = new JPanel(participantLayout);
    participantPanel.setBackground(Color.white);
    participantPanel.add(new JScrollPane(participantTable), cc.xywh(1, 2, 3, 2));
    participantPanel.add(addParticipantButton, cc.xy(2, 1));
    participantPanel.add(editParticipantButton, cc.xy(3, 1));
    participantPanel.add(removeParticipantButton, cc.xy(4, 2));
    participantTable.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent arg0) {
            if (arg0.getClickCount() == 2 && arg0.getButton() == MouseEvent.BUTTON1) {
                editParticipantAct.actionPerformed(new ActionEvent(arg0.getSource(), arg0.getID(), "edit"));
            }
        }

    });

    languageField = new LanguageField();
    languageField.getDocument().addDocumentListener(languageFieldListener);

    int rowIdx = 0;
    final JLabel dateLbl = new JLabel("Session Date");
    dateLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(dateLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(dateField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel mediaLbl = new JLabel("Media");
    mediaLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(mediaLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(mediaLocationField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel partLbl = new JLabel("Participants");
    partLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(partLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(participantPanel, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel langLbl = new JLabel("Language");
    langLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(langLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(languageField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    add(new JScrollPane(contentPanel), BorderLayout.CENTER);

    update();
}