📄 panel.java
字号:
{ // remove the panels and put them in the right place waveWindow.getSignalNamesPanel().remove(wsig.getPanel().leftHalf); waveWindow.getSignalTracesPanel().remove(wsig.getPanel().rightHalf); Component [] lefts = waveWindow.getSignalNamesPanel().getComponents(); int destIndex = 0; for( ; destIndex < lefts.length; destIndex++) { if (lefts[destIndex] == leftHalf) break; } waveWindow.getSignalNamesPanel().add(wsig.getPanel().leftHalf, destIndex+increment); waveWindow.getSignalTracesPanel().add(wsig.getPanel().rightHalf, destIndex+increment); } increment++; } if (WaveformWindow.USETABLES) { waveWindow.reloadTable(); } } waveWindow.validatePanel(); waveWindow.saveSignalOrder(); } // ************************************* X AND Y AXIS CONTROL ************************************* /** * Method to compute the smallest X and Y values (for log display). */ private void computeSmallestValues() { if (analysisType == null) return; Stimuli sd = waveWindow.getSimData(); Analysis an = sd.findAnalysis(analysisType); if (an == null) return; Rectangle2D anBounds = an.getBounds(); if (anBounds == null) return; // no signals smallestXValue = anBounds.getMinX(); smallestYValue = anBounds.getMinY();// smallestXValue = anBounds.getWidth() / 1000;// smallestYValue = anBounds.getHeight() / 1000; } /** * Method to set the X axis range in this panel. * Since the panel may go backwards in time, these values aren't * guaranteed to run from left to right. * @param leftEdge the X axis value on the left side of the panel. * @param rightEdge the X axis value on the right side of the panel. */ public void setXAxisRange(double leftEdge, double rightEdge) { this.minXPosition = leftEdge; this.maxXPosition = rightEdge; } /** * Method to return the low X axis value shown in this panel. * @return the low X axis value shown in this panel. */ public double getMinXAxis() { return minXPosition; } /** * Method to return the high X axis value shown in this panel. * @return the high X axis value shown in this panel. */ public double getMaxXAxis() { return maxXPosition; } /** * Method to make this Panel show a signal fully. * @param sSig the signal to show (must be analog) */ public void fitToSignal(Signal sSig) { if (sSig instanceof AnalogSignal) { AnalogSignal as = (AnalogSignal)sSig; Rectangle2D rangeBounds = as.getBounds(); double lowValue = rangeBounds.getMinY(); double highValue = rangeBounds.getMaxY(); double range = highValue - lowValue; if (range == 0) range = 2; double rangeExtra = range / 10; setYAxisRange(lowValue - rangeExtra, highValue + rangeExtra); } } /** * Method to set the Y axis range in this panel. * @param low the low Y axis value. * @param high the high Y axis value. */ public void setYAxisRange(double low, double high) { if (low == high) { low -= 0.5; high += 0.5; } analogLowValue = low; analogHighValue = high; analogRange = analogHighValue - analogLowValue; } public double getYAxisRange() { return analogRange; } public double getYAxisLowValue() { return analogLowValue; } public double getYAxisHighValue() { return analogHighValue; } /** * Method to scale a simulation X value to the X coordinate in this window. * @param value the simulation X value. * @return the X coordinate of that simulation value on the screen. */ public int convertXDataToScreen(double value) { // see if doing logarithmic axes boolean log = waveWindow.isWaveWindowLogarithmic(); if (!waveWindow.isXAxisLocked()) log = horizRulerPanelLogarithmic; if (log) { // logarithmic axes if (value <= smallestXValue) value = smallestXValue; double logValue = Math.log10(value); double winMinX = minXPosition; if (winMinX <= 0) winMinX = smallestXValue; double logWinMinX = Math.log10(winMinX); double winMaxX = maxXPosition; if (winMaxX <= 0) winMaxX = smallestXValue; double logWinMaxX = Math.log10(winMaxX); double x = (logValue - logWinMinX) / (logWinMaxX - logWinMinX) * (sz.width - vertAxisPos) + vertAxisPos; return (int)x; } // linear axes double x = (value - minXPosition) / (maxXPosition - minXPosition) * (sz.width - vertAxisPos) + vertAxisPos; return (int)x; } /** * Method to scale an X coordinate from screen space to data space. * @param x the X coordinate on the screen. * @return the X value in the simulation corresponding to that screen coordinate. */ public double convertXScreenToData(int x) { // see if doing logarithmic axes boolean log = waveWindow.isWaveWindowLogarithmic(); if (!waveWindow.isXAxisLocked()) log = horizRulerPanelLogarithmic; if (log) { // logarithmic axes double winMinX = minXPosition; if (winMinX <= 0) winMinX = smallestXValue; double logWinMinX = Math.log10(winMinX); double winMaxX = maxXPosition; if (winMaxX <= 0) winMaxX = smallestXValue; double logWinMaxX = Math.log10(winMaxX); double xValue = Math.pow(10, ((double)(x - vertAxisPos)) / (sz.width - vertAxisPos) * (logWinMaxX - logWinMinX) + logWinMinX); return xValue; } // linear axes double xValue = ((double)(x - vertAxisPos)) / (sz.width - vertAxisPos) * (maxXPosition - minXPosition) + minXPosition; return xValue; } /** * Method to scale a simulation Y value to the Y coordinate in this window. * @param value the simulation Y value. * @return the Y coordinate of that simulation value on the screen */ private int convertYDataToScreen(double value) { if (vertPanelLogarithmic) { // logarithmic axes if (value <= smallestYValue) value = smallestYValue; double logValue = Math.log10(value); double winMinY = analogLowValue; if (winMinY <= 0) winMinY = smallestYValue; double logWinMinY = Math.log10(winMinY); double winMaxY = analogHighValue; if (winMaxY <= 0) winMaxY = smallestYValue; double logWinMaxY = Math.log10(winMaxY); double y = sz.height - 1 - (logValue - logWinMinY) / (logWinMaxY - logWinMinY) * (sz.height-1); return (int)y; } // linear axes double y = sz.height - 1 - (value - analogLowValue) / analogRange * (sz.height-1); return (int)y; } /** * Method to scale a Y coordinate from screen space to data space. * @param y the Y coordinate on the screen. * @return the Y value in the simulation corresponding to that screen coordinate. */ private double convertYScreenToData(int y) { if (vertPanelLogarithmic) { // logarithmic axes double winMinY = analogLowValue; if (winMinY <= 0) winMinY = smallestYValue; double logWinMinY = Math.log10(winMinY); double winMaxY = analogHighValue; if (winMaxY <= 0) winMaxY = smallestYValue; double logWinMaxY = Math.log10(winMaxY); double yValue = Math.pow(10, logWinMinY - (y - sz.height + 1) * (logWinMaxY - logWinMinY) / (sz.height-1)); return yValue; } // linear axes double value = 0; if (sz.height > 1) value = analogLowValue - (y - sz.height + 1) * analogRange / (sz.height-1); return value; } // ************************************* DISPLAY CONTROL ************************************* /** * Method to repaint this window and its associated ruler panel. */ public void repaintWithRulers() { if (horizRulerPanel != null) horizRulerPanel.repaint(); else { waveWindow.getMainHorizRuler().repaint(); } repaintContents(); } /** * Method to repaint the panel. * Rebuilds the offscreen image and schedules a repaint. */ public void repaintContents() { needRepaintOffscreenImage = true;// repaintOffscreenImage(); if (WaveformWindow.USETABLES) { waveWindow.getWaveformTable().repaint(); } else { repaint(); } } private boolean needRepaintOffscreenImage; private Image offscreen; /** * Method to repaint this Panel. */ public void paint(Graphics g) { // requestFocus moved to mousePressed(). // to enable keys to be received //if (waveWindow.getWindowFrame() == WindowFrame.getCurrentWindowFrame()) // requestFocus(); sz = getSize(); szValid = true; int wid = sz.width; int hei = sz.height;// long startTime = System.currentTimeMillis();// long repaintOffscreenTime = startTime; if (USE_VOLATILE_IMAGE) { VolatileImage offscreen = (VolatileImage)this.offscreen; do { int returnCode = VolatileImage.IMAGE_INCOMPATIBLE; if (offscreen != null && offscreen.getWidth() == wid && offscreen.getHeight() == hei) returnCode = offscreen.validate(getGraphicsConfiguration()); if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) { // old offscreen doesn't work with new GraphicsConfig; re-create it if (offscreen != null) offscreen.flush(); this.offscreen = offscreen = createVolatileImage(wid, hei); needRepaintOffscreenImage = true; } if (returnCode != VolatileImage.IMAGE_OK || needRepaintOffscreenImage) { // Contents need to be restored repaintOffscreenImage(wid, hei); } if (offscreen.contentsLost()) continue;// repaintOffscreenTime = System.currentTimeMillis(); g.drawImage(offscreen, 0, 0, null); } while (offscreen.contentsLost()); } else { BufferedImage offscreen = (BufferedImage)this.offscreen; if (offscreen == null || offscreen.getWidth() != wid || offscreen.getHeight() != hei) { this.offscreen = offscreen = new BufferedImage(wid, hei, BufferedImage.TYPE_INT_RGB); needRepaintOffscreenImage = true; } if (needRepaintOffscreenImage) { repaintOffscreenImage(wid, hei); }// repaintOffscreenTime = System.currentTimeMillis(); g.drawImage(offscreen, 0, 0, null); }// long drawImageTime = System.currentTimeMillis(); if (WaveformWindow.USETABLES) { Dimension tableSz = waveWindow.getWaveformTable().getSize(); Point screenLoc = waveWindow.getWaveformTable().getLocationOnScreen(); waveWindow.setScreenXSize(screenLoc.x + tableSz.width - wid, screenLoc.x + tableSz.width); } else { Point screenLoc = getLocationOnScreen(); waveWindow.setScreenXSize(screenLoc.x, screenLoc.x + wid); } paintDragging((Graphics2D)g, wid, hei);// long dragTime = System.currentTimeMillis();// System.out.println("Panel" + panelNumber +// " offscreen " + (repaintOffscreenTime - startTime) + " msec;" +// " drawImage " + (drawImageTime - repaintOffscreenTime) + " msec;" +// " dragging " + (dragTime - drawImageTime) + " msec"); } private void repaintOffscreenImage(int wid, int hei) { needRepaintOffscreenImage = false; Graphics2D offscreenGraphics = (Graphics2D)offscreen.getGraphics(); // clear the buffer offscreenGraphics.setColor(new Color(User.getColor(User.ColorPrefType.WAVE_BACKGROUND))); offscreenGraphics.fillRect(0, 0, wid, hei); drawPanelContents(wid, hei, offscreenGraphics, null, null); offscreenGraphics.dispose(); } private void paintDragging(Graphics2D g, int wid, int hei) { g.setColor(new Color(User.getColor(User.ColorPrefType.WAVE_FOREGROUND))); // draw the X position cursors g.setStroke(Highlight2.dashedLine); int x = convertXDataToScreen(waveWindow.getMainXPositionCursor()); if (x >= vertAxisPos) g.drawLine(x, 0, x, hei); g.setStroke(farDottedLine); x = convertXDataToScreen(waveWindow.getExtensionXPositionCursor()); if (x >= vertAxisPos) g.drawLine(x, 0, x, hei); g.setStroke(Highlight2.solidLine); // show dragged area if there if (draggingArea) { int lowX = Math.min(convertXDataToScreen(dragStartXD), convertXDataToScreen(dragEndXD)); int highX = Math.max(convertXDataToScreen(dragStartXD), convertXDataToScreen(dragEndXD)); int lowY = Math.min(convertYDataToScreen(dragStartYD), convertYDataToScreen(dragEndYD)); int highY = Math.max(convertYDataToScreen(dragStartYD), convertYDataToScreen(dragEndYD)); g.drawLine(lowX, lowY, lowX, highY); g.drawLine(lowX, highY, highX, highY); g.drawLine(highX, highY, highX, lowY); g.drawLine(highX, lowY, lowX, lowY); } for(Rectangle2D meas : measurementList) { int lowX = Math.min(convertXDataToScreen(meas.getMinX()), convertXDataToScreen(meas.getMaxX())); int highX = Math.max(convertXDataToScreen(meas.getMinX()), convertXDataToScreen(meas.getMaxX())); int lowY = Math.min(convertYDataToScreen(meas.getMinY()), convertYDataToScreen(meas.getMaxY()));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -