コード例 #1
0
  public void saveScriptToFile(
      String code, String filename, Component parent, PropertyPanelController cont) {

    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setDialogTitle("Save to file");
    String currentDirectory = new File(".").getAbsolutePath();

    fileChooser.setSelectedFile(new File(currentDirectory, filename));
    fileChooser.setName(FILE_CHOOSER);

    if (fileChooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
      File file = fileChooser.getSelectedFile();

      try {
        if (file.createNewFile()) {
          OutputStream out = new FileOutputStream(file);
          out.write(code.getBytes());
          out.close();

          cont.fileSaveSuccess(file.getAbsolutePath());
        }
      } catch (IOException e) {
        Log.error(e.getMessage(), e);

        cont.fileSaveError(file.getAbsolutePath());
      }
    }
  }
コード例 #2
0
  public void actionPerformed(ActionEvent e) {

    // Handle open button action.
    if (e.getSource() == openButton) {
      int returnVal = fc.showOpenDialog(FileChooserDemo.this);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would open the file.
        log.append("Opening: " + file.getName() + "." + newline);
      } else {
        log.append("Open command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());

      // Handle save button action.
    } else if (e.getSource() == saveButton) {
      int returnVal = fc.showSaveDialog(FileChooserDemo.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would save the file.
        log.append("Saving: " + file.getName() + "." + newline);
      } else {
        log.append("Save command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());
    }
  }
コード例 #3
0
ファイル: IdeMain.java プロジェクト: aimozg/ja-dcpu
 private void saveBin() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(binFilter);
   fileChooser.setFileFilter(binFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == binFilter && !binFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + binFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       FileOutputStream output = new FileOutputStream(file);
       for (char i : binary) {
         output.write(i & 0xff);
         output.write((i >> 8) & 0xff);
       }
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
コード例 #4
0
ファイル: Decipher.java プロジェクト: johnperry/MIRC1
 /**
  * The ActionListener implementation
  *
  * @param event the event.
  */
 public void actionPerformed(ActionEvent event) {
   String searchText = textField.getText().trim();
   if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) {
     textPane.setText("Blank search text is not allowed for large IdTables.");
   } else {
     File outputFile = null;
     if (saveAs.isSelected()) {
       outputFile = chooser.getSelectedFile();
       if (outputFile != null) {
         String name = outputFile.getName();
         int k = name.lastIndexOf(".");
         if (k != -1) name = name.substring(0, k);
         name += ".txt";
         File parent = outputFile.getAbsoluteFile().getParentFile();
         outputFile = new File(parent, name);
         chooser.setSelectedFile(outputFile);
       }
       if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0);
       outputFile = chooser.getSelectedFile();
     }
     textPane.setText("");
     Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile);
     searcher.start();
   }
 }
コード例 #5
0
ファイル: ScreenShotTest.java プロジェクト: okeeper/jietu
  // 保存图像到文件
  public void saveImage() throws IOException {
    JFileChooser jfc = new JFileChooser();
    jfc.setDialogTitle("保存");

    // 文件过滤器,用户过滤可选择文件
    FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG", "jpg");
    jfc.setFileFilter(filter);

    // 初始化一个默认文件(此文件会生成到桌面上)
    SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddHHmmss");
    String fileName = sdf.format(new Date());
    File filePath = FileSystemView.getFileSystemView().getHomeDirectory();
    File defaultFile = new File(filePath + File.separator + fileName + ".jpg");
    jfc.setSelectedFile(defaultFile);

    int flag = jfc.showSaveDialog(this);
    if (flag == JFileChooser.APPROVE_OPTION) {
      File file = jfc.getSelectedFile();
      String path = file.getPath();
      // 检查文件后缀,放置用户忘记输入后缀或者输入不正确的后缀
      if (!(path.endsWith(".jpg") || path.endsWith(".JPG"))) {
        path += ".jpg";
      }
      // 写入文件
      ImageIO.write(saveImage, "jpg", new File(path));
      System.exit(0);
    }
  }
コード例 #6
0
ファイル: InterpreterFrame.java プロジェクト: DavePearce/jkit
  private boolean checkForSave() {
    // build warning message
    String message;
    if (file == null) {
      message = "File has been modified.  Save changes?";
    } else {
      message = "File \"" + file.getName() + "\" has been modified.  Save changes?";
    }

    // show confirm dialog
    int r =
        JOptionPane.showConfirmDialog(
            this,
            new JLabel(message),
            "Warning!",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.WARNING_MESSAGE);

    if (r == JOptionPane.YES_OPTION) {
      // Save File
      if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        // write the file
        physWriteTextFile(fileChooser.getSelectedFile(), textView.getText());
      } else {
        // user cancelled save after all
        return false;
      }
    }
    return r != JOptionPane.CANCEL_OPTION;
  }
コード例 #7
0
  /**
   * Actions-handling method.
   *
   * @param e The event.
   */
  public void actionPerformed(ActionEvent e) {
    // Prepares the file chooser
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(idata.getInstallPath()));
    fc.setMultiSelectionEnabled(false);
    fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
    // fc.setCurrentDirectory(new File("."));

    // Shows it
    try {
      if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        // We handle the xml data writing
        File file = fc.getSelectedFile();
        FileOutputStream out = new FileOutputStream(file);
        BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120);
        parent.writeXMLTree(idata.xmlData, outBuff);
        outBuff.flush();
        outBuff.close();

        autoButton.setEnabled(false);
      }
    } catch (Exception err) {
      err.printStackTrace();
      JOptionPane.showMessageDialog(
          this,
          err.toString(),
          parent.langpack.getString("installer.error"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #8
0
ファイル: IdeMain.java プロジェクト: aimozg/ja-dcpu
 private void saveSrc() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(asmFilter);
   fileChooser.setFileFilter(asmFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == asmFilter && !asmFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + asmFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       PrintStream output = new PrintStream(file);
       output.print(sourceTextarea.getText());
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
コード例 #9
0
ファイル: WordListScreen.java プロジェクト: blueocci/codes
 public void saveAs(ActionEvent e) {
   int returnVal = fc.showSaveDialog(this);
   if (returnVal != JFileChooser.APPROVE_OPTION) {
     return;
   }
   file = fc.getSelectedFile();
   save(e);
 }
コード例 #10
0
    public void actionPerformed(ActionEvent a) {
      QuizCard card = new QuizCard(question.getText(), answer.getText());
      cardList.add(card);
      clearCard();

      JFileChooser fileSave = new JFileChooser();
      fileSave.showSaveDialog(frame);
      saveFile(fileSave.getSelectedFile());
    }
コード例 #11
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
 private void saveAs() {
   if (saveFC == null) {
     saveFC = new SaveDataFileChooser();
   }
   int ret = saveFC.showSaveDialog(this);
   if (ret == JFileChooser.APPROVE_OPTION) {
     saveDataToFile(saveFC.getSelectedFile());
   }
 }
コード例 #12
0
ファイル: CopyWindow.java プロジェクト: schneehund/synchros
  public Path dateiAuswählen(Path neuesLaufwerk) {
    JFileChooser fc1 = new JFileChooser();
    fc1.setDialogTitle("SyncOrdner auswählen");
    fc1.setCurrentDirectory(neuesLaufwerk.toFile());
    fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
      return fc1.getSelectedFile().toPath();
    else return null;
  }
コード例 #13
0
ファイル: Game.java プロジェクト: Genki91/collapsing-puzzle
  /*
   * Present the user with a file chooser dialog to select a file for
   * output. The title of the dialog box is determined by the ``caption''
   * argument.
   */
  public File getOutputFile(String caption) {

    JFileChooser outputdialog = new JFileChooser();
    outputdialog.setDialogTitle(caption);
    int openReturnVal = outputdialog.showSaveDialog(null);
    if (openReturnVal == JFileChooser.APPROVE_OPTION) {
      return outputdialog.getSelectedFile();
    } else {
      return null;
    }
  }
コード例 #14
0
 private void buttonActionPerformed(ActionEvent evt) {
   if (mode == MODE_OPEN) {
     if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
       textField.setText(fileChooser.getSelectedFile().getAbsolutePath());
     }
   } else if (mode == MODE_SAVE) {
     if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
       textField.setText(fileChooser.getSelectedFile().getAbsolutePath());
     }
   }
 }
コード例 #15
0
 public void save() {
   if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = chooser.getSelectedFile();
       XMLEncoder encoder = new XMLEncoder(new FileOutputStream(file));
       encoder.writeObject(frame);
       encoder.close();
     } catch (IOException e) {
       JOptionPane.showMessageDialog(null, e);
     }
   }
 }
