source: trunk/src/org/expeditee/importer/TextImporter.java@ 282

Last change on this file since 282 was 282, checked in by ra33, 16 years ago
File size: 1.6 KB
Line 
1package org.expeditee.importer;
2
3import java.awt.Color;
4import java.awt.Point;
5import java.io.BufferedReader;
6import java.io.File;
7import java.io.FileReader;
8import java.io.IOException;
9
10import org.expeditee.gui.FrameCreator;
11import org.expeditee.gui.FrameGraphics;
12import org.expeditee.gui.MessageBay;
13import org.expeditee.items.Item;
14import org.expeditee.items.Text;
15
16public 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}
Note: See TracBrowser for help on using the repository browser.