Hi,
I have a data file like this: 20020704001 plugin 20020704002 pluginfilter 20020704003 pluginframe I want to read the file data and display them with headings "ID" and "Name", the displaying results like the ImageJ's Results window: ------------------------------- ID Name 1 20020704001 plugin 2 20020704002 pluginfilter 3 20020704003 pluginframe ------------------------------- I read TextWindow class and TextPanel class, but don't know how to do it. Thanks! Yili Zhao |
In TextWindow constructor like
: public TextWindow(String title, String data, int width, int height) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The second parameter "data" is what you desire to display. To meet your needs, headings may be added by string operations. Like this, __________________________________________________ int count = 0; String data = "\t\tID\t\tName\r\n"; // Suppose "str" is ONE record of your data file data += Integer.toString(count++) + "\t\t" + str +"\r\n"; // Iterate the operation obove, it may produce the result you want. Good Luck. Yeliang ----- Original Message ----- From: "Yl Zhao" <[hidden email]> To: <[hidden email]> Sent: Wednesday, March 22, 2006 3:23 PM Subject: How to display file data in TextWindow or TextPanel? Hi, I have a data file like this: 20020704001 plugin 20020704002 pluginfilter 20020704003 pluginframe I want to read the file data and display them with headings "ID" and "Name", the displaying results like the ImageJ's Results window: ------------------------------- ID Name 1 20020704001 plugin 2 20020704002 pluginfilter 3 20020704003 pluginframe ------------------------------- I read TextWindow class and TextPanel class, but don't know how to do it. Thanks! Yili Zhao |
In reply to this post by panovr
However, this method can not set the headings of the TextWindow like
the ImageJ's ResultsTable class. What I want to do is: 1. read the data from the file 2. store every line into the ArrayList 3. display one record per line in the TextWindow: ------------------------------- ID Name 1 20020704001 plugin 2 20020704002 pluginfilter 3 20020704003 pluginframe ------------------------------- TextWindow uses TextPanel to display data, but I do not know how to format and dispay data in it. Yili Zhao yeliang wrote: In TextWindow constructor like : public TextWindow(String title, String data, int width, int height) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The second parameter "data" is what you desire to display. To meet your needs, headings may be added by string operations. Like this, __________________________________________________ int count = 0; String data = "\t\tID\t\tName\r\n"; // Suppose "str" is ONE record of your data file data += Integer.toString(count++) + "\t\t" + str +"\r\n"; // Iterate the operation obove, it may produce the result you want. |
There are many TextWindow examples in the ImageJ source code. You can
find them by downloading the source from <http://rsb.info.nih.gov/ij/download/src/> and using the Find macro at <http://rsb.info.nih.gov/ij/macros/Find.txt> to search for "TextWindow". Here are some of the ImageJ commands that use TextWindows: "List" button in Image>Color>Show LUT "List" button in Analyze>Histogram "List" button in Analyze>Plot Profile Plugins>Utilities>List Commands Plugins>Utilities>List Shortcuts You should also check out the TextWindow API at: http://rsb.info.nih.gov/ij/developer/api/ij/text/TextWindow.html -wayne On Mar 23, 2006, at 2:21 AM, zhao yl wrote: > However, this method can not set the headings of the TextWindow like > the ImageJ's ResultsTable class. > What I want to do is: > 1. read the data from the file > 2. store every line into the ArrayList > 3. display one record per line in the TextWindow: > ------------------------------- > ID Name > 1 20020704001 plugin > 2 20020704002 pluginfilter > 3 20020704003 pluginframe > ------------------------------- > TextWindow uses TextPanel to display data, but I do not know how to > format and dispay data in it. > > Yili Zhao > > yeliang wrote: > > In TextWindow constructor like > : public TextWindow(String title, String data, int width, int height) > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > The second parameter "data" is what you desire to display. > > To meet your needs, headings may be added by string operations. > > Like this, > __________________________________________________ > int count = 0; > String data = "\t\tID\t\tName\r\n"; > // Suppose "str" is ONE record of your data file > data += Integer.toString(count++) + "\t\t" + str +"\r\n"; > // Iterate the operation obove, it may produce the result you want. > |
In reply to this post by panovr
Hi,
thanks Wayne for the help, now I can display the file data in a TextWindow. The data is like: 1 20020704001 PlugIn 2 20020704002 PlugInFilter 3 20020704003 PlugInFrame This is the sourcecode: import ij.*; import ij.text.*; import ij.util.*; import ij.plugin.PlugIn; import java.util.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Record_Display implements PlugIn { public void run(String arg) { listRecords(); } public void listRecords() { File f = new File("plugins/demos/data.txt"); FileReader fr; BufferedReader br; ArrayList<String> al = new ArrayList<String>(); try { fr = new FileReader(f); br = new BufferedReader(fr); String s; String[] ss; while ((s = br.readLine()) != null) { ss = Tools.split(s, " "); al.add(ss[0] + "\t" + ss[1] + "\t" + ss[2]); } br.close(); } catch (IOException e) { e.printStackTrace(); } showList("Record Display", "Number\tID\tName", al); } void showList(String title, String headings, ArrayList<String> al) { String[] list = new String[al.size()]; al.toArray((String[])list); StringSorter.sort(list); StringBuffer sb = new StringBuffer(); for (int i = 0; i < list.length; i++) { sb.append(list[i]); sb.append("\n"); } TextWindow tw = new TextWindow(title, headings, sb.toString(), 300, 400); } } By the way, how can I find the source of the ImageJ's Menu: "File"->"Import"->"Text File..."? Sincerely Yili Zhao |
Zhao xiansheng,
> By the way, how can I find the source of the ImageJ's Menu: > "File"->"Import"->"Text File..."? Such things are encoded in the file "IJ_Props.txt", where it says: import05="Text File... ",ij.plugin.TextFileReader hence it seems to be ij/plugin/TextFileReader.java Sincerely Joachim ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ |
In reply to this post by panovr
Thanks for posting your solution. It is interesting to see the your
method to get tabular data into ImageJ. Ben zhao yl wrote: > Hi, > thanks Wayne for the help, now I can display the file data in a TextWindow. > The data is like: > > 1 20020704001 PlugIn > 2 20020704002 PlugInFilter > 3 20020704003 PlugInFrame > > This is the sourcecode: > > import ij.*; > import ij.text.*; > import ij.util.*; > import ij.plugin.PlugIn; > import java.util.*; > import java.awt.*; > import java.awt.event.*; > import java.io.*; > > public class Record_Display implements PlugIn { > > public void run(String arg) { > listRecords(); > } > > public void listRecords() { > File f = new File("plugins/demos/data.txt"); > FileReader fr; > BufferedReader br; > ArrayList<String> al = new ArrayList<String>(); > try { > fr = new FileReader(f); > br = new BufferedReader(fr); > String s; > String[] ss; > while ((s = br.readLine()) != null) { > ss = Tools.split(s, " "); > al.add(ss[0] + "\t" + ss[1] + "\t" + ss[2]); > } > br.close(); > } catch (IOException e) { > e.printStackTrace(); > } > showList("Record Display", "Number\tID\tName", al); > } > > void showList(String title, String headings, ArrayList<String> al) { > String[] list = new String[al.size()]; > al.toArray((String[])list); > StringSorter.sort(list); > StringBuffer sb = new StringBuffer(); > for (int i = 0; i < list.length; i++) { > sb.append(list[i]); > sb.append("\n"); > } > TextWindow tw = new TextWindow(title, headings, sb.toString(), > 300, 400); > } > } > > By the way, how can I find the source of the ImageJ's Menu: > "File"->"Import"->"Text File..."? > > Sincerely > Yili Zhao > |
Free forum by Nabble | Edit this page |