stuck with problem!
Posted by sridevi polavaram on Oct 03, 2006; 8:45pm
URL: http://imagej.273.s1.nabble.com/stuck-with-problem-tp3701413.html
Dear List,
This is the first time i am posing in this forum. I am trying to develop a
simple plugin that allows user to
(a) draw lines interactively and saves the xy points in a file,
(b) display lines by reading from files.
I am reusing some of neuron_morpho code and also the imagej API and source
code is itself very helpful.
But I am having a strange problem when i am trying to display lines by
reading from the input file, here is the code snippet:
public void actionPerformed(ActionEvent e) {
String label = e.getActionCommand();
if (label==null)
return;
img = WindowManager.getCurrentImage();
if (img==null) {
IJ.beep();
IJ.showStatus("No image");
return;
}
//here i am trying to read a file and display it on the image window. img is
an object of ImagePlus class. the input file contains x-coord and y-coord
seperated by a space in each line
if(label=="Open"){
IJ.showStatus("entered Open");
String line[] = new String[4];
JFileChooser chooser = new JFileChooser(morphoFile);
if ( morphoFile.isFile() ) {
chooser.setSelectedFile(morphoFile);
}
int result = chooser.showOpenDialog(frame);
if (result == JFileChooser.CANCEL_OPTION) return;
morphoFile = chooser.getSelectedFile();
try {
FileReader readIn = new FileReader(morphoFile);
BufferedReader in = new BufferedReader(readIn);
String inLine;
String fLine="";
int linectr=0;
int ctr=0;
//ControlPanel cp = new ControlPanel();
//NewImage nimg = new NewImage();
//ImagePlus imp = nimg.createRGBImage("Draw a Line",400,400,0,0);
//int[] xy = new int[4];
//IJ.showStatus("reading file"+morphoFile.getName()+"
"+morphoFile.exists());
//here i am reading 2 lines at a time so that i get two endpoints to draw a
line
while ((inLine = in.readLine()) != null & linectr <= 1) {
fLine = fLine + " " + inLine;
++linectr;
if(linectr > 1){
StringTokenizer st = new StringTokenizer(fLine);
while(st.hasMoreTokens()){
line[ctr++] = st.nextToken();
}
//this line is printed just fine!
//IJ.showStatus(line[0]+" "+line[1]+" "+line[2]+" "+line[3]);
canvas.setImageUpdated();
//int[] xy = cp.s2ints(fLine);
//the problem is here. this is a simple routine that converts String to int
using Integer.parseInt(s). But any showStatus messages that i try to print
after calling this routin doesn't show at all!!
int[] xy = transfer(line);
//none of these prints work!
IJ.showStatus("len:"+xy.length);
//IJ.showMessage(xy[0]+" "+xy[1]+" "+xy[2]+" "+xy[3]);
//IJ.showMessage("pnt:"+x_1+" "+y_1);
//Line ln = new Line(canvas.offScreenX(xy[0]),canvas.offScreenY
(xy[1]),canvas.offScreenX(xy[2]),canvas.offScreenY(xy[3]));
//imp.setRoi(ln);
//These two lines should hopefully draw a line! am i right? but i don't get
anything displayed on the image window!
img.getProcessor().moveTo(canvas.offScreenX(xy[0]),
canvas.offScreenY(xy[1]));
img.getProcessor().lineTo(canvas.offScreenX(xy[2]),
canvas.offScreenY(xy[3]));
//imp.drawLine(x_1,y_1,x_2,y_2);
//img.setProcessor("Draw A Line",imp);
img.updateAndRepaintWindow();
linectr=0;
ctr=0;
}
}
}catch(Exception ex){IJ.showStatus(ex.getMessage());}//nothing is
shown here as exception
}
// small routine that converts string to int
int[] transfer(String[] line){
int[] xycoord = new int[4];
try{
// I can see this line
// IJ.showStatus(line[0]+" "+line[1]+" "+line[2]+"
"+line[3]);
int int0 = Integer.parseInt(line[0].trim());
// But not this line. for some reason as soon as i use parseInt i don't see
any messages on the panel!! why?
IJ.showMessage("int:"+int0);
xycoord[0] =int0;
xycoord[1] = Integer.parseInt(line[1].trim());
xycoord[2] =Integer.parseInt(line[2].trim());
xycoord[3] =Integer.parseInt(line[3].trim());
IJ.showStatus(xycoord[0]+" "+xycoord[1]+" "+xycoord[2]+"
"+xycoord[3]);
/*
xycoord[0] = canvas.offScreenX(x_1);
xycoord[1] = canvas.offScreenY(y_1);
xycoord[2] = canvas.offScreenX(x_2);
xycoord[3] = canvas.offScreenY(y_2);
*/
}catch(NumberFormatException nfe){IJ.showMessage("entered
exc");IJ.showMessage(nfe.getMessage());}
return xycoord;
}
I would really appreciate if any of you can throw some light on this! I just
have no clue what i should do
-Thanks a lot
Sridevi.