Example usage for java.awt.event KeyEvent getKeyCode

List of usage examples for java.awt.event KeyEvent getKeyCode

Introduction

In this page you can find the example usage for java.awt.event KeyEvent getKeyCode.

Prototype

public int getKeyCode() 

Source Link

Document

Returns the integer keyCode associated with the key in this event.

Usage

From source file:self.philbrown.javaQuery.$.java

/**
 * Refreshes the listeners for key events
 *//*  w  w  w .  j a v  a 2 s.c  o m*/
private void setupKeyListener() {
    for (final Component view : views) {
        view.addKeyListener(new KeyListener() {

            @Override
            public void keyPressed(KeyEvent event) {
                if (keyDown != null)
                    keyDown.invoke($.with(view), event.getKeyCode(), event);
            }

            @Override
            public void keyReleased(KeyEvent event) {
                if (keyUp != null)
                    keyUp.invoke($.with(view), event.getKeyCode(), event);
            }

            @Override
            public void keyTyped(KeyEvent event) {
                if (keyPress != null)
                    keyPress.invoke($.with(view), event.getKeyCode(), event);
            }

        });
    }
}

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * _more_/*from  www  . j  a v  a  2s. c  om*/
 *
 * @return _more_
 */
public JComponent doMakePointsPanel() {

    pointTableModel = new FlythroughTableModel(this);
    pointTable = new JTable(pointTableModel);
    pointTable.setToolTipText("Double click: view; Control-P: Show point properties; Delete: delete point");

    pointTable.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if ((e.getKeyCode() == KeyEvent.VK_P) && e.isControlDown()) {
                List<FlythroughPoint> newPoints = new ArrayList<FlythroughPoint>();
                int[] rows = pointTable.getSelectedRows();
                List<FlythroughPoint> oldPoints = pointsToUse;
                for (int j = 0; j < rows.length; j++) {
                    FlythroughPoint pt = oldPoints.get(rows[j]);
                    if (!showProperties(pt)) {
                        break;
                    }
                    pointTable.repaint();
                }
            }

            if (GuiUtils.isDeleteEvent(e)) {
                List<FlythroughPoint> newPoints = new ArrayList<FlythroughPoint>();
                int[] rows = pointTable.getSelectedRows();
                List<FlythroughPoint> oldPoints = pointsToUse;
                for (int i = 0; i < oldPoints.size(); i++) {
                    boolean good = true;
                    for (int j = 0; j < rows.length; j++) {
                        if (i == rows[j]) {
                            good = false;
                            break;
                        }
                    }
                    if (good) {
                        newPoints.add(oldPoints.get(i));
                    }
                }
                flythrough(newPoints);
            }
        }
    });

    pointTable.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            final int row = pointTable.rowAtPoint(e.getPoint());
            if ((row < 0) || (row >= pointsToUse.size())) {
                return;
            }
            if (e.getClickCount() > 1) {
                animation.setCurrent(row);
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(pointTable);
    scrollPane.setPreferredSize(new Dimension(400, 300));
    return scrollPane;

}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java

/**
 * Sets the properties and adds the listeners for the Message Table. No data is loaded at this
 * point./* ww w.j  a  va2 s .c  o  m*/
 */
private void makeMessageTable() {
    messageTreeTable.setDragEnabled(true);
    messageTreeTable.setSortable(false);
    messageTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    messageTreeTable.setColumnFactory(new MessageBrowserTableColumnFactory());
    messageTreeTable.setLeafIcon(null);
    messageTreeTable.setOpenIcon(null);
    messageTreeTable.setClosedIcon(null);
    messageTreeTable.setAutoCreateColumnsFromModel(false);
    messageTreeTable.setMirthColumnControlEnabled(true);
    messageTreeTable.setShowGrid(true, true);
    messageTreeTable.setHorizontalScrollEnabled(true);
    messageTreeTable.setPreferredScrollableViewportSize(messageTreeTable.getPreferredSize());
    messageTreeTable.setMirthTransferHandlerEnabled(true);

    tableModel = new MessageBrowserTableModel(columnMap.size());
    // Add a blank column to the column initially, otherwise it return an exception on load
    // Columns will be re-generated when the message browser is viewed
    tableModel.setColumnIdentifiers(Arrays.asList(new String[] { "" }));
    messageTreeTable.setTreeTableModel(tableModel);

    // Sets the alternating highlighter for the table
    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        messageTreeTable.setHighlighters(highlighter);
    }

    // Add the listener for when the table selection changes
    messageTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            MessageListSelected(evt);
        }

    });

    // Add the mouse listener
    messageTreeTable.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mousePressed(java.awt.event.MouseEvent evt) {
            checkMessageSelectionAndPopupMenu(evt);
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
            checkMessageSelectionAndPopupMenu(evt);
        }

        // Opens the send message dialog when a message is double clicked.
        // If the root message or source connector is selected, select all destination connectors initially
        // If a destination connector is selected, select only that destination connector initially
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (evt.getClickCount() >= 2) {
                int row = getSelectedMessageIndex();
                if (row >= 0) {
                    MessageBrowserTableNode messageNode = (MessageBrowserTableNode) messageTreeTable
                            .getPathForRow(row).getLastPathComponent();
                    if (messageNode.isNodeActive()) {
                        Long messageId = messageNode.getMessageId();
                        Integer metaDataId = messageNode.getMetaDataId();

                        Message currentMessage = messageCache.get(messageId);
                        ConnectorMessage connectorMessage = currentMessage.getConnectorMessages()
                                .get(metaDataId);
                        List<Integer> selectedMetaDataIds = new ArrayList<Integer>();

                        Map<String, Object> sourceMap = new HashMap<String, Object>();
                        if (connectorMessage.getSourceMap() != null) {
                            sourceMap.putAll(connectorMessage.getSourceMap());
                            // Remove the destination set if it exists, because that will be determined by the selected metadata IDs
                            sourceMap.remove("destinationSet");
                        }

                        if (metaDataId == 0) {
                            selectedMetaDataIds = null;
                        } else {
                            selectedMetaDataIds.add(metaDataId);
                        }

                        if (connectorMessage.getRaw() != null) {
                            parent.editMessageDialog.setPropertiesAndShow(
                                    connectorMessage.getRaw().getContent(),
                                    connectorMessage.getRaw().getDataType(), channelId,
                                    parent.dashboardPanel.getDestinationConnectorNames(channelId),
                                    selectedMetaDataIds, sourceMap);
                        }
                    }
                }
            }
        }
    });

    // Key Listener trigger for DEL
    messageTreeTable.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            int row = getSelectedMessageIndex();
            if (row >= 0) {
                if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                    MessageBrowserTableNode messageNode = (MessageBrowserTableNode) messageTreeTable
                            .getPathForRow(row).getLastPathComponent();

                    if (messageNode.isNodeActive()) {
                        parent.doRemoveMessage();
                    }

                } else if (descriptionTabbedPane.getTitleAt(descriptionTabbedPane.getSelectedIndex())
                        .equals("Messages")) {
                    if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                        List<AbstractButton> buttons = Collections.list(messagesGroup.getElements());
                        boolean passedSelected = false;
                        for (int i = buttons.size() - 1; i >= 0; i--) {
                            AbstractButton button = buttons.get(i);
                            if (passedSelected && button.isShowing()) {
                                lastUserSelectedMessageType = buttons.get(i).getText();
                                updateMessageRadioGroup();
                                break;
                            } else if (button.isSelected()) {
                                passedSelected = true;
                            }
                        }
                    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                        List<AbstractButton> buttons = Collections.list(messagesGroup.getElements());
                        boolean passedSelected = false;
                        for (int i = 0; i < buttons.size(); i++) {
                            AbstractButton button = buttons.get(i);
                            if (passedSelected && button.isShowing()) {
                                lastUserSelectedMessageType = buttons.get(i).getText();
                                updateMessageRadioGroup();
                                break;
                            } else if (button.isSelected()) {
                                passedSelected = true;
                            }
                        }
                    }
                }
            }

        }
    });
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

private void initComponents() {
    splitPane = new JSplitPane();
    splitPane.setBackground(getBackground());
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPane.setBorder(BorderFactory.createEmptyBorder());
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(//from ww w.  j  a va2s  .co  m
            Preferences.userNodeForPackage(Mirth.class).getInt("height", UIConstants.MIRTH_HEIGHT) / 3);
    splitPane.setResizeWeight(0.5);

    topPanel = new JPanel();
    topPanel.setBackground(UIConstants.COMBO_BOX_BACKGROUND);

    final CodeTemplateTreeTableCellEditor templateCellEditor = new CodeTemplateTreeTableCellEditor(this);

    templateTreeTable = new MirthTreeTable("CodeTemplate", new HashSet<String>(
            Arrays.asList(new String[] { "Name", "Description", "Revision", "Last Modified" }))) {

        private TreeTableNode selectedNode;

        @Override
        public boolean isCellEditable(int row, int column) {
            return column == TEMPLATE_NAME_COLUMN;
        }

        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            if (isHierarchical(column)) {
                return templateCellEditor;
            } else {
                return super.getCellEditor(row, column);
            }
        }

        @Override
        protected void beforeSort() {
            updateCurrentNode();
            updateCurrentNode.set(false);

            int selectedRow = templateTreeTable.getSelectedRow();
            selectedNode = selectedRow >= 0
                    ? (TreeTableNode) templateTreeTable.getPathForRow(selectedRow).getLastPathComponent()
                    : null;
        }

        @Override
        protected void afterSort() {
            final TreePath selectedPath = selectPathFromNodeId(selectedNode,
                    (CodeTemplateRootTreeTableNode) templateTreeTable.getTreeTableModel().getRoot());
            if (selectedPath != null) {
                selectTemplatePath(selectedPath);
            }

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    if (selectedPath != null) {
                        selectTemplatePath(selectedPath);
                    }
                    updateCurrentNode.set(true);
                }
            });
        }
    };

    DefaultTreeTableModel model = new CodeTemplateTreeTableModel();
    model.setColumnIdentifiers(
            Arrays.asList(new String[] { "Name", "Id", "Type", "Description", "Revision", "Last Modified" }));

    CodeTemplateRootTreeTableNode rootNode = new CodeTemplateRootTreeTableNode();
    model.setRoot(rootNode);

    fullModel = new CodeTemplateTreeTableModel();
    fullModel.setColumnIdentifiers(
            Arrays.asList(new String[] { "Name", "Id", "Type", "Description", "Revision", "Last Modified" }));

    CodeTemplateRootTreeTableNode fullRootNode = new CodeTemplateRootTreeTableNode();
    fullModel.setRoot(fullRootNode);

    templateTreeTable.setColumnFactory(new CodeTemplateTableColumnFactory());
    templateTreeTable.setTreeTableModel(model);
    templateTreeTable.setOpenIcon(null);
    templateTreeTable.setClosedIcon(null);
    templateTreeTable.setLeafIcon(null);
    templateTreeTable.setRootVisible(false);
    templateTreeTable.setDoubleBuffered(true);
    templateTreeTable.setDragEnabled(false);
    templateTreeTable.setRowSelectionAllowed(true);
    templateTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    templateTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    templateTreeTable.setFocusable(true);
    templateTreeTable.setOpaque(true);
    templateTreeTable.getTableHeader().setReorderingAllowed(true);
    templateTreeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    templateTreeTable.setEditable(true);
    templateTreeTable.setSortable(true);
    templateTreeTable.setAutoCreateColumnsFromModel(false);
    templateTreeTable.setShowGrid(true, true);
    templateTreeTable.restoreColumnPreferences();
    templateTreeTable.setMirthColumnControlEnabled(true);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        templateTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    templateTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            int row = templateTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY()));

            if (row < 0) {
                templateTreeTable.clearSelection();
            }

            if (evt.isPopupTrigger()) {
                if (row != -1) {
                    if (!templateTreeTable.isRowSelected(row)) {
                        templateTreeTable.setRowSelectionInterval(row, row);
                    }
                }
                codeTemplatePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
            }
        }
    });

    templateTreeTable.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                TreePath selectedPath = templateTreeTable.getTreeSelectionModel().getSelectionPath();
                if (selectedPath != null) {
                    MutableTreeTableNode selectedNode = (MutableTreeTableNode) selectedPath
                            .getLastPathComponent();
                    if (selectedNode instanceof CodeTemplateLibraryTreeTableNode && codeTemplateTasks
                            .getContentPane().getComponent(TASK_CODE_TEMPLATE_LIBRARY_DELETE).isVisible()) {
                        doDeleteLibrary();
                    } else if (selectedNode instanceof CodeTemplateTreeTableNode && codeTemplateTasks
                            .getContentPane().getComponent(TASK_CODE_TEMPLATE_DELETE).isVisible()) {
                        doDeleteCodeTemplate();
                    }
                }
            }
        }
    });

    templateTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting() && !templateTreeTable.getSelectionModel().getValueIsAdjusting()) {
                int selectedRow = templateTreeTable.getSelectedRow();

                boolean saveEnabled = isSaveEnabled();
                boolean adjusting = saveAdjusting.getAndSet(true);

                printTreeTable();

                updateCurrentNode();
                currentSelectedRow = selectedRow;

                if (selectedRow < 0) {
                    if (!adjusting) {
                        switchSplitPaneComponent(blankPanel);
                    }
                } else {
                    TreePath path = templateTreeTable.getPathForRow(selectedRow);
                    if (path != null) {
                        TreeTableNode node = (TreeTableNode) path.getLastPathComponent();

                        if (node instanceof CodeTemplateLibraryTreeTableNode) {
                            setLibraryProperties((CodeTemplateLibraryTreeTableNode) node);
                            switchSplitPaneComponent(libraryPanel);
                        } else if (node instanceof CodeTemplateTreeTableNode) {
                            setCodeTemplateProperties((CodeTemplateTreeTableNode) node);
                            switchSplitPaneComponent(templatePanel);
                        }
                    }
                }

                updateTasks();

                setSaveEnabled(saveEnabled);
                if (!adjusting) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            saveAdjusting.set(false);
                        }
                    });
                }
            }
        }
    });

    templateTreeTable.addTreeWillExpandListener(new TreeWillExpandListener() {
        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            treeExpansionChanged();
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
            treeExpansionChanged();
        }

        private void treeExpansionChanged() {
            updateCurrentNode();
            updateCurrentNode.set(false);
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    updateCurrentNode.set(true);
                }
            });
        }
    });

    templateTreeTableScrollPane = new JScrollPane(templateTreeTable);
    templateTreeTableScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(0x6E6E6E)));

    templateFilterNotificationLabel = new JLabel();

    templateFilterLabel = new JLabel("Filter:");

    templateFilterField = new JTextField();
    templateFilterField.setToolTipText(
            "Filters (by name) the code templates and libraries that show up in the table above.");

    templateFilterField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent evt) {
            filterChanged(evt);
        }

        @Override
        public void insertUpdate(DocumentEvent evt) {
            filterChanged(evt);
        }

        @Override
        public void changedUpdate(DocumentEvent evt) {
            filterChanged(evt);
        }

        private void filterChanged(DocumentEvent evt) {
            try {
                updateTemplateFilter(evt.getDocument().getText(0, evt.getLength()));
            } catch (BadLocationException e) {
            }
        }
    });

    templateFilterField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent evt) {
            updateTemplateFilter(templateFilterField.getText());
        }
    });

    blankPanel = new JPanel();

    libraryPanel = new JPanel();
    libraryPanel.setBackground(splitPane.getBackground());

    libraryLeftPanel = new JPanel();
    libraryLeftPanel.setBackground(libraryPanel.getBackground());

    librarySummaryLabel = new JLabel("Summary:");
    librarySummaryValue = new JLabel();

    libraryDescriptionLabel = new JLabel("Description:");
    libraryDescriptionScrollPane = new MirthRTextScrollPane(null, false, SyntaxConstants.SYNTAX_STYLE_NONE,
            false);

    DocumentListener codeChangeListener = new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent evt) {
            codeChanged();
        }

        @Override
        public void insertUpdate(DocumentEvent evt) {
            codeChanged();
        }

        @Override
        public void changedUpdate(DocumentEvent evt) {
            codeChanged();
        }

        private void codeChanged() {
            if (codeChangeWorker != null) {
                codeChangeWorker.cancel(true);
            }

            int selectedRow = templateTreeTable.getSelectedRow();
            if (selectedRow >= 0) {
                TreePath selectedPath = templateTreeTable.getPathForRow(selectedRow);
                if (selectedPath != null) {
                    codeChangeWorker = new CodeChangeWorker(
                            (String) ((TreeTableNode) selectedPath.getLastPathComponent())
                                    .getValueAt(TEMPLATE_ID_COLUMN));
                    codeChangeWorker.execute();
                }
            }
        }
    };
    libraryDescriptionScrollPane.getDocument().addDocumentListener(codeChangeListener);

    libraryRightPanel = new JPanel();
    libraryRightPanel.setBackground(libraryPanel.getBackground());

    libraryChannelsSelectPanel = new JPanel();
    libraryChannelsSelectPanel.setBackground(libraryRightPanel.getBackground());

    libraryChannelsLabel = new JLabel("<html><b>Channels</b></html>");
    libraryChannelsLabel.setForeground(new Color(64, 64, 64));

    libraryChannelsSelectAllLabel = new JLabel("<html><u>Select All</u></html>");
    libraryChannelsSelectAllLabel.setForeground(Color.BLUE);
    libraryChannelsSelectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    libraryChannelsSelectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            if (evt.getComponent().isEnabled()) {
                for (int row = 0; row < libraryChannelsTable.getRowCount(); row++) {
                    ChannelInfo channelInfo = (ChannelInfo) libraryChannelsTable.getValueAt(row,
                            LIBRARY_CHANNELS_NAME_COLUMN);
                    channelInfo.setEnabled(true);
                    libraryChannelsTable.setValueAt(channelInfo, row, LIBRARY_CHANNELS_NAME_COLUMN);
                }
                setSaveEnabled(true);
            }
        }
    });

    libraryChannelsDeselectAllLabel = new JLabel("<html><u>Deselect All</u></html>");
    libraryChannelsDeselectAllLabel.setForeground(Color.BLUE);
    libraryChannelsDeselectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    libraryChannelsDeselectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            if (evt.getComponent().isEnabled()) {
                for (int row = 0; row < libraryChannelsTable.getRowCount(); row++) {
                    ChannelInfo channelInfo = (ChannelInfo) libraryChannelsTable.getValueAt(row,
                            LIBRARY_CHANNELS_NAME_COLUMN);
                    channelInfo.setEnabled(false);
                    libraryChannelsTable.setValueAt(channelInfo, row, LIBRARY_CHANNELS_NAME_COLUMN);
                }
                setSaveEnabled(true);
            }
        }
    });

    libraryChannelsFilterLabel = new JLabel("Filter:");
    libraryChannelsFilterField = new JTextField();
    libraryChannelsFilterField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent evt) {
            libraryChannelsTable.getRowSorter().allRowsChanged();
        }

        @Override
        public void insertUpdate(DocumentEvent evt) {
            libraryChannelsTable.getRowSorter().allRowsChanged();
        }

        @Override
        public void changedUpdate(DocumentEvent evt) {
            libraryChannelsTable.getRowSorter().allRowsChanged();
        }
    });

    libraryChannelsTable = new MirthTable();
    libraryChannelsTable.setModel(new RefreshTableModel(new Object[] { "Name", "Id" }, 0));
    libraryChannelsTable.setDragEnabled(false);
    libraryChannelsTable.setRowSelectionAllowed(false);
    libraryChannelsTable.setRowHeight(UIConstants.ROW_HEIGHT);
    libraryChannelsTable.setFocusable(false);
    libraryChannelsTable.setOpaque(true);
    libraryChannelsTable.getTableHeader().setReorderingAllowed(false);
    libraryChannelsTable.setEditable(true);

    OffsetRowSorter libraryChannelsRowSorter = new OffsetRowSorter(libraryChannelsTable.getModel(), 1);
    libraryChannelsRowSorter.setRowFilter(new RowFilter<TableModel, Integer>() {
        @Override
        public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
            String name = entry.getStringValue(LIBRARY_CHANNELS_NAME_COLUMN);
            return name.equals(NEW_CHANNELS) || StringUtils.containsIgnoreCase(name,
                    StringUtils.trim(libraryChannelsFilterField.getText()));
        }
    });
    libraryChannelsTable.setRowSorter(libraryChannelsRowSorter);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        libraryChannelsTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    libraryChannelsTable.getColumnExt(LIBRARY_CHANNELS_NAME_COLUMN)
            .setCellRenderer(new ChannelsTableCellRenderer());
    libraryChannelsTable.getColumnExt(LIBRARY_CHANNELS_NAME_COLUMN)
            .setCellEditor(new ChannelsTableCellEditor());

    // Hide ID column
    libraryChannelsTable.getColumnExt(LIBRARY_CHANNELS_ID_COLUMN).setVisible(false);

    libraryChannelsScrollPane = new JScrollPane(libraryChannelsTable);

    templatePanel = new JPanel();
    templatePanel.setBackground(splitPane.getBackground());

    templateLeftPanel = new JPanel();
    templateLeftPanel.setBackground(templatePanel.getBackground());

    templateLibraryLabel = new JLabel("Library:");
    templateLibraryComboBox = new JComboBox<String>();
    templateLibraryComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            libraryComboBoxActionPerformed();
        }
    });

    templateTypeLabel = new JLabel("Type:");
    templateTypeComboBox = new JComboBox<CodeTemplateType>(CodeTemplateType.values());
    templateTypeComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            setSaveEnabled(true);
        }
    });

    templateCodeLabel = new JLabel("Code:");
    templateCodeTextArea = new MirthRTextScrollPane(ContextType.GLOBAL_DEPLOY);
    templateCodeTextArea.getDocument().addDocumentListener(codeChangeListener);

    templateAutoGenerateDocumentationButton = new JButton("Update JSDoc");
    templateAutoGenerateDocumentationButton.setToolTipText(
            "<html>Generates/updates a JSDoc at the beginning of your<br/>code, with parameter/return annotations as needed.</html>");
    templateAutoGenerateDocumentationButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            String currentText = templateCodeTextArea.getText();
            String newText = CodeTemplateUtil.updateCode(templateCodeTextArea.getText());
            templateCodeTextArea.setText(newText, false);
            if (!currentText.equals(newText)) {
                setSaveEnabled(true);
            }
        }
    });

    templateRightPanel = new JPanel();
    templateRightPanel.setBackground(templatePanel.getBackground());

    templateContextSelectPanel = new JPanel();
    templateContextSelectPanel.setBackground(templateRightPanel.getBackground());

    templateContextLabel = new JLabel("<html><b>Context</b></html>");
    templateContextLabel.setForeground(new Color(64, 64, 64));

    templateContextSelectAllLabel = new JLabel("<html><u>Select All</u></html>");
    templateContextSelectAllLabel.setForeground(Color.BLUE);
    templateContextSelectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    templateContextSelectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            TreeTableNode root = (TreeTableNode) templateContextTreeTable.getTreeTableModel().getRoot();
            for (Enumeration<? extends TreeTableNode> groups = root.children(); groups.hasMoreElements();) {
                TreeTableNode group = groups.nextElement();
                ((MutablePair<Integer, String>) group.getUserObject()).setLeft(MirthTriStateCheckBox.CHECKED);
                for (Enumeration<? extends TreeTableNode> children = group.children(); children
                        .hasMoreElements();) {
                    ((MutablePair<Integer, String>) children.nextElement().getUserObject())
                            .setLeft(MirthTriStateCheckBox.CHECKED);
                }
            }
            templateContextTreeTable.updateUI();
            setSaveEnabled(true);
        }
    });

    templateContextDeselectAllLabel = new JLabel("<html><u>Deselect All</u></html>");
    templateContextDeselectAllLabel.setForeground(Color.BLUE);
    templateContextDeselectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    templateContextDeselectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            TreeTableNode root = (TreeTableNode) templateContextTreeTable.getTreeTableModel().getRoot();
            for (Enumeration<? extends TreeTableNode> groups = root.children(); groups.hasMoreElements();) {
                TreeTableNode group = groups.nextElement();
                ((MutablePair<Integer, String>) group.getUserObject()).setLeft(MirthTriStateCheckBox.UNCHECKED);
                for (Enumeration<? extends TreeTableNode> children = group.children(); children
                        .hasMoreElements();) {
                    ((MutablePair<Integer, String>) children.nextElement().getUserObject())
                            .setLeft(MirthTriStateCheckBox.UNCHECKED);
                }
            }
            templateContextTreeTable.updateUI();
            setSaveEnabled(true);
        }
    });

    final TableCellEditor contextCellEditor = new ContextTreeTableCellEditor(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            setSaveEnabled(true);
        }
    });

    templateContextTreeTable = new MirthTreeTable() {
        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            if (isHierarchical(column)) {
                return contextCellEditor;
            } else {
                return super.getCellEditor(row, column);
            }
        }
    };

    DefaultMutableTreeTableNode rootContextNode = new DefaultMutableTreeTableNode();
    DefaultMutableTreeTableNode globalScriptsNode = new DefaultMutableTreeTableNode(
            new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Global Scripts"));
    globalScriptsNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_DEPLOY)));
    globalScriptsNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_UNDEPLOY)));
    globalScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_PREPROCESSOR)));
    globalScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_POSTPROCESSOR)));
    rootContextNode.add(globalScriptsNode);
    DefaultMutableTreeTableNode channelScriptsNode = new DefaultMutableTreeTableNode(
            new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Channel Scripts"));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_DEPLOY)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_UNDEPLOY)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_PREPROCESSOR)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_POSTPROCESSOR)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_ATTACHMENT)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_BATCH)));
    rootContextNode.add(channelScriptsNode);
    DefaultMutableTreeTableNode sourceConnectorNode = new DefaultMutableTreeTableNode(
            new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Source Connector"));
    sourceConnectorNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.SOURCE_RECEIVER)));
    sourceConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.SOURCE_FILTER_TRANSFORMER)));
    rootContextNode.add(sourceConnectorNode);
    DefaultMutableTreeTableNode destinationConnectorNode = new DefaultMutableTreeTableNode(
            new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Destination Connector"));
    destinationConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.DESTINATION_FILTER_TRANSFORMER)));
    destinationConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.DESTINATION_DISPATCHER)));
    destinationConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.DESTINATION_RESPONSE_TRANSFORMER)));
    rootContextNode.add(destinationConnectorNode);

    DefaultTreeTableModel contextModel = new SortableTreeTableModel(rootContextNode);
    contextModel.setColumnIdentifiers(Arrays.asList(new String[] { "Context" }));
    templateContextTreeTable.setTreeTableModel(contextModel);

    templateContextTreeTable.setRootVisible(false);
    templateContextTreeTable.setDragEnabled(false);
    templateContextTreeTable.setRowSelectionAllowed(false);
    templateContextTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    templateContextTreeTable.setFocusable(false);
    templateContextTreeTable.setOpaque(true);
    templateContextTreeTable.getTableHeader().setReorderingAllowed(false);
    templateContextTreeTable.setEditable(true);
    templateContextTreeTable.setSortable(false);
    templateContextTreeTable.setShowGrid(true, true);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        templateContextTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    templateContextTreeTable.setTreeCellRenderer(new ContextTreeTableCellRenderer());
    templateContextTreeTable.setOpenIcon(null);
    templateContextTreeTable.setClosedIcon(null);
    templateContextTreeTable.setLeafIcon(null);

    templateContextTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            if (templateContextTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) {
                templateContextTreeTable.clearSelection();
            }
        }
    });

    templateContextTreeTable.getTreeTableModel().addTreeModelListener(new TreeModelListener() {
        @Override
        public void treeNodesChanged(TreeModelEvent evt) {
            if (ArrayUtils.isNotEmpty(evt.getChildren())) {
                TreeTableNode node = (TreeTableNode) evt.getChildren()[0];

                if (evt.getTreePath().getPathCount() == 2) {
                    boolean allChildren = true;
                    boolean noChildren = true;
                    for (Enumeration<? extends TreeTableNode> children = node.getParent().children(); children
                            .hasMoreElements();) {
                        TreeTableNode child = children.nextElement();
                        if (((Pair<Integer, ContextType>) child.getUserObject())
                                .getLeft() == MirthTriStateCheckBox.UNCHECKED) {
                            allChildren = false;
                        } else {
                            noChildren = false;
                        }
                    }

                    int value;
                    if (allChildren) {
                        value = MirthTriStateCheckBox.CHECKED;
                    } else if (noChildren) {
                        value = MirthTriStateCheckBox.UNCHECKED;
                    } else {
                        value = MirthTriStateCheckBox.PARTIAL;
                    }

                    ((MutablePair<Integer, String>) node.getParent().getUserObject()).setLeft(value);
                } else if (evt.getTreePath().getPathCount() == 1) {
                    int value = ((Pair<Integer, String>) node.getUserObject()).getLeft();

                    for (Enumeration<? extends TreeTableNode> children = node.children(); children
                            .hasMoreElements();) {
                        ((MutablePair<Integer, ContextType>) children.nextElement().getUserObject())
                                .setLeft(value);
                    }
                }
            }
        }

        @Override
        public void treeNodesInserted(TreeModelEvent evt) {
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent evt) {
        }

        @Override
        public void treeStructureChanged(TreeModelEvent evt) {
        }
    });

    templateContextTreeTableScrollPane = new JScrollPane(templateContextTreeTable);
}

From source file:plugins.tprovoost.Microscopy.MicroManagerForIcy.MMMainFrame.java

/**
 * Singleton pattern : private constructor Use instead.
 *///w  w  w . ja va 2  s.  co  m
private MMMainFrame() {
    super(NODE_NAME, false, true, false, true);
    instancing = true;
    // --------------
    // INITIALIZATION
    // --------------
    _sysConfigFile = "";
    _isConfigLoaded = false;
    _root = PluginPreferences.getPreferences().node(NODE_NAME);
    final MainFrame mainFrame = Icy.getMainInterface().getMainFrame();

    // --------------
    // PROGRESS FRAME
    // --------------
    ThreadUtil.invokeLater(new Runnable() {
        @Override
        public void run() {
            _progressFrame = new IcyFrame("", false, false, false, false);
            _progressBar = new JProgressBar();
            _progressBar.setString("Please wait while loading...");
            _progressBar.setStringPainted(true);
            _progressBar.setIndeterminate(true);
            _progressBar.setMinimum(0);
            _progressBar.setMaximum(1000);
            _progressBar.setBounds(50, 50, 100, 30);
            _progressFrame.setSize(300, 100);
            _progressFrame.setResizable(false);
            _progressFrame.add(_progressBar);
            _progressFrame.addToMainDesktopPane();
            loadConfig(true);
            if (_sysConfigFile == "") {
                instancing = false;
                return;
            }
            ThreadUtil.bgRun(new Runnable() {

                @Override
                public void run() {
                    while (!_isConfigLoaded) {
                        if (!instancing)
                            return;
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                        }
                    }
                    ThreadUtil.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            // --------------------
                            // START INITIALIZATION
                            // --------------------
                            if (_progressBar != null)
                                getContentPane().remove(_progressBar);
                            if (mCore == null) {
                                close();
                                return;
                            }

                            // ReportingUtils.setCore(mCore);
                            _afMgr = new AutofocusManager(MMMainFrame.this);
                            acqMgr = new AcquisitionManager();
                            PositionList posList = new PositionList();

                            _camera_label = MMCoreJ.getG_Keyword_CameraName();
                            if (_camera_label == null)
                                _camera_label = "";
                            try {
                                setPositionList(posList);
                            } catch (MMScriptException e1) {
                                e1.printStackTrace();
                            }
                            posListDlg_ = new PositionListDlg(mCore, MMMainFrame.this, _posList, null, dlg);
                            posListDlg_.setModalityType(ModalityType.APPLICATION_MODAL);

                            callback = new EventCallBackManager();
                            mCore.registerCallback(callback);

                            engine_ = new AcquisitionWrapperEngineIcy();
                            engine_.setParentGUI(MMMainFrame.this);
                            engine_.setCore(mCore, getAutofocusManager());
                            engine_.setPositionList(getPositionList());

                            setSystemMenuCallback(new MenuCallback() {

                                @Override
                                public JMenu getMenu() {
                                    JMenu toReturn = MMMainFrame.this.getDefaultSystemMenu();
                                    JMenuItem hconfig = new JMenuItem("Configuration Wizard");
                                    hconfig.setIcon(new IcyIcon("cog", MENU_ICON_SIZE));

                                    hconfig.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            if (!_pluginListEmpty && !ConfirmDialog.confirm("Are you sure ?",
                                                    "<html>Loading the Configuration Wizard will unload all the devices and pause all running acquisitions.</br> Are you sure you want to continue ?</html>"))
                                                return;
                                            notifyConfigAboutToChange(null);
                                            try {
                                                mCore.unloadAllDevices();
                                            } catch (Exception e1) {
                                                e1.printStackTrace();
                                            }
                                            String previous_config = _sysConfigFile;
                                            ConfiguratorDlg2 configurator = new ConfiguratorDlg2(mCore,
                                                    _sysConfigFile);
                                            configurator.setVisible(true);
                                            String res = configurator.getFileName();
                                            if (_sysConfigFile == "" || _sysConfigFile == res || res == "") {
                                                _sysConfigFile = previous_config;
                                                loadConfig();
                                            }
                                            refreshGUI();
                                            notifyConfigChanged(null);
                                        }
                                    });

                                    JMenuItem menuPxSizeConfigItem = new JMenuItem("Pixel Size Config");
                                    menuPxSizeConfigItem.setIcon(new IcyIcon("link", MENU_ICON_SIZE));
                                    menuPxSizeConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,
                                            InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK));
                                    menuPxSizeConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            CalibrationListDlg dlg = new CalibrationListDlg(mCore);
                                            dlg.setDefaultCloseOperation(2);
                                            dlg.setParentGUI(MMMainFrame.this);
                                            dlg.setVisible(true);
                                            dlg.addWindowListener(new WindowAdapter() {
                                                @Override
                                                public void windowClosed(WindowEvent e) {
                                                    super.windowClosed(e);
                                                    notifyConfigChanged(null);
                                                }
                                            });
                                            notifyConfigAboutToChange(null);
                                        }
                                    });

                                    JMenuItem loadConfigItem = new JMenuItem("Load Configuration");
                                    loadConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
                                            InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK));
                                    loadConfigItem.setIcon(new IcyIcon("folder_open", MENU_ICON_SIZE));
                                    loadConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            loadConfig();
                                            initializeGUI();
                                            refreshGUI();
                                        }
                                    });
                                    JMenuItem saveConfigItem = new JMenuItem("Save Configuration");
                                    saveConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
                                            InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK));
                                    saveConfigItem.setIcon(new IcyIcon("save", MENU_ICON_SIZE));
                                    saveConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            saveConfig();
                                        }
                                    });
                                    JMenuItem advancedConfigItem = new JMenuItem("Advanced Configuration");
                                    advancedConfigItem.setIcon(new IcyIcon("wrench_plus", MENU_ICON_SIZE));
                                    advancedConfigItem.addActionListener(new ActionListener() {

                                        /**
                                         */
                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            new ToolTipFrame(
                                                    "<html><h3>About Advanced Config</h3><p>Advanced Configuration is a tool "
                                                            + "in which you fill some data <br/>about your configuration that some "
                                                            + "plugins may need to access to.<br/> Exemple: the real values of the magnification"
                                                            + "of your objectives.</p></html>",
                                                    "MM4IcyAdvancedConfig");
                                            if (advancedDlg == null)
                                                advancedDlg = new AdvancedConfigurationDialog();
                                            advancedDlg.setVisible(!advancedDlg.isVisible());
                                            advancedDlg.setLocationRelativeTo(mainFrame);
                                        }
                                    });
                                    JMenuItem loadPresetConfigItem = new JMenuItem(
                                            "Load Configuration Presets");
                                    loadPresetConfigItem.setIcon(new IcyIcon("doc_import", MENU_ICON_SIZE));
                                    loadPresetConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            notifyConfigAboutToChange(null);
                                            loadPresets();
                                            notifyConfigChanged(null);
                                        }
                                    });
                                    JMenuItem savePresetConfigItem = new JMenuItem(
                                            "Save Configuration Presets");
                                    savePresetConfigItem.setIcon(new IcyIcon("doc_export", MENU_ICON_SIZE));
                                    savePresetConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            savePresets();
                                        }
                                    });
                                    JMenuItem aboutItem = new JMenuItem("About");
                                    aboutItem.setIcon(new IcyIcon("info", MENU_ICON_SIZE));
                                    aboutItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            final JDialog dialog = new JDialog(mainFrame, "About");
                                            JPanel panel_container = new JPanel();
                                            panel_container
                                                    .setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
                                            JPanel center = new JPanel(new BorderLayout());
                                            final JLabel value = new JLabel("<html><body>"
                                                    + "<h2>About</h2><p>Micro-Manager for Icy is being developed by Thomas Provoost."
                                                    + "<br/>Copyright 2011, Institut Pasteur</p><br/>"
                                                    + "<p>This plugin is based on Micro-Manager v1.4.6. which is developed under the following license:<br/>"
                                                    + "<i>This software is distributed free of charge in the hope that it will be<br/>"
                                                    + "useful, but WITHOUT ANY WARRANTY; without even the implied<br/>"
                                                    + "warranty of merchantability or fitness for a particular purpose. In no<br/>"
                                                    + "event shall the copyright owner or contributors be liable for any direct,<br/>"
                                                    + "indirect, incidental spacial, examplary, or consequential damages.<br/>"
                                                    + "Copyright University of California San Francisco, 2007, 2008, 2009,<br/>"
                                                    + "2010. All rights reserved.</i>" + "</p>"
                                                    + "</body></html>");
                                            JLabel link = new JLabel(
                                                    "<html><a href=\"\">For more information, please follow this link.</a></html>");
                                            link.addMouseListener(new MouseAdapter() {
                                                @Override
                                                public void mousePressed(MouseEvent mouseevent) {
                                                    NetworkUtil.openBrowser(
                                                            "http://valelab.ucsf.edu/~MM/MMwiki/index.php/Micro-Manager");
                                                }
                                            });
                                            value.setSize(new Dimension(50, 18));
                                            value.setAlignmentX(SwingConstants.HORIZONTAL);
                                            value.setBorder(BorderFactory.createEmptyBorder(0, 0, 20, 0));

                                            center.add(value, BorderLayout.CENTER);
                                            center.add(link, BorderLayout.SOUTH);

                                            JPanel panel_south = new JPanel();
                                            panel_south.setLayout(new BoxLayout(panel_south, BoxLayout.X_AXIS));
                                            JButton btn = new JButton("OK");
                                            btn.addActionListener(new ActionListener() {

                                                @Override
                                                public void actionPerformed(ActionEvent actionevent) {
                                                    dialog.dispose();
                                                }
                                            });
                                            panel_south.add(Box.createHorizontalGlue());
                                            panel_south.add(btn);
                                            panel_south.add(Box.createHorizontalGlue());

                                            dialog.setLayout(new BorderLayout());
                                            panel_container.setLayout(new BorderLayout());
                                            panel_container.add(center, BorderLayout.CENTER);
                                            panel_container.add(panel_south, BorderLayout.SOUTH);
                                            dialog.add(panel_container, BorderLayout.CENTER);
                                            dialog.setResizable(false);
                                            dialog.setVisible(true);
                                            dialog.pack();
                                            dialog.setLocation(
                                                    (int) mainFrame.getSize().getWidth() / 2
                                                            - dialog.getWidth() / 2,
                                                    (int) mainFrame.getSize().getHeight() / 2
                                                            - dialog.getHeight() / 2);
                                            dialog.setLocationRelativeTo(mainFrame);
                                        }
                                    });
                                    JMenuItem propertyBrowserItem = new JMenuItem("Property Browser");
                                    propertyBrowserItem.setAccelerator(
                                            KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, SHORTCUTKEY_MASK));
                                    propertyBrowserItem.setIcon(new IcyIcon("db", MENU_ICON_SIZE));
                                    propertyBrowserItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            editor.setVisible(!editor.isVisible());
                                        }
                                    });
                                    int idx = 0;
                                    toReturn.insert(hconfig, idx++);
                                    toReturn.insert(loadConfigItem, idx++);
                                    toReturn.insert(saveConfigItem, idx++);
                                    toReturn.insert(advancedConfigItem, idx++);
                                    toReturn.insertSeparator(idx++);
                                    toReturn.insert(loadPresetConfigItem, idx++);
                                    toReturn.insert(savePresetConfigItem, idx++);
                                    toReturn.insertSeparator(idx++);
                                    toReturn.insert(propertyBrowserItem, idx++);
                                    toReturn.insert(menuPxSizeConfigItem, idx++);
                                    toReturn.insertSeparator(idx++);
                                    toReturn.insert(aboutItem, idx++);
                                    return toReturn;
                                }
                            });

                            saveConfigButton_ = new JButton("Save Button");

                            // SETUP
                            _groupPad = new ConfigGroupPad();
                            _groupPad.setParentGUI(MMMainFrame.this);
                            _groupPad.setFont(new Font("", 0, 10));
                            _groupPad.setCore(mCore);
                            _groupPad.setParentGUI(MMMainFrame.this);
                            _groupButtonsPanel = new ConfigButtonsPanel();
                            _groupButtonsPanel.setCore(mCore);
                            _groupButtonsPanel.setGUI(MMMainFrame.this);
                            _groupButtonsPanel.setConfigPad(_groupPad);

                            // LEFT PART OF INTERFACE
                            _panelConfig = new JPanel();
                            _panelConfig.setLayout(new BoxLayout(_panelConfig, BoxLayout.Y_AXIS));
                            _panelConfig.add(_groupPad, BorderLayout.CENTER);
                            _panelConfig.add(_groupButtonsPanel, BorderLayout.SOUTH);
                            _panelConfig.setPreferredSize(new Dimension(300, 300));

                            // MIDDLE PART OF INTERFACE
                            _panel_cameraSettings = new JPanel();
                            _panel_cameraSettings.setLayout(new GridLayout(5, 2));
                            _panel_cameraSettings.setMinimumSize(new Dimension(100, 200));

                            _txtExposure = new JTextField();
                            try {
                                mCore.setExposure(90.0D);
                                _txtExposure.setText(String.valueOf(mCore.getExposure()));
                            } catch (Exception e2) {
                                _txtExposure.setText("90");
                            }
                            _txtExposure.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
                            _txtExposure.addKeyListener(new KeyAdapter() {
                                @Override
                                public void keyPressed(KeyEvent keyevent) {
                                    if (keyevent.getKeyCode() == KeyEvent.VK_ENTER)
                                        setExposure();
                                }
                            });
                            _panel_cameraSettings.add(new JLabel("Exposure [ms]: "));
                            _panel_cameraSettings.add(_txtExposure);

                            _combo_binning = new JComboBox();
                            _combo_binning.setMaximumRowCount(4);
                            _combo_binning.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25));
                            _combo_binning.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                    changeBinning();
                                }
                            });

                            _panel_cameraSettings.add(new JLabel("Binning: "));
                            _panel_cameraSettings.add(_combo_binning);

                            _combo_shutters = new JComboBox();
                            _combo_shutters.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent arg0) {
                                    try {
                                        if (_combo_shutters.getSelectedItem() != null) {
                                            mCore.setShutterDevice((String) _combo_shutters.getSelectedItem());
                                            _prefs.put(PREF_SHUTTER, (String) _combo_shutters
                                                    .getItemAt(_combo_shutters.getSelectedIndex()));
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            });
                            _combo_shutters.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25));
                            _panel_cameraSettings.add(new JLabel("Shutter : "));
                            _panel_cameraSettings.add(_combo_shutters);

                            ActionListener action_listener = new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    updateHistogram();
                                }
                            };

                            _cbAbsoluteHisto = new JCheckBox();
                            _cbAbsoluteHisto.addActionListener(action_listener);
                            _cbAbsoluteHisto.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent actionevent) {
                                    _comboBitDepth.setEnabled(_cbAbsoluteHisto.isSelected());
                                    _prefs.putBoolean(PREF_ABS_HIST, _cbAbsoluteHisto.isSelected());
                                }
                            });
                            _panel_cameraSettings.add(new JLabel("Display absolute histogram ?"));
                            _panel_cameraSettings.add(_cbAbsoluteHisto);

                            _comboBitDepth = new JComboBox(new String[] { "8-bit", "9-bit", "10-bit", "11-bit",
                                    "12-bit", "13-bit", "14-bit", "15-bit", "16-bit" });
                            _comboBitDepth.addActionListener(action_listener);
                            _comboBitDepth.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent actionevent) {
                                    _prefs.putInt(PREF_BITDEPTH, _comboBitDepth.getSelectedIndex());
                                }
                            });
                            _comboBitDepth.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
                            _comboBitDepth.setEnabled(false);
                            _panel_cameraSettings.add(new JLabel("Select your bit depth for abs. hitogram: "));
                            _panel_cameraSettings.add(_comboBitDepth);

                            // Acquisition
                            _panelAcquisitions = new JPanel();
                            _panelAcquisitions.setLayout(new BoxLayout(_panelAcquisitions, BoxLayout.Y_AXIS));

                            // Color settings
                            _panelColorChooser = new JPanel();
                            _panelColorChooser.setLayout(new BoxLayout(_panelColorChooser, BoxLayout.Y_AXIS));
                            painterPreferences = MicroscopePainterPreferences.getInstance();
                            painterPreferences.setPreferences(_prefs.node("paintersPreferences"));
                            painterPreferences.loadColors();

                            HashMap<String, Color> allColors = painterPreferences.getColors();
                            String[] allKeys = (String[]) allColors.keySet().toArray(new String[0]);
                            String[] columnNames = { "Painter", "Color", "Transparency" };
                            Object[][] data = new Object[allKeys.length][3];

                            for (int i = 0; i < allKeys.length; ++i) {
                                final int actualRow = i;
                                String actualKey = allKeys[i].toString();
                                data[i][0] = actualKey;
                                data[i][1] = allColors.get(actualKey);
                                final JSlider slider = new JSlider(0, 255, allColors.get(actualKey).getAlpha());
                                slider.addChangeListener(new ChangeListener() {

                                    @Override
                                    public void stateChanged(ChangeEvent changeevent) {
                                        painterTable.setValueAt(slider, actualRow, 2);
                                    }
                                });
                                data[i][2] = slider;
                            }
                            final AbstractTableModel tableModel = new JTableEvolvedModel(columnNames, data);
                            painterTable = new JTable(tableModel);
                            painterTable.getModel().addTableModelListener(new TableModelListener() {

                                @Override
                                public void tableChanged(TableModelEvent tablemodelevent) {
                                    if (tablemodelevent.getType() == TableModelEvent.UPDATE) {
                                        int row = tablemodelevent.getFirstRow();
                                        int col = tablemodelevent.getColumn();
                                        String columnName = tableModel.getColumnName(col);
                                        String painterName = (String) tableModel.getValueAt(row, 0);
                                        if (columnName.contains("Color")) {
                                            // New color value
                                            int alpha = painterPreferences.getColor(painterName).getAlpha();
                                            Color coloNew = (Color) tableModel.getValueAt(row, 1);
                                            painterPreferences.setColor(painterName, new Color(coloNew.getRed(),
                                                    coloNew.getGreen(), coloNew.getBlue(), alpha));
                                        } else if (columnName.contains("Transparency")) {
                                            // New alpha value
                                            Color c = painterPreferences.getColor(painterName);
                                            int alphaValue = ((JSlider) tableModel.getValueAt(row, 2))
                                                    .getValue();
                                            painterPreferences.setColor(painterName, new Color(c.getRed(),
                                                    c.getGreen(), c.getBlue(), alphaValue));
                                        }
                                        /*
                                         * for (int i = 0; i <
                                         * tableModel.getRowCount(); ++i) { try {
                                         * String painterName = (String)
                                         * tableModel.getValueAt(i, 0); Color c =
                                         * (Color) tableModel.getValueAt(i, 1); int
                                         * alphaValue; if (ASpinnerChanged &&
                                         * tablemodelevent.getFirstRow() == i) {
                                         * alphaValue = ((JSlider)
                                         * tableModel.getValueAt(i, 2)).getValue();
                                         * } else { alphaValue =
                                         * painterPreferences.getColor
                                         * (painterPreferences
                                         * .getPainterName(i)).getAlpha(); }
                                         * painterPreferences.setColor(painterName,
                                         * new Color(c.getRed(), c.getGreen(),
                                         * c.getBlue(), alphaValue)); } catch
                                         * (Exception e) { System.out.println(
                                         * "error with painter table update"); } }
                                         */
                                    }
                                }
                            });
                            painterTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
                            painterTable.setFillsViewportHeight(true);

                            // Create the scroll pane and add the table to it.
                            JScrollPane scrollPane = new JScrollPane(painterTable);

                            // Set up renderer and editor for the Favorite Color
                            // column.
                            painterTable.setDefaultRenderer(Color.class, new ColorRenderer(true));
                            painterTable.setDefaultEditor(Color.class, new ColorEditor());

                            painterTable.setDefaultRenderer(JSlider.class, new SliderRenderer(0, 255));
                            painterTable.setDefaultEditor(JSlider.class, new SliderEditor());

                            _panelColorChooser.add(scrollPane);
                            _panelColorChooser.add(Box.createVerticalGlue());

                            _mainPanel = new JPanel();
                            _mainPanel.setLayout(new BorderLayout());

                            // EDITOR
                            // will refresh the data and verify if any change
                            // occurs.
                            // editor = new PropertyEditor(MMMainFrame.this);
                            // editor.setCore(mCore);
                            // editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
                            // editor.addToMainDesktopPane();
                            // editor.refresh();
                            // editor.start();

                            editor = new PropertyEditor();
                            editor.setGui(MMMainFrame.this);
                            editor.setCore(mCore);
                            editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
                            // editor.addToMainDesktopPane();
                            // editor.refresh();
                            // editor.start();

                            add(_mainPanel);
                            initializeGUI();
                            loadPreferences();
                            refreshGUI();
                            setResizable(true);
                            addToMainDesktopPane();
                            instanced = true;
                            instancing = false;
                            _singleton = MMMainFrame.this;
                            setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                            addFrameListener(new IcyFrameAdapter() {
                                @Override
                                public void icyFrameClosing(IcyFrameEvent e) {
                                    customClose();
                                }
                            });
                            acceptListener = new AcceptListener() {

                                @Override
                                public boolean accept(Object source) {
                                    close();
                                    return _pluginListEmpty;
                                }
                            };

                            adapter = new MainAdapter() {

                                @Override
                                public void sequenceOpened(MainEvent event) {
                                    updateHistogram();
                                }

                            };
                            Icy.getMainInterface().addCanExitListener(acceptListener);
                            Icy.getMainInterface().addListener(adapter);
                        }
                    });
                }
            });
        }
    });
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

private void treeStructMapKeyPressed(java.awt.event.KeyEvent evt) {
    if ((evt.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            moveItem(false);//from  w  w  w.  jav  a  2s .com
        } else if (evt.getKeyCode() == KeyEvent.VK_UP) {
            moveItem(true);
        }
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

private void treeEntitiesKeyPressed(java.awt.event.KeyEvent evt) {
    if ((evt.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            moveItem(false);//www.  j av a  2  s  . c o  m
        } else if (evt.getKeyCode() == KeyEvent.VK_UP) {
            moveItem(true);
        }
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

private void checkHotKey(java.awt.event.KeyEvent evt) {
    if ((evt.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
        if (evt.getKeyCode() == KeyEvent.VK_1) {
            showSearch(true);//from  www  .j ava 2  s . co  m
        } else if (evt.getKeyCode() == KeyEvent.VK_2) {
            showMetaData(true);
        }
    } else if ((evt.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) {
        if (evt.getKeyCode() == KeyEvent.VK_S) {
            showSearch(true);
        } else if (evt.getKeyCode() == KeyEvent.VK_M) {
            showMetaData(true);
        }
    }
    if (evt.getKeyCode() == KeyEvent.VK_F5) {
        depositPresenter.refreshFileList();
    }
}

From source file:com.hexidec.ekit.EkitCore.java

public void keyPressed(KeyEvent ke) {

    // log.debug("> keyPressed");

    int keyCode = ke.getKeyCode();

    if (ke.getKeyChar() == KeyEvent.VK_ENTER && (enterIsBreak || inlineEdit)) {
        ke.consume();/*from   w  w w  .j a  v  a 2 s . c  om*/
    } else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_KP_UP) {
        Element tdElement = DocumentUtil.getElementByTag(htmlDoc, jtpMain.getCaretPosition(), Tag.TD);
        if (tdElement != null) {
            moveCaretOnTable(tdElement, true, ke.isShiftDown());
            ke.consume();
        }
    } else if (keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_KP_DOWN) {
        Element tdElement = DocumentUtil.getElementByTag(htmlDoc, jtpMain.getCaretPosition(), Tag.TD);
        if (tdElement != null) {
            moveCaretOnTable(tdElement, false, ke.isShiftDown());
            ke.consume();
        }
    } else if (keyCode == KeyEvent.VK_ENTER) {
        Element tdElement = DocumentUtil.getElementByTag(htmlDoc, jtpMain.getCaretPosition(), Tag.TD);
        // inside table
        if (tdElement != null) {
            try {
                insertBreakInsideTD(tdElement);
            } catch (Exception e) {
                log.error("Falha ao inserir quebra de linha.", e);
            }
            ke.consume();
        }
    } else if (keyCode == KeyEvent.VK_D && ke.isShiftDown() && ke.isControlDown()) {
        debug();
    }

    // log.debug("< keyPressed");
}

From source file:com.mirth.connect.client.ui.ChannelSetup.java

/**
 * Makes the destination table with a parameter that is true if a new destination should be
 * added as well.//from  ww  w.  j  a v a 2  s .  c om
 */
public void makeDestinationTable(boolean addNew) {
    List<Connector> destinationConnectors;
    Object[][] tableData;
    int tableSize;

    destinationConnectors = currentChannel.getDestinationConnectors();
    tableSize = destinationConnectors.size();

    if (addNew) {
        tableSize++;
    }

    int chain = 1;

    tableData = new Object[tableSize][5];

    for (int i = 0; i < tableSize; i++) {
        if (tableSize - 1 == i && addNew) {
            Connector connector = makeNewConnector(true);

            // Set the default inbound and outbound dataType and properties
            String dataType = currentChannel.getSourceConnector().getTransformer().getOutboundDataType();
            // Use a different properties object for the inbound and outbound
            DataTypeProperties defaultInboundProperties = LoadedExtensions.getInstance().getDataTypePlugins()
                    .get(dataType).getDefaultProperties();
            DataTypeProperties defaultOutboundProperties = LoadedExtensions.getInstance().getDataTypePlugins()
                    .get(dataType).getDefaultProperties();
            DataTypeProperties defaultResponseInboundProperties = LoadedExtensions.getInstance()
                    .getDataTypePlugins().get(dataType).getDefaultProperties();
            DataTypeProperties defaultResponseOutboundProperties = LoadedExtensions.getInstance()
                    .getDataTypePlugins().get(dataType).getDefaultProperties();

            connector.getTransformer().setInboundDataType(dataType);
            connector.getTransformer().setInboundProperties(defaultInboundProperties);
            connector.getTransformer().setOutboundDataType(dataType);
            connector.getTransformer().setOutboundProperties(defaultOutboundProperties);
            connector.getResponseTransformer().setInboundDataType(dataType);
            connector.getResponseTransformer().setInboundProperties(defaultResponseInboundProperties);
            connector.getResponseTransformer().setOutboundDataType(dataType);
            connector.getResponseTransformer().setOutboundProperties(defaultResponseOutboundProperties);

            connector.setName(getNewDestinationName(tableSize));
            connector.setTransportName(DESTINATION_DEFAULT);

            // We need to add the destination first so that the metadata ID is initialized.
            currentChannel.addDestination(connector);

            if (connector.isEnabled()) {
                tableData[i][0] = new CellData(
                        new ImageIcon(
                                com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_blue.png")),
                        UIConstants.ENABLED_STATUS);
            } else {
                tableData[i][0] = new CellData(
                        new ImageIcon(
                                com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_black.png")),
                        UIConstants.DISABLED_STATUS);
            }
            tableData[i][1] = connector.getName();
            tableData[i][2] = connector.getMetaDataId();
            tableData[i][3] = new ConnectorTypeData(destinationConnectors.get(i).getTransportName());

            if (i > 0 && !connector.isWaitForPrevious()) {
                chain++;
            }

            tableData[i][4] = chain;
        } else {

            if (destinationConnectors.get(i).isEnabled()) {
                tableData[i][0] = new CellData(
                        new ImageIcon(
                                com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_blue.png")),
                        UIConstants.ENABLED_STATUS);
            } else {
                tableData[i][0] = new CellData(
                        new ImageIcon(
                                com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_black.png")),
                        UIConstants.DISABLED_STATUS);
            }
            tableData[i][1] = destinationConnectors.get(i).getName();
            tableData[i][2] = destinationConnectors.get(i).getMetaDataId();
            tableData[i][3] = new ConnectorTypeData(destinationConnectors.get(i).getTransportName());

            if (i > 0 && !destinationConnectors.get(i).isWaitForPrevious()) {
                chain++;
            }

            tableData[i][4] = chain;
        }
    }

    destinationTable = new MirthTable();

    destinationTable.setModel(new javax.swing.table.DefaultTableModel(tableData,
            new String[] { STATUS_COLUMN_NAME, DESTINATION_COLUMN_NAME, METADATA_COLUMN_NAME,
                    CONNECTOR_TYPE_COLUMN_NAME, DESTINATION_CHAIN_COLUMN_NAME }) {

        boolean[] canEdit = new boolean[] { false, true, false, false, false };

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
        }
    });

    destinationTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    // Set the custom cell editor for the Destination Name column.
    destinationTable.getColumnModel()
            .getColumn(destinationTable.getColumnModel().getColumnIndex(DESTINATION_COLUMN_NAME))
            .setCellEditor(new DestinationTableCellEditor());
    destinationTable.setCustomEditorControls(true);

    // Must set the maximum width on columns that should be packed.
    destinationTable.getColumnExt(STATUS_COLUMN_NAME).setMaxWidth(UIConstants.MAX_WIDTH);
    destinationTable.getColumnExt(STATUS_COLUMN_NAME).setMinWidth(UIConstants.MIN_WIDTH);

    // Set the cell renderer for the status column.
    destinationTable.getColumnExt(STATUS_COLUMN_NAME).setCellRenderer(new ImageCellRenderer());

    // Set the maximum width and cell renderer for the metadata ID column
    destinationTable.getColumnExt(METADATA_COLUMN_NAME).setMaxWidth(UIConstants.METADATA_ID_COLUMN_WIDTH);
    destinationTable.getColumnExt(METADATA_COLUMN_NAME).setMinWidth(UIConstants.METADATA_ID_COLUMN_WIDTH);
    destinationTable.getColumnExt(METADATA_COLUMN_NAME)
            .setCellRenderer(new NumberCellRenderer(SwingConstants.CENTER, false));

    // Set the cell renderer for the destination connector type
    destinationTable.getColumnExt(CONNECTOR_TYPE_COLUMN_NAME).setCellRenderer(new ConnectorTypeCellRenderer());

    // Set the cell renderer and the max width for the destination chain column
    destinationTable.getColumnExt(DESTINATION_CHAIN_COLUMN_NAME)
            .setCellRenderer(new NumberCellRenderer(SwingConstants.CENTER, false));
    destinationTable.getColumnExt(DESTINATION_CHAIN_COLUMN_NAME).setMaxWidth(50);

    destinationTable.setSelectionMode(0);
    destinationTable.setRowSelectionAllowed(true);
    destinationTable.setRowHeight(UIConstants.ROW_HEIGHT);
    destinationTable.setFocusable(true);
    destinationTable.setSortable(false);
    destinationTable.getTableHeader().setReorderingAllowed(false);

    destinationTable.setOpaque(true);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        destinationTable.setHighlighters(highlighter);
    }

    // This action is called when a new selection is made on the destination
    // table.
    destinationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                if (lastModelIndex != -1 && lastModelIndex != destinationTable.getRowCount() && !isDeleting) {
                    Connector destinationConnector = currentChannel.getDestinationConnectors()
                            .get(lastModelIndex);

                    ConnectorProperties props = destinationConnectorPanel.getProperties();
                    ((DestinationConnectorPropertiesInterface) props).getDestinationConnectorProperties()
                            .setResourceIds(resourceIds.get(destinationConnector.getMetaDataId()));
                    destinationConnector.setProperties(props);
                }

                if (!loadConnector()) {
                    if (lastModelIndex == destinationTable.getRowCount()) {
                        destinationTable.setRowSelectionInterval(lastModelIndex - 1, lastModelIndex - 1);
                    } else {
                        destinationTable.setRowSelectionInterval(lastModelIndex, lastModelIndex);
                    }
                } else {
                    lastModelIndex = destinationTable.getSelectedModelIndex();
                }

                /*
                 * Loading the connector may have updated the current destination with incorrect
                 * properties, so after updating lastModelIndex we need to update the
                 * destination panel again.
                 */
                saveDestinationPanel();
                checkVisibleDestinationTasks();
            }
        }
    });

    destinationTable.requestFocus();

    // Mouse listener for trigger-button popup on the table.
    destinationTable.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mousePressed(java.awt.event.MouseEvent evt) {
            checkSelectionAndPopupMenu(evt);
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
            checkSelectionAndPopupMenu(evt);
        }
    });

    // Checks to see what to set the new row selection to based on
    // last index and if a new destination was added.
    int last = lastModelIndex;

    // Select each destination in turn so that the connector types can be decorated
    for (int row = 0; row < destinationTable.getRowCount(); row++) {
        destinationTable.setRowSelectionInterval(row, row);
        destinationConnectorPanel.decorateConnectorType();
    }

    if (addNew) {
        destinationTable.setRowSelectionInterval(destinationTable.getRowCount() - 1,
                destinationTable.getRowCount() - 1);
    } else if (last == -1) {
        destinationTable.setRowSelectionInterval(0, 0); // Makes sure the
    } // event is called
      // when the table is
      // created.
    else if (last == destinationTable.getRowCount()) {
        destinationTable.setRowSelectionInterval(last - 1, last - 1);
    } else {
        destinationTable.setRowSelectionInterval(last, last);
    }

    destinationTablePane.setViewportView(destinationTable);
    destinationTablePane.setWheelScrollingEnabled(true);

    // Key Listener trigger for DEL
    destinationTable.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                parent.doDeleteDestination();
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }
    });

    destinationTable.addMouseWheelListener(new MouseWheelListener() {

        public void mouseWheelMoved(MouseWheelEvent e) {
            destinationTablePane.getMouseWheelListeners()[0].mouseWheelMoved(e);
        }
    });
}