Example usage for org.jfree.chart.plot ValueMarker setValue

List of usage examples for org.jfree.chart.plot ValueMarker setValue

Introduction

In this page you can find the example usage for org.jfree.chart.plot ValueMarker setValue.

Prototype

public void setValue(double value) 

Source Link

Document

Sets the value for the marker and sends a MarkerChangeEvent to all registered listeners.

Usage

From source file:pt.lsts.neptus.util.bathymetry.TidCachedData.java

public static void test(String[] args) throws Exception {
    TidReader.main(args);/*from  w  w  w.j a v a2 s .  c  o m*/

    JFreeChart timeSeriesChart = null;
    TimeSeriesCollection tsc = new TimeSeriesCollection();
    ValueMarker marker = new ValueMarker(System.currentTimeMillis());
    ValueMarker levelMarker = new ValueMarker(0);

    String tmpFolder = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator", "/");
    File tidFx = new File(tmpFolder + "tmp.tid");

    TidCachedData tide = new TidCachedData(tidFx);

    TimeSeries ts = new TimeSeries(I18n.text("Tide level"));
    tsc.addSeries(ts);

    Date sDate = new GregorianCalendar(1993, 9, 28).getTime();
    for (double i = -12; i < 12; i += 0.25) {
        Date d = new Date((long) (sDate.getTime() + (i * 6.45 * 1E3 * 60 * 60)));
        ts.addOrUpdate(new Millisecond(d), tide.getTidePrediction(d, false));
    }

    JPanel panel = new JPanel(new BorderLayout());
    timeSeriesChart = ChartFactory.createTimeSeriesChart(null, null, null, tsc, true, true, true);
    panel.add(new ChartPanel(timeSeriesChart), BorderLayout.CENTER);

    timeSeriesChart.getXYPlot().addDomainMarker(marker);
    levelMarker.setValue(TidePredictionFactory.getTideLevel(new Date()));
    timeSeriesChart.getXYPlot().addRangeMarker(levelMarker);

    GuiUtils.testFrame(panel);

    System.out.println("\n________________________________________");
    long start = System.currentTimeMillis();
    TidCachedData tcd = new TidCachedData(new File(ConfigFetch.getConfFolder() + "mra/Leixoes.tid"));
    System.out.println("Loading of " + tcd.getName() + " took "
            + MathMiscUtils.parseToEngineeringNotation((System.currentTimeMillis() - start) / 1E3, 2) + "s");
}

From source file:windows.sensorWindow.java

/**
 * update maxima marker// w  ww . ja  v a  2  s  . c  o  m
 * 
 * @param UID
 *            uid of the sensor
 * @param value
 *            new maximum vallue
 * @param index
 *            sensor index, 0 = primary sensor, 1 = secondary
 */
public static void updateMaxima(String UID, double value, int index) {
    if (index == 0) {
        if (markerMaxima.containsKey(UID)) {
            ValueMarker vm = markerMaxima.get(UID);
            vm.setValue(value);
            markerMaxima.put(UID, vm);
        }
    }
    if (index == 1) {
        if (marker2Maxima.containsKey(UID)) {
            ValueMarker vm = marker2Maxima.get(UID);
            vm.setValue(value);
            marker2Maxima.put(UID, vm);
        }
    }
}

From source file:windows.sensorWindow.java

/**
 * update minima marker//ww  w .j  a v  a  2  s  .c  om
 * 
 * @param UID
 *            uid of the sensor
 * @param value
 *            new maximum vallue
 * @param index
 *            sensor index, 0 = primary sensor, 1 = secondary
 */
public static void updateMinima(String UID, double value, int index) {
    if (index == 0) {
        if (markerMinima.containsKey(UID)) {
            ValueMarker vm = markerMinima.get(UID);
            vm.setValue(value);
            markerMinima.put(UID, vm);
        }
    }
    if (index == 1) {
        if (marker2Minima.containsKey(UID)) {
            ValueMarker vm = marker2Minima.get(UID);
            vm.setValue(value);
            marker2Minima.put(UID, vm);
        }
    }
}

From source file:windows.sensorWindow.java

