Ejemplo n.º 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, "沒有檔案可以儲存!");
   }
 }
Ejemplo n.º 2
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!!!");
    }
  }
Ejemplo n.º 3
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) {
     }
   }
 }
Ejemplo n.º 4
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, "沒有檔案可以儲存!");
   }
 }
 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);
 }
Ejemplo n.º 6
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);
      }
    }
Ejemplo n.º 7
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);
    }
  }
Ejemplo n.º 8
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);
   }
 }
Ejemplo n.º 9
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);
   }
 }
 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);
   }
 }
Ejemplo n.º 12
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();
 }
Ejemplo n.º 13
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);
    }
  }
Ejemplo n.º 14
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);
 }
    // 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) {
          }
        }
      }
    }
Ejemplo n.º 17
0
 private void showErrorDialog(String msg) {
   // show a dialog window containing the error message
   JOptionPane.showMessageDialog(this, new JLabel(msg), "Error!", JOptionPane.ERROR_MESSAGE);
 }
Ejemplo n.º 18
0
  public void jFileChooserActionPerformed(java.awt.event.ActionEvent evt)
      throws FileNotFoundException, IOException {
    File initialBoard = this.jFileChooser.getSelectedFile();
    InputStream inputStream = new FileInputStream(initialBoard);
    Scanner scanner = new Scanner(inputStream);

    if (!initialBoard
        .getName()
        .toLowerCase()
        .contains("initialboard")) { // .toLowerCase().compareTo("initialboard")!=0){
      JOptionPane.showMessageDialog(
          frame, "Wrong File \n Please select InitialBoard.txt", "Eror", JOptionPane.ERROR_MESSAGE);
    } else {

      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

      try {
        in = new BufferedReader(new FileReader(initialBoard.getAbsolutePath()));

      } catch (FileNotFoundException e) {
        System.out.println(e.getCause());
        System.out.println("Error loading initial board");
      }

      int[] boardRows = new int[15];

      // ----------------
      String text = in.readLine();

      StringTokenizer tokenizer = new StringTokenizer(text, " ");

      int boardSize = 0;
      while (tokenizer.hasMoreElements()) {
        boardRows[boardSize] = Integer.parseInt(tokenizer.nextToken());
        boardSize++;
      }

      int[] newBoard = new int[boardSize * boardSize + 1];
      System.arraycopy(boardRows, 0, newBoard, 1, boardSize);

      int index = 0;
      while (in.ready()) {
        index++;
        text = in.readLine();

        tokenizer = new StringTokenizer(text, " ");
        int pos = 0;
        while (tokenizer.hasMoreElements()) {
          pos++;
          newBoard[index * boardSize + pos] = Integer.parseInt(tokenizer.nextToken());
        }
      }

      this.jFrameFileChooser.setVisible(false);
      // this.boardPanel.s

      gameInitialBoard = new Board(newBoard, boardSize);
      gameBoard = new Board(newBoard, boardSize);
      init();
    }
  }