]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.scenegraph.example;\r
13 \r
14 import javax.swing.RepaintManager;\r
15 import javax.swing.UIManager;\r
16 import javax.swing.UnsupportedLookAndFeelException;\r
17 import javax.swing.UIManager.LookAndFeelInfo;\r
18 \r
19 import org.eclipse.swt.events.DisposeEvent;\r
20 import org.eclipse.swt.events.DisposeListener;\r
21 import org.eclipse.swt.widgets.Composite;\r
22 import org.eclipse.ui.part.ViewPart;\r
23 \r
24 import org.simantics.scenegraph.g2d.nodes.TransformNode;\r
25 import org.simantics.scenegraph.swing.SliderNode;\r
26 \r
27 public class G2DLocalView extends ViewPart {\r
28         SGComponent c;\r
29         \r
30         protected boolean rotate = true;\r
31         protected TransformNode transform = null;\r
32         protected TransformNode transform2 = null;\r
33         protected SliderNode sn1 = null;\r
34         protected SliderNode sn2 = null;\r
35         protected SampleThread t = new SampleThread() {\r
36                 public void repaint() {\r
37                         if(c != null) {\r
38                                 RepaintManager rm = RepaintManager.currentManager(c.getCanvas());\r
39                                 rm.markCompletelyDirty(c.getCanvas());\r
40                         }\r
41                 }\r
42         };\r
43 \r
44         @Override\r
45         public void createPartControl(Composite parent) {\r
46                 try {\r
47                     for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {\r
48                         if ("Nimbus".equals(info.getName())) {\r
49                             UIManager.setLookAndFeel(info.getClassName());\r
50                             break;\r
51                         }\r
52                     }\r
53                 } catch (UnsupportedLookAndFeelException e) {\r
54                     // handle exception\r
55                 } catch (ClassNotFoundException e) {\r
56                     // handle exception\r
57                 } catch (InstantiationException e) {\r
58                     // handle exception\r
59                 } catch (IllegalAccessException e) {\r
60                     // handle exception\r
61                 }\r
62                 \r
63             c = new SGComponent(parent, 0);\r
64             c.syncPopulate();\r
65             \r
66                 c.addDisposeListener(new DisposeListener(){\r
67                         @Override\r
68                         public void widgetDisposed(DisposeEvent e) {\r
69                                 t.stop();\r
70                         }});\r
71                 \r
72             c.getCanvas().setSceneGraph(t.sg);\r
73             \r
74             c.initListeners();\r
75 \r
76                 t.start();\r
77         }\r
78         \r
79         @Override\r
80         public void setFocus() {\r
81                 c.setFocus();\r
82         }\r
83         \r
84 }\r