/**
* Name: WindowJS
* Version: 1.2.1
* Language: Java 6
*
* Author: GoToLoop
* Date: 2015/Sep/15
* License: LGPL 2.1
*/
// https://Gist.GitHub.com/GoToLoop/8017bc38b8c8e0a5b70b
package js; // Uncomment "package js;" for ".java" and comment out for ".pde".
import static javax.swing.JOptionPane.*;
import java.lang.reflect.Array;
//static // Uncomment "static" for ".pde" and comment out for ".java".
public abstract class window {
public static final window self = new window() {}, window = self;
public static final Object undefined = null;
public static final float NaN = Float.NaN;
public static final float Infinity = Float.POSITIVE_INFINITY;
public static String name = "";
public static final Object alert() {
return alert(null);
}
public static final Object alert(final Object msg) {
showMessageDialog(null, msg);
return null;
}
public static final boolean confirm() {
return confirm(null);
}
public static final boolean confirm(final Object msg) {
return showConfirmDialog(null, msg, "Confirm?", OK_CANCEL_OPTION)
== OK_OPTION;
}
public static final String prompt() {
return prompt(null);
}
public static final String prompt(final Object msg) {
return showInputDialog(msg);
}
public static final String prompt(final Object msg, final Object val) {
return showInputDialog(msg, val);
}
public static final boolean isNaN() {
return true;
}
public static final boolean isNaN(final long val) {
return false;
}
public static final boolean isNaN(final double val) {
return val != val;
}
public static final boolean isNaN(final Object o) {
if (o == null | o instanceof java.util.Date |
o instanceof Boolean | o instanceof Character) return false;
if (o instanceof Number) return isNaN(((Number) o).doubleValue());
if (o.getClass().isArray()) {
int len = Array.getLength(o);
return len == 0? false : len > 1? true : isNaN(Array.get(o, 0));
}
final String s = o.toString().trim();
if (s.isEmpty()) return false;
try {
return isNaN(Double.parseDouble(s));
}
catch (final NumberFormatException e) {
return true;
}
}
public static final boolean isFinite() {
return false;
}
public static final boolean isFinite(final long val) {
return true;
}
public static final boolean isFinite(final double val) {
return val != -Infinity & val != Infinity & val == val;
}
public static final boolean isFinite(final Object o) {
if (o == null | o instanceof java.util.Date |
o instanceof Boolean | o instanceof Character) return true;
if (o instanceof Number) return isFinite(((Number) o).doubleValue());
if (o.getClass().isArray()) {
final int len = Array.getLength(o);
return len == 0? true : len > 1? false : isFinite(Array.get(o, 0));
}
final String s = o.toString().trim();
if (s.isEmpty()) return true;
try {
return isFinite(Double.parseDouble(s));
}
catch (final NumberFormatException e) {
return false;
}
}
public static final String Date() {
return new java.util.Date().toString();
}
public static final class Date extends java.util.Date {
public static final long now() {
return new java.util.Date().getTime();
}
}
public static final Object[] Array(final int len) {
return new Object[len];
}
@SafeVarargs public static final T[] Array(final T... arr) {
return arr == null? (T[]) new Object[0] : arr;
}
Aside from its readBoolean() method which directly invokes JOptionPane::showConfirmDialog(), everything else relies on a JDialog instance created outta a customized JOptionPane: :-B
protected static final JDialog dialog = new JOptionPane(panel, QUESTION_MESSAGE) {
@Override public void selectInitialValue() {
field.requestFocusInWindow();
}
}
.createDialog(null, TITLE);
Notice its @Override method invokes method requestFocusInWindow() over a JTextField object. L-)
Whether that's enough to force Processing's P3D and other renderers to always behave correctly related to foreground placement is your task now. #:-S
Indeed a red warning "No library found for iadt.creative.Inputs" appeared.
Just ignore it!
I get similar warnings on some of my sketches that include local libraries which are not installed in the sketchbook libraries folder. The sketches still run fine.
To remove the warnings you can (sometimes) also add the resource to sketchbook > libraries.
If you really had to, you're highly probably running a very old P3 version!
no, I just installed 3.3.7 to make it work... ;-)
here are some warnings:
java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:2062)
at java.awt.Component.getLocationOnScreen(Component.java:2036)
at javax.swing.text.JTextComponent$InputMethodRequestsHandler.getTextLocation(JTextComponent.java:4643)
at sun.awt.im.InputMethodContext.getTextLocation(InputMethodContext.java:278)
at sun.awt.windows.WInputMethod$1.run(WInputMethod.java:588)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Comments
static
members are called via prefixing them w/window.
as in:window.alert();
http://Studio.SketchPad.cc/sp/pad/view/ro.9$Bjf6i21oXBw/latest
http://Studio.ProcessingTogether.com/sp/pad/export/ro.9$Bjf6i21oXBw
Thanks for that!
I am just working on it.
I have a problem that when using confirm the msgbox is not in the foreground but behind the main window
I have an mcve where this error does NOT occur (not helpful I know)
But how can I make sure the msgbox gets in the foreground and has the focus? It's in P3D by the way.
Thanks a ton as always!
Chrisir ;-)
ah, it's because of P3D
this mcve shows it (sometimes)
solution...?
Sorry @Chrisir; but I've never tested it w/ other renderers yet. Just JAVA2D! ~:>
This library simply invokes JOptionPane's
static
methods: showMessageDialog(), showConfirmDialog() & showInputDialog().Which respectively corresponds to JS' alert(), confirm() & prompt(). ~O)
Therefore, that is simply a JOptionPane interaction glitch w/ Processing's OpenGL P3D renderer you've just found out AFAIK. :|
As you can see, JOptionPane is a Swing/AWT class: 8-|
import static javax.swing.JOptionPane.*;
And almost n1 knows Processing doesn't behave that well when we use Swing/AWT classes. ^#(^
solution in P3D....?
@Chrisir, can you check out whether this Inputs class behaves correctly for all Processing's renderers: :-?
https://Gist.GitHub.com/GoToLoop/bba0c288aaeeb5ef9bb1
Aside from its readBoolean() method which directly invokes JOptionPane::showConfirmDialog(), everything else relies on a JDialog instance created outta a customized JOptionPane: :-B
Notice its
@Override
method invokes method requestFocusInWindow() over a JTextField object. L-)Whether that's enough to force Processing's P3D and other renderers to always behave correctly related to foreground placement is your task now. #:-S
Good luck! B-)
thanks!!
Thanks, I couldn't get it to run
Do I need this library?
https://Gist.GitHub.com/GoToLoop/bba0c288aaeeb5ef9bb1
I get similar warnings on some of my sketches that include local libraries which are not installed in the sketchbook libraries folder. The sketches still run fine.
To remove the warnings you can (sometimes) also add the resource to sketchbook > libraries.
this works, I needed the class in test tab
in the 2nd tab Inputs.java I had to comment out the package
I also receive huge bunch of warnings but it runs now in 2D
I've turned off warnings & auto code complete since the very beginning of P3. >:)
If you really had to, you're highly probably running a very old P3 version! 8-X
only when I enter a false age by the way!
no, I just installed 3.3.7 to make it work... ;-)
here are some warnings:
I'm still using PDE v3.3.5. And due to many folks reporting bugs for v3.3.6, I've decided to skip it completely. :-h
I had high hopes for this latest v3.3.7. But after reading that huge list of warnings, I'm gonna hold on to v3.3.5 for a while again! :-\"
in P3D the InputBox is not in the foreground.
Is there not a command for this...
annoying...
Problem is, both renderers P2D & P3D are OpenGL-based wrapped by JOGL bindings: :-B
https://JogAmp.org/
Up till PDE v3.0a5, JOGL was somehow embedded as a Java's Applet. ~O)
But after that, Processing's PApplet class isn't a subclass of Java's Applet anymore. :-&
So I've got no idea how to control which component gets the right to be foreground:
JOptionPane's Swing or P3D's JOGL. :-<
You can check its API if you wish though: ^#(^
https://JogAmp.org/deployment/jogamp-next/javadoc/jogl/javadoc/index.html?overview-summary.html
I would rather report it as a bug....
but thank you!
I had other difficulties in P3D with receiving keys etc. ...