Esempio n. 1
0
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand() == "Open") { // open버튼을 눌렀다면
     fdOpen.setVisible(true);
     System.out.println(fdOpen.getDirectory() + fdOpen.getFile());
   } else { // save버튼을 눌렀다면
     fdSave.setVisible(true);
     System.out.println(fdSave.getDirectory() + fdSave.getFile());
   }
 }
Esempio n. 2
0
 public void loadROM() {
   FileDialog fileDialog = new FileDialog(this);
   fileDialog.setMode(FileDialog.LOAD);
   fileDialog.setTitle("Select a ROM to load");
   // should open last folder used, and if that doesn't exist, the folder it's running in
   final String path = PrefsSingleton.get().get("filePath", System.getProperty("user.dir", ""));
   final File startDirectory = new File(path);
   if (startDirectory.isDirectory()) {
     fileDialog.setDirectory(path);
   }
   // and if the last path used doesn't exist don't set the directory at all
   // and hopefully the jFileChooser will open somewhere usable
   // on Windows it does - on Mac probably not.
   fileDialog.setFilenameFilter(new NESFileFilter());
   boolean wasInFullScreen = false;
   if (inFullScreen) {
     wasInFullScreen = true;
     // load dialog won't show if we are in full screen, so this fixes for now.
     toggleFullScreen();
   }
   fileDialog.setVisible(true);
   if (fileDialog.getFile() != null) {
     PrefsSingleton.get().put("filePath", fileDialog.getDirectory());
     loadROM(fileDialog.getDirectory() + fileDialog.getFile());
   }
   if (wasInFullScreen) {
     toggleFullScreen();
   }
 }
Esempio n. 3
0
 /** This method cannot be called directly. */
 public void actionPerformed(ActionEvent e) {
   FileDialog chooser =
       new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
   chooser.setVisible(true);
   String filename = chooser.getFile();
   if (filename != null) {
     StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
   }
 }
  public static void main(String args[]) {
    Frame f = new SampleFrame("File Dialog Demo");
    f.setVisible(true);
    f.setSize(200, 200);

    FileDialog fd = new FileDialog(f, "File Dialog");

    fd.setVisible(true);
  }
Esempio n. 5
0
  protected boolean browseFile() {
    File currentFile = new File(fnameField.getText());

    FileDialog fd = new FileDialog(this, "Save next session as...", FileDialog.SAVE);
    fd.setDirectory(currentFile.getParent());
    fd.setVisible(true);
    if (fd.getFile() != null) {
      String newDir = fd.getDirectory();
      String sep = System.getProperty("file.separator");
      if (newDir.length() > 0) {
        if (!sep.equals(newDir.substring(newDir.length() - sep.length()))) newDir += sep;
      }
      String newFname = newDir + fd.getFile();
      if (newFname.equals(fnameField.getText())) {
        fnameField.setText(newFname);
        return true;
      }
    }
    return false;
  }
Esempio n. 6
0
  public getPicInfo(Frame father) {
    try {
      FileDialog diag = new FileDialog(father);
      diag.setVisible(true);
      m_Img =
          getToolkit()
              .getImage(diag.getDirectory() + diag.getFile())
              .getScaledInstance(W, H, Image.SCALE_SMOOTH);
      MediaTracker mt = new MediaTracker(this);
      mt.addImage(m_Img, 0);
      mt.waitForAll();
      PixelGrabber grab = new PixelGrabber(m_Img, 0, 0, W, H, m_Pix, 0, W);
      grab.grabPixels();
      m_ImgSrc = new MemoryImageSource(W, H, m_Pix, 0, W);
      m_Img = createImage(m_ImgSrc);
      System.out.println("Wait HERE !");
    } catch (InterruptedException e) {

    }
  }
Esempio n. 7
0
  public dbfShow(String title, String fname) throws Exception {

    super(title);
    String dbname;
    addWindowListener(this);
    sp = new ScrollPane();
    viewPane = new Panel();
    sp.add(viewPane);
    this.add(sp);

    if (fname == null || fname.length() == 0) {
      FileDialog fd = new FileDialog(this, "dbfShow", FileDialog.LOAD);
      fd.setFile("*.DBF");
      fd.pack();
      fd.setVisible(true);
      String DBFname = fd.getFile();
      String dirname = fd.getDirectory();

      if (DBFname == null) {
        System.exit(0);
      }
      if (DBFname.length() < 1) {
        System.exit(0);
      }
      dbname = new String(dirname + DBFname);
    } else {
      dbname = new String(fname);
    }

    MenuBar mb = new MenuBar();
    this.setMenuBar(mb);
    Menu file = new Menu("File");
    opener = new MenuItem("Open..");
    file.add(opener);
    opener.addActionListener(this);
    packer = new MenuItem("Pack");
    packer.addActionListener(this);
    file.add(packer);
    quiter = new MenuItem("Quit");
    file.add(quiter);
    quiter.addActionListener(this);
    mb.add(file);
    Menu record = new Menu("Record");
    firstRecord = new MenuItem("First");
    firstRecord.addActionListener(this);
    record.add(firstRecord);
    nextRecord = new MenuItem("Next");
    nextRecord.addActionListener(this);
    record.add(nextRecord);
    prevRecord = new MenuItem("Prev");
    prevRecord.addActionListener(this);
    record.add(prevRecord);
    lastRecord = new MenuItem("Last");
    lastRecord.addActionListener(this);
    record.add(lastRecord);
    addRecord = new MenuItem("Add");
    addRecord.addActionListener(this);
    record.add(addRecord);
    updateRecord = new MenuItem("Update");
    updateRecord.addActionListener(this);
    record.add(updateRecord);
    clearRecord = new MenuItem("Clear");
    clearRecord.addActionListener(this);
    record.add(clearRecord);
    mb.add(record);
    crl = new Label("Record", Label.RIGHT);
    trl = new Label(" of ", Label.LEFT);
    SBrecpos = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 0, 0);
    SBrecpos.addAdjustmentListener(this);
    delCB = new Checkbox("Deleted");
    delCB.addItemListener(this);
    Prev = new Button("<<Prev");
    Prev.addActionListener(this);
    Next = new Button("Next>>");
    Next.addActionListener(this);
    Add = new Button("Add");
    Add.addActionListener(this);
    Update = new Button("Update");
    Update.addActionListener(this);
    Clear = new Button("Clear");
    Clear.addActionListener(this);
    setupDBFields(dbname);
    setTitle(dbname + ",   org.xBaseJ Version:" + org.xBaseJ.DBF.xBaseJVersion);
    pack();
    setVisible(true);
  }
Esempio n. 8
0
  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == firstRecord) {
      goTo(1);
      return;
    }
    if (event.getSource() == lastRecord) {
      goTo(db.getRecordCount());
      return;
    }
    if (event.getSource() == Next || event.getSource() == nextRecord) {
      if (db.getCurrentRecordNumber() < db.getRecordCount()) {
        goTo(db.getCurrentRecordNumber() + 1);
      }
      return;
    }

    if (event.getSource() == Prev || event.getSource() == prevRecord) {
      if (db.getCurrentRecordNumber() > 1) {
        goTo(db.getCurrentRecordNumber() - 1);
      }
      return;
    }

    if (event.getSource() == Add || event.getSource() == addRecord) {
      addRec();
      return;
    }
    if (event.getSource() == Update || event.getSource() == updateRecord) {
      updateRec();
      return;
    }
    if (event.getSource() == Clear || event.getSource() == clearRecord) {
      clearFields();
      return;
    }

    if (event.getSource() == opener) {
      FileDialog fd = new FileDialog(this, "dbfShow", FileDialog.LOAD);
      fd.setFile("*.DBF");
      fd.pack();
      fd.setVisible(true);
      String DBFname = fd.getFile();
      String dirname = fd.getDirectory();
      if (DBFname == null) {
        return;
      }
      if (DBFname.length() < 1) {
        return;
      }
      String dbname = new String(dirname + DBFname);
      try {
        setupDBFields(dbname);
      } catch (Exception e1) {
        System.out.println(e1);
        System.exit(4);
      }
      pack();
      setVisible(true);
      return;
    }

    if (event.getSource() == packer) {
      packer.setEnabled(false);
      try {
        db.pack();
        trl.setText(" of " + db.getRecordCount());
      } catch (Exception e1) {
        e1.printStackTrace();
      }
      if (db.getRecordCount() == 0) {
        Update.setEnabled(false);
        Next.setEnabled(false);
        updateRecord.setEnabled(false);
        nextRecord.setEnabled(false);
        SBrecpos.setValues(0, 1, 0, 0);
      } else {
        goTo(1);
      }
      packer.setEnabled(true);
      return;
    }

    if (event.getSource() == quiter) {
      System.exit(0);
      return;
    }

    if (event.getSource() instanceof Button) {
      int i;
      Field f;
      for (i = 1; i <= db.getFieldCount(); i++) {
        try {
          f = db.getField(i);
          if (f.isMemoField()) {
            if (event.getActionCommand().equals(f.getName())) {
              md = new memoDialog(this, f);
              md.setVisible(true);
              return;
            }
          }
        } catch (Exception e1) {
          System.out.println(e1);
        }
      }
    }
  }
  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");
    }
  }
Esempio n. 10
0
  paintboard1(String s) {
    super(s);
    addMouseMotionListener(this);
    addMouseListener(this);

    paintInfo = new Vector();

    /* 各工具按钮及选择项 */
    // 颜色选择
    ColChoice = new Choice();
    ColChoice.add("black");
    ColChoice.add("red");
    ColChoice.add("blue");
    ColChoice.add("green");
    ColChoice.addItemListener(this);
    // 画笔大小选择
    SizeChoice = new Choice();
    SizeChoice.add("1");
    SizeChoice.add("3");
    SizeChoice.add("5");
    SizeChoice.add("7");
    SizeChoice.add("9");
    SizeChoice.addItemListener(this);
    // 橡皮大小选择
    EraserChoice = new Choice();
    EraserChoice.add("5");
    EraserChoice.add("9");
    EraserChoice.add("13");
    EraserChoice.add("17");
    EraserChoice.addItemListener(this);
    // //////////////////////////////////////////////////
    toolPanel = new Panel();

    clear = new Button("清除");
    eraser = new Button("橡皮");
    pen = new Button("画笔");
    drLine = new Button("画直线");
    drCircle = new Button("画圆形");
    drRect = new Button("画矩形");

    openPic = new Button("打开图画");
    savePic = new Button("保存图画");

    colchooser = new Button("显示调色板");

    // 各组件事件监听
    clear.addActionListener(this);
    eraser.addActionListener(this);
    pen.addActionListener(this);
    drLine.addActionListener(this);
    drCircle.addActionListener(this);
    drRect.addActionListener(this);
    openPic.addActionListener(this);
    savePic.addActionListener(this);
    colchooser.addActionListener(this);

    颜色 = new Label("画笔颜色", Label.CENTER);
    大小B = new Label("画笔大小", Label.CENTER);
    大小E = new Label("橡皮大小", Label.CENTER);
    // 面板添加组件
    toolPanel.add(openPic);
    toolPanel.add(savePic);

    toolPanel.add(pen);
    toolPanel.add(drLine);
    toolPanel.add(drCircle);
    toolPanel.add(drRect);

    toolPanel.add(颜色);
    toolPanel.add(ColChoice);
    toolPanel.add(大小B);
    toolPanel.add(SizeChoice);
    toolPanel.add(colchooser);

    toolPanel.add(eraser);
    toolPanel.add(大小E);
    toolPanel.add(EraserChoice);

    toolPanel.add(clear);
    // 工具面板到APPLET面板
    add(toolPanel, BorderLayout.NORTH);

    setBounds(230, 50, 900, 650);
    setVisible(true);
    validate();
    // dialog for save and load

    openPicture = new FileDialog(this, "打开图画", FileDialog.LOAD);
    openPicture.setVisible(false);
    savePicture = new FileDialog(this, "保存图画", FileDialog.SAVE);
    savePicture.setVisible(false);

    openPicture.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            openPicture.setVisible(false);
          }
        });

    savePicture.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            savePicture.setVisible(false);
          }
        });

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
Esempio n. 11
0
  public void actionPerformed(ActionEvent e) {
    System.out.println("actionPerformed");
    if (e.getSource() == pen) // 画笔
    {
      System.out.println("pen");
      toolFlag = 0;
    }

    if (e.getSource() == eraser) // 橡皮
    {
      System.out.println("eraser");
      toolFlag = 1;
    }

    if (e.getSource() == clear) // 清除
    {
      System.out.println("clear");
      toolFlag = 2;
      paintInfo.removeAllElements();
      repaint();
    }

    if (e.getSource() == drLine) // 画线
    {
      System.out.println("drLine");
      toolFlag = 3;
    }

    if (e.getSource() == drCircle) // 画圆
    {
      System.out.println("drCircle");
      toolFlag = 4;
    }

    if (e.getSource() == drRect) // 画矩形
    {
      System.out.println("drRect");
      toolFlag = 5;
    }

    if (e.getSource() == colchooser) // 调色板
    {
      System.out.println("colchooser");
      Color newColor = JColorChooser.showDialog(this, "我的调色板", c);
      c = newColor;
    }

    if (e.getSource() == openPic) // 打开图画
    {

      openPicture.setVisible(true);

      if (openPicture.getFile() != null) {
        int tempflag;
        tempflag = toolFlag;
        toolFlag = 2;
        repaint();

        try {
          paintInfo.removeAllElements();
          File filein = new File(openPicture.getDirectory(), openPicture.getFile());
          picIn = new FileInputStream(filein);
          VIn = new ObjectInputStream(picIn);
          paintInfo = (Vector) VIn.readObject();
          VIn.close();
          repaint();
          toolFlag = tempflag;

        } catch (ClassNotFoundException IOe2) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read object");
        } catch (IOException IOe) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read file");
        }
      }
    }

    if (e.getSource() == savePic) // 保存图画
    {
      savePicture.setVisible(true);
      try {
        File fileout = new File(savePicture.getDirectory(), savePicture.getFile());
        picOut = new FileOutputStream(fileout);
        VOut = new ObjectOutputStream(picOut);
        VOut.writeObject(paintInfo);
        VOut.close();
      } catch (IOException IOe) {
        System.out.println("can not write object");
      }
    }
  }
  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");
    }
  }