Search in sources :

Example 11 with Splitter

use of com.intellij.openapi.ui.Splitter in project intellij-community by JetBrains.

the class GuiUtils method replaceJSplitPaneWithIDEASplitter.

public static void replaceJSplitPaneWithIDEASplitter(JComponent root) {
    final Container parent = root.getParent();
    if (root instanceof JSplitPane) {
        // we can painlessly replace only splitter which is the only child in container
        if (parent.getComponents().length != 1 && !(parent instanceof Splitter)) {
            return;
        }
        final JSplitPane pane = (JSplitPane) root;
        final Component component1 = pane.getTopComponent();
        final Component component2 = pane.getBottomComponent();
        final int orientation = pane.getOrientation();
        final Splitter splitter = new JBSplitter(orientation == JSplitPane.VERTICAL_SPLIT);
        splitter.setFirstComponent((JComponent) component1);
        splitter.setSecondComponent((JComponent) component2);
        splitter.setShowDividerControls(pane.isOneTouchExpandable());
        splitter.setHonorComponentsMinimumSize(true);
        if (pane.getDividerLocation() > 0) {
            // let the component chance to resize itself
            SwingUtilities.invokeLater(() -> {
                double proportion;
                if (pane.getOrientation() == JSplitPane.VERTICAL_SPLIT) {
                    proportion = pane.getDividerLocation() / (double) (parent.getHeight() - pane.getDividerSize());
                } else {
                    proportion = pane.getDividerLocation() / (double) (parent.getWidth() - pane.getDividerSize());
                }
                if (proportion > 0 && proportion < 1) {
                    splitter.setProportion((float) proportion);
                }
            });
        }
        if (parent instanceof Splitter) {
            final Splitter psplitter = (Splitter) parent;
            if (psplitter.getFirstComponent() == root)
                psplitter.setFirstComponent(splitter);
            else
                psplitter.setSecondComponent(splitter);
        } else {
            parent.remove(0);
            parent.setLayout(new BorderLayout());
            parent.add(splitter, BorderLayout.CENTER);
        }
        replaceJSplitPaneWithIDEASplitter((JComponent) component1);
        replaceJSplitPaneWithIDEASplitter((JComponent) component2);
    } else {
        final Component[] components = root.getComponents();
        for (Component component : components) {
            if (component instanceof JComponent) {
                replaceJSplitPaneWithIDEASplitter((JComponent) component);
            }
        }
    }
}
Also used : Splitter(com.intellij.openapi.ui.Splitter)

Example 12 with Splitter

use of com.intellij.openapi.ui.Splitter in project intellij-community by JetBrains.

the class EqualsHashCodeTemplatesPanel method createConfigurable.

@Override
protected UnnamedConfigurable createConfigurable(Couple<TemplateResource> item) {
    final GenerateTemplateConfigurable equalsConfigurable = new GenerateTemplateConfigurable(item.first, GenerateEqualsHelper.getEqualsImplicitVars(myProject), myProject);
    final GenerateTemplateConfigurable hashCodeConfigurable = new GenerateTemplateConfigurable(item.second, GenerateEqualsHelper.getHashCodeImplicitVars(), myProject);
    return new UnnamedConfigurable() {

        @Nullable
        @Override
        public JComponent createComponent() {
            final Splitter splitter = new Splitter(true);
            final JPanel eqPanel = new JPanel(new BorderLayout());
            eqPanel.add(new TitledSeparator("Equals Template:"), BorderLayout.NORTH);
            final JComponent eqPane = equalsConfigurable.createComponent();
            eqPane.setPreferredSize(JBUI.size(300, 200));
            eqPanel.add(eqPane, BorderLayout.CENTER);
            splitter.setFirstComponent(eqPanel);
            final JPanel hcPanel = new JPanel(new BorderLayout());
            hcPanel.add(new TitledSeparator("HashCode Template:"), BorderLayout.NORTH);
            final JComponent hcPane = hashCodeConfigurable.createComponent();
            hcPane.setPreferredSize(JBUI.size(300, 200));
            hcPanel.add(hcPane, BorderLayout.CENTER);
            splitter.setSecondComponent(hcPanel);
            return splitter;
        }

        @Override
        public boolean isModified() {
            return equalsConfigurable.isModified() || hashCodeConfigurable.isModified();
        }

        @Override
        public void apply() throws ConfigurationException {
            equalsConfigurable.apply();
            hashCodeConfigurable.apply();
        }

        @Override
        public void reset() {
            equalsConfigurable.reset();
            hashCodeConfigurable.reset();
        }

        @Override
        public void disposeUIResources() {
            equalsConfigurable.disposeUIResources();
            hashCodeConfigurable.disposeUIResources();
        }
    };
}
Also used : Splitter(com.intellij.openapi.ui.Splitter) TitledSeparator(com.intellij.ui.TitledSeparator) UnnamedConfigurable(com.intellij.openapi.options.UnnamedConfigurable) GenerateTemplateConfigurable(org.jetbrains.java.generate.view.GenerateTemplateConfigurable)

Example 13 with Splitter

use of com.intellij.openapi.ui.Splitter in project intellij-community by JetBrains.

the class EditorWindow method changeOrientation.

void changeOrientation() {
    checkConsistency();
    final Container parent = myPanel.getParent();
    if (parent instanceof Splitter) {
        final Splitter splitter = (Splitter) parent;
        splitter.setOrientation(!splitter.getOrientation());
    }
}
Also used : ThreeComponentsSplitter(com.intellij.openapi.ui.ThreeComponentsSplitter) Splitter(com.intellij.openapi.ui.Splitter) OnePixelSplitter(com.intellij.ui.OnePixelSplitter)

Example 14 with Splitter

use of com.intellij.openapi.ui.Splitter in project intellij-community by JetBrains.

the class EditorWindow method closeFile.

public void closeFile(@NotNull final VirtualFile file, final boolean disposeIfNeeded, final boolean transferFocus) {
    final FileEditorManagerImpl editorManager = getManager();
    editorManager.runChange(splitters -> {
        final List<EditorWithProviderComposite> editors = splitters.findEditorComposites(file);
        if (editors.isEmpty())
            return;
        try {
            final EditorWithProviderComposite editor = findFileComposite(file);
            final FileEditorManagerListener.Before beforePublisher = editorManager.getProject().getMessageBus().syncPublisher(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER);
            beforePublisher.beforeFileClosed(editorManager, file);
            if (myTabbedPane != null && editor != null) {
                final int componentIndex = findComponentIndex(editor.getComponent());
                if (componentIndex >= 0) {
                    final int indexToSelect = calcIndexToSelect(file, componentIndex);
                    Pair<String, Integer> pair = Pair.create(file.getUrl(), componentIndex);
                    myRemovedTabs.push(pair);
                    if (myTabsHidingInProgress.get()) {
                        myHiddenTabs.push(pair);
                    }
                    myTabbedPane.removeTabAt(componentIndex, indexToSelect, transferFocus);
                    editorManager.disposeComposite(editor);
                }
            } else {
                if (inSplitter()) {
                    Splitter splitter = (Splitter) myPanel.getParent();
                    JComponent otherComponent = splitter.getOtherComponent(myPanel);
                    if (otherComponent != null) {
                        IdeFocusManager.findInstance().requestFocus(otherComponent, true);
                    }
                }
                myPanel.removeAll();
                if (editor != null) {
                    editorManager.disposeComposite(editor);
                }
            }
            if (disposeIfNeeded && getTabCount() == 0) {
                removeFromSplitter();
                if (UISettings.getInstance().getEditorTabPlacement() == UISettings.TABS_NONE) {
                    final EditorsSplitters owner = getOwner();
                    if (owner != null) {
                        final ThreeComponentsSplitter splitter = UIUtil.getParentOfType(ThreeComponentsSplitter.class, owner);
                        if (splitter != null) {
                            splitter.revalidate();
                            splitter.repaint();
                        }
                    }
                }
            } else {
                myPanel.revalidate();
                if (myTabbedPane == null) {
                    myPanel.repaint();
                }
            }
        } finally {
            editorManager.removeSelectionRecord(file, this);
            editorManager.notifyPublisher(() -> {
                final Project project = editorManager.getProject();
                if (!project.isDisposed()) {
                    final FileEditorManagerListener afterPublisher = project.getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);
                    afterPublisher.fileClosed(editorManager, file);
                }
            });
            splitters.afterFileClosed(file);
        }
    }, myOwner);
}
Also used : ThreeComponentsSplitter(com.intellij.openapi.ui.ThreeComponentsSplitter) Splitter(com.intellij.openapi.ui.Splitter) OnePixelSplitter(com.intellij.ui.OnePixelSplitter) ThreeComponentsSplitter(com.intellij.openapi.ui.ThreeComponentsSplitter) Project(com.intellij.openapi.project.Project) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener)

Example 15 with Splitter

use of com.intellij.openapi.ui.Splitter in project intellij-community by JetBrains.

the class EditorWindow method removeFromSplitter.

private void removeFromSplitter() {
    if (!inSplitter())
        return;
    if (myOwner.getCurrentWindow() == this) {
        EditorWindow[] siblings = findSiblings();
        myOwner.setCurrentWindow(siblings[0], false);
    }
    Splitter splitter = (Splitter) myPanel.getParent();
    JComponent otherComponent = splitter.getOtherComponent(myPanel);
    Container parent = splitter.getParent().getParent();
    if (parent instanceof Splitter) {
        Splitter parentSplitter = (Splitter) parent;
        if (parentSplitter.getFirstComponent() == splitter.getParent()) {
            parentSplitter.setFirstComponent(otherComponent);
        } else {
            parentSplitter.setSecondComponent(otherComponent);
        }
    } else if (parent instanceof EditorsSplitters) {
        parent.removeAll();
        parent.add(otherComponent, BorderLayout.CENTER);
        parent.revalidate();
    } else {
        throw new IllegalStateException("Unknown container: " + parent);
    }
    dispose();
}
Also used : ThreeComponentsSplitter(com.intellij.openapi.ui.ThreeComponentsSplitter) Splitter(com.intellij.openapi.ui.Splitter) OnePixelSplitter(com.intellij.ui.OnePixelSplitter)

Aggregations

Splitter (com.intellij.openapi.ui.Splitter)47 OnePixelSplitter (com.intellij.ui.OnePixelSplitter)7 NotNull (org.jetbrains.annotations.NotNull)7 ThreeComponentsSplitter (com.intellij.openapi.ui.ThreeComponentsSplitter)6 ListSelectionEvent (javax.swing.event.ListSelectionEvent)6 ListSelectionListener (javax.swing.event.ListSelectionListener)6 Nullable (org.jetbrains.annotations.Nullable)6 AllIcons (com.intellij.icons.AllIcons)4 Disposable (com.intellij.openapi.Disposable)4 Project (com.intellij.openapi.project.Project)4 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)3 ApplicationManager (com.intellij.openapi.application.ApplicationManager)3 UsageInfo (com.intellij.usageView.UsageInfo)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 java.awt (java.awt)3 ActionEvent (java.awt.event.ActionEvent)3 List (java.util.List)3 javax.swing (javax.swing)3 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)2 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2