From 8729a061e4138420ec8a33a5ab5f4378eec2097b Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 21 Dec 2009 16:23:41 +0000
Subject: [PATCH] Fix for issue 4413 (setup should use scroll panes in its panels)

---
 opends/src/quicksetup/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java |   17 ++-
 opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java        |   11 --
 opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java                      |   12 +-
 opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java                      |   17 ---
 opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallLicensePanel.java         |    8 +
 opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java                   |  106 ++++++++++++++-------
 opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java                         |   10 +
 opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java           |    9 +
 opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java       |    8 -
 opends/src/guitools/org/opends/guitools/controlpanel/ui/ColorAndFontConstants.java        |    1 
 opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java                             |   36 +++++++
 opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java                  |   20 ---
 opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java    |   15 +-
 13 files changed, 160 insertions(+), 110 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/ColorAndFontConstants.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/ColorAndFontConstants.java
index 313bf69..630af75 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/ColorAndFontConstants.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/ColorAndFontConstants.java
@@ -85,7 +85,6 @@
     try
     {
       JScrollPane scroll = new JScrollPane();
-      Utilities.setScrollIncrementUnit(scroll);
       border = scroll.getBorder();
       // If the border is of class MetalBorders$ScrollPaneBorder it cannot
       // be used.
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
index 8a5a4f5..c64bd4d 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -723,8 +723,15 @@
             null,
             ERR_CTRL_PANEL_REBUILDING_INDEXES_ERROR_DETAILS,
             progressDialog, false);
-        progressDialog.toFront();
+        if (progressDialog.isModal())
+        {
+          progressDialog.toFront();
+        }
         progressDialog.setVisible(true);
+        if (!progressDialog.isModal())
+        {
+          progressDialog.toFront();
+        }
       }
       if (errors.size() > 0)
       {
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java b/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
index f880b77..ef3ebd7 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -402,7 +402,7 @@
     scroll.getViewport().setOpaque(false);
     scroll.getViewport().setBackground(ColorAndFontConstants.background);
     scroll.setBackground(ColorAndFontConstants.background);
-    setScrollIncrementUnit(scroll);
+    UIFactory.setScrollIncrementUnit(scroll);
     return scroll;
   }
 
@@ -418,27 +418,11 @@
     scroll.setOpaque(false);
     scroll.getViewport().setBackground(ColorAndFontConstants.background);
     scroll.setBackground(ColorAndFontConstants.background);
-    setScrollIncrementUnit(scroll);
+    UIFactory.setScrollIncrementUnit(scroll);
     return scroll;
   }
 
   /**
-   * Sets the scroll increment unit for the scroll.
-   * @param scroll the scroll to be updated.
-   */
-  public static void setScrollIncrementUnit(JScrollPane scroll)
-  {
-    if (scroll.getVerticalScrollBar() != null)
-    {
-      int increment = scroll.getVerticalScrollBar().getUnitIncrement();
-      if (increment < 16)
-      {
-        scroll.getVerticalScrollBar().setUnitIncrement(16);
-      }
-    }
-  }
-
-  /**
    * Creates a button.
    * @param text the message to be displayed by the button.
    * @return the created button.
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java b/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java
index 9722e96..518cbc6 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java
@@ -95,14 +95,6 @@
   /**
    * {@inheritDoc}
    */
