List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:es.deusto.weblab.client.experiments.aquarium.ui.SingleWebcamPanel.java
License:Open Source License
private void parseWebcamConfig(String initialConfiguration, int camera) { System.out.println("Aquarium: initial config:" + initialConfiguration); final JSONValue initialConfigValue = JSONParser.parseStrict(initialConfiguration); final JSONObject initialConfigObject = initialConfigValue.isObject(); if (initialConfigObject == null) { Window.alert("Error parsing aquarium configuration: not an object: " + initialConfiguration); return;//from ww w . j a v a 2 s . co m } configureWebcam(this.webcam, initialConfigObject, camera); }
From source file:es.deusto.weblab.client.experiments.aquarium.ui.WebcamPanel.java
License:Open Source License
private void parseWebcamConfig(String initialConfiguration) { System.out.println("Aquarium: initial config:" + initialConfiguration); final JSONValue initialConfigValue = JSONParser.parseStrict(initialConfiguration); final JSONObject initialConfigObject = initialConfigValue.isObject(); if (initialConfigObject == null) { Window.alert("Error parsing aquarium configuration: not an object: " + initialConfiguration); return;/*from www . j a va 2 s .co m*/ } configureWebcam(this.webcam1, initialConfigObject, 1); configureWebcam(this.webcam2, initialConfigObject, 2); }
From source file:es.deusto.weblab.client.experiments.logic.ui.LogicExperiment.java
License:Open Source License
/** * This function gets called just when the actual experiment starts, after * the reserve is done and the queue is over. *///from w w w .j av a2s . c o m @Override public void start(int time, String initialConfiguration) { final JSONValue parsedInitialConfiguration = JSONParser.parseStrict(initialConfiguration); final String webcamUrl = parsedInitialConfiguration.isObject().get("webcam").isString().stringValue(); this.textIntroPanel.setVisible(false); if (this.useWebcam) { this.webcam.setUrl(webcamUrl); this.webcam.setVisible(true); } else { this.light.setVisible(true); turnOffLight(); } this.points = 0; this.widget.setVisible(true); this.timer.start(); // Inputs this.input1Label = new HTML(this.getFormatedInputLabel(this.zeroString, 1)); this.input1Label.setStyleName(Style.LOGIC_INPUT_VALUE_LABEL); this.circuitGrid.setWidget(0, 0, this.input1Label); this.input2Label = new HTML(this.getFormatedInputLabel(this.zeroString, 2)); this.input2Label.setStyleName(Style.LOGIC_INPUT_VALUE_LABEL); this.circuitGrid.setWidget(1, 0, this.input2Label); this.input3Label = new HTML(this.getFormatedInputLabel(this.zeroString, 3)); this.input3Label.setStyleName(Style.LOGIC_INPUT_VALUE_LABEL); this.circuitGrid.setWidget(3, 0, this.input3Label); this.input4Label = new HTML(this.getFormatedInputLabel(this.zeroString, 4)); this.input4Label.setStyleName(Style.LOGIC_INPUT_VALUE_LABEL); this.circuitGrid.setWidget(4, 0, this.input4Label); // Gates (level A) this.gateA1Image = new Image(this.unknownOperationUrl); this.circuitGrid.setWidget(0, 2, this.gateA1Image); this.gateA2Image = new Image(this.unknownOperationUrl); this.circuitGrid.setWidget(2, 2, this.gateA2Image); this.gateA3Image = new Image(this.unknownOperationUrl); this.circuitGrid.setWidget(4, 2, this.gateA3Image); // Gates (level B) this.gateB1Image = new Image(this.unknownOperationUrl); this.circuitGrid.setWidget(1, 4, this.gateB1Image); this.gateB2Image = new Image(this.unknownOperationUrl); this.circuitGrid.setWidget(3, 4, this.gateB2Image); // Gates (level C) this.gateC1Image = new Image(this.unknownOperationUrl); this.circuitGrid.setWidget(2, 6, this.gateC1Image); // Connections for (final RowColumnPair pair : RowColumnPair.getRowsColumnPairs()) { final Image pairImage = new Image(pair.getImageResourceWeb(this.resources)); this.circuitGrid.setWidget(pair.getRow(), pair.getColumn() + 1, pairImage); } // Setting the Unknown Gate this.unknownGateImage = this.gateA2Image; this.unknownGateImage.addStyleName(Style.LOGIC_MOUSE_POINTER_HAND); this.changeUnknownGateDialogBox = new ChangeUnknownGateDialogBox(this); this.unknownGateImage.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (LogicExperiment.this.solving) //WlDeustoLogicBasedBoard.this.changeUnknownGateDialogBox.show(); LogicExperiment.this.changeUnknownGateDialogBox .showRelativeTo(LogicExperiment.this.referenceToShowBoxesLabel); } }); // Webcam final Widget webcamWidget; if (this.useWebcam) { this.webcam.start(); webcamWidget = this.webcam.getWidget(); } else { webcamWidget = this.light; } this.circuitAndWebcamPanel.add(webcamWidget); this.circuitAndWebcamPanel.setCellHorizontalAlignment(this.circuitGrid, HasHorizontalAlignment.ALIGN_RIGHT); this.circuitAndWebcamPanel.setCellVerticalAlignment(webcamWidget, HasVerticalAlignment.ALIGN_MIDDLE); this.circuitAndWebcamPanel.setCellHorizontalAlignment(webcamWidget, HasHorizontalAlignment.ALIGN_LEFT); // Messages this.messages.setText("Receiving the circuit"); this.messages.start(); this.sendCommand(new GetCircuitCommand()); this.sendSolutionButton.setVisible(true); }
From source file:es.deusto.weblab.client.experiments.logic.ui.MobileLogicExperiment.java
License:Open Source License
@Override public void start(int time, String initialConfiguration) { final JSONValue parsedInitialConfiguration = JSONParser.parseStrict(initialConfiguration); final String webcamUrl = parsedInitialConfiguration.isObject().get("webcam").isString().stringValue(); this.points = 0; this.widget.setVisible(true); while (this.removableWidgetsPanel.getWidgetCount() > 0) this.removableWidgetsPanel.remove(0); // Timer//from www. j a va2s. c o m this.timer = new WlTimer(); this.timer.setStyleName(GpibExperiment.Style.TIME_REMAINING); this.timer.getWidget().setWidth("30%"); this.timer.setTimerFinishedCallback(new IWlTimerFinishedCallback() { @Override public void onFinished() { MobileLogicExperiment.this.boardController.clean(); } }); this.removableWidgetsPanel.add(this.timer.getWidget()); // Webcam this.webcam = new WlWebcam(this.getWebcamRefreshingTime(), webcamUrl); final Widget webcamWidget; if (this.useWebcam) { webcamWidget = this.webcam.getWidget(); this.webcam.start(); } else { this.light = new Image(); webcamWidget = this.light; turnOffLight(); } this.removableWidgetsPanel.add(webcamWidget); // Horizontal Panel this.circuitPanel = new HorizontalPanel(); this.circuitPanel.setWidth("100%"); this.circuitPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); this.circuitPanel.add(this.referenceToShowBoxesLabel); // Circuit this.circuitGrid = new Grid(5, 8); this.circuitGrid.setBorderWidth(0); this.circuitPanel.add(this.circuitGrid); // Inputs this.input1Label = new HTML(this.getFormatedInputLabel(this.zeroString, 1)); this.input1Label.setStyleName(Style.LOGIC_INPUT_VALUE_LABEL); this.circuitGrid.setWidget(0, 0, this.input1Label); this.input2Label = new HTML(this.getFormatedInputLabel(this.zeroString, 2)); this.input2Label.setStyleName(Style.LOGIC_INPUT_VALUE_LABEL); this.circuitGrid.setWidget(1, 0, this.input2Label); this.input3Label = new HTML(this.getFormatedInputLabel(this.zeroString, 3)); this.input3Label.setStyleName(Style.LOGIC_INPUT_VALUE_LABEL); this.circuitGrid.setWidget(3, 0, this.input3Label); this.input4Label = new HTML(this.getFormatedInputLabel(this.zeroString, 4)); this.input4Label.setStyleName(Style.LOGIC_INPUT_VALUE_LABEL); this.circuitGrid.setWidget(4, 0, this.input4Label); // Gates (level A) this.gateA1Image = new Image(this.resources.smallUNKNOWN()); this.circuitGrid.setWidget(0, 2, this.gateA1Image); this.gateA2Image = new Image(this.resources.smallUNKNOWN()); this.circuitGrid.setWidget(2, 2, this.gateA2Image); this.gateA3Image = new Image(this.resources.smallUNKNOWN()); this.circuitGrid.setWidget(4, 2, this.gateA3Image); // Gates (level B) this.gateB1Image = new Image(this.resources.smallUNKNOWN()); this.circuitGrid.setWidget(1, 4, this.gateB1Image); this.gateB2Image = new Image(this.resources.smallUNKNOWN()); this.circuitGrid.setWidget(3, 4, this.gateB2Image); // Gates (level C) this.gateC1Image = new Image(this.resources.smallUNKNOWN()); this.circuitGrid.setWidget(2, 6, this.gateC1Image); // Connections for (final RowColumnPair pair : RowColumnPair.getRowsColumnPairs()) { final Image pairImage = new Image(pair.getImageResourceMobile(this.resources)); this.circuitGrid.setWidget(pair.getRow(), pair.getColumn() + 1, pairImage); } // Setting the Unknown Gate this.unknownGateImage = this.gateA2Image; this.unknownGateImage.addStyleName(Style.LOGIC_MOUSE_POINTER_HAND); this.changeUnknownGateDialogBox = new MobileChangeUnknownGateDialogBox(this); this.circuitPanel.setCellHorizontalAlignment(this.circuitGrid, HasHorizontalAlignment.ALIGN_RIGHT); this.circuitPanel.setCellVerticalAlignment(webcamWidget, HasVerticalAlignment.ALIGN_MIDDLE); this.circuitPanel.setCellHorizontalAlignment(webcamWidget, HasHorizontalAlignment.ALIGN_LEFT); this.removableWidgetsPanel.add(this.circuitPanel); // Messages this.messages = new WlWaitingLabel("Receiving the circuit"); this.messages.start(); this.removableWidgetsPanel.add(this.messages.getWidget()); // Send Solution button this.sendSolutionButton = new Button(i18n.sendSolution()); this.sendSolutionButton.setEnabled(false); this.sendSolutionButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { MobileLogicExperiment.this.sendCommand(new SolveCircuitCommand(MobileLogicExperiment.this.circuit)); MobileLogicExperiment.this.messages.setText("Sending solution"); MobileLogicExperiment.this.messages.start(); } }); this.removableWidgetsPanel.add(this.sendSolutionButton); this.sendCommand(new GetCircuitCommand()); }
From source file:es.deusto.weblab.client.experiments.pic18.ui.Pic18Experiment.java
License:Open Source License
/** * Called when the experiment starts. //from w ww.j a va2 s . c om * @param time Time available for the experiment * @param initialConfiguration JSON-encoded server-provided configuration parameters. * This feature is part of the API version 2. Parameters expected by this experiment * are "webcam" and "expected_programming_time". */ @Override public void start(int time, String initialConfiguration) { if (parseWebcamConfig(initialConfiguration)) return; try { final JSONValue parsedInitialConfiguration = JSONParser.parseStrict(initialConfiguration); double expectedProgrammingTime = parsedInitialConfiguration.isObject().get("expected_programming_time") .isNumber().doubleValue(); Pic18Experiment.this.expectedProgrammingTime = (int) (expectedProgrammingTime * 1000); } catch (Exception e) { this.messages.setText("[PIC18] Did not receive the expected_programming_time parameter."); GWT.log("[PIC18] Did not receive the expected_programming_time parameter.", null); return; } // If it's not a demo, the user will have been prompted a file uploading form. // He might have indeed chosen a file to upload, or he might not. if (!isDemo()) { boolean success = this.tryUpload(); // If the file upload attempt on the reserve stage failed, then we will have to display // a button during the experiment itself so that the user can request the file he chose // be uploaded to the server. if (!success) this.uploadButton.setVisible(true); } else { this.loadStartControls(); } // The experiment started, so we should start the timer. this.timer.start(); // Start polling to know when the board has been programmed and the server is ready // to receive our requests. setupReadyTimer(); }
From source file:es.deusto.weblab.client.experiments.pic18.ui.Pic18Experiment.java
License:Open Source License
private boolean parseWebcamConfig(String initialConfiguration) { final JSONValue initialConfigValue = JSONParser.parseStrict(initialConfiguration); final JSONObject initialConfigObject = initialConfigValue.isObject(); if (initialConfigObject == null) { Window.alert("Error parsing robot configuration: not an object: " + initialConfiguration); return true; }//from w w w. ja v a 2 s. c o m final JSONValue webcamValue = initialConfigObject.get("webcam"); if (webcamValue != null) { final String urlWebcam = webcamValue.isString().stringValue(); this.webcam.setUrl(urlWebcam); } final JSONValue mjpegValue = initialConfigObject.get("mjpeg"); if (mjpegValue != null) { final String mjpeg = mjpegValue.isString().stringValue(); int width = 320; int height = 240; if (initialConfigObject.get("mjpegWidth") != null) { final JSONValue mjpegWidth = initialConfigObject.get("mjpegWidth"); if (mjpegWidth.isNumber() != null) { width = (int) mjpegWidth.isNumber().doubleValue(); } else if (mjpegWidth.isString() != null) { width = Integer.parseInt(mjpegWidth.isString().stringValue()); } } if (initialConfigObject.get("mjpegHeight") != null) { final JSONValue mjpegHeight = initialConfigObject.get("mjpegHeight"); if (mjpegHeight.isNumber() != null) { height = (int) mjpegHeight.isNumber().doubleValue(); } else if (mjpegHeight.isString() != null) { height = Integer.parseInt(mjpegHeight.isString().stringValue()); } } this.webcam.setStreamingUrl(mjpeg, width, height); } return false; }
From source file:es.deusto.weblab.client.experiments.submarine.ui.SubmarineExperiment.java
License:Open Source License
private JSONObject parseWebcamConfig(String initialConfiguration) { final JSONValue initialConfigValue = JSONParser.parseStrict(initialConfiguration); final JSONObject initialConfigObject = initialConfigValue.isObject(); if (initialConfigObject == null) { Window.alert("Error parsing submarine configuration: not an object: " + initialConfiguration); return null; }/*from w w w.j a va 2 s.c om*/ configureWebcam(this.webcam1, initialConfigObject, 1); configureWebcam(this.webcam2, initialConfigObject, 2); return initialConfigObject; }
From source file:es.deusto.weblab.client.experiments.visir.VisirSetupData.java
License:Open Source License
/** * Parses the string, storing the received parameters for them * to be retrieved through various getters. * @param response Response that was received * @return true if the response was successfully parsed, false otherwise */// ww w. ja v a 2 s .c o m public boolean parseData(String response) { try { final JSONValue val = JSONParser.parseStrict(response); final JSONObject obj = val.isObject(); if (obj == null) return false; final JSONValue cookieval = obj.get("cookie"); final JSONValue savedataval = obj.get("savedata"); final JSONValue urlval = obj.get("url"); final JSONValue teacherval = obj.get("teacher"); final JSONValue circuitsList = obj.get("circuits"); if (cookieval == null || savedataval == null || urlval == null) return false; final JSONString cookiestr = cookieval.isString(); final JSONString savedatastr = savedataval.isString(); final JSONString urlstr = urlval.isString(); if (cookiestr == null || savedatastr == null || urlstr == null) return false; this.cookie = cookiestr.stringValue(); this.saveData = savedatastr.stringValue(); this.url = urlstr.stringValue(); if (teacherval != null) { JSONBoolean teacherbool = teacherval.isBoolean(); this.teacher = teacherbool != null && teacherbool.booleanValue(); } else this.teacher = false; // We will now parse the list of available circuits. This is a list containing // the names of available circuits. Their actual data is not included and needs to // be requested separatedly. this.circuitsAvailable = new ArrayList<String>(); if (circuitsList == null) { } else { JSONArray circuitsAvailableArray = circuitsList.isArray(); for (int i = 0; i < circuitsAvailableArray.size(); ++i) { final JSONValue circuitName = circuitsAvailableArray.get(i); final String circuitNameStr = circuitName.isString().stringValue(); this.circuitsAvailable.add(circuitNameStr); } } } catch (Throwable e) { return false; } return true; }
From source file:es.deusto.weblab.client.experiments.xilinx.ui.XilinxExperiment.java
License:Open Source License
/** * Called when the experiment starts. /*from ww w . ja va 2 s . c o m*/ * @param time Time available for the experiment * @param initialConfiguration JSON-encoded server-provided configuration parameters. * This feature is part of the API version 2. Parameters expected by this experiment * are "webcam", "expected_programming_time", "expected_synthesizing_time". */ @Override public void start(int time, String initialConfiguration) { final JSONValue parsedInitialConfiguration = JSONParser.parseStrict(initialConfiguration); this.currentState = STATE_NOT_READY; try { final String webcamUrl = parsedInitialConfiguration.isObject().get("webcam").isString().stringValue(); this.webcam.setUrl(webcamUrl); } catch (Exception e) { this.messages.setText("[Xilinx] Did not receive the webcam parameter."); GWT.log("[Xilinx] Did not receive the webcam parameter.", null); return; } try { double expectedProgrammingTime = parsedInitialConfiguration.isObject().get("expected_programming_time") .isNumber().doubleValue(); XilinxExperiment.this.expectedProgrammingTime = (int) (expectedProgrammingTime * 1000); } catch (Exception e) { this.messages.setText("[Xilinx] Did not receive the expected_programming_time parameter."); GWT.log("[Xilinx] Did not receive the expected_programming_time parameter.", null); return; } // TODO: Consider whether this parameter should or should not be mandatory. For now, it isn't. // If the parameter is not provided by the server then the default will be used. try { double expectedSynthesizingTime = parsedInitialConfiguration.isObject() .get("expected_synthesizing_time").isNumber().doubleValue(); XilinxExperiment.this.expectedSynthesizingTime = (int) (expectedSynthesizingTime * 1000); } catch (Exception e) { //this.messages.setText("[Xilinx] Did not receive the expected_synthesizing_time parameter."); GWT.log("[Xilinx] Did not receive the expected_synthesizing_time parameter. Using the default. ", null); XilinxExperiment.this.expectedSynthesizingTime = this.DEFAULT_EXPECTED_SYNTHESIZING_TIME; //return; } // If it's not a demo, the user will have been prompted a file uploading form. // He might have indeed chosen a file to upload, or he might not. if (!isDemo()) { boolean success = this.tryUpload(); // If the file upload attempt on the reserve stage failed, then we will have to display // a button during the experiment itself so that the user can request the file he chose // be uploaded to the server. if (!success) this.uploadButton.setVisible(true); } else { this.loadStartControls(); } // The experiment started, so we should start the timer. this.timer.start(); // Start polling to know when the board has been programmed and the server is ready // to receive our requests. setupReadyTimer(); }
From source file:es.deusto.weblab.client.lab.comm.LabSerializerJSON.java
License:Open Source License
@Override public ExperimentAllowed[] parseListExperimentsResponse(String responseText) throws SerializationException, SessionNotFoundException, UserProcessingException, WebLabServerException { // "{\"result\": [" + // "{\"experiment\": {\"category\": {\"name\": \"Dummy experiments\"}, " + // "\"name\": \"ud-dummy\", \"end_date\": \"2008-01-01\", \"start_date\": \"2007-08-17\"}, \"time_allowed\": 30.0}, " + // "{\"experiment\": {\"category\": {\"name\": \"FPGA experiments\"}, " + // "\"name\": \"ud-fpga\", \"end_date\": \"2006-01-01\", \"start_date\": \"2005-01-01\"}, \"time_allowed\": 30.0}" + // "], \"is_exception\": false}" final JSONArray result = this.parseResultArray(responseText); final ExperimentAllowed[] experiments = new ExperimentAllowed[result.size()]; for (int i = 0; i < result.size(); ++i) { final JSONValue value = result.get(i); final JSONObject jsonExperimentAllowed = value.isObject(); if (jsonExperimentAllowed == null) throw new SerializationException("Expected JSON Object as ExperimentAllowed, found: " + value); final JSONValue jsonExperimentValue = jsonExperimentAllowed.get("experiment"); if (jsonExperimentValue == null) throw new SerializationException("Expected experiment field in ExperimentAllowed"); final JSONObject jsonExperiment = jsonExperimentValue.isObject(); if (jsonExperiment == null) throw new SerializationException( "Expected JSON Object as Experiment, found: " + jsonExperimentValue); final JSONValue jsonCategoryValue = jsonExperiment.get("category"); if (jsonCategoryValue == null) throw new SerializationException("Expected category field in Experiment"); final JSONObject jsonCategory = jsonCategoryValue.isObject(); if (jsonCategory == null) throw new SerializationException("Expected JSON Object as Category, found: " + jsonCategoryValue); final Category category = new Category(this.json2string(jsonCategory.get("name"))); final Experiment experiment = new Experiment(); experiment.setCategory(category); experiment.setName(this.json2string(jsonExperiment.get("name"))); final String startDateString = this.json2string(jsonExperiment.get("start_date")); final String endDateString = this.json2string(jsonExperiment.get("end_date")); final DateTimeFormat formatter1 = DateTimeFormat.getFormat("yyyy-MM-dd"); final DateTimeFormat formatter2 = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss"); final DateTimeFormat formatter3 = DateTimeFormat.getFormat("yyyy-MM-ddTHH:mm:ss"); final DateTimeFormat formatter4 = DateTimeFormat.getFormat("yyyy-MM-ddTHH:mm:ss.S"); try {// w w w.j av a 2 s. c om experiment.setStartDate(formatter1.parse(startDateString)); experiment.setEndDate(formatter1.parse(endDateString)); } catch (final IllegalArgumentException iae) { try { experiment.setStartDate(formatter2.parse(startDateString)); experiment.setEndDate(formatter2.parse(endDateString)); } catch (final IllegalArgumentException iae2) { try { experiment.setStartDate(formatter3.parse(startDateString)); experiment.setEndDate(formatter3.parse(endDateString)); } catch (final IllegalArgumentException iae3) { try { experiment.setStartDate(formatter4.parse(startDateString)); experiment.setEndDate(formatter4.parse(endDateString)); } catch (final IllegalArgumentException iae4) { throw new SerializationException( "Couldn't parse date: " + startDateString + "; or: " + endDateString); } } } } final ExperimentAllowed experimentAllowed = new ExperimentAllowed(); experimentAllowed.setTimeAllowed(this.json2int(jsonExperimentAllowed.get("time_allowed"))); experimentAllowed.setExperiment(experiment); experiments[i] = experimentAllowed; } return experiments; }