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

📄 timelineviewer.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    /**     * Retrieves the default, platform specific width of a scrollbar.     *     * @return the default width, or 20 when not found     */    private int getDefaultBarWidth() {        int width = 20;        if (UIManager.getDefaults().get("ScrollBar.width") != null) {            width = ((Integer) (UIManager.getDefaults().get("ScrollBar.width"))).intValue();        }        return width;    }    /**     * Initialise tiers and tags.     */    private void initTiers() {        allTiers = new ArrayList(20);        visibleTiers = new ArrayList(allTiers.size());        if (transcription == null) {            tierYPositions = new int[0];            return;        }        extractTiers();        tierYPositions = new int[allTiers.size()];        //allTiers is filled, set all tiers visible        // not neccessary anymore        /*           Iterator it = allTiers.iterator();           while(it.hasNext()) {               visibleTiers.add(it.next());           }         */    }    /**     * Extract all Tiers from the Transcription. Store the information in     * Tier2D and Tag2D objects.     */    private void extractTiers() {        Tier2D tier2d;        Iterator tierIter = transcription.getTiers().iterator();        while (tierIter.hasNext()) {            TierImpl tier = (TierImpl) tierIter.next();            tier2d = createTier2D(tier);            allTiers.add(tier2d);        }    }    private Tier2D createTier2D(TierImpl tier) {        Tier2D tier2d = new Tier2D(tier);        Tag2D tag2d;        int xPos;        int tagWidth;        Iterator annotIter = tier.getAnnotations().iterator();        while (annotIter.hasNext()) {            Annotation a = (Annotation) annotIter.next();            //System.out.println("Annotation: " + a);            tag2d = new Tag2D(a);            xPos = timeToPixels(a.getBeginTimeBoundary());            tag2d.setX(xPos);            tagWidth = timeToPixels(a.getEndTimeBoundary()) - xPos;            tag2d.setWidth(tagWidth);            tag2d.setTruncatedValue(truncateString(a.getValue(), tagWidth,                    metrics));            tier2d.addTag(tag2d);            if (a == getActiveAnnotation()) {                cursorTag2D = tag2d;            }        }        return tier2d;    }    /**     * When the resolution or zoom level of the viewer has been changed the     * Tag2D x position, width and truncated string value needs to be     * recalculated.     */    private void recalculateTagSizes() {        Tier2D tier2d;        Tag2D tag2d;        int xPos;        int tagWidth;        Iterator tierIt = allTiers.iterator();        while (tierIt.hasNext()) {            tier2d = (Tier2D) tierIt.next();            Iterator tagIt = tier2d.getTags();            while (tagIt.hasNext()) {                tag2d = (Tag2D) tagIt.next();                xPos = timeToPixels(tag2d.getBeginTime());                tag2d.setX(xPos);                tagWidth = timeToPixels(tag2d.getEndTime()) - xPos;                tag2d.setWidth(tagWidth);                tag2d.setTruncatedValue(truncateString(tag2d.getValue(),                        tagWidth, metrics));            }        }    }    /**     * Re-processes the annotations of a tier.<br>     * Necessary after removal of an unknown number of annotations.     *     * @param tier2d the Tier2D     */    private void reextractTagsForTier(Tier2D tier2d) {        if ((transcription == null) || (tier2d == null)) {            return;        }        //int index = transcription.getTiers(userIdentity).indexOf(tier2d.getTier());        //TierImpl tier = null;        //if (index > -1) {        //    tier = (TierImpl) transcription.getTiers(userIdentity).get(index);        //}        TierImpl tier = tier2d.getTier();        if (tier == null) {            return;        }        tier2d.getTagsList().clear();        Tag2D tag2d;        int xPos;        int tagWidth;        Iterator annotIter = tier.getAnnotations().iterator();        while (annotIter.hasNext()) {            Annotation a = (Annotation) annotIter.next();            //System.out.println("Annotation: " + a);            tag2d = new Tag2D(a);            xPos = timeToPixels(a.getBeginTimeBoundary());            tag2d.setX(xPos);            tagWidth = timeToPixels(a.getEndTimeBoundary()) - xPos;            tag2d.setWidth(tagWidth);            tag2d.setTruncatedValue(truncateString(a.getValue(), tagWidth,                    metrics));            tier2d.addTag(tag2d);            if (a == getActiveAnnotation()) {                cursorTag2D = tag2d;            }        }    }    /**     * Create a truncated String of a tag's value to display in the viewer.     *     * @param string the tag's value     * @param width the available width for the String     * @param fMetrics the font metrics     *     * @return the truncated String     */    private String truncateString(String string, int width, FontMetrics fMetrics) {        String line = string.replace('\n', ' ');        if (fMetrics != null) {            int stringWidth = fMetrics.stringWidth(line);            if (stringWidth > (width - 4)) { // truncate                int i = 0;                String s = "";                int size = line.length();                while (i < size) {                    if (fMetrics.stringWidth(s) > (width - 4)) {                        break;                    } else {                        s = s + line.charAt(i++);                    }                }                if (!s.equals("")) {                    line = s.substring(0, s.length() - 1);                } else {                    line = s;                }            }        }        return line;    }    /**     * Paint to a buffer.<br>     * First paint the top ruler, next the current selection and finally paint     * the tags of the visible tiers.     */    private void paintBuffer() {        if (!useBufferedImage && /*!playerIsPlaying()*/                !isPlaying) {            repaint();            return;        }        if ((getWidth() <= 0) || (getHeight() <= 0)) {            return;        }        if (((getWidth() - defBarWidth) != imageWidth) ||                (imageHeight != ((visibleTiers.size() * pixelsForTierHeight) +                rulerHeight))) {            imageWidth = getWidth() - defBarWidth;            imageHeight = (visibleTiers.size() * pixelsForTierHeight) +                rulerHeight;            if ((imageWidth <= 0) || (imageHeight <= 0)) {                return;            }            intervalEndTime = intervalBeginTime +                (int) (imageWidth * msPerPixel);            if (timeScaleConnected) {                setGlobalTimeScaleIntervalEndTime(intervalEndTime);            }        }        if ((bi == null) || (bi.getWidth() < imageWidth) ||                (bi.getHeight() < imageHeight)) {            bi = new BufferedImage(imageWidth, imageHeight,                    BufferedImage.TYPE_INT_RGB);            big2d = bi.createGraphics();        }        if (bi.getHeight() > imageHeight) {            imageHeight = bi.getHeight();        }        //big2d.setFont(font);        big2d.setColor(Constants.DEFAULTBACKGROUNDCOLOR);        big2d.fillRect(0, 0, imageWidth, bi.getHeight());        // mark the area beyond the media time        int xx = xAt(getMediaDuration());        if (intervalEndTime > getMediaDuration()) {            big2d.setColor(Color.LIGHT_GRAY);            big2d.drawLine(xx, 0, xx, bi.getHeight());            big2d.setColor(UIManager.getColor("Panel.background"));            big2d.fillRect(xx + 1, 0, imageWidth - xx, bi.getHeight());        }        /*paint time ruler */        big2d.setColor(Constants.DEFAULTFOREGROUNDCOLOR);        big2d.translate(-(intervalBeginTime / msPerPixel), 0.0);        ruler.paint(big2d, intervalBeginTime, imageWidth, msPerPixel,            SwingConstants.TOP);        big2d.setFont(font);        ///end ruler        // paint a slightly dif. background color for every other tier        int y = rulerHeight;        int ax = timeToPixels(intervalBeginTime);        big2d.setColor(Constants.LIGHTBACKGROUNDCOLOR);        for (int i = 0; i < visibleTiers.size(); i++) {            if ((i % 2) != 0) {                big2d.fillRect(ax, y + (i * pixelsForTierHeight),                    imageWidth - (imageWidth - xx), pixelsForTierHeight);            }        }        //paint selection        if (selectionBeginPos != selectionEndPos) {            int beginPos = timeToPixels(getSelectionBeginTime());            int endPos = timeToPixels(getSelectionEndTime());            big2d.setColor(Constants.SELECTIONCOLOR);            big2d.setComposite(alpha04);            big2d.fillRect(beginPos, 0, (endPos - beginPos), rulerHeight);            big2d.setComposite(AlphaComposite.Src);            big2d.fillRect(beginPos, rulerHeight, (endPos - beginPos),                imageHeight - rulerHeight);        }        // paint tags        //int x;        //int w;        int h = pixelsForTierHeight - (2 * pixelsForTierHeightMargin);        Tier2D tier2d;        Tag2D tag2d;        synchronized (tierLock) {            Iterator visIt = visibleTiers.iterator();            int count = 0;            while (visIt.hasNext()) {                tier2d = (Tier2D) visIt.next();                count++;                if (tier2d.isActive()) {                    big2d.setColor(Constants.ACTIVETIERCOLOR);                    big2d.setComposite(alpha07);                    big2d.fillRect(ax, y, imageWidth, pixelsForTierHeight);                    big2d.setComposite(AlphaComposite.Src);                }                Iterator tagIt = tier2d.getTags();                while (tagIt.hasNext()) {                    tag2d = (Tag2D) tagIt.next();                    if (tag2d.getEndTime() < intervalBeginTime) {                        continue; //don't paint                    } else if (tag2d.getBeginTime() > intervalEndTime) {                        break; // stop looping this tier                    }                    //paint tag at this position                    paintTag(big2d, tag2d, tag2d.getX(),                        y + pixelsForTierHeightMargin, tag2d.getWidth(), h);                }                y += pixelsForTierHeight;            }        }        // end paint tags        big2d.setTransform(new AffineTransform()); //reset transform        //big2d.dispose(); // does not work properly in jdk 1.4        repaint();    }    /**     * Override <code>JComponent</code>'s paintComponent to paint:<br>     * - a BufferedImage with a ruler, the selection and the tags<br>     * - the current selection Tag<br>     * - the "mouse over" Tag<br>     * - the time ruler when rulerAlwaysVisible is true<br>     * - the cursor / crosshair - empty slots - the drag edit tag     *     * @param g the graphics object     */    public void paintComponent(Graphics g) {        super.paintComponent(g);        Graphics2D g2d = (Graphics2D) g;        if (!useBufferedImage && /*!playerIsPlaying()*/                !isPlaying) {            paintUnbuffered(g2d);            return;        }        int h = getHeight();        // scrolling related fill        g2d.setColor(Constants.DEFAULTBACKGROUNDCOLOR);        g2d.fillRect(0, 0, imageWidth, h);        if (bi != null) {            g2d.translate(0, -verticalScrollOffset);            //paint selection in the part not occupied by the image            if ((selectionBeginPos != selectionEndPos) && (bi.getHeight() < h)) {                g2d.setColor(Constants.SELECTIONCOLOR);                g2d.fillRect(selectionBeginPos, 0,                    (selectionEndPos - selectionBeginPos), h);            }            g2d.drawImage(bi, 0, 0, this);

⌨️ 快捷键说明

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