📄 signalviewer.java
字号:
Graphics2D g2d = (Graphics2D) g; int h = getHeight(); if (bi != null) { //synchronized (paintlock) { g2d.drawImage(bi, 0, 0, this); //} } //paint selection if (selectionBeginPos != selectionEndPos) { g2d.setColor(selectionColor); g2d.setComposite(alpha04); g2d.fillRect(selectionBeginPos, 0, (selectionEndPos - selectionBeginPos), rulerHeight); g2d.setComposite(alpha07); g2d.fillRect(selectionBeginPos, rulerHeight, (selectionEndPos - selectionBeginPos), h - rulerHeight); g2d.setComposite(AlphaComposite.Src); } //draw the cursor g2d.setColor(Constants.CROSSHAIRCOLOR); g2d.drawLine(crossHairPos, 0, crossHairPos, h); } /** * Implements updateTimeScale from TimeScaleBasedViewer to adjust the * TimeScale if needed and when in TimeScale connected mode.<br> * Checks the GlobalTimeScaleIntervalBeginTime and * GlobalTimeScaleMsPerPixel and adjusts the interval and resolution of * this viewer when they differ from the global values.<br> * For the time being assume that the viewer is notified only once when * the resolution or the interval begintime has changed. */ public void updateTimeScale() { if (timeScaleConnected) { // if the resolution is changed recalculate the begin time if (getGlobalTimeScaleMsPerPixel() != msPerPixel) { setLocalTimeScaleMsPerPixel(getGlobalTimeScaleMsPerPixel()); } else if (getGlobalTimeScaleIntervalBeginTime() != intervalBeginTime) { //assume the resolution has not been changed setLocalTimeScaleIntervalBeginTime(getGlobalTimeScaleIntervalBeginTime()); //System.out.println("update begin time in SignalViewer called"); } } } /** * Sets whether or not this viewer listens to global time scale updates. * * @param connected the new timescale connected value */ public void setTimeScaleConnected(boolean connected) { timeScaleConnected = connected; if (timeScaleConnected) { if (msPerPixel != getGlobalTimeScaleMsPerPixel()) { setLocalTimeScaleMsPerPixel(getGlobalTimeScaleMsPerPixel()); } if (intervalBeginTime != getGlobalTimeScaleIntervalBeginTime()) { setLocalTimeScaleIntervalBeginTime(getGlobalTimeScaleIntervalBeginTime()); } } } /** * Gets whether this viewer listens to time scale updates from other * viewers. * * @return true when connected to global time scale values, false otherwise */ public boolean getTimeScaleConnected() { return timeScaleConnected; } /** * Checks whether this viewer is TimeScale connected and changes the * milliseconds per pixel value globally or locally.<br> * On setting the global MsPerPixel {@link #updateTimeScale()} will be * called and the local msPerPixel value will be updated also. * * @param mspp the new milliseconds per pixel value */ public void setMsPerPixel(int mspp) { if (timeScaleConnected) { setGlobalTimeScaleMsPerPixel(mspp); setGlobalTimeScaleIntervalBeginTime(intervalBeginTime); setGlobalTimeScaleIntervalEndTime(intervalEndTime); } else { setLocalTimeScaleMsPerPixel(mspp); } } /** * Change the horizontal resolution or zoomlevel locally. The msPerPixel * denotes the number of milliseconds of which the samples should be * merged to one value. It corresponds to one pixel in image space (a * pixel is the smallest unit in image space).<br> * The position on the screen of crosshair cursor should change as little * as possible.<br> * This is calculated as follows:<br> * The absolute x coordinate in image space is the current media time * divided by the new msPerPixel.<br> * <pre> * |----------|----------|-------x--|-- <br> * |imagesize | | absolute x coordinate of media time<br> * | 1 | 2 | 3 | * </pre> * Calculate the number of screen images that fit within the absolute x * coordinate. The new position on the screen would then be the absolute x * coordinate minus the number of screen images multiplied by the image * width. The difference between the old x value and the new x value is * then used to calculte the new interval start time.<br> * The new start time = (number of screen images image width - * difference) msPerPixel. * * @param step the new horizontal zoomlevel */ private void setLocalTimeScaleMsPerPixel(int step) { if (msPerPixel == step) { return; } if (step >= 1) { msPerPixel = step; } else { msPerPixel = 1; } resolution = (int) (1000f / msPerPixel); /*stop the player if necessary*/ boolean playing = playerIsPlaying(); if (playing) { stopPlayer(); } long mediaTime = getMediaTime(); int oldScreenPos = crossHairPos; int newMediaX = (int) (mediaTime / msPerPixel); int numScreens = (int) (mediaTime / (imageWidth * msPerPixel)); int newScreenPos = newMediaX - (numScreens * imageWidth); int diff = oldScreenPos - newScreenPos; //new values intervalBeginTime = ((numScreens * imageWidth) - diff) * msPerPixel; if (intervalBeginTime < 0) { intervalBeginTime = 0; } intervalEndTime = intervalBeginTime + (imageWidth * msPerPixel); crossHairPos = xAt(mediaTime); selectionBeginPos = xAt(getSelectionBeginTime()); selectionEndPos = xAt(getSelectionEndTime()); if (samp != null) { samplesPerPixel = (msPerPixel * samp.getSampleFrequency()) / 1000; } //force to reload data currentPart.setStartTime(0L); currentPart.setStopTime(0L); paintBuffer(); if (playing) { startPlayer(); } int zoom = (int) (100f * (10f / msPerPixel)); if (zoom <= 0) { zoom = 100; } updateZoomPopup(zoom); //repaint(); } /** * Returns the current msPerPixel. * * @return msPerPixel */ public int getMsPerPixel() { return msPerPixel; } /** * Calls #setMsPerPixel with the appropriate value. In setMsPerPixel the * value of this.resolution is actually set. msPerPixel = 1000 / resolution<br> * resolution = 1000 / msPerPixel * * @param resolution the new resolution */ public void setResolution(int resolution) { this.resolution = resolution; int mspp = (int) (1000f / resolution); setMsPerPixel(mspp); } /** * Sets the resolution by providing a factor the default PIXELS_FOR_SECOND * should be multiplied with.<br> * resolution = factor PIXELS_FOR_SECOND.<br> * <b>Note:</b><br> * The factor = 100 / resolution_menu_percentage ! * * @param factor the multiplication factor */ public void setResolutionFactor(float factor) { int res = (int) (PIXELS_FOR_SECOND * factor); setResolution(res); } /** * Gets the current resolution * * @return the current resolution */ public int getResolution() { return resolution; } /** * Gets the current channel display mode. * * @return the current channel mode, one of MONO, STEREO_SEPARATE, * STEREO_MERGED or STEREO_BLENDED */ public int getChannelMode() { return channelMode; } /** * Sets the channel display mode. * * @param mode the new channel mode */ public void setChannelMode(int mode) { if (mode == channelMode) { return; } if ((mode <= MONO) || (mode > STEREO_BLENDED)) { channelMode = MONO; } else { if ((samp != null) && (samp.getWavHeader().getNumberOfChannels() != 2)) { return; } channelMode = mode; } paintBuffer(); } /** * Returns the x-ccordinate for a specific time. The coorsidate is in the * component's coordinate system. * * @param t time * * @return int the x-coordinate for the specified time */ public int xAt(long t) { return (int) (t - intervalBeginTime) / msPerPixel; } /** * Returns the time in ms at a given position in the current image. The * given x coordinate is in the component's ("this") coordinate system. * The interval begin time is included in the calculation of the time at * the given coordinate. * * @param x x-coordinate * * @return the mediatime corresponding to the specified position */ public long timeAt(int x) { return intervalBeginTime + (x * msPerPixel); } /** * DOCUMENT ME! * * @return the current interval begin time */ public long getIntervalBeginTime() { return intervalBeginTime; } /** * DOCUMENT ME! * * @return the current interval end time */ public long getIntervalEndTime() { return intervalEndTime; } /** * Checks whether this viewer is TimeScale connected and changes the * interval begin time globally or locally.<br> * On setting the global interval begin time {@link #updateTimeScale()} * will be called and the local intervalBeginTime will be updated also. * * @param begin the new interval begin time */ public void setIntervalBeginTime(long begin) { if (timeScaleConnected) { setGlobalTimeScaleIntervalBeginTime(begin); setGlobalTimeScaleIntervalEndTime(intervalEndTime); } else { setLocalTimeScaleIntervalBeginTime(begin); } } /** * Calculates the new interval begin and/or end time.<br> * There are two special cases taken into account:<br> * * <ul> * <li> * when the player is playing attempts are made to shift the interval * <i>n</i> times the interval size to the left or to the right, until the * new interval contains the new mediatime. * </li> * <li> * when the player is not playing and the new interval begin time coincides * with the selection begin time, the interval is shifted a certain offset * away from the image edge. Same thing when the interval end time * coincides with the selection end time. * </li> * </ul> * * * @param mediaTime */ private void recalculateInterval(final long mediaTime) { long newBeginTime; long newEndTime; if (playerIsPlaying()) { // we might be in a selection outside the new interval // shift the interval n * intervalsize to the left or right if (mediaTime > intervalEndTime) { newBeginTime = intervalEndTime; newEndTime = newBeginTime + (imageWidth * msPerPixel); while ((newEndTime += (imageWidth + msPerPixel)) < mediaTime) { newBeginTime += (imageWidth * msPerPixel); } } else if (mediaTime < intervalBeginTime) { newEndTime = intervalBeginTime; newBeginTime = newEndTime - (imageWidth * msPerPixel); while ((newEndTime -= (imageWidth * msPerPixel)) > mediaTime) { newBeginTime -= (imageWidth * msPerPixel); } if (newBeginTime < 0) { newBeginTime = 0; newEndTime = imageWidth * msPerPixel; } } else { // the new time appears to be in the current interval after all return; } } else { //player is not playing // is the new media time to the left or to the right of the current interval if (mediaTime < intervalBeginTime) { newBeginTime = mediaTime - (SCROLL_OFFSET * msPerPixel); if (newBeginTime < 0) { newBeginTime = 0; } newEndTime = newBeginTime + (imageWidth * msPerPixel); } else { newEndTime = mediaTime + (SCROLL_OFFSET * msPerPixel);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -