Search in sources :

Example 6 with ChartMouseEvent

use of org.jfree.chart.ChartMouseEvent in project cubrid-manager by CUBRID.

the class WhiteChart method loadChart.

public void loadChart() {
    ChartComposite frame;
    if (groupName != null) {
        final Group chartGroup = new Group(composite, SWT.RESIZE);
        chartGroup.setText(groupName);
        GridLayout chartGroupLayout = new GridLayout();
        chartGroupLayout.marginHeight = 6;
        chartGroupLayout.marginWidth = 6;
        chartGroup.setLayout(chartGroupLayout);
        chartGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
        frame = new ChartComposite(chartGroup, SWT.NONE, createChart(), false, false, false, false, false);
    } else {
        frame = new ChartComposite(composite, SWT.NONE, createChart(), false, false, false, false, false);
    }
    GridData gdFrame = new GridData(SWT.FILL, SWT.FILL, true, true);
    frame.setLayoutData(gdFrame);
    frame.setLayout(new FillLayout());
    frame.setDomainZoomable(false);
    frame.setRangeZoomable(false);
    frame.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseMoved(ChartMouseEvent event) {
        }

        public void chartMouseClicked(ChartMouseEvent event) {
            if (event.getTrigger().getButton() == 1) {
                editor.openEditStatisticItemDialog();
            }
        }
    });
}
Also used : ChartComposite(org.jfree.experimental.chart.swt.ChartComposite) Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ChartMouseListener(org.jfree.chart.ChartMouseListener)

Example 7 with ChartMouseEvent

use of org.jfree.chart.ChartMouseEvent in project tdq-studio-se by Talend.

the class TOPChartService method addListenerToChartComp.

@Override
public void addListenerToChartComp(Object chartComposite, final String referenceLink, final String menuText) {
    final ChartComposite chartComp = (ChartComposite) chartComposite;
    final ChartMouseListener listener = new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            if (event.getTrigger().getButton() == 1 && referenceLink != null) {
                Menu menu = new Menu(chartComp.getShell(), SWT.POP_UP);
                chartComp.setMenu(menu);
                MenuItem item = new MenuItem(menu, SWT.PUSH);
                item.setText(menuText);
                item.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        ChartUtils.openReferenceLink(referenceLink);
                    }
                });
                menu.setVisible(true);
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        // no need to implement
        }
    };
    chartComp.addChartMouseListener(listener);
    chartComp.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            chartComp.removeChartMouseListener(listener);
            chartComp.dispose();
        }
    });
}
Also used : TalendChartComposite(org.talend.dataprofiler.chart.util.TalendChartComposite) ChartComposite(org.jfree.experimental.chart.swt.ChartComposite) DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ChartMouseListener(org.jfree.chart.ChartMouseListener)

Example 8 with ChartMouseEvent

use of org.jfree.chart.ChartMouseEvent in project tdq-studio-se by Talend.

the class TOPChartService method addSpecifiedListenersForCorrelationChart.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.service.ITOPChartService#addSpecifiedListenersForCorrelationChart(boolean, boolean,
     * java.lang.Object, java.util.List)
     */
