Search in sources :

Example 1 with SpringLayoutAlgorithm

use of org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm 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)

Example 2 with SpringLayoutAlgorithm

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

the class ZestView method doCreatePartControl.

@Override
protected void doCreatePartControl(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    parent.setLayout(layout);
    fLabel = new CLabel(parent, SWT.NONE);
    fLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fGraphViewer = new ZestGraphViewer(parent, SWT.NONE);
    fGraphViewer.getGraphControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    // spring is the default - we do need to set this here!
    fGraphViewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
    // fGraphViewer.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
    // fGraphViewer.setLayoutAlgorithm(new RadialLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
    // fGraphViewer.setLayoutAlgorithm(new HorizontalTreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
    // Graph selection listener
    fGraphViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // Update actions
            updateActions();
            // Need to do this in order for Tabbed Properties View to update on Selection
            getSite().getSelectionProvider().setSelection(event.getSelection());
        }
    });
    // Double-click
    fGraphViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            fDrillDownManager.goInto();
        }
    });
    fDrillDownManager = new DrillDownManager(this);
    makeActions();
    hookContextMenu();
    registerGlobalActions();
    makeLocalToolBar();
    // This will update previous Undo/Redo text if View was closed before
    updateActions();
    // Register selections
    getSite().setSelectionProvider(getViewer());
    // Listen to global selections to update the viewer
    getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fGraphViewer.getControl(), HELP_ID);
    // Initialise with whatever is selected in the workbench
    ISelection selection = getSite().getWorkbenchWindow().getSelectionService().getSelection();
    selectionChanged(null, selection);
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) SpringLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm) GridLayout(org.eclipse.swt.layout.GridLayout) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent)

Aggregations

SpringLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm)2 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 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 CLabel (org.eclipse.swt.custom.CLabel)1