[Mc4j-cvs] mc4j/src/org/mc4j/console/swing/graph GraphSeriesPanel.java,1.1,1.2 GlassWindow.java,1.1,
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2006-04-12 19:14:43
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/swing/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20162/src/org/mc4j/console/swing/graph Modified Files: AbstractGraphPanel.java Added Files: GraphSeriesPanel.java GlassWindow.java AttributeGraphPanel.java Log Message: Merging EMS into head for the 2.0 release work --- NEW FILE: GraphSeriesPanel.java --- /* * Copyright 2002-2005 Greg Hinkle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.mc4j.console.swing.graph; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.decorator.HighlighterPipeline; import org.jdesktop.swingx.decorator.Highlighter; import org.jdesktop.swingx.decorator.AlternateRowHighlighter; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.mc4j.ems.connection.bean.attribute.EmsAttribute; import javax.swing.*; import javax.swing.table.AbstractTableModel; import java.awt.BorderLayout; import java.awt.Dimension; /** * @author Greg Hinkle (gh...@us...), Mar 30, 2006 * @version $Revision: 1.2 $($Author: ghinkl $ / $Date: 2006/04/12 19:14:06 $) */ public class GraphSeriesPanel extends JPanel { TimeSeriesCollection timeSeriesCollection; public GraphSeriesPanel(TimeSeriesCollection timeSeriesCollection) { this.timeSeriesCollection = timeSeriesCollection; init(); } private void init() { setLayout(new BorderLayout()); add(new JLabel("Currently graphed attributes"), BorderLayout.NORTH); JXTable table = new JXTable(new SeriesTableModel()); table.setHighlighters(new HighlighterPipeline(new Highlighter[] { new AlternateRowHighlighter() })); table.setColumnControlVisible(true); add(new JScrollPane(table), BorderLayout.CENTER); setSize(450,250); setPreferredSize(new Dimension(450,250)); } private class SeriesTableModel extends AbstractTableModel { public int getRowCount() { return timeSeriesCollection.getSeriesCount(); } public int getColumnCount() { return 3; } public String getColumnName(int column) { switch (column) { case 0: return "Name"; case 1: return "Description"; case 2: return "Value"; default: return ""; } } public Class<?> getColumnClass(int column) { switch (column) { case 0: return String.class; case 1: return String.class; case 2: return Number.class; default: return Object.class; } } public Object getValueAt(int row, int column) { TimeSeries s = timeSeriesCollection.getSeries(row); EmsAttribute attribute = (EmsAttribute) s.getKey(); switch (column) { case 0: return attribute.getName(); case 1: return attribute.getDescription(); case 2: return attribute.getValue(); case 3: return new JButton("Hi"); default: return s; } } } } --- NEW FILE: AttributeGraphPanel.java --- /* * Copyright 2002-2004 Greg Hinkle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.mc4j.console.swing.graph; import org.jfree.data.time.Millisecond; import org.jfree.data.time.TimeSeries; import org.mc4j.console.bean.attribute.AttributeNode; import org.mc4j.ems.connection.bean.attribute.EmsAttribute; import org.openide.nodes.Node; import org.openide.nodes.NodeTransfer; import java.awt.dnd.DnDConstants; import java.awt.dnd.DropTarget; import java.awt.dnd.DropTargetDragEvent; import java.awt.dnd.DropTargetDropEvent; import java.awt.dnd.DropTargetEvent; import java.awt.dnd.DropTargetListener; import java.util.List; /** * This TopComponent is a graph of JMX MBean Attributes. It only works * with numeric attributes. * * @author Greg Hinkle (gh...@us...), January 2002 * @version $Revision: 1.2 $($Author: ghinkl $ / $Date: 2006/04/12 19:14:06 $) */ public class AttributeGraphPanel extends AbstractGraphPanel implements DropTargetListener { private static int graphNumber = 1; public AttributeGraphPanel() { } protected void initGraphPanel() { super.initGraphPanel(); chartPanel.setDropTarget(new DropTarget(this,this)); } public AttributeGraphPanel(List<EmsAttribute> attributes) { for (EmsAttribute attribute : attributes) { addAttribute(attribute); } if (attributes.size() == 1) { setChartTitle(attributes.get(0).getName() + " Graph"); } else { setChartTitle("Graph " + graphNumber++); } reschedule(); } public void addAttribute(EmsAttribute attribute) { createTimeSeries(attribute.getName(),attribute); } public void addObservation() throws Exception { for (Object at : getTimeSeriesKeys()) { EmsAttribute attribute = (EmsAttribute) at; Object value = attribute.refresh(); Number val = (Number) value; TimeSeries ts = getTimeSeries(attribute); ts.add(new Millisecond(), val.doubleValue()); } } /** * We handle drops of AttributeNodes only at this time * @param dtde */ public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop( DnDConstants.ACTION_REFERENCE); // For some stupid reason, this utility requires action mapping, so i can't ignore action types like i want to Node[] nodes = NodeTransfer.nodes(dtde.getTransferable(), 1); for (Node node : nodes) { if (node instanceof AttributeNode) { EmsAttribute attribute = ((AttributeNode) node).getEmsAttribute(); if (attribute.isNumericType()) { addAttribute(attribute); } } } } public void dragEnter(DropTargetDragEvent dtde) { } public void dragOver(DropTargetDragEvent dtde) { } public void dropActionChanged(DropTargetDragEvent dtde) { } public void dragExit(DropTargetEvent dte) { } } Index: AbstractGraphPanel.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/swing/graph/AbstractGraphPanel.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** AbstractGraphPanel.java 5 Oct 2004 05:16:03 -0000 1.9 --- AbstractGraphPanel.java 12 Apr 2006 19:14:06 -0000 1.10 *************** *** 23,37 **** import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.XYPlot; ! import org.jfree.chart.renderer.DefaultXYItemRenderer; import org.jfree.chart.title.TextTitle; import org.jfree.data.time.Millisecond; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; - - import org.openide.windows.TopComponent; - import org.mc4j.console.dashboard.components.RefreshControlComponent; import org.mc4j.console.swing.LogarithmicTimeJSlider; import java.awt.BorderLayout; import java.awt.Color; --- 23,37 ---- import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.XYPlot; ! import org.jfree.chart.renderer.xy.DefaultXYItemRenderer; import org.jfree.chart.title.TextTitle; import org.jfree.data.time.Millisecond; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.mc4j.console.dashboard.components.RefreshControlComponent; import org.mc4j.console.swing.LogarithmicTimeJSlider; + import org.openide.windows.TopComponent; + import javax.swing.*; + import javax.swing.border.LineBorder; import java.awt.BorderLayout; import java.awt.Color; *************** *** 50,67 **** import java.util.Timer; import java.util.TimerTask; ! ! import javax.swing.BorderFactory; ! import javax.swing.BoxLayout; ! import javax.swing.ButtonGroup; ! import javax.swing.Icon; ! import javax.swing.ImageIcon; ! import javax.swing.JCheckBox; ! import javax.swing.JFrame; ! import javax.swing.JLabel; ! import javax.swing.JPanel; ! import javax.swing.JPopupMenu; ! import javax.swing.JRadioButton; ! import javax.swing.SwingUtilities; ! import javax.swing.border.LineBorder; /** --- 50,54 ---- import java.util.Timer; import java.util.TimerTask; ! import java.util.Set; /** *************** *** 74,88 **** * @version $Revision$($Author$ / $Date$) */ ! public abstract class AbstractGraphPanel extends TopComponent { protected TimeSeriesCollection dataset = new TimeSeriesCollection(); - protected JFreeChart chart; protected Timer dataGeneratorTimer; protected TimerTask dataGeneratorTimerTask; ! protected Map timeSeriesMap = new HashMap(); protected XYPlot xyplot; --- 61,74 ---- * @version $Revision$($Author$ / $Date$) */ ! public abstract class AbstractGraphPanel<T> extends TopComponent { protected TimeSeriesCollection dataset = new TimeSeriesCollection(); protected JFreeChart chart; protected Timer dataGeneratorTimer; protected TimerTask dataGeneratorTimerTask; ! protected Map<T,TimeSeries> timeSeriesMap = new HashMap<T, TimeSeries>(); protected XYPlot xyplot; *************** *** 108,111 **** --- 94,98 ---- protected int failures = 0; protected static final int MAX_FAILURES = 10; + protected ChartPanel chartPanel; *************** *** 119,123 **** } - public void setChartTitle(final String name) { SwingUtilities.invokeLater(new Runnable() { --- 106,109 ---- *************** *** 140,145 **** NumberAxis range = new NumberAxis(""); ! this.xyplot = new XYPlot(dataset, domain, range, new DefaultXYItemRenderer()); ! domain.setAutoRange(true); domain.setLowerMargin(0.0); --- 126,137 ---- NumberAxis range = new NumberAxis(""); ! this.xyplot = new XYPlot(); ! this.xyplot.setDataset(dataset); ! this.xyplot.setDomainAxis(domain); ! this.xyplot.setRangeAxis(range); ! DefaultXYItemRenderer renderer = new DefaultXYItemRenderer(); ! renderer.setShapesVisible(false); ! this.xyplot.setRenderer(renderer); ! domain.setAutoRange(true); domain.setLowerMargin(0.0); *************** *** 160,164 **** new Font("SansSerif",Font.BOLD, 12))); ! ChartPanel chartPanel = new ChartPanel(chart,false,true,true,false,false); //chartPanel.setPopupMenu(null); chartPanel.setOpaque(true); --- 152,156 ---- new Font("SansSerif",Font.BOLD, 12))); ! chartPanel = new ChartPanel(chart,false,true,true,false,false); //chartPanel.setPopupMenu(null); chartPanel.setOpaque(true); *************** *** 174,179 **** buildGraphControls(); ! this.controlsButton = new ControlsPopupButton(); JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); northPanel.add(this.controlsButton); northPanel.setOpaque(false); --- 166,174 ---- buildGraphControls(); ! ControlsPopupButton dataButton = new ControlsPopupButton(new GraphSeriesPanel(dataset),"images/GraphElements.gif"); ! this.controlsButton = new ControlsPopupButton(this.controlsPanel,"images/GraphSettings2.gif"); ! JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + northPanel.add(dataButton); northPanel.add(this.controlsButton); northPanel.setOpaque(false); *************** *** 189,196 **** * A custom JCheckBox that will popup the controls toolbox for the chart */ ! public class ControlsPopupButton extends JCheckBox { private JPopupMenu popup; ! private Icon descendingIcon = createImageIcon("images/GraphSettings.gif"); /** Returns an ImageIcon, or null if the path was invalid. */ --- 184,202 ---- * A custom JCheckBox that will popup the controls toolbox for the chart */ ! public static class ControlsPopupButton extends JCheckBox { private JPopupMenu popup; ! private Icon icon;// = createImageIcon("images/GraphSettings2.gif"); ! ! private JComponent payload; ! ! public ControlsPopupButton(JComponent payload, String img) { ! this.payload = payload; ! this.icon = createImageIcon(img); ! ! setIcon(icon); ! setOpaque(false); ! init(); ! } /** Returns an ImageIcon, or null if the path was invalid. */ *************** *** 205,220 **** } - public ControlsPopupButton() { - setIcon(descendingIcon); - setOpaque(false); - init(); - } - public void showPopup() { ! if (popup == null) { ! popup = new JPopupMenu(); ! popup.add(controlsPanel); ! } ! popup.show(controlsButton, 0, controlsButton.getHeight()); } --- 211,226 ---- } public void showPopup() { ! GlassWindow.show(this.payload, this); ! //JXGlassBox gb = new JXGlassBox(0.8f); ! // gb.add(this.payload); ! // gb.setDismissOnClick(true); ! // gb.setVisible(true); ! // gb.showOnGlassPane((Container) this.getRootPane().getGlassPane(),this.getX() - this.payload.getWidth(), this.getY() + this.getHeight()); ! // if (popup == null) { ! // popup = new JPopupMenu(); ! // popup.add(this.payload); ! // } ! // popup.show(this, 0, this.getHeight()); } *************** *** 489,504 **** } ! protected void createTimeSeries(String name, Object key) { ! TimeSeries ts = ! new TimeSeries( ! name, ! Millisecond.class); ! ts.setHistoryCount(1728000); // 48 hours at 100 seconds this.timeSeriesMap.put(key, ts); dataset.addSeries(ts); } ! protected TimeSeries getTimeSeries(Object key) { ! return (TimeSeries) this.timeSeriesMap.get(key); } --- 495,512 ---- } ! protected void createTimeSeries(String name, T key) { ! TimeSeries ts = new TimeSeries(name, Millisecond.class); ! ts.setMaximumItemAge(1000 * 60 * 60 * 48); // 48 hours this.timeSeriesMap.put(key, ts); + //ts.setKey((Comparable) key); Duh, don't do this dataset.addSeries(ts); } ! protected TimeSeries getTimeSeries(T key) { ! return this.timeSeriesMap.get(key); ! } ! ! public Set<T> getTimeSeriesKeys() { ! return this.timeSeriesMap.keySet(); } --- NEW FILE: GlassWindow.java --- /* * Copyright 2002-2005 Greg Hinkle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.mc4j.console.swing.graph; import org.jdesktop.swingx.JXGlassBox; import javax.swing.*; import javax.swing.event.MouseInputAdapter; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; /** * @author Greg Hinkle (gh...@us...), Feb 24, 2005 * @version $Revision: 1.2 $($Author: ghinkl $ / $Date: 2006/04/12 19:14:06 $) */ public class GlassWindow extends JXGlassBox { protected JPanel header; protected JPanel footer; protected JLabel title; protected JComponent contents; protected static GlassWindow INSTANCE = new GlassWindow(); protected static JComponent currentParent; private GlassWindow() { super(0.85f); initUI(); } private void initUI() { setBorder(BorderFactory.createRaisedBevelBorder()); header = new JPanel(new BorderLayout()); header.add(new JLabel("Graph Series"),BorderLayout.WEST); JButton close = new JButton("x"); close.setAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { INSTANCE.setVisible(false); } }); MoveListener listener = new MoveListener(); header.addMouseListener(listener); header.addMouseMotionListener(listener); header.add(close, BorderLayout.EAST); header.setBackground(Color.gray); ResizeListener resizeListener = new ResizeListener(); footer = new JPanel(new BorderLayout()); ResizeButton b = new ResizeButton(); footer.add(b); b.addMouseListener(resizeListener); b.addMouseMotionListener(resizeListener); } public static class ResizeButton extends JPanel { public ResizeButton() { super(); setSize(8,8); } public void paint(Graphics g) { super.paint(g); // After painting our components, we're gonna draw fake resize lines g.setColor(Color.white); g.fillRect(getWidth() - 8, getHeight() - 8, 8,8); g.setColor(Color.gray); g.drawLine(getWidth() - 7, getHeight() - 1, getWidth() - 1, getHeight() - 7); g.drawLine(getWidth() - 5, getHeight() - 1, getWidth() - 1, getHeight() - 5); g.drawLine(getWidth() - 3, getHeight() - 1, getWidth() - 1, getHeight() - 3); } } public class MoveListener extends MouseInputAdapter { private Point last; public void mouseClicked(MouseEvent e) { last = e.getPoint(); } public void mouseReleased(MouseEvent e) { last = null; } public void mouseDragged(MouseEvent e) { if (last == null) { last = e.getPoint(); } else { Point p = e.getPoint(); Point newLocation = getLocation(); newLocation.translate(p.x - last.x, p.y - last.y); setLocation(newLocation); } } } public class ResizeListener extends MouseInputAdapter { private Point last; public void mouseClicked(MouseEvent e) { last = e.getPoint(); } public void mouseReleased(MouseEvent e) { last = null; } public void mouseDragged(MouseEvent e) { if (last == null) { last = e.getPoint(); } else { Point p = e.getPoint(); setSize(getWidth() + p.x - last.x, getHeight() + p.y - last.y); last = e.getPoint(); } } } public void setContents(JComponent contents) { removeAll(); setLayout(new BorderLayout()); add(header, BorderLayout.NORTH); add(contents, BorderLayout.CENTER); add(footer, BorderLayout.SOUTH); } public static void show(JComponent contents, JComponent parent) { Container glass = (Container) parent.getRootPane().getGlassPane(); INSTANCE.setContents(contents); INSTANCE.setVisible(true); INSTANCE.showOnGlassPane(glass,parent,0,0,1); } } |