author | serb |
Mon, 24 Sep 2012 21:33:41 +0400 | |
changeset 13993 | 8b3fe3d8badb |
parent 13143 | 31c70a66a053 |
child 17414 | 3e422b97a601 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
||
27 |
package sun.lwawt; |
|
28 |
||
29 |
import java.awt.Adjustable; |
|
30 |
import java.awt.Scrollbar; |
|
31 |
import java.awt.event.AdjustmentEvent; |
|
32 |
import java.awt.event.AdjustmentListener; |
|
33 |
import java.awt.peer.ScrollbarPeer; |
|
34 |
||
35 |
import javax.swing.JScrollBar; |
|
36 |
||
37 |
final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar> |
|
38 |
implements ScrollbarPeer, AdjustmentListener { |
|
39 |
||
40 |
//JScrollBar fires two changes with firePropertyChange (one for old value |
|
41 |
// and one for new one. |
|
42 |
// We save the last value and don't fire event if not changed. |
|
43 |
private int currentValue; |
|
44 |
||
45 |
LWScrollBarPeer(final Scrollbar target, |
|
46 |
final PlatformComponent platformComponent) { |
|
47 |
super(target, platformComponent); |
|
48 |
} |
|
49 |
||
50 |
@Override |
|
51 |
protected JScrollBar createDelegate() { |
|
52 |
return new JScrollBar(); |
|
53 |
} |
|
54 |
||
55 |
@Override |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12047
diff
changeset
|
56 |
void initializeImpl() { |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12047
diff
changeset
|
57 |
super.initializeImpl(); |
12047 | 58 |
final Scrollbar target = getTarget(); |
59 |
setValues(target.getValue(), target.getVisibleAmount(), |
|
60 |
target.getMinimum(), target.getMaximum()); |
|
61 |
||
62 |
final int orientation = target.getOrientation(); |
|
63 |
final JScrollBar delegate = getDelegate(); |
|
64 |
synchronized (getDelegateLock()) { |
|
65 |
delegate.setOrientation(orientation == Scrollbar.HORIZONTAL |
|
66 |
? Adjustable.HORIZONTAL |
|
67 |
: Adjustable.VERTICAL); |
|
68 |
delegate.addAdjustmentListener(this); |
|
69 |
} |
|
70 |
} |
|
71 |
||
72 |
@Override |
|
73 |
public void setValues(final int value, final int visible, final int minimum, |
|
74 |
final int maximum) { |
|
75 |
synchronized (getDelegateLock()) { |
|
76 |
currentValue = value; |
|
77 |
getDelegate().setValues(value, visible, minimum, maximum); |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
@Override |
|
82 |
public void setLineIncrement(final int l) { |
|
83 |
synchronized (getDelegateLock()) { |
|
84 |
getDelegate().setUnitIncrement(l); |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
@Override |
|
89 |
public void setPageIncrement(final int l) { |
|
90 |
synchronized (getDelegateLock()) { |
|
91 |
getDelegate().setBlockIncrement(l); |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
// Peer also registered as a listener for ComponentDelegate component |
|
96 |
@Override |
|
97 |
public void adjustmentValueChanged(final AdjustmentEvent e) { |
|
98 |
final int value = e.getValue(); |
|
99 |
synchronized (getDelegateLock()) { |
|
100 |
if (currentValue == value) { |
|
101 |
return; |
|
102 |
} |
|
103 |
currentValue = value; |
|
104 |
} |
|
105 |
getTarget().setValueIsAdjusting(e.getValueIsAdjusting()); |
|
106 |
getTarget().setValue(value); |
|
107 |
postEvent(new AdjustmentEvent(getTarget(), e.getID(), |
|
108 |
e.getAdjustmentType(), value, |
|
109 |
e.getValueIsAdjusting())); |
|
110 |
} |
|
111 |
} |