Java Code Examples for org.netbeans.api.visual.widget.Scene#convertSceneToView()
The following examples show how to use
org.netbeans.api.visual.widget.Scene#convertSceneToView() .
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 File: PopupMenuAction.java From netbeans with Apache License 2.0 | 6 votes |
/** * Conditionally display a {@link JPopupMenu} for the given Widget if * the WidgetMouseEvent is a popup trigger. This method is called * by both {@link #mousePressed(Widget, WidgetMouseEvent)} and * {@link #mouseReleased(Widget, WidgetMouseEvent)} methods to handle * displaying a popup menu for the given widget and event. Uses * {@link WidgetMouseEvent#isPopupTrigger() event.isPopupTrigger()} to * determine whether or not a popup menu should be displayed. * @param widget * @param event * @return {@link State#REJECTED} if no JPopupMenu is displayed, * or {@link State#CONSUMED} if a JPopupMenu is displayed. * @see #mousePressed(Widget, WidgetMouseEvent) * @see #mouseReleased(Widget, WidgetMouseEvent) */ protected State handleMouseEvent (Widget widget, WidgetMouseEvent event) { // Different OSes use different MouseEvents (Pressed/Released) to // signal that an event is a PopupTrigger. So, the mousePressed(...) // and mouseReleased(...) methods delegate to this method to // handle the MouseEvent. if (event.isPopupTrigger ()) { JPopupMenu popupMenu = provider.getPopupMenu (widget, event.getPoint ()); if (popupMenu != null) { Scene scene = widget.getScene (); Point point = scene.convertSceneToView (widget.convertLocalToScene (event.getPoint ())); popupMenu.show (scene.getView (), point.x, point.y); } return State.CONSUMED; } return State.REJECTED; }
Example 2
Source File: OffscreenRenderingTest.java From netbeans with Apache License 2.0 | 6 votes |
private BufferedImage dumpSceneOffscreenRendering (Scene scene) { // validate the scene with a off-screen graphics BufferedImage emptyImage = new BufferedImage (1, 1, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D emptyGraphics = emptyImage.createGraphics (); scene.validate (emptyGraphics); emptyGraphics.dispose (); // now the scene is calculated using the emptyGraphics, all widgets should be layout and scene has its size resolved // paint the scene with a off-screen graphics Rectangle viewBounds = scene.convertSceneToView (scene.getBounds ()); BufferedImage image = new BufferedImage (viewBounds.width, viewBounds.height, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = image.createGraphics (); double zoomFactor = scene.getZoomFactor (); graphics.scale (zoomFactor, zoomFactor); scene.paint (graphics); graphics.dispose (); return image; }
Example 3
Source File: CenteredZoomAnimator.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void tick(double progress) { double nextZoom = progress >= 1.0 ? targetZoom : (sourceZoom + progress * (targetZoom - sourceZoom)); Scene scene = getScene(); JComponent view = scene.getView (); if (view != null) { Point viewLocation = view.getVisibleRect ().getLocation(); Dimension viewSize = view.getVisibleRect ().getSize(); Point oldCenter = scene.convertSceneToView (center); ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom); scene.validate (); // HINT - forcing to change preferred size of the JComponent view Point newCenter = scene.convertSceneToView (center); Rectangle viewBounds = view.getVisibleRect(); Point visibleCenter = new Point((int)viewBounds.getCenterX(), (int)viewBounds.getCenterY()); newCenter.x += Math.round((newCenter.x - visibleCenter.x) * progress); newCenter.y += Math.round((newCenter.y - visibleCenter.y) * progress); view.scrollRectToVisible (new Rectangle ( newCenter.x - oldCenter.x + viewLocation.x, newCenter.y - oldCenter.y + viewLocation.y, viewSize.width, viewSize.height )); } else { ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom); } }
Example 4
Source File: MouseCenteredZoomAction.java From netbeans with Apache License 2.0 | 4 votes |
public State mouseWheelMoved (Widget widget, WidgetMouseWheelEvent event) { Scene scene = widget.getScene (); int modifiers = scene.getInputBindings ().getZoomActionModifiers (); if ((event.getModifiers () & modifiers) != modifiers) return State.REJECTED; int amount = event.getWheelRotation (); double scale = 1.0; while (amount > 0) { scale /= zoomMultiplier; amount --; } while (amount < 0) { scale *= zoomMultiplier; amount ++; } JComponent view = scene.getView (); if (view != null) { Rectangle viewBounds = view.getVisibleRect (); Point center = widget.convertLocalToScene (event.getPoint ()); Point mouseLocation = scene.convertSceneToView (center); scene.setZoomFactor (scale * scene.getZoomFactor ()); scene.validate (); // HINT - forcing to change preferred size of the JComponent view center = scene.convertSceneToView (center); view.scrollRectToVisible (new Rectangle ( center.x - (mouseLocation.x - viewBounds.x), center.y - (mouseLocation.y - viewBounds.y), viewBounds.width, viewBounds.height )); } else scene.setZoomFactor (scale * scene.getZoomFactor ()); return State.CONSUMED; }
Example 5
Source File: CenteredZoomAction.java From netbeans with Apache License 2.0 | 4 votes |
public State mouseWheelMoved (Widget widget, WidgetMouseWheelEvent event) { Scene scene = widget.getScene (); int modifiers = scene.getInputBindings ().getZoomActionModifiers (); if ((event.getModifiers () & modifiers) != modifiers) return State.REJECTED; int amount = event.getWheelRotation (); double scale = 1.0; while (amount > 0) { scale /= zoomMultiplier; amount --; } while (amount < 0) { scale *= zoomMultiplier; amount ++; } JComponent view = scene.getView (); if (view != null) { Rectangle viewBounds = view.getVisibleRect (); Point center = GeomUtil.center (viewBounds); center = scene.convertViewToScene (center); scene.setZoomFactor (scale * scene.getZoomFactor ()); scene.validate (); // HINT - forcing to change preferred size of the JComponent view center = scene.convertSceneToView (center); view.scrollRectToVisible (new Rectangle ( center.x - viewBounds.width / 2, center.y - viewBounds.height / 2, viewBounds.width, viewBounds.height )); } else scene.setZoomFactor (scale * scene.getZoomFactor ()); return State.CONSUMED; }