📄 framemanager.java
字号:
if (ef2.getViewerManager() != null) { TranscriptionImpl tr = (TranscriptionImpl) ef2.getViewerManager() .getTranscription(); if (!tr.getName().equals(TranscriptionImpl.UNDEFINED_FILE_NAME)) { fullPath = tr.getFullPath(); if (fullPath.startsWith("file")) { fullPath = fullPath.substring(5); } fileName = tr.getName(); frInfo.setFilePath(fullPath); frInfo.setFrameName(fileName); } } // add current recent files list to the new window String sho; String lon; for (int i = 0; i < recentFilesList.size(); i++) { lon = (String) recentFilesList.get(i); sho = (String) recentFilesMap.get(lon); ef2.addActionToMenu(new RecentAction(sho, lon), FrameConstants.RECENT, i); } } // add a menu item for the new frame to all window menu's // add actions for all existing frames to the new frame FrameInfo fin; ElanFrame2 ef2; Action ac; for (int i = 0; i < openFrameList.size(); i++) { fin = (FrameInfo) openFrameList.get(i); if (fin.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) fin.getFrame(); ac = new ActiveWindowAction(id, fileName); ef2.addActionToMenu(ac, FrameConstants.WINDOW, -1); // set selected ? ef2.setMenuSelected(id, FrameConstants.WINDOW); } if (fin != frInfo) { if (frInfo.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) frInfo.getFrame(); ac = new ActiveWindowAction(fin.getFrameId(), fin.getFrameName()); ef2.addActionToMenu(ac, FrameConstants.WINDOW, i); } } } if (fullPath != null) { addToRecentFiles(fullPath); } } /** * Adds the filePath to the recent files list, if it is an .eaf path * and if it is not already in the list. * * @param fullPath the eaf file path */ private void addToRecentFiles(final String fullPath) { if (fullPath == null) { return; } if (!fullPath.toLowerCase().endsWith(".eaf")) { return; } String shortUrl = fullPathToDisplayPath(fullPath); boolean move = false; if (recentFilesList.contains(fullPath)) { if (recentFilesList.indexOf(fullPath) == 0) { return; // change nothing } move = true; recentFilesList.remove(fullPath); recentFilesList.add(0, fullPath); } else { recentFilesList.add(0, fullPath); if (recentFilesList.size() > FrameConstants.MAX_NUM_RECENTS) { recentFilesList.remove(recentFilesList.size() - 1); // could remove from the recentFilesMap } if (shortUrl != null) { recentFilesMap.put(fullPath, shortUrl); } } FrameInfo fin; ElanFrame2 ef2; Action ac; for (int i = 0; i < openFrameList.size(); i++) { fin = (FrameInfo) openFrameList.get(i); if (fin.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) fin.getFrame(); if (move) { ac = ef2.removeActionFromMenu(fullPath, FrameConstants.RECENT); ef2.addActionToMenu(ac, FrameConstants.RECENT, 0); } else { ac = new RecentAction(shortUrl, fullPath); ef2.addActionToMenu(ac, FrameConstants.RECENT, 0); } } } Preferences.set(RECENTS_PREF, recentFilesList, null); } /** * Removes the specified file (path) from the recent files list, if it is in the list * e.g. when a file has been deleted or moved. * * @param fullPath the path */ private void removeFromRecentFiles(final String fullPath) { if (fullPath == null) { return; } if (recentFilesList.contains(fullPath)) { recentFilesList.remove(fullPath); // remove from menus FrameInfo fin; ElanFrame2 ef2; for (int i = 0; i < openFrameList.size(); i++) { fin = (FrameInfo) openFrameList.get(i); if (fin.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) fin.getFrame(); ef2.removeActionFromMenu(fullPath, FrameConstants.RECENT); } } Preferences.set(RECENTS_PREF, recentFilesList, null); } } /** * Converts a full eaf file path to a shortened display path for a menu * item. * * @param fullPath the full eaf file path * * @return a shortened file path */ public String fullPathToDisplayPath(String fullPath) { if (fullPath == null) { return ""; } int start = 0; int lastSep = fullPath.lastIndexOf(File.separatorChar); if (lastSep < 0) { if (fullPath.length() <= maxFilePathLength) { return fullPath; } else { return fullPath.substring(0, maxFilePathLength - 3) + "..."; } } if (fullPath.startsWith("file:")) { start = 5; } int colon = fullPath.indexOf(':', start); if (((colon - start) > 0) && ((colon - start) < 5)) { // assume windows path ? start = colon - 1; } else { int ad = 0; for (int i = 0; i < 3; i++) { if (fullPath.charAt(start + i) == File.separatorChar) { ad++; } } if (ad == 3) { start += 2; } } if ((fullPath.length() - start) < maxFilePathLength) { return fullPath.substring(start); } else { int fl = fullPath.length() - lastSep; if (fl > maxFilePathLength) { return fullPath.substring(lastSep, lastSep + maxFilePathLength); } int fd = fullPath.indexOf(File.separatorChar, start + 3); if (fd == lastSep) { if (((fl + fd) - start) <= maxFilePathLength) { return fullPath.substring(start); } else { return fullPath.substring(start, (start + maxFilePathLength) - fl - 3) + "..." + fullPath.substring(lastSep); } } else if ((fd >= 0) && ((fl + (fd - start)) < (maxFilePathLength - 3))) { int nextSep = fd; while (true) { nextSep = fullPath.indexOf(File.separatorChar, fd + 1); if ((nextSep > 0) && (nextSep != lastSep)) { if ((fl + (nextSep - start)) < (maxFilePathLength - 3)) { fd = nextSep; } else { break; } } else { break; } } return fullPath.substring(start, fd + 1) + "..." + fullPath.substring(lastSep); } else if (fd >= 0) { int rm = Math.max(maxFilePathLength - fl - 4, 1); if ((fd - start) > rm) { fd = start + rm; return fullPath.substring(start, fd) + "." + File.separator + "..." + fullPath.substring(lastSep); } else { return fullPath.substring(start, fd + 1) + "..." + fullPath.substring(lastSep); } } else { return fullPath.substring(start); } } } /** * Returns whether or not the manager is allowed to call System.exit(). * ELAN or an ELAN window may have been created by another tool, in such * case frames should just be closed without exiting the VM. * Default is false. * * @return whether or not the manager may call System.exit() */ public boolean isExitAllowed() { return exitAllowed; } /** * Sets whther or not the application may call System.exit(). * In ELAN's main method this flag is set to true. * * @param exitAllowed if true, ELAN can exit the VM */ public void setExitAllowed(boolean exitAllowed) { this.exitAllowed = exitAllowed; } /** * An action object that stores a full path and a short path of * a recently used file. The actionPerformed() opens the file in * a (new) ELAN window. * * @author Han Sloetjes, MPI * @version 1.0 */ class RecentAction extends AbstractAction { /** * Creates a new RecentAction instance * * @param shortUrl a shortened path for display in menu * @param fullUrl the full path to the file */ RecentAction(String shortUrl, String fullUrl) { putValue(Action.NAME, shortUrl); // use LONG_DESCRIPTION or DEFAULT ? putValue(Action.LONG_DESCRIPTION, fullUrl); } /** * Lets the FrameManager open the corresponding file. * * @param e event */ public void actionPerformed(ActionEvent e) { //check if file still exists, if file does not exist warn and remove from lists try { String path = (String) getValue(Action.LONG_DESCRIPTION); File fileTemp = new File(path); //check if file exists and is a file if (!fileTemp.exists() || fileTemp.isDirectory()) { String strMessage = ElanLocale.getString( "Menu.Dialog.Message1"); strMessage += path; strMessage += ElanLocale.getString("Menu.Dialog.Message2"); String strError = ElanLocale.getString("Message.Error"); JOptionPane.showMessageDialog(null, strMessage, strError, JOptionPane.ERROR_MESSAGE); FrameManager.this.removeFromRecentFiles(path); return; } } catch (Exception exc) { } FrameManager.getInstance().createFrame((String) getValue( Action.LONG_DESCRIPTION)); } } /** * An Action that activates (brings to front) the frame identified * by the internal frame id. Th action stores a filename/framename for * displayal in a menu. * * @author Han Sloetjes, MPI * @version 1.0 */ class ActiveWindowAction extends AbstractAction { /** * Creates a new ActiveWindowAction instance * * @param frameId the internal frame id * @param fileName the file or frame name */ ActiveWindowAction(String frameId, String fileName) { putValue(Action.NAME, fileName); // use LONG_DESCRIPTION or DEFAULT ? putValue(Action.LONG_DESCRIPTION, frameId); } /** * Lets the FrameManager activate the corresponding frame and update * the Window menu in all open frames. * * @param e the event */ public void actionPerformed(ActionEvent e) { FrameManager.getInstance().setToFront((String) getValue( Action.LONG_DESCRIPTION)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -