/** * sets the window passed as a current ('focused') window among all splitters. All file openings * will be done inside this current window * * @param window a window to be set as current * @param requestFocus whether to request focus to the editor currently selected in this window */ public void setCurrentWindow(@Nullable final EditorWindow window, final boolean requestFocus) { final EditorWithProviderComposite newEditor = window != null ? window.getSelectedEditor() : null; Runnable fireRunnable = new Runnable() { public void run() { getManager().fireSelectionChanged(newEditor); } }; setCurrentWindow(window); getManager().updateFileName(window == null ? null : window.getSelectedFile()); if (window != null) { final EditorWithProviderComposite selectedEditor = window.getSelectedEditor(); if (selectedEditor != null) { fireRunnable.run(); } if (requestFocus) { window.requestFocus(true); } } else { fireRunnable.run(); } }
/** Performs the action of loading a session from a file. */ public void actionPerformed(ActionEvent e) { DataModel dataModel = getDataEditor().getSelectedDataModel(); if (!(dataModel instanceof DataSet)) { JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Must be a tabular data set."); return; } this.dataSet = (DataSet) dataModel; SpinnerNumberModel spinnerNumberModel = new SpinnerNumberModel(getNumLags(), 0, 20, 1); JSpinner jSpinner = new JSpinner(spinnerNumberModel); jSpinner.setPreferredSize(jSpinner.getPreferredSize()); spinnerNumberModel.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { SpinnerNumberModel model = (SpinnerNumberModel) e.getSource(); setNumLags(model.getNumber().intValue()); } }); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); Box b = Box.createVerticalBox(); Box b1 = Box.createHorizontalBox(); b1.add(new JLabel("Number of time lags: ")); b1.add(Box.createHorizontalGlue()); b1.add(Box.createHorizontalStrut(15)); b1.add(jSpinner); b1.setBorder(new EmptyBorder(10, 10, 10, 10)); b.add(b1); panel.add(b, BorderLayout.CENTER); EditorWindow editorWindow = new EditorWindow(panel, "Create time series data", "Save", true); DesktopController.getInstance().addEditorWindow(editorWindow); editorWindow.setVisible(true); editorWindow.addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameClosed(InternalFrameEvent e) { EditorWindow window = (EditorWindow) e.getSource(); if (!window.isCanceled()) { if (dataSet.isContinuous()) { createContinuousTimeSeriesData(); } else if (dataSet.isDiscrete()) { createDiscreteTimeSeriesData(); } else { JOptionPane.showMessageDialog( JOptionUtils.centeringComp(), "Data set must be either continuous or discrete."); } } } }); }
void updateFileColor(@NotNull final VirtualFile file) { final Collection<EditorWindow> windows = findWindows(file); for (final EditorWindow window : windows) { final int index = window.findEditorIndex(window.findFileComposite(file)); LOG.assertTrue(index != -1); window.setForegroundAt(index, getManager().getFileColor(file)); window.setWaveColor(index, getManager().isProblem(file) ? JBColor.red : null); } }
boolean isEmptyVisible() { EditorWindow[] windows = getWindows(); for (EditorWindow each : windows) { if (!each.isEmptyVisible()) { return false; } } return true; }
public EditorWithProviderComposite[] getEditorsComposites() { List<EditorWithProviderComposite> res = new ArrayList<EditorWithProviderComposite>(); for (final EditorWindow myWindow : myWindows) { final EditorWithProviderComposite[] editors = myWindow.getEditors(); ContainerUtil.addAll(res, editors); } return res.toArray(new EditorWithProviderComposite[res.size()]); }
public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final EditorWindow that = (EditorWindow) o; DocumentWindow thatWindow = that.getDocument(); return myDelegate.equals(that.myDelegate) && myDocumentWindow.equals(thatWindow); }
public void clear() { for (EditorWindow window : myWindows) { window.dispose(); } removeAll(); myWindows.clear(); setCurrentWindow(null); repaint(); // revalidate doesn't repaint correctly after "Close All" }
public DockableEditor( Image img, VirtualFile file, Presentation presentation, EditorWindow window) { myImg = img; myFile = file; myPresentation = presentation; myContainer = new DockableEditorTabbedContainer(myProject); myEditorWindow = window; myPreferredSize = myEditorWindow.getSize(); myPinned = window.isFilePinned(file); }
@NotNull private List<EditorWindow> findWindows(final VirtualFile file) { List<EditorWindow> res = new ArrayList<EditorWindow>(); for (final EditorWindow window : myWindows) { if (window.findFileComposite(file) != null) { res.add(window); } } return res; }
@NotNull public List<EditorWithProviderComposite> findEditorComposites(@NotNull VirtualFile file) { List<EditorWithProviderComposite> res = new ArrayList<EditorWithProviderComposite>(); for (final EditorWindow window : myWindows) { final EditorWithProviderComposite fileComposite = window.findFileComposite(file); if (fileComposite != null) { res.add(fileComposite); } } return res; }
private void writeWindow(@NotNull Element res, @Nullable EditorWindow window) { if (window != null) { EditorWithProviderComposite[] composites = window.getEditors(); for (int i = 0; i < composites.length; i++) { VirtualFile file = window.getFileAt(i); res.addContent( writeComposite( file, composites[i], window.isFilePinned(file), window.getSelectedEditor())); } } }
@NotNull public VirtualFile[] getOpenFiles() { final ArrayListSet<VirtualFile> files = new ArrayListSet<VirtualFile>(); for (final EditorWindow myWindow : myWindows) { final EditorWithProviderComposite[] editors = myWindow.getEditors(); for (final EditorWithProviderComposite editor : editors) { final VirtualFile file = editor.getFile(); LOG.assertTrue(file.isValid(), Arrays.toString(editor.getProviders())); files.add(file); } } return VfsUtil.toVirtualFileArray(files); }
private void writeWindow(final Element res, final EditorWindow window) { if (window != null) { final EditorWithProviderComposite[] composites = window.getEditors(); for (int i = 0; i < composites.length; i++) { final VirtualFile file = window.getFileAt(i); final boolean isPinned = window.isFilePinned(file); final EditorWithProviderComposite composite = composites[i]; final EditorWithProviderComposite selectedEditor = window.getSelectedEditor(); writeComposite(res, file, composite, isPinned, selectedEditor); } } }
public static void disposeInvalidEditors() { ApplicationManager.getApplication().assertWriteAccessAllowed(); Iterator<EditorWindow> iterator = allEditors.iterator(); while (iterator.hasNext()) { EditorWindow editorWindow = iterator.next(); if (!editorWindow.isValid()) { editorWindow.dispose(); InjectedLanguageUtil.clearCaches(editorWindow.myInjectedFile, editorWindow.getDocument()); iterator.remove(); } } }
public static Editor create( @NotNull final DocumentWindowImpl documentRange, @NotNull final EditorImpl editor, @NotNull final PsiFile injectedFile) { assert documentRange.isValid(); assert injectedFile.isValid(); EditorWindow window; synchronized (allEditors) { for (EditorWindow editorWindow : allEditors) { if (editorWindow.getDocument() == documentRange && editorWindow.getDelegate() == editor) { editorWindow.myInjectedFile = injectedFile; if (editorWindow.isValid()) { return editorWindow; } } if (editorWindow.getDocument().areRangesEqual(documentRange)) { // int i = 0; } } window = new EditorWindow(documentRange, editor, injectedFile, documentRange.isOneLine()); allEditors.add(window); } assert window.isValid(); return window; }
@Nullable @SuppressWarnings({"HardCodedStringLiteral"}) private JPanel readExternalPanel( final Element element, @Nullable JPanel panel, Ref<EditorWindow> currentWindow) { final Element splitterElement = element.getChild("splitter"); if (splitterElement != null) { return readSplitter(panel, splitterElement, currentWindow); } final Element leaf = element.getChild("leaf"); if (leaf == null) { return null; } EditorWindow window = (panel == null) ? new EditorWindow(this) : findWindowWith(panel); LOG.assertTrue(window != null); @SuppressWarnings("unchecked") final List<Element> children = ContainerUtil.newArrayList(leaf.getChildren("file")); if (UISettings.getInstance().ACTIVATE_RIGHT_EDITOR_ON_CLOSE) { Collections.reverse(children); } VirtualFile currentFile = null; for (final Element file : children) { try { final HistoryEntry entry = new HistoryEntry(getManager().getProject(), file.getChild(HistoryEntry.TAG), true); boolean isCurrent = Boolean.valueOf(file.getAttributeValue("current")).booleanValue(); getManager().openFileImpl3(window, entry.myFile, false, entry, isCurrent); if (getManager().isFileOpen(entry.myFile)) { window.setFilePinned( entry.myFile, Boolean.valueOf(file.getAttributeValue("pinned")).booleanValue()); if (Boolean.valueOf(file.getAttributeValue("current-in-tab")).booleanValue()) { currentFile = entry.myFile; } } } catch (InvalidDataException e) { // OK } } if (currentFile != null) { final EditorComposite editor = window.findFileComposite(currentFile); if (editor != null) { window.setSelectedEditor(editor, true); } } return window.myPanel; }
/** Must pass knowledge from getMappings. If null, creates new Knowledge2 object. */ private void openKnowledgeEditor() { if (this.getParams() == null) { throw new NullPointerException( "Parameter object must not be " + "null if you want to launch a OldKnowledgeEditor."); } IKnowledge knowledge = this.getParams().getKnowledge(); KnowledgeEditor knowledgeEditor = new KnowledgeEditor(knowledge, varNames, params.getSourceGraph()); EditorWindow window = new EditorWindow(knowledgeEditor, knowledgeEditor.getName(), "Save", false, this); DesktopController.getInstance().addEditorWindow(window, JLayeredPane.PALETTE_LAYER); window.setVisible(true); }
@NotNull public FileEditor[] getSelectedEditors() { List<FileEditor> editors = new ArrayList<FileEditor>(); Set<EditorWindow> windows = new THashSet<EditorWindow>(myWindows); final EditorWindow currentWindow = getCurrentWindow(); if (currentWindow != null) { windows.add(currentWindow); } for (final EditorWindow window : windows) { final EditorWithProviderComposite composite = window.getSelectedEditor(); if (composite != null) { editors.add(composite.getSelectedEditor()); } } return editors.toArray(new FileEditor[editors.size()]); }
@NotNull public VirtualFile[] getOpenFiles() { final Set<VirtualFile> files = new ArrayListSet<VirtualFile>(); for (final EditorWindow myWindow : myWindows) { final EditorWithProviderComposite[] editors = myWindow.getEditors(); for (final EditorWithProviderComposite editor : editors) { VirtualFile file = editor.getFile(); // background thread may call this method when invalid file is being removed // do not return it here as it will quietly drop out soon if (file.isValid()) { files.add(file); } } } return VfsUtilCore.toVirtualFileArray(files); }
@Nullable public VirtualFile getCurrentFile() { if (myCurrentWindow != null) { return myCurrentWindow.getSelectedFile(); } return null; }
public void actionPerformed(ActionEvent e) { DataSet dataSet = (DataSet) dataEditor.getSelectedDataModel(); if (dataSet == null || dataSet.getNumColumns() == 0) { JOptionPane.showMessageDialog( findOwner(), "Cannot display a scatter plot for an empty data set."); return; } JPanel panel = new ScatterPlotView(dataSet); EditorWindow editorWindow = new EditorWindow(panel, "Scatter Plots", "Save", true, dataEditor); // JPanel dialog = createScatterPlotDialog(null, null); // EditorWindow editorWindow = new EditorWindow(dialog, "Scatter Plots", "Save", true, // dataEditor); DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER); editorWindow.pack(); editorWindow.setVisible(true); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (myCurrentWindow == null || myCurrentWindow.getFiles().length == 0) { g.setColor(UIUtil.isUnderDarcula() ? UIUtil.getBorderColor() : new Color(0, 0, 0, 50)); g.drawLine(0, 0, getWidth(), 0); } if (showEmptyText()) { UIUtil.applyRenderingHints(g); g.setColor(new JBColor(Gray._100, Gray._160)); g.setFont(UIUtil.getLabelFont().deriveFont(UIUtil.isUnderDarcula() ? 24f : 18f)); final UIUtil.TextPainter painter = new UIUtil.TextPainter().withShadow(true).withLineSpacing(1.4f); painter.appendLine("No files are open").underlined(new JBColor(Gray._150, Gray._100)); if (!isProjectViewVisible()) { painter .appendLine( "Open Project View with " + KeymapUtil.getShortcutText( new KeyboardShortcut( KeyStroke.getKeyStroke((SystemInfo.isMac ? "meta" : "alt") + " 1"), null))) .smaller() .withBullet(); } painter .appendLine("Open a file by name with " + getActionShortcutText("GotoFile")) .smaller() .withBullet() .appendLine( "Open Recent files with " + getActionShortcutText(IdeActions.ACTION_RECENT_FILES)) .smaller() .withBullet() .appendLine("Open Navigation Bar with " + getActionShortcutText("ShowNavBar")) .smaller() .withBullet() .appendLine("Drag'n'Drop file(s) here from " + ShowFilePathAction.getFileManagerName()) .smaller() .withBullet() .draw( g, new PairFunction<Integer, Integer, Pair<Integer, Integer>>() { @Override public Pair<Integer, Integer> fun(Integer width, Integer height) { final Dimension s = getSize(); return Pair.create((s.width - width) / 2, (s.height - height) / 2); } }); } }
public void actionPerformed(final AnActionEvent e) { final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject); EditorWindow window; final VirtualFile file = (VirtualFile) myTabInfo.getObject(); if (ActionPlaces.EDITOR_TAB.equals(e.getPlace())) { window = myWindow; } else { window = mgr.getCurrentWindow(); } if (window != null) { if ((e.getModifiers() & InputEvent.ALT_MASK) != 0) { window.closeAllExcept(file); } else { if (window.findFileComposite(file) != null) { mgr.closeFile(file, window); } } } }
@NotNull public FileEditor[] getSelectedEditors() { final List<FileEditor> editors = new ArrayList<FileEditor>(); final EditorWindow currentWindow = getCurrentWindow(); if (currentWindow != null) { final EditorWithProviderComposite composite = currentWindow.getSelectedEditor(); if (composite != null) { editors.add(composite.getSelectedEditor()); } } for (final EditorWindow window : myWindows) { if (!window.equals(currentWindow)) { final EditorWithProviderComposite composite = window.getSelectedEditor(); if (composite != null) { editors.add(composite.getSelectedEditor()); } } } return editors.toArray(new FileEditor[editors.size()]); }
public void actionPerformed(ActionEvent e) { DataSet dataSet = (DataSet) dataEditor.getSelectedDataModel(); if (dataSet == null || dataSet.getNumColumns() == 0) { JOptionPane.showMessageDialog( findOwner(), "Cannot run normality tests on an empty data set."); return; } // if there are missing values warn and don't display q-q plot. // if(DataUtils.containsMissingValue(dataSet)){ // JOptionPane.showMessageDialog(findOwner(), new JLabel("<html>Data has missing // values, " + // "remove all missing values before<br>" + // "running normality tests.</html>")); // return; // } JPanel panel = createNormalityTestDialog(null); EditorWindow window = new EditorWindow(panel, "Normality Tests", "Close", false, dataEditor); DesktopController.getInstance().addEditorWindow(window, JLayeredPane.PALETTE_LAYER); window.setVisible(true); }
public void openFiles() { if (mySplittersElement != null) { Ref<EditorWindow> currentWindow = new Ref<EditorWindow>(); final JPanel comp = readExternalPanel(mySplittersElement, getTopPanel(), currentWindow); if (comp != null) { removeAll(); add(comp, BorderLayout.CENTER); mySplittersElement = null; } // clear empty splitters for (EditorWindow window : getWindows()) { if (window.getEditors().length == 0) { for (EditorWindow sibling : window.findSiblings()) { sibling.unsplit(false); } } } if (!currentWindow.isNull()) { setCurrentWindow(currentWindow.get(), true); } } }
@NotNull public VirtualFile[] getSelectedFiles() { final Set<VirtualFile> files = new ArrayListSet<VirtualFile>(); for (final EditorWindow window : myWindows) { final VirtualFile file = window.getSelectedFile(); if (file != null) { files.add(file); } } final VirtualFile[] virtualFiles = VfsUtilCore.toVirtualFileArray(files); final VirtualFile currentFile = getCurrentFile(); if (currentFile != null) { for (int i = 0; i != virtualFiles.length; ++i) { if (Comparing.equal(virtualFiles[i], currentFile)) { virtualFiles[i] = virtualFiles[0]; virtualFiles[0] = currentFile; break; } } } return virtualFiles; }
void closeFile(VirtualFile file, boolean moveFocus) { final List<EditorWindow> windows = findWindows(file); if (!windows.isEmpty()) { final VirtualFile nextFile = findNextFile(file); for (final EditorWindow window : windows) { LOG.assertTrue(window.getSelectedEditor() != null); window.closeFile(file, false, moveFocus); if (window.getTabCount() == 0 && nextFile != null && myManager.getProject().isOpen()) { EditorWithProviderComposite newComposite = myManager.newEditorComposite(nextFile); window.setEditor(newComposite, moveFocus); // newComposite can be null } } // cleanup windows with no tabs for (final EditorWindow window : windows) { if (window.isDisposed()) { // call to window.unsplit() which might make its sibling disposed continue; } if (window.getTabCount() == 0) { window.unsplit(false); } } } }
@Override protected JPanel processFiles(@NotNull List<Element> fileElements, final JPanel context) { final Ref<EditorWindow> windowRef = new Ref<EditorWindow>(); UIUtil.invokeAndWaitIfNeeded( new Runnable() { @Override public void run() { windowRef.set(context == null ? createEditorWindow() : findWindowWith(context)); } }); final EditorWindow window = windowRef.get(); LOG.assertTrue(window != null); VirtualFile focusedFile = null; for (int i = 0; i < fileElements.size(); i++) { final Element file = fileElements.get(i); if (i == 0) { EditorTabbedContainer tabbedPane = window.getTabbedPane(); if (tabbedPane != null) { try { int limit = Integer.parseInt( file.getParentElement() .getAttributeValue( JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY.toString(), String.valueOf(JBTabsImpl.DEFAULT_MAX_TAB_WIDTH))); UIUtil.putClientProperty( tabbedPane.getComponent(), JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY, limit); } catch (NumberFormatException e) { // ignore } } } try { final FileEditorManagerImpl fileEditorManager = getManager(); Element historyElement = file.getChild(HistoryEntry.TAG); final HistoryEntry entry = HistoryEntry.createLight(fileEditorManager.getProject(), historyElement); final VirtualFile virtualFile = entry.getFile(); if (virtualFile == null) throw new InvalidDataException("No file exists: " + entry.getFilePointer().getUrl()); Document document = ApplicationManager.getApplication() .runReadAction( new Computable<Document>() { @Override public Document compute() { return virtualFile.isValid() ? FileDocumentManager.getInstance().getDocument(virtualFile) : null; } }); final boolean isCurrentInTab = Boolean.valueOf(file.getAttributeValue(CURRENT_IN_TAB)).booleanValue(); Boolean pin = Boolean.valueOf(file.getAttributeValue(PINNED)); fileEditorManager.openFileImpl4( window, virtualFile, entry, isCurrentInTab, isCurrentInTab, pin, i); if (isCurrentInTab) { focusedFile = virtualFile; } if (document != null) { // This is just to make sure document reference is kept on stack till this point // so that document is available for folding state deserialization in HistoryEntry // constructor // and that document will be created only once during file opening document.putUserData(DUMMY_KEY, null); } updateProgress(); } catch (InvalidDataException e) { if (ApplicationManager.getApplication().isUnitTestMode()) { LOG.error(e); } } } if (focusedFile != null) { getManager().addSelectionRecord(focusedFile, window); } return window.myPanel; }
public void trimToSize(final int editor_tab_limit) { for (final EditorWindow window : myWindows) { window.trimToSize(editor_tab_limit, null, true); } }