Search in sources :

Example 96 with ComponentAdapter

use of java.awt.event.ComponentAdapter in project Spark by igniterealtime.

the class BroadcastDialog method invokeDialog.

/**
 * Displays the broadcast dialog.
 */
public void invokeDialog() {
    final JDialog dlg;
    TitlePanel titlePanel;
    // Create the title panel for this dialog
    titlePanel = new TitlePanel(Res.getString("title.broadcast.message"), Res.getString("message.enter.broadcast.message"), null, true);
    // Construct main panel w/ layout.
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(titlePanel, BorderLayout.NORTH);
    // The user should only be able to close this dialog.
    JButton okButton = new JButton(Res.getString("ok"));
    JButton closeButton = new JButton(Res.getString("close"));
    mainPanel.add(this, BorderLayout.CENTER);
    JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    buttonpanel.add(okButton);
    buttonpanel.add(closeButton);
    mainPanel.add(buttonpanel, BorderLayout.SOUTH);
    dlg = new JDialog(SparkManager.getMainWindow(), Res.getString("broadcast"));
    dlg.setContentPane(mainPanel);
    dlg.pack();
    final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getBroadcastMessageBounds();
    if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
        // Use default settings.
        dlg.setSize(800, 600);
        dlg.setLocationRelativeTo(null);
    } else {
        dlg.setBounds(bounds);
    }
    dlg.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setBroadcastMessageBounds(dlg.getBounds());
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setBroadcastMessageBounds(dlg.getBounds());
        }
    });
    dlg.setResizable(false);
    // Add listener
    okButton.addActionListener(e -> {
        try {
            if (sendBroadcasts(dlg)) {
                dlg.setVisible(false);
            }
        } catch (SmackException.NotConnectedException e1) {
            Log.warning("Unable to broadcast.", e1);
        }
    });
    closeButton.addActionListener(e -> dlg.setVisible(false));
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
    messageBox.requestFocus();
}
Also used : JPanel(javax.swing.JPanel) SmackException(org.jivesoftware.smack.SmackException) JButton(javax.swing.JButton) ComponentEvent(java.awt.event.ComponentEvent) JDialog(javax.swing.JDialog) TitlePanel(org.jivesoftware.spark.component.TitlePanel) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 97 with ComponentAdapter

use of java.awt.event.ComponentAdapter in project Spark by igniterealtime.

the class BroadcastHistoryFrame method initComponents.

private void initComponents() {
    SearchButton = new javax.swing.JToggleButton();
    DateField = new javax.swing.JFormattedTextField();
    SearchDate = new javax.swing.JLabel();
    Date date = new Date();
    Format formatter = new SimpleDateFormat("yyy-MM");
    String myDate = formatter.format(date);
    DateField.setValue(myDate);
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    JScrollPane panelPane = new JScrollPane(BroadcastHistoryArea);
    SearchDate.setText(Res.getString("label.broadcast.history.search.date"));
    setTitle(Res.getString("title.broadcast.history"));
    try {
        readFromFile(myDate);
    } catch (IOException ex) {
        Log.error("Couldn't read from file" + ex.getMessage() + Arrays.toString(ex.getStackTrace()));
    }
    SearchButton.setText((Res.getString("button.search")));
    SearchButton.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            SearchButtonMouseClicked(evt);
        }
    });
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(panelPane, javax.swing.GroupLayout.DEFAULT_SIZE, 533, javax.swing.GroupLayout.DEFAULT_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(SearchDate).addComponent(SearchButton).addComponent(DateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(22, 22, 22)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(panelPane, javax.swing.GroupLayout.DEFAULT_SIZE, 350, javax.swing.GroupLayout.DEFAULT_SIZE)).addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(SearchDate).addGap(10, 10, 10).addComponent(DateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(SearchButton))).addContainerGap(15, Short.MAX_VALUE)));
    pack();
    final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getBroadcastHistoryBounds();
    if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
        // Use default settings.
        setLocationRelativeTo(null);
    } else {
        setBounds(bounds);
    }
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setBroadcastHistoryBounds(getBounds());
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setBroadcastHistoryBounds(getBounds());
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) IOException(java.io.IOException) Date(java.util.Date) Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) ComponentEvent(java.awt.event.ComponentEvent) SimpleDateFormat(java.text.SimpleDateFormat) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 98 with ComponentAdapter

use of java.awt.event.ComponentAdapter 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, favFirst, dockedHelper.isDocked());
            m.setSorting(currentSorting.key);
            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) {
            if (s != null && !s.isEmpty() && liveStreamListener != null) {
                liveStreamListener.liveStreamClicked(s);
            }
        }
    });
}
Also used : Color(java.awt.Color) Settings(chatty.util.settings.Settings) HashMap(java.util.HashMap) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) Helper(chatty.Helper) ArrayList(java.util.ArrayList) Border(javax.swing.border.Border) ChannelFavorites(chatty.ChannelFavorites) HashSet(java.util.HashSet) SwingUtilities(javax.swing.SwingUtilities) ComponentListener(java.awt.event.ComponentListener) Map(java.util.Map) ImageIcon(javax.swing.ImageIcon) TitledBorder(javax.swing.border.TitledBorder) Timer(javax.swing.Timer) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) JPopupMenu(javax.swing.JPopupMenu) JList(javax.swing.JList) Set(java.util.Set) DockedDialogHelper(chatty.gui.DockedDialogHelper) StreamInfo(chatty.util.api.StreamInfo) BorderFactory(javax.swing.BorderFactory) ComponentEvent(java.awt.event.ComponentEvent) Logger(java.util.logging.Logger) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) ChangeListener(chatty.ChannelFavorites.ChangeListener) ComponentAdapter(java.awt.event.ComponentAdapter) Action(chatty.gui.components.JListActionHelper.Action) List(java.util.List) ElapsedTime(chatty.util.ElapsedTime) DateTime(chatty.util.DateTime) JTextArea(javax.swing.JTextArea) Comparator(java.util.Comparator) GuiUtil(chatty.gui.GuiUtil) ComponentListener(java.awt.event.ComponentListener) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) ActionEvent(java.awt.event.ActionEvent) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 99 with ComponentAdapter

use of java.awt.event.ComponentAdapter in project triplea by triplea-game.

the class BattleCalculatorDialog method show.

/**
 * Shows the Odds Calculator dialog and initializes it using the current state of the specified
 * territory.
 */
public static void show(final TripleAFrame taFrame, final Territory t, final GameData data) {
    // Note: The data param may not be the same as taFrame.getGame().getData() as GameData gets
    // cloned when showing history with a different History instance that doesn't correspond to
    // what's shown.
    final BattleCalculatorPanel panel = new BattleCalculatorPanel(data, taFrame.getUiContext(), t);
    final BattleCalculatorDialog dialog = new BattleCalculatorDialog(panel, taFrame);
    dialog.pack();
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowActivated(final WindowEvent e) {
            instances.remove(dialog);
            instances.add(dialog);
        }

        @Override
        public void windowClosed(final WindowEvent e) {
            if (taFrame.getUiContext() != null && !taFrame.getUiContext().isShutDown()) {
                taFrame.getUiContext().removeShutdownWindow(dialog);
            }
        }
    });
    dialog.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(final ComponentEvent e) {
            final Dimension size = dialog.getSize();
            size.width = Math.min(size.width, taFrame.getWidth() - 50);
            size.height = Math.min(size.height, taFrame.getHeight() - 50);
            dialog.setSize(size);
        }
    });
    taFrame.getTerritoryDetails().addBattleCalculatorKeyBindings(dialog);
    // close when hitting the escape key
    SwingKeyBinding.addKeyBinding(dialog, KeyCode.ESCAPE, () -> {
        dialog.setVisible(false);
        dialog.dispose();
    });
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    if (lastPosition == null) {
        dialog.setLocationRelativeTo(taFrame);
    } else {
        dialog.setLocation(lastPosition);
    }
    dialog.setVisible(true);
    // On some desktop environments, there is an odd behaviour: The new battle calculator dialog is
    // not put at the front if the last user-interaction was to move the window of an already
    // existing battle calculator dialog.  Oddly enough, calling toFront() directly here (before or
    // after setVisible(true)) has no effect either, but delaying the call to the end of the queue
    // of the Event Dispatch Thread solves the issue (though you can see the new dialog in the
    // background for an blink of an eye).
    // Tested with Cinnamon Desktop 4.8.5.
    SwingUtilities.invokeLater(dialog::toFront);
    taFrame.getUiContext().addShutdownWindow(dialog);
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) ComponentEvent(java.awt.event.ComponentEvent) Dimension(java.awt.Dimension) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 100 with ComponentAdapter

use of java.awt.event.ComponentAdapter in project cayenne by apache.

the class CayenneModelerFrame method initToolbar.

/**
 * Initializes main toolbar.
 */
protected void initToolbar() {
    final JToolBar toolBar = new MainToolBar();
    Dimension smallBtnDim = new Dimension(30, 30);
    JButton backButton = getAction(NavigateBackwardAction.class).buildButton(1);
    backButton.setMinimumSize(smallBtnDim);
    backButton.setPreferredSize(smallBtnDim);
    toolBar.add(backButton);
    JButton forwardButton = getAction(NavigateForwardAction.class).buildButton(3);
    forwardButton.setMinimumSize(smallBtnDim);
    forwardButton.setPreferredSize(smallBtnDim);
    toolBar.add(forwardButton);
    toolBar.addSeparator(new Dimension(30, 0));
    toolBar.add(getAction(NewProjectAction.class).buildButton(1));
    toolBar.add(getAction(OpenProjectAction.class).buildButton(2));
    toolBar.add(getAction(SaveAction.class).buildButton(3));
    toolBar.addSeparator();
    JButton removeButton = getAction(RemoveAction.class).buildButton();
    toolBar.add(removeButton);
    toolBar.addSeparator();
    toolBar.add(getAction(CutAction.class).buildButton(1));
    toolBar.add(getAction(CopyAction.class).buildButton(2));
    toolBar.add(getAction(PasteAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(getAction(UndoAction.class).buildButton(1));
    toolBar.add(getAction(RedoAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(getAction(CreateNodeAction.class).buildButton(1));
    toolBar.add(getAction(CreateDataMapAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(getAction(CreateDbEntityAction.class).buildButton(1));
    toolBar.add(getAction(CreateProcedureAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(getAction(CreateObjEntityAction.class).buildButton(1));
    toolBar.add(getAction(CreateEmbeddableAction.class).buildButton(2));
    toolBar.add(getAction(CreateQueryAction.class).buildButton(3));
    // is used to place search feature components the most right on a toolbar
    toolBar.add(new SearchPanel());
    getContentPane().add(toolBar, BorderLayout.NORTH);
    // Hide some buttons when frame is too small
    final int defaultBtnWidth = removeButton.getUI().getPreferredSize(backButton).width;
    addComponentListener(new ComponentAdapter() {

        private final int[] empty = {};

        private final int[] all = { 6, 7, 8, 9, 10, 11, 12, 13, 14 };

        private final int[] remove = { 6, 7 };

        private final int[] removeAndCopy = { 6, 7, 8, 9, 10, 11 };

        private final int[] undo = { 12, 13, 14 };

        private final int[] undoAndCopy = { 8, 9, 10, 11, 12, 13, 14 };

        @Override
        public void componentResized(ComponentEvent e) {
            int[] hidden, shown;
            if (getSize().width < (13 * defaultBtnWidth + 300)) {
                hidden = all;
                shown = empty;
            } else if (getSize().width < (16 * defaultBtnWidth + 300)) {
                hidden = removeAndCopy;
                shown = undo;
            } else if (getSize().width < (18 * defaultBtnWidth + 300)) {
                hidden = remove;
                shown = undoAndCopy;
            } else {
                hidden = empty;
                shown = all;
            }
            for (int i : hidden) {
                toolBar.getComponentAtIndex(i).setVisible(false);
            }
            for (int i : shown) {
                toolBar.getComponentAtIndex(i).setVisible(true);
            }
        }
    });
}
Also used : JButton(javax.swing.JButton) NavigateForwardAction(org.apache.cayenne.modeler.action.NavigateForwardAction) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) NavigateBackwardAction(org.apache.cayenne.modeler.action.NavigateBackwardAction) MainToolBar(org.apache.cayenne.swing.components.MainToolBar) ComponentEvent(java.awt.event.ComponentEvent) RemoveAction(org.apache.cayenne.modeler.action.RemoveAction) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

ComponentAdapter (java.awt.event.ComponentAdapter)207 ComponentEvent (java.awt.event.ComponentEvent)207 Dimension (java.awt.Dimension)46 JPanel (javax.swing.JPanel)41 BorderLayout (java.awt.BorderLayout)36 WindowEvent (java.awt.event.WindowEvent)36 WindowAdapter (java.awt.event.WindowAdapter)35 JScrollPane (javax.swing.JScrollPane)30 JLabel (javax.swing.JLabel)27 ActionEvent (java.awt.event.ActionEvent)25 MouseEvent (java.awt.event.MouseEvent)25 JButton (javax.swing.JButton)25 MouseAdapter (java.awt.event.MouseAdapter)20 Component (java.awt.Component)19 Insets (java.awt.Insets)19 Point (java.awt.Point)19 Color (java.awt.Color)17 ActionListener (java.awt.event.ActionListener)17 JFrame (javax.swing.JFrame)17 GridBagConstraints (java.awt.GridBagConstraints)16