package com.nextwavesoft; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; import javax.swing.JFrame; import com.nextwavesoft.enumeration.PointerBarType; import com.nextwavesoft.enumeration.ScalePlacement; import com.nextwavesoft.enumeration.UnitType; import com.nextwavesoft.gauge.*; import com.nextwavesoft.shared.Unit; import javax.swing.Timer; public class LinearTest implements ActionListener { static Timer timer; int z = 0; LinearPointerBar bar = new LinearPointerBar(); Random rand = new Random(); public void actionPerformed(ActionEvent e) { if ( z == 0) { bar.setValue(60); z++; } else { bar.setValue(-50); z = 0; } } public static void main(String[] argv) { LinearTest m = new LinearTest(); m.createAndShowGUI(); } /** * Creates the and show gui. */ private void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("IconDisplayer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); LinearGauge linearGauge = new LinearGauge(); linearGauge.setBackground(Color.blue); //Setup scale bar LinearScale linearScale = new LinearScale(); linearScale.setBackground(Color.WHITE); linearScale.setBarExtent(new Unit(80,UnitType.Percentage)); linearGauge.getLinearScaleCollection().add(linearScale); //gaugeLabel /*GaugeLabel gLabel = new GaugeLabel(); gLabel.setText("Nextwave Gauge for Java"); gLabel.setTopLeftX(new Unit(50,UnitType.Percentage)); gLabel.setTopLeftY(new Unit(10,UnitType.Percentage)); ts.gaugeLabels().add(gLabel);*/ //Setup Major Tick Mark and LAbel LinearTickMarkMajor major = new LinearTickMarkMajor(); major.setMajorInterval(20); LinearTickLabelMajor label = new LinearTickLabelMajor(); label.setFontSize(new Unit(7,UnitType.Percentage)); label.setScalePlacement(ScalePlacement.Outside); label.setScaleOffset(new Unit(10,UnitType.Percentage)); label.setMajorInterval(20); label.setBackground(Color.WHITE); label.setTextFormat("%sC"); //Setup Pointer Bar bar.setBarType(PointerBarType.CircleBulbRoundedRectangle); //Setup Minor Tick Mark LinearTickMarkMinor minor = new LinearTickMarkMinor(); //Setup Tick Set LinearTickSet tickSet = new LinearTickSet(); tickSet.getLinearPointerCollection().add(bar); tickSet.getLinearTickCollection().add(minor); tickSet.getLinearTickCollection().add(major); tickSet.getLinearTickCollection().add(label); //Add custom label for farenheight for ( int i = 0 ; i <= 10 ; i ++ ) { LinearTickLabelCustom custom = new LinearTickLabelCustom(); custom.setFontSize(new Unit(7,UnitType.Percentage)); custom.setScalePlacement(ScalePlacement.Inside); custom.setScaleOffset(new Unit(10,UnitType.Percentage)); custom.setMajorInterval(20); custom.setBackground(Color.WHITE); custom.setValue(-100+(i*20)); custom.setText(Integer.toString((-100+(i*20))*(9/5)+32) + "F"); tickSet.getLinearTickCollection().add(custom); } tickSet.setMinimum(-100); tickSet.setMaximum(100); //add set to scale bar linearScale.getLinearTickSetCollection().add(tickSet); timer = new Timer(5000, this); // timer.setInitialDelay(pause); timer.start(); frame.getContentPane().add(linearGauge, BorderLayout.CENTER); frame.pack(); frame.setSize(new Dimension(350, 150)); frame.setVisible(true); } }