예제 #1
0
  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;
  }
예제 #2
0
    /** handle the action event */
    protected void handleToDefaultFolderAction() throws Exception {
      if (!defaultFolderSpecified()) {
        String message =
            "A default folder has not been specified.  Would you like to specify one now?\n";
        if (_subfolderName != null) {
          message +=
              "Note that you will be specifying the parent folder of " + _subfolderName + ".\n";
          message += _subfolderName + " under the selected folder will hold your files.";
        }
        final int confirm =
            JOptionPane.showConfirmDialog(
                _view, message, "Specify Default Folder", JOptionPane.YES_NO_OPTION);

        try {
          switch (confirm) {
            case JOptionPane.YES_OPTION:
              if (!showDefaultFolderSelector()) return;
              break;
            default:
              return;
          }
        } catch (Exception exception) {
          exception.printStackTrace();
        }
      }

      applyDefaultFolder(_activeFileChooser);
    }
예제 #3
0
  // Remove a test case from testBox and tests array.
  private void removeTest() {

    // Make sure they want to remove the checked tests.
    String message = "Are you sure you would like to remove the selected tests?";
    int decision =
        JOptionPane.showConfirmDialog(null, message, "Remove", JOptionPane.OK_CANCEL_OPTION);

    // If they definitely do want to remove.
    if (decision == JOptionPane.OK_OPTION) {

      // Make array list copy, so as to avoid index errors.
      ArrayList<JCheckBox> newTests = (ArrayList<JCheckBox>) tests.clone();
      int removed = 0;

      for (int i = 0; i < tests.size(); i++) {
        if (tests.get(i).isSelected()) {
          // Remove from the tests copy.
          newTests.remove(i - removed);
          // Remove from the GUI box.
          testBox.setEditable(true);
          testBox.remove(tests.get(i));
          testBox.repaint();
          testBox.setEditable(false);
        }
      }

      // Update the tests with the newly made list.
      tests = newTests;
    }
  }
예제 #4
0
 private void btnEliminarRenglonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnEliminarRenglonActionPerformed
   // TODO add your handling code here:
   int IDRenglon = this.tablaPrincipal.getSelectedRow();
   if (IDRenglon != -1) {
     if (JOptionPane.showConfirmDialog(
             null,
             "¿Realmente desea eliminar el renglón seleccionado?",
             "¿Eliminar?",
             JOptionPane.OK_CANCEL_OPTION)
         == JOptionPane.OK_OPTION) {
       ((DefaultTableModel) tablaPrincipal.getModel()).removeRow(IDRenglon);
     }
   }
 } // GEN-LAST:event_btnEliminarRenglonActionPerformed
예제 #5
0
파일: Board.java 프로젝트: ankeshs/hex
  void exit() {
    int n =
        JOptionPane.showConfirmDialog(
            this,
            "Are you sure you want to exit this game?",
            "Confirm Exit",
            JOptionPane.YES_NO_OPTION);

    if (n == JOptionPane.YES_OPTION) {
      if (gst.audio) {
        AePlayWave.play(AePlayWave.EXIT);
        try {
          Thread.sleep(2000);
        } catch (Exception e) {
        }
      }
      dispose();
      System.exit(0);
    }
  }
예제 #6
0
 public void exit() {
   // user is attempting to exit the interpreter.
   // make sure this is what they want to do
   // and check if changes need to be saved.
   int r =
       JOptionPane.showConfirmDialog(
           this,
           new JLabel("Exit Interpreter?"),
           "Confirm Exit",
           JOptionPane.YES_NO_OPTION,
           JOptionPane.QUESTION_MESSAGE);
   if (r == JOptionPane.YES_OPTION) {
     // user still wants to go ahead.
     // if file not saved then prompt to check
     // whether it should be.
     if (!dirty || checkForSave()) {
       System.exit(0);
     }
   }
 }
예제 #7
0
    /** Runs this thread. */
    public void run() {
      CommonFileChooser file_chooser = new CommonFileChooser();
      file_chooser.setDialogTitle("Save selected data.");
      file_chooser.setMultiSelectionEnabled(false);

      if (file_chooser.showSaveDialog(pane) == JFileChooser.APPROVE_OPTION) {
        try {
          File file = file_chooser.getSelectedFile();
          if (file.exists()) {
            String message = "Overwrite to " + file.getPath() + " ?";
            if (0
                != JOptionPane.showConfirmDialog(
                    pane, message, "Confirmation", JOptionPane.YES_NO_OPTION)) {
              return;
            }
          }

          AstrometricaWriter writer = new AstrometricaWriter(file);
          writer.open();

          int check_column = getCheckColumn();
          for (int i = 0; i < model.getRowCount(); i++) {
            if (((Boolean) getValueAt(i, check_column)).booleanValue()) {
              Variability record = (Variability) record_list.elementAt(index.get(i));
              writer.write(record.getStar());
            }
          }

          writer.close();

          String message = "Completed.";
          JOptionPane.showMessageDialog(pane, message);
        } catch (IOException exception) {
          String message = "Failed to save file.";
          JOptionPane.showMessageDialog(pane, message, "Error", JOptionPane.ERROR_MESSAGE);
        } catch (UnsupportedStarClassException exception) {
          String message = "Failed to save file.";
          JOptionPane.showMessageDialog(pane, message, "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    }
예제 #8
0
    /** Runs this thread. */
    public void run() {
      CommonFileChooser file_chooser = new CommonFileChooser();
      file_chooser.setDialogTitle("Save package file.");
      file_chooser.setMultiSelectionEnabled(false);
      file_chooser.addChoosableFileFilter(new XmlFilter());
      file_chooser.setSelectedFile(new File("package.xml"));

      if (file_chooser.showSaveDialog(pane) == JFileChooser.APPROVE_OPTION) {
        try {
          File file = file_chooser.getSelectedFile();
          if (file.exists()) {
            String message = "Overwrite to " + file.getPath() + " ?";
            if (0
                != JOptionPane.showConfirmDialog(
                    pane, message, "Confirmation", JOptionPane.YES_NO_OPTION)) {
              return;
            }
          }

          // Outputs the variability XML file.

          XmlVariabilityHolder holder = new XmlVariabilityHolder();

          Variability[] records = getSelectedRecords();
          for (int i = 0; i < records.length; i++) {
            XmlVariability variability = new XmlVariability(records[i]);
            holder.addVariability(variability);
          }

          holder.write(file);

          String message = "Completed.";
          JOptionPane.showMessageDialog(pane, message);
        } catch (IOException exception) {
          String message = "Failed.";
          JOptionPane.showMessageDialog(pane, message, "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    }
예제 #9
0
파일: Board.java 프로젝트: ankeshs/hex
  void place(int mx, int my) {
    if (drme) {
      drme = false;
      return;
    }

    int n = data.a.length;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (((mx - data.a[i][j].x) * (mx - data.a[i][j].x)
                    + (my - data.a[i][j].y) * (my - data.a[i][j].y)
                < bst.scale * bst.scale * .75)
            && data.a[i][j].getState() == 0) {
          if (count == 1 && gst.swap) {
            int ch =
                JOptionPane.showConfirmDialog(
                    this, "Swap moves?", "Swap", JOptionPane.YES_NO_OPTION);
            if (ch == JOptionPane.YES_OPTION) {
              lmv.setState(cst);
              switch (cst) {
                case 1:
                  data.a[i][j].setState(2);
                  break;
                case 2:
                  data.a[i][j].setState(1);
                  break;
              }
              repaint(
                  (int) (lmv.x - 0.8 * bst.scale),
                  (int) (lmv.y - 0.8 * bst.scale),
                  (int) (1.6 * bst.scale),
                  (int) (1.6 * bst.scale));
              if (AIMethods.gameOver(this, lmv.i, lmv.j, count)) {
                newGame();
              }
              if (gst.ai != null) gst.ai.updateAI(lmv.i, lmv.j, lmv.getState(), count);

            } else data.a[i][j].setState(cst);

          } else data.a[i][j].setState(cst);
          lmv = data.a[i][j];
          repaint(
              (int) (data.a[i][j].x - 0.8 * bst.scale),
              (int) (data.a[i][j].y - 0.8 * bst.scale),
              (int) (1.6 * bst.scale),
              (int) (1.6 * bst.scale));
          switch (cst) {
            case 1:
              cst = 2;
              break;
            case 2:
              cst = 1;
              break;
          }

          if (AIMethods.gameOver(this, lmv.i, lmv.j, count)) {
            System.out.println("Game Over");
            firstrun = true;
            String win = "";
            if (lmv.getState() == Block.RED_BEAD) {
              switch (gst.theme) {
                case 0:
                  win = "Red";
                  break;
                case 1:
                  win = "Black";
                  break;
                case 2:
                  win = "Gold";
                  break;
              }

            } else {
              switch (gst.theme) {
                case 0:
                  win = "Blue";
                  break;
                case 1:
                  win = "Green";
                  break;
                case 2:
                  win = "Silver";
                  break;
              }
            }
            if (gst.audio) AePlayWave.play(AePlayWave.END);
            JOptionPane.showMessageDialog(
                this, win + " wins", "Game Over", JOptionPane.INFORMATION_MESSAGE);
            newGame();
            return;
          }

          if (gst.audio) {
            if (gst.ai == null) AePlayWave.play(AePlayWave.PLACE);
            else if (userMove) AePlayWave.play(AePlayWave.AIMOVE);
          }
          count++;
          if (gst.ai != null && userMove) {
            userMove = false;
            gst.ai.nextMove(lmv.i, lmv.j, lmv.getState(), count);
          } else userMove = true;
          return;
        }
      }
    }
    if (gst.audio) AePlayWave.play(AePlayWave.BLOCK);
  }
예제 #10
0
  @Override
  public void actionPerformed(ActionEvent axnEve) {
    Object obj = axnEve.getSource();

    if (obj == selectAllCB) {
      Boolean state;
      if (selectAllCB.isSelected()) {
        state = true;
        deleteBut.setVisible(true);
        if (Home.titlePan.getTitle().equals("Trash")) {
          restoreBut.setVisible(true);
        }
      } else {
        state = false;
        deleteBut.setVisible(false);
        if (Home.titlePan.getTitle().equals("Trash")) {
          restoreBut.setVisible(false);
        }
      }
      for (int i = 0; i < table.getRowCount(); i++) {
        table.setValueAt(state, i, 0);
      }
    } else if (obj == refreshBut || obj == backBut) {
      setContent(Home.titlePan.getTitle());
      backBut.setVisible(false);
    } else if (obj == deleteBut) {
      ArrayList selectedMessages = getSelectedMessages();
      if (selectedMessages.isEmpty()) {
        FootPan.setMessage(FootPan.NO_SELECTION_MESSAGE);
      } else {
        int option =
            JOptionPane.showConfirmDialog(
                Home.home.homeFrame,
                "Are You Sure?",
                "DELETE",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE);
        if (option == 0) {
          Database.deleteMessages(selectedMessages, Home.titlePan.getTitle());
          setContent(Home.titlePan.getTitle());
        }
      }
    } else if (obj == restoreBut) {
      ArrayList selectedMessages = getSelectedMessages();
      if (selectedMessages.isEmpty()) {
        FootPan.setMessage(FootPan.NO_SELECTION_MESSAGE);
      } else {
        int option =
            JOptionPane.showConfirmDialog(
                Home.home.homeFrame,
                "Are You Sure?",
                "RESTORE",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE);
        if (option == 0) {
          Database.restoreMessages(selectedMessages);
          setContent(Home.titlePan.getTitle());
        }
      }
    }
  }
예제 #11
0
  /** Runs a Windows installer */
  public static boolean runWindowsInstaller(String installPath, File installFile) {
    boolean deleteHopperKey = false;
    boolean deleteMerlinKey = false;
    // If Hopper, and JavaWS can update, ask the user if they want
    // to update.
    if (Config.isHopper()
        && !WinRegistry.doesSubKeyExist(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_HOPPER_KEY)) {
      int res =
          JOptionPane.showConfirmDialog(
              _installerFrame,
              Config.getJavaWSConfirmMessage(),
              Config.getJavaWSConfirmTitle(),
              JOptionPane.YES_NO_OPTION);
      if (res == JOptionPane.NO_OPTION) {
        // create the registry key so that JavaWS will not install
        WinRegistry.setStringValue(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_HOPPER_KEY, "Home", "");
        // flag to delete the key later
        deleteHopperKey = true;
      }
    }

    // If Merlin, never update JavaWS.  1.0.1_02 bundled with Merlin does
    // not have the ability to update while JavaWS is running.  So just
    // prevent the update by spoofing the registry key.
    if (Config.isMerlin()) {
      WinRegistry.setStringValue(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_MERLIN_KEY, "Home", "");
      deleteMerlinKey = true;
    }

    /** Build temp. script file */
    boolean success = false;
    File iss = null;
    try {
      String[] args = new String[2];
      args[0] = installFile.getAbsolutePath();
      if (Config.getJavaVersion().startsWith("1.4.2")) {
        args[1] = "/s /v\"/qn WEBSTARTICON=1 INSTALLDIR=\\\"" + installPath + "\\\"\"";

      } else {
        iss = WindowsInstaller.createTempISSScript(installPath, Config.getJavaVersion());
        args[1] = iss.getAbsolutePath();
      }
      String execString = getExecuteString(args);
      success = WindowsInstaller.execute(execString);
    } catch (IOException ioe) {
      return false;
    } finally {
      if (iss != null) iss.delete();
    }

    // delete any spoofed keys we created earlier
    if (deleteHopperKey) {
      WinRegistry.deleteKey(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_HOPPER_KEY);
    }
    if (deleteMerlinKey) {
      WinRegistry.deleteKey(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_MERLIN_KEY);
    }

    // 4662215 cannot reboot here because the config hasn't been written
    // by JavaWS yet.  Reboot later, after installSucceeded has been
    // called.
    // WindowsInstaller.rebootIfNecessary();

    return success;
  }
예제 #12
0
    /** Runs this thread. */
    public void run() {
      CommonFileChooser file_chooser = new CommonFileChooser();
      file_chooser.setDialogTitle("Choose a directory.");
      file_chooser.setMultiSelectionEnabled(false);
      file_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

      if (file_chooser.showSaveDialog(pane) == JFileChooser.APPROVE_OPTION) {
        try {
          File directory = file_chooser.getSelectedFile();
          directory.mkdirs();

          // Outputs the variability XML file.

          String path = FileManager.unitePath(directory.getAbsolutePath(), "package.xml");
          File file = new File(path);
          if (file.exists()) {
            String message = "Overwrite to " + file.getPath() + " ?";
            if (0
                != JOptionPane.showConfirmDialog(
                    pane, message, "Confirmation", JOptionPane.YES_NO_OPTION)) {
              return;
            }
          }

          XmlVariabilityHolder holder = new XmlVariabilityHolder();

          Variability[] records = getSelectedRecords();
          for (int i = 0; i < records.length; i++) {
            XmlVariability variability = new XmlVariability(records[i]);
            holder.addVariability(variability);
          }

          holder.write(file);

          // Copies the report XML document files.

          Hashtable hash_xml = new Hashtable();

          for (int i = 0; i < records.length; i++) {
            XmlMagRecord[] mag_records = records[i].getMagnitudeRecords();
            for (int j = 0; j < mag_records.length; j++)
              hash_xml.put(mag_records[j].getImageXmlPath(), this);
          }

          Vector failed_list = new Vector();

          Enumeration keys = hash_xml.keys();
          while (keys.hasMoreElements()) {
            String xml_path = (String) keys.nextElement();
            try {
              File src_file = desktop.getFileManager().newFile(xml_path);
              File dst_file =
                  new File(FileManager.unitePath(directory.getAbsolutePath(), xml_path));
              if (dst_file.exists() == false) FileManager.copy(src_file, dst_file);
            } catch (Exception exception) {
              failed_list.addElement(xml_path);
            }
          }

          if (failed_list.size() > 0) {
            String header = "Failed to copy the following XML files:";
            MessagesDialog dialog = new MessagesDialog(header, failed_list);
            dialog.show(pane, "Error", JOptionPane.ERROR_MESSAGE);
          }

          // Copies the image files.

          failed_list = new Vector();

          keys = hash_xml.keys();
          while (keys.hasMoreElements()) {
            path = (String) keys.nextElement();
            try {
              XmlInformation info =
                  XmlReport.readInformation(desktop.getFileManager().newFile(path));
              path = info.getImage().getContent();

              File src_file = desktop.getFileManager().newFile(path);
              File dst_file = new File(FileManager.unitePath(directory.getAbsolutePath(), path));
              if (dst_file.exists() == false) FileManager.copy(src_file, dst_file);
            } catch (Exception exception) {
              failed_list.addElement(path);
            }
          }

          if (failed_list.size() > 0) {
            String header = "Failed to copy the following image files:";
            MessagesDialog dialog = new MessagesDialog(header, failed_list);
            dialog.show(pane, "Error", JOptionPane.ERROR_MESSAGE);
          }

          // Creates the sub catalog database.

          try {
            DiskFileSystem file_system =
                new DiskFileSystem(
                    new File(
                        directory.getAbsolutePath(),
                        net.aerith.misao.pixy.Properties.getDatabaseDirectoryName()));
            CatalogDBManager new_manager = new GlobalDBManager(file_system).getCatalogDBManager();

            Hashtable hash_stars = new Hashtable();
            for (int i = 0; i < records.length; i++) {
              CatalogStar star = records[i].getStar();

              CatalogDBReader reader =
                  new CatalogDBReader(desktop.getDBManager().getCatalogDBManager());
              StarList list = reader.read(star.getCoor(), 0.5);
              for (int j = 0; j < list.size(); j++) {
                CatalogStar s = (CatalogStar) list.elementAt(j);
                hash_stars.put(s.getOutputString(), s);
              }
            }

            keys = hash_stars.keys();
            while (keys.hasMoreElements()) {
              String string = (String) keys.nextElement();
              CatalogStar star = (CatalogStar) hash_stars.get(string);
              new_manager.addElement(star);
            }
          } catch (Exception exception) {
            String message = "Failed to create sub catalog database.";
            JOptionPane.showMessageDialog(pane, message, "Error", JOptionPane.ERROR_MESSAGE);
          }

          String message = "Completed.";
          JOptionPane.showMessageDialog(pane, message);
        } catch (IOException exception) {
          String message = "Failed.";
          JOptionPane.showMessageDialog(pane, message, "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    }