Esempio n. 1
0
  /**
   * Build the UI of the given process according to the given data.
   *
   * @param processExecutionData Process data.
   * @return The UI for the configuration of the process.
   */
  public JComponent buildUIConf(ProcessExecutionData processExecutionData) {
    JPanel panel = new JPanel(new MigLayout("fill"));
    // For each input, display its title, its abstract and gets its UI from the dataUIManager
    for (Input i : processExecutionData.getProcess().getInput()) {
      JPanel inputPanel = new JPanel(new MigLayout("fill"));
      inputPanel.setBorder(BorderFactory.createTitledBorder(i.getTitle()));
      JLabel inputAbstrac = new JLabel(i.getResume());
      inputAbstrac.setFont(inputAbstrac.getFont().deriveFont(Font.ITALIC));
      inputPanel.add(inputAbstrac, "wrap");
      DataUI dataUI = dataUIManager.getDataUI(i.getDataDescription().getClass());
      if (dataUI != null) {
        inputPanel.add(dataUI.createUI(i, processExecutionData.getInputDataMap()), "wrap");
      }
      panel.add(inputPanel, "growx, wrap");
    }

    // For each output, display its title, its abstract and gets its UI from the dataUIManager
    for (Output o : processExecutionData.getProcess().getOutput()) {
      DataUI dataUI = dataUIManager.getDataUI(o.getDataDescription().getClass());
      if (dataUI != null) {
        JComponent component = dataUI.createUI(o, processExecutionData.getOutputDataMap());
        if (component != null) {
          JPanel outputPanel = new JPanel(new MigLayout("fill"));
          outputPanel.setBorder(BorderFactory.createTitledBorder(o.getTitle()));
          JLabel outputAbstrac = new JLabel(o.getResume());
          outputAbstrac.setFont(outputAbstrac.getFont().deriveFont(Font.ITALIC));
          outputPanel.add(outputAbstrac, "wrap");
          outputPanel.add(component, "wrap");
          panel.add(outputPanel, "growx, wrap");
        }
      }
    }
    return panel;
  }
Esempio n. 2
0
  /**
   * Build the UI of the given process according to the given data.
   *
   * @param processExecutionData Process data.
   * @return The UI for the configuration of the process.
   */
  public JComponent buildUIInfo(ProcessExecutionData processExecutionData) {
    JPanel panel = new JPanel(new MigLayout("fill"));
    Process p = processExecutionData.getProcess();
    // Process info
    JLabel titleContentLabel = new JLabel(p.getTitle());
    JLabel abstracContentLabel = new JLabel();
    if (p.getResume() != null) {
      abstracContentLabel.setText(p.getResume());
    } else {
      abstracContentLabel.setText("-");
      abstracContentLabel.setFont(abstracContentLabel.getFont().deriveFont(Font.ITALIC));
    }

    JPanel processPanel = new JPanel(new MigLayout());
    processPanel.setBorder(BorderFactory.createTitledBorder("Process :"));
    processPanel.add(titleContentLabel, "wrap, align left");
    processPanel.add(abstracContentLabel, "wrap, align left");

    // Input info
    JPanel inputPanel = new JPanel(new MigLayout());
    inputPanel.setBorder(BorderFactory.createTitledBorder("Inputs :"));

    for (Input i : p.getInput()) {
      inputPanel.add(new JLabel(dataUIManager.getIconFromData(i)));
      inputPanel.add(new JLabel(i.getTitle()), "align left, wrap");
      if (i.getResume() != null) {
        JLabel abstrac = new JLabel(i.getResume());
        abstrac.setFont(abstrac.getFont().deriveFont(Font.ITALIC));
        inputPanel.add(abstrac, "span 2, wrap");
      } else {
        inputPanel.add(new JLabel("-"), "span 2, wrap");
      }
    }

    // Output info
    JPanel outputPanel = new JPanel(new MigLayout());
    outputPanel.setBorder(BorderFactory.createTitledBorder("Outputs :"));

    for (Output o : p.getOutput()) {
      outputPanel.add(new JLabel(dataUIManager.getIconFromData(o)));
      outputPanel.add(new JLabel(o.getTitle()), "align left, wrap");
      if (o.getResume() != null) {
        JLabel abstrac = new JLabel(o.getResume());
        abstrac.setFont(abstrac.getFont().deriveFont(Font.ITALIC));
        outputPanel.add(abstrac, "span 2, wrap");
      } else {
        outputPanel.add(new JLabel("-"), "align center, span 2, wrap");
      }
    }

    panel.add(processPanel, "growx, wrap");
    panel.add(inputPanel, "growx, wrap");
    panel.add(outputPanel, "growx, wrap");

    return panel;
  }
Esempio n. 3
0
  @Override
  public void update(GameContainer gameContainer, StateBasedGame stateBasedGame, int delta)
      throws SlickException {

    Input in = gameContainer.getInput();

    if (in.isKeyPressed(Input.KEY_C)) {
      clear();
    }

    gameContainer.setMaximumLogicUpdateInterval(updateInterval);

    if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
      float x1 = in.getMouseX() / ratio;
      float y1 = in.getMouseY() / ratio;
      if (start == null) {
        start = new Cell((int) x1, (int) y1, ratio, false);
        start.start = true;
        cells[start.gridPosX][start.gridPosY].start = true;
        cellStack.add(cells[start.gridPosX][start.gridPosY]);
      } else if (goal == null) {
        goal = new Cell((int) x1, (int) y1, ratio, false);
        cells[goal.gridPosX][goal.gridPosY].goal = true;
      } else {
        changeCellAtPosition((int) x1, (int) y1);
      }

      if (start != null && goal != null) {
        this.wall = cells[(int) x1][(int) y1].wall;
      }
    }

    if (in.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
      if (start != null && goal != null) {
        mousePressing = true;
        float x1 = in.getMouseX() / ratio;
        float y1 = in.getMouseY() / ratio;
        cells[(int) x1][(int) y1].wall = this.wall;
      }
    } else {
      mousePressing = false;
    }

    if (in.isKeyPressed(Input.KEY_ENTER)) {
      if (mazeSolved && displayingMaze) {
        clear();
        createGraph();
        maze = true;
      } else if (!maze) {
        this.search = true;
      }
    }

    if (in.isKeyPressed(Input.KEY_M) && !maze) {
      createGraph();
      maze = true;
      this.logger.initWriter();
    }

    if (in.isKeyPressed(Input.KEY_S)) {
      clear();
      for (int i = 0; i < cells.length; i++) {
        for (int j = 0; j < cells.length; j++) {
          Random random = new Random();
          if (random.nextInt(3) == 0) {
            cells[i][j].wall = true;
          }
        }
      }
      setDefaultStartAndEnd(true);
    }

    if (in.isKeyPressed(Input.KEY_ADD)) {
      if (updateInterval > 1) {
        updateInterval -= 1;
      }
    }
    if (in.isKeyPressed(Input.KEY_SUBTRACT)) {
      if (updateInterval < 20) {
        updateInterval += 1;
      }
    }

    if (in.isKeyPressed(Input.KEY_P)) {
      if (!gameContainer.isPaused()) {
        gameContainer.pause();
      } else {
        gameContainer.resume();
      }
    }

    if (in.isKeyPressed(Input.KEY_D)) {
      this.diagonal = !this.diagonal;
    }

    if (in.isKeyPressed(Input.KEY_ESCAPE)) {
      stateBasedGame.enterState(1);
    }

    if (in.isKeyPressed(Input.KEY_A)) {
      AnalyzeLog.analyzeBacktracks(AnalyzeLog.FIRST);
    }

    if (in.isKeyPressed(Input.KEY_I)) {
      this.createImage();
    }

    if (this.search) {
      if (start == null || goal == null) {
        this.search = false;
      } else {
        if (ButtonStates.DFSState) {
          if (solvingVisited.size() < 1) {
            solvingVisited.add(cells[start.gridPosX][start.gridPosY]);
            cells[start.gridPosX][start.gridPosY].solvingVisited = true;
            currentDFSCell = cells[start.gridPosX][start.gridPosY];
          } else {
            for (int x = 0; x < CELLS; x++) {
              for (int y = 0; y < CELLS; y++) {
                cells[x][y].dfsCheckNeighbors();
              }
            }
            if (currentDFSCell.goal) {
              this.search = false;
              this.drawWay = true;
              this.end = currentDFSCell;
              getPath(false, null);
              if (displayingMaze) {
                mazeSolved = true;
              }
              foundSolution = true;
            } else {
              if (solvingVisited.size() != (CELLS * CELLS)) {
                ArrayList<Cell> currentNeighbors = new ArrayList<>();
                if (currentDFSCell.dfsNorth != null
                    && !currentDFSCell.dfsNorth.solvingVisited
                    && !currentDFSCell.dfsNorth.wall) {
                  currentNeighbors.add(currentDFSCell.dfsNorth);
                } else if (currentDFSCell.dfsEast != null
                    && !currentDFSCell.dfsEast.solvingVisited
                    && !currentDFSCell.dfsEast.wall) {
                  currentNeighbors.add(currentDFSCell.dfsEast);
                } else if (currentDFSCell.dfsSouth != null
                    && !currentDFSCell.dfsSouth.solvingVisited
                    && !currentDFSCell.dfsSouth.wall) {
                  currentNeighbors.add(currentDFSCell.dfsSouth);
                } else if (currentDFSCell.dfsWest != null
                    && !currentDFSCell.dfsWest.solvingVisited
                    && !currentDFSCell.dfsWest.wall) {
                  currentNeighbors.add(currentDFSCell.dfsWest);
                } else {;
                }
                if (currentNeighbors.size() > 0) {
                  Cell neighbor = currentNeighbors.get(0);
                  neighbor.solvingPrevious = currentDFSCell;
                  neighbor.solvingVisited = true;
                  currentDFSCell = neighbor;
                } else {
                  dfsBacktracked.add(currentDFSCell);
                  dfsBacktracked.add(currentDFSCell.solvingPrevious);
                  currentDFSCell = currentDFSCell.solvingPrevious;
                }
              }
            }
          }
        } else if (ButtonStates.AStarState) {

        } else if (ButtonStates.BFSState) {
          if (solvingVisited.size() < 1) {
            solvingVisited.add(cells[start.gridPosX][start.gridPosY]);
            cells[start.gridPosX][start.gridPosY].solvingVisited = true;
            cellStack.add(cells[start.gridPosX][start.gridPosY]);
          } else {
            if (!cellStack.isEmpty()) {
              Cell current = (Cell) cellStack.remove();
              Cell child;
              if (current.goal) {
                this.end = current;
                this.drawWay = true;
                this.search = false;
                getPath(false, null);
                if (displayingMaze) {
                  mazeSolved = true;
                }
                foundSolution = true;
              } else {
                while ((child = getUnvisitedChildCell(current)) != null) {
                  child.solvingVisited = true;
                  child.solvingPrevious = current;
                  solvingVisited.add(child);
                  cellStack.add(child);
                  current.solvingCheckNeighbors(diagonal);
                  getPath(true, child);
                }
              }
            }
          }
        } else {
          try {
            throw new NoSolvingAlgorithmSelectedException();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    }
    if (this.maze) {
      if (this.logger.used) {
        this.logger.createNewLogFile();
        this.logger.initWriter();
        this.logger.used = false;
      }
      if (cells.length != 0) {
        logger.writeInLog("Checking neighbors");
        for (int i = 0; i < CELLS; i++) {
          for (int j = 0; j < CELLS; j++) {
            cells[i][j].genCheckNeighbors();
          }
        }

        if (genVisited.size() < 1) {
          genVisited.add(cells[1][1]);
          currentGenCell = cells[1][1];
          currentGenCell.genVisited = true;
          logger.writeInLog("Adding Cell X1 and Y1 to visited Cells");
        }
        if (genVisited.size() != totalCells) {
          ArrayList<Cell> currentNeighbors = new ArrayList<>();
          if (currentGenCell.north != null
              && !currentGenCell.north.genVisited
              && currentGenCell.north.allWallsIntact) {
            currentNeighbors.add(currentGenCell.north);
            logger.writeInLog(
                "Adding north cell to neighbors at: "
                    + currentGenCell.north.gridPosX
                    + "; "
                    + currentGenCell.north.gridPosY);
          }
          if (currentGenCell.east != null
              && !currentGenCell.east.genVisited
              && currentGenCell.east.allWallsIntact) {
            currentNeighbors.add(currentGenCell.east);
            logger.writeInLog(
                "Adding east cell to neighbors at: "
                    + currentGenCell.east.gridPosX
                    + "; "
                    + currentGenCell.east.gridPosY);
          }
          if (currentGenCell.south != null
              && !currentGenCell.south.genVisited
              && currentGenCell.south.allWallsIntact) {
            currentNeighbors.add(currentGenCell.south);
            logger.writeInLog(
                "Adding south cell to neighbors at: "
                    + currentGenCell.south.gridPosX
                    + "; "
                    + currentGenCell.south.gridPosY);
          }
          if (currentGenCell.west != null
              && !currentGenCell.west.genVisited
              && currentGenCell.west.allWallsIntact) {
            currentNeighbors.add(currentGenCell.west);
            logger.writeInLog(
                "Adding west cell to neighbors at: "
                    + currentGenCell.west.gridPosX
                    + "; "
                    + currentGenCell.west.gridPosY);
          }

          if (currentNeighbors.size() > 0) {
            Random random = new Random();
            int randomValue = random.nextInt(currentNeighbors.size());
            logger.writeInLog("Generated random number: " + randomValue);
            Cell neighbor = currentNeighbors.get(randomValue);
            logger.writeInLog("Picked neighbor: " + neighbor.gridPosX + "; " + neighbor.gridPosY);
            neighbor.genVisited = true;

            int wallX = 0;
            int wallY = 0;

            // break wall
            if (neighbor.gridPosX > currentGenCell.gridPosX) {
              wallX = currentGenCell.gridPosX + 1;
            } else if (neighbor.gridPosX < currentGenCell.gridPosX) {
              wallX = currentGenCell.gridPosX - 1;
            } else {
              wallX = currentGenCell.gridPosX;
            }

            if (neighbor.gridPosY > currentGenCell.gridPosY) {
              wallY = currentGenCell.gridPosY + 1;
            } else if (neighbor.gridPosY < currentGenCell.gridPosY) {
              wallY = currentGenCell.gridPosY - 1;
            } else {
              wallY = currentGenCell.gridPosY;
            }

            cells[wallX][wallY].wall = false;
            cells[wallX][wallY].genVisited = true;
            logger.writeInLog("Breaking wall at: " + wallX + "; " + wallY);
            genVisited.add(cells[wallX][wallY]);
            neighbor.genBacktrack = currentGenCell;
            logger.writeInLog(
                "Set current cell to backtrack cell at: "
                    + currentGenCell.gridPosX
                    + "; "
                    + currentGenCell.gridPosY);
            currentGenCell = neighbor;

          } else {
            currentGenCell = currentGenCell.genBacktrack;
            logger.writeInLog(
                "Backtracking at: "
                    + currentGenCell.genBacktrack.gridPosX
                    + "; "
                    + currentGenCell.genBacktrack.gridPosY);
          }
        } else {
          currentGenCell = null;
          this.maze = false;
          setDefaultStartAndEnd(true);
          displayingMaze = true;
          if ((this.search = !this.search) == true) {
            if (this.startSearch == false) {
              this.search = false;
              createImage();
            }
          }
          logger.writeInLog("Done Maze, closing logger.");
          logger.closeWriter();
          if (this.automaticallyGenerateMazes && (generatedMazes < mazesToGenerate)) {
            generatedMazes += 1;
            clear();
            createGraph();
            this.maze = true;
          } else if (this.logger.stepList.size() != 0) {
            this.logger.printStepList();
          } else {;
          }
        }
      }
    }
    char[][] copyOfLevel = new char[CELLS][CELLS];
    for (int x = 0; x < cells.length; x++) {
      for (int y = 0; y < cells.length; y++) {
        if (cells[x][y].wall) {
          copyOfLevel[x][y] = 'W';
        } else if (!cells[x][y].wall) {
          copyOfLevel[x][y] = 'D';
        } else if (cells[x][y].start) {
          copyOfLevel[x][y] = 'S';
        } else if (cells[x][y].goal) {
          copyOfLevel[x][y] = 'G';
        } else {
          copyOfLevel[x][y] = 'D';
        }
      }
    }
    Level.update(copyOfLevel);
  }