Skip to content

Commit

Permalink
more clean-up of draw2d examples
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl committed Jul 31, 2023
1 parent 6e2f189 commit 6c037e5
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,51 @@
*******************************************************************************/
package org.eclipse.draw2d.examples;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.GroupBoxBorder;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;

/**
* A factory for figures. Created on :Sep 26, 2002
*
*
* @author hudsonr
* @since 2.0
*/
public final class ExampleUtil {

static final Font FONT_LARGE = new Font(null, "Arial", 16, SWT.BOLD);
static final Font FONT_LARGE = new Font(null, "Arial", 16, SWT.BOLD); //$NON-NLS-1$

public static IFigure createFlowLayoutPanel() {
Figure f = new Figure();

f.setBorder(new GroupBoxBorder("FlowLayout"));
f.setBorder(new GroupBoxBorder("FlowLayout")); //$NON-NLS-1$
f.setLayoutManager(new FlowLayout());

for (int i = 0; i < 5; i++)
f.add(new Label("Label " + i, ExampleImages.GEORGE));
for (int i = 0; i < 5; i++) {
f.add(new Label("Label " + i, ExampleImages.GEORGE)); //$NON-NLS-1$
}

// Label l = new Label("A really wide label is here");
// l.setBorder(new LineBorder());
// l.setFont(FONT_LARGE);
// f.add(l);

for (int i = 6; i < 10; i++)
f.add(new Label("Label " + i, ExampleImages.GEORGE));
for (int i = 6; i < 10; i++) {
f.add(new Label("Label " + i, ExampleImages.GEORGE)); //$NON-NLS-1$
}

return f;
}

public static IFigure createToolbarLayout() {
Figure f = new Figure();
f.setBorder(new GroupBoxBorder("Toolbar"));
f.setBorder(new GroupBoxBorder("Toolbar")); //$NON-NLS-1$
f.setLayoutManager(new ToolbarLayout());
f.add(createFlowLayoutPanel());
f.add(createFlowLayoutPanel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
*******************************************************************************/
package org.eclipse.draw2d.examples;

import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.Label;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.Label;

public class HelloWorld {

public static void main(String[] args) {
Expand All @@ -25,14 +26,16 @@ public static void main(String[] args) {
shell.setLayout(new FillLayout());

FigureCanvas canvas = new FigureCanvas(shell);
canvas.setContents(new Label("Hello World"));
canvas.setContents(new Label("Hello World")); //$NON-NLS-1$

shell.setText("Draw2d");
shell.setText("Draw2d"); //$NON-NLS-1$
shell.setSize(200, 100);
shell.open();
while (!shell.isDisposed())
while (!d.readAndDispatch())
while (!shell.isDisposed()) {
while (!d.readAndDispatch()) {
d.sleep();
}
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,16 @@ public void paint(Graphics graphics) {
super.paint(graphics);
Rectangle b = getBounds();
Point p = b.getCenter().translate(-22, -15);
graphics.drawString("y:" + b.y() + "h:" + b.height(), p);
graphics.drawString("y:" + b.y() + "h:" + b.height(), p); //$NON-NLS-1$ //$NON-NLS-2$
p.setY(p.y() + 12);
graphics.drawString("x:" + b.x() + "w:" + b.width(), p);
graphics.drawString("x:" + b.x() + "w:" + b.width(), p); //$NON-NLS-1$ //$NON-NLS-2$
}
}

class TestFigure extends Figure {

private static final int INITAL_OBSTACLE_COUNT = 5;

Map obstacleMap = new HashMap();
boolean showSegs = false;

public TestFigure() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.draw2d.examples.connections;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.ConnectionEndpointLocator;
Expand Down Expand Up @@ -129,9 +131,10 @@ protected IFigure createContents() {
}

/**
* @see org.eclipse.draw2d.examples.AbstractExample#hookShell()
* @see org.eclipse.draw2d.examples.AbstractExample#hookShell(Shell shell)
*/
protected void hookShell() {
@Override
protected void hookShell(Shell shell) {
getFigureCanvas().setSize(820, 440);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.draw2d.AbsoluteBendpoint;
import org.eclipse.draw2d.BendpointConnectionRouter;
import org.eclipse.draw2d.ChopboxAnchor;
Expand All @@ -30,15 +40,6 @@
import org.eclipse.draw2d.graph.Edge;
import org.eclipse.draw2d.graph.Node;
import org.eclipse.draw2d.graph.NodeList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* @author Daniel Lee
Expand Down Expand Up @@ -184,9 +185,7 @@ static PolylineConnection connection(Edge e) {
return conn;
}

/**
* @see org.eclipse.graph.AbstractExample#createContents()
*/
@SuppressWarnings("static-method")
protected IFigure getContents() {
return null;
}
Expand All @@ -208,9 +207,6 @@ protected FigureCanvas getFigureCanvas() {
*/
protected abstract String[] getGraphMethods();

/**
* @see org.eclipse.graph.AbstractExample#hookShell()
*/
protected void hookShell() {
Composite composite = new Composite(shell, 0);
composite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import java.lang.reflect.Method;

import org.eclipse.swt.graphics.Font;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
Expand All @@ -23,7 +25,6 @@
import org.eclipse.draw2d.graph.Edge;
import org.eclipse.draw2d.graph.Node;
import org.eclipse.draw2d.graph.Subgraph;
import org.eclipse.swt.graphics.Font;

/**
* @author hudsonr
Expand All @@ -39,7 +40,7 @@ public class CompoundGraphDemo extends AbstractGraphDemo {
*/
public static Figure buildGraph(CompoundDirectedGraph graph) {
Figure contents = new Panel();
contents.setFont(new Font(null, "Tahoma", 10, 0));
contents.setFont(new Font(null, "Tahoma", 10, 0)); //$NON-NLS-1$
contents.setBackgroundColor(ColorConstants.white);
contents.setLayoutManager(new XYLayout());

Expand Down Expand Up @@ -134,13 +135,13 @@ protected IFigure getContents() {
graph = (CompoundDirectedGraph) (CompoundGraphTests.class.getMethod(graphMethod, int.class).invoke(null,
Integer.valueOf(graphDirection)));
} catch (Exception e) {
System.out.println("Could not build graph");
System.out.println("Could not build graph"); //$NON-NLS-1$
}
return buildGraph(graph);
}

/**
* @see org.eclipse.graph.demo.GraphDemo#getGraphMethods()
* @see org.eclipse.draw2d.examples.graph.AbstractGraphDemo#getGraphMethods()
*/
@Override
protected String[] getGraphMethods() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static void main(String[] args) {
}

/**
* @see org.eclipse.graph.demo.GraphDemo#getGraphMethods()
* @see org.eclipse.draw2d.examples.graph.AbstractGraphDemo#getGraphMethods()
*/
@Override
protected String[] getGraphMethods() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@
*******************************************************************************/
package org.eclipse.draw2d.examples.layouts;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.OrderedLayout;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.Triangle;
import org.eclipse.draw2d.examples.AbstractExample;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
Expand All @@ -34,6 +23,18 @@
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.OrderedLayout;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.Triangle;
import org.eclipse.draw2d.examples.AbstractExample;

/**
* @author hudsonr Created on Apr 30, 2003
*/
Expand Down Expand Up @@ -124,7 +125,7 @@ protected IFigure createContents() {
}

/**
* @see org.eclipse.draw2d.examples.AbstractExample#hookShell()
* @see org.eclipse.draw2d.examples.AbstractExample#hookShell(Shell shell)
*/
@Override
protected void hookShell(Shell shell) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
*******************************************************************************/
package org.eclipse.draw2d.examples.path;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.widgets.Display;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Polyline;
Expand All @@ -18,11 +24,6 @@
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.widgets.Display;

public class PathFigure extends Polyline {

Expand Down Expand Up @@ -65,7 +66,7 @@ private void drawShape(Graphics g, boolean fill) {

TextLayout textLayout = new TextLayout(Display.getDefault());
textLayout.setFont(g.getFont());
textLayout.setText("zoom" + (g instanceof ScaledGraphics ? "[e]" : "[n]"));
textLayout.setText("zoom" + (g instanceof ScaledGraphics ? "[e]" : "[n]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
TextStyle textStyle = new TextStyle();
textStyle.underline = true;
textStyle.underlineColor = ColorConstants.blue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.draw2d.examples.scrollpane;

import org.eclipse.swt.graphics.Cursor;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.CompoundBorder;
import org.eclipse.draw2d.Cursors;
Expand All @@ -26,7 +28,6 @@
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Cursor;

public class InternalFrame extends LabeledContainer {

Expand Down Expand Up @@ -113,7 +114,7 @@ public void mouseMoved(MouseEvent me) {
Rectangle figBounds = getBounds();
Point mouseLocation = me.getLocation();
if (!getBounds().contains(mouseLocation)) {
System.out.println("Error");
System.out.println("Error"); //$NON-NLS-1$
}
if (!figBounds.contains(mouseLocation)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
*******************************************************************************/
package org.eclipse.draw2d.examples.swt;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
Expand All @@ -24,6 +21,10 @@
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.Label;

public class InheritBackgroundExample {

static Shell shell;
Expand Down
Loading

0 comments on commit 6c037e5

Please sign in to comment.