List of usage examples for java.awt.event MouseEvent getButton
public int getButton()
From source file:com.lfv.lanzius.server.WorkspaceView.java
public void mousePressed(MouseEvent e) { Point p = e.getPoint();/*ww w . j a va2 s .co m*/ if (e.getButton() == MouseEvent.BUTTON1) { Document doc = server.getDocument(); if (doc == null) return; List<Integer> selectionList = new LinkedList<Integer>(); boolean selectionChanged = false; // Clicked on a group? Iterator<Group> iterg = groupList.iterator(); while (iterg.hasNext()) { Group g = iterg.next(); if (g.boundingRect.contains(p)) { g.isSelected = !g.isSelected; synchronized (doc) { Element egd = DomTools.getElementFromSection(doc, "GroupDefs", "id", String.valueOf(g.gid)); if (egd != null) egd.setAttribute("selected", String.valueOf(g.isSelected)); } selectionChanged = true; } if (g.isSelected) selectionList.add(g.gid); } if (selectionChanged) { // Update panel and view deselectTerminals(); panel.updateButtons(false, selectionList); repaint(); return; } // Clicked a terminal? selectionList.clear(); Iterator<Terminal> itert = terminalMap.values().iterator(); while (itert.hasNext()) { Terminal t = itert.next(); if ((p.x >= t.x) && (p.x < t.x + SERVERVIEW_TERMINAL_WIDTH) && (p.y >= t.y) && (p.y < t.y + SERVERVIEW_TERMINAL_HEIGHT)) { t.isSelected = !t.isSelected; synchronized (doc) { Element etd = DomTools.getElementFromSection(doc, "TerminalDefs", "id", String.valueOf(t.tid)); if (etd != null) etd.setAttribute("selected", String.valueOf(t.isSelected)); } selectionChanged = true; } if (t.isSelected) selectionList.add(t.tid); } if (selectionChanged) { // Update panel and view deselectGroups(); panel.updateButtons(true, selectionList); repaint(); } // Clicked on the workspace, deselect all else { panel.deselectAll(); } } }
From source file:be.nbb.demetra.dfm.output.simulation.RealTimePerspGraphView.java
/** * Creates new form FixedHorizonsGraphView *///from ww w . jav a 2 s . com public RealTimePerspGraphView(DfmDocument doc) { initComponents(); demetraUI = DemetraUI.getDefault(); formatter = demetraUI.getDataFormat().numberFormatter(); defaultColorSchemeSupport = new SwingColorSchemeSupport() { @Override public ColorScheme getColorScheme() { return demetraUI.getColorScheme(); } }; this.graphs_ = new LinkedHashMap<>(); trueDataRenderer = new XYLineAndShapeRenderer(true, false); trueDataRenderer.setAutoPopulateSeriesPaint(false); trueDataRenderer.setBasePaint(defaultColorSchemeSupport.getLineColor(KnownColor.RED)); forecastsRenderer = new XYLineAndShapeRenderer(true, false); forecastsRenderer.setAutoPopulateSeriesPaint(false); forecastsRenderer.setAutoPopulateSeriesShape(false); forecastsRenderer.setBaseShape(new Ellipse2D.Double(-2, -2, 4, 4)); forecastsRenderer.setBasePaint(defaultColorSchemeSupport.getLineColor(KnownColor.BLUE)); forecastsRenderer.setBaseShapesFilled(false); arimaRenderer = new XYLineAndShapeRenderer(true, false); arimaRenderer.setAutoPopulateSeriesPaint(false); arimaRenderer.setAutoPopulateSeriesShape(false); arimaRenderer.setBaseShape(new Ellipse2D.Double(-2, -2, 4, 4)); arimaRenderer.setBasePaint(defaultColorSchemeSupport.getLineColor(KnownColor.GREEN)); arimaRenderer.setBaseShapesFilled(false); mainChart = createChart(); detailChart = createChart(); this.dfmSimulation = Optional.absent(); chartPanel = new JChartPanel(null); chartPanel.setPopupMenu(buildMenu().getPopupMenu()); chartPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { indexSelected = -1; if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { double x = chartPanel.getChartX(e.getX()); Graphs g = null; for (Bornes b : graphs_.keySet()) { indexSelected++; if (x >= b.min_ && x <= b.max_) { g = graphs_.get(b); break; } } if (g == null) { return; } showDetail(g); } } }); comboBox.setRenderer(new ComboBoxRenderer()); comboBox.addItemListener((ItemEvent e) -> { filterPanel = null; updateChart(); }); addPropertyChangeListener((PropertyChangeEvent evt) -> { switch (evt.getPropertyName()) { case DFM_SIMULATION_PROPERTY: updateComboBox(); updateChart(); break; } }); updateComboBox(); updateChart(); demetraUI.addPropertyChangeListener((PropertyChangeEvent evt) -> { switch (evt.getPropertyName()) { case DemetraUI.DATA_FORMAT_PROPERTY: onDataFormatChanged(); break; case DemetraUI.COLOR_SCHEME_NAME_PROPERTY: onColorSchemeChanged(); break; } }); add(chartPanel, BorderLayout.CENTER); }
From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java
@Override public void mouseMoved(MouseEvent e) { if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOVED)) return;//www.ja va 2s.c o m if (e.getComponent() instanceof ChartPanel) { ChartPanel chartPanel = (ChartPanel) e.getComponent(); ChartEntity entity = findChartEntity(chartPanel, e); ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity); Button button = Button.getButton(e.getButton()); // handle event handleEvent(new ChartGestureEvent(chartPanel, e, entity, new ChartGesture(gestureEntity, Event.MOVED, button))); } }
From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java
@Override public void mouseExited(MouseEvent e) { if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.EXITED)) return;/*from w ww . j a v a 2 s . c o m*/ if (e.getComponent() instanceof ChartPanel) { ChartPanel chartPanel = (ChartPanel) e.getComponent(); ChartEntity entity = findChartEntity(chartPanel, e); ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity); Button button = Button.getButton(e.getButton()); // handle event handleEvent(new ChartGestureEvent(chartPanel, e, entity, new ChartGesture(gestureEntity, Event.EXITED, button))); } }
From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java
@Override public void mousePressed(MouseEvent e) { if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.PRESSED)) return;//from w w w . j a v a 2 s.co m if (e.getComponent() instanceof ChartPanel) { ChartPanel chartPanel = (ChartPanel) e.getComponent(); ChartEntity entity = findChartEntity(chartPanel, e); ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity); Button button = Button.getButton(e.getButton()); // handle event lastDragEvent = new ChartGestureEvent(chartPanel, e, entity, new ChartGesture(gestureEntity, Event.PRESSED, button)); handleEvent(lastDragEvent); } }
From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java
@Override public void mouseEntered(MouseEvent e) { if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.ENTERED)) return;// w ww. j a v a2 s . c o m if (e.getComponent() instanceof ChartPanel) { ChartPanel chartPanel = (ChartPanel) e.getComponent(); ChartEntity entity = findChartEntity(chartPanel, e); ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity); Button button = Button.getButton(e.getButton()); // handle event handleEvent(new ChartGestureEvent(chartPanel, e, entity, new ChartGesture(gestureEntity, Event.ENTERED, button))); } }
From source file:net.sf.mzmine.modules.visualization.tic.TICPlot.java
@Override public void mouseClicked(final MouseEvent event) { // Let the parent handle the event (selection etc.) super.mouseClicked(event); // Request focus to receive key events. requestFocus();/*from ww w . j av a 2s. com*/ // If user double-clicked left button, place a request to open a spectrum. if (event.getButton() == MouseEvent.BUTTON1 && event.getClickCount() == 2) { showSpectrumRequest = true; } }
From source file:org.tinymediamanager.ui.tvshows.TvShowPanel.java
/** * Inits the./* ww w.ja v a 2 s.com*/ */ private void init() { // build menu buildMenu(); // add double click listener MouseListener mouseListener = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2 && !e.isConsumed() && e.getButton() == MouseEvent.BUTTON1) { actionEdit2.actionPerformed(new ActionEvent(e, 0, "")); } } }; tree.addMouseListener(mouseListener); }
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);//from w w w . j a v a 2 s .co m 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:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java
@Override public void mouseReleased(MouseEvent e) { if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.RELEASED)) return;//from w w w . j a va 2 s .c o m if (e.getComponent() instanceof ChartPanel) { ChartPanel chartPanel = (ChartPanel) e.getComponent(); ChartEntity entity = findChartEntity(chartPanel, e); ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity); Button button = Button.getButton(e.getButton()); // last gesture was dragged? keep the same chartEntity if (lastDragEvent != null) { entity = lastDragEvent.getEntity(); gestureEntity = lastDragEvent.getGesture().getEntity(); } // handle event handleEvent(new ChartGestureEvent(chartPanel, e, entity, new ChartGesture(gestureEntity, Event.RELEASED, button))); // reset drag lastDragEvent = null; } }