summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300>2004-11-01 23:06:19 +0000
committerkcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300>2004-11-01 23:06:19 +0000
commit311aeb50a8ad4c2c23b5f0ebe7871fdf10303e98 (patch)
tree39c4fef83bcc84d1172a3402d13a2b4b35e1d251
parentb050676ee23e3cff594f2aff6e1ab42c9f8d8de2 (diff)
1) Add "Free OffScreen Buffer" menu item to free the off-screen buffer (by calling setOffScreenBuffer(null)).
2) Free snapshot image resources when scrollable ImageDisplayer window is closed. 3) Free scene graph and off-screen buffer information when application exits
-rw-r--r--src/PrintCanvas3D/ImageDisplayer.java17
-rw-r--r--src/PrintCanvas3D/PrintCanvas3D.java38
2 files changed, 49 insertions, 6 deletions
diff --git a/src/PrintCanvas3D/ImageDisplayer.java b/src/PrintCanvas3D/ImageDisplayer.java
index 4666bf2..30f498e 100644
--- a/src/PrintCanvas3D/ImageDisplayer.java
+++ b/src/PrintCanvas3D/ImageDisplayer.java
@@ -70,6 +70,12 @@ class ImageDisplayer extends JFrame implements ActionListener {
private JMenuItem printItem;
private JMenuItem closeItem;
+ private void freeResources() {
+ this.removeAll();
+ this.setVisible(false);
+ bImage = null;
+ }
+
public void actionPerformed (ActionEvent event) {
Object target = event.getSource();
@@ -77,9 +83,7 @@ class ImageDisplayer extends JFrame implements ActionListener {
new ImagePrinter(bImage).print();
}
else if (target == closeItem) {
- this.removeAll();
- this.setVisible(false);
- bImage = null;
+ freeResources();
}
}
@@ -109,6 +113,13 @@ class ImageDisplayer extends JFrame implements ActionListener {
JScrollPane scrollPane = new JScrollPane(imagePanel);
scrollPane.getViewport().setPreferredSize(new Dimension(700, 700));
+ // Handle the close event
+ this.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent winEvent) {
+ freeResources();
+ }
+ });
+
// Add scroll pane to the frame and make it visible
this.getContentPane().add(scrollPane);
this.pack();
diff --git a/src/PrintCanvas3D/PrintCanvas3D.java b/src/PrintCanvas3D/PrintCanvas3D.java
index 536dc4f..a6ac4c3 100644
--- a/src/PrintCanvas3D/PrintCanvas3D.java
+++ b/src/PrintCanvas3D/PrintCanvas3D.java
@@ -68,6 +68,7 @@ public class PrintCanvas3D extends JFrame implements ActionListener {
private static final double creaseAngle = 60.0;
private JMenuItem snapshotItem;
+ private JMenuItem freeBufferItem;
private JMenuItem printItem;
private JMenuItem quitItem;
@@ -261,6 +262,27 @@ public class PrintCanvas3D extends JFrame implements ActionListener {
}
}
+ private void doExit() {
+ View view = u.getViewer().getView();
+
+ // Free offscreen buffer
+ try {
+ offScreenCanvas3D.setOffScreenBuffer(null);
+ }
+ catch (NullPointerException npe) {
+ //System.err.println(npe + " while freeing off-screen buffer");
+ }
+
+ // clear universe resources
+ u.removeAllLocales();
+
+ // remove all canvas3Ds from View
+ view.removeCanvas3D(offScreenCanvas3D);
+ view.removeCanvas3D(canvas3D);
+
+ System.exit(0);
+ }
+
public void actionPerformed (ActionEvent event) {
Object target = event.getSource();
@@ -281,9 +303,16 @@ public class PrintCanvas3D extends JFrame implements ActionListener {
new ImagePrinter(bImage).print();
}
}
+ else if (target == freeBufferItem) {
+ try {
+ offScreenCanvas3D.setOffScreenBuffer(null);
+ }
+ catch (NullPointerException npe) {
+ //System.err.println(npe + " while freeing off-screen buffer");
+ }
+ }
else if (target == quitItem) {
- u.removeAllLocales();
- System.exit(0);
+ doExit();
}
}
@@ -292,11 +321,14 @@ public class PrintCanvas3D extends JFrame implements ActionListener {
JMenu fileMenu = new JMenu("File");
snapshotItem = new JMenuItem("Snapshot");
snapshotItem.addActionListener(this);
+ freeBufferItem = new JMenuItem("Free OffScreen Buffer");
+ freeBufferItem.addActionListener(this);
printItem = new JMenuItem("Print...");
printItem.addActionListener(this);
quitItem = new JMenuItem("Quit");
quitItem.addActionListener(this);
fileMenu.add(snapshotItem);
+ fileMenu.add(freeBufferItem);
fileMenu.add(printItem);
fileMenu.add(new JSeparator());
fileMenu.add(quitItem);
@@ -314,7 +346,7 @@ public class PrintCanvas3D extends JFrame implements ActionListener {
// Handle the close event
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent winEvent) {
- System.exit(0);
+ doExit();
}
});