1 30 31 package com.jgoodies.looks.demo; 32 33 import java.awt.Container ; 34 import java.awt.Dialog ; 35 import java.awt.FileDialog ; 36 import java.awt.event.ActionEvent ; 37 import java.awt.event.ActionListener ; 38 39 import javax.swing.*; 40 41 import com.jgoodies.forms.builder.ButtonBarBuilder; 42 import com.jgoodies.forms.builder.PanelBuilder; 43 import com.jgoodies.forms.layout.CellConstraints; 44 import com.jgoodies.forms.layout.FormLayout; 45 46 52 final class DialogsTab { 53 54 private Container parent; 55 56 private JButton informationButton; 57 private JButton warningButton; 58 private JButton questionButton; 59 private JButton errorButton; 60 private JButton chooseFileNativeButton; 61 private JButton chooseFileSwingButton; 62 63 64 67 private void initComponents() { 68 informationButton = new JButton("Information"); 69 informationButton.addActionListener(new ActionListener () { 70 public void actionPerformed(ActionEvent e) { 71 JOptionPane.showMessageDialog( 72 getParentFrame(), 73 "We just wanted to let you know that you have pressed\n" + 74 "the Information button to open this sample message dialog.\n\n", 75 "Information", 76 JOptionPane.INFORMATION_MESSAGE); 77 } 78 }); 79 warningButton = new JButton("Warning"); 80 warningButton.addActionListener(new ActionListener () { 81 public void actionPerformed(ActionEvent e) { 82 JOptionPane.showMessageDialog( 83 getParentFrame(), 84 "We just wanted to let you know that you have pressed\n" + 85 "the Warning button to open this sample message dialog.\n\n", 86 "Warning", 87 JOptionPane.WARNING_MESSAGE); 88 } 89 }); 90 questionButton = new JButton("Question"); 91 questionButton.addActionListener(new ActionListener () { 92 public void actionPerformed(ActionEvent e) { 93 JOptionPane.showConfirmDialog( 94 getParentFrame(), 95 "We just wanted to let you know that you have pressed\n" + 96 "the Question button to open this sample question dialog.\n\n" + 97 "Are you satisfied with the dialog's appearance?\n\n", 98 "Question", 99 JOptionPane.YES_NO_OPTION 100 ); 101 } 102 }); 103 errorButton = new JButton("Error"); 104 errorButton.addActionListener(new ActionListener () { 105 public void actionPerformed(ActionEvent e) { 106 JOptionPane.showMessageDialog( 107 getParentFrame(), 108 "We just wanted to let you know that you have pressed\n" + 109 "the Error button to open this error message dialog.\n\n" + 110 "Just go ahead and proceed.\n\n", 111 "Error", 112 JOptionPane.ERROR_MESSAGE); 113 } 114 }); 115 chooseFileNativeButton = new JButton("Open..."); 116 chooseFileNativeButton.addActionListener(new ActionListener () { 117 public void actionPerformed(ActionEvent e) { 118 Dialog dialog = new FileDialog ( 119 getParentFrame(), "Open File (Native)"); 120 dialog.setResizable(true); 121 dialog.setVisible(true); 122 } 123 }); 124 chooseFileSwingButton = new JButton("Open..."); 125 chooseFileSwingButton.addActionListener(new ActionListener () { 126 public void actionPerformed(ActionEvent e) { 127 new JFileChooser("Open File (Swing)").showOpenDialog( 128 getParentFrame()); 129 } 130 }); 131 } 132 133 136 JComponent build(Container aParent) { 137 this.parent = aParent; 138 initComponents(); 139 140 FormLayout layout = 141 new FormLayout( 142 "0:grow, left:pref, 0:grow", 143 "0:grow, pref, 4dlu, pref, 14dlu, pref, 4dlu, pref, 14dlu, pref, 4dlu, pref, 0:grow"); 144 PanelBuilder builder = new PanelBuilder(layout); 145 builder.setDefaultDialogBorder(); 146 147 CellConstraints cc = new CellConstraints(); 148 149 builder.addLabel("Press a button to open a message dialog.", cc.xy(2, 2)); 150 builder.add(buildButtonBar(), cc.xy(2, 4)); 151 builder.addLabel("This opens the native file chooser.", cc.xy(2, 6)); 152 builder.add(chooseFileNativeButton, cc.xy(2, 8)); 153 builder.addLabel("This opens the Swing file chooser.", cc.xy(2, 10)); 154 builder.add(chooseFileSwingButton, cc.xy(2, 12)); 155 156 return builder.getPanel(); 157 } 158 159 164 private JPanel buildButtonBar() { 165 ButtonBarBuilder builder = new ButtonBarBuilder(); 166 builder.addGriddedButtons(new JButton[]{ 167 informationButton, warningButton, questionButton, errorButton}); 168 return builder.getPanel(); 169 } 170 171 172 174 JFrame getParentFrame() { 175 return (JFrame) (SwingUtilities.getWindowAncestor(parent)); 176 } 177 178 } | Popular Tags |