Coverage Report - org.argouml.notation.Notation
 
Classes in this File Line Coverage Branch Coverage Complexity
Notation
77%
31/40
50%
1/2
1.111
 
 1  
 /* $Id: Notation.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) 1996-2009 The Regents of the University of California. 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 Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does 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  
 // UNIVERSITY OF CALIFORNIA 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 UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS 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 UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.notation;
 40  
 
 41  
 import java.beans.PropertyChangeEvent;
 42  
 import java.beans.PropertyChangeListener;
 43  
 import java.util.List;
 44  
 
 45  
 import javax.swing.Icon;
 46  
 
 47  
 import org.apache.log4j.Logger;
 48  
 import org.argouml.application.events.ArgoEventPump;
 49  
 import org.argouml.application.events.ArgoEventTypes;
 50  
 import org.argouml.application.events.ArgoNotationEvent;
 51  
 import org.argouml.application.helpers.ResourceLoaderWrapper;
 52  
 import org.argouml.configuration.Configuration;
 53  
 import org.argouml.configuration.ConfigurationKey;
 54  
 
 55  
 /**
 56  
  * Provides centralized methods dealing with notation.
 57  
  *
 58  
  * @stereotype singleton
 59  
  * @author Thierry Lach
 60  
  * @since 0.9.4
 61  
  */
 62  
 public final class Notation implements PropertyChangeListener {
 63  
 
 64  900
     private static final Logger LOG = Logger.getLogger(Notation.class);
 65  
 
 66  
     // TODO: Do we have any potential consumers of the unversioned name outside
 67  
     // of the notation subsystem?
 68  
     private static final String DEFAULT_NOTATION_NAME = "UML";
 69  
 
 70  
     private static final String DEFAULT_NOTATION_VERSION = "1.4";
 71  
 
 72  
     /**
 73  
      * Default notation with both base name and version (e.g. "UML 1.4")
 74  
      */
 75  
     public static final String DEFAULT_NOTATION = DEFAULT_NOTATION_NAME + " "
 76  
             + DEFAULT_NOTATION_VERSION;
 77  
     
 78  
     /**
 79  
      * The name of the default ArgoUML notation.  This notation is
 80  
      * part of ArgoUML core distribution.
 81  
      */
 82  900
     private static NotationName notationArgo =
 83  
         makeNotation(
 84  
             DEFAULT_NOTATION_NAME,
 85  
             DEFAULT_NOTATION_VERSION,
 86  
             ResourceLoaderWrapper.lookupIconResource("UmlNotation"));
 87  
 
 88  
     /*
 89  
      * Remark:
 90  
      * There is also a java-like notation, which is also
 91  
      * part of ArgoUML core distribution.
 92  
      */
 93  
 
 94  
     /**
 95  
      * The configuration key for the preferred notation.
 96  
      */
 97  900
     public static final ConfigurationKey KEY_DEFAULT_NOTATION =
 98  
         Configuration.makeKey("notation", "default");
 99  
 
 100  
     /**
 101  
      * The configuration key that indicates whether to show stereotypes
 102  
      * in the navigation panel.
 103  
      */
 104  900
     public static final ConfigurationKey KEY_SHOW_STEREOTYPES =
 105  
         Configuration.makeKey("notation", "navigation", "show", "stereotypes");
 106  
 
 107  
     /**
 108  
      * The configuration key that indicates whether to show stereotypes
 109  
      * in the navigation panel.
 110  
      */
 111  900
     public static final ConfigurationKey KEY_SHOW_SINGULAR_MULTIPLICITIES =
 112  
         Configuration.makeKey("notation", "show", "singularmultiplicities");
 113  
 
 114  
 
 115  
     /**
 116  
      * The configuration key that indicates whether to use guillemots
 117  
      * or greater/lessthan characters in stereotypes.
 118  
      */
 119  900
     public static final ConfigurationKey KEY_USE_GUILLEMOTS =
 120  
         Configuration.makeKey("notation", "guillemots");
 121  
 
 122  
     /**
 123  
      * Indicates if the user wants to see association names
 124  
      */
 125  900
     public static final ConfigurationKey KEY_SHOW_ASSOCIATION_NAMES =
 126  
         Configuration.makeKey("notation", "show", "associationnames");
 127  
 
 128  
     /**
 129  
      * Indicates if the user wants to see visibility signs (public,
 130  
      * private, protected or # + -).
 131  
      */
 132  900
     public static final ConfigurationKey KEY_SHOW_VISIBILITY =
 133  
         Configuration.makeKey("notation", "show", "visibility");
 134  
 
 135  
     /**
 136  
      * Indicates if the user wants to see multiplicity in attributes
 137  
      * and classes.
 138  
      */
 139  900
     public static final ConfigurationKey KEY_SHOW_MULTIPLICITY =
 140  
         Configuration.makeKey("notation", "show", "multiplicity");
 141  
 
 142  
     /**
 143  
      * Indicates if the user wants to see the initial value.
 144  
      */
 145  900
     public static final ConfigurationKey KEY_SHOW_INITIAL_VALUE =
 146  
         Configuration.makeKey("notation", "show", "initialvalue");
 147  
 
 148  
     /**
 149  
      * Indicates if the user wants to see the properties (everything
 150  
      * between braces), that is for example the concurrency.
 151  
      */
 152  900
     public static final ConfigurationKey KEY_SHOW_PROPERTIES =
 153  
         Configuration.makeKey("notation", "show", "properties");
 154  
 
 155  
     /**
 156  
      * Indicates if the user wants to see the types and parameters
 157  
      * of attributes and operations.
 158  
      */
 159  900
     public static final ConfigurationKey KEY_SHOW_TYPES =
 160  
         Configuration.makeKey("notation", "show", "types");
 161  
 
 162  
 
 163  
     /**
 164  
      * The instance.
 165  
      */
 166  900
     private static final Notation SINGLETON = new Notation();
 167  
 
 168  
 
 169  
     /**
 170  
      * The constructor.
 171  
      * TODO: Why does this method not handle all settings?
 172  
      */
 173  900
     private Notation() {
 174  900
         Configuration.addListener(KEY_USE_GUILLEMOTS, this);
 175  900
         Configuration.addListener(KEY_DEFAULT_NOTATION, this);
 176  900
         Configuration.addListener(KEY_SHOW_TYPES, this);
 177  900
         Configuration.addListener(KEY_SHOW_MULTIPLICITY, this);
 178  900
         Configuration.addListener(KEY_SHOW_PROPERTIES, this);
 179  900
         Configuration.addListener(KEY_SHOW_ASSOCIATION_NAMES, this);
 180  900
         Configuration.addListener(KEY_SHOW_VISIBILITY, this);
 181  900
         Configuration.addListener(KEY_SHOW_INITIAL_VALUE, this);
 182  900
     }
 183  
 
 184  
     /**
 185  
      * @param n the NotationName that will become default
 186  
      */
 187  
     public static void setDefaultNotation(NotationName n) {
 188  0
         LOG.info("default notation set to " + n.getConfigurationValue());
 189  0
         Configuration.setString(
 190  
             KEY_DEFAULT_NOTATION,
 191  
             n.getConfigurationValue());
 192  0
     }
 193  
 
 194  
     /**
 195  
      * Convert a String into a NotationName.
 196  
      * @param s the String
 197  
      * @return the matching NotationName
 198  
      */
 199  
     public static NotationName findNotation(String s) {
 200  2912
         return NotationNameImpl.findNotation(s);
 201  
     }
 202  
 
 203  
     /**
 204  
      * Returns the Notation as set in the menu.
 205  
      *
 206  
      * @return the default NotationName
 207  
      */
 208  
     public static NotationName getConfiguredNotation() {
 209  993
         NotationName n =
 210  
             NotationNameImpl.findNotation(
 211  
                 Configuration.getString(
 212  
                     KEY_DEFAULT_NOTATION,
 213  
                     notationArgo.getConfigurationValue()));
 214  
         // This is needed for the case when the default notation is
 215  
         // not loaded at this point.
 216  993
         if (n == null) {
 217  0
             n = NotationNameImpl.findNotation(DEFAULT_NOTATION);
 218  
         }
 219  993
         LOG.debug("default notation is " + n.getConfigurationValue());
 220  993
         return n;
 221  
     }
 222  
 
 223  
     ////////////////////////////////////////////////////////////////
 224  
     // class accessors
 225  
 
 226  
     ////////////////////////////////////////////////////////////////
 227  
     // static accessors
 228  
 
 229  
     /**
 230  
      * @return the singleton
 231  
      */
 232  
     public static Notation getInstance() {
 233  0
         return SINGLETON;
 234  
     }
 235  
 
 236  
     /*
 237  
      * Called after the notation default property gets changed.
 238  
      *
 239  
      * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
 240  
      */
 241  
     public void propertyChange(PropertyChangeEvent pce) {
 242  0
         LOG.info(
 243  
             "Notation change:"
 244  
                 + pce.getOldValue()
 245  
                 + " to "
 246  
                 + pce.getNewValue());
 247  0
         ArgoEventPump.fireEvent(
 248  
             new ArgoNotationEvent(ArgoEventTypes.NOTATION_CHANGED, pce));
 249  0
     }
 250  
 
 251  
     ////////////////////////////////////////////////////////////////
 252  
     // Static workers for dealing with notation names.
 253  
 
 254  
     /**
 255  
      * Get list of available notations, of type NotationName.
 256  
      * This returns an immutable list so that
 257  
      * the implementation type isn't exposed in the API.
 258  
      *
 259  
      * @return list of available notations
 260  
      */
 261  
     public static List<NotationName> getAvailableNotations() {
 262  143
         return NotationNameImpl.getAvailableNotations();
 263  
     }
 264  
 
 265  
     /**
 266  
      * Remove a complete Notation language.
 267  
      * This is to be used by plug-ins that implement their own notation,
 268  
      * and that are removed. <p>
 269  
      * This function fails if the given notation does not exist.
 270  
      *
 271  
      * @param theNotation the given NotationName
 272  
      * @return true if the Notation indeed is removed
 273  
      */
 274  
     public static boolean removeNotation(NotationName theNotation)  {
 275  0
         return NotationNameImpl.removeNotation(theNotation);
 276  
     }
 277  
 
 278  
     /**
 279  
      * Create a versioned notation name with an icon.
 280  
      *
 281  
      * @param k1 the name (e.g. UML)
 282  
      * @param k2 the version (e.g. 1.3)
 283  
      * @param icon the icon
 284  
      * @return the notation name
 285  
      */
 286  
     public static NotationName makeNotation(String k1, String k2, Icon icon) {
 287  2700
         NotationName nn = NotationNameImpl.makeNotation(k1, k2, icon);
 288  2700
         return nn;
 289  
     }
 290  
 }