コード例 #16
0
ファイル: OpenFileDir.java プロジェクト: NCIP/dwd
  /**
   * Use a JFileChooser in Save mode to select files to open. Use a filter for FileFilter subclass
   * to select for "*.java" files. If a file is selected, then this file will be used as final
   * output
   */
  boolean saveFile() {
    File file = null;
    JFileChooser fc = new JFileChooser();

    // Start in current directory
    fc.setCurrentDirectory(new File("."));

    // Set filter for Java source files.
    fc.setFileFilter(fJavaFilter);

    // Set to a default name for save.
    fc.setSelectedFile(fFile);

    // Open chooser dialog
    int result = fc.showSaveDialog(this);

    if (result == JFileChooser.CANCEL_OPTION) {
      return true;
    } else if (result == JFileChooser.APPROVE_OPTION) {
      fFile = fc.getSelectedFile();
      String textFile = fFile.toString();
      if (fileNo.equalsIgnoreCase("SAVE")) {
        UpLoadFile.outputfile.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("SAVE2")) {
        UpLoadMAGEMLFile.outputfile1.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("SAVE3")) {
        UpLoadMAGEMLFile.outputfile2.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("SAVEJPAG")) {
        JPEGFileName = textFile;
        // System.out.println ("JPG filename OpenFileDir= " +JPEGFileName);
        File fFile = new File(JPEGFileName);
        if (fFile.exists()) {
          int response =
              JOptionPane.showConfirmDialog(
                  null,
                  "Overwrite existing file " + JPEGFileName + " ??",
                  "Confirm Overwrite",
                  JOptionPane.OK_CANCEL_OPTION,
                  JOptionPane.QUESTION_MESSAGE);
          if (response == JOptionPane.CANCEL_OPTION) {
            /* go back to reload the file*/
            return false;
          }
        }
        SetUpPlotWindow.saveComponentAsJPEG(SetUpPlotWindow.content, JPEGFileName);
      }
      return true;

    } else {
      return false;
    }
  } // saveFile
コード例 #17
0
ファイル: TabView.java プロジェクト: linvald/JarFileAnalyser
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();
    if (o instanceof JMenuItem) {
      JMenuItem sender = (JMenuItem) o;
      String name = sender.getText();
      if (name.equals("close")) {
        tabbedPane.removeTabAt(tabbedPane.getSelectedIndex());
      } else if (name.equals("save")) {
        int index = tabbedPane.getSelectedIndex();
        Component c = tabbedPane.getComponent(index);
        Point p = c.getLocation();
        Component t = tabbedPane.getComponentAt(new Point(p.x + 20, p.y + 30));
        if (t instanceof TextView) {
          TextView text = (TextView) t;
          // String code = text.getText();
          // save the code
          // saveTab(code);
        }
        if (t instanceof HTMLTextView) {
          HTMLTextView text = (HTMLTextView) t;
          fileChooser.setSelectedFile(new File(text.node.getName()));
          int returnVal = fileChooser.showSaveDialog(this);

          if (returnVal == JFileChooser.APPROVE_OPTION) {
            File f = fileChooser.getSelectedFile();

            // save the code
            String fileType =
                f.getName().substring(f.getName().lastIndexOf("."), f.getName().length());
            if (fileType.indexOf("htm") != -1) {
              // save as html
              String code = text.getText();
              saveTab(code, f);
            } else if (fileType.indexOf("java") != -1) {
              // save as java
              String code = text.getUnModyfiedContent();
              saveTab(code, f);
            } else if (text.node.fileType.indexOf(FileTypes.MANIFEST) != -1
                || text.node.fileType.indexOf(FileTypes.MANIFEST2) != -1) {
              String code = text.getUnModyfiedContent();
              saveTab(code, f);
              System.out.println("Saved manifest");
            } else {
              System.out.println("FILETYPE UNKNOWN:" + text.node.fileType);
            }
          }
        }
      } else if (name.equals("close all")) {
        tabbedPane.removeAll();
      }
    }
  }
