📄 multitiercontrolpanel.java
字号:
/* * File: MultiTierControlPanel.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.ElanLocaleListener;import mpi.eudico.client.annotator.commands.Command;import mpi.eudico.client.annotator.commands.CommandAction;import mpi.eudico.client.annotator.commands.ELANCommandFactory;import mpi.eudico.client.annotator.commands.TierDependenciesCA;import mpi.eudico.client.annotator.gui.*;import mpi.eudico.server.corpora.clom.Tier;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.type.LinguisticType;import mpi.util.gui.TreeFrame;import java.awt.Color;import java.awt.Component;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.GridLayout;import java.awt.Insets;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.image.BufferedImage;import java.util.ArrayList;import java.util.Collections;import java.util.Enumeration;import java.util.HashMap;import java.util.Hashtable;import java.util.Iterator;import java.util.List;import java.util.Set;import java.util.Vector;import javax.swing.BoxLayout;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JCheckBoxMenuItem;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.JRadioButtonMenuItem;import javax.swing.JScrollPane;import javax.swing.JTree;import javax.swing.MenuElement;import javax.swing.SwingUtilities;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.TreeNode;import javax.swing.tree.TreePath;/** * JPanel that shows Tier labels for a MultiTierViewer The labels can be hidden * and replaced. */public class MultiTierControlPanel extends JPanel implements MouseListener, MouseMotionListener, ActionListener, ElanLocaleListener { /** Holds value of property width */ public final static int WIDTH = 120; /** the horizontal margins of the component */ public final static int MARGIN = 5; /** Indentation for each hierarchical tier level */ public final static int LEVEL_INDENT = 10; /** The size of the node expand/collapse marker */ public static final int MARKER_SIZE = 6; private Dimension dimension; private Transcription transcription; private Vector tiers; private Vector visibleTiers; private JPopupMenu popup; private JMenu viewerMenu; private JMenu visTiersMenu; private JMenu sortTiersMenu; private JMenuItem hideAllMI; private JMenuItem showAllMI; private JMenuItem showHideMoreMI; private JMenuItem collapseAllMI; private JMenuItem expandAllMI; private JMenuItem hideMI; private JMenuItem changeMI; private JMenuItem deleteMI; private JMenuItem colOrExpMI; private JMenuItem showHierMI; private JRadioButtonMenuItem timelineMI; private JRadioButtonMenuItem interlinearMI; private JRadioButtonMenuItem sortByHierarchMI; private JRadioButtonMenuItem sortByTypeMI; private JRadioButtonMenuItem sortByPartMI; private JRadioButtonMenuItem sortByAnnotMI; private JRadioButtonMenuItem unsortedMI; private MultiTierViewer viewer; private int[] tierPositions; private Hashtable tierNames; private BufferedImage bi; private Graphics2D big2d; private FontMetrics fontMetrics; private Font boldFont; private FontMetrics boldMetrics; private boolean dragging; private int dragX; private int dragY; private int dragIndex; private String dragLabel; private Tier activeTier; private TierImpl rightClickTier; private int[] colorValues; private Hashtable tierRootColors; private int tierHeight; //ordering private DefaultMutableTreeNode sortedRootNode; /** Holds the current sorting mode */ private int sortMode; /** Holds value of the unsorted sorting property */ private final int UNSORTED = 0; /** Holds value of the sort by hierarchy sorting property */ private final int SORT_BY_HIERARCHY = 1; /** Holds value of the sort by participant sorting property */ private final int SORT_BY_PARTICIPANT = 2; /** Holds value of the sort by linguistic type sorting property */ private final int SORT_BY_LINGUISTIC_TYPE = 3; /** Holds value of the sort by annotator sorting property */ private final int SORT_BY_ANNOTATOR = 4; /** * A flattened view on the tier tree. It contains tier nodes that are * visible and that are not a child of a collapsed node. */ private Vector displayableTierNodes; /** A constant for unspecified participant or linguistic type */ private final String NOT_SPECIFIED = "not specified"; /** * Add a marker to the action command of a tier to avoid collisions in the * handling of menuitem's action events */ private final String TIER_AC = "@&@"; private Vector viewers; /** * PROBLEMS WHEN MORE THAN ONE MULTI TIER VIEWER IS VISIBLE * * @param transcription DOCUMENT ME! */ public MultiTierControlPanel(Transcription transcription) { dimension = new Dimension(); visibleTiers = new Vector(); displayableTierNodes = new Vector(); viewers = new Vector(); setFont(Constants.DEFAULTFONT); sortMode = UNSORTED; //colorValues = new int[]{0, 128, 255}; colorValues = new int[] { 0, 90, 160 }; setTranscription(transcription); addMouseListener(this); addMouseMotionListener(this); } /** * Overrides <code>JComponent.setFont(Font)</code> by creating a bold * derivative and <code>FontMetrics</code> objects for both Font objects. * * @param f DOCUMENT ME! */ public void setFont(Font f) { super.setFont(f); tierHeight = 3 * f.getSize(); // first guess fontMetrics = getFontMetrics(getFont()); boldFont = getFont().deriveFont(Font.BOLD); boldMetrics = getFontMetrics(boldFont); } /** * Set the viewer that must be controlled * * @param viewer DOCUMENT ME! */ public void setViewer(MultiTierViewer viewer) { this.viewer = viewer; viewer.setMultiTierControlPanel(this); // notify the viewer about the current visible tiers // this results in a callback to setTierPositions if (visibleTiers != null) { setVisibleTiers(visibleTiers); } if (activeTier != null) { setActiveTier(activeTier); } } /** * Add a viewer that must be controlled * * @param viewer DOCUMENT ME! */ public void addViewer(MultiTierViewer viewer) { viewers.add(viewer); viewer.setMultiTierControlPanel(this); // notify the viewer about the current visible tiers // this results in a callback to setTierPositions if (visibleTiers != null) { setVisibleTiers(visibleTiers); } if (activeTier != null) { setActiveTier(activeTier); } } /** * Remove a viewer that must be controlled * * @param viewer DOCUMENT ME! */ public void removeViewer(MultiTierViewer viewer) { viewer.setMultiTierControlPanel(null); viewers.remove(viewer); } /** * DOCUMENT ME! */ public void updateLocale() { if (popup == null) { return; } hideAllMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.HideAllTiers")); showAllMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.ShowAllTiers")); showHideMoreMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.ShowHideMore")); viewerMenu.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.Viewer")); visTiersMenu.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.VisibleTiers")); sortTiersMenu.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.SortTiers")); expandAllMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.ExpandAll")); collapseAllMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.CollapseAll")); unsortedMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.Unsorted")); sortByHierarchMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.SortByHierarchy")); sortByTypeMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.SortByType")); sortByPartMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.SortByParticipant")); sortByAnnotMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.SortByAnnotator")); hideMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.ThisTier.Hide")); changeMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.ThisTier.Change")); deleteMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.ThisTier.Delete")); colOrExpMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.ThisTier.CollapseExpand")); showHierMI.setText(ElanLocale.getString( "MultiTierControlPanel.Menu.ThisTier.ShowInHierarchy")); } private void setTranscription(Transcription transcription) { this.transcription = transcription; try { tiers = transcription.getTiers(); tierNames = new Hashtable(); tierRootColors = new Hashtable(); popup = new JPopupMenu(""); // popup.setLightWeightPopupEnabled(true); viewerMenu = new JMenu(); popup.add(viewerMenu); popup.addSeparator(); visTiersMenu = new JMenu(); popup.add(visTiersMenu); expandAllMI = new JMenuItem(); expandAllMI.setActionCommand("expandAll"); expandAllMI.addActionListener(this); visTiersMenu.add(expandAllMI); collapseAllMI = new JMenuItem(); collapseAllMI.setActionCommand("collapseAll"); collapseAllMI.addActionListener(this); visTiersMenu.add(collapseAllMI); visTiersMenu.addSeparator(); hideAllMI = new JMenuItem(""); hideAllMI.setActionCommand("hideAll"); hideAllMI.addActionListener(this); visTiersMenu.add(hideAllMI); showAllMI = new JMenuItem(""); showAllMI.setActionCommand("showAll"); showAllMI.addActionListener(this); visTiersMenu.add(showAllMI); showHideMoreMI = new JMenuItem();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -