📄 signalviewer.java
字号:
newBeginTime = newEndTime - (imageWidth * msPerPixel); if (newBeginTime < 0) { // somehing would be wrong?? newBeginTime = 0; newEndTime = newBeginTime + (imageWidth * msPerPixel); } } if ((newBeginTime == getSelectionBeginTime()) && (newBeginTime > (SCROLL_OFFSET * msPerPixel))) { newBeginTime -= (SCROLL_OFFSET * msPerPixel); newEndTime = newBeginTime + (imageWidth * msPerPixel); } if (newEndTime == getSelectionEndTime()) { newEndTime += (SCROLL_OFFSET * msPerPixel); newBeginTime = newEndTime - (imageWidth * msPerPixel); if (newBeginTime < 0) { // something would be wrong?? newBeginTime = 0; newEndTime = newBeginTime + (imageWidth * msPerPixel); } } } if (timeScaleConnected) { //System.out.println("SV new begin time: " + newBeginTime); //System.out.println("SV new end time: " + newEndTime); setGlobalTimeScaleIntervalBeginTime(newBeginTime); setGlobalTimeScaleIntervalEndTime(newEndTime); } else { setLocalTimeScaleIntervalBeginTime(newBeginTime); } } /** * Changes the interval begin time locally. * * @param begin the new local interval begin time */ private void setLocalTimeScaleIntervalBeginTime(long begin) { if (begin == intervalBeginTime) { return; } intervalBeginTime = begin; intervalEndTime = intervalBeginTime + (imageWidth * msPerPixel); crossHairPos = xAt(crossHairTime); selectionBeginPos = xAt(getSelectionBeginTime()); selectionEndPos = xAt(getSelectionEndTime()); //System.out.println("SV begin:" + intervalBeginTime); paintBuffer(); } /** * Create a popup menu to enable the manipulation of some settings for this * viewer. */ private void createPopupMenu() { popup = new JPopupMenu("Signal Viewer"); JMenu zoomMI = new JMenu(ElanLocale.getString( "TimeScaleBasedViewer.Zoom")); zoomBG = new ButtonGroup(); // JRadioButtonMenuItem zoomRB; for (int i = 0; i < ZOOMLEVELS.length; i++) { zoomRB = new JRadioButtonMenuItem(ZOOMLEVELS[i] + "%"); zoomRB.setActionCommand(String.valueOf(ZOOMLEVELS[i])); zoomRB.addActionListener(this); zoomBG.add(zoomRB); zoomMI.add(zoomRB); if (ZOOMLEVELS[i] == 100) { zoomRB.setSelected(true); } } popup.add(zoomMI); JMenu vertZoomMenu = new JMenu(ElanLocale.getString( "SignalViewer.VertZoom")); ButtonGroup vzGroup = new ButtonGroup(); for (int i = 0; i < VERT_ZOOM.length; i++) { zoomRB = new JRadioButtonMenuItem(VERT_ZOOM[i] + "%"); zoomRB.setActionCommand("vz-" + VERT_ZOOM[i]); zoomRB.addActionListener(this); vzGroup.add(zoomRB); vertZoomMenu.add(zoomRB); if (vertZoom == VERT_ZOOM[i]) { zoomRB.setSelected(true); } } popup.add(vertZoomMenu); if ((samp != null) && (samp.getWavHeader().getNumberOfChannels() == 2)) { ButtonGroup chanGroup = new ButtonGroup(); JMenu channelMI = new JMenu(ElanLocale.getString( "SignalViewer.Stereo")); JRadioButtonMenuItem separateMI = new JRadioButtonMenuItem(ElanLocale.getString( "SignalViewer.Stereo.Separate")); separateMI.setActionCommand("sep"); separateMI.addActionListener(this); chanGroup.add(separateMI); channelMI.add(separateMI); if (channelMode == STEREO_SEPARATE) { separateMI.setSelected(true); } JRadioButtonMenuItem mergedMI = new JRadioButtonMenuItem(ElanLocale.getString( "SignalViewer.Stereo.Merged")); mergedMI.setActionCommand("merge"); mergedMI.addActionListener(this); chanGroup.add(mergedMI); channelMI.add(mergedMI); if (channelMode == STEREO_MERGED) { mergedMI.setSelected(true); } JRadioButtonMenuItem blendMI = new JRadioButtonMenuItem(ElanLocale.getString( "SignalViewer.Stereo.Blended")); blendMI.setActionCommand("blend"); blendMI.addActionListener(this); chanGroup.add(blendMI); channelMI.add(blendMI); if (channelMode == STEREO_BLENDED) { blendMI.setSelected(true); } popup.add(channelMI); } if (allowConnecting) { JCheckBoxMenuItem timeScaleConMI = new JCheckBoxMenuItem(ElanLocale.getString( "TimeScaleBasedViewer.Connected"), timeScaleConnected); timeScaleConMI.setActionCommand("connect"); timeScaleConMI.addActionListener(this); popup.add(timeScaleConMI); } popup.addSeparator(); JMenuItem praatMI = new JMenuItem(ElanLocale.getString( "SignalViewer.Praat.File")); praatMI.setActionCommand("praat"); praatMI.addActionListener(this); popup.add(praatMI); praatSelMI = new JMenuItem(ElanLocale.getString( "SignalViewer.Praat.Selection")); praatSelMI.setActionCommand("praatSel"); praatSelMI.addActionListener(this); popup.add(praatSelMI); clipSelPraatMI = new JMenuItem(ElanLocale.getString( "SignalViewer.Praat.Clip")); clipSelPraatMI.setActionCommand("clipSel"); clipSelPraatMI.addActionListener(this); popup.add(clipSelPraatMI); if (getSelectionBeginTime() == getSelectionEndTime()) { praatSelMI.setEnabled(false); clipSelPraatMI.setEnabled(false); } else { praatSelMI.setEnabled(true); clipSelPraatMI.setEnabled(true); } if (allowConnecting) { popup.addSeparator(); infoItem = new JMenuItem(ElanLocale.getString("Player.Info")); infoItem.setActionCommand("info"); infoItem.addActionListener(this); popup.add(infoItem); } JPopupMenu.setDefaultLightWeightPopupEnabled(false); int zoom = (int) (100f * (10f / msPerPixel)); if (zoom <= 0) { zoom = 100; } updateZoomPopup(zoom); } /** * Updates the "zoom" menu item. Needed, when timeScaleConnected, after a * change of the zoomlevel in some other connected viewer. * * @param zoom the zoom level */ private void updateZoomPopup(int zoom) { // first find the closest match (ther can be rounding issues) int zoomMenuIndex = 0; int diff = Integer.MAX_VALUE; for (int i = 0; i < ZOOMLEVELS.length; i++) { int d = Math.abs(ZOOMLEVELS[i] - zoom); if (d < diff) { diff = d; zoomMenuIndex = i; } } if (popup != null) { java.util.Enumeration en = zoomBG.getElements(); int counter = 0; while (en.hasMoreElements()) { JRadioButtonMenuItem rbmi = (JRadioButtonMenuItem) en.nextElement(); if (counter == zoomMenuIndex) { rbmi.setSelected(true); break; } else { rbmi.setSelected(false); } counter++; } } } /** * Updates the value of the media offset field, i.e. the new media start * point in the .wav file. * * @param offset the new offset in ms */ public void setOffset(long offset) { //System.out.println("SignalViewer: new offset: " + offset); if (offset != mediaOffset) { mediaOffset = offset; //force a reload of data // currentPart.setStartTime(0); currentPart.setStopTime(0); //currentPart.reset(); // paintBuffer(); } } /** * When a TimeEvent or StopEvent is received the crosshair position is * updated. If necessary a new interval is loaded and the new position of * the selection in image space is calculated.<br> * * @see ControllerListener */ public void controllerUpdate(ControllerEvent event) { if (event instanceof TimeEvent || event instanceof StopEvent) { crossHairTime = getMediaTime(); /* //System.out.println("SignalViewer time: " + crossHairTime); if (crossHairTime < intervalBeginTime || crossHairTime > intervalEndTime) { if (playerIsPlaying()) { // we might be in a selection outside the new interval long newBeginTime = intervalEndTime; long newEndTime = newBeginTime + (imageWidth * msPerPixel); if (crossHairTime > newEndTime) { while ((newEndTime += imageWidth + msPerPixel) < crossHairTime) { newBeginTime += imageWidth * msPerPixel; } } else if (crossHairTime < newBeginTime) { while ((newEndTime -= imageWidth * msPerPixel) > crossHairTime) { newBeginTime -= imageWidth * msPerPixel; } } setIntervalBeginTime(newBeginTime); } else { setIntervalBeginTime(crossHairTime); } */ if ((crossHairTime == intervalEndTime) && !playerIsPlaying()) { recalculateInterval(crossHairTime); } else if ((crossHairTime < intervalBeginTime) || (crossHairTime > intervalEndTime)) { recalculateInterval(crossHairTime); } else { //repaint a part of the viewer int oldCrossHairPos = crossHairPos; crossHairPos = xAt(crossHairTime); if (crossHairPos >= oldCrossHairPos) { repaint(oldCrossHairPos - 1, 0, crossHairPos - oldCrossHairPos + 2, getHeight()); //repaint(); } else { repaint(crossHairPos - 1, 0, oldCrossHairPos - crossHairPos + 2, getHeight()); //repaint(); } } } } /* * Implement SelectionUser * @see mpi.eudico.client.annotator.SelectionUser#updateSelection() */ public void updateSelection() { selectionBeginPos = xAt(getSelectionBeginTime()); selectionEndPos = xAt(getSelectionEndTime()); if (praatSelMI != null) { if (selectionBeginPos == selectionEndPos) { praatSelMI.setEnabled(false); } else { praatSelMI.setEnabled(true); } } if (clipSelPraatMI != null) { if (selectionBeginPos == selectionEndPos) { clipSelPraatMI.setEnabled(false); } else { clipSelPraatMI.setEnabled(true); } } repaint(); } /** * AR heeft dit hier neergezet, zie abstract viewer voor get en set * methodes van ActiveAnnotation. Update method from ActiveAnnotationUser */ public void updateActiveAnnotation() { } /** * method from ElanLocaleListener not implemented in AbstractViewer */ public void updateLocale() { if (popup != null) { createPopupMenu(); } } /** * Layout information, gives the nr of pixels at the left of the viewer * panel that contains no time line information * * @return the nr of pixels at the left that contain no time line related * data */ public int getLeftMargin() { return 0; } /** * Layout information, gives the nr of pixels at the right of the viewer * panel that contains no time line information * * @return the nr of pixels at the right that contain no time line related * data */ public int getRightMargin() { return 0; } /* * For testing purposes */ private void printMem(String message) { System.out.println(message); Runtime r = Runtime.getRuntime(); System.out.println("Total memory: " + (r.totalMemory() / 1024) + " Kb"); System.out.println("Free memory: " + (r.freeMemory() / 1024) + " Kb");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -