|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package javax.microedition.lcdui; |
|
18 |
|
19 import org.eclipse.swt.events.*; |
|
20 import org.eclipse.swt.graphics.Rectangle; |
|
21 import org.eclipse.swt.widgets.Composite; |
|
22 import org.eclipse.swt.widgets.ScrollBar; |
|
23 |
|
24 /** |
|
25 * Implementation of <code>ScrolledComposite</code> control. |
|
26 */ |
|
27 class ScrolledComposite extends Composite implements FocusListener, |
|
28 ControlListener { |
|
29 |
|
30 private ScrollBar vBar; |
|
31 |
|
32 /** |
|
33 * Constructor. |
|
34 * |
|
35 * @param parent |
|
36 * @param style |
|
37 */ |
|
38 public ScrolledComposite(Composite parent, int style) { |
|
39 super(parent, style); |
|
40 vBar = parent.getVerticalBar(); |
|
41 if (vBar != null) { |
|
42 vBar.addSelectionListener(new ScrollBarListener()); |
|
43 } |
|
44 |
|
45 // addKeyListener(new ScrollKeyListener()); |
|
46 addTraverseListener(new ScrollTraverseListener()); |
|
47 addControlListener(new ScrollControlListener()); |
|
48 } |
|
49 |
|
50 /** |
|
51 * Set the position of this Composite relative to its parent. |
|
52 * |
|
53 * @param x X-coordinate |
|
54 * @param y Y-coordinate |
|
55 */ |
|
56 void setOrigin(int x, int y, boolean keyNavigation) { |
|
57 //setRedraw(false); |
|
58 |
|
59 if (vBar != null) { |
|
60 if (keyNavigation) { |
|
61 vBar.setSelection(y); |
|
62 } |
|
63 y = -vBar.getSelection(); |
|
64 } |
|
65 else { |
|
66 y = 0; |
|
67 } |
|
68 |
|
69 this.setLocation(x, y); |
|
70 //setRedraw(true); |
|
71 } |
|
72 |
|
73 /** |
|
74 * Updates range and thumb size of the ScrollBars. |
|
75 */ |
|
76 void updateScrollbar(int height) { |
|
77 Rectangle clientArea = getParent().getClientArea(); |
|
78 if (vBar != null) { |
|
79 vBar.setMinimum(0); |
|
80 vBar.setMaximum(height); |
|
81 vBar.setThumb(clientArea.height); |
|
82 } |
|
83 } |
|
84 |
|
85 private class ScrollBarListener implements SelectionListener { |
|
86 |
|
87 public void widgetDefaultSelected(SelectionEvent e) { |
|
88 Logger.verbose(e.toString()); |
|
89 } |
|
90 |
|
91 public void widgetSelected(SelectionEvent e) { |
|
92 Logger.verbose(e.toString()); |
|
93 } |
|
94 } |
|
95 |
|
96 private class ScrollKeyListener implements KeyListener { |
|
97 |
|
98 public void keyPressed(KeyEvent e) { |
|
99 Logger.verbose(e.toString()); |
|
100 } |
|
101 |
|
102 public void keyReleased(KeyEvent e) { |
|
103 Logger.verbose(e.toString()); |
|
104 } |
|
105 } |
|
106 |
|
107 private class ScrollTraverseListener implements TraverseListener { |
|
108 |
|
109 public void keyTraversed(TraverseEvent e) { |
|
110 } |
|
111 } |
|
112 |
|
113 private class ScrollControlListener implements ControlListener { |
|
114 |
|
115 public void controlMoved(ControlEvent e) { |
|
116 } |
|
117 |
|
118 public void controlResized(ControlEvent e) { |
|
119 } |
|
120 } |
|
121 |
|
122 public void focusGained(FocusEvent e) { |
|
123 // makeVisible((Control) e.widget); |
|
124 } |
|
125 |
|
126 public void focusLost(FocusEvent e) { |
|
127 } |
|
128 |
|
129 public void controlMoved(ControlEvent e) { |
|
130 updateScrollbar(0); |
|
131 } |
|
132 |
|
133 public void controlResized(ControlEvent e) { |
|
134 updateScrollbar(0); |
|
135 } |
|
136 |
|
137 } |