コード例 #18
0
 protected void fileSaveXML() {
   JFileChooser chooser = null;
   if (currentFile == null) {
     chooser = new JFileChooser(startDirectory);
   } else {
     chooser = new JFileChooser(currentFile);
   }
   int returnVal = chooser.showSaveDialog(gw);
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     currentFile = chooser.getSelectedFile();
     generalXML.saveGraph(currentFile);
   }
 }
コード例 #19
0
 @SuppressWarnings("unchecked")
 private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) {
   toggle(false);
   JFileChooser fc = new JFileChooser();
   String path =
       FileUtils.getUserDirectoryPath() + File.separator + treeViewNode.getText() + ".csv";
   fc.setSelectedFile(new File(path));
   fc.showSaveDialog(this);
   File target = fc.getSelectedFile();
   int row = model.getRowCount();
   try {
     boolean written;
     try (FileOutputStream fos = new FileOutputStream(target)) {
       while (--row > -1) {
         Vector v = (Vector) model.getDataVector().get(row);
         for (int i = 0; i < v.size(); i++) {
           if (v.get(i).toString().contains(",")) {
             v.set(i, ST.format("\"<%1>\"", v.get(i)));
           }
         }
         String line = ST.format("<%1:{ x |, <x>}>", v).substring(2);
         fos.write(line.getBytes(CHARSET));
         fos.write(Character.LINE_SEPARATOR);
       }
       written = true;
     }
     if (written) {
       LogEmitter.factory
           .get()
           .emit(
               this,
               Core.ALERT.INFO,
               ST.format("<%1> hosts written to <%2>", model.getRowCount(), target.getPath()));
     } else {
       LogEmitter.factory
           .get()
           .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
     }
   } catch (FileNotFoundException ex) {
     Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex);
     LogEmitter.factory
         .get()
         .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
   } catch (IOException ex) {
     Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex);
     LogEmitter.factory
         .get()
         .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
   }
   toggle(true);
 }
コード例 #20
0
 public void actionPerformed(ActionEvent e) {
   int x = jfc.showSaveDialog(null);
   // int x=jfc.showOpenDialog(null);
   if (x == JFileChooser.APPROVE_OPTION) {
     File f = jfc.getSelectedFile();
     System.out.println(f.getPath());
     System.out.println(jfc.getName(f));
     File f1 = jfc.getCurrentDirectory();
     System.out.println(jfc.getName(f1));
   }
   if (x == JFileChooser.CANCEL_OPTION) {
     System.out.println("cancle");
   }
 }
コード例 #21
0
ファイル: Notepad.java プロジェクト: ArcherSys/ArcherSysRuby
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showSaveDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      frame.setTitle(f.getName());
      Thread saver = new FileSaver(f, editor.getDocument());
      saver.start();
    }
コード例 #22
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == save) {
     JFileChooser c = new JFileChooser(ResourceFactory.getRootDir());
     c.setDialogTitle("Save result");
     if (c.showSaveDialog(resultFrame) == JFileChooser.APPROVE_OPTION) {
       File output = c.getSelectedFile();
       if (output.exists()) {
         String[] options = {"Overwrite", "Cancel"};
         if (JOptionPane.showOptionDialog(
                 resultFrame,
                 output + "exists. Overwrite?",
                 "Save result",
                 JOptionPane.YES_NO_OPTION,
                 JOptionPane.WARNING_MESSAGE,
                 null,
                 options,
                 options[0])
             == 1) return;
       }
       try {
         PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter(output)));
         w.println("Searched for unused strings");
         w.println("Number of hits: " + table.getRowCount());
         w.println("");
         for (int i = 0; i < table.getRowCount(); i++) {
           w.println(
               "StringRef: "
                   + table.getTableItemAt(i).getObjectAt(1)
                   + " /* "
                   + table
                       .getTableItemAt(i)
                       .toString()
                       .replaceAll("\r\n", System.getProperty("line.separator"))
                   + " */");
         }
         w.close();
         JOptionPane.showMessageDialog(
             resultFrame,
             "Result saved to " + output,
             "Save complete",
             JOptionPane.INFORMATION_MESSAGE);
       } catch (IOException ex) {
         JOptionPane.showMessageDialog(
             resultFrame, "Error while saving " + output, "Error", JOptionPane.ERROR_MESSAGE);
         ex.printStackTrace();
       }
     }
   }
 }
コード例 #23
0
  /** Shows a file dialog and saves drawing. */
  public void promptSaveAs() {
    toolDone();
    JFileChooser saveDialog = createSaveFileChooser();
    getStorageFormatManager().registerFileFilters(saveDialog);

    if (saveDialog.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
      StorageFormat foundFormat =
          getStorageFormatManager().findStorageFormat(saveDialog.getFileFilter());
      if (foundFormat != null) {
        saveDrawing(foundFormat, saveDialog.getSelectedFile().getAbsolutePath());
      } else {
        showStatus("Not a valid file format: " + saveDialog.getFileFilter().getDescription());
      }
    }
  }
コード例 #24
0
 // Get the name of the file
 private File getFileName(int option) {
   JFileChooser fc = new JFileChooser(new File(".."));
   if (oldFile != null) fc.setSelectedFile(oldFile);
   int returnVal = 0;
   if (option == UintahGui.OPEN) {
     returnVal = fc.showOpenDialog(UintahGui.this);
   } else {
     returnVal = fc.showSaveDialog(UintahGui.this);
   }
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     File file = fc.getSelectedFile();
     oldFile = file;
     return file;
   } else return null;
 }
コード例 #25
0
ファイル: InterpreterFrame.java プロジェクト: DavePearce/jkit
 public void saveFileAs() {
   // Force user to enter new file name
   if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
     file = fileChooser.getSelectedFile();
   } else {
     // user cancelled save after all
     return;
   }
   // file selected, so write it.
   physWriteTextFile(file, textView.getText());
   // update status
   statusView.setText(" Saved file \"" + file.getName() + "\".");
   // reset dirty bit
   dirty = false;
 }
コード例 #26
0
 protected void fileSaveSimple() {
   JFileChooser chooser = null;
   if (currentFile == null) {
     chooser = new JFileChooser(startDirectory);
   } else {
     chooser = new JFileChooser(currentFile);
     if (!currentFile.isDirectory()) {
       chooser.setSelectedFile(currentFile);
     }
   }
   int returnVal = chooser.showSaveDialog(gw);
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     currentFile = chooser.getSelectedFile();
     graph.saveSimple(currentFile);
   }
 }
コード例 #27
0
  /** Show the save dialog to save the network file. */
  private void saveEvent() {
    JFileChooser fileSaver = new JFileChooser(inpFile.getParent());
    fileSaver.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileSaver.setAcceptAllFileFilterUsed(false);
    fileSaver.addChoosableFileFilter(new XLSXFilter());
    fileSaver.addChoosableFileFilter(new XMLFilter());
    fileSaver.addChoosableFileFilter(new INPFilter());

    fileSaver.showSaveDialog(frame);

    if (fileSaver.getSelectedFile() == null) return;

    Network.FileType netType = Network.FileType.INP_FILE;

    if (fileSaver.getFileFilter() instanceof XLSXFilter) {
      netType = Network.FileType.EXCEL_FILE;
    } else if (fileSaver.getFileFilter() instanceof XMLFilter) {
      netType = Network.FileType.XML_FILE;
      JOptionPane.showMessageDialog(frame, "Not supported yet !", "Error", JOptionPane.OK_OPTION);
      return;
    }

    OutputComposer compose = OutputComposer.create(netType);

    String extension = "";

    if (Utilities.getFileExtension(fileSaver.getSelectedFile().getName()).equals(""))
      switch (netType) {
        case INP_FILE:
          extension = ".inp";
          break;
        case EXCEL_FILE:
          extension = ".xlsx";
          break;
        case XML_FILE:
          extension = ".xml";
          break;
      }

    try {
      compose.composer(
          epanetNetwork, new File(fileSaver.getSelectedFile().getAbsolutePath() + extension));
    } catch (ENException e1) {
      e1.printStackTrace();
    }
  }
