Normand Briere
2018-07-07 09ddd38fd4a8a7100c834a5e976f4796fae53541
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package timeflow.app.actions;
 
import timeflow.model.*;
import timeflow.app.TimeflowApp;
import timeflow.app.ui.*;
import timeflow.data.db.*;
import timeflow.format.field.FieldFormatCatalog;
import timeflow.format.file.DelimitedFormat;
 
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
 
public class ImportFromPasteAction extends TimeflowAction {
 
   public ImportFromPasteAction(TimeflowApp app)
   {
       super(app, "Paste From Spreadsheet / HTML...", null, "Import from copy-and-pasted data.");
   }
   
   public void actionPerformed(ActionEvent event) 
   {
       if (!app.checkSaveStatus())
           return;
       JTextArea text=new JTextArea(10,40);
       JScrollPane scroll=new JScrollPane(text);
       text.setText("Paste here! (replacing this :-)");
       text.setSelectionStart(0);
       text.setSelectionEnd(text.getText().length());
       Object[] options = {"Cancel", "Import"};
       int n = JOptionPane.showOptionDialog(app,
                   scroll,
                   "Import From Paste",
                   JOptionPane.YES_NO_CANCEL_OPTION,
                   JOptionPane.QUESTION_MESSAGE,
                   null,
                   options,
                   "Import");
       if (n==1)
       {
           try
           {
               String pasted=text.getText();
               String[][] data=DelimitedFormat.readArrayFromString(pasted, System.out);
               app.showImportEditor("Paste", data);
           }
           catch (Exception e)
           {
               app.showUserError(e);
           }
       }
   }
}