-  protected boolean hasCheckingLabel()
-  {
-    return true;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
   public Object getFieldValue(FieldName fieldName) {
     Object v = null;
     if (FieldName.SERVER_TO_UPGRADE_LOCATION.equals(fieldName)) {
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java
index 05c7f64..6028c8e 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008 Sun Microsystems, Inc.
+ *      Copyright 2008-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.quicksetup.installer.ui;
@@ -320,15 +320,6 @@
     return text;
   }
 
-
-  /**
-   * {@inheritDoc}
-   */
-  protected boolean hasCheckingLabel()
-  {
-    return true;
-  }
-
   /**
    * Returns the default value for the provided field Name.
    * @param fieldName the field name for which we want to get the default
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallLicensePanel.java b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallLicensePanel.java
index 5995b7e..191b1e7 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallLicensePanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallLicensePanel.java
@@ -134,6 +134,14 @@
   }
 
   /**
+   * {@inheritDoc}
+   */
+  protected boolean requiresScroll()
+  {
+    return false;
+  }
+
+  /**
    * Adds the required action listeners to the fields.
    */
   private void addActionListeners()
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java
index 5bb61a7..a224363 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008 Sun Microsystems, Inc.
+ *      Copyright 2008-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.quicksetup.installer.ui;
@@ -46,7 +46,6 @@
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
-import javax.swing.border.EmptyBorder;
 import javax.swing.text.JTextComponent;
 
 import org.opends.admin.ads.ServerDescriptor;
@@ -163,6 +162,14 @@
   /**
    * {@inheritDoc}
    */
+  protected boolean requiresScroll()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
   public int compare(ServerDescriptor desc1, ServerDescriptor desc2)
   {
     return desc1.getHostPort(true).compareTo(desc2.getHostPort(true));
@@ -186,11 +193,7 @@
     gbc.fill = GridBagConstraints.BOTH;
     fieldsPanel = new JPanel(new GridBagLayout());
     fieldsPanel.setOpaque(false);
-    scroll = new JScrollPane(fieldsPanel);
-    scroll.setBorder(new EmptyBorder(0, 0, 0, 0));
-    scroll.setViewportBorder(new EmptyBorder(0, 0, 0, 0));
-    scroll.setOpaque(false);
-    scroll.getViewport().setOpaque(false);
+    scroll = UIFactory.createBorderLessScrollBar(fieldsPanel);
 
     panel.add(scroll, gbc);
 
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java
index f10336a..8bce571 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java
@@ -43,7 +43,6 @@
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.SwingConstants;
-import javax.swing.border.EmptyBorder;
 
 import org.opends.admin.ads.ADSContext;
 import org.opends.admin.ads.ReplicaDescriptor;
@@ -170,11 +169,7 @@
     gbc.anchor = GridBagConstraints.NORTH;
     gbc.weighty = 1.0;
     gbc.fill = GridBagConstraints.BOTH;
-    scroll = new JScrollPane(checkBoxPanel);
-    scroll.setBorder(new EmptyBorder(0, 0, 0, 0));
-    scroll.setViewportBorder(new EmptyBorder(0, 0, 0, 0));
-    scroll.setOpaque(false);
-    scroll.getViewport().setOpaque(false);
+    scroll = UIFactory.createBorderLessScrollBar(checkBoxPanel);
 
     panel.add(scroll, gbc);
 
@@ -197,6 +192,14 @@
   /**
    * {@inheritDoc}
    */
+  protected boolean requiresScroll()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
   protected Message getInstructions()
   {
     return INFO_SUFFIXES_TO_REPLICATE_PANEL_INSTRUCTIONS.get();
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java b/opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java
index 577dc9f..e76de30 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.quicksetup.ui;
@@ -239,16 +239,14 @@
   }
 
   /**
-   * This method sets up an icon on the bottom left side of the dialog.
-   * Generally this method is called with an animated gif that is passed to
-   * display progress.
-   * @param iconType the icon type to be set.
+   * This method displays a working progress icon in the panel.
+   * @param visible whether the icon must be displayed or not.
    */
-  public void setIcon(UIFactory.IconType iconType)
+  public void setCheckingVisible(boolean visible)
   {
     for (WizardStep s : hmPanels.keySet())
     {
-      getPanel(s).setIcon(iconType);
+      getPanel(s).setCheckingVisible(visible);
     }
   }
 
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java b/opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java
index 1c7e0c8..c7121c9 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.quicksetup.ui;
@@ -182,6 +182,14 @@
   /**
    * {@inheritDoc}
    */
+  protected boolean requiresScroll()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
   public void endDisplay()
   {
     if (lastFocusComponent != null)
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java
index 294b5ba..0479b31 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java
@@ -22,12 +22,11 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.quicksetup.ui;
 
-import java.awt.event.ComponentListener;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.util.HashSet;
@@ -147,17 +146,6 @@
     frame.pack();
     Utilities.centerOnScreen(frame);
     setFocusOnButton(ButtonName.NEXT);
-    int minWidth = (int) frame.getPreferredSize().getWidth();
-    int minHeight = (int) frame.getPreferredSize().getHeight();
-
-    ComponentListener[] listeners = frame.getComponentListeners();
-    for (ComponentListener listener : listeners) {
-      if (listener instanceof MinimumSizeComponentListener) {
-        frame.removeComponentListener(listener);
-      }
-    }
-    frame.addComponentListener(new MinimumSizeComponentListener(frame,
-        minWidth, minHeight));
   }
 
   /**
@@ -536,7 +524,6 @@
 
   private void displayWorkingProgressImage(boolean display)
   {
-    getCurrentStepPanel().setIcon(display ?
-          UIFactory.IconType.WAIT : UIFactory.IconType.NO_ICON);
+    getCurrentStepPanel().setCheckingVisible(display);
   }
 }
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java
index 4e3ed16..be83e33 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java
@@ -27,6 +27,7 @@
 
 package org.opends.quicksetup.ui;
 
+import java.awt.CardLayout;
 import java.awt.Component;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
@@ -62,14 +63,19 @@
 public abstract class QuickSetupStepPanel extends QuickSetupPanel
 implements HyperlinkListener
 {
+  private JPanel inputContainer;
   private Component inputPanel;
 
-  private JLabel checkingLabel;
   private HashSet<ButtonActionListener> buttonListeners =
     new HashSet<ButtonActionListener>();
 
   private ProgressMessageFormatter formatter;
 
+  private static final String INPUT_PANEL = "input";
+  private static final String CHECKING_PANEL = "checking";
+
+  private boolean isCheckingVisible;
+
   /* We can use a HashMap (not multi-thread safe) because all
   the calls to this object are done in the event-thread.
   */
@@ -185,7 +191,7 @@
 
   /**
    * Returns the minimum width of the panel.  This is used to calculate the
-   * minimum widht of the dialog.
+   * minimum width of the dialog.
    * @return the minimum width of the panel.
    */
   public int getMinimumWidth()
@@ -233,15 +239,34 @@
   }
 
   /**
-   * This method sets up an icon on the bottom left side of the dialog.
-   * Generally this method is called with an animated gif that is passed to
-   * display progress.
-   * @param iconType the icon type to be set.
+   * This method displays a working progress icon in the panel.
+   * @param visible whether the icon must be displayed or not.
    */
-  public void setIcon(UIFactory.IconType iconType)
+  public void setCheckingVisible(boolean visible)
   {
-    checkingLabel.setIcon(UIFactory.getImageIcon(iconType));
-    checkingLabel.setText(String.valueOf(getTextForIcon(iconType)));
+    if (visible != isCheckingVisible && inputContainer != null)
+    {
+      CardLayout cl = (CardLayout) inputContainer.getLayout();
+      if (visible)
+      {
+        cl.show(inputContainer, CHECKING_PANEL);
+      }
+      else
+      {
+        cl.show(inputContainer, INPUT_PANEL);
+      }
+      isCheckingVisible = visible;
+    }
+  }
+
+  /**
+   * Tells whether a working progress icon is being displayed in the panel.
+   * @return <CODE>true</CODE> if a working progress icon is being displayed in
+   * the panel and <CODE>false</CODE> otherwise.
+   */
+  public boolean isCheckingVisible()
+  {
+      return isCheckingVisible;
   }
 
   /**
@@ -280,7 +305,7 @@
    * Creates the layout of the panel.
    *
    */
-  private void createLayout()
+  protected void createLayout()
   {
     setLayout(new GridBagLayout());
 
@@ -310,7 +335,7 @@
     {
       if (somethingAdded)
       {
-        gbc.insets.top = UIFactory.TOP_INSET_INSTRUCTIONS_SUBPANEL;
+        gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD;
       } else
       {
         gbc.insets.top = 0;
@@ -319,7 +344,7 @@
       gbc.weightx = 1.0;
       gbc.weighty = 0.0;
       gbc.gridwidth = GridBagConstraints.REMAINDER;
-      gbc.fill = GridBagConstraints.HORIZONTAL;
+      gbc.fill = GridBagConstraints.BOTH;
       gbc.anchor = GridBagConstraints.NORTHWEST;
       add(instructionsPanel, gbc);
       somethingAdded = true;
@@ -327,6 +352,26 @@
 
     if (inputPanel != null)
     {
+      inputContainer = new JPanel(new CardLayout());
+
+      if (requiresScroll())
+      {
+        inputContainer.add(UIFactory.createBorderLessScrollBar(inputPanel),
+            INPUT_PANEL);
+      }
+      else
+      {
+        inputContainer.add(inputPanel, INPUT_PANEL);
+      }
+
+      JPanel checkingPanel = UIFactory.makeJPanel();
+      checkingPanel.setLayout(new GridBagLayout());
+      checkingPanel.add(UIFactory.makeJLabel(UIFactory.IconType.WAIT,
+          INFO_GENERAL_CHECKING_DATA.get(),
+          UIFactory.TextStyle.PRIMARY_FIELD_VALID),
+          new GridBagConstraints());
+      inputContainer.add(checkingPanel, CHECKING_PANEL);
+
       if (somethingAdded)
       {
         gbc.insets.top = UIFactory.TOP_INSET_INPUT_SUBPANEL;
@@ -340,25 +385,13 @@
       gbc.fill = GridBagConstraints.BOTH;
       gbc.anchor = GridBagConstraints.NORTHWEST;
       gbc.insets.left = 0;
-      add(inputPanel, gbc);
+      add(inputContainer, gbc);
       somethingAdded = true;
-    } else
+    }
+    else
     {
       addVerticalGlue(this);
     }
-
-    checkingLabel = UIFactory.makeJLabel(UIFactory.IconType.NO_ICON,
-            Message.EMPTY, UIFactory.TextStyle.PROGRESS);
-    if (hasCheckingLabel())
-    {
-      gbc.insets.top = UIFactory.TOP_INSET_SECONDARY_FIELD;
-      gbc.insets.bottom = 0;
-      gbc.insets.left = 0;
-      gbc.weighty = 0.0;
-      gbc.anchor = GridBagConstraints.NORTHWEST;
-      gbc.fill = GridBagConstraints.HORIZONTAL;
-      add(checkingLabel, gbc);
-    }
   }
 
   /**
@@ -396,15 +429,6 @@
   }
 
   /**
-   * Tells whether we must add a label at the bottom left of the panel
-   * containing an icon that will show that we are doing some checkings.
-   * @return true if the checking label must be added and false otherwise.
-   */
-  protected boolean hasCheckingLabel()
-  {
-    return false;
-  }
-  /**
    * This method is called by the URLWorker when it has finished its task.
    * @param worker the URLWorker that finished its task.
    */
@@ -414,6 +438,16 @@
   }
 
   /**
+   * Tells whether the input panel should have a scroll or not.
+   * @return <CODE>true</CODE> if the input panel should have a scroll and
+   * <CODE>false</CODE> otherwise.
+   */
+  protected boolean requiresScroll()
+  {
+    return true;
+  }
+
+  /**
    * Returns <CODE>true</CODE> if this is a WebStart based installer and
    * <CODE>false</CODE> otherwise.
    * @return <CODE>true</CODE> if this is a WebStart based installer and
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java b/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java
index 235d28d..5110237 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java
@@ -1226,6 +1226,42 @@
   }
 
   /**
+   * Returns a JScrollPane that contains the provided component.  The scroll
+   * pane will not contain any border.
+   * @param comp the component contained in the scroll pane.
+   * @return a JScrollPane that contains the provided component.  The scroll
+   * pane will not contain any border.
+   */
+  public static JScrollPane createBorderLessScrollBar(Component comp)
+  {
+    JScrollPane scroll = new JScrollPane(comp);
+    scroll.setBorder(new EmptyBorder(0, 0, 0, 0));
+    scroll.setViewportBorder(new EmptyBorder(0, 0, 0, 0));
+    scroll.setOpaque(false);
+    scroll.getViewport().setOpaque(false);
+    scroll.getViewport().setBackground(DEFAULT_BACKGROUND);
+    scroll.setBackground(DEFAULT_BACKGROUND);
+    setScrollIncrementUnit(scroll);
+    return scroll;
+  }
+
+  /**
+   * Sets the scroll increment unit for the scroll.
+   * @param scroll the scroll to be updated.
+   */
+  public static void setScrollIncrementUnit(JScrollPane scroll)
+  {
+    if (scroll.getVerticalScrollBar() != null)
+    {
+      int increment = scroll.getVerticalScrollBar().getUnitIncrement();
+      if (increment < 16)
+      {
+        scroll.getVerticalScrollBar().setUnitIncrement(16);
+      }
+    }
+  }
+
+  /**
    * Return empty insets.
    * @return empty insets.
    */

--
Gitblit v1.10.0