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

📄 abstractsvgviewer.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     AbstractSVGViewer.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package mpi.eudico.client.annotator.svg;import mpi.eudico.client.annotator.viewer.AbstractViewer;import mpi.eudico.client.annotator.viewer.MultiTierControlPanel;import mpi.eudico.client.annotator.viewer.MultiTierViewer;import mpi.eudico.client.mediacontrol.ControllerEvent;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clom.Tier;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.SVGAlignableAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.type.LinguisticType;import mpi.eudico.server.corpora.util.ACMEditEvent;import mpi.eudico.server.corpora.util.ACMEditListener;import java.awt.Color;import java.awt.Graphics2D;import java.util.ArrayList;import java.util.Collections;import java.util.Iterator;import java.util.Vector;/** * An abstract class that handles (part of) the managing of svg annotations. * * @author Han Sloetjes * @version july 2004 * @version Aug 2005 Identity removed */public abstract class AbstractSVGViewer extends AbstractViewer    implements MultiTierViewer, ACMEditListener {    /** the transcription */    Transcription transcription;    /** list that contains the graphic tiers */    ArrayList allGraphicTiers;    /** the color to use for the stroke of 2d annotations */    public final Color STROKE_COLOR = Color.red;    /**     * Creates a new AbstractSVGViewer instance     *     * @param transcription the transcription     */    public AbstractSVGViewer(Transcription transcription) {        this.transcription = transcription;        // parse the svg file        SVGParserAndStore.parse(transcription);        allGraphicTiers = new ArrayList();        initViewer();    }    /**     * Initializes the viewer by extracting the graphical annotations.     */    void initViewer() {        TierImpl tier;        GraphicTier2D tier2d;        Iterator tierIt = transcription.getTiers().iterator();        while (tierIt.hasNext()) {            tier = (TierImpl) tierIt.next();            tier2d = createTier2D(tier);            if (tier2d != null) {                allGraphicTiers.add(tier2d);            }        }    }    /**     * Extract tiers with graphic annotations and create Graphic nodes from     * these annotations.     *     * @param tier the tier to examine     *     * @return a GraphicsTier2D     */    GraphicTier2D createTier2D(TierImpl tier) {        if ((tier == null) || (tier.getLinguisticType() == null) ||                !tier.getLinguisticType().hasGraphicReferences()) {            return null;        }        GraphicTier2D tier2d = new GraphicTier2D(tier);        Vector annotations = tier.getAnnotations();        Iterator annIt = annotations.iterator();        Annotation a;        SVGAlignableAnnotation ann;        while (annIt.hasNext()) {            a = (Annotation) annIt.next();            if (!(a instanceof SVGAlignableAnnotation)) {                break;            }            ann = (SVGAlignableAnnotation) a;            if (ann.getShape() != null) {                GraphicNode2D node2d = new GraphicNode2D(ann, ann.getShape());                tier2d.insertNode(node2d);            }        }        return tier2d;    }    /**     * Update the active annotation.     */    public void updateActiveAnnotation() {    }    /**     * When a tier is set invisible in the multitierviewers don't render the     * graphics.     *     * @param tiers the visible tiers     */    public void setVisibleTiers(Vector tiers) {        GraphicTier2D tier2d;        for (int i = 0; i < allGraphicTiers.size(); i++) {            tier2d = (GraphicTier2D) allGraphicTiers.get(i);            if (tiers.contains(tier2d.getTier())) {                tier2d.setVisible(true);            } else {                tier2d.setVisible(false);            }        }        requestRepaint();    }    //////////    // acm edit event handling methods    /////////    /**     * A tier has been added.     *     * @param tier the new tier     */    void tierAdded(TierImpl tier) {        GraphicTier2D tier2d = createTier2D(tier);        if (tier2d != null) {            allGraphicTiers.add(tier2d);            requestRepaint();        }    }    /**     * A tier has been removed.     *     * @param tier the removed tier     */    void tierRemoved(TierImpl tier) {        if ((tier != null) && (tier.getLinguisticType() != null) &&                tier.getLinguisticType().hasGraphicReferences()) {            GraphicTier2D tier2d = null;            for (int i = 0; i < allGraphicTiers.size(); i++) {                tier2d = (GraphicTier2D) allGraphicTiers.get(i);                if (tier2d.getTier() == tier) {                    allGraphicTiers.remove(i);                    requestRepaint();                    return;                }            }        }    }    /**     * 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();                GraphicTier2D tier2d = null;                for (int i = 0; i < allGraphicTiers.size(); i++) {                    tier2d = (GraphicTier2D) allGraphicTiers.get(i);                    if ((tier2d.getTier() == tier) ||                            depTiers.contains(tier2d.getTier())) {                        reextractNodesForTier2D(tier2d);                    }                }            } else {                transcriptionChanged();                return;            }            /*               if (tier2d != null) {                   //String svgId = annotation.getSVGElementID();                   if (annotation.getShape() != null) {                       GraphicNode2D node2d = new GraphicNode2D(annotation,                               annotation.getShape());                       tier2d.insertNode(node2d);                   }                   requestRepaint();               }             */            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();        GraphicTier2D tier2d;        for (int i = 0; i < allGraphicTiers.size(); i++) {            tier2d = (GraphicTier2D) allGraphicTiers.get(i);            if (tiers.contains(tier2d.getTier())) {                reextractNodesForTier2D(tier2d);            }        }        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() {        GraphicTier2D tier2d;        LinguisticType type;        Vector tiers = transcription.getTiers();        TierImpl tier;        for (int i = 0; i < tiers.size(); i++) {            tier = (TierImpl) tiers.get(i);            type = tier.getLinguisticType();            if ((type != null) && type.hasGraphicReferences()) {                boolean alreadyThere = false;                for (int j = 0; j < allGraphicTiers.size(); j++) {                    tier2d = (GraphicTier2D) allGraphicTiers.get(j);                    if (tier2d.getTier() == tier) {                        alreadyThere = true;                        break;                    }                }

⌨️ 快捷键说明

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