use of gate.CorpusController in project gate-core by GateNLP.
the class SerialControllerEditor method initGuiComponents.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void initGuiComponents() {
// we use a JSplitPane for most of the content, and add the Run button to
// the South area
setLayout(new BorderLayout());
JPanel topSplit = new JPanel();
topSplit.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
constraints.gridy = 0;
loadedPRsTableModel = new LoadedPRsTableModel();
loadedPRsTable = new XJTable();
loadedPRsTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
loadedPRsTable.setSortable(false);
loadedPRsTable.setModel(loadedPRsTableModel);
loadedPRsTable.setDragEnabled(true);
loadedPRsTable.setDefaultRenderer(ProcessingResource.class, new ResourceRenderer());
// create a renderer that doesn't mind being extended horizontally.
loadedPRsTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer() {
@Override
public Dimension getMaximumSize() {
// we don't mind being extended horizontally
Dimension dim = super.getMaximumSize();
if (dim != null) {
dim.width = Integer.MAX_VALUE;
setMaximumSize(dim);
}
return dim;
}
@Override
public Dimension getMinimumSize() {
// we don't like being squashed!
return getPreferredSize();
}
});
final int width1 = new JLabel("Loaded Processing resources").getPreferredSize().width + 30;
JScrollPane scroller = new JScrollPane() {
@Override
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
dim.width = Math.max(dim.width, width1);
return dim;
}
@Override
public Dimension getMinimumSize() {
Dimension dim = super.getMinimumSize();
dim.width = Math.max(dim.width, width1);
return dim;
}
};
scroller.getViewport().setView(loadedPRsTable);
scroller.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " Loaded Processing resources "));
// adding a scrollable table
constraints.weightx = 1;
constraints.weighty = 1;
constraints.insets = new Insets(0, 0, 0, 5);
topSplit.add(scroller, constraints);
addButton = new JButton(addPRAction);
addButton.setText("");
addButton.setEnabled(false);
removeButton = new JButton(removePRAction);
removeButton.setText("");
removeButton.setEnabled(false);
Box buttonsBox = Box.createVerticalBox();
buttonsBox.add(Box.createVerticalGlue());
buttonsBox.add(addButton);
buttonsBox.add(Box.createVerticalStrut(5));
buttonsBox.add(removeButton);
buttonsBox.add(Box.createVerticalGlue());
constraints.weightx = 0;
constraints.weighty = 0;
constraints.insets = new Insets(0, 0, 0, 5);
topSplit.add(buttonsBox, constraints);
memberPRsTableModel = new MemberPRsTableModel();
memberPRsTable = new XJTable();
memberPRsTable.setSortable(false);
memberPRsTable.setModel(memberPRsTableModel);
memberPRsTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
memberPRsTable.setDefaultRenderer(ProcessingResource.class, new ResourceRenderer());
memberPRsTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer() {
@Override
public Dimension getMaximumSize() {
// we don't mind being extended horizontally
Dimension dim = super.getMaximumSize();
if (dim != null) {
dim.width = Integer.MAX_VALUE;
setMaximumSize(dim);
}
return dim;
}
@Override
public Dimension getMinimumSize() {
// we don't like being squashed!
return getPreferredSize();
}
});
memberPRsTable.setDefaultRenderer(Icon.class, new IconRenderer());
memberPRsTable.setDragEnabled(true);
final int width2 = new JLabel("Selected Processing resources").getPreferredSize().width + 30;
scroller = new JScrollPane() {
@Override
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
dim.width = Math.max(dim.width, width2);
return dim;
}
@Override
public Dimension getMinimumSize() {
Dimension dim = super.getMinimumSize();
dim.width = Math.max(dim.width, width2);
return dim;
}
};
scroller.getViewport().setView(memberPRsTable);
scroller.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " Selected Processing resources "));
// adding a scrollable table
constraints.weightx = 1;
constraints.weighty = 1;
constraints.insets = new Insets(0, 0, 0, 5);
topSplit.add(scroller, constraints);
moveUpButton = new JButton(MainFrame.getIcon("up"));
moveUpButton.setMnemonic(KeyEvent.VK_UP);
moveUpButton.setToolTipText("Move the selected resources up.");
moveUpButton.setEnabled(false);
moveDownButton = new JButton(MainFrame.getIcon("down"));
moveDownButton.setMnemonic(KeyEvent.VK_DOWN);
moveDownButton.setToolTipText("Move the selected resources down.");
moveDownButton.setEnabled(false);
buttonsBox = Box.createVerticalBox();
buttonsBox.add(Box.createVerticalGlue());
buttonsBox.add(moveUpButton);
buttonsBox.add(Box.createVerticalStrut(5));
buttonsBox.add(moveDownButton);
buttonsBox.add(Box.createVerticalGlue());
// adding a scrollable table
constraints.weightx = 0;
constraints.weighty = 0;
constraints.insets = new Insets(0, 0, 0, 0);
topSplit.add(buttonsBox, constraints);
// =========== BOTTOM Half ===========
JPanel bottomSplit = new JPanel();
bottomSplit.setLayout(new GridBagLayout());
// first row
constraints.gridy = 0;
if (conditionalMode) {
strategyPanel = new JPanel();
strategyPanel.setLayout(new BoxLayout(strategyPanel, BoxLayout.X_AXIS));
strategyPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
runBtnGrp = new ButtonGroup();
yes_RunRBtn = new JRadioButton("Yes", true);
yes_RunRBtn.setHorizontalTextPosition(AbstractButton.LEFT);
runBtnGrp.add(yes_RunRBtn);
no_RunRBtn = new JRadioButton("No", false);
no_RunRBtn.setHorizontalTextPosition(AbstractButton.LEFT);
runBtnGrp.add(no_RunRBtn);
conditional_RunRBtn = new JRadioButton("If value of feature", false);
conditional_RunRBtn.setHorizontalTextPosition(AbstractButton.LEFT);
runBtnGrp.add(conditional_RunRBtn);
featureNameTextField = new JTextField("", 25);
featureNameTextField.setMaximumSize(new Dimension(Integer.MAX_VALUE, featureNameTextField.getPreferredSize().height));
featureValueTextField = new JTextField("", 25);
featureValueTextField.setMaximumSize(new Dimension(Integer.MAX_VALUE, featureValueTextField.getPreferredSize().height));
strategyPanel.add(new JLabel(MainFrame.getIcon("greenBall")));
strategyPanel.add(yes_RunRBtn);
strategyPanel.add(Box.createHorizontalStrut(5));
strategyPanel.add(new JLabel(MainFrame.getIcon("redBall")));
strategyPanel.add(no_RunRBtn);
strategyPanel.add(Box.createHorizontalStrut(5));
strategyPanel.add(new JLabel(MainFrame.getIcon("yellowBall")));
strategyPanel.add(conditional_RunRBtn);
strategyPanel.add(Box.createHorizontalStrut(5));
strategyPanel.add(featureNameTextField);
strategyPanel.add(Box.createHorizontalStrut(5));
strategyPanel.add(new JLabel("is"));
strategyPanel.add(Box.createHorizontalStrut(5));
strategyPanel.add(featureValueTextField);
strategyPanel.add(Box.createHorizontalStrut(5));
strategyBorder = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " No processing resource selected... ");
strategyPanel.setBorder(strategyBorder);
constraints.weightx = 1;
constraints.weighty = 0;
constraints.insets = new Insets(0, 0, 0, 0);
bottomSplit.add(strategyPanel, constraints);
constraints.gridy++;
}
if (corpusControllerMode) {
// we need to add the corpus combo
corpusCombo = new JComboBox(corpusComboModel = new CorporaComboModel());
corpusCombo.setRenderer(new ResourceRenderer());
corpusCombo.setMaximumSize(new Dimension(Integer.MAX_VALUE, corpusCombo.getPreferredSize().height));
Corpus corpus = null;
if (controller instanceof CorpusController) {
corpus = ((CorpusController) controller).getCorpus();
} else {
throw new GateRuntimeException("Controller editor in corpus " + "controller mode " + "but the target controller is not an " + "CorpusController!");
}
if (corpus != null) {
corpusCombo.setSelectedItem(corpus);
} else {
if (corpusCombo.getModel().getSize() > 1)
corpusCombo.setSelectedIndex(1);
else
corpusCombo.setSelectedIndex(0);
}
JPanel horBox = new JPanel();
horBox.setLayout(new BoxLayout(horBox, BoxLayout.X_AXIS));
horBox.setAlignmentX(Component.LEFT_ALIGNMENT);
horBox.add(new JLabel("Corpus:"));
horBox.add(Box.createHorizontalStrut(5));
horBox.add(corpusCombo);
horBox.add(Box.createHorizontalStrut(5));
constraints.weightx = 1;
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.BOTH;
constraints.weighty = 0;
constraints.insets = new Insets(0, 0, 0, 0);
bottomSplit.add(horBox, constraints);
// all the following rows have one element only
constraints.gridwidth = 1;
constraints.gridy++;
}
// if(corpusControllerMode)
parametersPanel = new JPanel();
parametersPanel.setLayout(new BoxLayout(parametersPanel, BoxLayout.Y_AXIS));
parametersPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
parametersBorder = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " No selected processing resource ");
parametersPanel.setBorder(parametersBorder);
parametersEditor = new ResourceParametersEditor();
parametersEditor.init(null, null);
parametersPanel.add(new JScrollPane(parametersEditor));
// parametersPanel.add(parametersEditor, constraints);
constraints.weighty = 1;
constraints.weightx = 1;
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = new Insets(0, 0, 0, 0);
bottomSplit.add(parametersPanel, constraints);
constraints.gridy++;
constraints.weightx = 0;
constraints.weighty = 0;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER;
bottomSplit.add(new JButton(runAction), constraints);
final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topSplit, bottomSplit);
splitPane.addAncestorListener(new AncestorListener() {
@Override
public void ancestorRemoved(AncestorEvent event) {
}
@Override
public void ancestorMoved(AncestorEvent event) {
}
/**
* One-shot ancestor listener that places the divider location on first
* show, and then de-registers self.
*/
@Override
public void ancestorAdded(AncestorEvent event) {
// This seems to work more reliably if queued rather than executed
// directly.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
splitPane.setDividerLocation(0.5);
}
});
splitPane.removeAncestorListener(this);
}
});
add(splitPane, BorderLayout.CENTER);
}
use of gate.CorpusController in project gate-core by GateNLP.
the class SerialControllerEditor method resourceUnloaded.
@Override
public void resourceUnloaded(CreoleEvent e) {
if (Gate.getHiddenAttribute(e.getResource().getFeatures()))
return;
if (e.getResource() instanceof ProcessingResource) {
ProcessingResource pr = (ProcessingResource) e.getResource();
if (controller != null && controller.getPRs().contains(pr)) {
controller.remove(pr);
}
refreshPRLists();
} else if (e.getResource() instanceof LanguageResource) {
if (e.getResource() instanceof Corpus && corpusControllerMode) {
Corpus c = (Corpus) e.getResource();
if (controller instanceof CorpusController) {
if (c == ((CorpusController) controller).getCorpus()) {
// setCorpus(null) is also called in the controller's
// resourceUnloaded(), but we can't be sure which handler is
// called first...
((CorpusController) controller).setCorpus(null);
}
} else {
throw new GateRuntimeException("Controller editor in analyser mode " + "but the target controller is not an " + "analyser!");
}
corpusComboModel.fireDataChanged();
}
}
}
use of gate.CorpusController in project gate-core by GateNLP.
the class CorpusBenchmarkTool method processDocument.
// evaluateMarkedClean
protected void processDocument(Document doc) {
try {
if (application instanceof CorpusController) {
Corpus tempCorpus = Factory.newCorpus("temp");
tempCorpus.add(doc);
((CorpusController) application).setCorpus(tempCorpus);
application.execute();
Factory.deleteResource(tempCorpus);
tempCorpus = null;
} else {
Iterator<ProcessingResource> iter = application.getPRs().iterator();
while (iter.hasNext()) iter.next().setParameterValue("document", doc);
application.execute();
}
} catch (ResourceInstantiationException ex) {
throw (RuntimeException) new RuntimeException("Error executing application: " + ex.getMessage()).initCause(ex);
} catch (ExecutionException ex) {
throw (RuntimeException) new RuntimeException("Error executing application: " + ex.getMessage()).initCause(ex);
}
}
Aggregations