1 19 20 package org.netbeans.modules.uihandler; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.ByteArrayOutputStream ; 25 import java.io.IOException ; 26 import java.util.logging.Level ; 27 import java.util.logging.LogRecord ; 28 import java.util.logging.Logger ; 29 import javax.swing.text.BadLocationException ; 30 import org.netbeans.lib.uihandler.LogRecords; 31 import org.openide.explorer.ExplorerManager; 32 import org.openide.nodes.Node; 33 34 38 public class SubmitPanel extends javax.swing.JPanel 39 implements ExplorerManager.Provider, PropertyChangeListener { 40 41 42 public SubmitPanel() { 43 manager = new ExplorerManager(); 44 45 initComponents(); 46 manager.addPropertyChangeListener(this); 47 } 48 49 54 private void initComponents() { 56 57 tabs = new javax.swing.JTabbedPane (); 58 structured = new javax.swing.JPanel (); 59 jSplitPane1 = new javax.swing.JSplitPane (); 60 listView1 = new org.openide.explorer.view.ListView(); 61 recordScroll = new javax.swing.JScrollPane (); 62 record = new javax.swing.JTextArea (); 63 raw = new javax.swing.JPanel (); 64 scroll = new javax.swing.JScrollPane (); 65 text = new javax.swing.JTextArea (); 66 67 setPreferredSize(new java.awt.Dimension (640, 480)); 68 setLayout(new java.awt.BorderLayout ()); 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); 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); 123 add(tabs, java.awt.BorderLayout.CENTER); 124 } 126 public ExplorerManager getExplorerManager() { 127 return manager; 128 } 129 130 public void addRecord(LogRecord r) { 131 ByteArrayOutputStream os = new ByteArrayOutputStream (); 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 ex) { 137 Installer.LOG.log(Level.WARNING, null, ex); 138 } catch (BadLocationException 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 ex) { 147 Logger.getLogger("global").log(Level.SEVERE, 148 ex.getMessage(), ex); 149 } 150 } 151 152 public void propertyChange(PropertyChangeEvent 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 data = arr[0].getLookup().lookup(LogRecord .class); 161 if (data == null) { 162 clearRecord(); 163 return; 164 } 165 166 try { 167 ByteArrayOutputStream os = new ByteArrayOutputStream (); 168 LogRecords.write(os, data); 169 os.close(); 170 record.setText(os.toString()); 171 record.getCaret().setDot(0); 172 } catch (IOException ex) { 173 Logger.getLogger("global").log(Level.SEVERE, 174 ex.getMessage(), ex); 175 clearRecord(); 176 } 177 178 } 179 } 180 181 private javax.swing.JSplitPane jSplitPane1; 183 private org.openide.explorer.view.ListView listView1; 184 private javax.swing.JPanel raw; 185 private javax.swing.JTextArea record; 186 private javax.swing.JScrollPane recordScroll; 187 private javax.swing.JScrollPane scroll; 188 private javax.swing.JPanel structured; 189 private javax.swing.JTabbedPane tabs; 190 private javax.swing.JTextArea text; 191 193 private ExplorerManager manager; 194 195 } 196 | Popular Tags |