/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.intellij.util.PairFunction;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
-/**
- * @author gregsh
- */
public class EditorEmptyTextPainter {
-
- public void paintEmptyText(final JComponent splitters, Graphics g) {
- boolean isDarkBackground = UIUtil.isUnderDarcula();
+ public void paintEmptyText(@NotNull final JComponent splitters, @NotNull Graphics g) {
UISettings.setupAntialiasing(g);
- g.setColor(new JBColor(isDarkBackground ? Gray._230 : Gray._80, Gray._160));
- g.setFont(JBUI.Fonts.label(isDarkBackground ? 24f : 20f));
-
- UIUtil.TextPainter painter = new UIUtil.TextPainter().withLineSpacing(1.5f);
- painter.withShadow(true, new JBColor(Gray._200.withAlpha(100), Gray._0.withAlpha(255)));
-
- painter.appendLine("No files are open").underlined(new JBColor(Gray._150, Gray._180));
-
+ g.setColor(new JBColor(Gray._80, Gray._160));
+ g.setFont(JBUI.Fonts.label(16f));
+ UIUtil.TextPainter painter = new UIUtil.TextPainter().withLineSpacing(1.6f);
advertiseActions(splitters, painter);
-
painter.draw(g, new PairFunction<Integer, Integer, Couple<Integer>>() {
@Override
public Couple<Integer> fun(Integer width, Integer height) {
});
}
- protected void advertiseActions(JComponent splitters, UIUtil.TextPainter painter) {
+ protected void advertiseActions(@NotNull JComponent splitters, @NotNull UIUtil.TextPainter painter) {
appendSearchEverywhere(painter);
appendToolWindow(painter, "Open Project View", ToolWindowId.PROJECT_VIEW, splitters);
appendAction(painter, "Open a file by name", getActionShortcutText("GotoFile"));
appendAction(painter, "Open Recent Files", getActionShortcutText(IdeActions.ACTION_RECENT_FILES));
appendAction(painter, "Open Navigation Bar", getActionShortcutText("ShowNavBar"));
- appendLine(painter, "Drag and Drop file(s) here from " + ShowFilePathAction.getFileManagerName());
+ appendDnd(painter);
}
- protected void appendSearchEverywhere(UIUtil.TextPainter painter) {
+ protected void appendDnd(@NotNull UIUtil.TextPainter painter) {
+ appendLine(painter, "Drag and drop files from " + ShowFilePathAction.getFileManagerName());
+ }
+
+ protected void appendSearchEverywhere(@NotNull UIUtil.TextPainter painter) {
Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SEARCH_EVERYWHERE);
- if (shortcuts.length == 0) {
- appendAction(painter, "Search Everywhere", "Double " + (SystemInfo.isMac ? MacKeymapUtil.SHIFT : "Shift"));
- }
- else {
- appendAction(painter, "Search Everywhere", KeymapUtil.getShortcutsText(shortcuts));
- }
+ appendAction(painter, "Search Everywhere", shortcuts.length == 0 ?
+ "Double " + (SystemInfo.isMac ? MacKeymapUtil.SHIFT : "Shift") :
+ KeymapUtil.getShortcutsText(shortcuts));
}
- protected void appendToolWindow(UIUtil.TextPainter painter, String action, String toolWindowId, JComponent splitters) {
+ protected void appendToolWindow(@NotNull UIUtil.TextPainter painter,
+ @NotNull String action,
+ @NotNull String toolWindowId,
+ @NotNull JComponent splitters) {
if (!isToolwindowVisible(splitters, toolWindowId)) {
String activateActionId = ActivateToolWindowAction.getActionIdForToolWindow(toolWindowId);
appendAction(painter, action, getActionShortcutText(activateActionId));
}
}
- protected void appendAction(UIUtil.TextPainter painter, String action, String shortcut) {
+ protected void appendAction(@NotNull UIUtil.TextPainter painter, @NotNull String action, @Nullable String shortcut) {
if (StringUtil.isEmpty(shortcut)) return;
- appendLine(painter, action + " with " + "<shortcut>" + shortcut + "</shortcut>");
+ appendLine(painter, action + " " + "<shortcut>" + shortcut + "</shortcut>");
}
- protected void appendLine(UIUtil.TextPainter painter, String line) {
- painter.appendLine(line).smaller().withBullet();
+ protected void appendLine(@NotNull UIUtil.TextPainter painter, String line) {
+ painter.appendLine(line);
}
- protected String getActionShortcutText(String actionId) {
+ @NotNull
+ protected String getActionShortcutText(@NotNull String actionId) {
return KeymapUtil.getFirstKeyboardShortcutText(actionId);
}
- protected static boolean isToolwindowVisible(JComponent splitters, String toolwindowId) {
- final Window frame = SwingUtilities.getWindowAncestor(splitters);
+ protected static boolean isToolwindowVisible(@NotNull JComponent splitters, @NotNull String toolwindowId) {
+ Window frame = SwingUtilities.getWindowAncestor(splitters);
if (frame instanceof IdeFrameImpl) {
- final Project project = ((IdeFrameImpl)frame).getProject();
+ Project project = ((IdeFrameImpl)frame).getProject();
if (project != null) {
if (!project.isInitialized()) return true;
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(toolwindowId);
return toolWindow != null && toolWindow.isVisible();
}
}
-
return false;
}
}
g.drawString(text, xOffset, yOffset[0]);
if (!StringUtil.isEmpty(shortcut)) {
Color oldColor = g.getColor();
- if (isUnderDarcula()) {
- g.setColor(new Color(60, 118, 249));
- }
+ g.setColor(new JBColor(new Color(82, 99, 155),
+ new Color(88, 157, 246)));
g.drawString(shortcut, xOffset + fm.stringWidth(text + (isUnderDarcula() ? " " : "")), yOffset[0]);
g.setColor(oldColor);
}
package com.jetbrains.edu.learning;
-import com.intellij.ide.ui.UISettings;
-import com.intellij.openapi.actionSystem.ActionManager;
-import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.KeyboardShortcut;
import com.intellij.openapi.fileEditor.impl.EditorEmptyTextPainter;
import com.intellij.openapi.keymap.KeymapUtil;
-import com.intellij.openapi.util.Couple;
-import com.intellij.ui.Gray;
-import com.intellij.ui.JBColor;
-import com.intellij.util.PairFunction;
import com.intellij.util.ui.UIUtil;
import com.jetbrains.edu.learning.actions.*;
import com.jetbrains.edu.learning.ui.StudyProgressToolWindowFactory;
+import org.jetbrains.annotations.NotNull;
import javax.swing.*;
-import java.awt.*;
-/**
- * author: liana
- * data: 7/29/14.
- */
public class StudyInstructionPainter extends EditorEmptyTextPainter {
-
- public static final String SHORTCUT_TAG = "<shortcut>";
- public static final String SHORTCUT_CLOSING_TAG = "</shortcut>";
-
+ private static final String separator = " / ";
@Override
- public void paintEmptyText(final JComponent splitters, Graphics g) {
- boolean isDarkBackground = UIUtil.isUnderDarcula();
- UISettings.setupAntialiasing(g);
-
- g.setColor(new JBColor(isDarkBackground ? Gray._230 : Gray._80, Gray._160));
- g.setFont(UIUtil.getLabelFont().deriveFont(isDarkBackground ? 24f : 20f));
-
- UIUtil.TextPainter painter = new UIUtil.TextPainter().withLineSpacing(1.5f);
-
- painter.appendLine("PyCharm Edu").underlined(new JBColor(Gray._150, Gray._180));
- addAction(painter, "Navigate to the next answer placeholder", StudyNextWindowAction.ACTION_ID, StudyNextWindowAction.SHORTCUT2, true);
- String shortcut1 = getShortcutText(StudyPrevWindowAction.ACTION_ID, StudyPrevWindowAction.SHORTCUT, false, false);
- String shortcut2 = getShortcutText(StudyNextWindowAction.ACTION_ID, StudyNextWindowAction.SHORTCUT, false, false);
- String text = "Navigate between answer placeholders with " + SHORTCUT_TAG + shortcut1 +
- "/" + shortcut2 + SHORTCUT_CLOSING_TAG;
- painter.appendLine(text).smaller().withBullet();
- shortcut1 = getShortcutText(StudyPreviousStudyTaskAction.ACTION_ID, StudyPreviousStudyTaskAction.SHORTCUT, false, false);
- shortcut2 = getShortcutText(StudyNextStudyTaskAction.ACTION_ID, StudyNextStudyTaskAction.SHORTCUT, false, false);
- painter.appendLine("Navigate between tasks with " +SHORTCUT_TAG + shortcut1 + "/" + shortcut2 + SHORTCUT_CLOSING_TAG).smaller().withBullet();
- addAction(painter, "Reset current task file", StudyRefreshTaskFileAction.ACTION_ID, StudyRefreshTaskFileAction.SHORTCUT, false);
- addAction(painter, "Check task", StudyCheckAction.ACTION_ID, StudyCheckAction.SHORTCUT, false);
- addAction(painter, "Get hint for the answer placeholder", StudyShowHintAction.ACTION_ID, StudyShowHintAction.SHORTCUT, false);
- painter.appendLine("To see your progress open the '" + StudyProgressToolWindowFactory.ID + "' panel").smaller().withBullet();
- painter.draw(g, new PairFunction<Integer, Integer, Couple<Integer>>() {
- @Override
- public Couple<Integer> fun(Integer width, Integer height) {
- Dimension s = splitters.getSize();
- return Couple.of((s.width - width) / 2, (s.height - height) / 2);
- }
- });
- }
- private static void addAction(UIUtil.TextPainter painter, String text, String actionId, String defaultShortcutString, boolean useDefault) {
- String shortcut = getShortcutText(actionId, defaultShortcutString, useDefault, true);
- String actionText = text + " with " + shortcut;
- painter.appendLine(actionText).smaller().withBullet();
- }
-
- private static String getShortcutText(String actionId, String defaultShortcutString, boolean useDefault, boolean wrapTag) {
- AnAction action = ActionManager.getInstance().getAction(actionId);
- String shortcut = "";
- if (!useDefault) {
- shortcut = KeymapUtil.getFirstKeyboardShortcutText(action);
- }
- if (shortcut.isEmpty() && defaultShortcutString != null) {
- KeyboardShortcut keyboardShortcut = new KeyboardShortcut(KeyStroke.getKeyStroke(defaultShortcutString), null);
- shortcut = KeymapUtil.getShortcutText(keyboardShortcut);
- }
- if (!wrapTag) {
- return shortcut;
- }
- return SHORTCUT_TAG + shortcut + SHORTCUT_CLOSING_TAG;
+ protected void advertiseActions(@NotNull JComponent splitters, @NotNull UIUtil.TextPainter painter) {
+ String shortcut = KeymapUtil.getShortcutText(new KeyboardShortcut(KeyStroke.getKeyStroke(StudyNextWindowAction.SHORTCUT2), null));
+ appendAction(painter, "Navigate to the next answer placeholder", shortcut);
+ appendAction(painter, "Navigate between answer placeholders", getActionShortcutText(StudyPrevWindowAction.ACTION_ID) + separator +
+ getActionShortcutText(StudyNextWindowAction.ACTION_ID));
+ appendAction(painter, "Navigate between tasks", getActionShortcutText(StudyPreviousStudyTaskAction.ACTION_ID) + separator +
+ getActionShortcutText(StudyNextStudyTaskAction.ACTION_ID));
+ appendAction(painter, "Reset current task file", getActionShortcutText(StudyRefreshTaskFileAction.ACTION_ID));
+ appendAction(painter, "Check task", getActionShortcutText(StudyCheckAction.ACTION_ID));
+ appendAction(painter, "Get hint for the answer placeholder", getActionShortcutText(StudyShowHintAction.ACTION_ID));
+ appendLine(painter,"To see your progress open the '" + StudyProgressToolWindowFactory.ID + "' panel");
}
-}
+}
\ No newline at end of file