SHARE
TWEET

moa TaskManagerPanel patch

draxus May 23rd, 2011 263 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- moa-svn/moa-datastream/trunk/src/main/java/moa/gui/TaskManagerPanel.java
  2. +++ machine-learning-incremental/moa-datastream/trunk/src/main/java/moa/gui/TaskManagerPanel.java
  3. @@ -24,11 +24,18 @@
  4.  import java.awt.Dimension;
  5.  import java.awt.event.ActionEvent;
  6.  import java.awt.event.ActionListener;
  7. +import java.io.BufferedWriter;
  8. +import java.io.File;
  9. +import java.io.FileWriter;
  10. +import java.io.IOException;
  11. +import java.io.PrintWriter;
  12.  import java.util.ArrayList;
  13.  import java.util.List;
  14.  
  15.  import javax.swing.JButton;
  16. +import javax.swing.JFileChooser;
  17.  import javax.swing.JFrame;
  18. +import javax.swing.JOptionPane;
  19.  import javax.swing.JPanel;
  20.  import javax.swing.JProgressBar;
  21.  import javax.swing.JScrollPane;
  22. @@ -61,6 +68,8 @@
  23.      private static final long serialVersionUID = 1L;
  24.  
  25.      public static final int MILLISECS_BETWEEN_REFRESH = 600;
  26. +    
  27. +    public static String exportFileExtension = "log";
  28.  
  29.      public class ProgressCellRenderer extends JProgressBar implements
  30.              TableCellRenderer {
  31. @@ -187,6 +196,10 @@
  32.      protected JButton cancelTaskButton = new JButton("Cancel");
  33.  
  34.      protected JButton deleteTaskButton = new JButton("Delete");
  35. +    
  36. +    protected JButton saveLogButton = new JButton("Save Log");
  37. +    
  38. +    protected JButton setTaskButton = new JButton("Set task manually");
  39.  
  40.      protected PreviewPanel previewPanel;
  41.  
  42. @@ -213,6 +226,8 @@
  43.          controlPanel.add(this.resumeTaskButton);
  44.          controlPanel.add(this.cancelTaskButton);
  45.          controlPanel.add(this.deleteTaskButton);
  46. +        controlPanel.add(this.saveLogButton);
  47. +        controlPanel.add(this.setTaskButton);
  48.          setLayout(new BorderLayout());
  49.          add(configPanel, BorderLayout.NORTH);
  50.          add(new JScrollPane(this.taskTable), BorderLayout.CENTER);
  51. @@ -268,6 +283,21 @@
  52.              @Override
  53.              public void actionPerformed(ActionEvent arg0) {
  54.                  deleteSelectedTasks();
  55. +            }
  56. +        });
  57. +        this.saveLogButton.addActionListener(new ActionListener() {
  58. +              
  59. +            @Override
  60. +            public void actionPerformed(ActionEvent arg0) {
  61. +                saveLogSelectedTasks();
  62. +             }
  63. +         });
  64. +        this.setTaskButton.addActionListener(new ActionListener() {
  65. +              
  66. +            @Override
  67. +            public void actionPerformed(ActionEvent arg0) {
  68. +               String newTaskString = JOptionPane.showInputDialog("Insert command line");
  69. +                setTaskString(newTaskString);
  70.              }
  71.          });
  72.          javax.swing.Timer updateListTimer = new javax.swing.Timer(
  73. @@ -354,6 +384,37 @@
  74.          }
  75.          this.taskTableModel.fireTableDataChanged();
  76.      }
  77. +    
  78. +       public void saveLogSelectedTasks() {
  79. +               String tasksLog = "";
  80. +               TaskThread[] selectedTasks = getSelectedTasks();
  81. +               for (TaskThread thread : selectedTasks) {
  82. +                       tasksLog += ((OptionHandler) thread.getTask()).getCLICreationString(MainTask.class) + "\n";
  83. +               }
  84. +              
  85. +               JFileChooser fileChooser = new JFileChooser();
  86. +               fileChooser.setAcceptAllFileFilterUsed(true);
  87. +               fileChooser.addChoosableFileFilter(new FileExtensionFilter(
  88. +                       exportFileExtension));
  89. +               if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
  90. +                   File chosenFile = fileChooser.getSelectedFile();
  91. +                   String fileName = chosenFile.getPath();
  92. +                   if (!chosenFile.exists()
  93. +                           && !fileName.endsWith(exportFileExtension)) {
  94. +                       fileName = fileName + "." + exportFileExtension;
  95. +                   }
  96. +                   try {
  97. +                       PrintWriter out = new PrintWriter(new BufferedWriter(
  98. +                               new FileWriter(fileName)));
  99. +                       out.write(tasksLog);
  100. +                       out.close();
  101. +                   } catch (IOException ioe) {
  102. +                       GUIUtils.showExceptionDialog(
  103. +                               this.saveLogButton,
  104. +                               "Problem saving file " + fileName, ioe);
  105. +                   }
  106. +               }
  107. +           }
  108.  
  109.      private static void createAndShowGUI() {
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top