Search in sources :

Example 1 with VisualResource

use of gate.VisualResource 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 2 with VisualResource

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

the class NameBearerHandle method buildViews.

protected void buildViews() {
    viewsBuilt = true;
    fireStatusChanged("Building views...");
    // build the large views
    List<String> largeViewNames = Gate.getCreoleRegister().getLargeVRsForResource(target.getClass().getName());
    if (largeViewNames != null && !largeViewNames.isEmpty()) {
        largeView = new JTabbedPane(JTabbedPane.BOTTOM);
        Iterator<String> classNameIter = largeViewNames.iterator();
        while (classNameIter.hasNext()) {
            try {
                String className = classNameIter.next();
                ResourceData rData = Gate.getCreoleRegister().get(className);
                FeatureMap params = Factory.newFeatureMap();
                FeatureMap features = Factory.newFeatureMap();
                Gate.setHiddenAttribute(features, true);
                VisualResource view = (VisualResource) Factory.createResource(className, params, features);
                try {
                    view.setTarget(target);
                } catch (IllegalArgumentException iae) {
                    // the view cannot display this particular target
                    Factory.deleteResource(view);
                    view = null;
                }
                if (view != null) {
                    view.setHandle(this);
                    ((JTabbedPane) largeView).add((Component) view, rData.getName());
                    // publishers
                    if (view instanceof ActionsPublisher)
                        actionPublishers.add((ActionsPublisher) view);
                }
            } catch (ResourceInstantiationException rie) {
                rie.printStackTrace(Err.getPrintWriter());
            }
        }
        // select the first view by default
        ((JTabbedPane) largeView).setSelectedIndex(0);
    }
    // build the small views
    List<String> smallViewNames = Gate.getCreoleRegister().getSmallVRsForResource(target.getClass().getName());
    if (smallViewNames != null && !smallViewNames.isEmpty()) {
        smallView = new JTabbedPane(JTabbedPane.BOTTOM);
        Iterator<String> classNameIter = smallViewNames.iterator();
        while (classNameIter.hasNext()) {
            try {
                String className = classNameIter.next();
                ResourceData rData = Gate.getCreoleRegister().get(className);
                FeatureMap params = Factory.newFeatureMap();
                FeatureMap features = Factory.newFeatureMap();
                Gate.setHiddenAttribute(features, true);
                VisualResource view = (VisualResource) Factory.createResource(className, params, features);
                try {
                    view.setTarget(target);
                } catch (IllegalArgumentException iae) {
                    // the view cannot display this particular target
                    Factory.deleteResource(view);
                    view = null;
                }
                if (view != null) {
                    view.setHandle(this);
                    ((JTabbedPane) smallView).add((Component) view, rData.getName());
                    if (view instanceof ActionsPublisher)
                        actionPublishers.add((ActionsPublisher) view);
                }
            } catch (ResourceInstantiationException rie) {
                rie.printStackTrace(Err.getPrintWriter());
            }
        }
        ((JTabbedPane) smallView).setSelectedIndex(0);
    }
    fireStatusChanged("Views built!");
    // Add the CTRL +F4 key & action combination to the resource
    JComponent largeView = this.getLargeView();
    if (largeView != null) {
        largeView.getActionMap().put("Close resource", new CloseAction());
        if (target instanceof Controller) {
            largeView.getActionMap().put("Close recursively", new CloseRecursivelyAction());
        }
    /*if(target instanceof gate.TextualDocument) {
        largeView.getActionMap().put("Save As XML", new SaveAsXmlAction());
      }// End if*/
    }
// End if
}
Also used : ResourceData(gate.creole.ResourceData) VisualResource(gate.VisualResource) JTabbedPane(javax.swing.JTabbedPane) JComponent(javax.swing.JComponent) SerialAnalyserController(gate.creole.SerialAnalyserController) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) CorpusController(gate.CorpusController) ConditionalController(gate.creole.ConditionalController) ResourceInstantiationException(gate.creole.ResourceInstantiationException) FeatureMap(gate.FeatureMap)

Aggregations

Controller (gate.Controller)2 VisualResource (gate.VisualResource)2 ConditionalSerialAnalyserController (gate.creole.ConditionalSerialAnalyserController)2 CorpusController (gate.CorpusController)1 FeatureMap (gate.FeatureMap)1 LanguageResource (gate.LanguageResource)1 ProcessingResource (gate.ProcessingResource)1 Resource (gate.Resource)1 ConditionalController (gate.creole.ConditionalController)1 PackagedController (gate.creole.PackagedController)1 ResourceData (gate.creole.ResourceData)1 ResourceInstantiationException (gate.creole.ResourceInstantiationException)1 SerialAnalyserController (gate.creole.SerialAnalyserController)1 JComponent (javax.swing.JComponent)1 JTabbedPane (javax.swing.JTabbedPane)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1