296 case METER:
297 fc = new FormProgressBar(WidgetType.METER);
298 break;
299 default:
300 log.severe("unknown widget index: {0}", widgetIndex);
301 return null;
302 }
303 fc.asControl().setFocusTraversable(false);
304 pool.put(id, fc, accessor.getPage().getUpdateContentCycleID()); // put or replace the entry
305 accessor.addChild(fc.asControl());
306 }
307
308 fc.setState(state);
309 Control ctrl = fc.asControl();
310 if (ctrl.getWidth() != w || ctrl.getHeight() != h) {
311 ctrl.resize(w, h);
312 }
313 if (ctrl.isManaged()) {
314 ctrl.setManaged(false);
315 }
316 if (type == WidgetType.SLIDER) {
317 Slider slider = (Slider)ctrl;
318 extParams.order(ByteOrder.nativeOrder());
319 slider.setOrientation(extParams.getInt()==0
320 ? Orientation.HORIZONTAL
321 : Orientation.VERTICAL);
322 slider.setMax(extParams.getFloat());
323 slider.setMin(extParams.getFloat());
324 slider.setValue(extParams.getFloat());
325 } else if (type == WidgetType.PROGRESSBAR) {
326 ProgressBar progress = (ProgressBar)ctrl;
327 extParams.order(ByteOrder.nativeOrder());
328 progress.setProgress(extParams.getInt() == 1
329 ? extParams.getFloat()
330 : progress.INDETERMINATE_PROGRESS);
331 } else if (type == WidgetType.METER) {
332 ProgressBar progress = (ProgressBar) ctrl;
333 extParams.order(ByteOrder.nativeOrder());
334 progress.setProgress(extParams.getFloat());
335 progress.setStyle(getMeterStyle(extParams.getInt()));
336 }
337 return new FormControlRef(fc);
338 }
339
340 private String getMeterStyle(int region) {
341 // see GaugeRegion in HTMLMeterElement.h
342 switch (region) {
343 case 1: // GaugeRegionSuboptimal
344 return "-fx-accent: yellow";
345 case 2: // GaugeRegionEvenLessGood
346 return "-fx-accent: red";
347 default: // GaugeRegionOptimum
348 return "-fx-accent: green";
349 }
350 }
351
352 @Override
353 public void drawWidget(
354 WCGraphicsContext g,
355 final Ref widget,
|
296 case METER:
297 fc = new FormProgressBar(WidgetType.METER);
298 break;
299 default:
300 log.severe("unknown widget index: {0}", widgetIndex);
301 return null;
302 }
303 fc.asControl().setFocusTraversable(false);
304 pool.put(id, fc, accessor.getPage().getUpdateContentCycleID()); // put or replace the entry
305 accessor.addChild(fc.asControl());
306 }
307
308 fc.setState(state);
309 Control ctrl = fc.asControl();
310 if (ctrl.getWidth() != w || ctrl.getHeight() != h) {
311 ctrl.resize(w, h);
312 }
313 if (ctrl.isManaged()) {
314 ctrl.setManaged(false);
315 }
316
317 if (extParams != null) {
318 if (type == WidgetType.SLIDER) {
319 Slider slider = (Slider)ctrl;
320 extParams.order(ByteOrder.nativeOrder());
321 slider.setOrientation(extParams.getInt()==0
322 ? Orientation.HORIZONTAL
323 : Orientation.VERTICAL);
324 slider.setMax(extParams.getFloat());
325 slider.setMin(extParams.getFloat());
326 slider.setValue(extParams.getFloat());
327 } else if (type == WidgetType.PROGRESSBAR) {
328 ProgressBar progress = (ProgressBar)ctrl;
329 extParams.order(ByteOrder.nativeOrder());
330 progress.setProgress(extParams.getInt() == 1
331 ? extParams.getFloat()
332 : progress.INDETERMINATE_PROGRESS);
333 } else if (type == WidgetType.METER) {
334 ProgressBar progress = (ProgressBar) ctrl;
335 extParams.order(ByteOrder.nativeOrder());
336 progress.setProgress(extParams.getFloat());
337 progress.setStyle(getMeterStyle(extParams.getInt()));
338 }
339 }
340 return new FormControlRef(fc);
341 }
342
343 private String getMeterStyle(int region) {
344 // see GaugeRegion in HTMLMeterElement.h
345 switch (region) {
346 case 1: // GaugeRegionSuboptimal
347 return "-fx-accent: yellow";
348 case 2: // GaugeRegionEvenLessGood
349 return "-fx-accent: red";
350 default: // GaugeRegionOptimum
351 return "-fx-accent: green";
352 }
353 }
354
355 @Override
356 public void drawWidget(
357 WCGraphicsContext g,
358 final Ref widget,
|