예제 #1
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();
       }
     }
   }
 }
예제 #2
0
 public void valueChanged(ListSelectionEvent event) {
   if (table.getSelectedRow() == -1) textArea.setText(null);
   else {
     TableItem item = table.getTableItemAt(table.getSelectedRow());
     textArea.setText(item.toString());
   }
   textArea.setCaretPosition(0);
 }
예제 #3
0
 public String getText(int nr) {
   if (nr < 0 || nr >= table.getRowCount()) return null;
   return table.getTableItemAt(nr).toString();
 }