| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ActionSetMode |
|
| 1.0833333333333333;1.083 |
| 1 | /* $Id: ActionSetMode.java 17865 2010-01-12 20:45:26Z 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) 2003-2007 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.uml.diagram.ui; | |
| 40 | ||
| 41 | import java.util.Hashtable; | |
| 42 | import java.util.Properties; | |
| 43 | ||
| 44 | import javax.swing.Action; | |
| 45 | import javax.swing.ImageIcon; | |
| 46 | ||
| 47 | import org.apache.log4j.Logger; | |
| 48 | import org.argouml.application.helpers.ResourceLoaderWrapper; | |
| 49 | import org.argouml.i18n.Translator; | |
| 50 | import org.tigris.gef.base.SetModeAction; | |
| 51 | ||
| 52 | /** | |
| 53 | * Extends GEF ActionSetMode to add additional metadata such as tooltips. | |
| 54 | * | |
| 55 | * @author Jeremy Jones | |
| 56 | */ | |
| 57 | public class ActionSetMode extends SetModeAction { | |
| 58 | ||
| 59 | 900 | private static final Logger LOG = Logger.getLogger(ActionSetMode.class); |
| 60 | ||
| 61 | /** | |
| 62 | * The constructor. | |
| 63 | * | |
| 64 | * @param args arguments | |
| 65 | */ | |
| 66 | public ActionSetMode(Properties args) { | |
| 67 | 0 | super(args); |
| 68 | 0 | } |
| 69 | ||
| 70 | /** | |
| 71 | * The constructor. | |
| 72 | * | |
| 73 | * @param modeClass the next global editor mode | |
| 74 | */ | |
| 75 | public ActionSetMode(Class modeClass) { | |
| 76 | 0 | super(modeClass); |
| 77 | 0 | } |
| 78 | ||
| 79 | /** | |
| 80 | * The constructor. | |
| 81 | * | |
| 82 | * @param modeClass the next global editor mode | |
| 83 | * @param name the name of the icon | |
| 84 | */ | |
| 85 | public ActionSetMode(Class modeClass, String name) { | |
| 86 | 1819 | super(modeClass); |
| 87 | 1819 | putToolTip(name); |
| 88 | 1819 | putIcon(name); |
| 89 | 1819 | } |
| 90 | ||
| 91 | /** | |
| 92 | * The constructor. | |
| 93 | * | |
| 94 | * @param modeClass the next global editor mode | |
| 95 | * @param name the icon name | |
| 96 | * @param tooltipkey The key for the tooltip text. | |
| 97 | */ | |
| 98 | public ActionSetMode(Class modeClass, String name, String tooltipkey) { | |
| 99 | 7200 | super(modeClass, name); |
| 100 | 7200 | putToolTip(tooltipkey); |
| 101 | 7200 | putIcon(name); |
| 102 | 7200 | } |
| 103 | ||
| 104 | /** | |
| 105 | * The constructor. | |
| 106 | * | |
| 107 | * @param modeClass the next global editor mode | |
| 108 | * @param sticky the global sticky mode boolean allows the user | |
| 109 | * to place several nodes rapidly (in succession) | |
| 110 | */ | |
| 111 | public ActionSetMode(Class modeClass, boolean sticky) { | |
| 112 | 0 | super(modeClass, sticky); |
| 113 | 0 | } |
| 114 | ||
| 115 | /** | |
| 116 | * The constructor. | |
| 117 | * | |
| 118 | * @param modeClass the next global editor mode | |
| 119 | * @param modeArgs arguments for the new mode | |
| 120 | */ | |
| 121 | public ActionSetMode(Class modeClass, Hashtable modeArgs) { | |
| 122 | 0 | super(modeClass, modeArgs); |
| 123 | 0 | } |
| 124 | ||
| 125 | /** | |
| 126 | * The constructor. | |
| 127 | * TODO: The "name" parameter is used for the icon and for the tooltip. | |
| 128 | * This makes i18n of the tooltip impossible. | |
| 129 | * | |
| 130 | * @param modeClass the next global editor mode | |
| 131 | * @param modeArgs arguments for the new mode | |
| 132 | * @param name the name of the command that is the tooltip text. | |
| 133 | */ | |
| 134 | public ActionSetMode(Class modeClass, Hashtable modeArgs, String name) { | |
| 135 | 0 | super(modeClass); |
| 136 | 0 | this.modeArgs = modeArgs; |
| 137 | 0 | putToolTip(name); |
| 138 | 0 | putIcon(name); |
| 139 | 0 | } |
| 140 | ||
| 141 | /** | |
| 142 | * The constructor. | |
| 143 | * | |
| 144 | * @param modeClass the next global editor mode | |
| 145 | * @param arg the name of a new argument for the new mode | |
| 146 | * @param value the value of a new argument for the new mode | |
| 147 | */ | |
| 148 | public ActionSetMode(Class modeClass, String arg, Object value) { | |
| 149 | 0 | super(modeClass, arg, value); |
| 150 | 0 | } |
| 151 | ||
| 152 | /** | |
| 153 | * The constructor. | |
| 154 | * TODO: The "name" parameter is used for the icon and for the tooltip. | |
| 155 | * This makes i18n of the tooltip impossible. | |
| 156 | * | |
| 157 | * @param modeClass the next global editor mode | |
| 158 | * @param arg the name of a new argument for the new mode | |
| 159 | * @param value the value of a new argument for the new mode | |
| 160 | * @param name the name of the command that is the tooltip text. | |
| 161 | */ | |
| 162 | public ActionSetMode(Class modeClass, String arg, Object value, | |
| 163 | String name) { | |
| 164 | 15299 | super(modeClass, arg, value); |
| 165 | 15299 | putToolTip(name); |
| 166 | 15299 | putIcon(name); |
| 167 | 15299 | } |
| 168 | ||
| 169 | /** | |
| 170 | * The constructor. | |
| 171 | * | |
| 172 | * @param modeClass the next global editor mode | |
| 173 | * @param arg the name of a new argument for the new mode | |
| 174 | * @param value the value of a new argument for the new mode | |
| 175 | * @param name the name of the command that is the tooltip text. | |
| 176 | * @param icon the SMALL_ICON for the action | |
| 177 | */ | |
| 178 | public ActionSetMode( | |
| 179 | Class modeClass, | |
| 180 | String arg, | |
| 181 | Object value, | |
| 182 | String name, | |
| 183 | ImageIcon icon) { | |
| 184 | 0 | super(modeClass, arg, value, name, icon); |
| 185 | 0 | putToolTip(name); |
| 186 | 0 | } |
| 187 | ||
| 188 | /** | |
| 189 | * Adds tooltip text to the Action. | |
| 190 | * | |
| 191 | * @param key The key to be localized to become the tooltip. | |
| 192 | */ | |
| 193 | private void putToolTip(String key) { | |
| 194 | 24318 | putValue(Action.SHORT_DESCRIPTION, Translator.localize(key)); |
| 195 | 24318 | } |
| 196 | ||
| 197 | private void putIcon(String key) { | |
| 198 | 24318 | ImageIcon icon = ResourceLoaderWrapper.lookupIcon(key); |
| 199 | 24318 | if (icon != null) { |
| 200 | 24299 | putValue(Action.SMALL_ICON, icon); |
| 201 | } else { | |
| 202 | 19 | LOG.debug("Failed to find icon for key " + key); |
| 203 | } | |
| 204 | 24318 | } |
| 205 | } |