List of usage examples for java.awt.event MouseMotionAdapter MouseMotionAdapter
MouseMotionAdapter
From source file:Main.java
ScreenCaptureRectangle(final BufferedImage screen) { BufferedImage screenCopy = new BufferedImage(screen.getWidth(), screen.getHeight(), screen.getType()); JLabel screenLabel = new JLabel(new ImageIcon(screenCopy)); JScrollPane screenScroll = new JScrollPane(screenLabel); screenScroll.setPreferredSize(new Dimension(300, 300)); repaint(screen, screenCopy);/*from ww w . jav a 2 s .com*/ screenLabel.repaint(); screenLabel.addMouseMotionListener(new MouseMotionAdapter() { Point start = new Point(); @Override public void mouseMoved(MouseEvent me) { start = me.getPoint(); repaint(screen, screenCopy); screenLabel.repaint(); } @Override public void mouseDragged(MouseEvent me) { Point end = me.getPoint(); captureRect = new Rectangle(start, new Dimension(end.x - start.x, end.y - start.y)); repaint(screen, screenCopy); screenLabel.repaint(); } }); JOptionPane.showMessageDialog(null, screenScroll); }
From source file:Main.java
public DrawPad() { setDoubleBuffered(false);//from w w w . ja v a 2s .c om addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { oldX = e.getX(); oldY = e.getY(); } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { currentX = e.getX(); currentY = e.getY(); if (graphics2D != null) graphics2D.drawLine(oldX, oldY, currentX, currentY); repaint(); oldX = currentX; oldY = currentY; } }); }
From source file:com.mirth.connect.client.ui.components.MirthIconTextField.java
public MirthIconTextField(ImageIcon icon) { setIcon(icon);// w w w .j a v a 2 s .c om addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (isIconActive(evt) && iconPopupMenuComponent != null) { JPopupMenu iconPopupMenu = new JPopupMenu(); iconPopupMenu.insert(iconPopupMenuComponent, 0); iconPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }); addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent evt) { int cursorType = getCursor().getType(); if (isIconActive(evt)) { if (StringUtils.isNotBlank(alternateToolTipText)) { MirthIconTextField.super.setToolTipText(alternateToolTipText); } if (iconPopupMenuComponent != null) { if (cursorType != Cursor.HAND_CURSOR) { setCursor(new Cursor(Cursor.HAND_CURSOR)); } } else { if (cursorType != Cursor.DEFAULT_CURSOR) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } } else { if (StringUtils.isNotBlank(alternateToolTipText)) { MirthIconTextField.super.setToolTipText(originalToolTipText); } if (cursorType != Cursor.TEXT_CURSOR) { setCursor(new Cursor(Cursor.TEXT_CURSOR)); } } } }); }
From source file:DigitalClock.java
public DigitalClock() { // Set default values for our properties setFormat(DateFormat.getTimeInstance(DateFormat.MEDIUM, getLocale())); setUpdateFrequency(1000); // Update once a second // Specify a Swing TransferHandler object to do the dirty work of // copy-and-paste and drag-and-drop for us. This one will transfer // the value of the "time" property. Since this property is read-only // it will allow drags but not drops. setTransferHandler(new TransferHandler("time")); // Since JLabel does not normally support drag-and-drop, we need an // event handler to detect a drag and start the transfer. addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { getTransferHandler().exportAsDrag(DigitalClock.this, e, TransferHandler.COPY); }/*w ww . j a v a 2s. com*/ }); // Before we can have a keyboard binding for a Copy command, // the component needs to be able to accept keyboard focus. setFocusable(true); // Request focus when we're clicked on addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { requestFocus(); } }); // Use a LineBorder to indicate when we've got the keyboard focus addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { setBorder(LineBorder.createBlackLineBorder()); } public void focusLost(FocusEvent e) { setBorder(null); } }); // Now bind the Ctrl-C keystroke to a "Copy" command. InputMap im = new InputMap(); im.setParent(getInputMap(WHEN_FOCUSED)); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK), "Copy"); setInputMap(WHEN_FOCUSED, im); // And bind the "Copy" command to a pre-defined Action that performs // a copy using the TransferHandler we've installed. ActionMap am = new ActionMap(); am.setParent(getActionMap()); am.put("Copy", TransferHandler.getCopyAction()); setActionMap(am); // Create a javax.swing.Timer object that will generate ActionEvents // to tell us when to update the displayed time. Every updateFrequency // milliseconds, this timer will cause the actionPerformed() method // to be invoked. (For non-GUI applications, see java.util.Timer.) timer = new Timer(updateFrequency, new ActionListener() { public void actionPerformed(ActionEvent e) { setText(getTime()); // set label to current time string } }); timer.setInitialDelay(0); // Do the first update immediately timer.start(); // Start timing now! }
From source file:org.jcurl.mr.gui.MouseSketchPanel.java
public MouseSketchPanel(final char hotKey) { this.hotKey = hotKey; addMouseMotionListener(new MouseMotionAdapter() { @Override/*from w w w .j a va 2s. c om*/ public void mouseMoved(final MouseEvent e) { if (isHot) MouseSketchPanel.this.lineTo(e.getPoint()); } }); addKeyListener(this); }
From source file:Main.java
public Main(Synthesizer synth) { super("Drums"); // Channel 10 is the GeneralMidi percussion channel. In Java code, we // number channels from 0 and use channel 9 instead. channel = synth.getChannels()[9];// www .ja va 2 s. c o m addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key >= 35 && key <= 81) { channel.noteOn(key, velocity); } } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key >= 35 && key <= 81) channel.noteOff(key); } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { velocity = e.getX(); } }); }
From source file:Drums.java
public Drums(Synthesizer synth) { super("Drums"); // Channel 10 is the GeneralMidi percussion channel. In Java code, we // number channels from 0 and use channel 9 instead. channel = synth.getChannels()[9];//w w w. j av a 2s. c o m addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key >= 35 && key <= 81) { channel.noteOn(key, velocity); } } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key >= 35 && key <= 81) channel.noteOff(key); } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { velocity = e.getX(); } }); }
From source file:br.univali.ps.ui.telas.TelaPrincipal.java
/** /**//from w w w.j a v a 2s .c o m * Creates new form TelaInicial */ public TelaPrincipal() { initComponents(); criaAbas(); configurarCores(); instalarObservadores(); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { // Get x,y and store them pX = me.getX(); pY = me.getY(); } public void mouseDragged(MouseEvent me) { Lancador.getJFrame().setLocation(Lancador.getJFrame().getLocation().x + me.getX() - pX, Lancador.getJFrame().getLocation().y + me.getY() - pY); } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent me) { Lancador.getJFrame().setLocation(Lancador.getJFrame().getLocation().x + me.getX() - pX, Lancador.getJFrame().getLocation().y + me.getY() - pY); } }); }
From source file:org.jcurl.mr.exp.gui.MouseSketchPanel.java
public MouseSketchPanel(final char hotKey) { this.hotKey = hotKey; addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { if (isHot) lineTo(e.getPoint());/*from w w w.ja v a 2 s . c o m*/ } }); addKeyListener(this); }
From source file:com.anrisoftware.prefdialog.miscswing.lists.RubberBandingList.java
private void init() { this.srcPoint = new Point(); this.selectionColor = createSelectionColor(); this.rubberBandMouseListener = new MouseAdapter() { @Override//from w w w . ja v a 2s .c o m public void mousePressed(MouseEvent e) { int index = locationToIndex(e.getPoint()); Rectangle rect = getCellBounds(index, index); if (!rect.contains(e.getPoint())) { clearSelection(); getSelectionModel().setAnchorSelectionIndex(-1); getSelectionModel().setLeadSelectionIndex(-1); setFocusable(false); } else { setFocusable(true); } } @Override public void mouseReleased(MouseEvent e) { setFocusable(true); rubberBand = null; repaint(); } }; this.rubberBandMouseMotionListener = new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { setFocusable(true); if (rubberBand == null) { srcPoint.setLocation(e.getPoint()); } Point destPoint = e.getPoint(); rubberBand = new Path2D.Double(); rubberBand.moveTo(srcPoint.x, srcPoint.y); rubberBand.lineTo(destPoint.x, srcPoint.y); rubberBand.lineTo(destPoint.x, destPoint.y); rubberBand.lineTo(srcPoint.x, destPoint.y); rubberBand.closePath(); setSelectedIndices(getIntersectsIdices(rubberBand)); repaint(); } }; addMouseListener(rubberBandMouseListener); addMouseMotionListener(rubberBandMouseMotionListener); }