-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOpenComet_.java
692 lines (604 loc) · 27.8 KB
/
OpenComet_.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
/**
* OpenComet_.java
* Created in 2012 by Benjamin Gyori
* National University of Singapore
* e-mail: [email protected]
*
* OpenComet_.java is the outside wrapper for the OpenComet plug-in.
* It displays the GUI and manages all input-output functions
* by the plug-in.
*
* This plugin is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* This work is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* When you use this plugin for your work, please cite
* Gyori BM, Venkatachalam G, et al. OpenComet: An automated tool for
* comet assay image analysis
* You should have received a copy of the GNU General Public License
* along with this plugin; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
import ij.*;
import ij.process.*;
import ij.gui.*;
import ij.plugin.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
//import CometStatistics.CometAnalyzer;
import java.util.HashMap;
import java.util.Map;
public class OpenComet_ implements PlugIn, MouseListener {
//private JLabel inFilesLabel, outDirLabel;
private JLabel inFilesStatusLabel, outDirStatusLabel;
private JButton inFilesButton, outDirButton, runButton;
private JButton updateOutputButton;
private JButton liveButton;
private ActionListener inFilesButtonLis, outDirButtonLis, runButtonLis;
private ActionListener updateOutputButtonLis;
private ActionListener liveButtonLis;
private JFileChooser inFileChooser, outDirChooser;
private JTextField outFileNameField;
private JCheckBox bgCorrectCheck;
private JRadioButton headFindingAuto, headFindingProfile;
private JRadioButton headFindingBrightest;
private int cometOptions;
private static Color labelInvalidColor = new Color(200,0,0);
private static Color labelValidColor = new Color(0,150,0);
File[] inFiles;
File outDir;
String outDirPath;
String outFileName;
private static Color cometValidColor = Color.red;
private static Color cometInvalidColor = Color.gray;
private static Color cometOutlierColor = Color.orange;
private static Color cometColor = Color.yellow;
private static Color headColor = Color.green;
private static Color tailColor = Color.blue;
private HashMap<ImagePlus,Comet[]> Comets;
public OpenComet_(){}
public void run(String arg) {
IJ.log("Welcome to OpenComet v1.3.1!");
makeLayout();
updateOutputButton.setEnabled(false);
}
private void runOnInput(int type){
// Make an instance of the comet analyzer class
CometAnalyzer cometAnalyzer = new CometAnalyzer();
Comets = new HashMap<ImagePlus,Comet[]>();
cometOptions = 0;
// Setup comet analysis options
if(bgCorrectCheck.isSelected())
cometOptions |= CometAnalyzer.COMETFIND_BGCORRECT;
if(headFindingAuto.isSelected())
cometOptions |= CometAnalyzer.HEADFIND_AUTO;
if(headFindingProfile.isSelected())
cometOptions |= CometAnalyzer.HEADFIND_PROFILE;
if(headFindingBrightest.isSelected())
cometOptions |= CometAnalyzer.HEADFIND_BRIGHTEST;
String tmpText = outFileNameField.getText();
if((tmpText!=null) && (tmpText.length()>1)){
outFileName = tmpText;
}
IJ.log(cometOptions+"");
if(type==0) {
// Open each input image and run comet analysis
// Iterate over each input file
for(int i=0;i<inFiles.length;i++){
// Try to open file as image
ImagePlus imp = IJ.openImage(inFiles[i].getPath());
// If image could be opened, run comet analysis
if(imp!=null){
String imageKey = inFiles[i].getName();
IJ.log("Run started, image key: "+ imageKey);
Comet[] cometsOut =
cometAnalyzer.cometAnalyzerRun(imp, cometOptions);
IJ.log("Run complete, image key: "+ imageKey);
storeComets(cometsOut,imp,imageKey);
// if(cometsOut!=null && cometsOut.length>0){
// ImageProcessor ip = imp.getProcessor();
// int imgType = imp.getType();
// ColorProcessor ip_out = null;
// if(imgType == 0){
// TypeConverter t = new TypeConverter(ip,false);
// ip_out = (ColorProcessor)t.convertToRGB();
// }
//RGB
// else if(imgType == 4){
// ip_out = (ColorProcessor)(ip.duplicate());
// }
// String imgOutFileName = imageKey +"_out.tif";
// ImagePlus img_out = new ImagePlus(imgOutFileName,ip_out);
// Comets.put(img_out, cometsOut);
// for(int j=0;j<cometsOut.length;j++){
// if(cometsOut[j].status==Comet.VALID)
// printArray(cometsOut[j].cometProfile);
// }
// Overlay cometOverlay = new Overlay();
// drawComets(ip_out, cometOverlay, cometsOut);
// img_out.setOverlay(cometOverlay);
// img_out.show();
// img_out.getCanvas().addMouseListener(this);
// ImagePlus img_out_save = img_out.flatten();
// IJ.save(img_out_save, outDirPath + imgOutFileName);
// }
// else {
// IJ.log("No comets stored");
// }
}
else {
IJ.log("Could not open " + inFiles[i].getName() +
", unsupported format");
}
}
}
else {
ImageWindow imw = WindowManager.getCurrentWindow();
if(imw!=null){
ImagePlus img = imw.getImagePlus();
ImagePlus img2 = imw.getImagePlus().duplicate();
if(img!=null){
Comet[] cometsOut =
cometAnalyzer.cometAnalyzerRun(img,cometOptions);
if(cometsOut==null || cometsOut.length==0){
IJ.log("No comets found.");
}
else {
IJ.log("Number of comets found: "+cometsOut.length);
}
storeComets(cometsOut,img2,outFileName+"_image");
}
}
}
printComets(outFileName);
updateOutputButton.setEnabled(true);
runButton.setEnabled(false);
}
private void storeComets(Comet[] cometsOut, ImagePlus imp,
String imageKey){
ImageProcessor ip = imp.getProcessor();
int imgType = imp.getType();
ColorProcessor ip_out = null;
if(imgType == ImagePlus.GRAY8){
TypeConverter t = new TypeConverter(ip,false);
ip_out = (ColorProcessor)t.convertToRGB();
}
else if (imgType == ImagePlus.GRAY16 || imgType == ImagePlus.GRAY32){
ImageProcessor ip_temp = ip.convertToByte(true);
TypeConverter t = new TypeConverter(ip_temp,false);
ip_out = (ColorProcessor)t.convertToRGB();
}
else if(imgType == ImagePlus.COLOR_RGB){
ip_out = (ColorProcessor)(ip.duplicate());
}
else {
IJ.log("Unhandled image type: "+imgType);
}
String imgOutFileName = imageKey +"_out.tif";
ImagePlus img_out = new ImagePlus(imgOutFileName,ip_out);
if(cometsOut!=null && cometsOut.length>0){
Comets.put(img_out, cometsOut);
for(int j=0;j<cometsOut.length;j++){
if(cometsOut[j].status==Comet.VALID)
printArray(cometsOut[j].cometProfile);
}
Overlay cometOverlay = new Overlay();
drawComets(ip_out, cometOverlay, cometsOut);
img_out.setOverlay(cometOverlay);
} else {
IJ.log("No comets in image stored.");
}
img_out.show();
img_out.getCanvas().addMouseListener(this);
ImagePlus img_out_save = img_out.flatten();
IJ.save(img_out_save, outDirPath + imgOutFileName);
}
private void drawComets(ImageProcessor ip, Overlay overlay, Comet[] comets){
for(int i=0;i<comets.length;i++){
if(comets[i].status == Comet.INVALID){
comets[i].cometRoi.setStrokeColor(cometInvalidColor);
overlay.add(comets[i].cometRoi);
}
else if (comets[i].status == Comet.OUTLIER){
comets[i].cometRoi.setStrokeColor(cometOutlierColor);
comets[i].headRoi.setStrokeColor(cometOutlierColor);
//overlay.add(comets[i].cometRoi);
overlay.add(comets[i].oldRoi);
overlay.add(comets[i].headRoi);
ip.setColor(Color.red);
TextRoi textRoi = new TextRoi(comets[i].x+comets[i].width,
comets[i].y, "" + comets[i].id,
new Font("Arial", Font.BOLD, 22));
textRoi.drawPixels(ip);
}
else if(comets[i].status == Comet.VALID){
comets[i].cometRoi.setStrokeColor(cometValidColor);
comets[i].headRoi.setStrokeColor(cometValidColor);
overlay.add(comets[i].cometRoi);
overlay.add(comets[i].headRoi);
ip.setColor(Color.red);
TextRoi textRoi = new TextRoi(comets[i].x+comets[i].width,
comets[i].y, ""+comets[i].id,
new Font("Arial", Font.BOLD, 22));
textRoi.drawPixels(ip);
ImageProcessor ipProfile = getCometProfilePlot(comets[i]);
ip.copyBits(ipProfile, comets[i].x,
comets[i].y,Blitter.COPY_TRANSPARENT);
}
}
}
private ImageProcessor getCometProfilePlot(Comet comet){
ImageProcessor ip = new ColorProcessor(comet.width, comet.height);
ip.invert();
double heightStep = comet.height / comet.profileMax;
drawProfilePlot(ip, comet.cometProfile, cometColor, heightStep);
drawProfilePlot(ip, comet.headProfile, headColor, heightStep);
drawProfilePlot(ip, comet.tailProfile, tailColor, heightStep);
return ip;
}
private void drawProfilePlot(ImageProcessor ip, double[] profile,
Color col, double heightStep){
int height = ip.getHeight();
int width = ip.getWidth();
int x1,x2,y1,y2;
ip.setColor(col);
for(int x=0;x<width-1;x++){
x1 = x; x2 = x+1;
y1 = (int)((height - 1) - profile[x]*heightStep);
y2 = (int)((height - 1) - profile[x+1]*heightStep);
ip.drawLine(x1,y1,x2,y2);
}
}
private void printComets(String fileName){
// Setup output data file
try {
String outFileName = outDirPath + fileName + ".xls";
FileOutputStream fos = new FileOutputStream(outFileName);
BufferedOutputStream bos = new BufferedOutputStream(fos);
PrintWriter outPrintWriter = new PrintWriter(bos);
IJ.log("Out filename: " + outFileName);
String sep = "\t";
String headerstr = "FileName" + sep + "Num" + sep +
"Flag" + sep + "CometArea" + sep +
"CometIntensity" + sep +
"CometLength" + sep + "CometDNA" + sep +
"HeadArea" + sep + "HeadIntensity" + sep +
"HeadLength" + sep + "HeadDNA"+ sep +
"HeadDNAPercent" + sep +
"TailArea" + sep + "TailIntensity" + sep +
"TailLength" + sep + "TailDNA"+ sep +
"TailDNAPercent" + sep + "TailMoment"
+ sep + "OliveMoment";
outPrintWriter.println(headerstr);
for (Map.Entry<ImagePlus,Comet[]> element : Comets.entrySet()) {
ImagePlus imp = element.getKey();
String imgTitle = imp.getTitle();
IJ.log("Image title: "+imgTitle);
int endIdx = imgTitle.lastIndexOf('_');
if(endIdx > 0){
String imageKey = imgTitle.substring(0,endIdx);
Comet[] imageComets = element.getValue();
for(int i=0;i<imageComets.length;i++){
if(imageComets[i].status != Comet.INVALID){
String outstr = imageKey + sep;
outstr += imageComets[i].getMeasurementString(sep);
outPrintWriter.println(outstr);
}
}
}
}
CometStatistics cometStats = new CometStatistics(Comets,Comet.VALID);
String outstr = cometStats.getStatisticsString(sep,"normal");
outPrintWriter.print(outstr);
cometStats = new CometStatistics(Comets,Comet.VALID|Comet.OUTLIER);
outstr = cometStats.getStatisticsString(sep,"normal+outlier");
outPrintWriter.print(outstr);
outPrintWriter.close();
}
catch (Exception ex) {
IJ.log(ex.toString());
}
}
private void makeLayout(){
ij.util.Java2.setSystemLookAndFeel();
JDialog mainDialog = new JDialog(ij.IJ.getInstance(),"OpenComet",false);
mainDialog.setLocationRelativeTo(ij.IJ.getInstance());
mainDialog.setLayout(new BorderLayout(0,10));
//ImagePlus imlogo = IJ.openImage("opencometlogo.gif");
//if (imlogo != null) {
// mainDialog.setIconImage(imlogo.getImage());
// }
inFileChooser = new JFileChooser();
outDirChooser = new JFileChooser();
runButtonLis = new ActionListener(){
public void actionPerformed(ActionEvent e){
if((inFiles == null) || (inFiles.length == 0)){
IJ.log("Select input files");
}
else if((outDir == null)){
IJ.log("Select output directory");
}
else {
runOnInput(0);
}
}
};
liveButtonLis = new ActionListener(){
public void actionPerformed(ActionEvent e){
if((outDir == null)){
IJ.log("Select output directory");
}
else {
runOnInput(1);
}
}
};
inFilesButtonLis = new ActionListener(){
public void actionPerformed(ActionEvent e) {
inFileChooser.setDialogTitle("Input Files");
inFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
inFileChooser.setMultiSelectionEnabled(true);
inFileChooser.showOpenDialog(null);
inFiles = inFileChooser.getSelectedFiles();
if(inFiles.length == 0){
inFilesStatusLabel.setText("Choose input files");
inFilesStatusLabel.setForeground(labelInvalidColor);
}
else if(inFiles.length == 1){
inFilesStatusLabel.setText("1 file selected");
inFilesStatusLabel.setForeground(labelValidColor);
}
else {
inFilesStatusLabel.setText(inFiles.length+" files selected");
inFilesStatusLabel.setForeground(labelValidColor);
}
inFilesStatusLabel.repaint();
}
};
outDirButtonLis = new ActionListener(){
public void actionPerformed(ActionEvent e){
outDirChooser.setDialogTitle("Output Directory");
outDirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
outDirChooser.setMultiSelectionEnabled(false);
int result = outDirChooser.showOpenDialog(null);
outDir = outDirChooser.getSelectedFile();
if(result==0){
outDirPath = outDir+"";
int len = outDirPath.length();
if(outDirPath.charAt(len-1) != File.separatorChar){
outDirPath = outDirPath + File.separatorChar;
}
String outDirStatusLabelText = outDirPath ;
if(len > 25){
outDirStatusLabelText = outDirPath.substring(0,12) +
"..." + outDirPath.substring(len-12,len);
}
boolean canWrite = checkWriteAccess(outDirPath);
if(canWrite) {
outDirStatusLabel.setText(outDirStatusLabelText);
outDirStatusLabel.setForeground(labelValidColor);
} else {
outDirStatusLabel.setText(outDirStatusLabelText);
outDirStatusLabel.setForeground(labelInvalidColor);
}
}
else {
outDirStatusLabel.setText("Choose output directory");
outDirStatusLabel.setForeground(labelInvalidColor);
}
outDirStatusLabel.repaint();
}
};
updateOutputButtonLis = new ActionListener(){
public void actionPerformed(ActionEvent e){
printComets(outFileName + "_update");
for (Map.Entry<ImagePlus,Comet[]> element : Comets.entrySet()) {
ImagePlus imp = element.getKey();
if(imp.getCanvas()==null) continue;
ImagePlus impSave = imp.flatten();
IJ.save(impSave, outDirPath + imp.getTitle());
}
}
};
// liveButtonLis = new ActionListener(){
// public void actionPerformed(ActionEvent e){
// ImageWindow imw = WindowManager.getCurrentWindow();
// if(imw!=null){
// ImagePlus img = imw.getImagePlus();
// if(img!=null){
// CometAnalyzer cometAnalyzer = new CometAnalyzer();
// Comet[] cometsOut = cometAnalyzer.cometAnalyzerRun(img,3);
// IJ.log("Number of comets found: "+cometsOut.length);
// }
// }
// }
// };
// Set up main dialog layout
Panel mainPanel = new Panel();
mainPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2,2,8,8);
// Input files label
JLabel inFilesLabel = new JLabel("Input files");
c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 0;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(inFilesLabel, c);
// Input files browse button
inFilesButton = new JButton("Browse");
c.fill = GridBagConstraints.NONE; c.gridx = 1; c.gridy = 0;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(inFilesButton, c);
inFilesButton.addActionListener(inFilesButtonLis);
// Input files status label
inFilesStatusLabel = new JLabel("Choose input files");
inFilesStatusLabel.setForeground(labelInvalidColor);
c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 1;
c.gridwidth = 2;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(inFilesStatusLabel, c);
// Output directory label
JLabel outDirLabel = new JLabel("Output directory");
c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 2;
c.gridwidth = 1;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(outDirLabel, c);
// Output directory browse button
outDirButton = new JButton("Browse");
c.fill = GridBagConstraints.NONE; c.gridx = 1; c.gridy = 2;
c.gridwidth = 1;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(outDirButton, c);
outDirButton.addActionListener(outDirButtonLis);
// Output directory status label
outDirStatusLabel = new JLabel("Choose output directory");
outDirStatusLabel.setForeground(labelInvalidColor);
c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 3;
c.gridwidth = 2;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(outDirStatusLabel, c);
JLabel outFileNameLabel = new JLabel("Output file name");
c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 4;
c.gridwidth = 1;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(outFileNameLabel, c);
Date dateNow = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy_MMdd_HHmmss");
outFileName = "comets_" + dateFormat.format(dateNow);
outFileNameField = new JTextField(20);
outFileNameField.setText(outFileName);
c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 5;
c.gridwidth = 2;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(outFileNameField, c);
// Comet finding options
JSeparator cometFindingSep = new JSeparator(SwingConstants.HORIZONTAL);
cometFindingSep.setPreferredSize(new Dimension(1,1));
c.fill = GridBagConstraints.HORIZONTAL;
c.gridy = 6;
mainPanel.add(cometFindingSep,c);
JLabel cometFindingLabel = new JLabel("Comet finding");
bgCorrectCheck = new JCheckBox("Background correction",true);
c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 7;
c.gridwidth = 2;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(cometFindingLabel, c);
c.gridy = 8;
mainPanel.add(bgCorrectCheck, c);
// Head finding options
JSeparator headFindingSep = new JSeparator(SwingConstants.HORIZONTAL);
headFindingSep.setPreferredSize(new Dimension(1,1));
c.fill = GridBagConstraints.HORIZONTAL;
c.gridy = 9;
mainPanel.add(headFindingSep,c);
JLabel headFindingLabel = new JLabel("Head finding");
Panel headFindingGroupPanel = new Panel();
headFindingGroupPanel.setLayout(new BoxLayout(headFindingGroupPanel,
BoxLayout.Y_AXIS));
headFindingAuto = new JRadioButton("Auto",true);
headFindingProfile = new JRadioButton("Profile analysis");
headFindingBrightest = new JRadioButton("Brigthest region");
ButtonGroup headFindingGroup = new ButtonGroup();
headFindingGroup.add(headFindingAuto);
headFindingGroup.add(headFindingProfile);
headFindingGroup.add(headFindingBrightest);
headFindingGroupPanel.add(headFindingAuto);
headFindingGroupPanel.add(headFindingProfile);
headFindingGroupPanel.add(headFindingBrightest);
c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 10;
c.gridwidth = 2;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(headFindingLabel, c);
c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 11;
c.gridwidth = 2;
c.anchor = GridBagConstraints.LINE_START;
mainPanel.add(headFindingGroupPanel, c);
//mainPanel.add(headFindingAuto, c);
//c.gridy = 10;
//mainPanel.add(headFindingProfile, c);
//c.gridy = 11;
//mainPanel.add(headFindingBrightest, c);
// Run button panel
Panel runPanel = new Panel();
runButton = new JButton("Run");
updateOutputButton = new JButton("Update");
liveButton = new JButton("Live");
runPanel.add(runButton);
runPanel.add(updateOutputButton);
runPanel.add(liveButton);
runButton.addActionListener(runButtonLis);
updateOutputButton.addActionListener(updateOutputButtonLis);
liveButton.addActionListener(liveButtonLis);
// Add panels to main dialog
Box mainBox = Box.createVerticalBox();
mainBox.add(mainPanel);
mainBox.add(Box.createVerticalStrut(3) );
mainDialog.add(mainBox, BorderLayout.CENTER);
mainDialog.add(runPanel, BorderLayout.SOUTH);
mainDialog.pack();
mainDialog.setResizable(false);
mainDialog.setVisible(true);
}
public void mousePressed (MouseEvent e) {
int x = e.getX();
int y = e.getY();
ImageCanvas canvas = (ImageCanvas)e.getSource();
ImagePlus imp = canvas.getImage();
x = canvas.offScreenX(x);
y = canvas.offScreenY(y);
IJ.log(x+","+y);
Comet comet = findClickedComet(imp, x, y);
if(comet!=null){
IJ.log("Comet found");
comet.status = Comet.DELETED;
comet.cometRoi.setStrokeColor(Color.gray);
comet.oldRoi.setStrokeColor(Color.gray);
if(comet.headRoi!=null){
comet.headRoi.setStrokeColor(Color.gray);
}
}
}
private Comet findClickedComet(ImagePlus imp, int x,int y){
Comet[] comets = (Comet[])Comets.get(imp);
if(comets!=null){
for(int i=0;i<comets.length;i++){
if(comets[i].cometRoi.contains(x, y)){
return comets[i];
}
}
}
return null;
}
public void mouseReleased (MouseEvent e) {}
public void mouseClicked (MouseEvent e) {}
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e) {}
private boolean checkWriteAccess(String path){
File tmpFile = new File(path+"tmp");
try {
tmpFile.createNewFile();
tmpFile.delete();
}
catch(IOException e) {
return false;
}
return true;
}
private void printArray(double[] arr){
String s = "";
for(int i=0;i<arr.length;i++){
s += arr[i];
if(i<arr.length-1) s+=",";
}
IJ.log(s);
}
}