]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/JScrollPaneSG.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scenegraph.swing / src / org / simantics / scenegraph / swing / JScrollPaneSG.java
1 package org.simantics.scenegraph.swing;
2
3 import java.awt.AWTEvent;
4 import java.awt.Component;
5 import java.awt.Point;
6
7 import javax.swing.JComponent;
8 import javax.swing.JScrollBar;
9 import javax.swing.JScrollPane;
10 import javax.swing.JViewport;
11 import javax.swing.ScrollPaneLayout;
12
13 import org.simantics.scenegraph.INode;
14
15 public class JScrollPaneSG extends JScrollPane implements JComponentSG {
16
17         private static final long serialVersionUID = 1941565557888406721L;
18
19         final private INode node;
20         
21         public JScrollPaneSG(Component view, INode node) {
22                 
23                 this.node = node;
24         setLayout(new ScrollPaneLayout.UIResource());
25         setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_AS_NEEDED);
26         setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED);
27         setViewport(createViewport());
28         setVerticalScrollBar(createVerticalScrollBar());
29         setHorizontalScrollBar(createHorizontalScrollBar());
30         if (view != null) {
31             setViewportView(view);
32         }
33         
34         setOpaque(true);
35
36         updateUI();
37
38         if (!this.getComponentOrientation().isLeftToRight()) {
39             viewport.setViewPosition(new Point(Integer.MAX_VALUE, 0));
40         }
41                 
42         }
43
44         class ScrollBarSG extends ScrollBar implements JComponentSG {
45
46                 private static final long serialVersionUID = 209426441282352819L;
47
48                 ScrollBarSG(int flags) {
49                         super(flags);
50                 }
51
52                 @Override
53                 public boolean contains(int eventX, int eventY) {
54                         return JComponentUtils.contains(eventX, eventY, this, node);
55                 }
56                 
57                 @Override
58                 public boolean containsTransformed(Point p) {
59                         return super.contains(p.x, p.y);
60                 }
61                 
62                 @Override
63                 public JComponent getComponent() {
64                         return this;
65                 }
66                 
67                 @Override
68                 protected void processEvent(AWTEvent e) {
69                         super.processEvent(JComponentUtils.relocate(e, this, node));
70                 }
71                 
72         }
73         
74         @Override
75         public JScrollBar createVerticalScrollBar() {
76                 return new ScrollBarSG(JScrollBar.VERTICAL);
77         }
78
79         @Override
80         public JScrollBar createHorizontalScrollBar() {
81                 return new ScrollBarSG(JScrollBar.HORIZONTAL);
82         }
83
84         @Override
85         public boolean contains(int eventX, int eventY) {
86                 return JComponentUtils.contains(eventX, eventY, this, node);
87         }
88         
89         @Override
90         public boolean containsTransformed(Point p) {
91                 return super.contains(p.x, p.y);
92         }
93         
94         @Override
95         public JComponent getComponent() {
96                 return this;
97         }
98         
99         @Override
100         protected JViewport createViewport() {
101                 return new JViewportSG(node);
102         }
103         
104 }