diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/SmartTwoComponentPanel.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/SmartTwoComponentPanel.kt new file mode 100644 index 00000000000..f370d43d2e3 --- /dev/null +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/SmartTwoComponentPanel.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.tools.projectWizard.wizard.ui + +import javax.swing.JComponent +import javax.swing.JPanel +import javax.swing.Spring +import javax.swing.SpringLayout + +class SmartTwoComponentPanel( + main: JComponent, + side: JComponent, + sideIsOnTheRight: Boolean +) : JPanel(SpringLayout()) { + private val springLayout = this@SmartTwoComponentPanel.layout as SpringLayout + private fun JComponent.constraints() = springLayout.getConstraints(this) + + init { + add(main) + add(side) + + val left = if (sideIsOnTheRight) main else side + val right = if (sideIsOnTheRight) side else main + + springLayout.putConstraint(SpringLayout.WEST, left, 0, SpringLayout.WEST, this) + springLayout.putConstraint(SpringLayout.NORTH, left, 0, SpringLayout.NORTH, this) + + springLayout.putConstraint(SpringLayout.WEST, right, 0, SpringLayout.EAST, left) + springLayout.putConstraint(SpringLayout.NORTH, right, 0, SpringLayout.NORTH, this) + + springLayout.putConstraint(SpringLayout.EAST, this, 0, SpringLayout.EAST, right) + springLayout.putConstraint(SpringLayout.SOUTH, this, 0, SpringLayout.SOUTH, right) + springLayout.putConstraint(SpringLayout.SOUTH, left, 0, SpringLayout.SOUTH, this) + + val mainConstraints = main.constraints() + val sideConstraints = side.constraints() + + mainConstraints.width = Spring.max(mainConstraints.width, MAIN_PANEL_MIN_WIDTH.asSpring()) + sideConstraints.width = springMin(sideConstraints.width, SIDE_PANEL_MAX_WIDTH.asSpring()) + } + + companion object { + private const val MAIN_PANEL_MIN_WIDTH = 500 + private const val SIDE_PANEL_MAX_WIDTH = 280 + } +} \ No newline at end of file diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt index 2b207481e35..3c96cac5e22 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.roots.ui.configuration.JdkComboBox import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel import com.intellij.openapi.util.Condition import com.intellij.ui.JBColor +import com.intellij.ui.ScrollPaneFactory import com.intellij.ui.TitledSeparator import com.intellij.ui.layout.panel import com.intellij.util.ui.JBUI @@ -27,7 +28,6 @@ import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.createSettingC import java.awt.Cursor import java.awt.event.MouseAdapter import java.awt.event.MouseEvent -import javax.swing.BorderFactory import javax.swing.JComponent class FirstWizardStepComponent(ideWizard: IdeWizard) : WizardStepComponent(ideWizard.context) { @@ -35,10 +35,11 @@ class FirstWizardStepComponent(ideWizard: IdeWizard) : WizardStepComponent(ideWi private val projectSettingsComponent = ProjectSettingsComponent(ideWizard).asSubComponent() private val projectPreviewComponent = ProjectPreviewComponent(context).asSubComponent() - override val component: JComponent = borderPanel { - addToCenter(projectSettingsComponent.component) - addToRight(projectPreviewComponent.component) - } + override val component: JComponent = SmartTwoComponentPanel( + projectSettingsComponent.component, + projectPreviewComponent.component, + sideIsOnTheRight = true + ) } class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizard.context) { @@ -62,7 +63,7 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar ).asSubComponent() override val component: JComponent by lazy(LazyThreadSafetyMode.NONE) { - panel { + val panel = panel { row { nameAndLocationComponent.component(growX) } @@ -70,6 +71,9 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar buildSystemAdditionalSettingsComponent.component(growX) } }.addBorder(JBUI.Borders.emptyRight(UIConstants.PADDING)) + ScrollPaneFactory.createScrollPane(panel, true).apply { + viewport.background = JBColor.PanelBackground + } } private var locationWasUpdatedByHand: Boolean = false diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt index 635edfc40db..c4f65df5d30 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt @@ -11,10 +11,6 @@ import org.jetbrains.kotlin.tools.projectWizard.wizard.KotlinNewProjectWizardUIB import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.* import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEditor.ModulesEditorComponent import java.awt.BorderLayout -import java.awt.Dimension -import javax.swing.Box -import javax.swing.BoxLayout -import javax.swing.JPanel class SecondStepWizardComponent( wizard: IdeWizard, @@ -24,10 +20,11 @@ class SecondStepWizardComponent( ProjectStructureEditorComponent(wizard.context, uiEditorUsagesStats, ::onNodeSelected).asSubComponent() private val moduleSettingsComponent = ModuleSettingsSubStep(wizard, uiEditorUsagesStats).asSubComponent() - override val component = borderPanel { - addToLeft(moduleEditorComponent.component) - addToCenter(moduleSettingsComponent.component) - } + override val component = SmartTwoComponentPanel( + moduleSettingsComponent.component, + moduleEditorComponent.component, + sideIsOnTheRight = false + ) override fun navigateTo(error: ValidationResult.ValidationError) { moduleEditorComponent.navigateTo(error) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt index cf71f4b9ea6..fd49d1a507c 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt @@ -1,6 +1,7 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEditor import com.intellij.ui.JBColor +import com.intellij.ui.ScrollPaneFactory import com.intellij.util.ui.JBUI import org.jetbrains.kotlin.idea.projectWizard.UiEditorUsageStats import org.jetbrains.kotlin.tools.projectWizard.core.Context @@ -11,8 +12,6 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ProjectKind import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module -import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.UIConstants -import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.addBorder import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.customPanel import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.SettingComponent import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.ValidationIndicator @@ -90,9 +89,13 @@ class ModulesEditorComponent( } private fun createEditorComponent() = - (if (editable) toolbarDecorator!!.createToolPanel() else tree).apply { + when { + editable -> toolbarDecorator!!.createToolPanel() + else -> ScrollPaneFactory.createScrollPane(tree, true).apply { + viewport.background = JBColor.PanelBackground + } + }.apply { preferredSize = Dimension(TREE_WIDTH, preferredSize.height) - minimumSize = Dimension(TREE_WIDTH, minimumSize.height) } override val validationIndicator: ValidationIndicator? = null diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/TitledComponentsList.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/TitledComponentsList.kt index b8b7cdefc55..5ba2306da91 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/TitledComponentsList.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/TitledComponentsList.kt @@ -80,7 +80,7 @@ open class TitledComponentsList( var lastLabel: SpringLayout.Constraints? = null var lastComponent: SpringLayout.Constraints? = null - for ((index, data) in componentsWithLabels.withIndex()) { + for (data in componentsWithLabels) { val (label, component) = data label.x = xPanelPadding.asSpring() component.x = label[SpringLayout.EAST] + xGap @@ -120,15 +120,3 @@ open class TitledComponentsList( ) } -private operator fun Spring.plus(other: Spring) = Spring.sum(this, other) -private operator fun Spring.plus(gap: Int) = Spring.sum(this, Spring.constant(gap)) -private operator fun Spring.minus(other: Spring) = this + Spring.minus(other) -private operator fun Spring.unaryMinus() = Spring.minus(this) -private operator fun Spring.times(by: Float) = Spring.scale(this, by) -private fun Int.asSpring() = Spring.constant(this) -private operator fun SpringLayout.Constraints.get(edgeName: String) = getConstraint(edgeName) -private operator fun SpringLayout.Constraints.set(edgeName: String, spring: Spring) { - setConstraint(edgeName, spring) -} - - diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/springUtils.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/springUtils.kt new file mode 100644 index 00000000000..b61fd0740f7 --- /dev/null +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/springUtils.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.tools.projectWizard.wizard.ui + +import javax.swing.Spring +import javax.swing.SpringLayout + +internal operator fun Spring.plus(other: Spring) = Spring.sum(this, other) +internal operator fun Spring.plus(gap: Int) = Spring.sum(this, Spring.constant(gap)) +internal operator fun Spring.minus(other: Spring) = this + Spring.minus(other) +internal operator fun Spring.unaryMinus() = Spring.minus(this) +internal operator fun Spring.times(by: Float) = Spring.scale(this, by) +internal fun Int.asSpring() = Spring.constant(this) +internal operator fun SpringLayout.Constraints.get(edgeName: String) = getConstraint(edgeName) +internal operator fun SpringLayout.Constraints.set(edgeName: String, spring: Spring) { + setConstraint(edgeName, spring) +} + +fun springMin(s1: Spring, s2: Spring) = -Spring.max(-s1, -s2) + +