Author: tfmorris
Date: 2008-07-01 00:28:53-0700
New Revision: 15135
Modified:
trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustGrid.java (contents, props changed)
trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustSnap.java (contents, props changed)
Log:
Make constructor public. Set SVN properties.
Modified: trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustGrid.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustGrid.java?view=diff&rev=15135&p1=trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustGrid.java&p2=trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustGrid.java&r1=15134&r2=15135
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustGrid.java (original)
+++ trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustGrid.java 2008-07-01 00:28:53-0700
@@ -1,176 +1,176 @@
-// $Id: eclipse-argo-codetemplates.xml 10612 2006-05-25 12:58:04Z linus $
-// Copyright (c) 2006-2007 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.ui.cmd;
-
-import java.awt.Toolkit;
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.AbstractAction;
-import javax.swing.AbstractButton;
-import javax.swing.Action;
-import javax.swing.ButtonGroup;
-import javax.swing.KeyStroke;
-
-import org.argouml.application.api.Argo;
-import org.argouml.configuration.Configuration;
-import org.argouml.i18n.Translator;
-import org.tigris.gef.base.Editor;
-import org.tigris.gef.base.Globals;
-import org.tigris.gef.base.Layer;
-import org.tigris.gef.base.LayerGrid;
-
-
-/**
- * This action changes the grid shown on the diagram.
- *
- * @author Michiel
- */
-public class ActionAdjustGrid extends AbstractAction {
-
- private final Map<String, Comparable> myMap;
- private static final String DEFAULT_ID = "03";
- private static ButtonGroup myGroup;
-
- private static final int DEFAULT_MASK =
- Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
-
- /**
- * @param map this map contains the values for
- * the spacing, paintLines and paintDots.
- * @param name the name for this action
- */
- private ActionAdjustGrid(final Map<String, Comparable> map,
- final String name) {
- super();
- myMap = map;
- putValue(Action.NAME, name);
- }
-
- public void actionPerformed(final ActionEvent e) {
- final Editor editor = Globals.curEditor();
- final Layer grid = editor.getLayerManager().findLayerNamed("Grid");
- if (grid instanceof LayerGrid) {
- if (myMap != null) {
- // Kludge required by GEF's use of HashMap in the API
- // TODO: This can be removed if they ever fix GEF to use Maps
- if (myMap instanceof HashMap) {
- grid.adjust((HashMap<String, Comparable>) myMap);
- } else {
- grid.adjust(new HashMap<String, Comparable>(myMap));
- }
- Configuration.setString(Argo.KEY_GRID, (String) getValue("ID"));
- }
- }
- }
-
- static void setGroup(final ButtonGroup group) {
- myGroup = group;
- }
-
- /**
- * This executes one of the actions,
- * based on the stored ArgoUML configuration.
- * This function is intended for the initial setting
- * of the grid when ArgoUML is started. <p>
- *
- * Additionally, the ButtonGroup is searched for the right Action,
- * and when found, the button's model initialised.
- */
- static void init() {
- String id = Configuration.getString(Argo.KEY_GRID, DEFAULT_ID);
- List<Action> actions = createAdjustGridActions(false);
- for (Action a : actions) {
- if (a.getValue("ID").equals(id)) {
- a.actionPerformed(null);
-
- if (myGroup != null) {
- for (Enumeration e = myGroup.getElements();
- e.hasMoreElements();) {
- AbstractButton ab = (AbstractButton) e.nextElement();
- Action action = ab.getAction();
- if (action instanceof ActionAdjustGrid) {
- String currentID = (String) action.getValue("ID");
- if (id.equals(currentID)) {
- myGroup.setSelected(ab.getModel(), true);
- return;
- }
- }
- }
- }
- return;
- }
- }
- }
-
- /**
- * This function is the one and only location
- * that defines the number of grid settings, and their content.
- *
- * @constraint one of the actions should have the ID 'defaultID',
- * since this is used in init().
- * @param longStrings
- * @return List of Actions which adjust the grid
- */
- static List<Action> createAdjustGridActions(final boolean longStrings) {
- List<Action> result = new ArrayList<Action>();
-
- result.add(buildGridAction(longStrings ? "action.adjust-grid.lines-16"
- : "menu.item.lines-16", 16, true, true, "01", KeyEvent.VK_1));
- result.add(buildGridAction(longStrings ? "action.adjust-grid.lines-8"
- : "menu.item.lines-8", 8, true, true, "02", KeyEvent.VK_2));
- result.add(buildGridAction(longStrings ? "action.adjust-grid.lines-16"
- : "menu.item.lines-16", 16, false, true, "03", KeyEvent.VK_3));
- result.add(buildGridAction(longStrings ? "action.adjust-grid.lines-32"
- : "menu.item.lines-32", 32, false, true, "04", KeyEvent.VK_4));
- result.add(buildGridAction(
- longStrings ? "action.adjust-grid.lines-none"
- : "menu.item.lines-none", 16, false, false, "05",
- KeyEvent.VK_5));
-
- return result;
- }
-
- private static Action buildGridAction(final String property,
- final int spacing, final boolean paintLines,
- final boolean paintDots, final String id, final int key) {
- String name = Translator.localize(property);
- HashMap<String, Comparable> map1 = new HashMap<String, Comparable>(4);
- map1.put("spacing", Integer.valueOf(spacing));
- map1.put("paintLines", Boolean.valueOf(paintLines));
- map1.put("paintDots", Boolean.valueOf(paintDots));
- Action action = new ActionAdjustGrid(map1, name);
- action.putValue("ID", id);
- action.putValue("shortcut", KeyStroke.getKeyStroke(
- key, DEFAULT_MASK));
- return action;
- }
-
+// $Id$
+// Copyright (c) 2006-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.ui.cmd;
+
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+import javax.swing.ButtonGroup;
+import javax.swing.KeyStroke;
+
+import org.argouml.application.api.Argo;
+import org.argouml.configuration.Configuration;
+import org.argouml.i18n.Translator;
+import org.tigris.gef.base.Editor;
+import org.tigris.gef.base.Globals;
+import org.tigris.gef.base.Layer;
+import org.tigris.gef.base.LayerGrid;
+
+
+/**
+ * This action changes the grid shown on the diagram.
+ *
+ * @author Michiel
+ */
+public class ActionAdjustGrid extends AbstractAction {
+
+ private final Map<String, Comparable> myMap;
+ private static final String DEFAULT_ID = "03";
+ private static ButtonGroup myGroup;
+
+ private static final int DEFAULT_MASK =
+ Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+
+ /**
+ * @param map this map contains the values for
+ * the spacing, paintLines and paintDots.
+ * @param name the name for this action
+ */
+ private ActionAdjustGrid(final Map<String, Comparable> map,
+ final String name) {
+ super();
+ myMap = map;
+ putValue(Action.NAME, name);
+ }
+
+ public void actionPerformed(final ActionEvent e) {
+ final Editor editor = Globals.curEditor();
+ final Layer grid = editor.getLayerManager().findLayerNamed("Grid");
+ if (grid instanceof LayerGrid) {
+ if (myMap != null) {
+ // Kludge required by GEF's use of HashMap in the API
+ // TODO: This can be removed if they ever fix GEF to use Maps
+ if (myMap instanceof HashMap) {
+ grid.adjust((HashMap<String, Comparable>) myMap);
+ } else {
+ grid.adjust(new HashMap<String, Comparable>(myMap));
+ }
+ Configuration.setString(Argo.KEY_GRID, (String) getValue("ID"));
+ }
+ }
+ }
+
+ static void setGroup(final ButtonGroup group) {
+ myGroup = group;
+ }
+
+ /**
+ * This executes one of the actions,
+ * based on the stored ArgoUML configuration.
+ * This function is intended for the initial setting
+ * of the grid when ArgoUML is started. <p>
+ *
+ * Additionally, the ButtonGroup is searched for the right Action,
+ * and when found, the button's model initialised.
+ */
+ static void init() {
+ String id = Configuration.getString(Argo.KEY_GRID, DEFAULT_ID);
+ List<Action> actions = createAdjustGridActions(false);
+ for (Action a : actions) {
+ if (a.getValue("ID").equals(id)) {
+ a.actionPerformed(null);
+
+ if (myGroup != null) {
+ for (Enumeration e = myGroup.getElements();
+ e.hasMoreElements();) {
+ AbstractButton ab = (AbstractButton) e.nextElement();
+ Action action = ab.getAction();
+ if (action instanceof ActionAdjustGrid) {
+ String currentID = (String) action.getValue("ID");
+ if (id.equals(currentID)) {
+ myGroup.setSelected(ab.getModel(), true);
+ return;
+ }
+ }
+ }
+ }
+ return;
+ }
+ }
+ }
+
+ /**
+ * This function is the one and only location
+ * that defines the number of grid settings, and their content.
+ *
+ * @constraint one of the actions should have the ID 'defaultID',
+ * since this is used in init().
+ * @param longStrings
+ * @return List of Actions which adjust the grid
+ */
+ static List<Action> createAdjustGridActions(final boolean longStrings) {
+ List<Action> result = new ArrayList<Action>();
+
+ result.add(buildGridAction(longStrings ? "action.adjust-grid.lines-16"
+ : "menu.item.lines-16", 16, true, true, "01", KeyEvent.VK_1));
+ result.add(buildGridAction(longStrings ? "action.adjust-grid.lines-8"
+ : "menu.item.lines-8", 8, true, true, "02", KeyEvent.VK_2));
+ result.add(buildGridAction(longStrings ? "action.adjust-grid.lines-16"
+ : "menu.item.lines-16", 16, false, true, "03", KeyEvent.VK_3));
+ result.add(buildGridAction(longStrings ? "action.adjust-grid.lines-32"
+ : "menu.item.lines-32", 32, false, true, "04", KeyEvent.VK_4));
+ result.add(buildGridAction(
+ longStrings ? "action.adjust-grid.lines-none"
+ : "menu.item.lines-none", 16, false, false, "05",
+ KeyEvent.VK_5));
+
+ return result;
+ }
+
+ public static Action buildGridAction(final String property,
+ final int spacing, final boolean paintLines,
+ final boolean paintDots, final String id, final int key) {
+ String name = Translator.localize(property);
+ HashMap<String, Comparable> map1 = new HashMap<String, Comparable>(4);
+ map1.put("spacing", Integer.valueOf(spacing));
+ map1.put("paintLines", Boolean.valueOf(paintLines));
+ map1.put("paintDots", Boolean.valueOf(paintDots));
+ Action action = new ActionAdjustGrid(map1, name);
+ action.putValue("ID", id);
+ action.putValue("shortcut", KeyStroke.getKeyStroke(
+ key, DEFAULT_MASK));
+ return action;
+ }
+
}
\ No newline at end of file
Modified: trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustSnap.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustSnap.java?view=diff&rev=15135&p1=trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustSnap.java&p2=trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustSnap.java&r1=15134&r2=15135
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustSnap.java (original)
+++ trunk/src/argouml-app/src/org/argouml/ui/cmd/ActionAdjustSnap.java 2008-07-01 00:28:53-0700
@@ -1,156 +1,156 @@
-// $Id: eclipse-argo-codetemplates.xml 10612 2006-05-25 12:58:04Z linus $
-// Copyright (c) 2006-2007 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.ui.cmd;
-
-import java.awt.Event;
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-
-import javax.swing.AbstractAction;
-import javax.swing.AbstractButton;
-import javax.swing.Action;
-import javax.swing.ButtonGroup;
-import javax.swing.KeyStroke;
-
-import org.argouml.application.api.Argo;
-import org.argouml.configuration.Configuration;
-import org.argouml.i18n.Translator;
-import org.tigris.gef.base.Editor;
-import org.tigris.gef.base.Globals;
-import org.tigris.gef.base.Guide;
-import org.tigris.gef.base.GuideGrid;
-
-/**
- * This action changes the snap (called guide or grid-guide in GEF).
- *
- * @author Michiel
- */
-public class ActionAdjustSnap extends AbstractAction {
-
- private int guideSize;
- private static final String DEFAULT_ID = "8";
- private static ButtonGroup myGroup;
-
- /**
- * @param size the size of the snap in pixels
- * @param name the name of the action
- */
- private ActionAdjustSnap(int size, String name) {
- super();
- guideSize = size;
- putValue(Action.NAME, name);
- }
-
- public void actionPerformed(ActionEvent e) {
- Editor ce = Globals.curEditor();
- Guide guide = ce.getGuide();
- if (guide instanceof GuideGrid) {
- ((GuideGrid) guide).gridSize(guideSize);
- Configuration.setString(Argo.KEY_SNAP, (String) getValue("ID"));
- }
- }
-
- static void setGroup(ButtonGroup group) {
- myGroup = group;
- }
-
- /**
- * This executes one of the actions,
- * based on the stored ArgoUML configuration.
- * This function is intended for the initial setting
- * of the snap when ArgoUML is started.
- */
- static void init() {
- String id = Configuration.getString(Argo.KEY_SNAP, DEFAULT_ID);
- List<Action> actions = createAdjustSnapActions();
- for (Action a : actions) {
- if (a.getValue("ID").equals(id)) {
- a.actionPerformed(null);
-
- if (myGroup != null) {
- for (Enumeration e = myGroup.getElements();
- e.hasMoreElements();) {
- AbstractButton ab = (AbstractButton) e.nextElement();
- Action action = ab.getAction();
- if (action instanceof ActionAdjustSnap) {
- String currentID = (String) action.getValue("ID");
- if (id.equals(currentID)) {
- myGroup.setSelected(ab.getModel(), true);
- return;
- }
- }
- }
- }
- return;
- }
- }
- }
-
- /**
- * Return a list of actions to adjust the size of the snap grid.
- * Current values are 4, 8, 16, and 32.
- *
- * @return List of Actions which adjust the size of the snap grid
- */
- static List<Action> createAdjustSnapActions() {
- List<Action> result = new ArrayList<Action>();
- Action a;
- String name;
-
- name = Translator.localize("menu.item.snap-4");
- a = new ActionAdjustSnap(4, name);
- a.putValue("ID", "4");
- a.putValue("shortcut", KeyStroke.getKeyStroke(
- KeyEvent.VK_1, Event.ALT_MASK + Event.CTRL_MASK));
- result.add(a);
-
- name = Translator.localize("menu.item.snap-8");
- a = new ActionAdjustSnap(8, name);
- a.putValue("ID", "8"); /* This ID is used as DEFAULT_ID ! */
- a.putValue("shortcut", KeyStroke.getKeyStroke(
- KeyEvent.VK_2, Event.ALT_MASK + Event.CTRL_MASK));
- result.add(a);
-
- name = Translator.localize("menu.item.snap-16");
- a = new ActionAdjustSnap(16, name);
- a.putValue("ID", "16");
- a.putValue("shortcut", KeyStroke.getKeyStroke(
- KeyEvent.VK_3, Event.ALT_MASK + Event.CTRL_MASK));
- result.add(a);
-
- name = Translator.localize("menu.item.snap-32");
- a = new ActionAdjustSnap(32, name);
- a.putValue("ID", "32");
- a.putValue("shortcut", KeyStroke.getKeyStroke(
- KeyEvent.VK_4, Event.ALT_MASK + Event.CTRL_MASK));
- result.add(a);
-
- return result;
- }
-
-}
+// $Id$
+// Copyright (c) 2006-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.ui.cmd;
+
+import java.awt.Event;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+import javax.swing.ButtonGroup;
+import javax.swing.KeyStroke;
+
+import org.argouml.application.api.Argo;
+import org.argouml.configuration.Configuration;
+import org.argouml.i18n.Translator;
+import org.tigris.gef.base.Editor;
+import org.tigris.gef.base.Globals;
+import org.tigris.gef.base.Guide;
+import org.tigris.gef.base.GuideGrid;
+
+/**
+ * This action changes the snap (called guide or grid-guide in GEF).
+ *
+ * @author Michiel
+ */
+public class ActionAdjustSnap extends AbstractAction {
+
+ private int guideSize;
+ private static final String DEFAULT_ID = "8";
+ private static ButtonGroup myGroup;
+
+ /**
+ * @param size the size of the snap in pixels
+ * @param name the name of the action
+ */
+ public ActionAdjustSnap(int size, String name) {
+ super();
+ guideSize = size;
+ putValue(Action.NAME, name);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ Editor ce = Globals.curEditor();
+ Guide guide = ce.getGuide();
+ if (guide instanceof GuideGrid) {
+ ((GuideGrid) guide).gridSize(guideSize);
+ Configuration.setString(Argo.KEY_SNAP, (String) getValue("ID"));
+ }
+ }
+
+ static void setGroup(ButtonGroup group) {
+ myGroup = group;
+ }
+
+ /**
+ * This executes one of the actions,
+ * based on the stored ArgoUML configuration.
+ * This function is intended for the initial setting
+ * of the snap when ArgoUML is started.
+ */
+ static void init() {
+ String id = Configuration.getString(Argo.KEY_SNAP, DEFAULT_ID);
+ List<Action> actions = createAdjustSnapActions();
+ for (Action a : actions) {
+ if (a.getValue("ID").equals(id)) {
+ a.actionPerformed(null);
+
+ if (myGroup != null) {
+ for (Enumeration e = myGroup.getElements();
+ e.hasMoreElements();) {
+ AbstractButton ab = (AbstractButton) e.nextElement();
+ Action action = ab.getAction();
+ if (action instanceof ActionAdjustSnap) {
+ String currentID = (String) action.getValue("ID");
+ if (id.equals(currentID)) {
+ myGroup.setSelected(ab.getModel(), true);
+ return;
+ }
+ }
+ }
+ }
+ return;
+ }
+ }
+ }
+
+ /**
+ * Return a list of actions to adjust the size of the snap grid.
+ * Current values are 4, 8, 16, and 32.
+ *
+ * @return List of Actions which adjust the size of the snap grid
+ */
+ static List<Action> createAdjustSnapActions() {
+ List<Action> result = new ArrayList<Action>();
+ Action a;
+ String name;
+
+ name = Translator.localize("menu.item.snap-4");
+ a = new ActionAdjustSnap(4, name);
+ a.putValue("ID", "4");
+ a.putValue("shortcut", KeyStroke.getKeyStroke(
+ KeyEvent.VK_1, Event.ALT_MASK + Event.CTRL_MASK));
+ result.add(a);
+
+ name = Translator.localize("menu.item.snap-8");
+ a = new ActionAdjustSnap(8, name);
+ a.putValue("ID", "8"); /* This ID is used as DEFAULT_ID ! */
+ a.putValue("shortcut", KeyStroke.getKeyStroke(
+ KeyEvent.VK_2, Event.ALT_MASK + Event.CTRL_MASK));
+ result.add(a);
+
+ name = Translator.localize("menu.item.snap-16");
+ a = new ActionAdjustSnap(16, name);
+ a.putValue("ID", "16");
+ a.putValue("shortcut", KeyStroke.getKeyStroke(
+ KeyEvent.VK_3, Event.ALT_MASK + Event.CTRL_MASK));
+ result.add(a);
+
+ name = Translator.localize("menu.item.snap-32");
+ a = new ActionAdjustSnap(32, name);
+ a.putValue("ID", "32");
+ a.putValue("shortcut", KeyStroke.getKeyStroke(
+ KeyEvent.VK_4, Event.ALT_MASK + Event.CTRL_MASK));
+ result.add(a);
+
+ return result;
+ }
+
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.