1 19 package org.netbeans.modules.xml.multiview.test; 20 21 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel; 22 import org.netbeans.modules.xml.multiview.ui.SectionView; 23 import org.netbeans.modules.xml.multiview.test.bookmodel.Book; 24 import org.netbeans.modules.xml.multiview.Error; 25 26 30 public class BookPanel extends SectionInnerPanel { 31 Book book; 32 BookDataObject dObj; 33 javax.swing.JTextArea [] paragraphTA; 34 35 public BookPanel(SectionView view, BookDataObject dObj, Book book) { 36 super(view); 37 this.dObj=dObj; 38 this.book=book; 39 initComponents(); 40 titleTF.setText(book.getTitle()); 41 addValidatee(titleTF); 42 priceTF.setText(book.getPrice()); 43 addModifier(priceTF); 44 paperbackBox.setSelected(book.isPaperback()); 45 String instock = book.getAttributeValue("instock"); 46 instockBox.setSelected("yes".equals(instock)); 47 } 48 49 public void setValue(javax.swing.JComponent source, Object value) { 50 if (source==titleTF) { 51 book.setTitle((String )value); 52 } else if (source==priceTF) { 53 book.setPrice((String )value); 54 } 55 } 56 57 public void documentChanged(javax.swing.text.JTextComponent comp, String value) { 58 if (comp==titleTF) { 59 String val = (String )value; 60 if (val.length()==0) { 61 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "title", comp)); 62 return; 63 } 64 getSectionView().getErrorPanel().clearError(); 65 } 66 } 67 68 public void rollbackValue(javax.swing.text.JTextComponent source) { 69 if (titleTF==source) { 70 titleTF.setText(book.getTitle()); 71 } 72 } 73 74 protected void endUIChange() { 75 dObj.modelUpdatedFromUI(); 76 } 77 78 public void linkButtonPressed(Object ddBean, String ddProperty) { 79 } 80 81 public javax.swing.JComponent getErrorComponent(String errorId) { 82 if ("title".equals(errorId)) return titleTF; 83 return null; 84 } 85 86 91 private void initComponents() { 93 java.awt.GridBagConstraints gridBagConstraints; 94 95 titleLabel = new javax.swing.JLabel (); 96 titleTF = new javax.swing.JTextField (); 97 priceLabel = new javax.swing.JLabel (); 98 priceTF = new javax.swing.JTextField (); 99 paperbackBox = new javax.swing.JCheckBox (); 100 instockBox = new javax.swing.JCheckBox (); 101 filler = new javax.swing.JPanel (); 102 103 setLayout(new java.awt.GridBagLayout ()); 104 105 titleLabel.setText("Title:"); 106 gridBagConstraints = new java.awt.GridBagConstraints (); 107 gridBagConstraints.gridx = 0; 108 gridBagConstraints.gridy = 0; 109 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 110 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 111 add(titleLabel, gridBagConstraints); 112 113 titleTF.setColumns(40); 114 gridBagConstraints = new java.awt.GridBagConstraints (); 115 gridBagConstraints.gridx = 1; 116 gridBagConstraints.gridy = 0; 117 gridBagConstraints.gridwidth = 3; 118 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 119 gridBagConstraints.weightx = 2.0; 120 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 121 add(titleTF, gridBagConstraints); 122 123 priceLabel.setText("Price:"); 124 gridBagConstraints = new java.awt.GridBagConstraints (); 125 gridBagConstraints.gridx = 0; 126 gridBagConstraints.gridy = 1; 127 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 128 gridBagConstraints.insets = new java.awt.Insets (5, 5, 5, 0); 129 add(priceLabel, gridBagConstraints); 130 131 priceTF.setColumns(30); 132 gridBagConstraints = new java.awt.GridBagConstraints (); 133 gridBagConstraints.gridx = 1; 134 gridBagConstraints.gridy = 1; 135 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 136 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 137 add(priceTF, gridBagConstraints); 138 139 paperbackBox.setText("Paperback"); 140 paperbackBox.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING); 141 paperbackBox.setOpaque(false); 142 gridBagConstraints = new java.awt.GridBagConstraints (); 143 gridBagConstraints.gridx = 2; 144 gridBagConstraints.gridy = 1; 145 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 146 gridBagConstraints.insets = new java.awt.Insets (0, 10, 5, 0); 147 add(paperbackBox, gridBagConstraints); 148 149 instockBox.setText("In Stock"); 150 instockBox.setActionCommand("instock"); 151 instockBox.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING); 152 instockBox.setOpaque(false); 153 gridBagConstraints = new java.awt.GridBagConstraints (); 154 gridBagConstraints.gridx = 3; 155 gridBagConstraints.gridy = 1; 156 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 157 gridBagConstraints.insets = new java.awt.Insets (0, 10, 5, 0); 158 add(instockBox, gridBagConstraints); 159 160 filler.setOpaque(false); 161 gridBagConstraints = new java.awt.GridBagConstraints (); 162 gridBagConstraints.gridx = 4; 163 gridBagConstraints.gridy = 0; 164 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 165 gridBagConstraints.weightx = 1.0; 166 add(filler, gridBagConstraints); 167 168 } 169 171 172 private javax.swing.JPanel filler; 174 private javax.swing.JCheckBox instockBox; 175 private javax.swing.JCheckBox paperbackBox; 176 private javax.swing.JLabel priceLabel; 177 private javax.swing.JTextField priceTF; 178 private javax.swing.JLabel titleLabel; 179 private javax.swing.JTextField titleTF; 180 182 } 183 | Popular Tags |