📄 timelineviewer.java
字号:
/* * File: TimeLineViewer.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.AnnotationTransfer;import mpi.eudico.client.annotator.util.Tag2D;import mpi.eudico.client.annotator.util.Tier2D;import mpi.eudico.client.mediacontrol.ControllerEvent;import mpi.eudico.client.mediacontrol.StartEvent;import mpi.eudico.client.mediacontrol.StopEvent;import mpi.eudico.client.mediacontrol.TimeEvent;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clom.Tier;import mpi.eudico.server.corpora.clom.TimeSlot;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.AlignableAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;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 mpi.util.TimeFormatter;import java.awt.AlphaComposite;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Point;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.InputEvent;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.geom.AffineTransform;import java.awt.geom.Point2D;import java.awt.image.BufferedImage;import java.util.ArrayList;import java.util.Enumeration;import java.util.Iterator;import java.util.List;import java.util.Vector;import javax.swing.ButtonGroup;import javax.swing.JCheckBoxMenuItem;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.JToolTip;import javax.swing.KeyStroke;import javax.swing.SwingConstants;import javax.swing.SwingUtilities;import javax.swing.ToolTipManager;import javax.swing.UIManager;/** * This viewer shows annotations of multiple tiers relative to a time scale.<br> * The value of each tag is truncated in such a way that it does not extent * beyond the available space at a given resolution. * * @author Han Sloetjes * @version 0.1 2/7/2003 * @version Aug 2005 Identity removed */public class TimeLineViewer extends TimeScaleBasedViewer implements ComponentListener, MouseListener, MouseMotionListener, MouseWheelListener, KeyListener, AdjustmentListener, ActionListener, MultiTierViewer, ACMEditListener { /** default number of pixels that represents one second */ static final int PIXELS_FOR_SECOND = 100; private Transcription transcription; private boolean rulerAlwaysVisible; private int rulerHeight; private TimeRuler ruler; private Font font; private Font tooltipFont; private FontMetrics metrics; private BufferedImage bi; private Graphics2D big2d; private AlphaComposite alpha04; private AlphaComposite alpha07; private BasicStroke stroke; private BasicStroke stroke2; //private BasicStroke stroke3; private int msPerPixel; /** default value of milliseconds per pixel */ public final int DEFAULT_MS_PER_PIXEL = 10; /** * The resolution in number of pixels for a second. This is not a * percentage value. Historically resolution = PIXELS_FOR_SECOND factor, * where factor = 100 / menu_resolution_percentage_value. */ private int resolution; private int imageWidth; private int imageHeight; private long crossHairTime; private int crossHairPos; private long intervalBeginTime; private long intervalEndTime; private int verticalScrollOffset; private long selectionBeginTime; private long selectionEndTime; private int selectionBeginPos; private int selectionEndPos; private long dragStartTime; private Point dragStartPoint; private Point dragEndPoint; /** width of border area where auto scrolling starts */ public final int SCROLL_OFFSET = 16; private DragScroller scroller; private JPopupMenu popup; private ButtonGroup zoomBG; private JMenu zoomMI; private ButtonGroup fontSizeBG; private JMenu fontMenu; private JCheckBoxMenuItem timeScaleConMI; private JCheckBoxMenuItem activeAnnStrokeBoldMI; private JCheckBoxMenuItem hScrollBarVisMI; // 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; // copy / paste menu items private JMenuItem copyAnnoMI; private JMenuItem copyAnnoTreeMI; private JMenuItem pasteAnnoHereMI; private JMenuItem pasteAnnoTreeHereMI; private boolean timeScaleConnected; private boolean panMode; // do or don't show empty slots on a child tier private boolean showEmptySlots; private boolean aaStrokeBold; /** Holds value of property DOCUMENT ME! */ protected int pixelsForTierHeight; /** Holds value of property DOCUMENT ME! */ protected int pixelsForTierHeightMargin; /** Holds value of property DOCUMENT ME! */ protected int tierGroupSize = 5; //new storage fields private ArrayList allTiers; private List visibleTiers; private Tag2D hoverTag2D; private int hoverTierIndex; /** Holds value of property DOCUMENT ME! */ protected Tag2D cursorTag2D; private int cursorTierIndex; private Tier2D rightClickTier; private long rightClickTime; // vertical scrolling private JScrollBar scrollBar; private JScrollBar hScrollBar; private boolean hScrollBarVisible = true; /** default scrollbar width */ private final int defBarWidth; private int[] tierYPositions; private int tooltipFontSize; /** ar the control panel that receives the setTierPositions call */ MultiTierControlPanel multiTierControlPanel; // editing private InlineEditBox editBox; private boolean forceOpenControlledVocabulary = false; private Tag2D dragEditTag2D; private boolean dragEditing; private Color dragEditColor = Color.green; /** Holds value of property DOCUMENT ME! */ private final int DRAG_EDIT_MARGIN = 8; /** Holds value of property DOCUMENT ME! */ private final int DRAG_EDIT_CENTER = 0; /** Holds value of property DOCUMENT ME! */ private final int DRAG_EDIT_LEFT = 1; /** Holds value of property DOCUMENT ME! */ private final int DRAG_EDIT_RIGHT = 2; private int dragEditMode = 0; // the parent's boundaries private long dragParentBegin = -1L; private long dragParentEnd = -1L; // a flag for the scroll thread /** Holds value of property DOCUMENT ME! */ boolean stopScrolling = true; private Object tierLock = new Object(); /** a flag to decide wether to use a BufferedImage or not. This is always advised but * leads to strange painting artifacts on some systems (XP/Vista, jre version and graphics * hardware/driver may play a role) */ private boolean useBufferedImage = false; /** a flag to decide which painting strategy is to be used. The call to playerIsPlaying * isn't always consistent between frameworks */ private boolean isPlaying = false; /** * Constructs a new TimeLineViewer.<br> * Takes care of some one time initialization and adds listeners. */ public TimeLineViewer() { initViewer(); initTiers(); defBarWidth = getDefaultBarWidth(); addComponentListener(this); addMouseListener(this); addMouseMotionListener(this); addMouseWheelListener(this); addKeyListener(this); setDoubleBuffered(true); setOpaque(true); String bufImg = System.getProperty("useBufferedImage"); if ((bufImg != null) && bufImg.toLowerCase().equals("true")) { useBufferedImage = true; } } /** * Constructs a new TimeLineViewer using the specified transcription.<br> * Calls the no-arg constructor first. * * @param transcription the transcription containing the data for the * viewer */ public TimeLineViewer(Transcription transcription) { this(); this.transcription = transcription; paintBuffer(); initTiers(); } /** * Overrides <code>JComponent</code>'s processKeyBinding by always * returning false. Necessary for the proper working of (menu) shortcuts * in Elan. * * @param ks DOCUMENT ME! * @param e DOCUMENT ME! * @param condition DOCUMENT ME! * @param pressed DOCUMENT ME! * * @return DOCUMENT ME! */ protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { return false; } /** * Performs the initialization of fields and sets up the viewer.<br> */ private void initViewer() { font = Constants.DEFAULTFONT; setFont(font); metrics = getFontMetrics(font); tooltipFontSize = getDefaultTooltipFontSize(); tooltipFont = font.deriveFont((float) tooltipFontSize); // Keep the tool tip showing int dismissDelay = Integer.MAX_VALUE; ToolTipManager.sharedInstance().setDismissDelay(dismissDelay); rulerAlwaysVisible = true; ruler = new TimeRuler(font, TimeFormatter.toString(0)); rulerHeight = ruler.getHeight(); stroke = new BasicStroke(); stroke2 = new BasicStroke(2.0f); //stroke3 = new BasicStroke(3.0f); msPerPixel = 10; resolution = PIXELS_FOR_SECOND; crossHairTime = 0L; crossHairPos = 0; intervalBeginTime = 0L; intervalEndTime = 0L; verticalScrollOffset = 0; selectionBeginTime = 0L; selectionEndTime = 0L; selectionBeginPos = 0; selectionEndPos = 0; dragStartTime = 0; timeScaleConnected = true; imageWidth = 0; imageHeight = 0; alpha04 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f); alpha07 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f); //pixelsForTierHeight = font.getSize() * 3; //hardcoded for now pixelsForTierHeight = font.getSize() + 24; pixelsForTierHeightMargin = 2; // hardcoded for now scrollBar = new JScrollBar(JScrollBar.VERTICAL, 0, 50, 0, 200); scrollBar.setUnitIncrement(pixelsForTierHeight / 2); scrollBar.setBlockIncrement(pixelsForTierHeight); scrollBar.addAdjustmentListener(this); hScrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 50, 0, 400); hScrollBar.setUnitIncrement(10); hScrollBar.setBlockIncrement(40); hScrollBar.addAdjustmentListener(this); setLayout(null); add(scrollBar); add(hScrollBar); editBox = new InlineEditBox(true); editBox.setFont(font); editBox.setVisible(false); add(editBox);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -