Example usage for org.jfree.chart.plot XYPlot getDomainMarkers

List of usage examples for org.jfree.chart.plot XYPlot getDomainMarkers

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getDomainMarkers.

Prototype

public Collection getDomainMarkers(Layer layer) 

Source Link

Document

Returns the list of domain markers (read only) for the specified layer.

Usage

From source file:com.ivli.roim.controls.ChartControl.java

Collection getDomainMarkersForSeries(XYSeries aS) {
    final XYPlot plot = getChart().getXYPlot();
    Collection mrak = plot.getDomainMarkers(Layer.FOREGROUND);
    return (new ArrayList<DomainMarker>(mrak)).stream().filter((DomainMarker m) -> {
        return (m.getSeries() == aS);
    }).collect(Collectors.toList());
}

From source file:com.ivli.roim.controls.ChartControl.java

private ValueMarker findMarker(MouseEvent e) {
    final XYPlot plot = getChart().getXYPlot();

    Collection mark = plot.getDomainMarkers(Layer.FOREGROUND);

    if (null == mark || mark.isEmpty())
        return null;

    final double domainX = plot.getDomainAxis().java2DToValue(e.getX(), getScreenDataArea(),
            plot.getDomainAxisEdge());/*from  w w w  . j  a va 2 s. c  om*/

    final double Epsilon = plot.getDataRange(plot.getDomainAxis()).getLength() * .01d;

    for (Object o : mark) {
        if (o instanceof DomainMarker) {
            //DomainMarker m = (DomainMarker)o;
            double val = ((DomainMarker) o).getValue();
            if (val >= domainX - Epsilon && val <= domainX + Epsilon) {
                //getContentPane().setCursor(new Cursor(Cursor.HAND_CURSOR)); 
                return (ValueMarker) o;
            }
        }
    }
    return null;
}

From source file:ec.ui.view.ARPView.java

@Override
protected void onColorSchemeChange() {
    XYPlot plot = getPlot();
    plot.setBackgroundPaint(themeSupport.getPlotColor());
    plot.setDomainGridlinePaint(themeSupport.getGridColor());
    plot.setRangeGridlinePaint(themeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor());

    plot.getRenderer().setBasePaint(themeSupport.getLineColor(KnownColor.BROWN));

    List<Marker> markers = new ArrayList<>();
    Collection rm = plot.getRangeMarkers(Layer.FOREGROUND);
    if (rm != null) {
        markers.addAll(rm);// w  w  w . jav  a  2s  .  c om
    }
    Collection dm = plot.getDomainMarkers(Layer.FOREGROUND);
    if (dm != null) {
        markers.addAll(dm);
    }
    for (Marker o : markers) {
        if (o instanceof ExtValueMarker) {
            ((ExtValueMarker) o).applyColorScheme(themeSupport);
        }
    }
}

From source file:ec.ui.view.AutoCorrelationsView.java

@Override
protected void onColorSchemeChange() {
    XYPlot plot = chartPanel.getChart().getXYPlot();
    plot.setBackgroundPaint(themeSupport.getPlotColor());
    plot.setDomainGridlinePaint(themeSupport.getGridColor());
    plot.setRangeGridlinePaint(themeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor());

    XYItemRenderer renderer = plot.getRenderer();
    KnownColor color = ACKind.Normal == kind ? NORMAL_COLOR : PARTIAL_COLOR;
    renderer.setBasePaint(themeSupport.getAreaColor(color));
    renderer.setBaseOutlinePaint(themeSupport.getLineColor(color));

    Collection<Marker> markers = (Collection<Marker>) plot.getDomainMarkers(Layer.FOREGROUND);
    if (!Jdk6.Collections.isNullOrEmpty(markers)) {
        Color markerColor = themeSupport.getLineColor(MARKER_COLOR);
        for (Marker o : markers) {
            o.setPaint(markerColor);//www. j a  va 2s .  c om
        }
    }
}

From source file:ec.ui.view.MarginView.java

@Override
protected void onColorSchemeChange() {
    XYPlot plot = chartPanel.getChart().getXYPlot();
    plot.setBackgroundPaint(themeSupport.getPlotColor());
    plot.setDomainGridlinePaint(themeSupport.getGridColor());
    plot.setRangeGridlinePaint(themeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor());

    XYLineAndShapeRenderer main = (XYLineAndShapeRenderer) plot.getRenderer(MAIN_INDEX);
    main.setBasePaint(themeSupport.getLineColor(MAIN_COLOR));

    XYDifferenceRenderer difference = ((XYDifferenceRenderer) plot.getRenderer(DIFFERENCE_INDEX));
    Color diffArea = SwingColorSchemeSupport.withAlpha(themeSupport.getAreaColor(DIFFERENCE_COLOR), 150);
    difference.setPositivePaint(diffArea);
    difference.setNegativePaint(diffArea);
    difference.setBasePaint(themeSupport.getLineColor(DIFFERENCE_COLOR));

    Collection<Marker> markers = (Collection<Marker>) plot.getDomainMarkers(Layer.FOREGROUND);
    if (!Jdk6.Collections.isNullOrEmpty(markers)) {
        Color markerColor = themeSupport.getLineColor(DATE_MARKER_COLOR);
        for (Marker o : markers) {
            o.setPaint(markerColor);/*from  www .  j a  v a 2  s  .c o m*/
        }
    }

    Collection<Marker> intervalMarkers = (Collection<Marker>) plot.getDomainMarkers(Layer.BACKGROUND);
    if (!Jdk6.Collections.isNullOrEmpty(intervalMarkers)) {
        Color markerColor = themeSupport.getLineColor(KnownColor.ORANGE);
        for (Marker o : intervalMarkers) {
            o.setPaint(markerColor);
        }
    }
}

From source file:gda.gui.mca.McaGUI.java

@SuppressWarnings("unchecked")
protected void removeRegionMarkers(int region, double d, double e) {
    XYPlot xy = simplePlot.getChart().getXYPlot();
    int found = 0;
    Collection<ValueMarker> c = xy.getDomainMarkers(Layer.FOREGROUND);
    if (c != null) {
        Iterator<ValueMarker> i = c.iterator();
        xy.clearDomainMarkers();//from  w ww.  ja  v  a2 s  . c o m
        while (i.hasNext()) {
            ValueMarker m = i.next();
            if (found < 2 && (m.getValue() == d || m.getValue() == e)) {
                found++;
            }

            else
                xy.addDomainMarker(m, Layer.FOREGROUND);
        }
        if (regionMap.containsKey(region))
            regionMap.remove(region);
    }
}

From source file:com.ivli.roim.controls.ChartControl.java

@Override
public void actionPerformed(ActionEvent e) {
    super.actionPerformed(e);
    final XYPlot plot = getChart().getXYPlot();

    switch (MENUS.translate(e.getActionCommand())) {
    case ADD://  www .  j  a  v a2 s . c  om
        if (null != iSeries && iSeries instanceof XYSeries) {
            addMarker(new DomainMarker(iDataItem.getXValue(), iSeries));
        }
        break;
    case EXPORT_CSV:
        if (null != iSeries && iSeries instanceof XYSeries) {
            FileOpenDialog dlg = new FileOpenDialog(
                    java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle").getString("CHOICE_FILE_TO_OPEN"),
                    "csv", //NOI18N 
                    "CSV file", //NOI18N 
                    false);

            if (dlg.doModal()) {
                try (Writer pwr = new PrintWriter(dlg.getFileName())) { //NOI18N                              
                    for (int i = 0; i < iSeries.getItemCount(); ++i) {
                        XYDataItem xy = iSeries.getDataItem(i);
                        pwr.append(String.format("%f\t%f\n", xy.getXValue(), xy.getYValue())); //NOI18N                        
                    }
                    pwr.flush();
                    pwr.close();
                } catch (IOException ex) {
                    LOG.throwing(ex);
                }
            }
        }
        break;
    case MOVE_TO_MAX:
        iMarker.setValue(XYSeriesUtilities.getDomainValueOfMaximum(((DomainMarker) iMarker).getSeries()));
        break;//((DomainMarker)iMarker).moveToMaximum(DomainMarker.MOVETO.GLOBAL)); break;                           
    case MOVE_TO_MIN:
        iMarker.setValue(XYSeriesUtilities.getDomainValueOfMinimum(((DomainMarker) iMarker).getSeries()));
        break;
    case MOVE_TO_MEDIAN: {
        iMarker.setValue(XYSeriesUtilities.getDomainValueOfMaximum(((DomainMarker) iMarker).getSeries()));
        double medY = (iSeries.getMaxY() - iSeries.getMinY()) / 2.;
        double val = XYSeriesUtilities.getNearestX(iSeries, medY);

        if (Double.isFinite(val))
            iMarker.setValue(val);
    }
        ;
        break;
    case DELETE:
        removeMarker((DomainMarker) iMarker);
        break;
    case DELETE_ALL:
        plot.getDomainMarkers(Layer.FOREGROUND).clear();
        iInterpolations.stream().forEach((i) -> {
            i.close();
        });
        iInterpolations.clear();
        break;
    case FIT_LEFT:
    case FIT_RIGHT: {
        final FITDIR dir = (MENUS.FIT_LEFT == MENUS.translate(e.getActionCommand()) ? FITDIR.FIT_LEFT
                : FITDIR.FIT_RIGHT);

        List<DomainMarker> list = (new ArrayList<DomainMarker>(plot.getDomainMarkers(Layer.FOREGROUND)))
                .stream().filter((DomainMarker m) -> {
                    return ((DomainMarker) iMarker).getSeries() == m.getSeries();
                }).sorted((DomainMarker aLhs, DomainMarker aRhs) -> {
                    return (int) (aLhs.getValue() - aRhs.getValue());
                }).collect(Collectors.toList());

        LOG.debug("-->Found " + list.size() + " markers");

        switch (list.size()) {
        case 0:
            break;
        case 1:
            iInterpolations.add(new Interpolation((DomainMarker) iMarker, dir));
            break;
        case 2: //fallthrough as default
        default: {
            DomainMarker left = null, right = null;
            int ndx = list.indexOf(iMarker);
            if (dir == FITDIR.FIT_LEFT) {
                if (ndx >= 1) {
                    right = (DomainMarker) iMarker;
                    left = list.get(--ndx);
                    iInterpolations.add(new Interpolation(left, right));
                } else {
                    iInterpolations.add(new Interpolation((DomainMarker) iMarker, dir));
                }

            } else if (dir == FITDIR.FIT_RIGHT) {
                if (ndx < list.size() - 1) {
                    right = list.get(++ndx);
                    left = (DomainMarker) iMarker;
                    iInterpolations.add(new Interpolation(left, right));
                } else {
                    iInterpolations.add(new Interpolation((DomainMarker) iMarker, dir));
                }
            }
        }
            break;
        }
    }
        break;
    default:
        break;
    }

    dropSelection();
}