List of usage examples for java.awt.event MouseEvent NOBUTTON
int NOBUTTON
To view the source code for java.awt.event MouseEvent NOBUTTON.
Click Source Link
From source file:Main.java
public Main() { setSize(300, 300);/*from w w w . j a va 2 s . c om*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextArea textArea = new JTextArea(); textArea.setText("Click Me!"); textArea.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.NOBUTTON) { textArea.setText("No button clicked..."); } else if (e.getButton() == MouseEvent.BUTTON1) { textArea.setText("Button 1 clicked..."); } else if (e.getButton() == MouseEvent.BUTTON2) { textArea.setText("Button 2 clicked..."); } else if (e.getButton() == MouseEvent.BUTTON3) { textArea.setText("Button 3 clicked..."); } System.out.println("Number of click: " + e.getClickCount()); System.out.println("Click position (X, Y): " + e.getX() + ", " + e.getY()); } }); getContentPane().add(textArea); }
From source file:Main.java
public Main() { setLayout(null);/*from w w w .j av a2 s.c o m*/ add(button); button.setSize(button.getPreferredSize()); button.setLocation(20, 20); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { System.out.println(e.getButton() == MouseEvent.NOBUTTON); } }); }
From source file:SWTUtils.java
/** * Creates an AWT <code>MouseEvent</code> from a swt event. * This method helps passing SWT mouse event to awt components. * @param event The swt event.//from w ww .ja v a 2 s . c o m * @return A AWT mouse event based on the given SWT event. */ public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) { int button = MouseEvent.NOBUTTON; switch (event.button) { case 1: button = MouseEvent.BUTTON1; break; case 2: button = MouseEvent.BUTTON2; break; case 3: button = MouseEvent.BUTTON3; break; } int modifiers = 0; if ((event.stateMask & SWT.CTRL) != 0) { modifiers |= InputEvent.CTRL_DOWN_MASK; } if ((event.stateMask & SWT.SHIFT) != 0) { modifiers |= InputEvent.SHIFT_DOWN_MASK; } if ((event.stateMask & SWT.ALT) != 0) { modifiers |= InputEvent.ALT_DOWN_MASK; } MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(), event.time, modifiers, event.x, event.y, 1, false, button); return awtMouseEvent; }
From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java
/** * Default constructor./*from w ww .ja v a2 s. com*/ * * @since 0.2.3 */ public JUNGCanvas(IVisualizationCallback callback, TopologyPanel topologyPanel) { this.callback = callback; transformNetPlanCoordinatesToJungCoordinates = vertex -> { final int vlIndex = this.callback.getVisualizationState() .getCanvasVisualizationOrderRemovingNonVisible(vertex.getLayer()); final double interLayerDistanceInNpCoord = currentInterLayerDistanceInNpCoordinates; final Point2D basePositionInNetPlanCoord = vertex.getAssociatedNetPlanNode().getXYPositionMap(); return new Point2D.Double(basePositionInNetPlanCoord.getX(), -(basePositionInNetPlanCoord.getY() + (vlIndex * interLayerDistanceInNpCoord))); }; g = new DirectedOrderedSparseMultigraph<>(); l = new StaticLayout<>(g, transformNetPlanCoordinatesToJungCoordinates); vv = new VisualizationViewer<>(l); osmStateManager = new OSMStateManager(callback, topologyPanel, this); originalEdgeShapeTransformer = new EdgeShape.QuadCurve<>(); ((EdgeShape.QuadCurve<GUINode, GUILink>) originalEdgeShapeTransformer).setControlOffsetIncrement(10); // how much they separate from the direct line (default is 20) //((EdgeShape.QuadCurve<GUINode, GUILink>) originalEdgeShapeTransformer).setEdgeIndexFunction(DefaultParallelEdgeIndexFunction.<GUINode, GUILink>getInstance()); // how much they separate from the direct line (default is 20) /* This functions gives an index to the links to show separate (curved): the order among the parallel links (BUT NOW only among the separated ones among them) */ ((EdgeShape.QuadCurve<GUINode, GUILink>) originalEdgeShapeTransformer) .setEdgeIndexFunction(new EdgeIndexFunction<GUINode, GUILink>() { public void reset(Graph<GUINode, GUILink> graph, GUILink e) { } public void reset() { } public int getIndex(Graph<GUINode, GUILink> graph, GUILink e) { final GUINode u = e.getOriginNode(); final GUINode v = e.getDestinationNode(); final HashSet<GUILink> commonEdgeSet = new HashSet<>(graph.getInEdges(v)); commonEdgeSet.retainAll(graph.getOutEdges(u)); commonEdgeSet.removeIf(ee -> !ee.isShownSeparated()); int count = 0; for (GUILink other : commonEdgeSet) if (other == e) return count; else count++; throw new RuntimeException(); } }); /* Customize the graph */ vv.getRenderContext().setVertexDrawPaintTransformer(n -> n.getDrawPaint()); vv.getRenderContext().setVertexFillPaintTransformer(n -> n.getFillPaint()); vv.getRenderContext().setVertexFontTransformer(n -> n.getFont()); vv.getRenderContext().setVertexIconTransformer(gn -> gn.getIcon()); vv.getRenderContext().setVertexIncludePredicate( guiNodeContext -> callback.getVisualizationState().isVisibleInCanvas(guiNodeContext.element)); vv.getRenderer().setVertexLabelRenderer(new NodeLabelRenderer()); vv.setVertexToolTipTransformer(node -> node.getToolTip()); vv.getRenderContext().setEdgeIncludePredicate( context -> callback.getVisualizationState().isVisibleInCanvas(context.element)); vv.getRenderContext().setEdgeArrowPredicate( context -> callback.getVisualizationState().isVisibleInCanvas(context.element) && context.element.getHasArrow()); vv.getRenderContext().setEdgeArrowStrokeTransformer(i -> i.getArrowStroke()); vv.getRenderContext() .setEdgeArrowTransformer(new ConstantTransformer(ArrowFactory.getNotchedArrow(7, 10, 5))); vv.getRenderContext().setEdgeLabelClosenessTransformer(new ConstantDirectionalEdgeValueTransformer(.6, .6)); vv.getRenderContext().setEdgeStrokeTransformer(i -> i.getEdgeStroke()); vv.getRenderContext().setEdgeDrawPaintTransformer(e -> e.getEdgeDrawPaint()); vv.getRenderContext().setArrowDrawPaintTransformer(e -> e.getArrowDrawPaint()); vv.getRenderContext().setArrowFillPaintTransformer(e -> e.getArrowFillPaint()); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.BLUE)); vv.getRenderer().setEdgeLabelRenderer(new BasicEdgeLabelRenderer<GUINode, GUILink>() { public void labelEdge(RenderContext<GUINode, GUILink> rc, Layout<GUINode, GUILink> layout, GUILink e, String label) { if (callback.getVisualizationState().isCanvasShowLinkLabels()) super.labelEdge(rc, layout, e, e.getLabel()); } }); vv.setEdgeToolTipTransformer(link -> link.getToolTip()); vv.getRenderContext().setEdgeShapeTransformer( c -> c.element.isShownSeparated() ? originalEdgeShapeTransformer.transform(c) : new Line2D.Float(0.0f, 0.0f, 1.0f, 0.0f)); // Background controller this.paintableAssociatedToBackgroundImage = null; gm = new PluggableGraphMouse(); vv.setGraphMouse(gm); scalingControl = new LayoutScalingControl(); ITopologyCanvasPlugin scalingPlugin = new ScalingCanvasPlugin(scalingControl, MouseEvent.NOBUTTON); addPlugin(scalingPlugin); vv.setOpaque(false); vv.setBackground(new Color(0, 0, 0, 0)); this.updateInterLayerDistanceInNpCoordinates(callback.getVisualizationState().getInterLayerSpaceInPixels()); // reset(); }