| 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 | |
package org.argouml.uml.diagram.static_structure.ui; |
| 40 | |
|
| 41 | |
import java.awt.event.MouseEvent; |
| 42 | |
import java.util.Collection; |
| 43 | |
|
| 44 | |
import javax.swing.Icon; |
| 45 | |
|
| 46 | |
import org.argouml.application.helpers.ResourceLoaderWrapper; |
| 47 | |
import org.argouml.model.Model; |
| 48 | |
import org.argouml.uml.diagram.deployment.DeploymentDiagramGraphModel; |
| 49 | |
import org.argouml.uml.diagram.ui.SelectionNodeClarifiers2; |
| 50 | |
import org.tigris.gef.base.Editor; |
| 51 | |
import org.tigris.gef.base.Globals; |
| 52 | |
import org.tigris.gef.base.ModeCreateEdgeAndNode; |
| 53 | |
import org.tigris.gef.presentation.Fig; |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public class SelectionClass extends SelectionNodeClarifiers2 { |
| 59 | |
|
| 60 | 0 | private static Icon inherit = |
| 61 | |
ResourceLoaderWrapper.lookupIconResource("Generalization"); |
| 62 | |
|
| 63 | 0 | private static Icon assoc = |
| 64 | |
ResourceLoaderWrapper.lookupIconResource("Association"); |
| 65 | |
|
| 66 | 0 | private static Icon compos = |
| 67 | |
ResourceLoaderWrapper.lookupIconResource("CompositeAggregation"); |
| 68 | |
|
| 69 | 0 | private static Icon selfassoc = |
| 70 | |
ResourceLoaderWrapper.lookupIconResource("SelfAssociation"); |
| 71 | |
|
| 72 | |
private boolean useComposite; |
| 73 | |
|
| 74 | 0 | private static Icon icons[] = |
| 75 | |
{inherit, |
| 76 | |
inherit, |
| 77 | |
assoc, |
| 78 | |
assoc, |
| 79 | |
selfassoc, |
| 80 | |
}; |
| 81 | |
|
| 82 | |
|
| 83 | 0 | private static String instructions[] = |
| 84 | |
{"Add a superclass", |
| 85 | |
"Add a subclass", |
| 86 | |
"Add an associated class", |
| 87 | |
"Add an associated class", |
| 88 | |
"Add a self association", |
| 89 | |
"Move object(s)", |
| 90 | |
}; |
| 91 | |
|
| 92 | 0 | private static Object edgeType[] = |
| 93 | |
{Model.getMetaTypes().getGeneralization(), |
| 94 | |
Model.getMetaTypes().getGeneralization(), |
| 95 | |
Model.getMetaTypes().getAssociation(), |
| 96 | |
Model.getMetaTypes().getAssociation(), |
| 97 | |
Model.getMetaTypes().getAssociation(), |
| 98 | |
}; |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
public SelectionClass(Fig f) { |
| 106 | 0 | super(f); |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
@Override |
| 110 | |
protected Icon[] getIcons() { |
| 111 | 0 | Icon workingIcons[] = new Icon[icons.length]; |
| 112 | 0 | System.arraycopy(icons, 0, workingIcons, 0, icons.length); |
| 113 | |
|
| 114 | |
|
| 115 | 0 | if (Globals.curEditor().getGraphModel() |
| 116 | |
instanceof DeploymentDiagramGraphModel) { |
| 117 | 0 | workingIcons[TOP - BASE] = null; |
| 118 | 0 | workingIcons[BOTTOM - BASE] = null; |
| 119 | |
} |
| 120 | 0 | if (useComposite) { |
| 121 | 0 | workingIcons[LEFT - BASE] = compos; |
| 122 | 0 | workingIcons[RIGHT - BASE] = compos; |
| 123 | |
} |
| 124 | |
|
| 125 | 0 | if (Model.getModelManagementHelper().isReadOnly( |
| 126 | |
getContent().getOwner())) { |
| 127 | 0 | return new Icon[] {null, inherit, null, null, null }; |
| 128 | |
} |
| 129 | 0 | return workingIcons; |
| 130 | |
} |
| 131 | |
|
| 132 | |
@Override |
| 133 | |
protected String getInstructions(int index) { |
| 134 | 0 | return instructions[index - BASE]; |
| 135 | |
} |
| 136 | |
|
| 137 | |
@Override |
| 138 | |
protected Object getNewNodeType(int i) { |
| 139 | 0 | return Model.getMetaTypes().getUMLClass(); |
| 140 | |
} |
| 141 | |
|
| 142 | |
@Override |
| 143 | |
protected Object getNewEdgeType(int i) { |
| 144 | 0 | if (i == 0) { |
| 145 | 0 | i = getButton(); |
| 146 | |
} |
| 147 | 0 | return edgeType[i - 10]; |
| 148 | |
} |
| 149 | |
|
| 150 | |
@Override |
| 151 | |
protected boolean isReverseEdge(int i) { |
| 152 | 0 | if (i == BOTTOM || i == LEFT) { |
| 153 | 0 | return true; |
| 154 | |
} |
| 155 | 0 | return false; |
| 156 | |
} |
| 157 | |
|
| 158 | |
@Override |
| 159 | |
protected boolean isDraggableHandle(int index) { |
| 160 | |
|
| 161 | 0 | if (index == LOWER_LEFT) { |
| 162 | 0 | return false; |
| 163 | |
} |
| 164 | 0 | return true; |
| 165 | |
} |
| 166 | |
|
| 167 | |
@Override |
| 168 | |
protected boolean isEdgePostProcessRequested() { |
| 169 | 0 | return useComposite; |
| 170 | |
} |
| 171 | |
|
| 172 | |
@Override |
| 173 | |
protected ModeCreateEdgeAndNode getNewModeCreateEdgeAndNode(Editor ce, |
| 174 | |
Object theEdgeType, boolean postProcess, |
| 175 | |
SelectionNodeClarifiers2 nodeCreator) { |
| 176 | 0 | return new ModeCreateEdgeAndNodeWithComposition(ce, |
| 177 | |
theEdgeType, postProcess, nodeCreator); |
| 178 | |
} |
| 179 | |
|
| 180 | |
@Override |
| 181 | |
protected void postProcessEdge2(Object newEdge) { |
| 182 | 0 | if (Model.getFacade().isAAssociation(newEdge)) { |
| 183 | 0 | Collection assocEnds = Model.getFacade().getConnections(newEdge); |
| 184 | 0 | Object firstAE = assocEnds.iterator().next(); |
| 185 | 0 | Object aggregationKind = Model.getAggregationKind().getComposite(); |
| 186 | 0 | Model.getCoreHelper().setAggregation(firstAE, aggregationKind); |
| 187 | |
} |
| 188 | 0 | } |
| 189 | |
|
| 190 | |
@Override |
| 191 | |
public void mouseEntered(MouseEvent me) { |
| 192 | 0 | super.mouseEntered(me); |
| 193 | 0 | useComposite = me.isShiftDown(); |
| 194 | 0 | } |
| 195 | |
|
| 196 | |
@Override |
| 197 | |
protected Object getNewNode(int index) { |
| 198 | 0 | return Model.getCoreFactory().buildClass(); |
| 199 | |
} |
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
class ModeCreateEdgeAndNodeWithComposition extends ModeCreateEdgeAndNode { |
| 207 | |
|
| 208 | |
public ModeCreateEdgeAndNodeWithComposition(Editor ce, Object edgeType, |
| 209 | 0 | boolean postProcess, SelectionNodeClarifiers2 nodeCreator) { |
| 210 | 0 | super(ce, edgeType, postProcess, nodeCreator); |
| 211 | 0 | } |
| 212 | |
|
| 213 | |
@Override |
| 214 | |
protected void postProcessEdge(Object newEdge) { |
| 215 | 0 | postProcessEdge2(newEdge); |
| 216 | 0 | } |
| 217 | |
} |
| 218 | |
|
| 219 | |
} |