View Javadoc
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 org.jscroll.*; 24 25 import javax.swing.*; 26 27 import java.awt.*; 28 import java.awt.event.*; 29 30 31 /*** 32 * This class coordinates state changes between other classes in the system. 33 * Based upon the "mediator" design pattern. 34 * 35 * @author <a href="mailto:tessier@gabinternet.com">Tom Tessier</a> 36 * @version 1.0 11-Aug-2001 37 */ 38 public class DesktopMediator implements DesktopConstants { 39 private DesktopScrollPane desktopScrollpane; 40 private DesktopResizableToolBar desktopResizableToolbar; 41 private DesktopListener dListener; 42 private DesktopMenu dMenu; 43 44 /*** 45 * creates the DesktopMediator object. 46 * 47 * @param mainPane a reference to the JScrollDesktopPane that this 48 * object is to mediate. 49 */ 50 public DesktopMediator(JScrollDesktopPane mainPane) { 51 desktopScrollpane = new DesktopScrollPane(this); 52 desktopResizableToolbar = new DesktopResizableToolBar(this); 53 dListener = new DesktopListener(this); 54 55 mainPane.add(desktopResizableToolbar, BorderLayout.NORTH); 56 mainPane.add(desktopScrollpane, BorderLayout.CENTER); 57 mainPane.addComponentListener(dListener); 58 } 59 60 /*** 61 * registers a menubar with the mediator, applying the "Window" menu items 62 * to that menubar in the process. 63 * 64 * @param mb the menubar to register 65 */ 66 public void registerMenuBar(JMenuBar mb) { 67 dMenu = new DesktopMenu(this); 68 mb.add(dMenu); 69 mb.setBorder(null); // turn off the menubar border (looks better) 70 } 71 72 /*** 73 * adds an internal frame to the scrollable desktop pane 74 * 75 * @param title the title displayed in the title bar of the internal frame 76 * @param icon the icon displayed in the title bar of the internal frame 77 * @param frameContents the contents of the internal frame 78 * @param isClosable <code>boolean</code> indicating whether 79 * internal frame is closable 80 * @param x x coordinates of internal frame within the scrollable desktop 81 * <code>-1</code> indicates the virtual desktop is to determine 82 * the position 83 * @param y y coordinates of internal frame within the scrollable desktop 84 * <code>-1</code> indicates the virtual desktop is to 85 * determine the position 86 * 87 * @return the internal frame that was created 88 */ 89 public JInternalFrame add(String title, ImageIcon icon, 90 JPanel frameContents, boolean isClosable, int x, int y) { 91 JScrollInternalFrame frame = null; 92 93 if (desktopScrollpane.getNumberOfFrames() < MAX_FRAMES) { 94 frame = desktopScrollpane.add(dListener, title, icon, 95 frameContents, isClosable, x, y); 96 97 createFrameAssociates(frame); 98 } 99 100 return frame; 101 } 102 103 /*** 104 * adds an internal frame to the scrollable desktop pane 105 * 106 * @param frame the internal frame of class JScrollInternalFrame to add 107 * @param x x coordinates of internal frame within the scrollable desktop 108 * <code>-1</code> indicates the virtual desktop is to determine 109 * the position 110 * @param y y coordinates of internal frame within the scrollable desktop 111 * <code>-1</code> indicates the virtual desktop is to determine 112 * the position 113 */ 114 public void add(JInternalFrame frame, int x, int y) { 115 if (desktopScrollpane.getNumberOfFrames() < MAX_FRAMES) { 116 desktopScrollpane.add(dListener, frame, x, y); 117 createFrameAssociates((JScrollInternalFrame) frame); 118 } 119 } 120 121 /*** 122 * creates the associated frame components (ie: toggle and menu items) 123 * 124 * @param frame the internal frame of class JScrollInternalFrame to add 125 * 126 */ 127 private void createFrameAssociates(JScrollInternalFrame frame) { 128 RootToggleButton button = null; 129 130 button = desktopResizableToolbar.add(frame.getTitle()); 131 132 button.setAssociatedFrame(frame); 133 frame.setAssociatedButton(button); 134 135 if (dMenu != null) { 136 dMenu.add(frame); 137 } 138 139 if (desktopScrollpane.getAutoTile()) { 140 desktopScrollpane.tileInternalFrames(); 141 } 142 } 143 144 /*** 145 * removes the secondary components associated with an internal frame, 146 * such as toggle and menu buttons, and selects the next available frame 147 * 148 * @param f the internal frame whose associated components are 149 * to be removed 150 */ 151 public void removeAssociatedComponents(JScrollInternalFrame f) { 152 desktopResizableToolbar.remove(f.getAssociatedButton()); 153 154 if (dMenu != null) { 155 dMenu.remove(f.getAssociatedMenuButton()); 156 } 157 158 // and select the next available frame... 159 desktopScrollpane.selectNextFrame(); 160 } 161 162 /*** 163 * propogates getSelectedFrame to DesktopScrollPane 164 * 165 * @return the currently selected internal frame 166 */ 167 public JInternalFrame getSelectedFrame() { 168 return desktopScrollpane.getSelectedFrame(); 169 } 170 171 /*** 172 * propogates setSelectedFrame to DesktopScrollPane 173 * 174 * @param f the internal frame to set as selected 175 */ 176 public void setSelectedFrame(JInternalFrame f) { 177 desktopScrollpane.setSelectedFrame(f); 178 } 179 180 /*** 181 * propogates flagContentsChanged to DesktopScrollPane 182 * 183 * @param f the internal frame to flag as "contents changed" 184 */ 185 public void flagContentsChanged(JInternalFrame f) { 186 desktopScrollpane.flagContentsChanged(f); 187 } 188 189 /*** 190 * propogates resizeDesktop to DesktopScrollPane 191 */ 192 public void resizeDesktop() { 193 desktopScrollpane.resizeDesktop(); 194 } 195 196 /*** 197 * propogates revalidateViewport to DesktopScrollPane 198 */ 199 public void revalidateViewport() { 200 desktopScrollpane.revalidate(); 201 } 202 203 /*** 204 * propogates centerView to DesktopScrollPane 205 * 206 * @param f the internal frame to center the view about 207 */ 208 public void centerView(JScrollInternalFrame f) { 209 desktopScrollpane.centerView(f); 210 } 211 212 /*** 213 * propogates closeSelectedFrame to DesktopScrollPane 214 */ 215 public void closeSelectedFrame() { 216 desktopScrollpane.closeSelectedFrame(); 217 } 218 219 /*** 220 * propogates tileInternalFrames to DesktopScrollPane 221 */ 222 public void tileInternalFrames() { 223 desktopScrollpane.tileInternalFrames(); 224 } 225 226 /*** 227 * propogates cascadeInternalFrames to DesktopScrollPane 228 */ 229 public void cascadeInternalFrames() { 230 desktopScrollpane.cascadeInternalFrames(); 231 } 232 233 /*** 234 * propogates setAutoTile to DesktopScrollPane 235 * 236 * @param tileMode <code>true</code> indicates tile internal frames, 237 * <code>false</code> indicates cascade internal frames 238 */ 239 public void setAutoTile(boolean tileMode) { 240 desktopScrollpane.setAutoTile(tileMode); 241 } 242 243 /*** 244 * propogates actionPerformed event to DesktopListener 245 * 246 * @param e the ActionEvent to propogate 247 */ 248 public void actionPerformed(ActionEvent e) { 249 dListener.actionPerformed(e); 250 } 251 }

This page was automatically generated by Maven