View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/JBDialog.java,v 1.10 2003/09/11 02:36:14 farrukh_najmi Exp $ 3 */ 4 package com.sun.xml.registry.client.browser; 5 6 import java.util.*; 7 import javax.xml.registry.*; 8 import javax.xml.registry.infomodel.*; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 import javax.swing.*; 13 import javax.swing.event.*; 14 15 /*** 16 * Base class for all JAXR Browser dialogs. 17 * 18 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 19 */ 20 public class JBDialog extends JDialog implements java.beans.PropertyChangeListener { 21 22 //Parent for JBPanel 23 protected JPanel mainPanel = null; 24 25 //Parent for OK / Cancel buttons 26 protected JPanel buttonPanel = null; 27 28 public static final int CANCEL_STATUS = 0; 29 public static final int OK_STATUS = 1; 30 public static final int ERROR_STATUS = 2; 31 32 protected int status = CANCEL_STATUS; 33 34 public static final String PROPERTY_DIALOG_OK = "DIALOG_OK"; 35 36 protected boolean editable = RegistryBrowser.getInstance().isAuthenticated(); 37 38 protected GridBagConstraints c = new GridBagConstraints(); 39 protected GridBagLayout gbl = new GridBagLayout(); 40 41 private JButton okButton=null; 42 private JButton cancelButton=null; 43 44 public JBDialog(JDialog parent, boolean modal) { 45 this(parent, modal, null); 46 } 47 48 public JBDialog(JFrame parent, boolean modal) { 49 this(parent, modal, null); 50 } 51 52 public JBDialog(JDialog parent, boolean modal, JPanel mainPanel) { 53 super(parent, modal); 54 this.mainPanel = mainPanel; 55 jbDialog_initialize(); 56 } 57 58 public JBDialog(JFrame parent, boolean modal, JPanel mainPanel) { 59 super(parent, modal); 60 this.mainPanel = mainPanel; 61 jbDialog_initialize(); 62 } 63 64 public JPanel getMainPanel() { 65 return mainPanel; 66 } 67 68 private void jbDialog_initialize() { 69 70 Container contentPane = getContentPane(); 71 contentPane.setLayout(gbl); 72 73 if (mainPanel == null) { 74 mainPanel = new JPanel(); 75 mainPanel.setLayout(new BorderLayout()); 76 } 77 c.gridx = 0; 78 c.gridy = 0; 79 c.gridwidth = 1; 80 c.gridheight = 1; 81 c.weightx = 1.0; 82 c.weighty = 1.0; 83 c.fill = GridBagConstraints.BOTH; 84 c.anchor = GridBagConstraints.CENTER; 85 c.insets = new Insets(4, 4, 0, 4); 86 gbl.setConstraints(mainPanel, c); 87 contentPane.add(mainPanel); 88 89 //The buttonPanel 90 JPanel buttonPanel = new JPanel(); 91 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); 92 93 okButton = new JButton("OK"); 94 okButton.setVisible(editable); 95 okButton.addActionListener(new ActionListener() { 96 public void actionPerformed(ActionEvent ae) { 97 okAction(); 98 } 99 }); 100 101 cancelButton = new JButton("Cancel"); 102 cancelButton.addActionListener(new ActionListener() { 103 public void actionPerformed(ActionEvent e) { 104 cancelAction(); 105 } 106 }); 107 buttonPanel.add(okButton); 108 buttonPanel.add(cancelButton); 109 110 if (editable) { 111 getRootPane().setDefaultButton( okButton ); 112 } else { 113 getRootPane().setDefaultButton( cancelButton ); 114 } 115 116 117 c.gridx = 0; 118 c.gridy = 1; 119 c.gridwidth = 1; 120 c.gridheight = 1; 121 c.weightx = 0.0; 122 c.weighty = 0.0; 123 c.fill = GridBagConstraints.NONE; 124 c.anchor = GridBagConstraints.EAST; 125 c.insets = new Insets(4, 4, 0, 4); 126 gbl.setConstraints(buttonPanel, c); 127 contentPane.add(buttonPanel); 128 129 Point lastDialogLocation = getParent().getLocation(); 130 lastDialogLocation.x += 40; 131 lastDialogLocation.y += 40; 132 setLocation(lastDialogLocation); 133 134 pack(); 135 136 137 //add lister authenticated bound property 138 RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_AUTHENTICATED, this); 139 } 140 141 public int getStatus() { 142 return status; 143 } 144 145 protected void okAction() { 146 try { 147 validateInput(); 148 status = OK_STATUS; 149 dispose(); 150 } 151 catch (Exception e) { 152 status = ERROR_STATUS; 153 RegistryBrowser.displayError(e); 154 } 155 } 156 157 protected void cancelAction() { 158 status = CANCEL_STATUS; 159 dispose(); 160 } 161 162 protected void validateInput() throws JAXRException { 163 } 164 165 protected void clear() throws JAXRException { 166 cancelAction(); 167 } 168 169 /*** 170 * Sets whether this dialog is read-only or editable. 171 */ 172 public void setEditable(boolean editable) { 173 this.editable = editable; 174 okButton.setVisible(editable); 175 176 if (editable) { 177 getRootPane().setDefaultButton( okButton ); 178 } else { 179 getRootPane().setDefaultButton( cancelButton ); 180 } 181 182 } 183 184 /*** 185 * Gets whether this dialog is read-only or editable. 186 */ 187 public boolean isEditable() { 188 return editable; 189 } 190 191 /*** 192 * Listens to property changes in the bound property RegistryBrowser.PROPERTY_AUTHENTICATED. 193 * Calls setEditable according to user authentication state. 194 */ 195 public void propertyChange(java.beans.PropertyChangeEvent ev) { 196 if (ev.getPropertyName().equals(RegistryBrowser.PROPERTY_AUTHENTICATED)) { 197 198 boolean authenticated = ((Boolean)ev.getNewValue()).booleanValue(); 199 200 setEditable(authenticated); 201 } 202 } 203 204 }

This page was automatically generated by Maven