예제 #1
0
 public void nameFocusLost(java.awt.event.FocusEvent evt) {
   ctxt.saveState = true;
   String newName = name.getText(), msg;
   while (!Library.validateFileName(newName, false)) {
     msg = "The name '" + newName + "' violates the rules for names:";
     msg += "\nIt must have 2 to 28 characters.";
     msg += "\nYou may not use BackSlash, ForwardSlash, Colon, DoubleQuote";
     msg += "\nAsterisk, QuestionMark, LeftAngleBracket, RightAngleBracket,";
     msg += "\nor the VerticalBar in a name. TRY AGAIN.";
     newName = JOptionPane.showInputDialog(msg);
   } //  end of harrass-em-until-they-give-a-good-name
   name.setText(newName);
   if (!newName.equals(ctxt.languageName)) { // Made a change
     msg = "Change this context's language name\nto" + newName + "?";
     String[] options = {newName, ctxt.languageName};
     int choice =
         JOptionPane.showOptionDialog(
             this,
             msg,
             "Confirm Changed Language Name",
             JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE,
             null,
             options,
             options[0]);
     if (choice == 0) { //  Change is confirmed
       ctxt.languageName = newName;
       msg =
           "Normally, the file name for a context is the same as the language name "
               + "\nfor that context.  Change this context's file name\n"
               + "to "
               + newName
               + "?";
       options[0] = "Change File Name";
       options[1] = "Do Not Change";
       choice =
           JOptionPane.showOptionDialog(
               this,
               msg,
               "Confirm Correct File Name",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.QUESTION_MESSAGE,
               null,
               options,
               options[0]);
       if (choice == 0) {
         Library.userContextName = newName;
         if (SIL_Edit.edWin != null && ctxt == Library.contextUnderConstruction) {
           SIL_Edit.edWin.chart.changeFileName(newName);
         }
       }
     } //  end of Change-is-confirmed
   } //  end of change-was-made
 }
예제 #2
0
 public void actionPerformed(ActionEvent e) {
   JFileChooser chooser = new JFileChooser();
   chooser.setDialogTitle("Load");
   int choice = 0;
   do {
     int result = chooser.showOpenDialog(null);
     if (result == JFileChooser.APPROVE_OPTION) {
       file = chooser.getSelectedFile();
       try {
         if (file != null) {
           fileName = file.getCanonicalPath();
           reader = new BufferedReader(new FileReader(fileName));
           String line;
           while ((line = reader.readLine()) != null) {
             myPatternList.add(line);
           }
           //							for(int i=0;i<myPatternList.size();i++) {
           //								responseArea.append(myPatternList.get(i)+"\n");
           //							}
         }
         choice = 2;
         reader.close();
       } catch (IOException c) {
         c.printStackTrace();
         Object[] options = new String[] {"Load New File", "Exit"};
         choice =
             JOptionPane.showOptionDialog(
                 null,
                 "Invalid FileChoosen." + "Would you like to load a new file " + "or exit?",
                 "Options",
                 JOptionPane.YES_NO_OPTION,
                 JOptionPane.ERROR_MESSAGE,
                 null,
                 options,
                 options[0]);
         if (choice == 1) System.exit(0);
       }
     } else if (result == JFileChooser.CANCEL_OPTION) {
       Object[] options = new String[] {"Load Different File", "Exit"};
       choice =
           JOptionPane.showOptionDialog(
               null,
               "Would you like to load a new file " + " or exit?",
               "Options",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.ERROR_MESSAGE,
               null,
               options,
               options[0]);
       if (choice == 1) System.exit(0);
     }
   } while (choice == 0);
 }
예제 #3
0
    public void actionPerformed(ActionEvent e) {
      JFileChooser chooser = new JFileChooser();
      chooser.setDialogTitle("SaveAs");
      int choice = 0;
      do {
        int result = chooser.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION) {
          file = chooser.getSelectedFile();
          try {
            if (file != null) {
              fileName = file.getCanonicalPath();
              printWriter = new PrintWriter(new FileOutputStream(fileName), true);
            }
            printWriter.append(responseArea.getText());
            choice = 2;

          } catch (IOException c) {
            c.printStackTrace();
            Object[] options = new String[] {"Choose New File", "Exit"};
            choice =
                JOptionPane.showOptionDialog(
                    null,
                    "Invalid FileChoosen." + "Would you like to choose a new file " + "or exit?",
                    "Options",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.ERROR_MESSAGE,
                    null,
                    options,
                    options[0]);
            if (choice == 1) System.exit(0);
          }
        } else if (result == JFileChooser.CANCEL_OPTION) {
          Object[] options = new String[] {"Choose Different File", "Exit"};
          choice =
              JOptionPane.showOptionDialog(
                  null,
                  "Would you like to choose a new file " + " or exit?",
                  "Options",
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
          if (choice == 1) System.exit(0);
        }
      } while (choice == 0);
      printWriter.flush();
      printWriter.close();
    }
예제 #4
0
  protected boolean confirmDeletion(Component src, String prompt) {
    int endResult =
        JOptionPane.showOptionDialog(
            src,
            prompt,
            "Confirm",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE,
            null,
            null,
            null);

    return !(endResult == JOptionPane.CANCEL_OPTION || endResult == JOptionPane.CLOSED_OPTION);
  }
예제 #5
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == save) {
     JFileChooser c = new JFileChooser(ResourceFactory.getRootDir());
     c.setDialogTitle("Save result");
     if (c.showSaveDialog(resultFrame) == JFileChooser.APPROVE_OPTION) {
       File output = c.getSelectedFile();
       if (output.exists()) {
         String[] options = {"Overwrite", "Cancel"};
         if (JOptionPane.showOptionDialog(
                 resultFrame,
                 output + "exists. Overwrite?",
                 "Save result",
                 JOptionPane.YES_NO_OPTION,
                 JOptionPane.WARNING_MESSAGE,
                 null,
                 options,
                 options[0])
             == 1) return;
       }
       try {
         PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter(output)));
         w.println("Searched for unused strings");
         w.println("Number of hits: " + table.getRowCount());
         w.println("");
         for (int i = 0; i < table.getRowCount(); i++) {
           w.println(
               "StringRef: "
                   + table.getTableItemAt(i).getObjectAt(1)
                   + " /* "
                   + table
                       .getTableItemAt(i)
                       .toString()
                       .replaceAll("\r\n", System.getProperty("line.separator"))
                   + " */");
         }
         w.close();
         JOptionPane.showMessageDialog(
             resultFrame,
             "Result saved to " + output,
             "Save complete",
             JOptionPane.INFORMATION_MESSAGE);
       } catch (IOException ex) {
         JOptionPane.showMessageDialog(
             resultFrame, "Error while saving " + output, "Error", JOptionPane.ERROR_MESSAGE);
         ex.printStackTrace();
       }
     }
   }
 }
예제 #6
0
 protected boolean informUserError(String msg) // this is just for SPPmon
     {
   if (!ExpCoordinator.isSPPMon()) return false;
   final String opt0 = "Try Again";
   final String opt1 = "Cancel";
   JLabel lbl = new JLabel(msg);
   TextFieldwLabel tfaddress = new TextFieldwLabel(30, "daemon addr:");
   tfaddress.setText(host);
   TextFieldwLabel tfport = new TextFieldwLabel(30, "daemon port:");
   tfport.setText(String.valueOf(port));
   Object[] params = {lbl, tfaddress, tfport};
   Object[] options = {opt0, opt1};
   int rtn =
       JOptionPane.showOptionDialog(
           ExpCoordinator.getMainWindow(),
           params,
           "Connection Error",
           JOptionPane.YES_NO_OPTION,
           JOptionPane.WARNING_MESSAGE,
           null,
           options,
           options[0]);
   if (rtn == JOptionPane.NO_OPTION) {
     connectionFailed();
     return false;
   } else {
     String tmp_host = host;
     boolean change = false;
     if (tfaddress.getText().length() > 0) tmp_host = tfaddress.getText();
     int tmp_port = port;
     if (tfport.getText().length() > 0) tmp_port = Integer.parseInt(tfport.getText());
     if (!tmp_host.equals(host)) {
       host = new String(tmp_host);
       change = true;
     }
     if (port != tmp_port) {
       port = tmp_port;
       change = true;
     }
     if (change) fireEvent(new ConnectionEvent(this, ConnectionEvent.ADDRESS_CHANGED));
     state = ConnectionEvent.CONNECTION_CLOSED;
     return (connect());
   }
 }
예제 #7
0
 private int saveExitDialog() {
   String[] Optionen = {"Yes", "No"};
   int Auswahl =
       JOptionPane.showOptionDialog(
           this,
           "Do you want to save your changes?",
           "Save?",
           JOptionPane.YES_NO_OPTION,
           JOptionPane.QUESTION_MESSAGE,
           null,
           Optionen,
           Optionen[0]);
   if (Auswahl == JOptionPane.YES_OPTION) {
     save();
     return 1;
   } else {
     return 0;
   }
 }
예제 #8
0
  // ask user for script file and name of new profile
  // return false if user cancelled operation
  private boolean getNewWkldInput(
      JFileChooser chooser, Object[] optionDlgMsg, StringBuffer name, StringBuffer scriptFile) {
    // let user select script file with queries
    boolean fileOk = false;
    int retval;
    File file = null;
    FileReader reader = null;
    while (!fileOk) {
      if ((retval = chooser.showDialog(this, "Ok")) != 0) {
        return false;
      }
      file = chooser.getSelectedFile();
      try {
        reader = new FileReader(file.getPath());
        fileOk = true;
        scriptFile.append(file.getPath());
      } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(
            this,
            "Selected script file does not exist",
            "Error: New Profile",
            JOptionPane.ERROR_MESSAGE);
      }
    }

    // let user select filename for profile
    int response =
        JOptionPane.showOptionDialog(
            this,
            optionDlgMsg,
            "New Profile",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE,
            null,
            null,
            null);
    if (response != JOptionPane.OK_OPTION) {
      return false;
    }
    JTextField textFld = (JTextField) optionDlgMsg[1];
    name.append(file.getParent() + "/" + textFld.getText());
    return true;
  }
예제 #9
0
  private void neuesLaufwerkDialog() {
    Object[] options = {"Quell", "Ziel", "Abbruch"};

    System.out.println("windowClosing()");

    int retValue =
        JOptionPane.showOptionDialog(
            null,
            "Neues Laufwerk wurde gefunden. Soll es eingebunden werden?",
            "Laufwerk endeckt",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            options,
            options[2]);

    if (retValue == JOptionPane.CANCEL_OPTION || retValue == JOptionPane.CLOSED_OPTION) return;
    else if (retValue == JOptionPane.YES_OPTION) addQListBoxEintrag(dateiAuswählen(neuesLaufwerk));
    else if (retValue == JOptionPane.NO_OPTION) addZListBoxEintrag(dateiAuswählen(neuesLaufwerk));
  }
예제 #10
0
  // Choose and run the app to test.
  private void displayAppFrame() {

    // Set up the frame for the file chooser.
    final JFrame appframe = new JFrame("Select Application");
    appframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Container contentPane = appframe.getContentPane();
    JFileChooser fileChooser = new JFileChooser(".");

    // Ask user what type of executable the program is in, display chooser accordingly.
    int isJar =
        JOptionPane.showOptionDialog(
            null,
            "Is the program a .jar file?",
            "Question",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            null,
            null);
    if (isJar == JOptionPane.YES_OPTION) {
      fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    } else if (isJar == JOptionPane.NO_OPTION) {
      fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    } else {
      fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    }
    contentPane.add(fileChooser, BorderLayout.CENTER);

    // Make a new action listener for the file chooser.
    ActionListener actionListener =
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {

            // Get the information to check if the file chosen is valid.
            JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource();
            String command = actionEvent.getActionCommand();

            // If the user cancels selecting a program.
            if (command.equals(JFileChooser.CANCEL_SELECTION)) {
              appframe.setVisible(false);
              appframe.dispose();
              return;
            }

            // If the file chosen is valid.
            if (command.equals(JFileChooser.APPROVE_SELECTION)) {
              // Retrieve the selected file and ask for the main class name.
              File f = theFileChooser.getSelectedFile();
              String className = JOptionPane.showInputDialog("Please enter the main class name: ");
              mainClass = className;
              programPath = f.getAbsolutePath();

              // Obtain the file URL.
              URL[] folderURL = new URL[1];
              String fileURL = null;
              String programName = "/";
              try {
                folderURL[0] = f.toURI().toURL();
                fileURL = new String(folderURL[0].toString());
              } catch (MalformedURLException e1) {
                System.err.println("File URL not correct.");
              }

              // check if OS is *nix, if so, add leading /
              String os = System.getProperty("os.name").toLowerCase();
              if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0) {
                fileURL = "/" + fileURL;
              }

              // Run the selected application.
              try {
                // Begin capturing the programs GUI.
                System.out.println("Before Capture: #Frames=" + Frame.getFrames().length);
                guiCapture.beginCapture();
                // Load the program through the CaptureAsYouGo
                guiCapture.loadApplication(className, folderURL, new String[] {});
                // Update the label that shows what program is running.
                programName = fileURL.substring(fileURL.lastIndexOf('/'));
                if (programName.length() == 1) {
                  programName = "Main Class - " + className;
                }
                appName.setText(programName);
              } catch (IOException e) {
                e.printStackTrace();
                System.out.println("TEST 1");
              } catch (Exception e) {
                e.printStackTrace();
                System.out.println("TEST 2");
              }

              // Make the file chooser disappear.
              appframe.setVisible(false);
              appframe.dispose();
            }
          }
        };

    // Add the action listener created above to file chooser, display it.
    fileChooser.addActionListener(actionListener);
    appframe.pack();
    appframe.setVisible(true);
  }