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

📄 halfedge.java

📁 UML设计测试工具
💻 JAVA
字号:
/*
 * 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.util.Iterator;

import org.tzi.use.gui.views.diagrams.edges.DirectedEdgeFactory;
import org.tzi.use.uml.mm.MAssociation;

/**
 * An edge being part of a nary edge. This edge connects an node with a
 * DiamondNode in case of an nary edge, or an Object/ClassNode with a 
 * PseudoNode in case of an association class.
 * 
 * @version $ProjectVersion: 2-3-0-release.1 $
 * @author Fabian Gutsche
 */
public class HalfEdge extends EdgeBase {
    
    /**
     * Constructs a new edge. source is a pseude-node, target is a node.
     */
    public HalfEdge( NodeBase source, NodeBase target, String targetLabel,
                     String targetMulti, DiagramView diagram, MAssociation assoc ) {
        super( source, target, assoc.name(), diagram, assoc );
        
        fTargetRolename = new Rolename( targetLabel, (NodeBase) target,
                                        (NodeBase) source, fX2, fY2, fX1, fY1,
                                        fOpt, Rolename.TARGET_SIDE, assoc,
                                        this );
        
        fTargetMultiplicity = new Multiplicity( targetMulti, (NodeBase) target,
                                                (NodeBase) source, assoc, this,
                                                fX2, fY2, fX1, fY1, fOpt,
                                                Multiplicity.TARGET_SIDE );
    }

    public void draw( Graphics g, FontMetrics fm ) {
        int x1 = (int) fSource.x();
        int y1 = (int) fSource.y();
        int x2 = (int) fTarget.x();
        int y2 = (int) fTarget.y();
        
        if ( isSelected() ) {
            g.setColor( fOpt.getEDGE_SELECTED_COLOR() );
        } else {
            g.setColor( fOpt.getEDGE_COLOR() );
        }
        drawHalfEdge( g, x1, y1, x2, y2 );
        
        
        if ( isSelected() ) {
            g.setColor( fOpt.getEDGE_SELECTED_COLOR() );
        } else {
            g.setColor( fOpt.getEDGE_LABEL_COLOR() );    
        }
        if ( fOpt.isShowRolenames() ) {
            fTargetRolename.draw( g, fm );
        }
        
        if ( fOpt.isShowMutliplicities() ) {
            fTargetMultiplicity.draw( g, fm );
        }
        g.setColor( fOpt.getEDGE_COLOR() );
    }
    
    private void drawHalfEdge( Graphics g, int x1, int y1, int x2, int y2 ) {
        NodeOnEdge n1 = null;
        NodeOnEdge n2 = null;
        
        // draw all line segments
        if ( !fNodesOnEdge.isEmpty() ) {
            Iterator it = fNodesOnEdge.iterator();
            int counter = 0;
            if ( it.hasNext() ) {
                n1 = (NodeOnEdge) it.next();
                counter++;
            }
            while( it.hasNext() ) {
                n2 = (NodeOnEdge) it.next();
                counter++;
                n2.draw( g, g.getFontMetrics() );
                try {
                    if ( counter < fNodesOnEdge.size() ) {
                        DirectedEdgeFactory.drawAssociation( g,
                                                             (int) n1.x(),
                                                             (int) n1.y(),
                                                             (int) n2.x(),
                                                             (int) n2.y() );
                        n1 = n2;
                    }
                } catch ( Exception e ) {
                    //ignore
                }
            }
        }
        
        // draw the last line segment, as an association, 
        // composition or aggregation
        try {
            // draw association
            DirectedEdgeFactory.drawAssociation( g, (int) n1.x(), 
                                                 (int) n1.y(),
                                                 (int) n2.x(),
                                                 (int) n2.y() );
        } catch ( Exception ex ) {
            // ignore
        }
    }
}

⌨️ 快捷键说明

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