Java Code Examples for java.awt.event.MouseEvent

The following examples show how to use java.awt.event.MouseEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Logisim   Source File: Toolbar.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
	int mx = e.getX();
	int my = e.getY();
	int col = (e.getX() - ICON_SEP) / (ICON_WIDTH + ICON_SEP);
	int row = (e.getY() - ICON_SEP) / (ICON_HEIGHT + ICON_SEP);
	int x0 = ICON_SEP + col * (ICON_SEP + ICON_WIDTH);
	int y0 = ICON_SEP + row * (ICON_SEP + ICON_HEIGHT);

	if (mx >= x0 && mx < x0 + ICON_WIDTH && my >= y0 && my < y0 + ICON_HEIGHT && col >= 0 && col < tools.length
			&& row >= 0 && row < tools[col].length) {
		toolPressed = tools[col][row];
		inTool = true;
		toolX = x0;
		toolY = y0;
		repaint();
	} else {
		toolPressed = null;
		inTool = false;
	}
}
 
Example 2
Source Project: lizzie   Source File: LizziePane.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** Creates a window */
public LizziePane(LizzieMain owner) {
  //    super(owner);
  //    initCompotents();
  //    input = owner.input;
  //    installInputListeners();
  setOpaque(false);

  addMouseListener(
      new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          Lizzie.frame.getFocus();
        }
      });
}
 
Example 3
Source Project: Luyten   Source File: FileSaver.java    License: Apache License 2.0 6 votes vote down vote up
public FileSaver(JProgressBar bar, JLabel label) {
	this.bar = bar;
	this.label = label;
	final JPopupMenu menu = new JPopupMenu("Cancel");
	final JMenuItem item = new JMenuItem("Cancel");
	item.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent arg0) {
			setCancel(true);
		}
	});
	menu.add(item);
	this.label.addMouseListener(new MouseAdapter() {
		public void mouseClicked(MouseEvent ev) {
			if (SwingUtilities.isRightMouseButton(ev) && isExtracting())
				menu.show(ev.getComponent(), ev.getX(), ev.getY());
		}
	});
}
 
Example 4
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
protected EditorGlassPane() {
  super();
  setOpaque(false);
  setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
    @Override public boolean accept(Component c) {
      return Objects.equals(c, getEditorTextField());
    }
  });
  addMouseListener(new MouseAdapter() {
    @Override public void mouseClicked(MouseEvent e) {
      if (!getEditorTextField().getBounds().contains(e.getPoint())) {
        renameTitle.actionPerformed(new ActionEvent(e.getComponent(), ActionEvent.ACTION_PERFORMED, ""));
      }
    }
  });
}
 
Example 5
Source Project: RipplePower   Source File: Screen.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 鼠标放开
 */
public void mouseReleased(MouseEvent e) {
	if (isLock || isClose || !isLoad) {
		return;
	}
	int type = ACTION_UP;
	int button = e.getButton();
	touch.action = type;
	touch.type = button;
	touch.pointer = 1;
	touch.x = e.getX() - tx;
	touch.y = e.getY() - ty;
	this.touchX = (int) touch.x;
	this.touchY = (int) touch.y;
	this.isDraging = false;
	try {
		touchType[type] = false;
		touchButtonReleased = button;
		touchButtonPressed = LInput.NO_BUTTON;
		onTouchUp(touch);
	} catch (Exception ex) {
		touchButtonPressed = LInput.NO_BUTTON;
		touchButtonReleased = LInput.NO_BUTTON;
		ex.printStackTrace();
	}
}
 
Example 6
Source Project: radiance   Source File: ShapesFrame.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public ShapesPanel() {
    this.shapes = new ArrayList<MyShape>();
    this.topColor = COLOR_BLUE;
    this.bottomColor = COLOR_GREEN;

    this.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            addShape(e.getPoint());
        }
    });

    // animate the gradient endpoint colors in an infinite timeline
    SwingRepaintTimeline.repaintBuilder(this)
            .addPropertyToInterpolate("topColor", COLOR_BLUE, COLOR_GREEN)
            .addPropertyToInterpolate("bottomColor", COLOR_GREEN, COLOR_BLUE)
            .setDuration(1000)
            .playLoop(RepeatBehavior.REVERSE);
}
 
Example 7
private void maybeEditCustomExtKeyUsage(MouseEvent evt) {
	if (evt.getClickCount() > 1) {
		Point point = new Point(evt.getX(), evt.getY());
		int row = jtCustomExtKeyUsages.rowAtPoint(point);

		if (row != -1) {
			try {
				CursorUtil.setCursorBusy(JCustomExtendedKeyUsage.this);
				jtCustomExtKeyUsages.setRowSelectionInterval(row, row);
				editSelectedCustomExtKeyUsage();
			} finally {
				CursorUtil.setCursorFree(JCustomExtendedKeyUsage.this);
			}
		}
	}
}
 
Example 8
public void onMousePressed(MouseEvent e) {
    _mouseDownPos.x = e.getX();
    _mouseDownPos.y = e.getY();

    MousePos mPos = new MousePos();
    mPos.curTop = 0;
    mPos.inItem = false;
    _dragNode = getNodeByPosition(e.getX(), e.getY(), mPos);
}
 
Example 9
Source Project: java-photoslibrary   Source File: PhotoListView.java    License: Apache License 2.0 5 votes vote down vote up
private JLabel visualizeMediaItem(MediaItem mediaItem) throws MalformedURLException {
  URL imgSource = new URL(getResizedImageSource(mediaItem.getBaseUrl()));
  ImageIcon fetchedImage = new ImageIcon(imgSource);
  JLabel label = new JLabel("", fetchedImage, JLabel.CENTER);
  final PhotoListView self = this;
  label.addMouseListener(
      new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          onItemClicked.accept(self, mediaItem);
        }
      });
  return label;
}
 
Example 10
Source Project: netbeans   Source File: ResultSetTableCellEditor.java    License: Apache License 2.0 5 votes vote down vote up
public ResultSetTableCellEditor(final JTextField textField) {
    super(textField);
    delegate = new EditorDelegate() {

        @Override
        public void setValue(Object value) {
            val = value;
            textField.setText((value != null) ? value.toString() : "");
        }

        @Override
        public boolean isCellEditable(EventObject evt) {
            if (evt instanceof MouseEvent) {
                return ((MouseEvent) evt).getClickCount() >= 2;
            }
            return true;
        }

        @Override
        public Object getCellEditorValue() {
            String txtVal = textField.getText();
            if (val == null && txtVal.equals("")) {
                return null;
            } else {
                    return txtVal;
                }
            }
    };

    textField.addActionListener(delegate);
    // #204176 - workarround for MacOS L&F
    textField.setCaret(new DefaultCaret());
}
 
Example 11
Source Project: pumpernickel   Source File: ColorWellUI.java    License: MIT License 5 votes vote down vote up
public SingleClickTimer(JColorWell well, int doubleClickThreshold,
		Long timeStamp, ActionListener actionListener,
		MouseEvent trigger) {
	super(doubleClickThreshold, timerListener);
	this.well = well;
	this.timeStamp = timeStamp;
	this.actionListener = actionListener;
	this.trigger = trigger;
	setRepeats(false);
}
 
Example 12
@Override
public void mouseDragged(MouseEvent e) {
	this.stateTransitionTracker.turnOffModelChangeTracking();
	try {
		super.mouseDragged(e);
	} finally {
		this.stateTransitionTracker.onModelStateChanged();
	}
}
 
Example 13
Source Project: visualvm   Source File: ChartPanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void processMouseEvent(MouseEvent e) {
    if (isSelected()) {
        e.consume();
        action = false;
    } else {
        action = true;
    }
    super.processMouseEvent(e);
}
 
Example 14
Source Project: ET_Redux   Source File: ValueModelValueSlider.java    License: Apache License 2.0 5 votes vote down vote up
/**
         *
         * @param e
         */
        @Override
        public void mouseReleased(MouseEvent e) {
            nextX = lastX;//e.getX();
            if (mouseInsideValueModelSliderBox) {
                // recalculate fraction - fire property
                setValueProperty(currentValue);
                // june 2017 workaround for broken java 1.8
//            mouseInsideValueModelSliderBox = false;
            }
        }
 
Example 15
Source Project: pdfxtk   Source File: TextArea.java    License: Apache License 2.0 5 votes vote down vote up
public boolean mouseMovedAction(MouseEvent event) {
     if (overHandler != null) {
context.actionFactory.handleAction(overHandler, null, this, context);
return true;
     }
     return false;
   }
 
Example 16
Source Project: ProtegeVOWL   Source File: ControlListener.java    License: MIT License 5 votes vote down vote up
/**
 * mouse-over event on a visual item (node item or edge item)
 */
@Override
public void itemEntered(VisualItem item, MouseEvent e) {

	// if ctrl is pressed, user zooms -> ignore itemEntered
	if (e.getModifiers() == InputEvent.CTRL_MASK) {
		ctrlZoom(e);
		return;
	}

	// only mark items as highlighted if the layout process is active
	RunLayoutControl rlc = new RunLayoutControl(viewManagerID);
	if (rlc.isLayouting()) {

		if (item instanceof NodeItem) {
			/* set highlight attribute to true, NodeRenderer will change the color */
			item.set(ColumnNames.IS_HIGHLIGHTED, true);
		}

		if (item instanceof EdgeItem) {
			/* set highlight attribute to true, EdgeRenderer will change the color */
			item.set(ColumnNames.IS_HIGHLIGHTED, true);
		}

		if (item instanceof TableDecoratorItem) {
			/* set highlight attribute to true, EdgeRenderer will change the color */
			item.set(ColumnNames.IS_HIGHLIGHTED, true);
		}
	}

}
 
Example 17
Source Project: dragonwell8_jdk   Source File: FontPanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void mouseReleased( MouseEvent e ) {
    if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
        if ( nowZooming )
          zoomWindow.hide();
        nowZooming = false;
    }
    this.setCursor( Cursor.getDefaultCursor() );
}
 
Example 18
Source Project: jdk8u-jdk   Source File: bug7170657.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void test(final Frame frame, final MouseEvent me) {
    MouseEvent newme = SwingUtilities.convertMouseEvent(frame, me, frame);
    if (me.getModifiersEx() != newme.getModifiersEx()
            || me.getModifiers() != newme.getModifiers()) {
        fail(me, newme);
    }
}
 
Example 19
CommentsPanel(HttpRequestResponse requestResponse, SharedValues sharedValues) {
    this.sharedValues = sharedValues;
    commentsList = new JList<>();
    commentsList.setCellRenderer(new JPanelListCellRenderer());
    commentsList.setModel(new JPanelListModel());
    commentsList.addMouseListener( new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            /*
            Checks to see if it is a right click and if the click point is
            within the bounds of a Comments borders
             */
            if ( SwingUtilities.isRightMouseButton(e) && commentsList.getCellBounds(commentsList.locationToIndex(e.getPoint()),commentsList.locationToIndex(e.getPoint())).contains(e.getPoint())) {
                int selectedIndex =
                        commentsList.locationToIndex(e.getPoint());
                RequestComment selectedComment =
                        commentsList.getModel().getElementAt(selectedIndex);
                if (sharedValues.getClient().getUsername().equals(selectedComment.getUserWhoCommented())) {
                    JPopupMenu menu = new JPopupMenu();
                    JMenuItem itemRemove = new JMenuItem("Delete");
                    itemRemove.addActionListener(e1 -> {
                        sharedValues.getCallbacks().printOutput(
                                "Deleting comment " + selectedComment);
                        ((JPanelListModel) commentsList.getModel()).removeComment(selectedIndex);
                        sharedValues.getRequestCommentModel().removeCommentFromNewOrExistingReqResp(selectedComment, requestResponse);
                    });
                    menu.add(itemRemove);
                    menu.show(commentsList, e.getPoint().x, e.getPoint().y);
                }
            }
        }
    });
    setPreferredSize(new Dimension(400, 700));
    setViewportView(commentsList);
}
 
Example 20
DatasetTreeView() {
  // the catalog tree
  tree = new JTree() {
    public JToolTip createToolTip() {
      return new MultilineTooltip();
    }
  };
  tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(null, false)));
  tree.setCellRenderer(new MyTreeCellRenderer());

  tree.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
      int selRow = tree.getRowForLocation(e.getX(), e.getY());
      if (selRow != -1) {
        TreeNode node = (TreeNode) tree.getLastSelectedPathComponent();
        if (node instanceof VariableNode) {
          Variable v = ((VariableNode) node).var;
          firePropertyChangeEvent(new PropertyChangeEvent(this, "Selection", null, v));
        }
      }
    }
  });

  tree.putClientProperty("JTree.lineStyle", "Angled");
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  tree.setToggleClickCount(1);
  ToolTipManager.sharedInstance().registerComponent(tree);

  // layout
  setLayout(new BorderLayout());
  add(new JScrollPane(tree), BorderLayout.CENTER);
}
 
Example 21
public void mouseEntered(final MouseEvent e) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            inChart = true;
            mouseX = e.getX();
            mouseY = e.getY();
        }
    });
    
}
 
Example 22
Source Project: binnavi   Source File: CStateFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new state event object when the edge is clicked with the right mouse button.
 * 
 * @param e The edge which is clicked.
 * @param event The mouse event that caused the state change.
 * 
 * @return The state object that describes the mouse state.
 */
public IMouseState createEdgeClickedRightState(final Edge e, final MouseEvent event) {
  final CEdgeClickedRightState<NodeType, EdgeType> state =
      new CEdgeClickedRightState<NodeType, EdgeType>(this, m_graph, e);

  m_factory.createEdgeClickedRightAction().execute(state, event);

  return state;
}
 
Example 23
Source Project: netbeans   Source File: FindInQueryBar.java    License: Apache License 2.0 5 votes vote down vote up
private void processMouseEvent(MouseEvent evt, boolean over) {
    Object src = evt.getSource();
    if (src instanceof JButton) {
        JButton button = (JButton)src;
        button.setContentAreaFilled(over);
        button.setBorderPainted(over);
    }
}
 
Example 24
Source Project: darklaf   Source File: ColorPipetteBase.java    License: MIT License 5 votes vote down vote up
@Override
public void eventDispatched(final AWTEvent event) {
    if (pickerWindow == null || !pickerWindow.isVisible()) return;
    switch (event.getID()) {
        case MouseEvent.MOUSE_PRESSED :
            ((MouseEvent) event).consume();
            pickAndClose();
            break;
        case MouseEvent.MOUSE_CLICKED :
            ((MouseEvent) event).consume();
            break;
        case KeyEvent.KEY_PRESSED :
            downKeyCode = ((KeyEvent) event).getKeyCode();
            switch (downKeyCode) {
                case KeyEvent.VK_ESCAPE :
                    cancelPipette();
                    break;
                case KeyEvent.VK_ENTER :
                    pickAndClose();
                    break;
                default :
                    break;
            }
            if (!keyDown) {
                keyDown = true;
                updatePipette(true);
            }
            break;
        case KeyEvent.KEY_RELEASED :
            keyDown = false;
            Window picker = getPickerWindow();
            if (picker != null) {
                picker.repaint();
            }
            break;
        default :
            break;
    }
}
 
Example 25
@Override
public void mouseDragged(MouseEvent e) {
    super.mouseDragged(e);

    ERDesignerGraph theGraph = (ERDesignerGraph) graph;
    theGraph.setDragging(true);
}
 
Example 26
Source Project: Logisim   Source File: TableTabCaret.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
	table.requestFocus();
	int row = table.getRow(e);
	int col = table.getColumn(e);
	setCursor(row, col, (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0);
}
 
Example 27
Source Project: Logisim   Source File: EditTool.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mouseMoved(Canvas canvas, Graphics g, MouseEvent e) {
	updateLocation(canvas, e);
	select.mouseMoved(canvas, g, e);
}
 
Example 28
Source Project: jdk8u60   Source File: bug7146377.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static boolean oldIsRightMouseButton(MouseEvent e) {
    return ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK);
}
 
Example 29
Source Project: swift-k   Source File: GridView.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void mouseEntered(MouseEvent e) {
}
 
Example 30
Source Project: tikione-steam-cleaner   Source File: JDialogOptionsTabs.java    License: MIT License 4 votes vote down vote up
private void jButtonDownloadDefinitionsMouseExited(MouseEvent evt) {//GEN-FIRST:event_jButtonDownloadDefinitionsMouseExited
  jLabelDescP0.setText("");
}