📄 netbeamschart.java
字号:
/** Copyright (c) 2001 Sun Microsystems, Inc. All rights* reserved.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:** 1. Redistributions of source code must retain the above copyright* notice, this list of conditions and the following disclaimer.** 2. Redistributions in binary form must reproduce the above copyright* notice, this list of conditions and the following disclaimer in* the documentation and/or other materials provided with the* distribution.** 3. The end-user documentation included with the redistribution,* if any, must include the following acknowledgment:* "This product includes software developed by the* Sun Microsystems, Inc. for Project JXTA."* Alternately, this acknowledgment may appear in the software itself,* if and wherever such third-party acknowledgments normally appear.** 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"* must not be used to endorse or promote products derived from this* software without prior written permission. For written* permission, please contact Project JXTA at http://www.jxta.org.** 5. Products derived from this software may not be called "JXTA",* nor may "JXTA" appear in their name, without prior written* permission of Sun.** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF* SUCH DAMAGE.* ====================================================================** This software consists of voluntary contributions made by many* individuals on behalf of Project JXTA. For more* information on Project JXTA, please see* <http://www.jxta.org/>.** This license is based on the BSD license adopted by the Apache Foundation.** $Id: NetBeamsChart.java,v 1.2 2006/07/13 05:26:37 nano Exp $*/package net.jxta.myjxta.misc.beam;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Rectangle;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import java.awt.geom.Line2D;import java.awt.image.BufferedImage;import java.util.Date;import java.util.Properties;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EtchedBorder;import javax.swing.border.TitledBorder;/** * Tracks Memory allocated & used, displayed in graph form. */public class NetBeamsChart extends JPanel { public Surface surf; String desc = null; String gid = null; String sid = null; String units = null; String type = null; String url = null; String vxpath = null; float gpsx = 0.0f; float gpsy = 0.0f; float scalefactor = 1.0f; public NetBeamsChart(Properties p) { this.desc = p.getProperty("desc"); this.units = p.getProperty("units"); this.gid = p.getProperty("gridid"); this.sid = p.getProperty("sid"); this.type = p.getProperty("type"); this.url = p.getProperty("url"); this.vxpath = p.getProperty("vxpath"); this.gpsx = Float.parseFloat(p.getProperty("gpsx")); this.gpsy = Float.parseFloat(p.getProperty("gpsy")); this.scalefactor = Float.parseFloat(p.getProperty("scalefactor")); setLayout(new BorderLayout()); setBorder(new TitledBorder(new EtchedBorder(), "Sensor: " + sid + " - " + desc)); add(surf = new Surface()); } public String getSensorID() { return sid; } public String getValueXPath() { return vxpath; } public String getSensorURL() { return url; } public String getDescription() { return desc; } public String getSensorType() { return type; } public String getSensorUnits() { return units; } public float getSensorGPSXCoordinate() { return gpsx; } public float getSensorGPSYCoordinate() { return gpsy; } public class Surface extends JPanel implements Runnable { public Thread thread; public long sleepAmount = 1000; public long lastDraw = 0L; public boolean fullDrawNeeded = false; private int w, h; private BufferedImage bimg; private Graphics2D big; private Font font = new Font("Times New Roman", Font.PLAIN, 11); private FontMetrics fm = null; private Runtime r = Runtime.getRuntime(); private int columnInc; private float pts[]; private int ptNum; private int ascent, descent; private Rectangle graphOutlineRect = new Rectangle(); private Line2D graphLine = new Line2D.Float(); private Color graphColor = new Color(46, 139, 87); private float currVal = 0.0f; private long lastwritetime = 0L; private long writeInterval = 5000L; // set some start values here. If you want the graph // graph will adjust over time, but only when boundaries // of min and max have been exceeded private float minval = 0.0f; private float maxval = 10.0f; // pick number of rows as 5 or 10 to help with decimals public int NROWS = 6; public int NCOLS = 12; public Surface() { setBackground(Color.black); setPreferredSize(new Dimension(135, 80)); } public Dimension getMinimumSize() { return getPreferredSize(); } public Dimension getMaximumSize() { return getPreferredSize(); } public Dimension getPreferredSize() { return new Dimension(135, 80); } public void setCurrentIntValue(float val) { currVal = val; } public float getCurrentValue() { return currVal; } public void paint(Graphics g) { if (big == null) { return; } long currDraw = System.currentTimeMillis(); if ((currDraw - lastDraw) > sleepAmount) { fullDrawNeeded = true; //System.out.println("fullDrawNeeded = true"); lastDraw = currDraw; } // Calculate dimensions float ssH = ascent + descent; float remainingHeight = (h - (ssH * 2) - 0.5f); int graphX = 35; int graphY = (int) ssH; int graphW = w - graphX - 5; int graphH = (int) remainingHeight; // initialize the data buffer if necessary. Make the number of // points equal to the pixel width of the graph if (pts == null) { pts = new float[graphW]; ptNum = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -