📄 plotbox.java
字号:
int miny = Math.min(_zoomy, _zoomyn); int maxy = Math.max(_zoomy, _zoomyn); _graphics.drawRect(minx, miny, maxx - minx, maxy - miny); } // Draw a new box if necessary. if (y > _zoomy) { _zoomxn = x; _zoomyn = y; int minx = Math.min(_zoomx, _zoomxn); int maxx = Math.max(_zoomx, _zoomxn); int miny = Math.min(_zoomy, _zoomyn); int maxy = Math.max(_zoomy, _zoomyn); _graphics.drawRect(minx, miny, maxx - minx, maxy - miny); _graphics.setPaintMode(); _drawn = true; return true; } else _drawn = false; } else if (_zoomout == true){ _graphics.setXORMode(_background); // Erase previous box if necessary. if ((_zoomxn != -1 || _zoomyn != -1) && (_drawn == true)) { int x_diff = Math.abs(_zoomx-_zoomxn); int y_diff = Math.abs(_zoomy-_zoomyn); _graphics.drawRect(_zoomx-15-x_diff, _zoomy-15-y_diff, 30+x_diff*2, 30+y_diff*2); } if (y < _zoomy){ _zoomxn = x; _zoomyn = y; int x_diff = Math.abs(_zoomx-_zoomxn); int y_diff = Math.abs(_zoomy-_zoomyn); _graphics.drawRect(_zoomx-15-x_diff, _zoomy-15-y_diff, 30+x_diff*2, 30+y_diff*2); _graphics.setPaintMode(); _drawn = true; return true; } else _drawn = false; } } _graphics.setPaintMode(); return false; } /** * Zoom in or out based on the box that has been drawn. * @deprecated As of JDK1.1 in java.awt.component * but we need to compile under 1.0.2 for netscape3.x compatibility. */ public synchronized boolean mouseUp(Event evt, int x, int y) { //deprecated // We make this method synchronized so that we can draw the drag // box properly. If this method is not synchronized, then // we could end up calling setXORMode, being interrupted // and having setPaintMode() called in another method. if (_debug > 9) System.out.println("PlotBox: mouseUp"); boolean handled = false; if ((_zoomin == true) && (_drawn == true)){ if (_zoomxn != -1 || _zoomyn != -1) { // erase previous rectangle. int minx = Math.min(_zoomx, _zoomxn); int maxx = Math.max(_zoomx, _zoomxn); int miny = Math.min(_zoomy, _zoomyn); int maxy = Math.max(_zoomy, _zoomyn); _graphics.setXORMode(_background); _graphics.drawRect(minx, miny, maxx - minx, maxy - miny); _graphics.setPaintMode(); // constrain to be in range if (y > _lry) y=_lry; if (y < _uly) y=_uly; if (x > _lrx) x=_lrx; if (x < _ulx) x=_ulx; // NOTE: ignore if total drag less than 5 pixels. if ((Math.abs(_zoomx-x) > 5) && (Math.abs(_zoomy-y) > 5)) { double a = _xMin + (_zoomx - _ulx)/_xscale; double b = _xMin + (x - _ulx)/_xscale; if (a < b) setXRange(a, b); else setXRange(b, a); a = _yMax - (_zoomy - _uly)/_yscale; b = _yMax - (y - _uly)/_yscale; if (a < b) setYRange(a, b); else setYRange(b, a); } drawPlot(_graphics, true); handled = true; } } else if ((_zoomout == true) && (_drawn == true)){ // Erase previous rectangle. _graphics.setXORMode(_background); int x_diff = Math.abs(_zoomx-_zoomxn); int y_diff = Math.abs(_zoomy-_zoomyn); _graphics.drawRect(_zoomx-15-x_diff, _zoomy-15-y_diff, 30+x_diff*2, 30+y_diff*2); _graphics.setPaintMode(); // Calculate zoom factor. double a = (double)(Math.abs(_zoomx - x)) / 30.0; double b = (double)(Math.abs(_zoomy - y)) / 30.0; double newx1 = _xMax + (_xMax - _xMin) * a; double newx2 = _xMin - (_xMax - _xMin) * a; if (newx1 > _xTop) newx1 = _xTop; if (newx2 < _xBottom) newx2 = _xBottom; double newy1 = _yMax + (_yMax - _yMin) * b; double newy2 = _yMin - (_yMax - _yMin) * b; if (newy1 > _yTop) newy1 = _yTop; if (newy2 < _yBottom) newy2 = _yBottom; setXRange(newx2, newx1); setYRange(newy2, newy1); drawPlot(_graphics, true); handled = true; } else if (_drawn == false){ drawPlot(_graphics, true); handled = true; } _drawn = false; _zoomin = _zoomout = false; _zoomxn = _zoomyn = _zoomx = _zoomy = -1; return handled; } /** * Paint the component contents, which in this base class is * only the axes. */ public void paint(Graphics graphics) { if (_debug > 7) System.out.println("PlotBox: paint"); //super.paint(graphics); drawPlot(graphics, true); } /** * Syntactic sugar for parseFile(dataurl, documentBase); */ public void parseFile(String dataurl) { parseFile(dataurl, (URL)null); } /** * Open up the input file, which could be stdin, a URL or a file. * This code can be called from an application, which means that * getDocumentBase() might fail. */ public void parseFile(String dataurl, URL documentBase) { DataInputStream in = null; if (_debug > 2) System.out.println("PlotBox: parseFile("+ dataurl+" "+ documentBase+") _dataurl = "+_dataurl+" "+_documentBase); if (dataurl == null || dataurl.length() == 0) { // Open up stdin in = new DataInputStream(System.in); } else { try { URL url = null; if (documentBase == null && _documentBase != null) { documentBase = _documentBase; } if (documentBase == null) { url = new URL(dataurl); } else { try { url = new URL(documentBase, dataurl); } catch (NullPointerException e) { // If we got a NullPointerException, then perhaps we // are calling this as an application, not as an applet url = new URL(dataurl); } } in = new DataInputStream(url.openStream()); } catch (MalformedURLException e) { try { // Just try to open it as a file. in = new DataInputStream(new FileInputStream(dataurl)); } catch (FileNotFoundException me) { _errorMsg = new String [2]; _errorMsg[0] = "File not found: " + dataurl; _errorMsg[1] = me.getMessage(); return; } catch (SecurityException me) { _errorMsg = new String [2]; _errorMsg[0] = "Security Exception: " + dataurl; _errorMsg[1] = me.getMessage(); return; } } catch (IOException ioe) { _errorMsg = new String [3]; _errorMsg[0] = "Failure opening URL: "; _errorMsg[1] = " " + dataurl; _errorMsg[2] = ioe.getMessage(); return; } } _newFile(); // Hook for child classes to do any preprocessing. // Can't use cursors with jdk1.0.2, which we require for netscape4 //Cursor oldCursor = getCursor(); // At this point, we've opened the data source, now read it in try { if (dataurl != null) { // We are not reading from stdin, so set the wait cursor. //setCursor(new Cursor(Cursor.WAIT_CURSOR)); } if (_binary) { _parseBinaryStream(in); } else { String line = in.readLine(); // FIXME: readLine() is // deprecated in JDK1.1, but we need to compile under //1.0.2 for netscape3.x compatibility. while (line != null) { _parseLine(line); line = in.readLine(); // readLine() is deprecated. } } } catch (MalformedURLException e) { _errorMsg = new String [2]; _errorMsg[0] = "Malformed URL: " + dataurl; _errorMsg[1] = e.getMessage(); return; } catch (IOException e) { _errorMsg = new String [2]; _errorMsg[0] = "Failure reading data: " + dataurl; _errorMsg[1] = e.getMessage(); } catch (PlotDataException e) { _errorMsg = new String [2]; _errorMsg[0] = "Incorrectly formatted plot data in " + dataurl; _errorMsg[1] = e.getMessage(); } finally { //setCursor(oldCursor); try { in.close(); } catch (IOException me) {} } } /** The preferred size. * @deprecated As of JDK1.1 in java.awt.component, but we need * to compile under 1.0.2 for netscape3.x compatibility. */ public Dimension preferredSize() { if (_debug > 9) System.out.println("PlotBox: preferredSize "+_width+" "+_height); return getPreferredSize(); } /** Reshape */ public void reshape(int x, int y, int width, int height) {
_reshapeFlag = 1; //Rainer's Flag if (_debug > 9) System.out.println("PlotBox: reshape: "+x+" "+y+" "+ width+" "+height); _width = width; _height = height;
super.reshape(x,y,_width,_height);
} /** * Resize the plot. * @deprecated As of JDK1.1 in java.awt.component, but we need * to compile under 1.0.2 for netscape3.x compatibility. */ public void resize(int width, int height) { if (_debug > 8) System.out.println("PlotBox: resize"+width+" "+height); _width = width; _height = height; super.resize(width,height); // FIXME: resize() is deprecated.
} /** Set the background color. */ public void setBackground (Color background) { _background = background; super.setBackground(_background); } /** Set the debug value. The higher the integer, the greater the * number of debugging messages printed to stdout. Useful values * are 10 - argument parsing, 20 - legend parsing, 101 - data point * debugging. */ public void setDebug (int debug ) { _debug = debug; } /** Set the foreground color. */ public void setForeground (Color foreground) { _foreground = foreground; super.setForeground(_foreground); } /** Set the binary flag to true if we are reading pxgraph format binary * data. */ public void setBinary (boolean binary) { _binary = binary; } /** Set the dataurl. */ public void setDataurl (String dataurl) { _dataurl = dataurl; } /** Set the document base so that we can find the dataurl. */ public void setDocumentBase (URL documentBase) { _documentBase = documentBase; } /** Control whether the grid is drawn. */ public void setGrid (boolean grid) { _grid = grid; } /** Set the label font, which is used for axis labels and legend labels. */ public void setLabelFont (String fullfontname) { // Can't use Font.decode() here, it is not present in jdk1.0.2 //_labelfont = Font.decode(fullfontname); _labelfont = getFontByName(fullfontname); } /** * Set the title of the graph. The title will appear on the subsequent * call to <code>paint()</code> or <code>drawPlot()</code>. */ public void setTitle (String title) { _title = title; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -