private void connectHandlers() {
		EventBus eventBus = playerServices.getEventBus();
		
		eventBus.addHandler(ShowErrorsEvent.TYPE, new ShowErrorsEvent.Handler() {
			public void onShowErrors(ShowErrorsEvent event) {
				setShowErrorsMode();
			}
		});
		
		eventBus.addHandler(WorkModeEvent.TYPE, new WorkModeEvent.Handler() {
			public void onWorkMode(WorkModeEvent event) {
				setWorkMode();
			}
		});
		
		eventBus.addHandler(ResetPageEvent.TYPE, new ResetPageEvent.Handler() {
			public void onResetPage(ResetPageEvent event) {
				setWorkMode();
			}
		});
		
		eventBus.addHandler(CustomEvent.TYPE, new CustomEvent.Handler() {
			@Override
			public void onCustomEventOccurred(CustomEvent event) {
				if (event.eventName.equals("ShowAnswers")) {
					if (view.isShowErrorsMode()) {
						view.setShowErrorsMode(false);
					}
				}
			}
		});
	}
	@Override
	public String getState() {
		IJsonServices json = playerServices.getJsonServices();
		HashMap<String, String> state = new HashMap<String, String>();

		state.put("isVisible", Boolean.toString(isVisible));
		
		return json.toJSONString(state);
	}
	private void removeItem() {
		if (consumedItem != null) {
			view.setImageUrl("");
			fireItemReturnedEvent(consumedItem);
			consumedItem = null;
			ValueChangedEvent valueEvent = new ValueChangedEvent(model.getId(), "", "", "0");
			playerServices.getEventBus().fireEvent(valueEvent);
		}
	}
	private void setGapAnswer(int index, String value) {
		isSetGapAnswers = true;
		ImageSourcePresenter igp = (ImageSourcePresenter) playerServices.getModule(value.replaceAll("\"", ""));
		view.setImageUrl(igp.getImageUrl());
		view.resetStyles();
		view.setDisabled(true);
		view.showCorrectAnswers();
		view.removeClass("ui-state-disabled");
	}
	private void fireItemConsumedEvent() {
		ItemConsumedEvent event = new ItemConsumedEvent(readyToDraggableItem);
		playerServices.getEventBus().fireEventFromSource(event, this);

		if (isCorrect()) {
			sendEventCode(model.getEventCode(ImageGapModule.EVENT_CORRECT));
		} else {
			sendEventCode(model.getEventCode(ImageGapModule.EVENT_WRONG));
		}
	}
	private void connectHandlers() {
		EventBus eventBus = playerServices.getEventBus();

		eventBus.addHandler(ShowErrorsEvent.TYPE, new ShowErrorsEvent.Handler() {
			@Override
			public void onShowErrors(ShowErrorsEvent event) {
				setShowErrorsMode();
			}
		});

		eventBus.addHandler(WorkModeEvent.TYPE, new WorkModeEvent.Handler() {
			@Override
			public void onWorkMode(WorkModeEvent event) {
				setWorkMode();
			}
		});

		eventBus.addHandler(ResetPageEvent.TYPE, new ResetPageEvent.Handler() {
			@Override
			public void onResetPage(ResetPageEvent event) {
				reset();
			}
		});

		eventBus.addHandler(ItemSelectedEvent.TYPE, new ItemSelectedEvent.Handler() {
			@Override
			public void onItemSelected(ItemSelectedEvent event) {
				if (event.getItem() instanceof DraggableImage) {
					if (event.getItem().getId() == null) {
						readyToDraggableItem = null;
					} else {
						readyToDraggableItem = event.getItem();
					}
				}
			}
		});

		eventBus.addHandler(ItemConsumedEvent.TYPE, new ItemConsumedEvent.Handler() {
			@Override
			public void onItemConsumed(ItemConsumedEvent event) {
				readyToDraggableItem = null;
			}
		});

		eventBus.addHandler(CustomEvent.TYPE, new CustomEvent.Handler() {
			@Override
			public void onCustomEventOccurred(CustomEvent event) {
				if (event.eventName.equals("ShowAnswers")) {
					showAnswers();
				} else if (event.eventName.equals("HideAnswers")) {
					hideAnswers();
				}
			}
		});
	}
	private void insertItem() {
		if (readyToDraggableItem != null) {
			view.setImageUrl(readyToDraggableItem.getValue());
			consumedItem = readyToDraggableItem;
			fireItemConsumedEvent();
			String score = Integer.toString(getScore());
			ValueChangedEvent valueEvent = new ValueChangedEvent(model.getId(), "", consumedItem.getId(), score);
			playerServices.getEventBus().fireEvent(valueEvent);
			view.makeDraggable(this);
		}
	}
	@Override
	public void setState(String state) {
		IJsonServices json = playerServices.getJsonServices();
		HashMap<String, String> decodedState = json.decodeHashMap(state);
		
		if (decodedState.containsKey("isVisible")) {
			isVisible = Boolean.parseBoolean(decodedState.get("isVisible"));
			if (isVisible) {
				show();
			} else {
				hide();
			}
		}
	}
	@Override
	public String getState() {
		IJsonServices json = playerServices.getJsonServices();
		HashMap<String, String> state = new HashMap<String, String>();
		if (consumedItem != null) {
			state.put("consumed",  consumedItem.toString());
		}
		state.put("isVisible", Boolean.toString(isVisible));
		if (isShowErrorsMode) {
			state.put("isDisabled", Boolean.toString(workModeDisabled));
		} else if (this.isShowAnswersActive) {
			state.put("isDisabled", Boolean.toString(showAnswersModeDisabled));
		} else {
			state.put("isDisabled", Boolean.toString(view.getDisabled()));
		}

		return json.toJSONString(state);
	}
Beispiel #10
0
  private Widget createInnerButton(IPlayerServices playerServices) {

    Widget button = null;

    IPlayerCommands pageService = null;
    if (playerServices != null) {
      pageService = playerServices.getCommands();
    }

    ButtonType type = module.getType();

    if (ButtonType.checkAnswers == type) {
      button = new CheckAnswersButton(playerServices);
    } else if (ButtonType.cancel == type) {
      button = new ClosePopupButton(pageService);
    } else if (ButtonType.nextPage == type) {
      button = new NextPageButton(playerServices);
    } else if (ButtonType.popup == type) {
      button =
          new PopupButton(module.getOnClick(), this, pageService, module.getAdditionalClasses());
    } else if (ButtonType.prevPage == type) {
      button = new PrevPageButton(playerServices);
    } else if (ButtonType.gotoPage == type) {
      button = new GotoPageButton(module.getOnClick(), module.getPageIndex(), playerServices);
    } else if (ButtonType.reset == type) {
      button = new ResetButton(pageService);
    } else {
      button = new StandardButton(module, playerServices);
    }

    if (button instanceof ButtonBase) {
      ButtonBase pushButton = (ButtonBase) button;
      StyleUtils.applyInlineStyle(pushButton, module);

      pushButton.setText(module.getText());
    }

    if (playerServices != null) {
      button.setVisible(module.isVisible());
    }

    return button;
  }
Beispiel #11
0
	@Override
	public void setState(String stateObj) {
		IJsonServices json = playerServices.getJsonServices();
		HashMap<String, String> state = json.decodeHashMap(stateObj);
		if (state.containsKey("consumed")) {
			consumedItem = DraggableItem.createFromString(state.get("consumed"));
			view.setImageUrl(getImageURL(consumedItem));
			view.makeDraggable(this);
		}
		if (state.containsKey("isVisible")) {
			if (Boolean.parseBoolean(state.get("isVisible"))) {
				show();
			} else {
				hide();
			}
		}

		if (state.containsKey("isDisabled")) {
			view.setDisabled(Boolean.parseBoolean(state.get("isDisabled")));
		}
	}
Beispiel #12
0
	private void itemStopped() {
		CustomEvent stopEvent = new CustomEvent("itemStopped", prepareEventData());
		playerServices.getEventBus().fireEvent(stopEvent);
	}
Beispiel #13
0
	private void itemDragged() {
		CustomEvent dragEvent = new CustomEvent("itemDragged", prepareEventData());
		removeItem();
		playerServices.getEventBus().fireEvent(dragEvent);
	}
Beispiel #14
0
	private void sendEventCode(String eventCode) {
		if (eventCode != null && !eventCode.isEmpty()) {
			playerServices.getCommands().executeEventCode(eventCode);
		}
	}
Beispiel #15
0
	private void fireItemReturnedEvent(DraggableItem previouslyConsumedItem) {
		ItemReturnedEvent event = new ItemReturnedEvent(previouslyConsumedItem);
		playerServices.getEventBus().fireEvent(event);

		sendEventCode(model.getEventCode(ImageGapModule.EVENT_EMPTY));
	}
Beispiel #16
0
	private void setCorrectImage() {
		String[] answers = model.getAnswerId().split(";");
		ImageSourcePresenter igp = (ImageSourcePresenter) playerServices.getModule(answers[0]);
		view.setImageUrl(igp.getImageUrl());
	}