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();
}
}
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);
}
Aggregations