Search Results

Search found 8 results on 1 pages for 'actionfactory'.

Page 1/1 | 1 

  • Savable in Widget Lookup on Move Action

    - by Geertjan
    Possible from 7.3 onwards, since Widget now implements Lookup.Provider for the first time: import java.awt.Point; import java.io.IOException; import org.netbeans.api.visual.action.ActionFactory; import org.netbeans.api.visual.action.MoveProvider; import org.netbeans.api.visual.widget.LabelWidget; import org.netbeans.api.visual.widget.Scene; import org.netbeans.api.visual.widget.Widget; import org.netbeans.spi.actions.AbstractSavable; import org.openide.util.Lookup; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; import org.openide.windows.TopComponent; public class MyWidget extends LabelWidget { private MySavable mySavable; private Lookup lookup; private TopComponent tc; private InstanceContent ic; public MyWidget(Scene scene, String label, TopComponent tc) { super(scene, label); this.tc = tc; ic = new InstanceContent(); getActions().addAction(ActionFactory.createMoveAction(null, new MoveStrategyProvider())); } @Override public Lookup getLookup() { if (lookup == null) { lookup = new AbstractLookup(ic); } return lookup; } private class MoveStrategyProvider implements MoveProvider { @Override public void movementStarted(Widget widget) { } @Override public void movementFinished(Widget widget) { modify(); } @Override public Point getOriginalLocation(Widget widget) { return ActionFactory.createDefaultMoveProvider().getOriginalLocation(widget); } @Override public void setNewLocation(Widget widget, Point point) { ActionFactory.createDefaultMoveProvider().setNewLocation(widget, point); } } private void modify() { if (getLookup().lookup(MySavable.class) == null) { ic.add(mySavable = new MySavable()); } } private class MySavable extends AbstractSavable { public MySavable() { register(); } TopComponent tc() { return tc; } @Override protected String findDisplayName() { return getLabel(); } @Override protected void handleSave() throws IOException { ic.remove(mySavable); unregister(); } @Override public boolean equals(Object obj) { if (obj instanceof MySavable) { MySavable m = (MySavable) obj; return tc() == m.tc(); } return false; } @Override public int hashCode() { return tc().hashCode(); } } }

    Read the article

  • How to Draw Lines on the Screen

    - by Geertjan
    I've seen occasional questions on mailing lists about how to use the NetBeans Visual Library to draw lines, e.g., to make graphs or diagrams of various kinds by drawing on the screen. So, rather than drag/drop causing widgets to be added, you'd want widgets to be added on mouse clicks, and you'd want to be able to connect those widgets together somehow. Via the code below, you'll be able to click on the screen, which causes a dot to appear. When you have multiple dots, you can hold down the Ctrl key and connect them together. A guiding line appears to help you position the dots exactly in line with each other. When you go to File | Print, you'll be able to preview and print the diagram you've created. A picture that speaks 1000 words: Here's the code: public final class PlotterTopComponent extends TopComponent { private final Scene scene; private final LayerWidget baseLayer; private final LayerWidget connectionLayer; private final LayerWidget interactionLayer; public PlotterTopComponent() { initComponents(); setName(Bundle.CTL_PlotterTopComponent()); setToolTipText(Bundle.HINT_PlotterTopComponent()); setLayout(new BorderLayout()); this.scene = new Scene(); this.baseLayer = new LayerWidget(scene); this.interactionLayer = new LayerWidget(scene); this.connectionLayer = new LayerWidget(scene); scene.getActions().addAction(new SceneCreateAction()); scene.addChild(baseLayer); scene.addChild(interactionLayer); scene.addChild(connectionLayer); add(scene.createView(), BorderLayout.CENTER); putClientProperty("print.printable", true); } private class SceneCreateAction extends WidgetAction.Adapter { @Override public WidgetAction.State mousePressed(Widget widget, WidgetAction.WidgetMouseEvent event) { if (event.getClickCount() == 1) { if (event.getButton() == MouseEvent.BUTTON1 || event.getButton() == MouseEvent.BUTTON2) { baseLayer.addChild(new BlackDotWidget(scene, widget, event)); repaint(); return WidgetAction.State.CONSUMED; } } return WidgetAction.State.REJECTED; } } private class BlackDotWidget extends ImageWidget { public BlackDotWidget(Scene scene, Widget widget, WidgetAction.WidgetMouseEvent event) { super(scene); setImage(ImageUtilities.loadImage("org/netbeans/plotter/blackdot.gif")); setPreferredLocation(widget.convertLocalToScene(event.getPoint())); getActions().addAction( ActionFactory.createExtendedConnectAction( connectionLayer, new BlackDotConnectProvider())); getActions().addAction( ActionFactory.createAlignWithMoveAction( baseLayer, interactionLayer, ActionFactory.createDefaultAlignWithMoveDecorator())); } } private class BlackDotConnectProvider implements ConnectProvider { @Override public boolean isSourceWidget(Widget source) { return source instanceof BlackDotWidget && source != null ? true : false; } @Override public ConnectorState isTargetWidget(Widget src, Widget trg) { return src != trg && trg instanceof BlackDotWidget ? ConnectorState.ACCEPT : ConnectorState.REJECT; } @Override public boolean hasCustomTargetWidgetResolver(Scene arg0) { return false; } @Override public Widget resolveTargetWidget(Scene arg0, Point arg1) { return null; } @Override public void createConnection(Widget source, Widget target) { ConnectionWidget conn = new ConnectionWidget(scene); conn.setTargetAnchor(AnchorFactory.createCircularAnchor(target, 10)); conn.setSourceAnchor(AnchorFactory.createCircularAnchor(source, 10)); connectionLayer.addChild(conn); } } ... ... ... Note: The code above was written based on the Visual Library tutorials on the NetBeans Platform Learning Trail, in particular via the "ConnectScene" sample in the "test.connect" package, which is part of the very long list of Visual Library samples referred to in the Visual Library tutorials on the NetBeans Platform Learning Trail. The next steps are to add a reconnect action and an action to delete a dot by double-clicking on it. Would be interesting to change the connecting line so that the length of the line were to be shown, i.e., as you draw a line from one dot to another, you'd see a constantly changing number representing the current distance of the connecting line. Also, once lines are connected to form a rectangle, would be cool to be able to write something within that rectangle. Then one could really create diagrams, which would be pretty cool.

    Read the article

  • Any good, visual HTML5 Editor or IDE?

    - by ActionFactory
    Hi All, Well it looks like Dreamweaver CS5 will try to smoother the HTML5 thing for a few more years (weeks actually). Seems like the next rung down is right to Notepad! Anyone know a good HTML5 editor with a visual/preview/style leaning? Eclispe with some pluggin? (Seems like the market will be begging for it soon.) Thanks

    Read the article

  • How to Filter ADO.NET data using a Full Text Seach (FTS) field?

    - by ActionFactory
    Hi All, We are using ADO.NET dataservices & are building URL based filters. Example: /Customers?filter=City eq 'London' We now need to filter on a Full Text 'tags' Field. WAS HOPING FOR: /Customers?filter=Tag like 'Friendly' PROBLEM: ADO.NET does not have a LIKE operator. ADO.NET does not seem to like FTS (It is not finding a match - because it is not parsing through the CSV's) Any ideas how to make this work? THX

    Read the article

  • Passing HTML using JSON

    - by ActionFactory
    Hi All, I'm passing Data using JSON to iPhone and iPad. One Field of Data is HTML. The problem is the encoding. Here's what I get back: > "GadgetHTML": "<strong>Hello</strong> > from Catworld<br />\n<img alt=\"\" > src=\"http://www.iconarchive.com/icons/fasticon/ifunny/128/dog-icon.png\" > />", The \ are killing me. The \n does not help. Any good way to do this? Any JSON to HTML Cleaning Functions? Encoding? (There must be something better than manually removing ) Thanks

    Read the article

  • Rotating a NetBeans Visual Library Widget

    - by Geertjan
    Trying to create a widget which, when clicked, rotates slightly further on each subsequent click: Above, the bird where the mouse is visible has been clicked a few times and so has rotated a bit further on each click. The code isn't quite right yet and I'm hoping someone will take this code, try it out, and help with a nice solution! public class BirdScene extends Scene {     public BirdScene() {         addChild(new LayerWidget(this));         getActions().addAction(ActionFactory.createAcceptAction(new AcceptProvider() {             public ConnectorState isAcceptable(Widget widget, Point point, Transferable transferable) {                 Image dragImage = getImageFromTransferable(transferable);                 if (dragImage != null) {                     JComponent view = getView();                     Graphics2D g2 = (Graphics2D) view.getGraphics();                     Rectangle visRect = view.getVisibleRect();                     view.paintImmediately(visRect.x, visRect.y, visRect.width, visRect.height);                     g2.drawImage(dragImage,                             AffineTransform.getTranslateInstance(point.getLocation().getX(),                             point.getLocation().getY()),                             null);                     return ConnectorState.ACCEPT;                 } else {                     return ConnectorState.REJECT;                 }             }             public void accept(Widget widget, final Point point, Transferable transferable) {                 addChild(new BirdWidget(getScene(), getImageFromTransferable(transferable), point));             }         }));     }     private Image getImageFromTransferable(Transferable transferable) {         Object o = null;         try {             o = transferable.getTransferData(DataFlavor.imageFlavor);         } catch (IOException ex) {         } catch (UnsupportedFlavorException ex) {         }         return o instanceof Image ? (Image) o : null;     }     private class BirdWidget extends IconNodeWidget {         private int theta = 0;         public BirdWidget(Scene scene, Image imageFromTransferable, Point point) {             super(scene);             setImage(imageFromTransferable);             setPreferredLocation(point);             setCheckClipping(true);             getActions().addAction(ActionFactory.createMoveAction());             getActions().addAction(ActionFactory.createSelectAction(new SelectProvider() {                 public boolean isAimingAllowed(Widget widget, Point localLocation, boolean invertSelection) {                     return true;                 }                 public boolean isSelectionAllowed(Widget widget, Point localLocation, boolean invertSelection) {                     return true;                 }                 public void select(final Widget widget, Point localLocation, boolean invertSelection) {                     theta = (theta + 100) % 360;                     repaint();                     getScene().validate();                 }             }));         }         @Override         public void paintWidget() {             final Image image = getImageWidget().getImage();             Graphics2D g = getGraphics();             g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);             Rectangle bounds = getClientArea();             AffineTransform newXform = g.getTransform();             int xRot = image.getWidth(null) / 2;             int yRot = image.getWidth(null) / 2;             newXform.rotate(theta * Math.PI / 180, xRot, yRot);             g.setTransform(newXform);             g.drawImage(image, bounds.x, bounds.y, null);         }     } } The problem relates to refreshing the scene after the rotation. But it would help if someone would just take the code above, add it to their own application, try it out, see the problem for yourself, and develop it a bit further!

    Read the article

  • Add Widget via Action in Toolbar

    - by Geertjan
    The question of the day comes from Vadim, who asks on the NetBeans Platform mailing list: "Looking for example showing how to add Widget to Scene, e.g. by toolbar button click." Well, the solution is very similar to this blog entry, where you see a solution provided by Jesse Glick for VisiTrend in Boston: https://blogs.oracle.com/geertjan/entry/zoom_capability Other relevant articles to read are as follows: http://netbeans.dzone.com/news/which-netbeans-platform-action http://netbeans.dzone.com/how-to-make-context-sensitive-actions Let's go through it step by step, with this result in the end, a solution involving 4 classes split (optionally, since a central feature of the NetBeans Platform is modularity) across multiple modules: The Customer object has a "name" String and the Droppable capability has a method "doDrop" which takes a Customer object: public interface Droppable {    void doDrop(Customer c);} In the TopComponent, we use "TopComponent.associateLookup" to publish an instance of "Droppable", which creates a new LabelWidget and adds it to the Scene in the TopComponent. Here's the TopComponent constructor: public CustomerCanvasTopComponent() {    initComponents();    setName(Bundle.CTL_CustomerCanvasTopComponent());    setToolTipText(Bundle.HINT_CustomerCanvasTopComponent());    final Scene scene = new Scene();    final LayerWidget layerWidget = new LayerWidget(scene);    Droppable d = new Droppable(){        @Override        public void doDrop(Customer c) {            LabelWidget customerWidget = new LabelWidget(scene, c.getTitle());            customerWidget.getActions().addAction(ActionFactory.createMoveAction());            layerWidget.addChild(customerWidget);            scene.validate();        }    };    scene.addChild(layerWidget);    jScrollPane1.setViewportView(scene.createView());    associateLookup(Lookups.singleton(d));} The Action is displayed in the toolbar and is enabled only if a Droppable is currently in the Lookup: @ActionID(        category = "Tools",        id = "org.customer.controler.AddCustomerAction")@ActionRegistration(        iconBase = "org/customer/controler/icon.png",        displayName = "#AddCustomerAction")@ActionReferences({    @ActionReference(path = "Toolbars/File", position = 300)})@NbBundle.Messages("AddCustomerAction=Add Customer")public final class AddCustomerAction implements ActionListener {    private final Droppable context;    public AddCustomerAction(Droppable droppable) {        this.context = droppable;    }    @Override    public void actionPerformed(ActionEvent ev) {        NotifyDescriptor.InputLine inputLine = new NotifyDescriptor.InputLine("Name:", "Data Entry");        Object result = DialogDisplayer.getDefault().notify(inputLine);        if (result == NotifyDescriptor.OK_OPTION) {            Customer customer = new Customer(inputLine.getInputText());            context.doDrop(customer);        }    }} Therefore, when the Properties window, for example, is selected, the Action will be disabled. (See the Zoomable example referred to in the link above for another example of this.) As you can see above, when the Action is invoked, a Droppable must be available (otherwise the Action would not have been enabled). The Droppable is obtained in the Action and a new Customer object is passed to its "doDrop" method. The above in pictures, take note of the enablement of the toolbar button with the red dot, on the extreme left of the toolbar in the screenshots below: The above shows the JButton is only enabled if the relevant TopComponent is active and, when the Action is invoked, the user can enter a name, after which a new LabelWidget is created in the Scene. The source code of the above is here: http://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.3/misc/WidgetCreationFromAction Note: Showing this as an MVC example is slightly misleading because, depending on which model object ("Customer" and "Droppable") you're looking at, the V and the C are different. From the point of view of "Customer", the TopComponent is the View, while the Action is the Controler, since it determines when the M is displayed. However, from the point of view of "Droppable", the TopComponent is the Controler, since it determines when the Action, i.e., which is in this case the View, displays the presence of the M.

    Read the article

1