/**
 * updates the threshold marker on the graph of the given sensor
 * // w ww .j  a va2 s .  c  o m
 * @param UID
 *            UID of the sensor
 * @param treshold
 *            new threshold
 */
public static void updateTresholdMax2(String UID, double treshold) {
    if (markerMapMax2Critical.containsKey(UID)) {
        ValueMarker vm = markerMapMax2Critical.get(UID);
        vm.setValue(treshold);
        markerMapMax2Critical.put(UID, vm);

        ValueMarker vm2 = markerMapMax2Warning.get(UID);
        double diff = markerMapMin2Warning.get(UID).getValue() - markerMapMin2Critical.get(UID).getValue();
        vm2.setValue(treshold - diff);
        markerMapMax2Warning.put(UID, vm2);
    }
}

From source file:windows.sensorWindow.java

/**
 * updates the threshold marker on the graph of the given sensor
 * /* w  w  w.j av  a2  s  .co m*/
 * @param UID
 *            UID of the sensor
 * @param treshold
 *            new threshold
 */

public static void updateTresholdMax1(String UID, double treshold) {
    if (markerMapMax1Critical.containsKey(UID)) {
        ValueMarker vm = markerMapMax1Critical.get(UID);
        vm.setValue(treshold);
        markerMapMax1Critical.put(UID, vm);

        ValueMarker vm2 = markerMapMax1Warning.get(UID);
        double diff = markerMapMin1Warning.get(UID).getValue() - markerMapMin1Critical.get(UID).getValue();
        vm2.setValue(treshold - diff);
        markerMapMax1Warning.put(UID, vm2);
    }
}

From source file:windows.sensorWindow.java

/**
 * updates the threshold marker on the graph of the given sensor
 * /* w  w w  .j  a v a2  s  . c  o  m*/
 * @param UID
 *            UID of the sensor
 * @param treshold
 *            new threshold
 */
public static void updateTresholdMin2(String UID, double treshold) {
    if (markerMapMin2Critical.containsKey(UID)) {
        ValueMarker vm = markerMapMin2Critical.get(UID);
        vm.setValue(treshold);
        markerMapMin2Critical.put(UID, vm);

        ValueMarker vm2 = markerMapMin2Warning.get(UID);
        vm2.setValue(treshold + treshold);
        markerMapMin2Warning.put(UID, vm2);

        ValueMarker vm3 = markerMapMax2Warning.get(UID);
        double diff = markerMapMin2Warning.get(UID).getValue() - markerMapMin2Critical.get(UID).getValue();
        vm3.setValue(markerMapMax2Critical.get(UID).getValue() - diff);
        markerMapMax2Warning.put(UID, vm3);
    }
}

From source file:ch.algotrader.client.chart.ChartTab.java

@SuppressWarnings("unchecked")
public void updateData(ChartDataVO chartData) {

    resetAxis();//from  w w w.  j a  v a2  s  .co m

    // add/update indicators
    for (IndicatorVO indicator : chartData.getIndicators()) {

        RegularTimePeriod timePeriod = getRegularTimePeriod(indicator.getDateTime());
        TimeSeries series = this.indicators.get(indicator.getName());

        if (series != null) {
            series.addOrUpdate(timePeriod, indicator.getValue());
        }
    }

    // add/update bars
    for (BarVO bar : chartData.getBars()) {

        OHLCSeries series = this.bars.get(bar.getSecurityId());

        if (series != null) {

            // remove a value if it already exists
            RegularTimePeriod timePeriod = getRegularTimePeriod(bar.getDateTime());
            if (series.indexOf(timePeriod) >= 0) {
                series.remove(timePeriod);
            }
            series.add(timePeriod, bar.getOpen().doubleValue(), bar.getHigh().doubleValue(),
                    bar.getLow().doubleValue(), bar.getClose().doubleValue());
        }
    }

    // make all invisible since they might not currently have a value
    for (Marker marker : this.markers.values()) {
        marker.setAlpha(0);
    }

    // update markers
    for (MarkerVO markerVO : chartData.getMarkers()) {

        Marker marker = this.markers.get(markerVO.getName());
        Boolean selected = this.markersSelectionStatus.get(markerVO.getName());
        String name = marker.getLabel().split(":")[0];
        if (marker instanceof ValueMarker && markerVO instanceof ValueMarkerVO) {

            ValueMarker valueMarker = (ValueMarker) marker;
            ValueMarkerVO valueMarkerVO = (ValueMarkerVO) markerVO;
            valueMarker.setValue(valueMarkerVO.getValue());
            marker.setLabel(name + ": " + valueMarkerVO.getValue());
            marker.setAlpha(selected ? 1.0f : 0.0f);

        } else if (marker instanceof IntervalMarker && markerVO instanceof IntervalMarkerVO) {

            IntervalMarker intervalMarker = (IntervalMarker) marker;
            IntervalMarkerVO intervalMarkerVO = (IntervalMarkerVO) markerVO;
            intervalMarker.setStartValue(intervalMarkerVO.getStartValue());
            intervalMarker.setEndValue(intervalMarkerVO.getEndValue());
            marker.setLabel(
                    name + ": " + intervalMarkerVO.getStartValue() + " - " + intervalMarkerVO.getEndValue());
            marker.setAlpha(selected ? 0.5f : 0.0f);

        } else {
            throw new RuntimeException(marker.getClass() + " does not match " + markerVO.getClass());
        }
    }

    // update annotations
    for (AnnotationVO annotationVO : chartData.getAnnotations()) {

        AbstractXYAnnotation annotation;
        if (annotationVO instanceof PointerAnnotationVO) {

            PointerAnnotationVO pointerAnnotationVO = (PointerAnnotationVO) annotationVO;
            XYPointerAnnotation pointerAnnotation = new XYPointerAnnotation(pointerAnnotationVO.getText(),
                    pointerAnnotationVO.getDateTime().getTime(), pointerAnnotationVO.getValue(),
                    3.926990816987241D);
            pointerAnnotation.setTipRadius(0);
            pointerAnnotation.setBaseRadius(20);
            pointerAnnotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
            pointerAnnotation.setFont(new Font("SansSerif", 0, 9));
            pointerAnnotation.setToolTipText("<html>" + formatter.format(pointerAnnotationVO.getDateTime())
                    + "<br>" + pointerAnnotationVO.getValue() + "</html>");

            annotation = pointerAnnotation;

        } else if (annotationVO instanceof BoxAnnotationVO) {

            BoxAnnotationVO boxAnnotationVO = (BoxAnnotationVO) annotationVO;
            XYBoxAnnotation boxAnnotation = new XYBoxAnnotation(boxAnnotationVO.getStartDateTime().getTime(),
                    boxAnnotationVO.getStartValue(), boxAnnotationVO.getEndDateTime().getTime(),
                    boxAnnotationVO.getEndValue(), null, null, new java.awt.Color(0, 0, 0, 60));
            boxAnnotation.setToolTipText("<html>" + formatter.format(boxAnnotationVO.getStartDateTime()) + " - "
                    + formatter.format(boxAnnotationVO.getEndDateTime()) + "<br>"
                    + boxAnnotationVO.getStartValue() + " - " + boxAnnotationVO.getEndValue() + "</html>");

            annotation = boxAnnotation;
        } else {
            throw new RuntimeException("unkown annotation type" + annotationVO.getClass());
        }

        if (!getPlot().getAnnotations().contains(annotation)) {
            getPlot().addAnnotation(annotation);
        }
    }

    // update description
    for (Title title : (List<Title>) this.getChart().getSubtitles()) {
        if (title instanceof TextTitle) {
            TextTitle textTitle = ((TextTitle) title);
            if (chartData.getDescription() != null && !("".equals(chartData.getDescription()))) {
                textTitle.setText(chartData.getDescription());
                textTitle.setVisible(true);
            } else {
                textTitle.setVisible(false);
            }
        }
    }

    initAxis();
}

From source file:windows.sensorWindow.java

/**
 * updates the threshold marker on the graph of the given sensor
 * /*w w w  .  j  av a  2  s  . com*/
 * @param UID
 *            UID of the sensor
 * @param treshold
 *            new threshold
 */
