Search in sources :

Example 1 with Controller

use of gate.Controller in project gate-core by GateNLP.

the class MainFrame method initListeners.

protected void initListeners() {
    Gate.getCreoleRegister().addCreoleListener(this);
    Gate.getCreoleRegister().addPluginListener(this);
    resourcesTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                // shows in the central tabbed pane, the selected resources
                // in the resource tree when the Enter key is pressed
                (new ShowSelectedResourcesAction()).actionPerformed(null);
            } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                // close selected resources from GATE
                (new CloseSelectedResourcesAction()).actionPerformed(null);
            } else if (e.getKeyCode() == KeyEvent.VK_DELETE && e.getModifiers() == InputEvent.SHIFT_DOWN_MASK) {
                // close recursively selected resources from GATE
                (new CloseRecursivelySelectedResourcesAction()).actionPerformed(null);
            }
        }
    });
    resourcesTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            TreePath path = resourcesTree.getClosestPathForLocation(e.getX(), e.getY());
            if (e.isPopupTrigger() && !resourcesTree.isPathSelected(path)) {
                // if right click outside the selection then reset selection
                resourcesTree.getSelectionModel().setSelectionPath(path);
            }
            processMouseEvent(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            processMouseEvent(e);
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            processMouseEvent(e);
        }

        protected void processMouseEvent(MouseEvent e) {
            // where inside the tree?
            int x = e.getX();
            int y = e.getY();
            TreePath path = resourcesTree.getClosestPathForLocation(x, y);
            JPopupMenu popup = null;
            Handle handle = null;
            if (path != null) {
                Object value = path.getLastPathComponent();
                if (value == resourcesTreeRoot) {
                // no default item for this menu
                } else if (value == applicationsRoot) {
                    appsPopup = new XJPopupMenu();
                    LiveMenu appsMenu = new LiveMenu(LiveMenu.APP);
                    appsMenu.setText("Create New Application");
                    appsMenu.setIcon(MainFrame.getIcon("applications"));
                    appsPopup.add(appsMenu);
                    appsPopup.add(new ReadyMadeMenu());
                    appsPopup.add(new XJMenuItem(new LoadResourceFromFileAction(), MainFrame.this));
                    RecentAppsMenu recentApps = new RecentAppsMenu();
                    if (recentApps.getMenuComponentCount() > 0)
                        appsPopup.add(recentApps);
                    popup = appsPopup;
                } else if (value == languageResourcesRoot) {
                    popup = lrsPopup;
                } else if (value == processingResourcesRoot) {
                    popup = prsPopup;
                } else if (value == datastoresRoot) {
                    popup = dssPopup;
                } else {
                    value = ((DefaultMutableTreeNode) value).getUserObject();
                    if (value instanceof Handle) {
                        handle = (Handle) value;
                        fileChooser.setResource(handle.getTarget().getClass().getName());
                        if (e.isPopupTrigger()) {
                            popup = handle.getPopup();
                        }
                    }
                }
            }
            // popup menu
            if (e.isPopupTrigger()) {
                if (resourcesTree.getSelectionCount() > 1) {
                    // multiple selection in tree
                    popup = new XJPopupMenu();
                    // add a close all action
                    popup.add(new XJMenuItem(new CloseSelectedResourcesAction(), MainFrame.this));
                    // add a close recursively all action
                    TreePath[] selectedPaths = resourcesTree.getSelectionPaths();
                    for (TreePath selectedPath : selectedPaths) {
                        Object userObject = ((DefaultMutableTreeNode) selectedPath.getLastPathComponent()).getUserObject();
                        if (userObject instanceof NameBearerHandle && ((NameBearerHandle) userObject).getTarget() instanceof Controller) {
                            // there is at least one application
                            popup.add(new XJMenuItem(new CloseRecursivelySelectedResourcesAction(), MainFrame.this));
                            break;
                        }
                    }
                    // add a show all action
                    selectedPaths = resourcesTree.getSelectionPaths();
                    for (TreePath selectedPath : selectedPaths) {
                        Object userObject = ((DefaultMutableTreeNode) selectedPath.getLastPathComponent()).getUserObject();
                        if (userObject instanceof Handle && (!((Handle) userObject).viewsBuilt() || (mainTabbedPane.indexOfComponent(((Handle) userObject).getLargeView()) == -1))) {
                            // there is at least one resource not shown
                            popup.add(new XJMenuItem(new ShowSelectedResourcesAction(), MainFrame.this));
                            break;
                        }
                    }
                    // add a hide all action
                    selectedPaths = resourcesTree.getSelectionPaths();
                    for (TreePath selectedPath : selectedPaths) {
                        Object userObject = ((DefaultMutableTreeNode) selectedPath.getLastPathComponent()).getUserObject();
                        if (userObject instanceof Handle && ((Handle) userObject).viewsBuilt() && ((Handle) userObject).getLargeView() != null && (mainTabbedPane.indexOfComponent(((Handle) userObject).getLargeView()) != -1)) {
                            // there is at least one resource shown
                            popup.add(new XJMenuItem(new CloseViewsForSelectedResourcesAction(), MainFrame.this));
                            break;
                        }
                    }
                    popup.show(resourcesTree, e.getX(), e.getY());
                } else if (popup != null) {
                    if (handle != null) {
                        // add a close action
                        if (handle instanceof NameBearerHandle) {
                            popup.insert(new XJMenuItem(((NameBearerHandle) handle).getCloseAction(), MainFrame.this), 0);
                        }
                        // if application then add a close recursively action
                        if (handle instanceof NameBearerHandle && handle.getTarget() instanceof Controller) {
                            popup.insert(new XJMenuItem(((NameBearerHandle) handle).getCloseRecursivelyAction(), MainFrame.this), 1);
                        }
                        // add a show/hide action
                        if (handle.viewsBuilt() && handle.getLargeView() != null && (mainTabbedPane.indexOfComponent(handle.getLargeView()) != -1)) {
                            popup.insert(new XJMenuItem(new CloseViewAction(handle), MainFrame.this), 2);
                        } else {
                            popup.insert(new XJMenuItem(new ShowResourceAction(handle), MainFrame.this), 2);
                        }
                        // add a rename action
                        popup.insert(new XJMenuItem(new RenameResourceAction(path), MainFrame.this), 3);
                        // add a help action
                        if (handle instanceof NameBearerHandle) {
                            popup.insert(new XJMenuItem(new HelpOnItemTreeAction((NameBearerHandle) handle), MainFrame.this), 4);
                        }
                    }
                    popup.show(resourcesTree, e.getX(), e.getY());
                }
            } else if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() == 2 && handle != null) {
                // double click - show the resource
                select(handle);
            }
        }
    });
    resourcesTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (!Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".treeselectview")) {
                return;
            }
            // the resource tree selection
            if (resourcesTree.getSelectionPaths() != null && resourcesTree.getSelectionPaths().length == 1) {
                Object value = e.getPath().getLastPathComponent();
                Object object = ((DefaultMutableTreeNode) value).getUserObject();
                if (object instanceof Handle && ((Handle) object).viewsBuilt() && (mainTabbedPane.indexOfComponent(((Handle) object).getLargeView()) != -1)) {
                    select((Handle) object);
                }
            }
        }
    });
    // define keystrokes action bindings at the level of the main window
    InputMap inputMap = ((JComponent) this.getContentPane()).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke("control F4"), "Close resource");
    inputMap.put(KeyStroke.getKeyStroke("shift F4"), "Close recursively");
    inputMap.put(KeyStroke.getKeyStroke("control H"), "Hide");
    inputMap.put(KeyStroke.getKeyStroke("control shift H"), "Hide all");
    inputMap.put(KeyStroke.getKeyStroke("control S"), "Save As XML");
    // TODO: remove when Swing will take care of the context menu key
    if (inputMap.get(KeyStroke.getKeyStroke("CONTEXT_MENU")) == null) {
        inputMap.put(KeyStroke.getKeyStroke("CONTEXT_MENU"), "Show context menu");
    }
    ActionMap actionMap = ((JComponent) instance.getContentPane()).getActionMap();
    actionMap.put("Show context menu", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
            // get the current focused component
            Component focusedComponent = focusManager.getFocusOwner();
            if (focusedComponent != null) {
                Point menuLocation = null;
                Rectangle selectionRectangle = null;
                if (focusedComponent instanceof JTable && ((JTable) focusedComponent).getSelectedRowCount() > 0) {
                    // selection in a JTable
                    JTable table = (JTable) focusedComponent;
                    selectionRectangle = table.getCellRect(table.getSelectionModel().getLeadSelectionIndex(), table.convertColumnIndexToView(table.getSelectedColumn()), false);
                } else if (focusedComponent instanceof JTree && ((JTree) focusedComponent).getSelectionCount() > 0) {
                    // selection in a JTree
                    JTree tree = (JTree) focusedComponent;
                    selectionRectangle = tree.getRowBounds(tree.getSelectionModel().getLeadSelectionRow());
                } else {
                    // for other component set the menu location at the top left corner
                    menuLocation = new Point(focusedComponent.getX() - 1, focusedComponent.getY() - 1);
                }
                if (menuLocation == null) {
                    // menu location at the bottom left of the JTable or JTree
                    menuLocation = new Point(new Double(selectionRectangle.getMinX() + 1).intValue(), new Double(selectionRectangle.getMaxY() - 1).intValue());
                }
                // generate a right/button 3/popup menu mouse click
                focusedComponent.dispatchEvent(new MouseEvent(focusedComponent, MouseEvent.MOUSE_PRESSED, e.getWhen(), MouseEvent.BUTTON3_DOWN_MASK, menuLocation.x, menuLocation.y, 1, true, MouseEvent.BUTTON3));
            }
        }
    });
    mainTabbedPane.getModel().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            // find the handle in the resources tree for the main view
            JComponent largeView = (JComponent) mainTabbedPane.getSelectedComponent();
            Enumeration<?> nodesEnum = resourcesTreeRoot.preorderEnumeration();
            boolean done = false;
            DefaultMutableTreeNode node = resourcesTreeRoot;
            while (!done && nodesEnum.hasMoreElements()) {
                node = (DefaultMutableTreeNode) nodesEnum.nextElement();
                done = node.getUserObject() instanceof Handle && ((Handle) node.getUserObject()).viewsBuilt() && ((Handle) node.getUserObject()).getLargeView() == largeView;
            }
            ActionMap actionMap = ((JComponent) instance.getContentPane()).getActionMap();
            if (done) {
                Handle handle = (Handle) node.getUserObject();
                if (Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".viewselecttree")) {
                    // synchronise the selection in the tabbed pane with
                    // the one in the resources tree
                    TreePath nodePath = new TreePath(node.getPath());
                    resourcesTree.setSelectionPath(nodePath);
                    resourcesTree.scrollPathToVisible(nodePath);
                }
                lowerScroll.getViewport().setView(handle.getSmallView());
                // redefine MainFrame actionMaps for the selected tab
                JComponent resource = (JComponent) mainTabbedPane.getSelectedComponent();
                actionMap.put("Close resource", resource.getActionMap().get("Close resource"));
                actionMap.put("Close recursively", resource.getActionMap().get("Close recursively"));
                actionMap.put("Hide", new CloseViewAction(handle));
                actionMap.put("Hide all", new HideAllAction());
                actionMap.put("Save As XML", resource.getActionMap().get("Save As XML"));
            } else {
                // the selected item is not a resource (maybe the log area?)
                lowerScroll.getViewport().setView(null);
                // disabled actions on the selected tabbed pane
                actionMap.put("Close resource", null);
                actionMap.put("Close recursively", null);
                actionMap.put("Hide", null);
                actionMap.put("Hide all", null);
                actionMap.put("Save As XML", null);
            }
        }
    });
    mainTabbedPane.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            processMouseEvent(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            processMouseEvent(e);
        }

        protected void processMouseEvent(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int index = mainTabbedPane.getIndexAt(e.getPoint());
                if (index != -1) {
                    JComponent view = (JComponent) mainTabbedPane.getComponentAt(index);
                    Enumeration<?> nodesEnum = resourcesTreeRoot.preorderEnumeration();
                    boolean done = false;
                    DefaultMutableTreeNode node = resourcesTreeRoot;
                    while (!done && nodesEnum.hasMoreElements()) {
                        node = (DefaultMutableTreeNode) nodesEnum.nextElement();
                        done = node.getUserObject() instanceof Handle && ((Handle) node.getUserObject()).viewsBuilt() && ((Handle) node.getUserObject()).getLargeView() == view;
                    }
                    if (done) {
                        Handle handle = (Handle) node.getUserObject();
                        JPopupMenu popup = handle.getPopup();
                        // add a hide action
                        CloseViewAction cva = new CloseViewAction(handle);
                        XJMenuItem menuItem = new XJMenuItem(cva, MainFrame.this);
                        popup.insert(menuItem, 0);
                        // add a hide all action
                        if (mainTabbedPane.getTabCount() > 2) {
                            HideAllAction haa = new HideAllAction();
                            menuItem = new XJMenuItem(haa, MainFrame.this);
                            popup.insert(menuItem, 1);
                        }
                        popup.show(mainTabbedPane, e.getX(), e.getY());
                    }
                }
            }
        }
    });
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentShown(ComponentEvent e) {
            leftSplit.setDividerLocation(0.7);
        }

        @Override
        public void componentResized(ComponentEvent e) {
            // resize proportionally the status bar elements
            int width = MainFrame.this.getWidth();
            statusBar.setPreferredSize(new Dimension(width * 65 / 100, statusBar.getPreferredSize().height));
            progressBar.setPreferredSize(new Dimension(width * 20 / 100, progressBar.getPreferredSize().height));
            progressBar.setMinimumSize(new Dimension(80, 0));
            globalProgressBar.setPreferredSize(new Dimension(width * 10 / 100, globalProgressBar.getPreferredSize().height));
            globalProgressBar.setMinimumSize(new Dimension(80, 0));
        }
    });
    // blink the messages tab when new information is displayed
    logArea.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {

        @Override
        public void insertUpdate(javax.swing.event.DocumentEvent e) {
            changeOccured();
        }

        @Override
        public void removeUpdate(javax.swing.event.DocumentEvent e) {
            changeOccured();
        }

        @Override
        public void changedUpdate(javax.swing.event.DocumentEvent e) {
        }

        protected void changeOccured() {
            logHighlighter.highlight();
        }
    });
    logArea.addPropertyChangeListener("document", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            // add the document listener
            logArea.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {

                @Override
                public void insertUpdate(javax.swing.event.DocumentEvent e) {
                    changeOccured();
                }

                @Override
                public void removeUpdate(javax.swing.event.DocumentEvent e) {
                    changeOccured();
                }

                @Override
                public void changedUpdate(javax.swing.event.DocumentEvent e) {
                    changeOccured();
                }

                protected void changeOccured() {
                    logHighlighter.highlight();
                }
            });
        }
    });
    Gate.getListeners().put("gate.event.StatusListener", MainFrame.this);
    Gate.getListeners().put("gate.event.ProgressListener", MainFrame.this);
    if (Gate.runningOnMac()) {
        // mac-specific initialisation
        initMacListeners();
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) Rectangle(java.awt.Rectangle) AbstractAction(javax.swing.AbstractAction) PropertyChangeEvent(java.beans.PropertyChangeEvent) JTree(javax.swing.JTree) JTable(javax.swing.JTable) InputMap(javax.swing.InputMap) ComponentEvent(java.awt.event.ComponentEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PropertyChangeListener(java.beans.PropertyChangeListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) KeyEvent(java.awt.event.KeyEvent) MenuKeyEvent(javax.swing.event.MenuKeyEvent) XJPopupMenu(gate.swing.XJPopupMenu) KeyboardFocusManager(java.awt.KeyboardFocusManager) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) Component(java.awt.Component) JComponent(javax.swing.JComponent) ComponentAdapter(java.awt.event.ComponentAdapter) MouseEvent(java.awt.event.MouseEvent) Enumeration(java.util.Enumeration) ActionMap(javax.swing.ActionMap) MouseAdapter(java.awt.event.MouseAdapter) JComponent(javax.swing.JComponent) Point(java.awt.Point) Dimension(java.awt.Dimension) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) PackagedController(gate.creole.PackagedController) XJPopupMenu(gate.swing.XJPopupMenu) JPopupMenu(javax.swing.JPopupMenu) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) XJMenuItem(gate.swing.XJMenuItem) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 2 with Controller

use of gate.Controller in project gate-core by GateNLP.

the class MainFrame method resourceLoaded.

@Override
public void resourceLoaded(CreoleEvent e) {
    final Resource res = e.getResource();
    if (Gate.getHiddenAttribute(res.getFeatures()) || res instanceof VisualResource)
        return;
    // SwingUtilities.invokeLater(new Runnable() {
    // @Override
    // public void run() {
    NameBearerHandle handle = null;
    if (res instanceof Controller) {
        handle = new NameBearerHandle(res, MainFrame.this);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(handle, false);
        resourcesTreeModel.insertNodeInto(node, applicationsRoot, 0);
    } else if (res instanceof ProcessingResource) {
        handle = new NameBearerHandle(res, MainFrame.this);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(handle, false);
        resourcesTreeModel.insertNodeInto(node, processingResourcesRoot, 0);
    } else if (res instanceof LanguageResource) {
        handle = new NameBearerHandle(res, MainFrame.this);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(handle, false);
        resourcesTreeModel.insertNodeInto(node, languageResourcesRoot, 0);
    }
    if (handle != null)
        handle.addProgressListener(MainFrame.this);
    if (handle != null)
        handle.addStatusListener(MainFrame.this);
// }
// });
// JPopupMenu popup = handle.getPopup();
// 
// // Create a CloseViewAction and a menu item based on it
// CloseViewAction cva = new CloseViewAction(handle);
// XJMenuItem menuItem = new XJMenuItem(cva, this);
// // Add an accelerator ATL+F4 for this action
// menuItem.setAccelerator(KeyStroke.getKeyStroke(
// KeyEvent.VK_H, ActionEvent.CTRL_MASK));
// popup.insert(menuItem, 1);
// popup.insert(new JPopupMenu.Separator(), 2);
// 
// popup.insert(new XJMenuItem(
// new RenameResourceAction(
// new TreePath(resourcesTreeModel.getPathToRoot(node))),
// MainFrame.this) , 3);
// 
// // Put the action command in the component's action map
// if (handle.getLargeView() != null)
// handle.getLargeView().getActionMap().put("Hide current
// view",cva);
// 
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) VisualResource(gate.VisualResource) LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) VisualResource(gate.VisualResource) Resource(gate.Resource) LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) PackagedController(gate.creole.PackagedController)

