Search in sources :

Example 41 with ComponentEvent

use of java.awt.event.ComponentEvent in project mylizzie by aerisnju.

the class AnalysisFrame method createAnalysisDialog.

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
public static JDialog createAnalysisDialog(JFrame owner) {
    // Create and set up the window.
    JDialog dialog = new JDialog(owner, "Leela Analyzer");
    // Create and set up the content pane.
    final AnalysisFrame newContentPane = new AnalysisFrame();
    // content panes must be opaque
    newContentPane.setOpaque(true);
    dialog.setContentPane(newContentPane);
    // Display the window.
    dialog.setSize(800, 600);
    // Handle close event
    dialog.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentHidden(ComponentEvent e) {
            newContentPane.getAnalysisTableModel().setSelectedMove(null);
            Lizzie.optionSetting.setAnalysisWindowShow(false);
        }
    });
    return dialog;
}
Also used : ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 42 with ComponentEvent

use of java.awt.event.ComponentEvent in project logisim-evolution by reds-heig.

the class Analyzer method addTab.

private void addTab(int index, final JComponent comp) {
    final JScrollPane pane = new JScrollPane(comp, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    if (comp instanceof TableTab) {
        pane.setVerticalScrollBar(((TableTab) comp).getVerticalScrollBar());
    }
    pane.addComponentListener(new ComponentListener() {

        public void componentHidden(ComponentEvent arg0) {
        }

        public void componentMoved(ComponentEvent arg0) {
        }

        public void componentResized(ComponentEvent event) {
            int width = pane.getViewport().getWidth();
            comp.setSize(new Dimension(width, comp.getHeight()));
        }

        public void componentShown(ComponentEvent arg0) {
        }
    });
    tabbedPane.insertTab("Untitled", null, pane, null, index);
}
Also used : JScrollPane(javax.swing.JScrollPane) ComponentListener(java.awt.event.ComponentListener) ComponentEvent(java.awt.event.ComponentEvent) Dimension(java.awt.Dimension)

Example 43 with ComponentEvent

use of java.awt.event.ComponentEvent in project chatty by chatty.

the class LiveStreamsList method addListeners.

private void addListeners() {
    ComponentListener cl = new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            // Trick from kleopatra:
            // https://stackoverflow.com/questions/7306295/swing-jlist-with-multiline-text-and-dynamic-height
            // next line possible if list is of type JXList
            // list.invalidateCellSizeCache();
            // for core: force cache invalidation by temporarily setting fixed height
            setFixedCellHeight(10);
            setFixedCellHeight(-1);
        }
    };
    addComponentListener(cl);
    JListActionHelper.install(this, (a, l, s) -> {
        if (a == Action.CONTEXT_MENU) {
            StreamInfosContextMenu m = new StreamInfosContextMenu(s, true);
            for (ContextMenuListener cml : contextMenuListeners) {
                m.addContextMenuListener(cml);
            }
            lastContextMenu = m;
            m.show(this, l.x, l.y);
        } else if (a == Action.ENTER) {
            List<String> channels = new ArrayList<>();
            s.forEach(si -> channels.add(si.stream));
            for (ContextMenuListener cml : contextMenuListeners) {
                cml.streamsMenuItemClicked(new ActionEvent(s, 0, "join"), channels);
            }
        } else if (a == Action.DOUBLE_CLICK || a == Action.SPACE) {
            StreamInfo info = getSelectedValue();
            if (info != null && liveStreamListener != null) {
                liveStreamListener.liveStreamClicked(info);
            }
        }
    });
}
Also used : Color(java.awt.Color) Timer(java.util.Timer) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) Helper(chatty.Helper) ArrayList(java.util.ArrayList) Border(javax.swing.border.Border) HashSet(java.util.HashSet) SwingUtilities(javax.swing.SwingUtilities) ComponentListener(java.awt.event.ComponentListener) TitledBorder(javax.swing.border.TitledBorder) TimerTask(java.util.TimerTask) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) JPopupMenu(javax.swing.JPopupMenu) JList(javax.swing.JList) Set(java.util.Set) StreamInfo(chatty.util.api.StreamInfo) BorderFactory(javax.swing.BorderFactory) ComponentEvent(java.awt.event.ComponentEvent) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) ComponentAdapter(java.awt.event.ComponentAdapter) Action(chatty.gui.components.JListActionHelper.Action) List(java.util.List) DateTime(chatty.util.DateTime) JTextArea(javax.swing.JTextArea) Comparator(java.util.Comparator) ComponentListener(java.awt.event.ComponentListener) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) ActionEvent(java.awt.event.ActionEvent) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) StreamInfo(chatty.util.api.StreamInfo) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 44 with ComponentEvent

