Ejemplo n.º 1
0
 public void handleLoad() {
     JFileChooser fc = new JFileChooser(System.getProperty("user.dir") + System.getProperty("file.separator") + "saves");
     fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
     fc.setDialogTitle(_("Load game"));
     fc.setDialogType(JFileChooser.OPEN_DIALOG);
     fc.setFileFilter(new SavegameFileFilter());
     fc.setLocale(getLocale());
     int returnVal = fc.showOpenDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
         File file = fc.getSelectedFile();
         if (file != null) {
             if (!closeGame()) return;
             try {
                 localServer = new Server(new Snapshot(file));
                 localServer.start(config.getPort());
                 connect(InetAddress.getLocalHost(), config.getPort());
             } catch (SnapshotVersionException ex1) {
                 //do not create error.log
                 JOptionPane.showMessageDialog(this, ex1.getLocalizedMessage(), _("Error"), JOptionPane.ERROR_MESSAGE);
             } catch (Exception ex) {
                 logger.error(ex.getMessage(), ex);
                 JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), _("Error"), JOptionPane.ERROR_MESSAGE);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void handleSave() {
     JFileChooser fc = new JFileChooser(System.getProperty("user.dir") + System.getProperty("file.separator") + "saves");
     fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
     fc.setDialogTitle(_("Save game"));
     fc.setDialogType(JFileChooser.SAVE_DIALOG);
     fc.setFileFilter(new SavegameFileFilter());
     fc.setLocale(getLocale());
     int returnVal = fc.showSaveDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
         File file = fc.getSelectedFile();
         if (file != null) {
             if (!file.getName().endsWith(".jcz")) {
                 file = new File(file.getAbsolutePath() + ".jcz");
             }
             try {
                 Snapshot snapshot = new Snapshot(game, getClientId());
                 DebugConfig debugConfig = getConfig().getDebug();
                 if (debugConfig != null && "plain".equals(debugConfig.getSave_format())) {
                     snapshot.setGzipOutput(false);
                 }
                 snapshot.save(file);
             } catch (Exception ex) {
                 logger.error(ex.getMessage(), ex);
                 JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), _("Error"), JOptionPane.ERROR_MESSAGE);
             }
         }
     }
 }
Ejemplo n.º 3
0
  private JFCFolderExplorer() {

    mFileChooser = new JFileChooser();
    mFileChooser.setLocale(Locale.ENGLISH);
    try {
      UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
      SwingUtilities.updateComponentTreeUI(mFileChooser);
    } catch (Exception e1) {
      e1.printStackTrace();
    }
    mFileChooser.setMultiSelectionEnabled(false);
    mFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    String strDir = Property.getInstance().getProperty(Property.DEFALT_REPORT_LOCATION);
    File curDir = new File(strDir);

    if (curDir.exists()) mFileChooser.setCurrentDirectory(curDir);
  }