01: /*
02: * Beryl - A web platform based on XML, XSLT and Java
03: * This file is part of the Beryl XML GUI
04: *
05: * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11:
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107 USA
20: */
21:
22: package org.beryl.gui.swing;
23:
24: import java.awt.BorderLayout;
25: import java.awt.Dimension;
26: import java.awt.event.ActionEvent;
27: import java.awt.event.ActionListener;
28: import java.util.ArrayList;
29:
30: import javax.swing.BorderFactory;
31: import javax.swing.BoxLayout;
32: import javax.swing.JButton;
33: import javax.swing.JComponent;
34: import javax.swing.JPanel;
35: import javax.swing.JScrollPane;
36:
37: import org.beryl.gui.LFConstants;
38:
39: public class JCascade extends JPanel {
40: private ArrayList panels = null;
41:
42: public JCascade() {
43: setLayout(new BoxLayout(this , BoxLayout.Y_AXIS));
44: setBorder(BorderFactory.createLoweredBevelBorder());
45: panels = new ArrayList();
46: }
47:
48: public void addPanel(JCascadePanel panel) {
49: JButton button = panel.getButton();
50: JScrollPane scrollPane = new JScrollPane(panel);
51: final JPanel container = new JPanel(new BorderLayout());
52: container.add(scrollPane, BorderLayout.CENTER);
53:
54: button.setMaximumSize(new Dimension(LFConstants.MAX_WIDTH,
55: LFConstants.DEFAULT_HEIGHT));
56: button.setAlignmentX(1.0f);
57: button.addActionListener(new ActionListener() {
58: public void actionPerformed(ActionEvent e) {
59: for (int i = 0; i < panels.size(); i++) {
60: JComponent c = (JComponent) panels.get(i);
61: if (!c.isVisible())
62: continue;
63: c.setVisible(false);
64: }
65: container.setVisible(true);
66: }
67: });
68: panels.add(container);
69: add(panel.getButton());
70: if (panels.size() != 1)
71: container.setVisible(false);
72: container.setAlignmentX(1.0f);
73: add(container);
74: panel.container = container;
75: }
76:
77: public void removePanel(JCascadePanel panel) {
78: remove(panel.getButton());
79: remove(panel.container);
80: }
81:
82: public Dimension getMinimumSize() {
83: return new Dimension(0, 0);
84: }
85: }
|