1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
public class SaveDialog extends JDialog implements ActionListener
{
private static ObjectPanel op;
private static SaveDialog dialog;
private static Object value = null;
/** Creates a new instance of SaveDialog */
public static Object showDialog(Component comp,
Component locationComp,
String title,
boolean modal,
ObjectPanel objectPanel)
{
op = objectPanel;
Frame frameComp = JOptionPane.getFrameForComponent(comp);
dialog = new SaveDialog(frameComp,locationComp,title,modal,op);
dialog.setModal(true);
dialog.setVisible(true);
return value;
}
public void actionPerformed(ActionEvent e)
{
if("Save".equals(e.getActionCommand()))
{
this.value = op.getObject();
}
this.dialog.setVisible(false);
}
private SaveDialog(Frame frame,Component locationComp,String title,boolean modal,ObjectPanel objectPanel)
{
this.op = objectPanel;
this.setModal(modal);
this.setTitle(title);
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(this);
JButton saveButton = new JButton("Save");
saveButton.addActionListener(this);
getRootPane().setDefaultButton(cancelButton);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane,BoxLayout.LINE_AXIS));
buttonPane.setBorder(BorderFactory.createEmptyBorder(0,10,10,10));
buttonPane.add(Box.createHorizontalGlue());
buttonPane.add(cancelButton);
buttonPane.add(Box.createRigidArea(new Dimension(10,0)));
buttonPane.add(saveButton);
Container contentPane = getContentPane();
contentPane.add((JPanel)op,BorderLayout.CENTER);
contentPane.add(buttonPane,BorderLayout.PAGE_END);
pack();
setLocationRelativeTo(locationComp);
} |
Partager