use of java.awt.event.ComponentEvent in project briefcase by opendatakit.

the class ODKOptionPane method showErrorDialog.

public static void showErrorDialog(Component parentComponent, String errorString, String title) {
    // create a n-character wide label for aiding layout calculations...
    // the dialog box will display this width of text.
    JLabel t = new JLabel("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");
    JTextArea textArea = new JTextArea(errorString);
    textArea.setEditable(false);
    // same as JLabel
    textArea.setFont(t.getFont());
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    // same as JLabel
    textArea.setBackground(t.getBackground());
    // textArea.setBackground(Color.white); // same as JLabel
    // same as JLabel
    textArea.setForeground(t.getForeground());
    final JScrollPane scrollPane = new JScrollPane(textArea);
    // don't show the gray border of the scroll pane
    // unless we are showing the scroll bar, in which case we do show it.
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    scrollPane.getVerticalScrollBar().addComponentListener(new ComponentListener() {

        @Override
        public void componentHidden(ComponentEvent component) {
            if (component.getComponent().equals(scrollPane.getVerticalScrollBar())) {
                scrollPane.setBorder(BorderFactory.createEmptyBorder());
            }
        }

        @Override
        public void componentMoved(ComponentEvent component) {
        }

        @Override
        public void componentResized(ComponentEvent component) {
        }

        @Override
        public void componentShown(ComponentEvent component) {
            if (component.getComponent().equals(scrollPane.getVerticalScrollBar())) {
                scrollPane.setBorder(BorderFactory.createLineBorder(Color.GRAY));
            }
        }
    });
    // set preferred and minimum widths of the scroll pane to
    // the width of the 't' label above with 5 lines within the scroll area.
    Dimension pref = t.getPreferredSize();
    pref.setSize(pref.getWidth(), 5.3 * pref.getHeight());
    scrollPane.setMinimumSize(pref);
    scrollPane.setPreferredSize(pref);
    JOptionPane.showMessageDialog(parentComponent, scrollPane, title, JOptionPane.ERROR_MESSAGE);
}
Also used : JScrollPane(javax.swing.JScrollPane) ComponentListener(java.awt.event.ComponentListener) JTextArea(javax.swing.JTextArea) JLabel(javax.swing.JLabel) ComponentEvent(java.awt.event.ComponentEvent) Dimension(java.awt.Dimension)

Example 45 with ComponentEvent

use of java.awt.event.ComponentEvent in project CCDD by nasa.

the class CcddProjectFieldDialog method initialize.

/**
 ********************************************************************************************
 * Create the project data field manager dialog. This is executed in a separate thread since it
 * can take a noticeable amount time to complete, and by using a separate thread the GUI is
 * allowed to continue to update. The GUI menu commands, however, are disabled until the
 * telemetry scheduler initialization completes execution
 ********************************************************************************************
 */
