55 private volatile boolean firstChangeSkipped;
56
57 LWTextComponentPeer(final T target,
58 final PlatformComponent platformComponent) {
59 super(target, platformComponent);
60 if (!getTarget().isBackgroundSet()) {
61 getTarget().setBackground(SystemColor.text);
62 }
63 }
64
65 @Override
66 public void initialize() {
67 super.initialize();
68 synchronized (getDelegateLock()) {
69 // This listener should be added before setText().
70 getTextComponent().getDocument().addDocumentListener(this);
71 }
72 setEditable(getTarget().isEditable());
73 setText(getTarget().getText());
74 getTarget().addInputMethodListener(this);
75 final int start = getTarget().getSelectionStart();
76 final int end = getTarget().getSelectionEnd();
77 if (end > start) {
78 select(start, end);
79 }
80 setCaretPosition(getTarget().getCaretPosition());
81 firstChangeSkipped = true;
82 }
83
84 abstract JTextComponent getTextComponent();
85
86 public Dimension getPreferredSize(final int rows, final int columns) {
87 final Insets insets;
88 synchronized (getDelegateLock()) {
89 insets = getDelegate().getInsets();
90 }
91 final int borderHeight = insets.top + insets.bottom;
92 final int borderWidth = insets.left + insets.right;
93 final FontMetrics fm = getFontMetrics(getFont());
94 final int charWidth = (fm != null) ? fm.charWidth(WIDE_CHAR) : 10;
95 final int itemHeight = (fm != null) ? fm.getHeight() : 10;
96 return new Dimension(columns * charWidth + borderWidth,
97 rows * itemHeight + borderHeight);
98 }
99
100 @Override
|
55 private volatile boolean firstChangeSkipped;
56
57 LWTextComponentPeer(final T target,
58 final PlatformComponent platformComponent) {
59 super(target, platformComponent);
60 if (!getTarget().isBackgroundSet()) {
61 getTarget().setBackground(SystemColor.text);
62 }
63 }
64
65 @Override
66 public void initialize() {
67 super.initialize();
68 synchronized (getDelegateLock()) {
69 // This listener should be added before setText().
70 getTextComponent().getDocument().addDocumentListener(this);
71 }
72 setEditable(getTarget().isEditable());
73 setText(getTarget().getText());
74 getTarget().addInputMethodListener(this);
75 setCaretPosition(getTarget().getCaretPosition());
76 final int start = getTarget().getSelectionStart();
77 final int end = getTarget().getSelectionEnd();
78 if (end > start) {
79 select(start, end);
80 }
81 firstChangeSkipped = true;
82 }
83
84 abstract JTextComponent getTextComponent();
85
86 public Dimension getPreferredSize(final int rows, final int columns) {
87 final Insets insets;
88 synchronized (getDelegateLock()) {
89 insets = getDelegate().getInsets();
90 }
91 final int borderHeight = insets.top + insets.bottom;
92 final int borderWidth = insets.left + insets.right;
93 final FontMetrics fm = getFontMetrics(getFont());
94 final int charWidth = (fm != null) ? fm.charWidth(WIDE_CHAR) : 10;
95 final int itemHeight = (fm != null) ? fm.getHeight() : 10;
96 return new Dimension(columns * charWidth + borderWidth,
97 rows * itemHeight + borderHeight);
98 }
99
100 @Override
|