]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/example/G2DLocalView.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph.swing / src / org / simantics / scenegraph / example / G2DLocalView.java
diff --git a/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/example/G2DLocalView.java b/bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/example/G2DLocalView.java
new file mode 100644 (file)
index 0000000..6be31d1
--- /dev/null
@@ -0,0 +1,84 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.scenegraph.example;\r
+\r
+import javax.swing.RepaintManager;\r
+import javax.swing.UIManager;\r
+import javax.swing.UnsupportedLookAndFeelException;\r
+import javax.swing.UIManager.LookAndFeelInfo;\r
+\r
+import org.eclipse.swt.events.DisposeEvent;\r
+import org.eclipse.swt.events.DisposeListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.ui.part.ViewPart;\r
+\r
+import org.simantics.scenegraph.g2d.nodes.TransformNode;\r
+import org.simantics.scenegraph.swing.SliderNode;\r
+\r
+public class G2DLocalView extends ViewPart {\r
+       SGComponent c;\r
+       \r
+       protected boolean rotate = true;\r
+       protected TransformNode transform = null;\r
+       protected TransformNode transform2 = null;\r
+       protected SliderNode sn1 = null;\r
+       protected SliderNode sn2 = null;\r
+       protected SampleThread t = new SampleThread() {\r
+               public void repaint() {\r
+                       if(c != null) {\r
+                               RepaintManager rm = RepaintManager.currentManager(c.getCanvas());\r
+                               rm.markCompletelyDirty(c.getCanvas());\r
+                       }\r
+               }\r
+       };\r
+\r
+       @Override\r
+       public void createPartControl(Composite parent) {\r
+               try {\r
+                   for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {\r
+                       if ("Nimbus".equals(info.getName())) {\r
+                           UIManager.setLookAndFeel(info.getClassName());\r
+                           break;\r
+                       }\r
+                   }\r
+               } catch (UnsupportedLookAndFeelException e) {\r
+                   // handle exception\r
+               } catch (ClassNotFoundException e) {\r
+                   // handle exception\r
+               } catch (InstantiationException e) {\r
+                   // handle exception\r
+               } catch (IllegalAccessException e) {\r
+                   // handle exception\r
+               }\r
+               \r
+           c = new SGComponent(parent, 0);\r
+           c.syncPopulate();\r
+           \r
+               c.addDisposeListener(new DisposeListener(){\r
+                       @Override\r
+                       public void widgetDisposed(DisposeEvent e) {\r
+                               t.stop();\r
+                       }});\r
+               \r
+           c.getCanvas().setSceneGraph(t.sg);\r
+           \r
+           c.initListeners();\r
+\r
+               t.start();\r
+       }\r
+       \r
+       @Override\r
+       public void setFocus() {\r
+               c.setFocus();\r
+       }\r
+       \r
+}\r