1 | package org.expeditee.importer;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.awt.Point;
|
---|
5 | import java.io.BufferedReader;
|
---|
6 | import java.io.File;
|
---|
7 | import java.io.FileReader;
|
---|
8 | import java.io.IOException;
|
---|
9 |
|
---|
10 | import org.expeditee.gui.FrameCreator;
|
---|
11 | import org.expeditee.gui.FrameGraphics;
|
---|
12 | import org.expeditee.gui.MessageBay;
|
---|
13 | import org.expeditee.items.Item;
|
---|
14 | import org.expeditee.items.Text;
|
---|
15 |
|
---|
16 | public class TextImporter implements FileImporter {
|
---|
17 |
|
---|
18 | public TextImporter() {
|
---|
19 | super();
|
---|
20 | }
|
---|
21 |
|
---|
22 | public Item importFile(final File f, Point location) throws IOException {
|
---|
23 | if (location == null || f == null) {
|
---|
24 | return null;
|
---|
25 | }
|
---|
26 | final String fullPath = f.getAbsolutePath();
|
---|
27 |
|
---|
28 | final Text source = FrameDNDTransferHandler.importString(f.getPath(),
|
---|
29 | location);
|
---|
30 |
|
---|
31 | // Create a frameCreator to write the text
|
---|
32 | final FrameCreator frames = new FrameCreator(f.getName());
|
---|
33 |
|
---|
34 | new Thread() {
|
---|
35 | public void run() {
|
---|
36 | try {
|
---|
37 | // Open a file stream to the file
|
---|
38 | BufferedReader br = new BufferedReader(new FileReader(
|
---|
39 | fullPath));
|
---|
40 |
|
---|
41 | MessageBay.displayMessage("Importing " + f.getName() + "...");
|
---|
42 |
|
---|
43 | // Read in the text
|
---|
44 | String nextLine;
|
---|
45 | while ((nextLine = br.readLine()) != null) {
|
---|
46 | frames.addText(nextLine, null, null, null, false);
|
---|
47 | }
|
---|
48 |
|
---|
49 | frames.save();
|
---|
50 | source.setLink(frames.getName());
|
---|
51 | MessageBay.displayMessage(f.getName() + " import complete", Color.GREEN);
|
---|
52 | FrameGraphics.requestRefresh(true);
|
---|
53 | } catch (Exception e) {
|
---|
54 | e.printStackTrace();
|
---|
55 | MessageBay.errorMessage(e.getMessage());
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }.start();
|
---|
59 | FrameGraphics.refresh(true);
|
---|
60 | return source;
|
---|
61 | }
|
---|
62 | }
|
---|