public void closeFrontmostSession() { JInternalFrame[] frames = desktopPane.getAllFramesInLayer(0); if (frames.length > 0) { frames[0].dispose(); Map<SessionEditor, JInternalFrame> framesMap = this.framesMap; for (Iterator<SessionEditor> i = framesMap.keySet().iterator(); i.hasNext(); ) { SessionEditor key = i.next(); JInternalFrame value = framesMap.get(key); if (value == frames[0]) { i.remove(); break; } } } }
/** Returns the next available session name in the series untitled1.tet, untitled2.tet, etc. */ private String getNewSessionName() { String base = "untitled"; String suffix = ".tet"; int i = 0; // Sequence 1, 2, 3, ... loop: while (true) { i++; String name = base + i + suffix; for (Object _o : framesMap.keySet()) { if (_o instanceof SessionEditor) { SessionEditor sessionEditor = (SessionEditor) _o; SessionEditorWorkbench workbench = sessionEditor.getSessionWorkbench(); SessionWrapper sessionWrapper = workbench.getSessionWrapper(); if (sessionWrapper.getName().equals(name)) { continue loop; } } } return name; } }
/** * Adds a component to the middle layer of the desktop--that is, the layer for session node * editors. Note: The comp is a SessionEditor */ public void addSessionEditor(SessionEditorIndirectRef editorRef) { SessionEditor editor = (SessionEditor) editorRef; JInternalFrame frame = new TetradInternalFrame(null); frame.getContentPane().add(editor); framesMap.put(editor, frame); editor.addPropertyChangeListener(this); // Set the "small" size of the frame so that it has sensible // bounds when the users unmazimizes it. Dimension fullSize = desktopPane.getSize(); int smallSize = Math.min(fullSize.width - MARGIN, fullSize.height - MARGIN); Dimension size = new Dimension(smallSize, smallSize); setGoodBounds(frame, desktopPane, size); desktopPane.add(frame); // Set the frame to be maximized. This step must come after the frame // is added to the desktop. -Raul. 6/21/01 try { frame.setMaximum(true); } catch (Exception e) { throw new RuntimeException("Problem setting frame to max: " + frame); } desktopPane.setLayer(frame, 0); frame.moveToFront(); frame.setTitle(editor.getName()); frame.setVisible(true); setMainTitle(editor.getName()); }