From d99fac83ac0b02c2e8d1e93c18a25a3c92539726 Mon Sep 17 00:00:00 2001 From: yvesf Date: Mon, 9 May 2011 23:37:38 +0200 Subject: Vor-Ergebnisse Studienarbeit --- de.dhbw.horb.ksm.simulator/.classpath | 9 + de.dhbw.horb.ksm.simulator/.gitignore | 1 + de.dhbw.horb.ksm.simulator/.project | 28 ++++ .../.settings/org.eclipse.jdt.core.prefs | 8 + de.dhbw.horb.ksm.simulator/META-INF/MANIFEST.MF | 16 ++ de.dhbw.horb.ksm.simulator/build.properties | 7 + .../icons/16/ksm-simulator.png | Bin 0 -> 1101 bytes .../icons/32/ksm-simulator.png | Bin 0 -> 2200 bytes .../lib/org.swtchart.ext_0.7.0.v20110128.jar | Bin 0 -> 94661 bytes .../lib/org.swtchart_0.7.0.v20110128.jar | Bin 0 -> 173774 bytes de.dhbw.horb.ksm.simulator/plugin.xml | 26 +++ .../src/de/dhbw/horb/simulator/Activator.java | 50 ++++++ .../perspective/SimulatorPerspective.java | 33 ++++ .../de/dhbw/horb/simulator/view/SimulatorView.java | 184 +++++++++++++++++++++ 14 files changed, 362 insertions(+) create mode 100644 de.dhbw.horb.ksm.simulator/.classpath create mode 100644 de.dhbw.horb.ksm.simulator/.gitignore create mode 100644 de.dhbw.horb.ksm.simulator/.project create mode 100644 de.dhbw.horb.ksm.simulator/.settings/org.eclipse.jdt.core.prefs create mode 100644 de.dhbw.horb.ksm.simulator/META-INF/MANIFEST.MF create mode 100644 de.dhbw.horb.ksm.simulator/build.properties create mode 100644 de.dhbw.horb.ksm.simulator/icons/16/ksm-simulator.png create mode 100644 de.dhbw.horb.ksm.simulator/icons/32/ksm-simulator.png create mode 100644 de.dhbw.horb.ksm.simulator/lib/org.swtchart.ext_0.7.0.v20110128.jar create mode 100644 de.dhbw.horb.ksm.simulator/lib/org.swtchart_0.7.0.v20110128.jar create mode 100644 de.dhbw.horb.ksm.simulator/plugin.xml create mode 100644 de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/Activator.java create mode 100644 de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/perspective/SimulatorPerspective.java create mode 100644 de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/view/SimulatorView.java (limited to 'de.dhbw.horb.ksm.simulator') diff --git a/de.dhbw.horb.ksm.simulator/.classpath b/de.dhbw.horb.ksm.simulator/.classpath new file mode 100644 index 0000000..65582bc --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/de.dhbw.horb.ksm.simulator/.gitignore b/de.dhbw.horb.ksm.simulator/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/de.dhbw.horb.ksm.simulator/.project b/de.dhbw.horb.ksm.simulator/.project new file mode 100644 index 0000000..797d7bb --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/.project @@ -0,0 +1,28 @@ + + + de.dhbw.horb.ksm.simulator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/de.dhbw.horb.ksm.simulator/.settings/org.eclipse.jdt.core.prefs b/de.dhbw.horb.ksm.simulator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..4741363 --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon May 09 15:47:49 CEST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/de.dhbw.horb.ksm.simulator/META-INF/MANIFEST.MF b/de.dhbw.horb.ksm.simulator/META-INF/MANIFEST.MF new file mode 100644 index 0000000..727b6a8 --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: KSM Simulator Prototype +Bundle-SymbolicName: de.dhbw.horb.ksm.simulator;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: de.dhbw.horb.simulator.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + de.dhbw.horb.ksm.core;bundle-version="1.0.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: de.dhbw.horb.ksm.model.api, + org.eclipse.gef.commands +Bundle-ClassPath: lib/org.swtchart_0.7.0.v20110128.jar, + lib/org.swtchart.ext_0.7.0.v20110128.jar, + . diff --git a/de.dhbw.horb.ksm.simulator/build.properties b/de.dhbw.horb.ksm.simulator/build.properties new file mode 100644 index 0000000..2ba7ae7 --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + lib/org.swtchart_0.7.0.v20110128.jar,\ + lib/org.swtchart.ext_0.7.0.v20110128.jar diff --git a/de.dhbw.horb.ksm.simulator/icons/16/ksm-simulator.png b/de.dhbw.horb.ksm.simulator/icons/16/ksm-simulator.png new file mode 100644 index 0000000..89d3780 Binary files /dev/null and b/de.dhbw.horb.ksm.simulator/icons/16/ksm-simulator.png differ diff --git a/de.dhbw.horb.ksm.simulator/icons/32/ksm-simulator.png b/de.dhbw.horb.ksm.simulator/icons/32/ksm-simulator.png new file mode 100644 index 0000000..554de7e Binary files /dev/null and b/de.dhbw.horb.ksm.simulator/icons/32/ksm-simulator.png differ diff --git a/de.dhbw.horb.ksm.simulator/lib/org.swtchart.ext_0.7.0.v20110128.jar b/de.dhbw.horb.ksm.simulator/lib/org.swtchart.ext_0.7.0.v20110128.jar new file mode 100644 index 0000000..cb0d4e6 Binary files /dev/null and b/de.dhbw.horb.ksm.simulator/lib/org.swtchart.ext_0.7.0.v20110128.jar differ diff --git a/de.dhbw.horb.ksm.simulator/lib/org.swtchart_0.7.0.v20110128.jar b/de.dhbw.horb.ksm.simulator/lib/org.swtchart_0.7.0.v20110128.jar new file mode 100644 index 0000000..6ee142b Binary files /dev/null and b/de.dhbw.horb.ksm.simulator/lib/org.swtchart_0.7.0.v20110128.jar differ diff --git a/de.dhbw.horb.ksm.simulator/plugin.xml b/de.dhbw.horb.ksm.simulator/plugin.xml new file mode 100644 index 0000000..2808e8c --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/plugin.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + diff --git a/de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/Activator.java b/de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/Activator.java new file mode 100644 index 0000000..274c2dd --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/Activator.java @@ -0,0 +1,50 @@ +package de.dhbw.horb.simulator; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "Simulator"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/perspective/SimulatorPerspective.java b/de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/perspective/SimulatorPerspective.java new file mode 100644 index 0000000..c040bdc --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/perspective/SimulatorPerspective.java @@ -0,0 +1,33 @@ +package de.dhbw.horb.simulator.perspective; + +import org.eclipse.ui.IFolderLayout; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +import de.dhbw.horb.simulator.view.SimulatorView; + +public class SimulatorPerspective implements IPerspectiveFactory { + public static final String ID = "ksm.simulator.perspectives.SimulatorPerspective"; //$NON-NLS-N$ + private IPageLayout factory; + + public SimulatorPerspective() { + super(); + } + + public void createInitialLayout(IPageLayout factory) { + this.factory = factory; + factory.setEditorAreaVisible(true); + addViews(); + } + + private void addViews() { + IFolderLayout topLeft = factory.createFolder("topLeft", //$NON-NLS-N$ + IPageLayout.LEFT, 0.30f, factory.getEditorArea()); + + topLeft.addView(de.dhbw.horb.ksm.core.view.Navigator.VIEW_ID); + + IFolderLayout topRight = factory.createFolder("bottom", + IPageLayout.BOTTOM, 0.30f, factory.getEditorArea()); + topRight.addView(SimulatorView.VIEW_ID); + } +} \ No newline at end of file diff --git a/de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/view/SimulatorView.java b/de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/view/SimulatorView.java new file mode 100644 index 0000000..2cdf737 --- /dev/null +++ b/de.dhbw.horb.ksm.simulator/src/de/dhbw/horb/simulator/view/SimulatorView.java @@ -0,0 +1,184 @@ +package de.dhbw.horb.simulator.view; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.EventObject; + +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CommandStackListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.IPage; +import org.eclipse.ui.part.MessagePage; +import org.eclipse.ui.part.Page; +import org.eclipse.ui.part.PageBook; +import org.eclipse.ui.part.PageBookView; +import org.eclipse.ui.part.PageSite; +import org.swtchart.Chart; +import org.swtchart.ILineSeries; +import org.swtchart.ISeries.SeriesType; + +import de.dhbw.horb.ksm.core.editor.model.ModelProperties; +import de.dhbw.horb.ksm.core.editor.ui.DiagramEditor; +import de.dhbw.horb.ksm.model.api.Node; + +public class SimulatorView extends PageBookView { + public final static String VIEW_ID = "ksm.simulator.views.SimulatorView"; + + private final String message = "No compatible Editor selected"; + + @Override + public void setFocus() { + + } + + @Override + protected IPage createDefaultPage(PageBook book) { + MessagePage page = new MessagePage(); + initPage(page); + page.createControl(book); + page.setMessage(message); + return page; + } + + @Override + protected PageRec doCreatePage(IWorkbenchPart part) { + if (part instanceof DiagramEditor) { + DiagramEditor editor = (DiagramEditor) part; + SimulatorPage page = new SimulatorPage(editor); + page.init(new PageSite(getViewSite())); + page.createControl(getPageBook()); + return new PageRec(part, page); + } + return null; + } + + @Override + protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { + pageRecord.page.dispose(); + pageRecord.dispose(); + } + + @Override + protected IWorkbenchPart getBootstrapPart() { + IWorkbenchPage page = getSite().getPage(); + if (page != null) { + return page.getActiveEditor(); + } + return null; + } + + @Override + protected boolean isImportant(IWorkbenchPart part) { + return (part instanceof DiagramEditor); + } + + private class SimulatorPage extends Page implements CommandStackListener { + private Chart chart; + private ILineSeries xPositionSeries; + private final DiagramEditor editor; + private ILineSeries yPositionSeries; + + public SimulatorPage(DiagramEditor editor) { + this.editor = editor; + } + + @Override + public void createControl(Composite parent) { + chart = new Chart(parent, SWT.NONE); + + chart.getTitle().setVisible(false); + chart.getAxisSet().getXAxis(0).getTitle().setText("KSM Knoten"); + chart.getAxisSet().getYAxis(0).getTitle().setText("Position"); + + xPositionSeries = (ILineSeries) chart.getSeriesSet().createSeries( + SeriesType.LINE, "X-Position"); + xPositionSeries.setLineColor(Display.getCurrent().getSystemColor( + SWT.COLOR_BLUE)); + yPositionSeries = (ILineSeries) chart.getSeriesSet().createSeries( + SeriesType.LINE, "Y-Position"); + yPositionSeries.setLineColor(Display.getCurrent().getSystemColor( + SWT.COLOR_RED)); + + // Enable Strings as X-Axis Ticks + chart.getAxisSet().getXAxes()[0].enableCategory(true); + + refresh(); + + ((CommandStack) editor.getAdapter(CommandStack.class)) + .addCommandStackListener(this); + } + + @Override + public void commandStackChanged(EventObject event) { + refresh(); + } + + private void refresh() { + ArrayList listXY = new ArrayList(); + ArrayList listCaptions = new ArrayList(); + for (Node n : editor.getModel().getAllNodes()) { + BigInteger locationX = n + .getProperties() + .getInteger( + ModelProperties.INSTANCE + .stripType(ModelProperties.INSTANCE.NODE_VISUAL_LOCATION_X)); + BigInteger locationY = n + .getProperties() + .getInteger( + ModelProperties.INSTANCE + .stripType(ModelProperties.INSTANCE.NODE_VISUAL_LOCATION_Y)); + listXY.add(new int[] { locationX.intValue(), + locationY.intValue() }); + + String caption = n + .getProperties() + .getString( + ModelProperties.INSTANCE + .stripType(ModelProperties.INSTANCE.NODE_VISUAL_CAPTION)); + listCaptions.add(caption); + } + double[] seriesX = new double[listXY.size()]; + double[] seriesY = new double[listXY.size()]; + String[] xCaption = new String[listXY.size()]; + for (int i = 0; i < listXY.size(); i++) { + seriesX[i] = listXY.get(i)[0]; + seriesY[i] = listXY.get(i)[1]; + xCaption[i] = listCaptions.get(i); + } + + // Set Y-Axis Data + xPositionSeries.setYSeries(seriesX); + yPositionSeries.setYSeries(seriesY); + + // Set X-Axis Description + chart.getAxisSet().getXAxes()[0].setCategorySeries(xCaption); + + // adjust the axis range and redraw + chart.getAxisSet().adjustRange(); + chart.redraw(); + } + + @Override + public Control getControl() { + return chart; + } + + @Override + public void setFocus() { + chart.setFocus(); + } + + @Override + public void dispose() { + ((CommandStack) editor.getAdapter(CommandStack.class)) + .removeCommandStackListener(this); + super.dispose(); + chart.dispose(); + } + } +} -- cgit v1.2.1