Java Code Examples for org.netbeans.api.visual.model.ObjectScene#addObject()

The following examples show how to use org.netbeans.api.visual.model.ObjectScene#addObject() . 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: TableWidget.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void notifyRemoved() {
    super.notifyRemoved();
    if(getScene() instanceof ObjectScene && userObject!=null) {
        ObjectScene scene =(ObjectScene) getScene();
        List<Widget> widgets = scene.findWidgets(userObject);
        if(widgets!=null && widgets.contains(this)) {
            if(widgets.size()==1) 
                scene.removeObject(userObject);
            else {
                widgets = new ArrayList<Widget>(widgets);
                widgets.remove(this);
                scene.removeObject(userObject);
                scene.addObject(userObject, widgets.toArray(new Widget[widgets.size()]));
            }
        }
    }
}
 
Example 2
Source File: TableWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void notifyAdded() {
    super.notifyAdded();
    if(getScene() instanceof ObjectScene && userObject!=null) {
        ObjectScene scene =(ObjectScene) getScene();
        List<Widget> widgets = scene.findWidgets(userObject);
        if(widgets==null|| widgets.isEmpty())
            scene.addObject(userObject, this);
        else {
            scene.removeObject(userObject);
            widgets = new ArrayList<Widget>(widgets);
            widgets.add(this);
            scene.addObject(userObject, widgets.toArray(new Widget[widgets.size()]));
        }
    }
}
 
Example 3
Source File: ButtonWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void notifyAdded() {
    super.notifyAdded();
    Scene scene = getScene();
    if(scene instanceof ObjectScene) {
        ObjectScene objectScene = (ObjectScene)scene;
        objectScene.addObject(hashKey(), this);
    }
}
 
Example 4
Source File: DesignView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance of GraphView.
 * @param service
 * @param implementationClass
 */
public DesignView(ProjectService service, FileObject implementationClass) {
    super(new BorderLayout());
    
    this.service = service;
    this.implementationClass = implementationClass;
    
    scene = new ObjectScene() {
        @Override
        /**
         * Use our own traversal policy
         */
        public Comparable<DesignerWidgetIdentityCode> getIdentityCode(Object object) {
            return new DesignerWidgetIdentityCode(scene,object);
        }
    };
    zoomer = new ZoomManager(scene);

    scene.getActions().addAction(ActionFactory.createCycleObjectSceneFocusAction());
    scene.setKeyEventProcessingType (EventProcessingType.FOCUSED_WIDGET_AND_ITS_PARENTS);

    mainLayer = new LayerWidget(scene);
    mainLayer.setPreferredLocation(new Point(0, 0));
    mainLayer.setLayout(LayoutFactory.createVerticalFlowLayout(
            LayoutFactory.SerialAlignment.JUSTIFY, 12));
    scene.addChild(mainLayer);
    
    mainWidget = new Widget(scene);
    mainWidget.setLayout(LayoutFactory.createVerticalFlowLayout(
            LayoutFactory.SerialAlignment.JUSTIFY, 12));
    
    headerWidget = new LabelWidget(scene);
    headerWidget.setFont(scene.getFont().deriveFont(Font.BOLD));
    headerWidget.setForeground(Color.GRAY);
    headerWidget.setBorder(BorderFactory.createEmptyBorder(6,28,0,0));
    mainWidget.addChild(headerWidget);
    
    separatorWidget = new SeparatorWidget(scene,
            SeparatorWidget.Orientation.HORIZONTAL);
    separatorWidget.setForeground(Color.ORANGE);
    mainWidget.addChild(separatorWidget);
    
    contentWidget = new Widget(scene);
    contentWidget.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
    contentWidget.setLayout(LayoutFactory.createVerticalFlowLayout(
            LayoutFactory.SerialAlignment.JUSTIFY, 16));
    mainWidget.addChild(contentWidget);
    
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER){
        /* (non-Javadoc)
         * @see java.awt.FlowLayout#layoutContainer(java.awt.Container)
         */
        @Override
        public void layoutContainer( Container target ) {
            super.layoutContainer(target);
            Component[] components = target.getComponents();
            double height = target.getSize().getHeight()/2;
            for (Component component : components) {
                Point location = component.getLocation();
                component.setLocation( (int)location.getX(), (int)height );
            }
        }
    });
    panel.add(new JLabel(NbBundle.getMessage( DesignView.class, "LBL_Wait")));
    add( panel,BorderLayout.CENTER);
    
    mainLayer.addChild(mainWidget);

    messageWidget = new Widget(scene);
    messageWidget.setLayout(LayoutFactory.createVerticalFlowLayout(
            LayoutFactory.SerialAlignment.JUSTIFY, 4));
    mainLayer.addChild(messageWidget);
    scene.addObject(messageLayerKey, messageWidget);
    
    initServiceModel();
}