Skip to content

Commit e706634

Browse files
hansonrhansonr
authored andcommitted
AWT adds automated List wrapping with JScrollPane
1 parent b47f9d5 commit e706634

File tree

5 files changed

+63
-37
lines changed

5 files changed

+63
-37
lines changed

sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
*/
2828
package java.awt;
2929

30-
import java.applet.JSApplet;
3130
import java.awt.event.KeyListener;
3231
import java.awt.peer.ComponentPeer;
3332
import java.beans.PropertyChangeListener;
@@ -67,6 +66,32 @@
6766
*/
6867
public abstract class JSComponent extends Component {
6968

69+
/**
70+
* A marker for the SwingJS version of JViewPort to indicate that it
71+
* can add an A2SWrappedComponent, not pass it back for wrapping.
72+
*
73+
* @author hansonr
74+
*
75+
*/
76+
public interface A2SComponentWrapper {
77+
78+
public void isWrapper$();
79+
}
80+
81+
/**
82+
* For JViewPort.
83+
*
84+
* Implementations of java.awt.List require a JScrollPane/JViewPort
85+
* wrapper.
86+
*
87+
* @author hansonr
88+
*
89+
*/
90+
public interface A2SWrappedComponent {
91+
92+
public Component getWrap$();
93+
94+
}
7095
/**
7196
* overridden in Applet
7297
*

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@
114114
* @author Philip Milne
115115
* @see JScrollPane
116116
*/
117-
public class JViewport extends JComponent
117+
public class JViewport extends JComponent implements JSComponent.A2SComponentWrapper
118118
{
119-
/** Property used to indicate window blitting should not be done.
119+
120+
// BH for SwingJS
121+
public void isWrapper$() {};
122+
123+
124+
/** Property used to indicate window blitting should not be done.
120125
*/
121126
static final Object EnableWindowBlit = "EnableWindowBlit";
122127

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,5 @@ public A2SListener getA2SListener() {
136136
return listener;
137137
}
138138

139+
139140
}

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

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.awt.AWTEvent;
44
import java.awt.AWTEventMulticaster;
5+
import java.awt.Component;
56
import java.awt.Dimension;
67
import java.awt.ItemSelectable;
78
import java.awt.event.ActionEvent;
@@ -13,12 +14,11 @@
1314

1415
import javax.swing.DefaultListModel;
1516
import javax.swing.JList;
17+
import javax.swing.JScrollPane;
1618
import javax.swing.ListSelectionModel;
1719
import javax.swing.border.LineBorder;
18-
19-
import com.sun.prism.paint.Color;
20-
21-
public class List extends JList implements ItemSelectable {
20+
import java.awt.JSComponent;
21+
public class List extends JList implements ItemSelectable, JSComponent.A2SWrappedComponent {
2222

2323
public void isAWT() {} // for SwingJS isAWT$
2424

@@ -34,6 +34,10 @@ public void isAWT() {} // for SwingJS isAWT$
3434

3535
final static int DEFAULT_VISIBLE_ROWS = 4;
3636

37+
@Override
38+
public Component getWrap$() {
39+
return new JScrollPane(this);
40+
}
3741

3842
public List(int rows, boolean multipleMode) {
3943
this();
@@ -493,12 +497,12 @@ public Dimension getPreferredSize(int rows) {
493497
*/
494498
@Deprecated
495499
public Dimension preferredSize(int rows) {
496-
synchronized (getTreeLock()) {
500+
// synchronized (getTreeLock()) {
497501
ListPeer peer = (ListPeer)this.peer;
498-
return (peer != null) ?
499-
peer.getPreferredSize(rows) :
500-
super.preferredSize();
501-
}
502+
if (peer != null)
503+
return peer.getPreferredSize(rows);
504+
return preferredSize();
505+
// }
502506
}
503507

504508
/**
@@ -511,18 +515,21 @@ public Dimension getPreferredSize() {
511515
return preferredSize();
512516
}
513517

514-
/**
515-
* @deprecated As of JDK version 1.1,
516-
* replaced by <code>getPreferredSize()</code>.
517-
*/
518-
@Deprecated
519-
public Dimension preferredSize() {
520-
// synchronized (getTreeLock()) {
521-
int rows = awtmodel.getSize();
522-
return (rows > 0) ?
523-
preferredSize(rows) :
524-
super.preferredSize();
525-
}
518+
/**
519+
* @deprecated As of JDK version 1.1, replaced by
520+
* <code>getPreferredSize()</code>.
521+
*/
522+
@Deprecated
523+
public Dimension preferredSize() {
524+
// synchronized (getTreeLock()) {
525+
int rows = awtmodel.getSize();
526+
if (rows > 0) {
527+
ListPeer peer = (ListPeer) this.peer;
528+
if (peer != null)
529+
return peer.getPreferredSize(rows);
530+
}
531+
return super.preferredSize();
532+
}
526533
// }
527534

528535
/**

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSListUI.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,10 @@ public class JSListUI extends JSLightweightUI //true, but unnecessary implements
118118

119119
String itemHTML = null;
120120

121-
private JScrollPane scrollPane;
122-
123121
@Override
124122
public DOMNode updateDOMNode() {
125123
list = (JList) jc;
126124
if (domNode == null) {
127-
128-
129-
/**@j2sNative xxL = this.jc; */
130-
131125

132126
focusNode = enableNode = newDOMObject("div", id);
133127
// maybe DOMNode.setAttrInt(domNode, "tabIndex", 1);
@@ -143,12 +137,6 @@ public DOMNode updateDOMNode() {
143137
fillDOM();
144138
}
145139

146-
if (isAWT && scrollPane == null && list.getParent() != null) {
147-
JComponent parent = (JComponent) list.getParent();
148-
scrollPane = new JScrollPane();
149-
scrollPane.getViewport().setView(list);
150-
parent.add(scrollPane);
151-
}
152140
return updateDOMNodeCUI();
153141
}
154142

@@ -2245,7 +2233,7 @@ private void changeSelection(JList list, int type, int index, int direction) {
22452233
type = CHANGE_SELECTION;
22462234
}
22472235

2248-
// IMPORTANT - This needs to happen before the index is changed.
2236+
// importANT - This needs to happen before the index is changed.
22492237
// This is because JFileChooser, which uses JList, also scrolls
22502238
// the selected item into view. If that happens first, then
22512239
// this method becomes a no-op.

0 commit comments

Comments
 (0)