📄 structuredmultiplefilesearchframe.java
字号:
/* * File: StructuredMultipleFileSearchFrame.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.smfsearch;import mpi.annex.search.SearchApplication;import mpi.annex.search.SearchApplicationMediator;import mpi.eudico.client.annotator.ElanFrame2;import mpi.eudico.client.annotator.FrameManager;import mpi.eudico.client.annotator.Preferences;import mpi.eudico.client.annotator.gui.ClosableFrame;import mpi.eudico.client.annotator.search.viewer.EAFMultipleFileUtilities;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.search.SearchLocale;import java.awt.Color;import java.awt.Cursor;import java.awt.EventQueue;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.io.File;import java.util.ArrayList;import javax.swing.ImageIcon;import javax.swing.JPanel;import javax.swing.UIManager;/** * A frame for structured search in multiple local annotation (eaf) files. * This is the ELAN version of Annex search. This class implements Annex' * SearchApplication interface to communicate with Annex functionality. * A separate class that implements SearchApplication instead of this Frame * might be created later. * * @author HS * @version 1.0 */public class StructuredMultipleFileSearchFrame extends ClosableFrame implements SearchApplication { /** prefs key for directories */ protected static final String PREFERENCES_DIRS_KEY = "MultipleFileSearchDirs"; /** prefs key for annotation files */ protected static final String PREFERENCES_PATHS_KEY = "MultipleFileSearchPaths"; private ArrayList searchDirs; private ArrayList searchPaths; private File[] searchFiles; private JPanel defPanel; private JPanel resPanel; /** * Creates a new StructuredMultipleFileSearchFrame instance * * @param elanFrame the parent frame */ public StructuredMultipleFileSearchFrame(ElanFrame2 elanFrame) { super(SearchLocale.getString("MultipleFileSearch.Title")); ImageIcon icon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/ELAN16.png")); if (icon != null) { setIconImage(icon.getImage()); } else { setIconImage(null); } ArrayList curDomain = loadDomain(); if (curDomain == null) { return; } // initialize mediator and panels SearchApplicationMediator mediator = new SearchApplicationMediator(this, curDomain); defPanel = mediator.getSearchDefinitionPanel(); resPanel = mediator.getSearchResultPanel(); initComponents(); pack(); setLocationRelativeTo(elanFrame); setVisible(true); } private void initComponents() { getContentPane().setLayout(new GridBagLayout()); Insets insets = new Insets(2, 2, 2, 2); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.insets = insets; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1.0; gbc.weighty = 1.0; getContentPane().add(defPanel, gbc); gbc.gridy = 1; gbc.fill = GridBagConstraints.BOTH; gbc.weighty = 1.0; getContentPane().add(resPanel, gbc); } /** * Loads the stored files and folders. If no domain has been specified * before the user will be prompted to add files to the domain. The ui * will not be instantiated if there are no files to be searched. * * @return a list of eaf files */ private ArrayList loadDomain() { // initialize lists for directories and files from preferences searchDirs = (Preferences.get(PREFERENCES_DIRS_KEY, null) != null) ? (ArrayList) Preferences.get(PREFERENCES_DIRS_KEY, null) : new ArrayList(); searchPaths = (Preferences.get(PREFERENCES_PATHS_KEY, null) != null) ? (ArrayList) Preferences.get(PREFERENCES_PATHS_KEY, null) : new ArrayList(); searchFiles = EAFMultipleFileUtilities.getUniqueEAFFilesIn(searchDirs, searchPaths); if (searchFiles.length == 0) { EAFMultipleFileUtilities.specifyDomain(this, searchDirs, searchPaths); searchFiles = EAFMultipleFileUtilities.getUniqueEAFFilesIn(searchDirs, searchPaths); if (searchFiles.length == 0) { return null; } } ArrayList domain = new ArrayList(searchFiles.length); for (int i = 0; i < searchFiles.length; i++) { domain.add(searchFiles[i]); // or add the path? } return domain; } /** * Opens the specified file in the viewer application (i.e. ELAN) * activating the annotation at the specified time, on the specified tier. * * @param filePath the file path * @param tierName the name of the tier * @param beginTime begin time of the annotation * @param endTime end time of the annotation */ public void showInViewer(String filePath, final String tierName, final long beginTime, final long endTime) { if (filePath != null) { final ElanFrame2 newElanFrame = FrameManager.getInstance() .getFrameFor(filePath); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); if (newElanFrame != null) { if (newElanFrame.getViewerManager() != null) { newElanFrame.getViewerManager().getSelection().setSelection(beginTime, endTime); newElanFrame.getViewerManager().getMasterMediaPlayer() .setMediaTime(beginTime); TierImpl t = (TierImpl) newElanFrame.getViewerManager() .getTranscription() .getTierWithId(tierName); if (t != null) { Annotation ann = t.getAnnotationAtTime(beginTime); if (ann != null) { newElanFrame.getViewerManager().getActiveAnnotation() .setAnnotation(ann); } } } else { EventQueue.invokeLater(new Runnable() { public void run() { newElanFrame.getViewerManager().getSelection() .setSelection(beginTime, endTime); newElanFrame.getViewerManager() .getMasterMediaPlayer() .setMediaTime(beginTime); TierImpl t = (TierImpl) newElanFrame.getViewerManager() .getTranscription() .getTierWithId(tierName); if (t != null) { Annotation ann = t.getAnnotationAtTime(beginTime); if (ann != null) { newElanFrame.getViewerManager() .getActiveAnnotation() .setAnnotation(ann); } } } }); } newElanFrame.toFront(); this.toFront(); } } } /** * Returns a list of annotation files (File objects). * * @return a list of file objects or null if no annotation file is in the * domain. When null is returned this is interpreted as no change * to the search domain */ public ArrayList getDomain() { EAFMultipleFileUtilities.specifyDomain(this, searchDirs, searchPaths); searchFiles = EAFMultipleFileUtilities.getUniqueEAFFilesIn(searchDirs, searchPaths); if (searchFiles.length == 0) { return null; } ArrayList domain = new ArrayList(searchFiles.length); for (int i = 0; i < searchFiles.length; i++) { domain.add(searchFiles[i]); } return domain; } /** * Return the default background color. * * @return the default background color */ public Color getBackgroundColor() { return UIManager.getColor("Panel.background"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -