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: keystore-explorer   Author: kaikramer   File: JCustomExtendedKeyUsage.java    License: GNU General Public License v3.0 7 votes vote down vote up
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 #2
Source Project: Logisim   Author: LogisimIt   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 #3
Source Project: lizzie   Author: featurecat   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 #4
Source Project: Luyten   Author: deathmarine   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 #5
Source Project: java-swing-tips   Author: aterai   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 #6
Source Project: RipplePower   Author: cping   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 #7
Source Project: radiance   Author: kirill-grouchnikov   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 #8
Source Project: MeteoInfo   Author: meteoinfo   File: LayersLegend.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
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   Author: google   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   Author: apache   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   Author: mickleness   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
Source Project: radiance   Author: kirill-grouchnikov   File: RolloverButtonListener.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
	this.stateTransitionTracker.turnOffModelChangeTracking();
	try {
		super.mouseDragged(e);
	} finally {
		this.stateTransitionTracker.onModelStateChanged();
	}
}
 
Example #13
Source Project: visualvm   Author: oracle   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   Author: CIRDLES   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   Author: tamirhassan   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   Author: VisualDataWeb   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   Author: alibaba   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   Author: frohoff   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
Source Project: BurpSuite-Team-Extension   Author: Static-Flow   File: CommentFrame.java    License: GNU General Public License v3.0 5 votes vote down vote up
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
Source Project: netcdf-java   Author: Unidata   File: DatasetTreeView.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source Project: visualvm   Author: oracle   File: TimelineSelectionManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
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   Author: google   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   Author: apache   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   Author: weisJ   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
Source Project: MogwaiERDesignerNG   Author: mirkosertic   File: ERDesignerGraphUI.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
    super.mouseDragged(e);

    ERDesignerGraph theGraph = (ERDesignerGraph) graph;
    theGraph.setDragging(true);
}
 
Example #26
Source Project: Logisim   Author: LogisimIt   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   Author: LogisimIt   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   Author: chenghanpeng   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   Author: swift-lang   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   Author: jonathanlermitage   File: JDialogOptionsTabs.java    License: MIT License 4 votes vote down vote up
private void jButtonDownloadDefinitionsMouseExited(MouseEvent evt) {//GEN-FIRST:event_jButtonDownloadDefinitionsMouseExited
  jLabelDescP0.setText("");
}