Author: allain.lalonde
Date: Mon Jul 13 15:18:15 2009
New Revision: 458
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
Log:
Issue 82; Fixed ; Made PSwing register itself as a ComponentListener to the
component. When the component's visibility changes, so does the PSwing
node. Also, I've overridden setVisible so that it calls setVisible on the
underlying component.
Modified:
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java
==============================================================================
---
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java
(original)
+++
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java
Mon Jul 13 15:18:15 2009
@@ -240,11 +240,25 @@
component.putClientProperty( PSWING_PROPERTY, this );
init( component );
component.revalidate();
+
component.addPropertyChangeListener( new PropertyChangeListener() {
public void propertyChange( PropertyChangeEvent evt ) {
reshape();
}
} );
+
+ component.addComponentListener(new ComponentAdapter() {
+ public void componentHidden(ComponentEvent e) {
+ System.out.println("Hiding component");
+ setVisible(false);
+ }
+
+ public void componentShown(ComponentEvent e) {
+ System.out.println("Showing component");
+ setVisible(true);
+ }
+ });
+
reshape();
listenForCanvas( this );
}
@@ -388,6 +402,11 @@
manager.unlockRepaint( component );
}
+
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ component.setVisible(visible);
+ }
/**
* Tells whether the buffer for the image of the Swing components
@@ -497,7 +516,7 @@
init( component );
}
- ////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////
///////Start methods for automatic canvas detection
////////////////////////////////////////////////////////////
/**
Modified:
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java
==============================================================================
---
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java
(original)
+++
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java
Mon Jul 13 15:18:15 2009
@@ -110,4 +110,25 @@
pSwing.paint(graphics);
assertEquals(Color.RED.getRGB(), img.getRGB(50, 50));
}
+
+ public void testHidingComponentHidesPSwing() throws
InterruptedException {
+ JPanel panel = new JPanel();
+ 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 next line. 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
+ Thread.sleep(50);
+ assertFalse(pSwing.getVisible());
+ }
+
+ public void testHidingPNodeHidesComponent() {
+ JPanel panel = new JPanel();
+ PSwing pSwing = new PSwing(panel);
+ pSwing.setVisible(false);
+ assertFalse(panel.isVisible());
+ }
}
--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---