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

📄 timeseriesviewer.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * File:     TimeSeriesViewer.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.timeseries.AbstractTSTrack;import mpi.eudico.client.annotator.timeseries.ExtractDataMultiStep;import mpi.eudico.client.annotator.timeseries.TSRulerImpl;import mpi.eudico.client.annotator.timeseries.TSTrackManager;import mpi.eudico.client.annotator.timeseries.TSTrackPanelImpl;import mpi.eudico.client.annotator.timeseries.TimeSeriesChangeEvent;import mpi.eudico.client.annotator.timeseries.TimeSeriesChangeListener;import mpi.eudico.client.annotator.timeseries.config.TSTrackConfiguration;import mpi.eudico.client.mediacontrol.ControllerEvent;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import java.awt.AlphaComposite;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Insets;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.AdjustmentEvent;import java.awt.event.AdjustmentListener;import java.awt.event.ComponentEvent;import java.awt.event.MouseEvent;import java.awt.event.MouseWheelEvent;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.Collections; // Lefvert - May 9 2006import java.util.List;import javax.swing.JCheckBoxMenuItem;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JScrollBar;import javax.swing.SwingConstants;import javax.swing.UIManager;/** * A viewer that can handle one or more TimeSeriesTrack panels,  adding a * horizontal ruler, a crosshair, selection (time interval) etc. */public class TimeSeriesViewer extends DefaultTimeScaleBasedViewer    implements AdjustmentListener, TimeSeriesChangeListener {    private TranscriptionImpl transcription;    private TSTrackManager trackManager;    /** Holds value of property DOCUMENT ME! */    private final String ADD_PR = "add-";    /** Holds value of property DOCUMENT ME! */    private final String REM_PR = "rem-";    /** Holds value of property DOCUMENT ME! */    private final String RANGE = "ran-";    /** Holds value of property DOCUMENT ME! */    private final int DEF_PANEL_HEIGHT = 300;    //private BufferedImage bi;    //private Graphics2D big2d;    // a separate buf img for the hor. ruler    private BufferedImage ri;    private Graphics2D rug2d;    //private int imageWidth;    //private int imageHeight;    //private Font font;    //private FontMetrics metrics;    //private int rulerHeight;    private int vertRulerWidth;    //private TimeRuler ruler;    private int verticalScrollOffset;    //private AffineTransform identity;    //private long crossHairTime;    //private int crossHairPos;    //private long intervalBeginTime;    //private long intervalEndTime;    //private long selectionBeginTime;    //private long selectionEndTime;    //private int selectionBeginPos;    //private int selectionEndPos;    //private AlphaComposite alpha04;    //private AlphaComposite alpha07;    //private float msPerPixel;    // vertical scrolling    private JScrollBar scrollBar;    /** default scrollbar width */    private final int defBarWidth;    /** a list of trackpanels */    private List trackPanels;    private int trackPanelHeight;    private Insets panelMargins;    private TSTrackPanelImpl selTrackPanel;    private boolean autoFitVertical = true;    /** menu's and menu items */    private JCheckBoxMenuItem fitVerticalMI;    private JMenu trPanelMenu;    private JMenuItem addPanelMI;    private JMenuItem removePanelMI;    private JMenu setRangeMenu;    private JMenu addTrackMenu;    private JMenu removeTrackMenu;    private JMenuItem extractDataMI;    private JMenuItem configureTrMI;    private JMenuItem removeAllPanelsMI;    private JMenuItem addPanelForEachTrackMI;    // $sidgrid    private JMenuItem addAllTrackMI;    private JMenuItem removeAllTrackMI;    /**     * Constructor.     */    public TimeSeriesViewer() {        super();        initViewer();        defBarWidth = getDefaultBarWidth();        paintBuffer();        addMouseWheelListener(this);        addEmptyTrackPanel();    }    /**     * Constructor. The specified transcription is used as a document   within     * ELAN this viewer is associated with.     *     * @param transcription the transcription     */    public TimeSeriesViewer(Transcription transcription) {        this();        this.transcription = (TranscriptionImpl) transcription;        //testTrack();    }    /**     * Constructor. The specified transcription is used as a document   within     * ELAN this viewer is associated with.     *     * @param transcription the transcription     * @param trackManager the track manager     */    public TimeSeriesViewer(Transcription transcription,        TSTrackManager trackManager) {        this();        this.transcription = (TranscriptionImpl) transcription;        this.trackManager = trackManager;        if (trackManager != null) {            // register as a listener            trackManager.addTimeSeriesChangeListener(this);        }        //testTrack();    }    /**     * Returns the track manager.     *     * @return the track manager     */    public TSTrackManager getTrackManager() {        return trackManager;    }    /**     * Sets the track manager.     *     * @param manager the track manager     */    public void setTrackManager(TSTrackManager manager) {        trackManager = manager;        if (trackManager != null) {            // register as a listener            trackManager.addTimeSeriesChangeListener(this);        }    }    /**     * Performs the initialization of fields and sets up the viewer.<br>     */    protected void initViewer() {        super.initViewer();        trackPanels = new ArrayList(4);        //font = Constants.DEFAULTFONT;        //setFont(font);        //metrics = getFontMetrics(font);        //ruler = new TimeRuler(font, TimeFormatter.toString(0));        //rulerHeight = ruler.getHeight();        vertRulerWidth = 43;        //msPerPixel = 10f;        //crossHairTime = 0L;        //crossHairPos = 100;        //selectionBeginTime = 0L;        //selectionEndTime = 0L;        //selectionBeginPos = 150;        //selectionEndPos = 250;        //alpha04 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);        //alpha07 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f);        //dragStartTime = 0;        //imageWidth = 0;        //imageHeight = 0;        trackPanelHeight = DEF_PANEL_HEIGHT;        panelMargins = new Insets(3, 3, 3, 0);        verticalScrollOffset = 0;        scrollBar = new JScrollBar(JScrollBar.VERTICAL, 0, 50, 0, 200);        scrollBar.setBlockIncrement(trackPanelHeight);        //scrollBar.setUnitIncrement(5);        scrollBar.addAdjustmentListener(this);        //setLayout(null);        add(scrollBar);    }    /**     * 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;    }    /**     * Override <code>JComponent</code>'s paintComponent to paint:<br>     * - a BufferedImage with a ruler and the tags<br>     * - the cursor / crosshair     *     * @param g the graphics object     */    public void paintComponent(Graphics g) {        super.paintComponent(g);        Graphics2D g2d = (Graphics2D) g;        int h = getHeight();        if (h > imageHeight) {            g2d.setColor(Color.WHITE);            g2d.fillRect(0, 0, imageWidth, h);            if (bi != null) {                // keeps the image at the bottom, with the hor. ruler                g2d.drawImage(bi, 0, h - imageHeight - verticalScrollOffset,                    null);            }        } else {            if (bi != null) {                g2d.drawImage(bi, 0, -verticalScrollOffset, null);            }        }        if (ri != null) {            g2d.drawImage(ri, 0, h - rulerHeight, null);        }        // paint selection: here or in paintBuffer        // paint selection, not in the vertical ruler        if ((selectionBeginPos != selectionEndPos) &&                (selectionEndPos > vertRulerWidth)) {            g2d.setColor(Constants.SELECTIONCOLOR);            g2d.setComposite(alpha05);            if (selectionBeginPos < vertRulerWidth) {                selectionBeginPos = vertRulerWidth;            }            g2d.fillRect(selectionBeginPos, h - rulerHeight,                (selectionEndPos - selectionBeginPos), rulerHeight);            //g2d.setComposite(alpha07);            g2d.fillRect(selectionBeginPos, 0,                (selectionEndPos - selectionBeginPos), h - rulerHeight);            g2d.setComposite(AlphaComposite.Src);        }        if ((crossHairPos >= vertRulerWidth) && (crossHairPos <= imageWidth)) {            // prevents drawing outside the component on Mac            g2d.setColor(Constants.CROSSHAIRCOLOR);            g2d.drawLine(crossHairPos, 0, crossHairPos, h);        }    }    /**     * Paint to a buffer.<br>     * First paint the top ruler, next the annotations of the current tier.     */    private void paintBuffer() {        if ((getWidth() <= 0) || (getHeight() <= 0)) {            return;        }        if (imageWidth != (getWidth() - defBarWidth)) {            imageWidth = getWidth() - defBarWidth;        }        int h = (trackPanels.size() * trackPanelHeight) + rulerHeight;        if (imageHeight != h) {            imageHeight = (getHeight() > h) ? getHeight() : h;        }        intervalEndTime = intervalBeginTime +            (int) (intervalWidth * msPerPixel);        if ((bi == null) || (bi.getWidth() < imageWidth) ||                (bi.getHeight() < imageHeight)) {            bi = new BufferedImage(imageWidth, imageHeight,                    BufferedImage.TYPE_INT_RGB);            big2d = bi.createGraphics();        }        big2d.setColor(Color.WHITE);        big2d.fillRect(0, 0, imageWidth, bi.getHeight());        TSTrackPanelImpl panel;        int y = imageHeight - rulerHeight;        for (int i = 0; i < trackPanels.size(); i++) {            panel = (TSTrackPanelImpl) trackPanels.get(i);            y -= panel.getHeight();            big2d.translate(0, y);            panel.paint(big2d, intervalBeginTime);            big2d.translate(0, -y);            //big2d.setTransform(identity);		        }        big2d.setTransform(identity); //reset transform        /*paint time ruler */        if ((ri == null) || (ri.getWidth() < imageWidth) ||                (ri.getHeight() != rulerHeight)) {            ri = new BufferedImage(imageWidth, rulerHeight,                    BufferedImage.TYPE_INT_RGB);            rug2d = ri.createGraphics();        }        rug2d.setColor(Constants.DEFAULTBACKGROUNDCOLOR);        rug2d.fillRect(0, 0, imageWidth, rulerHeight);        rug2d.setColor(Color.DARK_GRAY);        rug2d.drawLine(0, 0, imageWidth, 0);        rug2d.setColor(Constants.DEFAULTFOREGROUNDCOLOR);        rug2d.translate(-(intervalBeginTime / msPerPixel) + vertRulerWidth, 0.0);        //rug2d.translate(vertRulerWidth, 0);        //big2d.translate(vertRulerWidth, y);        ruler.paint(rug2d, intervalBeginTime, imageWidth, msPerPixel,            SwingConstants.TOP);        rug2d.setTransform(identity); //reset transform        //big2d.setTransform(identity); //reset transform        repaint();    }    /**     * Adds a trackpanel to the viewer. The panel's settings are forced to     * comply to the viewer's settings.     *     * @param trackPanel the trackpanel to add     */    public void addTSTrackPanel(TSTrackPanelImpl trackPanel) {        trackPanel.setHeight(trackPanelHeight);        trackPanel.setWidth(getWidth() - defBarWidth);        trackPanel.setMargin(panelMargins);        trackPanel.setRulerWidth(vertRulerWidth - panelMargins.left);        trackPanel.setMsPerPixel(msPerPixel);        trackPanels.add(trackPanel);        adjustPanelHeight();        paintBuffer();        updateScrollBar();    }    /**     * Adds an empty default track panel.     */    public void addEmptyTrackPanel() {        TSTrackPanelImpl tsp = new TSTrackPanelImpl();        TSRulerImpl ruler = new TSRulerImpl();        ruler.setFont(Constants.SMALLFONT);        tsp.setRuler(ruler);        addTSTrackPanel(tsp);    }    /**     * Removes a trackpanel from the viewer     *     * @param trackPanel the trackpanel to remove     */    public void removeTSTrackPanel(TSTrackPanelImpl trackPanel) {        trackPanels.remove(trackPanel);        adjustPanelHeight();        paintBuffer();        updateScrollBar();    }    /**     * Returns the width for the vertical ruler.     *     * @return the width for the vertical ruler     */    public int getVerticalRulerWidth() {        return vertRulerWidth;    }    /**     * Sets the width for the vertical ruler.     *     * @param rulerWidth the width for the vertical ruler     */    public void setVerticalRulerWidth(int rulerWidth) {        vertRulerWidth = rulerWidth;

⌨️ 快捷键说明

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