KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > graph > AttributeGraphPanel


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
27 import java.awt.dnd.DropTarget JavaDoc;
28 import java.awt.dnd.DropTargetDragEvent JavaDoc;
29 import java.awt.dnd.DropTargetDropEvent JavaDoc;
30 import java.awt.dnd.DropTargetEvent JavaDoc;
31 import java.awt.dnd.DropTargetListener JavaDoc;
32 import java.util.List JavaDoc;
33
34 /**
35  * This TopComponent is a graph of JMX MBean Attributes. It only works
36  * with numeric attributes.
37  *
38  * @author Greg Hinkle (ghinkle@users.sourceforge.net), January 2002
39  * @version $Revision: 570 $($Author: ghinkl $ / $Date: 2006-04-12 15:14:16 -0400 (Wed, 12 Apr 2006) $)
40  */

41 public class AttributeGraphPanel extends AbstractGraphPanel implements DropTargetListener JavaDoc {
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 JavaDoc(this,this));
52     }
53
54     public AttributeGraphPanel(List JavaDoc<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 JavaDoc {
72
73         for (Object JavaDoc at : getTimeSeriesKeys()) {
74             EmsAttribute attribute = (EmsAttribute) at;
75             Object JavaDoc value = attribute.refresh();
76             Number JavaDoc val = (Number JavaDoc) value;
77
78             TimeSeries ts = getTimeSeries(attribute);
79             ts.add(new Millisecond(), val.doubleValue());
80         }
81     }
82
83     /**
84      * We handle drops of AttributeNodes only at this time
85      * @param dtde
86      */

87     public void drop(DropTargetDropEvent JavaDoc dtde) {
88
89         dtde.acceptDrop( DnDConstants.ACTION_REFERENCE);
90
91         // For some stupid reason, this utility requires action mapping, so i can't ignore action types like i want to
92
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 JavaDoc dtde) {
105     }
106
107     public void dragOver(DropTargetDragEvent JavaDoc dtde) {
108     }
109
110     public void dropActionChanged(DropTargetDragEvent JavaDoc dtde) {
111     }
112
113     public void dragExit(DropTargetEvent JavaDoc dte) {
114     }
115 }
116
Popular Tags