Search in sources :

Example 6 with ActionListener

use of com.ramussoft.gui.common.event.ActionListener in project ramus by Vitaliy-Yakovchuk.

the class IDEF0ViewPlugin method getActionDescriptors.

@SuppressWarnings("unused")
@Override
public ActionDescriptor[] getActionDescriptors() {
    ActionDescriptor openStreans = new ActionDescriptor();
    openStreans.setActionLevel(ActionLevel.GLOBAL);
    openStreans.setMenu("Tools");
    openStreans.setAction(new AbstractAction() {

        {
            putValue(ACTION_COMMAND_KEY, "streams");
        }

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            framework.propertyChanged(OPEN_STREAMS);
        }
    });
    ActionDescriptor runWebServer = new ActionDescriptor();
    runWebServer.setActionLevel(ActionLevel.GLOBAL);
    runWebServer.setMenu("Tools");
    runWebServer.setAction(new AbstractAction() {

        {
            putValue(ACTION_COMMAND_KEY, MainFrame.OPEN_WEB_SERVER);
        }

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if (server == null) {
                server = new HTTPServer("0", NDataPluginFactory.getDataPlugin(null, engine, rules), framework) {

                    @Override
                    protected void serverStarted() {
                        AbstractAttributePlugin.openUrl("http://127.0.0.1:" + getServer().getLocalPort(), framework);
                    }
                };
            } else {
                AbstractAttributePlugin.openUrl("http://127.0.0.1:" + server.getServer().getLocalPort(), framework);
            }
        }
    });
    ActionDescriptor idef0Separator = new ActionDescriptor();
    idef0Separator.setMenu("IDEF0");
    ActionDescriptor loadModelsFromFile = new ActionDescriptor();
    loadModelsFromFile.setActionLevel(ActionLevel.GLOBAL);
    loadModelsFromFile.setMenu("IDEF0");
    loadModelsFromFile.setAction(new AbstractAction() {

        {
            putValue(ACTION_COMMAND_KEY, "loadModelsFromFile");
        }

        @Override
        public void actionPerformed(java.awt.event.ActionEvent event) {
            DataPlugin plugin = NDataPluginFactory.getDataPlugin(null, engine, rules);
            try {
                final JFileChooser chooser = frame.getChooser();
                if (chooser.showOpenDialog(framework.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
                    plugin.loadFromParalel(chooser.getSelectedFile(), framework);
                }
            } catch (final IOException e) {
                JOptionPane.showMessageDialog(framework.getMainFrame(), e.getLocalizedMessage());
            }
        }
    });
    ActionDescriptor toolsSeparator = new ActionDescriptor();
    toolsSeparator.setMenu("Tools");
    if ((Metadata.DEMO) && (!new SerialCheker().check(Options.getString("SERIAL")))) {
        Metadata.DEMO_REGISTERED = false;
        if (Metadata.DEMO) {
            framework.addActionListener("MainFrameShown", new ActionListener() {

                @Override
                public void onAction(ActionEvent event) {
                    String title = framework.getMainFrame().getTitle();
                    if (!Metadata.DEMO_REGISTERED)
                        title += " " + GlobalResourcesManager.getString("UnregisteredCopy");
                    else
                        title += " " + MessageFormat.format(GlobalResourcesManager.getString("RegisteredName"), Metadata.REGISTERED_FOR);
                    framework.getMainFrame().setTitle(title);
                }
            });
        }
        return new ActionDescriptor[] { runWebServer, openStreans, findAction(CURSOR_TOOL), findAction(FUNCTION_TOOL), findAction(ARROW_TOOL), findAction(TILDA_TOOL), findAction(TEXT_TOOL), findAction(EXTERNAL_REFERENCE_TOOL), findAction(DFDS_ROLE_TOOL), findAction(DATA_STORE_TOOL), findAction(IDEF0_NET), findAction(GO_TO_PARENT), findAction(GO_TO_CHILD), idef0Separator, findAction(CENTER_ALL_SECTORS), idef0Separator, loadModelsFromFile, toolsSeparator, findAction(ADD_MODEL_TO_TEMPLATE, "Tools"), findAction(USER_TEMPLATES, "Tools"), idef0Separator, findAction(MODEL_PROPETIES), findAction(DIAGRAM_PROPETIES), idef0Separator, findAction(EXPORT_TO_IMAGES), createExportToIDL(), createImportFromIDL(), createRegisterAction(), toolsSeparator, findAction(CREATE_LEVEL) };
    } else {
        if (Metadata.DEMO) {
            framework.addActionListener("MainFrameShown", new ActionListener() {

                @Override
                public void onAction(ActionEvent event) {
                    String title = framework.getMainFrame().getTitle();
                    if (!Metadata.DEMO_REGISTERED)
                        title += " " + GlobalResourcesManager.getString("UnregisteredCopy");
                    else
                        title += " " + MessageFormat.format(GlobalResourcesManager.getString("RegisteredName"), Metadata.REGISTERED_FOR);
                    framework.getMainFrame().setTitle(title);
                }
            });
        }
        ActionDescriptor editSeparator = new ActionDescriptor();
        editSeparator.setMenu("Edit");
        ActionDescriptor cut = new ActionDescriptor();
        cut.setMenu("Edit");
        cut.setAction(frame.findAction(MainFrame.CUT));
        ActionDescriptor copy = new ActionDescriptor();
        copy.setMenu("Edit");
        copy.setAction(frame.findAction(MainFrame.COPY));
        ActionDescriptor paste = new ActionDescriptor();
        paste.setMenu("Edit");
        paste.setAction(frame.findAction(MainFrame.PASTE));
        return new ActionDescriptor[] { runWebServer, openStreans, findAction(CURSOR_TOOL), findAction(FUNCTION_TOOL), findAction(ARROW_TOOL), findAction(TILDA_TOOL), findAction(TEXT_TOOL), findAction(EXTERNAL_REFERENCE_TOOL), findAction(DFDS_ROLE_TOOL), findAction(DATA_STORE_TOOL), findAction(IDEF0_NET), findAction(GO_TO_PARENT), findAction(GO_TO_CHILD), idef0Separator, findAction(CENTER_ALL_SECTORS), idef0Separator, loadModelsFromFile, toolsSeparator, findAction(ADD_MODEL_TO_TEMPLATE, "Tools"), findAction(USER_TEMPLATES, "Tools"), idef0Separator, findAction(MODEL_PROPETIES), findAction(DIAGRAM_PROPETIES), idef0Separator, findAction(EXPORT_TO_IMAGES), createExportToIDL(), createImportFromIDL(), editSeparator, cut, copy, paste };
    }
}
Also used : SerialCheker(com.ramussoft.pb.frames.components.SerialCheker) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) IOException(java.io.IOException) HTTPServer(com.ramussoft.pb.print.web.HTTPServer) JFileChooser(javax.swing.JFileChooser) ActionListener(com.ramussoft.gui.common.event.ActionListener) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) AbstractAction(javax.swing.AbstractAction)

Example 7 with ActionListener

use of com.ramussoft.gui.common.event.ActionListener in project ramus by Vitaliy-Yakovchuk.

the class IDEF0ViewPlugin method addOpenDiagramListener.

private void addOpenDiagramListener() {
    framework.addActionListener(OPEN_DIAGRAM, new ActionListener() {

        @Override
        public void onAction(final ActionEvent event) {
            if (framework.openView(event))
                return;
            final DiagramData data = new DiagramData();
            data.openDiagram = (OpenDiagram) event.getValue();
            data.listener = new QualifierAdapter() {

                @Override
                public void qualifierDeleted(QualifierEvent event) {
                    if (event.getOldQualifier().equals(data.openDiagram.getQualifier())) {
                        data.view.close();
                    }
                }

                @Override
                public void qualifierUpdated(QualifierEvent event) {
                    if (data.openDiagram.getQualifier().equals(event.getNewQualifier())) {
                        IDEF0TabView view = (IDEF0TabView) data.view;
                        if (view.isBaseFunctionSelected()) {
                            ViewTitleEvent event2 = new ViewTitleEvent(data.view, event.getNewQualifier().getName());
                            view.titleChanged(event2);
                        }
                    }
                }
            };
            data.elementListener = new ElementAdapter() {

                @Override
                public void elementDeleted(ElementEvent event) {
                    if (((IDEF0TabView) data.view).isSelectedElementId(event.getOldElement()))
                        data.view.close();
                }
            };
            engine.addQualifierListener(data.listener);
            engine.addElementListener(data.openDiagram.getQualifier(), data.elementListener);
            data.view = new IDEF0TabView(framework, NDataPluginFactory.getDataPlugin(data.openDiagram.getQualifier(), engine, rules), data.openDiagram.getFunctionId(), frame, rules) {

                @Override
                public void close() {
                    super.close();
                    engine.removeQualifierListener(data.listener);
                    engine.removeElementListener(data.openDiagram.getQualifier(), data.elementListener);
                    TabbedEvent tEvent = new TabbedEvent(IDEF0TabbedView.IDEF0_TAB_VIEW, this);
                    tabRemoved(tEvent);
                }
            };
            TabbedEvent tEvent = new TabbedEvent(IDEF0TabbedView.IDEF0_TAB_VIEW, (TabView) data.view);
            tabCreated(tEvent);
        }
    });
}
Also used : QualifierAdapter(com.ramussoft.common.event.QualifierAdapter) ElementAdapter(com.ramussoft.common.event.ElementAdapter) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) QualifierEvent(com.ramussoft.common.event.QualifierEvent) ElementEvent(com.ramussoft.common.event.ElementEvent) TabbedEvent(com.ramussoft.gui.common.event.TabbedEvent) ViewTitleEvent(com.ramussoft.gui.common.event.ViewTitleEvent) ActionListener(com.ramussoft.gui.common.event.ActionListener)

Example 8 with ActionListener

use of com.ramussoft.gui.common.event.ActionListener in project ramus by Vitaliy-Yakovchuk.

the class IDEF0ViewPlugin method addOpenStreamsViewListener.

private void addOpenStreamsViewListener() {
    framework.addActionListener(OPEN_STREAMS, new ActionListener() {

        @Override
        public void onAction(final ActionEvent event) {
            if (framework.openView(event))
                return;
            final StreamsData data = new StreamsData();
            data.view = new StreamsTabView(framework) {

                @Override
                public void close() {
                    super.close();
                    TabbedEvent tEvent = new TabbedEvent(IDEF0TabbedView.IDEF0_TAB_VIEW, this);
                    tabRemoved(tEvent);
                }
            };
            TabbedEvent tEvent = new TabbedEvent(IDEF0TabbedView.IDEF0_TAB_VIEW, (TabView) data.view);
            tabCreated(tEvent);
        }
    });
}
Also used : ActionListener(com.ramussoft.gui.common.event.ActionListener) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) TabbedEvent(com.ramussoft.gui.common.event.TabbedEvent)

Example 9 with ActionListener

use of com.ramussoft.gui.common.event.ActionListener in project ramus by Vitaliy-Yakovchuk.

the class IDEF0ViewPlugin method setFramework.

@Override
public void setFramework(final GUIFramework framework) {
    super.setFramework(framework);
    this.engine = framework.getEngine();
    this.rules = framework.getAccessRules();
    this.frame.setEngine(framework);
    addOpenDiagramListener();
    addOpenStreamsViewListener();
    framework.addCloseMainFrameListener(new CloseMainFrameAdapter() {

        @Override
        public void closed() {
            Options.save();
            if (navigator != null)
                navigator.dispose();
            if (engine.getPluginProperty("Core", "MainFrame") == framework.getMainFrame()) {
                NDataPlugin dataPlugin = (NDataPlugin) engine.getPluginProperty("IDEF0", "DataPlugin");
                if (dataPlugin != null) {
                    dataPlugin.clear();
                    dataPlugin.clearAll();
                }
            }
            if (server != null) {
                try {
                    server.getServer().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                server.interrupt();
            }
        }
    });
    framework.addActionListener("FileOpened", new ActionListener() {

        @Override
        public void onAction(ActionEvent event) {
            if (event.getValue() == null) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        NewProjectDialog dialog = new NewProjectDialog(framework.getMainFrame());
                        dialog.showModal(engine, rules, framework);
                    }
                });
            }
        }
    });
    framework.addActionListener(Commands.FULL_REFRESH, new ActionListener() {

        @Override
        public void onAction(ActionEvent event) {
            if (NDataPluginFactory.getExistingDataPlugin(engine) != null)
                NDataPluginFactory.fullRefrash(framework);
        }
    });
    framework.setSystemAttributeName(IDEF0Plugin.getBackgroundColorAttribute(engine), ResourceLoader.getString("bk_color"));
    framework.setSystemAttributeName(IDEF0Plugin.getForegroundColorAttribute(engine), ResourceLoader.getString("fg_color"));
    framework.setSystemAttributeName(IDEF0Plugin.getFontAttribute(engine), ResourceLoader.getString("font"));
    framework.setSystemAttributeName(IDEF0Plugin.getFunctionTypeAttribute(engine), ResourceLoader.getString("function_type"));
    framework.setSystemAttributeName(IDEF0Plugin.getFunctionOunerAttribute(engine), ResourceLoader.getString("select_owner"));
    StreamAttributePlugin plugin = new StreamAttributePlugin();
    plugin.setFramework(framework);
    framework.setSystemAttributePlugin(IDEF0Plugin.getStreamAttribute(engine), plugin);
    framework.setSystemAttributeName(IDEF0Plugin.getStreamAttribute(engine), ResourceLoader.getString("stream"));
    framework.setSystemAttributePlugin(IDEF0Plugin.getSectorBorderEndAttribute(engine), new SectorFontAttributePlugin());
    framework.setSystemAttributeName(IDEF0Plugin.getSectorBorderEndAttribute(engine), ResourceLoader.getString("font"));
    framework.setSystemAttributePlugin(IDEF0Plugin.getSectorBorderStartAttribute(engine), new SectorColorAttributePlugin());
    framework.setSystemAttributeName(IDEF0Plugin.getSectorBorderStartAttribute(engine), ResourceLoader.getString("color"));
    framework.setSystemAttributePlugin(IDEF0Plugin.getSectorFunctionAttribute(engine), new LineStyleAttributePlugin());
    framework.setSystemAttributeName(IDEF0Plugin.getSectorFunctionAttribute(engine), ResourceLoader.getString("arrow"));
}
Also used : NewProjectDialog(com.ramussoft.pb.master.NewProjectDialog) SectorFontAttributePlugin(com.ramussoft.idef0.attribute.SectorFontAttributePlugin) StreamAttributePlugin(com.ramussoft.idef0.attribute.StreamAttributePlugin) CloseMainFrameAdapter(com.ramussoft.gui.common.event.CloseMainFrameAdapter) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) ActionListener(com.ramussoft.gui.common.event.ActionListener) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) IOException(java.io.IOException) SectorColorAttributePlugin(com.ramussoft.idef0.attribute.SectorColorAttributePlugin) LineStyleAttributePlugin(com.ramussoft.idef0.attribute.LineStyleAttributePlugin)

Example 10 with ActionListener

use of com.ramussoft.gui.common.event.ActionListener in project ramus by Vitaliy-Yakovchuk.

the class GUIPluginFactory method initContent.

@SuppressWarnings("deprecation")
private void initContent() {
    control = new CControl(plugableFrame, false);
    // control.setTheme(control.getThemes().getFactory(2).create());
    control.addControlListener(new CControlListener() {

        @Override
        public void added(CControl control, CDockable dockable) {
        }

        @Override
        public void closed(CControl control, CDockable dockable) {
            Boolean b = recHash.get(Thread.currentThread());
            if (b != null)
                return;
            recHash.put(Thread.currentThread(), true);
            List<TabView> list = new ArrayList<TabView>();
            for (Entry<TabView, TabDockable> e : tabDockables.entrySet()) {
                if (e.getValue().equals(dockable)) {
                    TabView view = e.getKey();
                    list.add(view);
                }
            }
            for (TabView view : list) view.close();
            recHash.remove(Thread.currentThread());
        }

        @Override
        public void opened(CControl control, CDockable dockable) {
        }

        @Override
        public void removed(CControl control, CDockable dockable) {
        }
    });
    control.addFocusListener(new CFocusListener() {

        @Override
        public void focusGained(CDockable dockable) {
            List<View> list = new ArrayList<View>();
            for (Entry<TabView, TabDockable> e : tabDockables.entrySet()) {
                if (e.getValue().equals(dockable)) {
                    TabView view = e.getKey();
                    list.add(view);
                }
            }
            if (dockable instanceof DefaultSingleCDockable) {
                list.add(findUniqueView(((DefaultSingleCDockable) dockable).getUniqueId()));
            }
            for (View view : list) {
                lastActiveView = view;
                view.focusGained();
                plugableFrame.setViewActions(view.getGlobalActions());
                if ((!(view instanceof UniqueView)) && (view instanceof TabView)) {
                    if (currentWorkspace != null)
                        workspaceViews.put(currentWorkspace, view);
                }
            }
        }

        @Override
        public void focusLost(CDockable dockable) {
            List<View> list = new ArrayList<View>();
            for (Entry<TabView, TabDockable> e : tabDockables.entrySet()) {
                if (e.getValue().equals(dockable)) {
                    TabView view = e.getKey();
                    list.add(view);
                }
            }
            if (dockable instanceof DefaultSingleCDockable) {
                list.add(findUniqueView(((DefaultSingleCDockable) dockable).getUniqueId()));
            }
            for (View view : list) view.focusLost();
            plugableFrame.setViewActions(new String[] {});
        }
    });
    // control.setTheme(ThemeMap.KEY_ECLIPSE_THEME);
    contentArea = control.getContentArea();
    plugableFrame.add(contentArea, BorderLayout.CENTER);
    for (UniqueView view : uniqueViews) {
        String id = view.getId();
        final DefaultSingleCDockable dockable = new DefaultSingleCDockable(id, findPluginForViewId(id).getString(id), view.createComponent());
        dockable.setCloseable(true);
        initActions(view.getId(), view, dockable);
        control.addDockable(dockable);
        uniqueDockables.add(dockable);
        framework.addActionListener(id, new ActionListener() {

            @Override
            public void onAction(ActionEvent event) {
                dockable.setVisible(true);
            }
        });
        if (currentWorkspace.equals(view.getDefaultWorkspace()))
            dockable.setVisible(true);
    }
    for (TabbedView view : tabbedViews) {
        String id = view.getId();
        if (getWorkingArea(id) != null)
            continue;
        CWorkingArea area = control.createWorkingArea(id);
        uniqueWorkingAreas.add(area);
        // area.setTitleShown(false);
        // if (currentWorkspace.equals(view.getDefaultWorkspace()))
        area.setVisible(true);
        TabbedFactory factory = new TabbedFactory();
        factories.put(id, factory);
        control.addMultipleDockableFactory(id, factory);
    // dockable.setWorkingArea(area);
    // dockable1.setWorkingArea(area);
    // control.add(dockable1);
    // control.add(dockable);
    // dockable.setLocation(CLocation.base().)
    }
    framework.setMainFrame(plugableFrame);
}
Also used : CControl(bibliothek.gui.dock.common.CControl) TabView(com.ramussoft.gui.common.TabView) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) UniqueView(com.ramussoft.gui.common.UniqueView) TabView(com.ramussoft.gui.common.TabView) TabbedView(com.ramussoft.gui.common.TabbedView) View(com.ramussoft.gui.common.View) CWorkingArea(bibliothek.gui.dock.common.CWorkingArea) TabbedView(com.ramussoft.gui.common.TabbedView) Entry(java.util.Map.Entry) UniqueView(com.ramussoft.gui.common.UniqueView) CFocusListener(bibliothek.gui.dock.common.event.CFocusListener) ActionListener(com.ramussoft.gui.common.event.ActionListener) List(java.util.List) ArrayList(java.util.ArrayList) CControlListener(bibliothek.gui.dock.common.event.CControlListener) DefaultSingleCDockable(bibliothek.gui.dock.common.DefaultSingleCDockable) SingleCDockable(bibliothek.gui.dock.common.SingleCDockable) CDockable(bibliothek.gui.dock.common.intern.CDockable) DefaultSingleCDockable(bibliothek.gui.dock.common.DefaultSingleCDockable) DefaultCDockable(bibliothek.gui.dock.common.intern.DefaultCDockable)

Aggregations

ActionListener (com.ramussoft.gui.common.event.ActionListener)16 ActionEvent (com.ramussoft.gui.common.event.ActionEvent)11 TabbedEvent (com.ramussoft.gui.common.event.TabbedEvent)7 TabView (com.ramussoft.gui.common.TabView)3 ViewTitleEvent (com.ramussoft.gui.common.event.ViewTitleEvent)3 IOException (java.io.IOException)3 Element (com.ramussoft.common.Element)2 ElementAdapter (com.ramussoft.common.event.ElementAdapter)2 ElementEvent (com.ramussoft.common.event.ElementEvent)2 QualifierAdapter (com.ramussoft.common.event.QualifierAdapter)2 QualifierEvent (com.ramussoft.common.event.QualifierEvent)2 TabbedView (com.ramussoft.gui.common.TabbedView)2 UniqueView (com.ramussoft.gui.common.UniqueView)2 View (com.ramussoft.gui.common.View)2 CloseMainFrameAdapter (com.ramussoft.gui.common.event.CloseMainFrameAdapter)2 NDataPlugin (com.ramussoft.pb.data.negine.NDataPlugin)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 CControl (bibliothek.gui.dock.common.CControl)1