1 10 11 package org.netbeans.modules.piagetproject.topcomponent; 12 import java.util.ArrayList ; 13 import java.util.Enumeration ; 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 23 public class SessionTopComponent extends TopComponent { 24 25 private static final String PREFF_ID = "sessionTab"; 26 private static String tcID = PREFF_ID; 27 private static final String MODE = "explorer"; 28 private ArrayList 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 34 public SessionTopComponent() { 35 this.setName("Piaget"); 36 } 37 38 public void initComponents(int total, String tcName){ 39 StatsJPanel panel = new StatsJPanel(this); 40 41 String windowString = Property.WINDOW_TABLE; 42 Property [] windows = Property.getTableElements(windowString); 43 for(int i=0; i<windows.length; i++){ 44 String name = windows[i].getName(); 45 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 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 tableName, StatsJPanel panel, int total){ 62 Property p [] = Property.getTableElements(tableName); 63 if (p==null || p.length==0) return; 64 StringBuffer buf = new StringBuffer (); 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 c = new SessionTopComponent(); 89 tcID = WindowManager.getDefault().findTopComponentID(c); 90 } 91 return (SessionTopComponent)c; 92 } 93 94 protected String 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 |