1 16 17 package org.mc4j.console.swing.graph; 18 19 import org.jfree.data.time.Millisecond; 20 import org.jfree.data.time.TimeSeries; 21 import org.mc4j.console.bean.attribute.AttributeNode; 22 import org.mc4j.ems.connection.bean.attribute.EmsAttribute; 23 import org.openide.nodes.Node; 24 import org.openide.nodes.NodeTransfer; 25 26 import java.awt.dnd.DnDConstants ; 27 import java.awt.dnd.DropTarget ; 28 import java.awt.dnd.DropTargetDragEvent ; 29 import java.awt.dnd.DropTargetDropEvent ; 30 import java.awt.dnd.DropTargetEvent ; 31 import java.awt.dnd.DropTargetListener ; 32 import java.util.List ; 33 34 41 public class AttributeGraphPanel extends AbstractGraphPanel implements DropTargetListener { 42 43 private static int graphNumber = 1; 44 45 46 public AttributeGraphPanel() { 47 } 48 49 protected void initGraphPanel() { 50 super.initGraphPanel(); 51 chartPanel.setDropTarget(new DropTarget (this,this)); 52 } 53 54 public AttributeGraphPanel(List <EmsAttribute> attributes) { 55 for (EmsAttribute attribute : attributes) { 56 addAttribute(attribute); 57 } 58 59 if (attributes.size() == 1) { 60 setChartTitle(attributes.get(0).getName() + " Graph"); 61 } else { 62 setChartTitle("Graph " + graphNumber++); 63 } 64 reschedule(); 65 } 66 67 public void addAttribute(EmsAttribute attribute) { 68 createTimeSeries(attribute.getName(),attribute); 69 } 70 71 public void addObservation() throws Exception { 72 73 for (Object at : getTimeSeriesKeys()) { 74 EmsAttribute attribute = (EmsAttribute) at; 75 Object value = attribute.refresh(); 76 Number val = (Number ) value; 77 78 TimeSeries ts = getTimeSeries(attribute); 79 ts.add(new Millisecond(), val.doubleValue()); 80 } 81 } 82 83 87 public void drop(DropTargetDropEvent dtde) { 88 89 dtde.acceptDrop( DnDConstants.ACTION_REFERENCE); 90 91 Node[] nodes = NodeTransfer.nodes(dtde.getTransferable(), 1); 93 94 for (Node node : nodes) { 95 if (node instanceof AttributeNode) { 96 EmsAttribute attribute = ((AttributeNode) node).getEmsAttribute(); 97 if (attribute.isNumericType()) { 98 addAttribute(attribute); 99 } 100 } 101 } 102 } 103 104 public void dragEnter(DropTargetDragEvent dtde) { 105 } 106 107 public void dragOver(DropTargetDragEvent dtde) { 108 } 109 110 public void dropActionChanged(DropTargetDragEvent dtde) { 111 } 112 113 public void dragExit(DropTargetEvent dte) { 114 } 115 } 116 | Popular Tags |