Beispiel #1
0
  public FlowQuad(String title) {
    super(title);
    JPanel contentPanel = new JPanel(new BorderLayout());

    VectorField field = new VectorField();

    // The interaction control panel is a separate window
    contentPanel.add(field, BorderLayout.CENTER);
    GUIPanel control = new GUIPanel(field);
    control.setLocation(700, 0);
    control.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.add(contentPanel);

    // The initial window size is good for a square vector field with sides
    // that are a power of 2, plus some extra in x and y (8 and 30) that
    // appear to be about right for window pieces outside the draw area.
    this.setSize(new Dimension(768 + 8, 768 + 30));
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //  make both windows visible
    this.setVisible(true);
    control.setVisible(true);
  }
  public void actionPerformed(ActionEvent e) {
    System.out.println("April working");

    // Creates the "Open a File" dialog box

    FileDialog fd = new FileDialog(new Frame(), "Open April hillshade ASCII", FileDialog.LOAD);
    fd.setVisible(true);

    // Creates a new File object from the file that is opened

    File file = new File(fd.getDirectory() + fd.getFile());

    if ((fd.getDirectory() == null) || (fd.getFile() == null)) {
      System.out.println("April hillshade file not uploaded");
      return;
    } else {

      // Creates a GRIDJava object from the opened file

      GRIDJava2 gj = new GRIDJava2(file, true, store);

      // Adds the GRIDJava object to the panel

      panel.addGRIDJavaMethod(gj);

      // Creates a 2D array from the GRIDJava object

      double hillshade_April[][] = gj.getTwoDdoubleArray();

      // Converts hillshade values (0-255) to %

      for (int i = 0; i < hillshade_April.length; i++) {
        for (int j = 0; j < hillshade_April[i].length; j++) {

          if ((hillshade_April[i][j] != -9999) && (hillshade_April[i][j] != 0)) {
            double percentage1 = (hillshade_April[i][j] / 255.0); // half the way.... (* 100)
            double percentage2 = percentage1 * 100.0;
            hillshade_April[i][j] = percentage2;
          } else if (hillshade_April[i][j] == 0) {
            hillshade_April[i][j] = 0;
          } else {
            hillshade_April[i][j] = -9999;
          }
        }
      }

      store.setHillshade_April(hillshade_April);

      // ****************** End of hillshade conversion **********************

      // Creates a 1D array from the GRIDJava object

      int data1d[] = gj.getOneDintArray();

      // Creates an Image object

      Image temp = null;

      // Creates a MemoryImageSource object which uses methods from GRIDJava.java and takes in the
      // 1D array created above

      MemoryImageSource mis =
          new MemoryImageSource(
              gj.getNumberOfColumns(), gj.getNumberOfRows(), data1d, 0, gj.getNumberOfColumns());

      // Using a toolkit, this creates the image and assigns it to the Image object created earlier
      // (previously set to null)

      temp = panel.getToolkit().createImage(mis);

      // Displays the image on the panel

      panel.displayImage(temp);

      System.out.println("April hillshade uploaded");
    }
  }
  public void actionPerformed(ActionEvent e) {

    System.out.println("November 6pm working");

    // Creates the "Open a File" dialog box

    FileDialog fd =
        new FileDialog(new Frame(), "Open November 6pm hillshade ASCII", FileDialog.LOAD);
    fd.setVisible(true);

    // Creates a new File object from the file that is opened

    File file = new File(fd.getDirectory() + fd.getFile());

    // File file = new File("F:\\Model_Test_Files\\59_hillshade.txt");

    if ((fd.getDirectory() == null) || (fd.getFile() == null)) {
      System.out.println("November 6pm hillshade file not uploaded");
      return;
    } else {

      // Creates a GRIDJava object from the opened file

      GRIDJava2 gj = new GRIDJava2(file, true, store);

      // Adds the GRIDJava object to the panel

      panel.addGRIDJavaMethod(gj);

      // Creates a 2D array from the GRIDJava object

      double hillshade_November_6pm[][] = gj.getTwoDdoubleArray();

      store.setHillshade_Nov_6pm(hillshade_November_6pm);

      // ****************** End of hillshade conversion **********************

      // Creates a 1D array from the GRIDJava object

      int data1d[] = gj.getOneDintArray();

      // Creates an Image object

      Image temp = null;

      // Creates a MemoryImageSource object which uses methods from GRIDJava.java and takes in the
      // 1D array created above

      MemoryImageSource mis =
          new MemoryImageSource(
              gj.getNumberOfColumns(), gj.getNumberOfRows(), data1d, 0, gj.getNumberOfColumns());

      // Using a toolkit, this creates the image and assigns it to the Image object created earlier
      // (previously set to null)

      temp = panel.getToolkit().createImage(mis);

      // Displays the image on the panel

      panel.displayImage(temp);

      System.out.println("November 6pm hillshade uploaded");
    }
  }