| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ArgoFigText |
|
| 1.8125;1.812 |
| 1 | /* $Id: ArgoFigText.java 17921 2010-01-27 05:17:47Z bobtarling $ | |
| 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) 2007-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.uml.diagram.ui; | |
| 40 | ||
| 41 | import java.awt.Font; | |
| 42 | import java.awt.Rectangle; | |
| 43 | import java.beans.PropertyChangeEvent; | |
| 44 | ||
| 45 | import javax.management.ListenerNotFoundException; | |
| 46 | import javax.management.MBeanNotificationInfo; | |
| 47 | import javax.management.Notification; | |
| 48 | import javax.management.NotificationBroadcasterSupport; | |
| 49 | import javax.management.NotificationEmitter; | |
| 50 | import javax.management.NotificationFilter; | |
| 51 | import javax.management.NotificationListener; | |
| 52 | ||
| 53 | import org.argouml.kernel.Project; | |
| 54 | import org.argouml.model.Model; | |
| 55 | import org.argouml.uml.diagram.DiagramSettings; | |
| 56 | import org.tigris.gef.presentation.FigText; | |
| 57 | ||
| 58 | /** | |
| 59 | * Primitive Fig for text. | |
| 60 | * | |
| 61 | * @author Michiel | |
| 62 | */ | |
| 63 | public class ArgoFigText extends FigText | |
| 64 | implements NotificationEmitter, ArgoFig { | |
| 65 | ||
| 66 | 1071 | private NotificationBroadcasterSupport notifier = |
| 67 | new NotificationBroadcasterSupport(); | |
| 68 | ||
| 69 | private DiagramSettings settings; | |
| 70 | ||
| 71 | /** | |
| 72 | * Construct a text fig owned by the given UML element. <p> | |
| 73 | * | |
| 74 | * Even if there is no owner, then you still have to use this constructor; | |
| 75 | * setting the owner parameter to null is acceptable. | |
| 76 | * | |
| 77 | * @param owner owning model element or null | |
| 78 | * @param bounds rectangle describing bounds of figure | |
| 79 | * @param renderSettings render settings | |
| 80 | * @param expandOnly true if Fig should never shrink | |
| 81 | */ | |
| 82 | public ArgoFigText(Object owner, Rectangle bounds, | |
| 83 | DiagramSettings renderSettings, boolean expandOnly) { | |
| 84 | 1071 | super(bounds.x, bounds.y, bounds.width, bounds.height, expandOnly); |
| 85 | //setFontFamily("dialog"); /* TODO: Is this needed?*/ | |
| 86 | ||
| 87 | // TODO: We don't currently have any settings that can change on a | |
| 88 | // per-fig basis, so we can just use the project/diagram defaults | |
| 89 | // settings = new DiagramSettings(renderSettings); | |
| 90 | 1071 | settings = renderSettings; |
| 91 | 1071 | super.setFontFamily(settings.getFontName()); |
| 92 | 1071 | super.setFontSize(settings.getFontSize()); |
| 93 | 1071 | super.setFilled(false); |
| 94 | 1071 | super.setFillColor(null); |
| 95 | 1071 | super.setTextFilled(false); |
| 96 | 1071 | super.setTextFillColor(null); |
| 97 | 1071 | super.setTextColor(TEXT_COLOR); |
| 98 | /* This makes the text not touch the text-border line: */ | |
| 99 | 1071 | super.setTopMargin(1); |
| 100 | 1071 | super.setBotMargin(1); |
| 101 | 1071 | super.setLeftMargin(1); |
| 102 | 1071 | super.setRightMargin(1); |
| 103 | // Certain types of fixed text (e.g. a FigStereotype with a keyword) | |
| 104 | // may not have an owner | |
| 105 | 1071 | if (owner != null) { |
| 106 | 0 | super.setOwner(owner); |
| 107 | 0 | Model.getPump().addModelEventListener(this, owner, "remove"); |
| 108 | } | |
| 109 | 1071 | } |
| 110 | ||
| 111 | /* | |
| 112 | * @see org.tigris.gef.presentation.Fig#deleteFromModel() | |
| 113 | */ | |
| 114 | @Override | |
| 115 | public void deleteFromModel() { | |
| 116 | 0 | super.deleteFromModel(); |
| 117 | 0 | firePropChange("remove", null, null); |
| 118 | 0 | notifier.sendNotification(new Notification("remove", this, 0)); |
| 119 | 0 | } |
| 120 | ||
| 121 | /* | |
| 122 | * @see javax.management.NotificationEmitter#removeNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) | |
| 123 | */ | |
| 124 | public void removeNotificationListener(NotificationListener listener, | |
| 125 | NotificationFilter filter, Object handback) | |
| 126 | throws ListenerNotFoundException { | |
| 127 | 0 | notifier.removeNotificationListener(listener, filter, handback); |
| 128 | 0 | } |
| 129 | ||
| 130 | /* | |
| 131 | * @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) | |
| 132 | */ | |
| 133 | public void addNotificationListener(NotificationListener listener, | |
| 134 | NotificationFilter filter, Object handback) | |
| 135 | throws IllegalArgumentException { | |
| 136 | 0 | notifier.addNotificationListener(listener, filter, handback); |
| 137 | 0 | } |
| 138 | ||
| 139 | /* | |
| 140 | * @see javax.management.NotificationBroadcaster#getNotificationInfo() | |
| 141 | */ | |
| 142 | public MBeanNotificationInfo[] getNotificationInfo() { | |
| 143 | 0 | return notifier.getNotificationInfo(); |
| 144 | } | |
| 145 | ||
| 146 | /* | |
| 147 | * @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener) | |
| 148 | */ | |
| 149 | public void removeNotificationListener(NotificationListener listener) | |
| 150 | throws ListenerNotFoundException { | |
| 151 | 0 | notifier.removeNotificationListener(listener); |
| 152 | 0 | } |
| 153 | ||
| 154 | /** | |
| 155 | * This optional method is not implemented. It will throw an | |
| 156 | * {@link UnsupportedOperationException} if used. Figs are | |
| 157 | * added to a GraphModel which is, in turn, owned by a project. | |
| 158 | * | |
| 159 | * @param project the project | |
| 160 | * @deprecated | |
| 161 | */ | |
| 162 | @SuppressWarnings("deprecation") | |
| 163 | @Deprecated | |
| 164 | public void setProject(Project project) { | |
| 165 | 0 | throw new UnsupportedOperationException(); |
| 166 | } | |
| 167 | ||
| 168 | /** | |
| 169 | * @return the owning project | |
| 170 | * @see org.argouml.uml.diagram.ui.ArgoFig#getProject() | |
| 171 | * @deprecated for 0.27.2 by tfmorris. Implementations should have all | |
| 172 | * the information that they require in the DiagramSettings object. | |
| 173 | */ | |
| 174 | @SuppressWarnings("deprecation") | |
| 175 | @Deprecated | |
| 176 | public Project getProject() { | |
| 177 | 0 | return ArgoFigUtil.getProject(this); |
| 178 | } | |
| 179 | ||
| 180 | public void renderingChanged() { | |
| 181 | 0 | updateFont(); |
| 182 | 0 | setBounds(getBounds()); |
| 183 | 0 | damage(); |
| 184 | 0 | } |
| 185 | ||
| 186 | /** | |
| 187 | * This function should, for all FigTexts, | |
| 188 | * recalculate the font-style (plain, bold, italic, bold/italic), | |
| 189 | * and apply it by calling FigText.setFont(). | |
| 190 | */ | |
| 191 | protected void updateFont() { | |
| 192 | 0 | setFont(getSettings().getFont(getFigFontStyle())); |
| 193 | 0 | } |
| 194 | ||
| 195 | /** | |
| 196 | * Determines the font style based on the UML model. | |
| 197 | * Overrule this in Figs that have to show bold or italic based on the | |
| 198 | * UML model they represent. | |
| 199 | * E.g. abstract classes show their name in italic. | |
| 200 | * | |
| 201 | * @return the font style for the nameFig. | |
| 202 | */ | |
| 203 | protected int getFigFontStyle() { | |
| 204 | 0 | return Font.PLAIN; |
| 205 | } | |
| 206 | ||
| 207 | /** | |
| 208 | * Update listeners for a new owner. Obsolete since owner is not allow to | |
| 209 | * change. | |
| 210 | * | |
| 211 | * @param oldOwner the old owner | |
| 212 | * @param newOwner the new owner | |
| 213 | * @deprecated for 0.27.3 by tfmorris. The owner must be specified in the | |
| 214 | * constructor and never changed. | |
| 215 | */ | |
| 216 | @Deprecated | |
| 217 | protected void updateListeners(Object oldOwner, Object newOwner) { | |
| 218 | 0 | if (oldOwner == newOwner) { |
| 219 | 0 | return; |
| 220 | } | |
| 221 | 0 | if (oldOwner != null) { |
| 222 | 0 | Model.getPump().removeModelEventListener(this, oldOwner); |
| 223 | } | |
| 224 | 0 | if (newOwner != null) { |
| 225 | 0 | Model.getPump().addModelEventListener(this, newOwner, "remove"); |
| 226 | } | |
| 227 | 0 | } |
| 228 | ||
| 229 | @Override | |
| 230 | public void propertyChange(PropertyChangeEvent pce) { | |
| 231 | 0 | super.propertyChange(pce); |
| 232 | 0 | if ("remove".equals(pce.getPropertyName()) |
| 233 | && (pce.getSource() == getOwner())) { | |
| 234 | 0 | deleteFromModel(); |
| 235 | } | |
| 236 | 0 | } |
| 237 | ||
| 238 | ||
| 239 | public DiagramSettings getSettings() { | |
| 240 | // TODO: This is a temporary crutch to use until all Figs are updated | |
| 241 | // to use the constructor that accepts a DiagramSettings object | |
| 242 | 0 | if (settings == null) { |
| 243 | 0 | Project p = getProject(); |
| 244 | 0 | if (p != null) { |
| 245 | 0 | return p.getProjectSettings().getDefaultDiagramSettings(); |
| 246 | } | |
| 247 | } | |
| 248 | 0 | return settings; |
| 249 | } | |
| 250 | ||
| 251 | public void setSettings(DiagramSettings renderSettings) { | |
| 252 | 0 | settings = renderSettings; |
| 253 | 0 | renderingChanged(); |
| 254 | 0 | } |
| 255 | ||
| 256 | ||
| 257 | /** | |
| 258 | * Setting the owner of the Fig must be done in the constructor and not | |
| 259 | * changed afterwards for all ArgoUML figs. | |
| 260 | * | |
| 261 | * @param owner owning UML element | |
| 262 | * @throws UnsupportedOperationException | |
| 263 | * @deprecated for 0.27.3 by tfmorris. Set owner in constructor. This method | |
| 264 | * is implemented in GEF, so we'll leave this implementation | |
| 265 | * here to block any attempts to use it within ArgoUML. | |
| 266 | */ | |
| 267 | @SuppressWarnings("deprecation") | |
| 268 | @Deprecated | |
| 269 | public void setOwner(Object owner) { | |
| 270 | 0 | if (owner != getOwner()) { |
| 271 | 0 | throw new UnsupportedOperationException( |
| 272 | "Owner must be set in constructor and left unchanged"); | |
| 273 | } | |
| 274 | 0 | } |
| 275 | ||
| 276 | } |