use of org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm in project hale by halestudio.
the class TypeCellSelectionDialog method setupViewer.
/**
* @see eu.esdihumboldt.hale.ui.util.selector.AbstractViewerSelectionDialog#setupViewer(org.eclipse.jface.viewers.StructuredViewer,
* java.lang.Object)
*/
@Override
protected void setupViewer(final GraphViewer viewer, Cell initialSelection) {
// content and label provider
viewer.setContentProvider(new ReverseCellGraphContentProvider());
viewer.setLabelProvider(new GraphLabelProvider(viewer, HaleUI.getServiceProvider()));
// layout
final TreeLayoutAlgorithm layout = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
viewer.getControl().addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
int width = viewer.getControl().getSize().x;
layout.setNodeSpace(new Dimension((width - 10) / 3, 30));
}
});
viewer.setLayoutAlgorithm(layout, true);
viewer.applyLayout();
// input and selection
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
viewer.setInput(as.getAlignment().getTypeCells());
if (initialSelection != null)
viewer.setSelection(new StructuredSelection(initialSelection));
}
use of org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm in project hale by halestudio.
the class AbstractMappingView method createLayout.
/**
* Create the initial layout to use
*
* @return the layout
*/
protected LayoutAlgorithm createLayout() {
LayoutAlgorithm layout;
layout = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
return layout;
}
use of org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm 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.TreeLayoutAlgorithm in project archi by archimatetool.
the class Graph method applyLayoutInternal.
private void applyLayoutInternal() {
hasPendingLayoutRequest = false;
if ((this.getNodes().size() == 0)) {
return;
}
int layoutStyle = 0;
if ((nodeStyle & ZestStyles.NODES_NO_LAYOUT_RESIZE) > 0) {
layoutStyle = LayoutStyles.NO_LAYOUT_NODE_RESIZING;
}
if (layoutAlgorithm == null) {
layoutAlgorithm = new TreeLayoutAlgorithm(layoutStyle);
}
layoutAlgorithm.setStyle(layoutAlgorithm.getStyle() | layoutStyle);
// calculate the size for the layout algorithm
Dimension d = this.getViewport().getSize();
d.width = d.width - 10;
d.height = d.height - 10;
if (this.preferredSize.width >= 0) {
d.width = preferredSize.width;
}
if (this.preferredSize.height >= 0) {
d.height = preferredSize.height;
}
if (d.isEmpty()) {
return;
}
LayoutRelationship[] connectionsToLayout = getConnectionsToLayout(nodes);
LayoutEntity[] nodesToLayout = getNodesToLayout(getNodes());
try {
if ((nodeStyle & ZestStyles.NODES_NO_LAYOUT_ANIMATION) == 0 && animationEnabled) {
Animation.markBegin();
}
layoutAlgorithm.applyLayout(nodesToLayout, connectionsToLayout, 0, 0, d.width, d.height, false, false);
if ((nodeStyle & ZestStyles.NODES_NO_LAYOUT_ANIMATION) == 0 && animationEnabled) {
Animation.run(animationTime);
}
getLightweightSystem().getUpdateManager().performUpdate();
} catch (InvalidLayoutConfiguration e) {
e.printStackTrace();
}
}
use of org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm in project hale by halestudio.
the class GraphMLDialog method open.
/**
* Opens the dialog for displaying the graph
*
* @throws IOException may be thrown if the graph string from the database
* can fails to convert
*/
public void open() throws IOException {
Shell parent = super.getParent();
final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.MIN | SWT.MODELESS);
shell.setFocus();
shell.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
shell.setMinimized(true);
}
@Override
public void focusGained(FocusEvent e) {
// ignore
}
});
shell.setLayout(GridLayoutFactory.fillDefaults().create());
shell.setText(getText());
final Composite viewerContainer = new Composite(shell, SWT.EMBEDDED);
viewerContainer.setLayout(new FillLayout());
viewerContainer.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
TinkerGraph tgraph = new TinkerGraph();
GraphMLReader greader = new GraphMLReader(tgraph);
ByteArrayInputStream in;
in = new ByteArrayInputStream(graphString.getBytes(("UTF-8")));
greader.inputGraph(in);
GraphViewer viewer = new GraphViewer(viewerContainer, SWT.NONE);
TreeLayoutAlgorithm la = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
viewer.setLabelProvider(new GraphMLLabelProvider());
viewer.setContentProvider(new GraphMLContentProvider());
viewer.setInput(tgraph.getEdges());
viewer.setLayoutAlgorithm(la, true);
viewer.applyLayout();
viewerContainer.pack();
viewerContainer.setVisible(true);
shell.open();
Display display = parent.getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
Aggregations