[piccolo2d] r962 committed - Made PSwing.setVisible lazily call its component's setVisible method d...

0 views
Skip to first unread message

picc...@googlecode.com

unread,
Jan 28, 2010, 10:05:01 AM1/28/10
to piccol...@googlegroups.com
Revision: 962
Author: allain.lalonde
Date: Thu Jan 28 07:04:37 2010
Log: Made PSwing.setVisible lazily call its component's setVisible method
depending on its current visibility. This should stop the stack overflow
being experienced by Chris Malley. Since I have been unable to reproduce
it, I can't test it.
http://code.google.com/p/piccolo2d/source/detail?r=962

Modified:

/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java

/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java

=======================================
---
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java
Wed Jan 27 13:24:26 2010
+++
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java
Thu Jan 28 07:04:37 2010
@@ -442,7 +442,10 @@
/** {@inheritDoc} */
public void setVisible(final boolean visible) {
super.setVisible(visible);
- component.setVisible(visible);
+
+ if (component.isVisible() != visible) {
+ component.setVisible(visible);
+ }
}

/**
=======================================
---
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java
Wed Jan 27 13:34:51 2010
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java
Thu Jan 28 07:04:37 2010
@@ -44,297 +44,300 @@
import edu.umd.cs.piccolo.util.PPaintContext;

public class PSwingTest extends TestCase {
- public void setUp() {
- RepaintManager.setCurrentManager(new PSwingRepaintManager());
- }
-
- public void testConstructorFailsOnNullComponent() {
- try {
- new PSwing(null);
- }
- catch (final NullPointerException e) {
- // expected
- }
- }
-
- public void testPSwingRegistersItselfWithComponent() {
- final JPanel panel = new JPanel();
- final PSwing pSwing = new PSwing(panel);
-
- assertEquals(pSwing,
panel.getClientProperty(PSwing.PSWING_PROPERTY));
- }
-
- public void testGetComponentReturnsValidComponent() {
- final JPanel panel = new JPanel();
- final PSwing pSwing = new PSwing(panel);
- assertEquals(panel, pSwing.getComponent());
- }
-
- public void testPSwingResizesItselfWhenComponentIsResized() {
- final boolean[] reshaped = new boolean[1];
- final JPanel panel = new JPanel();
-
- new PSwing(panel) {
- public void updateBounds() {
- super.updateBounds();
-
- reshaped[0] = true;
- }
- };
- panel.setSize(100, 100);
- assertTrue(reshaped[0]);
- }
-
- public void testPSwingDelegatesPaintingToItsComponent() throws
IOException {
- final JPanel panel = new JPanel();
- final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
- panel.setBackground(Color.RED);
- panel.setPreferredSize(new Dimension(100, 100));
-
- final BufferedImage img = pSwing.paintComponent();
-
- assertEquals(Color.RED.getRGB(), img.getRGB(50, 50));
- }
-
- public void testHidingComponentHidesPSwing() {
- final JPanel panel = new JPanel();
- final PSwing pSwing = new PSwing(panel);
- panel.setPreferredSize(new Dimension(100, 100));
- pSwing.setBounds(0, 0, 00, 100);
- panel.setVisible(false);
-
- // Wow, do I hate this chunk of code. Turns out that the event
dispatch
- // thread needs time to push the component hidden method before
this
- // test passes
- // There has to be a way of forcing this without a sleep
- assertDelayedSuccess("setting component to invisible did not
reflect in associated PSwing", 500,
- new Predicate() {
-
- public boolean isTrue() {
- return !pSwing.getVisible();
- }
- });
-
- }
-
- public void
testAddingSwingComponentToWrappedHierarchyMakesItNotDoubleBuffer() {
- final JPanel panel = new JPanel();
- final PSwing pSwing = new PSwing(panel);
- final JComponent child = new JLabel("Test Component");
- child.setDoubleBuffered(true);
- panel.add(child);
- assertFalse(child.isDoubleBuffered());
- }
-
- public void assertDelayedSuccess(String message, int delay, Predicate
p) {
- int remainingTries = delay / 50;
- while (remainingTries > 0) {
- if (p.isTrue()) {
- return;
- }
- remainingTries--;
- try {
- Thread.sleep(50);
- }
- catch (InterruptedException e) {
- // do nothing
- }
- }
- fail(message);
- }
-
- public void assertDelayedSuccess(int delay, Predicate p) {
- assertDelayedSuccess("Failed asserting delayed success", delay, p);
- }
-
- private interface Predicate {
- boolean isTrue();
- }
-
- public void testHidingPNodeHidesComponent() {
- final JPanel panel = new JPanel();
- final PSwing pSwing = new PSwing(panel);
- pSwing.setVisible(false);
- assertFalse(panel.isVisible());
- }
-
- public void testPaintTooSmallPaintsGreek() {
- final JPanel panel = new JPanel();
- panel.setBounds(0, 0, 100, 100);
- final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
-
- BufferedImage image = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
- Graphics2D graphics = image.createGraphics();
- graphics.setTransform(AffineTransform.getScaleInstance(0.01,
0.01));
- PPaintContext paintContext = new PPaintContext(graphics);
-
- pSwing.paint(paintContext);
- assertTrue(pSwing.isPaintedGreek());
- assertFalse(pSwing.isPaintedComponent());
-
- }
-
- public void testPaintBigPaintsComponent() {
- final JPanel panel = new JPanel();
- panel.setBounds(0, 0, 100, 100);
- final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
-
- BufferedImage image = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
- Graphics2D graphics = image.createGraphics();
- graphics.setTransform(AffineTransform.getScaleInstance(5, 5));
- PPaintContext paintContext = new PPaintContext(graphics);
-
- pSwing.paint(paintContext);
- assertFalse(pSwing.isPaintedGreek());
- assertTrue(pSwing.isPaintedComponent());
- }
-
- public void testGreekThresholdIsHonoured() {
- final JPanel panel = new JPanel();
- panel.setBounds(0, 0, 100, 100);
- final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
- pSwing.setGreekThreshold(2);
- BufferedImage image = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
- Graphics2D graphics = image.createGraphics();
- PPaintContext paintContext = new PPaintContext(graphics);
-
- pSwing.paint(paintContext);
- assertTrue(pSwing.isPaintedGreek());
- assertFalse(pSwing.isPaintedComponent());
- }
-
- public void testGreekThresholdIsPersisted() {
- final JPanel panel = new JPanel();
- final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
- pSwing.setGreekThreshold(2);
- assertEquals(2, pSwing.getGreekThreshold(), Double.MIN_VALUE);
- pSwing.setGreekThreshold(0.5);
- assertEquals(0.5, pSwing.getGreekThreshold(), Double.MIN_VALUE);
- }
-
- public void testAssertSettingJLabelWidthTooSmallGrowsIt() {
- final JLabel label = new JLabel("Hello");
- PSwingCanvas canvas = new PSwingCanvas();
- canvas.setBounds(0, 0, 100, 100);
- final MockPaintingPSwing swing = new MockPaintingPSwing(label);
- assertDelayedSuccess(500,
- new Predicate() {
-
- public boolean isTrue() {
- return label.getMinimumSize().getWidth() != 0;
- }
- });
- swing.setWidth(10);
- canvas.getLayer().addChild(swing);
- canvas.doLayout();
- // While paint, it uses the graphics element to determine the
font's
- // display size and hence determine minimum size of JLabel.
- swing.paint();
-
- assertFalse(10 == swing.getWidth());
- }
-
- public void testAssertSettingJButtonWidthTooSmallGrowsIt() {
- JButton label = new JButton("Hello");
- PSwingCanvas canvas = new PSwingCanvas();
- canvas.setBounds(0, 0, 100, 100);
- MockPaintingPSwing swing = new MockPaintingPSwing(label);
- assertFalse(label.getMinimumSize().getWidth() == 0);
- swing.setWidth(10);
- canvas.getLayer().addChild(swing);
- canvas.doLayout();
- // While paint, it uses the graphics element to determine the
font's
- // display size and hence determine minimum size of JLabel.
- swing.paint();
- assertFalse(10 == swing.getWidth());
- }
-
- public void
testPSwingAttachesItselfToItsCanvasWhenAddedToItsSceneGraph() {
- PSwingCanvas canvas1 = new PSwingCanvas();
- PSwing label = new PSwing(new JLabel("Hello"));
- assertEquals(0, canvas1.getSwingWrapper().getComponentCount());
- canvas1.getLayer().addChild(label);
- assertEquals(1, canvas1.getSwingWrapper().getComponentCount());
- }
-
- public void testPSwingRemovesItselfFromItsCanvasWhenRemovedFromScene()
{
- PSwingCanvas canvas1 = new PSwingCanvas();
- PSwing label = new PSwing(new JLabel("Hello"));
- canvas1.getLayer().addChild(label);
- assertEquals(1, canvas1.getSwingWrapper().getComponentCount());
- label.removeFromParent();
- assertEquals(0, canvas1.getSwingWrapper().getComponentCount());
- }
-
- public void testPSwingReattachesItselfWhenMovedFromCanvasToCanvas() {
- PSwingCanvas canvas1 = new PSwingCanvas();
- PSwingCanvas canvas2 = new PSwingCanvas();
- PSwing label = new PSwing(new JLabel("Hello"));
- canvas1.getLayer().addChild(label);
- canvas2.getLayer().addChild(label);
- assertEquals(0, canvas1.getSwingWrapper().getComponentCount());
- assertEquals(1, canvas2.getSwingWrapper().getComponentCount());
- }
-
- public void testPSwingRegistersWithCanvasThroughoutItsLifeCycle() {
- PSwingCanvas canvas = new PSwingCanvas();
- PSwing label = new PSwing(new JLabel("Hello"));
-
- canvas.getLayer().addChild(label);
- assertEquals(1, canvas.getSwingWrapper().getComponentCount());
-
- label.removeFromParent();
- assertEquals(0, canvas.getSwingWrapper().getComponentCount());
-
- canvas.getLayer().addChild(label);
- assertEquals(1, canvas.getSwingWrapper().getComponentCount());
- }
-
- public class MockPaintingPSwing extends PSwing {
- private boolean paintedGreek;
- private boolean paintedComponent;
-
- public MockPaintingPSwing(JComponent component) {
- super(component);
- }
-
- public void paintOnto(BufferedImage image) {
- PPaintContext paintContext = new
PPaintContext(image.createGraphics());
- paint(paintContext);
- }
-
- public BufferedImage paint() {
- BufferedImage image = new BufferedImage((int) getWidth(),
(int) getHeight(), BufferedImage.TYPE_INT_RGB);
- paintOnto(image);
- return image;
- }
-
- public BufferedImage paintComponent() {
- BufferedImage image = new BufferedImage((int) getWidth(),
(int) getHeight(), BufferedImage.TYPE_INT_RGB);
- paintComponentOnto(image);
- return image;
- }
-
- public void paintComponentOnto(BufferedImage image) {
- paint(image.createGraphics());
- }
-
- public void paint(Graphics2D paintContext) {
- super.paint(paintContext);
- paintedComponent = true;
- }
-
- public void paintAsGreek(Graphics2D paintContext) {
- super.paintAsGreek(paintContext);
- paintedGreek = true;
- }
-
- public boolean isPaintedGreek() {
- return paintedGreek;
- }
-
- public boolean isPaintedComponent() {
- return paintedComponent;
- }
- }
-}
+ public void setUp() {
+ RepaintManager.setCurrentManager(new PSwingRepaintManager());
+ }
+
+ public void testConstructorFailsOnNullComponent() {
+ try {
+ new PSwing(null);
+ } catch (final NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testPSwingRegistersItselfWithComponent() {
+ final JPanel panel = new JPanel();
+ final PSwing pSwing = new PSwing(panel);
+
+ assertEquals(pSwing, panel.getClientProperty(PSwing.PSWING_PROPERTY));
+ }
+
+ public void testGetComponentReturnsValidComponent() {
+ final JPanel panel = new JPanel();
+ final PSwing pSwing = new PSwing(panel);
+ assertEquals(panel, pSwing.getComponent());
+ }
+
+ public void testPSwingResizesItselfWhenComponentIsResized() {
+ final boolean[] reshaped = new boolean[1];
+ final JPanel panel = new JPanel();
+
+ new PSwing(panel) {
+ public void updateBounds() {
+ super.updateBounds();
+
+ reshaped[0] = true;
+ }
+ };
+ panel.setSize(100, 100);
+ assertTrue(reshaped[0]);
+ }
+
+ public void testPSwingDelegatesPaintingToItsComponent() throws
IOException {
+ final JPanel panel = new JPanel();
+ final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
+ panel.setBackground(Color.RED);
+ panel.setPreferredSize(new Dimension(100, 100));
+
+ final BufferedImage img = pSwing.paintComponent();
+
+ assertEquals(Color.RED.getRGB(), img.getRGB(50, 50));
+ }
+
+ public void testHidingComponentHidesPSwing() {
+ final JPanel panel = new JPanel();
+ final PSwing pSwing = new PSwing(panel);
+ panel.setPreferredSize(new Dimension(100, 100));
+ pSwing.setBounds(0, 0, 00, 100);
+ panel.setVisible(false);
+
+ // Wow, do I hate this chunk of code. Turns out that the event dispatch
+ // thread needs time to push the component hidden method before this
+ // test passes
+ // There has to be a way of forcing this without a sleep
+ assertDelayedSuccess(
+ "setting component to invisible did not reflect in associated PSwing",
+ 500, new Predicate() {
+
+ public boolean isTrue() {
+ return !pSwing.getVisible();
+ }
+ });
+ }
+
+ public void testHidingPNodeHidesComponent() {
+ final JPanel panel = new JPanel();
+ final PSwing pSwing = new PSwing(panel);
+ pSwing.setVisible(false);
+ assertFalse(panel.isVisible());
+ }
+
+ public void
testAddingSwingComponentToWrappedHierarchyMakesItNotDoubleBuffer() {
+ final JPanel panel = new JPanel();
+ final PSwing pSwing = new PSwing(panel);
+ final JComponent child = new JLabel("Test Component");
+ child.setDoubleBuffered(true);
+ panel.add(child);
+ assertFalse(child.isDoubleBuffered());
+ }
+
+ public void assertDelayedSuccess(String message, int delay, Predicate p) {
+ int remainingTries = delay / 50;
+ while (remainingTries > 0) {
+ if (p.isTrue()) {
+ return;
+ }
+ remainingTries--;
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ }
+ fail(message);
+ }
+
+ public void assertDelayedSuccess(int delay, Predicate p) {
+ assertDelayedSuccess("Failed asserting delayed success", delay, p);
+ }
+
+ private interface Predicate {
+ boolean isTrue();
+ }
+
+ public void testPaintTooSmallPaintsGreek() {
+ final JPanel panel = new JPanel();
+ panel.setBounds(0, 0, 100, 100);
+ final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
+
+ BufferedImage image = new BufferedImage(100, 100,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = image.createGraphics();
+ graphics.setTransform(AffineTransform.getScaleInstance(0.01, 0.01));
+ PPaintContext paintContext = new PPaintContext(graphics);
+
+ pSwing.paint(paintContext);
+ assertTrue(pSwing.isPaintedGreek());
+ assertFalse(pSwing.isPaintedComponent());
+
+ }
+
+ public void testPaintBigPaintsComponent() {
+ final JPanel panel = new JPanel();
+ panel.setBounds(0, 0, 100, 100);
+ final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
+
+ BufferedImage image = new BufferedImage(100, 100,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = image.createGraphics();
+ graphics.setTransform(AffineTransform.getScaleInstance(5, 5));
+ PPaintContext paintContext = new PPaintContext(graphics);
+
+ pSwing.paint(paintContext);
+ assertFalse(pSwing.isPaintedGreek());
+ assertTrue(pSwing.isPaintedComponent());
+ }
+
+ public void testGreekThresholdIsHonoured() {
+ final JPanel panel = new JPanel();
+ panel.setBounds(0, 0, 100, 100);
+ final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
+ pSwing.setGreekThreshold(2);
+ BufferedImage image = new BufferedImage(100, 100,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = image.createGraphics();
+ PPaintContext paintContext = new PPaintContext(graphics);
+
+ pSwing.paint(paintContext);
+ assertTrue(pSwing.isPaintedGreek());
+ assertFalse(pSwing.isPaintedComponent());
+ }
+
+ public void testGreekThresholdIsPersisted() {
+ final JPanel panel = new JPanel();
+ final MockPaintingPSwing pSwing = new MockPaintingPSwing(panel);
+ pSwing.setGreekThreshold(2);
+ assertEquals(2, pSwing.getGreekThreshold(), Double.MIN_VALUE);
+ pSwing.setGreekThreshold(0.5);
+ assertEquals(0.5, pSwing.getGreekThreshold(), Double.MIN_VALUE);
+ }
+
+ public void testAssertSettingJLabelWidthTooSmallGrowsIt() {
+ final JLabel label = new JLabel("Hello");
+ PSwingCanvas canvas = new PSwingCanvas();
+ canvas.setBounds(0, 0, 100, 100);
+ final MockPaintingPSwing swing = new MockPaintingPSwing(label);
+ assertDelayedSuccess(500, new Predicate() {
+
+ public boolean isTrue() {
+ return label.getMinimumSize().getWidth() != 0;
+ }
+ });
+ swing.setWidth(10);
+ canvas.getLayer().addChild(swing);
+ canvas.doLayout();
+ // While paint, it uses the graphics element to determine the font's
+ // display size and hence determine minimum size of JLabel.
+ swing.paint();
+
+ assertFalse(10 == swing.getWidth());
+ }
+
+ public void testAssertSettingJButtonWidthTooSmallGrowsIt() {
+ JButton label = new JButton("Hello");
+ PSwingCanvas canvas = new PSwingCanvas();
+ canvas.setBounds(0, 0, 100, 100);
+ MockPaintingPSwing swing = new MockPaintingPSwing(label);
+ assertFalse(label.getMinimumSize().getWidth() == 0);
+ swing.setWidth(10);
+ canvas.getLayer().addChild(swing);
+ canvas.doLayout();
+ // While paint, it uses the graphics element to determine the font's
+ // display size and hence determine minimum size of JLabel.
+ swing.paint();
+ assertFalse(10 == swing.getWidth());
+ }
+
+ public void testPSwingAttachesItselfToItsCanvasWhenAddedToItsSceneGraph()
{
+ PSwingCanvas canvas1 = new PSwingCanvas();
+ PSwing label = new PSwing(new JLabel("Hello"));
+ assertEquals(0, canvas1.getSwingWrapper().getComponentCount());
+ canvas1.getLayer().addChild(label);
+ assertEquals(1, canvas1.getSwingWrapper().getComponentCount());
+ }
+
+ public void testPSwingRemovesItselfFromItsCanvasWhenRemovedFromScene() {
+ PSwingCanvas canvas1 = new PSwingCanvas();
+ PSwing label = new PSwing(new JLabel("Hello"));
+ canvas1.getLayer().addChild(label);
+ assertEquals(1, canvas1.getSwingWrapper().getComponentCount());
+ label.removeFromParent();
+ assertEquals(0, canvas1.getSwingWrapper().getComponentCount());
+ }
+
+ public void testPSwingReattachesItselfWhenMovedFromCanvasToCanvas() {
+ PSwingCanvas canvas1 = new PSwingCanvas();
+ PSwingCanvas canvas2 = new PSwingCanvas();
+ PSwing label = new PSwing(new JLabel("Hello"));
+ canvas1.getLayer().addChild(label);
+ canvas2.getLayer().addChild(label);
+ assertEquals(0, canvas1.getSwingWrapper().getComponentCount());
+ assertEquals(1, canvas2.getSwingWrapper().getComponentCount());
+ }
+
+ public void testPSwingRegistersWithCanvasThroughoutItsLifeCycle() {
+ PSwingCanvas canvas = new PSwingCanvas();
+ PSwing label = new PSwing(new JLabel("Hello"));
+
+ canvas.getLayer().addChild(label);
+ assertEquals(1, canvas.getSwingWrapper().getComponentCount());
+
+ label.removeFromParent();
+ assertEquals(0, canvas.getSwingWrapper().getComponentCount());
+
+ canvas.getLayer().addChild(label);
+ assertEquals(1, canvas.getSwingWrapper().getComponentCount());
+ }
+
+ public class MockPaintingPSwing extends PSwing {
+ private boolean paintedGreek;
+ private boolean paintedComponent;
+
+ public MockPaintingPSwing(JComponent component) {
+ super(component);
+ }
+
+ public void paintOnto(BufferedImage image) {
+ PPaintContext paintContext = new PPaintContext(image
+ .createGraphics());
+ paint(paintContext);
+ }
+
+ public BufferedImage paint() {
+ BufferedImage image = new BufferedImage((int) getWidth(),
+ (int) getHeight(), BufferedImage.TYPE_INT_RGB);
+ paintOnto(image);
+ return image;
+ }
+
+ public BufferedImage paintComponent() {
+ BufferedImage image = new BufferedImage((int) getWidth(),
+ (int) getHeight(), BufferedImage.TYPE_INT_RGB);
+ paintComponentOnto(image);
+ return image;
+ }
+
+ public void paintComponentOnto(BufferedImage image) {
+ paint(image.createGraphics());
+ }
+
+ public void paint(Graphics2D paintContext) {
+ super.paint(paintContext);
+ paintedComponent = true;
+ }
+
+ public void paintAsGreek(Graphics2D paintContext) {
+ super.paintAsGreek(paintContext);
+ paintedGreek = true;
+ }
+
+ public boolean isPaintedGreek() {
+ return paintedGreek;
+ }
+
+ public boolean isPaintedComponent() {
+ return paintedComponent;
+ }
+ }
+}

cma...@pixelzoom.com

unread,
Jan 28, 2010, 5:46:19 PM1/28/10
to Piccolo2D Developers
Thanks for being so responsive Allain!

Unfortunately this change did not correct the problem. And it's
actually unnecessary, since JComponent.setVisible is already a no-op
if the visibility isn't changing.

To clarify... I'm not seeing a stack overflow, but a continuous
toggling between visible and invisible. And I'm still trying to
reproduce the problem in a simple example.

Chris

On Jan 28, 8:05 am, piccol...@googlecode.com wrote:
> Revision: 962
> Author: allain.lalonde
> Date: Thu Jan 28 07:04:37 2010
> Log: Made PSwing.setVisible lazily call its component's setVisible method  
> depending on its current visibility. This should stop the stack overflow  
> being experienced by Chris Malley. Since I have been unable to reproduce  
> it, I can't test it.http://code.google.com/p/piccolo2d/source/detail?r=962

[snip]

cma...@pixelzoom.com

unread,
Feb 1, 2010, 4:24:32 PM2/1/10
to Piccolo2D Developers
I can't seem to reproduce this in a simple example. But in one of our
applications, I see an endless series of calls to the
ComponentListener that is added in PSwing's constructor. The calls
alternate between componentShown and componentHidden. And there is
nothing in the application code that appears to be triggering this, it
keeps feeding back through PSwing.setVisible.

So rather than continue to chase my tail on this, I'd like to discuss
the motivation for adding this ComponentListener. What purpose is it
serving? It seems unnecessary. And undesirable - should client code
be able to call setVisible on a Component? And both this
ComponentListener and the override of PSwing.setVisibile seem a little
dangerous, given how the entire Swing approach works by parenting
JComponents to PSwingCanvas.ChildWrapper.

Also note that an additional ComponentListener is added in
PSwing.initializeComponent, could this be creating problems, depending
on the call order? It seems like there is component initialization
going on in the constructor that should really be in
initializeComponent.

Thoughts anyone?...

Chris

On Jan 28, 3:46 pm, "cmal...@pixelzoom.com" <cmal...@pixelzoom.com>
wrote:

Allain Lalonde

unread,
Feb 1, 2010, 4:32:27 PM2/1/10
to piccol...@googlegroups.com
Reason for adding the component listener in PSwing's constructor was that during the creation of unit tests for it, a bizarre situation became obviously possible.

Invisible PSwing node and visible JComponent or Visible PSwing and invisible JComponent.

Rather than try to parse out the behaviour in those gray areas, I figured the best bet would be to make hiding/showing one, hide/show the other.

I figured that some optimizations could be done at the JComponent level if it were aware that it were invisible (like unloading an image from memory, etc).

If it's causing more problems than it's fixing I'm 100% for removing it.

Try commenting out the ComponentListener registration in the constructor and see if the problem goes away.

Thoughts?

cma...@pixelzoom.com

unread,
Feb 1, 2010, 6:07:32 PM2/1/10
to Piccolo2D Developers
I've reproduced the problem in an example, see issue160:
http://code.google.com/p/piccolo2d/issues/detail?id=160

Chris

On Feb 1, 2:32 pm, Allain Lalonde <allain.lalo...@gmail.com> wrote:
> Reason for adding the component listener in PSwing's constructor was that
> during the creation of unit tests for it, a bizarre situation became
> obviously possible.
>
> Invisible PSwing node and visible JComponent or Visible PSwing and invisible
> JComponent.
>
> Rather than try to parse out the behaviour in those gray areas, I figured
> the best bet would be to make hiding/showing one, hide/show the other.
>
> I figured that some optimizations could be done at the JComponent level if
> it were aware that it were invisible (like unloading an image from memory,
> etc).
>
> If it's causing more problems than it's fixing I'm 100% for removing it.
>
> Try commenting out the ComponentListener registration in the constructor and
> see if the problem goes away.
>
> Thoughts?
>

cma...@pixelzoom.com

unread,
Feb 1, 2010, 6:20:42 PM2/1/10
to Piccolo2D Developers
Btw... Commenting out the ComponentListener added in the PSwing
constructor does make the problem go away.

Chris

On Feb 1, 4:07 pm, "cmal...@pixelzoom.com" <cmal...@pixelzoom.com>
wrote:

Reply all
Reply to author
Forward
0 new messages