Skip to content

Commit

Permalink
Merge develop
Browse files Browse the repository at this point in the history
Conflicts:
	pom.xml
	src/main/java/org/chrisle/netbeans/plugins/nbscratchfile/CreateScratchFile.java
  • Loading branch information
Chris2011 committed Aug 30, 2018
2 parents 4983249 + 60700c6 commit 8686fe6
Show file tree
Hide file tree
Showing 107 changed files with 27,513 additions and 849 deletions.
58 changes: 46 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.chrisle.netbeans.plugins</groupId>
<artifactId>NbScratchFile</artifactId>
<version>1.7.2</version>
<version>1.8.0-SNAPSHOT</version>
<packaging>nbm</packaging>
<name>NbScratchFile</name>
<description>&lt;h1&gt;Scratch Files for Netbeans (Required JDK 8 &gt; 1.8.0_122 - &lt;a href="https://github.com/Chris2011/NbScratchFile/issues/1#issuecomment-331884374"&gt;#1&lt;/a&gt;)&lt;/h1&gt;
Expand Down Expand Up @@ -46,6 +46,7 @@
<exclude>**/ui/tests/**</exclude>
<exclude>**/ui/node_modules/**</exclude>
<exclude>**/ui/node/**</exclude>
<exclude>**/ui/.tmp/**</exclude>
</excludes>
</resource>
</resources>
Expand Down Expand Up @@ -82,29 +83,30 @@
<version>1.6</version>
<executions>
<execution>
<id>install node and npm</id>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-npm</goal>
<goal>install-node-and-yarn</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<id>yarn install</id>
<goals>
<goal>npm</goal>
<goal>yarn</goal>
</goals>
</execution>
<execution>
<id>npm run build-prod</id>
<id>yarn run build-prod</id>
<goals>
<goal>npm</goal>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>run build-prod</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>v7.5.0</nodeVersion>
<nodeVersion>v10.5.0</nodeVersion>
<yarnVersion>v1.7.0</yarnVersion>
<workingDirectory>src/main/resources/org/chrisle/netbeans/plugins/nbscratchfile/ui</workingDirectory>
</configuration>
</plugin>
Expand All @@ -119,6 +121,7 @@
<keystorealias>${project.author}</keystorealias>
<keystorepassword>${project.artifactId}</keystorepassword>
<homePageUrl>https://github.com/Chris2011/NbScratchFile</homePageUrl>
<verifyIntegrity>false</verifyIntegrity>
<useOSGiDependencies>true</useOSGiDependencies>
</configuration>
</plugin>
Expand Down Expand Up @@ -152,7 +155,7 @@
<plugin>
<groupId>org.netbeans.html</groupId>
<artifactId>html4j-maven-plugin</artifactId>
<version>1.3</version>
<version>1.5.1</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -225,15 +228,46 @@
<version>RELEASE82</version>
</dependency>
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>net-java-html-boot</artifactId>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-api-htmlui</artifactId>
<version>RELEASE82</version>
<type>jar</type>
<exclusions>
<exclusion>
<groupId>org.netbeans.external</groupId>
<artifactId>net-java-html-boot</artifactId>
</exclusion>
<exclusion>
<groupId>org.netbeans.external</groupId>
<artifactId>net-java-html-boot-fx</artifactId>
</exclusion>
<exclusion>
<groupId>org.netbeans.external</groupId>
<artifactId>net-java-html</artifactId>
</exclusion>
<exclusion>
<groupId>org.netbeans.external</groupId>
<artifactId>net-java-html-geo</artifactId>
</exclusion>
<exclusion>
<groupId>org.netbeans.external</groupId>
<artifactId>net-java-html-json</artifactId>
</exclusion>
<exclusion>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-libs-javafx</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-api-htmlui</artifactId>
<artifactId>org-openide-modules</artifactId>
<version>RELEASE82</version>
</dependency>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>net.java.html.boot</artifactId>
<version>1.3</version>
<type>jar</type>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,142 +1,56 @@
/*
* Copyright 2017 Chris2011.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.chrisle.netbeans.plugins.nbscratchfile;

import java.awt.Component;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.KeyStroke;
import net.java.html.js.JavaScriptBody;
import org.netbeans.api.htmlui.HTMLComponent;
import org.netbeans.api.htmlui.HTMLDialog;
import org.chrisle.netbeans.plugins.utils.WebViewDialog;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;

/**
*
* @author Chris2011
*/
@ActionID(
category = "Tools",
id = "org.chrisle.netbeans.plugins.nbscratchfile.CreateScratchFile"
category = "Tools",
id = "org.chrisle.netbeans.plugins.nbscratchfile.CreateScratchFile"
)
@ActionRegistration(
displayName = "#CTL_CreateScratchFile",
iconBase = "org/chrisle/netbeans/plugins/nbscratchfile/add_file.png"
displayName = "#CTL_CreateScratchFile",
iconBase = "org/chrisle/netbeans/plugins/nbscratchfile/add_file.png"
)
@ActionReferences({
@ActionReference(path = "Menu/File", position = 150)
,
@ActionReference(path = "Menu/File", position = 150),
@ActionReference(path = "Shortcuts", name = "DOS-N")
})
@Messages("CTL_CreateScratchFile=New Scratch File...")
public final class CreateScratchFile implements ActionListener {
private final JDialog dialog;
private final JComponent jfxPanel;
private final NbScratchFileViewModel viewModel;
private static WebViewDialog _dialog;
public static final String viewPath = "/org/chrisle/netbeans/plugins/nbscratchfile/ui/dist/index.html";

public CreateScratchFile() {
dialog = new JDialog();
viewModel = new NbScratchFileViewModel(dialog);
jfxPanel = Pages.initWebView(viewModel);
initDialog();
public static void setDialog(WebViewDialog dialog) {
_dialog = dialog;
}

private void initDialog() {
dialog.add(jfxPanel);
dialog.setSize(700, 450);
dialog.setResizable(false);
dialog.setAlwaysOnTop(true);
dialog.setUndecorated(true);
dialog.addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowGainedFocus(WindowEvent e) {
}

@Override
public void windowLostFocus(WindowEvent e) {
dialog.setVisible(false);
}
});

dialog.getRootPane().registerKeyboardAction((ActionEvent e1) -> {
dialog.setVisible(false);
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
}

@JavaScriptBody(
args = { "id", "tag", "css" }, body = "\n"
+ "var sourceElem = id ? document.getElementById(id) : document.getElementsByTagName(tag)[0];\n"
+ "sourceElem.setAttribute('style', css);\n"
+ ""
)
private static native void colorizeElement(String id, String tag, String css);

/* this would rather be done on the TypeScript side as it doesn't talk to Java:
private void addHoverEffectToElement(Element sourceElem, String newCss, String oldCss) {
((EventTarget) sourceElem).addEventListener("mouseover", (elem) -> {
sourceElem.setAttribute("style", newCss);
}, false);
((EventTarget) sourceElem).addEventListener("mouseout", (elem) -> {
sourceElem.setAttribute("style", oldCss);
}, false);
}
private void addHoverEffectToElements(NodeList sourceElements, String newCss, String oldCss) {
for (int i = 0; i < sourceElements.getLength(); i++) {
addHoverEffectToElement((Element) sourceElements.item(i), newCss, oldCss);
}
}
*/

@Override
public void actionPerformed(ActionEvent e) {
showDialog();
}

@HTMLComponent(url = "/org/chrisle/netbeans/plugins/nbscratchfile/ui/dist/index.html", type = JComponent.class)
static void initWebView(NbScratchFileViewModel viewModel) {
exposeModel("NbScratchFileViewModel", viewModel);

colorizeElement("languageSearch", null, String.format("background-color: %s; color: %s;", viewModel.getColor("TextField.background", false), viewModel.getColor("TextField.foreground", false)));
colorizeElement(null, "body", String.format("background-color: %s;", viewModel.getColor("Menu.background", false)));
colorizeElement(null, "ul", String.format("color: %s;", viewModel.getColor("Label.foreground", false)));

// addHoverEffectToElements(webEngine.getDocument().getElementsByTagName("li"), String.format("background-color: %s; color: %s;", viewModel.getColor("Menu.background", true), viewModel.getColor("Menu.foreground", true)), String.format("background-color: %s; color: %s;", viewModel.getColor("Menu.background", false), viewModel.getColor("Menu.foreground", false)));
}

@HTMLDialog(url = "/org/chrisle/netbeans/plugins/nbscratchfile/ui/dist/index.html")
static void workaroundNetBeansBug148() {
}

@JavaScriptBody(args = { "name", "value" }, javacall = true, body = "\n"
+ "window[name] = {"
+ "setExt : function(ext, languageName) {\n"
+ " value.@org.chrisle.netbeans.plugins.nbscratchfile.NbScratchFileViewModel::setExt(Ljava/lang/String;Ljava/lang/String;)(ext, languageName);\n"
+ "},\n"
+ "getColor : function(colorString, brighter) {\n"
+ " return value.@org.chrisle.netbeans.plugins.nbscratchfile.NbScratchFileViewModel::getColor(Ljava/lang/String;Ljava/lang/Boolean;)(colorString, brighter);\n"
+ "}\n"
+ "};"
)
private static native void exposeModel(String name, NbScratchFileViewModel value);

public void showDialog() {
// try to use monitor, where the input focus is
// therefor get the topmost component based on the input focus
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();

if (null != focusOwner) {
while (focusOwner.getParent() != null) {
focusOwner = focusOwner.getParent();
}
}

dialog.setLocationRelativeTo(focusOwner);
dialog.setVisible(true);
_dialog.showDialog();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.chrisle.netbeans.plugins.nbscratchfile;

import javax.swing.JComponent;
import net.java.html.js.JavaScriptBody;
import org.chrisle.netbeans.plugins.utils.WebViewDialog;
import org.netbeans.api.htmlui.HTMLComponent;
import org.netbeans.api.htmlui.HTMLDialog;
import org.openide.modules.ModuleInstall;
import org.openide.windows.OnShowing;

@OnShowing
public class Installer extends ModuleInstall implements Runnable {
private NbScratchFileViewModel viewModel;
private static final WebViewDialog dialog = new WebViewDialog();

@Override
public void run() {
viewModel = new NbScratchFileViewModel(dialog);

System.out.println("Init Webview stuff.");

dialog.init(Pages.initWebView(viewModel, dialog));
CreateScratchFile.setDialog(dialog);
}

@HTMLComponent(url = CreateScratchFile.viewPath, type = JComponent.class)
static void initWebView(NbScratchFileViewModel viewModel, WebViewDialog dialog) {
exposeModel("NbScratchFileViewModel", viewModel);

dialog.colorizeElement("languageSearch", null, String.format("background-color: %s; color: %s;", viewModel.getColor("TextField.background", false), viewModel.getColor("TextField.foreground", false)));
dialog.colorizeElement(null, "body", String.format("background-color: %s;", viewModel.getColor("Menu.background", false)));
dialog.colorizeElement(null, "ul", String.format("color: %s;", viewModel.getColor("Label.foreground", false)));

// dialog.addHoverEffectToElements(dialog.getWebEngine().getDocument().getElementsByTagName("li"), String.format("background-color: %s; color: %s;", viewModel.getColor("Menu.background", true), viewModel.getColor("Menu.foreground", true)), String.format("background-color: %s; color: %s;", viewModel.getColor("Menu.background", false), viewModel.getColor("Menu.foreground", false)));
}

@HTMLDialog(url = CreateScratchFile.viewPath)
public static void workaroundNetBeansBug148() {}

@JavaScriptBody(args = { "name", "value" }, javacall = true, body = ""
+ "window[name] = {"
+ "setExt : function(ext, languageName) {"
+ " value.@org.chrisle.netbeans.plugins.nbscratchfile.NbScratchFileViewModel::setExt(Ljava/lang/String;Ljava/lang/String;)(ext, languageName);"
+ "},"
+ "getColor : function(colorString, brighter) {"
+ " return value.@org.chrisle.netbeans.plugins.utils.BaseWebViewDialogViewModel::getColor(Ljava/lang/String;Ljava/lang/Boolean;)(colorString, brighter);"
+ "}"
+ "};"
)
private static native void exposeModel(String name, NbScratchFileViewModel value);
}
Loading

0 comments on commit 8686fe6

Please sign in to comment.