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);
}
}
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));
}
}
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;
}
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);
}
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));
}
}
Aggregations