Пример #1
0
 @Override
 public void actionPerformed(ActionEvent e) {
   boolean isHaveNewDocument = false;
   for (int i = 0; i < td.getTabCount(); i++) { // 依序將檔案撈出
     TextDocument ta = (TextDocument) td.getComponentAt(i);
     if (ta.file == null) { // 判斷是否有新黨案,有的會將運用到預設儲存路徑
       isHaveNewDocument = true;
       break;
     }
   }
   // 有新黨案,但是卻沒設定預設路徑,將跳出警告
   if (isHaveNewDocument && default_auto_save_path == null) {
     JOptionPane.showMessageDialog(
         null,
         "請先設定自動儲存預設位置!\nEdit->Default AutoSave-Path",
         "Save error",
         JOptionPane.ERROR_MESSAGE);
     return;
   }
   if (td.getTabCount() > 0) {
     for (int i = 0; i < td.getTabCount(); i++) { // 依序儲存
       save(i);
     }
     System.out.println("Save pass!");
     JOptionPane.showMessageDialog(
         null, "可儲存的檔案已儲存檔案。\n新檔案儲存於預設位置" + default_auto_save_path + "目錄下.");
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
Пример #2
0
  /**
   * Used to show the message dialogs to the user. @ param parent a reference to the main <code>
   *  Word </code> object @ param msg message to be displayed in the message dialog. @ param type
   * type of the message dialog @ param icon icon to be shown in the message dialog @ param options
   * command options to be displayed in the message dialog @ param selectIndex index of the
   * component to be focused.
   */
  public static int showDialog(
      Component parent,
      String msg,
      int option,
      int type,
      Icon icon,
      Object[] options,
      int selectIndex) {
    // 	Contains the word bundle for the current local
    ResourceBundle wordBundle = Word.wordBundle;
    String messageTitle = wordBundle.getString("MessageTitle");

    String message;

    if (msg.indexOf("RHBD") != -1) // to show "replacement(s) have been done." message.
    message = msg.substring(0, msg.indexOf("RHBD") - 1) + " " + wordBundle.getString("RHBD");
    else message = wordBundle.getString(msg);

    JOptionPane p = new JOptionPane((Object) message, option, type, null, options, options[0]);
    JDialog d = p.createDialog(parent, messageTitle);

    d.setResizable(false);
    d.show();
    Object selectedValue = p.getValue();

    if (selectedValue.equals(new Integer(-1))) {
      d.dispose();
      return JOptionPane.CANCEL_OPTION;
    }

    if (selectedValue == null) {
      d.dispose();
      return JOptionPane.CLOSED_OPTION;
    }

    // If there is not an array of option buttons:
    if (options == null) {
      if (selectedValue instanceof Integer) {
        d.dispose();
        return ((Integer) selectedValue).intValue();
      }
      d.dispose();
      return JOptionPane.CLOSED_OPTION;
    }

    // If there is an array of option buttons:
    for (int counter = 0, maxCounter = options.length; counter < maxCounter; counter++) {
      if (options[counter].equals(selectedValue)) {
        d.dispose();
        return counter;
      }
    }
    d.dispose();
    return 0;
  }
 /**
  * Method used by the SystemIO class to get interactive user input requested by a running MIPS
  * program (e.g. syscall #5 to read an integer). SystemIO knows whether simulator is being run at
  * command line by the user, or by the GUI. If run at command line, it gets input from System.in
  * rather than here.
  *
  * <p>This is an overloaded method. This version, with the String parameter, is used to get input
  * from a popup dialog.
  *
  * @param prompt Prompt to display to the user.
  * @return User input.
  */
 public String getInputString(String prompt) {
   String input;
   JOptionPane pane =
       new JOptionPane(prompt, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION);
   pane.setWantsInput(true);
   JDialog dialog = pane.createDialog(Globals.getGui(), "MIPS Keyboard Input");
   dialog.setVisible(true);
   input = (String) pane.getInputValue();
   this.postRunMessage(Globals.userInputAlert + input + "\n");
   return input;
 }
Пример #4
0
  /**
   * Is called from the model when data is changed, updates members and view of this class. Checks
   * if the game is over.
   *
   * @param e ChangeEvent object
   */
  public void stateChanged(ChangeEvent e) {

    // update the view: accessors and repaint
    data = model.getData();
    repaint();
    if (model.isFinish() && !gameOver) {
      gameOver = true;
      JFrame frame = new JFrame("Declare Winner");
      if (model.declareWinner() == 1) JOptionPane.showMessageDialog(frame, "A is the winner!!!");
      else if (model.declareWinner() == 2)
        JOptionPane.showMessageDialog(frame, "B is the winner!!!");
      else JOptionPane.showMessageDialog(frame, "It is a tie!!!");
    }
  }
Пример #5
0
 private void multiConnect() {
   if (jButtonMultiConnect.getText().equals("Multi-Connect")) {
     String res =
         JOptionPane.showInputDialog(this, "Enter number of connections", "Multi-Connect");
     if (res != null) {
       jButtonMultiConnect.setText("Multi-Disconnect");
       jMenuItemTestMulticonnect.setEnabled(false);
       jMenuItemTestMultidisconnect.setEnabled(true);
       int count = Integer.parseInt(res);
       MultiSessions = new Session[count];
       for (int i = 0; i < count; i++) {
         MultiSessions[i] = new Session();
         try {
           MultiSessions[i].connect(
               this.jTextFieldServer.getText(), this.jTextFieldUser.getText() + String.valueOf(i));
         } catch (ConnectionException ex1) {
         }
       }
     }
   } else {
     for (int i = 0; i < MultiSessions.length; i++) {
       try {
         ((Session) MultiSessions[i]).disconnect();
       } catch (Exception ex) {
         System.out.println("Error disconnectiong from session");
       }
     }
     jButtonMultiConnect.setText("Multi-Connect");
     jMenuItemTestMulticonnect.setEnabled(true);
     jMenuItemTestMultidisconnect.setEnabled(false);
   }
 }
Пример #6
0
 public void save(int i) {
   BufferedWriter brw = null;
   TextDocument ta = (TextDocument) td.getComponentAt(i);
   try {
     File file = null;
     if (ta.file == null) { // 判斷是否為新黨案,是的話使用預設路徑儲存
       file = new File(default_auto_save_path + "\\" + ta.fileName);
     } else {
       file = ta.file; // 儲存於原檔案
     }
     brw = new BufferedWriter(new FileWriter(file));
     ta.write(brw);
     ta.save = true;
     td.setTitleAt(i, ta.fileName); // 更新標題名稱
   } catch (FileNotFoundException ffe) { // 若預設路徑不存在,則跳出警告
     JOptionPane.showMessageDialog(
         null,
         ta.fileName + "儲存失敗!\n請檢查Default AutoSave-Path是否存在,或是權限不足.",
         "Save error",
         JOptionPane.ERROR_MESSAGE);
   } catch (Exception exc) {
     exc.printStackTrace();
   } finally {
     try {
       brw.close();
     } catch (Exception exc) {
     }
   }
 }
Пример #7
0
 public String saveAsFile(boolean accessingAsFile) throws IOException {
   File file = new SikuliIDEFileChooser(SikuliIDE.getInstance(), accessingAsFile).save();
   if (file == null) {
     return null;
   }
   String bundlePath = FileManager.slashify(file.getAbsolutePath(), false);
   if (!file.getAbsolutePath().endsWith(".sikuli")) {
     bundlePath += ".sikuli";
   }
   if (FileManager.exists(bundlePath)) {
     int res =
         JOptionPane.showConfirmDialog(
             null,
             SikuliIDEI18N._I("msgFileExists", bundlePath),
             SikuliIDEI18N._I("dlgFileExists"),
             JOptionPane.YES_NO_OPTION);
     if (res != JOptionPane.YES_OPTION) {
       return null;
     }
   } else {
     FileManager.mkdir(bundlePath);
   }
   try {
     saveAsBundle(bundlePath, (SikuliIDE.getInstance().getCurrentFileTabTitle()));
     if (Settings.isMac()) {
       if (!Settings.handlesMacBundles) {
         makeBundle(bundlePath, accessingAsFile);
       }
     }
   } catch (IOException iOException) {
   }
   return getCurrentShortFilename();
 }
Пример #8
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showOpenDialog(frame);

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

      File f = chooser.getSelectedFile();
      if (f.isFile() && f.canRead()) {
        Document oldDoc = getEditor().getDocument();
        if (oldDoc != null) {
          oldDoc.removeUndoableEditListener(undoHandler);
        }
        if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
        }
        getEditor().setDocument(new PlainDocument());
        frame.setTitle(f.getName());
        Thread loader = new FileLoader(f, editor.getDocument());
        loader.start();
      } else {
        JOptionPane.showMessageDialog(
            getFrame(),
            "Could not open file: " + f,
            "Error opening file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
Пример #9
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     TextDocument ta = (TextDocument) td.getComponentAt(td.getSelectedIndex());
     Pattern pn = Pattern.compile(tf1.getText());
     Matcher mt = pn.matcher(ta.getText());
     if (e.getSource() == jb2) { // 取代
       ta.setText(mt.replaceAll(tf2.getText()));
     } else if (e.getSource() == jb1) { // 尋找
       Highlighter hl = ta.getHighlighter();
       hl.removeAllHighlights();
       while (mt.find()) {
         try {
           hl.addHighlight(
               mt.start(), mt.end(), new DefaultHighlighter.DefaultHighlightPainter(null));
         } catch (Exception ex) {
         }
       } // 開啟及關閉介面
     } else if (e.getSource() == replace_searchMenuItem) {
       System.out.println("Replace/Search is show:" + !show);
       if (show) {
         getContentPane().remove(jp);
         show = false;
       } else {
         getContentPane().add(jp, BorderLayout.SOUTH);
         show = true;
       }
       validate(); // 刷新容器
     }
   } else if (e.getSource() == replace_searchMenuItem) {
     JOptionPane.showMessageDialog(
         null, "尚無檔案,無法使用!", "Repace/Search error", JOptionPane.ERROR_MESSAGE);
   }
 }
Пример #10
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     JFileChooser f = new JFileChooser();
     f.setFileFilter(new MyFileFilter());
     int choose = f.showSaveDialog(getContentPane());
     if (choose == JFileChooser.APPROVE_OPTION) {
       BufferedWriter brw = null;
       try {
         File file = f.getSelectedFile();
         brw = new BufferedWriter(new FileWriter(file));
         int i = td.getSelectedIndex();
         TextDocument ta = (TextDocument) td.getComponentAt(i);
         ta.write(brw);
         ta.fileName = file.getName(); // 將檔案名稱更新為存檔的名稱
         td.setTitleAt(td.getSelectedIndex(), ta.fileName);
         ta.file = file;
         ta.save = true; // 設定已儲存
         System.out.println("Save as pass!");
         td.setTitleAt(i, ta.fileName); // 更新標題名稱
       } catch (Exception exc) {
         exc.printStackTrace();
       } finally {
         try {
           brw.close();
         } catch (Exception ecx) {
           ecx.printStackTrace();
         }
       }
     }
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
Пример #11
0
  private void setExceptionPane(Object msg) {
    // If debug is enabled display dialog.
    if (debugEnabled) {
      // Display message and retrieve selected value.
      int result =
          JOptionPane.showConfirmDialog(this, msg, "Information", JOptionPane.YES_NO_OPTION);

      // Display message and retrieve selected value.
      switch (result) {
        case JOptionPane.CLOSED_OPTION:
          resetExceptionString();
          break;

        case JOptionPane.YES_OPTION:
          getStackTraceDialog();
          break;

        case JOptionPane.NO_OPTION:
          resetExceptionString();
          break;
      } // End of result evaluation switch.

    } // End of if debugEnabled evaluation.
    else {
      // Disgard the error and reset the class instance exception String.
      // This resets the value to a zero length String.
      resetExceptionString();
    } // End of else debugEnabled evaluation.
  } // End of setExceptionPane() method.
Пример #12
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;
  }
Пример #13
0
  private void updateEditorView() {
    editorPane.setText("");
    numParameters = 0;
    try {
      java.util.List elements = editableTemplate.getPrintfElements();
      for (Iterator it = elements.iterator(); it.hasNext(); ) {
        PrintfUtil.PrintfElement el = (PrintfUtil.PrintfElement) it.next();
        if (el.getFormat().equals(PrintfUtil.PrintfElement.FORMAT_NONE)) {
          appendText(el.getElement(), PLAIN_ATTR);
        } else {
          insertParameter(
              (ConfigParamDescr) paramKeys.get(el.getElement()),
              el.getFormat(),
              editorPane.getDocument().getLength());
        }
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          this,
          "Invalid Format: " + ex.getMessage(),
          "Invalid Printf Format",
          JOptionPane.ERROR_MESSAGE);

      selectedPane = 1;
      printfTabPane.setSelectedIndex(selectedPane);
      updatePane(selectedPane);
    }
  }
 public int submit() {
   String newName = produktgruppeFormular.nameField.getText();
   if (isProdGrAlreadyKnown(newName)) {
     // not allowed: changing name to one that is already registered in DB
     JOptionPane.showMessageDialog(
         this,
         "Fehler: Produktgruppe '" + newName + "' bereits vorhanden!",
         "Info",
         JOptionPane.INFORMATION_MESSAGE);
     produktgruppeFormular.nameField.setText("");
     return 0;
   }
   Integer parentProdGrID =
       produktgruppeFormular.parentProdGrIDs.get(
           produktgruppeFormular.parentProdGrBox.getSelectedIndex());
   Vector<Integer> idsNew = produktgruppeFormular.idsOfNewProdGr(parentProdGrID);
   Integer topID = idsNew.get(0);
   Integer subID = idsNew.get(1);
   Integer subsubID = idsNew.get(2);
   Integer mwstID =
       produktgruppeFormular.mwstIDs.get(produktgruppeFormular.mwstBox.getSelectedIndex());
   Integer pfandID =
       produktgruppeFormular.pfandIDs.get(produktgruppeFormular.pfandBox.getSelectedIndex());
   return insertNewProdGr(topID, subID, subsubID, newName, mwstID, pfandID);
 }
