Back to index

moin  1.9.0~rc2
Public Member Functions | Protected Member Functions | Protected Attributes | Package Attributes | Private Member Functions | Private Attributes
CH.ifa.draw.standard.ConnectionTool Class Reference

A tool that can be used to connect figures, to split connections, and to join two segments of a connection. More...

Inheritance diagram for CH.ifa.draw.standard.ConnectionTool:
Inheritance graph
[legend]
Collaboration diagram for CH.ifa.draw.standard.ConnectionTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ConnectionTool (DrawingView view, ConnectionFigure prototype)
void mouseMove (MouseEvent e, int x, int y)
 Handles mouse move events in the drawing view.
void mouseDown (MouseEvent e, int x, int y)
 Manipulates connections in a context dependent way.
void mouseDrag (MouseEvent e, int x, int y)
 Adjust the created connection or split segment.
void mouseUp (MouseEvent e, int x, int y)
 Connects the figures if the mouse is released over another figure.
void deactivate ()
 Deactivates the tool.
void activate ()
 Activates the tool for the given view.
void keyDown (KeyEvent evt, int key)
 Handles key down events in the drawing view.
Drawing drawing ()
 Gets the tool's drawing.
DrawingEditor editor ()
 Gets the tool's editor.
DrawingView view ()
 Gets the tool's view.

Protected Member Functions

ConnectionFigure createConnection ()
 Creates the ConnectionFigure.
Figure findSource (int x, int y, Drawing drawing)
 Finds a connectable figure target.
Figure findTarget (int x, int y, Drawing drawing)
 Finds a connectable figure target.
ConnectionFigure findConnection (int x, int y, Drawing drawing)
 Finds an existing connection figure.
ConnectionFigure createdFigure ()
 Gets the currently created figure.
void trackConnectors (MouseEvent e, int x, int y)
Figure findConnectionStart (int x, int y, Drawing drawing)
 Finds a connection start figure.
Connector getStartConnector ()
Connector getEndConnector ()
Connector getTarget ()

Protected Attributes

DrawingView fView
int fAnchorX
 The position of the initial mouse down.

Package Attributes

int fAnchorY

Private Member Functions

Connector findConnector (int x, int y, Figure f)
Figure findConnectableFigure (int x, int y, Drawing drawing)

Private Attributes

Connector fStartConnector
 the anchor point of the interaction
Connector fEndConnector
Connector fConnectorTarget = null
Figure fTarget = null
ConnectionFigure fConnection
 the currently created figure
int fSplitPoint
 the currently manipulated connection point
ConnectionFigure fEditedConnection = null
 the currently edited connection
ConnectionFigure fPrototype
 the prototypical figure that is used to create new connections.

Detailed Description

A tool that can be used to connect figures, to split connections, and to join two segments of a connection.

ConnectionTools turns the visibility of the Connectors on when it enters a figure. The connection object to be created is specified by a prototype.


Design Patterns

 o

Prototype
ConnectionTools creates the connection by cloning a prototype.


See also:
ConnectionFigure
Object::clone

Definition at line 32 of file ConnectionTool.java.


Constructor & Destructor Documentation

CH.ifa.draw.standard.ConnectionTool.ConnectionTool ( DrawingView  view,
ConnectionFigure  prototype 
) [inline]

Definition at line 65 of file ConnectionTool.java.

                                                                        {
        super(view);
        fPrototype = prototype;
    }

Member Function Documentation

void CH.ifa.draw.standard.AbstractTool.activate ( ) [inline, inherited]

Activates the tool for the given view.

This method is called whenever the user switches to this tool. Use this method to reinitialize a tool.

Reimplemented in CH.ifa.draw.standard.CreationTool, and CH.ifa.draw.figures.ScribbleTool.

Definition at line 41 of file AbstractTool.java.

                           {
        fView.clearSelection();
    }
ConnectionFigure CH.ifa.draw.standard.ConnectionTool.createConnection ( ) [inline, protected]

Creates the ConnectionFigure.

By default the figure prototype is cloned.

Definition at line 161 of file ConnectionTool.java.

                                                  {
              try {
            return (ConnectionFigure)fPrototype.clone();
              } catch (Exception e) {}
              return null;
    }

Here is the caller graph for this function:

ConnectionFigure CH.ifa.draw.standard.ConnectionTool.createdFigure ( ) [inline, protected]

Gets the currently created figure.

Definition at line 208 of file ConnectionTool.java.

                                               {
        return fConnection;
    }

Deactivates the tool.

This method is called whenever the user switches to another tool. Use this method to do some clean-up when the tool is switched. Subclassers should always call super.deactivate.

Reimplemented from CH.ifa.draw.standard.AbstractTool.

Definition at line 151 of file ConnectionTool.java.

                             {
        super.deactivate();
        if (fTarget != null)
            fTarget.connectorVisibility(false);
    }
Drawing CH.ifa.draw.standard.AbstractTool.drawing ( ) [inline, inherited]

Gets the tool's drawing.

Definition at line 90 of file AbstractTool.java.

                             {
        return fView.drawing();
    }

Here is the caller graph for this function:

DrawingEditor CH.ifa.draw.standard.AbstractTool.editor ( ) [inline, inherited]

Gets the tool's editor.

Definition at line 97 of file AbstractTool.java.

                                  {
        return fView.editor();
    }

Here is the caller graph for this function:

Figure CH.ifa.draw.standard.ConnectionTool.findConnectableFigure ( int  x,
int  y,
Drawing  drawing 
) [inline, private]

Definition at line 252 of file ConnectionTool.java.

                                                                        {
        FigureEnumeration k = drawing.figuresReverse();
        while (k.hasMoreElements()) {
            Figure figure = k.nextFigure();
            if (!figure.includes(fConnection) && figure.canConnect()) {
                if (figure.containsPoint(x, y))
                    return figure;
            }
        }
        return null;
    }

Here is the caller graph for this function:

ConnectionFigure CH.ifa.draw.standard.ConnectionTool.findConnection ( int  x,
int  y,
Drawing  drawing 
) [inline, protected]

Finds an existing connection figure.

Definition at line 194 of file ConnectionTool.java.

                                                                             {
        Enumeration k = drawing.figuresReverse();
        while (k.hasMoreElements()) {
            Figure figure = (Figure) k.nextElement();
            figure = figure.findFigureInside(x, y);
            if (figure != null && (figure instanceof ConnectionFigure))
                return (ConnectionFigure)figure;
        }
        return null;
    }

Here is the caller graph for this function:

Figure CH.ifa.draw.standard.ConnectionTool.findConnectionStart ( int  x,
int  y,
Drawing  drawing 
) [inline, protected]

Finds a connection start figure.

Definition at line 245 of file ConnectionTool.java.

                                                                        {
        Figure target = findConnectableFigure(x, y, drawing);
        if ((target != null) && target.canConnect())
            return target;
        return null;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Connector CH.ifa.draw.standard.ConnectionTool.findConnector ( int  x,
int  y,
Figure  f 
) [inline, private]

Definition at line 238 of file ConnectionTool.java.

                                                            {
        return f.connectorAt(x, y);
    }

Here is the caller graph for this function:

Figure CH.ifa.draw.standard.ConnectionTool.findSource ( int  x,
int  y,
Drawing  drawing 
) [inline, protected]

Finds a connectable figure target.

Definition at line 171 of file ConnectionTool.java.

                                                               {
        return findConnectableFigure(x, y, drawing);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Figure CH.ifa.draw.standard.ConnectionTool.findTarget ( int  x,
int  y,
Drawing  drawing 
) [inline, protected]

Finds a connectable figure target.

Definition at line 178 of file ConnectionTool.java.

                                                               {
        Figure target = findConnectableFigure(x, y, drawing);
        Figure start = fStartConnector.owner();

        if (target != null
             && fConnection != null
             && target.canConnect()
             && !target.includes(start)
             && fConnection.canConnect(start, target))
            return target;
        return null;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Connector CH.ifa.draw.standard.ConnectionTool.getEndConnector ( ) [inline, protected]

Definition at line 268 of file ConnectionTool.java.

                                          {
        return fEndConnector;
    }
Connector CH.ifa.draw.standard.ConnectionTool.getStartConnector ( ) [inline, protected]

Definition at line 264 of file ConnectionTool.java.

                                            {
        return fStartConnector;
    }
Connector CH.ifa.draw.standard.ConnectionTool.getTarget ( ) [inline, protected]

Definition at line 272 of file ConnectionTool.java.

                                    {
        return fConnectorTarget;
    }
void CH.ifa.draw.standard.AbstractTool.keyDown ( KeyEvent  evt,
int  key 
) [inline, inherited]

Handles key down events in the drawing view.

Definition at line 84 of file AbstractTool.java.

                                               {
    }
void CH.ifa.draw.standard.ConnectionTool.mouseDown ( MouseEvent  e,
int  x,
int  y 
) [inline]

Manipulates connections in a context dependent way.

If the mouse down hits a figure start a new connection. If the mousedown hits a connection split a segment or join two segments.

Reimplemented from CH.ifa.draw.standard.AbstractTool.

Definition at line 82 of file ConnectionTool.java.

    {
        int ex = e.getX();
        int ey = e.getY();
        fTarget = findConnectionStart(ex, ey, drawing());
        if (fTarget != null) {
            fStartConnector = findConnector(ex, ey, fTarget);
            if (fStartConnector != null) {
                Point p = new Point(ex, ey);
                fConnection = createConnection();
                fConnection.startPoint(p.x, p.y);
                fConnection.endPoint(p.x, p.y);
                view().add(fConnection);
            }
        }
        else {
            ConnectionFigure connection = findConnection(ex, ey, drawing());
            if (connection != null) {
                if (!connection.joinSegments(ex, ey)) {
                    fSplitPoint = connection.splitSegment(ex, ey);
                    fEditedConnection = connection;
                } else {
                    fEditedConnection = null;
                }
            }
        }
    }

Here is the call graph for this function:

void CH.ifa.draw.standard.ConnectionTool.mouseDrag ( MouseEvent  e,
int  x,
int  y 
) [inline]

Adjust the created connection or split segment.

Reimplemented from CH.ifa.draw.standard.AbstractTool.

Definition at line 113 of file ConnectionTool.java.

                                                      {
        Point p = new Point(e.getX(), e.getY());
        if (fConnection != null) {
            trackConnectors(e, x, y);
            if (fConnectorTarget != null)
                p = Geom.center(fConnectorTarget.displayBox());
            fConnection.endPoint(p.x, p.y);
        }
        else if (fEditedConnection != null) {
            Point pp = new Point(x, y);
            fEditedConnection.setPointAt(pp, fSplitPoint);
        }
    }

Here is the call graph for this function:

void CH.ifa.draw.standard.ConnectionTool.mouseMove ( MouseEvent  e,
int  x,
int  y 
) [inline]

Handles mouse move events in the drawing view.

Reimplemented from CH.ifa.draw.standard.AbstractTool.

Definition at line 73 of file ConnectionTool.java.

                                                      {
        trackConnectors(e, x, y);
    }

Here is the call graph for this function:

void CH.ifa.draw.standard.ConnectionTool.mouseUp ( MouseEvent  e,
int  x,
int  y 
) [inline]

Connects the figures if the mouse is released over another figure.

Reimplemented from CH.ifa.draw.standard.AbstractTool.

Definition at line 131 of file ConnectionTool.java.

                                                    {
        Figure c = null;
        if (fStartConnector != null)
            c = findTarget(e.getX(), e.getY(), drawing());

        if (c != null) {
            fEndConnector = findConnector(e.getX(), e.getY(), c);
            if (fEndConnector != null) {
                fConnection.connectStart(fStartConnector);
                fConnection.connectEnd(fEndConnector);
                fConnection.updateConnection();
            }
        } else if (fConnection != null)
            view().remove(fConnection);

        fConnection = null;
        fStartConnector = fEndConnector = null;
        editor().toolDone();
    }

Here is the call graph for this function:

void CH.ifa.draw.standard.ConnectionTool.trackConnectors ( MouseEvent  e,
int  x,
int  y 
) [inline, protected]

Definition at line 212 of file ConnectionTool.java.

                                                               {
        Figure c = null;

        if (fStartConnector == null)
            c = findSource(x, y, drawing());
        else
            c = findTarget(x, y, drawing());

        // track the figure containing the mouse
        if (c != fTarget) {
            if (fTarget != null)
                fTarget.connectorVisibility(false);
            fTarget = c;
            if (fTarget != null)
                fTarget.connectorVisibility(true);
        }

        Connector cc = null;
        if (c != null)
            cc = findConnector(e.getX(), e.getY(), c);
        if (cc != fConnectorTarget)
            fConnectorTarget = cc;

        view().checkDamage();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

DrawingView CH.ifa.draw.standard.AbstractTool.view ( ) [inline, inherited]

Gets the tool's view.

Definition at line 104 of file AbstractTool.java.

                              {
        return fView;
    }

Here is the caller graph for this function:


Member Data Documentation

int CH.ifa.draw.standard.AbstractTool.fAnchorX [protected, inherited]

The position of the initial mouse down.

Definition at line 27 of file AbstractTool.java.

Definition at line 27 of file AbstractTool.java.

the currently created figure

Definition at line 46 of file ConnectionTool.java.

Definition at line 39 of file ConnectionTool.java.

ConnectionFigure CH.ifa.draw.standard.ConnectionTool.fEditedConnection = null [private]

the currently edited connection

Definition at line 56 of file ConnectionTool.java.

Definition at line 38 of file ConnectionTool.java.

the prototypical figure that is used to create new connections.

Definition at line 62 of file ConnectionTool.java.

the currently manipulated connection point

Definition at line 51 of file ConnectionTool.java.

the anchor point of the interaction

Definition at line 37 of file ConnectionTool.java.

Definition at line 41 of file ConnectionTool.java.

DrawingView CH.ifa.draw.standard.AbstractTool.fView [protected, inherited]

Definition at line 22 of file AbstractTool.java.


The documentation for this class was generated from the following file: