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

📄 interlinearviewer.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * File:     InterlinearViewer.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.viewer;import mpi.eudico.client.annotator.Constants;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.commands.Command;import mpi.eudico.client.annotator.commands.ELANCommandFactory;import mpi.eudico.client.annotator.gui.EditTierDialog;import mpi.eudico.client.annotator.gui.InlineEditBox;import mpi.eudico.client.annotator.util.Tier2D;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.RefAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.shoebox.AnnotationSize;import mpi.eudico.server.corpora.clomimpl.shoebox.AnnotationSizeContainer;import mpi.eudico.server.corpora.clomimpl.shoebox.SBLayout;import mpi.eudico.server.corpora.clomimpl.type.Constraint;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.BasicStroke;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.Point;import java.awt.Rectangle;import java.awt.Toolkit;import java.awt.Window;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.AdjustmentEvent;import java.awt.event.AdjustmentListener;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.MouseWheelEvent;import java.awt.event.MouseWheelListener;import java.awt.image.BufferedImage;import java.util.ArrayList;import java.util.Collections;import java.util.Enumeration;import java.util.Iterator;import java.util.Vector;import javax.swing.BorderFactory;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.JRadioButtonMenuItem;import javax.swing.JScrollBar;import javax.swing.SwingUtilities;import javax.swing.UIManager;/** * This viewer shows annotations of multiple tiers. The annotations are not * abbreviated and they are not displayed relative to some kind of time scale. * @version Aug 2005 Identity removed */public class InterlinearViewer extends AbstractViewer    implements ComponentListener, MouseMotionListener, MouseListener,        MouseWheelListener, MultiTierViewer, AdjustmentListener, ActionListener,        KeyListener, ACMEditListener {    private Transcription transcription = null;    private SBLayout sbl = null;    /** Holds value of property DOCUMENT ME! */    protected int pixelsForTierHeight;    /** Holds value of property DOCUMENT ME! */    protected int pixelsForTierHeightMargin;    private BufferedImage bi;    private Graphics2D g2d;    private FontMetrics currentMetrics;    private BasicStroke stroke;    private JButton prevButton;    private JButton nextButton;    private JPopupMenu popup;    private ButtonGroup fontSizeBG;    private JMenu fontMenu;    // menu items that can be enabled / disabled    private JMenuItem newAnnoMI;    private JMenuItem newAnnoBeforeMI;    private JMenuItem newAnnoAfterMI;    private JMenuItem modifyAnnoMI;    //private JMenuItem modifyAnnoTimeMI;    private JMenuItem deleteAnnoMI;    private JMenuItem activeTierMI;    private JMenuItem deleteTierMI;    private JMenuItem changeTierMI;    private long selSTime;    private long selETime;    private long curSTime = -1;    private long curETime;    private SBTime curSBSelection = null;    private SBTime cursorTag = null;    private Annotation refAnnotation = null;    private Annotation activeAnnotation = null;    private int imageWidth = 1200;    private int imageHeight = 380;    /** Holds value of property DOCUMENT ME! */    private final int HOR_TAG_GAP = 20;    /** Holds value of property DOCUMENT ME! */    private final int VER_MARGIN;    /** Holds value of property DOCUMENT ME! */    private final int HOR_TAG_SURPLUS = 5;    /** Holds value of property DOCUMENT ME! */    private final int MIN_TAG_SIZE = 15;    // a vector of vectors each vector elem represents a tier    // and stores SBTime objects    private Vector _vTiers = new Vector();    private ArrayList allTiers;    private int currentSegmentWidth;    // treated as a constant, but not final for rare occasion where the width on screen     // is greater than the default (initial) value of 3000    private int MAX_BUF_WIDTH = 3000;    // ar    private ArrayList visibleTiers;    private JPanel buttonPanel;    private JScrollBar vScrollBar;    private JScrollBar hScrollBar;    /** Holds value of property DOCUMENT ME! */    private final int defBarWidth;    private int horizontalScrollOffset;    private int verticalScrollOffset;    private MultiTierControlPanel multiTierControlPanel;    private int[] tierYPositions;    private boolean showEmptySlots;    private long rightClickTime;    private int rightClickTierIndex;    private Tier2D rightClickTier;    private SBTime rightClickTag;    // editing    private InlineEditBox editBox;    /**     * Constructs an InterLinearViewer using the specified user identity and     * transcription.     *     * @param transcription the transcription containing the data for the     *        viewer     */    public InterlinearViewer(Transcription transcription) {        this.transcription = transcription;        setFont(Constants.DEFAULTFONT);        currentMetrics = getFontMetrics(getFont());        // pixelsForTierHeight = getFont().getSize() * 3;        pixelsForTierHeight = getFont().getSize() + 24;        pixelsForTierHeightMargin = 2;        stroke = new BasicStroke();        initTiers();        sbl = new SBLayout(transcription);        sbl.getSegOrder();        sbl.getPrevRef();        //M_P Outcommented because of template files        //				if (allTiers.size() > 0) {        //					sbl.setWorkingSegmentsRange(1,0);        //				}        //enableEvents removed because of problems hiding a popup menu after a click on this component        addMouseMotionListener(this);        addMouseListener(this);        addMouseWheelListener(this);        addKeyListener(this);        addComponentListener(this);        defBarWidth = getDefaultBarWidth();        hScrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 10, 0, imageWidth);        hScrollBar.setUnitIncrement(10);        hScrollBar.setBlockIncrement(50);        hScrollBar.addAdjustmentListener(this);        vScrollBar = new JScrollBar(JScrollBar.VERTICAL, 0, 10, 0, imageHeight);        vScrollBar.setUnitIncrement(pixelsForTierHeight / 2);        vScrollBar.setBlockIncrement(pixelsForTierHeight);        vScrollBar.addAdjustmentListener(this);        //setLayout(new BorderLayout());        //add(hScrollBar, BorderLayout.SOUTH);        //add(vScrollBar, BorderLayout.EAST);        setLayout(null);        add(hScrollBar);        add(vScrollBar);        buttonPanel = createButtonPanel();        //add(buttonPanel, BorderLayout.NORTH);        add(buttonPanel);        if (buttonPanel.getPreferredSize() != null) {            VER_MARGIN = buttonPanel.getPreferredSize().height;        } else {            VER_MARGIN = 32;        }        horizontalScrollOffset = 0;        verticalScrollOffset = 0;        editBox = new InlineEditBox(true);        editBox.setVisible(false);        add(editBox);        extractCurrentSegment();    }    /**     * 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;    }    private JPanel createButtonPanel() {        JPanel panel = new JPanel(new GridBagLayout());        panel.setFocusable(false);        prevButton = new JButton();        prevButton.setText(ElanLocale.getString(                "InterlinearViewer.PrevButton.Text"));        prevButton.setToolTipText(ElanLocale.getString(                "InterlinearViewer.PrevButton.Tooltip"));        prevButton.setActionCommand("prev");        prevButton.addActionListener(this);        prevButton.setFocusable(false);        nextButton = new JButton();        nextButton.setText(ElanLocale.getString(                "InterlinearViewer.NextButton.Text"));        nextButton.setToolTipText(ElanLocale.getString(                "InterlinearViewer.NextButton.Tooltip"));        nextButton.setActionCommand("next");        nextButton.addActionListener(this);        nextButton.setFocusable(false);        Insets inset = new Insets(2, 6, 2, 6);        GridBagConstraints gbc = new GridBagConstraints();        gbc.gridx = 0;        gbc.gridy = 0;        gbc.gridwidth = 1;        gbc.gridheight = 1;        gbc.anchor = GridBagConstraints.WEST;        gbc.fill = GridBagConstraints.NONE;        gbc.insets = inset;        panel.add(prevButton, gbc);        gbc.gridx = 1;        panel.add(nextButton, gbc);        JPanel spacer = new JPanel();        spacer.setBackground(Constants.DEFAULTBACKGROUNDCOLOR);        spacer.setFocusable(false);        gbc.gridx = 2;        gbc.weightx = 1.0;        gbc.fill = GridBagConstraints.HORIZONTAL;        panel.add(spacer, gbc);        int w = Toolkit.getDefaultToolkit().getScreenSize().width;        panel.setPreferredSize(new Dimension(w,                prevButton.getPreferredSize().height + 4));        panel.setBackground(Constants.DEFAULTBACKGROUNDCOLOR);        panel.setBorder(BorderFactory.createLineBorder(Constants.SELECTIONCOLOR));        return panel;    }    /**     * Extract the Tiers from the annotation.<br>     * Store Tier2D objects in the ArrayList of all Tiers and in the ArrayList     * of visible tiers. There are other collections for storing all     * information from the annotations.     */    private void initTiers() {        Tier2D tier2d;        allTiers = new ArrayList(10);        visibleTiers = new ArrayList(10);        Iterator tierIt = transcription.getTiers().iterator();        while (tierIt.hasNext()) {            TierImpl tier = (TierImpl) tierIt.next();            tier2d = new Tier2D(tier);            allTiers.add(tier2d);            //visibleTiers.add(tier2d);        }        tierYPositions = new int[allTiers.size()];    }    /**     * Processes the information for the current segment or annotation.<br>     * A segment corresponds to the annotations of one (time) block. Shoebox     * specific??     */    private void extractCurrentSegment() {        dismissEditBox();        cursorTag = null;        _vTiers = new Vector(20);        if (!(allTiers.size() > 0) || !sbl.isRefAnnAvailable()) {            buildLayout();            return;        }        AnnotationSize as = new AnnotationSize(transcription, sbl.getRefAnn(),                currentMetrics);        Vector segTiers = as.getTiers();        int segWidth = 0;        Tier tier;        Iterator tierIt = visibleTiers.iterator();        int yPos = VER_MARGIN;        int xPos = 0;        long time = -1;        while (tierIt.hasNext()) {            tier = ((Tier2D) tierIt.next()).getTier();            xPos = 0;            boolean symbassflag = false; // have we counted freetranslation tiers - part of HACK ALERT            int stereo = 0;            if ((tier != null) && segTiers.contains(tier)) {                ArrayList tieranns = as.getTierLayoutInPixels(tier,                        currentMetrics);                if (tieranns == null) {                    System.err.println("SB DRAWING ERROR!");                    return;                }                Vector ht = new Vector(20);                Rectangle rect = null;                for (int itor = 0; itor < tieranns.size(); itor++) {                    AnnotationSizeContainer asc = (AnnotationSizeContainer) tieranns.get(itor);                    Annotation a = asc.getAnnotation();

⌨️ 快捷键说明

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