List of usage examples for java.awt.event MouseListener mouseReleased
public void mouseReleased(MouseEvent e);
From source file:unikn.dbis.univis.visualization.graph.plaf.VGraphUI.java
/** * Creates the listener responsible for calling the correct handlers based * on mouse events, and to select invidual cells. *//*from w w w.ja v a 2s . c om*/ protected MouseListener createMouseListener() { return new MouseHandler() { /** * Invoked when a mouse button has been pressed on a component. * //@Override public void mousePressed(MouseEvent e) { Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; JPopupMenu menu = new JPopupMenu(); VChartPanel chartPanel = (VChartPanel) cell.getUserObject(); if (chartPanel.isShowPopUp()) { LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems(); JMenu first = new JMenu("1-39"); int checker = 0; for (Iterator iter = collect.iterator(); iter.hasNext();) { LegendItem item = (LegendItem) iter.next(); checker++; first.add(new JMenuItem(item.getLabel())); if ((checker % 40) == 0) { menu.add(first); first = new JMenu("" + checker + "-" + (checker + 39)); } if (!iter.hasNext()) { menu.add(first); } } menu.show(graph, e.getX(), e.getY()); } } super.mousePressed(e); } */ /** * Invoked when a mouse button has been pressed on a component. */ @Override public void mousePressed(MouseEvent e) { Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (SwingUtilities.isLeftMouseButton(e) && e.isAltDown()) { if (o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; JPopupMenu menu = new JPopupMenu(); VChartPanel chartPanel = (VChartPanel) cell.getUserObject(); LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems(); JMenu first = new JMenu("1-39"); int checker = 0; for (Iterator iter = collect.iterator(); iter.hasNext();) { LegendItem item = (LegendItem) iter.next(); checker++; first.add(new JMenuItem(item.getLabel())); if ((checker % 40) == 0) { menu.add(first); first = new JMenu("" + checker + "-" + (checker + 39)); } if (!iter.hasNext()) { menu.add(first); } } menu.show(graph, e.getX(), e.getY()); } } super.mousePressed(e); if (o != null && o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; for (MouseListener l : chart.getMouseListeners()) { l.mousePressed(e); } } } } // Event may be null when called to cancel the current operation. @Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o != null && o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; for (MouseListener l : chart.getMouseListeners()) { l.mouseReleased(e); } } } } /** * Invoked when the mouse has been clicked on a component. */ @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o != null && o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu menu = chart.createPopupMenu(true, true, true, true); menu.show(graph, e.getX(), e.getY()); } /* for (MouseListener l : chart.getMouseListeners()) { System.out.println("LISTENS CLI"); l.mouseClicked(e); } */ } } } /* // Event may be null when called to cancel the current operation. @Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); Object[] cells = graphSelectionModel.getSelectionCells(); Rectangle2D bounds = graph.getCellBounds(cells); if (bounds != null) { Rectangle2D b2 = graph.toScreen((Rectangle2D) bounds.clone()); graph.scrollRectToVisible(new Rectangle((int) b2.getX(), (int) b2.getY(), (int) b2.getWidth(), (int) b2.getHeight())); } } */ /** * Invoked when the mouse pointer has been moved on a component (with no * buttons down). */ @Override public void mouseMoved(MouseEvent e) { if (graph.isMoveable()) { super.mouseMoved(e); } Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o != null && o instanceof VGraphCell) { selectedCell = (VGraphCell) o; Rectangle2D bounds = graph.getCellBounds(selectedCell); menu.show(graph, (int) (bounds.getX() + bounds.getWidth()), (int) bounds.getY() + (int) (bounds.getHeight() - menu.getHeight())); } } }; }