Search in sources :

Example 71 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project grafikon by jub77.

the class FloatingWindowsFactory method createTrainsWithConflictsDialog.

private static FloatingWindow createTrainsWithConflictsDialog(final Frame frame, final Mediator mediator, final ApplicationModel model) {
    final TrainsWithConflictsPanel panel = new TrainsWithConflictsPanel();
    panel.addTrainSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                JList<?> list = (JList<?>) e.getSource();
                Wrapper<?> wrapper = (Wrapper<?>) list.getSelectedValue();
                if (wrapper != null) {
                    if (wrapper.getElement() != model.getSelectedTrain()) {
                        model.setSelectedTrain((Train) wrapper.getElement());
                    }
                }
            }
        }
    });
    final FloatingWindow dialog = new FloatingDialog(frame, panel, "dialog.trainconflicts.title", "train.conflicts");
    mediator.addColleague(new ApplicationGTEventColleague() {

        @Override
        public void processTrainEvent(Event event) {
            switch(event.getType()) {
                case SPECIAL:
                    if (event.getData() instanceof SpecialTrainTimeIntervalList) {
                        panel.updateTrain((Train) event.getSource());
                    }
                    break;
                case ATTRIBUTE:
                    if (event.getAttributeChange().checkName(Train.ATTR_NAME)) {
                        panel.refreshTrain((Train) event.getSource());
                    }
                    if (event.getAttributeChange().checkName(Train.ATTR_TECHNOLOGICAL_AFTER, Train.ATTR_TECHNOLOGICAL_BEFORE)) {
                        panel.updateTrain((Train) event.getSource());
                    }
                    break;
                default:
                    break;
            }
        }

        @Override
        public void processTrainDiagramEvent(Event event) {
            switch(event.getType()) {
                case ADDED:
                    if (event.getObject() instanceof Train) {
                        panel.updateTrain((Train) event.getObject());
                    }
                    break;
                case REMOVED:
                    if (event.getObject() instanceof Train) {
                        panel.removeTrain((Train) event.getObject());
                    }
                    break;
                default:
                    break;
            }
        }

        @Override
        public void processApplicationEvent(ApplicationModelEvent event) {
            switch(event.getType()) {
                case SELECTED_TRAIN_CHANGED:
                    panel.updateSelectedTrain((Train) event.getObject());
                    break;
                case SET_DIAGRAM_CHANGED:
                    panel.updateAllTrains(model.getDiagram() != null ? model.getDiagram().getTrains() : null);
                    break;
                default:
                    break;
            }
        }
    });
    return dialog;
}
Also used : Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JList(javax.swing.JList)

Example 72 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project gate-core by GateNLP.

the class CorpusEditor method initListeners.

protected void initListeners() {
    // mouse double-click to open the document
    // context menu to get the actions for the selection
    docTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            processMouseEvent(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                processMouseEvent(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                processMouseEvent(e);
            }
        }

        private void processMouseEvent(MouseEvent e) {
            int row = docTable.rowAtPoint(e.getPoint());
            if (row == -1) {
                return;
            }
            if (e.isPopupTrigger()) {
                // context menu
                if (!docTable.isRowSelected(row)) {
                    // if right click outside the selection then reset selection
                    docTable.getSelectionModel().setSelectionInterval(row, row);
                }
                JPopupMenu popup = new XJPopupMenu();
                popup.add(openDocumentsAction);
                popup.add(removeDocumentsAction);
                popup.show(docTable, e.getPoint().x, e.getPoint().y);
            } else if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() == 2) {
                // open document on double-click
                openDocumentsAction.actionPerformed(null);
            }
        }
    });
    // Enter key opens the selected documents
    docTable.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                openDocumentsAction.actionPerformed(null);
            }
        }
    });
    docTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            // enable/disable buttons according to the selection
            removeDocumentsAction.setEnabled(docTable.getSelectedRowCount() > 0);
            openDocumentsAction.setEnabled(docTable.getSelectedRowCount() > 0);
            moveUpAction.setEnabled(docTable.getSelectedRowCount() > 0 && !docTable.isRowSelected(0));
            moveDownAction.setEnabled(docTable.getSelectedRowCount() > 0 && !docTable.isRowSelected(docTable.getRowCount() - 1));
        }
    });
    Gate.getCreoleRegister().addCreoleListener(new CreoleListener() {

        @Override
        public void resourceLoaded(CreoleEvent e) {
            if (e.getResource() instanceof Document) {
                documentsLoadedCount++;
                changeMessage();
            }
        }

        @Override
        public void resourceUnloaded(CreoleEvent e) {
            if (e.getResource() instanceof Document) {
                documentsLoadedCount--;
                changeMessage();
            }
        }

        @Override
        public void datastoreOpened(CreoleEvent e) {
        /* do nothing */
        }

        @Override
        public void datastoreCreated(CreoleEvent e) {
        /* do nothing */
        }

        @Override
        public void datastoreClosed(CreoleEvent e) {
        /* do nothing */
        }

        @Override
        public void resourceRenamed(Resource resource, String oldName, String newName) {
        /* do nothing */
        }
    });
}
Also used : CreoleEvent(gate.event.CreoleEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) CreoleResource(gate.creole.metadata.CreoleResource) AbstractVisualResource(gate.creole.AbstractVisualResource) XJPopupMenu(gate.swing.XJPopupMenu) ListSelectionListener(javax.swing.event.ListSelectionListener) CreoleListener(gate.event.CreoleListener) XJPopupMenu(gate.swing.XJPopupMenu)

