KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > console > ObjectFrame


1 package org.sape.carbon.services.console;
2
3
4 import java.awt.Color JavaDoc;
5 import java.io.ByteArrayOutputStream JavaDoc;
6
7 import javax.swing.JInternalFrame JavaDoc;
8 import javax.swing.table.DefaultTableColumnModel JavaDoc;
9 import javax.swing.table.TableColumn JavaDoc;
10
11 import org.sape.carbon.core.config.Config;
12 import org.sape.carbon.core.config.Configuration;
13 import org.sape.carbon.core.config.format.DefaultConfigurationFormatService;
14 import org.sape.carbon.services.swing.treetable.JTreeTable;
15
16 /**
17  * <P>This class provides a tree and xml view into configuration objects.</P>
18  *
19  * Copyright 2002 Sapient
20  * @since carbon 1.0
21  * @author Greg Hinkle, January 2002
22  * @version $Revision: 1.18 $($Author: ghinkl $ / $Date: 2003/04/04 01:11:49 $)
23  */

24 public class ObjectFrame extends JInternalFrame JavaDoc {
25
26     protected Configuration config;
27
28     /** Creates new form ObjectFrame */
29     public ObjectFrame(Configuration config) {
30         System.out.println("Showing ObjectFrame for [" + config.getConfigurationName() + "]");
31         this.config = config;
32         initComponents();
33
34         loadTree();
35         loadXMLPane();
36         this.setTitle(config.getConfigurationName());
37     }
38
39     
40     
41
42
43
44
45     private void loadTree() {
46
47         ObjectTreeModel treeTableModel = new ObjectTreeModel(config);
48         this.treeTable = new JTreeTable(treeTableModel);
49         this.jScrollPane1.setViewportView(this.treeTable);
50
51         DefaultTableColumnModel JavaDoc cm = new DefaultTableColumnModel JavaDoc();
52         TableColumn JavaDoc cName, cValue, cEdit;
53         cName = new TableColumn JavaDoc(0, 150);
54         cName.setHeaderValue("Name");
55         cValue = new TableColumn JavaDoc(1,200);
56         cValue.setHeaderValue("Value");
57         cEdit = new TableColumn JavaDoc(2,80);
58         cEdit.setHeaderValue("Type");
59         //cEdit.setMaxWidth(25);
60

61         cm.addColumn(cName);
62         cm.addColumn(cValue);
63         cm.addColumn(cEdit);
64
65         this.treeTable.setColumnModel(cm);
66         this.treeTable.getColumnModel().
67             getColumn(1).setCellRenderer(
68             new ConfigurationDataRenderer());
69         this.treeTable.getColumnModel().
70             getColumn(1).setCellEditor(
71             new ConfigurationDataEditor());
72         // Displays the header
73
//this.treeTable.configureEnclosingScrollPane();
74

75         //this.jScrollPane1.setColumnHeaderView(this.treeTable.getTableHeader());
76

77         this.treeTable.setRowHeight(22);
78         this.jScrollPane1.getComponent(0).setBackground(Color.white);
79         this.jScrollPane1.repaint();
80     }
81
82     private void loadXMLPane() {
83
84         try {
85         ByteArrayOutputStream JavaDoc baos =
86             new ByteArrayOutputStream JavaDoc(32000);
87
88         DefaultConfigurationFormatService dcfs = new DefaultConfigurationFormatService();
89         dcfs.writeConfigurationStream(this.config,baos);
90
91         this.XmlViewJEditorPane.setText(baos.toString("ISO-8859-1"));
92
93         } catch (Exception JavaDoc e) {
94
95             this.XmlViewJEditorPane.setText(e.toString());
96
97         }
98     }
99     
100     /** This method is called from within the constructor to
101      * initialize the form.
102      * WARNING: Do NOT modify this code. The content of this method is
103      * always regenerated by the Form Editor.
104      */

105     private void initComponents() {//GEN-BEGIN:initComponents
106
ObjectViewJTabbedPane = new javax.swing.JTabbedPane JavaDoc();
107         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
108         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
109         XmlViewJEditorPane = new javax.swing.JEditorPane JavaDoc();
110         topPanel = new javax.swing.JPanel JavaDoc();
111         jButton1 = new javax.swing.JButton JavaDoc();
112         jButton2 = new javax.swing.JButton JavaDoc();
113
114         setClosable(true);
115         setIconifiable(true);
116         setMaximizable(true);
117         setResizable(true);
118         setPreferredSize(new java.awt.Dimension JavaDoc(225, 406));
119         ObjectViewJTabbedPane.setBackground(new java.awt.Color JavaDoc(204, 204, 204));
120         jScrollPane1.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
121         ObjectViewJTabbedPane.addTab("Object View", jScrollPane1);
122
123         XmlViewJEditorPane.setFont(new java.awt.Font JavaDoc("Courier New", 0, 12));
124         jScrollPane2.setViewportView(XmlViewJEditorPane);
125
126         ObjectViewJTabbedPane.addTab("XML View", jScrollPane2);
127
128         getContentPane().add(ObjectViewJTabbedPane, java.awt.BorderLayout.CENTER);
129
130         jButton1.setText("Save");
131         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
132             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
133                 jButton1ActionPerformed(evt);
134             }
135         });
136
137         topPanel.add(jButton1);
138
139         jButton2.setText("Refresh");
140         jButton2.addActionListener(new java.awt.event.ActionListener JavaDoc() {
141             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
142                 jButton2ActionPerformed(evt);
143             }
144         });
145
146         topPanel.add(jButton2);
147
148         getContentPane().add(topPanel, java.awt.BorderLayout.NORTH);
149
150         pack();
151     }//GEN-END:initComponents
152

