📄 textviewer.java
字号:
private int getIndexBegin(int index, long beginTime) { int indexj; int retIndex = -1; for (int j = -2; j <= 2; j++) { indexj = index + j; if ((indexj >= 0) && (indexj < arrTagTimes.length)) { if (arrTagTimes[indexj] <= beginTime) { retIndex = indexj; } } } if (retIndex == -1) { return index; } else { return retIndex; } } private int getIndexEnd(int index, long endTime) { int indexj; int retIndex = -1; for (int j = 2; j >= -2; j--) { indexj = index + j; if ((indexj >= 0) && (indexj < arrTagTimes.length)) { if (arrTagTimes[indexj] >= endTime) { retIndex = indexj; } } } if (retIndex == -1) { return index; } else { return retIndex; } } /** * Update the complete text viewer Determines whether current time is in a * selection Sets the correct value in the text viewer */ public void doUpdate() { /////////////////////////////////////////////////////////////////////// // // Temporary code // highlighter.addHighlight in doUpdate gives an error when tabpane is // not visible. When not visible (in sync mode) the size of tabpane is // set to 0. So check size in doUpdate and if <= 0 return. // /////////////////////////////////////////////////////////////////////// Dimension dim = getSize(); if ((dim.height <= 0) || (dim.width <= 0)) { return; } /////////////////////////////////////////////////////////////////////// // // End temporary code // /////////////////////////////////////////////////////////////////////// if (arrTagTimes == null) { return; } //boolean bFound = false; long mediatime = getMediaTime(); //int annotations_size = annotations.size(); int indexj = 0; int index = 0; long activeAnnotationBeginTime = 0; long activeAnnotationEndTime = 0; indexActiveAnnotationBegin = 0; indexActiveAnnotationEnd = 0; long selectionBeginTime = getSelectionBeginTime(); long selectionEndTime = getSelectionEndTime(); Annotation activeAnnotation = getActiveAnnotation(); if ((activeAnnotation != null) && (activeAnnotation.getTier() == tier)) { activeAnnotationBeginTime = activeAnnotation.getBeginTimeBoundary(); activeAnnotationEndTime = activeAnnotation.getEndTimeBoundary(); } //select the appropriate text try { if ((activeAnnotation != null) && (activeAnnotation.getTier() == tier)) { //VALUES FOR HIGHLIGHTING ACTIVE ANNOTATION //use fast search to determine approximate index from array index = Math.abs(Arrays.binarySearch(arrTagTimes, activeAnnotationBeginTime)); //look for the 2 surrounding indexes //index from active annotation begin indexActiveAnnotationBegin = getIndexBegin(index, activeAnnotationBeginTime); index = Math.abs(Arrays.binarySearch(arrTagTimes, activeAnnotationEndTime)); //index from active annotation end indexActiveAnnotationEnd = getIndexEnd(index, activeAnnotationEndTime); } if ((selectionBeginTime == 0) && (selectionEndTime == 0)) { //selection is cleared indexSelectionBegin = 0; indexSelectionEnd = 0; } else { //VALUES FOR HIGHLIGHTING SELECTION //use fast search to determine approximate index from array index = Math.abs(Arrays.binarySearch(arrTagTimes, selectionBeginTime)); //look for the 2 surrounding indexes //index from selection begin indexSelectionBegin = getIndexBegin(index, selectionBeginTime); index = Math.abs(Arrays.binarySearch(arrTagTimes, selectionEndTime)); //index from selection end indexSelectionEnd = getIndexEnd(index, selectionEndTime); if (indexSelectionEnd >= arrTagPositions.length) { indexSelectionEnd = arrTagPositions.length - 1; } } //VALUES FOR HIGHLIGHTING CURRENT MEDIATIME index = Math.abs(Arrays.binarySearch(arrTagTimes, mediatime)); for (int j = -2; j <= 2; j++) { indexj = index + j; //needed to check whether no 'crosshair' should be drawn at left of first annotation if (indexj < 0) { indexMediaTime = -1; break; } if ((indexj >= 0) && (indexj < arrTagTimes.length)) { if (arrTagTimes[indexj] <= mediatime) { indexMediaTime = indexj; } } } // adjust painters if ((indexMediaTime >= 0) && ((indexMediaTime + 1) < arrTagPositions.length)) { currentPainter.setVisible(true); highlighter.changeHighlight(currentHighLightInfo, arrTagPositions[indexMediaTime], arrTagPositions[indexMediaTime + 1] - extraLength); } else { currentPainter.setVisible(false); // position the crosshair painter even if it is before the first annotation // or after the last; this way the painter's position can be used // to scroll to begin or end of the document if ((indexMediaTime < 0) && (arrTagPositions.length > 1)) { highlighter.changeHighlight(currentHighLightInfo, arrTagPositions[0], arrTagPositions[1]); } else if (((indexMediaTime + 1) >= arrTagPositions.length) && (arrTagPositions.length > 1)) { highlighter.changeHighlight(currentHighLightInfo, arrTagPositions[arrTagPositions.length - 2], arrTagPositions[arrTagPositions.length - 1]); } } if ((indexActiveAnnotationBegin >= 0) && (indexActiveAnnotationBegin < arrTagPositions.length) && (indexActiveAnnotationEnd >= 0) && (indexActiveAnnotationEnd < arrTagPositions.length)) { if (activeAnnotation != null) { activeAnnotationPainter.setVisible(true); highlighter.changeHighlight(activeHighLightInfo, arrTagPositions[indexActiveAnnotationBegin], arrTagPositions[indexActiveAnnotationEnd] - extraLength); } else { activeAnnotationPainter.setVisible(false); } } else { activeAnnotationPainter.setVisible(false); } if ((indexSelectionBegin >= 0) && (indexSelectionBegin < arrTagPositions.length) && (indexSelectionEnd >= 0) && (indexSelectionEnd < arrTagPositions.length)) { selectionPainter.setVisible(true); highlighter.changeHighlight(selectionHighLightInfo, arrTagPositions[indexSelectionBegin], arrTagPositions[indexSelectionEnd] - extraLength); } else { selectionPainter.setVisible(false); } /* if ((indexMediaTime >= 0) && ((indexMediaTime + 1) < arrTagPositions.length) && (indexSelectionBegin >= 0) && (indexSelectionBegin < arrTagPositions.length) && (indexSelectionEnd >= 0) && (indexSelectionEnd < arrTagPositions.length) && (indexActiveAnnotationBegin >= 0) && (indexActiveAnnotationBegin < arrTagPositions.length) && (indexActiveAnnotationEnd >= 0) && (indexActiveAnnotationEnd < arrTagPositions.length)) { taText.getHighlighter().removeAllHighlights(); //first highlight current, because first highlight blocks the second highlight //i.e., you can't put a second highlight 'over' an existing highlight highlighter.addHighlight(arrTagPositions[indexMediaTime], arrTagPositions[indexMediaTime + 1] - extraLength, currentPainter); if (activeAnnotation != null) { highlighter.addHighlight(arrTagPositions[indexActiveAnnotationBegin], arrTagPositions[indexActiveAnnotationEnd] - extraLength, activeAnnotationPainter); } highlighter.addHighlight(arrTagPositions[indexSelectionBegin], arrTagPositions[indexSelectionEnd] - extraLength, selectionPainter); } else if (((indexMediaTime == -1) || (indexMediaTime == (arrTagPositions.length - 1))) && (indexSelectionBegin >= 0) && (indexSelectionBegin < arrTagPositions.length) && (indexSelectionEnd >= 0) && (indexSelectionEnd < arrTagPositions.length) && (indexActiveAnnotationBegin >= 0) && (indexActiveAnnotationBegin < arrTagPositions.length) && (indexActiveAnnotationEnd >= 0) && (indexActiveAnnotationEnd < arrTagPositions.length)) { //for example, indexMediaTime = -1 at left of first annotation taText.getHighlighter().removeAllHighlights(); if (activeAnnotation != null) { highlighter.addHighlight(arrTagPositions[indexActiveAnnotationBegin], arrTagPositions[indexActiveAnnotationEnd] - extraLength, activeAnnotationPainter); } highlighter.addHighlight(arrTagPositions[indexSelectionBegin], arrTagPositions[indexSelectionEnd] - extraLength, selectionPainter); } */ } catch (Exception ex) { ex.printStackTrace(); } //repaint(); scrollIfNeeded(); repaint(); } /** * Sets the tier which is shown in the text viewer * * @param tier The tier which should become visible */ public void setTier(Tier tier) { // added by AR if (tier == null) { this.tier = null; annotations = new Vector(); } else { this.tier = (TierImpl) tier; try { annotations = this.tier.getAnnotations(); } catch (Exception ex) { ex.printStackTrace(); } } buildArrayAndText(); taText.setText(tierText); // call doUpdate after the TextArea has finished updating itself SwingUtilities.invokeLater(new Runnable() { public void run() { doUpdate(); } }); //doUpdate(); } /** * Gets the tier which is shown in the subtitle viewer * * @return DOCUMENT ME! */ public Tier getTier() { return tier; } /** * Returns the current font size. * * @return the current font size */ public int getFontSize() { return fontSize; } /** * Sets the font size. * * @param size the new font size */ public void setFontSize(int size) { fontSize = size; if (fontSizeBG != null) { Enumeration en = fontSizeBG.getElements(); JMenuItem item; String value; while (en.hasMoreElements()) { item = (JMenuItem) en.nextElement(); value = item.getText(); try { int v = Integer.parseInt(value); if (v == fontSize) { item.setSelected(true); taText.setFont(Constants.DEFAULTFONT.deriveFont( (float) fontSize)); break; } } catch (NumberFormatException nfe) { //// do nothing } } } else { createPopup(); taText.setFont(Constants.DEFAULTFONT.deriveFont((float) fontSize)); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -