Search in sources :

Example 11 with ChartMouseListener

use of org.jfree.chart.ChartMouseListener in project Course_Generator by patrovite.

the class JPanelAnalysisSpeedSlope method initComponents.

private void initComponents() {
    setLayout(new java.awt.BorderLayout());
    // -- Left - Toolbar
    Create_Toolbar();
    add(toolBar, java.awt.BorderLayout.WEST);
    // -- Bottom - Info
    jPanelSpeedSlopeInfo = new javax.swing.JPanel();
    jPanelSpeedSlopeInfo.setOpaque(true);
    jPanelSpeedSlopeInfo.setBackground(Color.WHITE);
    jPanelSpeedSlopeInfo.setLayout(new GridBagLayout());
    add(jPanelSpeedSlopeInfo, java.awt.BorderLayout.SOUTH);
    // -- Speed/Slope
    // -- Speed
    lbSpeedSlopeInfoSpeed = new javax.swing.JLabel();
    lbSpeedSlopeInfoSpeed.setOpaque(true);
    lbSpeedSlopeInfoSpeed.setBackground(Color.WHITE);
    lbSpeedSlopeInfoSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeedSlope.lbSpeedSlopeInfoSpeed.text") + "=0km/h ");
    lbSpeedSlopeInfoSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedSlopeInfo, lbSpeedSlopeInfoSpeed, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Slope
    lbSpeedSlopeInfoSlope = new javax.swing.JLabel();
    lbSpeedSlopeInfoSlope.setOpaque(true);
    lbSpeedSlopeInfoSlope.setBackground(Color.WHITE);
    lbSpeedSlopeInfoSlope.setText(" " + bundle.getString("JPanelAnalysisSpeedSlope.lbSpeedSlopeInfoSlope.text") + "=0.0% ");
    lbSpeedSlopeInfoSlope.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedSlopeInfo, lbSpeedSlopeInfoSlope, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL);
    // -- Chart Speed/Dist & Time/Dist
    ChartPanelSpeedSlope = new ChartPanel(chart, true, /* Properties */
    true, /* save */
    true, /* print */
    false, /* zoom */
    true);
    ChartPanelSpeedSlope.setDomainZoomable(false);
    ChartPanelSpeedSlope.setRangeZoomable(false);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.RED, new BasicStroke(0f));
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);
    // yCrosshair = new Crosshair(Double.NaN, Color.RED, new
    // BasicStroke(0f));
    // yCrosshair.setLabelBackgroundPaint(Color.WHITE);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    // crosshairOverlay.addRangeCrosshair(yCrosshair);
    ChartPanelSpeedSlope.addOverlay(crosshairOverlay);
    ChartPanelSpeedSlope.setBackground(new java.awt.Color(255, 0, 51));
    ChartPanelSpeedSlope.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);
                RefreshInfo(i);
            // //Refresh the position on the data grid
            // TableMain.setRowSelectionInterval(i, i);
            // Rectangle rect = TableMain.getCellRect(i, 0, true);
            // TableMain.scrollRectToVisible(rect);
            // //Refresh the marker position on the map
            // RefreshCurrentPosMarker(Track.data.get(i).getLatitude(),
            // Track.data.get(i).getLongitude());
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });
    add(ChartPanelSpeedSlope, java.awt.BorderLayout.CENTER);
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) ChartPanel(org.jfree.chart.ChartPanel) GridBagLayout(java.awt.GridBagLayout) Crosshair(org.jfree.chart.plot.Crosshair) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ChartMouseListener(org.jfree.chart.ChartMouseListener) XYItemEntity(org.jfree.chart.entity.XYItemEntity) JLabel(javax.swing.JLabel) CrosshairOverlay(org.jfree.chart.panel.CrosshairOverlay) XYDataset(org.jfree.data.xy.XYDataset) ChartEntity(org.jfree.chart.entity.ChartEntity) JPanel(javax.swing.JPanel)

Example 12 with ChartMouseListener

use of org.jfree.chart.ChartMouseListener in project Course_Generator by patrovite.

the class JPanelAnalysisTimeDist method initComponents.

private void initComponents() {
    setLayout(new java.awt.BorderLayout());
    // -- Bottom - Info
    jPanelTimeDistInfo = new javax.swing.JPanel();
    jPanelTimeDistInfo.setOpaque(true);
    jPanelTimeDistInfo.setBackground(Color.WHITE);
    jPanelTimeDistInfo.setLayout(new GridBagLayout());
    add(jPanelTimeDistInfo, java.awt.BorderLayout.SOUTH);
    // -- Distance/Elevation/Time/Hour/Slope
    lbTimeDistInfoDistance = new javax.swing.JLabel();
    lbTimeDistInfoDistance.setOpaque(true);
    lbTimeDistInfoDistance.setBackground(Color.WHITE);
    lbTimeDistInfoDistance.setText(" " + bundle.getString("JPanelAnalysisTimeDist.lbTimeDistInfoDistance.text") + "=0.000km ");
    lbTimeDistInfoDistance.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelTimeDistInfo, lbTimeDistInfoDistance, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Elevation
    lbTimeDistInfoElevation = new javax.swing.JLabel();
    lbTimeDistInfoElevation.setOpaque(true);
    lbTimeDistInfoElevation.setBackground(Color.WHITE);
    lbTimeDistInfoElevation.setText(" " + bundle.getString("JPanelAnalysisTimeDist.lbTimeDistInfoElevation.text") + "=0m ");
    lbTimeDistInfoElevation.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelTimeDistInfo, lbTimeDistInfoElevation, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Time
    lbTimeDistInfoTime = new javax.swing.JLabel();
    lbTimeDistInfoTime.setOpaque(true);
    lbTimeDistInfoTime.setBackground(Color.WHITE);
    lbTimeDistInfoTime.setText(" " + bundle.getString("JPanelAnalysisTimeDist.lbTimeDistInfoTime.text") + "=00:00:00 ");
    lbTimeDistInfoTime.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelTimeDistInfo, lbTimeDistInfoTime, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Hour
    lbTimeDistInfoHour = new javax.swing.JLabel();
    lbTimeDistInfoHour.setOpaque(true);
    lbTimeDistInfoHour.setBackground(Color.WHITE);
    lbTimeDistInfoHour.setText(" " + bundle.getString("JPanelAnalysisTimeDist.lbTimeDistInfoHour.text") + "=00:00:00 ");
    lbTimeDistInfoHour.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelTimeDistInfo, lbTimeDistInfoHour, 3, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Slope
    lbTimeDistSlope = new javax.swing.JLabel();
    lbTimeDistSlope.setOpaque(true);
    lbTimeDistSlope.setBackground(Color.WHITE);
    lbTimeDistSlope.setText(" " + bundle.getString("JPanelAnalysisTimeDist.lbTimeDistSlope.text") + "=0.0% ");
    lbTimeDistSlope.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelTimeDistInfo, lbTimeDistSlope, 4, 0, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL);
    // -- Chart Time/Dist
    ChartPanelTimeDist = new ChartPanel(chart, true, /*Properties*/
    true, /*save*/
    true, /*print*/
    false, /*zoom*/
    true);
    ChartPanelTimeDist.setDomainZoomable(false);
    ChartPanelTimeDist.setRangeZoomable(false);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.RED, new BasicStroke(0f));
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    ChartPanelTimeDist.addOverlay(crosshairOverlay);
    ChartPanelTimeDist.setBackground(new java.awt.Color(255, 0, 51));
    ChartPanelTimeDist.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);
                RefreshInfo(i);
            // Refresh the position on the data grid
            // TableMain.setRowSelectionInterval(i, i);
            // Rectangle rect = TableMain.getCellRect(i, 0, true);
            // TableMain.scrollRectToVisible(rect);
            // Refresh the marker position on the map
            // RefreshCurrentPosMarker(Track.data.get(i).getLatitude(),
            // Track.data.get(i).getLongitude());
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });
    add(ChartPanelTimeDist, java.awt.BorderLayout.CENTER);
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) ChartPanel(org.jfree.chart.ChartPanel) GridBagLayout(java.awt.GridBagLayout) Crosshair(org.jfree.chart.plot.Crosshair) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ChartMouseListener(org.jfree.chart.ChartMouseListener) XYItemEntity(org.jfree.chart.entity.XYItemEntity) JLabel(javax.swing.JLabel) CrosshairOverlay(org.jfree.chart.panel.CrosshairOverlay) XYDataset(org.jfree.data.xy.XYDataset) ChartEntity(org.jfree.chart.entity.ChartEntity) JPanel(javax.swing.JPanel)

