⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textviewer.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    /**     * Returns whether the annotation values are visualized separated by a dot.     *     * @return true if the annotation values are visualized separated by a dot,     * false otherwise     */    public boolean isDotSeparated() {        return bVisDotted;    }    /**     * Sets the visualization of the annotation values.     *     * @param dotted when true the annotations are separated by dots     */    public void setDotSeparated(boolean dotted) {        if (dotted != bVisDotted) {            bVisDotted = dotted;            setTier(getTier());        }    }    /**     * Sets whether the crosshair should be centered vertically in     * the view. When this value is <code>false</code> the crosshair     * will most of the time be drawn at he bottom of the view.      *     * @param centered the center vertically value     */    public void setCenteredVertically(boolean centered) {        centerVertically = centered;        if (centerMI.isSelected() != centerVertically) {            centerMI.setSelected(centerVertically);        }        scrollIfNeeded();        repaint();    }    /**     * Returns whether the crosshair is vertically centered .     *     * @return the center vertically value     */    public boolean isCenteredVertically() {        return centerVertically;    }    /**     * Builds an array with all begintimes and endtimes from a tag Used for     * searching (quickly) a particular tag     */    private void buildArrayAndText() {        tierText = "";        int annotations_size = annotations.size();        arrTagTimes = new long[2 * annotations_size];        arrTagPositions = new int[2 * annotations_size];        int arrIndexTimes = 0;        int arrIndexPositions = 0;        try {            Annotation ann;            for (int i = 0; i < annotations_size; i++) {                ann = (Annotation) annotations.elementAt(i);                String strTagValue = ann.getValue();                //next line for JDK1.4 only                //strTagValue = strTagValue.replaceAll("\n", "");                strTagValue = strTagValue.replace('\n', ' ');                //building text                if (bVisDotted) {                    tierText += (strTagValue +                    "\u0020\u0020\u00B7\u0020\u0020");                    extraLength = 4;                } else {                    tierText += (strTagValue + " ");                    extraLength = 0;                }                begintime = ann.getBeginTimeBoundary();                endtime = ann.getEndTimeBoundary();                arrTagTimes[arrIndexTimes++] = begintime;                arrTagTimes[arrIndexTimes++] = endtime;                int taglength = ((String) (strTagValue)).length() +                    extraLength;                if ((arrIndexPositions == 0) || (arrIndexPositions == 1)) {                    arrTagPositions[arrIndexPositions++] = 0;                    arrTagPositions[arrIndexPositions++] = taglength;                } else {                    arrTagPositions[arrIndexPositions] = arrTagPositions[arrIndexPositions -                        1] + 1; // 1 space                    arrIndexPositions++;                    arrTagPositions[arrIndexPositions] = arrTagPositions[arrIndexPositions -                        1] + taglength;                    arrIndexPositions++;                }            }        } catch (Exception ex) {            ex.printStackTrace();        }        //used for testing purposes        //for (int tel=0; tel < arrTagTimes.length; tel++)        //{        //    System.out.println("arrTagTimes[" + tel + "]: " + arrTagTimes[tel] + " --- " + "arrTagPositions[" + tel + "]: " + arrTagPositions[tel]);        //}    }    /**     * Handles mouse actions on the text viewer     */    private class TextViewerMouseListener extends MouseAdapter {        private InlineEditBox inlineEditBox = null;        private JComponent comp;        /**         * Creates a new TextViewerMouseListener instance         *         * @param c the parent component         */        public TextViewerMouseListener(JComponent c) {            comp = c;        }        /**         * DOCUMENT ME!         *         * @param e DOCUMENT ME!         */        public void mousePressed(MouseEvent e) {            stopPlayer();            if (SwingUtilities.isRightMouseButton(e) || e.isPopupTrigger()) {                Point p = e.getPoint();                SwingUtilities.convertPointToScreen(p, comp);                int x = e.getPoint().x;                int y = e.getPoint().y;                popup.show(comp, x, y);            }        }        /**         * Finds the index of the active annotation in the array of tags.         *         * @return the index         */        private int getArrayIndex() {            int index = -1;            int annotations_size = annotations.size();            for (int i = 0; i < annotations_size; i++) {                Annotation ann = (Annotation) annotations.elementAt(i);                // 4 dec 2003: there isn't always a selection to rely on                //exact time always exists in this case                /*                if (getSelectionBeginTime() == tag.getBeginTime()) {                    index = i;                    break;                }                // temp: use the active annotation                else */                // HS jul 2004 only use the active annotation to find the particular index                if ((getActiveAnnotation() != null) &&                        (getActiveAnnotation().getBeginTimeBoundary() == ann.getBeginTimeBoundary())) {                    index = i;                    break;                }            }            return index;        }        /**         * DOCUMENT ME!         *         * @param e DOCUMENT ME!         */        public void mouseReleased(MouseEvent e) {            if (SwingUtilities.isRightMouseButton(e) || e.isPopupTrigger()) {                return;            }            int annotations_size = annotations.size();            //bring up edit dialog            if (e.getClickCount() == 2) {                if (inlineEditBox == null) {                    inlineEditBox = new InlineEditBox(false);                    inlineEditBox.setLocale(ElanLocale.getLocale());                }                Annotation annotation = null;                int index = getArrayIndex();                if ((index >= 0) && (index < annotations_size)) {                    annotation = (Annotation) annotations.elementAt(index);                    if (e.isShiftDown()) {                        // open CV                        inlineEditBox.setAnnotation(annotation, true);                    } else {                        inlineEditBox.setAnnotation(annotation);                    }                    inlineEditBox.detachEditor();                }                return;            }            //setting selection color to background because of strange behaviour from JTextArea            //JTextArea's own selection system gets in the way with our selection.            //For example, a fast three-click will select a complete line.            //A workaround: set the selection color to the background color.            //So the JTextArea still shows its own selection , you just don't see it.            //One problem left: making a selection in the JTextArea by dragging a mouse.            //You can't see your selection while you're making it because of the color.            //To avoid this the selection color of the JTextArea is set to our            //selection color in the mouseDragged method of TextViewerMouseMotionListener.            //And here is the place to set it back again.            //taText.setSelectionColor(taText.getBackground());            taText.setSelectionColor(transparent);            if (!taText.getText().equals("")) {                int selectionStartPosition = taText.getSelectionStart();                int selectionEndPosition = taText.getSelectionEnd();                int indexSelectionStart = 0;                int indexSelectionEnd = 0;                int indexj = 0;                //index from selection begin                int index = Math.abs(Arrays.binarySearch(arrTagPositions,                            selectionStartPosition));                for (int j = -2; j <= 2; j++) {                    indexj = index + j;                    if ((indexj >= 0) && (indexj < arrTagPositions.length)) {                        if (arrTagPositions[indexj] <= selectionStartPosition) {                            indexSelectionStart = indexj;                        }                    }                }                //if clicked                if ((selectionStartPosition == selectionEndPosition) &&                        ((indexSelectionStart + 1) < arrTagTimes.length)) {                    //don't change order of setting things!                    // HS 4 dec 2003: changed in order to use application wide implementation of                    // setActiveAnnotation (i.e. don't set the selection when a RefAnnotation is made active)                    //setSelection(arrTagTimes[indexSelectionStart], arrTagTimes[indexSelectionStart + 1]);                    index = (int) Math.ceil(indexSelectionStart / 2);                    if (index < annotations_size) {                        Annotation ann = (Annotation) annotations.elementAt(index);                        setActiveAnnotation(ann);                    } else {                        setMediaTime(arrTagTimes[indexSelectionStart]);                    }                    return;                }                //if dragged                index = Math.abs(Arrays.binarySearch(arrTagPositions,                            selectionEndPosition));                for (int j = 2; j >= -2; j--) {                    indexj = index + j;                    if ((indexj >= 0) && (indexj < arrTagTimes.length)) {                        if (arrTagPositions[indexj] >= selectionEndPosition) {                            indexSelectionEnd = indexj;                        }                    }                }                //if dragged outside right border, then determine the new indexSelectionEnd                int indexNewJ;                if ((indexj + 2) < arrTagTimes.length) {                    indexNewJ = indexj + 2;                } else if ((indexj + 1) < arrTagTimes.length) {                    indexNewJ = indexj + 1;                } else {                    indexNewJ = indexj;                }                if (indexSelectionEnd == 0) {                    indexSelectionEnd = indexNewJ;                }                if ((indexSelectionStart < indexSelectionEnd) &&                        (indexSelectionEnd < arrTagTimes.length)) {                    setSelection(arrTagTimes[indexSelectionStart],                        arrTagTimes[indexSelectionEnd]);                    setMediaTime(arrTagTimes[indexSelectionStart]);                }            }        }    }    //end of TextViewerMouseListener    /**     * Handles mouse motion actions on the text viewer     */    private class TextViewerMouseMotionListener extends MouseMotionAdapter {        /**         * DOCUMENT ME!         *         * @param e DOCUMENT ME!         */        public void mouseDragged(MouseEvent e) {            //see comment in mouseReleased from TextViewerMouseListener            taText.setSelectionColor(Constants.SELECTIONCOLOR);        }    }    //end of TextViewerMouseMotionListener    /**     * DOCUMENT ME!     * $Id: TextViewer.java,v 1.5 2006/01/12 17:25:14 hasloe Exp $     * @author $Author: hasloe $     * @version $Revision: 1.5 $     */    private class TextViewerComponentListener extends ComponentAdapter {        /**         * DOCUMENT ME!         *         * @param e DOCUMENT ME!         */        public void componentResized(ComponentEvent e) {            doUpdate();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -