📄 qtsvgviewer.java
字号:
sampleContainer = new AtomContainer(); QTHandle imageHandle = createImageHandleForShape(svgAnn.getShape()); if (imageHandle != null) { Atom spriteSharedDataAtom; Atom spriteImageContainerAtom; Atom spriteImageAtom; Atom spritePropAtom; int spriteID = 1; spriteSharedDataAtom = sampleContainer.insertChild(new Atom( StdQTConstants.kParentAtomIsContainer), StdQTConstants.kSpriteSharedDataAtomType, spriteID, // id 0); //index if (spriteSharedDataAtom == null) { return null; } spriteImageContainerAtom = sampleContainer.insertChild(spriteSharedDataAtom, StdQTConstants.kSpriteImagesContainerAtomType, spriteID, //id 0); //index if (spriteImageContainerAtom == null) { return null; } spriteImageAtom = sampleContainer.insertChild(spriteImageContainerAtom, StdQTConstants.kSpriteImageAtomType, spriteID, //id 0); //index if (spriteImageAtom == null) { return null; } // add data sampleContainer.insertChild(spriteImageAtom, StdQTConstants.kSpriteImageDataAtomType, spriteID, //id 0, //index imageHandle); // add group id?? sampleContainer.insertChild(spriteImageAtom, StdQTConstants.kSpriteImageGroupIDAtomType, spriteID, 0, EndianOrder.flipNativeToBigEndian32(1)); // create properties atom spritePropAtom = sampleContainer.insertChild(new Atom( StdQTConstants.kParentAtomIsContainer), StdQTConstants.kSpriteAtomType, spriteID, //id 0); // setVisible sampleContainer.insertChild(spritePropAtom, StdQTConstants.kSpritePropertyVisible, spriteID, //id 0, EndianOrder.flipNativeToBigEndian16((short) 1)); //1 = visible // imageIndex sampleContainer.insertChild(spritePropAtom, StdQTConstants.kSpritePropertyImageIndex, 1, 0, EndianOrder.flipNativeToBigEndian16((short) (spriteID))); // layer, needed?? sampleContainer.insertChild(spritePropAtom, StdQTConstants.kSpritePropertyLayer, 1, 0, EndianOrder.flipNativeToBigEndian16((short) 0)); // 0 = topmost /* Matrix theMatrix = new Matrix(); theMatrix.setSx(((float)320) / 352); theMatrix.setSy(((float)240) / 288); //theMatrix.setIdentity(); EndianOrder.flipNativeToBigEndian(theMatrix, 0, new EndianDescriptor(EndianDescriptor.kFlipAllFields32)); sampleContainer.insertChild ( spritePropAtom, StdQTConstants.kSpritePropertyMatrix, 1, 0, theMatrix); */ } } catch (QTException qte) { LOG.warning("Could not create sample from annotation"); LOG.warning(LogUtil.formatStackTrace(qte)); } return sampleContainer; } /** * Paints the graphical annotations to an offscreen QDGraphics object, * creates an image from this graphics object and returns it as a QTHandle * object. * * @param shape the graphical annotation * * @return a QTHandle */ private QTHandle createImageHandleForShape(Shape shape) { if (shape == null) { return null; } try { QDGraphics qdg = new QDGraphics(QDGraphics.kDefaultPixelFormat, qtMediaRect); qdg.setForeColor(QD_STROKE_COLOR); QDRect shapeRect; float scaleX = qtMediaRect.getWidthF() / fileMediaRect.getWidth(); float scaleY = qtMediaRect.getHeightF() / fileMediaRect.getHeight(); if (shape instanceof RectangularShape) { RectangularShape rs = (RectangularShape) shape; shapeRect = new QDRect((float) (rs.getX() * scaleX), (float) (rs.getY() * scaleY), (float) (rs.getWidth() * scaleX), (float) (rs.getHeight() * scaleY)); if (shape instanceof Ellipse2D) { qdg.frameOval(shapeRect); } else if (shape instanceof Rectangle2D) { qdg.frameRect(shapeRect); } } else if (shape instanceof Line2D) { Point2D p1 = ((Line2D) shape).getP1(); Point2D p2 = ((Line2D) shape).getP2(); int p1x = (int) (scaleX * p1.getX()); int p1y = (int) (scaleY * p1.getY()); int p2x = (int) (scaleX * p2.getX()); int p2y = (int) (scaleY * p2.getY()); qdg.moveTo(p1x, p1y); qdg.lineTo(p2x, p2y); } PixMap pixmap = PixMap.fromQDGraphics(qdg); EncodedImage encodedImage = pixmap.getPixelData(); ImageDescription imageDescription = new ImageDescription(pixmap); //Endian flip the ImageDescription EndianOrder.flipNativeToBigEndian(imageDescription, 0, ImageDescription.getEndianDescriptor()); return new QTHandle(imageDescription, QTHandle.fromEncodedImage(encodedImage)); } catch (QTException qte) { } return null; } /** * Removes the track corresponding to the tier from the movie. * * @param tierName the tier identifier */ private void removeTrack(String tierName) { if (trackTable.containsKey(tierName)) { Track track = (Track) trackTable.get(tierName); if (track != null) { try { movie.removeTrack(track); track.disposeQTObject(); } catch (StdQTException sqte) { LOG.warning(LogUtil.formatStackTrace(sqte)); } catch (QTException qte) { LOG.warning(LogUtil.formatStackTrace(qte)); } } trackTable.remove(tierName); } } /** * When a tier is set invisible in the multitierviewers don't render the * graphics. * * @param tiers the visible tiers */ public void setVisibleTiers(Vector tiers) { // when it is possible to successfully set the visibility property // of a track implement this method } //////// // acm edit event handling methods ///////// /** * A tier has been added. * * @param tier the new tier */ void tierAdded(TierImpl tier) { createTrackFromTier(tier); requestRepaint(); } /** * A tier has been removed. * * @param tier the removed tier */ void tierRemoved(TierImpl tier) { if ((tier != null) && (tier.getLinguisticType() != null) && tier.getLinguisticType().hasGraphicReferences()) { removeTrack(tier.getName()); } } /** * An annotation has been added.<br> * Creation of an annotation can effect existing annotations on the same * tier and/or dependent tiers. Just reextract the graphic objects from * these tiers. In Shift mode all tiers could be changed, so all tracks * will be recreated in that case. * * @param annotation the new annotation */ void annotationAdded(SVGAlignableAnnotation annotation) { if (annotation != null) { int mode = transcription.getTimeChangePropagationMode(); if (mode != Transcription.SHIFT) { TierImpl tier = (TierImpl) annotation.getTier(); Vector depTiers = tier.getDependentTiers(); depTiers.add(0, tier); for (int i = 0; i < depTiers.size(); i++) { tier = (TierImpl) depTiers.get(i); createTrackFromTier(tier); } } else { transcriptionChanged(); } requestRepaint(); } } /** * Check every currently present tier with graphical annotations. We could * assume no tiers have been added and no tiers have been removed. There * are other events for that kind of actions. Doublecheck to be sure. */ void transcriptionChanged() { Vector tiers = transcription.getTiers(); TierImpl tier; for (int i = 0; i < tiers.size(); i++) { tier = (TierImpl) tiers.get(i); createTrackFromTier(tier); } requestRepaint(); } /** * Checks if the linguistic type of any of the current tiers with graphic * references has been changed to not allow graphic references. */ void linguisticTypeChanged() { LinguisticType type; Vector tiers = transcription.getTiers(); TierImpl tier; String tierName; for (int i = 0; i < tiers.size(); i++) { tier = (TierImpl) tiers.get(i); tierName = tier.getName(); type = tier.getLinguisticType(); if ((type != null) && type.hasGraphicReferences()) { if (!trackTable.containsKey(tierName)) { createTrackFromTier(tier); } } else { if (trackTable.containsKey(tierName)) { removeTrack(tierName); } } } requestRepaint(); } /** * An annotation's begin and/or end time has changed. Changing the begin * and/or end time of an annotation can effect existing annotations on * the same tier and/or dependent tiers. Just reextract the graphic * objects from these tiers. In Shift mode all tiers could be changed, so * all tracks will be recreated in that case. * * @param annotation the annotation */ void annotationTimeChanged(SVGAlignableAnnotation annotation) { if (annotation != null) { int mode = transcription.getTimeChangePropagationMode(); if (mode != Transcription.SHIFT) { TierImpl tier = (TierImpl) annotation.getTier(); Vector depTiers = tier.getDependentTiers(); depTiers.add(0, tier); for (int i = 0; i < depTiers.size(); i++) { tier = (TierImpl) depTiers.get(i); createTrackFromTier(tier); } } else { transcriptionChanged(); return; } requestRepaint(); } } /** * A graphic object has been edited. * * @param annotation the edited annotation */ void annotationGraphicChanged(SVGAlignableAnnotation annotation) { if (annotation != null) { // we could update a single atom... TierImpl tier = (TierImpl) annotation.getTier(); createTrackFromTier(tier); requestRepaint(); } } /** * Creates the Sprite tracks for each tier referencing graphic annotations. */ void requestRepaint() { if (movie != null) { try { movie.update(); } catch (QTException qte) { //ignore } } } /** * Stub. Ignored by this viewer. Rendering of the annotations is handled by * the QT player. * * @param big2d the graphics object provided by the player */ void paintAnnotations(Graphics2D big2d) { } /** * Stub. Ignored by this viewer. Rendering of the annotations is handled by * the QT player. */ void paintAnnotations() { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -