Search in sources :

Example 1 with Drawable

use of net.sf.sdedit.drawable.Drawable in project abstools by abstools.

the class PaintDevice method computeAxes.

public void computeAxes(int leftAxis) {
    int n = diagram.getNumberOfLifelines();
    int axis = leftAxis;
    int mainWidth = diagram.getConfiguration().getMainLifelineWidth();
    int subWidth = diagram.getConfiguration().getSubLifelineWidth();
    for (int i = 0; i < n; i++) {
        if (i > 0) {
            axis += diagram.getConfiguration().getGlue();
        }
        for (ExtensibleDrawable view : diagram.getLifelineAt(i).getAllViews()) {
            if (view instanceof Line) {
                view.setLeft(axis + mainWidth / 2);
            } else {
                switch(view.getLifeline().getDirection()) {
                    case CENTER:
                        view.setLeft(axis);
                        break;
                    case LEFT:
                        view.setLeft(axis - view.getLifeline().getSideLevel() * subWidth);
                        break;
                    case RIGHT:
                        view.setLeft(axis + mainWidth + (view.getLifeline().getSideLevel() - 1) * subWidth);
                }
            }
        }
        Lifeline lifeline = diagram.getLifelineAt(i);
        Drawable head = lifeline.getHead();
        int offset = mainWidth / 2;
        // int offset = lifeline.getView().getWidth() / 2;
        head.setLeft(axis - head.getWidth() / 2 + offset);
        if (lifeline.getCross() != null) {
            lifeline.getCross().setLeft(axis - diagram.getConfiguration().getDestructorWidth() / 2 + mainWidth / 2);
        }
        if (i < diagram.getNumberOfLifelines() - 1) {
            axis += head.getWidth() / 2 + diagram.getLifelineAt(i + 1).getHead().getWidth() / 2;
        } else {
            axis += head.getWidth() / 2 + mainWidth / 2;
        }
        // to the left of the (i+1)-th lifeline
        for (SequenceElement arrow : leftOf.get(i)) {
            int left = arrow.getLeftLimit().getRight();
            int level;
            if (arrow.getRightLimit() == rightBound) {
                level = 0;
            } else {
                level = arrow.getRightLimit().getLifeline().getSideLevel();
            }
            axis = Math.max(axis, left + arrow.getSpace() + arrow.getWidth() + level * subWidth);
        }
    }
    rightBound.setLeft(axis);
}
Also used : Line(net.sf.sdedit.drawable.Line) ExtensibleDrawable(net.sf.sdedit.drawable.ExtensibleDrawable) SequenceElement(net.sf.sdedit.drawable.SequenceElement) Drawable(net.sf.sdedit.drawable.Drawable) ExtensibleDrawable(net.sf.sdedit.drawable.ExtensibleDrawable)

Example 2 with Drawable

use of net.sf.sdedit.drawable.Drawable in project abstools by abstools.

the class PanelPaintDevice method mouseMoved.

/**
 * This method is called when the mouse moved over the panel. If it has
 * exited or entered a drawable object,
 * {@linkplain PanelPaintDeviceListener}s are notified.
 *
 * @param e
 */
public void mouseMoved(MouseEvent e) {
    if (interactive) {
        JPanel zp = panel.getZoomPane().getPanel();
        Point point = e.getPoint();
        if (lastDrawableMovedOver != null) {
            if (!lastDrawableMovedOver.contains(point)) {
                for (PanelPaintDeviceListener listener : listeners) {
                    listener.mouseExitedDrawable(lastDrawableMovedOver);
                    zp.setCursor(Cursor.getDefaultCursor());
                }
            } else {
                return;
            }
        }
        lastDrawableMovedOver = null;
        for (Drawable drawable : this) {
            if (!(drawable instanceof Fragment)) {
                if (drawable.contains(point)) {
                    lastDrawableMovedOver = drawable;
                    for (PanelPaintDeviceListener listener : listeners) {
                        if (listener.mouseEnteredDrawable(drawable)) {
                            zp.setCursor(HAND_CURSOR);
                        }
                    }
                    return;
                }
            }
        }
    }
}
Also used : JPanel(javax.swing.JPanel) Drawable(net.sf.sdedit.drawable.Drawable) ExtensibleDrawable(net.sf.sdedit.drawable.ExtensibleDrawable) Point(java.awt.Point) Fragment(net.sf.sdedit.drawable.Fragment)

Example 3 with Drawable

use of net.sf.sdedit.drawable.Drawable in project abstools by abstools.

the class Tab method scrollToCurrentDrawable.

private void scrollToCurrentDrawable() {
    int begin = textArea.getCurrentLineBegin();
    Diagram diagram = getDiagram();
    if (diagram != null) {
        PanelPaintDevice ppd = (PanelPaintDevice) diagram.getPaintDevice();
        Drawable drawable = diagram.getDrawableForState(begin);
        if (drawable instanceof Arrow) {
            Arrow arrow = (Arrow) drawable;
            Point textPosition = arrow.getTextPosition();
            int x = textPosition != null ? textPosition.x : arrow.getLeft();
            float xratio = 1F * x / ppd.getWidth();
            int y = drawable.getTop();
            float yratio = 1F * y / ppd.getHeight();
            zoomPane.scrollToPosition(xratio, yratio);
        } else {
            if (drawable != null) {
                int x = drawable.getLeft();
                float xratio = 1F * x / ppd.getWidth();
                int y = drawable.getTop();
                float yratio = 1F * y / ppd.getHeight();
                zoomPane.scrollToPosition(xratio, yratio);
            } else {
                int caret = textArea.getCaretPosition();
                if (textArea.getText().substring(caret).trim().length() == 0) {
                    zoomPane.scrollToBottom();
                }
            }
        }
    }
}
Also used : Arrow(net.sf.sdedit.drawable.Arrow) Drawable(net.sf.sdedit.drawable.Drawable) PanelPaintDevice(net.sf.sdedit.ui.PanelPaintDevice) Point(java.awt.Point) Point(java.awt.Point) Diagram(net.sf.sdedit.diagram.Diagram)

Example 4 with Drawable

use of net.sf.sdedit.drawable.Drawable in project abstools by abstools.

the class ExportMapAction method generateMapFile.

private void generateMapFile(Diagram diagram, TextHandler textHandler, String mapName, File target) throws IOException {
    String encoding = ConfigurationManager.getGlobalConfiguration().getFileEncoding();
    FileOutputStream fos = new FileOutputStream(target);
    OutputStreamWriter osw = new OutputStreamWriter(fos, encoding);
    PrintWriter pw = new PrintWriter(osw);
    pw.println("<!-- Generated by Quick Sequence Diagram Editor -->");
    pw.println("<!-- encoding: " + encoding + " -->");
    pw.println("<!-- You may append '#!href=\"<url>\"' to an object declaration\nin order to set" + " the 'href' attribute of an AREA tag -->");
    pw.println("<map id=\"" + mapName + "\" name=\"" + mapName + "\">");
    for (Lifeline lifeline : diagram.getAllLifelines()) {
        String annotation = textHandler.getAnnotation(lifeline);
        String file = lifeline.getName();
        if (annotation != null) {
            String[] href = Grep.parse("^.*?href=\"(.*?)\".*$", annotation);
            if (href != null) {
                file = href[0];
            }
        }
        Drawable drawable = lifeline.getHead();
        int x1 = drawable.getLeft();
        int y1 = drawable.getTop();
        int x2 = drawable.getRight();
        int y2 = drawable.getBottom();
        String coords = x1 + "," + y1 + "," + x2 + "," + y2;
        pw.println("  <area shape=\"rect\" coords=\"" + coords + "\"" + " href=\"" + file + "\"/>");
    }
    pw.println("</map>");
    pw.flush();
    pw.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) Lifeline(net.sf.sdedit.diagram.Lifeline) Drawable(net.sf.sdedit.drawable.Drawable) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Aggregations

Drawable (net.sf.sdedit.drawable.Drawable)4 Point (java.awt.Point)2 ExtensibleDrawable (net.sf.sdedit.drawable.ExtensibleDrawable)2 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 JPanel (javax.swing.JPanel)1 Diagram (net.sf.sdedit.diagram.Diagram)1 Lifeline (net.sf.sdedit.diagram.Lifeline)1 Arrow (net.sf.sdedit.drawable.Arrow)1 Fragment (net.sf.sdedit.drawable.Fragment)1 Line (net.sf.sdedit.drawable.Line)1 SequenceElement (net.sf.sdedit.drawable.SequenceElement)1 PanelPaintDevice (net.sf.sdedit.ui.PanelPaintDevice)1