📄 chartcomposite.java
字号:
if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Rectangle insets = getClientArea(); ChartEntity entity = entities.getEntity( (int) ((e.x - insets.x) / this.scaleX), (int) ((e.y - insets.y) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; } /** * The idea is to modify the zooming options depending on the type of chart * being displayed by the panel. * * @param x horizontal position of the popup. * @param y vertical position of the popup. */ protected void displayPopupMenu(int x, int y) { if (this.popup != null) { // go through each zoom menu item and decide whether or not to // enable it... Plot plot = this.chart.getPlot(); boolean isDomainZoomable = false; boolean isRangeZoomable = false; if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; isDomainZoomable = z.isDomainZoomable(); isRangeZoomable = z.isRangeZoomable(); } if (this.zoomInDomainMenuItem != null) { this.zoomInDomainMenuItem.setEnabled(isDomainZoomable); } if (this.zoomOutDomainMenuItem != null) { this.zoomOutDomainMenuItem.setEnabled(isDomainZoomable); } if (this.zoomResetDomainMenuItem != null) { this.zoomResetDomainMenuItem.setEnabled(isDomainZoomable); } if (this.zoomInRangeMenuItem != null) { this.zoomInRangeMenuItem.setEnabled(isRangeZoomable); } if (this.zoomOutRangeMenuItem != null) { this.zoomOutRangeMenuItem.setEnabled(isRangeZoomable); } if (this.zoomResetRangeMenuItem != null) { this.zoomResetRangeMenuItem.setEnabled(isRangeZoomable); } if (this.zoomInBothMenuItem != null) { this.zoomInBothMenuItem.setEnabled( isDomainZoomable & isRangeZoomable ); } if (this.zoomOutBothMenuItem != null) { this.zoomOutBothMenuItem.setEnabled( isDomainZoomable & isRangeZoomable ); } if (this.zoomResetBothMenuItem != null) { this.zoomResetBothMenuItem.setEnabled( isDomainZoomable & isRangeZoomable ); } this.popup.setLocation(x, y); this.popup.setVisible(true); } } /** * Creates a print job for the chart. */ public void createChartPrintJob() { //FIXME try to replace swing print stuff by swt PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); if (job.printDialog()) { try { job.print(); } catch (PrinterException e) { MessageBox messageBox = new MessageBox( canvas.getShell(), SWT.OK | SWT.ICON_ERROR ); messageBox.setMessage( e.getMessage() ); messageBox.open(); } } } } /** * Creates a popup menu for the canvas. * * @param properties include a menu item for the chart property editor. * @param save include a menu item for saving the chart. * @param print include a menu item for printing the chart. * @param zoom include menu items for zooming. * * @return The popup menu. */ protected Menu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) { Menu result = new Menu(this); boolean separator = false; if ( properties ) { MenuItem propertiesItem = new MenuItem(result, SWT.PUSH); propertiesItem.setText(localizationResources.getString( "Properties...")); propertiesItem.setData(PROPERTIES_COMMAND); propertiesItem.addSelectionListener(this); separator = true; } if (save) { if (separator) { new MenuItem(result, SWT.SEPARATOR); separator = false; } MenuItem saveItem = new MenuItem(result, SWT.NONE); saveItem.setText(localizationResources.getString("Save_as...")); saveItem.setData(SAVE_COMMAND); saveItem.addSelectionListener(this); separator = true; } if (print) { if (separator) { new MenuItem(result, SWT.SEPARATOR); separator = false; } MenuItem printItem = new MenuItem(result, SWT.NONE); printItem.setText(localizationResources.getString("Print...")); printItem.setData(PRINT_COMMAND); printItem.addSelectionListener(this); separator = true; } if (zoom) { if (separator) { new MenuItem(result, SWT.SEPARATOR); separator = false; } Menu zoomInMenu = new Menu(result); MenuItem zoomInMenuItem = new MenuItem(result, SWT.CASCADE); zoomInMenuItem.setText(localizationResources.getString("Zoom_In")); zoomInMenuItem.setMenu(zoomInMenu); this.zoomInBothMenuItem = new MenuItem(zoomInMenu, SWT.PUSH); this.zoomInBothMenuItem.setText(localizationResources.getString( "All_Axes")); this.zoomInBothMenuItem.setData(ZOOM_IN_BOTH_COMMAND); this.zoomInBothMenuItem.addSelectionListener(this); new MenuItem(zoomInMenu, SWT.SEPARATOR); this.zoomInDomainMenuItem = new MenuItem(zoomInMenu, SWT.PUSH); this.zoomInDomainMenuItem.setText(localizationResources.getString( "Domain_Axis" ) ); this.zoomInDomainMenuItem.setData(ZOOM_IN_DOMAIN_COMMAND); this.zoomInDomainMenuItem.addSelectionListener(this); this.zoomInRangeMenuItem = new MenuItem(zoomInMenu, SWT.PUSH); this.zoomInRangeMenuItem.setText(localizationResources.getString( "Range_Axis" ) ); this.zoomInRangeMenuItem.setData(ZOOM_IN_RANGE_COMMAND); this.zoomInRangeMenuItem.addSelectionListener(this); Menu zoomOutMenu = new Menu( result ); MenuItem zoomOutMenuItem = new MenuItem(result, SWT.CASCADE); zoomOutMenuItem.setText(localizationResources.getString( "Zoom_Out")); zoomOutMenuItem.setMenu(zoomOutMenu); this.zoomOutBothMenuItem = new MenuItem(zoomOutMenu, SWT.PUSH); this.zoomOutBothMenuItem.setText(localizationResources.getString( "All_Axes")); this.zoomOutBothMenuItem.setData(ZOOM_OUT_BOTH_COMMAND); this.zoomOutBothMenuItem.addSelectionListener(this); new MenuItem(zoomOutMenu, SWT.SEPARATOR); this.zoomOutDomainMenuItem = new MenuItem(zoomOutMenu, SWT.PUSH); this.zoomOutDomainMenuItem.setText(localizationResources.getString( "Domain_Axis")); this.zoomOutDomainMenuItem.setData(ZOOM_OUT_DOMAIN_COMMAND); this.zoomOutDomainMenuItem.addSelectionListener( this ); this.zoomOutRangeMenuItem = new MenuItem(zoomOutMenu, SWT.PUSH); this.zoomOutRangeMenuItem.setText( localizationResources.getString("Range_Axis")); this.zoomOutRangeMenuItem.setData(ZOOM_OUT_RANGE_COMMAND); this.zoomOutRangeMenuItem.addSelectionListener(this); Menu autoRangeMenu = new Menu(result); MenuItem autoRangeMenuItem = new MenuItem(result, SWT.CASCADE); autoRangeMenuItem.setText(localizationResources.getString( "Auto_Range")); autoRangeMenuItem.setMenu(autoRangeMenu); this.zoomResetBothMenuItem = new MenuItem(autoRangeMenu, SWT.PUSH); this.zoomResetBothMenuItem.setText(localizationResources.getString( "All_Axes")); this.zoomResetBothMenuItem.setData(ZOOM_RESET_BOTH_COMMAND); this.zoomResetBothMenuItem.addSelectionListener(this); new MenuItem(autoRangeMenu, SWT.SEPARATOR); this.zoomResetDomainMenuItem = new MenuItem(autoRangeMenu, SWT.PUSH); this.zoomResetDomainMenuItem.setText( localizationResources.getString("Domain_Axis")); this.zoomResetDomainMenuItem.setData(ZOOM_RESET_DOMAIN_COMMAND); this.zoomResetDomainMenuItem.addSelectionListener(this); this.zoomResetRangeMenuItem = new MenuItem(autoRangeMenu, SWT.PUSH); this.zoomResetRangeMenuItem.setText( localizationResources.getString("Range_Axis")); this.zoomResetRangeMenuItem.setData(ZOOM_RESET_RANGE_COMMAND); this.zoomResetRangeMenuItem.addSelectionListener(this); } return result; } /** * Handles action events generated by the popup menu. * * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected( * org.eclipse.swt.events.SelectionEvent) */ public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } /** * Handles action events generated by the popup menu. * * @see org.eclipse.swt.events.SelectionListener#widgetSelected( * org.eclipse.swt.events.SelectionEvent) */ public void widgetSelected(SelectionEvent e) { String command = (String) ((MenuItem) e.getSource()).getData(); if (command.equals(PROPERTIES_COMMAND)) { attemptEditChartProperties(); } else if (command.equals(SAVE_COMMAND)) { try { doSaveAs(); } catch (IOException ex) { ex.printStackTrace(); } } else if (command.equals(PRINT_COMMAND)) { createChartPrintJob(); } /* in the next zoomPoint.x and y replace by e.x and y for now. * this helps to handle the mouse events and besides, * those values are unused AFAIK. */ else if (command.equals(ZOOM_IN_BOTH_COMMAND)) { zoomInBoth( e.x, e.y ); } else if (command.equals(ZOOM_IN_DOMAIN_COMMAND)) { zoomInDomain( e.x, e.y ); } else if (command.equals(ZOOM_IN_RANGE_COMMAND)) { zoomInRange( e.x, e.y ); } else if (command.equals(ZOOM_OUT_BOTH_COMMAND)) { zoomOutBoth( e.x, e.y ); } else if (command.equals(ZOOM_OUT_DOMAIN_COMMAND)) { zoomOutDomain( e.x, e.y ); } else if (command.equals(ZOOM_OUT_RANGE_COMMAND)) { zoomOutRange( e.x, e.y ); } else if (command.equals(ZOOM_RESET_BOTH_COMMAND)) { restoreAutoBounds(); } else if (command.equals(ZOOM_RESET_DOMAIN_COMMAND)) { restoreAutoDomainBounds(); } else if (command.equals(ZOOM_RESET_RANGE_COMMAND)) { restoreAutoRangeBounds(); } this.forceRedraw(); } public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex != 0) { return NO_SUCH_PAGE; } /* CairoImage image = new CairoImage( this.getBounds().width, this.getBounds().height ); Graphics2D g2 = image.createGraphics2D(); double x = pageFormat.getImageableX(); double y = pageFormat.getImageableY(); double w = pageFormat.getImageableWidth(); double h = pageFormat.getImageableHeight(); this.chart.draw( g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null ); */ return PAGE_EXISTS; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -