[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview GraphAttribute.java, NONE, 1.1
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2010-08-31 13:48:14
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv20330/src/net/sourceforge/bprocessor/gui/attrview Modified Files: GenericPanel.java Added Files: GraphAttribute.java Log Message: --- NEW FILE: GraphAttribute.java --- //--------------------------------------------------------------------------------- // $Id: GraphAttribute.java,v 1.1 2010/08/31 13:48:06 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gui.attrview; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import javax.swing.BoxLayout; import javax.swing.JPanel; import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.sense.core.Measurement; import net.sourceforge.bprocessor.model.sense.monitor.DataItem; import net.sourceforge.bprocessor.model.sense.monitor.DataSet; import net.sourceforge.bprocessor.model.sense.monitor.Graph; import net.sourceforge.bprocessor.model.sense.monitor.Graph.Period; /** * A attribute for a preview */ public class GraphAttribute extends GenericAttribute { private Attribute attribute; private class GraphPanel extends JPanel { private Graph graph; public GraphPanel(Graph graph) { this.graph = graph; setBackground(Color.white); } public void paintComponent(Graphics g) { super.paintComponent(g); List<Color> colors = new LinkedList<Color>(); colors.add(Color.blue); colors.add(Color.red); colors.add(Color.green); colors.add(Color.yellow); colors.add(Color.cyan); colors.add(Color.magenta); double width = getSize().width; double height = getSize().height; int maxx = 0; long maxtime = 0; double maxvalue = Double.NEGATIVE_INFINITY; Period period = graph.period; long elapsed = period.to - period.from; System.out.println("elapsed " + elapsed); Iterator<Color> iter = colors.iterator(); for (DataSet set : graph.data) { if (!iter.hasNext()) { iter = colors.iterator(); } g.setColor(iter.next()); for (DataItem item : set.getItems()) { Measurement measurement = item.getMeasureMent(); long initial = measurement.getTime() - period.from; double delta = initial / (double) elapsed; int x = (int) (delta * width); double value = Double.valueOf(measurement.getValue()); if (value > maxvalue) { maxvalue = value; maxtime = measurement.getTime(); maxx = x; } int y = (int) ((value / 100) * height); y = (int) (height - y); if (set.getSensor().getType().equals("temperature")) { g.fillRect(x, y, 4, 4); } else { g.fillOval(x, y, 4, 4); } } } g.setColor(Color.gray); g.drawLine(maxx, 5, maxx, (int) (height - 5)); g.setFont(new Font("Verdana", Font.PLAIN, 10)); DateFormat format = new SimpleDateFormat("dd/MM HH:mm"); Date date = new Date(maxtime); g.drawString(format.format(date), 5, 12); } } /** * Constructor * @param attribute the attribute for the panel */ public GraphAttribute(Attribute attribute) { super(BoxLayout.PAGE_AXIS); this.setPreferredSize(new Dimension(150, 200)); this.setBackground(Color.white); this.attribute = attribute; GraphPanel panel = new GraphPanel((Graph) attribute.getValue()); this.add(panel); } /** {@inheritDoc} */ @Override public Attribute attribute() { return attribute; } /** {@inheritDoc} */ @Override public void cancelEditing() { } /** {@inheritDoc} */ @Override public void startEditing() { } /** {@inheritdoc} */ @Override public void stopEditing() { } } Index: GenericPanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** GenericPanel.java 20 May 2010 10:58:39 -0000 1.57 --- GenericPanel.java 31 Aug 2010 13:48:06 -0000 1.58 *************** *** 35,38 **** --- 35,39 ---- import net.sourceforge.bprocessor.model.Selector; import net.sourceforge.bprocessor.model.Structure; + import net.sourceforge.bprocessor.model.sense.monitor.Graph; /** *************** *** 206,209 **** --- 207,216 ---- } + private void handleGraph(Attribute attribute, JComponent where) { + GenericAttribute generic = new GraphAttribute(attribute); + genAttributes.add(generic); + where.add(new AttributeRow(generic)); + } + private void generateContent(List what, JComponent where) { Iterator iter = what.iterator(); *************** *** 222,225 **** --- 229,234 ---- } else if (a.getValue() instanceof Boolean) { handleBoolean(a, where); + } else if (a.getValue() instanceof Graph) { + handleGraph(a, where); } else if (a.getValue() instanceof Component) { handleComponent(a, where); |