interlinearviewer.java
来自「编辑视频文件」· Java 代码 · 共 2,005 行 · 第 1/5 页
JAVA
2,005 行
barWidth = ((Integer)(UIManager.getDefaults().get("ScrollBar.width"))).intValue(); } else { barWidth = 0; } } */ int width = currentSegmentWidth + HOR_TAG_GAP; int height = VER_MARGIN + (visibleTiers.size() * pixelsForTierHeight); /* this only changes the image size when it is to small, * not when it is larger than needed */ if ((imageWidth < width) && (width < MAX_BUF_WIDTH)) { imageWidth = width; } if (imageHeight < height) { imageHeight = height; } // Paint it off screen first if ((bi == null) || (bi.getWidth() < imageWidth) || (bi.getHeight() < imageHeight)) { bi = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); g2d = bi.createGraphics(); } g2d.setFont(getFont()); g2d.setColor(Constants.DEFAULTBACKGROUNDCOLOR); g2d.fillRect(0, 0, imageWidth, bi.getHeight()); Tier2D tier2d; // two painting strategies if (currentSegmentWidth > MAX_BUF_WIDTH) { // use the hor. scroll offset to paint in the buffer g2d.translate(-horizontalScrollOffset, 0); for (int i = 0; i < visibleTiers.size(); i++) { tier2d = (Tier2D) visibleTiers.get(i); if (tier2d.isActive()) { g2d.setColor(Constants.ACTIVETIERCOLOR); g2d.fillRect(horizontalScrollOffset, VER_MARGIN + (i * pixelsForTierHeight), imageWidth, pixelsForTierHeight); } if (i < _vTiers.size()) { Iterator tagIt = ((Vector) _vTiers.get(i)).iterator(); while (tagIt.hasNext()) { SBTime sbt = (SBTime) tagIt.next(); if ((sbt._rect.x + sbt._rect.width) < horizontalScrollOffset) { continue; } else if (sbt._rect.x > (horizontalScrollOffset + getWidth())) { break; } drawTag(g2d, sbt); } } } g2d.translate(horizontalScrollOffset, 0); } else { // paint all in the buffer, paintComponent will handle offsets for (int i = 0; i < visibleTiers.size(); i++) { tier2d = (Tier2D) visibleTiers.get(i); if (tier2d.isActive()) { g2d.setColor(Constants.ACTIVETIERCOLOR); g2d.fillRect(0, VER_MARGIN + (i * pixelsForTierHeight), imageWidth, pixelsForTierHeight); } if (i < _vTiers.size()) { Iterator tagIt = ((Vector) _vTiers.get(i)).iterator(); while (tagIt.hasNext()) { SBTime sbt = (SBTime) tagIt.next(); drawTag(g2d, sbt); } } } } repaint(); } /** * Draws the value of a Tag to the specified Graphics object. * * @param g the Graphics object to render to * @param tag the SBTime (tag) to render */ protected void drawTag(Graphics2D g, SBTime tag) { if (tag != null) { //g.drawString(tag.value, tag._rect.x, tag._rect.y + 2 * tag._rect.height / 3); // draw a marker when there is an annotation, but no text if ((tag.annotation != null) && (tag.value.length() == 0)) { g.setColor(Color.gray); g.draw(tag._rect); } // g.setColor(Constants.DEFAULTFOREGROUNDCOLOR); g.drawString(tag.value, tag._rect.x, tag._rect.y + (tag._rect.height / 2) + (getFont().getSize() / 2)); } } /** * Overrides <code>JComponent</code>'s paintComponent to paint:<br> * - a Buffered Image with all the current tag values<br> * - a marker for the current selection - a "mouse over" marker * * Mar 2006: Added alternative painting strategy in case the complete interlinear image does not fit * in the buffer; the buffer contains only part of the block and is painted at x = 0; * * @param g the Graphics context */ public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setColor(Constants.DEFAULTBACKGROUNDCOLOR); g2.fillRect(0, 0, getWidth(), getHeight()); if (currentSegmentWidth > MAX_BUF_WIDTH) { g2.translate(0, -verticalScrollOffset); // alternative paint strategy } else { g2.translate(-horizontalScrollOffset, -verticalScrollOffset); } if (bi != null) { g2.drawImage(bi, 0, 0, this); } else { return; } if (currentSegmentWidth > MAX_BUF_WIDTH) { g2.translate(-horizontalScrollOffset, 0); } if (selSTime != selETime) { paintSelectionMarker(g2); } /* if (curSBSelection != null && !playerIsPlaying()) { //AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.4f); //g2.setComposite(ac); Rectangle rect = curSBSelection._rect; g2.setColor(Constants.SHAREDCOLOR3); g2.fillRect(rect.x, rect.y, rect.width, rect.height); g2.setColor(Constants.SHAREDCOLOR4); g2.fillRect(rect.x, rect.y, rect.width - 1, rect.height - 1); drawTag(g2, curSBSelection); //g2.setComposite(AlphaComposite.Src); } */ // if (!playerIsPlaying()) { paintMediaTimeMarker(g2); if (showEmptySlots) { for (int i = 0; i < visibleTiers.size(); i++) { TierImpl ti = ((Tier2D) visibleTiers.get(i)).getTier(); if (ti.getParentTier() == null) { continue; } else { if (!ti.isTimeAlignable()) { paintEmptySlots(g2, ti, i); } } } } } if ((cursorTag != null) && (sbl.getRefAnn() == refAnnotation)) { g2.setColor(Constants.ACTIVEANNOTATIONCOLOR); g2.draw(cursorTag._rect); } g2.translate(horizontalScrollOffset, verticalScrollOffset); } /** * Paints the selected tags in a different color in order to visually * distinguish them from the other tags.<br> * <b>Note:</b> removed the Collections.binarySearch method. It fails when * the tier contains empty tags, tags without an annotation, or tags were * start time = -1. These tags ruin the "natural ordering" necessary for * the binary search algorithm. * * @param g2 the Graphics object to render to */ private void paintSelectionMarker(Graphics2D g2) { Enumeration enm = _vTiers.elements(); while (enm.hasMoreElements()) { Vector ht = (Vector) enm.nextElement(); if (ht == null) { continue; } Enumeration e = ht.elements();tagloop: while (e.hasMoreElements()) { SBTime sbt = (SBTime) e.nextElement(); if (sbt.startt == -1) { continue; } // if (((sbt.startt <= selSTime) && (sbt.endt > selSTime)) || ((sbt.startt >= selSTime) && (sbt.endt < selETime)) || ((sbt.startt < selETime) && (sbt.endt >= selETime))) { Rectangle rect = sbt._rect; if (rect != null) { g2.setColor(Constants.SELECTIONCOLOR); g2.fill(rect); drawTag(g2, sbt); } int pos = ht.indexOf(sbt); for (int i = pos + 1; i < ht.size(); i++) { sbt = (SBTime) ht.get(i); if (sbt.startt >= selETime) { break tagloop; } rect = sbt._rect; if ((rect != null) && (sbt.startt != -1)) { g2.setColor(Constants.SELECTIONCOLOR); g2.fill(rect); drawTag(g2, sbt); } } } // } } } /** * Determines whether to repaint or not.<br> * Sets alpha rect over ann's at current time. * * @return DOCUMENT ME! */ public boolean shouldPaint() { if (getMediaTime() != curSTime) { return true; } return false; } /** * Paints the a marker to visually distinguish the tags at the current * media time. <b>Note:</b> removed the Collections.binarySearch method. * It fails when the tier contains empty tags, tags without an annotation, * or tags were start time = -1. These tags ruin the "natural ordering" * necessary for the binary search algorithm. * * @param g2 the Graphics object to render to */ public void paintMediaTimeMarker(Graphics2D g2) { Enumeration enm = _vTiers.elements(); while (enm.hasMoreElements()) { Vector ht = (Vector) enm.nextElement(); // This could be improved maybe by using the method the the TimeLineControllers use!. // ie: assume time moves forward - get current position and search from that point forward if (ht == null) { continue; } Enumeration e = ht.elements(); while (e.hasMoreElements()) { SBTime sbt = (SBTime) e.nextElement(); if (sbt.startt == -1) { continue; } if ((sbt.startt <= getMediaTime()) && (sbt.endt > getMediaTime())) { g2.setColor(Constants.CROSSHAIRCOLOR); Rectangle rect = sbt._rect; curSTime = sbt.startt; if (rect != null) { g2.drawRect(rect.x, rect.y, rect.width, rect.height); } break; } } } } /** * Paint empty slots on this tier.<br> * Look for SBTime objects with annotation == null and start time == end * time. * * @param g2d the graphics context * @param tier the tier to check for empty slots * @param tierIndex the index of the tier */ private void paintEmptySlots(Graphics2D g2d, TierImpl tier, int tierIndex) { if (tierIndex >= _vTiers.size()) { return; } //try { Iterator tagIt = ((Vector) _vTiers.get(tierIndex)).iterator(); TierImpl parent = (TierImpl) tier.getParentTier(); SBTime sbt; while (tagIt.hasNext()) { sbt = (SBTime) tagIt.next(); if ((sbt.annotation == null) && (sbt.startt != -1)) { /* sbt start and end are the same add 1ms to the start time to prevent finding the previous annotation on the parent tier (prev annotation end == this annotation begin) */ if (parent.getAnnotationAtTime(sbt.startt + 1) != null) { g2d.setColor(Constants.SHAREDCOLOR4); g2d.fill(sbt._rect); g2d.setColor(Constants.DEFAULTFOREGROUNDCOLOR); g2d.draw(sbt._rect); } } } //} catch (RemoteException rex) { //rex.printStackTrace(); //} } /** * Returns the Tier object at a certain point in the image. * * @param p the point to find the Tier for * * @return the Tier at Point p */ private Tier2D getTierAtPoint(Point p) { Point pp = new Point(p); pp.y += verticalScrollOffset; int index = getTierIndexForPoint(pp); if ((index < 0) || (index >= visibleTiers.size())) { return null; } return (Tier2D) visibleTiers.get(index); } /** * Calculate the index in the visible tiers array for the given y * coordinate. Vertical scroll offset is not taken into account in this * method! * * @param p DOCUMENT ME! * * @return the index of the tier or -1 when not found */ private int getTierIndexForPoint(Point p) { int y = (int) p.getY() - VER_MARGIN; if ((y < 0) || (y > (_vTiers.size() * pixelsForTierHeight))) { return -1; } else { return y / pixelsForTierHeight; } } /**
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?