1 19 20 25 26 package org.netbeans.modules.xml.schema.ui.nodes.categorized.customizer; 27 28 import java.io.IOException ; 29 import javax.swing.event.DocumentEvent ; 30 import javax.swing.event.DocumentListener ; 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 41 public class DocumentationCustomizer extends AbstractSchemaComponentCustomizer<Documentation> { 42 static final long serialVersionUID = 1L; 43 44 private transient DocumentListener contentListener; 45 46 49 public DocumentationCustomizer(SchemaComponentReference<Documentation> reference) { 50 super(reference); 51 initComponents(); 52 reset(); 53 } 54 protected void applyChanges() throws IOException { 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 () { 71 public void changedUpdate(DocumentEvent e) { 72 determineValidity(); 73 } 74 public void insertUpdate(DocumentEvent e) { 75 determineValidity(); 76 } 77 public void removeUpdate(DocumentEvent 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 getContent() { 95 return contentEditorPane.getText(); 96 } 97 98 private void determineValidity() { 99 boolean flag = isModified(); 100 setSaveEnabled(flag); 101 setResetEnabled(flag); 102 } 103 104 109 private void initComponents() { 111 innerPanel = new javax.swing.JPanel (); 112 contentScrollPane = new javax.swing.JScrollPane (); 113 contentEditorPane = new javax.swing.JEditorPane () 114 { 115 static final long serialVersionUID = 1L; 116 protected void processMouseEvent(java.awt.event.MouseEvent 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 (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 } 163 private javax.swing.JEditorPane contentEditorPane; 165 private javax.swing.JScrollPane contentScrollPane; 166 private javax.swing.JPanel innerPanel; 167 169 } 170 | Popular Tags |