Search in sources :

Example 31 with GateRuntimeException

use of gate.util.GateRuntimeException in project gate-core by GateNLP.

the class AnnotationDiffGUI method populateGUI.

protected void populateGUI() {
    try {
        documents = Gate.getCreoleRegister().getAllInstances("gate.Document");
    } catch (GateException ge) {
        throw new GateRuntimeException(ge);
    }
    List<String> documentNames = new ArrayList<String>(documents.size());
    for (Resource document : documents) {
        documentNames.add(document.getName());
    }
    Object keyDocSelectedItem = keyDocCombo.getSelectedItem();
    Object resDocSelectedItem = resDocCombo.getSelectedItem();
    keyDocCombo.setModel(new DefaultComboBoxModel<String>(documentNames.toArray(new String[documentNames.size()])));
    resDocCombo.setModel(new DefaultComboBoxModel<String>(documentNames.toArray(new String[documentNames.size()])));
    if (!documents.isEmpty()) {
        keyDocCombo.setSelectedItem(keyDocSelectedItem);
        if (keyDocCombo.getSelectedIndex() == -1) {
            keyDocCombo.setSelectedIndex(0);
        }
        resDocCombo.setSelectedItem(resDocSelectedItem);
        if (resDocCombo.getSelectedIndex() == -1) {
            resDocCombo.setSelectedIndex(0);
        }
        statusLabel.setText(documents.size() + " documents loaded");
        if (annTypeCombo.getSelectedItem() == null) {
            statusLabel.setText(statusLabel.getText() + ". Choose two annotation sets to compare.");
        }
        statusLabel.setForeground(Color.BLACK);
    } else {
        statusLabel.setText("You must load at least one document.");
        statusLabel.setForeground(Color.RED);
    }
}
Also used : GateException(gate.util.GateException) GateRuntimeException(gate.util.GateRuntimeException) ArrayList(java.util.ArrayList) Resource(gate.Resource)

Example 32 with GateRuntimeException

use of gate.util.GateRuntimeException in project gate-core by GateNLP.

the class AnnotationEditor method initGUI.

protected void initGUI() {
    popupWindow = new JWindow(SwingUtilities.getWindowAncestor(owner.getTextComponent())) {

        @Override
        public void pack() {
            // than the main frame
            if (isVisible()) {
                int maxHeight = MainFrame.getInstance().getHeight();
                int otherHeight = getHeight() - featuresScroller.getHeight();
                maxHeight -= otherHeight;
                if (featuresScroller.getPreferredSize().height > maxHeight) {
                    featuresScroller.setMaximumSize(new Dimension(featuresScroller.getMaximumSize().width, maxHeight));
                    featuresScroller.setPreferredSize(new Dimension(featuresScroller.getPreferredSize().width, maxHeight));
                }
            }
            super.pack();
        }

        @Override
        public void setVisible(boolean b) {
            super.setVisible(b);
            // when the editor is shown put the focus in the type combo box
            if (b) {
                typeCombo.requestFocus();
            }
        }
    };
    JPanel pane = new JPanel();
    pane.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
    pane.setLayout(new GridBagLayout());
    pane.setBackground(UIManager.getLookAndFeelDefaults().getColor("ToolTip.background"));
    popupWindow.setContentPane(pane);
    Insets insets0 = new Insets(0, 0, 0, 0);
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.gridwidth = 1;
    constraints.gridy = 0;
    constraints.gridx = GridBagConstraints.RELATIVE;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.insets = insets0;
    solButton = new JButton();
    solButton.setContentAreaFilled(false);
    solButton.setBorderPainted(false);
    solButton.setMargin(insets0);
    pane.add(solButton, constraints);
    sorButton = new JButton();
    sorButton.setContentAreaFilled(false);
    sorButton.setBorderPainted(false);
    sorButton.setMargin(insets0);
    pane.add(sorButton, constraints);
    delButton = new JButton();
    delButton.setContentAreaFilled(false);
    delButton.setBorderPainted(false);
    delButton.setMargin(insets0);
    constraints.insets = new Insets(0, 20, 0, 20);
    pane.add(delButton, constraints);
    constraints.insets = insets0;
    eolButton = new JButton();
    eolButton.setContentAreaFilled(false);
    eolButton.setBorderPainted(false);
    eolButton.setMargin(insets0);
    pane.add(eolButton, constraints);
    eorButton = new JButton();
    eorButton.setContentAreaFilled(false);
    eorButton.setBorderPainted(false);
    eorButton.setMargin(insets0);
    pane.add(eorButton, constraints);
    pinnedButton = new JToggleButton(MainFrame.getIcon("pin"));
    pinnedButton.setSelectedIcon(MainFrame.getIcon("pin-in"));
    pinnedButton.setSelected(false);
    pinnedButton.setBorderPainted(false);
    pinnedButton.setContentAreaFilled(false);
    constraints.weightx = 1;
    constraints.insets = new Insets(0, 0, 0, 0);
    constraints.anchor = GridBagConstraints.EAST;
    pane.add(pinnedButton, constraints);
    dismissButton = new JButton();
    dismissButton.setBorder(null);
    constraints.anchor = GridBagConstraints.NORTHEAST;
    pane.add(dismissButton, constraints);
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.insets = insets0;
    typeCombo = new JComboBox<String>();
    typeCombo.setEditable(true);
    typeCombo.setBackground(UIManager.getLookAndFeelDefaults().getColor("ToolTip.background"));
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridy = 1;
    constraints.gridwidth = 7;
    constraints.weightx = 1;
    constraints.insets = new Insets(3, 2, 2, 2);
    pane.add(typeCombo, constraints);
    featuresEditor = new FeaturesSchemaEditor();
    featuresEditor.setBackground(UIManager.getLookAndFeelDefaults().getColor("ToolTip.background"));
    try {
        featuresEditor.init();
    } catch (ResourceInstantiationException rie) {
        throw new GateRuntimeException(rie);
    }
    constraints.gridy = 2;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.BOTH;
    featuresScroller = new JScrollPane(featuresEditor);
    pane.add(featuresScroller, constraints);
    // add the search and annotate GUI at the bottom of the annotator editor
    SearchAndAnnotatePanel searchPanel = new SearchAndAnnotatePanel(pane.getBackground(), this, popupWindow);
    constraints.insets = new Insets(0, 0, 0, 0);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.gridx = 0;
    constraints.gridy = GridBagConstraints.RELATIVE;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.gridheight = GridBagConstraints.REMAINDER;
    constraints.weightx = 0.0;
    constraints.weighty = 0.0;
    pane.add(searchPanel, constraints);
    popupWindow.pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JWindow(javax.swing.JWindow) JButton(javax.swing.JButton) FeaturesSchemaEditor(gate.gui.FeaturesSchemaEditor) Dimension(java.awt.Dimension) ResourceInstantiationException(gate.creole.ResourceInstantiationException) JToggleButton(javax.swing.JToggleButton) GateRuntimeException(gate.util.GateRuntimeException) SearchAndAnnotatePanel(gate.gui.annedit.SearchAndAnnotatePanel)

Example 33 with GateRuntimeException

use of gate.util.GateRuntimeException 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();
        }
    }
}
Also used : LanguageResource(gate.LanguageResource) CorpusController(gate.CorpusController) GateRuntimeException(gate.util.GateRuntimeException) ProcessingResource(gate.ProcessingResource) Corpus(gate.Corpus)

Example 34 with GateRuntimeException

use of gate.util.GateRuntimeException in project gate-core by GateNLP.

the class SearchExpressionsAction method modifySearchExpression.

private void modifySearchExpression(String modification, JTextField textField) {
    if (modification == null) {
        return;
    }
    int p = textField.getCaretPosition();
    int s1 = textField.getSelectionStart();
    int s2 = textField.getSelectionEnd();
    try {
        if (modification.equals("Number")) {
            textField.setText("\\b[\\p{N}][\\p{N},.]*\\b");
        } else if (modification.equals("Person")) {
            textField.setText("\\p{Lu}\\p{L}+, \\p{Lu}\\.(?: \\p{Lu}\\.)*");
        } else if (modification.equals("Either the selection or X")) {
            textField.getDocument().insertString(s1, "(?:", null);
            textField.getDocument().insertString(s2 + 3, ")|(?:X)", null);
        } else if (modification.equals("Once or not at all")) {
            textField.getDocument().insertString(s1, "(?:", null);
            textField.getDocument().insertString(s2 + 3, ")?", null);
        } else if (modification.equals("Zero or more times")) {
            textField.getDocument().insertString(s1, "(?:", null);
            textField.getDocument().insertString(s2 + 3, ")*", null);
        } else if (modification.equals("One or more times")) {
            textField.getDocument().insertString(s1, "(?:", null);
            textField.getDocument().insertString(s2 + 3, ")+", null);
        } else if (modification.equals("Capturing group")) {
            textField.getDocument().insertString(s1, "(?:", null);
            textField.getDocument().insertString(s2 + 3, ")", null);
        } else if (modification.equals("Non-capturing group")) {
            textField.getDocument().insertString(s1, "(?:", null);
            textField.getDocument().insertString(s2 + 3, ")", null);
        } else if (modification.equals("Any character")) {
            textField.getDocument().insertString(p, ".", null);
        } else if (modification.equals("The beginning of a line")) {
            textField.getDocument().insertString(p, "^", null);
        } else if (modification.equals("The end of a line")) {
            textField.getDocument().insertString(p, "$", null);
        } else if (modification.equals("Any character except Category")) {
            textField.getDocument().insertString(p, "\\P{Category}", null);
        } else if (modification.equals("Category1 and/or Category2")) {
            textField.getDocument().insertString(p, "[\\p{Category1}\\p{Category2}]", null);
        } else if (modification.equals("Category1 and Category2")) {
            textField.getDocument().insertString(p, "[\\p{Category1}&&\\p{Category2}]", null);
        } else if (modification.equals("All letters")) {
            textField.getDocument().insertString(p, "\\p{L}", null);
        } else if (modification.equals("Letter uppercase")) {
            textField.getDocument().insertString(p, "\\p{Lu}", null);
        } else if (modification.equals("Letter lowercase")) {
            textField.getDocument().insertString(p, "\\p{Ll}", null);
        } else if (modification.equals("Letter titlecase")) {
            textField.getDocument().insertString(p, "\\p{Lt}", null);
        } else if (modification.equals("Letter modifier")) {
            textField.getDocument().insertString(p, "\\p{Lm}", null);
        } else if (modification.equals("Letter other")) {
            textField.getDocument().insertString(p, "\\p{Lo}", null);
        } else if (modification.equals("All Marks")) {
            textField.getDocument().insertString(p, "\\p{M}", null);
        } else if (modification.equals("Mark nonspacing")) {
            textField.getDocument().insertString(p, "\\p{Mn}", null);
        } else if (modification.equals("Mark spacing combining")) {
            textField.getDocument().insertString(p, "\\p{Mc}", null);
        } else if (modification.equals("Mark enclosing")) {
            textField.getDocument().insertString(p, "\\p{Me}", null);
        } else if (modification.equals("All Numbers")) {
            textField.getDocument().insertString(p, "\\p{N}", null);
        } else if (modification.equals("Number decimal digit")) {
            textField.getDocument().insertString(p, "\\p{Nd}", null);
        } else if (modification.equals("Number letter")) {
            textField.getDocument().insertString(p, "\\p{Nl}", null);
        } else if (modification.equals("Number other")) {
            textField.getDocument().insertString(p, "\\p{No}", null);
        } else if (modification.equals("All separators")) {
            textField.getDocument().insertString(p, "\\p{Z}", null);
        } else if (modification.equals("Separator space")) {
            textField.getDocument().insertString(p, "\\p{Zs}", null);
        } else if (modification.equals("Separator line")) {
            textField.getDocument().insertString(p, "\\p{Zl}", null);
        } else if (modification.equals("Separator paragraph")) {
            textField.getDocument().insertString(p, "\\p{Zp}", null);
        } else if (modification.equals("All others")) {
            textField.getDocument().insertString(p, "\\p{C}", null);
        } else if (modification.equals("Other control")) {
            textField.getDocument().insertString(p, "\\p{Cc}", null);
        } else if (modification.equals("Other format")) {
            textField.getDocument().insertString(p, "\\p{Cf}", null);
        } else if (modification.equals("Other surrogate")) {
            textField.getDocument().insertString(p, "\\p{Cs}", null);
        } else if (modification.equals("Other private use")) {
            textField.getDocument().insertString(p, "\\p{Co}", null);
        } else if (modification.equals("Other not assigned")) {
            textField.getDocument().insertString(p, "\\p{Cn}", null);
        } else if (modification.equals("All punctuations")) {
            textField.getDocument().insertString(p, "\\p{P}", null);
        } else if (modification.equals("Punctuation connector")) {
            textField.getDocument().insertString(p, "\\p{Pc}", null);
        } else if (modification.equals("Punctuation dash")) {
            textField.getDocument().insertString(p, "\\p{Pd}", null);
        } else if (modification.equals("Punctuation open")) {
            textField.getDocument().insertString(p, "\\p{Ps}", null);
        } else if (modification.equals("Punctuation close")) {
            textField.getDocument().insertString(p, "\\p{Pe}", null);
        } else if (modification.equals("Punctuation initial quote")) {
            textField.getDocument().insertString(p, "\\p{Pi}", null);
        } else if (modification.equals("Punctuation final quote")) {
            textField.getDocument().insertString(p, "\\p{Pf}", null);
        } else if (modification.equals("Punctuation other")) {
            textField.getDocument().insertString(p, "\\p{Po}", null);
        } else if (modification.equals("All symbols")) {
            textField.getDocument().insertString(p, "\\p{S}", null);
        } else if (modification.equals("Symbol math")) {
            textField.getDocument().insertString(p, "\\p{Sm}", null);
        } else if (modification.equals("Symbol currency")) {
            textField.getDocument().insertString(p, "\\p{Sc}", null);
        } else if (modification.equals("Symbol modifier")) {
            textField.getDocument().insertString(p, "\\p{Sk}", null);
        } else if (modification.equals("Symbol other")) {
            textField.getDocument().insertString(p, "\\p{So}", null);
        }
    } catch (BadLocationException e) {
        // should never happend
        throw new GateRuntimeException(e);
    }
    textField.requestFocus();
}
Also used : GateRuntimeException(gate.util.GateRuntimeException) BadLocationException(javax.swing.text.BadLocationException)