Example 73 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project gate-core by GateNLP.

the class SerialControllerEditor method initListeners.

// initGuiComponents()
protected void initListeners() {
    Gate.getCreoleRegister().addCreoleListener(this);
    this.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            processMouseEvent(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            processMouseEvent(e);
        }

        protected void processMouseEvent(MouseEvent e) {
            if (e.isPopupTrigger()) {
                // context menu
                if (handle != null && handle.getPopup() != null) {
                    handle.getPopup().show(SerialControllerEditor.this, e.getX(), e.getY());
                }
            }
        }
    });
    moveUpButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = memberPRsTable.getSelectedRows();
            if (rows == null || rows.length == 0) {
                JOptionPane.showMessageDialog(SerialControllerEditor.this, "Please select some components to be moved " + "from the list of used components!\n", "GATE", JOptionPane.ERROR_MESSAGE);
            } else {
                // we need to make sure the rows are sorted
                Arrays.sort(rows);
                // get the list of PRs
                for (int row : rows) {
                    if (row > 0) {
                        // move it up
                        List<RunningStrategy> strategies = null;
                        if (conditionalMode) {
                            strategies = new ArrayList<RunningStrategy>(((ConditionalController) controller).getRunningStrategies());
                            RunningStrategy straegy = strategies.remove(row);
                            strategies.add(row - 1, straegy);
                        }
                        ProcessingResource value = controller.remove(row);
                        controller.add(row - 1, value);
                        if (conditionalMode) {
                            ((ConditionalController) controller).setRunningStrategies(strategies);
                            ;
                        }
                    }
                }
                // restore selection
                for (int row : rows) {
                    int newRow;
                    if (row > 0)
                        newRow = row - 1;
                    else
                        newRow = row;
                    memberPRsTable.addRowSelectionInterval(newRow, newRow);
                }
                memberPRsTable.requestFocusInWindow();
            }
        }
    });
    moveDownButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = memberPRsTable.getSelectedRows();
            if (rows == null || rows.length == 0) {
                JOptionPane.showMessageDialog(SerialControllerEditor.this, "Please select some components to be moved " + "from the list of used components!\n", "GATE", JOptionPane.ERROR_MESSAGE);
            } else {
                // we need to make sure the rows are sorted
                Arrays.sort(rows);
                // get the list of PRs
                for (int i = rows.length - 1; i >= 0; i--) {
                    int row = rows[i];
                    if (row < controller.getPRs().size() - 1) {
                        List<RunningStrategy> strategies = null;
                        if (conditionalMode) {
                            strategies = new ArrayList<RunningStrategy>(((ConditionalController) controller).getRunningStrategies());
                            RunningStrategy straegy = strategies.remove(row);
                            strategies.add(row + 1, straegy);
                        }
                        // move it down
                        ProcessingResource value = controller.remove(row);
                        controller.add(row + 1, value);
                        if (conditionalMode) {
                            ((ConditionalController) controller).setRunningStrategies(strategies);
                            ;
                        }
                    }
                }
                // restore selection
                for (int row : rows) {
                    int newRow;
                    if (row < controller.getPRs().size() - 1)
                        newRow = row + 1;
                    else
                        newRow = row;
                    memberPRsTable.addRowSelectionInterval(newRow, newRow);
                }
                memberPRsTable.requestFocusInWindow();
            }
        }
    });
    // mouse click edit the resource
    // mouse double click or context menu add the resource to the application
    loadedPRsTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                processMouseEvent(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                processMouseEvent(e);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            processMouseEvent(e);
        }

        protected void processMouseEvent(MouseEvent e) {
            int row = loadedPRsTable.rowAtPoint(e.getPoint());
            if (row == -1) {
                return;
            }
            if (e.isPopupTrigger()) {
                // context menu
                if (!loadedPRsTable.isRowSelected(row)) {
                    // if right click outside the selection then reset selection
                    loadedPRsTable.getSelectionModel().setSelectionInterval(row, row);
                }
                JPopupMenu popup = new XJPopupMenu();
                popup.add(addPRAction);
                popup.show(loadedPRsTable, e.getPoint().x, e.getPoint().y);
            } else if (e.getID() == MouseEvent.MOUSE_CLICKED) {
                if (e.getClickCount() == 2) {
                    // add selected modules on double click
                    addPRAction.actionPerformed(null);
                }
            }
        }
    });
    // drag and drop support
    loadedPRsTable.setTransferHandler(new TransferHandler() {

        // minimal drag and drop that only call the removePRAction when importing
        String source = "";

        @Override
        public int getSourceActions(JComponent c) {
            return MOVE;
        }

        @Override
        protected Transferable createTransferable(JComponent c) {
            return new StringSelection("loadedPRsTable");
        }

        @Override
        protected void exportDone(JComponent c, Transferable data, int action) {
        }

        @Override
        public boolean canImport(JComponent c, DataFlavor[] flavors) {
            for (DataFlavor flavor : flavors) {
                if (DataFlavor.stringFlavor.equals(flavor)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public boolean importData(JComponent c, Transferable t) {
            if (canImport(c, t.getTransferDataFlavors())) {
                try {
                    source = (String) t.getTransferData(DataFlavor.stringFlavor);
                    if (source.startsWith("memberPRsTable")) {
                        removePRAction.actionPerformed(null);
                        return true;
                    } else {
                        return false;
                    }
                } catch (UnsupportedFlavorException ufe) {
                // just return false later
                } catch (IOException ioe) {
                // just return false later
                }
            }
            return false;
        }
    });
    // mouse click edit the resource
    // mouse double click or context menu remove the resource from the
    // application
    memberPRsTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                processMouseEvent(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                processMouseEvent(e);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            processMouseEvent(e);
        }

        protected void processMouseEvent(MouseEvent e) {
            int row = memberPRsTable.rowAtPoint(e.getPoint());
            if (row == -1) {
                return;
            }
            if (e.isPopupTrigger()) {
                // context menu
                if (!memberPRsTable.isRowSelected(row)) {
                    // if right click outside the selection then reset selection
                    memberPRsTable.getSelectionModel().setSelectionInterval(row, row);
                }
                JPopupMenu popup = new XJPopupMenu();
                popup.add(removePRAction);
                popup.show(memberPRsTable, e.getPoint().x, e.getPoint().y);
            } else if (e.getID() == MouseEvent.MOUSE_CLICKED) {
                if (e.getClickCount() == 2) {
                    // open the double-clicked PR in the main view.
                    Component root = SwingUtilities.getRoot(SerialControllerEditor.this);
                    if (!(root instanceof MainFrame)) {
                        return;
                    }
                    final MainFrame mainFrame = (MainFrame) root;
                    if (controller != null) {
                        ProcessingResource res = controller.getPRs().get(row);
                        if (res != null)
                            mainFrame.select(res);
                    }
                }
            }
        }
    });
    // Drag and drop support
    memberPRsTable.setTransferHandler(new TransferHandler() {

        // minimal drag and drop that only call the addPRAction when importing
        String source = "";

        @Override
        public int getSourceActions(JComponent c) {
            return MOVE;
        }

        @Override
        protected Transferable createTransferable(JComponent c) {
            int[] selectedRows = memberPRsTable.getSelectedRows();
            Arrays.sort(selectedRows);
            return new StringSelection("memberPRsTable" + Arrays.toString(selectedRows));
        }

        @Override
        protected void exportDone(JComponent c, Transferable data, int action) {
        }

        @Override
        public boolean canImport(JComponent c, DataFlavor[] flavors) {
            for (DataFlavor flavor : flavors) {
                if (DataFlavor.stringFlavor.equals(flavor)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public boolean importData(JComponent c, Transferable t) {
            if (!canImport(c, t.getTransferDataFlavors())) {
                return false;
            }
            try {
                source = (String) t.getTransferData(DataFlavor.stringFlavor);
                if (source.startsWith("memberPRsTable")) {
                    int insertion = memberPRsTable.getSelectedRow();
                    int initialInsertion = insertion;
                    List<ProcessingResource> prs = new ArrayList<ProcessingResource>();
                    source = source.replaceFirst("^memberPRsTable\\[", "");
                    source = source.replaceFirst("\\]$", "");
                    String[] selectedRows = source.split(", ");
                    if (Integer.parseInt(selectedRows[0]) < insertion) {
                        insertion++;
                    }
                    // get the list of PRs selected when dragging started
                    for (String row : selectedRows) {
                        if (Integer.parseInt(row) == initialInsertion) {
                            // the user draged the selected rows on themselves, do nothing
                            return false;
                        }
                        prs.add((ProcessingResource) memberPRsTable.getValueAt(Integer.parseInt(row), memberPRsTable.convertColumnIndexToView(1)));
                        if (Integer.parseInt(row) < initialInsertion) {
                            insertion--;
                        }
                    }
                    // remove the PRs selected when dragging started
                    for (ProcessingResource pr : prs) {
                        controller.remove(pr);
                    }
                    // add the PRs at the insertion point
                    for (ProcessingResource pr : prs) {
                        controller.add(insertion, pr);
                        insertion++;
                    }
                    // select the moved PRs
                    memberPRsTable.addRowSelectionInterval(insertion - selectedRows.length, insertion - 1);
                    return true;
                } else if (source.equals("loadedPRsTable")) {
                    addPRAction.actionPerformed(null);
                    return true;
                } else {
                    return false;
                }
            } catch (UnsupportedFlavorException ufe) {
                return false;
            } catch (IOException ioe) {
                return false;
            }
        }
    });
    loadedPRsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            // disable Add button if no selection
            addButton.setEnabled(loadedPRsTable.getSelectedRowCount() > 0);
        }
    });
    memberPRsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            // disable Remove and Move buttons if no selection
            removeButton.setEnabled(memberPRsTable.getSelectedRowCount() > 0);
            moveUpButton.setEnabled(memberPRsTable.getSelectedRowCount() > 0 && !memberPRsTable.isRowSelected(0));
            moveDownButton.setEnabled(memberPRsTable.getSelectedRowCount() > 0 && !memberPRsTable.isRowSelected(memberPRsTable.getRowCount() - 1));
            // update the parameters & strategy editors
            if (memberPRsTable.getSelectedRowCount() == 1) {
                // only one selection
                selectPR(memberPRsTable.getSelectedRow());
            } else {
                // clean up UI
                selectPR(-1);
            }
        }
    });
    if (conditionalMode) {
        /**
         * A listener called when the selection state changes for any of the
         * execution mode radio buttons. We use selection changes rather than
         * action listeners, as the change of state may not be as results of an
         * action (e.g. editing one of the text fields, changes the selection).
         */
        ItemListener strategyModeListener = new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                if (selectedPRRunStrategy != null) {
                    if (selectedPRRunStrategy instanceof AnalyserRunningStrategy) {
                        AnalyserRunningStrategy strategy = (AnalyserRunningStrategy) selectedPRRunStrategy;
                        if (yes_RunRBtn.isSelected()) {
                            strategy.setRunMode(RunningStrategy.RUN_ALWAYS);
                        } else if (no_RunRBtn.isSelected()) {
                            strategy.setRunMode(RunningStrategy.RUN_NEVER);
                        } else if (conditional_RunRBtn.isSelected()) {
                            strategy.setRunMode(RunningStrategy.RUN_CONDITIONAL);
                        }
                    } else if (selectedPRRunStrategy instanceof UnconditionalRunningStrategy) {
                        UnconditionalRunningStrategy strategy = (UnconditionalRunningStrategy) selectedPRRunStrategy;
                        if (yes_RunRBtn.isSelected()) {
                            strategy.shouldRun(true);
                        } else if (no_RunRBtn.isSelected()) {
                            strategy.shouldRun(false);
                        }
                    }
                }
                // some icons may have changed!
                memberPRsTable.repaint();
            }
        };
        yes_RunRBtn.addItemListener(strategyModeListener);
        no_RunRBtn.addItemListener(strategyModeListener);
        conditional_RunRBtn.addItemListener(strategyModeListener);
        featureNameTextField.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {

            @Override
            public void insertUpdate(javax.swing.event.DocumentEvent e) {
                changeOccured(e);
            }

            @Override
            public void removeUpdate(javax.swing.event.DocumentEvent e) {
                changeOccured(e);
            }

            @Override
            public void changedUpdate(javax.swing.event.DocumentEvent e) {
                changeOccured(e);
            }

            protected void changeOccured(javax.swing.event.DocumentEvent e) {
                if (selectedPRRunStrategy != null && selectedPRRunStrategy instanceof AnalyserRunningStrategy) {
                    AnalyserRunningStrategy strategy = (AnalyserRunningStrategy) selectedPRRunStrategy;
                    strategy.setFeatureName(featureNameTextField.getText());
                }
                // editing the textfield changes the running strategy to conditional
                conditional_RunRBtn.setSelected(true);
            }
        });
        featureValueTextField.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {

            @Override
            public void insertUpdate(javax.swing.event.DocumentEvent e) {
                changeOccured(e);
            }

            @Override
            public void removeUpdate(javax.swing.event.DocumentEvent e) {
                changeOccured(e);
            }

            @Override
            public void changedUpdate(javax.swing.event.DocumentEvent e) {
                changeOccured(e);
            }

            protected void changeOccured(javax.swing.event.DocumentEvent e) {
                if (selectedPRRunStrategy != null && selectedPRRunStrategy instanceof AnalyserRunningStrategy) {
                    AnalyserRunningStrategy strategy = (AnalyserRunningStrategy) selectedPRRunStrategy;
                    strategy.setFeatureValue(featureValueTextField.getText());
                }
                // editing the textfield changes the running strategy to conditional
                conditional_RunRBtn.setSelected(true);
            }
        });
    }
    if (corpusControllerMode) {
        corpusCombo.addPopupMenuListener(new PopupMenuListener() {

            @Override
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                corpusComboModel.fireDataChanged();
            }

            @Override
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            }

            @Override
            public void popupMenuCanceled(PopupMenuEvent e) {
            }
        });
    }
    addAncestorListener(new AncestorListener() {

        @Override
        public void ancestorAdded(AncestorEvent event) {
            // every time the user switches back to this view, we check
            // whether another controller has just included this one
            loadedPRsTableModel.fireTableDataChanged();
            memberPRsTableModel.fireTableDataChanged();
        }

        @Override
        public void ancestorRemoved(AncestorEvent event) {
        /* do nothing */
        }

        @Override
        public void ancestorMoved(AncestorEvent event) {
        /* do nothing */
        }
    });
    // binds F3 key to the run action
    getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("F3"), "Run");
    getActionMap().put("Run", runAction);
}
Also used : ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) ArrayList(java.util.ArrayList) ProcessingResource(gate.ProcessingResource) ListSelectionEvent(javax.swing.event.ListSelectionEvent) PopupMenuEvent(javax.swing.event.PopupMenuEvent) AncestorEvent(javax.swing.event.AncestorEvent) StringSelection(java.awt.datatransfer.StringSelection) DataFlavor(java.awt.datatransfer.DataFlavor) XJPopupMenu(gate.swing.XJPopupMenu) AncestorListener(javax.swing.event.AncestorListener) List(java.util.List) ArrayList(java.util.ArrayList) Component(java.awt.Component) JComponent(javax.swing.JComponent) MouseEvent(java.awt.event.MouseEvent) RunningStrategy(gate.creole.RunningStrategy) AnalyserRunningStrategy(gate.creole.AnalyserRunningStrategy) UnconditionalRunningStrategy(gate.creole.RunningStrategy.UnconditionalRunningStrategy) MouseAdapter(java.awt.event.MouseAdapter) JComponent(javax.swing.JComponent) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) XJPopupMenu(gate.swing.XJPopupMenu) JPopupMenu(javax.swing.JPopupMenu) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) TransferHandler(javax.swing.TransferHandler) ItemListener(java.awt.event.ItemListener) AnalyserRunningStrategy(gate.creole.AnalyserRunningStrategy) UnconditionalRunningStrategy(gate.creole.RunningStrategy.UnconditionalRunningStrategy)

Example 74 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project gate-core by GateNLP.

the class SearchExpressionsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent arg0) {
    String[] values1 = { "Number", "Person" };
    String[] values2 = { "Any character", "The beginning of a line", "The end of a line", "All letters", "Letter uppercase", "Letter lowercase", "Letter titlecase", "Letter modifier", "Letter other", "All Numbers", "Number decimal digit", "Number letter", "Number other", "All punctuations", "Punctuation connector", "Punctuation dash", "Punctuation open", "Punctuation close", "Punctuation initial quote", "Punctuation final quote", "Punctuation other", "All symbols", "Symbol math", "Symbol currency", "Symbol modifier", "Symbol other", "All separators", "Separator space", "Separator line", "Separator paragraph", "All Marks", "Mark nonspacing", "Mark spacing combining", "Mark enclosing", "All others", "Other control", "Other format", "Other surrogate", "Other private use", "Other not assigned", "Any character except Category", "Category1 and/or Category2", "Category1 and Category2" };
    String[] values3 = { "Either the selection or X", "Once or not at all", "Zero or more times", "One or more times", "Capturing group", "Non-capturing group" };
    final JTextField modifiedTextField = new JTextField(25);
    modifiedTextField.setText(sourceTextField.getText());
    JPanel vspace1 = new JPanel();
    vspace1.setSize(0, 5);
    final JList<String> list1 = new JList<String>(values1);
    list1.setVisibleRowCount(Math.min(10, values1.length));
    list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane jsp1 = new JScrollPane(list1);
    final JButton b1 = new JButton("Replace search expression");
    b1.setEnabled(false);
    JPanel vspace2 = new JPanel();
    vspace2.setSize(0, 5);
    final JList<String> list2 = new JList<String>(values2);
    list2.setVisibleRowCount(Math.min(10, values2.length));
    list2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane jsp2 = new JScrollPane(list2);
    final JButton b2 = new JButton("Insert at the caret position");
    b2.setEnabled(false);
    JPanel vspace3 = new JPanel();
    vspace3.setSize(0, 5);
    final JList<String> list3 = new JList<String>(values3);
    list3.setVisibleRowCount(Math.min(10, values3.length));
    list3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane jsp3 = new JScrollPane(list3);
    final JButton b3 = new JButton("Modify the selection");
    b3.setEnabled(false);
    modifiedTextField.addCaretListener(new CaretListener() {

        @Override
        public void caretUpdate(CaretEvent e) {
            list3.setEnabled(modifiedTextField.getSelectedText() != null);
        }
    });
    Object[] messageObjects = { "Current search expression:", modifiedTextField, vspace1, jsp1, b1, vspace2, jsp2, b2, vspace3, jsp3, b3 };
    String[] options = { "OK", "Cancel" };
    final JOptionPane optionPane = new JOptionPane(messageObjects, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, "Cancel");
    b1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            modifySearchExpression(list1.getSelectedValue().toString(), modifiedTextField);
        }
    });
    list1.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            if (e.getClickCount() == 2) {
                modifySearchExpression(list1.getSelectedValue().toString(), modifiedTextField);
            }
        }
    });
    list1.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (list1.getSelectedValue() != null) {
                b1.setEnabled(true);
            } else {
                b1.setEnabled(false);
            }
        }
    });
    b2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            modifySearchExpression(list2.getSelectedValue().toString(), modifiedTextField);
        }
    });
    list2.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            if (e.getClickCount() == 2) {
                modifySearchExpression(list2.getSelectedValue().toString(), modifiedTextField);
            }
        }
    });
    list2.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (list2.getSelectedValue() != null) {
                b2.setEnabled(true);
            } else {
                b2.setEnabled(false);
            }
        }
    });
    b3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            modifySearchExpression(list3.getSelectedValue().toString(), modifiedTextField);
        }
    });
    list3.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            if (e.getClickCount() == 2 && list3.isEnabled()) {
                modifySearchExpression(list3.getSelectedValue().toString(), modifiedTextField);
            }
        }
    });
    list3.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (list3.getSelectedValue() != null) {
                b3.setEnabled(true);
            } else {
                b3.setEnabled(false);
            }
        }
    });
    annotationEditorWindow.setVisible(false);
    JDialog optionDialog = optionPane.createDialog(gate.gui.MainFrame.getInstance(), "GATE search expression builder");
    modifiedTextField.setCaretPosition(sourceTextField.getSelectionStart() == sourceTextField.getCaretPosition() ? sourceTextField.getSelectionEnd() : sourceTextField.getSelectionStart());
    modifiedTextField.moveCaretPosition(sourceTextField.getCaretPosition());
    modifiedTextField.requestFocus();
    optionDialog.setVisible(true);
    Object selectedValue = optionPane.getValue();
    if (selectedValue != null && selectedValue.equals("OK")) {
        if (searchRegExpChk != null) {
            searchRegExpChk.setSelected(true);
        }
        sourceTextField.setText(modifiedTextField.getText());
    }
    annotationEditorWindow.setVisible(true);
}
Also used : CaretEvent(javax.swing.event.CaretEvent) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) CaretListener(javax.swing.event.CaretListener) ActionListener(java.awt.event.ActionListener)

