KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piagetproject > topcomponent > StatsJPanel


1 /*
2  * SessionPanel.java
3  *
4  * Created on July 1, 2005, 10:59 AM
5  */

6
7 package org.netbeans.modules.piagetproject.topcomponent;
8 import java.awt.BorderLayout JavaDoc;
9 import java.awt.event.MouseEvent JavaDoc;
10 import java.text.NumberFormat JavaDoc;
11 import javax.swing.JComponent JavaDoc;
12 import javax.swing.JLabel JavaDoc;
13 import javax.swing.table.DefaultTableModel JavaDoc;
14 import org.netbeans.modules.piagetproject.property.Property;
15
16
17 /**
18  *
19  * @author loicsegapelli
20  */

21 public class StatsJPanel extends javax.swing.JPanel JavaDoc {
22     
23     private int yCounter;
24     private DefaultTableModel JavaDoc windowModel;
25     private static NumberFormat JavaDoc percent = NumberFormat.getPercentInstance();
26     
27     /** Creates new form SessionPanel */
28     public StatsJPanel(JComponent JavaDoc topComponent) {
29         myInitComponents();
30         initComponents();
31         yCounter = 2;
32         javax.swing.JScrollPane JavaDoc scroll = new javax.swing.JScrollPane JavaDoc();
33         scroll.setViewportView(this);
34         
35         topComponent.setLayout(new BorderLayout JavaDoc());
36         topComponent.add(scroll);
37     }
38     
39     private void myInitComponents(){
40         windowModel = new DefaultTableModel JavaDoc(null, new String JavaDoc [] {
41             "TopComponent",
42                     "Opened",
43                     "Activated"
44         });
45         
46     }
47     
48     public void addWindowRow(String JavaDoc name, double opened, double activated){
49         String JavaDoc openedS = percent.format(opened);
50         String JavaDoc activatedS = percent.format(activated);
51         Object JavaDoc [] row = new Object JavaDoc [] {name, openedS, activatedS};
52         windowModel.addRow(row);
53         int rc = windowModel.getRowCount();
54         jScrollPane1.setPreferredSize(new java.awt.Dimension JavaDoc(120, 50+16*rc));
55     }
56     
57
58     
59     public void addTable(String JavaDoc title, String JavaDoc content){
60         final javax.swing.JLabel JavaDoc LABEL = new javax.swing.JLabel JavaDoc();
61         final String JavaDoc CONTENT = content;
62         LABEL.setBorder(new javax.swing.border.TitledBorder JavaDoc(null, title, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font JavaDoc("Lucida Grande", 1, 13)));
63         LABEL.setOpaque(true);
64         LABEL.setText(CONTENT);
65         LABEL.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
66             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
67                 expandLabel(evt, LABEL, CONTENT);
68             }
69         });
70         
71         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
72         gridBagConstraints.gridx = 0;
73         if(title.equals(Property.LOG_TABLE)) gridBagConstraints.gridy = 0;
74         else gridBagConstraints.gridy = yCounter++;
75         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
76         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
77         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
78         gridBagConstraints.weightx = 1.0;
79         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 11, 11);
80         add(LABEL, gridBagConstraints);
81     }
82     
83     private void expandLabel(MouseEvent JavaDoc evt, JLabel JavaDoc label, String JavaDoc text) {
84         if(evt.getClickCount()!=2) return;
85         String JavaDoc s = label.getText();
86         if(s.equals("")){
87             label.setText(text);
88         }else {
89             label.setText("");
90         }
91         this.repaint();
92     }
93     
94     /** This method is called from within the constructor to
95      * initialize the form.
96      * WARNING: Do NOT modify this code. The content of this method is
97      * always regenerated by the Form Editor.
98      */

99     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
100
private void initComponents() {
101         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
102
103         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
104         jTable1 = new javax.swing.JTable JavaDoc(windowModel);
105         jLabel3 = new javax.swing.JLabel JavaDoc();
106
107         setLayout(new java.awt.GridBagLayout JavaDoc());
108
109         jScrollPane1.setBorder(new javax.swing.border.TitledBorder JavaDoc(null, "TopComponents", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font JavaDoc("Lucida Grande", 1, 13)));
110         jScrollPane1.setMaximumSize(null);
111         jScrollPane1.setMinimumSize(null);
112         jScrollPane1.setPreferredSize(new java.awt.Dimension JavaDoc(120, 120));
113         jTable1.setMaximumSize(null);
114         jTable1.setMinimumSize(null);
115         jTable1.setName("windowTable");
116         jTable1.setPreferredSize(null);
117         jTable1.setRowMargin(2);
118         //JScrollPane scrollPane = new JScrollPane(jTable1);
119
//jTable1.setPreferredScrollableViewportSize(new Dimension(jTable1.getColumnCount()*100, jTable1.getColumnCount()*50));
120
//jTable1.setPreferredScrollableViewportSize(new Dimension(300, 100));
121
jScrollPane1.setViewportView(jTable1);
122
123         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
124         gridBagConstraints.gridx = 0;
125         gridBagConstraints.gridy = 1;
126         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
127         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
128         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
129         gridBagConstraints.weightx = 1.0;
130         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 11, 11);
131         add(jScrollPane1, gridBagConstraints);
132
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridx = 0;
135         gridBagConstraints.gridy = 15;
136         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
137         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
138         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
139         gridBagConstraints.weightx = 1.0;
140         gridBagConstraints.weighty = 1.0;
141         add(jLabel3, gridBagConstraints);
142
143     }
144     // </editor-fold>//GEN-END:initComponents
145

146     
147     // Variables declaration - do not modify//GEN-BEGIN:variables
148
private javax.swing.JLabel JavaDoc jLabel3;
149     private javax.swing.JScrollPane JavaDoc jScrollPane1;
150     private javax.swing.JTable JavaDoc jTable1;
151     // End of variables declaration//GEN-END:variables
152

153 }
154
Popular Tags