mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Educational Edition task window freeze on Macos 10.12.5
This commit is contained in:
+42
-35
@@ -1,11 +1,14 @@
|
||||
package com.jetbrains.edu.learning.editor
|
||||
|
||||
import com.intellij.ide.IdeEventQueue
|
||||
import com.intellij.ide.ui.LafManager
|
||||
import com.intellij.ide.ui.LafManagerListener
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import com.jetbrains.edu.learning.courseFormat.tasks.ChoiceTask
|
||||
import com.sun.javafx.application.PlatformImpl
|
||||
import javafx.application.Platform
|
||||
import javafx.beans.value.ObservableValue
|
||||
import javafx.embed.swing.JFXPanel
|
||||
@@ -30,51 +33,55 @@ class StudyChoiceVariantsPanel(task: ChoiceTask) : JScrollPane() {
|
||||
private val RIGHT_INSET = 10.0
|
||||
private val TOP_INSET = 15.0
|
||||
private val BOTTOM_INSET = 10.0
|
||||
|
||||
|
||||
private val buttons: ArrayList<ButtonBase> = ArrayList()
|
||||
|
||||
init {
|
||||
val jfxPanel = JFXPanel()
|
||||
LafManager.getInstance().addLafManagerListener(StudyLafManagerListener(jfxPanel))
|
||||
Platform.runLater {
|
||||
val group = Group()
|
||||
val scene = Scene(group, getSceneBackground())
|
||||
jfxPanel.scene = scene
|
||||
val vBox = VBox()
|
||||
vBox.spacing = 10.0
|
||||
vBox.padding = Insets(TOP_INSET, RIGHT_INSET, BOTTOM_INSET, LEFT_INSET)
|
||||
if (task.isMultipleChoice) {
|
||||
for ((index, variant) in task.choiceVariants.withIndex()) {
|
||||
val isSelected = task.selectedVariants.contains(index)
|
||||
val checkBox = CheckBox(variant)
|
||||
checkBox.isSelected = isSelected
|
||||
checkBox.selectedProperty().addListener(createSelectionListener(task, index))
|
||||
setUpButtonStyle(checkBox, scene)
|
||||
vBox.children.add(checkBox)
|
||||
buttons.add(checkBox)
|
||||
}
|
||||
}
|
||||
else {
|
||||
val toggleGroup = ToggleGroup()
|
||||
for ((index, variant) in task.choiceVariants.withIndex()) {
|
||||
val isSelected = task.selectedVariants.contains(index)
|
||||
val radioButton = RadioButton(variant)
|
||||
radioButton.toggleGroup = toggleGroup
|
||||
radioButton.isSelected = isSelected
|
||||
radioButton.selectedProperty().addListener(createSelectionListener(task, index))
|
||||
setUpButtonStyle(radioButton, scene)
|
||||
vBox.children.add(radioButton)
|
||||
buttons.add(radioButton)
|
||||
}
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
IdeEventQueue.unsafeNonblockingExecute(Runnable {
|
||||
PlatformImpl.runLater(Runnable {
|
||||
val group = Group()
|
||||
val scene = Scene(group, getSceneBackground())
|
||||
jfxPanel.scene = scene
|
||||
val vBox = VBox()
|
||||
vBox.spacing = 10.0
|
||||
vBox.padding = Insets(TOP_INSET, RIGHT_INSET, BOTTOM_INSET, LEFT_INSET)
|
||||
if (task.isMultipleChoice) {
|
||||
for ((index, variant) in task.choiceVariants.withIndex()) {
|
||||
val isSelected = task.selectedVariants.contains(index)
|
||||
val checkBox = CheckBox(variant)
|
||||
checkBox.isSelected = isSelected
|
||||
checkBox.selectedProperty().addListener(createSelectionListener(task, index))
|
||||
setUpButtonStyle(checkBox, scene)
|
||||
vBox.children.add(checkBox)
|
||||
buttons.add(checkBox)
|
||||
}
|
||||
}
|
||||
else {
|
||||
val toggleGroup = ToggleGroup()
|
||||
for ((index, variant) in task.choiceVariants.withIndex()) {
|
||||
val isSelected = task.selectedVariants.contains(index)
|
||||
val radioButton = RadioButton(variant)
|
||||
radioButton.toggleGroup = toggleGroup
|
||||
radioButton.isSelected = isSelected
|
||||
radioButton.selectedProperty().addListener(createSelectionListener(task, index))
|
||||
setUpButtonStyle(radioButton, scene)
|
||||
vBox.children.add(radioButton)
|
||||
buttons.add(radioButton)
|
||||
}
|
||||
}
|
||||
|
||||
group.children.add(vBox)
|
||||
group.children.add(vBox)
|
||||
})
|
||||
})
|
||||
}
|
||||
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER)
|
||||
setViewportView(jfxPanel)
|
||||
}
|
||||
|
||||
private fun getSceneBackground(): Color{
|
||||
private fun getSceneBackground(): Color {
|
||||
val isDarcula = LafManager.getInstance().currentLookAndFeel is DarculaLookAndFeelInfo
|
||||
val panelBackground = if (isDarcula) UIUtil.getPanelBackground() else UIUtil.getTextFieldBackground()
|
||||
return Color.rgb(panelBackground.red, panelBackground.green, panelBackground.blue)
|
||||
@@ -95,7 +102,7 @@ class StudyChoiceVariantsPanel(task: ChoiceTask) : JScrollPane() {
|
||||
button.isWrapText = true
|
||||
button.maxWidthProperty().bind(scene.widthProperty().subtract(LEFT_INSET).subtract(RIGHT_INSET))
|
||||
button.font = Font.font((EditorColorsManager.getInstance().globalScheme.editorFontSize + 2).toDouble())
|
||||
|
||||
|
||||
setButtonLaf(button)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.jetbrains.edu.learning.ui;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.ide.IdeEventQueue;
|
||||
import com.intellij.ide.ui.LafManager;
|
||||
import com.intellij.ide.ui.LafManagerListener;
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo;
|
||||
@@ -15,7 +16,7 @@ import com.jetbrains.edu.learning.EduPluginConfigurator;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.navigation.StudyNavigator;
|
||||
import javafx.application.Platform;
|
||||
import com.sun.javafx.application.PlatformImpl;
|
||||
import javafx.concurrent.Worker;
|
||||
import javafx.embed.swing.JFXPanel;
|
||||
import javafx.scene.Scene;
|
||||
@@ -77,7 +78,7 @@ public class StudyBrowserWindow extends JFrame {
|
||||
}
|
||||
|
||||
private void updateIntellijAndGTKLaf() {
|
||||
Platform.runLater(() -> {
|
||||
runLater(() -> {
|
||||
final URL scrollBarStyleUrl = getClass().getResource("/style/javaFXBrowserScrollBar.css");
|
||||
final URL engineStyleUrl = getClass().getResource("/style/javaFXBrowser.css");
|
||||
myPane.getStylesheets().add(scrollBarStyleUrl.toExternalForm());
|
||||
@@ -88,7 +89,7 @@ public class StudyBrowserWindow extends JFrame {
|
||||
}
|
||||
|
||||
private void updateLafDarcula() {
|
||||
Platform.runLater(() -> {
|
||||
runLater(() -> {
|
||||
final URL engineStyleUrl = getClass().getResource("/style/javaFXBrowserDarcula.css");
|
||||
final URL scrollBarStyleUrl = getClass().getResource("/style/javaFXBrowserDarculaScrollBar.css");
|
||||
myEngine.setUserStyleSheetLocation(engineStyleUrl.toExternalForm());
|
||||
@@ -100,7 +101,7 @@ public class StudyBrowserWindow extends JFrame {
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
Platform.runLater(() -> {
|
||||
runLater(() -> {
|
||||
myPane = new StackPane();
|
||||
myWebComponent = new WebView();
|
||||
myWebComponent.setOnDragDetected(event -> {});
|
||||
@@ -128,14 +129,6 @@ public class StudyBrowserWindow extends JFrame {
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
}
|
||||
|
||||
|
||||
public void load(@NotNull final String url) {
|
||||
Platform.runLater(() -> {
|
||||
updateLookWithProgressBarIfNeeded();
|
||||
myEngine.load(url);
|
||||
});
|
||||
}
|
||||
|
||||
public void loadContent(@NotNull final String content) {
|
||||
Course course = StudyTaskManager.getInstance(myProject).getCourse();
|
||||
if (course == null) {
|
||||
@@ -143,11 +136,11 @@ public class StudyBrowserWindow extends JFrame {
|
||||
}
|
||||
EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(course.getLanguageById());
|
||||
if (configurator == null) {
|
||||
Platform.runLater(() -> myEngine.loadContent(content));
|
||||
runLater(() -> myEngine.loadContent(content));
|
||||
}
|
||||
else {
|
||||
String withCodeHighlighting = createHtmlWithCodeHighlighting(content, configurator.getLanguageScriptUrl(), configurator.getDefaultHighlightingMode());
|
||||
Platform.runLater(() -> {
|
||||
runLater(() -> {
|
||||
updateLookWithProgressBarIfNeeded();
|
||||
myEngine.loadContent(withCodeHighlighting);
|
||||
});
|
||||
@@ -298,8 +291,12 @@ public class StudyBrowserWindow extends JFrame {
|
||||
});
|
||||
}
|
||||
|
||||
private static void runLater(@NotNull Runnable r) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> IdeEventQueue.unsafeNonblockingExecute(() -> PlatformImpl.runLater(r)));
|
||||
}
|
||||
|
||||
private void addButtonsAvailabilityListeners(JButton backButton, JButton forwardButton) {
|
||||
Platform.runLater(() -> myEngine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
|
||||
runLater(() -> myEngine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
|
||||
if (newState == Worker.State.SUCCEEDED) {
|
||||
final WebHistory history = myEngine.getHistory();
|
||||
boolean isGoBackAvailable = history.getCurrentIndex() > 0;
|
||||
@@ -319,7 +316,7 @@ public class StudyBrowserWindow extends JFrame {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 1) {
|
||||
Platform.runLater(() -> myEngine.getHistory().go(direction));
|
||||
runLater(() -> myEngine.getHistory().go(direction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user