/**
   * Constructor for the GUI
   *
   * @param start true if the GUI should be displayed, false otherwise
   */
  public LightsOutGUI(boolean start) {
    if (start) {
      initialize();
      updateDatabase();
      if (firstTimeRunning) createAndShowGUI();
      setInteractions();
      LightsOutDialog.setVisible(true);
      askSettings();
      Main.delay(500);
      while (!ready) {
        Main.delay(1);
      }

      firstTimeRunning = false;

      new Thread() {
        @Override
        public void run() {
          try {
            game = new LightsOut();
            game.startGame();
          } catch (Exception ex) {
            Thread.currentThread().interrupt();
          }
        }
      }.start();

    } else {
      quit();
    }
  }
 /** Quits the game and closes the GUI */
 public static void quit() {
   Main.setClosing(true);
   Main.lightsOutRunning = false;
   game = null;
   Main.nothingRunning();
   Main.resetCards();
   LightsOutDialog.dispose();
   Main.setCardIcon(Main.lightsOutCard, "lightsOut", "default");
 }
 /**
  * Method called to close the GUI and game. <br>
  * Should not be called from within LightsOut class.
  *
  * @return 1
  */
 public static int quitLightsOut() {
   LightsOut.forceQuit();
   Main.setClosing(true);
   game = null;
   Main.lightsOutRunning = false;
   Main.nothingRunning();
   Main.resetCards();
   LightsOutDialog.dispose();
   return 1;
 }
  public void save() {
    // synch field with in-memory document, set field to appear saved
    for (Synchable s : list) {
      s.synch();
    }

    // call the method in Main
    Main.save();
  }
  /** Sets the window position and dimenstions */
  private static void initialize() {
    Main.setClosing(false);
    Main.setCardIcon(Main.lightsOutCard, "lightsOut", "selected");
    LightsOut.setDifficulty(defaultDifficulty);

    mainWindowX = Main.getWindowPositionX();
    mainWindowY = Main.getWindowPositionY();
    mainWindowW = Main.getWindowDimensionsW();
    mainWindowH = Main.getWindowDimensionsH();

    windowW = 600;
    windowH = mainWindowH;
    windowX = (mainWindowX + mainWindowW + 20);
    windowY = (mainWindowY);
  }
Exemplo n.º 6
0
 /** Ilmoita asetetulle ikkunalle muutoksista tietorakenteeseen. */
 private void notifySource() {
   if (notify instanceof Main) {
     ((Main) notify).update();
   }
 }
Exemplo n.º 7
0
  /** Sets up the behaviour of the Items int the menubar */
  private void setupMenuItems() {
    aboutMenu.setOnAction(
        event -> {
          AnchorPane root;
          try {
            root = FXMLLoader.load(getClass().getResource("about.fxml"));

            Stage stage = new Stage();
            stage.setScene(new Scene(root));
            stage.setTitle("About");
            stage.show();
          } catch (Exception e) {
            log.error("Error loading About Window - " + e.getMessage());
          }
        });

    exitMenu.setOnAction(
        event -> {
          Platform.runLater(
              new Runnable() {
                @Override
                public void run() {
                  Platform.exit();
                  log.debug("Window closed");
                }
              });
        });

    loadMenu.setOnAction(event -> loadFile(true));

    saveMenu.setOnAction(event -> Main.serializeItems());

    groupByMenu.setOnAction(
        event -> {
          Optional<String> sortOption =
              Alerter.getChoiceDialog("Sorting", null, "Select how you want to group: ");
          sortOption.ifPresent(letter -> groupItems(letter));
        });

    updateAllMenu.setOnAction(
        event -> {
          new Thread(
                  new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {
                      log.debug("UpdateAll Thread Triggered");

                      itemsMap.forEach(
                          (a, b) -> {
                            updateItem(b);
                          });

                      updateList();
                      Main.serializeItems();

                      log.debug("UpdateAll Thread terminated successfully");
                      return null;
                    }
                  })
              .start();
        });

    updateMenu.setOnAction(
        event -> {
          if (!listView.getSelectionModel().isEmpty()) {
            ItemBox itemBox = listView.getSelectionModel().getSelectedItem();
            updateItem(itemBox);
          } else {
            Alert alert =
                Alerter.getAlert(
                    AlertType.INFORMATION,
                    "No Item selected",
                    null,
                    "Please select the Item you want to update!");
            alert.showAndWait();
            log.debug("Info Popup triggered, No item selected");
          }
        });

    deleteMenu.setOnAction(
        event -> {
          ItemBox rem = itemsMap.remove(listView.getSelectionModel().getSelectedItem().getGtin());
          log.info("Item: " + rem.getName() + " removed");
          updateList();
        });

    repeatMenu.setOnAction(
        event -> {
          if (lastCommand != null) {
            String[] props = lastCommand.split(" ");
            log.info("Repeat called with: " + lastCommand);

            switch (props[0]) {
              case "ADD":
                addItem(props[1]);
                break;
              case "RM":
                removeItem(props[1]);
                break;
            }
          }
        });

    printMenu.setOnAction(
        event -> {
          printOut(PrintOutType.OVERVIEW);
        });

    printShoppingMenu.setOnAction(
        event -> {
          printOut(PrintOutType.SHOPPING);
        });
  }