Пример #15
0
 public boolean close() throws IOException {
   if (isDirty()) {
     Object[] options = {
       SikuliIDEI18N._I("yes"), SikuliIDEI18N._I("no"), SikuliIDEI18N._I("cancel")
     };
     int ans =
         JOptionPane.showOptionDialog(
             this,
             SikuliIDEI18N._I("msgAskSaveChanges", getCurrentShortFilename()),
             SikuliIDEI18N._I("dlgAskCloseTab"),
             JOptionPane.YES_NO_CANCEL_OPTION,
             JOptionPane.WARNING_MESSAGE,
             null,
             options,
             options[0]);
     if (ans == JOptionPane.CANCEL_OPTION || ans == JOptionPane.CLOSED_OPTION) {
       return false;
     } else if (ans == JOptionPane.YES_OPTION) {
       if (saveFile() == null) {
         return false;
       }
     } else {
       SikuliIDE.getInstance().getTabPane().resetLastClosed();
     }
     if (_srcBundleTemp) {
       FileManager.deleteTempDir(_srcBundlePath);
     }
     setDirty(false);
   }
   if (_srcBundlePath != null) {
     ImagePath.remove(_srcBundlePath);
   }
   return true;
 }
Пример #16
0
 private void messageStresser() throws HeadlessException {
   String res = JOptionPane.showInputDialog(this, "Number of messages to send");
   try {
     int count = Integer.parseInt(res);
     Thread t = new Thread(new Stresser(count));
     t.start();
   } catch (NumberFormatException nfe) {
   }
 }
