📄 framemanager.java
字号:
fin = (FrameInfo) openFrameList.get(i); if (fin.getFilePath().equals(filePath)) { if (fin.getFrame() instanceof ElanFrame2) { return (ElanFrame2) fin.getFrame(); } } } // not found, create a new frame return createFrame(filePath); } /** * To be used after a Save As action as well as after loading an existing * file in an empty frame * * @param frame the frame * @param newPath the new path */ public void updateFrameTitle(JFrame frame, String newPath) { if ((frame == null) || (newPath == null)) { return; } if (newPath.startsWith("file")) { newPath = newPath.substring(5); } // get the frameinfo object 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; } //String oldUrl = fin.getFilePath(); //String oldName = fin.getFrameName(); String nextName = FileUtility.fileNameFromPath(newPath); // update the open frames menu FrameInfo loopInfo; ElanFrame2 ef2; for (int i = 0; i < openFrameList.size(); i++) { loopInfo = (FrameInfo) openFrameList.get(i); if (loopInfo.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) loopInfo.getFrame(); ef2.removeActionFromMenu(fin.getFrameId(), FrameConstants.WINDOW); ef2.addActionToMenu(new ActiveWindowAction(fin.getFrameId(), nextName), FrameConstants.WINDOW, -1); if (frame.isActive()) { ef2.setMenuSelected(fin.getFrameId(), FrameConstants.WINDOW); } } } // adjust the frame info object fin.setFilePath(newPath); fin.setFrameName(nextName); // update recent file list addToRecentFiles(newPath); } /** * Prepares and executes the shutdown of the application. Checks if there * are any transcription that need to be saved. */ public void exit() { // show a warning message about the changed exit behavior Boolean again = (Boolean) Preferences.get(EXIT_PREF, null); if ((again == null) || !again.booleanValue()) { ExitStrategyPane pane = new ExitStrategyPane(); int option = JOptionPane.showConfirmDialog(null, pane, ElanLocale.getString("Menu.File.Exit"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (option != JOptionPane.OK_OPTION) { return; } boolean sel = pane.getDontShowAgain(); if (sel) { Preferences.set(EXIT_PREF, new Boolean(sel), null); } } // check openframes with changed transcriptions and ask save etc. ArrayList changedTrans = new ArrayList(openFrameList.size()); FrameInfo loopInfo; ElanFrame2 ef2; for (int i = 0; i < openFrameList.size(); i++) { loopInfo = (FrameInfo) openFrameList.get(i); if (loopInfo.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) loopInfo.getFrame(); if (ef2.getViewerManager() != null) { if (ef2.getViewerManager().getTranscription().isChanged()) { changedTrans.add(loopInfo.getFrameName()); } } else { ef2.doClose(false); } } } ArrayList vals = null; if (changedTrans.size() > 0) { // prompt with a list of dirty transcriptions ChangedTranscriptionsPane pane = new ChangedTranscriptionsPane(changedTrans); int option = JOptionPane.showConfirmDialog(null, pane, ElanLocale.getString("Menu.File.Save"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (option != JOptionPane.OK_OPTION) { return; } vals = pane.getSelectedValues(); } // close the frames, save the selected transcriptions for (int j = 0; j < openFrameList.size(); j++) { loopInfo = (FrameInfo) openFrameList.get(j); if ((vals != null) && vals.contains(loopInfo.getFrameName())) { // doublechecking maybe not necessary if (loopInfo.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) loopInfo.getFrame(); ef2.saveAndClose(false); } } else { if (loopInfo.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) loopInfo.getFrame(); ef2.doClose(false); } } } // store the recent files list in preferences Preferences.set(RECENTS_PREF, recentFilesList, null); // check if all frames are closed; the save as dialog of an unsaved, // new document could have been cancelled: don't quit ArrayList closed = new ArrayList(openFrameList.size()); for (int i = openFrameList.size() - 1; i >= 0; i--) { loopInfo = (FrameInfo) openFrameList.get(i); if (loopInfo.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) loopInfo.getFrame(); if (!ef2.isShowing()) { closed.add(loopInfo); openFrameList.remove(loopInfo); } } } if (openFrameList.size() > 0) { // there is still some frame open FrameInfo ofi; for (int i = 0; i < closed.size(); i++) { loopInfo = (FrameInfo) closed.get(i); for (int j = 0; j < openFrameList.size(); j++) { ofi = (FrameInfo) openFrameList.get(j); if (ofi.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) ofi.getFrame(); ef2.removeActionFromMenu(loopInfo.getFrameId(), FrameConstants.WINDOW); } } } // check which frame is active and update menu?? //don't exit return; } mpi.eudico.client.annotator.integration.ExternalLauncher.stop(); if (exitAllowed) { System.exit(0); } } /** * Creates a new empty frame and adds it to the lists. * * @return the new Elan window */ ElanFrame2 createEmptyFrame() { ElanFrame2 ef2 = new ElanFrame2(); addFrame(ef2); return ef2; } /** * Creates a new ELAN window, loading the specified eaf file. * * @param eafPath the path of the .eaf file * * @return the (new) ELAN window */ public ElanFrame2 createFrame(String eafPath) { if (eafPath == null) { return null; } ElanFrame2 ef2 = null; if (openFrameList.size() == 1) { FrameInfo fin = (FrameInfo) openFrameList.get(0); if (fin.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) fin.getFrame(); if (ef2.getViewerManager() == null) { // single empty frame ef2.openEAF(eafPath); updateFrameTitle(ef2, eafPath); } else { ef2 = new ElanFrame2(eafPath); addFrame(ef2); } } } else { ef2 = new ElanFrame2(eafPath); addFrame(ef2); } return ef2; } /** * Creates a new ELAN window, loading the specified eaf file and using the * mediafiles in the specified list as the associated media files. * * @param eafPath the path of the .eaf file * @param files a list of media file paths * * @return the (new) ELAN window */ public ElanFrame2 createFrame(String eafPath, List files) { if (eafPath == null) { return null; } if (files == null) { return createFrame(eafPath); } Vector fileVector = null; if (files instanceof Vector) { fileVector = (Vector) files; } else { fileVector = new Vector(files); } ElanFrame2 ef2 = null; if (openFrameList.size() == 1) { FrameInfo fin = (FrameInfo) openFrameList.get(0); if (fin.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) fin.getFrame(); if (ef2.getViewerManager() == null) { // single empty frame ef2.openEAF(eafPath, fileVector); updateFrameTitle(ef2, eafPath); } else { ef2 = new ElanFrame2(eafPath, fileVector); addFrame(ef2); } } } else { ef2 = new ElanFrame2(eafPath, fileVector); addFrame(ef2); } return ef2; } /** * Creates a new ELAN window with the specified transcription as the document. * * @param transcription the document object for the (new) frame * * @return the (new) ELAN window */ public ElanFrame2 createFrame(Transcription transcription) { if (transcription == null) { return null; } ElanFrame2 ef2 = null; if (openFrameList.size() == 1) { FrameInfo fin = (FrameInfo) openFrameList.get(0); if (fin.getFrame() instanceof ElanFrame2) { ef2 = (ElanFrame2) fin.getFrame(); if (ef2.getViewerManager() == null) { // single empty frame ef2.setTranscription(transcription); String fullPath = transcription.getName(); if (!transcription.getName().equals(TranscriptionImpl.UNDEFINED_FILE_NAME)) { fullPath = transcription.getFullPath(); if (fullPath.startsWith("file")) { fullPath = fullPath.substring(5); } updateFrameTitle(ef2, fullPath); } } else { ef2 = new ElanFrame2(transcription); addFrame(ef2); } } } else { ef2 = new ElanFrame2(transcription); addFrame(ef2); } return ef2; } /** * A new ELAN Frame has been created and should be added to the list. Menus * have to be updated. * * @param frame the new Elan Frame */ public void addFrame(JFrame frame) { if (frame == null) { return; } String id = FR_NAME + frameCounter++; String fullPath = null; String fileName = ElanLocale.getString("Frame.ElanFrame.Untitled") + "-" + frameCounter; FrameInfo frInfo = new FrameInfo(frame, id); frInfo.setFrameName(fileName); openFrameList.add(frInfo); if (frame instanceof ElanFrame2) { ElanFrame2 ef2 = (ElanFrame2) frame;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -