public void setComposite(PortfolioComposite composite) { this.portfolioComposite = composite; mainChartPanel.getPopupMenu().addSeparator(); JMenuItem manQuote = new JMenuItem("Add a quotation"); manQuote.addActionListener(portfolioComposite.new ManualQuotationSelectionListener()); mainChartPanel.getPopupMenu().add(manQuote); }
private ChartPanel createChartPanel(JFreeChart chart) { XYPlot plot = chart.getXYPlot(); plot.setForegroundAlpha(0.85f); plot.setNoDataMessage(NO_DATA_MESSAGE); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); ChartPanel chartPanel = new ChartPanel(chart); MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport( this, chartPanel, "histogram_plot_area", "Mask generated from selected histogram plot area", Color.RED, PlotAreaSelectionTool.AreaType.X_RANGE) { @Override protected String createMaskExpression( PlotAreaSelectionTool.AreaType areaType, Shape shape) { Rectangle2D bounds = shape.getBounds2D(); return createMaskExpression(bounds.getMinX(), bounds.getMaxX()); } protected String createMaskExpression(double x1, double x2) { String bandName = BandArithmetic.createExternalName(getRaster().getName()); HistogramPanelModel.HistogramConfig currentConfig = createHistogramConfig(); return String.format( "%s >= %s && %s <= %s", bandName, model.hasStx(currentConfig) ? model.getStx(currentConfig).getHistogramScaling().scaleInverse(x1) : x1, bandName, model.hasStx(currentConfig) ? model.getStx(currentConfig).getHistogramScaling().scaleInverse(x2) : x2); } }; chartPanel.getPopupMenu().addSeparator(); chartPanel.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem()); chartPanel.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem()); chartPanel.getPopupMenu().addSeparator(); chartPanel.getPopupMenu().add(createCopyDataToClipboardMenuItem()); return chartPanel; }
private ChartPanel createChartPanel(final JFreeChart chart) { scatterPlotDisplay = new ChartPanel(chart) { @Override public void restoreAutoBounds() { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... final XYPlot plot = chart.getXYPlot(); boolean savedNotify = plot.isNotify(); plot.setNotify(false); xAxisRangeControl.adjustAxis(plot.getDomainAxis(), 3); yAxisRangeControl.adjustAxis(plot.getRangeAxis(), 3); plot.setNotify(savedNotify); } }; MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport( this, scatterPlotDisplay, "correlative_plot_area", "Mask generated from selected correlative plot area", Color.RED, PlotAreaSelectionTool.AreaType.Y_RANGE) { @Override protected String createMaskExpression( PlotAreaSelectionTool.AreaType areaType, Shape shape) { Rectangle2D bounds = shape.getBounds2D(); return createMaskExpression(bounds.getMinY(), bounds.getMaxY()); } protected String createMaskExpression(double x1, double x2) { String bandName = BandArithmetic.createExternalName(getRaster().getName()); return String.format("%s >= %s && %s <= %s", bandName, x1, bandName, x2); } }; scatterPlotDisplay.getPopupMenu().addSeparator(); scatterPlotDisplay .getPopupMenu() .add(maskSelectionToolSupport.createMaskSelectionModeMenuItem()); scatterPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem()); scatterPlotDisplay.getPopupMenu().addSeparator(); scatterPlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem()); return scatterPlotDisplay; }
private void initGUI() { try { this.setOrientation(SWT.VERTICAL); this.setBackground(MainGui.cHART_DARKER); Color innerBgColor = MainGui.cHART_LIGHT; this.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent evt) { rootShellClosed(evt); } }); this.addListener( SWT.Hide, new Listener() { @Override public void handleEvent(Event event) { ChartsComposite.this.shutDownDisplay(); } }); { try { // Set cross-platform Java L&F (also called "Metal") UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (UnsupportedLookAndFeelException e) { LOGGER.error(e); } catch (ClassNotFoundException e) { LOGGER.error(e); } catch (InstantiationException e) { LOGGER.error(e); } catch (IllegalAccessException e) { LOGGER.error(e); } mainChartComposite = new Composite(this, SWT.EMBEDDED | SWT.NO_BACKGROUND); final Frame chartFrame = SWT_AWT.new_Frame(mainChartComposite); final Panel rootHeavyPanel = new Panel(); rootHeavyPanel.setLayout(new BorderLayout()); chartFrame.add(rootHeavyPanel); mainChartWraper = new ChartMain(ChartsComposite.DEFAULT_START_DATE, JFreeChartTimePeriod.DAY); mainChartPanel = new ChartPanel( mainChartWraper.initChart(stripedCloseFunction), true, true, true, false, true) { private static final long serialVersionUID = 1L; @Override public void restoreAutoBounds() { // Do nothing (disable mouse left drag zoom) } }; mainChartPanel.setMouseZoomable(false, false); mainChartPanel.setMinimumDrawWidth(0); mainChartPanel.setMinimumDrawHeight(0); mainChartPanel.setMaximumDrawWidth(Display.getCurrent().getClientArea().width); mainChartPanel.setMaximumDrawHeight(Display.getCurrent().getClientArea().height); mainChartPanel.getPopupMenu().addSeparator(); JMenuItem deleteVLines = new JMenuItem("Remove vertical lines"); deleteVLines.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { chartDisplayStrategy.removeVLines(); } }); mainChartPanel.getPopupMenu().add(deleteVLines); JMenuItem deleteHLines = new JMenuItem("Remove horizontal lines"); deleteHLines.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { chartDisplayStrategy.removeHLines(); } }); mainChartPanel.getPopupMenu().add(deleteHLines); mainChartPanel.getPopupMenu().addSeparator(); JMenuItem lookAndFeelInfoItem = new JMenuItem("Look and feel Info"); lookAndFeelInfoItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LOGGER.info(UIManager.getLookAndFeel()); } }); mainChartPanel.getPopupMenu().add(lookAndFeelInfoItem); mainChartPanel.addMouseListener( new ClickListener() { @Override public void singleClick(final MouseEvent event) { Display.getDefault() .asyncExec( new Runnable() { @Override public void run() { Boolean isSlidingArea = getMainChartWraper() .isSlidingArea( mainChartComposite.getSize().y, event.getPoint().y); if (isSlidingArea) return; int button = event.getButton(); if (button == MouseEvent.BUTTON1) { Point2D clickPoint = mainChartPanel.translateScreenToJava2D(event.getPoint()); Rectangle2D plotArea = mainChartPanel.getScreenDataArea(); if (plotArea.getMaxY() > clickPoint.getY() && clickPoint.getY() > plotArea.getY() && plotArea.getMaxX() > clickPoint.getX() && clickPoint.getX() > plotArea.getX()) { chartDisplayStrategy.addVLineAt(clickPoint, plotArea); } } } }); } @Override public void doubleClick(final MouseEvent event) { Display.getDefault() .asyncExec( new Runnable() { @Override public void run() { Boolean isSlidingArea = getMainChartWraper() .isSlidingArea( mainChartComposite.getSize().y, event.getPoint().y); if (isSlidingArea) return; int button = event.getButton(); if (button == MouseEvent.BUTTON1) { Point2D clickPoint = getPointCoordinates(event.getPoint()); Rectangle2D plotArea = mainChartPanel.getScreenDataArea(); if (plotArea.getMaxY() > clickPoint.getY() && clickPoint.getY() > plotArea.getY() && plotArea.getMaxX() > clickPoint.getX() && clickPoint.getX() > plotArea.getX()) { chartDisplayStrategy.removeVLineAt(clickPoint, plotArea); chartDisplayStrategy.removeHLineAt(clickPoint, plotArea); } } } }); } }); // Slider chartPanelFocusGain = false; mainChartPanel.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { chartPanelFocusGain = true; } @Override public void mouseExited(MouseEvent e) { chartPanelFocusGain = false; } @Override public void mousePressed(final MouseEvent e) { panelClickPosition = e.getPoint(); Display.getDefault() .asyncExec( new Runnable() { @Override public void run() { Boolean isSlidingArea = getMainChartWraper() .isSlidingArea(mainChartComposite.getSize().y, e.getPoint().y); if (isSlidingArea) { isInPanelChartSlider = true; } else { isInPanelChartSlider = false; } } }); } @Override public void mouseReleased(final MouseEvent e) { Display.getDefault() .asyncExec( new Runnable() { @Override public void run() { if (isInPanelChartSlider != null && isInPanelChartSlider && panelClickPosition != null) { int indicChartSlideIncrement = (int) ((((double) panelClickPosition.y - e.getPoint().y) / (double) mainChartComposite.getSize().y) * 100); chartDisplayStrategy.slideChart(indicChartSlideIncrement); } isInPanelChartSlider = false; } }); } }); // focus bizz (useful?) mainChartPanel.addMouseMotionListener( new MouseMotionListener() { @Override public void mouseMoved(final MouseEvent e) { // Sliding if (!closeRequested) { Display.getDefault() .asyncExec( new Runnable() { @Override public void run() { if (!closeRequested) { try { Cursor cursor = ChartsComposite.this.getCursor(); if (cursor == null || (!cursor.equals(CursorFactory.getCursor(SWT.CURSOR_WAIT)) && !cursor.equals( CursorFactory.getCursor(SWT.CURSOR_APPSTARTING)))) { Boolean isSlidingArea = getMainChartWraper() .isSlidingArea( mainChartComposite.getSize().y, e.getPoint().y); if (isSlidingArea) { ChartsComposite.this.setCursor( CursorFactory.getCursor(SWT.CURSOR_SIZENS)); } else { ChartsComposite.this.setCursor( CursorFactory.getCursor(SWT.CURSOR_ARROW)); } } } catch (Throwable e) { try { ChartsComposite.this.setCursor( CursorFactory.getCursor(SWT.CURSOR_ARROW)); } catch (Throwable e1) { LOGGER.warn(e1, e1); } LOGGER.warn(e, e); } } } }); } // Gain focus mgt if (!closeRequested) { Display.getDefault() .asyncExec( new Runnable() { public void run() { try { if (!closeRequested) { if (!mainChartComposite.isDisposed() && !mainChartComposite.isFocusControl()) { int cpt = 0; while (chartPanelFocusGain && cpt < 200) { Thread.sleep(10); cpt++; } if (chartPanelFocusGain && !mainChartComposite.isDisposed()) { mainChartComposite.forceFocus(); } } } } catch (Throwable e) { LOGGER.warn(e, e); } } }); } } @Override public void mouseDragged(MouseEvent e) { // Nothing } }); mainChartComposite.addKeyListener( new org.eclipse.swt.events.KeyListener() { @Override public void keyReleased(org.eclipse.swt.events.KeyEvent e) { if (((e.stateMask & SWT.CTRL) == SWT.CTRL) && ((e.stateMask & SWT.ALT) == SWT.ALT) && (e.keyCode == 'p')) { try { chartDisplayStrategy.exportBarChartPng(); } catch (InvalidParameterException exception) { chartDisplayStrategy.showPopupDialog(exception.getMessage(), "Ok", null, null); } } if (e.keyCode == SWT.ARROW_UP) { chartDisplayStrategy.slideChart(+1); } if (e.keyCode == SWT.ARROW_DOWN) { chartDisplayStrategy.slideChart(-1); } } @Override public void keyPressed(org.eclipse.swt.events.KeyEvent e) { // } }); mainChartComposite.addMouseTrackListener( new MouseTrackListener() { @Override public void mouseHover(org.eclipse.swt.events.MouseEvent e) {} @Override public void mouseExit(org.eclipse.swt.events.MouseEvent e) {} @Override public void mouseEnter(org.eclipse.swt.events.MouseEvent e) { mainChartPanel.requestFocusInWindow(); } }); rootHeavyPanel.add(mainChartPanel); chartFrame.pack(); chartFrame.setVisible(true); } { chartBoutonsGroup = new Group(this, SWT.NONE); chartBoutonsGroup.setBackground(innerBgColor); GridLayout portfolioBoutonsGroupLayout = new GridLayout(); portfolioBoutonsGroupLayout.numColumns = 1; portfolioBoutonsGroupLayout.verticalSpacing = 0; portfolioBoutonsGroupLayout.marginHeight = 0; chartBoutonsGroup.setLayout(portfolioBoutonsGroupLayout); GridData portfolioInfosGroupData = new GridData(GridData.FILL_HORIZONTAL); chartBoutonsGroup.setLayoutData(portfolioInfosGroupData); chartBoutonsGroup.setText("Portfolios charting : "); chartBoutonsGroup.setFont(MainGui.DEFAULTFONT); chartBoutonsGroup.setBackground(innerBgColor); { popusGroup = new Group(chartBoutonsGroup, SWT.NONE); GridData popusGroupData = new GridData(SWT.FILL, SWT.FILL, true, false); popusGroup.setLayoutData(popusGroupData); popusGroup.setBackground(innerBgColor); RowLayout popusGroupL = new RowLayout(SWT.HORIZONTAL); popusGroupL.justify = true; popusGroupL.fill = true; popusGroupL.wrap = false; popusGroupL.marginHeight = 0; popusGroup.setLayout(popusGroupL); } // Sliding { slidingGroup = new Group(chartBoutonsGroup, SWT.NONE); GridData slidingGroupData = new GridData(SWT.FILL, SWT.FILL, true, false); slidingGroup.setLayoutData(slidingGroupData); slidingGroup.setBackground(innerBgColor); GridLayout slidingGroupL = new GridLayout(); slidingGroupL.numColumns = 5; slidingGroupL.marginHeight = 0; slidingGroupL.verticalSpacing = 0; slidingGroup.setLayout(slidingGroupL); /// start { startDateLabel = new Label(slidingGroup, SWT.NONE); GridData startOneYearBackData = new GridData(SWT.BEGINNING, SWT.FILL, false, false); startOneYearBackData.horizontalSpan = 2; startDateLabel.setLayoutData(startOneYearBackData); startDateLabel.setText( DateFormat.getDateInstance(DateFormat.MEDIUM).format(slidingStartDate) + ""); startDateLabel.setBackground(innerBgColor); startDateLabel.setFont(MainGui.DEFAULTFONT); } /// sliding sliders Composite slidingSliderGroup = new Composite(slidingGroup, SWT.NONE); slidingSliderGroup.setSize(1000, SWT.DEFAULT); GridData slidersGridData = new GridData(SWT.FILL, SWT.FILL, true, true); slidersGridData.verticalSpan = 2; slidingSliderGroup.setLayoutData(slidersGridData); slidingSliderGroup.setBackground(innerBgColor); slidingSliderGroup.setForeground(innerBgColor); FillLayout slidingSliderGroupL = new FillLayout(SWT.VERTICAL); slidingSliderGroup.setLayout(slidingSliderGroupL); { sliderStartDate = new Slider(slidingSliderGroup, SWT.HORIZONTAL); sliderStartDate.setThumb(1); sliderStartDate.setMaximum(100); sliderStartDate.addListener( SWT.MouseExit, new Listener() { public void handleEvent(Event arg0) { sliderChangesApply(); } }); } { sliderEndDate = new Slider(slidingSliderGroup, SWT.HORIZONTAL); sliderEndDate.setThumb(1); sliderEndDate.setMinimum(0); sliderEndDate.setSelection(100); sliderEndDate.addListener( SWT.MouseExit, new Listener() { public void handleEvent(Event arg0) { sliderChangesApply(); } }); } // end { endDateLabel = new Label(slidingGroup, SWT.NONE); GridData endOneYearBackData = new GridData(SWT.END, SWT.FILL, false, false); endOneYearBackData.horizontalSpan = 2; endDateLabel.setLayoutData(endOneYearBackData); endDateLabel.setText( DateFormat.getDateInstance(DateFormat.MEDIUM).format(slidingEndDate)); endDateLabel.setBackground(innerBgColor); endDateLabel.setFont(MainGui.DEFAULTFONT); } // but start { Button startOneYearBack = new Button(slidingGroup, SWT.ARROW | SWT.LEFT); GridData startOneYearBackData = new GridData(SWT.END, SWT.FILL, false, true); startOneYearBack.setLayoutData(startOneYearBackData); startOneYearBack.setToolTipText("Move start date one year backward."); startOneYearBack.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { handle(); } private void handle() { Calendar calendar = Calendar.getInstance(); calendar.setTime(slidingStartDate); calendar.add(Calendar.YEAR, -1); firstStartDate = calendar.getTime(); sliderStartDate.setSelection(0); startSliderUpdateConditional( sliderStartDate, startDateLabel, sliderEndDate, endDateLabel); } @Override public void widgetDefaultSelected(SelectionEvent e) { handle(); } }); startOneYearBack.addListener( SWT.MouseExit, new Listener() { @Override public void handleEvent(Event event) { sliderChangesApply(); } }); } { Button startOneYearForward = new Button(slidingGroup, SWT.ARROW | SWT.RIGHT); GridData startOneYearBackData = new GridData(SWT.BEGINNING, SWT.FILL, false, true); startOneYearForward.setLayoutData(startOneYearBackData); startOneYearForward.setToolTipText("Move start date one year forward."); startOneYearForward.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { handle(); } private void handle() { Calendar calendar = Calendar.getInstance(); calendar.setTime(slidingStartDate); calendar.add(Calendar.YEAR, +1); if (calendar.getTime().before(slidingEndDate)) { firstStartDate = calendar.getTime(); sliderStartDate.setSelection(0); startSliderUpdateConditional( sliderStartDate, startDateLabel, sliderEndDate, endDateLabel); } else { chartDisplayStrategy.showPopupDialog( "To move the start date further forward, you will need to move the end date first.", "Ok", null, null); } } @Override public void widgetDefaultSelected(SelectionEvent e) { handle(); } }); startOneYearForward.addListener( SWT.MouseExit, new Listener() { @Override public void handleEvent(Event event) { sliderChangesApply(); } }); } /// but end { Button endOneYearBack = new Button(slidingGroup, SWT.ARROW | SWT.LEFT); GridData endOneYearBackData = new GridData(SWT.END, SWT.FILL, false, true); endOneYearBack.setLayoutData(endOneYearBackData); endOneYearBack.setToolTipText("Move end date one year backward."); endOneYearBack.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { handle(); } private void handle() { Calendar calendar = Calendar.getInstance(); calendar.setTime(slidingEndDate); calendar.add(Calendar.YEAR, -1); if (calendar.getTime().after(slidingStartDate)) { lastEndDate = calendar.getTime(); sliderEndDate.setSelection(100); endSliderUpdateConditional( sliderEndDate, endDateLabel, sliderStartDate, startDateLabel); } else { chartDisplayStrategy.showPopupDialog( "To move the end date further backward, you will need to move the start date first.", "Ok", null, null); } } @Override public void widgetDefaultSelected(SelectionEvent e) { handle(); } }); endOneYearBack.addListener( SWT.MouseExit, new Listener() { @Override public void handleEvent(Event event) { sliderChangesApply(); } }); } { Button endOneYearForward = new Button(slidingGroup, SWT.ARROW | SWT.RIGHT); GridData endOneYearBackData = new GridData(SWT.BEGINNING, SWT.FILL, false, true); endOneYearForward.setLayoutData(endOneYearBackData); endOneYearForward.setToolTipText("Move end date one year forward."); endOneYearForward.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { handle(); } private void handle() { Calendar calendar = Calendar.getInstance(); calendar.setTime(slidingEndDate); calendar.add(Calendar.YEAR, +1); Date newDate = EventSignalConfig.getNewDate(); if (calendar.getTime().after(newDate)) { calendar.setTime(newDate); } lastEndDate = calendar.getTime(); sliderEndDate.setSelection(100); endSliderUpdateConditional( sliderEndDate, endDateLabel, sliderStartDate, startDateLabel); } @Override public void widgetDefaultSelected(SelectionEvent e) { handle(); } }); endOneYearForward.addListener( SWT.MouseExit, new Listener() { @Override public void handleEvent(Event event) { sliderChangesApply(); } }); } sliderStartDate.addListener( SWT.Selection, new Listener() { public void handleEvent(Event event) { startSliderUpdateConditional( sliderStartDate, startDateLabel, sliderEndDate, endDateLabel); } }); sliderEndDate.addListener( SWT.Selection, new Listener() { public void handleEvent(Event event) { endSliderUpdateConditional( sliderEndDate, endDateLabel, sliderStartDate, startDateLabel); } }); slidingGroup.layout(); } } this.layout(); this.pack(); } catch (Exception e) { LOGGER.error("", e); } }
private ChartPanel createChartPanel(JFreeChart chart) { profilePlotDisplay = new ChartPanel(chart); MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport( this, profilePlotDisplay, "profile_plot_area", "Mask generated from selected profile plot area", Color.RED, PlotAreaSelectionTool.AreaType.Y_RANGE) { @Override protected String createMaskExpression( PlotAreaSelectionTool.AreaType areaType, Shape shape) { Rectangle2D bounds = shape.getBounds2D(); return createMaskExpression(bounds.getMinY(), bounds.getMaxY()); } protected String createMaskExpression(double x1, double x2) { String bandName = BandArithmetic.createExternalName(getRaster().getName()); return String.format("%s >= %s && %s <= %s", bandName, x1, bandName, x2); } }; profilePlotDisplay.addChartMouseListener( new XYPlotMarker( profilePlotDisplay, new XYPlotMarker.Listener() { @Override public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) { if (profileData != null) { GeoPos[] geoPositions = profileData.getGeoPositions(); int index = (int) dataPoint.getX(); if (index >= 0 && index < geoPositions.length) { if (cursorSynchronizer == null) { cursorSynchronizer = new CursorSynchronizer(VisatApp.getApp()); } if (!cursorSynchronizer.isEnabled()) { cursorSynchronizer.setEnabled(true); } cursorSynchronizer.updateCursorOverlays(geoPositions[index]); } } } @Override public void pointDeselected() { cursorSynchronizer.setEnabled(false); } })); profilePlotDisplay.setInitialDelay(200); profilePlotDisplay.setDismissDelay(1500); profilePlotDisplay.setReshowDelay(200); profilePlotDisplay.setZoomTriggerDistance(5); profilePlotDisplay.getPopupMenu().addSeparator(); profilePlotDisplay .getPopupMenu() .add(maskSelectionToolSupport.createMaskSelectionModeMenuItem()); profilePlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem()); profilePlotDisplay.getPopupMenu().addSeparator(); profilePlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem()); return profilePlotDisplay; }