KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > categorized > customizer > DocumentationCustomizer


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * DocumentationCustomizer.java
22  *
23  * Created on May 10, 2006, 10:04 AM
24  */

25
26 package org.netbeans.modules.xml.schema.ui.nodes.categorized.customizer;
27
28 import java.io.IOException JavaDoc;
29 import javax.swing.event.DocumentEvent JavaDoc;
30 import javax.swing.event.DocumentListener JavaDoc;
31 import org.netbeans.modules.xml.schema.model.Annotation;
32 import org.netbeans.modules.xml.schema.model.Documentation;
33 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36
37 /**
38  *
39  * @author Ajit Bhate
40  */

41 public class DocumentationCustomizer extends AbstractSchemaComponentCustomizer<Documentation> {
42     static final long serialVersionUID = 1L;
43     
44     private transient DocumentListener JavaDoc contentListener;
45     
46     /**
47      * Creates new form DocumentationCustomizer
48      */

49     public DocumentationCustomizer(SchemaComponentReference<Documentation> reference) {
50         super(reference);
51         initComponents();
52         reset();
53     }
54     protected void applyChanges() throws IOException JavaDoc {
55         getReference().get().setContentFragment(getContent());
56     }
57     
58     public void reset() {
59         initUI();
60         setSaveEnabled(false);
61         setResetEnabled(false);
62     }
63
64     public HelpCtx getHelpCtx() {
65         return new HelpCtx(DocumentationCustomizer.class);
66     }
67     
68     private void initUI() {
69         if(contentListener == null) {
70             contentListener = new DocumentListener JavaDoc() {
71                 public void changedUpdate(DocumentEvent JavaDoc e) {
72                     determineValidity();
73                 }
74                 public void insertUpdate(DocumentEvent JavaDoc e) {
75                     determineValidity();
76                 }
77                 public void removeUpdate(DocumentEvent JavaDoc e) {
78                     determineValidity();
79                 }
80             };
81         } else {
82             contentEditorPane.getDocument().
83                     removeDocumentListener(contentListener);
84         }
85         contentEditorPane.setText(getReference().get().getContentFragment());
86         contentEditorPane.getDocument().
87                 addDocumentListener(contentListener);
88     }
89     
90     private boolean isModified() {
91         return !getContent().equals(getReference().get().getContentFragment());
92     }
93     
94     private String JavaDoc getContent() {
95         return contentEditorPane.getText();
96     }
97     
98     private void determineValidity() {
99         boolean flag = isModified();
100         setSaveEnabled(flag);
101         setResetEnabled(flag);
102     }
103     
104     /** This method is called from within the constructor to
105      * initialize the form.
106      * WARNING: Do NOT modify this code. The content of this method is
107      * always regenerated by the Form Editor.
108      */

109     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
110
private void initComponents() {
111         innerPanel = new javax.swing.JPanel JavaDoc();
112         contentScrollPane = new javax.swing.JScrollPane JavaDoc();
113         contentEditorPane = new javax.swing.JEditorPane JavaDoc()
114         {
115             static final long serialVersionUID = 1L;
116             protected void processMouseEvent(java.awt.event.MouseEvent JavaDoc e)
117             {
118                 if(e.getButton()==java.awt.event.MouseEvent.BUTTON3)
119                 {
120                     e.consume();
121                     return;
122                 }
123                 super.processMouseEvent(e);
124             }
125         };
126
127         setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
128         innerPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color JavaDoc(204, 204, 204)));
129         contentScrollPane.setBorder(null);
130         contentEditorPane.setContentType("text/xml");
131         contentScrollPane.setViewportView(contentEditorPane);
132
133         org.jdesktop.layout.GroupLayout innerPanelLayout = new org.jdesktop.layout.GroupLayout(innerPanel);
134         innerPanel.setLayout(innerPanelLayout);
135         innerPanelLayout.setHorizontalGroup(
136             innerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
137             .add(innerPanelLayout.createSequentialGroup()
138                 .addContainerGap()
139                 .add(contentScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
140                 .addContainerGap())
141         );
142         innerPanelLayout.setVerticalGroup(
143             innerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
144             .add(org.jdesktop.layout.GroupLayout.TRAILING, innerPanelLayout.createSequentialGroup()
145                 .add(contentScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
146                 .addContainerGap())
147         );
148
149         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
150         this.setLayout(layout);
151         layout.setHorizontalGroup(
152             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153             .add(innerPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
154         );
155         layout.setVerticalGroup(
156             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
157             .add(layout.createSequentialGroup()
158                 .add(23, 23, 23)
159                 .add(innerPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
160         );
161     }// </editor-fold>//GEN-END:initComponents
162

163     // Variables declaration - do not modify//GEN-BEGIN:variables
164
private javax.swing.JEditorPane JavaDoc contentEditorPane;
165     private javax.swing.JScrollPane JavaDoc contentScrollPane;
166     private javax.swing.JPanel JavaDoc innerPanel;
167     // End of variables declaration//GEN-END:variables
168

169 }
170
Popular Tags