Beispiel #1
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);
             }
         }
     }
 }
  public GridPanel(Client client, Snapshot snapshot) {
    setDoubleBuffered(true);
    setOpaque(false);
    setLayout(null);

    this.client = client;
    this.controlPanel = client.getControlPanel();

    squareSize = INITIAL_SQUARE_SIZE;
    left = 0 - STARTING_GRID_SIZE / 2;
    right = 0 + STARTING_GRID_SIZE / 2;
    top = 0 - STARTING_GRID_SIZE / 2;
    bottom = 0 + STARTING_GRID_SIZE / 2;

    if (snapshot != null) {
      NodeList nl = snapshot.getTileElements();
      for (int i = 0; i < nl.getLength(); i++) {
        Element el = (Element) nl.item(i);
        Position pos = XmlUtils.extractPosition(el);
        if (pos.x <= left) left = pos.x - 1;
        if (pos.x >= right) right = pos.x + 1;
        if (pos.y <= top) top = pos.y - 1;
        if (pos.y >= bottom) bottom = pos.y + 1;
      }
    }
    registerMouseListeners();
    controlPanel.registerSwingComponents(this);
  }