Example 3 with Controller

use of gate.Controller in project gate-core by GateNLP.

the class MainFrame method resourceUnloaded.

// resourceLoaded();
@Override
public void resourceUnloaded(CreoleEvent e) {
    final Resource res = e.getResource();
    if (Gate.getHiddenAttribute(res.getFeatures()))
        return;
    Runnable runner = new Runnable() {

        @Override
        public void run() {
            DefaultMutableTreeNode node;
            DefaultMutableTreeNode parent = null;
            if (res instanceof Controller) {
                parent = applicationsRoot;
            } else if (res instanceof ProcessingResource) {
                parent = processingResourcesRoot;
            } else if (res instanceof LanguageResource) {
                parent = languageResourcesRoot;
            }
            if (parent != null) {
                Enumeration<?> children = parent.children();
                while (children.hasMoreElements()) {
                    node = (DefaultMutableTreeNode) children.nextElement();
                    if (((NameBearerHandle) node.getUserObject()).getTarget() == res) {
                        resourcesTreeModel.removeNodeFromParent(node);
                        Handle handle = (Handle) node.getUserObject();
                        if (handle.viewsBuilt()) {
                            if (mainTabbedPane.indexOfComponent(handle.getLargeView()) != -1)
                                mainTabbedPane.remove(handle.getLargeView());
                            if (lowerScroll.getViewport().getView() == handle.getSmallView())
                                lowerScroll.getViewport().setView(null);
                        }
                        handle.cleanup();
                        return;
                    }
                }
            }
        }
    };
    SwingUtilities.invokeLater(runner);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) VisualResource(gate.VisualResource) Resource(gate.Resource) LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) PackagedController(gate.creole.PackagedController)

Example 4 with Controller

use of gate.Controller in project gate-core by GateNLP.

the class NameBearerHandle method buildStaticPopupItems.

protected void buildStaticPopupItems() {
    // build the static part of the popup
    staticPopupItems = new ArrayList<JComponent>();
    if (target instanceof ProcessingResource && !(target instanceof Controller)) {
        // actions for PRs (but not Controllers)
        staticPopupItems.add(null);
        staticPopupItems.add(new XJMenuItem(new ReloadAction(), sListenerProxy));
        staticPopupItems.add(new XJMenuItem(new ApplicationWithPRAction(), sListenerProxy));
    } else if (target instanceof LanguageResource) {
        // Language Resources
        staticPopupItems.add(null);
        if (target instanceof Document) {
            staticPopupItems.add(new XJMenuItem(new CreateCorpusForDocAction(), sListenerProxy));
        }
        if (target instanceof gate.TextualDocument) {
            staticPopupItems.add(null);
            staticPopupItems.add(new DocumentExportMenu(this));
        } else if (target instanceof Corpus) {
            corpusFiller = new CorpusFillerComponent();
            scfInputDialog = new SingleConcatenatedFileInputDialog();
            staticPopupItems.add(new XJMenuItem(new PopulateCorpusAction(), sListenerProxy));
            staticPopupItems.add(new XJMenuItem(new PopulateCorpusFromSingleConcatenatedFileAction(), sListenerProxy));
            staticPopupItems.add(null);
            staticPopupItems.add(new DocumentExportMenu(this));
        }
        if (((LanguageResource) target).getDataStore() != null) {
            // this item can be used only if the resource belongs to a
            // datastore
            staticPopupItems.add(new XJMenuItem(new SaveAction(), sListenerProxy));
        }
        if (!(target instanceof AnnotationSchema)) {
            staticPopupItems.add(new XJMenuItem(new SaveToAction(), sListenerProxy));
        }
    }
    if (target instanceof Controller) {
        // Applications
        staticPopupItems.add(null);
        if (target instanceof SerialAnalyserController) {
            staticPopupItems.add(new XJMenuItem(new MakeConditionalAction(), sListenerProxy));
        }
        staticPopupItems.add(new XJMenuItem(new DumpToFileAction(), sListenerProxy));
        staticPopupItems.add(new XJMenuItem(new ExportApplicationAction(), sListenerProxy));
    }
}
Also used : LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) Document(gate.Document) IndexedCorpus(gate.creole.ir.IndexedCorpus) Corpus(gate.Corpus) AnnotationSchema(gate.creole.AnnotationSchema) SerialAnalyserController(gate.creole.SerialAnalyserController) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) JComponent(javax.swing.JComponent) SerialAnalyserController(gate.creole.SerialAnalyserController) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) CorpusController(gate.CorpusController) ConditionalController(gate.creole.ConditionalController) XJMenuItem(gate.swing.XJMenuItem)

Example 5 with Controller

use of gate.Controller in project gate-core by GateNLP.

the class ControllerMetadataViewer method setTarget.

@Override
public void setTarget(Object target) {
    if (target == null)
        throw new NullPointerException("received a null target");
    if (!(target instanceof Controller))
        throw new IllegalArgumentException("not a controller");
    Controller controller = (Controller) target;
    if (!controller.getFeatures().containsKey("gate.app.MetadataURL"))
        throw new IllegalArgumentException("no gate.app.MetadataURL feature");
    try {
        URL metadata = (URL) controller.getFeatures().get("gate.app.MetadataURL");
        URL longDesc = new URL(metadata, "long-desc.html");
        URL iconDesc = new URL(metadata, "icon.png");
        Document document = builder.parse(metadata.openStream());
        Node text = document.getDocumentElement().getElementsByTagName("pipeline-name").item(0).getFirstChild();
        Font font = Gate.getUserConfig().getFont(GateConstants.TEXT_COMPONENTS_FONT);
        StringBuilder page = new StringBuilder();
        page.append("<!DOCTYPE html>");
        page.append("<html>");
        page.append("<head>");
        page.append("<style type='text/css'>body { font-family: ").append(font.getFamily()).append("; font-size: ").append(font.getSize()).append("pt }</style>");
        page.append("</head>");
        page.append("<body>");
        page.append("<h1><img style='vertical-align: middle;' src='").append(StringEscapeUtils.escapeHtml(iconDesc.toString())).append("'/> ").append(StringEscapeUtils.escapeHtml(text.getTextContent())).append("</h1>");
        page.append(IOUtils.toString(longDesc, "UTF-8"));
        page.append("</body></html>");
        // parse using NekoHTML
        HTMLConfiguration config = new HTMLConfiguration();
        // Force element names to lower case to match XHTML requirements
        // as that is what Flying Saucer expects
        config.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
        DOMParser htmlParser = new DOMParser(config);
        htmlParser.parse(new InputSource(new StringReader(page.toString())));
        display.setDocument(htmlParser.getDocument(), longDesc.toString());
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) Node(org.w3c.dom.Node) HTMLConfiguration(org.cyberneko.html.HTMLConfiguration) Controller(gate.Controller) Document(org.w3c.dom.Document) URL(java.net.URL) Font(java.awt.Font) ResourceInstantiationException(gate.creole.ResourceInstantiationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) StringReader(java.io.StringReader) DOMParser(org.apache.xerces.parsers.DOMParser)

Aggregations

Controller (gate.Controller)8 ProcessingResource (gate.ProcessingResource)5 ConditionalSerialAnalyserController (gate.creole.ConditionalSerialAnalyserController)5 LanguageResource (gate.LanguageResource)3 VisualResource (gate.VisualResource)3 PackagedController (gate.creole.PackagedController)3 JComponent (javax.swing.JComponent)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 CorpusController (gate.CorpusController)2 Resource (gate.Resource)2 ConditionalController (gate.creole.ConditionalController)2 ResourceInstantiationException (gate.creole.ResourceInstantiationException)2 SerialAnalyserController (gate.creole.SerialAnalyserController)2 XJMenuItem (gate.swing.XJMenuItem)2 Corpus (gate.Corpus)1 Document (gate.Document)1 FeatureMap (gate.FeatureMap)1 AnnotationSchema (gate.creole.AnnotationSchema)1 ResourceData (gate.creole.ResourceData)1 IndexedCorpus (gate.creole.ir.IndexedCorpus)1