Skip to content

Commit 0347a6e

Browse files
committed
more JTable/JTree
1 parent 8b3cfc1 commit 0347a6e

File tree

5 files changed

+91
-38
lines changed

5 files changed

+91
-38
lines changed

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

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ public boolean isValid() {
11141114
public boolean isDisplayable() {
11151115
// that is, if this component is connected to a top-level ancestor
11161116
// see JSComponent
1117+
// return comp.peer != null;
11171118
return true;
11181119
}
11191120

@@ -2057,6 +2058,12 @@ public void setBounds(Rectangle r) {
20572058
*/
20582059
@Deprecated
20592060
public void reshape(int x, int y, int width, int height) {
2061+
秘reshape(x, y, width, height, true);
2062+
}
2063+
2064+
public void 秘reshape(int x, int y, int width, int height, boolean needNotify) {
2065+
2066+
needNotify &= (parent == null || !parent.秘isCRP);
20602067
try {
20612068
setBoundsOp(ComponentPeer.SET_BOUNDS);
20622069
// width or height can be < 0 if layout involved borders larger than
@@ -2083,7 +2090,6 @@ public void reshape(int x, int y, int width, int height) {
20832090
// resized to " + getBounds());
20842091
}
20852092

2086-
boolean needNotify = true;
20872093
mixOnReshaping();
20882094
if (getOrCreatePeer() != null) {
20892095
// LightwightPeer is an empty stub so can skip peer.reshape
@@ -2129,16 +2135,25 @@ private void repaintParentIfNeeded(int oldX, int oldY, int oldWidth, int oldHeig
21292135
}
21302136
}
21312137

2138+
/**
2139+
* SwingJS note: x and y are ignored
2140+
* @param x ignored
2141+
* @param y ignored
2142+
* @param width
2143+
* @param height
2144+
* @param op
2145+
*/
21322146
private void reshapeNativePeer(int x, int y, int width, int height, int op) {
21332147
// native peer might be offset by more than direct
21342148
// parent since parent might be lightweight.
2135-
int nativeX = x;
2136-
int nativeY = y;
2137-
for (Component c = parent; (c != null) && (c.peer instanceof LightweightPeer); c = c.parent) {
2138-
nativeX += c.x;
2139-
nativeY += c.y;
2140-
}
2141-
peer.setBounds(nativeX, nativeY, width, height, op);
2149+
// int nativeX = x;
2150+
// int nativeY = y;
2151+
// for (Component c = parent; (c != null) && (c.peer instanceof LightweightPeer); c = c.parent) {
2152+
// nativeX += c.x;
2153+
// nativeY += c.y;
2154+
// }
2155+
// peer.setBounds(nativeX, nativeY, width, height, op);
2156+
peer.setBounds(0, 0, width, height, op);
21422157
}
21432158

21442159
@SuppressWarnings("deprecation")
@@ -2632,34 +2647,38 @@ public void layout() {
26322647
}
26332648

26342649
/**
2650+
* SwingJS note: All this does in SwingJS is set valid = true. However, it is
2651+
* overridden in JSComponent, JRootPane, and the cell renderers.
2652+
*
2653+
*
26352654
* Ensures that this component has a valid layout. This method is primarily
26362655
* intended to operate on instances of <code>Container</code>.
2637-
*
2656+
*
26382657
* @see #invalidate
26392658
* @see #doLayout()
26402659
* @see LayoutManager
26412660
* @see Container#validate
26422661
* @since JDK1.0
26432662
*/
26442663
public void validate() {
2645-
synchronized (getTreeLock()) {
2646-
ComponentPeer peer = this.peer;
2647-
boolean wasValid = isValid();
2648-
if (!wasValid && peer != null) {
2649-
Font newfont = getFont();
2650-
Font oldfont = peerFont;
2651-
if (newfont != oldfont && (oldfont == null || !oldfont.equals(newfont))) {
2652-
peer.setFont(newfont);
2653-
peerFont = newfont;
2654-
}
2655-
peer.layout();
2656-
}
2664+
//
2665+
// synchronized (getTreeLock()) {
2666+
// ComponentPeer peer = this.peer;
2667+
// boolean wasValid = isValid();
2668+
// if (!wasValid && peer != null) {
2669+
// Font newfont = getFont();
2670+
// Font oldfont = peerFont;
2671+
// if (newfont != oldfont && (oldfont == null || !oldfont.equals(newfont))) {
2672+
// peer.setFont(newfont);
2673+
// peerFont = newfont;
2674+
// }
2675+
// peer.layout();
2676+
// }
26572677
valid = true;
2658-
// System.out.println("C is valid: " + this);
2659-
if (!wasValid) {
2660-
mixOnValidating();
2661-
}
2662-
}
2678+
// if (!wasValid) {
2679+
// mixOnValidating();
2680+
// }
2681+
// }
26632682
}
26642683

26652684
/**
@@ -8264,7 +8283,7 @@ void mixOnZOrderChanging(int oldZorder, int newZorder) {
82648283
}
82658284

82668285
void mixOnValidating() {
8267-
// This method gets overriden in the Container. Obviously, a plain
8286+
// This method gets overridden in the Container. Obviously, a plain
82688287
// non-container components don't need to handle validation.
82698288
}
82708289

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public class Container extends JSComponent {
8888
//
8989
public static final Component[] EMPTY_ARRAY = new Component[0];
9090

91+
protected boolean 秘isCRP;
92+
9193
/**
9294
* The components in this container.
9395
*
@@ -2776,6 +2778,11 @@ public void setDispatcher() {
27762778
*/
27772779
@Override
27782780
public void removeNotify() {
2781+
if (ui != null && 秘getUI().domNode == null) {
2782+
// A CellRenderer's ui domNode has already been nulled out.
2783+
// Don't discard its children.
2784+
return;
2785+
}
27792786
// synchronized (getTreeLock()) {
27802787
// We shouldn't use iterator because of the Swing menu
27812788
// implementation specifics:

sources/net.sf.j2s.java.core/src/java/awt/event/ComponentEvent.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ public class ComponentEvent extends AWTEvent {
114114
*/
115115
public ComponentEvent(Component source, int id) {
116116
super(source, id);
117+
/**
118+
* from ?j2sevents
119+
*
120+
* @j2sNative
121+
* if (J2S._traceEvents)
122+
* System.out.println("ComponentEvent " + id + " " + source.__CLASS_NAME__);
123+
*/
117124
}
118125

119126
public ComponentEvent() {

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@
6868
public class CellRendererPane extends JPanel
6969
{
7070
// SwingJS switched to JPanel instead of Container
71-
71+
// This class is essentially final. Only UI classes create it.
72+
7273
/**
7374
* Construct a CellRendererPane object.
7475
*/
7576
public CellRendererPane() {
7677
super();
78+
秘isCRP = true;
7779
秘paintClass = 秘updateClass = /**@j2sNative C$ || */null;
7880

7981
setLayout(null);
@@ -88,6 +90,11 @@ public CellRendererPane() {
8890
public void invalidate() { }
8991

9092

93+
@Override
94+
public void repaint() {
95+
// called by
96+
}
97+
9198
/**
9299
* Shouldn't be called.
93100
*/
@@ -124,8 +131,18 @@ protected void addImpl(Component x, Object constraints, int index) {
124131
* The Container p is the component we're actually drawing on, typically it's
125132
* equal to this.getParent(). If shouldValidate is true the component c will be
126133
* validated before painted.
134+
*
135+
* @param g
136+
* @param c
137+
* @param p
138+
* @param x
139+
* @param y
140+
* @param w
141+
* @param h
142+
* @param shouldValidate probably a NOP
127143
*/
128144
public void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h, boolean shouldValidate) {
145+
// p is the table, list, etc.
129146
if (c == null) {
130147
if (p != null) {
131148
Color oldColor = g.getColor();
@@ -140,17 +157,19 @@ public void paintComponent(Graphics g, Component c, Container p, int x, int y, i
140157
this.add(c);
141158
}
142159

143-
c.setBounds(-w, -h, 0, 0); // force new bounds
144-
c.setBounds(x, y, w, h);
160+
c.秘reshape(-w, -h, 0, 0, false); // force new bounds
145161

146-
if(shouldValidate) {
147-
c.validate();
148-
}
162+
// if(shouldValidate) {
163+
// // unlikely that this will do much; only JRootPane does anything significant here.
164+
// c.validate();
165+
// }
149166
JSComponentUI ui = ((JComponent) c).秘getUI();
150-
ui.updateDOMNode();
167+
c.秘reshape(x, y, w, h, false);
168+
((JComponent) c).validateTree();
169+
ui.updateDOMNode();
151170
// if (!ui.doPaintBackground())
152171
// return;
153-
ui.setTainted(false);
172+
// ui.setTainted(false);
154173

155174
// boolean wasDoubleBuffered = false;
156175
// if ((c instanceof JComponent) && ((JComponent)c).isDoubleBuffered()) {
@@ -170,7 +189,7 @@ public void paintComponent(Graphics g, Component c, Container p, int x, int y, i
170189
// ((JComponent)c).setDoubleBuffered(true);
171190
// }
172191
//
173-
c.setBounds(-w, -h, 0, 0);
192+
c.秘reshape(-w, -h, 0, 0, false);
174193

175194
}
176195

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ static void updateCellNode(DOMNode td, JSComponent c, int width, int height) {
4747
width = DOMNode.getWidth(td);
4848
height = DOMNode.getHeight(td);
4949
}
50-
c.setSize(width, height);
50+
c.秘reshape(c.getX(), c.getY(), width, height, false);
5151
ui.setRenderer(c, width, height, null);
5252
ui.saveCellNodes(td, isHeader);
5353
}
5454

5555
public static void setJ2SRendererComponent(JComponent comp) {
56-
comp.秘getUI().setRenderer(comp, 0, 0, null);
56+
if (comp != null)
57+
comp.秘getUI().setRenderer(comp, 0, 0, null);
5758
}
5859

5960

0 commit comments

Comments
 (0)