Example usage for javax.swing AbstractButton isShowing

List of usage examples for javax.swing AbstractButton isShowing

Introduction

In this page you can find the example usage for javax.swing AbstractButton isShowing.

Prototype

public boolean isShowing() 

Source Link

Document

Determines whether this component is showing on screen.

Usage

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./* w w  w . ja  v a 2 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;
                            }
                        }
                    }
                }
            }

        }
    });
}