Example 13 with ChartMouseListener

use of org.jfree.chart.ChartMouseListener in project Course_Generator by patrovite.

the class JPanelProfil method initComponents.

private void initComponents() {
    setPreferredSize(new java.awt.Dimension(677, 150));
    setLayout(new java.awt.BorderLayout());
    // -- Profil tool bar
    // ---------------------------------------------------
    Create_Profil_Toolbar();
    add(ToolBarProfil, java.awt.BorderLayout.WEST);
    // -- Profil chart
    // ------------------------------------------------------
    ChartPanelProfil = new ChartPanel(chartProfil);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.RED, new BasicStroke(0f));
    // xCrosshair.setLabelVisible(true);
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);
    yCrosshair = new Crosshair(Double.NaN, Color.RED, new BasicStroke(0f));
    // yCrosshair.setLabelVisible(true);
    yCrosshair.setLabelBackgroundPaint(Color.WHITE);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);
    ChartPanelProfil.addOverlay(crosshairOverlay);
    ChartPanelProfil.setBackground(new java.awt.Color(255, 0, 51));
    ChartPanelProfil.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);
                RefreshProfilInfo(i);
                notifyProfilSelection();
                index = i;
            // //Refresh the position on the data grid
            // TableMain.setRowSelectionInterval(i, i);
            // Rectangle rect = TableMain.getCellRect(i, 0, true);
            // TableMain.scrollRectToVisible(rect);
            // //Refresh the marker position on the map
            // RefreshCurrentPosMarker(Track.data.get(i).getLatitude(), Track.data.get(i).getLongitude());
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });
    add(ChartPanelProfil, java.awt.BorderLayout.CENTER);
    // -- Profil info bar
    // ---------------------------------------------------
    jPanelProfilInfo = new javax.swing.JPanel();
    jPanelProfilInfo.setLayout(new GridBagLayout());
    add(jPanelProfilInfo, java.awt.BorderLayout.SOUTH);
    // -- Line 0
    // -- Distance
    // ----------------------------------------------------------
    lbProfilDistance = new javax.swing.JLabel();
    lbProfilDistance.setOpaque(true);
    lbProfilDistance.setBackground(Color.WHITE);
    lbProfilDistance.setText(" " + bundle.getString("frmMain.lbProfilDistance.text") + "=0.000km ");
    lbProfilDistance.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilDistance, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH);
    // -- Time
    // --------------------------------------------------------------
    lbProfilTime = new javax.swing.JLabel();
    lbProfilTime.setOpaque(true);
    lbProfilTime.setBackground(Color.WHITE);
    lbProfilTime.setText(" " + bundle.getString("frmMain.lbProfilTime.text") + "=00:00:00 ");
    lbProfilTime.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilTime, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH);
    // -- Slope
    // -------------------------------------------------------------
    lbProfilSlope = new javax.swing.JLabel();
    lbProfilSlope.setOpaque(true);
    lbProfilSlope.setBackground(Color.WHITE);
    lbProfilSlope.setText(" " + bundle.getString("frmMain.lbProfilSlope.text") + "=0.0% ");
    lbProfilSlope.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilSlope, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH);
    // -- Name
    // --------------------------------------------------------------
    lbProfilName = new javax.swing.JLabel();
    lbProfilName.setOpaque(true);
    lbProfilName.setBackground(Color.WHITE);
    lbProfilName.setText(" " + bundle.getString("frmMain.lbProfilName.text") + "= ");
    lbProfilName.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilName, 3, 0, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH);
    // -- Line 1
    // -- Elevation
    // ---------------------------------------------------------
    lbProfilElevation = new javax.swing.JLabel();
    lbProfilElevation.setOpaque(true);
    lbProfilElevation.setBackground(Color.WHITE);
    lbProfilElevation.setText(" " + bundle.getString("frmMain.lbProfilElevation.text") + "=0m ");
    lbProfilElevation.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilElevation, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH);
    // -- Hour
    // --------------------------------------------------------------
    lbProfilHour = new javax.swing.JLabel();
    lbProfilHour.setOpaque(true);
    lbProfilHour.setBackground(Color.WHITE);
    lbProfilHour.setText(" " + bundle.getString("frmMain.lbProfilHour.text") + "=00:00:00 ");
    lbProfilHour.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilHour, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH);
    // -- Speed
    // -------------------------------------------------------------
    lbProfilSpeed = new javax.swing.JLabel();
    lbProfilSpeed.setOpaque(true);
    lbProfilSpeed.setBackground(Color.WHITE);
    lbProfilSpeed.setText(" " + bundle.getString("frmMain.lbProfilSpeed.text") + "=0.0km/h ");
    lbProfilSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilSpeed, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH);
    // -- Comment
    // -----------------------------------------------------------
    lbProfilComment = new javax.swing.JLabel();
    lbProfilComment.setOpaque(true);
    lbProfilComment.setBackground(Color.WHITE);
    lbProfilComment.setText(" " + bundle.getString("frmMain.lbProfilComment.text") + "= ");
    lbProfilComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilComment, 3, 1, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH);
// -- Distance / Time / Slope / Name
// -- Elevation / Hour / Speed / Comment
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) ChartPanel(org.jfree.chart.ChartPanel) GridBagLayout(java.awt.GridBagLayout) Crosshair(org.jfree.chart.plot.Crosshair) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ChartMouseListener(org.jfree.chart.ChartMouseListener) XYItemEntity(org.jfree.chart.entity.XYItemEntity) JLabel(javax.swing.JLabel) CrosshairOverlay(org.jfree.chart.panel.CrosshairOverlay) XYDataset(org.jfree.data.xy.XYDataset) ChartEntity(org.jfree.chart.entity.ChartEntity) JPanel(javax.swing.JPanel)

Example 14 with ChartMouseListener

use of org.jfree.chart.ChartMouseListener in project Course_Generator by patrovite.

the class frmEditCurve method initComponents.

/**
 * This method is called to initialize the form.
 */
private void initComponents() {
    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();
    // new ParamPointsModel(param));
    TablePoints.setModel(tablemodel);
    TablePoints.getTableHeader().setReorderingAllowed(false);
    TablePoints.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mouseClicked(java.awt.event.MouseEvent evt) {
        // TableMainMouseClicked(evt);
        // TODO
        }
    });
    TablePoints.addKeyListener(new java.awt.event.KeyAdapter() {

        public void keyReleased(java.awt.event.KeyEvent evt) {
        // TableMainKeyReleased(evt);
        // TODO
        }
    });
    TablePoints.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent event) {
            btEditLine.setEnabled(TablePoints.getSelectedRow() > 0);
        }
    });
    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("Global.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);
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) ChartPanel(org.jfree.chart.ChartPanel) GridBagLayout(java.awt.GridBagLayout) Crosshair(org.jfree.chart.plot.Crosshair) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JTextField(javax.swing.JTextField) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) XYItemEntity(org.jfree.chart.entity.XYItemEntity) Container(java.awt.Container) CrosshairOverlay(org.jfree.chart.panel.CrosshairOverlay) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) WindowEvent(java.awt.event.WindowEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ChartMouseListener(org.jfree.chart.ChartMouseListener) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) JTable(javax.swing.JTable) XYDataset(org.jfree.data.xy.XYDataset) ChartEntity(org.jfree.chart.entity.ChartEntity)

Example 15 with ChartMouseListener

use of org.jfree.chart.ChartMouseListener in project mafscaling by vimsh.

the class LogView method createWotChart.

protected void createWotChart() {
    wotMarker = new XYDomainMutilineAnnotation();
    wotMarker.setDefaultPaint(Color.WHITE);
    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
    wotChartPanel = new ChartPanel(chart, true, true, true, true, true);
    wotChartPanel.setFocusable(true);
    wotChartPanel.setAutoscrolls(true);
    chart.setBackgroundPaint(chartColor);
    wotPlot = chart.getXYPlot();
    wotPlot.setRangePannable(true);
    wotPlot.setDomainPannable(true);
    wotPlot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    wotPlot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    wotPlot.setBackgroundPaint(chartBgColor);
    wotPlot.addAnnotation(wotMarker);
    wotPlot.setRangeAxis(null);
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setTickLabelPaint(Color.WHITE);
    xAxis.setLabelPaint(Color.LIGHT_GRAY);
    wotPlot.setDomainAxis(0, xAxis);
    wotPlot.setDataset(0, new XYSeriesCollection());
    wotPlot.mapDatasetToDomainAxis(0, 0);
    wotPlot.mapDatasetToRangeAxis(0, 0);
    LegendTitle legend = new LegendTitle(wotPlot);
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    legend.setItemPaint(Color.WHITE);
    chart.addLegend(legend);
    wotChartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            try {
                wotPlot.clearRangeMarkers();
                wotMarker.clearLabels(false);
                Rectangle2D dataArea = wotChartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
                Point2D p = wotChartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
                double x = wotPlot.getDomainAxis().java2DToValue(p.getX(), dataArea, wotPlot.getDomainAxisEdge());
                XYSeriesCollection dataset;
                XYSeries series;
                for (int i = 0; i < wotPlot.getDatasetCount(); ++i) {
                    dataset = (XYSeriesCollection) wotPlot.getDataset(i);
                    if (dataset != null && dataset.getSeriesCount() > 0) {
                        for (int j = 0; j < dataset.getSeriesCount(); ++j) {
                            series = dataset.getSeries(j);
                            int idx = 0;
                            double closest;
                            double pclosest = Math.abs(series.getX(0).doubleValue() - x);
                            for (int k = 1; k < series.getItemCount(); ++k) {
                                closest = Math.abs(series.getX(k).doubleValue() - x);
                                if (closest < pclosest) {
                                    idx = k;
                                    pclosest = closest;
                                }
                            }
                            double x0 = series.getX(0).doubleValue();
                            double x1 = series.getX(series.getItemCount() - 1).doubleValue();
                            double xerr = x0 * 0.01;
                            if (x >= (x0 - xerr) && x <= (x1 + xerr))
                                wotMarker.addLabel(series.getDescription() + ": ", wotPlot.getRenderer(i).getSeriesPaint(j), series.getY(idx).toString(), false);
                        }
                    }
                }
                if (wotMarker.count() > 0) {
                    boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
                    if (isLeft) {
                        wotMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
                        wotMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
                    } else {
                        wotMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
                        wotMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
                    }
                    wotMarker.setValue(x);
                }
                wotChartPanel.repaint();
            } catch (Exception ex) {
                ex.printStackTrace();
                logger.error(ex);
            }
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            wotChartPanel.requestFocusInWindow();
            ChartEntity entity = event.getEntity();
            if (entity == null || !(entity instanceof LegendItemEntity))
                return;
            LegendItemEntity itemEntity = (LegendItemEntity) entity;
            int seriesIndex = ((XYDataset) itemEntity.getDataset()).indexOf(itemEntity.getSeriesKey());
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) wotChartPanel.getChart().getXYPlot().getRenderer();
            Paint p = renderer.getSeriesPaint(seriesIndex);
            colorChooser.setColor((Color) p);
            final ColorPreviewPanel preview = new ColorPreviewPanel(colorChooser);
            colorChooser.setPreviewPanel(preview);
            AbstractColorChooserPanel[] panels = colorChooser.getChooserPanels();
            for (AbstractColorChooserPanel accp : panels) {
                if (!accp.getDisplayName().equals("Swatches")) {
                    colorChooser.removeChooserPanel(accp);
                }
            }
            ColorSelectionModel model = colorChooser.getSelectionModel();
            model.addChangeListener(new ChangeListener() {

                @Override
                public void stateChanged(ChangeEvent event) {
                    ColorSelectionModel model = (ColorSelectionModel) event.getSource();
                    preview.setColor(model.getSelectedColor());
                }
            });
            if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(null, colorChooser, "Select new color for " + itemEntity.getSeriesKey(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE))
                renderer.setSeriesPaint(seriesIndex, colorChooser.getColor());
        }
    });
    wotChartPanel.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (!wotChartPanel.hasFocus())
                return;
            int keyCode = e.getKeyCode();
            if (keyCode < KeyEvent.VK_LEFT || keyCode > KeyEvent.VK_DOWN)
                return;
            ValueAxis axis = null;
            if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT)
                axis = ((XYPlot) wotChartPanel.getChart().getXYPlot()).getDomainAxis();
            else
                axis = ((XYPlot) wotChartPanel.getChart().getXYPlot()).getRangeAxis();
            if (axis != null) {
                double delta = (axis.getUpperBound() - axis.getLowerBound()) / 100.0;
                if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_DOWN)
                    axis.setRange(axis.getLowerBound() - delta, axis.getUpperBound() - delta);
                else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_RIGHT)
                    axis.setRange(axis.getLowerBound() + delta, axis.getUpperBound() + delta);
            }
        }

        public void keyReleased(KeyEvent arg0) {
        }

        public void keyTyped(KeyEvent arg0) {
        }
    });
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) ChartPanel(org.jfree.chart.ChartPanel) NumberAxis(org.jfree.chart.axis.NumberAxis) LegendTitle(org.jfree.chart.title.LegendTitle) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) Font(java.awt.Font) KeyEvent(java.awt.event.KeyEvent) AbstractColorChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) ChangeListener(javax.swing.event.ChangeListener) ColorSelectionModel(javax.swing.colorchooser.ColorSelectionModel) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) LegendItemEntity(org.jfree.chart.entity.LegendItemEntity) Paint(java.awt.Paint) JFreeChart(org.jfree.chart.JFreeChart) IOException(java.io.IOException) ChartMouseListener(org.jfree.chart.ChartMouseListener) ChangeEvent(javax.swing.event.ChangeEvent) KeyListener(java.awt.event.KeyListener) ChartEntity(org.jfree.chart.entity.ChartEntity) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Aggregations

