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);
//
}
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
}
Aggregations