Skip to content

Commit e59b691

Browse files
hansonrhansonr
authored andcommitted
TextArea/JTextArea/JViewport adjustments
1 parent f4fdd2b commit e59b691

File tree

11 files changed

+151
-192
lines changed

11 files changed

+151
-192
lines changed

sources/net.sf.j2s.java.core/src/javax/swing/JScrollPane.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
297297
}
298298
setUIProperty("opaque",true);
299299
updateUI();
300+
System.out.println("jscrollpanecolor " + getBackground());
300301
}
301302

302303
@Override

sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public void setRows(int rows) {
560560
protected int getRowHeight() {
561561
if (rowHeight == 0) {
562562
FontMetrics metrics = getFontMetrics(getFont());
563-
rowHeight = metrics.getHeight() + 2; // SwingJS adds +2 here
563+
rowHeight = metrics.getHeight();// + 2; // SwingJS adds +2 here
564564
}
565565
return rowHeight;
566566
}
@@ -640,7 +640,7 @@ public Dimension getSizeJS(Dimension d, int n, int rows, int columns) {
640640
}
641641
if (rows != 0) {
642642
Insets insets = getInsets();
643-
d.height = Math.max(h, (rows + 1) * getRowHeight() + insets.top + insets.bottom);
643+
d.height = Math.max(h, rows * getRowHeight() + insets.top + insets.bottom);
644644
}
645645
return d;
646646
}

sources/net.sf.j2s.java.core/src/javax/swing/JTextField.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ protected Dimension getPrefSizeJTF() {
443443
}
444444

