1 package de.desy.acop.video;
2
3 import java.awt.BorderLayout;
4 import java.awt.Color;
5 import java.awt.Cursor;
6 import java.awt.Dimension;
7 import java.awt.Graphics;
8 import java.awt.Graphics2D;
9 import java.awt.GridBagConstraints;
10 import java.awt.GridBagLayout;
11 import java.awt.Insets;
12 import java.awt.Rectangle;
13 import java.awt.Shape;
14 import java.awt.datatransfer.DataFlavor;
15 import java.awt.datatransfer.Transferable;
16 import java.awt.dnd.DnDConstants;
17 import java.awt.dnd.DragGestureEvent;
18 import java.awt.dnd.DragGestureListener;
19 import java.awt.dnd.DragSource;
20 import java.awt.dnd.DragSourceAdapter;
21 import java.awt.dnd.DropTarget;
22 import java.awt.dnd.DropTargetAdapter;
23 import java.awt.dnd.DropTargetDragEvent;
24 import java.awt.dnd.DropTargetDropEvent;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.MouseEvent;
27 import java.awt.geom.Rectangle2D;
28 import java.beans.PropertyChangeEvent;
29 import java.beans.PropertyChangeListener;
30 import java.beans.PropertyVetoException;
31 import java.io.File;
32
33 import javax.swing.AbstractAction;
34 import javax.swing.Action;
35 import javax.swing.JComponent;
36 import javax.swing.JFileChooser;
37 import javax.swing.JOptionPane;
38 import javax.swing.JPanel;
39 import javax.swing.JPopupMenu;
40 import javax.swing.JScrollPane;
41 import javax.swing.JViewport;
42 import javax.swing.border.LineBorder;
43 import javax.swing.filechooser.FileNameExtensionFilter;
44
45 import com.cosylab.gui.components.customizer.AbstractCustomizerPanel;
46 import com.cosylab.gui.components.util.PopupManageable;
47 import com.cosylab.gui.components.util.PopupManager;
48 import com.cosylab.gui.components.util.RunnerHelper;
49 import com.cosylab.util.CommonException;
50
51 import de.desy.acop.displayers.selector.ConnectionCustomizer;
52 import de.desy.acop.displayers.tools.AcopDisplayerParameters;
53 import de.desy.acop.displayers.tools.AcopDisplayerParametersFlavor;
54 import de.desy.acop.displayers.tools.ConnectionParametersFlavor;
55 import de.desy.acop.displayers.tools.ConnectionParametersReceiver;
56 import de.desy.acop.transport.ConnectionParameters;
57 import de.desy.acop.video.analysis.AImage;
58 import de.desy.acop.video.analysis.AnalysisMode;
59 import de.desy.acop.video.analysis.ImageAnalysisEngine;
60 import de.desy.acop.video.analysis.LuminosityColorDecoder;
61 import de.desy.acop.video.displayer.ColorLookupPanel;
62 import de.desy.acop.video.displayer.ColorMap;
63 import de.desy.acop.video.displayer.ImageCLUT;
64 import de.desy.acop.video.displayer.ImageDisplayer;
65 import de.desy.acop.video.displayer.ImageZoom;
66 import de.desy.acop.video.displayer.OverlayState;
67 import de.desy.acop.video.displayer.TineHandler;
68 import de.desy.acop.video.displayer.TineImageReceiver;
69 import de.desy.tine.types.IMAGE;
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 public class AcopVideo extends JComponent implements ConnectionParametersReceiver, PopupManageable, TineImageReceiver {
89
90 private static final long serialVersionUID = 1L;
91
92 public static final String PROPERTY_LIVE_MODE = "liveMode";
93 public static final String PROPERTY_AIMAGE = "aImage";
94 public static final String PROPERTY_CAN_CHANGE_SETTINGS = "canChangeSettings";
95 public static final String PROPERTY_DISPLAY_CLUT_HEADER = "displayClutHeader";
96 public static final String DISPLAY_STATISTISC = "displayStatistics";
97
98
99
100
101 private ImageDisplayer imageDisplayer;
102
103
104
105
106 private SideProfileDisplayer horizontalDisplayer;
107 private SideProfileDisplayer verticalDisplayer;
108
109
110
111
112 private NumericDataDisplayer numericDataDisplayer;
113
114
115
116
117 private GridBagLayout layout;
118
119
120
121
122 private JPanel displayerPanel;
123
124
125
126
127 private JViewport clutHeader;
128
129
130
131
132 private AnalysisMode analysisMode = AnalysisMode.NO_ANALYSIS;
133
134
135
136
137 private boolean canChangeSettings = false;
138
139
140
141
142 private boolean displayNumericalValues = false;
143
144
145
146
147 private boolean displayClutHeader = false;
148
149
150
151
152 private double decorationsWeight = 0.2;
153
154
155
156
157 private ImageAnalysisEngine imageAnalysisEngine;
158
159
160
161
162 private TineHandler tineHandler;
163
164
165
166
167 private ConnectionParameters connParams;
168
169
170
171
172 private AbstractCustomizerPanel customizer;
173
174
175
176
177 private PopupManager popupManager;
178
179
180
181
182 private AcopVideoInfoDialog infoDialog;
183
184
185
186
187 private boolean isLiveMode;
188
189
190
191
192 private JFileChooser chooser;
193
194
195
196
197 private Action actionStart, actionStop;
198
199
200
201
202 private DisplayerManager displayerManager;
203
204
205
206
207 private AImage aImage;
208
209
210
211
212 private boolean popupEnabled;
213
214
215
216
217
218 public AcopVideo() {
219 super();
220 initialize();
221
222 Thread th = new Thread(new Runnable() {
223 public void run() {
224 if (tineHandler != null) {
225 tineHandler.closeLink();
226 }
227 getImageAnalysisEngine().stopRemoteAnalysis();
228
229 }
230 });
231 th.setDaemon(false);
232 Runtime.getRuntime().addShutdownHook(th);
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 private void initialize() {
272 imageDisplayer = new ImageDisplayer() {
273
274 private static final long serialVersionUID = 310376L;
275
276
277
278
279
280
281
282
283 @Override
284 protected void paintComponent(Graphics g) {
285 super.paintComponent(g);
286 Graphics2D g2 = (Graphics2D) g;
287 if (getDisplayerManager().getDraggingRectangle() != null) {
288 Rectangle2D r = getDisplayerManager().getDraggingRectangle();
289 if (r != null) {
290 g2.setPaint(Definitions.getRoiSelectingColor());
291 g2.draw(r);
292 }
293 }
294 if (getDisplayerManager().isRoiSelected()) {
295 Rectangle2D r = getDisplayerManager().getScaledSelectedRectangle();
296 if (r != null) {
297 getDisplayerManager().updateImageDisplayerSize(getSize());
298 g2.setPaint(Definitions.getRoiColor());
299 g2.draw(r);
300 }
301 }
302 if (getDisplayerManager().isThresholdROISelected()) {
303 Rectangle2D r = getDisplayerManager().getScaledThresholdROIRectangle();
304 if (r != null) {
305 getDisplayerManager().updateImageDisplayerSize(getSize());
306 g2.setPaint(Definitions.getThresholdRoiColor());
307 g2.draw(r);
308 }
309 }
310 if (getDisplayerManager().isCrossAvailable()) {
311 Shape c = getDisplayerManager().getCross();
312 if (c != null) {
313 g2.setPaint(Definitions.getStatisticsColor());
314 g2.draw(c);
315 }
316 }
317 if (getDisplayerManager().isCrossFitAvailable()) {
318 Shape c = getDisplayerManager().getCrossFit();
319 if (c != null) {
320 g2.setPaint(Definitions.getFitColor());
321 g2.draw(c);
322 }
323 }
324 }
325 };
326
327 setPopupEnabled(true);
328
329
330
331 imageDisplayer.addPropertyChangeListener(ImageDisplayer.PROPERTY_COLOR_MAP, new PropertyChangeListener() {
332 @Override
333 public void propertyChange(PropertyChangeEvent evt) {
334 ColorLookupPanel clutPanel = (ColorLookupPanel) getClutHeader().getComponent(0);
335 clutPanel.setCLUT((ImageCLUT) evt.getNewValue());
336 clutPanel.repaint();
337 }
338 });
339
340
341 tineHandler = new TineHandler(this);
342
343
344 setLayout(new BorderLayout());
345 add(getDisplayerPanel(), BorderLayout.CENTER);
346 add(getNumericalDataDisplayer(), BorderLayout.SOUTH);
347
348
349 setDropTarget(new DropTarget(this, new DropTargetAdapter() {
350
351
352
353
354
355 private boolean isAcceptable(DropTargetDragEvent dtde) {
356 DataFlavor[] f = dtde.getCurrentDataFlavors();
357
358 boolean accept = false;
359
360 for (int i = 0; i < f.length; i++) {
361 if (f[i] == AcopVideoParametersFlavor.FLAVOR || f[i] == AcopDisplayerParametersFlavor.FLAVOR
362 || f[i] == ConnectionParametersFlavor.FLAVOR || f[i] == DataFlavor.stringFlavor) {
363 accept = true;
364
365 break;
366 }
367 }
368
369 return (accept & (dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0);
370 }
371
372 public void dragEnter(DropTargetDragEvent dtde) {
373 if (!isAcceptable(dtde)) {
374 dtde.rejectDrag();
375 return;
376 }
377 }
378
379 public void dragOver(DropTargetDragEvent dtde) {
380 if (!isAcceptable(dtde)) {
381 dtde.rejectDrag();
382 return;
383 }
384 }
385
386 public void dropActionChanged(DropTargetDragEvent dtde) {
387 if (!isAcceptable(dtde)) {
388 dtde.rejectDrag();
389 return;
390 }
391 }
392
393 public void drop(DropTargetDropEvent dtde) {
394
395 dtde.acceptDrop(DnDConstants.ACTION_COPY);
396 Transferable transferable = dtde.getTransferable();
397 try {
398
399
400 if (transferable.isDataFlavorSupported(AcopVideoParametersFlavor.FLAVOR)) {
401 AcopVideoParameters p = (AcopVideoParameters) transferable
402 .getTransferData(AcopVideoParametersFlavor.FLAVOR);
403
404 setConnectionParameters(p.getConnectionParameters());
405 setImageZoom(p.getImageZoom());
406 setOverlayState(p.getOverlayState());
407 setAOIZoom(p.isAOIZoom());
408 setHistogramEqualisation(p.isHistogramEqualisation());
409 setHistogramMin(p.getHistogramMin());
410 setHistogramMax(p.getHistogramMax());
411 setKeepAspectRatio(p.isKeepAspectRatio());
412
413 imageDisplayer.setCLUT(new ImageCLUT(p.getColorMap(), imageDisplayer.getCLUT()
414 .getComponentSize()));
415
416 } else if (transferable.isDataFlavorSupported(AcopDisplayerParametersFlavor.FLAVOR)) {
417 AcopDisplayerParameters p = (AcopDisplayerParameters) transferable
418 .getTransferData(AcopDisplayerParametersFlavor.FLAVOR);
419 setConnectionParameters(p.getConnectionParameters());
420 } else if (transferable.isDataFlavorSupported(ConnectionParametersFlavor.FLAVOR)) {
421 ConnectionParameters p = (ConnectionParameters) transferable
422 .getTransferData(ConnectionParametersFlavor.FLAVOR);
423 setConnectionParameters(p);
424 } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
425 String p = (String) transferable.getTransferData(DataFlavor.stringFlavor);
426 try {
427 setConnectionParameters(new ConnectionParameters(p));
428 } catch (RuntimeException e) {
429 dtde.dropComplete(false);
430 return;
431 }
432 } else {
433 dtde.dropComplete(false);
434 return;
435 }
436 dtde.dropComplete(true);
437 } catch (Exception e) {
438 e.printStackTrace();
439 }
440 }
441
442 }));
443
444
445 DragSource dragSource = DragSource.getDefaultDragSource();
446 dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE,
447 new DragGestureListener() {
448 public void dragGestureRecognized(DragGestureEvent dge) {
449 if (dge.getTriggerEvent() instanceof MouseEvent) {
450 if (!((MouseEvent) dge.getTriggerEvent()).isControlDown())
451 return;
452 }
453
454 AcopVideoParameters p = new AcopVideoParameters(
455 getConnectionParameters(),
456 imageDisplayer.isAOIZoom(),
457 imageDisplayer.getImageZoom(),
458 imageDisplayer.getOverlayState(),
459 imageDisplayer.isKeepAspectRatio(),
460 imageDisplayer.isHistogramEqualisation(),
461 imageDisplayer.getHistogramMin(),
462 imageDisplayer.getHistogramMax(),
463
464 imageDisplayer.getCLUT().getColorMap(),
465 getClutHeader().isVisible());
466
467 Transferable transferable = new AcopVideoTransferable(p);
468 dge.startDrag(new Cursor(Cursor.MOVE_CURSOR), transferable, new DragSourceAdapter() {
469 });
470 }
471 });
472
473 }
474
475 private SideProfileDisplayer getHorizontalDisplayer() {
476 if (horizontalDisplayer == null) {
477 horizontalDisplayer = new SideProfileDisplayer(true);
478 horizontalDisplayer.setVisible(isAnalysisEnabled());
479 }
480 return horizontalDisplayer;
481 }
482
483 private SideProfileDisplayer getVerticalDisplayer() {
484 if (verticalDisplayer == null) {
485 verticalDisplayer = new SideProfileDisplayer(false);
486 verticalDisplayer.setVisible(isAnalysisEnabled());
487 }
488 return verticalDisplayer;
489 }
490
491 private NumericDataDisplayer getNumericalDataDisplayer() {
492 if (numericDataDisplayer == null) {
493 numericDataDisplayer = new NumericDataDisplayer();
494 numericDataDisplayer.setVisible(displayNumericalValues);
495 }
496 return numericDataDisplayer;
497 }
498
499 protected DisplayerManager getDisplayerManager() {
500 if (displayerManager == null) {
501 displayerManager = new DisplayerManager(getImageAnalysisEngine(), getImageDisplayer(),
502 getHorizontalDisplayer(), getVerticalDisplayer());
503 }
504 return displayerManager;
505 }
506
507 public void setAnalysisServerConnectionParameters(ConnectionParameters param) {
508 getImageAnalysisEngine().setAnalysisServerConnectionParameters(param);
509 }
510
511
512
513
514
515
516
517
518
519 public synchronized void setBackgroundImage(IMAGE background) {
520 getImageAnalysisEngine().setBackground(background);
521 }
522
523
524
525
526
527
528
529 public synchronized IMAGE getBackgroundImage() {
530 return getImageAnalysisEngine().getBackground();
531 }
532
533
534
535
536
537
538
539 public void setROI(Rectangle rect) {
540 getImageAnalysisEngine().setRoi(rect.x, rect.y, rect.width, rect.height);
541 }
542
543
544
545
546
547
548 public Rectangle getROI() {
549 return getImageAnalysisEngine().getROI();
550 }
551
552
553
554
555
556
557
558 public void setThresholdROI(Rectangle rect) {
559 getImageAnalysisEngine().setRoi2(rect.x, rect.y, rect.width, rect.height);
560 }
561
562
563
564
565
566
567 public Rectangle getThresholdROI() {
568 return getImageAnalysisEngine().getThresholdROI();
569 }
570
571
572
573
574
575
576
577
578
579
580 public void setAutomaticThresholdCalculation(boolean automatic) {
581 getImageAnalysisEngine().setCalculateThreshold(automatic);
582 }
583
584
585
586
587
588
589
590 public boolean isAutomaticThresholdCalculation() {
591 return getImageAnalysisEngine().isCalculateThreshold();
592 }
593
594
595
596
597
598
599
600
601
602
603
604 public synchronized void setPreciseBackgroundImage(double[] image, int width) {
605 getImageAnalysisEngine().setPreciseBackground(image, width);
606 }
607
608
609
610
611
612
613 public synchronized double[] getPreciseBackgroundImage() {
614 return getImageAnalysisEngine().getPreciseBackground();
615 }
616
617
618
619
620
621
622 public synchronized int getBackgroundImageWidth() {
623 return getImageAnalysisEngine().getBackgroundWidth();
624 }
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639 public synchronized void setThreshold(final double threshold) {
640 ImageAnalysisEngine engine = getImageAnalysisEngine();
641 if (engine != null) {
642 engine.setThreshold(threshold);
643 }
644 }
645
646
647
648
649
650
651
652
653 public synchronized double getThreshold() {
654 return getImageAnalysisEngine().getThreshold();
655 }
656
657 protected synchronized ImageAnalysisEngine getImageAnalysisEngine() {
658 if (imageAnalysisEngine == null) {
659 imageAnalysisEngine = new ImageAnalysisEngine(new LuminosityColorDecoder());
660 imageAnalysisEngine.addPropertyChangeListener(new PropertyChangeListener() {
661 @Override
662 public void propertyChange(PropertyChangeEvent evt) {
663 String propertyName = evt.getPropertyName();
664 if (propertyName == ImageAnalysisEngine.PROPERTY_A_IMAGE) {
665 AImage aImage = (AImage) evt.getNewValue();
666 setAImage(aImage);
667 } else if (propertyName == ImageAnalysisEngine.PROPERTY_RESET) {
668 getImageDisplayer().resetForReceiving();
669 }
670 }
671 });
672 }
673 return imageAnalysisEngine;
674 }
675
676 private GridBagLayout getDisplayerPanelLayout() {
677 if (layout == null) {
678 layout = new GridBagLayout();
679 }
680 return layout;
681 }
682
683 private JPanel getDisplayerPanel() {
684 if (displayerPanel == null) {
685 displayerPanel = new JPanel(getDisplayerPanelLayout());
686 GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
687 GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0);
688
689 JScrollPane scroller = new JScrollPane(imageDisplayer);
690 scroller.setAutoscrolls(true);
691 scroller.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
692 scroller.getViewport().addChangeListener(getDisplayerManager().getViewPortListener());
693 scroller.setColumnHeader(getClutHeader());
694 displayerPanel.add(scroller, gbc);
695
696 gbc.gridy++;
697 gbc.weighty = decorationsWeight;
698 gbc.insets = new Insets(0, 1, 0, 1);
699 getHorizontalDisplayer().setBorder(new LineBorder(Color.BLACK, 1));
700 displayerPanel.add(getHorizontalDisplayer(), gbc);
701 gbc.gridy--;
702 gbc.gridx++;
703 gbc.weightx = decorationsWeight;
704 gbc.insets = new Insets(1, 0, 1, 0);
705 getVerticalDisplayer().setBorder(new LineBorder(Color.BLACK, 1));
706 displayerPanel.add(getVerticalDisplayer(), gbc);
707 }
708 return displayerPanel;
709 }
710
711 private JViewport getClutHeader() {
712 if (clutHeader == null) {
713 clutHeader = new JViewport();
714 clutHeader.add(new ColorLookupPanel(null));
715 clutHeader.setVisible(displayClutHeader);
716 clutHeader.setPreferredSize(new Dimension(0, 30));
717 }
718 return clutHeader;
719 }
720
721
722
723
724
725
726
727 public void setColorMap(ColorMap newValue) {
728 ColorMap oldValue = getColorMap();
729 imageDisplayer.setColorMap(newValue);
730 firePropertyChange(ImageDisplayer.PROPERTY_COLOR_MAP, oldValue, newValue);
731 }
732
733
734
735
736
737
738
739 public ColorMap getColorMap() {
740 return imageDisplayer.getColorMap();
741 }
742
743
744
745
746
747
748 public void setImageZoom(ImageZoom newValue) {
749 ImageZoom oldValue = getImageZoom();
750 imageDisplayer.setImageZoom(newValue);
751 firePropertyChange(ImageDisplayer.PROPERTY_IMAGE_ZOOM, oldValue, newValue);
752 }
753
754
755
756
757 public ImageZoom getImageZoom() {
758 return imageDisplayer.getImageZoom();
759 }
760
761
762
763
764
765 public void setOverlayState(OverlayState newValue) {
766 OverlayState oldValue = getOverlayState();
767 imageDisplayer.setOverlayState(newValue);
768 firePropertyChange(ImageDisplayer.PROPERTY_OVERLAY_STATE, oldValue, newValue);
769 }
770
771
772
773
774 public OverlayState getOverlayState() {
775 return imageDisplayer.getOverlayState();
776 }
777
778
779
780
781
782
783
784
785
786
787
788 public void setHistogramEqualisation(boolean newValue) {
789 boolean oldValue = isHistogramEqualisation();
790 imageDisplayer.setHistogramEqualisation(newValue);
791 firePropertyChange(ImageDisplayer.PROPERTY_HISTOGRAM_EQUALISATION, oldValue, newValue);
792 }
793
794
795
796
797
798
799
800
801 public boolean isHistogramEqualisation() {
802 return imageDisplayer.isHistogramEqualisation();
803 }
804
805
806 public void setHistogramMin(int newValue) {
807
808 int oldValue = getHistogramMin();
809 imageDisplayer.setHistogramMin(newValue);
810 firePropertyChange(ImageDisplayer.PROPERTY_HISTOGRAM_MIN, oldValue, newValue);
811 }
812
813
814 public int getHistogramMin() {
815 return imageDisplayer.getHistogramMin();
816 }
817
818
819 public void setHistogramMax(int newValue) {
820
821 int oldValue = getHistogramMax();
822 imageDisplayer.setHistogramMax(newValue);
823 firePropertyChange(ImageDisplayer.PROPERTY_HISTOGRAM_MAX, oldValue, newValue);
824 }
825
826
827 public int getHistogramMax() {
828 return imageDisplayer.getHistogramMax();
829 }
830
831
832
833
834
835
836
837
838
839 public void setAOIZoom(boolean newValue) {
840 boolean oldValue = isAOIZoom();
841 imageDisplayer.setAOIZoom(newValue);
842 firePropertyChange(ImageDisplayer.PROPERTY_AOI_ZOOM, oldValue, newValue);
843 }
844
845
846
847
848
849
850
851
852 public boolean isAOIZoom() {
853 return imageDisplayer.isAOIZoom();
854 }
855
856
857
858
859
860
861
862
863
864 public void setKeepAspectRatio(boolean newValue) {
865 boolean oldValue = isKeepAspectRatio();
866 imageDisplayer.setKeepAspectRatio(newValue);
867 firePropertyChange(ImageDisplayer.PROPERTY_KEEP_ASPECT_RATIO, oldValue, newValue);
868 }
869
870
871
872
873
874
875
876 public boolean isKeepAspectRatio() {
877 return imageDisplayer.isKeepAspectRatio();
878 }
879
880
881
882
883
884
885
886
887 public boolean isLiveMode() {
888 return isLiveMode;
889 }
890
891
892
893
894
895
896
897
898 private void setLiveMode(boolean newValue) {
899 boolean oldValue = isLiveMode;
900 isLiveMode = newValue;
901 firePropertyChange(PROPERTY_LIVE_MODE, oldValue, newValue);
902 }
903
904
905
906
907
908
909
910 public AImage getAImage() {
911 return aImage;
912 }
913
914
915
916
917
918
919
920 private void setAImage(AImage image) {
921 if (this.aImage == image)
922 return;
923 AImage old = aImage;
924 aImage = image;
925 getDisplayerManager().updateAImage(aImage);
926 if (aImage == null)
927 getNumericalDataDisplayer().clearData();
928 else
929 getNumericalDataDisplayer().setData(aImage.getImageW(), aImage.getImageH(), aImage.getRoiX(),
930 aImage.getRoiY(), aImage.getRoiW(), aImage.getRoiH(), aImage.getThreshold(), aImage.getMeanX(),
931 aImage.getStdX(), aImage.getSideViewAmplitudeX(), aImage.getSideViewConstX(), aImage.getMeanXFit(),
932 aImage.getStdXFit(), aImage.getAmplitudeXFit(), aImage.getConstXFit(), aImage.getSlopeXFit(),
933 aImage.getMeanY(), aImage.getStdY(), aImage.getSideViewAmplitudeY(), aImage.getSideViewConstY(),
934 aImage.getMeanYFit(), aImage.getStdYFit(), aImage.getAmplitudeYFit(), aImage.getConstYFit(),
935 aImage.getSlopeYFit(), aImage.getStdA(), aImage.getStdB(), aImage.getAngle2D(),
936 aImage.getAmplitude2D(), aImage.getConst2D());
937 firePropertyChange(PROPERTY_AIMAGE, old, aImage);
938 }
939
940
941
942
943
944
945 public double getDecorationsWeight() {
946 return decorationsWeight;
947 }
948
949
950
951
952
953
954
955 public void setDecorationsWeight(double decorationsWeight) {
956 if (this.decorationsWeight == decorationsWeight)
957 return;
958 this.decorationsWeight = decorationsWeight;
959 GridBagConstraints gbc = getDisplayerPanelLayout().getConstraints(getHorizontalDisplayer());
960 gbc.weighty = decorationsWeight;
961 getDisplayerPanelLayout().setConstraints(getHorizontalDisplayer(), gbc);
962 gbc = getDisplayerPanelLayout().getConstraints(getVerticalDisplayer());
963 gbc.weightx = decorationsWeight;
964 getDisplayerPanelLayout().setConstraints(getVerticalDisplayer(), gbc);
965 getDisplayerPanelLayout().layoutContainer(getDisplayerPanel());
966 }
967
968
969
970
971
972
973 public AnalysisMode getAnalysisMode() {
974 return analysisMode;
975 }
976
977
978
979
980
981
982
983 public void setAnalysisMode(AnalysisMode analysisMode) {
984 if (this.analysisMode == analysisMode)
985 return;
986 this.analysisMode = analysisMode;
987 getHorizontalDisplayer().setVisible(isAnalysisEnabled());
988 getVerticalDisplayer().setVisible(isAnalysisEnabled());
989 setAImage(null);
990 boolean local = analysisMode != AnalysisMode.REMOTE_ANALYSIS;
991 getImageAnalysisEngine().setLocalAnalysisMode(local);
992 setCanChangeSettings(analysisMode == AnalysisMode.LOCAL_ANALYSIS);
993 }
994
995
996
997
998
999
1000
1001 public void setPerformFit(boolean perform) {
1002 if (getImageAnalysisEngine().isPerformFit())
1003 return;
1004 getImageAnalysisEngine().setPerformFit(perform);
1005 firePropertyChange("performFit", !perform, perform);
1006 }
1007
1008
1009
1010
1011
1012
1013
1014 public boolean isPerformFit() {
1015 return getImageAnalysisEngine().isPerformFit();
1016 }
1017
1018
1019
1020
1021
1022
1023 public boolean isDisplayStatistics() {
1024 return getDisplayerManager().isDisplayStatistics();
1025 }
1026
1027
1028
1029
1030
1031
1032
1033 public void setDisplayStatistics(boolean display) {
1034
1035 getDisplayerManager().setDisplayStatistics(display);
1036 firePropertyChange(DISPLAY_STATISTISC, !display, display);
1037 repaint();
1038 }
1039
1040 private boolean isAnalysisEnabled() {
1041 if (analysisMode == AnalysisMode.LOCAL_ANALYSIS || analysisMode == AnalysisMode.REMOTE_ANALYSIS)
1042 return true;
1043 return false;
1044 }
1045
1046
1047
1048
1049
1050
1051
1052 public boolean isCanChangeSettings() {
1053 return canChangeSettings;
1054 }
1055
1056
1057
1058
1059
1060
1061
1062
1063 public void setCanChangeSettings(boolean canChange) {
1064 if (canChangeSettings == canChange)
1065 return;
1066 canChangeSettings = canChange;
1067 firePropertyChange(PROPERTY_CAN_CHANGE_SETTINGS, !canChange, canChange);
1068 getDisplayerManager().setCanChangeSettings(canChange);
1069 }
1070
1071
1072
1073
1074
1075
1076
1077 public boolean isDisplayNumericalValues() {
1078 return displayNumericalValues;
1079 }
1080
1081
1082
1083
1084
1085
1086
1087
1088 public void setDisplayNumericalValues(boolean displayNumericalValues) {
1089 this.displayNumericalValues = displayNumericalValues;
1090 getNumericalDataDisplayer().setVisible(displayNumericalValues);
1091 }
1092
1093
1094
1095
1096
1097
1098
1099 public boolean isDisplayClutHeader() {
1100 return displayClutHeader;
1101 }
1102
1103
1104
1105
1106
1107
1108
1109
1110 public void setDisplayClutHeader(boolean displayClutHeader) {
1111 if (this.displayClutHeader == displayClutHeader)
1112 return;
1113 boolean oldValue = this.displayClutHeader;
1114 this.displayClutHeader = displayClutHeader;
1115 getClutHeader().setVisible(displayClutHeader);
1116 firePropertyChange(PROPERTY_DISPLAY_CLUT_HEADER, oldValue, displayClutHeader);
1117 }
1118
1119
1120
1121
1122
1123
1124 public AbstractCustomizerPanel getCustomizer() {
1125 if (customizer == null)
1126 customizer = AbstractCustomizerPanel.findCustomizer(this);
1127 return customizer;
1128 }
1129
1130
1131
1132
1133
1134
1135 public PopupManager getPopupManager() {
1136 if (popupManager == null) {
1137 popupManager = new PopupManager(this, true);
1138 popupManager.addAction(new AbstractAction("Preferences...") {
1139 private static final long serialVersionUID = 1L;
1140
1141 public void actionPerformed(ActionEvent e) {
1142 getCustomizer().showDialog();
1143 }
1144 });
1145
1146 popupManager.addAction(new AbstractAction("Capture screen...") {
1147 private static final long serialVersionUID = 1L;
1148
1149 public void actionPerformed(ActionEvent e) {
1150 saveAsPNG();
1151 }
1152 });
1153
1154 popupManager.addAction(new AbstractAction("Info...") {
1155 private static final long serialVersionUID = 310376L;
1156
1157 public void actionPerformed(ActionEvent e) {
1158 getInfoDialog().setVisible(true);
1159 getInfoDialog().toFront();
1160 }
1161 });
1162
1163 actionStart = new AbstractAction("Start") {
1164 private static final long serialVersionUID = 310376L;
1165
1166 public void actionPerformed(ActionEvent e) {
1167 start();
1168 }
1169 };
1170 actionStart.setEnabled(false);
1171 popupManager.addAction(actionStart);
1172
1173 actionStop = new AbstractAction("Stop") {
1174 private static final long serialVersionUID = 1310376L;
1175
1176 public void actionPerformed(ActionEvent e) {
1177 stop();
1178 }
1179 };
1180 actionStop.setEnabled(false);
1181 popupManager.addAction(actionStop);
1182
1183
1184 JPopupMenu.setDefaultLightWeightPopupEnabled(false);
1185 }
1186 return popupManager;
1187 }
1188
1189
1190
1191
1192 public void saveAsPNG() {
1193 JFileChooser chooser = getPngFileChooser("Save As");
1194 int returnVal = chooser.showSaveDialog(this);
1195 if (returnVal == JFileChooser.APPROVE_OPTION) {
1196 String fileNamePath = chooser.getSelectedFile().getAbsolutePath();
1197 if (!fileNamePath.toLowerCase().endsWith(".png")) {
1198 int index = fileNamePath.lastIndexOf('.');
1199 if (index >= 0) {
1200 fileNamePath = fileNamePath.substring(0, index) + ".png";
1201 } else {
1202 fileNamePath = fileNamePath + ".png";
1203 }
1204 }
1205 if (!imageDisplayer.saveAsPNGImage(fileNamePath))
1206 JOptionPane.showMessageDialog(this, "Error saving image.", "Error", JOptionPane.ERROR_MESSAGE);
1207 }
1208 }
1209
1210
1211
1212
1213 public void exportToPNG() {
1214 JFileChooser chooser = getPngFileChooser("Export");
1215 int returnVal = chooser.showSaveDialog(this);
1216 if (returnVal == JFileChooser.APPROVE_OPTION) {
1217 String fileNamePath = chooser.getSelectedFile().getAbsolutePath();
1218 if (!fileNamePath.toLowerCase().endsWith(".png")) {
1219 int index = fileNamePath.lastIndexOf('.');
1220 if (index >= 0)
1221 fileNamePath = fileNamePath.substring(0, index) + ".png";
1222 else
1223 fileNamePath = fileNamePath + ".png";
1224 }
1225 if (!imageDisplayer.exportToPNG(fileNamePath))
1226 JOptionPane.showMessageDialog(this, "Error saving image.", "Error", JOptionPane.ERROR_MESSAGE);
1227 }
1228 }
1229
1230 private JFileChooser getPngFileChooser(String dialogTitle) {
1231 if (chooser == null) {
1232 chooser = new JFileChooser(new File("."));
1233 String[] fileType = { "png" };
1234 FileNameExtensionFilter PNGfilter = new FileNameExtensionFilter("PNG files", fileType);
1235 chooser.addChoosableFileFilter(PNGfilter);
1236 }
1237 chooser.setDialogTitle(dialogTitle);
1238 return chooser;
1239 }
1240
1241 private AcopVideoInfoDialog getInfoDialog() {
1242 if (infoDialog == null) {
1243 infoDialog = new AcopVideoInfoDialog(this);
1244 }
1245 return infoDialog;
1246 }
1247
1248
1249
1250
1251
1252
1253
1254 public ConnectionParameters getConnectionParameters() {
1255 return connParams;
1256 }
1257
1258
1259
1260
1261
1262
1263
1264 public void setConnectionParameters(ConnectionParameters cp) throws CommonException, PropertyVetoException {
1265
1266 if (connParams == null) {
1267 if (cp == null)
1268 return;
1269 } else if (connParams.equals(cp))
1270 return;
1271
1272 ConnectionParameters oldValue = this.connParams;
1273 connParams = cp;
1274 stop();
1275
1276 firePropertyChange(CONNECTION_PARAMETERS_PROPERTY, oldValue, connParams);
1277 }
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306 public void start() {
1307 if (connParams == null)
1308 return;
1309
1310 setEnabled(false);
1311
1312 new Thread(new Runnable() {
1313 public void run() {
1314 try {
1315 if (analysisMode == AnalysisMode.REMOTE_ANALYSIS) {
1316 getImageAnalysisEngine().setAnalysisServerConnectionParameters(connParams);
1317 getImageAnalysisEngine().startRemoteAnalysis();
1318
1319 } else
1320 tineHandler.openLink(connParams);
1321
1322 imageDisplayer.setLiveTransfer(true);
1323 setLiveMode(true);
1324
1325 } catch (Exception e) {
1326 System.out.println(e);
1327 JOptionPane.showMessageDialog(AcopVideo.this, "Error connecting to the address '"
1328 + connParams.getRemoteName() + "'.\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
1329 } finally {
1330 setEnabled(true);
1331 }
1332 }
1333
1334 }).start();
1335 }
1336
1337
1338
1339
1340
1341
1342 @Override
1343 public void setEnabled(boolean enabled) {
1344 super.setEnabled(enabled);
1345 actionStart.setEnabled(!isLiveMode);
1346 actionStop.setEnabled(isLiveMode);
1347 }
1348
1349
1350
1351
1352
1353
1354
1355 public void stop() {
1356 getImageAnalysisEngine().stopRemoteAnalysis();
1357 tineHandler.closeLink();
1358 imageDisplayer.setLiveTransfer(false);
1359 setLiveMode(false);
1360 setEnabled(false);
1361 }
1362
1363 public static void main(String[] args) {
1364 AcopVideo v = new AcopVideo();
1365 RunnerHelper.runComponent(v, 500, 500);
1366
1367
1368
1369
1370 }
1371
1372 public ImageDisplayer getImageDisplayer() {
1373 return imageDisplayer;
1374 }
1375
1376 @Override
1377 public void updateValue(IMAGE newImage) {
1378 if (analysisMode == AnalysisMode.LOCAL_ANALYSIS) {
1379 getImageAnalysisEngine().updateValue(newImage);
1380 } else if (analysisMode == AnalysisMode.NO_ANALYSIS) {
1381 imageDisplayer.updateValue(newImage);
1382 }
1383 }
1384
1385 @Override
1386 public void resetForReceiving() {
1387 if (analysisMode == AnalysisMode.LOCAL_ANALYSIS) {
1388 getImageAnalysisEngine().resetForReceiving();
1389 } else if (analysisMode == AnalysisMode.NO_ANALYSIS) {
1390 imageDisplayer.resetForReceiving();
1391 }
1392 }
1393
1394
1395
1396
1397
1398
1399 public boolean isPopupEnabled() {
1400 return popupEnabled;
1401 }
1402
1403
1404
1405
1406
1407
1408
1409 public void setPopupEnabled(boolean enabled) {
1410 if (popupEnabled == enabled)
1411 return;
1412 popupEnabled = enabled;
1413 if (enabled) {
1414 getImageDisplayer().addMouseListener(getPopupManager().getMouseHook());
1415 } else {
1416 getImageDisplayer().removeMouseListener(getPopupManager().getMouseHook());
1417 }
1418 firePropertyChange("popupEnabled", !popupEnabled, popupEnabled);
1419 }
1420 }