@Override
public void addSpecifiedListenersForCorrelationChart(Object chartcomp, final Object chart, final boolean isAvg, final boolean isDate, final Map<Integer, Object> keyWithAdapter) {
    final ChartComposite chartComp = (ChartComposite) chartcomp;
    chartComp.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            chartComp.setRangeZoomable(event.getTrigger().getButton() == 1);
            chartComp.setDomainZoomable(event.getTrigger().getButton() == 1);
            if (event.getTrigger().getButton() != 3) {
                return;
            }
            final Menu menu = new Menu(chartComp.getShell(), SWT.POP_UP);
            MenuItem itemShowInFullScreen = new MenuItem(menu, SWT.PUSH);
            // $NON-NLS-1$
            itemShowInFullScreen.setText(Messages.getString("HideSeriesChartComposite.ShowInFullScreen"));
            itemShowInFullScreen.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            showChartInFillScreen(chart, isAvg, isDate);
                        }
                    });
                }
            });
            chartComp.setMenu(menu);
            ChartEntity chartEntity = event.getEntity();
            if (chartEntity != null) {
                if (isAvg) {
                    addMenuOnBubbleChart(menu, chartEntity);
                } else if (isDate) {
                    addMenuOnGantChart(menu, chartEntity);
                }
            }
            menu.setVisible(true);
        }

        private void addMenuOnBubbleChart(Menu menu, ChartEntity chartEntity) {
            if (chartEntity instanceof XYItemEntity) {
                XYItemEntity xyItemEntity = (XYItemEntity) chartEntity;
                createMenuItem(menu, xyItemEntity.getItem());
            }
        }

        private void addMenuOnGantChart(Menu menu, ChartEntity chartEntity) {
            if (chartEntity instanceof CategoryItemEntity) {
                CategoryItemEntity itemEntity = (CategoryItemEntity) chartEntity;
                createMenuItem(menu, itemEntity.getCategoryIndex());
            }
        }

        private void createMenuItem(Menu menu, final int seriesK) {
            final SelectionAdapter selectionAdapter = (SelectionAdapter) keyWithAdapter.get(seriesK);
            MenuItem item;
            item = new MenuItem(menu, SWT.PUSH);
            // $NON-NLS-1$
            item.setText(Messages.getString("HideSeriesChartComposite.ViewRow"));
            item.addSelectionListener(selectionAdapter);
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        // no need to implement
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ChartMouseListener(org.jfree.chart.ChartMouseListener) XYItemEntity(org.jfree.chart.entity.XYItemEntity) TalendChartComposite(org.talend.dataprofiler.chart.util.TalendChartComposite) ChartComposite(org.jfree.experimental.chart.swt.ChartComposite) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ChartEntity(org.jfree.chart.entity.ChartEntity) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity)

Example 9 with ChartMouseEvent

use of org.jfree.chart.ChartMouseEvent in project tdq-studio-se by Talend.

the class TOPChartService method addMouseListenerForConceptChart.

@Override
public void addMouseListenerForConceptChart(Object chartComposite, final Map<String, Object> actionMap) {
    final ChartComposite chartComp = (ChartComposite) chartComposite;
    final ChartMouseListener listener = new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            boolean flag = event.getTrigger().getButton() == MouseEvent.BUTTON1;
            chartComp.setDomainZoomable(flag);
            chartComp.setRangeZoomable(flag);
            if (!flag) {
                return;
            }
            ChartEntity chartEntity = event.getEntity();
            if (chartEntity != null && chartEntity instanceof CategoryItemEntity) {
                CategoryItemEntity cateEntity = (CategoryItemEntity) chartEntity;
                // highlight current selected bar
                Plot plot = event.getChart().getPlot();
                if (plot != null) {
                    // ((CategoryPlot) plot).getRenderer().setSeriesPaint(cateEntity.getSeries(), Green);
                    CustomConceptRenderer render = new CustomConceptRenderer(cateEntity.getCategoryIndex());
                    render.setShadowVisible(false);
                    render.setDrawBarOutline(false);
                    ((CategoryPlot) plot).setRenderer(render);
                // ChartDecorator.decorateConceptChart(event.getChart(), PlotOrientation.HORIZONTAL);
                }
                Object action = getCurrentAction(cateEntity);
                Class<? extends Object> actionClass = action.getClass();
                try {
                    // $NON-NLS-1$
                    Method actionRunMethod = actionClass.getDeclaredMethod("run");
                    actionRunMethod.invoke(action);
                } catch (NoSuchMethodException e) {
                    log.error(e, e);
                } catch (SecurityException e) {
                    log.error(e, e);
                } catch (IllegalAccessException e) {
                    log.error(e, e);
                } catch (IllegalArgumentException e) {
                    log.error(e, e);
                } catch (InvocationTargetException e) {
                    log.error(e, e);
                }
            }
        }

        private Object getCurrentAction(CategoryItemEntity cateEntity) {
            return findCurrentAction(cateEntity.getColumnKey(), cateEntity.getRowKey());
        }

        /**
         * Find current action
         *
         * @param firstKey
         * @param secondKey
         * @return
         */
        private Object findCurrentAction(final Object firstKey, Object secondKey) {
            Object action = actionMap.get(firstKey);
            if (action != null) {
                return action;
            }
            action = actionMap.get(secondKey);
            if (action != null) {
                return action;
            }
            return null;
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        // no action here
        }
    };
    chartComp.addChartMouseListener(listener);
    chartComp.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            chartComp.removeChartMouseListener(listener);
            chartComp.dispose();
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) XYPlot(org.jfree.chart.plot.XYPlot) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Plot(org.jfree.chart.plot.Plot) Method(java.lang.reflect.Method) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) CategoryPlot(org.jfree.chart.plot.CategoryPlot) InvocationTargetException(java.lang.reflect.InvocationTargetException) ChartMouseListener(org.jfree.chart.ChartMouseListener) TalendChartComposite(org.talend.dataprofiler.chart.util.TalendChartComposite) ChartComposite(org.jfree.experimental.chart.swt.ChartComposite) ChartEntity(org.jfree.chart.entity.ChartEntity) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity)

Example 10 with ChartMouseEvent

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

the class JPanelAnalysisSpeed method initComponents.

private void initComponents() {
    setLayout(new java.awt.BorderLayout());
    // //-- Left - Toolbar
    // Create_Toolbar();
    // add(toolBar, java.awt.BorderLayout.WEST);
    // 
    // -- Bottom - Info
    jPanelSpeedInfo = new javax.swing.JPanel();
    jPanelSpeedInfo.setOpaque(true);
    jPanelSpeedInfo.setBackground(Color.WHITE);
    jPanelSpeedInfo.setLayout(new GridBagLayout());
    add(jPanelSpeedInfo, java.awt.BorderLayout.SOUTH);
    // -- Start speed/End speed/Speed/Distance
    // -- Start speed
    lbSpeedInfoStartSpeed = new javax.swing.JLabel();
    lbSpeedInfoStartSpeed.setOpaque(true);
    lbSpeedInfoStartSpeed.setBackground(Color.WHITE);
    lbSpeedInfoStartSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoStartSpeed.text") + "=0km/h ");
    lbSpeedInfoStartSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoStartSpeed, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- End speed
    lbSpeedInfoEndSpeed = new javax.swing.JLabel();
    lbSpeedInfoEndSpeed.setOpaque(true);
    lbSpeedInfoEndSpeed.setBackground(Color.WHITE);
    lbSpeedInfoEndSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoEndSpeed.text") + "=0km/h ");
    lbSpeedInfoEndSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoEndSpeed, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Speed
    lbSpeedInfoSpeed = new javax.swing.JLabel();
    lbSpeedInfoSpeed.setOpaque(true);
    lbSpeedInfoSpeed.setBackground(Color.WHITE);
    lbSpeedInfoSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoSpeed.text") + "=0km/h ");
    lbSpeedInfoSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoSpeed, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Distance
    lbSpeedInfoDistance = new javax.swing.JLabel();
    lbSpeedInfoDistance.setOpaque(true);
    lbSpeedInfoDistance.setBackground(Color.WHITE);
    lbSpeedInfoDistance.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoDistance.text") + "=0.000km ");
    lbSpeedInfoDistance.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoDistance, 3, 0, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL);
    // -- Chart Speed/Dist & Time/Dist
    ChartPanelSpeed = new ChartPanel(chart, true, /* Properties */
    true, /* save */
    true, /* print */
    false, /* zoom */
    true);
    ChartPanelSpeed.setDomainZoomable(false);
    ChartPanelSpeed.setRangeZoomable(false);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.RED, new BasicStroke(0f));
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    ChartPanelSpeed.addOverlay(crosshairOverlay);
    ChartPanelSpeed.setBackground(new java.awt.Color(255, 0, 51));
    ChartPanelSpeed.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);
                xCrosshair.setValue(x);
                RefreshInfo(i);
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });
    add(ChartPanelSpeed, 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)

Aggregations

ChartMouseEvent (org.jfree.chart.ChartMouseEvent)17 ChartMouseListener (org.jfree.chart.ChartMouseListener)17 ChartEntity (org.jfree.chart.entity.ChartEntity)12 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 Point2D (java.awt.geom.Point2D)3 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