-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: pom.xml src/main/java/org/chrisle/netbeans/plugins/nbscratchfile/CreateScratchFile.java
- Loading branch information
Showing
107 changed files
with
27,513 additions
and
849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 31 additions & 117 deletions
148
src/main/java/org/chrisle/netbeans/plugins/nbscratchfile/CreateScratchFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/chrisle/netbeans/plugins/nbscratchfile/Installer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.