KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * SessionTopComponent.java
3  *
4  * Created on July 1, 2005, 10:52 AM
5  *
6  * To change this template, choose Tools | Options and locate the template under
7  * the Source Creation and Management node. Right-click the template and choose
8  * Open. You can then make changes to the template in the Source Editor.
9  */

10
11 package org.netbeans.modules.piagetproject.topcomponent;
12 import java.util.ArrayList JavaDoc;
13 import java.util.Enumeration JavaDoc;
14 import org.netbeans.modules.piagetproject.property.Property;
15 import org.openide.windows.Mode;
16 import org.openide.windows.TopComponent;
17 import org.openide.windows.WindowManager;
18
19 /**
20  *
21  * @author loicsegapelli
22  */

23 public class SessionTopComponent extends TopComponent {
24     
25     private static final String JavaDoc PREFF_ID = "sessionTab";
26     private static String JavaDoc tcID = PREFF_ID;
27     private static final String JavaDoc MODE = "explorer";
28     private ArrayList JavaDoc filename;
29     private static final int LEVEL_INDEX = 0;
30     private static final int NAME_INDEX = 1;
31     private static final int DATE_INDEX = 2;
32     
33     /** Creates a new instance of SessionTopComponent */
34     public SessionTopComponent() {
35         this.setName("Piaget");
36     }
37     
38     public void initComponents(int total, String JavaDoc tcName){
39         StatsJPanel panel = new StatsJPanel(this);
40         
41         String JavaDoc windowString = Property.WINDOW_TABLE;
42         Property [] windows = Property.getTableElements(windowString);
43         for(int i=0; i<windows.length; i++){
44             String JavaDoc name = windows[i].getName();
45             /*the window "Out_NetBeans is artificial: we do not display it*/
46             if(name.equals(Property.OUT)) continue;
47             double d [] = (double [])windows[i].getValue(total);
48             panel.addWindowRow(name, d[0], d[1]);
49         }
50         
51         String JavaDoc id [] = Property.getTableIDs();
52         for(int i=0; i<id.length; i++){
53             if(!id[i].equals(Property.WINDOW_TABLE))
54                 generateTable(id[i], panel, total);
55         }
56         
57         if(total>1) this.setDisplayName("Piaget: multiple");
58         else this.setDisplayName("Piaget: "+tcName);
59     }
60     
61     private void generateTable(String JavaDoc tableName, StatsJPanel panel, int total){
62         Property p [] = Property.getTableElements(tableName);
63         if (p==null || p.length==0) return;
64         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
65         buf.append("<html><table border=\"0\">");
66         for(int i=0; i<p.length; i++){
67             buf.append("<tr><td></td>");
68             buf.append("<td><b>"+p[i].getName()+"</b></td>");
69             buf.append("<td>"+p[i].getValue(total).toString()+"</td>");
70             buf.append("</tr>");
71         }
72         buf.append("</table></html>");
73         panel.addTable(tableName, buf.toString());
74     }
75     
76     
77     public static synchronized void activate(){
78         TopComponent comp = getInstance();
79         comp.open();
80         comp.requestActive();
81     }
82     
83     public static synchronized SessionTopComponent getInstance(){
84         TopComponent c;
85         c = WindowManager.getDefault().findTopComponent(tcID);
86         if(c == null){
87             // create new one
88
c = new SessionTopComponent();
89             tcID = WindowManager.getDefault().findTopComponentID(c);
90         }
91         return (SessionTopComponent)c;
92     }
93     
94     protected String JavaDoc preferredID() {
95         return PREFF_ID;
96     }
97     
98     public int getPersistenceType() {
99         return TopComponent.PERSISTENCE_NEVER;
100     }
101     
102     public void open(){
103         Mode m = WindowManager.getDefault().findMode("editor");
104         m.dockInto(this);
105         super.open();
106     }
107 }
108
Popular Tags