| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | package org.pathvisio.example; |
|---|
| 18 | |
|---|
| 19 | import java.io.BufferedReader; |
|---|
| 20 | import java.io.File; |
|---|
| 21 | import java.io.FileReader; |
|---|
| 22 | import java.io.IOException; |
|---|
| 23 | |
|---|
| 24 | import org.pathvisio.gui.swing.PvDesktop; |
|---|
| 25 | import org.pathvisio.model.ConverterException; |
|---|
| 26 | import org.pathvisio.model.ObjectType; |
|---|
| 27 | import org.pathvisio.model.Pathway; |
|---|
| 28 | import org.pathvisio.model.PathwayElement; |
|---|
| 29 | import org.pathvisio.model.PathwayImporter; |
|---|
| 30 | import org.pathvisio.plugin.Plugin; |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | public class ExImporter implements Plugin |
|---|
| 39 | { |
|---|
| 40 | private PvDesktop desktop; |
|---|
| 41 | |
|---|
| 42 | public void init(PvDesktop desktop) |
|---|
| 43 | { |
|---|
| 44 | this.desktop = desktop; |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | desktop.getSwingEngine().getEngine().addPathwayImporter(new TextLinesImporter()); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public void done() {} |
|---|
| 51 | |
|---|
| 52 | private static class TextLinesImporter implements PathwayImporter |
|---|
| 53 | { |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | public Pathway doImport(File file) |
|---|
| 62 | throws ConverterException |
|---|
| 63 | { |
|---|
| 64 | Pathway pathway = new Pathway(); |
|---|
| 65 | try |
|---|
| 66 | { |
|---|
| 67 | |
|---|
| 68 | double xpos = 300; |
|---|
| 69 | double ypos = 300; |
|---|
| 70 | double height = 300; |
|---|
| 71 | double width = 1500; |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | BufferedReader reader = null; |
|---|
| 75 | reader = new BufferedReader(new FileReader (file)); |
|---|
| 76 | String line; |
|---|
| 77 | |
|---|
| 78 | while ((line = reader.readLine()) != null) |
|---|
| 79 | { |
|---|
| 80 | line = line.trim(); |
|---|
| 81 | |
|---|
| 82 | if (line.equals ("")) { continue; } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | PathwayElement elt = PathwayElement.createPathwayElement(ObjectType.LABEL); |
|---|
| 86 | elt.setMWidth(width); |
|---|
| 87 | elt.setMHeight(height); |
|---|
| 88 | elt.setMTop(ypos); |
|---|
| 89 | elt.setMLeft(xpos); |
|---|
| 90 | elt.setTextLabel(line); |
|---|
| 91 | |
|---|
| 92 | pathway.add(elt); |
|---|
| 93 | ypos += height; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | pathway.getMappInfo().setMapInfoName(file.getName()); |
|---|
| 97 | reader.close(); |
|---|
| 98 | } |
|---|
| 99 | catch (IOException ex) |
|---|
| 100 | { |
|---|
| 101 | throw new ConverterException (ex); |
|---|
| 102 | } |
|---|
| 103 | return pathway; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | private static final String[] EXTENSIONS = new String[] { "txt" }; |
|---|
| 107 | |
|---|
| 108 | public String[] getExtensions() |
|---|
| 109 | { |
|---|
| 110 | return EXTENSIONS; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | public String getName() |
|---|
| 114 | { |
|---|
| 115 | return "Lines from text file"; |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | } |
|---|