示例#1
0
  /**
   * Create / edit properties file with default settings
   *
   * @param args Startup arguments
   */
  public static void main(String[] args) {
    XMLEncoder xmlEncoder;
    try {
      xmlEncoder =
          new XMLEncoder(
              new BufferedOutputStream(new FileOutputStream(CommonPresenter.PROPERTIES_FILE_NAME)));
    } catch (FileNotFoundException e) {
      System.err.println("unable to create/open properties file for writing");
      System.out.println("Press return to exit...");
      try {
        new BufferedReader(new InputStreamReader(System.in)).readLine();
      } catch (IOException e1) {
        e1.printStackTrace();
      }
      return;
    }

    Properties props = new Properties();
    props.setPoolSize(10);
    props.setMazeGeneratorType(MazeGeneratorTypes.MY);
    props.setMazeSearcherType(MazeSearcherTypes.A_STAR_MANHATTER);
    props.setViewType(ViewTypes.GUI);

    xmlEncoder.writeObject(props);
    xmlEncoder.close();

    System.out.println("default properties file created");
    System.out.println("Press return to exit...");
    try {
      new BufferedReader(new InputStreamReader(System.in)).readLine();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 /** Constructor */
 public AbstractModelObservable() {
   this.hashMaze = new HashMap<String, Maze3d>();
   this.commandMap = new HashMap<String, Object>();
   threadPool = Executors.newCachedThreadPool();
   this.properties = new Properties();
   properties.defaultProp();
 }
示例#3
0
 @Override
 public void changeXmlFile(String filename) throws FileNotFoundException {
   File file = new File(filename);
   if (file.exists()) {
     this.modelCompletedCommand = 12;
     @SuppressWarnings("resource")
     XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(filename)));
     p.setDefAlgorithm((String) decoder.readObject());
     p.setDefSolver((String) decoder.readObject());
     p.setNumofThreads((int) decoder.readObject());
     p.setUI((String) decoder.readObject());
     Object[] dataSet = new Object[4];
     dataSet[0] = p.getDefAlgorithm();
     dataSet[1] = p.getDefSolver();
     dataSet[2] = p.getNumofThreads();
     dataSet[3] = p.getUI();
     setChanged();
     this.setData(dataSet);
     notifyObservers();
   } else errorNoticeToController("Xml file Error");
 }
示例#4
0
  /* (non-Javadoc)
   * @see model.Model#solve(java.lang.String)
   */
  @Override
  public void solve(String name) {
    String algorithm = prop.getSolveAlgo();

    String mazeName = name;

    try {
      Socket myServer = new Socket(this.prop.getIp(), this.prop.getPort());
      ObjectOutputStream output = new ObjectOutputStream(myServer.getOutputStream());

      ArrayList<Object> messageToServer = new ArrayList<Object>();
      messageToServer.add("solve");
      messageToServer.add(algorithm);
      messageToServer.add(mazeCollection.get(mazeName));
      output.writeObject(messageToServer);
      output.flush();

      ObjectInputStream input = new ObjectInputStream(myServer.getInputStream());
      Solution messageFromServer = (Solution) input.readObject();

      if (messageFromServer == null) {
        changeAndNotify("notify", "Bad Maze Name (m.solve)");
        output.close();
        input.close();
        myServer.close();
        return;
      }
      solutionCollection.put(mazeCollection.get(mazeName), messageFromServer);

      changeAndNotify("solved", name);

      myServer.getInputStream().close();
      myServer.getOutputStream().close();
      output.close();
      input.close();
      myServer.close();

    } catch (Exception e) {
      changeAndNotify("notify", "Server might be closed");
    }
  }
示例#5
0
 @SuppressWarnings("unchecked")
 public MyModel(Properties p) throws Exception {
   super();
   this.p = p;
   this.c = Executors.newFixedThreadPool(p.getNumofThreads());
   File sol = new File("solutionMap.txt");
   if (sol.exists()) {
     ObjectInputStream solLoader;
     try {
       solLoader =
           new ObjectInputStream(
               new GZIPInputStream(new FileInputStream(new File("solutionMap.txt"))));
       solutionMap = (HashMap<Maze3d, Solution<Position>>) solLoader.readObject();
       solLoader.close();
       this.p = read("Properties.xml");
     } catch (FileNotFoundException e) {
       errorNoticeToController("Error: problem with solution file");
     } catch (IOException e) {
       errorNoticeToController("Error: IO exeption");
     } catch (ClassNotFoundException e) {
       errorNoticeToController("Error: problem with class");
     }
   }
 }
示例#6
0
 public ObservableGUIView(Properties properties) {
   super(properties.getWindowTitle(), properties.getWindowWidth(), properties.getWindowHeight());
   setProp(properties);
 }
 /**
  * This method is used to set the properties
  *
  * @param p
  */
 public void setProperties(Properties p) {
   this.properties = p;
   ExecutorService thread = threadPool;
   threadPool = Executors.newFixedThreadPool(properties.getNumOfThread());
   thread.shutdown();
 }