Search in sources :

Example 6 with Controller

use of gate.Controller 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)

Example 7 with Controller

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

the class ControllerPersistence method createObject.

/**
 * Creates a new object from the data contained. This new object is supposed
 * to be a copy for the original object used as source for data extraction.
 */
@SuppressWarnings("unchecked")
@Override
public Object createObject() throws PersistenceException, ResourceInstantiationException {
    Controller controller = (Controller) super.createObject();
    if (controller.getPRs().isEmpty()) {
        prList = PersistenceManager.getTransientRepresentation(prList, resourceName, initParamOverrides);
        controller.setPRs((Collection<ProcessingResource>) prList);
    }
    return controller;
}
Also used : ProcessingResource(gate.ProcessingResource) Controller(gate.Controller)

Example 8 with Controller

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

the class ControllerPersistence method extractDataFromSource.

/**
 * Populates this Persistence with the data that needs to be stored from the
 * original source object.
 */
@Override
public void extractDataFromSource(Object source) throws PersistenceException {
    if (!(source instanceof Controller)) {
        throw new UnsupportedOperationException(getClass().getName() + " can only be used for " + Controller.class.getName() + " objects!\n" + source.getClass().getName() + " is not a " + Controller.class.getName());
    }
    Controller controller = (Controller) source;
    super.extractDataFromSource(source);
    /*prList = new ArrayList(controller.getPRs().size());
    Iterator prIter = controller.getPRs().iterator();

    while(prIter.hasNext()){
      ((List)prList).add(prIter.next());
    }*/
    prList = new ArrayList<ProcessingResource>(controller.getPRs());
    prList = PersistenceManager.getPersistentRepresentation(prList);
}
Also used : ProcessingResource(gate.ProcessingResource) Controller(gate.Controller)

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