1 package prefuse.controls; 2 3 import java.awt.event.MouseEvent ; 4 5 import prefuse.Display; 6 import prefuse.visual.VisualItem; 7 8 9 14 public class ToolTipControl extends ControlAdapter { 15 16 private String [] label; 17 private StringBuffer sbuf; 18 19 23 public ToolTipControl(String field) { 24 this(new String [] {field}); 25 } 26 27 32 public ToolTipControl(String [] fields) { 33 label = fields; 34 if ( fields.length > 1 ) 35 sbuf = new StringBuffer (); 36 } 37 38 41 public void itemEntered(VisualItem item, MouseEvent e) { 42 Display d = (Display)e.getSource(); 43 if ( label.length == 1 ) { 44 if ( item.canGetString(label[0]) ) 46 d.setToolTipText(item.getString(label[0])); 47 } else { 48 sbuf.delete(0, sbuf.length()); 49 for ( int i=0; i<label.length; ++i ) { 50 if ( item.canGetString(label[i]) ) { 51 if ( sbuf.length() > 0 ) 52 sbuf.append("; "); 53 sbuf.append(item.getString(label[i])); 54 } 55 } 56 d.setToolTipText(sbuf.toString()); 57 } 58 } 59 60 63 public void itemExited(VisualItem item, MouseEvent e) { 64 Display d = (Display)e.getSource(); 65 d.setToolTipText(null); 66 } 67 68 } | Popular Tags |