--- api.visual/apichanges.xml +++ api.visual/apichanges.xml @@ -757,6 +757,21 @@ + + + Support for rotating widgets + + + + + + Added support for rotating widgets. Patch provided by user + bcallebaut. + + + + + --- api.visual/manifest.mf +++ api.visual/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.visual OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 2.33 +OpenIDE-Module-Specification-Version: 2.34 AutoUpdate-Essential-Module: true --- api.visual/nbproject/project.xml +++ api.visual/nbproject/project.xml @@ -59,6 +59,15 @@ + org.netbeans.spi.palette + + + + 1 + 1.33 + + + org.openide.util --- api.visual/src/org/netbeans/api/visual/action/WidgetAction.java +++ api.visual/src/org/netbeans/api/visual/action/WidgetAction.java @@ -1087,6 +1087,64 @@ } /** + * @since 2.34 + * @author bcallebaut + */ + public static final class ChainProvider{ + + private String name = ""; + + /** + * Get the value of name + * + * @return the value of name + */ + public String getName() { + return name; + } + + /** + * Set the value of name + * + * @param name new value of name + */ + public void setName(String name) { + this.name = name; + } + + private Chain chain; + + /** + * Get the value of chain + * + * @return the value of chain + */ + public Chain getChain() { + return chain; + } + + /** + * Set the value of chain + * + * @param chain new value of chain + */ + public void setChain(Chain chain) { + this.chain = chain; + } + + public ChainProvider() { + } + + public ChainProvider(Chain chain) { + this.chain = chain; + } + + public ChainProvider(String name,Chain chain) { + this.name = name; + this.chain = chain; + } + } + /** * Represents an widget event. */ public static interface WidgetEvent { --- api.visual/src/org/netbeans/api/visual/widget/Widget.java +++ api.visual/src/org/netbeans/api/visual/widget/Widget.java @@ -89,11 +89,14 @@ * and actions. Yherefore you can define your own look and feel directly in the that method. * * Since version 2.6 Widget class implements Accessible interface. + * Since version 2.34 Widget class implements Lookup.Provider interface and + * tries to initialize itself using the lookup passed in the constructor. * * @author David Kaspar + * @author Benoit Callebaut */ // TODO - Should Widget be an abstract class? -public class Widget implements Accessible { +public class Widget implements Accessible, Lookup.Provider { static final String MESSAGE_NULL_BOUNDS = "Scene.validate was not called after last change. Widget is not validated. See first Q/A at http://graph.netbeans.org/faq.html page."; @@ -145,6 +148,7 @@ private Point location; private Rectangle bounds; + private Shape shape; private Rectangle calculatedPreferredBounds; private boolean requiresFullValidation; @@ -158,26 +162,44 @@ * a property is set by using using resources. */ private ResourceTable resourceTable = null; + protected final Lookup lookup; + private AffineTransform transform = new AffineTransform(); /** * Creates a new widget which will be used in a specified scene. * @param scene the scene where the widget is going to be used + * @since 2.34 */ - public Widget (Scene scene) { - if (scene == null) + public Widget (Scene scene, Lookup lookup) { + if (scene == null) { scene = (Scene) this; + } this.scene = scene; + this.lookup = lookup; children = new ArrayList (); childrenUm = Collections.unmodifiableList (children); actionsChain = new WidgetAction.Chain (); + toolsActions = new HashMap(); + toolsActions.put(null, actionsChain); + + for (WidgetAction.ChainProvider provider : lookup.lookupAll(WidgetAction.ChainProvider.class)) { + toolsActions.put(provider.getName(), provider.getChain()); + } opaque = false; font = null; background = Color.WHITE; foreground = Color.BLACK; + + border = lookup.lookup(Border.class); + if (border == null) { border = BorderFactory.createEmptyBorder (); + } + layout = lookup.lookup(Layout.class); + if (layout == null) { layout = LayoutFactory.createAbsoluteLayout (); + } preferredLocation = null; preferredBounds = null; checkClipping = false; @@ -191,6 +213,23 @@ } /** + * Creates a new widget which will be used in a specified scene. + * + * @param scene the scene where the widget is going to be used + */ + public Widget(Scene scene) { + this(scene, Lookup.EMPTY); + } + + /** + * @since 2.34 + */ + public Shape getShape() { + shape = getTransform().createTransformedShape (getBounds()); + return shape; + } + + /** * Returns a scene where the widget is assigned * @return the scene */ @@ -493,8 +532,9 @@ * Returns a lookup of the widget. * @return the lookup */ - public Lookup getLookup () { - return Lookup.EMPTY; + @Override + public Lookup getLookup() { + return lookup; } /** @@ -840,6 +880,22 @@ } /** + * @since 2.34 + * @return Widget transform + */ + public AffineTransform getTransform() { + return transform; + } + + /** + * @since 2.34 + */ + public void setTransform(AffineTransform transform) { + this.transform = transform; + this.revalidate(); + } + + /** * Returns the border of the widget. * @return the border */ @@ -1276,7 +1332,7 @@ * @return true, if the location belong to the widget */ public boolean isHitAt (Point localLocation) { - return visible && getBounds ().contains (localLocation); + return visible && getShape().contains (localLocation); } /** @@ -1399,10 +1455,11 @@ return; assert bounds != null : MESSAGE_NULL_BOUNDS; // NOI18N - Graphics2D gr = scene.getGraphics (); + Graphics2D gr = getGraphics (); AffineTransform previousTransform = gr.getTransform(); gr.translate (location.x, location.y); + gr.transform (transform); Shape tempClip = null; if (checkClipping) { --- api.visual/src/org/netbeans/modules/visual/graph/layout/HierarchicalLayout.java +++ api.visual/src/org/netbeans/modules/visual/graph/layout/HierarchicalLayout.java @@ -659,7 +659,7 @@ protected void run() { - layers = new List[layerCount]; + layers = (List.LayoutNode>[])new List[layerCount]; for (int i = 0; i < layerCount; i++) { layers[i] = new ArrayList();