diff --git a/api.visual/src/org/netbeans/api/visual/widget/ComponentWidget.java b/api.visual/src/org/netbeans/api/visual/widget/ComponentWidget.java --- a/api.visual/src/org/netbeans/api/visual/widget/ComponentWidget.java +++ b/api.visual/src/org/netbeans/api/visual/widget/ComponentWidget.java @@ -64,7 +64,8 @@ public class ComponentWidget extends Wid private Component component; private boolean componentAdded; private boolean widgetAdded; - private double zoomFactor = Double.MIN_VALUE; + private double zoomFactorX = Double.MIN_VALUE; + private double zoomFactorY = Double.MIN_VALUE; private ComponentSceneListener validateListener; private ComponentComponentListener componentListener; private boolean componentVisible = false; @@ -139,9 +140,10 @@ public class ComponentWidget extends Wid */ protected final Rectangle calculateClientArea () { Dimension preferredSize = component.getPreferredSize (); - zoomFactor = getScene ().getZoomFactor (); - preferredSize.width = (int) Math.floor (preferredSize.width / zoomFactor); - preferredSize.height = (int) Math.floor (preferredSize.height / zoomFactor); + zoomFactorX = getScene ().getZoomFactorX (); + zoomFactorY = getScene ().getZoomFactorY (); + preferredSize.width = (int) Math.floor (preferredSize.width / zoomFactorX); + preferredSize.height = (int) Math.floor (preferredSize.height / zoomFactorY); return new Rectangle (preferredSize); } @@ -181,8 +183,9 @@ public class ComponentWidget extends Wid Rectangle bounds = getClientArea (); AffineTransform previousTransform = graphics.getTransform (); graphics.translate (bounds.x, bounds.y); - double zoomFactor = getScene ().getZoomFactor (); - graphics.scale (1 / zoomFactor, 1 / zoomFactor); + double zoomFactorX = getScene ().getZoomFactorX (); + double zoomFactorY = getScene ().getZoomFactorY (); + graphics.scale (1 / zoomFactorX, 1 / zoomFactorY); component.paint (graphics); graphics.setTransform (previousTransform); if (isDoubleBuffered) @@ -196,10 +199,13 @@ public class ComponentWidget extends Wid } public void sceneValidating () { - double newZoomFactor = getScene ().getZoomFactor (); - if (Math.abs (newZoomFactor - zoomFactor) != 0.0) { + double newZoomFactorX = getScene ().getZoomFactorX (); + double newZoomFactorY = getScene ().getZoomFactorY (); + if ( (Math.abs (newZoomFactorX - zoomFactorX) != 0.0) || + Math.abs (newZoomFactorY - zoomFactorY) != 0.0){ revalidate (); - zoomFactor = newZoomFactor; + zoomFactorX = newZoomFactorX; + zoomFactorY = newZoomFactorY; } } diff --git a/api.visual/src/org/netbeans/api/visual/widget/Scene.java b/api.visual/src/org/netbeans/api/visual/widget/Scene.java --- a/api.visual/src/org/netbeans/api/visual/widget/Scene.java +++ b/api.visual/src/org/netbeans/api/visual/widget/Scene.java @@ -78,30 +78,23 @@ import java.util.HashSet; // TODO - remove SuppressWarnings public class Scene extends Widget { - private double zoomFactor = 1.0; + private double zoomFactorX = 1.0; + private double zoomFactorY = 1.0; private SceneAnimator sceneAnimator; - private JComponent component = null; private Graphics2D graphics = null; private boolean viewShowing = false; private boolean paintEverything = true; - private Rectangle repaintRegion = null; - private HashSet repaintWidgets = new HashSet (); - + private HashSet repaintWidgets = new HashSet(); private Font defaultFont; - private LookFeel lookFeel = LookFeel.createDefaultLookFeel (); - private InputBindings inputBindings = InputBindings.create (); + private LookFeel lookFeel = LookFeel.createDefaultLookFeel(); + private InputBindings inputBindings = InputBindings.create(); private String activeTool = null; - private Rectangle maximumBounds = new Rectangle (Integer.MIN_VALUE / 2, Integer.MIN_VALUE / 2, Integer.MAX_VALUE, Integer.MAX_VALUE); - - - private final ArrayList sceneListeners = new ArrayList (); // TODO - use CopyOnWriteArrayList - + private Rectangle maximumBounds = new Rectangle(Integer.MIN_VALUE / 2, Integer.MIN_VALUE / 2, Integer.MAX_VALUE, Integer.MAX_VALUE); + private final ArrayList sceneListeners = new ArrayList(); // TODO - use CopyOnWriteArrayList private EventProcessingType keyEventProcessingType = EventProcessingType.ALL_WIDGETS; - - private WidgetAction.Chain priorActions = new WidgetAction.Chain (); - + private WidgetAction.Chain priorActions = new WidgetAction.Chain(); private Widget focusedWidget = this; private WidgetAction widgetHoverAction; boolean extendSceneOnly = false; @@ -109,32 +102,35 @@ public class Scene extends Widget { /** * Creates a scene. */ - public Scene () { - super (null); - defaultFont = Font.decode (null); - resolveBounds (new Point (), new Rectangle ()); + public Scene() { + super(null); + defaultFont = Font.decode(null); + resolveBounds(new Point(), new Rectangle()); setOpaque(true); - setFont (defaultFont); - setBackground (lookFeel.getBackground ()); - setForeground (lookFeel.getForeground ()); - sceneAnimator = new SceneAnimator (this); + setFont(defaultFont); + setBackground(lookFeel.getBackground()); + setForeground(lookFeel.getForeground()); + sceneAnimator = new SceneAnimator(this); } /** * Creates a view. This method could be called once only. Call the getView method for getting created instance of a view. * @return the created view */ - public JComponent createView () { + public JComponent createView() { assert component == null; - component = new SceneComponent (this); - component.addAncestorListener (new AncestorListener() { - public void ancestorAdded (AncestorEvent event) { - repaintSatellite (); + component = new SceneComponent(this); + component.addAncestorListener(new AncestorListener() { + + public void ancestorAdded(AncestorEvent event) { + repaintSatellite(); } - public void ancestorRemoved (AncestorEvent event) { - repaintSatellite (); + + public void ancestorRemoved(AncestorEvent event) { + repaintSatellite(); } - public void ancestorMoved (AncestorEvent event) { + + public void ancestorMoved(AncestorEvent event) { } }); return component; @@ -144,16 +140,16 @@ public class Scene extends Widget { * Returns an instance of created view * @return the instance of created view; null if no view is created yet */ - public JComponent getView () { + public JComponent getView() { return component; } - /** + /** * Creates a satellite view. * @return the satellite view */ - public JComponent createSatelliteView () { - return new SatelliteComponent (this); + public JComponent createSatelliteView() { + return new SatelliteComponent(this); } /** @@ -161,62 +157,69 @@ public class Scene extends Widget { * @return the bird view controller * @since 2.7 */ - public BirdViewController createBirdView () { - return new BirdViewController (this); + public BirdViewController createBirdView() { + return new BirdViewController(this); } - void setViewShowing (boolean viewShowing) { + void setViewShowing(boolean viewShowing) { assert this.viewShowing != viewShowing : "Duplicate setViewShowing: " + viewShowing; this.viewShowing = viewShowing; - if (viewShowing) - dispatchNotifyAddedCore (); - else - dispatchNotifyRemovedCore (); + if (viewShowing) { + dispatchNotifyAddedCore(); + } else { + dispatchNotifyRemovedCore(); + } } - void dispatchNotifyAdded (Widget widget) { - assert widget != null; - Widget w = widget; - for (; ;) { - if (w == this) - break; - w = w.getParentWidget (); - if (w == null) - return; - } - if (! viewShowing) - return; - widget.dispatchNotifyAddedCore (); - } - - void dispatchNotifyRemoved (Widget widget) { + void dispatchNotifyAdded(Widget widget) { assert widget != null; Widget w = widget; for (;;) { if (w == this) { - if (viewShowing) - return; break; } - w = w.getParentWidget (); - if (w == null) + w = w.getParentWidget(); + if (w == null) { + return; + } + } + if (!viewShowing) { + return; + } + widget.dispatchNotifyAddedCore(); + } + + void dispatchNotifyRemoved(Widget widget) { + assert widget != null; + Widget w = widget; + for (;;) { + if (w == this) { + if (viewShowing) { + return; + } break; + } + w = w.getParentWidget(); + if (w == null) { + break; + } } - if (! viewShowing) + if (!viewShowing) { return; - widget.dispatchNotifyRemovedCore (); + } + widget.dispatchNotifyRemovedCore(); } /** * Returns an instance of Graphics2D which is used for calculating boundaries and rendering all widgets in the scene. * @return the instance of Graphics2D */ - public final Graphics2D getGraphics () { + public final Graphics2D getGraphics() { return graphics; } // HACK - used by SceneComponent and ConvolutionWidget - final void setGraphics (Graphics2D graphics) { + final void setGraphics(Graphics2D graphics) { this.graphics = graphics; } @@ -229,47 +232,48 @@ public class Scene extends Widget { * @param graphics the graphics instance used for validation * @since 2.7 */ - public final void validate (Graphics2D graphics) { - Graphics2D prevoiusGraphics = getGraphics (); - setGraphics (graphics); - validate (); - setGraphics (prevoiusGraphics); -} + public final void validate(Graphics2D graphics) { + Graphics2D prevoiusGraphics = getGraphics(); + setGraphics(graphics); + validate(); + setGraphics(prevoiusGraphics); + } + /** * Paints the whole scene into the graphics instance. The method calls validate before rendering. * @param graphics the Graphics2D instance where the scene is going to be painted */ - public final void paint (Graphics2D graphics) { - validate (); - Graphics2D prevoiusGraphics = getGraphics (); - setGraphics (graphics); - paint (); - setGraphics (prevoiusGraphics); + public final void paint(Graphics2D graphics) { + validate(); + Graphics2D prevoiusGraphics = getGraphics(); + setGraphics(graphics); + paint(); + setGraphics(prevoiusGraphics); } /** * Returns maximum bounds of the scene. * @return the maximum bounds */ - public final Rectangle getMaximumBounds () { - return new Rectangle (maximumBounds); + public final Rectangle getMaximumBounds() { + return new Rectangle(maximumBounds); } /** * Sets maximum bounds of the scene. * @param maximumBounds the non-null maximum bounds */ - public final void setMaximumBounds (Rectangle maximumBounds) { + public final void setMaximumBounds(Rectangle maximumBounds) { assert maximumBounds != null; - this.maximumBounds = new Rectangle (maximumBounds); - revalidate (); + this.maximumBounds = new Rectangle(maximumBounds); + revalidate(); } /** * Returns a default font of the scene. * @return the default font */ - public Font getDefaultFont () { + public Font getDefaultFont() { return defaultFont; } @@ -277,78 +281,81 @@ public class Scene extends Widget { * Returns whether the whole scene is validated and there is no widget or region that has to be revalidated. * @return true, if the whole scene is validated */ - public boolean isValidated () { - return super.isValidated () && repaintRegion == null && repaintWidgets.isEmpty (); + public boolean isValidated() { + return super.isValidated() && repaintRegion == null && repaintWidgets.isEmpty(); } /** * Returns whether the layer widget requires to repainted after revalidation. * @return always false */ - protected boolean isRepaintRequiredForRevalidating () { + protected boolean isRepaintRequiredForRevalidating() { return false; } // TODO - maybe it could improve the perfomance, if bounds != null then do nothing // WARNING - you have to asure that there will be no component/widget that will change its location/bounds between this and validate method calls - final void revalidateWidget (Widget widget) { - Rectangle widgetBounds = widget.getBounds (); + final void revalidateWidget(Widget widget) { + Rectangle widgetBounds = widget.getBounds(); if (widgetBounds != null) { - Rectangle sceneBounds = widget.convertLocalToScene (widgetBounds); - if (repaintRegion == null) + Rectangle sceneBounds = widget.convertLocalToScene(widgetBounds); + if (repaintRegion == null) { repaintRegion = sceneBounds; - else - repaintRegion.add (sceneBounds); + } else { + repaintRegion.add(sceneBounds); + } } - repaintWidgets.add (widget); + repaintWidgets.add(widget); } // TODO - requires optimalization while changing preferred size and calling revalidate/repaint - private void layoutScene () { - Point preLocation = getLocation (); - Rectangle preBounds = getBounds (); + private void layoutScene() { + Point preLocation = getLocation(); + Rectangle preBounds = getBounds(); - layout (false); - resolveBounds (null, null); - justify (); + layout(false); + resolveBounds(null, null); + justify(); Rectangle rect = null; - for (Widget widget : getChildren ()) { - Point location = widget.getLocation (); - Rectangle bounds = widget.getBounds (); - bounds.translate (location.x, location.y); - if (rect == null) + for (Widget widget : getChildren()) { + Point location = widget.getLocation(); + Rectangle bounds = widget.getBounds(); + bounds.translate(location.x, location.y); + if (rect == null) { rect = bounds; - else - rect.add (bounds); + } else { + rect.add(bounds); + } } if (rect != null) { - Insets insets = getBorder ().getInsets (); + Insets insets = getBorder().getInsets(); rect.x -= insets.left; rect.y -= insets.top; rect.width += insets.left + insets.right; rect.height += insets.top + insets.bottom; - rect = rect.intersection (maximumBounds); + rect = rect.intersection(maximumBounds); } - if (extendSceneOnly && rect != null && preBounds != null) - rect.add (new Rectangle (preBounds.x + preLocation.x, preBounds.y + preLocation.y, preBounds.width, preBounds.height)); - resolveBounds (rect != null ? new Point (- rect.x, - rect.y) : new Point (), rect); + if (extendSceneOnly && rect != null && preBounds != null) { + rect.add(new Rectangle(preBounds.x + preLocation.x, preBounds.y + preLocation.y, preBounds.width, preBounds.height)); + } + resolveBounds(rect != null ? new Point(-rect.x, -rect.y) : new Point(), rect); - Dimension preferredSize = rect != null ? rect.getSize () : new Dimension (); - preferredSize = new Dimension ((int) (preferredSize.width * zoomFactor), (int) (preferredSize.height * zoomFactor)); - Rectangle bounds = getBounds (); + Dimension preferredSize = rect != null ? rect.getSize() : new Dimension(); + preferredSize = new Dimension((int) (preferredSize.width * zoomFactorX), (int) (preferredSize.height * zoomFactorY)); + Rectangle bounds = getBounds(); if (component != null) { - if (! preferredSize.equals (component.getPreferredSize ())) { - component.setPreferredSize (preferredSize); - component.revalidate (); - bounds = getBounds (); + if (!preferredSize.equals(component.getPreferredSize())) { + component.setPreferredSize(preferredSize); + component.revalidate(); + bounds = getBounds(); // repaintSatellite (); } - Dimension componentSize = component.getSize (); - componentSize.width = (int) (componentSize.width / zoomFactor); - componentSize.height = (int) (componentSize.height / zoomFactor); + Dimension componentSize = component.getSize(); + componentSize.width = (int) (componentSize.width / zoomFactorX); + componentSize.height = (int) (componentSize.height / zoomFactorY); boolean sceneResized = false; if (bounds.width < componentSize.width) { @@ -359,15 +366,17 @@ public class Scene extends Widget { bounds.height = componentSize.height; sceneResized = true; } - if (sceneResized) - resolveBounds (getLocation (), bounds); + if (sceneResized) { + resolveBounds(getLocation(), bounds); + } } - if (! getLocation ().equals (preLocation) || ! getBounds ().equals (preBounds)) { - Rectangle rectangle = convertLocalToScene (getBounds ()); - if (repaintRegion == null) + if (!getLocation().equals(preLocation) || !getBounds().equals(preBounds)) { + Rectangle rectangle = convertLocalToScene(getBounds()); + if (repaintRegion == null) { repaintRegion = rectangle; - else - repaintRegion.add (rectangle); + } else { + repaintRegion.add(rectangle); + } } } @@ -376,47 +385,53 @@ public class Scene extends Widget { * in the scene after validating process. It also schedules invalid regions in the view for repainting. */ @SuppressWarnings("unchecked") - public final void validate () { - if (graphics == null) + public final void validate() { + if (graphics == null) { return; + } - while (! isValidated ()) { + while (!isValidated()) { SceneListener[] ls; synchronized (sceneListeners) { - ls = sceneListeners.toArray (new SceneListener[sceneListeners.size ()]); + ls = sceneListeners.toArray(new SceneListener[sceneListeners.size()]); } - for (SceneListener listener : ls) - listener.sceneValidating (); + for (SceneListener listener : ls) { + listener.sceneValidating(); + } - layoutScene (); + layoutScene(); for (Widget widget : repaintWidgets) { - Rectangle repaintBounds = widget.getBounds (); - if (repaintBounds == null) + Rectangle repaintBounds = widget.getBounds(); + if (repaintBounds == null) { continue; - repaintBounds = widget.convertLocalToScene (repaintBounds); - if (repaintRegion != null) - repaintRegion.add (repaintBounds); - else + } + repaintBounds = widget.convertLocalToScene(repaintBounds); + if (repaintRegion != null) { + repaintRegion.add(repaintBounds); + } else { repaintRegion = repaintBounds; + } } - repaintWidgets.clear (); - // System.out.println ("r = " + r); + repaintWidgets.clear(); + // System.out.println ("r = " + r); // NOTE - maybe improves performance when component.repaint will be called for all widgets/rectangles separately if (repaintRegion != null) { - Rectangle r = convertSceneToView (repaintRegion); - r.grow (1, 1); - if (component != null) - component.repaint (r); - repaintSatellite (); + Rectangle r = convertSceneToView(repaintRegion); + r.grow(1, 1); + if (component != null) { + component.repaint(r); + } + repaintSatellite(); repaintRegion = null; } - // System.out.println ("time: " + System.currentTimeMillis ()); + // System.out.println ("time: " + System.currentTimeMillis ()); - for (SceneListener listener : ls) - listener.sceneValidated (); + for (SceneListener listener : ls) { + listener.sceneValidated(); + } } } @@ -424,25 +439,26 @@ public class Scene extends Widget { * This methods makes the scene to be extended only - no shrunk. * @param extendSceneOnly if true, the scene is going to be extended only */ - void setExtendSceneOnly (boolean extendSceneOnly) { + void setExtendSceneOnly(boolean extendSceneOnly) { this.extendSceneOnly = extendSceneOnly; } - private void repaintSatellite () { + private void repaintSatellite() { SceneListener[] ls; synchronized (sceneListeners) { - ls = sceneListeners.toArray (new SceneListener[sceneListeners.size ()]); + ls = sceneListeners.toArray(new SceneListener[sceneListeners.size()]); } - for (SceneListener listener : ls) - listener.sceneRepaint (); + for (SceneListener listener : ls) { + listener.sceneRepaint(); + } } - final boolean isPaintEverything () { + final boolean isPaintEverything() { return paintEverything; } - final void setPaintEverything (boolean paintEverything) { + final void setPaintEverything(boolean paintEverything) { this.paintEverything = paintEverything; } @@ -450,7 +466,7 @@ public class Scene extends Widget { * Returns a key events processing type of the scene. * @return the processing type for key events */ - public final EventProcessingType getKeyEventProcessingType () { + public final EventProcessingType getKeyEventProcessingType() { return keyEventProcessingType; } @@ -458,7 +474,7 @@ public class Scene extends Widget { * Sets a key events processing type of the scene. * @param keyEventProcessingType the processing type for key events */ - public final void setKeyEventProcessingType (EventProcessingType keyEventProcessingType) { + public final void setKeyEventProcessingType(EventProcessingType keyEventProcessingType) { assert keyEventProcessingType != null; this.keyEventProcessingType = keyEventProcessingType; } @@ -468,7 +484,7 @@ public class Scene extends Widget { * If any of these actions consumes an event that the event processsing is stopped. Action locking is ignored. * @return the prior actions */ - public final WidgetAction.Chain getPriorActions () { + public final WidgetAction.Chain getPriorActions() { return priorActions; } @@ -476,7 +492,7 @@ public class Scene extends Widget { * Returns a focused widget of the scene. * @return the focused widget; null if no widget is focused */ - public final Widget getFocusedWidget () { + public final Widget getFocusedWidget() { return focusedWidget; } @@ -484,38 +500,79 @@ public class Scene extends Widget { * Sets a focused widget of the scene. * @param focusedWidget the focused widget; if null, then the scene itself is taken as the focused widget */ - public final void setFocusedWidget (Widget focusedWidget) { - if (focusedWidget == null) + public final void setFocusedWidget(Widget focusedWidget) { + if (focusedWidget == null) { focusedWidget = this; - else - assert focusedWidget.getScene () == this; - this.focusedWidget.setState (this.focusedWidget.getState ().deriveWidgetFocused (false)); + } else { + assert focusedWidget.getScene() == this; + } + this.focusedWidget.setState(this.focusedWidget.getState().deriveWidgetFocused(false)); this.focusedWidget = focusedWidget; - this.focusedWidget.setState (this.focusedWidget.getState ().deriveWidgetFocused (true)); + this.focusedWidget.setState(this.focusedWidget.getState().deriveWidgetFocused(true)); } /** + * @deprecated As of release 6.1, replaced by {@link #getZoomFactorX()}, {@link #getZoomFactorY()} * Returns a zoom factor. * @return the zoom factor */ - public final double getZoomFactor () { - return zoomFactor; + @Deprecated + public final double getZoomFactor() { + if (zoomFactorX != zoomFactorY) { + // @todo: What do we do in this case? + } + return zoomFactorX; + } + + /** + * Returns a zoom factor for X axis. + * @return the zoom factor X + */ + public final double getZoomFactorX() { + return zoomFactorX; + } + + /** + * Returns a zoom factor for Y axis. + * @return the zoom factor Y + */ + public final double getZoomFactorY() { + return zoomFactorY; } /** * Sets a zoom factor for the scene. * @param zoomFactor the zoom factor */ - public final void setZoomFactor (double zoomFactor) { - this.zoomFactor = zoomFactor; - revalidate (); + public final void setZoomFactor(double zoomFactor) { + this.zoomFactorX = zoomFactor; + this.zoomFactorY = zoomFactor; + revalidate(); + } + + /** + * Sets a zoom factor for the X axis of the scene. + * @param zoomFactor the zoom factor + */ + public final void setZoomFactorX(double zoomFactorX) { + this.zoomFactorX = zoomFactorX; + revalidate(); + } + + /** + * Sets a zoom factor for the X axis of the scene. + * @param zoomFactor the zoom factor + */ + public final void setZoomFactorY(double zoomFactorY) { + this.zoomFactorY = zoomFactorY; + revalidate(); } /** * Returns a scene animator of the scene. * @return the scene animator */ - public final SceneAnimator getSceneAnimator () { + public final SceneAnimator getSceneAnimator() { return sceneAnimator; } @@ -523,7 +580,7 @@ public class Scene extends Widget { * Returns a look'n'feel of the scene. * @return the look'n'feel */ - public final LookFeel getLookFeel () { + public final LookFeel getLookFeel() { return lookFeel; } @@ -532,7 +589,7 @@ public class Scene extends Widget { * will not be refreshed. * @param lookFeel the look'n'feel */ - public final void setLookFeel (LookFeel lookFeel) { + public final void setLookFeel(LookFeel lookFeel) { assert lookFeel != null; this.lookFeel = lookFeel; } @@ -542,7 +599,7 @@ public class Scene extends Widget { * @return the input bindings * @since 2.4 */ - public final InputBindings getInputBindings () { + public final InputBindings getInputBindings() { return inputBindings; } @@ -550,7 +607,7 @@ public class Scene extends Widget { * Returns an active tool of the scene. * @return the active tool; if null, then only default action chain of widgets will be used */ - public final String getActiveTool () { + public final String getActiveTool() { return activeTool; } @@ -558,7 +615,7 @@ public class Scene extends Widget { * Sets an active tool. * @param activeTool the active tool; if null, then the active tool is unset and only default action chain of widgets will be used */ - public void setActiveTool (String activeTool) { + public void setActiveTool(String activeTool) { this.activeTool = activeTool; } @@ -566,10 +623,10 @@ public class Scene extends Widget { * Registers a scene listener. * @param listener the scene listener */ - public final void addSceneListener (SceneListener listener) { + public final void addSceneListener(SceneListener listener) { assert listener != null; synchronized (sceneListeners) { - sceneListeners.add (listener); + sceneListeners.add(listener); } } @@ -577,9 +634,9 @@ public class Scene extends Widget { * Unregisters a scene listener. * @param listener the scene listener */ - public final void removeSceneListener (SceneListener listener) { + public final void removeSceneListener(SceneListener listener) { synchronized (sceneListeners) { - sceneListeners.remove (listener); + sceneListeners.remove(listener); } } @@ -588,9 +645,9 @@ public class Scene extends Widget { * @param sceneLocation the scene location * @return the view location */ - public final Point convertSceneToView (Point sceneLocation) { - Point location = getLocation (); - return new Point ((int) (zoomFactor * (location.x + sceneLocation.x)), (int) (zoomFactor * (location.y + sceneLocation.y))); + public final Point convertSceneToView(Point sceneLocation) { + Point location = getLocation(); + return new Point((int) (zoomFactorX * (location.x + sceneLocation.x)), (int) (zoomFactorY * (location.y + sceneLocation.y))); } /** @@ -598,13 +655,13 @@ public class Scene extends Widget { * @param sceneRectangle the scene rectangle * @return the view rectangle */ - public final Rectangle convertSceneToView (Rectangle sceneRectangle) { - Point location = getLocation (); - return GeomUtil.roundRectangle (new Rectangle2D.Double ( - (double) (sceneRectangle.x + location.x) * zoomFactor, - (double) (sceneRectangle.y + location.y) * zoomFactor, - (double) sceneRectangle.width * zoomFactor, - (double) sceneRectangle.height * zoomFactor)); + public final Rectangle convertSceneToView(Rectangle sceneRectangle) { + Point location = getLocation(); + return GeomUtil.roundRectangle(new Rectangle2D.Double( + (double) (sceneRectangle.x + location.x) * zoomFactorX, + (double) (sceneRectangle.y + location.y) * zoomFactorY, + (double) sceneRectangle.width * zoomFactorX, + (double) sceneRectangle.height * zoomFactorY)); } /** @@ -612,32 +669,31 @@ public class Scene extends Widget { * @param viewLocation the view location * @return the scene location */ - public Point convertViewToScene (Point viewLocation) { - return new Point ((int) ((double) viewLocation.x / zoomFactor) - getLocation ().x, (int) ((double) viewLocation.y / zoomFactor) - getLocation ().y); + public Point convertViewToScene(Point viewLocation) { + return new Point((int) ((double) viewLocation.x / zoomFactorX) - getLocation().x, (int) ((double) viewLocation.y / zoomFactorY) - getLocation().y); } /** * Creates a widget-specific hover action. * @return the widget-specific hover action */ - public WidgetAction createWidgetHoverAction () { + public WidgetAction createWidgetHoverAction() { if (widgetHoverAction == null) { - widgetHoverAction = ActionFactory.createHoverAction (new WidgetHoverAction ()); - getActions ().addAction (widgetHoverAction); + widgetHoverAction = ActionFactory.createHoverAction(new WidgetHoverAction()); + getActions().addAction(widgetHoverAction); } return widgetHoverAction; } private class WidgetHoverAction implements TwoStateHoverProvider { - public void unsetHovering (Widget widget) { - widget.setState (widget.getState ().deriveWidgetHovered (false)); + public void unsetHovering(Widget widget) { + widget.setState(widget.getState().deriveWidgetHovered(false)); } - public void setHovering (Widget widget) { - widget.setState (widget.getState ().deriveWidgetHovered (true)); + public void setHovering(Widget widget) { + widget.setState(widget.getState().deriveWidgetHovered(true)); } - } /** @@ -648,18 +704,16 @@ public class Scene extends Widget { /** * Called to notify that the whole scene was repainted. */ - void sceneRepaint (); + void sceneRepaint(); /** * Called to notify that the scene is going to be validated. */ - void sceneValidating (); + void sceneValidating(); /** * Called to notify that the scene has been validated. */ - void sceneValidated (); - + void sceneValidated(); } - } diff --git a/api.visual/src/org/netbeans/api/visual/widget/SceneComponent.java b/api.visual/src/org/netbeans/api/visual/widget/SceneComponent.java --- a/api.visual/src/org/netbeans/api/visual/widget/SceneComponent.java +++ b/api.visual/src/org/netbeans/api/visual/widget/SceneComponent.java @@ -102,8 +102,9 @@ final class SceneComponent extends JComp super.setBounds (x, y, width, height); Rectangle bounds = scene.getBounds (); - double zoomFactor = scene.getZoomFactor(); - if (bounds != null && width == (int) (bounds.width * zoomFactor) && height == (int) (bounds.height * zoomFactor)) + double zoomFactorX = scene.getZoomFactorX(); + double zoomFactorY = scene.getZoomFactorY(); + if (bounds != null && width == (int) (bounds.width * zoomFactorX) && height == (int) (bounds.height * zoomFactorY)) return; scene.revalidate (); @@ -123,8 +124,9 @@ final class SceneComponent extends JComp scene.setGraphics (gr); AffineTransform previousTransform = gr.getTransform (); - double zoomFactor = scene.getZoomFactor (); - gr.scale (zoomFactor, zoomFactor); + double zoomFactorX = scene.getZoomFactorX (); + double zoomFactorY = scene.getZoomFactorY (); + gr.scale (zoomFactorX, zoomFactorY); scene.setPaintEverything (false); scene.paint (); scene.setPaintEverything (true); @@ -286,8 +288,8 @@ final class SceneComponent extends JComp if (lockedAction != null) { Point sceneLocation = scene.getLocation (); Rectangle visibleRect = getVisibleRect (); - int xadd = (int) ((sceneLocation.x - oldSceneLocation.x) * scene.getZoomFactor ()); - int yadd = (int) ((sceneLocation.y - oldSceneLocation.y) * scene.getZoomFactor ()); + int xadd = (int) ((sceneLocation.x - oldSceneLocation.x) * scene.getZoomFactorX ()); + int yadd = (int) ((sceneLocation.y - oldSceneLocation.y) * scene.getZoomFactorY ()); if (xadd != 0 || yadd != 0) scrollRectToVisible (new Rectangle (oldVisibleRect.x + xadd, oldVisibleRect.y + yadd, visibleRect.width, visibleRect.height)); scrollRectToVisible (new Rectangle (scene.convertSceneToView (oldScenePoint))); diff --git a/api.visual/src/org/netbeans/modules/visual/widget/SatelliteComponent.java b/api.visual/src/org/netbeans/modules/visual/widget/SatelliteComponent.java --- a/api.visual/src/org/netbeans/modules/visual/widget/SatelliteComponent.java +++ b/api.visual/src/org/netbeans/modules/visual/widget/SatelliteComponent.java @@ -101,14 +101,15 @@ public final class SatelliteComponent ex gr.setTransform (previousTransform); JComponent component = scene.getView (); - double zoomFactor = scene.getZoomFactor (); + double zoomFactorX = scene.getZoomFactorX (); + double zoomFactorY = scene.getZoomFactorY (); Rectangle viewRectangle = component != null ? component.getVisibleRect () : null; if (viewRectangle != null) { Rectangle window = new Rectangle ( - (int) ((double) viewRectangle.x * scale / zoomFactor), - (int) ((double) viewRectangle.y * scale / zoomFactor), - (int) ((double) viewRectangle.width * scale / zoomFactor), - (int) ((double) viewRectangle.height * scale / zoomFactor) + (int) ((double) viewRectangle.x * scale / zoomFactorX), + (int) ((double) viewRectangle.y * scale / zoomFactorY), + (int) ((double) viewRectangle.width * scale / zoomFactorX), + (int) ((double) viewRectangle.height * scale / zoomFactorY) ); window.translate (vx, vy); // Area area = new Area (new Rectangle (vx, vy, vw, vh)); @@ -148,7 +149,8 @@ public final class SatelliteComponent ex JComponent component = scene.getView (); if (component == null) return; - double zoomFactor = scene.getZoomFactor (); + double zoomFactorX = scene.getZoomFactorX (); + double zoomFactorY = scene.getZoomFactorY (); Rectangle bounds = scene.getBounds (); Dimension size = getSize (); @@ -161,8 +163,8 @@ public final class SatelliteComponent ex int vx = (size.width - vw) / 2; int vy = (size.height - vh) / 2; - int cx = (int) ((double) (center.x - vx) / scale * zoomFactor); - int cy = (int) ((double) (center.y - vy) / scale * zoomFactor); + int cx = (int) ((double) (center.x - vx) / scale * zoomFactorX); + int cy = (int) ((double) (center.y - vy) / scale * zoomFactorY); Rectangle visibleRect = component.getVisibleRect (); visibleRect.x = cx - visibleRect.width / 2;