private void setForm(DisplayModel displayModel) { spriteNameTextBox.setText(displayModel.getName()); spriteXTextBox.setText(String.valueOf(displayModel.getInitX())); spriteYTextBox.setText(String.valueOf(displayModel.getInitY())); String temp = displayModel.getImageUrl().replace("./Images/", ""); spriteImageComboBox.setSelectedItem(temp); moveLeft.setSelected(false); moveRight.setSelected(false); moveUp.setSelected(false); moveDown.setSelected(false); }
public static void map(DisplayModel displayModel, Sprite sprite) { displayModel.setName(sprite.getName()); displayModel.setImageUrl(sprite.getImageFileUrl()); displayModel.setInitX(sprite.getInitCoordinate().getxPosition()); displayModel.setInitY(sprite.getInitCoordinate().getyPosition()); displayModel.setHeight(sprite.getHeight()); displayModel.setWidth(sprite.getWidth()); // TO-DO sprite to display mapper for event action map // Not needed for now }
@Override public void actionPerformed(ActionEvent e) { Map<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>(); ArrayList<String> actions = new ArrayList<String>(); ArrayList<String> collisionActionsEvents = new ArrayList<String>(); // TODO Auto-generated method stub if (!spriteNameTextBox.getText().isEmpty() && !spriteXTextBox.getText().isEmpty() && !spriteYTextBox.getText().isEmpty() && Pattern.matches("\\b\\d+\\b", spriteXTextBox.getText()) && Pattern.matches("\\b\\d+\\b", spriteYTextBox.getText())) { if (moveLeft.isSelected()) { actions.add(ActionName.MOVE_LEFT_ACTION); } if (moveRight.isSelected()) { actions.add(ActionName.MOVE_RIGHT_ACTION); } if (!collisionEventActionHashMap.isEmpty()) { for (String key : collisionEventActionHashMap.keySet()) { String tempActionEventCopy = new String(); tempActionEventCopy = key + ":" + collisionEventActionHashMap.get(key); collisionActionsEvents.add(tempActionEventCopy); } } DisplayModel model = new DisplayModel(); model.setName(spriteNameTextBox.getText().toString()); model.setImageUrl(spriteImageComboBox.getSelectedItem().toString()); /* model.setWidth(Integer.parseInt(spriteWidthValue.getText() .toString())); model.setHeight(Integer.parseInt(spriteHeightValue.getText() .toString()));*/ model.setInitX(Integer.parseInt(spriteXTextBox.getText().toString())); model.setInitY(Integer.parseInt(spriteYTextBox.getText().toString())); map.put(ActionName.KEY_PRESS_EVENT_KEY, actions); map.put(ActionName.COLLISION_EVENT, collisionActionsEvents); if (selfMove.isSelected()) { actions = new ArrayList<String>(); actions.add(selfMove.getText()); map.put(ActionName.MOVE_EVENT, actions); } model.setEventActionMap(map); controller.addSprite(model); clearFormOnReset(); setFormValues(); } }