opends/src/guitools/org/opends/guitools/controlpanel/ControlPanel.java
@@ -122,7 +122,7 @@ // Create and set up the content pane. controlCenterPane = new ControlCenterMainPane(info); // Create and set up the window. dlg = new JFrame(); dlg = Utilities.createFrame(); dlg.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); final MainMenuBar menuBar = new MainMenuBar(info); dlg.addWindowListener(new WindowAdapter() { opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
@@ -35,6 +35,7 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; @@ -269,8 +270,15 @@ public void toBeDisplayed(boolean visible) { super.toBeDisplayed(visible); ((GenericDialog)Utilities.getParentDialog(this)).getRootPane(). setDefaultButton(null); Window w = Utilities.getParentDialog(this); if (w instanceof GenericDialog) { ((GenericDialog)w).getRootPane().setDefaultButton(null); } else if (w instanceof GenericFrame) { ((GenericFrame)w).getRootPane().setDefaultButton(null); } } /** opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseEntriesPanel.java
@@ -22,7 +22,7 @@ * CDDL HEADER END * * * Copyright 2008 Sun Microsystems, Inc. * Copyright 2008-2009 Sun Microsystems, Inc. */ package org.opends.guitools.controlpanel.ui; @@ -1017,12 +1017,11 @@ BrowseEntriesPanel panel = new BrowseEntriesPanel(); panel.setDisposeOnClose(true); panel.setInfo(getInfo()); GenericDialog dlg = new GenericDialog(Utilities.getFrame(this), panel); GenericFrame frame = new GenericFrame(panel); Utilities.centerGoldenMean(dlg, Utilities.getFrame(this)); Utilities.centerGoldenMean(frame, Utilities.getFrame(this)); dlg.setVisible(true); frame.setVisible(true); } /** opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseGeneralMonitoringPanel.java
@@ -33,6 +33,7 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Window; import java.util.HashMap; import javax.swing.ImageIcon; @@ -167,8 +168,15 @@ @Override public void toBeDisplayed(boolean visible) { ((GenericDialog)Utilities.getParentDialog(this)).getRootPane(). setDefaultButton(null); Window w = Utilities.getParentDialog(this); if (w instanceof GenericDialog) { ((GenericDialog)w).getRootPane().setDefaultButton(null); } else if (w instanceof GenericFrame) { ((GenericFrame)w).getRootPane().setDefaultButton(null); } } /** opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseIndexPanel.java
@@ -34,6 +34,7 @@ import java.awt.GridBagConstraints; import java.awt.Insets; import java.awt.Point; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; @@ -159,8 +160,15 @@ public void toBeDisplayed(boolean visible) { super.toBeDisplayed(visible); ((GenericDialog)Utilities.getParentDialog(this)). getRootPane().setDefaultButton(null); Window w = Utilities.getParentDialog(this); if (w instanceof GenericDialog) { ((GenericDialog)w).getRootPane().setDefaultButton(null); } else if (w instanceof GenericFrame) { ((GenericFrame)w).getRootPane().setDefaultButton(null); } } /** opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java
@@ -35,6 +35,7 @@ import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Point; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; @@ -229,8 +230,15 @@ @Override public void toBeDisplayed(boolean visible) { ((GenericDialog)Utilities.getParentDialog(this)).getRootPane(). setDefaultButton(null); Window w = Utilities.getParentDialog(this); if (w instanceof GenericDialog) { ((GenericDialog)w).getRootPane().setDefaultButton(null); } else if (w instanceof GenericFrame) { ((GenericFrame)w).getRootPane().setDefaultButton(null); } } /** opends/src/guitools/org/opends/guitools/controlpanel/ui/GenericDialog.java
@@ -22,7 +22,7 @@ * CDDL HEADER END * * * Copyright 2008 Sun Microsystems, Inc. * Copyright 2008-2009 Sun Microsystems, Inc. */ package org.opends.guitools.controlpanel.ui; @@ -130,15 +130,10 @@ JMenuBar menu = panel.getMenuBar(); if (menu != null) { setJMenuBar(menu); parentFrame.setJMenuBar(menu); } setResizable(true); JScrollPane scroll = Utilities.createScrollPane(panel); /* CardLayout cardLayout = new CardLayout(); contentPanel = new JPanel(cardLayout); contentPanel.setOpaque(false); setContentPane(contentPanel); */ JPanel inputPanel = new JPanel(new GridBagLayout()); setContentPane(inputPanel); GridBagConstraints gbc = new GridBagConstraints(); opends/src/guitools/org/opends/guitools/controlpanel/ui/GenericFrame.java
New file @@ -0,0 +1,386 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * trunk/opends/resource/legal-notices/OpenDS.LICENSE * or https://OpenDS.dev.java.net/OpenDS.LICENSE. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, * add the following below this CDDL HEADER, with the fields enclosed * by brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Copyright 2009 Sun Microsystems, Inc. */ package org.opends.guitools.controlpanel.ui; import static org.opends.messages.AdminToolMessages.*; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.AbstractButton; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JMenuBar; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JViewport; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; import javax.swing.text.JTextComponent; import org.opends.guitools.controlpanel.ui.GenericDialog.ButtonType; import org.opends.guitools.controlpanel.util.Utilities; /** * The generic frame of the Control Panel. It contains a StatusGenericPanel. * */ public class GenericFrame extends JFrame { private static final long serialVersionUID = -2643144936460484112L; private final static Color buttonPanelBackground = ColorAndFontConstants.greyBackground; private JButton okButton; /** * The close button. */ protected JButton closeButton; private JButton cancelButton; //private JPanel contentPanel; /** * The panel contained in the frame. */ protected StatusGenericPanel panel; //private ProgressPanel progressPanel; //private boolean displayInputInNextVisible; private Component lastComponentWithFocus; /** * Constructor of the frame. * @param panel the panel contained in this frame. */ public GenericFrame(StatusGenericPanel panel) { super(); this.panel = panel; if (panel.requiresBorder()) { setDefaultBorder(panel); } JMenuBar menu = panel.getMenuBar(); if (menu != null) { setJMenuBar(menu); } setResizable(true); JScrollPane scroll = Utilities.createScrollPane(panel); JPanel inputPanel = new JPanel(new GridBagLayout()); setContentPane(inputPanel); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; if (panel.requiresScroll()) { inputPanel.add(scroll, gbc); } else { inputPanel.add(panel, gbc); } if (panel.getButtonType() != ButtonType.NO_BUTTON) { gbc.gridy ++; gbc.weighty = 0.0; inputPanel.add(createButtonsPanel(panel), gbc); } KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); ActionListener actionListener = new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent ev) { setVisible(false); } }; getRootPane().registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); FocusListener focusListener = new FocusAdapter() { /** * {@inheritDoc} */ public void focusGained(FocusEvent ev) { lastComponentWithFocus = ev.getComponent(); } }; addFocusListener(focusListener, panel); addWindowListener(new WindowAdapter() { /** * {@inheritDoc} */ public void windowClosing(WindowEvent e) { GenericFrame.this.panel.closeClicked(); } }); pack(); if (!SwingUtilities.isEventDispatchThread()) { Thread.dumpStack(); } } /** * Method used to add a focus listeners to all the components in the panel. * This is done to recover the focus on an item when the frame is closed * and then opened again. * @param focusListener the focus listener. * @param container the container where the components are layed out. */ private void addFocusListener(FocusListener focusListener, Container container) { for (int i=0; i < container.getComponentCount(); i++) { Component comp = container.getComponent(i); if ((comp instanceof AbstractButton) || (comp instanceof JTextComponent) || (comp instanceof JList) || (comp instanceof JComboBox) || (comp instanceof JTable)) { comp.addFocusListener(focusListener); } else if ((comp instanceof JPanel) || (comp instanceof JScrollPane) || (comp instanceof JViewport)) { addFocusListener(focusListener, (Container)comp); } } } /** * {@inheritDoc} */ public void setVisible(boolean visible) { if (lastComponentWithFocus == null) { lastComponentWithFocus = panel.getPreferredFocusComponent(); } if (visible && (lastComponentWithFocus != null)) { lastComponentWithFocus.requestFocusInWindow(); } updateDefaultButton(panel); panel.toBeDisplayed(visible); updateTitle(); super.setVisible(visible); } /** * Sets the enable state of the OK button. * @param enable whether the OK button must be enabled or not. */ public void setEnabledOK(boolean enable) { okButton.setEnabled(enable); } /** * Sets the enable state of the Cancel button. * @param enable whether the Cancel button must be enabled or not. */ public void setEnabledCancel(boolean enable) { cancelButton.setEnabled(enable); } /** * Sets the enable state of the Close button. * @param enable whether the Close button must be enabled or not. */ public void setEnabledClose(boolean enable) { closeButton.setEnabled(enable); } /** * Updates the title of the frame using the title of the panel. * */ public void updateTitle() { if (panel.getTitle() != null) { setTitle(INFO_CTRL_PANEL_GENERIC_TITLE.get( panel.getTitle().toString()).toString()); } } private void setDefaultBorder(JComponent comp) { Utilities.setBorder(comp, new EmptyBorder(20, 20, 20, 20)); } private JPanel createButtonsPanel(final StatusGenericPanel panel) { JPanel buttonsPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); ButtonType buttonType = panel.getButtonType(); gbc.gridx = 0; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; buttonsPanel.add(Box.createHorizontalGlue(), gbc); buttonsPanel.setOpaque(true); buttonsPanel.setBackground(buttonPanelBackground); gbc.insets = new Insets(10, 0, 10, 0); gbc.insets.left = 5; if (buttonType == ButtonType.OK_CANCEL) { gbc.gridx ++; gbc.weightx = 0.0; okButton = Utilities.createButton( INFO_CTRL_PANEL_OK_BUTTON_LABEL.get()); okButton.setOpaque(false); buttonsPanel.add(okButton, gbc); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { panel.okClicked(); } }); okButton.setEnabled(panel.isEnableOK()); gbc.gridx ++; cancelButton = Utilities.createButton( INFO_CTRL_PANEL_CANCEL_BUTTON_LABEL.get()); cancelButton.setOpaque(false); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { panel.cancelClicked(); } }); cancelButton.setEnabled(panel.isEnableCancel()); gbc.insets.right = 10; buttonsPanel.add(cancelButton, gbc); } if (buttonType == ButtonType.OK) { gbc.gridx ++; gbc.weightx = 0.0; okButton = Utilities.createButton( INFO_CTRL_PANEL_OK_BUTTON_LABEL.get()); okButton.setOpaque(false); gbc.insets.right = 10; buttonsPanel.add(okButton, gbc); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { panel.okClicked(); } }); okButton.setEnabled(panel.isEnableOK()); } if (buttonType == ButtonType.CLOSE) { gbc.gridx ++; gbc.weightx = 0.0; closeButton = Utilities.createButton( INFO_CTRL_PANEL_CLOSE_BUTTON_LABEL.get()); closeButton.setOpaque(false); gbc.insets.right = 10; buttonsPanel.add(closeButton, gbc); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { panel.closeClicked(); } }); closeButton.setEnabled(panel.isEnableClose()); } buttonsPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, ColorAndFontConstants.defaultBorderColor)); return buttonsPanel; } /** * Updates the default button of the frame, depending on the type of * generic panel that it contains. * @param panel the generic panel contained in this frame. */ private void updateDefaultButton(StatusGenericPanel panel) { ButtonType buttonType = panel.getButtonType(); if (buttonType == ButtonType.OK_CANCEL) { getRootPane().setDefaultButton(okButton); } else if (buttonType == ButtonType.OK) { getRootPane().setDefaultButton(okButton); } else if (buttonType == ButtonType.CLOSE) { getRootPane().setDefaultButton(closeButton); } } } opends/src/guitools/org/opends/guitools/controlpanel/ui/LDAPEntrySelectionPanel.java
@@ -22,13 +22,14 @@ * CDDL HEADER END * * * Copyright 2008 Sun Microsystems, Inc. * Copyright 2008-2009 Sun Microsystems, Inc. */ package org.opends.guitools.controlpanel.ui; import java.awt.Component; import java.awt.Dimension; import java.awt.Window; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -271,9 +272,14 @@ public void setTitle(Message title) { this.title = title; if (Utilities.getParentDialog(this) instanceof GenericDialog) Window w = Utilities.getParentDialog(this); if (w instanceof GenericDialog) { ((GenericDialog)Utilities.getParentDialog(this)).updateTitle(); ((GenericDialog)w).updateTitle(); } else if (w instanceof GenericFrame) { ((GenericFrame)w).updateTitle(); } } } opends/src/guitools/org/opends/guitools/controlpanel/ui/MainActionsPane.java
@@ -80,8 +80,8 @@ ArrayList<Category> categories = createCategories(); ButtonGroup group = new ButtonGroup(); int maxWidth = 0; final Map<Action, GenericDialog> dialogs = new HashMap<Action, GenericDialog>(); final Map<Action, GenericFrame> frames = new HashMap<Action, GenericFrame>(); ArrayList<ActionButton> actions = new ArrayList<ActionButton>(); for(Category category: categories) { @@ -104,8 +104,8 @@ { // Constructs the panels using reflection. Action action = b.getActionObject(); GenericDialog dlg = dialogs.get(action); if (dlg == null) GenericFrame frame = frames.get(action); if (frame == null) { Class<? extends StatusGenericPanel> panelClass = action.getAssociatedPanelClass(); @@ -118,10 +118,10 @@ { panel.setInfo(getInfo()); } dlg = createDialog(panel); frame = createFrame(panel); dialogs.put(action, dlg); Utilities.centerGoldenMean(dlg, frames.put(action, frame); Utilities.centerGoldenMean(frame, Utilities.getFrame(MainActionsPane.this)); } catch (Throwable t) @@ -130,13 +130,13 @@ t.printStackTrace(); } } if (!dlg.isVisible()) if (!frame.isVisible()) { dlg.setVisible(true); frame.setVisible(true); } else { dlg.toFront(); frame.toFront(); } } }); @@ -173,15 +173,13 @@ } /** * Creates the dialog to be displayed using the provided panel. * @param panel the panel that will be contained in the dialog. * @return the dialog to be displayed using the provided panel. * Creates the frame to be displayed using the provided panel. * @param panel the panel that will be contained in the frame. * @return the frame to be displayed using the provided panel. */ protected GenericDialog createDialog(StatusGenericPanel panel) protected GenericFrame createFrame(StatusGenericPanel panel) { return new GenericDialog( Utilities.getFrame(MainActionsPane.this), panel); return new GenericFrame(panel); } /** opends/src/guitools/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java
@@ -50,7 +50,6 @@ import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; @@ -789,7 +788,7 @@ SwingUtilities.invokeLater(new Runnable(){ public void run() { GenericDialog dlg = new GenericDialog(new JFrame(), p); GenericDialog dlg = new GenericDialog(Utilities.createFrame(), p); dlg.setModal(true); dlg.pack(); dlg.setVisible(true); opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -62,7 +62,6 @@ import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.JMenuBar; @@ -412,10 +411,14 @@ */ protected void setEnabledOK(boolean enable) { Window parent = Utilities.getParentDialog(this); if ((parent != null) && (parent instanceof GenericDialog)) Window w = Utilities.getParentDialog(this); if (w instanceof GenericDialog) { ((GenericDialog)parent).setEnabledOK(enable); ((GenericDialog)w).setEnabledOK(enable); } else if (w instanceof GenericFrame) { ((GenericFrame)w).setEnabledOK(enable); } enableOK = enable; } @@ -426,10 +429,14 @@ */ protected void setEnabledCancel(boolean enable) { JDialog parent = (JDialog)Utilities.getParentDialog(this); if ((parent != null) && (parent instanceof GenericDialog)) Window w = Utilities.getParentDialog(this); if (w instanceof GenericDialog) { ((GenericDialog)parent).setEnabledCancel(enable); ((GenericDialog)w).setEnabledCancel(enable); } else if (w instanceof GenericFrame) { ((GenericFrame)w).setEnabledCancel(enable); } enableCancel = enable; } opends/src/guitools/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java
@@ -46,7 +46,6 @@ import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; @@ -1170,7 +1169,7 @@ while (true) { TaskToSchedulePanel p = new TaskToSchedulePanel("TEST TASK"); GenericDialog dlg = new GenericDialog(new JFrame(), p); GenericDialog dlg = new GenericDialog(Utilities.createFrame(), p); dlg.setModal(true); dlg.setVisible(true); } opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -168,6 +168,17 @@ } /** * Creates a frame. * @return a frame. */ public static JFrame createFrame() { JFrame frame = new JFrame(); frame.setResizable(true); return frame; } /** * Returns <CODE>true</CODE> if an attribute value must be obfuscated because * it contains sensitive information (like passwords) and <CODE>false</CODE> * otherwise. opends/src/guitools/org/opends/guitools/uninstaller/ui/LoginDialog.java
@@ -22,7 +22,7 @@ * CDDL HEADER END * * * Copyright 2008 Sun Microsystems, Inc. * Copyright 2008-2009 Sun Microsystems, Inc. */ package org.opends.guitools.uninstaller.ui; @@ -717,7 +717,8 @@ { try { LoginDialog dlg = new LoginDialog(new JFrame(), LoginDialog dlg = new LoginDialog( org.opends.guitools.controlpanel.util.Utilities.createFrame(), new ApplicationTrustManager(null)); dlg.pack(); dlg.setVisible(true);