Search in sources :

Example 31 with TabInfo

use of com.intellij.ui.tabs.TabInfo in project intellij-community by JetBrains.

the class RunnerContentUi method restoreLastUiState.

private ActionCallback restoreLastUiState() {
    if (isStateBeingRestored())
        return ActionCallback.REJECTED;
    try {
        setStateIsBeingRestored(true, this);
        List<TabInfo> tabs = new ArrayList<>();
        tabs.addAll(myTabs.getTabs());
        final ActionCallback result = new ActionCallback(tabs.size());
        for (TabInfo each : tabs) {
            getGridFor(each).restoreLastUiState().notifyWhenDone(result);
        }
        return result;
    } finally {
        setStateIsBeingRestored(false, this);
    }
}
Also used : TabInfo(com.intellij.ui.tabs.TabInfo)

Example 32 with TabInfo

use of com.intellij.ui.tabs.TabInfo in project intellij-community by JetBrains.

the class StudyEditInputAction method showInput.

public void showInput(final Project project) {
    final Editor selectedEditor = StudyUtils.getSelectedEditor(project);
    if (selectedEditor != null) {
        FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
        final VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
        final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
        assert openedFile != null;
        TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
        assert taskFile != null;
        final Task currentTask = taskFile.getTask();
        tabbedPane = new JBEditorTabs(project, ActionManager.getInstance(), IdeFocusManager.findInstance(), project);
        tabbedPane.addListener(new TabsListener.Adapter() {

            @Override
            public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
                if (newSelection.getIcon() != null) {
                    int tabCount = tabbedPane.getTabCount();
                    VirtualFile taskDir = StudyUtils.getTaskDir(openedFile);
                    VirtualFile testsDir = taskDir.findChild(EduNames.USER_TESTS);
                    assert testsDir != null;
                    UserTest userTest = createUserTest(testsDir, currentTask, studyTaskManager);
                    userTest.setEditable(true);
                    StudyTestContentPanel testContentPanel = new StudyTestContentPanel(userTest);
                    TabInfo testTab = addTestTab(tabbedPane.getTabCount(), testContentPanel, currentTask, true);
                    myEditableTabs.put(testTab, userTest);
                    tabbedPane.addTabSilently(testTab, tabCount - 1);
                    tabbedPane.select(testTab, true);
                }
            }
        });
        List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
        int i = 1;
        for (UserTest userTest : userTests) {
            String inputFileText = StudyUtils.getFileText(null, userTest.getInput(), false, "UTF-8");
            String outputFileText = StudyUtils.getFileText(null, userTest.getOutput(), false, "UTF-8");
            StudyTestContentPanel myContentPanel = new StudyTestContentPanel(userTest);
            myContentPanel.addInputContent(inputFileText);
            myContentPanel.addOutputContent(outputFileText);
            TabInfo testTab = addTestTab(i, myContentPanel, currentTask, userTest.isEditable());
            tabbedPane.addTabSilently(testTab, i - 1);
            if (userTest.isEditable()) {
                myEditableTabs.put(testTab, userTest);
            }
            i++;
        }
        TabInfo plusTab = new TabInfo(new JPanel());
        plusTab.setIcon(PlatformIcons.ADD_ICON);
        tabbedPane.addTabSilently(plusTab, tabbedPane.getTabCount());
        final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), tabbedPane.getComponent()).setResizable(true).setMovable(true).setRequestFocus(true).createPopup();
        StudyEditor selectedStudyEditor = StudyUtils.getSelectedStudyEditor(project);
        assert selectedStudyEditor != null;
        hint.showInCenterOf(selectedStudyEditor.getComponent());
        hint.addListener(new HintClosedListener(currentTask, studyTaskManager));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) StudyTestContentPanel(com.jetbrains.edu.learning.ui.StudyTestContentPanel) UserTest(com.jetbrains.edu.learning.courseFormat.UserTest) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) TabsListener(com.intellij.ui.tabs.TabsListener) TabInfo(com.intellij.ui.tabs.TabInfo) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) JBEditorTabs(com.intellij.ui.tabs.impl.JBEditorTabs)

Example 33 with TabInfo

use of com.intellij.ui.tabs.TabInfo in project intellij-community by JetBrains.

the class StudyEditInputAction method createClosableTab.

private TabInfo createClosableTab(StudyTestContentPanel contentPanel, Task currentTask) {
    TabInfo closableTab = new TabInfo(contentPanel);
    final DefaultActionGroup tabActions = new DefaultActionGroup();
    tabActions.add(new CloseTab(closableTab, currentTask));
    closableTab.setTabLabelActions(tabActions, ActionPlaces.EDITOR_TAB);
    return closableTab;
}
Also used : TabInfo(com.intellij.ui.tabs.TabInfo)

Example 34 with TabInfo

use of com.intellij.ui.tabs.TabInfo in project intellij-community by JetBrains.

the class JBEditorTabs method doPaintInactive.

@Override
protected void doPaintInactive(Graphics2D g2d, boolean leftGhostExists, TabLabel label, Rectangle effectiveBounds, boolean rightGhostExists, int row, int column) {
    Insets insets = getTabsBorder().getEffectiveBorder();
    int _x = effectiveBounds.x + insets.left;
    int _y = effectiveBounds.y + insets.top;
    int _width = effectiveBounds.width - insets.left - insets.right + (getTabsPosition() == JBTabsPosition.right ? 1 : 0);
    int _height = effectiveBounds.height - insets.top - insets.bottom;
    if ((!isSingleRow()) || (isSingleRow() && isHorizontalTabs())) {
        if (isSingleRow() && getPosition() == JBTabsPosition.bottom) {
            _y += getActiveTabUnderlineHeight();
        } else {
            if (isSingleRow()) {
                _height -= getActiveTabUnderlineHeight();
            } else {
                TabInfo info = label.getInfo();
                if (((TableLayout) getEffectiveLayout()).isLastRow(info)) {
                    _height -= getActiveTabUnderlineHeight();
                }
            }
        }
    }
    final boolean vertical = getTabsPosition() == JBTabsPosition.left || getTabsPosition() == JBTabsPosition.right;
    final Color tabColor = label.getInfo().getTabColor();
    final Composite oldComposite = g2d.getComposite();
    //if (label != getSelectedLabel()) {
    //  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.9f));
    //}
    getPainter().doPaintInactive(g2d, effectiveBounds, _x, _y, _width, _height, tabColor, row, column, vertical);
//g2d.setComposite(oldComposite);
}
Also used : TabInfo(com.intellij.ui.tabs.TabInfo) TableLayout(com.intellij.ui.tabs.impl.table.TableLayout)

Example 35 with TabInfo

use of com.intellij.ui.tabs.TabInfo in project intellij-community by JetBrains.

the class CompressibleSingleRowLayout method layoutLabelsAndGhosts.

@Override
protected void layoutLabelsAndGhosts(SingleRowPassInfo data) {
    if (myTabs.getPresentation().getTabsPosition() != JBTabsPosition.top && myTabs.getPresentation().getTabsPosition() != JBTabsPosition.bottom) {
        super.layoutLabelsAndGhosts(data);
        return;
    }
    int maxGridSize = 0;
    int spentLength = 0;
    int lengthEstimation = 0;
    int[] lengths = new int[data.toLayout.size()];
    List<TabInfo> layout = data.toLayout;
    for (int i = 0; i < layout.size(); i++) {
        final TabLabel label = myTabs.myInfo2Label.get(layout.get(i));
        if (maxGridSize == 0) {
            Font font = label.getLabelComponent().getFont();
            maxGridSize = GraphicsUtil.stringWidth("m", font == null ? JBUI.Fonts.label() : font) * myTabs.tabMSize();
        }
        int lengthIncrement = label.getPreferredSize().width;
        lengths[i] = lengthIncrement;
        lengthEstimation += lengthIncrement;
    }
    final int extraWidth = data.toFitLength - lengthEstimation;
    Arrays.sort(lengths);
    double acc = 0;
    int actualGridSize = 0;
    for (int i = 0; i < lengths.length; i++) {
        int length = lengths[i];
        acc += length;
        actualGridSize = (int) Math.min(maxGridSize, (acc + extraWidth) / (i + 1));
        if (i < lengths.length - 1 && actualGridSize < lengths[i + 1])
            break;
    }
    for (Iterator<TabInfo> iterator = data.toLayout.iterator(); iterator.hasNext(); ) {
        final TabLabel label = myTabs.myInfo2Label.get(iterator.next());
        label.setActionPanelVisible(true);
        int length;
        int lengthIncrement = label.getPreferredSize().width;
        if (!iterator.hasNext()) {
            length = Math.min(data.toFitLength - spentLength, Math.max(actualGridSize, lengthIncrement));
        } else if (extraWidth <= 0) {
            //need compress
            length = (int) (lengthIncrement * (float) data.toFitLength / lengthEstimation);
        } else {
            length = Math.max(lengthIncrement, actualGridSize);
        }
        spentLength += length + myTabs.getInterTabSpaceLength();
        applyTabLayout(data, label, length, 0);
        data.position = (int) label.getBounds().getMaxX() + myTabs.getInterTabSpaceLength();
    }
    for (TabInfo eachInfo : data.toDrop) {
        JBTabsImpl.resetLayout(myTabs.myInfo2Label.get(eachInfo));
    }
}
Also used : TabLabel(com.intellij.ui.tabs.impl.TabLabel) TabInfo(com.intellij.ui.tabs.TabInfo) Font(java.awt.Font)

Aggregations

TabInfo (com.intellij.ui.tabs.TabInfo)41 TabLabel (com.intellij.ui.tabs.impl.TabLabel)6 RelativePoint (com.intellij.ui.awt.RelativePoint)4 JBTabsImpl (com.intellij.ui.tabs.impl.JBTabsImpl)4 Content (com.intellij.ui.content.Content)3 JBTabs (com.intellij.ui.tabs.JBTabs)3 TabsListener (com.intellij.ui.tabs.TabsListener)3 NonOpaquePanel (com.intellij.ui.components.panels.NonOpaquePanel)2 ContentManager (com.intellij.ui.content.ContentManager)2 PyDebugProcess (com.jetbrains.python.debugger.PyDebugProcess)2 ArrayList (java.util.ArrayList)2 EmptyBorder (javax.swing.border.EmptyBorder)2 Nullable (org.jetbrains.annotations.Nullable)2 BuckSettingsProvider (com.facebook.buck.intellij.ideabuck.config.BuckSettingsProvider)1 RunnerLayoutUi (com.intellij.execution.ui.RunnerLayoutUi)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 Editor (com.intellij.openapi.editor.Editor)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1