Пример #17
0
 private void saveOld() {
   if (changed) {
     if (JOptionPane.showConfirmDialog(
             this,
             "Would you like to save " + currentFile + " ?",
             "Save",
             JOptionPane.YES_NO_OPTION)
         == JOptionPane.YES_OPTION) saveFile(currentFile);
   }
 }
Пример #18
0
 private void updateBoard(DocumentEvent e) throws BadLocationException {
   Document doc = e.getDocument();
   int index = (int) doc.getProperty("index");
   String valueString = doc.getText(0, doc.getLength());
   if (doc.getLength() == 0) valueString = "0";
   int value = Integer.parseInt(valueString);
   gameBoard.changeCellAt(index, value);
   // gameBoard.out();
   if (gameBoard.checkGameOver()) {
     JOptionPane.showMessageDialog(frame, "NUMBRIX COMPLETED!!!");
   }
 }
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == submit) {
     if (rb1.isSelected()) {
       JFrame frame = Application.getFrame();
       if (typeCodes.isEmpty()) {
         JOptionPane.showMessageDialog(
             frame,
             "Please select at least one toponym type.",
             "Error",
             JOptionPane.ERROR_MESSAGE);
       } else {
         Application.getMainCitiesPanel(this, typeCodes, 0, 0.0);
       }
     } else if (rb2.isSelected()) {
       JFrame frame = Application.getFrame();
       try {
         nCities = new Integer(nCitiesField.getText());
         if (nCities <= 0) throw new NumberFormatException();
         typeCodes = new ArrayList<String>();
         Application.getMainCitiesPanel(this, typeCodes, nCities, 0.0);
       } catch (NumberFormatException ex) {
         JOptionPane.showMessageDialog(
             frame, "Please enter a positive integer number.", "Error", JOptionPane.ERROR_MESSAGE);
       }
     } else {
       JFrame frame = Application.getFrame();
       try {
         Double dist = new Double(distField.getText());
         if (dist <= 0) throw new NumberFormatException();
         typeCodes = new ArrayList<String>();
         Application.getMainCitiesPanel(this, typeCodes, 0, dist);
       } catch (NumberFormatException ex) {
         JOptionPane.showMessageDialog(
             frame, "Please enter a positive number.", "Error", JOptionPane.ERROR_MESSAGE);
       }
     }
   } else {
     Application.getOptionPanel(this, countryName);
   }
 }
