1 19 20 package org.netbeans.core.windows.model; 21 22 import java.util.Collections ; 23 import java.util.HashMap ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 import org.netbeans.core.windows.Constants; 27 import org.netbeans.core.windows.ModeImpl; 28 import org.netbeans.core.windows.ModeStructureSnapshot; 29 import org.netbeans.core.windows.SplitConstraint; 30 31 import java.util.HashSet ; 32 import java.util.Set ; 33 import org.netbeans.core.windows.WindowManagerImpl; 34 import org.openide.windows.TopComponent; 35 36 37 47 final class ModesSubModel { 48 49 50 private final Model parentModel; 51 52 53 private final Set <ModeImpl> modes = new HashSet <ModeImpl>(10); 54 55 56 private final EditorSplitSubModel editorSplitSubModel; 57 58 60 private final HashMap <ModeImpl, String > slidingModes2Sides = new HashMap <ModeImpl, String >(5); 61 private final HashMap <String , ModeImpl> slidingSides2Modes = new HashMap <String , ModeImpl>(5); 62 63 64 private ModeImpl activeMode; 65 66 private ModeImpl editorMaximizedMode; 67 private ModeImpl viewMaximizedMode; 68 69 private final Map <String ,Integer > slideInSizes = new HashMap <String ,Integer >(15); 72 73 74 75 public ModesSubModel(Model parentModel) { 76 this.parentModel = parentModel; 77 78 this.editorSplitSubModel = new EditorSplitSubModel(parentModel, new SplitSubModel(parentModel)); 79 } 80 81 82 public void setEditorAreaConstraints(SplitConstraint[] editorAreaConstraints) { 83 editorSplitSubModel.setEditorNodeConstraints(editorAreaConstraints); 84 } 85 86 public SplitConstraint[] getModelElementConstraints(ModelElement element) { 87 return editorSplitSubModel.getModelElementConstraints(element); 88 } 89 90 public SplitConstraint[] getEditorAreaConstraints() { 91 return editorSplitSubModel.getEditorNodeConstraints(); 92 } 93 94 public SplitConstraint[] getModeConstraints(ModeImpl mode) { 95 if(mode.getKind() == Constants.MODE_KIND_EDITOR) { 96 return editorSplitSubModel.getEditorArea().getModeConstraints(mode); 97 } else { 98 return editorSplitSubModel.getModeConstraints(mode); 99 } 100 } 101 102 109 public String getSlideSideForMode( ModeImpl mode ) { 110 return editorSplitSubModel.getSlideSideForMode( mode ); 111 } 112 113 public String getSlidingModeConstraints(ModeImpl mode) { 114 return slidingModes2Sides.get(mode); 115 } 116 117 public ModeImpl getSlidingMode(String side) { 118 return slidingSides2Modes.get(side); 119 } 120 121 public Set <ModeImpl> getSlidingModes() { 122 return Collections.unmodifiableSet(slidingModes2Sides.keySet()); 123 } 124 125 public boolean addMode(ModeImpl mode, SplitConstraint[] constraints) { 126 if(modes.contains(mode)) { 127 return false; 128 } 129 130 boolean result; 131 if(mode.getKind() == Constants.MODE_KIND_EDITOR && 132 mode.getState() == Constants.MODE_STATE_JOINED) { 133 result = editorSplitSubModel.getEditorArea().addMode(mode, constraints); 134 } else { 135 result = editorSplitSubModel.addMode(mode, constraints); 136 } 137 138 if(result) { 139 modes.add(mode); 140 } 141 return result; 142 } 143 144 public boolean addModeToSide(ModeImpl mode, ModeImpl attachMode, String side) { 146 if(modes.contains(mode)) { 147 return false; 148 } 149 150 boolean result; 151 if(mode.getKind() == Constants.MODE_KIND_EDITOR) { 153 result = editorSplitSubModel.getEditorArea().addModeToSide(mode, attachMode, side); 154 } else { 155 result = editorSplitSubModel.addModeToSide(mode, attachMode, side); 156 } 157 158 if(result) { 159 modes.add(mode); 160 } 161 return result; 162 } 163 164 public boolean addModeAround(ModeImpl mode, String side) { 166 if(modes.contains(mode)) { 167 return false; 168 } 169 170 boolean result; 171 if(mode.getKind() == Constants.MODE_KIND_EDITOR) { 173 result = false; 174 } else { 175 result = editorSplitSubModel.addModeAround(mode, side); 176 } 177 178 if(result) { 179 modes.add(mode); 180 } 181 return result; 182 } 183 184 public boolean addModeAroundEditor(ModeImpl mode, String side) { 186 if(modes.contains(mode)) { 187 return false; 188 } 189 190 boolean result; 191 if(mode.getKind() == Constants.MODE_KIND_EDITOR) { 193 result = editorSplitSubModel.getEditorArea().addModeToSideRoot(mode, side); 194 } else { 195 result = editorSplitSubModel.addModeAroundEditor(mode, side); 196 } 197 198 if(result) { 199 modes.add(mode); 200 } 201 return result; 202 } 203 204 public boolean addModeSliding(ModeImpl mode, String side, Map <String ,Integer > slideInSizes) { 205 if(modes.contains(mode) || (mode.getKind() != Constants.MODE_KIND_SLIDING)) { 206 return false; 207 } 208 209 slidingModes2Sides.put(mode, side); 210 slidingSides2Modes.put(side, mode); 211 212 modes.add(mode); 213 214 if( null != slideInSizes ) { 215 for( Iterator <String > i=slideInSizes.keySet().iterator(); i.hasNext(); ) { 216 String tcId = i.next(); 217 this.slideInSizes.put( side+tcId, slideInSizes.get( tcId ) ); 218 } 219 } 220 221 return true; 222 } 223 224 public Map <String , Integer > getSlideInSizes(String side) { 225 Map <String ,Integer > res = new HashMap <String ,Integer >( 5 ); 226 for( Iterator <String > i=slideInSizes.keySet().iterator(); i.hasNext(); ) { 227 String key = i.next(); 228 if( key.startsWith( side ) ) { 229 String tcId = key.substring( side.length() ); 230 Integer size = slideInSizes.get( key ); 231 res.put( tcId, size ); 232 } 233 } 234 return res; 235 } 236 237 public Map <TopComponent, Integer > getSlideInSizes(ModeImpl mode) { 238 WindowManagerImpl wm = WindowManagerImpl.getInstance(); 239 TopComponent[] tcs = mode.getTopComponents(); 240 Map <TopComponent,Integer > res = new HashMap <TopComponent,Integer >( tcs.length ); 241 for( TopComponent tc : tcs ) { 242 String tcId = wm.findTopComponentID( tc ); 243 Integer size = slideInSizes.get( mode.getSide() + tcId ); 244 if( null != size ) { 245 res.put( tc, size ); 246 } 247 } 248 return res; 249 } 250 251 public void setSlideInSize(String side, TopComponent tc, int size) { 252 if( null != tc && null != side ) { 253 String tcId = WindowManagerImpl.getInstance().findTopComponentID(tc); 254 slideInSizes.put( side+tcId, new Integer (size) ); 255 } 256 } 257 258 public boolean removeMode(ModeImpl mode) { 259 int kind = mode.getKind(); 260 if (kind == Constants.MODE_KIND_SLIDING) { 261 return true; 262 } 266 modes.remove(mode); 267 if(mode.getKind() == Constants.MODE_KIND_EDITOR) { 268 return editorSplitSubModel.getEditorArea().removeMode(mode); 269 } else { 270 return editorSplitSubModel.removeMode(mode); 271 } 272 } 273 274 275 public boolean setActiveMode(ModeImpl activeMode) { 276 if(activeMode == null || modes.contains(activeMode)) { 277 this.activeMode = activeMode; 278 return true; 279 } 280 281 return false; 282 } 283 284 285 public ModeImpl getActiveMode() { 286 return this.activeMode; 287 } 288 289 290 public boolean setEditorMaximizedMode(ModeImpl maximizedMode) { 291 if(maximizedMode == null || modes.contains(maximizedMode)) { 292 this.editorMaximizedMode = maximizedMode; 293 return true; 294 } 295 296 return false; 297 } 298 299 300 public ModeImpl getEditorMaximizedMode() { 301 return this.editorMaximizedMode; 302 } 303 304 305 public boolean setViewMaximizedMode(ModeImpl maximizedMode) { 306 if(maximizedMode == null || modes.contains(maximizedMode)) { 307 this.viewMaximizedMode = maximizedMode; 308 return true; 309 } 310 311 return false; 312 } 313 314 315 public ModeImpl getViewMaximizedMode() { 316 return this.viewMaximizedMode; 317 } 318 319 public Set <ModeImpl> getModes() { 320 return new HashSet <ModeImpl>(modes); 321 } 322 323 public void setSplitWeights( ModelElement[] snapshots, double[] splitWeights ) { 324 editorSplitSubModel.setSplitWeights( snapshots, splitWeights ); 325 } 326 327 public String toString() { 328 return getClass().getName() + "@" + Integer.toHexString(hashCode()) + "\n" + editorSplitSubModel; } 331 332 public ModeStructureSnapshot.ElementSnapshot createSplitSnapshot() { 335 return editorSplitSubModel.createSplitSnapshot(); 336 } 337 338 339 public Set <ModeStructureSnapshot.ModeSnapshot> createSeparateModeSnapshots() { 340 Set <ModeStructureSnapshot.ModeSnapshot> s = 341 new HashSet <ModeStructureSnapshot.ModeSnapshot>(); 342 343 s.addAll(editorSplitSubModel.createSeparateSnapshots()); 344 345 return s; 346 } 347 348 public Set <ModeStructureSnapshot.SlidingModeSnapshot> createSlidingModeSnapshots() { 349 Set <ModeStructureSnapshot.SlidingModeSnapshot> result = 350 new HashSet <ModeStructureSnapshot.SlidingModeSnapshot>(); 351 for (Map.Entry <ModeImpl, String > curEntry: slidingModes2Sides.entrySet()) { 352 result.add(new ModeStructureSnapshot.SlidingModeSnapshot( 353 curEntry.getKey(), curEntry.getValue(), 354 getSlideInSizes(curEntry.getKey()))); 355 } 356 357 return result; 358 } 359 360 362 363 366 public ModeImpl getModeForOriginator(ModelElement originator) { 367 ModeImpl mode = editorSplitSubModel.getModeForOriginator(originator); 368 369 if(modes.contains(mode)) { 370 return mode; 371 } else { 372 return null; 373 } 374 } 375 376 379 } 380 381 | Popular Tags |