001: /*
002: * argun 1.0
003: * Web 2.0 delivery framework
004: * Copyright (C) 2007 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.web.webdiagram;
024:
025: import java.awt.Color;
026: import java.awt.Frame;
027: import java.awt.event.ActionEvent;
028: import java.util.Iterator;
029: import java.util.Map;
030:
031: import javax.swing.AbstractAction;
032: import javax.swing.JPopupMenu;
033: import javax.swing.SwingUtilities;
034:
035: import org.jgraph.graph.DefaultPort;
036: import org.jgraph.graph.GraphConstants;
037:
038: import biz.hammurapi.diagram.DiagramApplet;
039: import biz.hammurapi.diagram.DiagramEdge;
040: import biz.hammurapi.diagram.DiagramModel;
041: import biz.hammurapi.diagram.data.Edge;
042:
043: public class RoleGeneralization extends DiagramEdge {
044:
045: public RoleGeneralization(DiagramModel owner, Edge data) {
046: super (owner, data);
047: }
048:
049: public void setAttributes(Map attributes) {
050: super .setAttributes(attributes);
051: GraphConstants.setLineEnd(attributes,
052: GraphConstants.ARROW_TECHNICAL);
053: GraphConstants.setLineColor(attributes, Color.GRAY);
054: GraphConstants.setEditable(attributes, false);
055: GraphConstants.setDashPattern(attributes, new float[] { 5, 5 });
056: }
057:
058: public boolean acceptsSource(Object port) {
059: if (port instanceof DefaultPort) {
060: Iterator it = ((DefaultPort) port).getEdges().iterator();
061: while (it.hasNext()) {
062: Object next = it.next();
063: if (next != this
064: && next instanceof RoleGeneralization
065: && ((RoleGeneralization) next).getTarget() == getTarget()) {
066: return false;
067: }
068: }
069: }
070:
071: return port != null
072: && ((DefaultPort) port).getParent() instanceof Role;
073: }
074:
075: public boolean acceptsTarget(Object port) {
076: if (port instanceof DefaultPort) {
077: Iterator it = ((DefaultPort) port).getEdges().iterator();
078: while (it.hasNext()) {
079: Object next = it.next();
080: if (next != this
081: && next instanceof RoleGeneralization
082: && ((RoleGeneralization) next).getSource() == getSource()) {
083: return false;
084: }
085: }
086: }
087:
088: return port != null
089: && ((DefaultPort) port).getParent() instanceof Role;
090: }
091:
092: public void populatePopupMenu(final DiagramApplet applet,
093: final java.awt.Point pt, final JPopupMenu menu) {
094: // Edit
095: menu.add(new AbstractAction("Edit") {
096: public void actionPerformed(ActionEvent e) {
097: Frame frame = (Frame) SwingUtilities
098: .getAncestorOfClass(Frame.class, applet
099: .getGraph());
100: NamelessDiagramElementPropertiesDialog pd = new NamelessDiagramElementPropertiesDialog(
101: frame, RoleGeneralization.this);
102: if (pd.edit()) {
103: applet.getGraph().repaint();
104: }
105: }
106: });
107: }
108:
109: }
|