📄 svgeditor.java
字号:
/* * File: SVGEditor.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.Constants;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.Preferences;import mpi.eudico.client.annotator.ViewerManager2;import mpi.eudico.client.annotator.commands.Command;import mpi.eudico.client.annotator.commands.ELANCommandFactory;import mpi.eudico.client.annotator.player.ElanMediaPlayer;import mpi.eudico.client.annotator.player.JMFGraphicMediaPlayer;import mpi.eudico.client.annotator.player.QTMediaPlayer;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.SVGAlignableAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import java.awt.AlphaComposite;import java.awt.BasicStroke;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Image;import java.awt.Insets;import java.awt.Point;import java.awt.Polygon;import java.awt.Rectangle;import java.awt.Shape;import java.awt.Toolkit;import java.awt.Window;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.Transferable;import java.awt.datatransfer.UnsupportedFlavorException;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.KeyEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.geom.AffineTransform;import java.awt.geom.Ellipse2D;import java.awt.geom.GeneralPath;import java.awt.geom.Line2D;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.awt.geom.RectangularShape;import java.awt.image.BufferedImage;import java.io.IOException;import java.text.NumberFormat;import java.util.Enumeration;import java.util.Hashtable;import java.util.Iterator;import java.util.Vector;import javax.swing.ButtonGroup;import javax.swing.DefaultComboBoxModel;import javax.swing.DefaultListCellRenderer;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JDesktopPane;import javax.swing.JDialog;import javax.swing.JInternalFrame;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JToggleButton;import javax.swing.JToolBar;import javax.swing.KeyStroke;import javax.swing.ListSelectionModel;import javax.swing.TransferHandler;/** * A dialog for editing graphical annotations. * * @author Han Sloetjes */public class SVGEditor extends JDialog implements ActionListener, ItemListener { /** the bounds of the editor dialog */ protected Rectangle dialogBounds; /** the transcription the edited annotation is part of */ protected Transcription transcription; /** the viewermanager */ protected ViewerManager2 viewerManager; /** the annotation that is being edited */ protected SVGAlignableAnnotation annotation; /** an internal frame displaying a list of library objects/shapes */ protected JInternalFrame libraryFrame; /** a table storing icons using it's id value as a key */ protected Hashtable iconTable; private Hashtable libTable = null; /** a JList containing icons of the objects in the library */ protected JList iconList; /** the internal frame containing the actual editor panel */ protected JInternalFrame editFrame; /** the panel that handles all editing operations */ protected EditorPanel editorPanel; /** the size of the icons in the library icon list */ protected final Dimension iconDimension = new Dimension(26, 26); /** the zoomlevels of the editor panel */ public final int[] ZOOMLEVELS = new int[] { 50, 75, 100, 150, 200 }; /** the color to use for the stroke of 2d annotations */ public final Color STROKE_COLOR = Color.red; private int msPerFrame = 40; //initial value is the PAL value private long currentFrame = 0; private JButton deleteButton; private JButton cutButton; private JButton copyButton; private JButton pasteButton; private JButton firstFrameButton; private JButton lastFrameButton; private JButton frameBackButton; private JButton frameForwardButton; private JToolBar statusBar; private JLabel xValue; private JLabel yValue; private JLabel wValue; private JLabel hValue; private JLabel dValue; private JLabel mxValue; private JLabel myValue; private NumberFormat numbFormat; /** * Creates a new SVGEditor instance * * @param transcription the transcription * @param annotation the annotation that has a reference to a 2d object */ public SVGEditor(Transcription transcription, SVGAlignableAnnotation annotation) { super(ELANCommandFactory.getRootFrame(transcription), true); //super(); this.annotation = annotation; this.transcription = transcription; loadPreferences(); initDialog(); setBounds(dialogBounds); setTitle(ElanLocale.getString("GraphicsEditor.Title")); setVisible(true); } /** * Create a menubar, toolbar, desktop pane and some iframes. */ protected void initDialog() { numbFormat = NumberFormat.getInstance(); numbFormat.setMaximumFractionDigits(3); getContentPane().setLayout(new BorderLayout()); setJMenuBar(createMenuBar()); getContentPane().add(createToolBar(), BorderLayout.NORTH); getContentPane().add(createDesktopPane(), BorderLayout.CENTER); getContentPane().add(createStatusBar(), BorderLayout.SOUTH); //setContentPane(createDesktopPane()); initLibrary(); // add containers addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { cancelEdit(); } }); updateToolBarShapeButtons(); updateFramePositionButtons(); updateObjectStatus(); } /** * Creates the menubar. * * @return the menubar */ protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu editMenu = new JMenu(ElanLocale.getString("Menu.Edit")); menuBar.add(editMenu); JMenuItem cancelMI = new JMenuItem(ElanLocale.getString( "GraphicsEditor.Menu.Cancel")); cancelMI.addActionListener(this); cancelMI.setActionCommand("cancel"); cancelMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); editMenu.add(cancelMI); JMenuItem commitMI = new JMenuItem(ElanLocale.getString( "GraphicsEditor.Menu.Commit")); commitMI.addActionListener(this); commitMI.setActionCommand("commit"); commitMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(commitMI); return menuBar; } /** * Creates a toolbar containing buttons and other ui elements for the * editing operations. * * @return a toolbar */ protected JToolBar createToolBar() { JToolBar bar = new JToolBar(JToolBar.HORIZONTAL); // create icons ImageIcon selIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/SelectTool16.gif")); ImageIcon rectIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/RectangleTool16.gif")); ImageIcon ovalIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/OvalTool16.gif")); ImageIcon lineIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/LineTool16.gif")); ImageIcon deleteIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/Delete16.gif")); ImageIcon cutIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/Cut16.gif")); ImageIcon copyIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/Copy16.gif")); ImageIcon pasteIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/Paste16.gif")); ImageIcon firstFrameIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/GoToPreviousScrollviewButton.gif")); ImageIcon lastFrameIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/GoToNextScrollviewButton.gif")); ImageIcon nextFrameIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/NextButton.gif")); ImageIcon prevFrameIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/PreviousButton.gif")); // create buttons deleteButton = new JButton(deleteIcon); deleteButton.setActionCommand("delete"); deleteButton.addActionListener(this); deleteButton.setEnabled(false); bar.add(deleteButton); bar.addSeparator(); cutButton = new JButton(cutIcon); cutButton.setActionCommand("cut"); cutButton.addActionListener(this); cutButton.setEnabled(false); bar.add(cutButton); copyButton = new JButton(copyIcon); copyButton.setActionCommand("copy"); copyButton.addActionListener(this); copyButton.setEnabled(false); bar.add(copyButton); pasteButton = new JButton(pasteIcon); pasteButton.setActionCommand("paste"); pasteButton.addActionListener(this); pasteButton.setEnabled(false); bar.add(pasteButton); bar.addSeparator(); JToggleButton selButton = new JToggleButton(selIcon, true); selButton.setActionCommand("select"); selButton.addActionListener(this); JToggleButton rectButton = new JToggleButton(rectIcon, false); rectButton.setActionCommand("recttool"); rectButton.addActionListener(this); JToggleButton ovalButton = new JToggleButton(ovalIcon, false); ovalButton.setActionCommand("ovaltool"); ovalButton.addActionListener(this); JToggleButton lineButton = new JToggleButton(lineIcon, false); lineButton.setActionCommand("linetool"); lineButton.addActionListener(this); ButtonGroup toolGroup = new ButtonGroup(); toolGroup.add(selButton); toolGroup.add(rectButton); toolGroup.add(ovalButton); toolGroup.add(lineButton); bar.add(selButton); bar.add(rectButton); bar.add(ovalButton); bar.add(lineButton); bar.addSeparator(); firstFrameButton = new JButton(firstFrameIcon); firstFrameButton.setActionCommand("first"); firstFrameButton.addActionListener(this); firstFrameButton.setEnabled(false); bar.add(firstFrameButton); frameBackButton = new JButton(prevFrameIcon); frameBackButton.setActionCommand("prev"); frameBackButton.addActionListener(this); frameBackButton.setEnabled(false); bar.add(frameBackButton); frameForwardButton = new JButton(nextFrameIcon); frameForwardButton.setActionCommand("next"); frameForwardButton.addActionListener(this); bar.add(frameForwardButton); lastFrameButton = new JButton(lastFrameIcon); lastFrameButton.setActionCommand("last"); lastFrameButton.addActionListener(this); bar.add(lastFrameButton); bar.addSeparator(); JPanel zoomPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(1, 3, 1, 3); gbc.anchor = GridBagConstraints.WEST; zoomPanel.add(new JLabel(ElanLocale.getString("Menu.Zoom")), gbc); JComboBox zoomBox = new JComboBox(); DefaultComboBoxModel model = new DefaultComboBoxModel(); for (int i = 0; i < ZOOMLEVELS.length; i++) { model.addElement(ZOOMLEVELS[i] + "%"); } model.setSelectedItem("100%"); zoomBox.setModel(model); zoomBox.setPreferredSize(new Dimension(60, 24)); gbc.gridx = 1; gbc.weightx = 1.0; zoomPanel.add(zoomBox, gbc); zoomBox.addItemListener(this); bar.add(zoomPanel); //bar.add(zoomBox); return bar; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ protected JToolBar createStatusBar() { statusBar = new JToolBar(JToolBar.HORIZONTAL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -