1 19 20 package org.netbeans.modules.xml.multiview.ui; 21 import org.openide.DialogDescriptor; 22 23 import org.openide.util.NbBundle; 24 25 30 public abstract class EditDialog extends DialogDescriptor { 31 private javax.swing.JPanel panel; 32 33 34 public EditDialog(javax.swing.JPanel panel, String title, boolean adding) { 35 super (new InnerPanel(panel),getTitle(title,adding),true, 36 DialogDescriptor.OK_CANCEL_OPTION, 37 DialogDescriptor.OK_OPTION, 38 DialogDescriptor.BOTTOM_ALIGN, 39 null, 40 null); 41 this.panel=panel; 42 } 43 44 45 public EditDialog(javax.swing.JPanel panel, String title) { 46 this(panel, title,false); 47 } 48 49 private static String getTitle(String title, boolean adding) { 50 return (adding?NbBundle.getMessage(EditDialog.class,"TTL_ADD",title): 51 NbBundle.getMessage(EditDialog.class,"TTL_EDIT",title)); 52 } 53 56 public final javax.swing.JPanel getDialogPanel() { 57 return panel; 58 } 59 60 63 public final void checkValues() { 64 String errorMessage = validate(); 65 if (errorMessage==null) { 66 setValid(true); 67 } else { 68 setValid(false); 69 } 70 javax.swing.JLabel errorLabel = ((InnerPanel)getMessage()).getErrorLabel(); 71 errorLabel.setText(errorMessage==null?" ":errorMessage); 72 } 73 74 75 protected abstract String validate(); 76 77 private static class InnerPanel extends javax.swing.JPanel { 78 javax.swing.JLabel errorLabel; 79 InnerPanel(javax.swing.JPanel panel) { 80 super(new java.awt.BorderLayout ()); 81 errorLabel = new javax.swing.JLabel (" "); 82 errorLabel.setBorder(new javax.swing.border.EmptyBorder (12,12,0,0)); 83 errorLabel.setForeground(SectionVisualTheme.getErrorLabelColor()); 84 add(panel, java.awt.BorderLayout.CENTER); 85 add(errorLabel, java.awt.BorderLayout.SOUTH); 86 } 87 88 void setErrorMessage(String message) { 89 errorLabel.setText(message); 90 } 91 92 javax.swing.JLabel getErrorLabel() { 93 return errorLabel; 94 } 95 } 96 97 98 public static class DocListener implements javax.swing.event.DocumentListener { 99 EditDialog dialog; 100 101 public DocListener(EditDialog dialog) { 102 this.dialog=dialog; 103 } 104 107 public void changedUpdate(javax.swing.event.DocumentEvent evt) { 108 dialog.checkValues(); 109 } 110 111 114 public void insertUpdate(javax.swing.event.DocumentEvent evt) { 115 dialog.checkValues(); 116 } 117 118 121 public void removeUpdate(javax.swing.event.DocumentEvent evt) { 122 dialog.checkValues(); 123 } 124 } 125 } 126 | Popular Tags |