Пример #20
0
  /** Initial Option Panes that lets user select style and number of stones */
  public void initScreen() {
    Object[] options = {"Style A", "Style B"};
    int input =
        JOptionPane.showOptionDialog(
            null,
            "Choose a Board Style:",
            "Board Styles",
            JOptionPane.DEFAULT_OPTION,
            JOptionPane.DEFAULT_OPTION,
            null,
            options,
            options[0]);
    if (input == 0) {
      boardPanel = boardContextDoWork(new StrategyGreen());
    } else if (input == 1) {
      boardPanel = boardContextDoWork(new StrategyBrown()); // change later
    } else {
      System.exit(0);
    }
    Object[] optionStones = {"3", "4"};
    int inputStones =
        JOptionPane.showOptionDialog(
            null,
            "Choose Number of Stones:",
            "Initial Stones",
            JOptionPane.DEFAULT_OPTION,
            JOptionPane.DEFAULT_OPTION,
            null,
            optionStones,
            optionStones[0]);

    if (inputStones == 0) {
      model.refreshBoard(3);
    } else if (inputStones == 1) {
      model.refreshBoard(4);
    } else {
      System.exit(0);
    }
  }
 private void readInFile(String fileName) {
   try {
     FileReader r = new FileReader(fileName);
     area.read(r, null);
     r.close();
     currentFile = fileName;
     setTitle(currentFile + " - CoreyTextEditor");
     changed = false;
   } catch (IOException e) {
     Toolkit.getDefaultToolkit().beep();
     JOptionPane.showMessageDialog(this, "Editor can't find the file called " + fileName);
   }
 }
Пример #22
0
 void jMenuItemScheduleCommand_actionPerformed(ActionEvent e) {
   try {
     String result = JOptionPane.showInputDialog("Enter <command>,<interval>");
     if (result != null) {
       StringTokenizer st = new StringTokenizer(result, ",");
       if (st.countTokens() == 2) {
         String command = st.nextToken();
         long interval = Long.parseLong(st.nextToken());
         CommandScheduler.create(command, interval * 1000);
       }
     }
   } catch (Exception ex) {
   }
 }
Пример #23
0
 protected FailureDetailView createFailureDetailView() {
   String className = BaseTestRunner.getPreference(FAILUREDETAILVIEW_KEY);
   if (className != null) {
     Class viewClass = null;
     try {
       viewClass = Class.forName(className);
       return (FailureDetailView) viewClass.newInstance();
     } catch (Exception e) {
       JOptionPane.showMessageDialog(
           mainPane, "Could not create Failure DetailView - using default view");
     }
   }
   return new DefaultFailureDetailView();
 }
Пример #24
0
  public PrintfEditor(Frame frame, String title) {
    super(frame, title, false);

    originalTemplate = new PrintfTemplate();
    editableTemplate = new PrintfTemplate();
    try {
      jbInit();
      pack();
      initMatches();
    } catch (Exception exc) {
      String logMessage = "Could not set up the printf editor";
      logger.critical(logMessage, exc);
      JOptionPane.showMessageDialog(frame, logMessage, "Printf Editor", JOptionPane.ERROR_MESSAGE);
    }
  }
Пример #25
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) { // 判斷是否有檔案
     TextDocument ta = (TextDocument) td.getComponentAt(td.getSelectedIndex());
     if (ta.file == null) { // 判斷是否為新黨案
       new SystemFileSaveAS().actionPerformed(e); // 做另存新黨
       System.out.println("Save->Save as pass!");
     } else {
       new SystemFileSaveAll().save(td.getSelectedIndex()); // 直接儲存於原檔案
       System.out.println("Save->Save pass!");
     }
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
 /**
  * * Each non abstract class that implements the ActionListener must have this method.
  *
  * @param e the action event.
  */
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == submitButton) {
     int result = submit();
     if (result == 0) {
       JOptionPane.showMessageDialog(
           this,
           "Fehler: Produktgruppe "
               + produktgruppeFormular.nameField.getText()
               + " konnte nicht eingefügt werden.",
           "Fehler",
           JOptionPane.ERROR_MESSAGE);
     } else {
       produktgruppenListe.updateAll();
       closeButton.doClick();
     }
     return;
   }
   super.actionPerformed(e);
 }
Пример #27
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);
     }
   }
 }
Пример #28
0
 // If this is a new installation, ask the user for a
 // port for the server; otherwise, return the negative
 // of the configured port. If the user selects an illegal
 // port, return zero.
 private int getPort() {
   // Note: directory points to the parent of the CTP directory.
   File ctp = new File(directory, "CTP");
   if (suppressFirstPathElement) ctp = ctp.getParentFile();
   File config = new File(ctp, "config.xml");
   if (!config.exists()) {
     // No config file - must be a new installation.
     // Figure out whether this is Windows or something else.
     String os = System.getProperty("os.name").toLowerCase();
     int defPort = ((os.contains("windows") && !programName.equals("ISN")) ? 80 : 1080);
     int userPort = 0;
     while (userPort == 0) {
       String port =
           JOptionPane.showInputDialog(
               null,
               "This is a new "
                   + programName
                   + " installation.\n\n"
                   + "Select a port number for the web server.\n\n",
               Integer.toString(defPort));
       try {
         userPort = Integer.parseInt(port.trim());
       } catch (Exception ex) {
         userPort = -1;
       }
       if ((userPort < 80) || (userPort > 32767)) userPort = 0;
     }
     return userPort;
   } else {
     try {
       Document doc = getDocument(config);
       Element root = doc.getDocumentElement();
       Element server = getFirstNamedChild(root, "Server");
       String port = server.getAttribute("port");
       return -Integer.parseInt(port);
     } catch (Exception ex) {
     }
   }
   return 0;
 }
    // Query user for a filename and attempt to open and write the text
    // component’s content to the file.
    public void actionPerformed(ActionEvent ev) {
      JFileChooser chooser = new JFileChooser();
      if (chooser.showSaveDialog(SimpleEditor.this) != JFileChooser.APPROVE_OPTION) return;
      File file = chooser.getSelectedFile();
      if (file == null) return;

      FileWriter writer = null;
      try {
        writer = new FileWriter(file);
        textComp.write(writer);
      } catch (IOException ex) {
        JOptionPane.showMessageDialog(
            SimpleEditor.this, "File Not Saved", "ERROR", JOptionPane.ERROR_MESSAGE);
      } finally {
        if (writer != null) {
          try {
            writer.close();
          } catch (IOException x) {
          }
        }
      }
    }
Пример #30
0
  public void jMenuItemNewGameActionPerformed(java.awt.event.ActionEvent evt) {
    // Custom button text
    Object[] optionPane = {"Load Board from File", "Random Board"};
    int selection =
        JOptionPane.showOptionDialog(
            frame,
            "Please select an option: ",
            "New Board",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            optionPane,
            optionPane[1]);

    if (selection == 0) {
      this.jFrameFileChooser.pack();
      this.jFrameFileChooser.setVisible(true);
      jFileChooser.enable();
      jFileChooser.setVisible(true);
    } else {
      // random board
    }
  }