| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
package org.argouml.uml.diagram.state.ui; |
| 42 | |
|
| 43 | |
import java.awt.Font; |
| 44 | |
import java.awt.Rectangle; |
| 45 | |
import java.beans.PropertyChangeEvent; |
| 46 | |
import java.beans.PropertyVetoException; |
| 47 | |
|
| 48 | |
import org.argouml.model.AssociationChangeEvent; |
| 49 | |
import org.argouml.model.AttributeChangeEvent; |
| 50 | |
import org.argouml.model.Model; |
| 51 | |
import org.argouml.notation.Notation; |
| 52 | |
import org.argouml.notation.NotationName; |
| 53 | |
import org.argouml.notation.NotationProvider; |
| 54 | |
import org.argouml.notation.NotationProviderFactory2; |
| 55 | |
import org.argouml.notation.NotationSettings; |
| 56 | |
import org.argouml.uml.diagram.DiagramSettings; |
| 57 | |
import org.tigris.gef.presentation.Fig; |
| 58 | |
import org.tigris.gef.presentation.FigRRect; |
| 59 | |
import org.tigris.gef.presentation.FigText; |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | 0 | public abstract class FigState extends FigStateVertex { |
| 69 | |
|
| 70 | |
protected static final int SPACE_TOP = 0; |
| 71 | |
protected static final int SPACE_MIDDLE = 0; |
| 72 | |
protected static final int DIVIDER_Y = 0; |
| 73 | |
protected static final int SPACE_BOTTOM = 6; |
| 74 | |
|
| 75 | |
protected static final int MARGIN = 2; |
| 76 | |
|
| 77 | |
protected NotationProvider notationProviderBody; |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
private FigText internal; |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
public FigState(Object owner, Rectangle bounds, DiagramSettings settings) { |
| 92 | 0 | super(owner, bounds, settings); |
| 93 | |
|
| 94 | 0 | initializeState(); |
| 95 | |
|
| 96 | 0 | NotationName notation = Notation.findNotation( |
| 97 | |
getNotationSettings().getNotationLanguage()); |
| 98 | 0 | notationProviderBody = |
| 99 | |
NotationProviderFactory2.getInstance().getNotationProvider( |
| 100 | |
NotationProviderFactory2.TYPE_STATEBODY, getOwner(), this, |
| 101 | |
notation); |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
@Override |
| 105 | |
protected Fig createBigPortFig() { |
| 106 | 0 | return new FigRRect(getInitialX() + 1, getInitialY() + 1, |
| 107 | |
getInitialWidth() - 2, getInitialHeight() - 2, |
| 108 | |
DEBUG_COLOR, DEBUG_COLOR); |
| 109 | |
} |
| 110 | |
|
| 111 | |
private void initializeState() { |
| 112 | |
|
| 113 | |
|
| 114 | 0 | getNameFig().setLineWidth(0); |
| 115 | 0 | getNameFig().setBounds(getInitialX() + 2, getInitialY() + 2, |
| 116 | |
getInitialWidth() - 4, |
| 117 | |
getNameFig().getBounds().height); |
| 118 | 0 | getNameFig().setFilled(false); |
| 119 | |
|
| 120 | 0 | internal = |
| 121 | |
new FigText(getInitialX() + 2, |
| 122 | |
getInitialY() + 2 + NAME_FIG_HEIGHT + 4, |
| 123 | |
getInitialWidth() - 4, |
| 124 | |
getInitialHeight() |
| 125 | |
- (getInitialY() + 2 + NAME_FIG_HEIGHT + 4)); |
| 126 | 0 | internal.setFont(getSettings().getFont(Font.PLAIN)); |
| 127 | 0 | internal.setTextColor(TEXT_COLOR); |
| 128 | 0 | internal.setLineWidth(0); |
| 129 | 0 | internal.setFilled(false); |
| 130 | 0 | internal.setExpandOnly(true); |
| 131 | 0 | internal.setReturnAction(FigText.INSERT); |
| 132 | 0 | internal.setJustification(FigText.JUSTIFY_LEFT); |
| 133 | 0 | } |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
@Override |
| 139 | |
protected void initNotationProviders(Object own) { |
| 140 | 0 | if (notationProviderBody != null) { |
| 141 | 0 | notationProviderBody.cleanListener(); |
| 142 | |
} |
| 143 | 0 | super.initNotationProviders(own); |
| 144 | 0 | NotationName notation = Notation.findNotation( |
| 145 | |
getNotationSettings().getNotationLanguage()); |
| 146 | 0 | if (Model.getFacade().isAState(own)) { |
| 147 | 0 | notationProviderBody = |
| 148 | |
NotationProviderFactory2.getInstance().getNotationProvider( |
| 149 | |
NotationProviderFactory2.TYPE_STATEBODY, own, this, |
| 150 | |
notation); |
| 151 | |
} |
| 152 | 0 | } |
| 153 | |
|
| 154 | |
@Override |
| 155 | |
protected void modelChanged(PropertyChangeEvent mee) { |
| 156 | 0 | super.modelChanged(mee); |
| 157 | |
|
| 158 | 0 | if (mee instanceof AssociationChangeEvent |
| 159 | |
|| mee instanceof AttributeChangeEvent) { |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | 0 | if ((mee.getPropertyName().equals("incoming") |
| 165 | |
|| mee.getPropertyName().equals("outgoing"))) { |
| 166 | 0 | return; |
| 167 | |
} |
| 168 | |
|
| 169 | 0 | renderingChanged(); |
| 170 | 0 | damage(); |
| 171 | |
} |
| 172 | 0 | } |
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
@Override |
| 178 | |
public void removeFromDiagramImpl() { |
| 179 | 0 | if (notationProviderBody != null) { |
| 180 | 0 | notationProviderBody.cleanListener(); |
| 181 | |
} |
| 182 | 0 | super.removeFromDiagramImpl(); |
| 183 | 0 | } |
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
@Override |
| 189 | |
public void renderingChanged() { |
| 190 | 0 | super.renderingChanged(); |
| 191 | 0 | Object state = getOwner(); |
| 192 | |
|
| 193 | |
|
| 194 | 0 | assert state != null; |
| 195 | 0 | if (state == null) { |
| 196 | 0 | return; |
| 197 | |
} |
| 198 | 0 | if (notationProviderBody != null) { |
| 199 | 0 | internal.setText(notationProviderBody.toString(getOwner(), |
| 200 | |
getNotationSettings())); |
| 201 | |
} |
| 202 | 0 | calcBounds(); |
| 203 | 0 | setBounds(getBounds()); |
| 204 | 0 | } |
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
protected abstract int getInitialX(); |
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
protected abstract int getInitialY(); |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
protected abstract int getInitialWidth(); |
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
protected abstract int getInitialHeight(); |
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
protected void setInternal(FigText theInternal) { |
| 230 | 0 | this.internal = theInternal; |
| 231 | 0 | } |
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
protected FigText getInternal() { |
| 237 | 0 | return internal; |
| 238 | |
} |
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
@Override |
| 244 | |
protected void textEditStarted(FigText ft) { |
| 245 | 0 | super.textEditStarted(ft); |
| 246 | 0 | if (ft == internal) { |
| 247 | 0 | showHelp(notationProviderBody.getParsingHelp()); |
| 248 | |
} |
| 249 | 0 | } |
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
@Override |
| 255 | |
public void textEdited(FigText ft) throws PropertyVetoException { |
| 256 | 0 | super.textEdited(ft); |
| 257 | 0 | if (ft == getInternal()) { |
| 258 | 0 | Object st = getOwner(); |
| 259 | 0 | if (st == null) { |
| 260 | 0 | return; |
| 261 | |
} |
| 262 | 0 | notationProviderBody.parse(getOwner(), ft.getText()); |
| 263 | 0 | ft.setText(notationProviderBody.toString(getOwner(), |
| 264 | |
getNotationSettings())); |
| 265 | |
} |
| 266 | 0 | } |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
@Override |
| 273 | |
protected void updateFont() { |
| 274 | 0 | super.updateFont(); |
| 275 | 0 | Font f = getSettings().getFont(Font.PLAIN); |
| 276 | 0 | internal.setFont(f); |
| 277 | 0 | } |
| 278 | |
|
| 279 | |
public void notationRenderingChanged(NotationProvider np, String rendering) { |
| 280 | 0 | super.notationRenderingChanged(np, rendering); |
| 281 | 0 | if (notationProviderBody == np) { |
| 282 | 0 | internal.setText(rendering); |
| 283 | 0 | updateBounds(); |
| 284 | 0 | damage(); |
| 285 | |
} |
| 286 | 0 | } |
| 287 | |
|
| 288 | |
public NotationSettings getNotationSettings(NotationProvider np) { |
| 289 | |
|
| 290 | 0 | return getNotationSettings(); |
| 291 | |
} |
| 292 | |
|
| 293 | |
public Object getOwner(NotationProvider np) { |
| 294 | |
|
| 295 | 0 | return getOwner(); |
| 296 | |
} |
| 297 | |
|
| 298 | |
} |