netscape.javascript.JSObject Java Examples

The following examples show how to use netscape.javascript.JSObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElevationService.java    From GMapsFX with Apache License 2.0 6 votes vote down vote up
/** Processess the Javascript response and generates the required objects 
 * that are then passed back to the original callback.
 * 
 * @param results
 * @param status 
 */
public void processResponse(Object results, Object status) {
    ElevationStatus pStatus = ElevationStatus.UNKNOWN_ERROR;
    
    if (status instanceof String && results instanceof JSObject) {
        pStatus = ElevationStatus.valueOf((String) status);
        if (ElevationStatus.OK.equals(pStatus)) {
            JSObject jsres = (JSObject) results;
            Object len = jsres.getMember("length");
            if (len instanceof Number) {
                int n = ((Number)len).intValue();
                ElevationResult[] ers = new ElevationResult[n];
                for (int i = 0; i < n; i++) {
                    Object obj = jsres.getSlot(i);
                    if (obj instanceof JSObject) {
                        ers[i] = new ElevationResult((JSObject) obj);
                    }
                }
                callback.elevationsReceived(ers, pStatus);
                return;
            }
        }
    }
    callback.elevationsReceived(new ElevationResult[]{}, pStatus);
}
 
Example #2
Source File: GeocoderUtils.java    From GMapsFX with Apache License 2.0 6 votes vote down vote up
public static <T extends Enum> List<T> convertJSObjectToListOfEnum(JSObject jsObject, Class<T> enumClass) {
    List<T> result = new ArrayList<>();
    if (jsObject != null) {
        try {
            String jsTypesString = jsObject.toString();

            for (T value : enumClass.getEnumConstants()) {
                if (jsTypesString.toLowerCase().contains(value.name().toLowerCase())) {
                    result.add(value);
                }
            }
        } catch (Exception e) {
            Logger.getLogger(GeocoderUtils.class.getName()).log(Level.SEVERE, "", e);
        }
    }
    return result;
}
 
Example #3
Source File: GeocodingService.java    From GMapsFX with Apache License 2.0 6 votes vote down vote up
public void processResponse(Object results, Object status) {
        GeocoderStatus pStatus = GeocoderStatus.UNKNOWN_ERROR;
        if (status instanceof String && results instanceof JSObject) {
            pStatus = GeocoderStatus.valueOf((String) status);
            if (GeocoderStatus.OK.equals(pStatus)) {
                JSObject jsres = (JSObject) results;
                Object len = jsres.getMember("length");
                if (len instanceof Number) {
                    int n = ((Number)len).intValue();
//                    LOG.trace("n: " + n);
                    GeocodingResult[] ers = new GeocodingResult[n];
                    for (int i = 0; i < n; i++) {
                        Object obj = jsres.getSlot(i);
                        if (obj instanceof JSObject) {
                            ers[i] = new GeocodingResult((JSObject) obj);
                        }
                    }
                    callback.geocodedResultsReceived(ers, pStatus);
                    return;
                }
            }
        }
        callback.geocodedResultsReceived(new GeocodingResult[]{}, pStatus);
    }
 
Example #4
Source File: Program.java    From jace with GNU General Public License v2.0 6 votes vote down vote up
public void initEditor(WebView editor, File sourceFile, boolean isBlank) {
    this.editor = editor;
    targetFile = sourceFile;
    if (targetFile != null) {
        filename = targetFile.getName();
    }

    editor.getEngine().getLoadWorker().stateProperty().addListener(
            (value, old, newState) -> {
                if (newState == Worker.State.SUCCEEDED) {
                    JSObject document = (JSObject) editor.getEngine().executeScript("window");
                    document.setMember("java", this);
                    Platform.runLater(()->createEditor(isBlank));
                }
            });

    editor.getEngine().setPromptHandler((PromptData prompt) -> {
        TextInputDialog dialog = new TextInputDialog(prompt.getDefaultValue());
        dialog.setTitle("Jace IDE");
        dialog.setHeaderText("Respond and press OK, or Cancel to abort");
        dialog.setContentText(prompt.getMessage());
        return dialog.showAndWait().orElse(null);
    });

    editor.getEngine().load(getClass().getResource(CODEMIRROR_EDITOR).toExternalForm());
}
 
Example #5
Source File: DirectionsLeg.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public LatLong getStartLocation(){
    try {
        JSObject location = (JSObject) getJSObject().getMember("start_location");
        return new LatLong((JSObject) location);
    } catch (Exception e) {
        Logger.getLogger(this.getClass().getName()).log(Level.FINE, "", e);
    }
    return null;
}
 
Example #6
Source File: JavascriptArray.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public Object pop() {
    //Object obj = jsObject.getSlot(jsLen - 1);
    Object obj = invokeJavascript("pop");
    if (obj instanceof JSObject && content.containsKey((JSObject) obj)) {
        return (JavascriptObject) content.get((JSObject) obj);
    }
    return obj;
}
 
Example #7
Source File: DirectionsLeg.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public String getStartAddress(){
    try {
        JSObject location = (JSObject) getJSObject().getMember("start_address");
        return location.toString();
    } catch (Exception e) {
        Logger.getLogger(this.getClass().getName()).log(Level.FINE, "", e);
    }
    return null;
}
 
Example #8
Source File: AbstractWizard.java    From netbeans with Apache License 2.0 5 votes vote down vote up
final Object evaluateCall(final Object fn, final Object p) throws InterruptedException, ExecutionException {
    FutureTask<?> t = new FutureTask<Object>(new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            JSObject jsRegFn = (JSObject) fn;
            return jsRegFn.call("call", null, p);
        }
    });
    ctx.execute(t);
    return t.get();
}
 
Example #9
Source File: RFXWebView.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public Map<String, String> getAttributes() {
    String r = (String) ((JSObject) getComponent().getProperties().get("player")).call("attributes",
            (String) getComponent().getProperties().get("current_selector"));
    JSONObject o = new JSONObject(r);
    String[] names = JSONObject.getNames(o);
    HashMap<String, String> rm = new HashMap<>();
    for (String name : names) {
        rm.put(name, o.getString(name));
    }
    return rm;
}
 
Example #10
Source File: DirectionsSteps.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public Distance getDistance(){
    try{
        JSObject distance = (JSObject) getJSObject().getMember("distance");
        return new Distance(distance);
    } catch(Exception e){
        Logger.getLogger(this.getClass().getName()).log(Level.FINE, "", e);
    }
    return null;
}
 
Example #11
Source File: SlidePane.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
@Override
    public void runScroller(String text) {
        String backendExt = backend + "Ext";
        try {
            ((JSObject) getWindow().eval(backendExt)).call("flipCurrentPage", text);
        } catch (Exception e) {
//            logger.debug("{} is not found while flipping page, but don't worry.", backendExt, e);
        }
    }
 
Example #12
Source File: RFXWebView.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void loadScript(WebView webview) {
    webview.getProperties().put("current_selector", "body");
    WebEngine webEngine = webview.getEngine();
    JSObject win = (JSObject) webEngine.executeScript("window");
    win.setMember("marathon_recorder", RFXWebView.this);
    webEngine.executeScript(script);
}
 
Example #13
Source File: MaxZoomService.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
/** Processess the Javascript response and generates the required objects 
 * that are then passed back to the original callback.
 * 
 * @param result
 */
public void processResponse(Object result) {
    if (result instanceof JSObject) {
        MaxZoomResult mzr = new MaxZoomResult((JSObject) result);
        callback.maxZoomReceived(mzr);
    }
}
 
Example #14
Source File: JavaFXWebViewElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public String getValue(String selector) {
    return EventQueueWait.exec(new Callable<String>() {
        @Override
        public String call() throws Exception {
            return (String) ((JSObject) getComponent().getProperties().get("player")).call("value", selector);
        }
    });
}
 
Example #15
Source File: DirectionsPane.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
/**
 * Registers an event handler in the repository shared between Javascript
 * and Java.
 *
 * @param h Event handler to be registered.
 * @return Callback key that Javascript will use to find this handler.
 */
private String registerEventHandler(GFXEventHandler h) {
    //checkInitialized();
    if (!registeredOnJS) {
        JSObject doc = (JSObject) runtime.execute("document");
        doc.setMember("jsHandlers", jsHandlers);
        registeredOnJS = true;
    }
    return jsHandlers.registerHandler(h);
}
 
Example #16
Source File: Projection.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public GMapPoint fromLatLngToPoint(LatLong loc) {
//        System.out.println("Projection.fromLatLngToPoint: " + loc);
        Object res = invokeJavascript("fromLatLngToPoint", loc);
//        System.out.println("Projection.fromLatLngToPoint.res: " + res);
        if (res != null && res instanceof JSObject) {
            return new GMapPoint((JSObject) res);
        }
        return null;
    }
 
Example #17
Source File: SlidePane.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
public void replaceSlides(String rendered) {
        getWindow().setMember("afx", controller);
        String backendExt = backend + "Ext";
        try {
            ((JSObject) getWindow().eval(backendExt)).call("replaceSlides", rendered);
        } catch (Exception e) {
//            logger.debug("{} is not found while replacing slide, but don't worry.", backendExt, e);
        }

    }
 
Example #18
Source File: GeocodingResult.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public List<GeocoderAddressComponent> getAddressComponents() {
    final List<GeocoderAddressComponent> components = new ArrayList<>();
    JSObject componentArray = (JSObject) getJSObject().getMember("address_components");
    List<JSObject> jsObjectsFromArray = GeocoderUtils.getJSObjectsFromArray(componentArray);
    for (JSObject obj : jsObjectsFromArray) {
        components.add(new GeocoderAddressComponent(obj));
    }
    return components;
}
 
Example #19
Source File: DirectionsSteps.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public String getInstructions(){
    try {
        JSObject location = (JSObject) getJSObject().getMember("instructions");
        return location.toString();
    } catch (Exception e) {
        Logger.getLogger(this.getClass().getName()).log(Level.FINE, "", e);
    }
    return null;
}
 
