List of usage examples for org.jfree.chart ChartMouseEvent getEntity
public ChartEntity getEntity()
From source file:com.tocea.scertify.eclipse.scertifycode.ui.stats.views.GraphStatsView.java
/** * Creates the master view containing the chart. * //from w w w . java 2 s . c o m * @param parent * the parent composite * @return the chart composite */ public Composite createMasterView(final Composite parent) { // create the date set for the chart this.mPieDataset = new GraphPieDataset(); // this.mPieDataset.setShowAllCategories(this.mShowAllCategoriesAction.isChecked()); this.mPieDataset.setShowAllCategories(true); this.mGraph = createChart(this.mPieDataset); // creates the chart component // final Composite embeddedComposite = new Composite(parent, SWT.EMBEDDED); // embeddedComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); // experimental usage of JFreeChart SWT // the composite to harbor the Swing chart control ChartComposite embeddedComposite = new ChartComposite(parent, SWT.NONE, mGraph, true); embeddedComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); embeddedComposite.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(final ChartMouseEvent event) { final MouseEvent trigger = event.getTrigger(); if (trigger.getButton() == MouseEvent.BUTTON1 && event.getEntity() instanceof PieSectionEntity) { // && trigger.getClickCount() == 2 //doubleclick not correctly detected with the SWT composite GraphStatsView.this.mMasterComposite.getDisplay().syncExec(new Runnable() { public void run() { GraphStatsView.this.mIsDrilledDown = true; GraphStatsView.this.mCurrentDetailCategory = (String) ((PieSectionEntity) event .getEntity()).getSectionKey(); GraphStatsView.this.mStackLayout.topControl = GraphStatsView.this.mDetailViewer .getTable(); GraphStatsView.this.mMainSection.layout(); GraphStatsView.this.mDetailViewer .setInput(GraphStatsView.this.mDetailViewer.getInput()); GraphStatsView.this.updateActions(); GraphStatsView.this.updateLabel(); } }); } else { event.getTrigger().consume(); } } public void chartMouseMoved(final ChartMouseEvent event) { // NOOP } }); return embeddedComposite; }
From source file:course_generator.param.frmEditCurve.java
/** * This method is called to initialize the form. *//*from w w w .ja va 2s . c o 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.trade.ui.chart.CandlestickChart.java
/** * A demonstration application showing a candlestick chart. * /*www . java 2s . c o m*/ * @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:uk.ac.lkl.cram.ui.ModuleFrame.java
private JXTaskPane createLearningTypeChartPane() { JXTaskPane typeChartPane = new JXTaskPane(); typeChartPane.setTitle("Learning Types"); typeChartPane.setScrollOnExpand(true); final LearningTypeChartMaker maker = new LearningTypeChartMaker(module); final ChartPanel chartPanel = maker.getChartPanel(); //Add a mouse listener to the chart chartPanel.addChartMouseListener(new ChartMouseListener() { @Override//from www . j a v a 2s.c o m public void chartMouseClicked(ChartMouseEvent cme) { //Get the mouse event MouseEvent trigger = cme.getTrigger(); //Test if the mouse event is a left-button if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) { //Check that the mouse click is on a segment of the pie if (cme.getEntity() instanceof PieSectionEntity) { //Get the selected segment of the pie PieSectionEntity pieSection = (PieSectionEntity) cme.getEntity(); //Get the key that corresponds to that segment--this is a learning type String key = pieSection.getSectionKey().toString(); //Get the set of tlalineitems whose activity contains that learning type Set<TLALineItem> relevantTLAs = maker.getLearningTypeMap().get(key); //Create a pop up dialog containing that set of tlalineitems LearningTypePopupDialog popup = new LearningTypePopupDialog( (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs, key); //Set the title of the popup to indicate which learning type was selected popup.setTitle("Activities with \'" + key + "\'"); //Centre the popup at the location of the mouse click Point location = trigger.getLocationOnScreen(); int w = popup.getWidth(); int h = popup.getHeight(); popup.setLocation(location.x - w / 2, location.y - h / 2); popup.setVisible(true); int returnStatus = popup.getReturnStatus(); if (returnStatus == LearningTypePopupDialog.RET_OK) { modifyTLALineItem(popup.getSelectedTLALineItem(), 0); } } } } @Override public void chartMouseMoved(ChartMouseEvent cme) { //Set the cursor shape according to the location of the cursor if (cme.getEntity() instanceof PieSectionEntity) { chartPanel.setCursor(HAND); } else { chartPanel.setCursor(Cursor.getDefaultCursor()); } } }); chartPanel.setPreferredSize(new Dimension(150, 200)); typeChartPane.add(chartPanel); return typeChartPane; }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private JXTaskPane createLearningExperienceChartPane() { JXTaskPane experienceChartPane = new JXTaskPane(); experienceChartPane.setScrollOnExpand(true); experienceChartPane.setTitle("Learning Experiences"); final LearningExperienceChartMaker maker = new LearningExperienceChartMaker(module); final ChartPanel chartPanel = maker.getChartPanel(); //Add a mouselistener, listening for a double click on a bar of the stacked bar chartPanel.addChartMouseListener(new ChartMouseListener() { @Override/*from ww w .j a va 2s. c o m*/ public void chartMouseClicked(ChartMouseEvent cme) { //Get the mouse event MouseEvent trigger = cme.getTrigger(); //Test if the mouse event is a left-button if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) { //Get the selected segment of the pie CategoryItemEntity bar = (CategoryItemEntity) cme.getEntity(); //Get the row key that corresponds to that segment--this is a learning experience String key = bar.getRowKey().toString(); //Get the set of tlalineitems whose activity contains that learning type Set<TLALineItem> relevantTLAs = maker.getLearningExperienceMap().get(key); //Create a pop up dialog containing that set of tlalineitems LearningExperiencePopupDialog popup = new LearningExperiencePopupDialog( (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs); //Set the title of the popup to indicate which learning type was selected popup.setTitle("Activities with \'" + key + "\'"); //Centre the popup at the location of the mouse click Point location = trigger.getLocationOnScreen(); int w = popup.getWidth(); int h = popup.getHeight(); popup.setLocation(location.x - w / 2, location.y - h / 2); popup.setVisible(true); int returnStatus = popup.getReturnStatus(); if (returnStatus == LearningTypePopupDialog.RET_OK) { modifyTLALineItem(popup.getSelectedTLALineItem(), 0); } } } @Override public void chartMouseMoved(ChartMouseEvent cme) { //Set the cursor shape according to the location of the cursor if (cme.getEntity() instanceof CategoryItemEntity) { chartPanel.setCursor(HAND); } else { chartPanel.setCursor(Cursor.getDefaultCursor()); } } }); chartPanel.setPreferredSize(new Dimension(125, 75)); chartPanel.setMinimumDrawHeight(75); experienceChartPane.add(chartPanel); return experienceChartPane; }
From source file:logdruid.ui.chart.GraphPanel.java
public void load(JPanel panel_2) { startDateJSpinner = (JSpinner) panel_2.getComponent(2); endDateJSPinner = (JSpinner) panel_2.getComponent(3); // scrollPane.setV panel.removeAll();/*from w w w . j av a 2s .com*/ Dimension panelSize = this.getSize(); add(scrollPane, BorderLayout.CENTER); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // scrollPane.set trying to replace scroll where it was JCheckBox relativeCheckBox = (JCheckBox) panel_2.getComponent(5); estimatedTime = System.currentTimeMillis() - startTime; logger.info("gathering time: " + estimatedTime); startTime = System.currentTimeMillis(); // Map<Source, Map<String, MineResult>> Map<Source, Map<String, MineResult>> treeMap = new TreeMap<Source, Map<String, MineResult>>( mineResultSet.mineResults); Iterator mineResultSetIterator = treeMap.entrySet().iterator(); int ite = 0; logger.debug("mineResultSet size: " + mineResultSet.mineResults.size()); while (mineResultSetIterator.hasNext()) { final Map.Entry pairs = (Map.Entry) mineResultSetIterator.next(); logger.debug("mineResultSet key/source: " + ((Source) pairs.getKey()).getSourceName()); JCheckBox checkBox = (JCheckBox) panel_1.getComponent(ite++); logger.debug("checkbox: " + checkBox.getText() + ", " + checkBox.isSelected()); if (checkBox.isSelected()) { Map mrArrayList = (Map<String, MineResult>) pairs.getValue(); ArrayList<String> mineResultGroup = new ArrayList<String>(); Set<String> mrss = mrArrayList.keySet(); mineResultGroup.addAll(mrss); Collections.sort(mineResultGroup, new AlphanumComparator()); Iterator mrArrayListIterator = mineResultGroup.iterator(); while (mrArrayListIterator.hasNext()) { String key = (String) mrArrayListIterator.next(); logger.debug(key); final MineResult mr = (MineResult) mrArrayList.get(key); Map<String, ExtendedTimeSeries> statMap = mr.getStatTimeseriesMap(); Map<String, ExtendedTimeSeries> eventMap = mr.getEventTimeseriesMap(); // logger.info("mineResultSet hash size: " // +mr.getTimeseriesMap().size()); // logger.info("mineResultSet hash content: " + // mr.getStatTimeseriesMap()); logger.debug("mineResultSet mr.getStartDate(): " + mr.getStartDate() + " mineResultSet mr.getEndDate(): " + mr.getEndDate()); logger.debug("mineResultSet (Date)jsp.getValue(): " + (Date) startDateJSpinner.getValue()); logger.debug("mineResultSet (Date)jsp2.getValue(): " + (Date) endDateJSPinner.getValue()); if (mr.getStartDate() != null && mr.getEndDate() != null) { if ((mr.getStartDate().before((Date) endDateJSPinner.getValue())) && (mr.getEndDate().after((Date) startDateJSpinner.getValue()))) { ArrayList<String> mineResultGroup2 = new ArrayList<String>(); Set<String> mrss2 = statMap.keySet(); mineResultGroup2.addAll(mrss2); Collections.sort(mineResultGroup2, new AlphanumComparator()); Iterator statMapIterator = mineResultGroup2.iterator(); // Iterator statMapIterator = statMap.entrySet().iterator(); if (!statMap.entrySet().isEmpty() || !eventMap.entrySet().isEmpty()) { JPanel checkboxPanel = new JPanel(new WrapLayout()); checkboxPanel.setBackground(Color.white); int count = 1; chart = ChartFactory.createXYAreaChart(// Title mr.getSourceID() + " " + mr.getGroup(), // + null, // X-Axis // label null, // Y-Axis label null, // Dataset PlotOrientation.VERTICAL, false, // Show // legend true, // tooltips false // url ); TextTitle my_Chart_title = new TextTitle(mr.getSourceID() + " " + mr.getGroup(), new Font("Verdana", Font.BOLD, 17)); chart.setTitle(my_Chart_title); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis range = plot.getRangeAxis(); range.setVisible(false); final DateAxis domainAxis1 = new DateAxis(); domainAxis1.setTickLabelsVisible(true); // domainAxis1.setTickMarksVisible(true); logger.debug("getRange: " + domainAxis1.getRange()); if (relativeCheckBox.isSelected()) { domainAxis1.setRange((Date) startDateJSpinner.getValue(), (Date) endDateJSPinner.getValue()); } else { Date startDate = mr.getStartDate(); Date endDate = mr.getEndDate(); if (mr.getStartDate().before((Date) startDateJSpinner.getValue())) { startDate = (Date) startDateJSpinner.getValue(); logger.debug("setMinimumDate: " + (Date) startDateJSpinner.getValue()); } if (mr.getEndDate().after((Date) endDateJSPinner.getValue())) { endDate = (Date) endDateJSPinner.getValue(); logger.debug("setMaximumDate: " + (Date) endDateJSPinner.getValue()); } if (startDate.before(endDate)) { domainAxis1.setRange(startDate, endDate); } } XYToolTipGenerator tt1 = new XYToolTipGenerator() { public String generateToolTip(XYDataset dataset, int series, int item) { StringBuffer sb = new StringBuffer(); String htmlStr = "<html>"; Number x; FastDateFormat sdf = FastDateFormat.getInstance("dd-MMM-yyyy HH:mm:ss"); x = dataset.getX(series, item); sb.append(htmlStr); if (x != null) { sb.append("<p style='color:#000000;'>" + (sdf.format(x)) + "</p>"); sb.append("<p style='color:#000000;'>" + dataset.getSeriesKey(series).toString() + ": " + form.format(dataset.getYValue(0, item)) + "</p>"); if (mr.getFileLineForDate(new Date(x.longValue()), dataset.getSeriesKey(series).toString()) != null) { sb.append( "<p style='color:#0000FF;'>" + cd.sourceFileArrayListMap .get(pairs.getKey()).get(mr .getFileLineForDate( new Date(x.longValue()), dataset.getSeriesKey(series) .toString()) .getFileId()) .getFile().getName() + ":" + mr.getFileLineForDate(new Date(x.longValue()), dataset.getSeriesKey(series).toString()) .getLineNumber() + "</p>"); } } return sb.toString(); } }; while (statMapIterator.hasNext()) { TimeSeriesCollection dataset = new TimeSeriesCollection(); String me = (String) statMapIterator.next(); ExtendedTimeSeries ts = (ExtendedTimeSeries) statMap.get(me); // logger.info(((TimeSeries) // me.getValue()).getMaxY()); if (((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMaxY() > 0) dataset.addSeries(ts.getTimeSeries()); logger.debug("mineResultSet group: " + mr.getGroup() + ", key: " + me + " nb records: " + ((ExtendedTimeSeries) statMap.get(me)) .getTimeSeries().getItemCount()); logger.debug("(((TimeSeries) me.getValue()).getMaxY(): " + (((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMaxY())); logger.debug("(((TimeSeries) me.getValue()).getMinY(): " + (((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMinY())); XYPlot plot1 = chart.getXYPlot(); // LogarithmicAxis axis4 = new LogarithmicAxis(me.toString()); NumberAxis axis4 = new NumberAxis(me.toString()); axis4.setAutoRange(true); axis4.setAxisLineVisible(true); axis4.setAutoRangeIncludesZero(false); plot1.setDomainCrosshairVisible(true); plot1.setRangeCrosshairVisible(true); axis4.setRange(new Range( ((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMinY(), ((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMaxY())); axis4.setLabelPaint(colors[count]); axis4.setTickLabelPaint(colors[count]); plot1.setRangeAxis(count, axis4); final ValueAxis domainAxis = domainAxis1; domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot1.setDomainAxis(domainAxis); plot1.setForegroundAlpha(0.5f); plot1.setDataset(count, dataset); plot1.mapDatasetToRangeAxis(count, count); final XYAreaRenderer renderer = new XYAreaRenderer(); // XYAreaRenderer2 // also // nice if ((((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMaxY() - ((ExtendedTimeSeries) statMap.get(me)).getTimeSeries() .getMinY()) > 0) { // renderer.setToolTipGenerator(new // StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,new // FastDateFormat("d-MMM-yyyy HH:mm:ss"), // new DecimalFormat("#,##0.00"))); } renderer.setSeriesPaint(0, colors[count]); renderer.setSeriesVisible(0, true); renderer.setSeriesToolTipGenerator(0, tt1); plot1.setRenderer(count, renderer); int hits = 0; // ts.getStat()[1] int matchs = 0; if (((ExtendedTimeSeries) statMap.get(me)).getStat() != null) { hits = ((ExtendedTimeSeries) statMap.get(me)).getStat()[1]; // matchs= ((ExtendedTimeSeries) statMap.get(me)).getStat()[0]; } JCheckBox jcb = new JCheckBox(new VisibleAction(panel, checkboxPanel, axis4, me.toString() + "(" + hits + ")", 0)); Boolean selected = true; jcb.setSelected(true); jcb.setBackground(Color.white); jcb.setBorderPainted(true); jcb.setBorder(BorderFactory.createLineBorder(colors[count], 1, true)); jcb.setFont(new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize())); checkboxPanel.add(jcb); count++; } Iterator eventMapIterator = eventMap.entrySet().iterator(); while (eventMapIterator.hasNext()) { // HistogramDataset histoDataSet=new HistogramDataset(); TimeSeriesCollection dataset = new TimeSeriesCollection(); Map.Entry me = (Map.Entry) eventMapIterator.next(); // if (dataset.getEndXValue(series, item)) if (((ExtendedTimeSeries) me.getValue()).getTimeSeries().getMaxY() > 0) dataset.addSeries(((ExtendedTimeSeries) me.getValue()).getTimeSeries()); logger.debug("mineResultSet group: " + mr.getGroup() + ", key: " + me.getKey() + " nb records: " + ((ExtendedTimeSeries) me.getValue()).getTimeSeries().getItemCount()); logger.debug("mineResultSet hash content: " + mr.getEventTimeseriesMap()); logger.debug("(((TimeSeries) me.getValue()).getMaxY(): " + (((ExtendedTimeSeries) me.getValue()).getTimeSeries().getMaxY())); logger.debug("(((TimeSeries) me.getValue()).getMinY(): " + (((ExtendedTimeSeries) me.getValue()).getTimeSeries().getMinY())); XYPlot plot2 = chart.getXYPlot(); // LogarithmicAxis axis4 = new LogarithmicAxis(me.toString()); NumberAxis axis4 = new NumberAxis(me.getKey().toString()); axis4.setAutoRange(true); // axis4.setInverted(true); axis4.setAxisLineVisible(true); axis4.setAutoRangeIncludesZero(true); // axis4.setRange(new Range(((TimeSeries) // axis4.setRange(new Range(((TimeSeries) // me.getValue()).getMinY(), ((TimeSeries) // me.getValue()).getMaxY())); axis4.setLabelPaint(colors[count]); axis4.setTickLabelPaint(colors[count]); plot2.setRangeAxis(count, axis4); final ValueAxis domainAxis = domainAxis1; // domainAxis.setLowerMargin(0.001); // domainAxis.setUpperMargin(0.0); plot2.setDomainCrosshairVisible(true); plot2.setRangeCrosshairVisible(true); //plot2.setRangeCrosshairLockedOnData(true); plot2.setDomainAxis(domainAxis); plot2.setForegroundAlpha(0.5f); plot2.setDataset(count, dataset); plot2.mapDatasetToRangeAxis(count, count); XYBarRenderer rend = new XYBarRenderer(); // XYErrorRenderer rend.setShadowVisible(false); rend.setDrawBarOutline(true); Stroke stroke = new BasicStroke(5); rend.setBaseStroke(stroke); final XYItemRenderer renderer = rend; renderer.setSeriesToolTipGenerator(0, tt1); // renderer.setItemLabelsVisible(true); renderer.setSeriesPaint(0, colors[count]); renderer.setSeriesVisible(0, true); plot2.setRenderer(count, renderer); int hits = 0; int matchs = 0; if (((ExtendedTimeSeries) me.getValue()).getStat() != null) { hits = ((ExtendedTimeSeries) me.getValue()).getStat()[1]; // matchs= ((ExtendedTimeSeries) me.getValue()).getStat()[0]; } JCheckBox jcb = new JCheckBox(new VisibleAction(panel, checkboxPanel, axis4, me.getKey().toString() + "(" + hits + ")", 0)); jcb.setSelected(true); jcb.setBackground(Color.white); jcb.setBorderPainted(true); jcb.setBorder(BorderFactory.createLineBorder(colors[count], 1, true)); jcb.setFont(new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize())); checkboxPanel.add(jcb); count++; } JPanel pan = new JPanel(); pan.setLayout(new BorderLayout()); pan.setPreferredSize(new Dimension(600, Integer.parseInt((String) Preferences.getPreference("chartSize")))); // pan.setPreferredSize(panelSize); panel.add(pan); final ChartPanel cpanel = new ChartPanel(chart); cpanel.setMinimumDrawWidth(0); cpanel.setMinimumDrawHeight(0); cpanel.setMaximumDrawWidth(1920); cpanel.setMaximumDrawHeight(1200); // cpanel.setInitialDelay(0); cpanel.setDismissDelay(9999999); cpanel.setInitialDelay(50); cpanel.setReshowDelay(200); cpanel.setPreferredSize(new Dimension(600, 350)); // cpanel.restoreAutoBounds(); fix the tooltip // missing problem but then relative display is // broken panel.add(new JSeparator(SwingConstants.HORIZONTAL)); pan.add(cpanel, BorderLayout.CENTER); // checkboxPanel.setPreferredSize(new Dimension(600, // 0)); cpanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent chartmouseevent) { // chartmouseevent.getEntity(). ChartEntity entity = chartmouseevent.getEntity(); if (entity instanceof XYItemEntity) { XYItemEntity item = ((XYItemEntity) entity); if (item.getDataset() instanceof TimeSeriesCollection) { TimeSeriesCollection data = (TimeSeriesCollection) item .getDataset(); TimeSeries series = data.getSeries(item.getSeriesIndex()); TimeSeriesDataItem dataitem = series.getDataItem(item.getItem()); // logger.info(" Serie: "+series.getKey().toString() // + // " Period : "+dataitem.getPeriod().toString()); // mr.getFileForDate(new Date // (x.longValue()) ; int x = chartmouseevent.getTrigger().getX(); // logger.info(mr.getFileForDate(dataitem.getPeriod().getEnd())); int y = chartmouseevent.getTrigger().getY(); String myString = ""; if (dataitem.getPeriod() != null) { logger.info(dataitem.getPeriod().getEnd()); // myString = mr.getFileForDate(dataitem.getPeriod().getEnd()).toString(); String lineString = "" + mr.getFileLineForDate(dataitem.getPeriod().getEnd(), item.getDataset() .getSeriesKey(item.getSeriesIndex()) .toString()) .getLineNumber(); String fileString = cd.sourceFileArrayListMap .get(pairs.getKey()) .get(mr.getFileLineForDate( dataitem.getPeriod().getEnd(), item.getDataset() .getSeriesKey(item.getSeriesIndex()) .toString()) .getFileId()) .getFile().getAbsolutePath(); String command = Preferences.getPreference("editorCommand"); command = command.replace("$line", lineString); command = command.replace("$file", fileString); logger.info(command); Runtime rt = Runtime.getRuntime(); try { rt.exec(command); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } StringSelection stringSelection = new StringSelection( fileString); Clipboard clpbrd = Toolkit.getDefaultToolkit() .getSystemClipboard(); clpbrd.setContents(stringSelection, null); // cpanel.getGraphics().drawString("file name copied", x - 5, y - 5); try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch // block e.printStackTrace(); } } // logger.info(mr.getFileForDate(dataitem.getPeriod().getStart())); } } } public void chartMouseMoved(ChartMouseEvent e) { } }); pan.add(checkboxPanel, BorderLayout.SOUTH); } } } else { logger.debug("mr dates null: " + mr.getGroup() + mr.getSourceID() + mr.getLogFiles()); } } } } // Map=miner.mine(sourceFiles,repo); estimatedTime = System.currentTimeMillis() - startTime; revalidate(); logger.info("display time: " + estimatedTime); }
From source file:de.bfs.radon.omsimulation.gui.OMPanelResults.java
/** * Creates a panel displaying the distribution chart of certain selected * statistical values./* ww w.j a va 2s .com*/ * * @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; }
From source file:edu.ucla.stat.SOCR.applications.demo.PortfolioApplication2.java
public void chartMouseClicked(ChartMouseEvent arg0) { //System.out.println(arg0.getEntity().getShapeCoords()); if (arg0.getEntity() == null) return;/*from w w w.ja v a2 s .c o m*/ tooltip = arg0.getEntity().getToolTipText(); mouse_x = Double.parseDouble(tooltip.substring(tooltip.indexOf("(") + 1, tooltip.indexOf(","))); mouse_y = Double.parseDouble(tooltip.substring(tooltip.indexOf(",") + 1, tooltip.indexOf(")"))); tooltip = "(" + mouse_x + "," + mouse_y + ")\n"; for (int i = 0; i < chartDataPoints.pointCount; i++) { double x = Double.parseDouble(tooltip_formatter.format(chartDataPoints.getX(i))); double y = Double.parseDouble(tooltip_formatter.format(chartDataPoints.getY(i))); //System.out.println(i+":"+x+","+y); if (x == mouse_x && y == mouse_y) { int sdpId = chartDataPoints.getSDPpointer(i); tooltip += "==> Stocks("; double[][] sdp = new double[1][numStocks]; sdp = simulatedPoints.getRow(sdpId); for (int j = 0; j < numStocks - 1; j++) tooltip += tooltip_formatter.format(sdp[0][j]) + ", "; tooltip += tooltip_formatter.format(sdp[0][numStocks - 1]) + ")\n"; } } mouseClicked = true; updateGraph(); // setChart(); //System.out.println("------"); }
From source file:ec.util.chart.swing.JTimeSeriesChart.java
private void enableObsTriggering() { chartPanel.addChartMouseListener(new ChartMouseListener() { @Override// w w w .j av a 2s.co 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:org.talend.dataprofiler.chart.TOPChartService.java
@Override public void addMouseListenerForChart(Object chartComposite, final Map<String, Object> menuMap, final boolean useRowFirst) { final ChartComposite chartComp = (ChartComposite) chartComposite; final ChartMouseListener listener = new ChartMouseListener() { @Override/* ww w. j a v a2 s . com*/ public void chartMouseClicked(ChartMouseEvent event) { boolean flag = event.getTrigger().getButton() != MouseEvent.BUTTON3; chartComp.setDomainZoomable(flag); chartComp.setRangeZoomable(flag); if (flag) { return; } ChartEntity chartEntity = event.getEntity(); if (chartEntity != null && chartEntity instanceof CategoryItemEntity) { CategoryItemEntity cateEntity = (CategoryItemEntity) chartEntity; Menu menu = getCurrentMenu(cateEntity); if (menu != null) { chartComp.setMenu(menu); menu.setVisible(true); } } } private Menu getCurrentMenu(CategoryItemEntity cateEntity) { if (useRowFirst) { return findCurrentMenu(cateEntity.getRowKey(), cateEntity.getColumnKey()); } else { return findCurrentMenu(cateEntity.getColumnKey(), cateEntity.getRowKey()); } } /** * DOC yyin Comment method "findCurrentMenu". * * @param firstKey * @param secondKey * @return */ private Menu findCurrentMenu(final Object firstKey, Object secondKey) { Object menu = menuMap.get(firstKey); if (menu != null) { return (Menu) menu; } menu = menuMap.get(secondKey); if (menu != null) { return (Menu) menu; } 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(); } }); }