1 6 7 package org.netbeans.modules.piagetproject.topcomponent; 8 import java.awt.BorderLayout ; 9 import java.awt.event.MouseEvent ; 10 import java.text.NumberFormat ; 11 import javax.swing.JComponent ; 12 import javax.swing.JLabel ; 13 import javax.swing.table.DefaultTableModel ; 14 import org.netbeans.modules.piagetproject.property.Property; 15 16 17 21 public class StatsJPanel extends javax.swing.JPanel { 22 23 private int yCounter; 24 private DefaultTableModel windowModel; 25 private static NumberFormat percent = NumberFormat.getPercentInstance(); 26 27 28 public StatsJPanel(JComponent topComponent) { 29 myInitComponents(); 30 initComponents(); 31 yCounter = 2; 32 javax.swing.JScrollPane scroll = new javax.swing.JScrollPane (); 33 scroll.setViewportView(this); 34 35 topComponent.setLayout(new BorderLayout ()); 36 topComponent.add(scroll); 37 } 38 39 private void myInitComponents(){ 40 windowModel = new DefaultTableModel (null, new String [] { 41 "TopComponent", 42 "Opened", 43 "Activated" 44 }); 45 46 } 47 48 public void addWindowRow(String name, double opened, double activated){ 49 String openedS = percent.format(opened); 50 String activatedS = percent.format(activated); 51 Object [] row = new Object [] {name, openedS, activatedS}; 52 windowModel.addRow(row); 53 int rc = windowModel.getRowCount(); 54 jScrollPane1.setPreferredSize(new java.awt.Dimension (120, 50+16*rc)); 55 } 56 57 58 59 public void addTable(String title, String content){ 60 final javax.swing.JLabel LABEL = new javax.swing.JLabel (); 61 final String CONTENT = content; 62 LABEL.setBorder(new javax.swing.border.TitledBorder (null, title, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font ("Lucida Grande", 1, 13))); 63 LABEL.setOpaque(true); 64 LABEL.setText(CONTENT); 65 LABEL.addMouseListener(new java.awt.event.MouseAdapter () { 66 public void mouseClicked(java.awt.event.MouseEvent evt) { 67 expandLabel(evt, LABEL, CONTENT); 68 } 69 }); 70 71 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 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 (12, 12, 11, 11); 80 add(LABEL, gridBagConstraints); 81 } 82 83 private void expandLabel(MouseEvent evt, JLabel label, String text) { 84 if(evt.getClickCount()!=2) return; 85 String s = label.getText(); 86 if(s.equals("")){ 87 label.setText(text); 88 }else { 89 label.setText(""); 90 } 91 this.repaint(); 92 } 93 94 99 private void initComponents() { 101 java.awt.GridBagConstraints gridBagConstraints; 102 103 jScrollPane1 = new javax.swing.JScrollPane (); 104 jTable1 = new javax.swing.JTable (windowModel); 105 jLabel3 = new javax.swing.JLabel (); 106 107 setLayout(new java.awt.GridBagLayout ()); 108 109 jScrollPane1.setBorder(new javax.swing.border.TitledBorder (null, "TopComponents", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font ("Lucida Grande", 1, 13))); 110 jScrollPane1.setMaximumSize(null); 111 jScrollPane1.setMinimumSize(null); 112 jScrollPane1.setPreferredSize(new java.awt.Dimension (120, 120)); 113 jTable1.setMaximumSize(null); 114 jTable1.setMinimumSize(null); 115 jTable1.setName("windowTable"); 116 jTable1.setPreferredSize(null); 117 jTable1.setRowMargin(2); 118 jScrollPane1.setViewportView(jTable1); 122 123 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (12, 12, 11, 11); 131 add(jScrollPane1, gridBagConstraints); 132 133 gridBagConstraints = new java.awt.GridBagConstraints (); 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 146 147 private javax.swing.JLabel jLabel3; 149 private javax.swing.JScrollPane jScrollPane1; 150 private javax.swing.JTable jTable1; 151 153 } 154 | Popular Tags |