コード例 #28
0
ファイル: ImageLabFrame.java プロジェクト: per-ola/db2004
  public void actionPerformed(ActionEvent e) {
    String cmd = (e.getActionCommand());

    if (cmd.equals(aboutItem.getText()))
      JOptionPane.showMessageDialog(
          this,
          "Simple Image Program for DB2004\nversion 0.1\nThanks to BvS",
          "About imageLab",
          JOptionPane.INFORMATION_MESSAGE);
    else if (cmd.equals(quitItem.getText())) System.exit(0);
    else if (cmd.equals(openItem.getText())) {
      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2 = new Picture(chooser.getSelectedFile().getName());
          pic1 = new Picture(pic2.width(), pic2.height());
          lab.setIcon(pic2.getJLabel().getIcon());
          sliderPanel.setVisible(false);
          pack();
          repaint();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not open " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Open Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }

    } else if (cmd.equals(saveItem.getText())) {
      int returnVal = chooser.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2.save(chooser.getSelectedFile().getName());
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not write " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Save Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }
    }
  }
コード例 #29
0
  private void jMenuItemSaveLSAResultsActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemSaveLSAResultsActionPerformed
    if (this.currentResults != null) {
      JFileChooser jfc = new JFileChooser();
      int fileDialogReturnVal = jfc.showSaveDialog(this);

      if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) {
        try {
          File outputFile = jfc.getSelectedFile();
          FileOutputStream fos = new FileOutputStream(outputFile);
          ObjectOutputStream oos = new ObjectOutputStream(fos);

          oos.writeObject(this.currentResults);
        } catch (IOException e) {
          System.out.println("IOexception");
          System.out.println(e.getMessage());
        }
      }
    }
  } // GEN-LAST:event_jMenuItemSaveLSAResultsActionPerformed
コード例 #30
0
  /**
   * @todo this is reduced code from the image export in the ToscanaJMainPanel. Extract the full
   *     code into a new object, and use it here.
   */
  protected void exportImages() {
    disableStepControls();

    final JFileChooser saveDialog = new JFileChooser(this.lastImageExportFile);
    boolean formatDefined;
    do {
      formatDefined = true;
      final int rv = saveDialog.showSaveDialog(this);
      if (rv == JFileChooser.APPROVE_OPTION) {
        final File selectedFile = saveDialog.getSelectedFile();
        final GraphicFormat format = GraphicFormatRegistry.getTypeByExtension(selectedFile);
        if (format != null) {
          this.diagramExportSettings.setGraphicFormat(format);
        } else {
          if (selectedFile.getName().indexOf('.') != -1) {
            JOptionPane.showMessageDialog(
                this,
                "Sorry, no type with this extension known.\n"
                    + "Please use either another extension or try\n"
                    + "manual settings.",
                "Export failed",
                JOptionPane.ERROR_MESSAGE);
          } else {
            JOptionPane.showMessageDialog(
                this,
                "No extension given.\n"
                    + "Please give an extension or pick a file type\n"
                    + "from the options.",
                "Export failed",
                JOptionPane.ERROR_MESSAGE);
          }
          formatDefined = false;
        }

        if (formatDefined) {
          exportImages(selectedFile);
        }
      }
    } while (!formatDefined);
  }