445445
protected Dimension getPrefSizeJTF(int columns) {
446-
Dimension size = getPrefSizeJComp();
446+
Dimension size = (!isPreferredSizeSet() && ui != null ? ui
447+
.getPreferredSize(this) : null);
448+
if (size == null)
449+
size = super.preferredSize();
447450
if (columns != 0) {
448451
size.width = getJ2SWidth(columns);
449452
}

sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
package javax.swing;
3030

31-
import java.applet.JSApplet;
3231
import java.awt.Component;
3332
import java.awt.Container;
3433
import java.awt.Dimension;
@@ -39,14 +38,15 @@
3938
import java.awt.LayoutManager;
4039
import java.awt.Point;
4140
import java.awt.Rectangle;
42-
import java.awt.Window;
4341
import java.awt.event.ComponentAdapter;
4442
import java.awt.event.ComponentEvent;
4543
import java.awt.event.ComponentListener;
44+
4645
import javax.swing.border.Border;
4746
import javax.swing.event.ChangeEvent;
4847
import javax.swing.event.ChangeListener;
4948
import javax.swing.event.EventListenerList;
49+
5050
import swingjs.JSGraphics2D;
5151

5252

@@ -118,6 +118,7 @@ public class JViewport extends JComponent implements JSComponent.A2SComponentWra
118118
{
119119

120120
// BH for SwingJS
121+
@Override
121122
public void isWrapper$() {};
122123

123124

@@ -574,7 +575,7 @@ public final void setBorder(Border border) {
574575
*/
575576
@Override
576577
public final Insets getInsets() {
577-
return Container.NULL_INSETS;
578+
return new Insets(1, 1, 1, 1);//Container.NULL_INSETS;
578579
}
579580

580581
/**

sources/net.sf.j2s.java.core/src/swingjs/a2s/TextArea.java

Lines changed: 116 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.awt.Color;
55
import java.awt.Dimension;
66
import java.awt.Font;
7+
import java.awt.FontMetrics;
78
import java.awt.event.TextListener;
89
import java.awt.im.InputMethodRequests;
910

@@ -27,6 +28,106 @@ public void isAWT() {
2728

2829
private int verticalScrollBarPolicy;
2930

31+
/**
32+
* Create and display both vertical and horizontal scrollbars.
33+
*
34+
* @since JDK1.1
35+
*/
36+
public static final int SCROLLBARS_BOTH = 0;
37+
38+
/**
39+
* Create and display vertical scrollbar only.
40+
*
41+
* @since JDK1.1
42+
*/
43+
public static final int SCROLLBARS_VERTICAL_ONLY = 1;
44+
45+
/**
46+
* Create and display horizontal scrollbar only.
47+
*
48+
* @since JDK1.1
49+
*/
50+
public static final int SCROLLBARS_HORIZONTAL_ONLY = 2;
51+
52+
/**
53+
* Do not create or display any scrollbars for the text area.
54+
*
55+
* @since JDK1.1
56+
*/
57+
public static final int SCROLLBARS_NONE = 3;
58+
59+
public TextArea(int rows, int cols) {
60+
this(null, rows, cols, SCROLLBARS_BOTH);
61+
}
62+
63+
public TextArea() {
64+
this(null, 0, 0, SCROLLBARS_BOTH);
65+
}
66+
67+
public TextArea(String text) {
68+
this(text, 0, 0, SCROLLBARS_BOTH);
69+
}
70+
71+
public TextArea(String text, int rows, int cols) {
72+
this(text, rows, cols, SCROLLBARS_BOTH);
73+
}
74+
75+
public TextArea(String text, int rows, int columns, int scrollbars) {
76+
super(text, rows < 0 ? 0 : rows, columns < 0 ? 0 : columns);
77+
setWrapStyleWord(false);
78+
setLineWrap(false);
79+
switch (scrollbars) {
80+
case SCROLLBARS_BOTH:
81+
setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
82+
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
83+
break;
84+
case SCROLLBARS_VERTICAL_ONLY:
85+
setLineWrap(true);
86+
setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
87+
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
88+
break;
89+
case SCROLLBARS_HORIZONTAL_ONLY:
90+
setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
91+
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
92+
break;
93+
case SCROLLBARS_NONE:
94+
setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
95+
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
96+
break;
97+
}
98+
}
99+
100+
public int getVerticalScrollBarPolicy() {
101+
return verticalScrollBarPolicy;
102+
}
103+
104+
private void setVerticalScrollBarPolicy(int policy) {
105+
int old = verticalScrollBarPolicy;
106+
verticalScrollBarPolicy = policy;
107+
firePropertyChange("verticalScrollBarPolicy", old, policy);
108+
revalidate();
109+
repaint();
110+
}
111+
112+
public int getHorizontalScrollBarPolicy() {
113+
return horizontalScrollBarPolicy;
114+
}
115+
116+
private void setHorizontalScrollBarPolicy(int policy) {
117+
int old = horizontalScrollBarPolicy;
118+
horizontalScrollBarPolicy = policy;
119+
firePropertyChange("horizontalScrollBarPolicy", old, policy);
120+
revalidate();
121+
repaint();
122+
}
123+
124+
public int getScrollbarVisibility() {
125+
boolean v = (getVerticalScrollBarPolicy() != ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
126+
boolean h = (getHorizontalScrollBarPolicy() != ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
127+
return (v && h ? SCROLLBARS_BOTH
128+
: v ? SCROLLBARS_VERTICAL_ONLY : h ? SCROLLBARS_HORIZONTAL_ONLY : SCROLLBARS_NONE);
129+
}
130+
30131
public synchronized void addTextListener(TextListener l) {
31132
if (l == null) {
32133
return;
@@ -67,11 +168,24 @@ public Dimension getPreferredSize() {
67168
@Override
68169
@Deprecated
69170
public Dimension preferredSize() {
70-
synchronized (getTreeLock()) {
171+
// synchronized (getTreeLock()) {
71172
return ((super.rows > 0) && (super.columns > 0)) ? preferredSize(super.rows, super.columns) : super.preferredSize();
72173
}
73-
}
174+
// }
74175

176+
@Override
177+
protected int getColumnWidth() {
178+
179+
//A column is an approximate average character width that is platform-dependent.
180+
//
181+
// We will call that "n" -- it is pretty close
182+
//
183+
if (columnWidth == 0) {
184+
FontMetrics metrics = getFontMetrics(getFont());
185+
columnWidth = metrics.charWidth('n');
186+
}
187+
return columnWidth;
188+
}
75189
/**
76190
* Determines the minimum size of a text area with the specified number of rows
77191
* and columns.
@@ -185,159 +299,6 @@ public InputMethodRequests getInputMethodRequests() {
185299
// return super.getCaretPosition();
186300
// }
187301
//
188-
/**
189-
* Create and display both vertical and horizontal scrollbars.
190-
*
191-
* @since JDK1.1
192-
*/
193-
public static final int SCROLLBARS_BOTH = 0;
194-
195-
/**
196-
* Create and display vertical scrollbar only.
197-
*
198-
* @since JDK1.1
199-
*/
200-
public static final int SCROLLBARS_VERTICAL_ONLY = 1;
201-
202-
/**
203-
* Create and display horizontal scrollbar only.
204-
*
205-
* @since JDK1.1
206-
*/
207-
public static final int SCROLLBARS_HORIZONTAL_ONLY = 2;
208-
209-
/**
210-
* Do not create or display any scrollbars for the text area.
211-
*
212-
* @since JDK1.1
213-
*/
214-
public static final int SCROLLBARS_NONE = 3;
215-
216-
public TextArea(int rows, int cols) {
217-
this(null, rows, cols, SCROLLBARS_BOTH);
218-
}
219-
220-
public TextArea() {
221-
this(null, 0, 0, SCROLLBARS_BOTH);
222-
}
223-
224-
public TextArea(String text) {
225-
this(text, 0, 0, SCROLLBARS_BOTH);
226-
}
227-
228-
public TextArea(String text, int rows, int cols) {
229-
this(text, rows, cols, SCROLLBARS_BOTH);
230-
}
231-
232-
public TextArea(String text, int rows, int columns, int scrollbars) {
233-
super(text, rows < 0 ? 0 : rows, columns < 0 ? 0 : columns);
234-
switch (scrollbars) {
235-
case SCROLLBARS_BOTH:
236-
setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
237-
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
238-
break;
239-
case SCROLLBARS_VERTICAL_ONLY:
240-
setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
241-
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
242-
break;
243-
case SCROLLBARS_HORIZONTAL_ONLY:
244-
setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
245-
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
246-
break;
247-
case SCROLLBARS_NONE:
248-
setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
249-
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
250-
break;
251-
}
252-
}
253-
254-
/**
255-
* Returns the vertical scroll bar policy value.
256-
* @return the <code>verticalScrollBarPolicy</code> property
257-
* @see #setVerticalScrollBarPolicy
258-
*/
259-
public int getVerticalScrollBarPolicy() {
260-
return verticalScrollBarPolicy;
261-
}
262-
263-
264-
/**
265-
* Determines when the vertical scrollbar appears in the scrollpane.
266-
* Legal values are:
267-
* <ul>
268-
* <li><code>ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED</code>
269-
* <li><code>ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER</code>
270-
* <li><code>ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS</code>
271-
* </ul>
272-
*
273-
* @param policy one of the three values listed above
274-
* @exception IllegalArgumentException if <code>policy</code>
275-
* is not one of the legal values shown above
276-
* @see #getVerticalScrollBarPolicy
277-
*
278-
* @beaninfo
279-
* preferred: true
280-
* bound: true
281-
* description: The scrollpane vertical scrollbar policy
282-
* enum: VERTICAL_SCROLLBAR_AS_NEEDED ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
283-
* VERTICAL_SCROLLBAR_NEVER ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
284-
* VERTICAL_SCROLLBAR_ALWAYS ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
285-
*/
286-
private void setVerticalScrollBarPolicy(int policy) {
287-
int old = verticalScrollBarPolicy;
288-
verticalScrollBarPolicy = policy;
289-
firePropertyChange("verticalScrollBarPolicy", old, policy);
290-
revalidate();
291-
repaint();
292-
}
293-
294-
295-
/**
296-
* Returns the horizontal scroll bar policy value.
297-
* @return the <code>horizontalScrollBarPolicy</code> property
298-
* @see #setHorizontalScrollBarPolicy
299-
*/
300-
public int getHorizontalScrollBarPolicy() {
301-
return horizontalScrollBarPolicy;
302-
}
303-
304-
305-
/**
306-
* Determines when the horizontal scrollbar appears in the scrollpane.
307-
* The options are:<ul>
308-
* <li><code>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED</code>
309-
* <li><code>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER</code>
310-
* <li><code>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS</code>
311-
* </ul>
312-
*
313-
* @param policy one of the three values listed above
314-
* @exception IllegalArgumentException if <code>policy</code>
315-
* is not one of the legal values shown above
316-
* @see #getHorizontalScrollBarPolicy
317-
*
318-
* @beaninfo
319-
* preferred: true
320-
* bound: true
321-
* description: The scrollpane scrollbar policy
322-
* enum: HORIZONTAL_SCROLLBAR_AS_NEEDED ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
323-
* HORIZONTAL_SCROLLBAR_NEVER ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
324-
* HORIZONTAL_SCROLLBAR_ALWAYS ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
325-
*/
326-
private void setHorizontalScrollBarPolicy(int policy) {
327-
int old = horizontalScrollBarPolicy;
328-
horizontalScrollBarPolicy = policy;
329-
firePropertyChange("horizontalScrollBarPolicy", old, policy);
330-
revalidate();
331-
repaint();
332-
}
333-
334-
public int getScrollbarVisibility() {
335-
boolean v = (getVerticalScrollBarPolicy() != ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
336-
boolean h = (getHorizontalScrollBarPolicy() != ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
337-
return (v && h ? SCROLLBARS_BOTH
338-
: v ? SCROLLBARS_VERTICAL_ONLY : h ? SCROLLBARS_HORIZONTAL_ONLY : SCROLLBARS_NONE);
339-
}
340-
341302
@Override
342303
public void setCaretPosition(int pos) {
343304
super.setCaretPosition(pos);

sources/net.sf.j2s.java.core/src/swingjs/a2s/TextField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Dimension getPreferredSize() {
6767
@Override
6868
@Deprecated
6969
public Dimension preferredSize() {
70-
return getPreferredSize(columns);
70+
return preferredSize(columns);
7171
}
7272

7373

0 commit comments

Comments
 (0)