Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add draw2d Examples #103

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions examples/org.eclipse.draw2d.examples/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.draw2d.examples</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
10 changes: 10 additions & 0 deletions examples/org.eclipse.draw2d.examples/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.draw2d.examples
Bundle-Version: 3.15.300.qualifier
Bundle-Localization: plugin
Require-Bundle: org.eclipse.draw2d
Bundle-Vendor: %Plugin.providerName
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.eclipse.draw2d.examples
5 changes: 5 additions & 0 deletions examples/org.eclipse.draw2d.examples/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties
14 changes: 14 additions & 0 deletions examples/org.eclipse.draw2d.examples/plugin.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
###############################################################################
# Copyright (c) 2007, 2009 IBM Corporation and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
Plugin.name=GEF Classic Draw2d Examples
Plugin.providerName=Eclipse GEF
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*******************************************************************************
* Copyright (c) 2005, 2023 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.draw2d.examples;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.IFigure;

/**
* A baseclass for draw2d examples.
*
* @author hudsonr
*/
public abstract class AbstractExample {

private static final String COURIER2 = "Courier"; //$NON-NLS-1$
private static final String HELVETICA = "Helvetica"; //$NON-NLS-1$

protected static final Font COURIER = new Font(null, COURIER2, 9, 0);
protected static final Font BOLD = new Font(null, HELVETICA, 10, SWT.BOLD);
protected static final Font ITALICS = new Font(null, HELVETICA, 10, SWT.ITALIC);
protected static final Font HEADING_1 = new Font(null, HELVETICA, 15, SWT.BOLD);

private FigureCanvas fc;
private IFigure contents;

private Shell shell;

protected void run() {
Display d = Display.getDefault();
shell = new Shell(d, getShellStyle());
String appName = getClass().getName();
appName = appName.substring(appName.lastIndexOf('.') + 1);
shell.setText(appName);
shell.setLayout(new GridLayout(2, false));
setFigureCanvas(new FigureCanvas(shell));
contents = createContents();
getFigureCanvas().setContents(contents);
getFigureCanvas().getViewport().setContentsTracksHeight(true);
getFigureCanvas().getViewport().setContentsTracksWidth(true);
getFigureCanvas().setLayoutData(new GridData(GridData.FILL_BOTH));
hookShell(shell);
sizeShell();
shell.open();
while (!shell.isDisposed()) {
while (!d.readAndDispatch()) {
d.sleep();
}
}
}

@SuppressWarnings("static-method") // allow children to provide their own shell style
protected int getShellStyle() {
return SWT.SHELL_TRIM;
}

protected void sizeShell() {
shell.pack();
}

protected abstract IFigure createContents();

protected FigureCanvas getFigureCanvas() {
return fc;
}

protected IFigure getContents() {
return contents;
}

public Shell getShell() {
return shell;
}

protected void hookShell(Shell shell) {
}

protected void setFigureCanvas(FigureCanvas canvas) {
this.fc = canvas;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.draw2d.examples;

import org.eclipse.swt.graphics.Image;

/**
* Created on :Sep 26, 2002
*
* @author hudsonr
* @since 2.0
*/
public final class ExampleImages {

public static final Image GEORGE = new Image(null, ExampleImages.class.getResourceAsStream("images/george.gif")); //$NON-NLS-1$

private ExampleImages() {
throw new UnsupportedOperationException("Utility class should not be instantiated"); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
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;

/**
* 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); //$NON-NLS-1$

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

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)); //$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)); //$NON-NLS-1$
}

return f;
}

public static IFigure createToolbarLayout() {
Figure f = new Figure();
f.setBorder(new GroupBoxBorder("Toolbar")); //$NON-NLS-1$
f.setLayoutManager(new ToolbarLayout());
f.add(createFlowLayoutPanel());
f.add(createFlowLayoutPanel());
return f;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.draw2d.examples;

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) {

Display d = new Display();
Shell shell = new Shell(d);
shell.setLayout(new FillLayout());

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

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

}

}
Loading