Example 75 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project keystore-explorer by kaikramer.

the class DViewCrl method initComponents.

private void initComponents() {
    GridBagConstraints gbcLbl = new GridBagConstraints();
    gbcLbl.gridx = 0;
    gbcLbl.gridwidth = 1;
    gbcLbl.gridheight = 1;
    gbcLbl.insets = new Insets(5, 5, 5, 5);
    gbcLbl.anchor = GridBagConstraints.EAST;
    GridBagConstraints gbcCtrl = new GridBagConstraints();
    gbcCtrl.gridx = 1;
    gbcCtrl.gridwidth = 1;
    gbcCtrl.gridheight = 1;
    gbcCtrl.insets = new Insets(5, 5, 5, 5);
    gbcCtrl.anchor = GridBagConstraints.WEST;
    jlVersion = new JLabel(res.getString("DViewCrl.jlVersion.text"));
    GridBagConstraints gbc_jlVersion = (GridBagConstraints) gbcLbl.clone();
    gbc_jlVersion.gridy = 0;
    jtfVersion = new JTextField(3);
    jtfVersion.setEditable(false);
    jtfVersion.setToolTipText(res.getString("DViewCrl.jtfVersion.tooltip"));
    GridBagConstraints gbc_jtfVersion = (GridBagConstraints) gbcCtrl.clone();
    gbc_jtfVersion.gridy = 0;
    jlIssuer = new JLabel(res.getString("DViewCrl.jlIssuer.text"));
    GridBagConstraints gbc_jlIssuer = (GridBagConstraints) gbcLbl.clone();
    gbc_jlIssuer.gridy = 1;
    jdnIssuer = new JDistinguishedName(res.getString("DViewCrl.Issuer.Title"), 30, false);
    jdnIssuer.setToolTipText(res.getString("DViewCrl.jdnIssuer.tooltip"));
    GridBagConstraints gbc_jdnIssuer = (GridBagConstraints) gbcCtrl.clone();
    gbc_jdnIssuer.gridy = 1;
    jlEffectiveDate = new JLabel(res.getString("DViewCrl.jlEffectiveDate.text"));
    GridBagConstraints gbc_jlEffectiveDate = (GridBagConstraints) gbcLbl.clone();
    gbc_jlEffectiveDate.gridy = 2;
    jtfEffectiveDate = new JTextField(30);
    jtfEffectiveDate.setEditable(false);
    jtfEffectiveDate.setToolTipText(res.getString("DViewCrl.jtfEffectiveDate.tooltip"));
    GridBagConstraints gbc_jtfEffectiveDate = (GridBagConstraints) gbcCtrl.clone();
    gbc_jtfEffectiveDate.gridy = 2;
    jlNextUpdate = new JLabel(res.getString("DViewCrl.jlNextUpdate.text"));
    GridBagConstraints gbc_jlNextUpdate = (GridBagConstraints) gbcLbl.clone();
    gbc_jlNextUpdate.gridy = 3;
    jtfNextUpdate = new JTextField(30);
    jtfNextUpdate.setEditable(false);
    jtfNextUpdate.setToolTipText(res.getString("DViewCrl.jtfNextUpdate.tooltip"));
    GridBagConstraints gbc_jtfNextUpdate = (GridBagConstraints) gbcCtrl.clone();
    gbc_jtfNextUpdate.gridy = 3;
    jlSignatureAlgorithm = new JLabel(res.getString("DViewCrl.jlSignatureAlgorithm.text"));
    GridBagConstraints gbc_jlSignatureAlgorithm = (GridBagConstraints) gbcLbl.clone();
    gbc_jlSignatureAlgorithm.gridy = 4;
    jtfSignatureAlgorithm = new JTextField(15);
    jtfSignatureAlgorithm.setEditable(false);
    jtfSignatureAlgorithm.setToolTipText(res.getString("DViewCrl.jtfSignatureAlgorithm.tooltip"));
    GridBagConstraints gbc_jtfSignatureAlgorithm = (GridBagConstraints) gbcCtrl.clone();
    gbc_jtfSignatureAlgorithm.gridy = 4;
    jbCrlExtensions = new JButton(res.getString("DViewCrl.jbCrlExtensions.text"));
    PlatformUtil.setMnemonic(jbCrlExtensions, res.getString("DViewCrl.jbCrlExtensions.mnemonic").charAt(0));
    jbCrlExtensions.setToolTipText(res.getString("DViewCrl.jbCrlExtensions.tooltip"));
    jbCrlExtensions.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewCrl.this);
                crlExtensionsPressed();
            } finally {
                CursorUtil.setCursorFree(DViewCrl.this);
            }
        }
    });
    jbCrlAsn1 = new JButton(res.getString("DViewCrl.jbCrlAsn1.text"));
    PlatformUtil.setMnemonic(jbCrlAsn1, res.getString("DViewCrl.jbCrlAsn1.mnemonic").charAt(0));
    jbCrlAsn1.setToolTipText(res.getString("DViewCrl.jbCrlAsn1.tooltip"));
    jbCrlAsn1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewCrl.this);
                asn1DumpPressed();
            } finally {
                CursorUtil.setCursorFree(DViewCrl.this);
            }
        }
    });
    jpCrlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
    jpCrlButtons.add(jbCrlExtensions);
    jpCrlButtons.add(jbCrlAsn1);
    GridBagConstraints gbc_jpCrlButtons = new GridBagConstraints();
    gbc_jpCrlButtons.gridx = 0;
    gbc_jpCrlButtons.gridy = 5;
    gbc_jpCrlButtons.gridwidth = 2;
    gbc_jpCrlButtons.gridheight = 1;
    gbc_jpCrlButtons.insets = new Insets(5, 0, 5, 0);
    gbc_jpCrlButtons.anchor = GridBagConstraints.EAST;
    jlRevokedCerts = new JLabel(res.getString("DViewCrl.jlRevokedCerts.text"));
    RevokedCertsTableModel rcModel = new RevokedCertsTableModel();
    jtRevokedCerts = new JKseTable(rcModel);
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(rcModel);
    jtRevokedCerts.setRowSorter(sorter);
    jtRevokedCerts.setShowGrid(false);
    jtRevokedCerts.setRowMargin(0);
    jtRevokedCerts.getColumnModel().setColumnMargin(0);
    jtRevokedCerts.getTableHeader().setReorderingAllowed(false);
    jtRevokedCerts.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    for (int i = 0; i < jtRevokedCerts.getColumnCount(); i++) {
        TableColumn column = jtRevokedCerts.getColumnModel().getColumn(i);
        if (i == 0) {
            column.setPreferredWidth(100);
        }
        column.setHeaderRenderer(new RevokedCertsTableHeadRend(jtRevokedCerts.getTableHeader().getDefaultRenderer()));
        column.setCellRenderer(new RevokedCertsTableCellRend());
    }
    ListSelectionModel listSelectionModel = jtRevokedCerts.getSelectionModel();
    listSelectionModel.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (// Ignore spurious
            !evt.getValueIsAdjusting()) // events
            {
                try {
                    CursorUtil.setCursorBusy(DViewCrl.this);
                    crlEntrySelection();
                } finally {
                    CursorUtil.setCursorFree(DViewCrl.this);
                }
            }
        }
    });
    jtRevokedCerts.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            maybeDisplayCrlEntryExtensions(evt);
        }
    });
    jspRevokedCertsTable = PlatformUtil.createScrollPane(jtRevokedCerts, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jspRevokedCertsTable.getViewport().setBackground(jtRevokedCerts.getBackground());
    jpRevokedCertsTable = new JPanel(new BorderLayout(10, 10));
    jpRevokedCertsTable.setPreferredSize(new Dimension(100, 200));
    jpRevokedCertsTable.add(jlRevokedCerts, BorderLayout.NORTH);
    jpRevokedCertsTable.add(jspRevokedCertsTable, BorderLayout.CENTER);
    jpRevokedCertsTable.setBorder(new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5)));
    jbCrlEntryExtensions = new JButton(res.getString("DViewCrl.jbCrlEntryExtensions.text"));
    PlatformUtil.setMnemonic(jbCrlEntryExtensions, res.getString("DViewCrl.jbCrlEntryExtensions.mnemonic").charAt(0));
    jbCrlEntryExtensions.setToolTipText(res.getString("DViewCrl.jbCrlEntryExtensions.tooltip"));
    jbCrlEntryExtensions.setEnabled(false);
    jbCrlEntryExtensions.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewCrl.this);
                crlEntryExtensionsPressed();
            } finally {
                CursorUtil.setCursorFree(DViewCrl.this);
            }
        }
    });
    jpCrlEntryExtensions = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    jpCrlEntryExtensions.add(jbCrlEntryExtensions);
    jpRevokedCertsTable.add(jpCrlEntryExtensions, BorderLayout.SOUTH);
    GridBagConstraints gbc_jpRevokedCertsTable = new GridBagConstraints();
    gbc_jpRevokedCertsTable.gridx = 0;
    gbc_jpRevokedCertsTable.gridy = 6;
    gbc_jpRevokedCertsTable.gridwidth = 2;
    gbc_jpRevokedCertsTable.gridheight = 1;
    gbc_jpRevokedCertsTable.insets = new Insets(5, 5, 5, 5);
    gbc_jpRevokedCertsTable.fill = GridBagConstraints.BOTH;
    gbc_jpRevokedCertsTable.anchor = GridBagConstraints.CENTER;
    jpCRL = new JPanel(new GridBagLayout());
    jpCRL.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder()));
    jpCRL.add(jlVersion, gbc_jlVersion);
    jpCRL.add(jtfVersion, gbc_jtfVersion);
    jpCRL.add(jlIssuer, gbc_jlIssuer);
    jpCRL.add(jdnIssuer, gbc_jdnIssuer);
    jpCRL.add(jlEffectiveDate, gbc_jlEffectiveDate);
    jpCRL.add(jtfEffectiveDate, gbc_jtfEffectiveDate);
    jpCRL.add(jlNextUpdate, gbc_jlNextUpdate);
    jpCRL.add(jtfNextUpdate, gbc_jtfNextUpdate);
    jpCRL.add(jlSignatureAlgorithm, gbc_jlSignatureAlgorithm);
    jpCRL.add(jtfSignatureAlgorithm, gbc_jtfSignatureAlgorithm);
    jpCRL.add(jpCrlButtons, gbc_jpCrlButtons);
    jpCRL.add(jpRevokedCertsTable, gbc_jpRevokedCertsTable);
    populateDialog();
    jbOK = new JButton(res.getString("DViewCrl.jbOK.text"));
    jbOK.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            okPressed();
        }
    });
    jpOK = PlatformUtil.createDialogButtonPanel(jbOK, false);
    getContentPane().add(jpCRL, BorderLayout.CENTER);
    getContentPane().add(jpOK, BorderLayout.SOUTH);
    setResizable(false);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });
    getRootPane().setDefaultButton(jbOK);
    pack();
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            jbOK.requestFocus();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) WindowAdapter(java.awt.event.WindowAdapter) JTextField(javax.swing.JTextField) JDistinguishedName(org.kse.gui.crypto.JDistinguishedName) BorderLayout(java.awt.BorderLayout) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) TableRowSorter(javax.swing.table.TableRowSorter) MouseEvent(java.awt.event.MouseEvent) JKseTable(org.kse.gui.JKseTable) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) ListSelectionModel(javax.swing.ListSelectionModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) EtchedBorder(javax.swing.border.EtchedBorder) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) TableModel(javax.swing.table.TableModel)

Aggregations

ListSelectionListener (javax.swing.event.ListSelectionListener)216 ListSelectionEvent (javax.swing.event.ListSelectionEvent)210 ActionEvent (java.awt.event.ActionEvent)90 ActionListener (java.awt.event.ActionListener)76 JScrollPane (javax.swing.JScrollPane)72 JPanel (javax.swing.JPanel)67 JButton (javax.swing.JButton)61 BorderLayout (java.awt.BorderLayout)53 MouseEvent (java.awt.event.MouseEvent)47 Dimension (java.awt.Dimension)44 JLabel (javax.swing.JLabel)40 MouseAdapter (java.awt.event.MouseAdapter)37 JTable (javax.swing.JTable)36 FlowLayout (java.awt.FlowLayout)28 Insets (java.awt.Insets)28 JList (javax.swing.JList)27 List (java.util.List)24 ArrayList (java.util.ArrayList)22 KeyEvent (java.awt.event.KeyEvent)21 GridBagConstraints (java.awt.GridBagConstraints)20