📄 framemanager.java
字号:
/* * File: FrameManager.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;import mpi.eudico.client.annotator.gui.ChangedTranscriptionsPane;import mpi.eudico.client.annotator.gui.ExitStrategyPane;import mpi.eudico.client.annotator.util.FileUtility;import mpi.eudico.client.annotator.util.FrameConstants;import mpi.eudico.client.annotator.util.FrameInfo;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import java.awt.event.ActionEvent;import java.io.File;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Vector;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.JFrame;import javax.swing.JOptionPane;/** * A singleton manager class that keeps track of open windows and that * maintains the "recent files" list. * * @author Han Sloetjes, MPI */public class FrameManager { // the manager /** Holds value of property DOCUMENT ME! */ private static final FrameManager manager = new FrameManager(); private boolean exitAllowed = false; /** contains mappings from abbreviated file path to full path */ private Map recentFilesMap; /** * contains a list of the recently opened files, the most recent at index 0 */ private List recentFilesList; /** a List containing (Elan)FrameInfo objects */ private List openFrameList; /** Holds value of property DOCUMENT ME! */ private final int maxFilePathLength = 40; /** a counter for frame id's */ private int frameCounter = 0; /** a prefix for frame id's */ private final String FR_NAME = "Frame-"; /** the preferences key for the recent file list */ private final String RECENTS_PREF = "FrameManager.RecentFiles"; /** Holds value of property DOCUMENT ME! */ private final String EXIT_PREF = "FrameManager.ExitMes"; /** * Private constructor, initializes some lists and maps. */ private FrameManager() { recentFilesMap = new HashMap(FrameConstants.MAX_NUM_RECENTS); recentFilesList = new ArrayList(FrameConstants.MAX_NUM_RECENTS); openFrameList = new ArrayList(10); // get the stored recent files list ArrayList tempList = (ArrayList) Preferences.get(RECENTS_PREF, null); if (tempList != null) { String url; String shUrl; for (int i = 0; i < tempList.size(); i++) { url = (String) tempList.get(i); if (url != null) { recentFilesList.add(url); shUrl = fullPathToDisplayPath(url); if (shUrl != null) { recentFilesMap.put(url, shUrl); } } } } } /** * Returns the single instance of the FrameManager. * * @return the framemanager */ public static FrameManager getInstance() { return manager; } /** * Finds the frame with the specified id and calls removeFrame(frame) * * @param frameId the id of the frame */ public void closeFrame(String frameId) { if (frameId == null) { return; } FrameInfo fin = null; for (int i = 0; i < openFrameList.size(); i++) { fin = (FrameInfo) openFrameList.get(i); if (fin.getFrameId().equals(frameId)) { break; } else { fin = null; } } if (fin != null) { closeFrame(fin.getFrame()); } } /** * Removes the specified frame, updates the open windows menus of the * remaining frames and creates a new empty frame if this was the last * open frame. * * @param frame the frame to remove from the lists */ public void closeFrame(JFrame frame) { if (frame == null) { return; } FrameInfo fin = null; for (int i = 0; i < openFrameList.size(); i++) { fin = (FrameInfo) openFrameList.get(i); if (fin.getFrame() == frame) { break; } else { fin = null; } } if (fin == null) { return; // the frame is not in the list } String id = fin.getFrameId(); openFrameList.remove(fin); if (id != null) { // notify remaining frames that the corresponding menuitem // should be removed FrameInfo info; for (int i = 0; i < openFrameList.size(); i++) { info = (FrameInfo) openFrameList.get(i); if (info.getFrame() instanceof ElanFrame2) { ((ElanFrame2) info.getFrame()).removeActionFromMenu(id, FrameConstants.WINDOW); } } } // check which window is now active FrameInfo actInfo = null; for (int i = 0; i < openFrameList.size(); i++) { actInfo = (FrameInfo) openFrameList.get(i); if (actInfo.getFrame().isActive()) { break; } else { actInfo = null; } } if (actInfo != null) { FrameInfo other; for (int i = 0; i < openFrameList.size(); i++) { other = (FrameInfo) openFrameList.get(i); if (other.getFrame() instanceof ElanFrame2) { ((ElanFrame2) other.getFrame()).setMenuSelected(actInfo.getFrameId(), FrameConstants.WINDOW); } } } if (openFrameList.size() == 0) { createEmptyFrame(); } } /** * Called from an action that has been added to the open window menu. * * @param frameId the internal id of the window */ public void setToFront(String frameId) { FrameInfo fin = null; for (int i = 0; i < openFrameList.size(); i++) { fin = (FrameInfo) openFrameList.get(i); if (fin.getFrameId().equals(frameId)) { fin.getFrame().toFront(); break; // updating the menu's should then follow a call from // the frame?? } } } /** * Activate next or previous frame as listed in the menu, through keyboard * shortcuts. * * @param forward if true the next frame in the menu list will be activated, * if it is the last the first element in the list will become active */ public void activateNextFrame(boolean forward) { if (openFrameList.size() <= 1) { return; } FrameInfo loopInfo; ElanFrame2 ef2; int current = -1; // find current active window for (int i = 0; i < openFrameList.size(); i++) { loopInfo = (FrameInfo) openFrameList.get(i); if (loopInfo.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) loopInfo.getFrame(); if (ef2.isActive()) { current = i; break; } } } int next = -1; if (current == (openFrameList.size() - 1)) { if (forward) { next = 0; } else { next = current - 1; } } else if (current == 0) { if (forward) { next = 1; } else { next = openFrameList.size() - 1; } } else { if (forward) { next = current + 1; } else { next = current - 1; } } if ((next > -1) && (next < openFrameList.size())) { loopInfo = (FrameInfo) openFrameList.get(next); loopInfo.getFrame().toFront(); // update of menus follows a call from the frame } } /** * After a frame has been activated this method should be called to update * the window menu. * * @param frame the new active frame */ public void frameActivated(JFrame frame) { if (frame == null) { return; } FrameInfo fin = null; for (int i = 0; i < openFrameList.size(); i++) { fin = (FrameInfo) openFrameList.get(i); if (fin.getFrame() == frame) { frameActivated(fin.getFrameId()); } } } /** * After a frame has been activated this method should be called to update * the window menu. * * @param frameId the internal id of the new active frame */ public void frameActivated(String frameId) { if (frameId != null) { // update menus FrameInfo fin = null; for (int i = 0; i < openFrameList.size(); i++) { fin = (FrameInfo) openFrameList.get(i); if (fin.getFrame() instanceof ElanFrame2) { ((ElanFrame2) fin.getFrame()).setMenuSelected(frameId, FrameConstants.WINDOW); } } } } /** * Find the frame for the specified file. * * @param filePath the file path * * @return the frame */ public ElanFrame2 getFrameFor(String filePath) { if (filePath == null) { return null; } //String url = FileUtility.pathToURLString(filePath); FrameInfo fin = null; for (int i = 0; i < openFrameList.size(); i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -