KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > multiview > test > ChapterPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
27  *
28  * @author mkuchtiak
29  */

30 public class ChapterPanel extends SectionInnerPanel {
31     Chapter chapter;
32     BookDataObject dObj;
33     javax.swing.JTextArea JavaDoc[] paragraphTA;
34     /** Creates new form ChapterPanel */
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 JavaDoc[] paragraphs = chapter.getParagraph();
46         paragraphTA = new javax.swing.JTextArea JavaDoc[paragraphs.length];
47         for (int i=0;i<paragraphs.length;i++) {
48             paragraphTA[i] = new javax.swing.JTextArea JavaDoc();
49             paragraphTA[i].setText(paragraphs[i]);
50             addModifier(paragraphTA[i]);
51             paragraphTA[i].setRows(10);
52             paragraphsPanel.add(new javax.swing.JScrollPane JavaDoc(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 JavaDoc source, Object JavaDoc value) {
59         if (source==titleTF) {
60             chapter.setTitle((String JavaDoc)value);
61         } else if (source==lengthTF) {
62             String JavaDoc text = (String JavaDoc)value;
63             chapter.setAttributeValue("length",text.length()==0?null:text);
64         } else if (source==summaryTA) {
65             chapter.setSummary((String JavaDoc)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 JavaDoc comp, String JavaDoc value) {
77         if (comp==titleTF) {
78             String JavaDoc val = (String JavaDoc)value;
79             if (val.length()==0) {
80                 getSectionView().getErrorPanel().setError(new Error JavaDoc(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 JavaDoc(Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, val, comp));
88                         return;
89                     }
90                 }
91             } catch(java.io.IOException JavaDoc ex){}
92             getSectionView().getErrorPanel().clearError();
93         }
94     }
95
96     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc 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 JavaDoc ddBean, String JavaDoc ddProperty) {
107     }
108
109     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc errorId) {
110         if ("title".equals(errorId)) return titleTF;
111         return null;
112     }
113     
114     /** This method is called from within the constructor to
115      * initialize the form.
116      * WARNING: Do NOT modify this code. The content of this method is
117      * always regenerated by the Form Editor.
118      */

119     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
120
private void initComponents() {
121         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
122
123         titleLabel = new javax.swing.JLabel JavaDoc();
124         titleTF = new javax.swing.JTextField JavaDoc();
125         summaryLabel = new javax.swing.JLabel JavaDoc();
126         summaryTA = new javax.swing.JTextArea JavaDoc();
127         paragraphLabel = new javax.swing.JLabel JavaDoc();
128         paragraphsPanel = new javax.swing.JTabbedPane JavaDoc();
129         filler = new javax.swing.JPanel JavaDoc();
130         lengthLabel = new javax.swing.JLabel JavaDoc();
131         lengthTF = new javax.swing.JTextField JavaDoc();
132
133         setLayout(new java.awt.GridBagLayout JavaDoc());
134
135         titleLabel.setText("Title:");
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.gridx = 0;
138         gridBagConstraints.gridy = 0;
139         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
140         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
141         add(titleLabel, gridBagConstraints);
142
143         titleTF.setColumns(40);
144         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.gridx = 1;
146         gridBagConstraints.gridy = 0;
147         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
148         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
149         add(titleTF, gridBagConstraints);
150
151         summaryLabel.setText("Summary:");
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.gridx = 0;
154         gridBagConstraints.gridy = 1;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
157         add(summaryLabel, gridBagConstraints);
158
159         summaryTA.setRows(3);
160         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(5, 0, 0, 5);
166         add(summaryTA, gridBagConstraints);
167
168         paragraphLabel.setText("Paragraphs:");
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.gridx = 0;
171         gridBagConstraints.gridy = 2;
172         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
173         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 5, 0, 0);
174         add(paragraphLabel, gridBagConstraints);
175
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 0, 5, 5);
182         add(paragraphsPanel, gridBagConstraints);
183
184         filler.setOpaque(false);
185         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc();
193         gridBagConstraints.gridx = 2;
194         gridBagConstraints.gridy = 2;
195         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
196         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 0, 0, 5);
197         add(lengthLabel, gridBagConstraints);
198
199         lengthTF.setColumns(5);
200         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
201         gridBagConstraints.gridx = 3;
202         gridBagConstraints.gridy = 2;
203         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
204         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 0, 0, 5);
205         add(lengthTF, gridBagConstraints);
206
207     }
208     // </editor-fold>//GEN-END:initComponents
209

210     
211     // Variables declaration - do not modify//GEN-BEGIN:variables
212
private javax.swing.JPanel JavaDoc filler;
213     private javax.swing.JLabel JavaDoc lengthLabel;
214     private javax.swing.JTextField JavaDoc lengthTF;
215     private javax.swing.JLabel JavaDoc paragraphLabel;
216     private javax.swing.JTabbedPane JavaDoc paragraphsPanel;
217     private javax.swing.JLabel JavaDoc summaryLabel;
218     private javax.swing.JTextArea JavaDoc summaryTA;
219     private javax.swing.JLabel JavaDoc titleLabel;
220     private javax.swing.JTextField JavaDoc titleTF;
221     // End of variables declaration//GEN-END:variables
222

223 }
224
Popular Tags