Search in sources :

Example 6 with SimpleNode

use of org.eclipse.zest.layouts.exampleStructures.SimpleNode in project archi by archimatetool.

the class SimpleSwingExample method createMainPanel.

private void createMainPanel() {
    // see below for class definition
    mainPanel = new MainPanel();
    mainPanel.setPreferredSize(new Dimension(INITIAL_PANEL_WIDTH, INITIAL_PANEL_HEIGHT));
    mainPanel.setBackground(Color.WHITE);
    mainPanel.setLayout(null);
    mainFrame.getContentPane().add(new JScrollPane(mainPanel), BorderLayout.CENTER);
    mainPanel.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            selectedEntity = null;
            for (Iterator iter = entities.iterator(); iter.hasNext() && selectedEntity == null; ) {
                SimpleNode entity = (SimpleNode) iter.next();
                double x = entity.getX();
                double y = entity.getY();
                double w = entity.getWidth();
                double h = entity.getHeight();
                Rectangle2D.Double rect = new Rectangle2D.Double(x, y, w, h);
                if (rect.contains(e.getX(), e.getY())) {
                    selectedEntity = entity;
                }
            }
            if (selectedEntity != null) {
                mouseDownPoint = e.getPoint();
                selectedEntityPositionAtMouseDown = new Point((int) selectedEntity.getX(), (int) selectedEntity.getY());
            } else {
                mouseDownPoint = null;
                selectedEntityPositionAtMouseDown = null;
            }
            updateGUI();
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            selectedEntity = null;
            mouseDownPoint = null;
            selectedEntityPositionAtMouseDown = null;
            updateGUI();
        }
    });
    mainPanel.addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseDragged(MouseEvent e) {
        // if (selectedEntity != null) {
        // //TODO: Add mouse moving
        // //selectedEntity.setLocationInLayout(selectedEntityPositionAtMouseDown.x + dx, selectedEntityPositionAtMouseDown.y + dy);
        // updateGUI();
        // }
        }

        @Override
        public void mouseMoved(MouseEvent e) {
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Rectangle2D(java.awt.geom.Rectangle2D) Dimension(java.awt.Dimension) Point(java.awt.Point) LayoutBendPoint(org.eclipse.zest.layouts.LayoutBendPoint) MouseMotionListener(java.awt.event.MouseMotionListener) SimpleNode(org.eclipse.zest.layouts.exampleStructures.SimpleNode) Iterator(java.util.Iterator)

Example 7 with SimpleNode

use of org.eclipse.zest.layouts.exampleStructures.SimpleNode in project archi by archimatetool.

the class SimpleSWTExample method createTreeGraphRecursive.

private void createTreeGraphRecursive(SimpleNode currentParentNode, int maxChildren, int maxLevel, int level, boolean random) {
    if (level > maxLevel) {
        return;
    }
    int numChildren = random ? (int) (Math.random() * maxChildren + 1) : maxChildren;
    for (int child = 0; child < numChildren; child++) {
        SimpleNode childNode = createSimpleNode(getNextID());
        entities.add(childNode);
        SimpleRelationship rel = new SimpleRelationship(currentParentNode, childNode, false);
        childNode.addRelationship(rel);
        currentParentNode.addRelationship(rel);
        relationships.add(rel);
        SimpleRelationship.setDefaultSize(2);
        createTreeGraphRecursive(childNode, maxChildren, maxLevel, level + 1, random);
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) LayoutBendPoint(org.eclipse.zest.layouts.LayoutBendPoint) SimpleRelationship(org.eclipse.zest.layouts.exampleStructures.SimpleRelationship) SimpleNode(org.eclipse.zest.layouts.exampleStructures.SimpleNode)

Aggregations

SimpleNode (org.eclipse.zest.layouts.exampleStructures.SimpleNode)7 LayoutBendPoint (org.eclipse.zest.layouts.LayoutBendPoint)5 Iterator (java.util.Iterator)4 Point (org.eclipse.swt.graphics.Point)4 ArrayList (java.util.ArrayList)2 SimpleRelationship (org.eclipse.zest.layouts.exampleStructures.SimpleRelationship)2 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 MouseMotionListener (java.awt.event.MouseMotionListener)1 Rectangle2D (java.awt.geom.Rectangle2D)1 List (java.util.List)1 JScrollPane (javax.swing.JScrollPane)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)1 Color (org.eclipse.swt.graphics.Color)1