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