1 /*
2 * JScroll - the scrollable desktop pane for Java.
3 * Copyright (C) 2003 Tom Tessier
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 */
20
21 package org.jscroll.widgets;
22
23 import javax.swing.*;
24
25 import java.awt.Color;
26 import java.awt.Dimension;
27
28
29 /***
30 * This class provides a custom internal frame. Each internal frame
31 * is assigned an associated toggle button and an optional radio button
32 * menu item. These buttons reside in the
33 * {@link org.jscroll.widgets.DesktopResizableToolBar
34 * DesktopResizableToolBar} and
35 * {@link org.jscroll.widgets.DesktopMenu DesktopMenu}.
36 * classes respectively.
37 *
38 * @author <a href="mailto:tessier@gabinternet.com">Tom Tessier</a>
39 * @author <a href="mailto:francesco.furfari@guest.cnuce.cnr.it">Francesco Furfari</a>
40 * <!-- Fran did some small fix, can't remember what -->
41 * @version 1.0.2 14-Mar-2003
42 * @version 1.0 9-Aug-2001
43 */
44 public class JScrollInternalFrame extends JInternalFrame {
45 private JToggleButton associatedButton;
46 private JRadioButtonMenuItem associatedMenuButton;
47 private boolean isClosable;
48 private int initialWidth;
49 private int initialHeight;
50
51 /***
52 * creates the JScrollInternalFrame
53 *
54 * @param title the string displayed in the title bar of the internal frame
55 * @param icon the ImageIcon displayed in the title bar of the internal frame
56 * @param frameContents the contents of the internal frame
57 * @param isClosable determines whether the frame is closable
58 */
59 public JScrollInternalFrame(String title, ImageIcon icon,
60 JPanel frameContents, boolean isClosable) {
61 super(title, // title
62 true, //resizable
63 isClosable, //closable
64 true, //maximizable
65 true); //iconifiable
66
67 this.isClosable = isClosable;
68
69 setBackground(Color.white);
70 setForeground(Color.blue);
71
72 if (icon != null) {
73 setFrameIcon(icon);
74 }
75
76 // add the window contents
77 getContentPane().add(frameContents);
78 pack();
79
80 saveSize();
81
82 setVisible(true); // turn the frame on
83 }
84
85 /***
86 * tell the frame to save its size for later restoration
87 */
88 public void saveSize() {
89 initialWidth = getWidth();
90 initialHeight = getHeight();
91 }
92
93 /***
94 * constructor provided for compatibility with JInternalFrame
95 */
96 public JScrollInternalFrame() {
97 super();
98 saveSize();
99 }
100
101 /***
102 * sets the associated menu button
103 *
104 * @param associatedMenuButton the menu button to associate with
105 * the internal frame
106 */
107 public void setAssociatedMenuButton(
108 JRadioButtonMenuItem associatedMenuButton) {
109 this.associatedMenuButton = associatedMenuButton;
110 }
111
112 /***
113 * returns the associated menu button
114 *
115 * @return the JRadioButtonMenuItem object associated with this internal frame
116 */
117 public JRadioButtonMenuItem getAssociatedMenuButton() {
118 return associatedMenuButton;
119 }
120
121 /***
122 * sets the associated toggle button
123 *
124 * @param associatedButton the toggle button to associate with
125 * the internal frame
126 */
127 public void setAssociatedButton(JToggleButton associatedButton) {
128 this.associatedButton = associatedButton;
129 }
130
131 /***
132 * returns the associated toggle button
133 *
134 * @return the JToggleButton object associated with this internal frame
135 */
136 public JToggleButton getAssociatedButton() {
137 return associatedButton;
138 }
139
140 /***
141 * returns the initial dimensions of this internal frame. Necessary so that
142 * internal frames can be restored to their default sizes when the cascade
143 * frame positioning mode is chosen in
144 * {@link org.jscroll.widgets.FramePositioning FramePositioning}.
145 *
146 * @return the Dimension object representing the initial dimensions of
147 * this internal frame
148 */
149 public Dimension getInitialDimensions() {
150 return new Dimension(initialWidth, initialHeight);
151 }
152
153 /***
154 * returns the toString() representation of this object. Useful for
155 * debugging purposes.
156 *
157 * @return the toString() representation of this object
158 */
159 public String toString() {
160 return "JScrollInternalFrame: " + getTitle();
161 }
162
163 /***
164 * selects the current frame, along with any toggle and menu
165 * buttons that may be associated with it
166 */
167 public void selectFrameAndAssociatedButtons() {
168 // select associated toolbar button
169 if (associatedButton != null) {
170 associatedButton.setSelected(true);
171 ((RootToggleButton) associatedButton).flagContentsChanged(false);
172 }
173
174 // select menu button
175 if (associatedMenuButton != null) {
176 associatedMenuButton.setSelected(true);
177 }
178
179 try {
180 setSelected(true);
181 setIcon(false); // select and de-iconify the frame
182 } catch (java.beans.PropertyVetoException pve) {
183 System.out.println(pve.getMessage());
184 }
185
186 setVisible(true); // and make sure the frame is turned on
187 }
188
189 /***
190 * saves the size of the current internal frame for those frames whose
191 * initial width and heights have not been set. Called when the internal
192 * frame is added to the JDesktopPane.
193 * <BR><BR>
194 * Manually-built internal frames won't display properly without this.
195 * <BR><BR>
196 * Fix by <a href="mailto:francesco.furfari@guest.cnuce.cnr.it">Francesco Furfari</a>
197 *
198 */
199 public void addNotify() {
200 super.addNotify();
201
202 if ((initialWidth == 0) && (initialHeight == 0)) {
203 saveSize();
204 }
205 }
206 }
This page was automatically generated by Maven