From 4dd0e589d6b01e86e8393e4d569bd7ede1f9c327 Mon Sep 17 00:00:00 2001 From: "rj.keller%beonex.com" Date: Sun, 8 May 2005 02:28:48 +0000 Subject: [PATCH] Making the collapsible toolbar display correctly after expanding a collapsed toolbar. --- .../grendel/addressbook/AddressBook.java | 2 +- .../grendel/composition/Composition.java | 3 +- .../grendel/composition/CompositionPanel.java | 1 - grendel/sources/grendel/ui/FolderFrame.java | 2 +- grendel/sources/grendel/ui/GeneralFrame.java | 14 -- grendel/sources/grendel/ui/MessageFrame.java | 2 +- .../ui/UnifiedMessageDisplayManager.java | 5 +- .../grendel/widgets/CollapsiblePanel.java | 215 ++++++++---------- 8 files changed, 101 insertions(+), 143 deletions(-) diff --git a/grendel/sources/grendel/addressbook/AddressBook.java b/grendel/sources/grendel/addressbook/AddressBook.java index bff73cfed47..98ac4516eda 100644 --- a/grendel/sources/grendel/addressbook/AddressBook.java +++ b/grendel/sources/grendel/addressbook/AddressBook.java @@ -296,7 +296,7 @@ public class AddressBook extends GeneralFrame { mTtoolbar = createToolbar(); //collapsible item - collapsePanel.add(mTtoolbar); + collapsePanel.setComponent(mTtoolbar); //create status bar (bottom) // mStatusbar = createStatusbar(); diff --git a/grendel/sources/grendel/composition/Composition.java b/grendel/sources/grendel/composition/Composition.java index d8d18e0fc23..c6b8a5c9f41 100644 --- a/grendel/sources/grendel/composition/Composition.java +++ b/grendel/sources/grendel/composition/Composition.java @@ -37,7 +37,6 @@ import javax.swing.event.*; import grendel.storage.MessageExtra; import grendel.storage.MessageExtraFactory; import grendel.widgets.Animation; -import grendel.widgets.CollapsiblePanel; import grendel.widgets.GrendelToolBar; import grendel.ui.FolderPanel; import grendel.ui.GeneralFrame; @@ -112,7 +111,7 @@ public class Composition extends GeneralFrame { fToolBarPanelConstraints.fill = GridBagConstraints.NONE; fToolBarPanelConstraints.weightx = 1.0; fToolBarPanelConstraints.gridwidth = GridBagConstraints.REMAINDER; - fToolBarPanel.add(fAnimation, fToolBarPanelConstraints); + fToolBar.add(fAnimation, fToolBarPanelConstraints); mBox.add(fToolBarPanel); //bottom item // fToolBarPanelConstraints.gridwidth = GridBagConstraints.RELATIVE; diff --git a/grendel/sources/grendel/composition/CompositionPanel.java b/grendel/sources/grendel/composition/CompositionPanel.java index dabe2be584e..5ee562f1b00 100644 --- a/grendel/sources/grendel/composition/CompositionPanel.java +++ b/grendel/sources/grendel/composition/CompositionPanel.java @@ -89,7 +89,6 @@ import grendel.storage.MessageExtra; import grendel.storage.MessageExtraFactory; import grendel.ui.ActionFactory; import grendel.ui.GeneralPanel; -import grendel.widgets.CollapsiblePanel; import grendel.widgets.GrendelToolBar; import com.trfenv.parsers.Event; diff --git a/grendel/sources/grendel/ui/FolderFrame.java b/grendel/sources/grendel/ui/FolderFrame.java index 04ad21f6a88..c4b6b4b7329 100644 --- a/grendel/sources/grendel/ui/FolderFrame.java +++ b/grendel/sources/grendel/ui/FolderFrame.java @@ -65,7 +65,7 @@ public class FolderFrame extends GeneralFrame { // fToolBar.addItem(ToolbarFactory.MakeINSToolbarItem(ToolBarLayout.CreateSpring(), // null)); // fToolBar.addItem(ToolbarFactory.MakeINSToolbarItem(fAnimation, null)); - fToolBarPanel.add(fToolBar); + fToolBarPanel.setComponent(fToolBar); fStatusBar = buildStatusBar(); fPanel.add(BorderLayout.SOUTH, fStatusBar); diff --git a/grendel/sources/grendel/ui/GeneralFrame.java b/grendel/sources/grendel/ui/GeneralFrame.java index 0ec3fe497f1..47e30d29396 100644 --- a/grendel/sources/grendel/ui/GeneralFrame.java +++ b/grendel/sources/grendel/ui/GeneralFrame.java @@ -75,19 +75,6 @@ import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.BoxLayout; -//import netscape.orion.toolbars.BarLayout; -//import netscape.orion.toolbars.CollapsibleToolbarPanel; -//import netscape.orion.toolbars.NSButton; -//import netscape.orion.toolbars.NSToolbar; -//import netscape.orion.toolbars.ToolBarLayout; -//import netscape.orion.uimanager.AbstractUICmd; -//import netscape.orion.uimanager.IUICmd; -//import netscape.orion.uimanager.IUIMMenuBar; -//import netscape.orion.uimanager.UIMConstants; - -//import xml.tree.TreeBuilder; -//import xml.tree.XMLNode; - import grendel.prefs.base.InvisiblePrefs; import grendel.ui.ToolBarLayout; import grendel.widgets.*; @@ -151,7 +138,6 @@ public class GeneralFrame extends JFrame fToolBarPanel = new CollapsiblePanel(true); fToolBarPanelLayout = new ToolBarLayout(); fToolBarPanelConstraints = new GridBagConstraints(); - fToolBarPanel.setLayout(fToolBarPanelLayout); fPanel.add(fToolBarPanel, BorderLayout.NORTH); // fUIManager = new netscape.orion.uimanager.UIManager(fToolBarPanel); diff --git a/grendel/sources/grendel/ui/MessageFrame.java b/grendel/sources/grendel/ui/MessageFrame.java index 653b13894a5..7ca260ea49a 100644 --- a/grendel/sources/grendel/ui/MessageFrame.java +++ b/grendel/sources/grendel/ui/MessageFrame.java @@ -64,7 +64,7 @@ public class MessageFrame extends GeneralFrame { // fToolBar.addItem(ToolbarFactory.MakeINSToolbarItem(ToolBarLayout.CreateSpring(), // null)); // fToolBar.addItem(ToolbarFactory.MakeINSToolbarItem(fAnimation, null)); - fToolBarPanel.add(fToolBar); + fToolBarPanel.setComponent(fToolBar); fStatusBar = buildStatusBar(); fPanel.add(BorderLayout.SOUTH, fStatusBar); diff --git a/grendel/sources/grendel/ui/UnifiedMessageDisplayManager.java b/grendel/sources/grendel/ui/UnifiedMessageDisplayManager.java index 8839b6d79e9..7c552c4df76 100644 --- a/grendel/sources/grendel/ui/UnifiedMessageDisplayManager.java +++ b/grendel/sources/grendel/ui/UnifiedMessageDisplayManager.java @@ -53,7 +53,6 @@ import javax.mail.MessagingException; import grendel.prefs.base.InvisiblePrefs; import grendel.prefs.base.UIPrefs; import grendel.view.ViewedMessage; -import grendel.widgets.CollapsiblePanel; import grendel.widgets.GrendelToolBar; import grendel.widgets.Spring; import grendel.widgets.StatusEvent; @@ -200,14 +199,14 @@ class UnifiedMessageFrame extends GeneralFrame { fToolBarPanelConstraints.fill = GridBagConstraints.HORIZONTAL; fToolBarPanelConstraints.anchor = GridBagConstraints.WEST; - fToolBarPanel.add(fToolBar, fToolBarPanelConstraints); + fToolBarPanel.setComponent(fToolBar); fToolBar.add(fToolBar.makeNewSpring()); fToolBarPanelConstraints.weightx = 1.0; fToolBarPanelConstraints.fill = GridBagConstraints.NONE; fToolBarPanelConstraints.gridwidth = GridBagConstraints.REMAINDER; fToolBarPanelConstraints.anchor = GridBagConstraints.EAST; - fToolBarPanel.add(fAnimation, fToolBarPanelConstraints); + fToolBar.add(fAnimation, fToolBarPanelConstraints); fStatusBar = buildStatusBar(); fPanel.add(BorderLayout.SOUTH, fStatusBar); diff --git a/grendel/sources/grendel/widgets/CollapsiblePanel.java b/grendel/sources/grendel/widgets/CollapsiblePanel.java index c74ade35f86..2f9868d7993 100644 --- a/grendel/sources/grendel/widgets/CollapsiblePanel.java +++ b/grendel/sources/grendel/widgets/CollapsiblePanel.java @@ -20,6 +20,7 @@ * Rights Reserved. * * Contributor(s): + * R.J. Keller * * Created: Jeff Galyan , 30 Dec 1998 */ @@ -32,6 +33,7 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.Insets; +import java.awt.BorderLayout; import javax.swing.Box; import javax.swing.BorderFactory; @@ -50,176 +52,149 @@ import grendel.widgets.Spring; * which provides the standard Communicator-style collapsing toolbar panel. * * @author Jeff Galyan + * @author R.J. Keller * @see Collapsible */ - public class CollapsiblePanel extends JPanel implements Collapsible { - private boolean collapsed = false; - private Component myComponents[]; - private int componentCount; - private final int VERTICAL = 0; - private final int HORIZONTAL = 1; - private GridBagConstraints constraints; - private Box aBox; - int width = 10, height = 50; + + private static final int VERTICAL = 0; + private static final int HORIZONTAL = 1; - private ToolBarLayout layout; + private boolean collapsed = false; + private Component curComponent; /** * Constructor */ + public CollapsiblePanel(boolean isDoubleBuffered) { + super(isDoubleBuffered); - public CollapsiblePanel(boolean isDoubleBuffered) { - super(isDoubleBuffered); + setLayout(new BorderLayout()); + collapsed = false; + } - constraints = new GridBagConstraints(); - constraints.ipadx = 0; - constraints.ipady = 0; + /** + *Sets the component that is to be collapsed and uncollapsed. Only one + *component can be shown in this panel at one time. For multiple components, + *add them all to a JPanel. Since this is usually for toolbars only, it + *shouldn't be an issue. + */ + public void setComponent(Component comp) { + curComponent = comp; - layout = new ToolBarLayout(); - layout.setInsets(new Insets(0,0,0,0)); - layout.setIPadX(0); - layout.setIPadY(0); - setLayout(layout); - constraints.insets = new Insets(0,0,0,0); - constraints.anchor = GridBagConstraints.NORTHWEST; - constraints.fill = GridBagConstraints.NONE; + removeAll(); - CollapseButton collapseButton = new CollapseButton(VERTICAL); - add(collapseButton, constraints); - Dimension dim = collapseButton.getSize(); - collapseButton.reshape(0,0,dim.width,dim.height); + CollapseButton collapseButton = new CollapseButton(VERTICAL); + add(collapseButton, BorderLayout.WEST); + Dimension dim = collapseButton.getSize(); + collapseButton.reshape(0,0,dim.width,dim.height); - // constraints.insets = new Insets(5,5,5,5); - constraints.anchor = GridBagConstraints.WEST; - collapsed = false; - revalidate(); - } + //set the new components background to the panel background. + setBackground(comp.getBackground()); + + add(comp, BorderLayout.CENTER); + + revalidate(); + } + + public Component getComponent() { + return curComponent; + } /** * Collapses the panel. */ + public void collapse() { + removeAll(); + add(new CollapseButton(HORIZONTAL), BorderLayout.WEST); + Dimension dim2 = getSize(); + setSize(new Dimension(dim2.width, 5)); - public void collapse() { + add(new Spring(), BorderLayout.CENTER); - GridBagConstraints constraints = new GridBagConstraints(); + revalidate(); - Component myComponents2[] = getComponents(); - componentCount = getComponentCount(); - myComponents = new Component[componentCount]; - - for (int i = 0; i < componentCount; i++) { - myComponents[i] = myComponents2[i]; - remove(myComponents2[i]); - } - constraints.anchor = GridBagConstraints.NORTHWEST; - constraints.fill = GridBagConstraints.NONE; - - add(new CollapseButton(HORIZONTAL), constraints); - Dimension dim2 = getSize(); - setSize(new Dimension(dim2.width, 5)); - - constraints.fill = GridBagConstraints.HORIZONTAL; - constraints.weightx = 10.0; - constraints.gridwidth = GridBagConstraints.REMAINDER; - - add(new Spring(), constraints); - - revalidate(); - - collapsed = true; - } + collapsed = true; + } /** * Uncollapses the panel. */ + public void expand() { + removeAll(); - public void expand() { - Dimension dim = new Dimension(height, width); + add(new CollapseButton(VERTICAL), BorderLayout.WEST); + add(curComponent, BorderLayout.CENTER); - // layout.defaultConstraints.anchor = GridBagConstraints.WEST; - removeAll(); - Dimension dim2 = getSize(); - setSize(dim2.width, 40); - myComponents[0] = new CollapseButton(VERTICAL); + revalidate(); - for (int i = 0; i < componentCount; i++) { - add(myComponents[i]); - } - - revalidate(); - - collapsed = false; - } + collapsed = false; + } /** * Tells you whether this component is collapsible. * @returns a boolean indicating this component is collapsible. */ - - public boolean isCollapsible() { - return collapsible; - } + public boolean isCollapsible() { + return collapsible; + } /** * Tells you whether this component is currently collapsed. * Useful for checking the component's status. * @returns true if this component is collapsed, false if it is not. */ - - public boolean isCollapsed() { - return collapsed; - } + public boolean isCollapsed() { + return collapsed; + } class CollapseListener implements ActionListener { - public void actionPerformed(ActionEvent evt) { - if (isCollapsed() == true) { - expand(); - } else { - collapse(); - } - } + public void actionPerformed(ActionEvent evt) { + if (isCollapsed() == true) { + expand(); + } else { + collapse(); + } + } } class CollapseButton extends JButton { - private ImageIcon collapseButtonIconVertical = new ImageIcon("widgets/images/collapseButton-vertical.gif", "regular collapseButton icon"); - private ImageIcon collapseButtonVerticalRollover = new ImageIcon("widgets/images/collapseButton-vertical-rollover.gif", "vertical rollover icon"); - private ImageIcon collapseButtonVerticalPressed = new ImageIcon("widgets/images/collapseButton-vertical-pressed.gif", "vertical pressed icon"); - private ImageIcon collapseButtonIconHorizontal = new ImageIcon("widgets/images/collapseButton-horizontal.gif", "horizontal normal icon"); - private ImageIcon collapseButtonHorizontalRollover = new ImageIcon("widgets/images/collapseButton-horizontal-rollover.gif", "horizontal rollover icon"); - private ImageIcon collapseButtonHorizontalPressed = new ImageIcon("widgets/images/collapseButton-horizontal-pressed.gif", "horizontal pressed icon"); + private ImageIcon collapseButtonIconVertical = new ImageIcon("widgets/images/collapseButton-vertical.gif", "regular collapseButton icon"); + private ImageIcon collapseButtonVerticalRollover = new ImageIcon("widgets/images/collapseButton-vertical-rollover.gif", "vertical rollover icon"); + private ImageIcon collapseButtonVerticalPressed = new ImageIcon("widgets/images/collapseButton-vertical-pressed.gif", "vertical pressed icon"); + private ImageIcon collapseButtonIconHorizontal = new ImageIcon("widgets/images/collapseButton-horizontal.gif", "horizontal normal icon"); + private ImageIcon collapseButtonHorizontalRollover = new ImageIcon("widgets/images/collapseButton-horizontal-rollover.gif", "horizontal rollover icon"); + private ImageIcon collapseButtonHorizontalPressed = new ImageIcon("widgets/images/collapseButton-horizontal-pressed.gif", "horizontal pressed icon"); - final int VERTICAL = 0; - final int HORIZONTAL = 1; + final int VERTICAL = 0; + final int HORIZONTAL = 1; - public CollapseButton(int orientation) { - super(); - setRolloverEnabled(true); - setFocusPainted(false); - setDefaultCapable(false); - setBorder(null); - setBorderPainted(false); - setMargin(new Insets(0,0,0,0)); - setToolTipText("Collapses/Expands the ToolBar"); + public CollapseButton(int orientation) { + super(); + setRolloverEnabled(true); + setFocusPainted(false); + setDefaultCapable(false); + setBorder(null); + setBorderPainted(false); + setMargin(new Insets(0,0,0,0)); + setToolTipText("Collapses/Expands the ToolBar"); - if (orientation == VERTICAL) { - setIcon(collapseButtonIconVertical); - setRolloverIcon(collapseButtonVerticalRollover); - setPressedIcon(collapseButtonVerticalPressed); - } else { - setIcon(collapseButtonIconHorizontal); - setRolloverIcon(collapseButtonHorizontalRollover); - setPressedIcon(collapseButtonHorizontalPressed); - } + if (orientation == VERTICAL) { + setIcon(collapseButtonIconVertical); + setRolloverIcon(collapseButtonVerticalRollover); + setPressedIcon(collapseButtonVerticalPressed); + } else { + setIcon(collapseButtonIconHorizontal); + setRolloverIcon(collapseButtonHorizontalRollover); + setPressedIcon(collapseButtonHorizontalPressed); + } - addActionListener(new CollapseListener()); - } + addActionListener(new CollapseListener()); + } } -} - - +} \ No newline at end of file