Пример #1
0
  /** @param edit */
  @Override
  public void setRoomEditMode(boolean edit) {
    roomEditMode = edit;

    if (roomEditMode) {
      Callout callout =
          new Callout(
              this.getClass().getCanonicalName(),
              "info",
              I18n.msg("environment_editing_instructions")
                  + ":\n"
                  + "- "
                  + I18n.msg("environment_editing_instructions_add_new_room")
                  + "\n"
                  + "- "
                  + I18n.msg("environment_editing_instructions_change_room_shape")
                  + "\n"
                  + "- "
                  + I18n.msg("environment_editing_instructions_remove_room")
                  + "\n"
                  + "- "
                  + I18n.msg("environment_editing_instructions_create_draggable_point")
                  + "\n"
                  + "- "
                  + I18n.msg("environment_editing_instructions_delete_draggable_point")
                  + "\n",
              100,
              200,
              0,
              -1);
      createCallout(callout);
      createHandles(null);
      // find the first room and select it
      Room selectedRoom = getCurrEnv().getRooms().get(0);
      if (selectedRoom != null) {
        setSelectedZone(selectedRoom);
      }
    } else {
      handles.clear();
      indicators.clear();
      selectedZone = null;
      calloutsUpdater.clearAll();
    }

    setNeedRepaint(true);
  }
Пример #2
0
  /** @param e */
  @Override
  public void mouseClicked(MouseEvent e) {
    if (!roomEditMode) {
      EnvObjectLogic obj = mouseOnObject(e.getPoint());

      if (obj != null) {
        // single click on an object
        if (e.getButton() == MouseEvent.BUTTON1) {
          if (e.getClickCount() == 1) {
            mouseClickObject(obj);
          } else {
            // double click on an object
            if (e.getClickCount() == 2) {
              mouseDoubleClickObject(obj);
            }
          }
        } else {
          // right click on an object
          if (e.getButton() == MouseEvent.BUTTON3) {
            if (e.getClickCount() == 1) {
              mouseRightClickObject(obj);
            }
          }
        }
      } else {
        removeIndicators();
        calloutsUpdater.clearAll();
      }
    } else { // if edit mode
      removeIndicators();
      calloutsUpdater.clearAll();

      toRealCoords(e.getPoint());

      // click on an handle in edit mode
      Handle clickedHandle = mouseOnHandle(e.getPoint());

      // single right click
      if (clickedHandle != null) {
        if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) {
          clickedHandle.setSelected(true);
        } else {
          // double right click
          if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1)) {
            clickedHandle.addAdiacent();
            setSelectedZone(clickedHandle.getZone());
          } else {
            // single left click
            if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON3)) {
              clickedHandle.remove();
              setSelectedZone(clickedHandle.getZone());
            }
          }
        }
      } else {
        // click on a zone in edit mode if no handle is selected
        ZoneLogic zone = mouseOnZone(e.getPoint());
        if (zone != null) {
          Callout callout =
              new Callout(
                  this.getClass().getCanonicalName(),
                  "info",
                  I18n.msg("room_zone_selected") + " [" + zone.getPojo().getName() + "]",
                  50,
                  150,
                  0,
                  -1);
          createCallout(callout);
          setSelectedZone(zone);
        } else {
          handles.clear();
          // createHandles(null);
        }
      }
      setNeedRepaint(true);
    }
  }