Example #20
Source File: JavaFXWebViewElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public Map<String, String> getAttributes(String selector) {
    String r = (String) ((JSObject) getComponent().getProperties().get("player")).call("attributes", selector);
    JSONObject o = new JSONObject(r);
    String[] names = JSONObject.getNames(o);
    HashMap<String, String> rm = new HashMap<>();
    for (String name : names) {
        rm.put(name, o.getString(name));
    }
    return rm;
}
 
Example #21
Source File: JavascriptEnum.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public Object getEnumValue() {
    if (value == null) {
        JSObject jsObject = runtime.execute(type);
        value = jsObject.getMember(name);
    }
    return value;
}
 
Example #22
Source File: DirectionsLeg.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public List<DirectionsSteps> getSteps(){
    final List<DirectionsSteps> result = new ArrayList<>();
    List<JSObject> jsLocalities = GeocoderUtils.getJSObjectsFromArray((JSObject) getJSObject().getMember("steps"));
    for (JSObject jsLocality : jsLocalities) {
        DirectionsSteps ll = new DirectionsSteps(jsLocality);
        if (!jsLocality.toString().equals("undefined")) {
            result.add(ll);
        }
    }
    return result;
}
 
Example #23
Source File: WebviewSnapshotter.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void fireJSSnap(int x, int y, int w, int h) {
    if (!Platform.isFxApplicationThread()) {
        Platform.runLater(()-> {
            fireJSSnap(x, y, w, h);
        });
        return;
    } 
    //System.out.println("in FireJSSnap "+x+","+y+","+w+","+h);
    JSObject window = (JSObject)web.getEngine().executeScript("window");
    window.setMember("snapper", this);
    web.getEngine().executeScript("getRectSnapshot("+x+","+y+","+w+","+h+");");
}
 
Example #24
Source File: DirectionsSteps.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public List<DirectionsSteps> getSteps(){
    final List<DirectionsSteps> result = new ArrayList<>();
    List<JSObject> jsLocalities = GeocoderUtils.getJSObjectsFromArray((JSObject) 
            getJSObject().getMember("postcode_localities"));
    for (JSObject jsLocality : jsLocalities) {
        DirectionsSteps ll = new DirectionsSteps(jsLocality);
        if (!jsLocality.toString().equals("undefined")) {
            result.add(ll);
        }
    }
    return result;
}
 
Example #25
Source File: JavascriptRuntimeTest.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    mockJSRuntime = Mockito.mock( IJavascriptRuntime.class );
    mockWebEngine = Mockito.mock( IWebEngine.class );
    mockJsObject = Mockito.mock( JSObject.class );
    JavascriptRuntime.runtime = null;
    JavascriptRuntime.setDefaultWebEngine( mockWebEngine );
}
 
Example #26
Source File: DirectionsLeg.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public Duration getDuration(){
    try{
        JSObject duration = (JSObject) getJSObject().getMember("duration");
        return new Duration(duration);
    } catch(Exception e){
        Logger.getLogger(this.getClass().getName()).log(Level.FINE, "", e);
    }
    return null;
}
 
Example #27
Source File: MapPane.java    From FXMaps with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns the default {@link MapEventHandler}. This is the handler that
 * converts clicks on the map to {@link Waypoint}s added.
 * 
 * @return the default {@code MapEventHandler}
 */
private MapEventHandler getDefaultMapEventHandler() {
    return (JSObject obj) -> {
        if(currentMode == Mode.ADD_WAYPOINTS) {
            LatLong ll = new LatLong((JSObject) obj.getMember("latLng"));
            
            Waypoint waypoint = createWaypoint(new LatLon(ll.getLatitude(), ll.getLongitude()));
            
            addNewWaypoint(waypoint);
            
            System.out.println("clicked: " + ll.getLatitude() + ", " + ll.getLongitude());
        }
    };
}
 
Example #28
Source File: GeocoderGeometry.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public LatLongBounds getViewPort() {
    try {
        JSObject viewPort = (JSObject) getJSObject().getMember("viewport");
        return new LatLongBounds((JSObject) viewPort);
    } catch (Exception e) {
        Logger.getLogger(this.getClass().getName()).log(Level.FINE, "", e);
    }
    return null;
}
 
Example #29
Source File: TextInput.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public TextInput(String _formName, String _objectName, Applet _parent){
  field = new TextField();
  setBackCol( Color.white );
  win = JSObject.getWindow(_parent);     
  field.addKeyListener( this );
  formName = _formName;
  objectName = _objectName;
}
 
Example #30
Source File: DirectionsRoute.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
public List<LatLong> getOverviewPath(){
    final List<LatLong> result = new ArrayList<>();
    List<JSObject> jsLocalities = GeocoderUtils.getJSObjectsFromArray((JSObject) 
            getJSObject().getMember("overview_path"));
    for (JSObject jsLocality : jsLocalities) {
        LatLong ll = new LatLong(jsLocality);
        if (!jsLocality.toString().equals("undefined")) {
            result.add(ll);
        }
    }
    return result;
}