-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
XTextAreaPeer.java
1487 lines (1281 loc) · 50.4 KB
/
XTextAreaPeer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.awt.X11;
import java.awt.*;
import java.awt.peer.TextAreaPeer;
import java.awt.event.*;
import javax.swing.event.DocumentListener;
import javax.swing.event.DocumentEvent;
import javax.swing.JTextArea;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JScrollBar;
import javax.swing.plaf.ComponentUI;
import com.sun.java.swing.plaf.motif.MotifTextAreaUI;
import javax.swing.plaf.UIResource;
import javax.swing.UIDefaults;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.CompoundBorder;
import javax.swing.border.AbstractBorder;
import javax.swing.JButton;
import javax.swing.JViewport;
import javax.swing.InputMap;
import javax.swing.SwingUtilities;
import javax.swing.TransferHandler;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicScrollBarUI;
import javax.swing.plaf.basic.BasicScrollPaneUI;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.text.Caret;
import javax.swing.text.DefaultCaret;
import javax.swing.text.JTextComponent;
import javax.swing.plaf.BorderUIResource;
import java.awt.im.InputMethodRequests;
import sun.awt.AWTAccessor;
import sun.awt.SunToolkit;
final class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
private final AWTTextPane textPane;
private final AWTTextArea jtext;
private final boolean firstChangeSkipped;
private final JavaMouseEventHandler javaMouseEventHandler =
new JavaMouseEventHandler(this);
/**
* Create a Text area.
*/
XTextAreaPeer(TextArea target) {
super(target);
// some initializations require that target be set even
// though init(target) has not been called
this.target = target;
//ComponentAccessor.enableEvents(target,AWTEvent.MOUSE_WHEEL_EVENT_MASK);
String text = target.getText();
jtext = new AWTTextArea(text, this);
jtext.setWrapStyleWord(true);
jtext.getDocument().addDocumentListener(jtext);
XToolkit.specialPeerMap.put(jtext,this);
textPane = new AWTTextPane(jtext,this, target.getParent());
setBounds(x, y, width, height, SET_BOUNDS);
textPane.setVisible(true);
textPane.validate();
AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
foreground = compAccessor.getForeground(target);
if (foreground == null) {
foreground = SystemColor.textText;
}
setForeground(foreground);
background = compAccessor.getBackground(target);
if (background == null) {
if (target.isEditable()) background = SystemColor.text;
else background = SystemColor.control;
}
setBackground(background);
if (!target.isBackgroundSet()) {
// This is a way to set the background color of the TextArea
// without calling setBackground - go through accessor
compAccessor.setBackground(target, background);
}
if (!target.isForegroundSet()) {
target.setForeground(SystemColor.textText);
}
setFont(font);
// set the text of this object to the text of its target
setTextImpl(target.getText()); //?? should this be setText
int start = target.getSelectionStart();
int end = target.getSelectionEnd();
// Fix for 5100200
// Restoring Motif behaviour
// Since the end position of the selected text can be greater than the length of the text,
// so we should set caret to max position of the text
setCaretPosition(Math.min(end, text.length()));
if (end > start) {
// Should be called after setText() and setCaretPosition()
select(start, end);
}
setEditable(target.isEditable());
setScrollBarVisibility();
// After this line we should not change the component's text
firstChangeSkipped = true;
compAccessor.setPeer(textPane, this);
}
@Override
public void dispose() {
XToolkit.specialPeerMap.remove(jtext);
// visible caret has a timer thread which must be stopped
jtext.getCaret().setVisible(false);
jtext.removeNotify();
super.dispose();
}
/*
* The method overrides one from XComponentPeer
* If ignoreSubComponents=={@code true} it calls super.
* If ignoreSubComponents=={@code false} it uses the XTextArea machinery
* to change cursor appropriately. In particular it changes the cursor to
* default if over scrollbars.
*/
@Override
public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) {
if (ignoreSubComponents ||
javaMouseEventHandler == null) {
super.pSetCursor(cursor, true);
return;
}
Point cursorPos = new Point();
((XGlobalCursorManager)XGlobalCursorManager.getCursorManager()).getCursorPos(cursorPos);
final Point onScreen = getLocationOnScreen();
Point localPoint = new Point(cursorPos.x - onScreen.x, cursorPos.y - onScreen.y );
javaMouseEventHandler.setPointerToUnderPoint(localPoint);
javaMouseEventHandler.setCursor();
}
private void setScrollBarVisibility() {
int visibility = ((TextArea)target).getScrollbarVisibility();
jtext.setLineWrap(false);
if (visibility == TextArea.SCROLLBARS_NONE) {
textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
jtext.setLineWrap(true);
}
else if (visibility == TextArea.SCROLLBARS_BOTH) {
textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
}
else if (visibility == TextArea.SCROLLBARS_VERTICAL_ONLY) {
textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jtext.setLineWrap(true);
}
else if (visibility == TextArea.SCROLLBARS_HORIZONTAL_ONLY) {
textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
}
}
/**
* Compute minimum size.
*/
@Override
public Dimension getMinimumSize() {
return getMinimumSize(10, 60);
}
@Override
public Dimension getPreferredSize(int rows, int cols) {
return getMinimumSize(rows, cols);
}
/**
* @see java.awt.peer.TextAreaPeer
*/
@Override
public Dimension getMinimumSize(int rows, int cols) {
/* Dimension d = null;
if (jtext != null) {
d = jtext.getMinimumSize(rows,cols);
}
return d;
*/
int vsbwidth=0;
int hsbheight=0;
JScrollBar vsb = textPane.getVerticalScrollBar();
if (vsb != null) {
vsbwidth = vsb.getMinimumSize().width;
}
JScrollBar hsb = textPane.getHorizontalScrollBar();
if (hsb != null) {
hsbheight = hsb.getMinimumSize().height;
}
Font f = jtext.getFont();
FontMetrics fm = jtext.getFontMetrics(f);
return new Dimension(fm.charWidth('0') * cols + /*2*XMARGIN +*/ vsbwidth,
fm.getHeight() * rows + /*2*YMARGIN +*/ hsbheight);
}
@Override
public boolean isFocusable() {
return true;
}
@Override
public void setVisible(boolean b) {
super.setVisible(b);
if (textPane != null)
textPane.setVisible(b);
}
void repaintText() {
jtext.repaintNow();
}
@Override
public void focusGained(FocusEvent e) {
super.focusGained(e);
jtext.forwardFocusGained(e);
}
@Override
public void focusLost(FocusEvent e) {
super.focusLost(e);
jtext.forwardFocusLost(e);
}
/**
* Paint the component
* this method is called when the repaint instruction has been used
*/
@Override
public void repaint() {
if (textPane != null) {
//textPane.validate();
textPane.repaint();
}
}
@Override
void paintPeer(final Graphics g) {
if (textPane != null) {
textPane.paint(g);
}
}
@Override
public void setBounds(int x, int y, int width, int height, int op) {
super.setBounds(x, y, width, height, op);
if (textPane != null) {
/*
* Fixed 6277332, 6198290:
* the coordinates is coming (to peer): relatively to closest HW parent
* the coordinates is setting (to textPane): relatively to closest ANY parent
* the parent of peer is target.getParent()
* the parent of textPane is the same
* see 6277332, 6198290 for more information
*/
int childX = x;
int childY = y;
Component parent = target.getParent();
// we up to heavyweight parent in order to be sure
// that the coordinates of the text pane is relatively to closest parent
while (parent.isLightweight()){
childX -= parent.getX();
childY -= parent.getY();
parent = parent.getParent();
}
textPane.setBounds(childX,childY,width,height);
textPane.validate();
}
}
@Override
void handleJavaKeyEvent(KeyEvent e) {
AWTAccessor.getComponentAccessor().processEvent(jtext,e);
}
@Override
public boolean handlesWheelScrolling() { return true; }
@Override
void handleJavaMouseWheelEvent(MouseWheelEvent e) {
AWTAccessor.getComponentAccessor().processEvent(textPane, e);
}
@Override
public void handleJavaMouseEvent( MouseEvent e ) {
super.handleJavaMouseEvent( e );
javaMouseEventHandler.handle( e );
}
@Override
void handleJavaInputMethodEvent(InputMethodEvent e) {
if (jtext != null)
jtext.processInputMethodEventPublic(e);
}
/**
* @see java.awt.peer.TextComponentPeer
*/
@Override
public void select(int s, int e) {
jtext.select(s, e);
// Fixed 5100806
// We must take care that Swing components repainted correctly
jtext.repaint();
}
@Override
public void setBackground(Color c) {
super.setBackground(c);
// synchronized (getStateLock()) {
// background = c;
// }
if (jtext != null) {
jtext.setBackground(c);
jtext.setSelectedTextColor(c);
}
// repaintText();
}
@Override
public void setForeground(Color c) {
super.setForeground(c);
// synchronized (getStateLock()) {
// foreground = c;
// }
if (jtext != null) {
jtext.setForeground(foreground);
jtext.setSelectionColor(foreground);
jtext.setCaretColor(foreground);
}
// repaintText();
}
@Override
public void setFont(Font f) {
super.setFont(f);
// synchronized (getStateLock()) {
// font = f;
// }
if (jtext != null) {
jtext.setFont(font);
}
textPane.validate();
}
/**
* @see java.awt.peer.TextComponentPeer
*/
@Override
public void setEditable(boolean editable) {
if (jtext != null) jtext.setEditable(editable);
repaintText();
}
/**
* @see java.awt.peer.ComponentPeer
*/
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (jtext != null) {
jtext.setEnabled(enabled);
jtext.repaint();
}
}
/**
* @see java.awt.peer.TextComponentPeer
*/
@Override
public InputMethodRequests getInputMethodRequests() {
if (jtext != null) return jtext.getInputMethodRequests();
else return null;
}
/**
* @see java.awt.peer.TextComponentPeer
*/
@Override
public int getSelectionStart() {
return jtext.getSelectionStart();
}
/**
* @see java.awt.peer.TextComponentPeer
*/
@Override
public int getSelectionEnd() {
return jtext.getSelectionEnd();
}
/**
* @see java.awt.peer.TextComponentPeer
*/
@Override
public String getText() {
return jtext.getText();
}
/**
* @see java.awt.peer.TextComponentPeer
*/
@Override
public void setText(String text) {
setTextImpl(text);
repaintText();
}
private void setTextImpl(String txt) {
if (jtext != null) {
// JTextArea.setText() posts two different events (remove & insert).
// Since we make no differences between text events,
// the document listener has to be disabled while
// JTextArea.setText() is called.
jtext.getDocument().removeDocumentListener(jtext);
jtext.setText(txt);
if (firstChangeSkipped) {
postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
}
jtext.getDocument().addDocumentListener(jtext);
}
}
/**
* insert the text "txt on position "pos" in the array lines
* @see java.awt.peer.TextAreaPeer
*/
@Override
public void insert(String txt, int p) {
if (jtext != null) {
boolean doScroll = (p >= jtext.getDocument().getLength() && jtext.getDocument().getLength() != 0);
jtext.insert(txt,p);
textPane.validate();
if (doScroll) {
JScrollBar bar = textPane.getVerticalScrollBar();
if (bar != null) {
bar.setValue(bar.getMaximum()-bar.getVisibleAmount());
}
}
}
}
/**
* replace the text between the position "s" and "e" with "txt"
* @see java.awt.peer.TextAreaPeer
*/
@Override
public void replaceRange(String txt, int s, int e) {
if (jtext != null) {
// JTextArea.replaceRange() posts two different events.
// Since we make no differences between text events,
// the document listener has to be disabled while
// JTextArea.replaceRange() is called.
jtext.getDocument().removeDocumentListener(jtext);
jtext.replaceRange(txt, s, e);
postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
jtext.getDocument().addDocumentListener(jtext);
}
}
/**
* to be implemented.
* @see java.awt.peer.TextComponentPeer
*/
@Override
public void setCaretPosition(int position) {
jtext.setCaretPosition(position);
}
/**
* to be implemented.
* @see java.awt.peer.TextComponentPeer
*/
@Override
public int getCaretPosition() {
return jtext.getCaretPosition();
}
static final class AWTTextAreaUI extends MotifTextAreaUI {
private JTextArea jta;
@Override
protected String getPropertyPrefix() { return "TextArea"; }
@Override
public void installUI(JComponent c) {
super.installUI(c);
jta = (JTextArea) c;
JTextArea editor = jta;
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
Font f = editor.getFont();
if ((f == null) || (f instanceof UIResource)) {
editor.setFont(uidefaults.getFont(prefix + ".font"));
}
Color bg = editor.getBackground();
if ((bg == null) || (bg instanceof UIResource)) {
editor.setBackground(uidefaults.getColor(prefix + ".background"));
}
Color fg = editor.getForeground();
if ((fg == null) || (fg instanceof UIResource)) {
editor.setForeground(uidefaults.getColor(prefix + ".foreground"));
}
Color color = editor.getCaretColor();
if ((color == null) || (color instanceof UIResource)) {
editor.setCaretColor(uidefaults.getColor(prefix + ".caretForeground"));
}
Color s = editor.getSelectionColor();
if ((s == null) || (s instanceof UIResource)) {
editor.setSelectionColor(uidefaults.getColor(prefix + ".selectionBackground"));
}
Color sfg = editor.getSelectedTextColor();
if ((sfg == null) || (sfg instanceof UIResource)) {
editor.setSelectedTextColor(uidefaults.getColor(prefix + ".selectionForeground"));
}
Color dfg = editor.getDisabledTextColor();
if ((dfg == null) || (dfg instanceof UIResource)) {
editor.setDisabledTextColor(uidefaults.getColor(prefix + ".inactiveForeground"));
}
Border b = new BevelBorder(false,SystemColor.controlDkShadow,SystemColor.controlLtHighlight);
editor.setBorder(new BorderUIResource.CompoundBorderUIResource(
b,new EmptyBorder(2, 2, 2, 2)));
Insets margin = editor.getMargin();
if (margin == null || margin instanceof UIResource) {
editor.setMargin(uidefaults.getInsets(prefix + ".margin"));
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
@Override
protected Caret createCaret() {
return new XAWTCaret();
}
}
@SuppressWarnings("serial") // JDK-implementation class
static final class XAWTCaret extends DefaultCaret {
@Override
public void focusGained(FocusEvent e) {
super.focusGained(e);
if (getComponent().isEnabled()){
// Make sure the cursor is visible in case of non-editable TextArea
super.setVisible(true);
}
getComponent().repaint();
}
@Override
public void focusLost(FocusEvent e) {
super.focusLost(e);
getComponent().repaint();
}
}
@SuppressWarnings("serial") // JDK-implementation class
static final class XAWTScrollBarButton extends BasicArrowButton {
private UIDefaults uidefaults = XToolkit.getUIDefaults();
private Color darkShadow = SystemColor.controlShadow;
private Color lightShadow = SystemColor.controlLtHighlight;
private Color buttonBack = uidefaults.getColor("ScrollBar.track");
XAWTScrollBarButton(int direction) {
super(direction);
switch (direction) {
case NORTH:
case SOUTH:
case EAST:
case WEST:
this.direction = direction;
break;
default:
throw new IllegalArgumentException("invalid direction");
}
setRequestFocusEnabled(false);
setOpaque(true);
setBackground(uidefaults.getColor("ScrollBar.thumb"));
setForeground(uidefaults.getColor("ScrollBar.foreground"));
}
@Override
public Dimension getPreferredSize() {
switch (direction) {
case NORTH:
case SOUTH:
return new Dimension(11, 12);
case EAST:
case WEST:
default:
return new Dimension(12, 11);
}
}
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}
@Override
public Dimension getMaximumSize() {
return getPreferredSize();
}
@Override
public boolean isFocusTraversable() {
return false;
}
@Override
public void paint(Graphics g)
{
int w = getWidth();
int h = getHeight();
if (isOpaque()) {
g.setColor(buttonBack);
g.fillRect(0, 0, w, h);
}
boolean isPressed = getModel().isPressed();
Color lead = (isPressed) ? darkShadow : lightShadow;
Color trail = (isPressed) ? lightShadow : darkShadow;
Color fill = getBackground();
int cx = w / 2;
int cy = h / 2;
int s = Math.min(w, h);
switch (direction) {
case NORTH:
g.setColor(lead);
g.drawLine(cx, 0, cx, 0);
for (int x = cx - 1, y = 1, dx = 1; y <= s - 2; y += 2) {
g.setColor(lead);
g.drawLine(x, y, x, y);
if (y >= (s - 2)) {
g.drawLine(x, y + 1, x, y + 1);
}
g.setColor(fill);
g.drawLine(x + 1, y, x + dx, y);
if (y < (s - 2)) {
g.drawLine(x, y + 1, x + dx + 1, y + 1);
}
g.setColor(trail);
g.drawLine(x + dx + 1, y, x + dx + 1, y);
if (y >= (s - 2)) {
g.drawLine(x + 1, y + 1, x + dx + 1, y + 1);
}
dx += 2;
x -= 1;
}
break;
case SOUTH:
g.setColor(trail);
g.drawLine(cx, s, cx, s);
for (int x = cx - 1, y = s - 1, dx = 1; y >= 1; y -= 2) {
g.setColor(lead);
g.drawLine(x, y, x, y);
if (y <= 2) {
g.drawLine(x, y - 1, x + dx + 1, y - 1);
}
g.setColor(fill);
g.drawLine(x + 1, y, x + dx, y);
if (y > 2) {
g.drawLine(x, y - 1, x + dx + 1, y - 1);
}
g.setColor(trail);
g.drawLine(x + dx + 1, y, x + dx + 1, y);
dx += 2;
x -= 1;
}
break;
case EAST:
g.setColor(lead);
g.drawLine(s, cy, s, cy);
for (int y = cy - 1, x = s - 1, dy = 1; x >= 1; x -= 2) {
g.setColor(lead);
g.drawLine(x, y, x, y);
if (x <= 2) {
g.drawLine(x - 1, y, x - 1, y + dy + 1);
}
g.setColor(fill);
g.drawLine(x, y + 1, x, y + dy);
if (x > 2) {
g.drawLine(x - 1, y, x - 1, y + dy + 1);
}
g.setColor(trail);
g.drawLine(x, y + dy + 1, x, y + dy + 1);
dy += 2;
y -= 1;
}
break;
case WEST:
g.setColor(trail);
g.drawLine(0, cy, 0, cy);
for (int y = cy - 1, x = 1, dy = 1; x <= s - 2; x += 2) {
g.setColor(lead);
g.drawLine(x, y, x, y);
if (x >= (s - 2)) {
g.drawLine(x + 1, y, x + 1, y);
}
g.setColor(fill);
g.drawLine(x, y + 1, x, y + dy);
if (x < (s - 2)) {
g.drawLine(x + 1, y, x + 1, y + dy + 1);
}
g.setColor(trail);
g.drawLine(x, y + dy + 1, x, y + dy + 1);
if (x >= (s - 2)) {
g.drawLine(x + 1, y + 1, x + 1, y + dy + 1);
}
dy += 2;
y -= 1;
}
break;
}
}
}
static final class XAWTScrollBarUI extends BasicScrollBarUI {
@Override
protected void installDefaults()
{
super.installDefaults();
scrollbar.setBorder(new BevelBorder(false,SystemColor.controlDkShadow,SystemColor.controlLtHighlight) );
}
@Override
protected void configureScrollBarColors() {
UIDefaults uidefaults = XToolkit.getUIDefaults();
Color bg = scrollbar.getBackground();
if (bg == null || bg instanceof UIResource) {
scrollbar.setBackground(uidefaults.getColor("ScrollBar.background"));
}
Color fg = scrollbar.getForeground();
if (fg == null || fg instanceof UIResource) {
scrollbar.setForeground(uidefaults.getColor("ScrollBar.foreground"));
}
thumbHighlightColor = uidefaults.getColor("ScrollBar.thumbHighlight");
thumbLightShadowColor = uidefaults.getColor("ScrollBar.thumbShadow");
thumbDarkShadowColor = uidefaults.getColor("ScrollBar.thumbDarkShadow");
thumbColor = uidefaults.getColor("ScrollBar.thumb");
trackColor = uidefaults.getColor("ScrollBar.track");
trackHighlightColor = uidefaults.getColor("ScrollBar.trackHighlight");
}
@Override
protected JButton createDecreaseButton(int orientation) {
JButton b = new XAWTScrollBarButton(orientation);
return b;
}
@Override
protected JButton createIncreaseButton(int orientation) {
JButton b = new XAWTScrollBarButton(orientation);
return b;
}
public JButton getDecreaseButton(){
return decrButton;
}
public JButton getIncreaseButton(){
return incrButton;
}
@Override
public void paint(Graphics g, JComponent c) {
paintTrack(g, c, getTrackBounds());
Rectangle thumbBounds = getThumbBounds();
paintThumb(g, c, thumbBounds);
}
@Override
public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
{
if(!scrollbar.isEnabled()) {
return;
}
if (thumbBounds.isEmpty())
thumbBounds = getTrackBounds();
int w = thumbBounds.width;
int h = thumbBounds.height;
g.translate(thumbBounds.x, thumbBounds.y);
g.setColor(thumbColor);
g.fillRect(0, 0, w-1, h-1);
g.setColor(thumbHighlightColor);
g.drawLine(0, 0, 0, h-1);
g.drawLine(1, 0, w-1, 0);
g.setColor(thumbLightShadowColor);
g.drawLine(1, h-1, w-1, h-1);
g.drawLine(w-1, 1, w-1, h-2);
g.translate(-thumbBounds.x, -thumbBounds.y);
}
}
@SuppressWarnings("serial") // JDK-implementation class
static final class AWTTextArea extends JTextArea implements DocumentListener {
private boolean isFocused = false;
private final XTextAreaPeer peer;
AWTTextArea(String text, XTextAreaPeer peer) {
super(text);
setFocusable(false);
this.peer = peer;
}
@Override
public void insertUpdate(DocumentEvent e) {
if (peer != null) {
peer.postEvent(new TextEvent(peer.target,
TextEvent.TEXT_VALUE_CHANGED));
}
}
@Override
public void removeUpdate(DocumentEvent e) {
if (peer != null) {
peer.postEvent(new TextEvent(peer.target,
TextEvent.TEXT_VALUE_CHANGED));
}
}
@Override
public void changedUpdate(DocumentEvent e) {
if (peer != null) {
peer.postEvent(new TextEvent(peer.target,
TextEvent.TEXT_VALUE_CHANGED));
}
}
void forwardFocusGained( FocusEvent e) {
isFocused = true;
FocusEvent fe = new FocusEvent(this, e.getID(), e.isTemporary(),
e.getOppositeComponent(), e.getCause());
super.processFocusEvent(fe);
}
void forwardFocusLost( FocusEvent e) {
isFocused = false;
FocusEvent fe = new FocusEvent(this, e.getID(), e.isTemporary(),
e.getOppositeComponent(), e.getCause());
super.processFocusEvent(fe);
}
@Override
public boolean hasFocus() {
return isFocused;
}
public void repaintNow() {
paintImmediately(getBounds());
}
public void processMouseEventPublic(MouseEvent e) {
processMouseEvent(e);
}
public void processMouseMotionEventPublic(MouseEvent e) {
processMouseMotionEvent(e);
}
public void processInputMethodEventPublic(InputMethodEvent e) {
processInputMethodEvent(e);
}
@Override
public void updateUI() {
ComponentUI ui = new AWTTextAreaUI();
setUI(ui);
}
@Override
public void setTransferHandler(final TransferHandler newHandler) {
// override the default implementation to avoid loading
// SystemFlavorMap and associated classes
Object key = AWTAccessor.getClientPropertyKeyAccessor()
.getJComponent_TRANSFER_HANDLER();
Object oldHandler = getClientProperty(key);
putClientProperty(key, newHandler);
firePropertyChange("transferHandler", oldHandler, newHandler);
}
}
static final class XAWTScrollPaneUI extends BasicScrollPaneUI {
private final Border vsbMarginBorderR = new EmptyBorder(0, 2, 0, 0);
private final Border vsbMarginBorderL = new EmptyBorder(0, 0, 0, 2);
private final Border hsbMarginBorder = new EmptyBorder(2, 0, 0, 0);
private Border vsbBorder;
private Border hsbBorder;
private PropertyChangeListener propertyChangeHandler;
@Override
protected void installListeners(JScrollPane scrollPane) {
super.installListeners(scrollPane);
propertyChangeHandler = createPropertyChangeHandler();
scrollPane.addPropertyChangeListener(propertyChangeHandler);