public static void updateTresholdMin1(String UID, double treshold) {
    if (markerMapMin1Critical.containsKey(UID)) {
        ValueMarker vm = markerMapMin1Critical.get(UID);
        vm.setValue(treshold);
        markerMapMin1Critical.put(UID, vm);

        ValueMarker vm2 = markerMapMin1Warning.get(UID);
        // vm2.setValue(treshold+treshold*warningPercentage/100);
        vm2.setValue(treshold + treshold);
        markerMapMin1Warning.put(UID, vm2);

        ValueMarker vm3 = markerMapMax1Warning.get(UID);
        double diff = markerMapMin1Warning.get(UID).getValue() - markerMapMin1Critical.get(UID).getValue();
        vm3.setValue(markerMapMax1Critical.get(UID).getValue() - diff);
        markerMapMax1Warning.put(UID, vm3);
    }
}

From source file:windows.sensorWindow.java

/**
 * update average control values/*from   w w w  . j  ava  2  s  .co  m*/
 * 
 * @param UID
 *            uid of the brick
 * @param value
 *            new value
 * @param index
 *            1=sensor1, 2=sensor2
 * @param high
 *            true = upper line, false = lower line
 */
public static void updateAvrgCtrl(String UID, double value, int index, boolean high) {
    switch (index) {
    case 1:
        if (high == true) {
            ValueMarker vm = avrg1High.get(UID);
            vm.setValue(value);
            avrg1High.put(UID, vm);
        }
        if (high == false) {
            ValueMarker vm = avrg1Low.get(UID);
            vm.setValue(value);
            avrg1Low.put(UID, vm);
        }
        break;

    case 2:
        if (high == true) {
            ValueMarker vm = avrg2High.get(UID);
            vm.setValue(value);
            avrg2High.put(UID, vm);
        }
        if (high == false) {
            ValueMarker vm = avrg2Low.get(UID);
            vm.setValue(value);
            avrg2Low.put(UID, vm);
        }
        break;
    }
}

From source file:windows.sensorWindow.java

/**
 * update maxima marker//from ww  w.ja  v  a2  s .  c  om
 * 
 * @param UID
 *            uid of the sensor
 * @param value
 *            new maximum vallue
 * @param index
 *            sensor index, 0 = primary sensor, 1 = secondary
 */
public static void updateAverage(String UID, double value, int index) {
    if (index == 0) {
        if (markerAverage.containsKey(UID)) {
            ValueMarker vm = markerAverage.get(UID);
            vm.setValue(value);
            markerAverage.put(UID, vm);

            // verify whether we are between admissible average control
            // lines
            if ((value > Brick.getBrick(connectionData.BrickList, UID).getAvg1high())
                    || (value < Brick.getBrick(connectionData.BrickList, UID).getAvg1low())) {
                if (avrgCtrl1Enabled.get(UID) == true) {
                    if (plot1StateMap.get(UID) == 0)
                        plotMap.get(UID).setBackgroundPaint(Color.GRAY);
                    plot1StateMap.put(UID, 1);
                }
            } else if (plot1StateMap.get(UID) == 1) {
                plotMap.get(UID).setBackgroundPaint(Color.white);
                plot1StateMap.put(UID, 0);
            }
        }
    }
    if (index == 1) {
        if (marker2Average.containsKey(UID)) {
            ValueMarker vm = marker2Average.get(UID);
            vm.setValue(value);
            marker2Average.put(UID, vm);

            // verify whether we are between admissible average control
            // lines
            if ((value > Brick.getBrick(connectionData.BrickList, UID).getAvg2high())
                    || (value < Brick.getBrick(connectionData.BrickList, UID).getAvg2low())) {
                if (avrgCtrl2Enabled.get(UID) == true) {
                    if (plot1StateMap.get(UID) == 0)
                        plotMap.get(UID).setBackgroundPaint(Color.GRAY);
                    plot1StateMap.put(UID, 1);
                }
            } else if (plot1StateMap.get(UID) == 1) {
                plotMap.get(UID).setBackgroundPaint(Color.white);
                plot1StateMap.put(UID, 0);
            }
        }
    }
}