1 4 package org.oddjob.designer.view; 5 6 import java.awt.Component ; 7 import java.awt.Dialog ; 8 import java.awt.Frame ; 9 import java.awt.GridBagConstraints ; 10 import java.awt.GridBagLayout ; 11 import java.awt.Window ; 12 import java.awt.event.ActionEvent ; 13 import java.awt.event.ActionListener ; 14 15 import javax.swing.JButton ; 16 import javax.swing.JDialog ; 17 18 21 public class ValueDialog extends JDialog { 22 23 public ValueDialog(Component form) { 24 super(); 25 setForm(form); 26 } 27 28 public ValueDialog(Dialog dialog, Component form) { 29 super(dialog); 30 setLocationRelativeTo(dialog); 31 setForm(form); 32 } 33 34 public ValueDialog(Frame frame, Component form) { 35 super(frame); 36 setLocationRelativeTo(frame); 37 setForm(form); 38 } 39 40 void setForm(Component form) { 41 getContentPane().setLayout(new GridBagLayout ()); 42 GridBagConstraints c = new GridBagConstraints (); 43 c.gridx = 0; 44 c.gridy = 0; 45 c.weightx = 1; 46 c.weighty = 1; 47 c.fill = GridBagConstraints.BOTH; 48 getContentPane().add(form, c); 49 50 JButton ok = new JButton ("OK"); 51 ok.addActionListener(new ActionListener () { 52 public void actionPerformed(ActionEvent e) { 53 setVisible(false); 54 } 55 }); 56 57 c.gridx = 0; 58 c.gridy = 1; 59 c.weightx = 0; 60 c.weighty = 0; 61 c.fill = GridBagConstraints.NONE; 62 getContentPane().add(ok, c); 63 setModal(true); 64 } 65 66 public static void showDialog(Component parent, Component form) { 67 Window w = ViewHelper.getWindowForComponent(parent); 69 ValueDialog valueDialog = null; 70 if (w instanceof Frame ) { 71 valueDialog = new ValueDialog((Frame ) w, form); 72 } else { 73 valueDialog = new ValueDialog((Dialog ) w, form); 74 } 75 valueDialog.pack(); 76 valueDialog.setVisible(true); 77 } 78 79 80 } 81 82 | Popular Tags |