Skip to content

Commit

Permalink
Merge branch 'release/0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
0legg committed Feb 21, 2017
2 parents b497364 + 5dcebb3 commit ca9f775
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 85 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.2

- Fixed plugin crash when JavaFX is not present
- Added player controls (play, pause, loop)
- Updated bodymovin to 4.5.7

## 0.0.1

- Initial release
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ Grab fresh copy from [releases page](https://github.com/0legg/bodylookin/release

## Requirements

- Oracle JDK 8 (plugin depends on JavaFX browser component)
- Oracle JDK 8 (plugin depends on JavaFX browser component).
- If you're getting message that your IDE runs unsupported JDK, follow instructions for
[IntellijJ IDEA](https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under) or [Android Studio](http://tools.android.com/tech-docs/configuration)
to set up proper JDK for your IDE.

This project uses source code of bodymovin library licensed under [MIT license](https://github.com/bodymovin/bodymovin/blob/master/LICENSE.md)

12 changes: 9 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ buildscript {
}

plugins {
id "org.jetbrains.intellij" version "0.2.1"
id "org.jetbrains.intellij" version "0.2.5"
id "com.zoltu.kotlin" version "1.0.6"
id 'nu.studer.credentials' version "1.0.1"
}

repositories {
Expand All @@ -21,8 +22,13 @@ dependencies {

intellij {
version '2016.1'
patchPluginXml.enabled false
updateSinceUntilBuild false
}

publishPlugin {
username credentials.JETBRAINS_USERNAME
password credentials.JETBRAINS_PASSWORD
}

group 'net.olegg'
version '0.0.1'
version '0.0.2'
24 changes: 24 additions & 0 deletions src/main/kotlin/net/olegg/bodylookin/BodylookinPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.olegg.bodylookin

import com.intellij.openapi.components.ApplicationComponent

/**
* Created by olegg on 2/15/17.
*/
class BodylookinPlugin : ApplicationComponent {

override fun getComponentName() = javaClass.name

val hasJavafx: Boolean by lazy {
try {
Class.forName("javafx.application.Platform")
return@lazy true
} catch (e: Exception) {
return@lazy false
}
}

override fun initComponent() { }

override fun disposeComponent() { }
}
9 changes: 0 additions & 9 deletions src/main/kotlin/net/olegg/bodylookin/Constants.kt

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/kotlin/net/olegg/bodylookin/Icons.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.olegg.bodylookin

import com.intellij.openapi.util.IconLoader

/**
* Created by olegg on 2/19/17.
*/
object Icons {
fun load(path: String) = IconLoader.getIcon(path)

val LOAD = load("/icons/wiggle.png")
val OPEN = load("/icons/in.png")
val PLAY = load("/icons/play.png")
val PAUSE = load("/icons/pause.png")
val LOOP = load("/icons/repeat.png")
}
35 changes: 0 additions & 35 deletions src/main/kotlin/net/olegg/bodylookin/action/LookAction.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package net.olegg.bodylookin.toolwindow

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.ui.components.JBLabel
import com.intellij.ui.content.ContentFactory
import com.intellij.util.ui.UIUtil
import net.olegg.bodylookin.BodylookinPlugin
import javax.swing.JComponent

/**
* Created by olegg on 2/12/17.
*/
class BodylookinFactory: ToolWindowFactory {

override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
val view = BodylookinView()
val view : JComponent = if (ApplicationManager.getApplication().getComponent(BodylookinPlugin::class.java).hasJavafx) {
BodylookinView()
} else {
JBLabel("""<html>Unable to instantiate JavaFX.
<br/><br/>
Please launch IDE using JDK with JavaFX bundled.</html>""", UIUtil.ComponentStyle.LARGE)
}

val content = ContentFactory.SERVICE.getInstance().createContent(view, null, false)
toolWindow.contentManager.addContent(content)
//val json = javaClass.classLoader.getResource("/data.json").readText()
}
}
95 changes: 79 additions & 16 deletions src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt
Original file line number Diff line number Diff line change
@@ -1,36 +1,99 @@
package net.olegg.bodylookin.toolwindow

import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.ui.components.JBPanel
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.ui.SimpleToolWindowPanel
import com.intellij.util.ui.JBUI
import javafx.application.Platform
import javafx.concurrent.Worker
import javafx.embed.swing.JFXPanel
import javafx.scene.Scene
import javafx.scene.web.WebEngine
import javafx.scene.web.WebView
import net.olegg.bodylookin.Constants
import java.awt.BorderLayout
import net.olegg.bodylookin.Icons
import netscape.javascript.JSObject

/**
* Created by olegg on 2/12/17.
*/
class BodylookinView : JBPanel<BodylookinView>(BorderLayout()) {
class BodylookinView : SimpleToolWindowPanel(true) {
val root: String = javaClass.classLoader.getResource("/bodylookin.html").toExternalForm()

val panel = JFXPanel()
lateinit var webview: WebView
lateinit var engine: WebEngine
var js: JSObject? = null

init {
val manager = ActionManager.getInstance()
val group = ActionManager.getInstance().getAction(Constants.ACTION_GROUP) as? ActionGroup
if (group != null) {
val toolbar = manager.createActionToolbar(ActionPlaces.TOOLWINDOW_TITLE, group, true)
add(BorderLayout.NORTH, toolbar.component)
val lookAction: AnAction = object : AnAction("Load from editor", "", Icons.LOAD) {
override fun actionPerformed(e: AnActionEvent?) {
val project = e?.project ?: return
val json = FileEditorManager.getInstance(project).selectedTextEditor?.document?.text
if (json != null) {
loadAnimation(json)
}
}
}

val playAction: AnAction = object : AnAction("Play", "", Icons.PLAY) {
override fun actionPerformed(e: AnActionEvent?) {
Platform.runLater {
js?.eval("""if (!this.loop && this.currentFrame >= this.totalFrames - 1) {
this.goToAndPlay(0, true);
} else {
this.play();
}""")
}
}

override fun update(e: AnActionEvent?) {
Platform.runLater {
e?.presentation?.isEnabled = js?.eval("this.isLoaded && this.isPaused") as? Boolean ?: false
}
}
}

val pauseAction: AnAction = object : AnAction("Pause", "", Icons.PAUSE) {
override fun actionPerformed(e: AnActionEvent?) {
Platform.runLater {
js?.eval("this.pause()")
}
}

override fun update(e: AnActionEvent?) {
Platform.runLater {
e?.presentation?.isEnabled = js?.eval("this.isLoaded && !this.isPaused") as? Boolean ?: false
}
}
}

val loopAction: AnAction = object : ToggleAction("Toggle loop", "", Icons.LOOP) {
var loop = true

override fun isSelected(e: AnActionEvent?): Boolean {
return loop
}

override fun setSelected(e: AnActionEvent?, state: Boolean) {
Platform.runLater {
loop = js?.eval("this.loop = $state") as? Boolean ?: state
}
}
add(BorderLayout.CENTER, panel)
}

init {
val group = DefaultActionGroup()
group.addAll(listOf(
lookAction,
Separator(),
playAction,
pauseAction,
loopAction
))

val toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.TOOLWINDOW_TITLE, group, true)
setToolbar(JBUI.Panels.simplePanel(toolbar.component))
setContent(panel)

Platform.setImplicitExit(false)
Platform.runLater {
webview = WebView()
Expand All @@ -57,11 +120,11 @@ class BodylookinView : JBPanel<BodylookinView>(BorderLayout()) {
if (engine.loadWorker.state != Worker.State.SUCCEEDED) {
engine.loadWorker.stateProperty().addListener { value, oldState, newState ->
if (newState == Worker.State.SUCCEEDED) {
engine.executeScript(script)
js = engine.executeScript(script) as? JSObject
}
}
} else {
engine.executeScript(script)
js = engine.executeScript(script) as? JSObject
}
}
}
Expand Down
27 changes: 13 additions & 14 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<idea-plugin>
<id>net.olegg.bodylookin</id>
<name>bodylookin</name>
<version>0.0.1</version>
<vendor email="[email protected]">Oleg Godovykh</vendor>

<description><![CDATA[
Expand All @@ -10,6 +9,12 @@
</description>

<change-notes><![CDATA[
<b>0.0.2</b>
<ul>
<li>Fixed plugin crash when JavaFX is not present</li>
<li>Added player controls (play, pause, loop)</li>
<li>Updated bodymovin to 4.5.7</li>
</ul>
<b>0.0.1</b>
<ul>
<li>Initial release</li>
Expand All @@ -20,25 +25,19 @@
<depends>com.intellij.modules.lang</depends>
<idea-version since-build="145"/>

<application-components>
<component>
<implementation-class>net.olegg.bodylookin.BodylookinPlugin</implementation-class>
</component>
</application-components>

<extensions defaultExtensionNs="com.intellij">
<toolWindow
id="bodylookin"
anchor="right"
secondary="true"
icon="/icons/wave.png"
factoryClass="net.olegg.bodylookin.toolwindow.BodylookinFactory"
/>
</extensions>

<actions>
<group id="bodylookin.ActionGroup">
<action
class="net.olegg.bodylookin.action.LookAction"
id="bodylookin.LookAction"
text="bodylookin"
icon="/icons/wave.png"
/>
<add-to-group group-id="ToolsMenu" anchor="last"/>
</group>
</actions>

</idea-plugin>
10 changes: 5 additions & 5 deletions src/main/resources/bodymovin.min.js

Large diffs are not rendered by default.

Binary file added src/main/resources/icons/in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/repeat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/icons/wave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/wiggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ca9f775

Please sign in to comment.