1 10 11 package org.netbeans.modules.piagetproject.treestructure; 12 13 import java.awt.Image ; 14 import java.text.SimpleDateFormat ; 15 import java.util.Date ; 16 import javax.swing.AbstractAction ; 17 import javax.swing.Action ; 18 import javax.swing.event.ChangeListener ; 19 import org.netbeans.modules.piagetproject.topcomponent.SessionFileWrapper; 20 import org.netbeans.modules.piagetproject.topcomponent.SessionTopComponent; 21 import org.openide.nodes.AbstractNode; 22 import org.openide.nodes.Children; 23 import org.openide.util.Utilities; 24 import org.openide.windows.Mode; 25 import org.openide.windows.TopComponent; 26 import org.openide.windows.WindowManager; 27 28 29 33 public class SessionNode extends AbstractNode implements PiagetTreeNode{ 34 private String filepath, name; 36 private ChangeListener listener; 37 private String level, username; 38 39 public SessionNode(String key, String filepath, String username, String level) { 40 super(Children.LEAF); 41 this.username = username; 42 this.level = level; 43 this.filepath = filepath; 44 int dotIndex = key.indexOf("."); 46 String sessionTime = key.substring(0, dotIndex); 47 48 long l = Long.parseLong(sessionTime); 49 name = prettyDate(l); 50 super.setName(name); 51 setShortDescription("Session node"); 52 } 53 54 55 public Action [] getActions(boolean context) { 56 Action [] result = new Action [] { 57 StatsAction.getInstance(), 58 new DeleteAction((AbstractNode)this, filepath) 59 }; 60 return result; 61 } 62 63 public String getFilepath(){ 64 return filepath; 65 } 66 67 public Image getIcon(int type) { 68 return Utilities.loadImage("org/netbeans/modules/piagetproject/resources/session.png"); 69 } 70 71 public Image getOpenedIcon(int type) { 72 return getIcon(type); 73 } 74 75 public static String prettyDate(long l){ 76 Date date = new Date (); 77 date.setTime(l); 78 SimpleDateFormat format = new SimpleDateFormat ("dd.MM.yy 'at' HH:mm"); 79 return format.format(date); 80 } 81 82 public Action getPreferredAction() { 83 return StatsAction.getInstance(); 84 } 85 86 public Info [] getInfos() { 87 return new Info[] {new Info(filepath, username, level)}; 88 } 89 90 } | Popular Tags |