ChartMouseEvent (org.jfree.chart.ChartMouseEvent)15 ChartMouseListener (org.jfree.chart.ChartMouseListener)15 ChartEntity (org.jfree.chart.entity.ChartEntity)10 ChartPanel (org.jfree.chart.ChartPanel)8 ChartComposite (org.jfree.experimental.chart.swt.ChartComposite)7 BasicStroke (java.awt.BasicStroke)6 Color (java.awt.Color)6 XYItemEntity (org.jfree.chart.entity.XYItemEntity)6 GridBagLayout (java.awt.GridBagLayout)5 JLabel (javax.swing.JLabel)5 JPanel (javax.swing.JPanel)5 CrosshairOverlay (org.jfree.chart.panel.CrosshairOverlay)5 Crosshair (org.jfree.chart.plot.Crosshair)5 XYDataset (org.jfree.data.xy.XYDataset)5 TalendChartComposite (org.talend.dataprofiler.chart.util.TalendChartComposite)4 DisposeEvent (org.eclipse.swt.events.DisposeEvent)3 DisposeListener (org.eclipse.swt.events.DisposeListener)3 Menu (org.eclipse.swt.widgets.Menu)3 CategoryItemEntity (org.jfree.chart.entity.CategoryItemEntity)3 Font (java.awt.Font)2