use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class AnnotationEditor method placeDialog.
/**
* Finds the best location for the editor dialog for a given span of text.
*/
@Override
public void placeDialog(int start, int end) {
if (popupWindow.isVisible() && pinnedButton.isSelected()) {
// just resize
Point where = popupWindow.getLocation();
popupWindow.pack();
if (where != null) {
popupWindow.setLocation(where);
}
} else {
// calculate position
try {
Rectangle startRect = owner.getTextComponent().modelToView(start);
Rectangle endRect = owner.getTextComponent().modelToView(end);
Point topLeft = owner.getTextComponent().getLocationOnScreen();
int x = topLeft.x + startRect.x;
int y = topLeft.y + endRect.y + endRect.height;
// make sure the window doesn't start lower
// than the end of the visible rectangle
Rectangle visRect = owner.getTextComponent().getVisibleRect();
int maxY = topLeft.y + visRect.y + visRect.height;
// make sure window doesn't get off-screen
popupWindow.pack();
// responding to changed orientation
if (currentOrientation == ComponentOrientation.RIGHT_TO_LEFT) {
x = x - popupWindow.getSize().width;
if (x < 0)
x = 0;
}
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
boolean revalidate = false;
if (popupWindow.getSize().width > screenSize.width) {
popupWindow.setSize(screenSize.width, popupWindow.getSize().height);
revalidate = true;
}
if (popupWindow.getSize().height > screenSize.height) {
popupWindow.setSize(popupWindow.getSize().width, screenSize.height);
revalidate = true;
}
if (revalidate)
popupWindow.validate();
// calculate max X
int maxX = screenSize.width - popupWindow.getSize().width;
// calculate max Y
if (maxY + popupWindow.getSize().height > screenSize.height) {
maxY = screenSize.height - popupWindow.getSize().height;
}
// correct position
if (y > maxY)
y = maxY;
if (x > maxX)
x = maxX;
popupWindow.setLocation(x, y);
} catch (BadLocationException ble) {
// this should never occur
throw new GateRuntimeException(ble);
}
}
if (!popupWindow.isVisible())
popupWindow.setVisible(true);
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class SerialDatastoreViewer method initGuiComponents.
protected void initGuiComponents() {
treeRoot = new DefaultMutableTreeNode(datastore.getName(), true);
treeModel = new DefaultTreeModel(treeRoot, true);
mainTree = new JTree();
mainTree.setModel(treeModel);
mainTree.setExpandsSelectedPaths(true);
mainTree.expandPath(new TreePath(treeRoot));
mainTree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillCollapse(TreeExpansionEvent e) {
// ignore these events as we don't care about collapsing trees, timmmmmmmmmber!
}
@Override
public void treeWillExpand(TreeExpansionEvent e) {
TreePath path = e.getPath();
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
if (node.getChildCount() == 0 && node.getUserObject() instanceof DSType) {
DSType dsType = (DSType) node.getUserObject();
if (dsType.expanded)
return;
node.removeAllChildren();
try {
Iterator<String> lrIDsIter = datastore.getLrIds(dsType.type).iterator();
while (lrIDsIter.hasNext()) {
String id = lrIDsIter.next();
DSEntry entry = new DSEntry(datastore.getLrName(id), id, dsType.type);
DefaultMutableTreeNode lrNode = new DefaultMutableTreeNode(entry, false);
treeModel.insertNodeInto(lrNode, node, node.getChildCount());
node.add(lrNode);
}
dsType.expanded = true;
} catch (PersistenceException pe) {
throw new GateRuntimeException(pe.toString());
}
}
}
});
try {
Iterator<String> lrTypesIter = datastore.getLrTypes().iterator();
CreoleRegister cReg = Gate.getCreoleRegister();
while (lrTypesIter.hasNext()) {
String type = lrTypesIter.next();
ResourceData rData = cReg.get(type);
DSType dsType = new DSType(rData.getName(), type);
DefaultMutableTreeNode node = new DefaultMutableTreeNode(dsType);
treeModel.insertNodeInto(node, treeRoot, treeRoot.getChildCount());
}
} catch (PersistenceException pe) {
throw new GateRuntimeException(pe.toString());
}
DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
selectionModel.setSelectionMode(DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
mainTree.setSelectionModel(selectionModel);
getViewport().setView(mainTree);
popup = new JPopupMenu();
deleteAction = new DeleteAction();
loadAction = new LoadAction();
popup.add(deleteAction);
popup.add(loadAction);
}
use of gate.util.GateRuntimeException 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.util.GateRuntimeException in project gate-core by GateNLP.
the class PRViewer method setTarget.
@Override
public void setTarget(Object target) {
if (target == null)
return;
if (!(target instanceof Resource)) {
throw new GateRuntimeException(this.getClass().getName() + " can only be used to display " + Resource.class.getName() + "\n" + target.getClass().getName() + " is not a " + Resource.class.getName() + "!");
}
Resource pr = (Resource) target;
ResourceData rData = Gate.getCreoleRegister().get(pr.getClass().getName());
if (rData != null) {
editor.init(pr, rData.getParameterList().getInitimeParameters());
} else {
editor.init(pr, null);
}
editor.removeCreoleListenerLink();
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class AnnotationSetsView method initGUI.
@Override
protected void initGUI() {
// get a pointer to the textual view used for highlights
Iterator<DocumentView> centralViewsIter = owner.getCentralViews().iterator();
while (textView == null && centralViewsIter.hasNext()) {
DocumentView aView = centralViewsIter.next();
if (aView instanceof TextualDocumentView)
textView = (TextualDocumentView) aView;
}
textPane = (JTextArea) ((JScrollPane) textView.getGUI()).getViewport().getView();
// get a pointer to the list view
Iterator<DocumentView> horizontalViewsIter = owner.getHorizontalViews().iterator();
while (listView == null && horizontalViewsIter.hasNext()) {
DocumentView aView = horizontalViewsIter.next();
if (aView instanceof AnnotationListView)
listView = (AnnotationListView) aView;
}
// get a pointer to the stack view
horizontalViewsIter = owner.getHorizontalViews().iterator();
while (stackView == null && horizontalViewsIter.hasNext()) {
DocumentView aView = horizontalViewsIter.next();
if (aView instanceof AnnotationStackView)
stackView = (AnnotationStackView) aView;
}
mainTable = new XJTable();
tableModel = new SetsTableModel();
mainTable.setSortable(false);
mainTable.setModel(tableModel);
mainTable.setRowMargin(0);
mainTable.getColumnModel().setColumnMargin(0);
SetsTableCellRenderer cellRenderer = new SetsTableCellRenderer();
mainTable.getColumnModel().getColumn(NAME_COL).setCellRenderer(cellRenderer);
mainTable.getColumnModel().getColumn(SELECTED_COL).setCellRenderer(cellRenderer);
SetsTableCellEditor cellEditor = new SetsTableCellEditor();
mainTable.getColumnModel().getColumn(SELECTED_COL).setCellEditor(cellEditor);
mainTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
mainTable.setColumnSelectionAllowed(false);
mainTable.setRowSelectionAllowed(true);
mainTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
// block autocreation of new columns from now on
mainTable.setAutoCreateColumnsFromModel(false);
mainTable.setTableHeader(null);
mainTable.setShowGrid(false);
mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// the background colour seems to change somewhere when using the GTK+
// look and feel on Linux, so we copy the value now and set it
Color tableBG = mainTable.getBackground();
// make a copy of the value (as the reference gets changed somewhere)
tableBG = new Color(tableBG.getRGB());
mainTable.setBackground(tableBG);
scroller = new JScrollPane(mainTable);
scroller.getViewport().setOpaque(true);
scroller.getViewport().setBackground(tableBG);
try {
annotationEditor = createAnnotationEditor(textView, this);
} catch (ResourceInstantiationException e) {
// this should not really happen
throw new GateRuntimeException("Could not initialise the annotation editor!", e);
}
mainPanel = new JPanel();
mainPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridy = 0;
constraints.gridx = GridBagConstraints.RELATIVE;
constraints.gridwidth = 2;
constraints.weighty = 1;
constraints.weightx = 1;
constraints.fill = GridBagConstraints.BOTH;
mainPanel.add(scroller, constraints);
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.weighty = 0;
newSetNameTextField = new JTextField();
mainPanel.add(newSetNameTextField, constraints);
constraints.weightx = 0;
newSetAction = new NewAnnotationSetAction();
mainPanel.add(new JButton(newSetAction), constraints);
populateUI();
tableModel.fireTableDataChanged();
eventMinder.start();
initListeners();
}
Aggregations