Coverage Report - org.argouml.notation.NotationSettings
 
Classes in this File Line Coverage Branch Coverage Complexity
NotationSettings
73%
112/152
45%
37/82
2.622
NotationSettings$1
60%
3/5
N/A
2.622
NotationSettings$2
57%
4/7
0%
0/2
2.622
NotationSettings$3
57%
4/7
0%
0/2
2.622
NotationSettings$4
57%
4/7
0%
0/2
2.622
NotationSettings$5
57%
4/7
0%
0/2
2.622
NotationSettings$6
57%
4/7
0%
0/2
2.622
NotationSettings$7
57%
4/7
0%
0/2
2.622
NotationSettings$8
57%
4/7
0%
0/2
2.622
NotationSettings$9
57%
4/7
0%
0/2
2.622
 
 1  
 /* $Id: NotationSettings.java 17825 2010-01-12 18:49:29Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    mvw
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2008-2009 Tom Morris and other contributors. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Contributors.
 22  
 // The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Contributors. The 
 24  
 // Contributors do not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // CONTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE CONTRIBUTORS SPECIFICALLY DISCLAIM ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE CONTRIBUTORS
 36  
 // HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.notation;
 40  
 
 41  
 import org.tigris.gef.undo.Memento;
 42  
 
 43  
 /**
 44  
  * Notation settings value object. Stores settings which control how text is
 45  
  * rendered on diagrams.
 46  
  * <p>
 47  
  * TODO: This needs to go on a diet. It's used everywhere, so is performance
 48  
  * sensitive. The current set of settings is the union of all those found in the
 49  
  * legacy code, but it's not clear that all of them are actually used.
 50  
  * 
 51  
  * @author Tom Morris <tfmorris@gmail.com>
 52  
  */
 53  31761
 public class NotationSettings {
 54  
 
 55  900
     private static final NotationSettings DEFAULT_SETTINGS = 
 56  
         initializeDefaultSettings();
 57  
     
 58  
     private NotationSettings parent;
 59  
 
 60  
     private String notationLanguage;
 61  
     
 62  
     // No valid field for above notationLanguage.  It's valid if not null.
 63  
     
 64  
     private boolean showAssociationNames;
 65  
 
 66  4010
     private boolean showAssociationNamesSet = false;
 67  
 
 68  
     private boolean showVisibilities;
 69  
 
 70  4010
     private boolean showVisibilitiesSet = false;
 71  
 
 72  
     private boolean showPaths;
 73  
 
 74  4010
     private boolean showPathsSet = false;
 75  
 
 76  
     private boolean fullyHandleStereotypes;
 77  
 
 78  4010
     private boolean fullyHandleStereotypesSet = false;
 79  
 
 80  
     private boolean useGuillemets;
 81  
 
 82  4010
     private boolean useGuillemetsSet = false;
 83  
 
 84  
     private boolean showMultiplicities;
 85  
 
 86  4010
     private boolean showMultiplicitiesSet = false;
 87  
 
 88  
     private boolean showSingularMultiplicities;
 89  
 
 90  4010
     private boolean showSingularMultiplicitiesSet = false;
 91  
 
 92  
     // TODO: Do we need to control separately for attributes and operations?
 93  
     private boolean showTypes;
 94  
 
 95  4010
     private boolean showTypesSet = false;
 96  
 
 97  
     private boolean showProperties;
 98  
 
 99  4010
     private boolean showPropertiesSet = false;
 100  
 
 101  
     private boolean showInitialValues;
 102  
 
 103  4010
     private boolean showInitialValuesSet = false;
 104  
 
 105  
     /**
 106  
      * Create a notation settings value object with all default values.
 107  
      * <p>
 108  
      * TODO: This class only has partial Undo support (basically just those
 109  
      * members that had it as part of a previous implementation).
 110  
      */
 111  
     public NotationSettings() {
 112  4010
         super();
 113  4010
         parent = getDefaultSettings();
 114  4010
     }
 115  
 
 116  
     /**
 117  
      * Create a notation settings object which uses the given settings as its
 118  
      * default values.  Note that there can be multiple levels of settings in
 119  
      * the hierarchy.
 120  
      */
 121  
     public NotationSettings(NotationSettings parentSettings) {
 122  1071
         this();
 123  1071
         parent = parentSettings;
 124  1071
     }
 125  
 
 126  
     // TODO: These defaults need to be checked against historical ones
 127  
     private static NotationSettings initializeDefaultSettings() {
 128  900
         NotationSettings settings = new NotationSettings();
 129  900
         settings.parent = null;
 130  900
         settings.setNotationLanguage(Notation.DEFAULT_NOTATION);
 131  900
         settings.setFullyHandleStereotypes(false);
 132  900
         settings.setShowAssociationNames(true);
 133  900
         settings.setShowInitialValues(false);
 134  900
         settings.setShowMultiplicities(false);
 135  900
         settings.setShowPaths(false);
 136  900
         settings.setShowProperties(false);
 137  900
         settings.setShowSingularMultiplicities(true);
 138  900
         settings.setShowTypes(true);
 139  900
         settings.setShowVisibilities(false);
 140  900
         settings.setUseGuillemets(false);
 141  900
         return settings;
 142  
     }
 143  
     
 144  
     /**
 145  
      * @return the default settings
 146  
      */
 147  
     public static NotationSettings getDefaultSettings() {
 148  4010
         return DEFAULT_SETTINGS;
 149  
     }
 150  
     
 151  
     /**
 152  
      * @return Return the notation language.
 153  
      */
 154  
     public String getNotationLanguage() {
 155  157
         if (notationLanguage == null) {
 156  0
             if (parent != null) {
 157  0
                 return parent.getNotationLanguage();
 158  
             } else {
 159  0
                 return Notation.DEFAULT_NOTATION;
 160  
             }
 161  
         }
 162  157
         return notationLanguage;
 163  
     }
 164  
 
 165  
 
 166  
     /**
 167  
      * @param newLanguage the notation language.
 168  
      * @return true if the notation is set - false if it does not exist
 169  
      */
 170  
     public boolean setNotationLanguage(final String newLanguage) {
 171  1869
         if (notationLanguage != null 
 172  
                 && notationLanguage.equals(newLanguage)) {
 173  0
             return true;
 174  
         }
 175  
         
 176  
         // TODO: Do we care?
 177  1869
         if (Notation.findNotation(newLanguage) == null) {
 178  
             /* This Notation is not available! */
 179  0
             return false;
 180  
         }
 181  
 
 182  1869
         final String oldLanguage = notationLanguage;
 183  
 
 184  1869
         Memento memento = new Memento() {
 185  
             public void redo() {
 186  1869
                 notationLanguage = newLanguage;
 187  
                 // TODO: We can't have a global "current" language
 188  
                 // NotationProviderFactory2.setCurrentLanguage(newLanguage);
 189  1869
             }
 190  
 
 191  
             public void undo() {
 192  0
                 notationLanguage = oldLanguage;
 193  
                 // TODO: We can't have a global "current" language
 194  
                 // NotationProviderFactory2.setCurrentLanguage(oldLanguage);
 195  0
             }
 196  
         };
 197  1869
         doUndoable(memento);
 198  1869
         return true;
 199  
     }
 200  
 
 201  
 
 202  
     /**
 203  
      * @return Returns the fullyHandleStereotypes setting. If true, it will
 204  
      *         cause notation providers to include the names of the stereotypes
 205  
      *         for an element in the editable string presented to the user.
 206  
      */
 207  
     public boolean isFullyHandleStereotypes() {
 208  0
         if (fullyHandleStereotypesSet) {
 209  0
             return fullyHandleStereotypes;
 210  
         } else {
 211  0
             if (parent != null) {
 212  0
                 return parent.isFullyHandleStereotypes();
 213  
             } else {
 214  0
                 return getDefaultSettings().isFullyHandleStereotypes();
 215  
             }
 216  
         }
 217  
     }
 218  
 
 219  
     /**
 220  
      * @param newValue The fullyHandleStereotypes to set. If true, it will cause
 221  
      *            notation providers to include the names of the stereotypes for
 222  
      *            an element in the editable string presented to the user.
 223  
      */
 224  
     public void setFullyHandleStereotypes(boolean newValue) {
 225  900
         fullyHandleStereotypes = newValue;
 226  900
         fullyHandleStereotypesSet = true;
 227  900
     }
 228  
 
 229  
     /**
 230  
      * @return Returns the showSingularMultiplicities.
 231  
      */
 232  
     public boolean isShowSingularMultiplicities() {
 233  120
         if (showSingularMultiplicitiesSet) {
 234  120
             return showSingularMultiplicities;
 235  0
         } else if (parent != null) {
 236  0
             return parent.isShowSingularMultiplicities();
 237  
         }
 238  0
         return getDefaultSettings().isShowSingularMultiplicities();
 239  
     }
 240  
 
 241  
     /**
 242  
      * @param showem <code>true</code> if "1" Multiplicities are to be shown.
 243  
      */
 244  
     public void setShowSingularMultiplicities(final boolean showem) {
 245  1880
         if (showSingularMultiplicities == showem 
 246  
                 && showSingularMultiplicitiesSet) {
 247  12
             return;
 248  
         }
 249  
 
 250  1868
         final boolean oldValid = showSingularMultiplicitiesSet;
 251  1868
         Memento memento = new Memento() {
 252  
             public void redo() {
 253  1868
                 showSingularMultiplicities = showem;
 254  1868
                 showSingularMultiplicitiesSet = true;
 255  1868
             }
 256  
 
 257  
             public void undo() {
 258  0
                 showSingularMultiplicities = !showem;
 259  0
                 showSingularMultiplicitiesSet = oldValid;
 260  0
             }
 261  
         };
 262  1868
         doUndoable(memento);
 263  1868
     }
 264  
 
 265  
     /**
 266  
      * @return Returns the useGuillemets.
 267  
      */
 268  
     public boolean isUseGuillemets() {
 269  132
         if (useGuillemetsSet) {
 270  132
             return useGuillemets;
 271  0
         } else if (parent != null) {
 272  0
             return parent.isUseGuillemets();
 273  
         }
 274  0
         return getDefaultSettings().isUseGuillemets();
 275  
     }
 276  
 
 277  
     /**
 278  
      * @param showem <code>true</code> if guillemets are to be shown.
 279  
      */
 280  
     public void setUseGuillemets(final boolean showem) {
 281  1868
         if (useGuillemets == showem && useGuillemetsSet) {
 282  0
             return;
 283  
         }
 284  
 
 285  1868
         final boolean oldValid = useGuillemetsSet;
 286  
         
 287  1868
         Memento memento = new Memento() {
 288  
             public void redo() {
 289  1868
                 useGuillemets = showem;
 290  1868
                 useGuillemetsSet = true;
 291  1868
             }
 292  
 
 293  
             public void undo() {
 294  0
                 useGuillemets = !showem;
 295  0
                 useGuillemetsSet = oldValid;
 296  0
             }
 297  
         };
 298  1868
         doUndoable(memento);
 299  1868
     }
 300  
 
 301  
     /**
 302  
      * @return Returns the showTypes.
 303  
      */
 304  
     public boolean isShowTypes() {
 305  120
         if (showTypesSet) {
 306  120
             return showTypes;
 307  0
         } else if (parent != null) {
 308  0
             return parent.isShowTypes();
 309  
         }
 310  0
         return getDefaultSettings().isShowTypes();
 311  
     }
 312  
 
 313  
 
 314  
     /**
 315  
      * @param showem <code>true</code> if types are to be shown.
 316  
      */
 317  
     public void setShowTypes(final boolean showem) {
 318  1880
         if (showTypes == showem && showTypesSet) {
 319  12
             return;
 320  
         }
 321  
 
 322  1868
         final boolean oldValid = showTypesSet;
 323  
         
 324  1868
         Memento memento = new Memento() {
 325  
             public void redo() {
 326  1868
                 showTypes = showem;
 327  1868
                 showTypesSet = true;
 328  1868
             }
 329  
 
 330  
             public void undo() {
 331  0
                 showTypes = !showem;
 332  0
                 showTypesSet = oldValid;
 333  0
             }
 334  
         };
 335  1868
         doUndoable(memento);
 336  
 
 337  1868
     }
 338  
 
 339  
     /**
 340  
      * @return Returns the showProperties.
 341  
      */
 342  
     public boolean isShowProperties() {
 343  120
         if (showPropertiesSet) {
 344  120
             return showProperties;
 345  0
         } else if (parent != null) {
 346  0
             return parent.isShowProperties();
 347  
         }
 348  0
         return getDefaultSettings().isShowProperties();
 349  
     }
 350  
 
 351  
     /**
 352  
      * @param showem <code>true</code> if properties are to be shown.
 353  
      */
 354  
     public void setShowProperties(final boolean showem) {
 355  1880
         if (showProperties == showem && showPropertiesSet) {
 356  12
             return;
 357  
         }
 358  
 
 359  1868
         final boolean oldValid = showPropertiesSet;
 360  
         
 361  1868
         Memento memento = new Memento() {
 362  
             public void redo() {
 363  1868
                 showProperties = showem;
 364  1868
                 showPropertiesSet = true;
 365  1868
             }
 366  
 
 367  
             public void undo() {
 368  0
                 showProperties = !showem;
 369  0
                 showPropertiesSet = oldValid;
 370  0
             }
 371  
         };
 372  1868
         doUndoable(memento);
 373  
 
 374  1868
     }
 375  
 
 376  
     /**
 377  
      * @return Returns the showInitialValues.
 378  
      */
 379  
     public boolean isShowInitialValues() {
 380  120
         if (showInitialValuesSet) {
 381  120
             return showInitialValues;
 382  0
         } else if (parent != null) {
 383  0
             return parent.isShowInitialValues();
 384  
         }
 385  0
         return getDefaultSettings().isShowInitialValues();
 386  
     }
 387  
 
 388  
 
 389  
     /**
 390  
      * @param showem <code>true</code> if initial values are to be shown.
 391  
      */
 392  
     public void setShowInitialValues(final boolean showem) {
 393  1880
         if (showInitialValues == showem && showInitialValuesSet) {
 394  12
             return;
 395  
         }
 396  
 
 397  1868
         final boolean oldValid = showInitialValuesSet;
 398  
         
 399  1868
         Memento memento = new Memento() {
 400  
             public void redo() {
 401  1868
                 showInitialValues = showem;
 402  1868
                 showInitialValuesSet = true;
 403  1868
             }
 404  
 
 405  
             public void undo() {
 406  0
                 showInitialValues = !showem;
 407  0
                 showInitialValuesSet = oldValid;
 408  0
             }
 409  
         };
 410  1868
         doUndoable(memento);
 411  
 
 412  1868
     }
 413  
 
 414  
     /**
 415  
      * @return Returns the showMultiplicities.
 416  
      */
 417  
     public boolean isShowMultiplicities() {
 418  120
         if (showMultiplicitiesSet) {
 419  120
             return showMultiplicities;
 420  0
         } else if (parent != null) {
 421  0
             return parent.isShowMultiplicities();
 422  
         }
 423  0
         return getDefaultSettings().isShowMultiplicities();
 424  
     }
 425  
 
 426  
     /**
 427  
      * @param showem <code>true</code> if the multiplicity is to be shown.
 428  
      */
 429  
     public void setShowMultiplicities(final boolean showem) {
 430  1880
         if (showMultiplicities == showem && showMultiplicitiesSet) {
 431  10
             return;
 432  
         }
 433  
 
 434  1870
         final boolean oldValid = showMultiplicitiesSet;
 435  
         
 436  1870
         Memento memento = new Memento() {
 437  
             public void redo() {
 438  1870
                 showMultiplicities = showem;
 439  1870
                 showMultiplicitiesSet = true;
 440  1870
             }
 441  
 
 442  
             public void undo() {
 443  0
                 showMultiplicities = !showem;
 444  0
                 showMultiplicitiesSet = oldValid;
 445  0
             }
 446  
         };
 447  1870
         doUndoable(memento);
 448  1870
     }
 449  
 
 450  
 
 451  
 
 452  
     /**
 453  
      * @return Returns the showAssociationNames.
 454  
      */
 455  
     public boolean isShowAssociationNames() {
 456  120
         if (showAssociationNamesSet) {
 457  120
             return showAssociationNames;
 458  0
         } else if (parent != null) {
 459  0
             return parent.isShowAssociationNames();
 460  
         }
 461  0
         return getDefaultSettings().isShowAssociationNames();
 462  
     }
 463  
 
 464  
     /**
 465  
      * @param showem <code>true</code> if association names are to be shown.
 466  
      */
 467  
     public void setShowAssociationNames(final boolean showem) {
 468  1880
         if (showAssociationNames == showem && showAssociationNamesSet) {
 469  12
             return;
 470  
         }
 471  
 
 472  1868
         final boolean oldValid = showAssociationNamesSet;
 473  
         
 474  1868
         Memento memento = new Memento() {
 475  
 
 476  
             public void redo() {
 477  1868
                 showAssociationNames = showem;
 478  1868
                 showAssociationNamesSet = true;
 479  1868
             }
 480  
 
 481  
             public void undo() {
 482  0
                 showAssociationNames = !showem;
 483  0
                 showAssociationNamesSet = oldValid;
 484  0
             }
 485  
         };
 486  1868
         doUndoable(memento);
 487  1868
     }
 488  
 
 489  
     /**
 490  
      * @return Returns the showVisibilities.
 491  
      */
 492  
     public boolean isShowVisibilities() {
 493  120
         if (showVisibilitiesSet) {
 494  120
             return showVisibilities;
 495  0
         } else if (parent != null) {
 496  0
             return parent.isShowVisibilities();
 497  
         }
 498  0
         return getDefaultSettings().isShowVisibilities();
 499  
     }
 500  
 
 501  
 
 502  
     /**
 503  
      * @param showem <code>true</code> if visibilities are to be shown.
 504  
      */
 505  
     public void setShowVisibilities(final boolean showem) {
 506  
         
 507  1880
         if (showVisibilities == showem && showVisibilitiesSet) {
 508  12
             return;
 509  
         }
 510  
 
 511  1868
         final boolean oldValid = showVisibilitiesSet;
 512  
         
 513  1868
         Memento memento = new Memento() {
 514  
             public void redo() {
 515  1868
                 showVisibilities = showem;
 516  1868
                 showVisibilitiesSet = true;
 517  1868
             }
 518  
 
 519  
             public void undo() {
 520  0
                 showVisibilities = !showem;
 521  0
                 showVisibilitiesSet = oldValid;
 522  0
             }
 523  
         };
 524  1868
         doUndoable(memento);
 525  1868
     }
 526  
 
 527  
     /**
 528  
      * @return Returns the showPaths.
 529  
      */
 530  
     public boolean isShowPaths() {
 531  0
         if (showPathsSet) {
 532  0
             return showPaths;
 533  0
         } else if (parent != null) {
 534  0
             return parent.isShowPaths();
 535  
         }
 536  0
         return getDefaultSettings().isShowPaths();
 537  
     }
 538  
 
 539  
 
 540  
     /**
 541  
      * @param showPaths The showPaths to set.
 542  
      */
 543  
     public void setShowPaths(boolean showPaths) {
 544  900
         this.showPaths = showPaths;
 545  900
         showPathsSet = true;
 546  900
     }
 547  
 
 548  
    
 549  
     
 550  
     private void doUndoable(Memento memento) {
 551  
         // TODO: Undo should be managed externally or we should be given 
 552  
         // an Undo manager to use (the project's) rather than using a global one
 553  
 //        if (DiagramUndoManager.getInstance().isGenerateMementos()) {
 554  
 //            DiagramUndoManager.getInstance().addMemento(memento);
 555  
 //        }
 556  16815
         memento.redo();
 557  
         // TODO: Mark diagram/project as dirty?
 558  16815
     }
 559  
 
 560  
 }