Example usage for org.jfree.chart.entity XYItemEntity getDataset

List of usage examples for org.jfree.chart.entity XYItemEntity getDataset

Introduction

In this page you can find the example usage for org.jfree.chart.entity XYItemEntity getDataset.

Prototype

public XYDataset getDataset() 

Source Link

Document

Returns the dataset this entity refers to.

Usage

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * A demonstration application showing a candlestick chart.
 * //from  w  ww  .j  av  a2 s  .  c om
 * @param title
 *            the frame title.
 * @param strategyData
 *            StrategyData
 */
public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) {

    this.strategyData = strategyData;
    this.setLayout(new BorderLayout());
    // Used to mark the current price
    stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0);
    valueMarker = new ValueMarker(0.00, Color.black, stroke);

    this.chart = createChart(this.strategyData, title, tradingday);

    BlockContainer container = new BlockContainer(new BorderArrangement());
    container.add(titleLegend1, RectangleEdge.LEFT);
    container.add(titleLegend2, RectangleEdge.RIGHT);
    container.add(new EmptyBlock(2000, 0));
    CompositeTitle legends = new CompositeTitle(container);
    legends.setPosition(RectangleEdge.BOTTOM);
    this.chart.addSubtitle(legends);

    final ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseZoomable(true, true);
    chartPanel.setRefreshBuffer(true);
    chartPanel.setDoubleBuffered(true);
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseMoved(ChartMouseEvent e) {
        }

        public void chartMouseClicked(final ChartMouseEvent e) {
            CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot();
            @SuppressWarnings("unchecked")
            List<XYPlot> subplots = combinedXYplot.getSubplots();
            if (e.getTrigger().getClickCount() == 2) {
                double xItem = 0;
                double yItem = 0;
                if (e.getEntity() instanceof XYItemEntity) {
                    XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity());
                    xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                    yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                } else {
                    PlotEntity plotEntity = ((PlotEntity) e.getEntity());
                    XYPlot plot = (XYPlot) plotEntity.getPlot();
                    xItem = plot.getDomainCrosshairValue();
                    yItem = plot.getRangeCrosshairValue();
                }

                for (XYPlot xyplot : subplots) {

                    double x = xyplot.getDomainCrosshairValue();
                    double y = xyplot.getRangeCrosshairValue();

                    /*
                     * If the cross hair is from a right-hand y axis we need
                     * to convert this to a left-hand y axis.
                     */
                    String rightAxisName = ", Price: ";
                    double rangeLowerLeft = 0;
                    double rangeUpperLeft = 0;
                    double rangeLowerRight = 0;
                    double rangeUpperRight = 0;
                    double yRightLocation = 0;
                    for (int index = 0; index < xyplot.getRangeAxisCount(); index++) {
                        AxisLocation axisLocation = xyplot.getRangeAxisLocation(index);
                        Range range = xyplot.getRangeAxis(index).getRange();

                        if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT)
                                || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) {
                            rangeLowerLeft = range.getLowerBound();
                            rangeUpperLeft = range.getUpperBound();
                            rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": ";
                        }
                        if (y >= range.getLowerBound() && y <= range.getUpperBound()
                                && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT)
                                        || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) {
                            rangeUpperRight = range.getUpperBound();
                            rangeLowerRight = range.getLowerBound();
                        }
                    }
                    if ((rangeUpperRight - rangeLowerRight) > 0) {
                        yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft)
                                * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight)));
                    } else {
                        yRightLocation = y;
                    }

                    String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName
                            + new Money(y);
                    if (x == xItem && y == yItem) {
                        titleLegend1.setText(text);
                        if (null == clickCrossHairs) {
                            clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation);
                            clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT);
                            xyplot.addAnnotation(clickCrossHairs);
                        } else {
                            clickCrossHairs.setText(text);
                            clickCrossHairs.setX(x);
                            clickCrossHairs.setY(yRightLocation);
                        }
                    }
                }
            } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) {
                for (XYPlot xyplot : subplots) {
                    if (xyplot.removeAnnotation(clickCrossHairs)) {
                        clickCrossHairs = null;
                        titleLegend1.setText(" Time: 0, Price :0.0");
                        break;
                    }
                }
            }
        }
    });
    this.add(chartPanel, null);
    this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this);
}

From source file:org.pentaho.platform.uifoundation.chart.XYSeriesCollectionChartComponent.java

private void populateInfo(final ChartRenderingInfo info) {
    if (urlTemplate == null) {
        return;/*  w ww .  j av a  2 s.  c  om*/
    }
    Iterator iter = info.getEntityCollection().iterator();
    while (iter.hasNext()) {
        ChartEntity entity = (ChartEntity) iter.next();
        if (entity instanceof XYItemEntity) {
            if (urlTemplate != null) {
                XYItemEntity xyItemEntity = (XYItemEntity) entity;
                if (paramName == null) {
                    xyItemEntity.setURLText(urlTemplate);
                } else {
                    try {
                        int seriesIndex = xyItemEntity.getSeriesIndex();
                        int itemIndex = xyItemEntity.getItem();
                        String xySeriesKey = (String) ((XYSeriesCollection) xyItemEntity.getDataset())
                                .getSeriesKey(seriesIndex);
                        String encodedVal = URLEncoder.encode(xySeriesKey, LocaleHelper.getSystemEncoding());
                        String drillURL = TemplateUtil.applyTemplate(urlTemplate, paramName, encodedVal);
                        String itemValueStr = ((XYSeriesCollection) xyItemEntity.getDataset())
                                .getX(seriesIndex, itemIndex).toString();
                        encodedVal = URLEncoder.encode(itemValueStr, LocaleHelper.getSystemEncoding());
                        if (seriesName == null) {
                            drillURL = TemplateUtil.applyTemplate(drillURL, "SERIES", encodedVal); //$NON-NLS-1$
                        } else {
                            drillURL = TemplateUtil.applyTemplate(drillURL, seriesName, encodedVal);
                        }
                        xyItemEntity.setURLText(drillURL);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

From source file:org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartComponent.java

private void populateInfo(final ChartRenderingInfo info) {
    if (urlTemplate == null) {
        return;/* ww w. j  a  v  a  2s . c  o  m*/
    }
    Iterator iter = info.getEntityCollection().iterator();
    while (iter.hasNext()) {
        ChartEntity entity = (ChartEntity) iter.next();
        if (entity instanceof XYItemEntity) {
            if (urlTemplate != null) {
                XYItemEntity xyItemEntity = (XYItemEntity) entity;
                if (paramName == null) {
                    xyItemEntity.setURLText(urlTemplate);
                } else {
                    try {
                        int seriesIndex = xyItemEntity.getSeriesIndex();
                        int itemIndex = xyItemEntity.getItem();
                        String xySeriesKey = (String) ((TimeSeriesCollection) xyItemEntity.getDataset())
                                .getSeriesKey(seriesIndex);
                        String encodedVal = URLEncoder.encode(xySeriesKey, LocaleHelper.getSystemEncoding());
                        String drillURL = TemplateUtil.applyTemplate(urlTemplate, paramName, encodedVal);
                        String itemValueStr = ((TimeSeriesCollection) xyItemEntity.getDataset())
                                .getX(seriesIndex, itemIndex).toString();
                        encodedVal = URLEncoder.encode(itemValueStr, LocaleHelper.getSystemEncoding());
                        if (seriesName == null) {
                            drillURL = TemplateUtil.applyTemplate(drillURL, "SERIES", encodedVal); //$NON-NLS-1$
                        } else {
                            drillURL = TemplateUtil.applyTemplate(drillURL, seriesName, encodedVal);
                        }
                        xyItemEntity.setURLText(drillURL);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

From source file:org.pentaho.platform.uifoundation.chart.XYZSeriesCollectionChartComponent.java

private void populateInfo(final ChartRenderingInfo info) {
    if (urlTemplate == null) {
        return;//from   w  w  w . j a va2 s  . c  o  m
    }
    Iterator iter = info.getEntityCollection().iterator();
    while (iter.hasNext()) {
        ChartEntity entity = (ChartEntity) iter.next();
        if (entity instanceof XYItemEntity) {
            if (urlTemplate != null) {
                XYItemEntity xyItemEntity = (XYItemEntity) entity;
                if (paramName == null) {
                    xyItemEntity.setURLText(urlTemplate);
                } else {
                    try {
                        int seriesIndex = xyItemEntity.getSeriesIndex();
                        int itemIndex = xyItemEntity.getItem();
                        String xySeriesKey = (String) ((XYZSeriesCollectionChartDefinition) xyItemEntity
                                .getDataset()).getSeriesKey(seriesIndex);
                        String encodedVal = URLEncoder.encode(xySeriesKey, LocaleHelper.getSystemEncoding());
                        String drillURL = TemplateUtil.applyTemplate(urlTemplate, paramName, encodedVal);
                        String itemValueStr = ((XYZSeriesCollectionChartDefinition) xyItemEntity.getDataset())
                                .getX(seriesIndex, itemIndex).toString();
                        encodedVal = URLEncoder.encode(itemValueStr, LocaleHelper.getSystemEncoding());
                        if (seriesName == null) {
                            drillURL = TemplateUtil.applyTemplate(drillURL, "SERIES", encodedVal); //$NON-NLS-1$
                        } else {
                            drillURL = TemplateUtil.applyTemplate(drillURL, seriesName, encodedVal);
                        }
                        xyItemEntity.setURLText(drillURL);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

From source file:com.bwc.ora.views.LrpDisplayFrame.java

private ChartMouseListener getMovementChartMouseListener(HighlightXYRenderer renderer) {
    return new ChartMouseListener() {

        @Override//from   ww w . ja  v a  2 s . c  om
        public void chartMouseClicked(ChartMouseEvent cme) {
            //do nothing
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
            ChartEntity entity = cme.getEntity();
            if (!(entity instanceof XYItemEntity)) {
                renderer.setHighlightedItem(-1, -1);
                octDrawnPointsCollection.clear();
            } else {
                XYItemEntity xyent = (XYItemEntity) entity;
                renderer.setHighlightedItem(xyent.getSeriesIndex(), xyent.getItem());
                int x = lrps.getSelectedValue().getLrpCenterXPosition();
                //get the Y value of the item on the LRP (in the case of
                // the graph this is the X value since the orientation of the plot is flipped)
                int y = (int) Math.round(xyent.getDataset().getXValue(xyent.getSeriesIndex(), xyent.getItem()));
                octDrawnPointsCollection.add(new OctDrawnPoint("Peak", new Point(x, y)));
            }
        }

    };
}

From source file:com.igalia.java.zk.components.JFreeChartEngine.java

/**
 * decode XYItemEntity into key-value pair of Area's componentScope.
 *///from   ww w  .j a v  a 2  s  .  co m
private void decodeXYInfo(Area area, XYItemEntity info, Chart chart) {
    if (info == null) {
        return;
    }
    TimeZone tz = chart.getTimeZone();
    if (tz == null)
        tz = TimeZones.getCurrent();

    XYDataset dataset = info.getDataset();
    int si = info.getSeriesIndex();
    int ii = info.getItem();

    area.setAttribute("series", dataset.getSeriesKey(si));

    if (dataset instanceof XYZDataset) {
        XYZDataset ds = (XYZDataset) dataset;
        area.setAttribute("x", ds.getX(si, ii));
        area.setAttribute("y", ds.getY(si, ii));
        area.setAttribute("z", ds.getZ(si, ii));
    } else {
        area.setAttribute("x", dataset.getX(si, ii));
        area.setAttribute("y", dataset.getY(si, ii));
    }

}

From source file:course_generator.param.frmEditCurve.java

/**
 * This method is called to initialize the form.
 *///from  w w  w .  j  av  a2 s  . co  m
private void initComponents() {
    int line = 0;

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(bundle.getString("frmEditCurve.title"));
    setPreferredSize(new Dimension(1200, 600));
    setAlwaysOnTop(true);
    setResizable(false);
    setType(java.awt.Window.Type.UTILITY);
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });

    // -- Layout
    // ------------------------------------------------------------
    Container paneGlobal = getContentPane();
    paneGlobal.setLayout(new GridBagLayout());

    //-- Curves list
    ListCurves = new javax.swing.JList<>();
    model = new ParamListModel();
    ListCurves.setModel(model);
    ListCurves.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    ListCurves.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            SelectCurve();
        }
    });
    jScrollPaneCurves = new javax.swing.JScrollPane();
    jScrollPaneCurves.setViewportView(ListCurves);

    Utils.addComponent(paneGlobal, jScrollPaneCurves, 0, 0, 1, 4, 0.5, 1, 10, 10, 0, 0,
            GridBagConstraints.PAGE_START, GridBagConstraints.BOTH);

    //-- Curve management toolbar
    CreateCurvesToolbar();
    Utils.addComponent(paneGlobal, ToolBarAction, 1, 0, 1, 4, 0, 0, 10, 0, 0, 0,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    lbSelectedCurve = new javax.swing.JLabel();
    lbSelectedCurve.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    lbSelectedCurve.setText("Selected");
    lbSelectedCurve.setHorizontalAlignment(JLabel.LEFT);
    Utils.addComponent(paneGlobal, lbSelectedCurve, 2, 0, GridBagConstraints.REMAINDER, 1, 1, 0, 10, 0, 5, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);

    //-- Curve name
    lbName = new javax.swing.JLabel();
    lbName.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    lbName.setText(" " + bundle.getString("frmEditCurve.lbName.text") + " ");
    Utils.addComponent(paneGlobal, lbName, 2, 1, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING,
            GridBagConstraints.HORIZONTAL);

    lbNameVal = new javax.swing.JLabel();
    lbNameVal.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(paneGlobal, lbNameVal, 3, 1, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    //-- Curve comment
    lbComment = new javax.swing.JLabel();
    lbComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    lbComment.setText(" " + bundle.getString("frmEditCurve.lbComment.text") + " ");
    Utils.addComponent(paneGlobal, lbComment, 2, 2, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING,
            GridBagConstraints.HORIZONTAL);

    tfComment = new JTextField();
    tfComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(paneGlobal, tfComment, 3, 2, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);

    //-- Point list
    TablePoints = new javax.swing.JTable();
    TablePoints.setModel(tablemodel);//new ParamPointsModel(param));
    TablePoints.getTableHeader().setReorderingAllowed(false);
    TablePoints.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            //            TableMainMouseClicked(evt);
        }
    });
    TablePoints.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            //            TableMainKeyReleased(evt);
        }
    });

    jScrollPanePoint = new javax.swing.JScrollPane();
    jScrollPanePoint.setViewportView(TablePoints);
    Utils.addComponent(paneGlobal, jScrollPanePoint, 2, 3, 2, 1, 0.5, 0, 0, 0, 0, 0,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    //-- Edit toolbar
    CreateEditToolbar();
    Utils.addComponent(paneGlobal, ToolBarEdit, 4, 3, 1, 1, 0, 0, 0, 0, 0, 0,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    jPanelProfilChart = new ChartPanel(chart);
    Utils.addComponent(paneGlobal, jPanelProfilChart, 5, 3, 1, 1, 1, 0, 0, 0, 0, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
    xCrosshair.setLabelVisible(true);
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);

    yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
    yCrosshair.setLabelVisible(true);
    yCrosshair.setLabelBackgroundPaint(Color.WHITE);

    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);

    jPanelProfilChart.addOverlay(crosshairOverlay);
    jPanelProfilChart.setBackground(new java.awt.Color(255, 0, 51));
    jPanelProfilChart.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent event) {

            ChartEntity chartentity = event.getEntity();
            if (chartentity instanceof XYItemEntity) {
                XYItemEntity e = (XYItemEntity) chartentity;
                XYDataset d = e.getDataset();
                int s = e.getSeriesIndex();
                int i = e.getItem();
                double x = d.getXValue(s, i);
                double y = d.getYValue(s, i);
                xCrosshair.setValue(x);
                yCrosshair.setValue(y);
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });

    // == Bottom button
    // ===========================================================
    btOk = new javax.swing.JButton();
    btOk.setText(bundle.getString("frmEditCurve.btOk.text"));
    btOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/valid.png")));
    btOk.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            RequestToClose();
        }
    });
    Utils.addComponent(paneGlobal, btOk, 0, 5, GridBagConstraints.REMAINDER, 1, 0, 0, 10, 0, 10, 0,
            GridBagConstraints.CENTER, GridBagConstraints.NONE);

    // --
    pack();

    //-- Refresh the curve list
    RefreshCurveList();

    //-- Center the windows
    setLocationRelativeTo(null);
}

From source file:org.mwc.debrief.sensorfusion.views.SensorFusionView.java

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it.//w w  w  . j  a v  a  2 s .  c  om
 */
public void createPartControl(final Composite parent) {
    makeActions();
    contributeToActionBars();

    // and the selection provider bits
    _selectionHelper = new SelectionHelper();
    getSite().setSelectionProvider(_selectionHelper);

    // declare our context sensitive help
    CorePlugin.declareContextHelp(parent, "org.mwc.debrief.help.BulkSensorData");

    parent.setLayout(new FillLayout());

    // ok, let's mockup the UI
    final JFreeChart myChart = DataSupport.createChart(null);
    myChart.setTitle(CHART_NAME);
    myChart.getXYPlot().setRenderer(_plotRenderer);

    // and the chart frame
    _myChartFrame = new ChartComposite(parent, SWT.NONE, myChart, 400, 600, 300, 200, 1800, 1800, true, true,
            true, true, true, true) {

        @Override
        protected Menu createPopupMenu(boolean arg0, boolean arg1, boolean arg2, boolean arg3) {
            // prevent the JFreeChart menu from opening
            return null;
        }

        @Override
        public void mouseUp(MouseEvent event) {
            super.mouseUp(event);
            JFreeChart c = getChart();
            if (c != null) {
                c.setNotify(true); // force redraw
            }
        }
    };
    _myChartFrame.setDisplayToolTips(false);
    _myChartFrame.setHorizontalAxisTrace(false);
    _myChartFrame.setVerticalAxisTrace(false);

    _myChartFrame.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseClicked(final ChartMouseEvent event) {
            final ChartEntity entity = event.getEntity();
            if (entity instanceof XYItemEntity) {
                final XYItemEntity xyi = (XYItemEntity) entity;
                final TimeSeriesCollection coll = (TimeSeriesCollection) xyi.getDataset();
                final TacticalSeries ts = (TacticalSeries) coll
                        .getSeries(((XYItemEntity) entity).getSeriesIndex());
                if (ts instanceof SensorSeries) {
                    final SensorSeries ss = (SensorSeries) ts;

                    // check which mouse it si
                    if (event.getTrigger().getButton() == 3) {
                        // get the sensor itself
                        final SensorWrapper sensor = ss.getSensor();

                        // get the parent layer
                        final TrackWrapper parentLayer = (TrackWrapper) _trackData.getPrimaryTrack();

                        // ok, create ourselves a menu
                        final MenuManager mmgr = new MenuManager();

                        // insert the relevant menu items
                        RightClickSupport.getDropdownListFor(mmgr, new Editable[] { sensor }, null,
                                new Layer[] { parentLayer }, _currentLayers, false);

                        // get the SWT menu object for it
                        final Menu thisM = mmgr.createContextMenu(_myChartFrame);

                        // and display it
                        thisM.setVisible(true);
                    } else {
                        // right, is ctrl-key pressed
                        final int mods = event.getTrigger().getModifiers();
                        if ((mods & InputEvent.CTRL_MASK) == 0) {
                            _selectedTracks.removeAllElements();
                            _selectedTracks.add(ss);
                        } else {
                            if (_selectedTracks.contains(ts))
                                _selectedTracks.remove(ts);
                            else
                                _selectedTracks.add(ss);

                        }

                        // and update the UI
                        updatedSelection();

                        // ok, we need to redraw
                        redrawPlot();
                    }
                }
            } else {
                _selectedTracks.removeAllElements();

                // and update the UI
                updatedSelection();
                // ok, we need to redraw
                redrawPlot();
            }
        }

        public void chartMouseMoved(final ChartMouseEvent event) {
        }
    });

    _selectionChangeListener = new ISelectionChangedListener() {

        @SuppressWarnings({ "rawtypes" })
        public void selectionChanged(final SelectionChangedEvent event) {
            // right, see what it is
            final ISelection sel = event.getSelection();
            if (sel instanceof StructuredSelection) {
                final StructuredSelection ss = (StructuredSelection) sel;
                final Iterator eles = ss.iterator();
                boolean processingThese = false;
                while (eles.hasNext()) {
                    final Object datum = eles.next();
                    if (datum instanceof EditableWrapper) {
                        final EditableWrapper pw = (EditableWrapper) datum;
                        final Editable ed = pw.getEditable();
                        if (ed instanceof SensorWrapper) {
                            if (!processingThese) {
                                processingThese = true;
                                _selectedTracks.removeAllElements();

                            }
                            final SensorSeries thisSeries = _trackIndex.get(ed);
                            _selectedTracks.add(thisSeries);
                        }
                    }
                }
                if (processingThese)
                    redrawPlot();
            }
        }
    };

    // and sort out the listeners
    setupListeners();

}

From source file:ec.util.chart.swing.JTimeSeriesChart.java

private void enableObsTriggering() {
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override/*from  w ww  . j a v  a 2  s  .c o  m*/
        public void chartMouseClicked(ChartMouseEvent event) {
            if (isInteractive()) {
                setSelectedObs(getObsIndex(event));
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            if (isInteractive()) {
                setHoveredObs(getObsIndex(event));
            }
        }

        private ObsIndex getObsIndex(ChartMouseEvent event) {
            if (event.getEntity() instanceof XYItemEntity) {
                XYItemEntity xxx = (XYItemEntity) event.getEntity();
                int series = ((FilteredXYDataset) xxx.getDataset()).originalIndexOf(xxx.getSeriesIndex());
                int obs = xxx.getItem();
                return ObsIndex.valueOf(series, obs);
            } else {
                return ObsIndex.NULL;
            }
        }
    });
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelResults.java

/**
 * Creates a panel displaying the distribution chart of certain selected
 * statistical values.//from w  w  w  .j a va  2  s. c  o  m
 * 
 * @param title
 *          The headline of the chart. Will be hidden if set to null.
 * @param statistics
 *          The selected statistics of a campaign containing all needed
 *          values.
 * @param roomType
 *          The room type to determine the colour of the chart.
 * @param preview
 *          Will hide annotations, labels and headlines if set true.
 * @param fullscreen
 *          Will correctly adjust the preferred size to screen resolution if
 *          true.
 * @param mouseEvent
 *          Will enable mouseClickedEvent if set true. Use with care, and only
 *          inside the results panel. Set to false if you are unsure what you
 *          are doing.
 * @return A chart displaying the distribution of certain selected statistical
 *         values.
 */
public JPanel createDistributionPanel(String title, DescriptiveStatistics statistics, OMRoomType roomType,
        boolean preview, boolean fullscreen, boolean mouseEvent) {
    JFreeChart chart = OMCharts.createDistributionChart(title, statistics, roomType, preview);
    ChartPanel chartPanel = new ChartPanel(chart);
    Dimension dim;
    if (fullscreen) {
        dim = Toolkit.getDefaultToolkit().getScreenSize();
    } else {
        dim = new Dimension(730, 347);
    }
    chartPanel.setPreferredSize(dim);
    if (mouseEvent) {
        chartPanel.addChartMouseListener(new ChartMouseListener() {
            @Override
            public void chartMouseClicked(ChartMouseEvent e) {
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                OMCampaign[] campaigns = simulation.getCampaigns();
                try {
                    XYItemEntity entity = (XYItemEntity) e.getEntity();
                    XYDataset dataset = entity.getDataset();
                    int item = entity.getItem();
                    double x = dataset.getXValue(0, item);
                    double comparable = 0.0;
                    OMCampaign result = null;
                    OMStatistics selectedType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    for (int i = 0; i < campaigns.length; i++) {
                        switch (selectedType) {
                        case RoomArithmeticMeans:
                            comparable = campaigns[i].getRoomAverage();
                            break;
                        case RoomGeometricMeans:
                            comparable = campaigns[i].getRoomLogAverage();
                            break;
                        case RoomMedianQ50:
                            comparable = campaigns[i].getRoomMedian();
                            break;
                        case RoomMaxima:
                            comparable = campaigns[i].getRoomMaximum();
                            break;
                        case CellarArithmeticMeans:
                            comparable = campaigns[i].getCellarAverage();
                            break;
                        case CellarGeometricMeans:
                            comparable = campaigns[i].getCellarLogAverage();
                            break;
                        case CellarMedianQ50:
                            comparable = campaigns[i].getCellarMedian();
                            break;
                        case CellarMaxima:
                            comparable = campaigns[i].getCellarMaximum();
                            break;
                        default:
                            comparable = campaigns[i].getRoomAverage();
                            break;
                        }
                        if (comparable == x) {
                            result = campaigns[i];
                        }
                    }
                    if (result != null) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ie) {
                            ie.printStackTrace();
                        }
                        JTabbedPane tab = (JTabbedPane) getParent();
                        tab.remove(tab.getComponentAt(4));
                        JPanel jpanelTesting = new OMPanelTesting(simulation, result);
                        tab.add(jpanelTesting, "Analyse", 4);
                        tab.updateUI();
                        tab.setSelectedIndex(4);
                    }
                } catch (Exception x) {
                    x.printStackTrace();
                }
            }

            @Override
            public void chartMouseMoved(ChartMouseEvent ignore) {
            }
        });
    }
    JPanel distPanel = (JPanel) chartPanel;
    return distPanel;
}