From b081535bb6a4af3c481454c2e072b8bcf02aee4c Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 5 Oct 2015 21:27:31 +0300 Subject: [PATCH] kotlin-swing can be found in its own repository: https://github.com/kotlin-projects/kotlin-swing --- libraries/kotlin-swing/ReadMe.md | 11 -- libraries/kotlin-swing/pom.xml | 114 ---------------- .../src/main/kotlin/kotlin/swing/Actions.kt | 27 ---- .../main/kotlin/kotlin/swing/BorderPanel.kt | 90 ------------- .../src/main/kotlin/kotlin/swing/Builders.kt | 18 --- .../src/main/kotlin/kotlin/swing/Buttons.kt | 11 -- .../main/kotlin/kotlin/swing/Components.kt | 59 --------- .../main/kotlin/kotlin/swing/Dimensions.kt | 32 ----- .../src/main/kotlin/kotlin/swing/Frames.kt | 55 -------- .../src/main/kotlin/kotlin/swing/Layouts.kt | 37 ------ .../src/main/kotlin/kotlin/swing/Menus.kt | 124 ------------------ .../kotlin/test/kotlin/swing/SwingSample.kt | 53 -------- libraries/pom.xml | 1 - 13 files changed, 632 deletions(-) delete mode 100644 libraries/kotlin-swing/ReadMe.md delete mode 100644 libraries/kotlin-swing/pom.xml delete mode 100644 libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Actions.kt delete mode 100644 libraries/kotlin-swing/src/main/kotlin/kotlin/swing/BorderPanel.kt delete mode 100644 libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Builders.kt delete mode 100644 libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Buttons.kt delete mode 100644 libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Components.kt delete mode 100644 libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Dimensions.kt delete mode 100644 libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Frames.kt delete mode 100644 libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Layouts.kt delete mode 100644 libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Menus.kt delete mode 100644 libraries/kotlin-swing/src/test/kotlin/test/kotlin/swing/SwingSample.kt diff --git a/libraries/kotlin-swing/ReadMe.md b/libraries/kotlin-swing/ReadMe.md deleted file mode 100644 index 6fb1a0aa3c2..00000000000 --- a/libraries/kotlin-swing/ReadMe.md +++ /dev/null @@ -1,11 +0,0 @@ -## Kotlin Swing - -The Kotlin Swing library provides some helper functions and extensions for creating Swing user interfaces. - -To try the sample run - - cd kotlin/libraries/kotlin-swing - mvn test -Pui - -Or browse the [source of the sample](https://github.com/JetBrains/kotlin/blob/master/libraries/kotlin-swing/src/test/kotlin/test/kotlin/swing/SwingSample.kt) -to see the kinds of features available \ No newline at end of file diff --git a/libraries/kotlin-swing/pom.xml b/libraries/kotlin-swing/pom.xml deleted file mode 100644 index 7550d600330..00000000000 --- a/libraries/kotlin-swing/pom.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - - 4.0.0 - - - org.jetbrains.kotlin - kotlin-project - 0.1-SNAPSHOT - - - kotlin-swing - - - - org.jetbrains.kotlin - kotlin-stdlib - ${project.version} - - - - - - src/main/kotlin - src/test/kotlin - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${project.version} - - - - compile - compile - - compile - - - - - test-compile - test-compile - - test-compile - - - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - java - - - - - demo.DemoPackage - test - - - java.awt.headless - false - - - - - - - - - - - - - - ui - - false - - - - - org.apache.maven.plugins - maven-antrun-plugin - 1.7 - - - run - test - - - - - - - run - - - - - - - - - diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Actions.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Actions.kt deleted file mode 100644 index 8ce71659b33..00000000000 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Actions.kt +++ /dev/null @@ -1,27 +0,0 @@ -package kotlin.swing - -import java.awt.event.ActionEvent -import javax.swing.AbstractAction -import javax.swing.Action -import javax.swing.Action.* -import javax.swing.Icon - -/** - * Helper method to create an action from a function - */ -fun action(text: String, description: String? = null, mnemonic: Int? = null, icon: Icon? = null, fn: (ActionEvent) -> Unit): Action { - val answer = object: AbstractAction(text, icon) { - public override fun actionPerformed(e: ActionEvent) { - val event: ActionEvent = if (e != null) { - e - } else { - // lets create a dummy event - ActionEvent(this, ActionEvent.ACTION_PERFORMED, text) - } - (fn)(event) - } - } - if (description != null) answer.putValue(SHORT_DESCRIPTION, description) - if (mnemonic != null) answer.putValue(MNEMONIC_KEY, mnemonic) - return answer -} \ No newline at end of file diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/BorderPanel.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/BorderPanel.kt deleted file mode 100644 index 7956abb49a6..00000000000 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/BorderPanel.kt +++ /dev/null @@ -1,90 +0,0 @@ -package kotlin.swing - -import javax.swing.* -import java.awt.event.* -import java.awt.* - - -// TODO ideally should use BorderPanel as only that class should have -// the north / south / east west properties -fun borderPanel(init: JPanel.() -> Unit): JPanel { - val p = JPanel() - p.init() - return p -} - - -/** - TODO compile error -class BorderPanel(layout: BorderLayout = BorderLayout(), init: BorderPanel.() -> Unit): JPanel(layout) { - { - this.init() - } - - var south: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.SOUTH) - } - - var north: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.NORTH) - } - - var east: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.EAST) - } - - var west: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.WEST) - } - - var center: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.CENTER) - } - -} - -*/ - - - - -// TODO remove these properties when we can zap -var Container.south: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.SOUTH) - } - -var Container.north: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.NORTH) - } - -var Container.east: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.EAST) - } - -var Container.west: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.WEST) - } - -var Container.center: JComponent - get() = throw UnsupportedOperationException() - set(comp) { - add(comp, BorderLayout.CENTER) - } diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Builders.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Builders.kt deleted file mode 100644 index 4db1a8f1a3b..00000000000 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Builders.kt +++ /dev/null @@ -1,18 +0,0 @@ -package kotlin.swing - -import javax.swing.* -import java.awt.event.* -import java.awt.* - - -fun frame(title : String, init : JFrame.() -> Unit) : JFrame { - val result = JFrame(title) - result.init() - return result -} - -fun panel(init: JPanel.() -> Unit): JPanel { - val p = JPanel() - p.init() - return p -} diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Buttons.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Buttons.kt deleted file mode 100644 index 5a210ca4683..00000000000 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Buttons.kt +++ /dev/null @@ -1,11 +0,0 @@ -package kotlin.swing - -import javax.swing.* -import java.awt.event.* -import java.awt.* - -fun button(text: String, action: (ActionEvent) -> Unit): JButton { - val result = JButton(text) - result.addActionListener(action) - return result -} diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Components.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Components.kt deleted file mode 100644 index 46cff27d79a..00000000000 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Components.kt +++ /dev/null @@ -1,59 +0,0 @@ -package kotlin.swing - -import java.awt.Dimension -import java.awt.Component -import javax.swing.JComponent - -var JComponent.description: String? - get() { - return getAccessibleContext()?.getAccessibleDescription() - } - set(value) { - getAccessibleContext()?.setAccessibleDescription(value) - } - -var JComponent.preferredWidth: Int - get() = getPreferredSize().width() - set(value) { - setPreferredSize(getPreferredSize().width(value)) - } -var JComponent.preferredHeight: Int - get() = getPreferredSize().height() - set(value) { - setPreferredSize(getPreferredSize().height(value)) - } - -var Component.minimumWidth: Int - get() = getMinimumSize().width() - set(value) { - setMinimumSize(getMinimumSize().width(value)) - } -var Component.minimumHeight: Int - get() = getMinimumSize().height() - set(value) { - setMinimumSize(getMinimumSize().height(value)) - } - -var Component.maximumWidth: Int - get() = getMaximumSize().width() - set(value) { - setMaximumSize(getMaximumSize().width(value)) - } -var Component.maximumHeight: Int - get() = getMaximumSize().height() - set(value) { - setMaximumSize(getMaximumSize().height(value)) - } - -var Component.width: Int - get() = getSize().width() - set(value) { - setSize(getSize().width(value)) - } -var Component.height: Int - get() = getSize().height() - set(value) { - setSize(getSize().height(value)) - } - - diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Dimensions.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Dimensions.kt deleted file mode 100644 index 74778e43d9a..00000000000 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Dimensions.kt +++ /dev/null @@ -1,32 +0,0 @@ -package kotlin.swing - -import java.awt.Dimension -import java.awt.Component -import javax.swing.JComponent - -/** - * Returns the width of the dimension or zero if its null - */ -fun Dimension?.width(): Int { - return if (this == null) 0 else this.width -} - -/** - * Returns the height of the dimension or zero if its null - */ -fun Dimension?.height(): Int { - return if (this == null) 0 else this.height -} - -/** - * Returns a new dimension with the same height and the given width - */ -fun Dimension?.width(newValue: Int): Dimension { - return Dimension(newValue, height()) -} -/** - * Returns a new dimension with the same width and the given height - */ -fun Dimension?.height(newValue: Int): Dimension { - return Dimension(width(), newValue) -} diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Frames.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Frames.kt deleted file mode 100644 index 8fdeaf8c221..00000000000 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Frames.kt +++ /dev/null @@ -1,55 +0,0 @@ -package kotlin.swing - -import javax.swing.* -import java.awt.event.* -import java.awt.* - - -fun JFrame.exitOnClose(): Unit { - // TODO causes compile error - //defaultCloseOperation = JFrame.EXIT_ON_CLOSE - defaultCloseOperation = 3 -} - -var JFrame.defaultCloseOperation: Int - get() = getDefaultCloseOperation() - set(def) { - setDefaultCloseOperation(def) - } - - -var JFrame.contentPane: Container? - get() = getContentPane() - set(value) { - setContentPane(value!!) - } - -var JFrame.title: String - get() = getTitle()!! - set(t) { - setTitle(t) - } - -var JFrame.size: Pair - get() = Pair(getSize()!!.getWidth().toInt(), getSize()!!.getHeight().toInt()) - set(dim) { - setSize(Dimension(dim.first, dim.second)) - } - -var JFrame.height: Int - get() = getSize()!!.getHeight().toInt() - set(h) { - setSize(width, h) - } - -var JFrame.width: Int - get() = getSize()!!.getWidth().toInt() - set(w) { - setSize(height, w) - } - -var JFrame.jmenuBar: JMenuBar? - get() = getJMenuBar() - set(value) { - setJMenuBar(value) - } diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Layouts.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Layouts.kt deleted file mode 100644 index e071902c9ff..00000000000 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Layouts.kt +++ /dev/null @@ -1,37 +0,0 @@ -package kotlin.swing - -import java.awt.GridBagConstraints - -/** - * Helper function to create a [GridBagConstraints] - */ -fun gridBagContraints(gridx: Int? = null, gridy: Int? = null, fill: Int? = null, anchor: Int? = null, - gridwidth: Int? = null, gridheight: Int? = null, - weightx: Double? = null, weighty: Double? = null): GridBagConstraints { - val answer = GridBagConstraints() - if (gridx != null) { - answer.gridx = gridx - } - if (gridy != null) { - answer.gridy = gridy - } - if (fill != null) { - answer.fill = fill - } - if (anchor != null) { - answer.anchor = anchor - } - if (gridwidth != null) { - answer.gridwidth = gridwidth - } - if (gridheight != null) { - answer.gridheight = gridheight - } - if (weightx != null) { - answer.weightx = weightx - } - if (weighty != null) { - answer.weighty = weighty - } - return answer -} \ No newline at end of file diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Menus.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Menus.kt deleted file mode 100644 index 90d54edb95c..00000000000 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Menus.kt +++ /dev/null @@ -1,124 +0,0 @@ -package kotlin.swing - -import javax.swing.* - -public fun JMenuBar.menu(text: String, init: JMenu.() -> Unit): JMenu { - val answer = JMenu(text) - answer.init() - add(answer) - return answer; -} - -public fun JPopupMenu.menu(text: String, init: JMenu.() -> Unit): JMenu { - val answer = JMenu(text) - answer.init() - add(answer) - return answer; -} - -var JMenu.mnemonic: Int -get() { - return getMnemonic() -} -set(value) { - setMnemonic(value) -} - -var JMenu.accelerator: KeyStroke? -get() { - return getAccelerator() -} -set(value) { - setAccelerator(value) -} - -fun JMenu.item(vararg actions: Action): Unit { - for (action in actions) { - val answer = JMenuItem(action) - add(answer) - } -} - -fun JMenu.item(text: String, description: String? = null, mnemonic: Char? = null, accelerator: KeyStroke? = null): JMenuItem { - val answer = menuItem(text, description, mnemonic, accelerator) - add(answer) - return answer -} - -fun JMenu.checkBoxItem(text: String, description: String? = null, mnemonic: Char? = null, accelerator: KeyStroke? = null): JCheckBoxMenuItem { - val answer = checkBoxMenuItem(text, description, mnemonic, accelerator) - add(answer) - return answer -} - -fun JMenu.radioButtonItem(text: String, description: String? = null, mnemonic: Char? = null, accelerator: KeyStroke? = null): JRadioButtonMenuItem { - val answer = radioButtonMenuItem(text, description, mnemonic, accelerator) - add(answer) - return answer -} - -/** - * Helper method to create a new [JMenuItem] - */ -public fun menuItem(text: String, description: String? = null, mnemonic: Char? = null, accelerator: KeyStroke? = null): JMenuItem { - return configureMenuItem(JMenuItem(text), description, mnemonic, accelerator) -} - -/** - * Helper method to create a new [JCheckBoxMenuItem] - */ -public fun checkBoxMenuItem(text: String, description: String? = null, mnemonic: Char? = null, accelerator: KeyStroke? = null): JCheckBoxMenuItem { - return configureMenuItem(JCheckBoxMenuItem(text), description, mnemonic, accelerator) -} - -/** - * Helper method to create a new [JRadioButtonMenuItem] - */ -public fun radioButtonMenuItem(text: String, description: String? = null, mnemonic: Char? = null, accelerator: KeyStroke? = null): JRadioButtonMenuItem { - return configureMenuItem(JRadioButtonMenuItem(text), description, mnemonic, accelerator) -} - -/** - * Helper method to create a new [JMenuItem] - */ -fun configureMenuItem(answer: T, description: String?, mnemonic: Char?, accelerator: KeyStroke?): T { - if (description != null) { - answer.getAccessibleContext()?.setAccessibleDescription(description) - } - if (mnemonic != null) { - answer.setMnemonic(mnemonic) - } - if (accelerator != null) { - answer.setAccelerator(accelerator) - } - return answer -} - -/** - * Helper function to create a [KeyStroke] - */ -public fun keyStroke(keyChar: Char, modifiers: Int?): KeyStroke? { - return if (modifiers != null) { - KeyStroke.getKeyStroke(keyChar, modifiers) - } else { - KeyStroke.getKeyStroke(keyChar) - } -} - -/** - * Creates a [JMenuBar] from a list of [JMenu] objects - */ -public fun menuBar(init: JMenuBar.() -> Unit): JMenuBar { - val answer = JMenuBar() - answer.init() - return answer -} - -/** - * Creates a [JPopupMenu] from a list of [JMenu] objects - */ -public fun popupMenu(init: JPopupMenu.() -> Unit): JPopupMenu { - val answer = JPopupMenu() - answer.init() - return answer -} diff --git a/libraries/kotlin-swing/src/test/kotlin/test/kotlin/swing/SwingSample.kt b/libraries/kotlin-swing/src/test/kotlin/test/kotlin/swing/SwingSample.kt deleted file mode 100644 index 89d9f12a88b..00000000000 --- a/libraries/kotlin-swing/src/test/kotlin/test/kotlin/swing/SwingSample.kt +++ /dev/null @@ -1,53 +0,0 @@ -package demo - -import javax.swing.* -import kotlin.swing.* - -fun main(args: Array): Unit { - - val greeting = """ -Welcome to Kotlin - -Enter some text here! -""" - - val f = frame("Kool Kotlin Swing Demo") { - exitOnClose() - - val aboutAction = action("About") { - println("Show about window") - } - val propertiesAction = action("Properties") { - println("Show Properties window") - } - - jmenuBar = menuBar{ - menu("File") { - add(aboutAction) - } - menu("Help") { - add(propertiesAction) - } - } - - size = Pair(500, 300) - - val textArea = JTextArea(greeting) - - center = textArea - south = borderPanel { - west = button("Clear") { - textArea.setText("") - println("Cleared text!") - } - east = button("Restore") { - textArea.setText(greeting) - println("Restored text!") - } - } - - } - - f.setLocationRelativeTo(null) - f.setVisible(true) -} \ No newline at end of file diff --git a/libraries/pom.xml b/libraries/pom.xml index a748ab0472f..c9da886d8f4 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -98,7 +98,6 @@ kunit kotlin-jdbc - kotlin-swing examples/kotlin-java-example examples/js-example