Hi-
I have an application that adds a ControlListerner to the
ProjectionControl of a DisplayImpl. This display gets
rebuilt when I change my projections or add in ScalarMaps
after some DataReferences are added. I figured that
as long as there is always one ProjectionControl associated
with a DisplayImpl, that no matter what I did to the display,
my listener would always be active. However, it appears
that when the display is rebuilt, all display listeners are
removed and are not added back in when the ProjectionControl
is added back (same for GraphicsModeControl and
DisplayRendererControl). So once the display is rebuilt,
I have no way of using the controlListener to listen for
ProjectionControl changes. Is this a bug? I've attached
a program that exhibits this behavior.
Don
import visad.*;
import visad.java3d.*;
import visad.data.mcidas.BaseMapAdapter;
import javax.swing.*;
import java.util.Vector;
import java.awt.event.*;
public class PCTest extends JFrame {
DisplayImpl display;
DataReference mapRef;
public PCTest() {
try {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
display = new DisplayImplJ3D("display");
ProjectionControl pc = display.getProjectionControl();
pc.addControlListener(new ControlListener() {
public void controlChanged(ControlEvent e) {
System.out.println("PC: got event: " + e);
}
});
display.addMap(
new ScalarMap(RealType.Latitude, Display.YAxis));
display.addMap(
new ScalarMap(RealType.Longitude, Display.XAxis));
display.addMap(
new ScalarMap(RealType.Altitude, Display.ZAxis));
BaseMapAdapter bma = new BaseMapAdapter("OUTLUSAM");
mapRef = new DataReferenceImpl("map");
mapRef.setData(bma.getData());
display.addReference(mapRef);
getContentPane().add(display.getComponent());
JButton rebuild = new JButton("Rebuild Display");
rebuild.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
rebuildDisplay();
}
});
getContentPane().add("South", rebuild);
} catch (Exception e) {
e.printStackTrace();
}
}
private void rebuildDisplay() {
try {
Vector maps = display.getMapVector();
display.removeAllReferences();
display.clearMaps();
for (int i = 0; i < maps.size(); i++) {
display.addMap((ScalarMap) maps.get(i));
}
display.addReference(mapRef);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
PCTest pc = new PCTest();
pc.pack();
pc.setVisible(true);
}
}