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.Chapter; 24 import org.netbeans.modules.xml.multiview.Error; 25 26 30 public class ChapterPanel extends SectionInnerPanel { 31 Chapter chapter; 32 BookDataObject dObj; 33 javax.swing.JTextArea [] paragraphTA; 34 35 public ChapterPanel(SectionView view, BookDataObject dObj, Chapter chapter) { 36 super(view); 37 this.dObj=dObj; 38 this.chapter=chapter; 39 initComponents(); 40 titleTF.setText(chapter.getTitle()); 41 addValidatee(titleTF); 42 summaryTA.setBorder(titleTF.getBorder()); 43 summaryTA.setText(chapter.getSummary()); 44 addModifier(summaryTA); 45 String [] paragraphs = chapter.getParagraph(); 46 paragraphTA = new javax.swing.JTextArea [paragraphs.length]; 47 for (int i=0;i<paragraphs.length;i++) { 48 paragraphTA[i] = new javax.swing.JTextArea (); 49 paragraphTA[i].setText(paragraphs[i]); 50 addModifier(paragraphTA[i]); 51 paragraphTA[i].setRows(10); 52 paragraphsPanel.add(new javax.swing.JScrollPane (paragraphTA[i]),String.valueOf(i+1)); 53 } 54 lengthTF.setText(chapter.getAttributeValue("length")); 55 addValidatee(lengthTF); 56 } 57 58 public void setValue(javax.swing.JComponent source, Object value) { 59 if (source==titleTF) { 60 chapter.setTitle((String )value); 61 } else if (source==lengthTF) { 62 String text = (String )value; 63 chapter.setAttributeValue("length",text.length()==0?null:text); 64 } else if (source==summaryTA) { 65 chapter.setSummary((String )value); 66 } else { 67 for (int i=0;i<paragraphTA.length;i++) { 68 if (source==paragraphTA[i]) { 69 chapter.setParagraph(i, paragraphTA[i].getText()); 70 break; 71 } 72 } 73 } 74 } 75 76 public void documentChanged(javax.swing.text.JTextComponent comp, String value) { 77 if (comp==titleTF) { 78 String val = (String )value; 79 if (val.length()==0) { 80 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "title", comp)); 81 return; 82 } 83 try { 84 Chapter[] chapters = dObj.getBook().getChapter(); 85 for (int i=0;i<chapters.length;i++) { 86 if (chapter!=chapters[i] && val.equals(chapters[i].getTitle())) { 87 getSectionView().getErrorPanel().setError(new Error (Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, val, comp)); 88 return; 89 } 90 } 91 } catch(java.io.IOException ex){} 92 getSectionView().getErrorPanel().clearError(); 93 } 94 } 95 96 public void rollbackValue(javax.swing.text.JTextComponent source) { 97 if (titleTF==source) { 98 titleTF.setText(chapter.getTitle()); 99 } 100 } 101 102 protected void endUIChange() { 103 dObj.modelUpdatedFromUI(); 104 } 105 106 public void linkButtonPressed(Object ddBean, String ddProperty) { 107 } 108 109 public javax.swing.JComponent getErrorComponent(String errorId) { 110 if ("title".equals(errorId)) return titleTF; 111 return null; 112 } 113 114 119 private void initComponents() { 121 java.awt.GridBagConstraints gridBagConstraints; 122 123 titleLabel = new javax.swing.JLabel (); 124 titleTF = new javax.swing.JTextField (); 125 summaryLabel = new javax.swing.JLabel (); 126 summaryTA = new javax.swing.JTextArea (); 127 paragraphLabel = new javax.swing.JLabel (); 128 paragraphsPanel = new javax.swing.JTabbedPane (); 129 filler = new javax.swing.JPanel (); 130 lengthLabel = new javax.swing.JLabel (); 131 lengthTF = new javax.swing.JTextField (); 132 133 setLayout(new java.awt.GridBagLayout ()); 134 135 titleLabel.setText("Title:"); 136 gridBagConstraints = new java.awt.GridBagConstraints (); 137 gridBagConstraints.gridx = 0; 138 gridBagConstraints.gridy = 0; 139 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 140 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 141 add(titleLabel, gridBagConstraints); 142 143 titleTF.setColumns(40); 144 gridBagConstraints = new java.awt.GridBagConstraints (); 145 gridBagConstraints.gridx = 1; 146 gridBagConstraints.gridy = 0; 147 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 148 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 149 add(titleTF, gridBagConstraints); 150 151 summaryLabel.setText("Summary:"); 152 gridBagConstraints = new java.awt.GridBagConstraints (); 153 gridBagConstraints.gridx = 0; 154 gridBagConstraints.gridy = 1; 155 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 156 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 157 add(summaryLabel, gridBagConstraints); 158 159 summaryTA.setRows(3); 160 gridBagConstraints = new java.awt.GridBagConstraints (); 161 gridBagConstraints.gridx = 1; 162 gridBagConstraints.gridy = 1; 163 gridBagConstraints.gridwidth = 3; 164 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 165 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 5); 166 add(summaryTA, gridBagConstraints); 167 168 paragraphLabel.setText("Paragraphs:"); 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.gridx = 0; 171 gridBagConstraints.gridy = 2; 172 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 173 gridBagConstraints.insets = new java.awt.Insets (10, 5, 0, 0); 174 add(paragraphLabel, gridBagConstraints); 175 176 gridBagConstraints = new java.awt.GridBagConstraints (); 177 gridBagConstraints.gridx = 0; 178 gridBagConstraints.gridy = 3; 179 gridBagConstraints.gridwidth = 4; 180 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 181 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 5); 182 add(paragraphsPanel, gridBagConstraints); 183 184 filler.setOpaque(false); 185 gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.gridwidth = 2; 187 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 188 gridBagConstraints.weightx = 1.0; 189 add(filler, gridBagConstraints); 190 191 lengthLabel.setText("Length:"); 192 gridBagConstraints = new java.awt.GridBagConstraints (); 193 gridBagConstraints.gridx = 2; 194 gridBagConstraints.gridy = 2; 195 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 196 gridBagConstraints.insets = new java.awt.Insets (10, 0, 0, 5); 197 add(lengthLabel, gridBagConstraints); 198 199 lengthTF.setColumns(5); 200 gridBagConstraints = new java.awt.GridBagConstraints (); 201 gridBagConstraints.gridx = 3; 202 gridBagConstraints.gridy = 2; 203 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 204 gridBagConstraints.insets = new java.awt.Insets (10, 0, 0, 5); 205 add(lengthTF, gridBagConstraints); 206 207 } 208 210 211 private javax.swing.JPanel filler; 213 private javax.swing.JLabel lengthLabel; 214 private javax.swing.JTextField lengthTF; 215 private javax.swing.JLabel paragraphLabel; 216 private javax.swing.JTabbedPane paragraphsPanel; 217 private javax.swing.JLabel summaryLabel; 218 private javax.swing.JTextArea summaryTA; 219 private javax.swing.JLabel titleLabel; 220 private javax.swing.JTextField titleTF; 221 223 } 224 | Popular Tags |