Wizard: do now allow project view occupy all space

This commit is contained in:
Ilya Kirillov
2020-04-07 19:42:47 +03:00
parent 80f09d66db
commit 91af859cb5
6 changed files with 96 additions and 31 deletions
@@ -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
}
}
@@ -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
@@ -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)
@@ -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
@@ -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)
}
@@ -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)