1 7 8 package javax.swing; 9 10 import java.util.Vector ; 11 import javax.swing.plaf.*; 12 import javax.accessibility.*; 13 14 import java.awt.Component ; 15 import java.awt.Container ; 16 import java.awt.DefaultFocusTraversalPolicy ; 17 import java.awt.FocusTraversalPolicy ; 18 import java.awt.Window ; 19 import java.io.ObjectOutputStream ; 20 import java.io.ObjectInputStream ; 21 import java.io.IOException ; 22 23 62 public class JDesktopPane extends JLayeredPane implements Accessible 63 { 64 68 private static final String uiClassID = "DesktopPaneUI"; 69 70 transient DesktopManager desktopManager; 71 72 private transient JInternalFrame selectedFrame = null; 73 74 81 public static final int LIVE_DRAG_MODE = 0; 82 83 90 public static final int OUTLINE_DRAG_MODE = 1; 91 92 private int dragMode = LIVE_DRAG_MODE; 93 private boolean dragModeSet = false; 94 95 98 public JDesktopPane() { 99 setFocusCycleRoot(true); 100 101 setFocusTraversalPolicy(new LayoutFocusTraversalPolicy () { 102 public Component getDefaultComponent(Container c) { 103 JInternalFrame jifArray[] = getAllFrames(); 104 Component comp = null; 105 for (int i = 0; i < jifArray.length; i++) { 106 comp = jifArray[i].getFocusTraversalPolicy().getDefaultComponent(jifArray[i]); 107 if (comp != null) { 108 break; 109 } 110 } 111 return comp; 112 } 113 }); 114 updateUI(); 115 } 116 117 123 public DesktopPaneUI getUI() { 124 return (DesktopPaneUI)ui; 125 } 126 127 138 public void setUI(DesktopPaneUI ui) { 139 super.setUI(ui); 140 } 141 142 158 public void setDragMode(int dragMode) { 159 int oldDragMode = this.dragMode; 160 this.dragMode = dragMode; 161 firePropertyChange("dragMode", oldDragMode, this.dragMode); 162 dragModeSet = true; 163 } 164 165 171 public int getDragMode() { 172 return dragMode; 173 } 174 175 179 public DesktopManager getDesktopManager() { 180 return desktopManager; 181 } 182 183 194 public void setDesktopManager(DesktopManager d) { 195 DesktopManager oldValue = desktopManager; 196 desktopManager = d; 197 firePropertyChange("desktopManager", oldValue, desktopManager); 198 } 199 200 207 public void updateUI() { 208 setUI((DesktopPaneUI)UIManager.getUI(this)); 209 } 210 211 212 219 public String getUIClassID() { 220 return uiClassID; 221 } 222 223 229 public JInternalFrame [] getAllFrames() { 230 int i, count; 231 JInternalFrame [] results; 232 Vector vResults = new Vector (10); 233 Object next, tmp; 234 235 count = getComponentCount(); 236 for(i = 0; i < count; i++) { 237 next = getComponent(i); 238 if(next instanceof JInternalFrame ) 239 vResults.addElement(next); 240 else if(next instanceof JInternalFrame.JDesktopIcon ) { 241 tmp = ((JInternalFrame.JDesktopIcon )next).getInternalFrame(); 242 if(tmp != null) 243 vResults.addElement(tmp); 244 } 245 } 246 247 results = new JInternalFrame [vResults.size()]; 248 vResults.copyInto(results); 249 250 return results; 251 } 252 253 261 262 public JInternalFrame getSelectedFrame() { 263 return selectedFrame; 264 } 265 266 272 273 public void setSelectedFrame(JInternalFrame f) { 274 selectedFrame = f; 275 } 276 277 286 public JInternalFrame [] getAllFramesInLayer(int layer) { 287 int i, count; 288 JInternalFrame [] results; 289 Vector vResults = new Vector (10); 290 Object next, tmp; 291 292 count = getComponentCount(); 293 for(i = 0; i < count; i++) { 294 next = getComponent(i); 295 if(next instanceof JInternalFrame ) { 296 if(((JInternalFrame )next).getLayer() == layer) 297 vResults.addElement(next); 298 } else if(next instanceof JInternalFrame.JDesktopIcon ) { 299 tmp = ((JInternalFrame.JDesktopIcon )next).getInternalFrame(); 300 if(tmp != null && ((JInternalFrame )tmp).getLayer() == layer) 301 vResults.addElement(tmp); 302 } 303 } 304 305 results = new JInternalFrame [vResults.size()]; 306 vResults.copyInto(results); 307 308 return results; 309 } 310 311 312 320 public boolean isOpaque() { 321 return true; 322 } 323 324 325 329 private void writeObject(ObjectOutputStream s) throws IOException { 330 s.defaultWriteObject(); 331 if (getUIClassID().equals(uiClassID)) { 332 byte count = JComponent.getWriteObjCounter(this); 333 JComponent.setWriteObjCounter(this, --count); 334 if (count == 0 && ui != null) { 335 ui.installUI(this); 336 } 337 } 338 } 339 340 void setUIProperty(String propertyName, Object value) { 341 if (propertyName == "dragMode") { 342 if (!dragModeSet) { 343 setDragMode(((Integer )value).intValue()); 344 dragModeSet = false; 345 } 346 } else { 347 super.setUIProperty(propertyName, value); 348 } 349 } 350 351 360 protected String paramString() { 361 String desktopManagerString = (desktopManager != null ? 362 desktopManager.toString() : ""); 363 364 return super.paramString() + 365 ",desktopManager=" + desktopManagerString; 366 } 367 368 372 382 public AccessibleContext getAccessibleContext() { 383 if (accessibleContext == null) { 384 accessibleContext = new AccessibleJDesktopPane(); 385 } 386 return accessibleContext; 387 } 388 389 404 protected class AccessibleJDesktopPane extends AccessibleJComponent { 405 406 413 public AccessibleRole getAccessibleRole() { 414 return AccessibleRole.DESKTOP_PANE; 415 } 416 } 417 } 418 419 | Popular Tags |