コード例 #1
0
  /**
   * Gets the online data to see it obtained previously in RESTAPI.
   *
   * @param doc
   * @return
   */
  public Visual getDataToSee(Document doc) {
    try {
      NodeList movieList = doc.getElementsByTagName("movie");
      Node p = movieList.item(0);
      if (p == null) {
        nodecheck = false;
      }
      if (p.getNodeType() == Node.ELEMENT_NODE) {
        Element movie = (Element) p;

        visual.setTitle(movie.getAttribute("title"));
        visual.setType(movie.getAttribute("type"));
        visual.setDate(movie.getAttribute("year"));
        visual.setLenght(movie.getAttribute("runtime"));
        visual.setGenre(movie.getAttribute("genre"));
        visual.setSynopsis(movie.getAttribute("plot"));
        visual.setLanguage(movie.getAttribute("language"));
        visual.setDirector(movie.getAttribute("director"));
        visual.setActors(movie.getAttribute("actors"));
      }

    } catch (NullPointerException e) {
      System.out.println("Error 404. File Not Found.");
    }

    return visual;
  }
コード例 #2
0
  @Override
  public PointVisual newInstance() {
    PointVisual instance = new PointVisual();
    super.copyFields(instance);

    return instance;
  }
コード例 #3
0
  /**
   * Reads the written data from a specific database and a specific item.
   *
   * @param type
   * @param name
   * @throws IOException
   */
  public Visual readWrittenData(String type, String name) throws IOException {
    String id;
    Document doc = null;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
      DocumentBuilder builder = factory.newDocumentBuilder();

      // Decides from where you want to read.
      if (type.equals("series")) {
        doc = builder.parse("resources/series.xml");
      } else if (type.equals("movies")) {
        doc = builder.parse("resources/movies.xml");
      }

      NodeList personList = doc.getElementsByTagName(name);
      for (int i = 0; i < personList.getLength(); i++) {
        Node p = personList.item(i);
        if (p == null) {
          nodecheck = false;
        }
        if (p.getNodeType() == Node.ELEMENT_NODE) {
          Element movie = (Element) p;
          // Gets the attribute from the specified element.
          visual.setTitle(movie.getAttribute("title"));
          visual.setType(movie.getAttribute("type"));
          visual.setDate(movie.getAttribute("year"));
          visual.setLenght(movie.getAttribute("runtime"));
          visual.setGenre(movie.getAttribute("genre"));
          visual.setSynopsis(movie.getAttribute("plot"));
          visual.setLanguage(movie.getAttribute("language"));
          visual.setDirector(movie.getAttribute("director"));
          visual.setActors(movie.getAttribute("actors"));

          System.out.println("Archivo leido.");
        }
      }

    } catch (Exception ex) {
      System.out.println("Please, write a correct database name.");
      // If the database´s name isn´t correct, the method will launch again.
      readWrittenData(api.lookForType(), api.lookForName());
    }

    return visual;
  }
コード例 #4
0
ファイル: Transformable.java プロジェクト: ericpauley/Alice
 public void setPivot(ReferenceFrame pivot) {
   Matrix44 m = getTransformation(pivot);
   Matrix44 mInverse = Matrix44.invert(m);
   transform(mInverse, this);
   for (int i = 0; i < getChildCount(); i++) {
     Component child = getChildAt(i);
     if (child instanceof Transformable) {
       ((Transformable) child).transform(m, this);
     } else if (child instanceof Visual) {
       ((Visual) child).transform(m);
     }
   }
 }
コード例 #5
0
ファイル: ModelElementVisual.java プロジェクト: kgabriel/Ape
 @Override
 public void readAMLNode(AMLNode node) {
   super.readAMLNode(node);
   this.modelElementId = node.getAttributeInt("id");
 }
コード例 #6
0
  /** Here is the main menu, where the user will interact. */
  public void menu() {

    System.out.println("Insert the option number to execute it:");
    System.out.println("-------------------------");
    System.out.println("1 -Get data online and read it:");
    System.out.println("2 -Get online data and write it into the local database:");
    System.out.println("3 -Look for a specific record in the local database:");
    while (check) {
      getOption();
    }

    switch (str) {
      case "1":
        {
          Visual visual;

          visual = getDataToSee(api.transformXML());
          if (checkNode()) {
            System.out.println(visual.toString());
            System.out.println("-------------------------");
            System.out.println("Want to save it? Y/N :");
            str = sc.next();
            if (str.equals("Y") || str.equals("y")) {
              System.out.println("Info saved.");
              System.out.println("");
              submenu();
            } else if (str.equals("N") || str.equals("n")) {
              submenu();
            }
          } else {
            submenu();
          }
          submenu();
        }

      case "2":
        {
          getDataToSee(api.transformXML());
          if (checkNode()) {
            System.out.println(
                "Received data: Now choose in what database you want it, and the name of the register:");
            getDataToWrite(api.getDocu(), api.enterType(), api.enterName());

            submenu();
          } else {
            submenu();
          }
        }

      case "3":
        {
          Visual visual = null;
          try {

            visual = readWrittenData(api.lookForType(), api.lookForName());
            if (checkNode()) {
              System.out.println(visual.toString());
            } else {
              System.out.println("Sorry, couldn´t find the data.");
            }
          } catch (IOException e) {
            System.out.println("Error. The file that you were trying to read doesn´t exist.");
            submenu();
          }
          submenu();
        }
    }
  }