Java Code Examples for org.netbeans.api.visual.widget.Widget#convertLocalToScene()
The following examples show how to use
org.netbeans.api.visual.widget.Widget#convertLocalToScene() .
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: ReconnectAction.java From netbeans with Apache License 2.0 | 6 votes |
private boolean move (Widget widget, Point point) { if (connectionWidget != widget) return false; Point replacementSceneLocation = widget.convertLocalToScene (point); replacementWidget = resolveReplacementWidgetCore (connectionWidget.getScene (), replacementSceneLocation); Anchor replacementAnchor = null; if (replacementWidget != null) replacementAnchor = decorator.createReplacementWidgetAnchor (replacementWidget); if (replacementAnchor == null) replacementAnchor = decorator.createFloatAnchor (replacementSceneLocation); if (reconnectingSource) connectionWidget.setSourceAnchor (replacementAnchor); else connectionWidget.setTargetAnchor (replacementAnchor); return true; }
Example 2
Source File: ResizeAction.java From netbeans with Apache License 2.0 | 6 votes |
public State mousePressed (Widget widget, WidgetMouseEvent event) { if (isLocked ()) return State.createLocked (widget, this); if (event.getButton () == MouseEvent.BUTTON1 && event.getClickCount () == 1) { insets = widget.getBorder ().getInsets (); controlPoint = resolver.resolveControlPoint (widget, event.getPoint ()); if (controlPoint != null) { resizingWidget = widget; originalSceneRectangle = null; if (widget.isPreferredBoundsSet ()) originalSceneRectangle = widget.getPreferredBounds (); if (originalSceneRectangle == null) originalSceneRectangle = widget.getBounds (); if (originalSceneRectangle == null) originalSceneRectangle = widget.getPreferredBounds (); dragSceneLocation = widget.convertLocalToScene (event.getPoint ()); provider.resizingStarted (widget); return State.createLocked (widget, this); } } return State.REJECTED; }
Example 3
Source File: BestPathAnchor.java From Llunatic with GNU General Public License v3.0 | 6 votes |
@Override public Result compute(Entry entry) { Widget widget = getRelatedWidget(); Widget otherWidget = entry.getOppositeAnchor().getRelatedWidget(); Rectangle bounds = widget.convertLocalToScene(widget.getBounds()); Rectangle otherBounds = otherWidget.convertLocalToScene(otherWidget.getBounds()); Point center = getCenter(bounds); int leftBound = bounds.x; int rightBound = bounds.x + bounds.width; int oppositeLeftBound = otherBounds.x; int oppositeRightBound = otherBounds.x + otherBounds.width; if (leftBound >= oppositeRightBound) { return new Anchor.Result(new Point(leftBound, center.y), Direction.LEFT); } else if (rightBound <= oppositeLeftBound) { return new Anchor.Result(new Point(rightBound, center.y), Direction.RIGHT); } else { int leftDist = Math.abs(leftBound - oppositeLeftBound); int rightDist = Math.abs(rightBound - oppositeRightBound); if (leftDist <= rightDist) { return new Anchor.Result(new Point(leftBound, center.y), Direction.LEFT); } else { return new Anchor.Result(new Point(rightBound, center.y), Direction.RIGHT); } } }
Example 4
Source File: AlignWithMoveStrategyProvider.java From netbeans with Apache License 2.0 | 6 votes |
public Point locationSuggested (Widget widget, Point originalLocation, Point suggestedLocation) { Point widgetLocation = widget.getLocation (); Rectangle widgetBounds = outerBounds ? widget.getBounds () : widget.getClientArea (); Rectangle bounds = widget.convertLocalToScene (widgetBounds); bounds.translate (suggestedLocation.x - widgetLocation.x, suggestedLocation.y - widgetLocation.y); Insets insets = widget.getBorder ().getInsets (); if (! outerBounds) { suggestedLocation.x += insets.left; suggestedLocation.y += insets.top; } Point point = super.locationSuggested (widget, bounds, widget.getParentWidget().convertLocalToScene(suggestedLocation), true, true, true, true); if (! outerBounds) { point.x -= insets.left; point.y -= insets.top; } return widget.getParentWidget ().convertSceneToLocal (point); }
Example 5
Source File: PopupMenuAction.java From netbeans with Apache License 2.0 | 6 votes |
public State keyPressed (Widget widget, WidgetKeyEvent event) { if (event.getKeyCode () == KeyEvent.VK_CONTEXT_MENU || ((event.getModifiers () & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK && event.getKeyCode () == KeyEvent.VK_F10)) { JPopupMenu popupMenu = provider.getPopupMenu (widget, null); if (popupMenu != null) { JComponent view = widget.getScene ().getView (); if (view != null) { // Rectangle visibleRect = view.getVisibleRect (); // popupMenu.show (view, visibleRect.x + 10, visibleRect.y + 10); Rectangle bounds = widget.getBounds (); Point location = new Point (bounds.x + 5, bounds.y + 5); location = widget.convertLocalToScene (location); location = widget.getScene ().convertSceneToView (location); popupMenu.show (view, location.x, location.y); } } return State.CONSUMED; } return State.REJECTED; }
Example 6
Source File: DirectionalAnchor.java From netbeans with Apache License 2.0 | 6 votes |
public Result compute (Entry entry) { Point relatedLocation = getRelatedSceneLocation (); Point oppositeLocation = getOppositeSceneLocation (entry); Widget widget = getRelatedWidget (); Rectangle bounds = widget.convertLocalToScene (widget.getBounds ()); Point center = GeomUtil.center (bounds); switch (kind) { case HORIZONTAL: if (relatedLocation.x >= oppositeLocation.x) return new Anchor.Result (new Point (bounds.x - gap, center.y), Direction.LEFT); else return new Anchor.Result (new Point (bounds.x + bounds.width + gap, center.y), Direction.RIGHT); case VERTICAL: if (relatedLocation.y >= oppositeLocation.y) return new Anchor.Result (new Point (center.x, bounds.y - gap), Direction.TOP); else return new Anchor.Result (new Point (center.x, bounds.y + bounds.height + gap), Direction.BOTTOM); } return null; }
Example 7
Source File: BestPathObjectAnchor.java From Llunatic with GNU General Public License v3.0 | 5 votes |
@Override public Result compute(Entry entry) { Widget widget = getRelatedWidget(); Widget otherWidget = entry.getOppositeAnchor().getRelatedWidget(); Rectangle bounds = widget.convertLocalToScene(widget.getBounds()); Rectangle otherBounds = otherWidget.convertLocalToScene(otherWidget.getBounds()); Point center = getCenter(bounds); Connection minimum = getMin(new Connection(bounds.x, otherBounds.x, Direction.LEFT), new Connection(bounds.x, otherBounds.x + otherBounds.width, Direction.LEFT)); minimum = getMin(minimum, new Connection(bounds.x + bounds.width, otherBounds.x, Direction.RIGHT)); minimum = getMin(minimum, new Connection(bounds.x + bounds.width, otherBounds.x + otherBounds.width, Direction.RIGHT)); return new Anchor.Result(new Point(minimum.getStartX(), center.y), minimum.getDirection()); }
Example 8
Source File: DependencyGraphScene.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void performLayout() { Rectangle rectangle = null; List<? extends Widget> toFit = widgets != null ? widgets : depScene.getChildren(); if (toFit == null) { return; } for (Widget widget : toFit) { Rectangle bounds = widget.getBounds(); if (bounds == null) { continue; } if (rectangle == null) { rectangle = widget.convertLocalToScene(bounds); } else { rectangle = rectangle.union(widget.convertLocalToScene(bounds)); } } // margin around if (widgets == null) { rectangle.grow(5, 5); } else { rectangle.grow(25, 25); } Dimension dim = rectangle.getSize(); Dimension viewDim = parentScrollPane.getViewportBorderBounds().getSize (); double zf = Math.min ((double) viewDim.width / dim.width, (double) viewDim.height / dim.height); if (depScene.isAnimated()) { if (widgets == null) { depScene.getSceneAnimator().animateZoomFactor(zf); } else { CenteredZoomAnimator cza = new CenteredZoomAnimator(depScene.getSceneAnimator()); cza.setZoomFactor(zf, new Point((int)rectangle.getCenterX(), (int)rectangle.getCenterY())); } } else { depScene.setMyZoomFactor (zf); } }
Example 9
Source File: FixedPathAnchor.java From Llunatic with GNU General Public License v3.0 | 5 votes |
@Override public Result compute(Entry entry) { Widget widget = getRelatedWidget(); Rectangle bounds = widget.convertLocalToScene(widget.getBounds()); Point center = getCenter(bounds); int leftBound = bounds.x; int rightBound = bounds.x + bounds.width; if (direction == Direction.LEFT) { return new Anchor.Result(new Point(leftBound, center.y), Direction.LEFT); } else { return new Anchor.Result(new Point(rightBound, center.y), Direction.RIGHT); } }
Example 10
Source File: DiagramScene.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void gotoSelection(Set<Object> ids) { Rectangle overall = null; Set<Integer> hiddenNodes = new HashSet<>(this.getModel().getHiddenNodes()); hiddenNodes.removeAll(ids); this.getModel().showNot(hiddenNodes); Set<Object> objects = idSetToObjectSet(ids); for (Object o : objects) { Widget w = getWidget(o); if (w != null) { Rectangle r = w.getBounds(); Point p = w.convertLocalToScene(new Point(0, 0)); Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height); if (overall == null) { overall = r2; } else { overall = overall.union(r2); } } } if (overall != null) { centerRectangle(overall); } setSelectedObjects(objects); }
Example 11
Source File: RectangularAnchor.java From netbeans with Apache License 2.0 | 5 votes |
private Result computeBoundaryIntersectionPoint(Point relatedLocation, Point oppositeLocation) { Widget widget = getRelatedWidget(); Rectangle bounds = widget.getBounds(); if (!includeBorders) { Insets insets = widget.getBorder().getInsets(); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.left + insets.right; bounds.height -= insets.top + insets.bottom; } bounds = widget.convertLocalToScene(bounds); if (bounds.isEmpty() || relatedLocation.equals(oppositeLocation)) { return null; } float dx = oppositeLocation.x - relatedLocation.x; float dy = oppositeLocation.y - relatedLocation.y; float ddx = Math.abs(dx) / (float) bounds.width; float ddy = Math.abs(dy) / (float) bounds.height; Anchor.Direction direction; if (ddx >= ddy) { direction = dx >= 0.0f ? Direction.RIGHT : Direction.LEFT; } else { direction = dy >= 0.0f ? Direction.BOTTOM : Direction.TOP; } float scale = 0.5f / Math.max(ddx, ddy); Point point = new Point(Math.round(relatedLocation.x + scale * dx), Math.round(relatedLocation.y + scale * dy)); return new Anchor.Result(point, direction); }
Example 12
Source File: RectangularAnchor.java From netbeans with Apache License 2.0 | 5 votes |
@Override public List<Point> compute(List<Point> points) { ArrayList<Point> bestPoints = new ArrayList<Point> (points) ; Point relatedLocation = getRelatedSceneLocation(); int direction = 1 ; int index = 0 ; //the related location is the center of this anchor. It is possible that //the list of points started at the opposite anchor (other end of connection). Point endPoint = bestPoints.get(index); if (!endPoint.equals(relatedLocation)) { index = bestPoints.size() - 1 ; endPoint = bestPoints.get(index); direction = -1 ; } Widget widget = getRelatedWidget(); Rectangle bounds = widget.getBounds(); bounds = widget.convertLocalToScene(bounds); Point neighbor = bestPoints.get (index+direction) ; //moving the end point to the end of the anchor from the interior while (bounds.contains(neighbor)) { bestPoints.remove(index) ; endPoint = bestPoints.get (index); neighbor = bestPoints.get (index+direction); } Result intersection = this.computeBoundaryIntersectionPoint(endPoint, neighbor); bestPoints.remove(index) ; bestPoints.add(index, intersection.getAnchorSceneLocation()); return bestPoints ; }
Example 13
Source File: ConnectAction.java From netbeans with Apache License 2.0 | 5 votes |
private boolean move (Widget widget, Point point) { if (sourceWidget != widget) return false; Point targetSceneLocation = widget.convertLocalToScene (point); targetWidget = resolveTargetWidgetCore (interractionLayer.getScene (), targetSceneLocation); Anchor targetAnchor = null; if (targetWidget != null) targetAnchor = decorator.createTargetAnchor (targetWidget); if (targetAnchor == null) targetAnchor = decorator.createFloatAnchor (targetSceneLocation); connectionWidget.setTargetAnchor (targetAnchor); return true; }
Example 14
Source File: MoveAction.java From netbeans with Apache License 2.0 | 5 votes |
private boolean move (Widget widget, Point newLocation) { if (movingWidget != widget) return false; initialMouseLocation = null; newLocation = widget.convertLocalToScene (newLocation); Point location = new Point (originalSceneLocation.x + newLocation.x - dragSceneLocation.x, originalSceneLocation.y + newLocation.y - dragSceneLocation.y); provider.setNewLocation (widget, strategy.locationSuggested (widget, originalSceneLocation, location)); return true; }
Example 15
Source File: MoveAction.java From netbeans with Apache License 2.0 | 5 votes |
public State mousePressed (Widget widget, WidgetMouseEvent event) { if (isLocked ()) return State.createLocked (widget, this); if (event.getButton () == MouseEvent.BUTTON1 && event.getClickCount () == 1) { movingWidget = widget; initialMouseLocation = event.getPoint (); originalSceneLocation = provider.getOriginalLocation (widget); if (originalSceneLocation == null) originalSceneLocation = new Point (); dragSceneLocation = widget.convertLocalToScene (event.getPoint ()); provider.movementStarted (widget); return State.createLocked (widget, this); } return State.REJECTED; }
Example 16
Source File: RectangularSelectAction.java From netbeans with Apache License 2.0 | 4 votes |
private void move (Widget widget, Point newLocation) { Point sceneLocation = widget.convertLocalToScene (newLocation); selectionSceneRectangle.width = sceneLocation.x - selectionSceneRectangle.x; selectionSceneRectangle.height = sceneLocation.y - selectionSceneRectangle.y; resolveSelectionWidgetLocationBounds (); }
Example 17
Source File: Util.java From jlibs with Apache License 2.0 | 4 votes |
public static Rectangle bounds(Widget widget){ return widget.convertLocalToScene(widget.getPreferredBounds()); }
Example 18
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 19
Source File: ResizeAction.java From netbeans with Apache License 2.0 | 4 votes |
private boolean resize (Widget widget, Point newLocation) { if (resizingWidget != widget) return false; newLocation = widget.convertLocalToScene (newLocation); int dx = newLocation.x - dragSceneLocation.x; int dy = newLocation.y - dragSceneLocation.y; int minx = insets.left + insets.right; int miny = insets.top + insets.bottom; Rectangle rectangle = new Rectangle (originalSceneRectangle); switch (controlPoint) { case BOTTOM_CENTER: resizeToBottom (miny, rectangle, dy); break; case BOTTOM_LEFT: resizeToLeft (minx, rectangle, dx); resizeToBottom (miny, rectangle, dy); break; case BOTTOM_RIGHT: resizeToRight (minx, rectangle, dx); resizeToBottom (miny, rectangle, dy); break; case CENTER_LEFT: resizeToLeft (minx, rectangle, dx); break; case CENTER_RIGHT: resizeToRight (minx, rectangle, dx); break; case TOP_CENTER: resizeToTop (miny, rectangle, dy); break; case TOP_LEFT: resizeToLeft (minx, rectangle, dx); resizeToTop (miny, rectangle, dy); break; case TOP_RIGHT: resizeToRight (minx, rectangle, dx); resizeToTop (miny, rectangle, dy); break; } widget.setPreferredBounds (strategy.boundsSuggested (widget, originalSceneRectangle, rectangle, controlPoint)); return true; }