Search in sources :

Example 1 with VerticalLayoutAlgorithm

use of org.eclipse.zest.layouts.algorithms.VerticalLayoutAlgorithm in project archi by archimatetool.

the class SimpleSwingExample method start.

public void start() {
    // $NON-NLS-1$
    mainFrame = new JFrame("Simple Swing Layout Example");
    toolBar = new JToolBar();
    mainFrame.getContentPane().setLayout(new BorderLayout());
    mainFrame.getContentPane().add(toolBar, BorderLayout.NORTH);
    // $NON-NLS-1$
    lblProgress = new JLabel("Progress: ");
    mainFrame.getContentPane().add(lblProgress, BorderLayout.SOUTH);
    createMainPanel();
    mainFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            stop();
            mainFrame.dispose();
        }
    });
    // $NON-NLS-1$
    btnContinuous = new JToggleButton("continuous", false);
    // $NON-NLS-1$
    btnAsynchronous = new JToggleButton("asynchronous", false);
    toolBar.add(btnContinuous);
    toolBar.add(btnAsynchronous);
    // $NON-NLS-1$
    btnStop = new JButton("Stop");
    btnStop.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            stop();
        }
    });
    toolBar.add(btnStop);
    // $NON-NLS-1$
    JButton btnCreateGraph = new JButton("New graph");
    btnCreateGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            stop();
            createGraph(true);
        }
    });
    toolBar.add(btnCreateGraph);
    // $NON-NLS-1$
    JButton btnCreateTree = new JButton("New tree");
    btnCreateTree.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            stop();
            createGraph(false);
        }
    });
    toolBar.add(btnCreateTree);
    createGraph(false);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    mainFrame.setLocation((int) (screenSize.getWidth() - INITIAL_PANEL_WIDTH) / 2, (int) (screenSize.getHeight() - INITIAL_PANEL_HEIGHT) / 2);
    mainFrame.pack();
    mainFrame.setVisible(true);
    mainFrame.repaint();
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                SPRING = new SpringLayoutAlgorithm(LayoutStyles.NONE);
                TREE_VERT = new TreeLayoutAlgorithm(LayoutStyles.NONE);
                TREE_HORIZ = new HorizontalTreeLayoutAlgorithm(LayoutStyles.NONE);
                RADIAL = new RadialLayoutAlgorithm(LayoutStyles.NONE);
                GRID = new GridLayoutAlgorithm(LayoutStyles.NONE);
                HORIZ = new HorizontalLayoutAlgorithm(LayoutStyles.NONE);
                VERT = new VerticalLayoutAlgorithm(LayoutStyles.NONE);
                SPRING.setIterations(1000);
                // initialize layouts
                TREE_VERT.setComparator(new Comparator() {

                    @Override
                    public int compare(Object o1, Object o2) {
                        if (o1 instanceof Comparable && o2 instanceof Comparable) {
                            return ((Comparable) o1).compareTo(o2);
                        }
                        return 0;
                    }
                });
                GRID.setRowPadding(20);
                // $NON-NLS-1$
                addAlgorithm(SPRING, "Spring", false);
                // $NON-NLS-1$
                addAlgorithm(TREE_VERT, "Tree-V", false);
                // $NON-NLS-1$
                addAlgorithm(TREE_HORIZ, "Tree-H", false);
                // $NON-NLS-1$
                addAlgorithm(RADIAL, "Radial", false);
                // $NON-NLS-1$
                addAlgorithm(GRID, "Grid", false);
                // $NON-NLS-1$
                addAlgorithm(HORIZ, "Horiz", false);
                // $NON-NLS-1$
                addAlgorithm(VERT, "Vert", false);
                for (int i = 0; i < algorithms.size(); i++) {
                    final LayoutAlgorithm algorithm = (LayoutAlgorithm) algorithms.get(i);
                    final String algorithmName = (String) algorithmNames.get(i);
                    // final boolean algorithmAnimate = ((Boolean)algorithmAnimates.get(i)).booleanValue();
                    JButton algorithmButton = new JButton(algorithmName);
                    algorithmButton.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            currentLayoutAlgorithm = algorithm;
                            currentLayoutAlgorithmName = algorithmName;
                            algorithm.setEntityAspectRatio((double) mainPanel.getWidth() / (double) mainPanel.getHeight());
                            // animate = algorithmAnimate;
                            performLayout();
                        }
                    });
                    toolBar.add(algorithmButton);
                }
            }
        });
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InvocationTargetException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) HorizontalTreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) RadialLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm) VerticalLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.VerticalLayoutAlgorithm) HorizontalLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalLayoutAlgorithm) Comparator(java.util.Comparator) BorderLayout(java.awt.BorderLayout) JToggleButton(javax.swing.JToggleButton) HorizontalTreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm) VerticalLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.VerticalLayoutAlgorithm) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm) SpringLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm) HorizontalLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalLayoutAlgorithm) RadialLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm) JFrame(javax.swing.JFrame) SpringLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm) JLabel(javax.swing.JLabel) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) HorizontalTreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm) InvocationTargetException(java.lang.reflect.InvocationTargetException) GridLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent)

Aggregations

BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Comparator (java.util.Comparator)1 JButton (javax.swing.JButton)1 JFrame (javax.swing.JFrame)1 JLabel (javax.swing.JLabel)1 JToggleButton (javax.swing.JToggleButton)1 JToolBar (javax.swing.JToolBar)1 LayoutAlgorithm (org.eclipse.zest.layouts.LayoutAlgorithm)1 GridLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm)1 HorizontalLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.HorizontalLayoutAlgorithm)1 HorizontalTreeLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm)1 RadialLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm)1 SpringLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm)1 TreeLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm)1