⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edgebase.java

📁 UML设计测试工具
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * USE - UML based specification environment
 * Copyright (C) 1999-2004 Mark Richters, University of Bremen
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* $ProjectHeader: use 2-3-0-release.1 Mon, 12 Sep 2005 20:18:33 +0200 green $ */

package org.tzi.use.gui.views.diagrams;

import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.tzi.use.graph.DirectedEdgeBase;
import org.tzi.use.graph.DirectedGraph;
import org.tzi.use.gui.views.diagrams.objectdiagram.NewObjectDiagram;
import org.tzi.use.gui.views.diagrams.objectdiagram.ObjectNode;
import org.tzi.use.parser.xml.LayoutTags;
import org.tzi.use.uml.mm.MAssociation;

/**
 * Base class of all edge types in the diagram.
 * 
 * @version $ProjectVersion: 2-3-0-release.1 $
 * @author Fabian Gutsche
 */
public abstract class EdgeBase extends DirectedEdgeBase
                               implements Selectable {
    /**
     * Special identification for the source node on this edge.
     */
    static final int SOURCE = 1;
    /**
     * Special identification for the target node on this edge.
     */
    static final int TARGET = 2;
    /**
     * Special identification for the first reflexive node on this edge.
     */
    static final int REFLEXIVE_1 = 3;
    /**
     * Special identification for the second reflexive node on this edge.
     */
    static final int REFLEXIVE_2 = 4;
    /**
     * Special identification for the third reflexive node on this edge.
     */
    static final int REFLEXIVE_3 = 5;
    /**
     * Special identification for the associationclass/objectlink node 
     * on this edge.
     */
    static final int ASSOC_CLASS = 6;
    /**
     * Special identification for the connection point from the dashed to 
     * the solid line of an associationclass/objectlink.
     */
    static final int ASSOC_CLASS_CON = 7;
    
    /**
     * Initial counter for the IDs for the nodes which are laying on 
     * this edge.
     */
    final int INITIAL_COUNTER = 0;
    /**
     * Counter for the IDs for the nodes which are laying on this edge.
     */
    int fNodesOnEdgeCounter = INITIAL_COUNTER;
    
    /**
     * Mouse click count of the given diagram. 
     */
    private int fClickCount = -1; // ==1 than show nodes on edge
    
    /**
     * Determinds if this edge is selected or not.
     */
    private boolean fIsSelected;
    
    /**
     * Determinds if this edge is dragged or not.
     */
    private boolean fIsDragged;
    
    /**
     * Name of this edge.
     */
    String fEdgeName;
    
    /**
     * List of all nodes laying on the dashed edge of an 
     * associationclass/objectlink.
     */
    List fNodesOnAssocClsEdge;
    /**
     * List of all nodes laying on this edge.
     */
    List fNodesOnEdge;
    /**
     * Source node of this edge (the drawn line starts here).
     */
    NodeOnEdge fSNode;
    /**
     * Target node of this edge (the drawn line ends here).
     */
    NodeOnEdge fTNode;
    /**
     * First reflexiv node on an reflexive edge.
     */
    NodeOnEdge fRefNode1;
    /**
     * Second reflexiv node on an reflexive edge.
     */
    NodeOnEdge fRefNode2;
    /**
     * Third reflexiv node on an reflexive edge.
     */
    NodeOnEdge fRefNode3;
    /**
     * Associationclass/Objectlink node.
     */
    NodeOnEdge fNENode; 
    /**
     * Point which connects the dashed line of an associationclass/objectlink
     * to the solid line.
     */
    NodeOnEdge fConNode; 
    
    /**
     * Options of the diagram in which this edge is drawn.
     */
    DiagramOptions fOpt;
    
    /**
     * Source node of this edge.
     */
    NodeBase fSource;
    /**
     * Target node of this edge.
     */
    NodeBase fTarget;
    /**
     * Rolename which is on the source side of this edge.
     */
    EdgeProperty fSourceRolename;
    /**
     * Rolename which is on the target side of this edge.
     */
    EdgeProperty fTargetRolename;
    /**
     * Multiplicity which is on the source side of this edge.
     */
    EdgeProperty fSourceMultiplicity;
    /**
     * Multiplicity which is on the target side of this edge.
     */
    EdgeProperty fTargetMultiplicity;
    /**
     * Associationname/Linkname of this edge.
     */
    EdgeProperty fAssocName;
    /**
     * X-coordinate of the source node.
     */
    int fX1;
    /**
     * Y-coordinate of the source node.
     */
    int fY1;
    /**
     * X-coordinate of the target node.
     */
    int fX2;
    /**
     * Y-coordinate of the target node.
     */
    int fY2;
    
    /**
     * The diagram the edge belongs to.
     */
    DiagramView fDiagram;
    
    /**
     * Association this edge belongs to.
     */
    MAssociation fAssoc;

    /**
     * Constructs a new edge.
     * @param source The source node of the edge.
     * @param target The target node of the edge.
     * @param edgeName The name of the edge.
     * @param diagram The diagram this edge belongs to.
     */
    public EdgeBase( Object source, Object target, String edgeName,
                     DiagramView diagram, MAssociation assoc ) {
        super( source, target );
        fDiagram = diagram;
        fOpt = fDiagram.getOptions();
        fEdgeName = edgeName;
        fAssoc = assoc;
        fSource = (NodeBase) source;
        fTarget = (NodeBase) target;
        fNodesOnEdge = new ArrayList();
        fNodesOnAssocClsEdge = new ArrayList();
        
        fX1 = (int) fSource.x();
        fY1 = (int) fSource.y();
        fX2 = (int) fTarget.x();
        fY2 = (int) fTarget.y();
        
        Point2D sp = getIntersectionCoordinate( fSource, fX1, fY1, 
                                                fX2, fY2 );
        Point2D tp = getIntersectionCoordinate( fTarget, fX2, fY2, 
                                                fX1, fY1 );
        
        fSNode = new NodeOnEdge( sp.getX(), sp.getY(),
                                 fSource, fTarget, this, 
                                 fNodesOnEdgeCounter++,
                                 EdgeBase.SOURCE, edgeName, fOpt );
        fTNode = new NodeOnEdge( tp.getX(), tp.getY(), 
                                 fSource, fTarget, this, 
                                 fNodesOnEdgeCounter++,
                                 EdgeBase.TARGET, edgeName, fOpt ); 
        fNodesOnEdge.add( fSNode );
        fNodesOnEdge.add( fTNode );
    }
    
    /**
     * Draws the edge in a given graphic object.
     */
    public abstract void draw( Graphics g, FontMetrics fm );
    
    
    public int getClickCount() {
        return fClickCount;
    }
    public void setClickCount( int clickCount ) {
        fClickCount = clickCount;
    }
    public boolean isReflexive() {
        return fSource.equals( fTarget );
    }
    public List getNodesOnEdge() {
        return fNodesOnEdge;
    }
    
    public boolean isSelected() {
        return fIsSelected;
    }
    public void setSelected( boolean selected ) {
        fIsSelected = selected;
    }
    
    public boolean isDragged() {
        return fIsDragged;
    }
    public void setDragged( boolean dragging ) {
        fIsDragged = dragging;
    }
    
    public boolean isLink() {
        return fDiagram instanceof NewObjectDiagram;
    }
    
    /**
     * Is beneith the x,y position an edge, than an additional node
     * will be added on this edge.
     *  
     * @param x x position to check
     * @param y y position to check
     * @return The new NodeOnEdge if there was an edge beneith this location
     * otherwise null is returnd.
     */
    public NodeOnEdge occupiesThanAdd( int x, int y, int clickCount ) {
        boolean occupies = false;
        Line2D line = new Line2D.Double();
        NodeOnEdge n1 = null;
        NodeOnEdge n2 = null;
        
        // checking every line segmend of this edge.
        Iterator it = fNodesOnEdge.iterator();
        if ( it.hasNext() ) {
            n1 = (NodeOnEdge) it.next();
        }
        while ( it.hasNext() ) {
            n2 = (NodeOnEdge) it.next();
            line = new Line2D.Double( n1.x(), n1.y(), n2.x(), n2.y() );
            occupies = line.intersects( x - 2, y - 2, 4, 4 );
            if ( occupies && clickCount == 2 ) {
                // are the coordinates abouve another node do not add another 
                // node.
                if ( !n2.dimension().contains( x, y ) 
                     || !n1.dimension().contains( x, y ) ) {
                    
                    NodeOnEdge newNode = new NodeOnEdge( x, y, fSource, fTarget, 
                                                         this, fNodesOnEdgeCounter++,
                                                         0, fEdgeName, fOpt );
                    addNode( newNode, n1 );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -