Skip to content

Commit

Permalink
Can copy text to clipboard; jar now generated with correct version
Browse files Browse the repository at this point in the history
  • Loading branch information
lunivore committed May 9, 2017
1 parent 6f8d0d4 commit 5b39863
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
group 'com.lunivore'
version '1.0-SNAPSHOT'
version '0.0.1-20170509'

buildscript {
ext.kotlin_version = '1.1.1'
ext.junitJupiterVersion = '5.0.0-M3'
ext.kotlinVersion = '1.1.1'
ext.junitJupiterVersion = '5.0.0-M4'
ext.mockitoVersion = "1.10.19"
ext.hamcrestVersion = "1.3"

repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4"
}
}

Expand All @@ -32,9 +32,9 @@ repositories {
}

dependencies {
exampleAppCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
exampleAppCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

testCompile sourceSets.exampleApp.output
testCompile("org.mockito:mockito-all:${mockitoVersion}")
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/com/lunivore/stirry/Stirry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import javafx.scene.Parent
import javafx.scene.control.Button
import javafx.scene.control.TextField
import javafx.scene.control.TextInputControl
import javafx.scene.input.Clipboard
import javafx.scene.input.DataFormat
import javafx.stage.Stage
import java.util.concurrent.ArrayBlockingQueue
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -96,5 +98,13 @@ class Stirry {
queue.poll(1L, TimeUnit.SECONDS)
textField.textProperty().removeListener(listener)
}

fun getClipboard(format: DataFormat): Any? {
waitForPlatform()
var result : Any? = null
Platform.runLater({ result = Clipboard.getSystemClipboard().getContent(format)} )
waitForPlatform()
return result
}
}
}
18 changes: 18 additions & 0 deletions src/test/kotlin/com/lunivore/stirry/StirryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.lunivore.stirry

import com.lunivore.stirry.Stirry.Companion.find
import com.lunivore.stirry.exampleapp.ExampleApp
import javafx.application.Platform
import javafx.scene.control.Button
import javafx.scene.control.TextField
import javafx.scene.input.Clipboard
import javafx.scene.input.DataFormat
import javafx.scene.layout.GridPane
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeAll
Expand Down Expand Up @@ -60,4 +63,19 @@ class StirryTest {
assertTrue(textSet)
assertEquals("Hello!", textField?.text)
}

@Test
fun shouldBeAbleToRecoverTextFromAClipboard() {
// Given the platform is initialized (which it is)
// and text has been put into the clipboard
val content = mutableMapOf<DataFormat, Any>()
content[DataFormat.PLAIN_TEXT] = "Clipped!"
Platform.runLater { Clipboard.getSystemClipboard().setContent(content)}

// When we ask Stirry to get the text
val result = Stirry.getClipboard(DataFormat.PLAIN_TEXT)

// Then it should be able to recover it for us
assertEquals("Clipped!", result)
}
}

0 comments on commit 5b39863

Please sign in to comment.