use of org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm 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();
}
}
Aggregations