Skip to content

Commit 6673024

Browse files
hansonrhansonr
authored andcommitted
fixing issues with labels not truncating, controlpanel background
1 parent 34e2867 commit 6673024

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ public void setDraggable(JSFunction f) {
528528
*
529529
*/
530530
protected boolean isContainer, isWindow, isRootPane, isPopupMenu,
531-
isContentPane, isPanel, isDesktop, isTable;
531+
isContentPane, isLayeredPane, isPanel, isDesktop, isTable;
532532

533533
/**
534534
* linked nodes of this class
@@ -1299,6 +1299,7 @@ protected void propertyChangedCUI(PropertyChangeEvent e, String prop) {
12991299
return;
13001300
case "opaque":
13011301
setBackground(c.getBackground());// BH was CUI??
1302+
System.err.println("prop opaque " + c.isOpaque() + " " + this.id);
13021303
return;
13031304
case "inverted":
13041305
updateDOMNode();
@@ -1790,6 +1791,7 @@ protected DOMNode setHTMLElementCUI() {
17901791
int w = getContainerWidth();
17911792
int h = getContainerHeight();
17921793
DOMNode.setSize(outerNode, w, h);
1794+
17931795
if (isPanel || isContentPane || isRootPane) {
17941796
DOMNode.setStyles(outerNode, "overflow",
17951797
allowDivOverflow ? "visible" : "hidden");
@@ -1810,6 +1812,8 @@ protected DOMNode setHTMLElementCUI() {
18101812
&& isFrameIndependent()) {
18111813
DOMNode.transferTo(outerNode, body);
18121814
}
1815+
} else {
1816+
DOMNode.setStyles(outerNode, "overflow", "hidden");
18131817
}
18141818
isTainted = false;
18151819

@@ -2661,14 +2665,14 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
26612665

26622666
switch (vAlign) {
26632667
case SwingConstants.TOP:
2664-
top = margins.top + insets.top;
2668+
top = margins.top;
26652669
break;
26662670
case SwingConstants.BOTTOM:
2667-
top = h - margins.bottom - insets.bottom - hCtr;
2671+
top = h - margins.bottom - hCtr;
26682672
break;
26692673
default:
26702674
case SwingConstants.CENTER:
2671-
top = (h - hCtr + margins.top - margins.bottom - insets.top - insets.bottom) / 2;
2675+
top = (h - hCtr + margins.top - margins.bottom) / 2;
26722676
break;
26732677
}
26742678

@@ -2695,7 +2699,6 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
26952699
yoff = "-50%";
26962700
break;
26972701
}
2698-
addCSS(cssCtr, "overflow", "none");
26992702
addCSS(cssTxt, "top", top + "%", "transform",
27002703
"translateY(" + (yoff == null ? "-" + top + "%" : yoff + ")"));
27012704
addCSS(cssIcon, "top", top + "%", "transform",
@@ -3298,6 +3301,7 @@ public void setForeground(Color c) {
32983301
@Override
32993302
public void setBackground(Color c) {
33003303
awtPeerBG = null;
3304+
33013305
setBackgroundImpl(c);
33023306
}
33033307

@@ -3306,11 +3310,15 @@ public void setBackground(Color c) {
33063310
protected void setBackgroundImpl(Color color) {
33073311
// Don't allow color for Menu and MenuItem. This is taken care of by
33083312
// jQuery
3309-
3313+
33103314
if (domNode == null || isMenuItem || isUIDisabled)
33113315
return;
33123316
// currently painting - update JSGraphics2D
33133317
backgroundColor = color;
3318+
if ((jc.秘paintsSelf() || (isContentPane || isLayeredPane)
3319+
&& jc.秘setPaintsSelf(JSComponent.PAINTS_SELF_YES) == JSComponent.PAINTS_SELF_YES) && jc.isOpaque()) {
3320+
clearPaintPath();
3321+
}
33143322
paintBackground(jc.秘gtemp);
33153323
}
33163324

@@ -3337,6 +3345,7 @@ private void setTransparent() {
33373345
public void paintBackground(JSGraphics2D g) {
33383346
boolean isOpaque = c.isOpaque();
33393347
boolean paintsSelf = jc.秘paintsSelf();
3348+
System.out.println("paintback " + this.id + " " + (/** @j2sNative this.jc.text||*/"")+ " " + isOpaque + " " + paintsSelf + " " + g);
33403349
Color color = (this.backgroundColor == null ? getBackground() : this.backgroundColor);
33413350
if (g == null) {
33423351
if (!paintsSelf)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class JSLayeredPaneUI extends JSLightweightUI {
99

1010
public JSLayeredPaneUI() {
11-
isContainer = true;
11+
isContainer = isLayeredPane = true;
1212
}
1313

1414
@Override

sources/net.sf.j2s.java.core/src/test/JalviewJSTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import javax.swing.JButton;
2727
import javax.swing.JCheckBox;
2828
import javax.swing.JCheckBoxMenuItem;
29-
import javax.swing.JDesktopPane;
3029
import javax.swing.JFrame;
31-
import javax.swing.JInternalFrame;
3230
import javax.swing.JLabel;
3331
import javax.swing.JMenu;
3432
import javax.swing.JMenuBar;
@@ -127,7 +125,7 @@ public void mouseExited(MouseEvent e) {
127125
}
128126

129127
};
130-
private Label status;
128+
private JLabel status;
131129
private JMenu menu, menu1, menu2;
132130
private JCheckBoxMenuItem cb4m;
133131
/**
@@ -169,6 +167,7 @@ public void keyReleased(KeyEvent e) {
169167
mb.add(menu2);
170168
frame.setContentPane(getVisualPaneContent(menu, menu1, menu2));
171169
frame.pack();
170+
System.out.println(frame.getContentPane());
172171
//frame.setBackground(Color.blue);
173172
// note -- this blue color is never seen
174173
JPopupMenu pmenu = new JPopupMenu();
@@ -198,7 +197,14 @@ public void mouseClicked(MouseEvent e) {
198197
public void mousePressed(MouseEvent e) {
199198
System.out.println(frame.getContentPane().getSize());
200199
frame.getContentPane().setBackground(Color.yellow);
200+
System.out.println(frame.getContentPane());
201+
System.out.println(frame.getContentPane().getComponent(0));
202+
System.out.println(frame.getContentPane().getComponent(0).getBackground());
203+
201204
((JPanel)frame.getContentPane()).setOpaque(true);
205+
206+
invalidate();
207+
repaint();
202208
//System.out.println(e.getButton());
203209
if (e.getButton() != MouseEvent.BUTTON3)
204210
return;
@@ -265,11 +271,14 @@ Container getVisualPaneContent(JMenu menu, JMenu menu1, JMenu menu2) {
265271
Font font = new Font("Verdana", Font.PLAIN, 12);
266272

267273
JPanel panel = new JPanel();
274+
panel.setName("top-blue");
268275
panel.setPreferredSize(new Dimension(600, 600));
269276
panel.setMaximumSize(new Dimension(600, 600));
270277
panel.setOpaque(true);
278+
panel.setBackground(Color.blue);
279+
271280
panel.setLayout(new BorderLayout());
272-
panel.add(status = new Label("ok"), BorderLayout.SOUTH);
281+
panel.add(status = new JLabel("ok"), BorderLayout.SOUTH);
273282

274283
JPanel firstColumn = new JPanel();
275284
firstColumn.setLayout(new GridLayout(13, 1));
@@ -296,6 +305,7 @@ public void actionPerformed(ActionEvent e) {
296305
JLabel l2 = new JLabel(getImage("test2.png"));
297306
l2.setText("leading left");
298307
l2.setFont(font);
308+
l2.setVerticalAlignment(SwingConstants.CENTER);
299309
l2.setHorizontalTextPosition(SwingConstants.LEADING);
300310
l2.setHorizontalAlignment(SwingConstants.LEFT);
301311
l2.setBorder(new LineBorder(Color.red, 7));
@@ -589,7 +599,7 @@ public void actionPerformed(ActionEvent e) {
589599
}
590600
});
591601
theTab.setLayout(null);
592-
theTab.setBackground(Color.white);
602+
theTab.setBackground(Color.GREEN);
593603
theTab.add(firstColumn);
594604
panel.add(theTab);
595605

0 commit comments

Comments
 (0)