private void initialize() {
    // Build the project data field manager dialog in the background
    CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {

        // Create panels to hold the components of the dialog
        JPanel dialogPnl = new JPanel(new GridBagLayout());

        JPanel buttonPnl = new JPanel();

        JButton btnClose;

        /**
         ************************************************************************************
         * Build the project data field manager dialog
         ************************************************************************************
         */
        @Override
        protected void execute() {
            // Set the initial layout manager characteristics
            GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, 0, 0), 0, 0);
            Border emptyBorder = BorderFactory.createEmptyBorder();
            // Set the flag to indicate the project data field manager dialog is being
            // initialized
            isInitializing = true;
            // Add an undo edit manager
            undoManager = new CcddUndoManager() {

                /**
                 ****************************************************************************
                 * Update the change indicator if the editor panel has changed
                 ****************************************************************************
                 */
                @Override
                protected void ownerHasChanged() {
                    // - changes during initialization are ignored
                    if (!isInitializing) {
                        updateChangeIndicator();
                    }
                }
            };
            // Create the undo handler for the components with undoable actions. Disable
            // storage of edit actions during dialog creation
            undoHandler = new CcddUndoHandler(undoManager);
            undoHandler.setAllowUndo(false);
            // Create the field panel for the project description and data fields
            fieldPnlHndlr = new CcddInputFieldPanelHandler() {

                /**
                 ****************************************************************************
                 * Update the project data field manager change indicator
                 ****************************************************************************
                 */
                @Override
                protected void updateOwnerChangeIndicator() {
                    updateChangeIndicator();
                }
            };
            // Get the project description
            committedDescription = dbControl.getDatabaseDescription(dbControl.getDatabaseName());
            // Set the undo/redo manager and handler for the description and data field values
            fieldPnlHndlr.setEditPanelUndo(undoManager, undoHandler);
            // Create a field handler containing all data fields
            fieldHandler = new CcddFieldHandler(ccddMain, CcddFieldHandler.getFieldProjectName(), CcddProjectFieldDialog.this);
            // Set the data field handler reference in the undo handler so that data field
            // edits can be undone/redone
            undoHandler.setFieldHandler(fieldHandler);
            // Build the field information for the project data fields
            committedFieldInformation = fieldHandler.getFieldInformationCopy();
            // Create the input field panel
            fieldPnlHndlr.createDescAndDataFieldPanel(CcddProjectFieldDialog.this, null, null, committedDescription, fieldHandler);
            // Set the modal undo manager in the keyboard handler while the project data
            // field manager is active
            ccddMain.getKeyboardHandler().setModalDialogReference(undoManager, null);
            dialogPnl.setBorder(emptyBorder);
            // Create the project data field manager dialog labels and fields
            JLabel dlgLabel = new JLabel("Project: " + dbControl.getProjectName());
            dlgLabel.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            dialogPnl.add(dlgLabel, gbc);
            // Add the field panel to the dialog
            gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
            gbc.insets.left = 0;
            gbc.insets.bottom = 0;
            gbc.insets.right = 0;
            gbc.weighty = 1.0;
            gbc.gridy++;
            dialogPnl.add(fieldPnlHndlr.getFieldPanel(), gbc);
            // Re-enable storage of edit actions
            undoHandler.setAllowUndo(true);
            // Manage fields button
            btnManageFields = CcddButtonPanelHandler.createButton("Fields", FIELD_ICON, KeyEvent.VK_F, "Manage the data fields");
            // Add a listener for the Manage Fields command
            btnManageFields.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Manage the data fields
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // Create the field editor dialog showing the fields for this project
                    new CcddFieldEditorDialog(ccddMain, fieldPnlHndlr, CcddFieldHandler.getFieldProjectName(), false, ModifiableSizeInfo.MIN_DIALOG_WIDTH.getSize());
                    // Set the undo manager in the keyboard handler back to the project data
                    // field manager
                    ccddMain.getKeyboardHandler().setModalDialogReference(undoManager, null);
                    // Enable/disable the Clear values button depending on if any data fields
                    // remain
                    btnClearValues.setEnabled(!fieldHandler.getFieldInformation().isEmpty());
                }
            });
            // Clear fields button
            btnClearValues = CcddButtonPanelHandler.createButton("Clear", CLEAR_ICON, KeyEvent.VK_C, "Clear the data fields");
            // Enable/disable the Clear values button depending on if any data fields
            // remain
            btnClearValues.setEnabled(!fieldHandler.getFieldInformation().isEmpty());
            // Add a listener for the Clear values command
            btnClearValues.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Clear the table data field values
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // Clear all of the data field values for the project
                    fieldPnlHndlr.clearFieldValues();
                }
            });
            // Undo button
            JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
            // Create a listener for the Undo command
            ActionListener undoAction = new ActionListener() {

                /**
                 ****************************************************************************
                 * Undo the last edit
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    undoManager.undo();
                    // Update the data field background colors
                    fieldPnlHndlr.setFieldBackgound();
                }
            };
            // Add the undo listener to the Undo button and menu command
            btnUndo.addActionListener(undoAction);
            // Redo button
            JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
            // Create a listener for the Redo command
            ActionListener redoAction = new ActionListener() {

                /**
                 ****************************************************************************
                 * Redo the last cell that was undone
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    undoManager.redo();
                    // Update the data field background colors
                    fieldPnlHndlr.setFieldBackgound();
                }
            };
            // Add the redo listener to the Redo button and menu command
            btnRedo.addActionListener(redoAction);
            // Store project data fields button
            JButton btnStoreFields = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store project data field updates in the database");
            // Add a listener for the Store button
            btnStoreFields.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Store the project description and data fields in the database
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // the user confirms discarding them
                    if (isFieldsChanged() && new CcddDialogHandler().showMessageDialog(CcddProjectFieldDialog.this, "<html><b>Store project data fields?", "Store Project Fields", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                        // Store the project description and data fields in the database
                        ccddMain.getDbTableCommandHandler().modifyProjectFields(fieldPnlHndlr.getDescription(), fieldHandler.getFieldInformation(), CcddProjectFieldDialog.this);
                        // Store the updated description and fields for comparison with a
                        // subsequent store operation
                        committedDescription = fieldPnlHndlr.getDescription();
                        committedFieldInformation = fieldHandler.getFieldInformationCopy();
                        // Update the project field dialog's change indicator
                        updateChangeIndicator();
                    }
                }
            });
            // Close button
            btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the group manager");
            // Add a listener for the Close button
            btnClose.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Close the group selection dialog
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // elects to discard the changes
                    if (!isFieldsChanged() || new CcddDialogHandler().showMessageDialog(CcddProjectFieldDialog.this, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                        // Close the dialog
                        closeDialog();
                        // Clear the modal dialog references in the keyboard handler
                        ccddMain.getKeyboardHandler().setModalDialogReference(null, null);
                    }
                }
            });
            // Add buttons in the order in which they'll appear (left to right, top to bottom)
            buttonPnl.add(btnManageFields);
            buttonPnl.add(btnUndo);
            buttonPnl.add(btnStoreFields);
            buttonPnl.add(btnClearValues);
            buttonPnl.add(btnRedo);
            buttonPnl.add(btnClose);
            // Distribute the buttons across two rows
            setButtonRows(2);
            // Store the current data field information in the event an undo/redo operation
            // occurs
            fieldPnlHndlr.storeCurrentFieldInformation();
            undoManager.endEditSequence();
            // Add a listener for changes in the panel's size
            CcddProjectFieldDialog.this.addComponentListener(new ComponentAdapter() {

                /**
                 ****************************************************************************
                 * Handle resizing of the panel
                 ****************************************************************************
                 */
                @Override
                public void componentResized(ComponentEvent ce) {
                    // Create a runnable object to be executed
                    SwingUtilities.invokeLater(new Runnable() {

                        /**
                         ********************************************************************
                         * Since the size returned by get___Size() can lag the actual size, use
                         * invokeLater to let the sizes "catch up"
                         ********************************************************************
                         */
                        @Override
                        public void run() {
                            // Update the minimum size of the owner so that all of the fields
                            // remain visible
                            CcddProjectFieldDialog.this.setPreferredSize(null);
                            CcddProjectFieldDialog.this.setMinimumSize(new Dimension(Math.max(ModifiableSizeInfo.MIN_DIALOG_WIDTH.getSize(), fieldPnlHndlr.getMaxFieldWidth()), CcddProjectFieldDialog.this.getPreferredSize().height));
                        }
                    });
                }
            });
            // Reset the flag now that initialization is complete
            isInitializing = false;
        }

        /**
         ************************************************************************************
         * Project data field manager dialog creation complete
         ************************************************************************************
         */
        @Override
        protected void complete() {
            // Display the project data field manager dialog
            showOptionsDialog(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnClose, DIALOG_TITLE, true);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand) ComponentEvent(java.awt.event.ComponentEvent) Border(javax.swing.border.Border) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

ComponentEvent (java.awt.event.ComponentEvent)120 ComponentAdapter (java.awt.event.ComponentAdapter)97 Dimension (java.awt.Dimension)22 Component (java.awt.Component)18 ActionEvent (java.awt.event.ActionEvent)18 JPanel (javax.swing.JPanel)18 JScrollPane (javax.swing.JScrollPane)16 ComponentListener (java.awt.event.ComponentListener)15 MouseEvent (java.awt.event.MouseEvent)15 JButton (javax.swing.JButton)15 JLabel (javax.swing.JLabel)15 BorderLayout (java.awt.BorderLayout)12 Point (java.awt.Point)12 WindowAdapter (java.awt.event.WindowAdapter)12 WindowEvent (java.awt.event.WindowEvent)12 MouseAdapter (java.awt.event.MouseAdapter)11 ActionListener (java.awt.event.ActionListener)10 JTable (javax.swing.JTable)9 AbstractAction (javax.swing.AbstractAction)8 BoxLayout (javax.swing.BoxLayout)8