KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > uihandler > SubmitPanel


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
20 package org.netbeans.modules.uihandler;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.ByteArrayOutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.LogRecord JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29 import javax.swing.text.BadLocationException JavaDoc;
30 import org.netbeans.lib.uihandler.LogRecords;
31 import org.openide.explorer.ExplorerManager;
32 import org.openide.nodes.Node;
33
34 /**
35  *
36  * @author Jaroslav Tulach
37  */

38 public class SubmitPanel extends javax.swing.JPanel JavaDoc
39 implements ExplorerManager.Provider, PropertyChangeListener JavaDoc {
40     
41     /** Creates new form SubmitPanel */
42     public SubmitPanel() {
43         manager = new ExplorerManager();
44         
45         initComponents();
46         manager.addPropertyChangeListener(this);
47     }
48     
49     /** This method is called from within the constructor to
50      * initialize the form.
51      * WARNING: Do NOT modify this code. The content of this method is
52      * always regenerated by the Form Editor.
53      */

54     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
55
private void initComponents() {
56
57         tabs = new javax.swing.JTabbedPane JavaDoc();
58         structured = new javax.swing.JPanel JavaDoc();
59         jSplitPane1 = new javax.swing.JSplitPane JavaDoc();
60         listView1 = new org.openide.explorer.view.ListView();
61         recordScroll = new javax.swing.JScrollPane JavaDoc();
62         record = new javax.swing.JTextArea JavaDoc();
63         raw = new javax.swing.JPanel JavaDoc();
64         scroll = new javax.swing.JScrollPane JavaDoc();
65         text = new javax.swing.JTextArea JavaDoc();
66
67         setPreferredSize(new java.awt.Dimension JavaDoc(640, 480));
68         setLayout(new java.awt.BorderLayout JavaDoc());
69
70         jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
71         jSplitPane1.setLeftComponent(listView1);
72
73         record.setColumns(20);
74         record.setEditable(false);
75         record.setRows(5);
76         recordScroll.setViewportView(record);
77
78         jSplitPane1.setRightComponent(recordScroll);
79
80         org.jdesktop.layout.GroupLayout structuredLayout = new org.jdesktop.layout.GroupLayout(structured);
81         structured.setLayout(structuredLayout);
82         structuredLayout.setHorizontalGroup(
83             structuredLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
84             .add(structuredLayout.createSequentialGroup()
85                 .addContainerGap()
86                 .add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE)
87                 .addContainerGap())
88         );
89         structuredLayout.setVerticalGroup(
90             structuredLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
91             .add(structuredLayout.createSequentialGroup()
92                 .addContainerGap()
93                 .add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE)
94                 .addContainerGap())
95         );
96
97         tabs.addTab(org.openide.util.NbBundle.getMessage(SubmitPanel.class, "MSG_TabRaw"), structured); // NOI18N
98

99         text.setColumns(20);
100         text.setEditable(false);
101         text.setRows(5);
102         scroll.setViewportView(text);
103
104         org.jdesktop.layout.GroupLayout rawLayout = new org.jdesktop.layout.GroupLayout(raw);
105         raw.setLayout(rawLayout);
106         rawLayout.setHorizontalGroup(
107             rawLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
108             .add(org.jdesktop.layout.GroupLayout.TRAILING, rawLayout.createSequentialGroup()
109                 .addContainerGap()
110                 .add(scroll, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE)
111                 .addContainerGap())
112         );
113         rawLayout.setVerticalGroup(
114             rawLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
115             .add(org.jdesktop.layout.GroupLayout.TRAILING, rawLayout.createSequentialGroup()
116                 .addContainerGap()
117                 .add(scroll, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE)
118                 .addContainerGap())
119         );
120
121         tabs.addTab(org.openide.util.NbBundle.getMessage(SubmitPanel.class, "MSG_Tab_Text"), raw); // NOI18N
122

123         add(tabs, java.awt.BorderLayout.CENTER);
124     }// </editor-fold>//GEN-END:initComponents
125

126     public ExplorerManager getExplorerManager() {
127         return manager;
128     }
129     
130     public void addRecord(LogRecord JavaDoc r) {
131         ByteArrayOutputStream JavaDoc os = new ByteArrayOutputStream JavaDoc();
132         try {
133             LogRecords.write(os, r);
134             text.getDocument().insertString(text.getDocument().getLength(), os.toString(), null);
135             text.getCaret().setDot(0);
136         } catch (IOException JavaDoc ex) {
137             Installer.LOG.log(Level.WARNING, null, ex);
138         } catch (BadLocationException JavaDoc ex) {
139             Installer.LOG.log(Level.WARNING, null, ex);
140         }
141     }
142     
143     private void clearRecord() {
144         try {
145             record.getDocument().remove(0, record.getDocument().getLength());
146         } catch (BadLocationException JavaDoc ex) {
147             Logger.getLogger("global").log(Level.SEVERE,
148                 ex.getMessage(), ex);
149         }
150 }
151     
152     public void propertyChange(PropertyChangeEvent JavaDoc ev) {
153         if (ExplorerManager.PROP_SELECTED_NODES.equals(ev.getPropertyName())) {
154             Node[] arr = getExplorerManager().getSelectedNodes();
155             if (arr.length != 1) {
156                 clearRecord();
157                 return;
158             }
159             
160             LogRecord JavaDoc data = arr[0].getLookup().lookup(LogRecord JavaDoc.class);
161             if (data == null) {
162                 clearRecord();
163                 return;
164             }
165             
166             try {
167                 ByteArrayOutputStream JavaDoc os = new ByteArrayOutputStream JavaDoc();
168                 LogRecords.write(os, data);
169                 os.close();
170                 record.setText(os.toString());
171                 record.getCaret().setDot(0);
172             } catch (IOException JavaDoc ex) {
173                 Logger.getLogger("global").log(Level.SEVERE,
174                     ex.getMessage(), ex);
175                 clearRecord();
176             }
177             
178         }
179     }
180     
181     // Variables declaration - do not modify//GEN-BEGIN:variables
182
private javax.swing.JSplitPane JavaDoc jSplitPane1;
183     private org.openide.explorer.view.ListView listView1;
184     private javax.swing.JPanel JavaDoc raw;
185     private javax.swing.JTextArea JavaDoc record;
186     private javax.swing.JScrollPane JavaDoc recordScroll;
187     private javax.swing.JScrollPane JavaDoc scroll;
188     private javax.swing.JPanel JavaDoc structured;
189     private javax.swing.JTabbedPane JavaDoc tabs;
190     private javax.swing.JTextArea JavaDoc text;
191     // End of variables declaration//GEN-END:variables
192

193     private ExplorerManager manager;
194     
195 }
196
Popular Tags