Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
SaveChangesDialog.java
1 package ij.gui;
2 import java.awt.*;
3 import java.awt.event.*;
4 import javax.swing.*;
5 
8 public class SaveChangesDialog extends JDialog implements ActionListener {
9  private Button dontSave, cancel, save;
10  private boolean cancelPressed, savePressed;
11 
12  public SaveChangesDialog(JApplet parent, String fileName) {
13  super(new JFrame(), "Save?", true);
14  setLayout(new BorderLayout());
15  Panel panel = new Panel();
16  panel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
17  Component message;
18  if (fileName.startsWith("Save "))
19  message = new Label(fileName);
20  else {
21  if (fileName.length()>22)
22  message = new MultiLineLabel("Save changes to\n" + "\"" + fileName + "\"?");
23  else
24  message = new Label("Save changes to \"" + fileName + "\"?");
25  }
26  message.setFont(new Font("Dialog", Font.BOLD, 12));
27  panel.add(message);
28  add("Center", panel);
29 
30  panel = new Panel();
31  panel.setLayout(new FlowLayout(FlowLayout.CENTER, 8, 8));
32  save = new Button(" Save ");
33  save.addActionListener(this);
34  cancel = new Button(" Cancel ");
35  cancel.addActionListener(this);
36  dontSave = new Button("Don't Save");
37  dontSave.addActionListener(this);
38  if (ij.IJ.isMacintosh()) {
39  panel.add(dontSave);
40  panel.add(cancel);
41  panel.add(save);
42  } else {
43  panel.add(save);
44  panel.add(dontSave);
45  panel.add(cancel);
46  }
47  add("South", panel);
48  if (ij.IJ.isMacintosh())
49  setResizable(false);
50  pack();
51  GUI.center(this);
52  show();
53  }
54 
55  public void actionPerformed(ActionEvent e) {
56  if (e.getSource()==cancel)
57  cancelPressed = true;
58  else if (e.getSource()==save)
59  savePressed = true;
60  setVisible(false);
61  dispose();
62  }
63 
65  public boolean cancelPressed() {
66  return cancelPressed;
67  }
68 
70  public boolean savePressed() {
71  return savePressed;
72  }
73 
74 }