153     private void jButton2ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton2ActionPerformed
154
// Add your handling code here:
155
this.loadXMLPane();
156     }//GEN-LAST:event_jButton2ActionPerformed
157

158     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
159
// Add your handling code here:
160
try {
161             Config.getInstance().storeConfiguration(this.config.getConfigurationName(),this.config);
162             this.loadXMLPane();
163         } catch (Exception JavaDoc e) {
164             e.printStackTrace();
165         }
166     }//GEN-LAST:event_jButton1ActionPerformed
167

168     private void parameterTablePropertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {//GEN-FIRST:event_parameterTablePropertyChange
169
}//GEN-LAST:event_parameterTablePropertyChange
170

171     private void jSplitPane1InputMethodTextChanged(java.awt.event.InputMethodEvent JavaDoc evt) {//GEN-FIRST:event_jSplitPane1InputMethodTextChanged
172
// Add your handling code here:
173
System.out.println("Changed: " + evt.getSource());
174         System.out.println("To: " + evt.getText());
175     }//GEN-LAST:event_jSplitPane1InputMethodTextChanged
176

177     private void objectTreeValueChanged(javax.swing.event.TreeSelectionEvent JavaDoc evt) {//GEN-FIRST:event_objectTreeValueChanged
178
}//GEN-LAST:event_objectTreeValueChanged
179

180
181     // Variables declaration - do not modify//GEN-BEGIN:variables
182
private javax.swing.JButton JavaDoc jButton2;
183     private javax.swing.JButton JavaDoc jButton1;
184     private javax.swing.JScrollPane JavaDoc jScrollPane2;
185     private javax.swing.JScrollPane JavaDoc jScrollPane1;
186     private javax.swing.JPanel JavaDoc topPanel;
187     private javax.swing.JEditorPane JavaDoc XmlViewJEditorPane;
188     private javax.swing.JTabbedPane JavaDoc ObjectViewJTabbedPane;
189     // End of variables declaration//GEN-END:variables
190
private JTreeTable treeTable;
191 }
192
Popular Tags