Example 35 with GateRuntimeException

use of gate.util.GateRuntimeException in project gate-core by GateNLP.

the class AnnotationEditor method initListeners.

protected void initListeners() {
    // resize the window when the table changes.
    featuresEditor.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            // the table has changed size -> resize the window too!
            popupWindow.pack();
        }
    });
    KeyAdapter keyAdapter = new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            hideTimer.stop();
        }
    };
    typeCombo.getEditor().getEditorComponent().addKeyListener(keyAdapter);
    MouseListener windowMouseListener = new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent evt) {
            hideTimer.stop();
        }

        // allow a JWindow to be dragged with a mouse
        @Override
        public void mousePressed(MouseEvent me) {
            pressed = me;
        }
    };
    MouseMotionListener windowMouseMotionListener = new MouseMotionAdapter() {

        Point location;

        // allow a JWindow to be dragged with a mouse
        @Override
        public void mouseDragged(MouseEvent me) {
            location = popupWindow.getLocation(location);
            int x = location.x - pressed.getX() + me.getX();
            int y = location.y - pressed.getY() + me.getY();
            popupWindow.setLocation(x, y);
            pinnedButton.setSelected(true);
        }
    };
    popupWindow.getRootPane().addMouseListener(windowMouseListener);
    popupWindow.getRootPane().addMouseMotionListener(windowMouseMotionListener);
    InputMap inputMap = ((JComponent) popupWindow.getContentPane()).getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    actionMap = ((JComponent) popupWindow.getContentPane()).getActionMap();
    // add the key-action bindings of this Component to the parent window
    solAction = new StartOffsetLeftAction("", MainFrame.getIcon("extend-left"), SOL_DESC, KeyEvent.VK_LEFT);
    solButton.setAction(solAction);
    setShortCuts(inputMap, SOL_KEY_STROKES, "solAction");
    actionMap.put("solAction", solAction);
    sorAction = new StartOffsetRightAction("", MainFrame.getIcon("extend-right"), SOR_DESC, KeyEvent.VK_RIGHT);
    sorButton.setAction(sorAction);
    setShortCuts(inputMap, SOR_KEY_STROKES, "sorAction");
    actionMap.put("sorAction", sorAction);
    delAction = new DeleteAnnotationAction("", MainFrame.getIcon("remove-annotation"), "Delete the annotation", KeyEvent.VK_DELETE);
    delButton.setAction(delAction);
    inputMap.put(KeyStroke.getKeyStroke("alt DELETE"), "delAction");
    actionMap.put("delAction", delAction);
    eolAction = new EndOffsetLeftAction("", MainFrame.getIcon("extend-left"), EOL_DESC, KeyEvent.VK_LEFT);
    eolButton.setAction(eolAction);
    setShortCuts(inputMap, EOL_KEY_STROKES, "eolAction");
    actionMap.put("eolAction", eolAction);
    eorAction = new EndOffsetRightAction("", MainFrame.getIcon("extend-right"), EOR_DESC, KeyEvent.VK_RIGHT);
    eorButton.setAction(eorAction);
    setShortCuts(inputMap, EOR_KEY_STROKES, "eorAction");
    actionMap.put("eorAction", eorAction);
    pinnedButton.setToolTipText("<html>Press to pin window in place" + "&nbsp;&nbsp;<font color=#667799><small>Ctrl-P" + "&nbsp;&nbsp;</small></font></html>");
    inputMap.put(KeyStroke.getKeyStroke("control P"), "toggle pin");
    actionMap.put("toggle pin", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            pinnedButton.doClick();
        }
    });
    DismissAction dismissAction = new DismissAction("", null, "Close the window", KeyEvent.VK_ESCAPE);
    dismissButton.setAction(dismissAction);
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "dismissAction");
    inputMap.put(KeyStroke.getKeyStroke("alt ESCAPE"), "dismissAction");
    actionMap.put("dismissAction", dismissAction);
    ApplyAction applyAction = new ApplyAction("Apply", null, "", KeyEvent.VK_ENTER);
    inputMap.put(KeyStroke.getKeyStroke("alt ENTER"), "applyAction");
    actionMap.put("applyAction", applyAction);
    typeCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            String newType = typeCombo.getSelectedItem().toString();
            if (ann == null || ann.getType().equals(newType))
                return;
            // annotation editing
            Integer oldId = ann.getId();
            Annotation oldAnn = ann;
            set.remove(ann);
            try {
                set.add(oldId, oldAnn.getStartNode().getOffset(), oldAnn.getEndNode().getOffset(), newType, oldAnn.getFeatures());
                Annotation newAnn = set.get(oldId);
                // update the selection to the new annotation
                getOwner().selectAnnotation(new AnnotationDataImpl(set, newAnn));
                editAnnotation(newAnn, set);
                owner.annotationChanged(newAnn, set, oldAnn.getType());
            } catch (InvalidOffsetException ioe) {
                throw new GateRuntimeException(ioe);
            }
        }
    });
    hideTimer = new Timer(HIDE_DELAY, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            annotationEditorInstance.setVisible(false);
        }
    });
    hideTimer.setRepeats(false);
    AncestorListener textAncestorListener = new AncestorListener() {

        @Override
        public void ancestorAdded(AncestorEvent event) {
            if (wasShowing) {
                annotationEditorInstance.setVisible(true);
            }
            wasShowing = false;
        }

        @Override
        public void ancestorRemoved(AncestorEvent event) {
            if (isShowing()) {
                wasShowing = true;
                popupWindow.dispose();
            }
        }

        @Override
        public void ancestorMoved(AncestorEvent event) {
        }

        private boolean wasShowing = false;
    };
    owner.getTextComponent().addAncestorListener(textAncestorListener);
}
Also used : ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseMotionListener(java.awt.event.MouseMotionListener) AncestorEvent(javax.swing.event.AncestorEvent) KeyEvent(java.awt.event.KeyEvent) MouseListener(java.awt.event.MouseListener) GateRuntimeException(gate.util.GateRuntimeException) AnnotationDataImpl(gate.gui.annedit.AnnotationDataImpl) AncestorListener(javax.swing.event.AncestorListener) AbstractAction(javax.swing.AbstractAction) ComponentAdapter(java.awt.event.ComponentAdapter) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JComponent(javax.swing.JComponent) InvalidOffsetException(gate.util.InvalidOffsetException) Point(java.awt.Point) Point(java.awt.Point) Annotation(gate.Annotation) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) ActionListener(java.awt.event.ActionListener) Timer(javax.swing.Timer) InputMap(javax.swing.InputMap) ComponentEvent(java.awt.event.ComponentEvent)

Aggregations

GateRuntimeException (gate.util.GateRuntimeException)42 ArrayList (java.util.ArrayList)12 URL (java.net.URL)6 FeatureMap (gate.FeatureMap)5 PersistenceException (gate.persist.PersistenceException)5 GateException (gate.util.GateException)5 Point (java.awt.Point)5 LinkedList (java.util.LinkedList)5 DataStore (gate.DataStore)4 ResourceInstantiationException (gate.creole.ResourceInstantiationException)4 InvalidOffsetException (gate.util.InvalidOffsetException)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 MalformedURLException (java.net.MalformedURLException)4 List (java.util.List)4 JButton (javax.swing.JButton)4 JPanel (javax.swing.JPanel)4 Annotation (gate.Annotation)3 AnnotationSet (gate.AnnotationSet)3 Corpus (gate.Corpus)3