KickJava   Java API By Example, From Geeks To Geeks.

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


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.Book;
24 import org.netbeans.modules.xml.multiview.Error;
25
26 /**
27  *
28  * @author mkuchtiak
29  */

30 public class BookPanel extends SectionInnerPanel {
31     Book book;
32     BookDataObject dObj;
33     javax.swing.JTextArea JavaDoc[] paragraphTA;
34     /** Creates new form ChapterPanel */
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 JavaDoc instock = book.getAttributeValue("instock");
46         instockBox.setSelected("yes".equals(instock));
47     }
48
49     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
50         if (source==titleTF) {
51             book.setTitle((String JavaDoc)value);
52         } else if (source==priceTF) {
53             book.setPrice((String JavaDoc)value);
54         }
55     }
56     
57     public void documentChanged(javax.swing.text.JTextComponent JavaDoc comp, String JavaDoc value) {
58         if (comp==titleTF) {
59             String JavaDoc val = (String JavaDoc)value;
60             if (val.length()==0) {
61                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "title", comp));
62                 return;
63             }
64             getSectionView().getErrorPanel().clearError();
65         }
66     }
67
68     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc 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 JavaDoc ddBean, String JavaDoc ddProperty) {
79     }
80
81     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc errorId) {
82         if ("title".equals(errorId)) return titleTF;
83         return null;
84     }
85     
86     /** This method is called from within the constructor to
87      * initialize the form.
88      * WARNING: Do NOT modify this code. The content of this method is
89      * always regenerated by the Form Editor.
90      */

91     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
92
private void initComponents() {
93         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
94
95         titleLabel = new javax.swing.JLabel JavaDoc();
96         titleTF = new javax.swing.JTextField JavaDoc();
97         priceLabel = new javax.swing.JLabel JavaDoc();
98         priceTF = new javax.swing.JTextField JavaDoc();
99         paperbackBox = new javax.swing.JCheckBox JavaDoc();
100         instockBox = new javax.swing.JCheckBox JavaDoc();
101         filler = new javax.swing.JPanel JavaDoc();
102
103         setLayout(new java.awt.GridBagLayout JavaDoc());
104
105         titleLabel.setText("Title:");
106         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107         gridBagConstraints.gridx = 0;
108         gridBagConstraints.gridy = 0;
109         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
110         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
111         add(titleLabel, gridBagConstraints);
112
113         titleTF.setColumns(40);
114         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(5, 0, 0, 0);
121         add(titleTF, gridBagConstraints);
122
123         priceLabel.setText("Price:");
124         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
125         gridBagConstraints.gridx = 0;
126         gridBagConstraints.gridy = 1;
127         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
128         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 5, 0);
129         add(priceLabel, gridBagConstraints);
130
131         priceTF.setColumns(30);
132         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
133         gridBagConstraints.gridx = 1;
134         gridBagConstraints.gridy = 1;
135         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc();
143         gridBagConstraints.gridx = 2;
144         gridBagConstraints.gridy = 1;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc();
154         gridBagConstraints.gridx = 3;
155         gridBagConstraints.gridy = 1;
156         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
157         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 10, 5, 0);
158         add(instockBox, gridBagConstraints);
159
160         filler.setOpaque(false);
161         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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     // </editor-fold>//GEN-END:initComponents
170

171     
172     // Variables declaration - do not modify//GEN-BEGIN:variables
173
private javax.swing.JPanel JavaDoc filler;
174     private javax.swing.JCheckBox JavaDoc instockBox;
175     private javax.swing.JCheckBox JavaDoc paperbackBox;
176     private javax.swing.JLabel JavaDoc priceLabel;
177     private javax.swing.JTextField JavaDoc priceTF;
178     private javax.swing.JLabel JavaDoc titleLabel;
179     private javax.swing.JTextField JavaDoc titleTF;
180     // End of variables declaration//GEN-END:variables
181

182 }
183
Popular Tags