1 19 20 package org.netbeans.core.windows.model; 21 22 23 24 import java.awt.*; 25 import java.util.List ; 26 27 import org.netbeans.core.windows.ModeImpl; 28 import org.netbeans.core.windows.SplitConstraint; 29 import org.openide.windows.TopComponent; 30 31 32 36 final class DefaultModeModel implements ModeModel { 37 38 39 40 private final String name; 41 42 private final Rectangle bounds = new Rectangle(); 43 44 private final Rectangle boundsSeparetedHelp = new Rectangle(); 45 46 47 private int state; 48 49 private final int kind; 50 51 52 private int frameState; 53 54 55 private final boolean permanent; 56 57 58 private final TopComponentSubModel topComponentSubModel; 59 60 62 private TopComponentContextSubModel topComponentContextSubModel = null; 63 64 66 private final Object LOCK_STATE = new Object (); 67 68 private final Object LOCK_BOUNDS = new Object (); 69 70 private final Object LOCK_BOUNDS_SEPARATED_HELP = new Object (); 71 72 private final Object LOCK_FRAMESTATE = new Object (); 73 74 private final Object LOCK_TOPCOMPONENTS = new Object (); 75 76 private final Object LOCK_TC_CONTEXTS = new Object (); 77 78 79 public DefaultModeModel(String name, int state, int kind, boolean permanent) { 80 this.name = name; 81 this.state = state; 82 this.kind = kind; 83 this.permanent = permanent; 84 this.topComponentSubModel = new TopComponentSubModel(kind); 85 } 86 87 public void setState(int state) { 91 synchronized(LOCK_STATE) { 92 this.state = state; 93 } 94 } 95 96 public void removeTopComponent(TopComponent tc) { 97 synchronized(LOCK_TOPCOMPONENTS) { 98 topComponentSubModel.removeTopComponent(tc); 99 } 100 } 101 102 public void removeClosedTopComponentID(String tcID) { 104 synchronized(LOCK_TOPCOMPONENTS) { 105 topComponentSubModel.removeClosedTopComponentID(tcID); 106 } 107 } 108 109 110 public void addOpenedTopComponent(TopComponent tc) { 111 synchronized(LOCK_TOPCOMPONENTS) { 112 topComponentSubModel.addOpenedTopComponent(tc); 113 } 114 } 115 116 public void insertOpenedTopComponent(TopComponent tc, int index) { 117 synchronized(LOCK_TOPCOMPONENTS) { 118 topComponentSubModel.insertOpenedTopComponent(tc, index); 119 } 120 } 121 122 public void addClosedTopComponent(TopComponent tc) { 123 synchronized(LOCK_TOPCOMPONENTS) { 124 topComponentSubModel.addClosedTopComponent(tc); 125 } 126 } 127 128 public void addUnloadedTopComponent(String tcID) { 129 synchronized(LOCK_TOPCOMPONENTS) { 130 topComponentSubModel.addUnloadedTopComponent(tcID); 131 } 132 } 133 134 public void setUnloadedSelectedTopComponent(String tcID) { 135 synchronized(LOCK_TOPCOMPONENTS) { 136 topComponentSubModel.setUnloadedSelectedTopComponent(tcID); 137 } 138 } 139 140 public void setUnloadedPreviousSelectedTopComponent(String tcID) { 141 synchronized(LOCK_TOPCOMPONENTS) { 142 topComponentSubModel.setUnloadedPreviousSelectedTopComponent(tcID); 143 } 144 } 145 146 147 public void setSelectedTopComponent(TopComponent selected) { 148 synchronized(LOCK_TOPCOMPONENTS) { 149 topComponentSubModel.setSelectedTopComponent(selected); 150 } 151 } 152 153 public void setPreviousSelectedTopComponent(TopComponent prevSelected) { 154 synchronized(LOCK_TOPCOMPONENTS) { 155 topComponentSubModel.setPreviousSelectedTopComponent(prevSelected); 156 } 157 } 158 159 160 public void setFrameState(int frameState) { 161 synchronized(LOCK_FRAMESTATE) { 162 this.frameState = frameState; 163 } 164 } 165 166 public void setBounds(Rectangle bounds) { 167 if(bounds == null) { 168 return; 169 } 170 171 synchronized(LOCK_BOUNDS) { 172 this.bounds.setBounds(bounds); 173 } 174 } 175 176 public void setBoundsSeparatedHelp(Rectangle boundsSeparatedHelp) { 177 if(bounds == null) { 178 return; 179 } 180 181 synchronized(LOCK_BOUNDS_SEPARATED_HELP) { 182 this.boundsSeparetedHelp.setBounds(boundsSeparatedHelp); 183 } 184 } 185 189 190 public String getName() { 194 return name; 195 } 196 197 public Rectangle getBounds() { 198 synchronized(LOCK_BOUNDS) { 199 return (Rectangle)this.bounds.clone(); 200 } 201 } 202 203 public Rectangle getBoundsSeparatedHelp() { 204 synchronized(LOCK_BOUNDS_SEPARATED_HELP) { 205 return (Rectangle)this.boundsSeparetedHelp.clone(); 206 } 207 } 208 209 public int getState() { 210 synchronized(LOCK_STATE) { 211 return this.state; 212 } 213 } 214 215 public int getKind() { 216 return this.kind; 217 } 218 219 220 public int getFrameState() { 221 synchronized(LOCK_FRAMESTATE) { 222 return this.frameState; 223 } 224 } 225 226 public boolean isPermanent() { 227 return this.permanent; 228 } 229 230 public boolean isEmpty() { 231 synchronized(LOCK_TOPCOMPONENTS) { 232 return topComponentSubModel.isEmpty(); 233 } 234 } 235 236 public boolean containsTopComponent(TopComponent tc) { 237 synchronized(LOCK_TOPCOMPONENTS) { 238 return topComponentSubModel.containsTopComponent(tc); 239 } 240 } 241 242 243 public List <TopComponent> getTopComponents() { 244 synchronized(LOCK_TOPCOMPONENTS) { 245 return topComponentSubModel.getTopComponents(); 246 } 247 } 248 249 250 251 public TopComponent getSelectedTopComponent() { 252 synchronized(LOCK_TOPCOMPONENTS) { 253 return topComponentSubModel.getSelectedTopComponent(); 254 } 255 } 256 257 public TopComponent getPreviousSelectedTopComponent() { 258 synchronized(LOCK_TOPCOMPONENTS) { 259 return topComponentSubModel.getPreviousSelectedTopComponent(); 260 } 261 } 262 263 264 public List <TopComponent> getOpenedTopComponents() { 265 synchronized(LOCK_TOPCOMPONENTS) { 266 return topComponentSubModel.getOpenedTopComponents(); 267 } 268 } 269 270 public List <String > getOpenedTopComponentsIDs() { 272 synchronized(LOCK_TOPCOMPONENTS) { 273 return topComponentSubModel.getOpenedTopComponentsIDs(); 274 } 275 } 276 277 public List <String > getClosedTopComponentsIDs() { 278 synchronized(LOCK_TOPCOMPONENTS) { 279 return topComponentSubModel.getClosedTopComponentsIDs(); 280 } 281 } 282 283 public List <String > getTopComponentsIDs() { 284 synchronized(LOCK_TOPCOMPONENTS) { 285 return topComponentSubModel.getTopComponentsIDs(); 286 } 287 } 288 289 public SplitConstraint[] getTopComponentPreviousConstraints(String tcID) { 290 synchronized(LOCK_TC_CONTEXTS) { 291 return getContextSubModel().getTopComponentPreviousConstraints(tcID); 292 } 293 } 294 295 public ModeImpl getTopComponentPreviousMode(String tcID) { 296 synchronized(LOCK_TC_CONTEXTS) { 297 return getContextSubModel().getTopComponentPreviousMode(tcID); 298 } 299 } 300 301 public int getTopComponentPreviousIndex(String tcID) { 302 synchronized(LOCK_TC_CONTEXTS) { 303 return getContextSubModel().getTopComponentPreviousIndex(tcID); 304 } 305 } 306 307 public void setTopComponentPreviousConstraints(String tcID, SplitConstraint[] constraints) { 308 synchronized(LOCK_TC_CONTEXTS) { 309 getContextSubModel().setTopComponentPreviousConstraints(tcID, constraints); 310 } 311 } 312 313 public void setTopComponentPreviousMode(String tcID, ModeImpl mode, int prevIndex) { 314 synchronized(LOCK_TC_CONTEXTS) { 315 getContextSubModel().setTopComponentPreviousMode(tcID, mode, prevIndex); 316 } 317 } 318 319 323 private TopComponentContextSubModel getContextSubModel() { 324 if (topComponentContextSubModel == null) { 325 topComponentContextSubModel = new TopComponentContextSubModel(); 326 } 327 return topComponentContextSubModel; 328 } 329 330 } 331 332 | Popular Tags |