svn commit: r16374 - trunk/src/argouml-app: src/org/argouml/notation tests/org/argouml/notation
Tom Morris <[email protected]>
| Newsgroups | gmane.comp.lang.uml.argouml.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: tfmorris
Date: 2008-12-18 14:50:44-0800
New Revision: 16374
Added:
trunk/src/argouml-app/tests/org/argouml/notation/TestNotationSettings.java (contents, props changed)
Modified:
trunk/src/argouml-app/src/org/argouml/notation/NotationSettings.java
Log:
More complete NotationSettings and associated tests
Modified: trunk/src/argouml-app/src/org/argouml/notation/NotationSettings.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/notation/NotationSettings.java?view=diff&pathrev=16374&r1=16373&r2=16374
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/notation/NotationSettings.java (original)
+++ trunk/src/argouml-app/src/org/argouml/notation/NotationSettings.java 2008-12-18 14:50:44-0800
@@ -24,6 +24,8 @@
package org.argouml.notation;
+import org.tigris.gef.undo.Memento;
+
/**
* Notation settings value object. Stores settings which control how text is
* rendered on diagrams.
@@ -41,18 +43,24 @@
// need a link to the parent, but not clear this is needed right now
// private NotationSettings parent;
- private boolean showAssociationName;
+ private String notationLanguage;
- private boolean showVisibility;
+ private boolean showAssociationNames;
- private boolean showPath;
+ private boolean showVisibilities;
- private boolean fullyHandleStereotypes;
+ private boolean showPaths;
- private boolean showSingularMultiplicities;
+ private boolean fullyHandleStereotypes;
+
+ private boolean showStereotypes = true;
private boolean useGuillemets;
+ private boolean showMultiplicities;
+
+ private boolean showSingularMultiplicities;
+
// TODO: Do we need to control separately for attributes and operations?
private boolean showTypes;
@@ -60,7 +68,7 @@
private boolean showInitialValues;
- private boolean showMultiplicities;
+
/**
* @return the default settings
@@ -70,47 +78,56 @@
}
/**
- * @return Returns the showAssociationName.
- */
- public boolean isShowAssociationName() {
- return showAssociationName;
- }
-
- /**
- * @param showAssociationName The showAssociationName to set.
- */
- public void setShowAssociationName(boolean showAssociationName) {
- this.showAssociationName = showAssociationName;
- }
-
- /**
- * @return Returns the showVisibility.
- */
- public boolean isShowVisibility() {
- return showVisibility;
- }
-
- /**
- * @param showVisibility The showVisibility to set.
+ * @return Return the notation language.
*/
- public void setShowVisibility(boolean showVisibility) {
- this.showVisibility = showVisibility;
+ public String getNotationLanguage() {
+ if (notationLanguage == null) {
+// if (parent != null) {
+// return parent.getNotationLanguage();
+// } else {
+ return "UML 1.4";
+// }
+ }
+ return notationLanguage;
}
- /**
- * @return Returns the showPath.
- */
- public boolean isShowPath() {
- return showPath;
- }
/**
- * @param showPath The showPath to set.
- */
- public void setShowPath(boolean showPath) {
- this.showPath = showPath;
+ * @param newLanguage the notation language.
+ * @return true if the notation is set - false if it does not exist
+ */
+ public boolean setNotationLanguage(final String newLanguage) {
+ if (notationLanguage != null
+ && notationLanguage.equals(newLanguage)) {
+ return true;
+ }
+
+ // TODO: Do we care?
+ if (Notation.findNotation(newLanguage) == null) {
+ /* This Notation is not available! */
+ return false;
+ }
+
+ final String oldLanguage = notationLanguage;
+
+ Memento memento = new Memento() {
+ public void redo() {
+ notationLanguage = newLanguage;
+ // TODO: We can't have a global "current" language
+ // NotationProviderFactory2.setCurrentLanguage(newLanguage);
+ }
+
+ public void undo() {
+ notationLanguage = oldLanguage;
+ // TODO: We can't have a global "current" language
+ // NotationProviderFactory2.setCurrentLanguage(oldLanguage);
+ }
+ };
+ doUndoable(memento);
+ return true;
}
+
/**
* @return Returns the fullyHandleStereotypes.
*/
@@ -133,10 +150,23 @@
}
/**
- * @param showSingularMultiplicities The showSingularMultiplicities to set.
+ * @param showem <code>true</code> if "1" Multiplicities are to be shown.
*/
- public void setShowSingularMultiplicities(boolean showSingularMultiplicities) {
- this.showSingularMultiplicities = showSingularMultiplicities;
+ public void setShowSingularMultiplicities(final boolean showem) {
+ if (showSingularMultiplicities == showem) {
+ return;
+ }
+
+ Memento memento = new Memento() {
+ public void redo() {
+ showSingularMultiplicities = showem;
+ }
+
+ public void undo() {
+ showSingularMultiplicities = !showem;
+ }
+ };
+ doUndoable(memento);
}
/**
@@ -147,10 +177,23 @@
}
/**
- * @param useGuillemets The useGuillemets to set.
+ * @param showem <code>true</code> if guillemets are to be shown.
*/
- public void setUseGuillemets(boolean useGuillemets) {
- this.useGuillemets = useGuillemets;
+ public void setUseGuillemets(final boolean showem) {
+ if (useGuillemets == showem) {
+ return;
+ }
+
+ Memento memento = new Memento() {
+ public void redo() {
+ useGuillemets = showem;
+ }
+
+ public void undo() {
+ useGuillemets = !showem;
+ }
+ };
+ doUndoable(memento);
}
/**
@@ -160,11 +203,26 @@
return showTypes;
}
+
/**
- * @param showTypes The showTypes to set.
+ * @param showem <code>true</code> if types are to be shown.
*/
- public void setShowTypes(boolean showTypes) {
- this.showTypes = showTypes;
+ public void setShowTypes(final boolean showem) {
+ if (showTypes == showem) {
+ return;
+ }
+
+ Memento memento = new Memento() {
+ public void redo() {
+ showTypes = showem;
+ }
+
+ public void undo() {
+ showTypes = !showem;
+ }
+ };
+ doUndoable(memento);
+
}
/**
@@ -175,10 +233,24 @@
}
/**
- * @param showProperties The showProperties to set.
+ * @param showem <code>true</code> if properties are to be shown.
*/
- public void setShowProperties(boolean showProperties) {
- this.showProperties = showProperties;
+ public void setShowProperties(final boolean showem) {
+ if (showProperties == showem) {
+ return;
+ }
+
+ Memento memento = new Memento() {
+ public void redo() {
+ showProperties = showem;
+ }
+
+ public void undo() {
+ showProperties = !showem;
+ }
+ };
+ doUndoable(memento);
+
}
/**
@@ -188,11 +260,26 @@
return showInitialValues;
}
+
/**
- * @param showInitialValues The showInitialValues to set.
+ * @param showem <code>true</code> if initial values are to be shown.
*/
- public void setShowInitialValues(boolean showInitialValues) {
- this.showInitialValues = showInitialValues;
+ public void setShowInitialValues(final boolean showem) {
+ if (showInitialValues == showem) {
+ return;
+ }
+
+ Memento memento = new Memento() {
+ public void redo() {
+ showInitialValues = showem;
+ }
+
+ public void undo() {
+ showInitialValues = !showem;
+ }
+ };
+ doUndoable(memento);
+
}
/**
@@ -203,10 +290,137 @@
}
/**
- * @param showMultiplicities The showMultiplicities to set.
+ * @param showem <code>true</code> if the multiplicity is to be shown.
*/
- public void setShowMultiplicities(boolean showMultiplicities) {
- this.showMultiplicities = showMultiplicities;
+ public void setShowMultiplicities(final boolean showem) {
+ if (showMultiplicities == showem) {
+ return;
+ }
+
+ Memento memento = new Memento() {
+ public void redo() {
+ showMultiplicities = showem;
+ }
+
+ public void undo() {
+ showMultiplicities = !showem;
+ }
+ };
+ doUndoable(memento);
+ }
+
+
+
+ /**
+ * @return Returns the showAssociationNames.
+ */
+ public boolean isShowAssociationNames() {
+ return showAssociationNames;
}
+
+ /**
+ * @param showem <code>true</code> if association names are to be shown.
+ */
+ public void setShowAssociationNames(final boolean showem) {
+ if (showAssociationNames == showem) {
+ return;
+ }
+
+ Memento memento = new Memento() {
+
+ public void redo() {
+ showAssociationNames = showem;
+ }
+
+ public void undo() {
+ showAssociationNames = !showem;
+ }
+ };
+ doUndoable(memento);
+ }
+
+ /**
+ * @return Returns the showVisibilities.
+ */
+ public boolean isShowVisibilities() {
+ return showVisibilities;
+ }
+
+
+ /**
+ * @param showem <code>true</code> if visibilities are to be shown.
+ */
+ public void setShowVisibilities(final boolean showem) {
+ if (showVisibilities == showem) {
+ return;
+ }
+
+ Memento memento = new Memento() {
+ public void redo() {
+ showVisibilities = showem;
+ }
+
+ public void undo() {
+ showVisibilities = !showem;
+ }
+ };
+ doUndoable(memento);
+ }
+
+ /**
+ * @return Returns the showPaths.
+ */
+ public boolean isShowPaths() {
+ return showPaths;
+ }
+
+
+ /**
+ * @param showPaths The showPaths to set.
+ */
+ public void setShowPaths(boolean showPaths) {
+ this.showPaths = showPaths;
+ }
+
+
+ /**
+ * @return Returns the showStereotypes.
+ */
+ public boolean isShowStereotypes() {
+ return showStereotypes;
+ }
+
+
+ /**
+ * @param showem <code>true</code> if stereotypes are to be shown.
+ */
+ public void setShowStereotypes(final boolean showem) {
+ if (showStereotypes == showem) {
+ return;
+ }
+
+ Memento memento = new Memento() {
+ public void redo() {
+ showStereotypes = showem;
+ }
+
+ public void undo() {
+ showStereotypes = !showem;
+ }
+ };
+ doUndoable(memento);
+
+ }
+
+ private void doUndoable(Memento memento) {
+ // TODO: Undo should be managed externally or we should be given
+ // an Undo manager to use (the project's) rather than using a global one
+// if (DiagramUndoManager.getInstance().isGenerateMementos()) {
+// DiagramUndoManager.getInstance().addMemento(memento);
+// }
+ memento.redo();
+ // TODO: Mark diagram/project as dirty?
+ }
+
}
Added: trunk/src/argouml-app/tests/org/argouml/notation/TestNotationSettings.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/notation/TestNotationSettings.java?view=markup&pathrev=16374
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/tests/org/argouml/notation/TestNotationSettings.java 2008-12-18 14:50:44-0800
@@ -0,0 +1,209 @@
+// $Id$
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.notation;
+
+import junit.framework.TestCase;
+
+public class TestNotationSettings extends TestCase {
+
+ private NotationSettings settings;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ settings = new NotationSettings();
+ }
+
+ public void testNotationLanguage() {
+ assertEquals("NotationLanguage default is not correct",
+ "UML 1.4",
+ settings.getNotationLanguage());
+ // The following should fail
+ assertFalse(settings.setNotationLanguage("foo"));
+ // and leave things unchanged
+ assertEquals("UML 1.4", settings.getNotationLanguage());
+ // This one should work except Java is not registered by default
+// assertTrue(settings.setNotationLanguage("Java"));
+// assertEquals("Java", settings.getNotationLanguage());
+ }
+
+ /**
+ * Test that default settings are available.
+ */
+ public void testGetDefaultSettings() {
+ assertNotNull(NotationSettings.getDefaultSettings());
+ }
+
+
+ public void testShowPath() {
+ assertFalse("Path is not correct", settings.isShowPaths());
+ settings.setShowPaths(true);
+ assertTrue("Path is not correct", settings.isShowPaths());
+ settings.setShowPaths(false);
+ assertFalse("Path is not correct", settings.isShowPaths());
+ }
+
+
+ public void testFullyHandleStereotypes() {
+ assertFalse("FullyHandleStereotypes is not correct",
+ settings.isFullyHandleStereotypes());
+ settings.setFullyHandleStereotypes(true);
+ assertTrue("FullyHandleStereotypes is not correct",
+ settings.isFullyHandleStereotypes());
+ settings.setFullyHandleStereotypes(false);
+ assertFalse("FullyHandleStereotypes is not correct",
+ settings.isFullyHandleStereotypes());
+ }
+
+
+ /**
+ * Test the project setting for showing Association names.
+ */
+ public void testAssociationNames() {
+ assertFalse("Association names not correct",
+ settings.isShowAssociationNames());
+ settings.setShowAssociationNames(true);
+ assertTrue("Association names not correct",
+ settings.isShowAssociationNames());
+ settings.setShowAssociationNames(false);
+ assertFalse("Association names not correct",
+ settings.isShowAssociationNames());
+ }
+
+
+ public void testShowInitialValues() {
+ assertFalse("InitialValue is not correct",
+ settings.isShowInitialValues());
+ settings.setShowInitialValues(true);
+ assertTrue("InitialValue is not correct",
+ settings.isShowInitialValues());
+ settings.setShowInitialValues(false);
+ assertFalse("InitialValue is not correct",
+ settings.isShowInitialValues());
+
+ }
+
+ public void testShowProperties() {
+ assertFalse("Properties is not correct",
+ settings.isShowProperties());
+ settings.setShowProperties(true);
+ assertTrue("Properties is not correct",
+ settings.isShowProperties());
+ settings.setShowProperties(false);
+ assertFalse("Properties is not correct",
+ settings.isShowProperties());
+ }
+
+ public void testShowMultiplicities() {
+ assertFalse("Multiplicities is not correct",
+ settings.isShowMultiplicities());
+ settings.setShowMultiplicities(true);
+ assertTrue("Multiplicities is not correct",
+ settings.isShowMultiplicities());
+ settings.setShowMultiplicities(false);
+ assertFalse("Multiplicities is not correct",
+ settings.isShowMultiplicities());
+
+ }
+
+ public void testSingularMultiplicities() {
+ assertFalse("ShowSingularMultiplicities is not correct",
+ settings.isShowSingularMultiplicities());
+ settings.setShowSingularMultiplicities(true);
+ assertTrue("ShowSingularMultiplicities is not correct",
+ settings.isShowSingularMultiplicities());
+ settings.setShowSingularMultiplicities(false);
+ assertFalse("SingularMultiplicities is not correct",
+ settings.isShowSingularMultiplicities());
+ }
+
+ public void testShowStereotypes() {
+ assertTrue("Stereotypes is not correct",
+ settings.isShowStereotypes());
+ settings.setShowStereotypes(true);
+ assertTrue("Stereotypes is not correct",
+ settings.isShowStereotypes());
+ settings.setShowStereotypes(false);
+ assertFalse("Stereotypes is not correct",
+ settings.isShowStereotypes());
+
+ }
+
+ public void testShowTypes() {
+ assertFalse("Types is not correct", settings.isShowTypes());
+ settings.setShowTypes(true);
+ assertTrue("Types is not correct", settings.isShowTypes());
+ settings.setShowTypes(false);
+ assertFalse("Types is not correct", settings.isShowTypes());
+ }
+
+ /**
+ * Test the project setting for showing Multiplicities.
+ */
+ public void testMultiplicities() {
+ assertFalse("Multiplicities not correct",
+ settings.isShowMultiplicities());
+
+ settings.setShowMultiplicities(true);
+ assertTrue("Multiplicities not correct",
+ settings.isShowMultiplicities());
+
+ settings.setShowMultiplicities(false);
+ assertFalse("Multiplicities not correct",
+ settings.isShowMultiplicities());
+
+ }
+
+ /**
+ * Test the project setting for showing Visibility.
+ */
+ public void testVisibilities() {
+ assertFalse("Visibility not correct",
+ settings.isShowVisibilities());
+
+ settings.setShowVisibilities(true);
+ assertTrue("Visibility not correct",
+ settings.isShowVisibilities());
+
+ settings.setShowVisibilities(false);
+ assertFalse("Visibility not correct",
+ settings.isShowVisibilities());
+ }
+
+ /**
+ * Test the use of Guillemets.
+ */
+ public void testUseGuillemets() {
+ assertFalse("Guillemots not correct",
+ settings.isUseGuillemets());
+ settings.setUseGuillemets(true);
+ assertTrue("Guillemots not correct",
+ settings.isUseGuillemets());
+ settings.setUseGuillemets(false);
+ assertFalse("Guillemots not correct",
+ settings.isUseGuillemets());
+ }
+
+
+}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=987022
To unsubscribe from this discussion, e-mail: [[email protected]].