1 19 20 package org.netbeans.core.windows; 21 22 23 import org.openide.windows.Mode; 24 import org.openide.windows.TopComponent; 25 import org.openide.windows.Workspace; 26 27 import java.beans.PropertyChangeListener ; 28 import java.beans.PropertyChangeSupport ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Set ; 32 import javax.swing.SwingUtilities ; 33 import java.awt.Image ; 34 import java.awt.Rectangle ; 35 36 37 42 public final class ModeImpl implements Mode { 43 44 45 private static final String MODE_ANONYMOUS_NAME = "anonymousMode"; 47 48 private final PropertyChangeSupport changeSupport = new PropertyChangeSupport (this); 49 50 51 private static final boolean DEBUG = Debug.isLoggable(ModeImpl.class); 52 53 54 55 private ModeImpl(String name, int state, int kind, boolean permanent) { 56 getCentral().createModeModel(this, name, state, kind, permanent); 57 } 58 59 60 61 public static ModeImpl createModeImpl(String name, int state, int kind, boolean permanent) { 62 return new ModeImpl(name, state, kind, permanent); 63 } 64 65 66 73 public String getName () { 74 WindowManagerImpl.assertEventDispatchThreadWeak(); 75 76 return getCentral().getModeName(this); 77 } 78 79 83 public String getDisplayName () { 84 WindowManagerImpl.assertEventDispatchThreadWeak(); 85 86 return getName(); 87 } 88 89 93 public Image getIcon () { 94 WindowManagerImpl.assertEventDispatchThreadWeak(); 95 96 return null; 97 } 98 99 103 public boolean canDock(TopComponent tc) { 104 WindowManagerImpl.assertEventDispatchThreadWeak(); 105 106 return true; 107 } 108 109 117 public boolean dockInto(TopComponent tc) { 118 WindowManagerImpl.assertEventDispatchThreadWeak(); 119 120 return dockIntoImpl(tc, true); 121 } 122 123 126 public void setBounds (Rectangle bounds) { 127 WindowManagerImpl.assertEventDispatchThreadWeak(); 128 129 getCentral().setModeBounds(this, bounds); 130 } 131 132 136 public Rectangle getBounds () { 137 WindowManagerImpl.assertEventDispatchThreadWeak(); 138 139 return getCentral().getModeBounds(this); 140 } 141 142 143 148 public Workspace getWorkspace () { 149 WindowManagerImpl.assertEventDispatchThreadWeak(); 150 151 return WindowManagerImpl.getInstance(); 153 } 154 155 161 public TopComponent[] getTopComponents() { 162 WindowManagerImpl.assertEventDispatchThreadWeak(); 163 164 return getCentral().getModeTopComponents(this).toArray(new TopComponent[0]); 165 } 166 167 169 public void addPropertyChangeListener (PropertyChangeListener pchl) { 170 changeSupport.addPropertyChangeListener(pchl); 171 } 172 173 175 public void removePropertyChangeListener (PropertyChangeListener pchl) { 176 changeSupport.removePropertyChangeListener(pchl); 177 } 178 182 183 191 private boolean dockIntoImpl(final TopComponent tc, final boolean select) { 192 if(DEBUG) { 193 Debug.log(ModeImpl.class, "Docking tc=" + tc.getName() + " into mode=" + this); Debug.dumpStack(ModeImpl.class); 195 } 196 197 ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(tc); 200 if(mode != null && mode != this) { 201 mode.removeTopComponent(tc); 204 } 205 206 addClosedTopComponent(tc); 207 return true; 208 } 209 210 211 public void close(TopComponent tc) { 212 if(!getOpenedTopComponents().contains(tc)) { 213 return; 214 } 215 216 if(WindowManagerImpl.getInstance().isTopComponentPersistentWhenClosed(tc)) { 217 addClosedTopComponent(tc); 218 } else { 219 removeTopComponent(tc); 220 } 221 } 222 223 224 public List <TopComponent> getOpenedTopComponents() { 225 return getCentral().getModeOpenedTopComponents(this); 226 } 227 228 229 public void setSelectedTopComponent(TopComponent tc) { 230 if(!getOpenedTopComponents().contains(tc)) { 231 return; 232 } 233 234 TopComponent old = getSelectedTopComponent(); 235 if(tc == old) { 236 return; 237 } 238 239 getCentral().setModeSelectedTopComponent(this, tc); 240 } 241 242 243 public TopComponent getSelectedTopComponent() { 244 WindowManagerImpl.assertEventDispatchThread(); 245 246 return getCentral().getModeSelectedTopComponent(this); 247 } 248 249 253 public void setPreviousSelectedTopComponent(TopComponent tc) { 254 TopComponent old = getPreviousSelectedTopComponent(); 255 if(tc == old) { 256 return; 257 } 258 259 getCentral().setModePreviousSelectedTopComponent(this, tc); 260 } 261 262 266 public TopComponent getPreviousSelectedTopComponent() { 267 WindowManagerImpl.assertEventDispatchThread(); 268 269 return getCentral().getModePreviousSelectedTopComponent(this); 270 } 271 272 public void addOpenedTopComponent(TopComponent tc) { 273 getCentral().addModeOpenedTopComponent(this, tc); 274 } 275 276 public void addOpenedTopComponent(TopComponent tc, int index) { 277 getCentral().insertModeOpenedTopComponent( this, tc, index ); 278 } 279 280 public void addClosedTopComponent(TopComponent tc) { 281 getCentral().addModeClosedTopComponent(this, tc); 282 } 283 284 public void addUnloadedTopComponent(String tcID) { 285 getCentral().addModeUnloadedTopComponent(this, tcID); 286 } 287 288 public void setUnloadedSelectedTopComponent(String tcID) { 289 getCentral().setUnloadedSelectedTopComponent(this, tcID); 290 } 291 292 public void setUnloadedPreviousSelectedTopComponent(String tcID) { 293 getCentral().setUnloadedPreviousSelectedTopComponent(this, tcID); 294 } 295 296 public List <String > getOpenedTopComponentsIDs() { 298 return getCentral().getModeOpenedTopComponentsIDs(this); 299 } 300 public List getClosedTopComponentsIDs() { 302 return getCentral().getModeClosedTopComponentsIDs(this); 303 } 304 public List getTopComponentsIDs() { 306 return getCentral().getModeTopComponentsIDs(this); 307 } 308 309 312 public void setFrameState(int state) { 313 getCentral().setModeFrameState(this, state); 314 } 315 316 322 public int getFrameState () { 323 return getCentral().getModeFrameState(this); 324 } 325 326 328 public boolean isPermanent () { 329 return getCentral().isModePermanent(this); 330 } 331 332 333 public boolean isEmpty() { 334 return getCentral().isModeEmpty(this); 335 } 336 337 public boolean containsTopComponent(TopComponent tc) { 338 return getCentral().containsModeTopComponent(this, tc); 339 } 340 341 342 public int getState() { 343 return getCentral().getModeState(this); 344 } 345 346 347 public int getKind() { 348 return getCentral().getModeKind(this); 349 } 350 351 public String getSide() { 352 return getCentral().getModeSide(this); 353 } 354 355 357 public void setConstraints(SplitConstraint[] constraints) { 358 WindowManagerImpl.getInstance().setModeConstraints(this, constraints); 359 } 360 361 362 public SplitConstraint[] getConstraints() { 363 return WindowManagerImpl.getInstance().getModeConstraints(this); 364 } 365 366 367 public void removeTopComponent(TopComponent tc) { 368 getCentral().removeModeTopComponent(this, tc); 369 } 370 371 public void removeTopComponents(Set topComponentSet) { 372 for(Iterator it = topComponentSet.iterator(); it.hasNext(); ) { 373 TopComponent tc = (TopComponent)it.next(); 374 removeTopComponent(tc); 375 } 376 } 377 378 public void removeClosedTopComponentID(String tcID) { 380 getCentral().removeModeClosedTopComponentID(this, tcID); 381 } 382 383 386 public boolean canContain(TopComponent tc) { 387 if(Constants.SWITCH_MODE_ADD_NO_RESTRICT 388 || WindowManagerImpl.getInstance().isTopComponentAllowedToMoveAnywhere(tc)) { 389 return true; 390 } 391 392 ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(tc); 393 if(mode == null) { 394 return true; 395 } 396 int myKind = getKind(); 398 int otherKind = mode.getKind(); 399 400 return (myKind == otherKind) || 401 (myKind != Constants.MODE_KIND_EDITOR && otherKind != Constants.MODE_KIND_EDITOR); 402 } 403 404 void doFirePropertyChange(final String propName, 405 final Object oldValue, final Object newValue) { 406 if(SwingUtilities.isEventDispatchThread()) { 410 changeSupport.firePropertyChange(propName, oldValue, newValue); 411 } else { 412 SwingUtilities.invokeLater(new Runnable () { 413 public void run() { 414 changeSupport.firePropertyChange(propName, oldValue, newValue); 415 } 416 }); 417 } 418 } 419 420 421 public String toString () { 422 return super.toString () + "[" + getCentral().getModeName(this) + "]"; } 425 426 427 private static Central getCentral() { 428 return WindowManagerImpl.getInstance().getCentral(); 429 } 430 431 432 static String getUnusedModeName() { 435 String base = MODE_ANONYMOUS_NAME; 436 437 if (base.length() > 20) { 440 base = base.substring(0, 20); 441 } 442 443 String result; 445 int modeNumber = 1; 446 WindowManagerImpl wm = WindowManagerImpl.getInstance(); 447 while(wm.findMode(result = base + "_" + modeNumber) != null) { modeNumber++; 449 } 450 return result; 451 } 452 455 456 } 457 458 | Popular Tags |