diff --git a/config/config.properties b/config/config.properties index 0d93163..0148555 100755 --- a/config/config.properties +++ b/config/config.properties @@ -1,90 +1,87 @@ -#Tue Oct 28 16:49:26 CET 2025 +#Wed Jan 14 14:03:24 CET 2026 autoSaveScanData=true -simulation=false -dataScanAutoSave=true -xscanCrlogicChannel=null -dataScanSaveOutput=false -scanPreserveTypes=false -userAuthenticator= -dataScanStrategy=default -dataScanSaveScript=false -notifiedTasks=null -parallelInitialization=false -fdaSerialization=false -consoleJournal=false -scanDataRelease=false -dataTransferPath=null -scanStreamingPort=-1 -saveConsoleSessionFiles=false -xscanAppendSuffix=true -devicePoolFile={config}/devices.properties -hostName= -disableEmbeddedAttributes=false -scanSaveTimestamps=false -commandTimeToLive=600000 -serverPort=8090 -versionTrackingEnabled=true -dataPath={data}/{year}/{month}/{day}/{date}_{time}_{name} -serverEnabled=false -depthDimension=0 -logLevel=Fine -dataLayout=sf -disableDataFileLogs=false -dataScanSaveTimestamps=false -sessionHandling=Off -deviceUpdateStrategyFile={config}/update.properties -terminalEnabled=false -notificationLevel=Off -terminalPort=3579 -commandQueueSize=-1 -dataTransferUser=null -xscanContinuousUpdate=false -scanLazyTableCreation=false -versionTrackingLogin= -noBytecodeFiles=false -scanSaveMeta=true -versionTrackingRemote=https\://gitea.psi.ch/pshell_config/sf-op.git -scanAutoSave=true -dataScanLazyTableCreation=false -pythonHome= -xscanMoveTimeout=600 -commandStatistics=false -serverHostName=null commandExecutionEvents=false -logDaysToLive=30 -xscanCrlogicSimulated=false -dataDepthDimension=0 -logLevelConsole=Off -filePermissionsConfig=Default -scanStreamerPort=-1 -dataEmbeddedAttributes=false -dataScanSaveSetpoints=false -scanSaveLogs=true -serverCommandsHidden=false -versionTrackingManual=true -dataTransferMode=Off -userManagement=false -instanceName=OP -dataServerPort=-1 -notificationTasks= -hideServerMessages=false -scanReleaseRecords=false -scanDefaultTag=null -dataScanReleaseRecords=false -dataScanPreserveTypes=false -dataScanFlushRecords=false -filePermissionsLogs=Public -logPath={logs}/{date}_{time} -filePermissionsScripts=Public -xscanCrlogicPrefix=null -dataFormat=null -dataScanSaveLogs=true -tasksFile={config}/tasks.properties -filePermissionsData=Default -xscanCrlogicAbortable=true +commandQueueSize=-1 +commandStatistics=false +commandTimeToLive=600000 +consoleJournal=false createSessionFiles=false -dataScanStreamerPort=-1 -scanFlushRecords=false -dataProvider=default -xscanCrlogicIoc=null +dataDepthDimension=0 +dataEmbeddedAttributes=false +dataFormat=default +dataLayout=sf +dataPath={data}/{year}/{month}/{day}/{date}_{time}_{name} +dataProvider=null +dataScanFlushRecords=false +dataScanLazyTableCreation=false +dataScanPreserveTypes=false +dataScanReleaseRecords=false +dataScanSaveOutput=false +dataScanSaveScript=false +dataScanSaveSetpoints=false +dataScanSaveTimestamps=false +dataServerPort=-1 +dataTransferMode=Off +dataTransferPath=null +dataTransferUser=null +dataTruncate=true +depthDimension=0 +devicePoolFile={config}/devices.properties +deviceUpdateStrategyFile={config}/update.properties +disableDataFileLogs=false +disableEmbeddedAttributes=false +fdaSerialization=false +filePermissionsConfig=Default +filePermissionsData=Default +filePermissionsLogs=Public +filePermissionsScripts=Public +hideServerMessages=false +hostName=null +instanceName=OP +logDaysToLive=30 +logLevel=Fine +logLevelConsole=Off +logPath={logs}/{date}_{time}.{mode} +noBytecodeFiles=false +notificationLevel=Off +notificationTasks= +notifiedTasks= +parallelInitialization=false +pythonHome= +pythonNoBytecodeFiles=false saveCommandStatistics=false +saveConsoleSessionFiles=false +scanAutoSave=true +scanDefaultTag="scan_{index}%d" +scanFlushRecords=false +scanLazyTableCreation=false +scanPreserveTypes=false +scanReleaseRecords=false +scanSaveLogs=true +scanSaveMeta=true +scanSaveTimestamps=false +scanStreamerPort=-1 +serverCommandsHidden=false +serverEnabled=false +serverHostName= +serverHttps=false +serverPort=8090 +sessionHandling=Off +simulation=false +tasksFile={config}/tasks.properties +terminalEnabled=false +terminalPort=3579 +userAuthenticator= +userManagement=false +versionTrackingEnabled=true +versionTrackingLogin= +versionTrackingManual=true +versionTrackingRemote=https\://gitea.psi.ch/pshell_config/sf-op.git +xscanAppendSuffix=true +xscanContinuousUpdate=false +xscanCrlogicAbortable=true +xscanCrlogicChannel=null +xscanCrlogicIoc=null +xscanCrlogicPrefix=null +xscanCrlogicSimulated=false +xscanMoveTimeout=600 diff --git a/config/devices.properties b/config/devices.properties index 3c9b088..3bdcfc4 100755 --- a/config/devices.properties +++ b/config/devices.properties @@ -1,5 +1,5 @@ dispatcher=ch.psi.pshell.bs.Dispatcher|https://dispatcher-api.psi.ch/sf||| -cam_server=ch.psi.pshell.bs.PipelineServer|sf-daqsync-01:8889||| +cam_server=ch.psi.pshell.camserver.PipelineSource|sf-daqsync-01:8889||| charge=ch.psi.pshell.epics.ProcessVariable|SINEG01-DICT215:B1_CHARGE_AVERAGE-OP||| rep_rate_bunch_1=ch.psi.pshell.epics.ProcessVariable|SIN-TIMAST-TMA:Bunch-1-Appl-Freq-RB||| rep_rate_bunch_2=ch.psi.pshell.epics.ProcessVariable|SIN-TIMAST-TMA:Bunch-2-Appl-Freq-RB||| diff --git a/config/preferences.json b/config/preferences.json index 184eae7..559990a 100644 --- a/config/preferences.json +++ b/config/preferences.json @@ -56,8 +56,7 @@ "scanPlotDisabled" : false, "scanTableDisabled" : false, "cachedDataPanel" : false, - "dataExtensions" : "", - "dataSubFiles" : "", + "dataVisibleFiles" : "", "hideFileName" : false, "showEmergencyStop" : false, "showHomingButtons" : false, diff --git a/config/sounds/KDE_Beep_Honk.wav b/config/sounds/KDE_Beep_Honk.wav new file mode 100755 index 0000000..9faf34c Binary files /dev/null and b/config/sounds/KDE_Beep_Honk.wav differ diff --git a/config/variables.properties b/config/variables.properties index d5c8971..08bffa8 100755 --- a/config/variables.properties +++ b/config/variables.properties @@ -1,4 +1,4 @@ -#Thu Dec 11 15:41:25 CET 2025 -LastRunDate=251211 -FileSequentialNumber=16000 -DaySequentialNumber=17 +#Mon Feb 09 14:27:51 CET 2026 +DaySequentialNumber=13 +FileSequentialNumber=16297 +LastRunDate=260209 diff --git a/devices/Beam phase.properties b/devices/Beam phase.properties index d84280e..ae34c7a 100755 --- a/devices/Beam phase.properties +++ b/devices/Beam phase.properties @@ -8,4 +8,4 @@ rotation=true sign_bit=0 scale=1.0 description=null -resolution=0.5 +deadband=0.5 diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 1996b76..9d2c8fe 100755 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,47 +1,47 @@ -#Mon Dec 15 10:58:09 CET 2025 -\u0000\u0000\u0000= -\u0000\u0000= -\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= +#Mon Feb 09 12:41:25 CET 2026 \u0000= +\u0000\u0000= +\u0000\u0000\u0000= \u0000\u0000\u0000\u0000= +\u0000\u0000\u0000\u0000\u0000= \u0000\u0000\u0000\u0000\u0000\u0000= \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= +\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= -\u0000\u0000\u0000\u0000\u0000= -colormapLogarithmic=false -spatialCalScaleX=-6.67596435546875 -spatialCalScaleY=-6.5573768833705355 -serverURL=null -rescaleOffset=0.0 -roiWidth=-1 +1= colormap=Flame +colormapAutomatic=false +colormapLogarithmic=false +colormapMax=4000.0 +colormapMin=80.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=1680 imageWidth=1744 invert=false -colormapMin=100.0 -rotationCrop=false -1= -roiHeight=-1 -colormapAutomatic=true -roiY=0 -roiX=0 -spatialCalOffsetY=-312.00000361676905 -spatialCalOffsetX=298.0 -scale=1.0 -regionStart= -grayscale=false -rtY=1 -colormapMax=30000.0 -spat= -rotation=0.0 -rescaleFactor=1.0 -imageHeight=1680 -spatialCalUnits=null -flipVertically=false r= -t= -flipHorizontally=false -transpose=false +regionStart= regionStartX=433 regionStartY=241 +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +rtY=1 +scale=1.0 +serverURL=null +spat= +spatialCalOffsetX=-393.0000004567311 +spatialCalOffsetY=-1023.999980257793 +spatialCalScaleX=-8.737659395658053 +spatialCalScaleY=-8.834898165327527 +spatialCalUnits=null +t= +transpose=false diff --git a/devices/DLAC motor.properties b/devices/DLAC motor.properties index c5ebf94..046b830 100755 --- a/devices/DLAC motor.properties +++ b/devices/DLAC motor.properties @@ -7,7 +7,7 @@ scale=1.0 description=null estbilizationDelay=0 maxSpeed=1.0 -resolution=8.0E-4 +deadband=8.0E-4 homingType=None startRetries=1 minValue=130.0 diff --git a/devices/DummyMotor.properties b/devices/DummyMotor.properties index 20b49ce..4f0cca4 100755 --- a/devices/DummyMotor.properties +++ b/devices/DummyMotor.properties @@ -7,7 +7,7 @@ minSpeed=0.1 minValue=-10.0 offset=0.0 precision=2 -resolution=NaN +deadband=NaN rotation=false scale=1.0 unit=mm diff --git a/devices/Gain.properties b/devices/Gain.properties index 8b047f9..cb0816e 100755 --- a/devices/Gain.properties +++ b/devices/Gain.properties @@ -3,6 +3,6 @@ maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN scale=1.0 unit=null diff --git a/devices/Gun Phase.properties b/devices/Gun Phase.properties index 97d7944..f93b5a1 100755 --- a/devices/Gun Phase.properties +++ b/devices/Gun Phase.properties @@ -8,4 +8,4 @@ rotation=true sign_bit=0 scale=1.0 description=null -resolution=0.5 +deadband=0.5 diff --git a/devices/Motor.properties b/devices/Motor.properties index af45da2..b5544b7 100755 --- a/devices/Motor.properties +++ b/devices/Motor.properties @@ -7,7 +7,7 @@ minSpeed=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN rotation=false scale=1.0 unit=null diff --git a/devices/Phase.properties b/devices/Phase.properties index de11d60..ca85595 100755 --- a/devices/Phase.properties +++ b/devices/Phase.properties @@ -8,4 +8,4 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=0.01 +deadband=0.01 diff --git a/devices/S10BC01-MQUA100.properties b/devices/S10BC01-MQUA100.properties index c0bc743..5d22421 100755 --- a/devices/S10BC01-MQUA100.properties +++ b/devices/S10BC01-MQUA100.properties @@ -3,6 +3,6 @@ maxValue=10.0 minValue=-10.0 offset=0.0 precision=3 -resolution=0.007 +deadband=0.007 scale=1.0 unit=A diff --git a/devices/S10CB01-MQUA430.properties b/devices/S10CB01-MQUA430.properties index 49af40f..d4a1279 100755 --- a/devices/S10CB01-MQUA430.properties +++ b/devices/S10CB01-MQUA430.properties @@ -3,6 +3,6 @@ maxValue=10.0 minValue=-10.0 offset=0.0 precision=3 -resolution=0.007 +deadband=0.007 scale=1.0 unit=A diff --git a/devices/S10CB02-MQUA230.properties b/devices/S10CB02-MQUA230.properties index 54a61e1..a2d3fd0 100755 --- a/devices/S10CB02-MQUA230.properties +++ b/devices/S10CB02-MQUA230.properties @@ -3,6 +3,6 @@ maxValue=10.0 minValue=-10.0 offset=0.0 precision=3 -resolution=0.007 +deadband=0.007 scale=1.0 unit=A diff --git a/devices/S10CB06-RMOD:FIL-I-SET.properties b/devices/S10CB06-RMOD:FIL-I-SET.properties index c83dac2..18d7a72 100644 --- a/devices/S10CB06-RMOD:FIL-I-SET.properties +++ b/devices/S10CB06-RMOD:FIL-I-SET.properties @@ -7,4 +7,4 @@ rotation=false precision=-1 sign_bit=0 scale=1.0 -resolution=NaN +deadband=NaN diff --git a/devices/S10CB09-RSYS:SET-VSUM-PHASE.properties b/devices/S10CB09-RSYS:SET-VSUM-PHASE.properties index bc4ad79..abc92f9 100755 --- a/devices/S10CB09-RSYS:SET-VSUM-PHASE.properties +++ b/devices/S10CB09-RSYS:SET-VSUM-PHASE.properties @@ -3,7 +3,7 @@ maxValue=0.0 minValue=0.0 offset=0.0 precision=4 -resolution=0.1 +deadband=0.1 rotation=true scale=1.0 unit=deg diff --git a/devices/S20SY01-MQUA080.properties b/devices/S20SY01-MQUA080.properties index c52e4b8..934588f 100755 --- a/devices/S20SY01-MQUA080.properties +++ b/devices/S20SY01-MQUA080.properties @@ -3,6 +3,6 @@ maxValue=10.0 minValue=-10.0 offset=0.0 precision=3 -resolution=0.007 +deadband=0.007 scale=1.0 unit=A diff --git a/devices/S20SY01.MQUA080.properties b/devices/S20SY01.MQUA080.properties index d8077de..43f2ac1 100755 --- a/devices/S20SY01.MQUA080.properties +++ b/devices/S20SY01.MQUA080.properties @@ -3,6 +3,6 @@ maxValue=10.0 minValue=-10.0 offset=0.0 precision=3 -resolution=0.007 +deadband=0.007 scale=1.0 unit=null diff --git a/devices/SARMA01-MQUA010.properties b/devices/SARMA01-MQUA010.properties index ecc76cd..2c90739 100755 --- a/devices/SARMA01-MQUA010.properties +++ b/devices/SARMA01-MQUA010.properties @@ -3,6 +3,6 @@ maxValue=10.0 minValue=-10.0 offset=0.0 precision=3 -resolution=0.007 +deadband=0.007 scale=1.0 unit=A diff --git a/devices/SARMA01-MQUA10.properties b/devices/SARMA01-MQUA10.properties index 0a8b9d7..fb6bc68 100755 --- a/devices/SARMA01-MQUA10.properties +++ b/devices/SARMA01-MQUA10.properties @@ -3,6 +3,6 @@ maxValue=10.0 minValue=-10.0 offset=0.0 precision=3 -resolution=0.007 +deadband=0.007 scale=1.0 unit=null diff --git a/devices/SARUN02-MCRX080.properties b/devices/SARUN02-MCRX080.properties index 2c5d4b7..b19666f 100755 --- a/devices/SARUN02-MCRX080.properties +++ b/devices/SARUN02-MCRX080.properties @@ -3,6 +3,6 @@ maxValue=5.0 minValue=-5.0 offset=0.0 precision=3 -resolution=NaN +deadband=NaN scale=1.0 unit=A diff --git a/devices/SARUN02-MCRY080.properties b/devices/SARUN02-MCRY080.properties index 427a68a..8986aa3 100755 --- a/devices/SARUN02-MCRY080.properties +++ b/devices/SARUN02-MCRY080.properties @@ -3,6 +3,6 @@ maxValue=5.0 minValue=-5.0 offset=0.0 precision=3 -resolution=NaN +deadband=NaN scale=1.0 unit=A diff --git a/devices/SARUN02_MCRX080.properties b/devices/SARUN02_MCRX080.properties index 671c895..a3bdf71 100755 --- a/devices/SARUN02_MCRX080.properties +++ b/devices/SARUN02_MCRX080.properties @@ -3,6 +3,6 @@ maxValue=5.0 minValue=-5.0 offset=0.0 precision=3 -resolution=NaN +deadband=NaN scale=1.0 unit=A diff --git a/devices/SARUN02_MCRY080.properties b/devices/SARUN02_MCRY080.properties index 22e4997..0bbc3fc 100755 --- a/devices/SARUN02_MCRY080.properties +++ b/devices/SARUN02_MCRY080.properties @@ -3,6 +3,6 @@ maxValue=5.0 minValue=-5.0 offset=0.0 precision=3 -resolution=NaN +deadband=NaN scale=1.0 unit=A diff --git a/devices/SINEG01-DBPM340.properties b/devices/SINEG01-DBPM340.properties index fcf8756..ad4ff20 100755 --- a/devices/SINEG01-DBPM340.properties +++ b/devices/SINEG01-DBPM340.properties @@ -3,6 +3,6 @@ maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN scale=1.0 unit=null diff --git a/devices/SINEG01-RSYS:SET-BEAM-PHASE-SIM.properties b/devices/SINEG01-RSYS:SET-BEAM-PHASE-SIM.properties index 79fc5eb..4f817d3 100755 --- a/devices/SINEG01-RSYS:SET-BEAM-PHASE-SIM.properties +++ b/devices/SINEG01-RSYS:SET-BEAM-PHASE-SIM.properties @@ -3,7 +3,7 @@ maxValue=360.0 minValue=-360.0 offset=0.0 precision=3 -resolution=0.1 +deadband=0.1 rotation=false scale=1.0 unit=deg diff --git a/devices/SINEG01-RSYS:SET-BEAM-PHASE.properties b/devices/SINEG01-RSYS:SET-BEAM-PHASE.properties index 9ebc166..d56e183 100755 --- a/devices/SINEG01-RSYS:SET-BEAM-PHASE.properties +++ b/devices/SINEG01-RSYS:SET-BEAM-PHASE.properties @@ -3,7 +3,7 @@ maxValue=360.0 minValue=-360.0 offset=0.0 precision=3 -resolution=0.1 +deadband=0.1 rotation=false scale=1.0 unit=deg diff --git a/devices/SINSB01_phase.properties b/devices/SINSB01_phase.properties index 3367de0..3ba0e43 100755 --- a/devices/SINSB01_phase.properties +++ b/devices/SINSB01_phase.properties @@ -3,7 +3,7 @@ maxValue=360.0 minValue=0.0 offset=0.0 precision=3 -resolution=NaN +deadband=NaN rotation=false scale=1.0 unit=Degree diff --git a/devices/STEST01-RSYS:SET-VSUM-PHASE.properties b/devices/STEST01-RSYS:SET-VSUM-PHASE.properties index a3ae393..dafc8fb 100755 --- a/devices/STEST01-RSYS:SET-VSUM-PHASE.properties +++ b/devices/STEST01-RSYS:SET-VSUM-PHASE.properties @@ -3,7 +3,7 @@ maxValue=360.0 minValue=-90.0 offset=0.0 precision=3 -resolution=0.1 +deadband=0.1 rotation=true scale=1.0 unit=deg diff --git a/devices/SimMotor.properties b/devices/SimMotor.properties index 954fd2c..9abc432 100755 --- a/devices/SimMotor.properties +++ b/devices/SimMotor.properties @@ -7,7 +7,7 @@ minSpeed=0.1 minValue=-10.0 offset=0.0 precision=2 -resolution=NaN +deadband=NaN rotation=false scale=1.0 unit=mm diff --git a/devices/TDS Phase.properties b/devices/TDS Phase.properties index 2e0e77a..8aef414 100644 --- a/devices/TDS Phase.properties +++ b/devices/TDS Phase.properties @@ -8,4 +8,4 @@ precision=4 sign_bit=0 scale=1.0 description=Dest. beam phase -resolution=0.05 +deadband=0.05 diff --git a/devices/Test.properties b/devices/Test.properties index 012ef8a..d5c408f 100755 --- a/devices/Test.properties +++ b/devices/Test.properties @@ -3,7 +3,7 @@ maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN rotation=false scale=1.0 unit=null diff --git a/devices/TestCV.properties b/devices/TestCV.properties index 431eb41..f8541db 100644 --- a/devices/TestCV.properties +++ b/devices/TestCV.properties @@ -3,7 +3,7 @@ offset=0.0 maxValue=210.0 precision=1 scale=1.0 -resolution=NaN +deadband=NaN minValue=0.0 unit=A sign_bit=0 diff --git a/devices/TestP.properties b/devices/TestP.properties index 74c7845..040dc79 100644 --- a/devices/TestP.properties +++ b/devices/TestP.properties @@ -4,7 +4,7 @@ maxValue=210.0 rotation=false precision=1 scale=1.0 -resolution=NaN +deadband=NaN minValue=0.0 unit=A sign_bit=0 diff --git a/devices/Time.properties b/devices/Time.properties index 29e5cb0..d2a214d 100755 --- a/devices/Time.properties +++ b/devices/Time.properties @@ -8,4 +8,4 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/WireScanner motor.properties b/devices/WireScanner motor.properties index ebeacfc..b1d55d1 100755 --- a/devices/WireScanner motor.properties +++ b/devices/WireScanner motor.properties @@ -1,19 +1,19 @@ -#Thu Dec 11 15:41:25 CET 2025 +#Sat Feb 07 18:10:03 CET 2026 +deadband=0.1 +defaultSpeed=2000.0 +description=PPMAC motor record +estbilizationDelay=0 +hasEnable=false +homingType=None +maxSpeed=2000.0 +maxValue=51500.0 +minSpeed=5.0 +minValue=-66903.0 +monitorByPosition=false offset=0.0 -maxValue=68500.0 precision=1 rotation=false scale=1.0 -description=PPMAC motor record -estbilizationDelay=0 -maxSpeed=2000.0 -resolution=0.1 -homingType=None -startRetries=1 -minValue=-70000.0 -unit=um -defaultSpeed=2000.0 -hasEnable=false sign_bit=0 -monitorByPosition=false -minSpeed=5.0 +startRetries=1 +unit=um diff --git a/devices/beam_phase.properties b/devices/beam_phase.properties index 149090e..d5ba3a1 100755 --- a/devices/beam_phase.properties +++ b/devices/beam_phase.properties @@ -3,6 +3,6 @@ maxValue=360.0 minValue=0.0 offset=0.0 precision=3 -resolution=NaN +deadband=NaN scale=1.0 unit=Degree diff --git a/devices/bpm_1_down_gun.properties b/devices/bpm_1_down_gun.properties index 9ba674a..a9dc564 100755 --- a/devices/bpm_1_down_gun.properties +++ b/devices/bpm_1_down_gun.properties @@ -3,6 +3,6 @@ maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN scale=1.0 unit=null diff --git a/devices/cam_server.properties b/devices/cam_server.properties index fb33f42..83dc127 100755 --- a/devices/cam_server.properties +++ b/devices/cam_server.properties @@ -1,25 +1,26 @@ -#Fri Oct 03 16:35:45 CEST 2025 -spatialCalOffsetY=-795.999998704586 -spatialCalOffsetX=-873.9999719532899 -colormapLogarithmic=false -scale=1.0 -grayscale=false -spatialCalScaleX=-20.775623700157773 -spatialCalScaleY=-21.55172349612865 -colormapMax=NaN -rescaleOffset=0.0 -roiWidth=-1 +#Sun Feb 08 08:34:51 CET 2026 colormap=Flame -invert=false +colormapAutomatic=true +colormapLogarithmic=false +colormapMax=NaN colormapMin=NaN +flipHorizontally=false +flipVertically=false +grayscale=false +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 rotation=0.0 rotationCrop=false -rescaleFactor=1.0 +scale=1.0 +serverURL=null +spatialCalOffsetX=-861.0000211619925 +spatialCalOffsetY=-829.0000262816876 +spatialCalScaleX=-18.90359092620482 +spatialCalScaleY=-19.607842977590828 spatialCalUnits=mm -flipVertically=false -roiHeight=-1 -flipHorizontally=false -colormapAutomatic=true -roiY=0 -roiX=0 transpose=false diff --git a/devices/charge.properties b/devices/charge.properties index dd3b894..124eedf 100755 --- a/devices/charge.properties +++ b/devices/charge.properties @@ -1,4 +1,4 @@ -#Tue Aug 16 16:27:15 CEST 2022 +#Wed Jan 07 13:30:45 CET 2026 minValue=NaN unit=pC offset=0.0 @@ -7,4 +7,5 @@ precision=1 sign_bit=0 scale=1.0 description=null +deadband=NaN resolution=NaN diff --git a/devices/cv.properties b/devices/cv.properties index 813be07..45ac602 100755 --- a/devices/cv.properties +++ b/devices/cv.properties @@ -3,6 +3,6 @@ maxValue=360.0 minValue=0.0 offset=0.0 precision=3 -resolution=NaN +deadband=NaN scale=1.0 unit=Degree diff --git a/devices/energy_AR.properties b/devices/energy_AR.properties index e7fbe47..c6556b9 100755 --- a/devices/energy_AR.properties +++ b/devices/energy_AR.properties @@ -1,4 +1,4 @@ -#Tue Aug 16 16:27:15 CEST 2022 +#Wed Jan 07 13:30:45 CET 2026 minValue=NaN unit=MeV offset=0.0 @@ -7,4 +7,5 @@ precision=3 sign_bit=0 scale=1.0 description=null +deadband=NaN resolution=NaN diff --git a/devices/energy_B1.properties b/devices/energy_B1.properties index 223ff7c..fc3ab74 100755 --- a/devices/energy_B1.properties +++ b/devices/energy_B1.properties @@ -3,7 +3,7 @@ maxValue=NaN minValue=NaN offset=0.0 precision=3 -resolution=NaN +deadband=NaN scale=1.0 sign_bit=0 unit=MeV diff --git a/devices/gain 1.properties b/devices/gain 1.properties index 0835d7b..cf5f96e 100755 --- a/devices/gain 1.properties +++ b/devices/gain 1.properties @@ -3,6 +3,6 @@ maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN scale=1.0 unit=null diff --git a/devices/gain 2.properties b/devices/gain 2.properties index c3fb410..fa33708 100755 --- a/devices/gain 2.properties +++ b/devices/gain 2.properties @@ -3,6 +3,6 @@ maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN scale=1.0 unit=null diff --git a/devices/gain.properties b/devices/gain.properties index 2233327..cf6b08b 100755 --- a/devices/gain.properties +++ b/devices/gain.properties @@ -3,6 +3,6 @@ maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN scale=1.0 unit=null diff --git a/devices/gsrx.properties b/devices/gsrx.properties index 102f6f0..358c49e 100755 --- a/devices/gsrx.properties +++ b/devices/gsrx.properties @@ -8,4 +8,4 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/gsry.properties b/devices/gsry.properties index 102f6f0..358c49e 100755 --- a/devices/gsry.properties +++ b/devices/gsry.properties @@ -8,4 +8,4 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/gsx.properties b/devices/gsx.properties index 53f20f9..038b710 100755 --- a/devices/gsx.properties +++ b/devices/gsx.properties @@ -8,4 +8,4 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/gsy.properties b/devices/gsy.properties index 53f20f9..038b710 100755 --- a/devices/gsy.properties +++ b/devices/gsy.properties @@ -8,4 +8,4 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/gun_phase.properties b/devices/gun_phase.properties index d630282..5ccf027 100755 --- a/devices/gun_phase.properties +++ b/devices/gun_phase.properties @@ -1,4 +1,4 @@ -#Tue Aug 16 16:27:15 CEST 2022 +#Wed Jan 07 13:30:45 CET 2026 minValue=-179.99 unit=DEG offset=0.0 @@ -8,4 +8,5 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=1.0 +deadband=1.0 +resolution=NaN diff --git a/devices/gun_sol_current.properties b/devices/gun_sol_current.properties index c443463..cf14120 100755 --- a/devices/gun_sol_current.properties +++ b/devices/gun_sol_current.properties @@ -3,6 +3,6 @@ maxValue=210.0 minValue=0.0 offset=0.0 precision=3 -resolution=NaN +deadband=NaN scale=1.0 unit=A diff --git a/devices/gun_solenoid.properties b/devices/gun_solenoid.properties index d9c7081..1b41728 100755 --- a/devices/gun_solenoid.properties +++ b/devices/gun_solenoid.properties @@ -1,4 +1,4 @@ -#Tue Aug 16 16:27:15 CEST 2022 +#Wed Jan 07 13:30:45 CET 2026 minValue=0.0 unit=A offset=0.0 @@ -8,4 +8,5 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=0.02 +deadband=0.02 +resolution=NaN diff --git a/devices/kick.properties b/devices/kick.properties index 4ff8701..3df957b 100755 --- a/devices/kick.properties +++ b/devices/kick.properties @@ -7,4 +7,4 @@ rotation=false precision=3 sign_bit=0 scale=1.0 -resolution=0.1 +deadband=0.1 diff --git a/devices/kick1.properties b/devices/kick1.properties index 61f5264..1de0165 100755 --- a/devices/kick1.properties +++ b/devices/kick1.properties @@ -7,4 +7,4 @@ rotation=false precision=3 sign_bit=0 scale=1.0 -resolution=NaN +deadband=NaN diff --git a/devices/kick2.properties b/devices/kick2.properties index 61f5264..1de0165 100755 --- a/devices/kick2.properties +++ b/devices/kick2.properties @@ -7,4 +7,4 @@ rotation=false precision=3 sign_bit=0 scale=1.0 -resolution=NaN +deadband=NaN diff --git a/devices/kick3.properties b/devices/kick3.properties index 812ef22..eadb14b 100755 --- a/devices/kick3.properties +++ b/devices/kick3.properties @@ -7,4 +7,4 @@ rotation=false precision=3 sign_bit=0 scale=1.0 -resolution=NaN +deadband=NaN diff --git a/devices/m1.properties b/devices/m1.properties index e74d0ab..46019ad 100755 --- a/devices/m1.properties +++ b/devices/m1.properties @@ -7,7 +7,7 @@ scale=1.0 description=null estbilizationDelay=0 maxSpeed=10.0 -resolution=NaN +deadband=NaN startRetries=1 minValue=-10.0 unit=mm diff --git a/devices/m2.properties b/devices/m2.properties index e74d0ab..46019ad 100755 --- a/devices/m2.properties +++ b/devices/m2.properties @@ -7,7 +7,7 @@ scale=1.0 description=null estbilizationDelay=0 maxSpeed=10.0 -resolution=NaN +deadband=NaN startRetries=1 minValue=-10.0 unit=mm diff --git a/devices/m3.properties b/devices/m3.properties index 84d6771..a4b86dc 100755 --- a/devices/m3.properties +++ b/devices/m3.properties @@ -7,6 +7,6 @@ minSpeed=0.1 minValue=-10.0 offset=0.0 precision=2 -resolution=NaN +deadband=NaN scale=1.0 unit=mm diff --git a/devices/mot.properties b/devices/mot.properties index 558d71a..c91e510 100755 --- a/devices/mot.properties +++ b/devices/mot.properties @@ -7,6 +7,6 @@ minSpeed=0.1 minValue=-10.0 offset=0.0 precision=2 -resolution=NaN +deadband=NaN scale=1.0 unit=mm diff --git a/devices/p1.properties b/devices/p1.properties index 3a98f61..172d373 100755 --- a/devices/p1.properties +++ b/devices/p1.properties @@ -8,4 +8,4 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/pbpg_mx.properties b/devices/pbpg_mx.properties index bc87caa..0f89abf 100755 --- a/devices/pbpg_mx.properties +++ b/devices/pbpg_mx.properties @@ -9,7 +9,7 @@ minSpeed=NaN minValue=-0.6 offset=0.0 precision=3 -resolution=0.02 +deadband=0.02 rotation=false scale=1.0 unit=mm diff --git a/devices/pbpg_my.properties b/devices/pbpg_my.properties index a2d476c..662116f 100755 --- a/devices/pbpg_my.properties +++ b/devices/pbpg_my.properties @@ -9,7 +9,7 @@ minSpeed=NaN minValue=-1.4 offset=0.0 precision=3 -resolution=0.02 +deadband=0.02 rotation=false scale=1.0 unit=mm diff --git a/devices/pos.properties b/devices/pos.properties index 44422f8..3312afc 100755 --- a/devices/pos.properties +++ b/devices/pos.properties @@ -7,4 +7,4 @@ precision=3 rotation=false sign_bit=0 scale=1.0 -resolution=NaN +deadband=NaN diff --git a/devices/positioner.properties b/devices/positioner.properties index d452287..9d873fb 100755 --- a/devices/positioner.properties +++ b/devices/positioner.properties @@ -1,9 +1,10 @@ -#Thu Sep 27 07:12:39 CEST 2018 +#Tue Dec 16 10:03:37 CET 2025 +deadband=NaN +description=null maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN rotation=false scale=1.0 sign_bit=0 diff --git a/devices/pv.properties b/devices/pv.properties index 5ea8da8..7730fff 100755 --- a/devices/pv.properties +++ b/devices/pv.properties @@ -3,6 +3,6 @@ maxValue=0.0 minValue=0.0 offset=0.0 precision=3 -resolution=0.01 +deadband=0.01 scale=1.0 unit=Degree diff --git a/devices/quad.properties b/devices/quad.properties index 439f98b..0598b4a 100755 --- a/devices/quad.properties +++ b/devices/quad.properties @@ -7,4 +7,4 @@ rotation=false precision=3 sign_bit=0 scale=1.0 -resolution=NaN +deadband=NaN diff --git a/devices/rep_rate.properties b/devices/rep_rate.properties index dd8297a..2f20ea4 100755 --- a/devices/rep_rate.properties +++ b/devices/rep_rate.properties @@ -3,7 +3,7 @@ maxValue=NaN minValue=NaN offset=0.0 precision=2 -resolution=NaN +deadband=NaN scale=1.0 sign_bit=0 unit=Hz diff --git a/devices/rep_rate_bunch_1.properties b/devices/rep_rate_bunch_1.properties index 86603f5..f747f19 100644 --- a/devices/rep_rate_bunch_1.properties +++ b/devices/rep_rate_bunch_1.properties @@ -1,4 +1,4 @@ -#Tue Aug 16 16:29:34 CEST 2022 +#Wed Jan 07 13:30:45 CET 2026 minValue=0.0 unit=Hz offset=0.0 @@ -7,4 +7,5 @@ precision=2 sign_bit=0 scale=1.0 description=null +deadband=NaN resolution=NaN diff --git a/devices/rep_rate_bunch_2.properties b/devices/rep_rate_bunch_2.properties index 86603f5..f747f19 100644 --- a/devices/rep_rate_bunch_2.properties +++ b/devices/rep_rate_bunch_2.properties @@ -1,4 +1,4 @@ -#Tue Aug 16 16:29:34 CEST 2022 +#Wed Jan 07 13:30:45 CET 2026 minValue=0.0 unit=Hz offset=0.0 @@ -7,4 +7,5 @@ precision=2 sign_bit=0 scale=1.0 description=null +deadband=NaN resolution=NaN diff --git a/devices/rot 1.properties b/devices/rot 1.properties index 9cdd5b4..df93ade 100755 --- a/devices/rot 1.properties +++ b/devices/rot 1.properties @@ -3,7 +3,7 @@ maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN rotation=false scale=1.0 unit=null diff --git a/devices/scanner.properties b/devices/scanner.properties index 8396081..63a78d8 100755 --- a/devices/scanner.properties +++ b/devices/scanner.properties @@ -3,7 +3,7 @@ maxValue=NaN minValue=NaN offset=0.0 precision=-1 -resolution=NaN +deadband=NaN rotation=false scale=1.0 sign_bit=0 diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100755 index 349a5b1..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM docker.psi.ch:5000/busybox_java -#COPY ./pshell-1.7.0-fat.jar /pshell/ -RUN cd / -RUN mkdir pshell -RUN cd /pshell -RUN wget -O /pshell/pshell-1.7.0-fat.jar http://artifacts.psi.ch/artifactory/releases/ch/psi/pshell/1.7.0/pshell-1.7.0-fat.jar --no-check-certificate -#RUN ls /pshell - -#COPY ./home/ /pshell/home/ -EXPOSE 5000-10000 - -CMD ls -al /pshell/home/log; while true; do echo "Starting";java -Djava.awt.headless=true -jar /pshell/pshell-1.7.0-fat.jar -v -home=/pshell/home -clog=FINE; done \ No newline at end of file diff --git a/docker/build.sh b/docker/build.sh deleted file mode 100755 index 2937d85..0000000 --- a/docker/build.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -VERSION=1.7.0 -docker build --no-cache=true -t docker.psi.ch:5000/pshell_server . -docker tag docker.psi.ch:5000/pshell_server docker.psi.ch:5000/pshell_server:$VERSION -docker push docker.psi.ch:5000/pshell_server:$VERSION -docker push docker.psi.ch:5000/pshell_server diff --git a/docker/start.sh b/docker/start.sh deleted file mode 100755 index a97ad47..0000000 --- a/docker/start.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -docker run --network="host" --name pshellsrv -v /home/gobbo/docker/home:/pshell/home -v /etc/timezone:/etc/timezone:ro -v /etc/localtime:/etc/localtime:ro docker.psi.ch:5000/pshell_server & - diff --git a/docker/stop.sh b/docker/stop.sh deleted file mode 100755 index e1b4c3c..0000000 --- a/docker/stop.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -docker stop pshellsrv -docker rm pshellsrv diff --git a/docker/wb.sh b/docker/wb.sh deleted file mode 100755 index 6291ddc..0000000 --- a/docker/wb.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -wget -O ./pshell-1.7.0-fat.jar http://artifacts.psi.ch/artifactory/releases/ch/psi/pshell/1.7.0/pshell-1.7.0-fat.jar --no-check-certificate - -java -jar ./pshell-1.7.0-fat.jar -o -dlaf - -rm ./pshell-1.7.0-fat.jar \ No newline at end of file diff --git a/plugins/BunchLength.form b/plugins/BunchLength.form index f25d25a..fc15593 100755 --- a/plugins/BunchLength.form +++ b/plugins/BunchLength.form @@ -84,7 +84,7 @@ - + diff --git a/plugins/BunchLength.java b/plugins/BunchLength.java index f6eabc6..7d4ec15 100755 --- a/plugins/BunchLength.java +++ b/plugins/BunchLength.java @@ -2,20 +2,16 @@ * Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved. */ -import ch.psi.pshell.core.Context; import ch.psi.pshell.plot.LinePlot; -import ch.psi.pshell.plot.LinePlotSeries; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.ui.AppListener; -import ch.psi.utils.State; -import ch.psi.utils.swing.SwingUtils; -import java.awt.Color; +import ch.psi.pshell.framework.App; +import ch.psi.pshell.app.AppListener; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.utils.State; +import ch.psi.pshell.swing.SwingUtils; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.script.ScriptException; import javax.swing.JSpinner; /** diff --git a/plugins/CameraCalibrationDialog.form b/plugins/CameraCalibrationDialog.form deleted file mode 100755 index 4ac7ff9..0000000 --- a/plugins/CameraCalibrationDialog.form +++ /dev/null @@ -1,545 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/CameraCalibrationDialog.java b/plugins/CameraCalibrationDialog.java deleted file mode 100755 index 2a93151..0000000 --- a/plugins/CameraCalibrationDialog.java +++ /dev/null @@ -1,726 +0,0 @@ - - -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.pshell.bs.CameraServer; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.ui.App; -import ch.psi.utils.Convert; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Frame; -import java.awt.Point; -import java.awt.Rectangle; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.swing.JDialog; - - -/* - */ - -/** - * - */ -public class CameraCalibrationDialog extends StandardDialog { - - CameraServer server; - Renderer renderer; - String cameraName; - Overlay[] calibrationOverlays; - Pen pen = new Pen(new Color(128, 0, 128), 1, Pen.LineStyle.solid); - Overlays.Crosshairs ovTop = new Overlays.Crosshairs(pen, new Dimension(-1, 1)); - Overlays.Crosshairs ovBottom = new Overlays.Crosshairs(pen, new Dimension(-1, 1)); - Overlays.Crosshairs ovLeft = new Overlays.Crosshairs(pen, new Dimension(1, -1)); - Overlays.Crosshairs ovRight = new Overlays.Crosshairs(pen, new Dimension(1, -1)); - - /** - * - * { - * name=SINEG01-DSCR350, - * prefix=SINEG01-DSCR350, - * mirror_x=true, - * mirror_y=true, - * rotate=0, - * calibration={ - * horizontal_camera_angle=0, - * vertical_camera_angle=0 - * reference_marker_width=16000.0, - * reference_marker_height=16000.0, - * reference_marker=[120, 245, 1251, 1504], - * }, - * } - */ - public CameraCalibrationDialog(Frame parent, String cameraName, Renderer renderer) throws IOException { - super(parent, cameraName, false); - - initComponents(); - - if (App.hasArgument("cam_srv_url")) { - this.server = new CameraServer("Camera Server", App.getArgumentValue("cam_srv_url")); - } else { - this.server = new CameraServer("Camera Server"); - } - - - this.cameraName = cameraName; - this.renderer = renderer; - - Map config = server.getConfig(cameraName); - Map calibration = (Map) config.get("camera_calibration"); - List refMarker = null; - System.out.println("Current config: " + config); - checkMirrorX.setSelected((config.get("mirror_x") ==null) ? Boolean.FALSE: (Boolean)config.get("mirror_x")); - checkMirrorY.setSelected((config.get("mirror_y") ==null) ? Boolean.FALSE: (Boolean)config.get("mirror_y")); - comboRotation.setSelectedIndex((config.get("rotate") == null) ? 0 :(Integer) (config.get("rotate"))); - ckCalibrationEnabled.setSelected(calibration!=null); - if (calibration!=null){ - spinnerRefWidth.setValue(((Number)calibration.get("reference_marker_width")).doubleValue()); - spinnerRefHeight.setValue(((Number)calibration.get("reference_marker_height")).doubleValue()); - spinnerAngleHor.setValue(((Number)calibration.get("angle_horizontal")).doubleValue()); - spinnerAngleVer.setValue(((Number)calibration.get("angle_vertical")).doubleValue()); - refMarker = ((List)calibration.get("reference_marker")); - if (refMarker.size()==4){ - spinnerLeft.setValue(refMarker.get(0)); - spinnerTop.setValue(refMarker.get(1)); - spinnerRight.setValue(refMarker.get(2)); - spinnerBottom.setValue(refMarker.get(3)); - } - } - updateResults(); - - - renderer.setMode(RendererMode.Fit); - calibrationOverlays = new Overlay[]{ovTop, ovBottom, ovLeft, ovRight}; - for (Overlay ov : calibrationOverlays){ - ov.setMovable(true); - } - renderer.addOverlays(calibrationOverlays); - - try{ - Rectangle r = new Rectangle(); - ovLeft.update(new Point(Math.max(refMarker.get(0), 0), 0)); - ovTop.update(new Point(0, Math.max(refMarker.get(1), 0))); - ovRight.update(new Point(Math.max(refMarker.get(2), 0), 0)); - ovBottom.update(new Point(0, Math.max(refMarker.get(3),0))); - } catch (Exception ex){ - SwingUtils.invokeDelayed(() -> { - Dimension size = renderer.getImageSize(); - ovTop.update(new Point(0, size.height/8)); - ovBottom.update(new Point(0, 7*size.height/8)); - ovLeft.update(new Point(size.width/8, 0)); - ovRight.update(new Point(7*size.width/8, 0)); - }, 500); - } - renderer.addListener(new RendererListener(){ - @Override - public void onMoveFinished(Renderer renderer, Overlay overlay) { - if (overlay==ovTop){ - spinnerTop.setValue(ovTop.getPosition().y); - } else if (overlay==ovBottom){ - spinnerBottom.setValue(ovBottom.getPosition().y); - } else if (overlay==ovLeft){ - spinnerLeft.setValue(ovLeft.getPosition().x); - } else if (overlay==ovRight){ - spinnerRight.setValue(ovRight.getPosition().x); - } - } - }); - setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - pack(); - } - - @Override - protected void onClosed() { - renderer.removeOverlays(calibrationOverlays); - calibrationOverlays = null; - server.close(); - } - - - void updateResults(){ - try{ - int left = (Integer)spinnerLeft.getValue(); - int right = (Integer)spinnerRight.getValue(); - int top = (Integer)spinnerTop.getValue(); - int bottom = (Integer)spinnerBottom.getValue(); - double width = (Double)spinnerRefWidth.getValue(); - double height = (Double)spinnerRefHeight.getValue(); - double angleHor = (Double)spinnerAngleHor.getValue(); - double angleVer = (Double)spinnerAngleVer.getValue(); - double pixelHor = width * Math.cos(Math.toRadians(angleHor)) /Math.abs(right-left); - double pixelVer = height * Math.cos(Math.toRadians(angleVer)) /Math.abs(bottom-top); - textOriginX.setText(String.valueOf((left+right)/2)); - textOriginY.setText(String.valueOf((top+bottom)/2)); - textPixelSizeX.setText(String.valueOf(Convert.roundDouble(pixelHor, 2))); - textPixelSizeY.setText(String.valueOf(Convert.roundDouble(pixelVer, 2))); - ovLeft.update(new Point(Math.max(left, 0), 0)); - ovTop.update(new Point(0, Math.max(top, 0))); - ovRight.update(new Point(Math.max(right, 0), 0)); - ovBottom.update(new Point(0, Math.max(bottom,0))); - renderer.refresh(); - - } catch (Exception ex){ - SwingUtils.showException(this, ex); - } - } - - - public static void main(String args[]) throws Exception { - //String cameraName = "SINEG01-DSCR190"; - String cameraName = "SATSY02-DSCR220" ; - //java.awt.EventQueue.invokeLater(() -> { - Renderer renderer = new Renderer(); - JDialog dlgRenderer = SwingUtils.showDialog(null, cameraName, new Dimension(600,400), renderer); - CameraCalibrationDialog dialog = new CameraCalibrationDialog(null, cameraName, renderer); - dialog.addWindowListener(new java.awt.event.WindowAdapter() { - @Override - public void windowClosing(java.awt.event.WindowEvent e) { - dlgRenderer.setVisible(false); - System.exit(0); - } - }); - SwingUtils.centerComponent(null, dialog); - dialog.setVisible(true); - // }); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel1 = new javax.swing.JLabel(); - jPanel1 = new javax.swing.JPanel(); - jLabel4 = new javax.swing.JLabel(); - jLabel5 = new javax.swing.JLabel(); - jLabel6 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jLabel8 = new javax.swing.JLabel(); - jLabel9 = new javax.swing.JLabel(); - jLabel10 = new javax.swing.JLabel(); - spinnerAngleHor = new javax.swing.JSpinner(); - spinnerAngleVer = new javax.swing.JSpinner(); - spinnerRefWidth = new javax.swing.JSpinner(); - spinnerRefHeight = new javax.swing.JSpinner(); - spinnerTop = new javax.swing.JSpinner(); - spinnerBottom = new javax.swing.JSpinner(); - spinnerLeft = new javax.swing.JSpinner(); - spinnerRight = new javax.swing.JSpinner(); - buttonFetch = new javax.swing.JButton(); - ckCalibrationEnabled = new javax.swing.JCheckBox(); - jPanel2 = new javax.swing.JPanel(); - checkMirrorX = new javax.swing.JCheckBox(); - checkMirrorY = new javax.swing.JCheckBox(); - comboRotation = new javax.swing.JComboBox(); - jLabel7 = new javax.swing.JLabel(); - jPanel3 = new javax.swing.JPanel(); - jLabel11 = new javax.swing.JLabel(); - textOriginX = new javax.swing.JTextField(); - jLabel12 = new javax.swing.JLabel(); - textOriginY = new javax.swing.JTextField(); - jLabel13 = new javax.swing.JLabel(); - jLabel14 = new javax.swing.JLabel(); - textPixelSizeX = new javax.swing.JTextField(); - textPixelSizeY = new javax.swing.JTextField(); - buttonOk = new javax.swing.JButton(); - buttonCancel = new javax.swing.JButton(); - buttonApply = new javax.swing.JButton(); - - jLabel1.setText("Calibrate the camera moving the line overlays to the reference marks."); - - jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Calibration")); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Reference marker height (um):"); - - jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel5.setText("Horizontal camera angle (deg):"); - - jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel6.setText("Vertical camera angle (deg):"); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Reference marker width (um):"); - - jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel2.setText("Top (px):"); - - jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel8.setText("Botton (px):"); - - jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel9.setText("Left (px):"); - - jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel10.setText("Right (px):"); - - spinnerAngleHor.setModel(new javax.swing.SpinnerNumberModel(0.0d, -360.0d, 360.0d, 1.0d)); - spinnerAngleHor.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerAngleVer.setModel(new javax.swing.SpinnerNumberModel(0.0d, -360.0d, 360.0d, 1.0d)); - spinnerAngleVer.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerRefWidth.setModel(new javax.swing.SpinnerNumberModel(30000.0d, 1.0d, 500000.0d, 1.0d)); - spinnerRefWidth.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerRefHeight.setModel(new javax.swing.SpinnerNumberModel(30000.0d, 1.0d, 500000.0d, 1.0d)); - spinnerRefHeight.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerTop.setModel(new javax.swing.SpinnerNumberModel(0, -10000, 10000, 1)); - spinnerTop.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerBottom.setModel(new javax.swing.SpinnerNumberModel(0, -10000, 10000, 1)); - spinnerBottom.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerLeft.setModel(new javax.swing.SpinnerNumberModel(0, -10000, 10000, 1)); - spinnerLeft.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerRight.setModel(new javax.swing.SpinnerNumberModel(0, -10000, 10000, 1)); - spinnerRight.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - buttonFetch.setText("Fetch from Inventory"); - buttonFetch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFetchActionPerformed(evt); - } - }); - - ckCalibrationEnabled.setText("Enabled"); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerTop, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerRefWidth, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(jLabel8) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerBottom, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel4) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerRefHeight, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(jLabel10) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerRight, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel6) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerAngleVer, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(jLabel9) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerAngleHor, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addGap(9, 9, 9) - .addComponent(ckCalibrationEnabled) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonFetch))) - .addContainerGap()) - ); - - jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel10, jLabel2, jLabel8, jLabel9}); - - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(jLabel2) - .addComponent(spinnerRefWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerTop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel4) - .addComponent(jLabel8) - .addComponent(spinnerRefHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerBottom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel5) - .addComponent(jLabel9) - .addComponent(spinnerAngleHor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel6) - .addComponent(jLabel10) - .addComponent(spinnerAngleVer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonFetch) - .addComponent(ckCalibrationEnabled)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Transformations")); - - checkMirrorX.setText("Mirror X"); - - checkMirrorY.setText("Mirror Y"); - - comboRotation.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "270", "180", "90" })); - - jLabel7.setText("Rotation: "); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addComponent(checkMirrorX) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel7) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(comboRotation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel2Layout.createSequentialGroup() - .addComponent(checkMirrorY) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboRotation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel7)) - .addComponent(checkMirrorX)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(checkMirrorY) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Results")); - - jLabel11.setText("Origin X (px):"); - - textOriginX.setEditable(false); - textOriginX.setHorizontalAlignment(javax.swing.JTextField.CENTER); - - jLabel12.setText("Origin Y (px):"); - - textOriginY.setEditable(false); - textOriginY.setHorizontalAlignment(javax.swing.JTextField.CENTER); - - jLabel13.setText("Y pixel size (um/px):"); - - jLabel14.setText("X pixel size (um/px):"); - - textPixelSizeX.setEditable(false); - textPixelSizeX.setHorizontalAlignment(javax.swing.JTextField.CENTER); - - textPixelSizeY.setEditable(false); - textPixelSizeY.setHorizontalAlignment(javax.swing.JTextField.CENTER); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(21, 21, 21) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel12) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textOriginY, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel11) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textOriginX, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel13) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textPixelSizeY, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel14) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textPixelSizeX, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel11, jLabel12}); - - jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel13, jLabel14}); - - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel14) - .addComponent(textPixelSizeX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel13) - .addComponent(textPixelSizeY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel11) - .addComponent(textOriginX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel12) - .addComponent(textOriginY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addContainerGap()) - ); - - buttonOk.setText("Ok"); - buttonOk.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonOkActionPerformed(evt); - } - }); - - buttonCancel.setText("Cancel"); - buttonCancel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonCancelActionPerformed(evt); - } - }); - - buttonApply.setText("Apply"); - buttonApply.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonApplyActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(buttonCancel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(buttonApply) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(buttonOk) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonApply, buttonCancel, buttonOk}); - - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonOk) - .addComponent(buttonCancel) - .addComponent(buttonApply)) - .addContainerGap()) - ); - }// //GEN-END:initComponents - - private void buttonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOkActionPerformed - - buttonApplyActionPerformed(evt); - accept(); - }//GEN-LAST:event_buttonOkActionPerformed - - private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed - cancel(); - }//GEN-LAST:event_buttonCancelActionPerformed - - private void buttonFetchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFetchActionPerformed - try{ - //List calib = Inventory.getCalibFromInventory(null, cameraName); - List calib = (List) Class.forName("Inventory"). - getMethod("getCalibFromInventory", - new Class[]{String.class,String.class}). - invoke(null, new Object[]{(String)null, cameraName}); - spinnerRefWidth.setValue(calib.get(0)*1000.0); - spinnerRefHeight.setValue(calib.get(1)*1000.0); - spinnerAngleHor.setValue(calib.get(2).doubleValue()); - spinnerAngleVer.setValue(calib.get(3).doubleValue()); - } catch (Exception ex){ - if (ex instanceof InvocationTargetException){ - ex = (Exception) ((InvocationTargetException)ex).getCause(); - } - SwingUtils.showException(this, ex); - } - }//GEN-LAST:event_buttonFetchActionPerformed - - private void calibrationSpinnerChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_calibrationSpinnerChanged - updateResults(); - }//GEN-LAST:event_calibrationSpinnerChanged - - private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed - try { - int left = (Integer)spinnerLeft.getValue(); //left.getPosition().x - int right = (Integer)spinnerRight.getValue(); //right.getPosition().x - int top = (Integer)spinnerTop.getValue(); //top.getPosition().y - int bottom = (Integer)spinnerBottom.getValue(); //bottom.getPosition().y - double width = (Double)spinnerRefWidth.getValue(); - double height = (Double)spinnerRefHeight.getValue(); - double angleHor = (Double)spinnerAngleHor.getValue(); - double angleVer = (Double)spinnerAngleVer.getValue(); - - int x1 = Math.min(left, right); - int x2 = Math.max(left, right); - int y1 = Math.min(top, bottom); - int y2 = Math.max(top, bottom); - System.out.println("Updating " + cameraName + " configuration"); - HashMap calibration = null; - if (ckCalibrationEnabled.isSelected()){ - calibration = new HashMap(); - calibration.put("reference_marker", Arrays.asList(new Integer[]{x1, y1, x2, y2})); - calibration.put("reference_marker_width", width); - calibration.put("reference_marker_height", height); - calibration.put("angle_horizontal", angleHor); - calibration.put("angle_vertical", angleVer); - } - - Map config = server.getConfig(cameraName); - config.put("camera_calibration", calibration); - config.put("mirror_x", checkMirrorX.isSelected()); - config.put("mirror_y", checkMirrorY.isSelected()); - config.put("rotate", comboRotation.getSelectedIndex()); - server.setConfig(cameraName, config); - - System.out.println("New config: " + config); - boolean reticle = renderer.getShowReticle(); - if (reticle){ - renderer.setShowReticle(false); - } - SwingUtils.showMessage(this, "Success", "Updated " + cameraName + " configuration"); - - if (reticle){ - renderer.setShowReticle(true); - } - } catch (Exception ex) { - SwingUtils.showException(this, ex); - } - }//GEN-LAST:event_buttonApplyActionPerformed - - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton buttonApply; - private javax.swing.JButton buttonCancel; - private javax.swing.JButton buttonFetch; - private javax.swing.JButton buttonOk; - private javax.swing.JCheckBox checkMirrorX; - private javax.swing.JCheckBox checkMirrorY; - private javax.swing.JCheckBox ckCalibrationEnabled; - private javax.swing.JComboBox comboRotation; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel10; - private javax.swing.JLabel jLabel11; - private javax.swing.JLabel jLabel12; - private javax.swing.JLabel jLabel13; - private javax.swing.JLabel jLabel14; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JLabel jLabel6; - private javax.swing.JLabel jLabel7; - private javax.swing.JLabel jLabel8; - private javax.swing.JLabel jLabel9; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JSpinner spinnerAngleHor; - private javax.swing.JSpinner spinnerAngleVer; - private javax.swing.JSpinner spinnerBottom; - private javax.swing.JSpinner spinnerLeft; - private javax.swing.JSpinner spinnerRefHeight; - private javax.swing.JSpinner spinnerRefWidth; - private javax.swing.JSpinner spinnerRight; - private javax.swing.JSpinner spinnerTop; - private javax.swing.JTextField textOriginX; - private javax.swing.JTextField textOriginY; - private javax.swing.JTextField textPixelSizeX; - private javax.swing.JTextField textPixelSizeY; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/CameraConfigDialog.form b/plugins/CameraConfigDialog.form deleted file mode 100755 index 73ac4fd..0000000 --- a/plugins/CameraConfigDialog.form +++ /dev/null @@ -1,524 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/CameraConfigDialog.java b/plugins/CameraConfigDialog.java deleted file mode 100755 index a5549a3..0000000 --- a/plugins/CameraConfigDialog.java +++ /dev/null @@ -1,696 +0,0 @@ - - -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.pshell.bs.Camtool; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.utils.Convert; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Frame; -import java.awt.Point; -import java.awt.Rectangle; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.swing.JDialog; - - -/* - */ - -/** - * - */ -public class CameraConfigDialog extends StandardDialog { - - Camtool camera; - Renderer renderer; - String cameraName; - Overlay[] calibrationOverlays; - Pen pen = new Pen(new Color(128, 0, 128), 1, Pen.LineStyle.solid); - Overlays.Crosshairs ovTop = new Overlays.Crosshairs(pen, new Dimension(-1, 1)); - Overlays.Crosshairs ovBottom = new Overlays.Crosshairs(pen, new Dimension(-1, 1)); - Overlays.Crosshairs ovLeft = new Overlays.Crosshairs(pen, new Dimension(1, -1)); - Overlays.Crosshairs ovRight = new Overlays.Crosshairs(pen, new Dimension(1, -1)); - - /** - * - * { - * name=SINEG01-DSCR350, - * prefix=SINEG01-DSCR350, - * mirror_x=true, - * mirror_y=true, - * rotate=0, - * calibration={ - * horizontal_camera_angle=0, - * vertical_camera_angle=0 - * reference_marker_width=16000.0, - * reference_marker_height=16000.0, - * reference_marker=[120, 245, 1251, 1504], - * }, - * } - */ - public CameraConfigDialog(Frame parent, Camtool camera, Renderer renderer) throws IOException { - super(parent, camera.getCurrentCamera(), false); - - initComponents(); - - this.camera = camera; - this.cameraName = camera.getCurrentCamera(); - this.renderer = renderer; - - Map config = camera.getConfig(cameraName); - Map calibration = (Map) config.get("calibration"); - List refMarker = null; - System.out.println("Current config: " + config); - checkMirrorX.setSelected((config.get("mirror_x") ==null) ? Boolean.FALSE: (Boolean)config.get("mirror_x")); - checkMirrorY.setSelected((config.get("mirror_y") ==null) ? Boolean.FALSE: (Boolean)config.get("mirror_y")); - comboRotation.setSelectedIndex((config.get("rotate") == null) ? 0 :(Integer) (config.get("rotate"))); - if (calibration!=null){ - spinnerRefWidth.setValue(((Number)calibration.get("reference_marker_width")).doubleValue()); - spinnerRefHeight.setValue(((Number)calibration.get("reference_marker_height")).doubleValue()); - spinnerAngleHor.setValue(((Number)calibration.get("horizontal_camera_angle")).doubleValue()); - spinnerAngleVer.setValue(((Number)calibration.get("vertical_camera_angle")).doubleValue()); - refMarker = ((List)calibration.get("reference_marker")); - if (refMarker.size()==4){ - spinnerLeft.setValue(refMarker.get(0)); - spinnerTop.setValue(refMarker.get(1)); - spinnerRight.setValue(refMarker.get(2)); - spinnerBottom.setValue(refMarker.get(3)); - } - } - updateResults(); - - camera.resetRoi(); - - - renderer.setMode(RendererMode.Fit); - calibrationOverlays = new Overlay[]{ovTop, ovBottom, ovLeft, ovRight}; - for (Overlay ov : calibrationOverlays){ - ov.setMovable(true); - } - renderer.addOverlays(calibrationOverlays); - - try{ - Rectangle r = new Rectangle(); - ovLeft.update(new Point(Math.max(refMarker.get(0), 0), 0)); - ovTop.update(new Point(0, Math.max(refMarker.get(1), 0))); - ovRight.update(new Point(Math.max(refMarker.get(2), 0), 0)); - ovBottom.update(new Point(0, Math.max(refMarker.get(3),0))); - } catch (Exception ex){ - SwingUtils.invokeDelayed(() -> { - Dimension size = renderer.getImageSize(); - ovTop.update(new Point(0, size.height/8)); - ovBottom.update(new Point(0, 7*size.height/8)); - ovLeft.update(new Point(size.width/8, 0)); - ovRight.update(new Point(7*size.width/8, 0)); - }, 500); - } - renderer.addListener(new RendererListener(){ - @Override - public void onMoveFinished(Renderer renderer, Overlay overlay) { - if (overlay==ovTop){ - spinnerTop.setValue(ovTop.getPosition().y); - } else if (overlay==ovBottom){ - spinnerBottom.setValue(ovBottom.getPosition().y); - } else if (overlay==ovLeft){ - spinnerLeft.setValue(ovLeft.getPosition().x); - } else if (overlay==ovRight){ - spinnerRight.setValue(ovRight.getPosition().x); - } - } - }); - setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - pack(); - } - - @Override - protected void onClosed() { - renderer.removeOverlays(calibrationOverlays); - calibrationOverlays = null; - } - - - void updateResults(){ - try{ - int left = (Integer)spinnerLeft.getValue(); - int right = (Integer)spinnerRight.getValue(); - int top = (Integer)spinnerTop.getValue(); - int bottom = (Integer)spinnerBottom.getValue(); - double width = (Double)spinnerRefWidth.getValue(); - double height = (Double)spinnerRefHeight.getValue(); - double angleHor = (Double)spinnerAngleHor.getValue(); - double angleVer = (Double)spinnerAngleVer.getValue(); - double pixelHor = width * Math.cos(Math.toRadians(angleHor)) /Math.abs(right-left); - double pixelVer = height * Math.cos(Math.toRadians(angleVer)) /Math.abs(bottom-top); - textOriginX.setText(String.valueOf((left+right)/2)); - textOriginY.setText(String.valueOf((top+bottom)/2)); - textPixelSizeX.setText(String.valueOf(Convert.roundDouble(pixelHor, 2))); - textPixelSizeY.setText(String.valueOf(Convert.roundDouble(pixelVer, 2))); - ovLeft.update(new Point(Math.max(left, 0), 0)); - ovTop.update(new Point(0, Math.max(top, 0))); - ovRight.update(new Point(Math.max(right, 0), 0)); - ovBottom.update(new Point(0, Math.max(bottom,0))); - renderer.refresh(); - - } catch (Exception ex){ - SwingUtils.showException(this, ex); - } - } - - - public static void main(String args[]) throws Exception { - //String cameraName = "SINEG01-DSCR190"; - String cameraName = "SATSY02-DSCR220" ; - Camtool camtool = new Camtool("Camera", "localhost:10000"); - camtool.start(cameraName); - //java.awt.EventQueue.invokeLater(() -> { - Renderer renderer = new Renderer(); - camtool.addListener(renderer); - JDialog dlgRenderer = SwingUtils.showDialog(null, cameraName, new Dimension(600,400), renderer); - CameraConfigDialog dialog = new CameraConfigDialog(null, camtool, renderer); - dialog.addWindowListener(new java.awt.event.WindowAdapter() { - @Override - public void windowClosing(java.awt.event.WindowEvent e) { - dlgRenderer.setVisible(false); - camtool.close(); - System.exit(0); - } - }); - SwingUtils.centerComponent(null, dialog); - dialog.setVisible(true); - // }); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel1 = new javax.swing.JLabel(); - jPanel1 = new javax.swing.JPanel(); - jLabel4 = new javax.swing.JLabel(); - jLabel5 = new javax.swing.JLabel(); - jLabel6 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jLabel8 = new javax.swing.JLabel(); - jLabel9 = new javax.swing.JLabel(); - jLabel10 = new javax.swing.JLabel(); - spinnerAngleHor = new javax.swing.JSpinner(); - spinnerAngleVer = new javax.swing.JSpinner(); - spinnerRefWidth = new javax.swing.JSpinner(); - spinnerRefHeight = new javax.swing.JSpinner(); - spinnerTop = new javax.swing.JSpinner(); - spinnerBottom = new javax.swing.JSpinner(); - spinnerLeft = new javax.swing.JSpinner(); - spinnerRight = new javax.swing.JSpinner(); - buttonFetch = new javax.swing.JButton(); - jPanel2 = new javax.swing.JPanel(); - checkMirrorX = new javax.swing.JCheckBox(); - checkMirrorY = new javax.swing.JCheckBox(); - comboRotation = new javax.swing.JComboBox(); - jLabel7 = new javax.swing.JLabel(); - jPanel3 = new javax.swing.JPanel(); - jLabel11 = new javax.swing.JLabel(); - textOriginX = new javax.swing.JTextField(); - jLabel12 = new javax.swing.JLabel(); - textOriginY = new javax.swing.JTextField(); - jLabel13 = new javax.swing.JLabel(); - jLabel14 = new javax.swing.JLabel(); - textPixelSizeX = new javax.swing.JTextField(); - textPixelSizeY = new javax.swing.JTextField(); - buttonOk = new javax.swing.JButton(); - buttonCancel = new javax.swing.JButton(); - - jLabel1.setText("Calibrate the camera moving the line overlays to the reference marks."); - - jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Calibration")); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Reference marker height (um):"); - - jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel5.setText("Horizontal camera angle (deg):"); - - jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel6.setText("Vertical camera angle (deg):"); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Reference marker width (um):"); - - jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel2.setText("Top (px):"); - - jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel8.setText("Botton (px):"); - - jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel9.setText("Left (px):"); - - jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel10.setText("Right (px):"); - - spinnerAngleHor.setModel(new javax.swing.SpinnerNumberModel(0.0d, -360.0d, 360.0d, 1.0d)); - spinnerAngleHor.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerAngleVer.setModel(new javax.swing.SpinnerNumberModel(0.0d, -360.0d, 360.0d, 1.0d)); - spinnerAngleVer.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerRefWidth.setModel(new javax.swing.SpinnerNumberModel(30000.0d, 1.0d, 500000.0d, 1.0d)); - spinnerRefWidth.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerRefHeight.setModel(new javax.swing.SpinnerNumberModel(30000.0d, 1.0d, 500000.0d, 1.0d)); - spinnerRefHeight.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerTop.setModel(new javax.swing.SpinnerNumberModel(0, -10000, 10000, 1)); - spinnerTop.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerBottom.setModel(new javax.swing.SpinnerNumberModel(0, -10000, 10000, 1)); - spinnerBottom.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerLeft.setModel(new javax.swing.SpinnerNumberModel(0, -10000, 10000, 1)); - spinnerLeft.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - spinnerRight.setModel(new javax.swing.SpinnerNumberModel(0, -10000, 10000, 1)); - spinnerRight.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - calibrationSpinnerChanged(evt); - } - }); - - buttonFetch.setText("Fetch from Inventory"); - buttonFetch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFetchActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerTop, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerRefWidth, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(jLabel8) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerBottom, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel4) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerRefHeight, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(jLabel10) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerRight, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel6) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerAngleVer, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(jLabel9) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spinnerAngleHor, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(buttonFetch))) - .addContainerGap()) - ); - - jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel10, jLabel2, jLabel8, jLabel9}); - - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(jLabel2) - .addComponent(spinnerRefWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerTop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel4) - .addComponent(jLabel8) - .addComponent(spinnerRefHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerBottom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel5) - .addComponent(jLabel9) - .addComponent(spinnerAngleHor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel6) - .addComponent(jLabel10) - .addComponent(spinnerAngleVer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) - .addComponent(buttonFetch) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Transformations")); - - checkMirrorX.setText("Mirror X"); - - checkMirrorY.setText("Mirror Y"); - - comboRotation.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "270", "180", "90" })); - - jLabel7.setText("Rotation: "); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addComponent(checkMirrorX) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel7) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(comboRotation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel2Layout.createSequentialGroup() - .addComponent(checkMirrorY) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboRotation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel7)) - .addComponent(checkMirrorX)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(checkMirrorY) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Results")); - - jLabel11.setText("Origin X (px):"); - - textOriginX.setEditable(false); - textOriginX.setHorizontalAlignment(javax.swing.JTextField.CENTER); - - jLabel12.setText("Origin Y (px):"); - - textOriginY.setEditable(false); - textOriginY.setHorizontalAlignment(javax.swing.JTextField.CENTER); - - jLabel13.setText("Y pixel size (um/px):"); - - jLabel14.setText("X pixel size (um/px):"); - - textPixelSizeX.setEditable(false); - textPixelSizeX.setHorizontalAlignment(javax.swing.JTextField.CENTER); - - textPixelSizeY.setEditable(false); - textPixelSizeY.setHorizontalAlignment(javax.swing.JTextField.CENTER); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(21, 21, 21) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel12) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textOriginY, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel11) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textOriginX, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel13) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textPixelSizeY, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel14) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textPixelSizeX, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel11, jLabel12}); - - jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel13, jLabel14}); - - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel14) - .addComponent(textPixelSizeX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel13) - .addComponent(textPixelSizeY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel11) - .addComponent(textOriginX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel12) - .addComponent(textOriginY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addContainerGap()) - ); - - buttonOk.setText("Ok"); - buttonOk.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonOkActionPerformed(evt); - } - }); - - buttonCancel.setText("Cancel"); - buttonCancel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonCancelActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(buttonOk) - .addGap(18, 18, 18) - .addComponent(buttonCancel) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonCancel, buttonOk}); - - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonOk) - .addComponent(buttonCancel)) - .addContainerGap(16, Short.MAX_VALUE)) - ); - }// //GEN-END:initComponents - - private void buttonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOkActionPerformed - - try { - //renderer.removeOverlays(calibrationOverlays); - //calibrationOverlays = null; - //calibrationDialolg = null; - - int left = (Integer)spinnerLeft.getValue(); //left.getPosition().x - int right = (Integer)spinnerRight.getValue(); //right.getPosition().x - int top = (Integer)spinnerTop.getValue(); //top.getPosition().y - int bottom = (Integer)spinnerBottom.getValue(); //bottom.getPosition().y - double width = (Double)spinnerRefWidth.getValue(); - double height = (Double)spinnerRefHeight.getValue(); - double angleHor = (Double)spinnerAngleHor.getValue(); - double angleVer = (Double)spinnerAngleVer.getValue(); - - int x1 = Math.min(left, right); - int x2 = Math.max(left, right); - int y1 = Math.min(top, bottom); - int y2 = Math.max(top, bottom); - if ((x1!=-1) && (x2!=-1) && (y1!=-1) && (y2!=-1)){ - System.out.println("Updating " + cameraName + " configuration"); - HashMap calibration = new HashMap(); - calibration.put("reference_marker", Arrays.asList(new Integer[]{x1, y1, x2, y2})); - calibration.put("reference_marker_width", width); - calibration.put("reference_marker_height", height); - calibration.put("horizontal_camera_angle", angleHor); - calibration.put("vertical_camera_angle", angleVer); - //((Camtool) camera).setCalibration(cameraName, calibration); - - HashMap config = new HashMap(); - config.put("calibration", calibration); - config.put("mirror_x", checkMirrorX.isSelected()); - config.put("mirror_y", checkMirrorY.isSelected()); - config.put("rotate", comboRotation.getSelectedIndex()); - ((Camtool) camera).setConfig(cameraName, config); - - System.out.println("New config: " + config); - SwingUtils.showMessage(this, "Success", "Updated " + cameraName + " configuration"); - } - } catch (Exception ex) { - SwingUtils.showException(this, ex); - } - - accept(); - }//GEN-LAST:event_buttonOkActionPerformed - - private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed - cancel(); - }//GEN-LAST:event_buttonCancelActionPerformed - - private void buttonFetchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFetchActionPerformed - try{ - //List calib = Inventory.getCalibFromInventory(null, cameraName); - List calib = (List) Class.forName("Inventory"). - getMethod("getCalibFromInventory", - new Class[]{String.class,String.class}). - invoke(null, new Object[]{(String)null, cameraName}); - spinnerRefWidth.setValue(calib.get(0)*1000.0); - spinnerRefHeight.setValue(calib.get(1)*1000.0); - spinnerAngleHor.setValue(calib.get(2).intValue()); - spinnerAngleVer.setValue(calib.get(3).intValue()); - } catch (Exception ex){ - if (ex instanceof InvocationTargetException){ - ex = (Exception) ((InvocationTargetException)ex).getCause(); - } - SwingUtils.showException(this, ex); - } - }//GEN-LAST:event_buttonFetchActionPerformed - - private void calibrationSpinnerChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_calibrationSpinnerChanged - updateResults(); - }//GEN-LAST:event_calibrationSpinnerChanged - - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton buttonCancel; - private javax.swing.JButton buttonFetch; - private javax.swing.JButton buttonOk; - private javax.swing.JCheckBox checkMirrorX; - private javax.swing.JCheckBox checkMirrorY; - private javax.swing.JComboBox comboRotation; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel10; - private javax.swing.JLabel jLabel11; - private javax.swing.JLabel jLabel12; - private javax.swing.JLabel jLabel13; - private javax.swing.JLabel jLabel14; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JLabel jLabel6; - private javax.swing.JLabel jLabel7; - private javax.swing.JLabel jLabel8; - private javax.swing.JLabel jLabel9; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JSpinner spinnerAngleHor; - private javax.swing.JSpinner spinnerAngleVer; - private javax.swing.JSpinner spinnerBottom; - private javax.swing.JSpinner spinnerLeft; - private javax.swing.JSpinner spinnerRefHeight; - private javax.swing.JSpinner spinnerRefWidth; - private javax.swing.JSpinner spinnerRight; - private javax.swing.JSpinner spinnerTop; - private javax.swing.JTextField textOriginX; - private javax.swing.JTextField textOriginY; - private javax.swing.JTextField textPixelSizeX; - private javax.swing.JTextField textPixelSizeY; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/Cameras.form b/plugins/Cameras.form deleted file mode 100755 index f0d2e57..0000000 --- a/plugins/Cameras.form +++ /dev/null @@ -1,189 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/Cameras.java b/plugins/Cameras.java deleted file mode 100755 index f2aa083..0000000 --- a/plugins/Cameras.java +++ /dev/null @@ -1,847 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.core.Context; -import java.io.File; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.IO; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.epics.PsiCamera; -import ch.psi.pshell.epics.Camtool; -import ch.psi.pshell.core.JsonSerializer; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.epics.ArraySource; -import ch.psi.pshell.epics.ChannelDouble; -import ch.psi.pshell.epics.ChannelDoubleArray; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.ChannelIntegerArray; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.Renderer.Profile; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.imaging.Utils; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Convert; -import ch.psi.utils.Str; -import ch.psi.utils.swing.Editor.EditorDialog; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Point; -import java.awt.image.BufferedImage; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; -/** - * - */ -public class Cameras extends Panel { - - public Cameras() { - initComponents(); - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - setPersistedComponents(new Component[]{checkCamtool}); - comboCameras.setEnabled(false); - if (App.hasArgument("poll")) { - try{ - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex){ - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try{ - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex){ - ex.printStackTrace(); - } - } - } - - @Override - public void onStart() { - super.onStart(); - if (App.hasArgument("ct")) { - checkCamtool.setSelected(!App.getArgumentValue("ct").equals("0") && !App.getArgumentValue("ct").equalsIgnoreCase("false")); - } - } - - final String configFolder = "/afs/psi.ch/intranet/SF/Applications/config/camtool"; - File[] cameraConfigFiles = new File[0]; - ArraySource camera; - String cameraName; - String cameraConfigJson; - CameraConfig config; - int polling = 1000; - Overlay marker = null; - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - if (App.hasArgument("s")){ - renderer.setDevice((Source)getDevice("image")); - renderer.setAutoScroll(true); - ((Source)getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi == null) { - fitOv = null; - } else { - Overlay[] profile = renderer.getProfileOverlays(); - profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(data) : null; - renderer.updateOverlays(profile, fitOv); - fitOv = profile; - } - } - @Override - public void onError(Object o, Exception excptn) { - } - } - ); - - } else { - cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"}); - Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b)); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (File file : cameraConfigFiles) { - String prefix = IO.getPrefix(file); - if (!prefix.startsWith("#")) { - model.addElement(prefix); - } - } - comboCameras.setModel(model); - comboCameras.setEnabled(true); - comboCameras.setSelectedItem(-1); - if (model.getSize() > 0) { - try { - //setCamera((String)comboCameras.getSelectedItem()); - if (App.hasArgument("cam")) { - comboCameras.setSelectedItem(App.getArgumentValue("cam")); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - startTimer(1000); - } - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - public static class CameraConfig { - - public HashMap kwargs; - public ArrayList args; - public ArrayList links; - public String type; - public HashMap state; - public CameraConfig image_source; - public HashMap subcomponents; - - public ArrayList getCalibration() { - return (ArrayList) state.get("calibration"); - } - - public double getCalOffsetX(){ - ArrayList calibration = getCalibration(); - double ret = - (calibration.get(0) + calibration.get(2))/2; - return ret; - } - - public double getCalOffsetY(){ - ArrayList calibration = getCalibration(); - double ret = - (calibration.get(1) + calibration.get(3))/2; - return ret; - } - - public double getScaleX(){ - ArrayList calibration = getCalibration(); - double width = Math.abs( calibration.get(2) - calibration.get(0)); - return getCalibrationWidth()/width; - //return getCalibrationWidth()/1000; - } - - public double getScaleY(){ - ArrayList calibration = getCalibration(); - double height = Math.abs( calibration.get(3) - calibration.get(1)); - return getCalibrationHeight()/height; - } - - - public Double getCalibrationHeight() { - return (Double) state.get("calibration_height"); - } - - public Double getCalibrationWidth() { - return (Double) state.get("calibration_width"); - } - - public Double getCalibrationHorizontalAngle() { - return (Double) state.get("calibration_horizontal_angle"); - } - - public Double getCalibrationVerticalAngle() { - return (Double) state.get("calibration_vertical_angle"); - } - - public Boolean getMirrorX() { - return (Boolean) state.get("mirror_x"); - } - - public Boolean getMirrorY() { - return (Boolean) state.get("mirror_y"); - } - - public Integer getRotate() { - return (Integer) state.get("rotate"); - } - - public ArrayList getOrigin() { - return (ArrayList) state.get("origin"); - } - - public ArrayList getRoi() { - return (ArrayList) state.get("roi"); - } - - public Boolean getRoiEnable() { - if ((state.get("roi_enable") == null) || (state.get("roi") == null)) { - return false; - } - return (Boolean) state.get("roi_enable"); - } - - public ArrayList getUnitSize() { - return (ArrayList) state.get("unit_size"); - } - - public Integer getRun() { - return (Integer) state.get("run"); - } - } - - Overlay[] fitOv; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Setting camera: " + cameraName); - if (camera != null) { - camera.close(); - camera = null; - renderer.setDevice(null); - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.clear(); - renderer.resetZoom(); - } - try { - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = new String(Files.readAllBytes(configFile)); - this.cameraName = cameraName; - //SwingUtils.showMessage(null, "", json); - try { - if (checkCamtool.isSelected()) { - camera = new Camtool("CurrentCamera", cameraName, false); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - camera = new PsiCamera("CurrentCamera", cameraName); - config = (CameraConfig) JsonSerializer.decode(cameraConfigJson, CameraConfig.class); - camera.getConfig().flipHorizontally = config.getMirrorX(); - camera.getConfig().flipVertically = config.getMirrorY(); - camera.getConfig().rotation = config.getRotate(); - camera.getConfig().rotationCrop = true; - camera.getConfig().roiX = config.getRoiEnable() ? config.getRoi().get(0) : 0; - camera.getConfig().roiY = config.getRoiEnable() ? config.getRoi().get(1) : 0; - camera.getConfig().roiWidth = config.getRoiEnable() ? config.getRoi().get(2) : -1; - camera.getConfig().roiHeight = config.getRoiEnable() ? config.getRoi().get(3) : -1; - try{ - camera.getConfig().spatialCalOffsetX = config.getCalOffsetX(); - camera.getConfig().spatialCalOffsetY = config.getCalOffsetY(); - camera.getConfig().spatialCalScaleX = config.getScaleX(); - camera.getConfig().spatialCalScaleY = config.getScaleY(); - } catch (Exception ex){ - camera.getConfig().spatialCalOffsetX = Double.NaN; - camera.getConfig().spatialCalOffsetY = Double.NaN; - camera.getConfig().spatialCalScaleX = Double.NaN; - camera.getConfig().spatialCalScaleY = Double.NaN; - } - } - } catch (Exception ex) { - config = null; - showException(ex); - } - camera.initialize(); - if (camera instanceof Camtool){ - try{ - camera.getConfig().spatialCalOffsetX = ((Camtool)camera).calOffX.read(); - camera.getConfig().spatialCalOffsetY = ((Camtool)camera).calOffY.read(); - camera.getConfig().spatialCalScaleX = ((Camtool)camera).calScaleX.read(); - camera.getConfig().spatialCalScaleY = ((Camtool)camera).calScaleY.read(); - } catch (Exception ex){ - ex.printStackTrace(); - camera.getConfig().spatialCalOffsetX = 0.0; - camera.getConfig().spatialCalOffsetY = 0.0; - camera.getConfig().spatialCalScaleX = 1.0; - camera.getConfig().spatialCalScaleY = 1.0; - } - /* - double[] origin = ((Camtool)camera).origin.read(); - if (origin.length>=2){ - camera.getConfig().spatialCalOffsetX = origin[0]; - camera.getConfig().spatialCalOffsetY = origin[1]; - } - */ - } - buttonReticle.setEnabled(camera.getConfig().isCalibrated()); - buttonGrabBackground.setEnabled(camera instanceof Camtool); - camera.getConfig().save(); - - if (polling<=0){ - camera.setMonitored(true); - } else { - camera.setPolling(-polling); - } - renderer.setDevice(camera); - renderer.setAutoScroll(true); - renderer.setMarker(marker); - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi == null) { - renderer.removeOverlays(fitOv); - fitOv = null; - } else { - //System.out.println(bi.getWidth() + " - " + bi.getHeight()); - if (!renderer.isPaused() && buttonFit.isSelected()){ - Overlay[] profile = renderer.getProfileOverlays(); - profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(data) : null; - renderer.updateOverlays(profile, fitOv); - fitOv = profile; - } - } - } - - @Override - public void onError(Object o, Exception excptn) { - } - }); - } catch (Exception ex) { - if (renderer.getDevice()==null){ - renderer.setZoom(1.0); - renderer.addOverlay(new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20))); - } - } finally { - checkReticle(); - onTimer(); - } - } - - void checkReticle(){ - if ((renderer.getDevice()!=null) && (camera!=null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()){ - renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800,800), 200); - renderer.setShowReticle(true); - } else { - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - @Override - protected void onTimer() { - textState.setText((camera == null) ? "" : camera.getState().toString()); - buttonConfig.setEnabled(camera != null); - if (App.hasArgument("s")){ - try { - ((Source)getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(Cameras.class.getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(Cameras.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - - Pen fitPen = new Pen(new Color(192, 105, 0), 1); - Pen crossPen = new Pen(new Color(192, 105, 0), 1); - - Overlay[] getFitOverlays(Data data) { - Overlays.Polyline hpoly = null; - Overlays.Polyline vpoly = null; - Double xMean = null; - Double xSigma = null; - Double yMean = null; - Double ySigma = null; - if (data != null) { - //img = Utils.grayscale(img); - int profileSize = Math.min(data.getWidth(), data.getHeight())/4; - - try { - double[] sum = (double[]) Convert.toDouble(data.integrateVertically(true)); - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - sum[i] = sum[i] - min; - } - - double[] gaussian = fitGaussian(sum, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)) { - double maxPlot = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - gaussian[0] += min; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (data.getHeight() - 1 - ((fit[i] / maxPlot) * profileSize)); - } - vpoly = new Overlays.Polyline(fitPen, x, y); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = (double[]) Convert.toDouble(data.integrateHorizontally(true)); - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - sum[i] = sum[i] - min; - } - - double[] gaussian = fitGaussian(sum, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)) { - double maxPlot = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - gaussian[0] += min; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((fit[i] / maxPlot) * profileSize); - } - hpoly = new Overlays.Polyline(fitPen, y, x); - } - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - - Overlays.Crosshairs cross = null; - Overlays.Text text = null; - if ((xMean != null) && (yMean != null)) { - cross = new Overlays.Crosshairs(crossPen, - new Point(xMean.intValue(), yMean.intValue()), - new Dimension(2 * xSigma.intValue(), 2 * ySigma.intValue())); - - text = new Overlays.Text(fitPen, - String.format("x = %f \n y = %f" , data.getX((int) Math.round(xMean)), data.getY((int) Math.round(yMean))), - new Font(Font.MONOSPACED, 0, 14), new Point(20,20)); - } - - return new Overlay[]{hpoly, vpoly, cross, text}; - } - return null; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - renderer = new ch.psi.pshell.imaging.Renderer(); - jLabel1 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - jLabel2 = new javax.swing.JLabel(); - textState = new javax.swing.JTextField(); - buttonConfig = new javax.swing.JButton(); - buttonSetup = new javax.swing.JButton(); - checkCamtool = new javax.swing.JCheckBox(); - buttonFit = new javax.swing.JToggleButton(); - buttonPause = new javax.swing.JToggleButton(); - buttonMarker = new javax.swing.JToggleButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - - jLabel1.setText("Camera:"); - - comboCameras.setMaximumRowCount(30); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - jLabel2.setText("State:"); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - buttonConfig.setText("Config"); - buttonConfig.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonConfigActionPerformed(evt); - } - }); - - buttonSetup.setText("Setup"); - buttonSetup.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSetupActionPerformed(evt); - } - }); - - checkCamtool.setSelected(true); - checkCamtool.setText("Camtool"); - - buttonFit.setSelected(true); - buttonFit.setText("Fit"); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - - buttonPause.setText("Pause"); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - - buttonMarker.setText("Marker"); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - - buttonSave.setText("Save Snapshot"); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - - buttonReticle.setSelected(true); - buttonReticle.setText("Reticle"); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - - buttonGrabBackground.setText("Grab Background"); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(renderer, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(checkCamtool) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboCameras, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonConfig) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonSetup) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(buttonPause) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonMarker) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonFit) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonReticle) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonGrabBackground) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonSave))) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfig, buttonSetup}); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonReticle}); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave}); - - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel2) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonConfig) - .addComponent(buttonSetup) - .addComponent(checkCamtool)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE) - .addGap(12, 12, 12) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonPause) - .addComponent(buttonFit) - .addComponent(buttonMarker) - .addComponent(buttonSave) - .addComponent(buttonReticle) - .addComponent(buttonGrabBackground)) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState}); - - }// //GEN-END:initComponents - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - comboCameras.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - try{ - setCamera((String) comboCameras.getSelectedItem()); - } catch(Exception ex){ - ex.printStackTrace(); - } finally{ - comboCameras.setEnabled(true); - } - } - }).start(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed - try { - if (camera != null) { - TextEditor editor = new TextEditor(); - editor.setText(cameraConfigJson); - editor.setReadOnly(true); - editor.setTitle(cameraName); - EditorDialog dlg = editor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(this, dlg); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonConfigActionPerformed - - private void buttonSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSetupActionPerformed - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonSetupActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - if (camera != null) { - if (buttonPause.isSelected()){ - renderer.pause(); - } else { - renderer.resume(); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - if (camera != null) { - if (buttonMarker.isSelected()){ - Dimension d = renderer.getImageSize(); - Point p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - } else { - marker = null; - } - renderer.setMarker(marker); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - renderer.setProfile(buttonFit.isSelected() ? Profile.Both :Profile.None); - if (!buttonFit.isSelected()){ - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - renderer.setSnapshotDialogVisible(buttonSave.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera instanceof Camtool){ - ((Camtool)camera).captureBackground(5); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton buttonConfig; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JButton buttonSetup; - private javax.swing.JCheckBox checkCamtool; - private javax.swing.JComboBox comboCameras; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JTextField textState; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/Camtool.java b/plugins/Camtool.java deleted file mode 100755 index 2347ade..0000000 --- a/plugins/Camtool.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.device.Device; -import ch.psi.pshell.device.Readable; -import ch.psi.pshell.epics.*; -import java.io.IOException; -import java.util.ArrayList; - -/** - * - */ -public class Camtool extends ArraySource { - - final String prefix; - final String dataPrefix; - final boolean latch; - - final public ChannelInteger channelRun; - final public ChannelInteger channelLatch; - final public ChannelDouble channelTimestamp; - final public ChannelDoubleArray origin; - final public ChannelDouble posX, posY; - final public ChannelDoubleArray profileX, profileY; - final public ChannelIntegerArray shape; - final public ChannelInteger roiEnabled; - final public ChannelIntegerArray roiShape; - final public ChannelInteger bgEnable, bgCapture, bgCaptureRemain; - final public ChannelDouble calOffX, calOffY, calScaleX, calScaleY; - final public CamToolPosX posMeanX; - final public CamToolPosY posMeanY; - final public CamToolVarX posVarX; - final public CamToolVarY posVarY; - - public Camtool(String name, String prefix) { - this(name, prefix, false); - } - - public Camtool(String name, String prefix, boolean latch) { - //super(name, prefix + (latch ? ":latch" : ":pipeline") + (roi ? ".roi.output" : ".image")); - super(name, prefix + (latch ? ":latch" : ":pipeline") + ".roi.output"); - this.prefix = prefix + ":"; - this.latch = latch; - dataPrefix = this.prefix + (latch ? "latch" : "pipeline") + "."; - - channelRun = new ChannelInteger(name + " run", this.prefix + "camera.run"); - channelLatch = new ChannelInteger(name + " latch", this.prefix + "latch.capture"); - channelTimestamp = new ChannelDouble(name + " timestamp", dataPrefix + "timestamp"); - channelTimestamp.setMonitored(true); - //posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com"); - //posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com"); - posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com_egu"); - posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com_egu"); - profileX = new ChannelDoubleArray(name + " profile x", dataPrefix + "profile.x"); - profileY = new ChannelDoubleArray(name + " profile y", dataPrefix + "profile.y"); - //shape = new ChannelIntegerArray(name + " shape", dataPrefix + (roi ? "roi.output.shape" : "image.shape")); - shape = new ChannelIntegerArray(name + " shape", dataPrefix + ("image.shape")); - roiShape = new ChannelIntegerArray(name + " roi shape", dataPrefix + "roi.roi"); - roiEnabled = new ChannelInteger(name + " roi enabled", dataPrefix + "roi.enabled"); - //origin = new ChannelDoubleArray(name + " origin X", roi ? (dataPrefix + "roi.origin_out") : (prefix + "origin")); - origin = new ChannelDoubleArray(name + " origin X", dataPrefix + "roi.origin_out"); - bgEnable = new ChannelInteger(name + " bg enable", this.prefix + "pipeline.bg.enabled"); - bgCapture = new ChannelInteger(name + " bg capture", this.prefix + "pipeline.bg.capture"); - bgCaptureRemain = new ChannelInteger(name + " bg capture remain", this.prefix + "pipeline.bg.capture_remain"); - calOffX = new ChannelDouble(name + " cal off x", this.prefix + "pipeline.egu.eoff_x"); - calOffY = new ChannelDouble(name + " cal off y", this.prefix + "pipeline.egu.eoff_y"); - calScaleX = new ChannelDouble(name + " cal scale x", this.prefix + "pipeline.egu.eslo_x"); - calScaleY = new ChannelDouble(name + " cal scale y", this.prefix + "pipeline.egu.eslo_y"); - - posMeanX = new CamToolPosX(); - posMeanY = new CamToolPosY(); - posVarX = new CamToolVarX(); - posVarY = new CamToolVarY(); - } - - @Override - public void doSetMonitored(boolean value) { - super.doSetMonitored(value); - getDevice().setMonitored(value); - } - - @Override - public void doUpdate() throws IOException, InterruptedException { - super.doUpdate(); - getDevice().update(); - } - - void safeInitialize(Device dev, int timeout) throws IOException, InterruptedException { - for (int retries = 0; retries < 10; retries++) { - try { - dev.initialize(); - break; - } catch (IOException ex) { - if (retries == 9) { - throw ex; - } - Thread.sleep(timeout / 10); - } - } - } - - - @Override - protected void doInitialize() throws IOException, InterruptedException { - try { - channelRun.initialize(); - channelLatch.initialize(); - if (latch) { - start(); - latch(); - } - safeInitialize(channelTimestamp, 2000); - posX.initialize(); - posY.initialize(); - profileX.initialize(); - profileY.initialize(); - shape.initialize(); - roiShape.initialize(); - roiEnabled.initialize(); - origin.initialize(); - bgEnable.initialize(); - bgCapture.initialize(); - bgCaptureRemain.initialize(); - try { - calOffX.initialize(); - calOffY.initialize(); - calScaleX.initialize(); - calScaleY.initialize(); - } catch (Exception ex) { - ex.printStackTrace(); - } - - if (roiEnabled.read()>0){ - int[] s = roiShape.read(); - //for (int x : s) System.out.println(x); - getConfig().imageHeight = s[3]; - getConfig().imageWidth = s[2]; - } else { - int[] s = shape.read(); - //for (int x : s){ System.out.println(x);} - getConfig().imageHeight = s[0]; - getConfig().imageWidth = s[1]; - } - - getConfig().save(); - getDevice().setSize(getConfig().imageHeight * getConfig().imageWidth); - super.doInitialize(); - //System.out.println(((int[])(getDevice().read())).length); - } catch (InterruptedException ex) { - throw ex; - } catch (Exception ex) { - ex.printStackTrace(); - throw new IOException(ex); - } - } - - int numImages = 1; - - public int getNumImages() { - return numImages; - } - - public void setNumImages(int value) { - numImages = value; - } - - double grabTimeout = 3.0; - - public double getGrabTimeout() { - return grabTimeout; - } - - public void setGrabTimeou(double value) { - grabTimeout = value; - } - - public void capture() throws IOException, InterruptedException { - int retries = 3; - while (true) { - try { - double timestamp = channelTimestamp.read(); - if (latch) { - channelLatch.write(1); - } else { - channelRun.write(1); - } - long start = System.currentTimeMillis(); - while (true) { - double val = channelTimestamp.read(); - if (timestamp != val) { - return; - } - if ((System.currentTimeMillis() - start) > grabTimeout) { - throw new IOException("Frame timeout"); - } - Thread.sleep(5); - } - } catch (IOException ex) { - retries--; - if (--retries <= 0) { - throw ex; - } - } - } - } - - public void start() throws IOException, InterruptedException { - channelRun.write(-1); - } - - public void stop() throws IOException, InterruptedException { - channelRun.write(0); - } - - public void grabSingle() throws IOException, InterruptedException { - channelRun.write(1); - } - - public void latch() throws IOException, InterruptedException { - channelLatch.write(1); - } - - public void enableBackground(boolean value) throws IOException, InterruptedException { - bgEnable.write(value ? 1 : 0); - } - - public void captureBackground(int images) throws IOException, InterruptedException { - start(); - bgCapture.write(images); - Thread.sleep(200); - while (bgCaptureRemain.read() > 0) { - Thread.sleep(10); - } - } - - //Statisticss pseudo devices - ArrayList posXSamples; - ArrayList posYSamples; - - public void updateStats() throws IOException, InterruptedException { - posXSamples.clear(); - posYSamples.clear(); - for (int i = 0; i < getNumImages(); i++) { - capture(); - posXSamples.add(posX.read()); - posXSamples.add(posY.read()); - } - } - - class CamToolPosX implements Readable { - - @Override - public Object read() throws IOException, InterruptedException { - return mean(posXSamples); - } - - } - - class CamToolPosY implements Readable { - - @Override - public Object read() throws IOException, InterruptedException { - return mean(posYSamples); - } - } - - class CamToolVarX implements Readable { - - @Override - public Object read() throws IOException, InterruptedException { - return stdev(posXSamples); - } - - } - - class CamToolVarY implements Readable { - - @Override - public Object read() throws IOException, InterruptedException { - return stdev(posYSamples); - } - } - - public double mean(ArrayList samples) { - int count = 0; - double temp = 0; - for (Double n : samples) { - if (!Double.isNaN(n)) { - temp += n.doubleValue(); - count++; - } - } - return count == 0 ? Double.NaN : temp / count; - } - - public double stdev(ArrayList samples) { - int count = 0; - double temp = 0; - double mean = mean(samples); - for (Double n : samples) { - if (!Double.isNaN(n)) { - temp += Math.pow((mean - n), 2); - } - } - return count == 0 ? Double.NaN : temp / count; - } - -} diff --git a/plugins/Correlation.java b/plugins/Correlation.java index 0f88f3c..4dfdba3 100755 --- a/plugins/Correlation.java +++ b/plugins/Correlation.java @@ -2,10 +2,11 @@ * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ +import ch.psi.pshell.App; +import ch.psi.pshell.framework.Context; import ch.psi.pshell.plot.Plot; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.ui.Panel; -import ch.psi.utils.State; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.utils.State; import java.awt.Component; import java.util.HashMap; import java.util.List; @@ -73,14 +74,14 @@ public class Correlation extends Panel { //DecimalFormat formatter = new DecimalFormat("0.##E0"); void updateResults(){ try{ - textCorrelation.setText(String.format("%1.4f", Double.valueOf((Double)getContext().getInterpreterVariable("corr")))); + textCorrelation.setText(String.format("%1.4f", Double.valueOf((Double)Context.getSequencer().getInterpreterVariable("corr")))); } catch (Exception ex){ textCorrelation.setText(""); } if (checkLinear.isSelected()){ try{ - List pars = (List)getContext().getInterpreterVariable("pars_lin"); + List pars = (List)Context.getSequencer().getInterpreterVariable("pars_lin"); //textLinear.setText(String.format("%1.3fx%+1.3f", (Double)(pars.get(1)), (Double)(pars.get(0)))); textLinear.setText(String.format("%1.6gx%+1.6g",pars.get(1), pars.get(0))); } catch (Exception ex){ @@ -90,7 +91,7 @@ public class Correlation extends Panel { if (checkQuadratic.isSelected()){ try{ - List pars = (List)getContext().getInterpreterVariable("pars_quad"); + List pars = (List)Context.getSequencer().getInterpreterVariable("pars_quad"); //textQuadratic.setText(String.format("%1.2fx\u00B2 %+1.2fx%+1.2f", (Double)(pars.get(0)), (Double)(pars.get(1)), (Double)(pars.get(0)))); textQuadratic.setText(String.format("%1.3gx\u00B2%+1.3gx%+1.3g", pars.get(0), pars.get(1), pars.get(0))); //textQuadratic.setText(formatter.format(pars.get(2))+ formatter.format(pars.get(1)) + formatter.format(pars.get(0))); diff --git a/plugins/Correlation2.java b/plugins/Correlation2.java index 2874cac..fe86b18 100755 --- a/plugins/Correlation2.java +++ b/plugins/Correlation2.java @@ -2,15 +2,17 @@ * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ +import ch.psi.pshell.App; +import ch.psi.pshell.app.Setup; +import ch.psi.pshell.framework.Context; import ch.psi.pshell.plot.Plot; import ch.psi.pshell.swing.ChannelSelector; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.ui.Panel; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.utils.State; +import ch.psi.pshell.utils.Chrono; +import ch.psi.pshell.swing.SwingUtils; +import ch.psi.pshell.swing.SwingUtils.OptionResult; +import ch.psi.pshell.swing.SwingUtils.OptionType; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -86,14 +88,14 @@ public class Correlation2 extends Panel { //DecimalFormat formatter = new DecimalFormat("0.##E0"); void updateResults(){ try{ - textCorrelation.setText(String.format("%1.4f", Double.valueOf((Double)getContext().getInterpreterVariable("corr")))); + textCorrelation.setText(String.format("%1.4f", Double.valueOf((Double)Context.getSequencer().getInterpreterVariable("corr")))); } catch (Exception ex){ textCorrelation.setText(""); } if (checkLinear.isSelected()){ try{ - List pars = (List)getContext().getInterpreterVariable("pars_lin"); + List pars = (List)Context.getSequencer().getInterpreterVariable("pars_lin"); //textLinear.setText(String.format("%1.3fx%+1.3f", (Double)(pars.get(1)), (Double)(pars.get(0)))); textLinear.setText(String.format("%1.6gx%+1.6g",pars.get(1), pars.get(0))); } catch (Exception ex){ @@ -103,7 +105,7 @@ public class Correlation2 extends Panel { if (checkQuadratic.isSelected()){ try{ - List pars = (List)getContext().getInterpreterVariable("pars_quad"); + List pars = (List)Context.getSequencer().getInterpreterVariable("pars_quad"); //textQuadratic.setText(String.format("%1.2fx\u00B2 %+1.2fx%+1.2f", (Double)(pars.get(0)), (Double)(pars.get(1)), (Double)(pars.get(0)))); textQuadratic.setText(String.format("%1.3gx\u00B2%+1.3gx%+1.3g", pars.get(0), pars.get(1), pars.get(0))); //textQuadratic.setText(formatter.format(pars.get(2))+ formatter.format(pars.get(1)) + formatter.format(pars.get(0))); @@ -112,11 +114,11 @@ public class Correlation2 extends Panel { textQuadratic.setText(""); } try{ - String peak = (String)getContext().getInterpreterVariable("pos_peak"); + String peak = (String)Context.getSequencer().getInterpreterVariable("pos_peak"); if (peak!=null){ textPeak.setText(peak + " (max)"); } else { - peak = (String)getContext().getInterpreterVariable("neg_peak"); + peak = (String)Context.getSequencer().getInterpreterVariable("neg_peak"); if (peak!=null){ textPeak.setText(peak + " (min)"); } else { @@ -449,15 +451,15 @@ public class Correlation2 extends Panel { if (isRunning()){ //abort(); //Stooping smootly so displayed variables get updated. - getContext().setInterpreterVariable("stop_exec", true); + Context.getSequencer().setInterpreterVariable("stop_exec", true); Chrono chrono = new Chrono(); while (!chrono.isTimeout(500)){ - if (!Boolean.TRUE.equals(getContext().getInterpreterVariable("stop_exec"))){ + if (!Boolean.TRUE.equals(Context.getSequencer().getInterpreterVariable("stop_exec"))){ break; } Thread.sleep(1); } - if (Boolean.TRUE.equals(getContext().getInterpreterVariable("stop_exec"))){ + if (Boolean.TRUE.equals(Context.getSequencer().getInterpreterVariable("stop_exec"))){ System.out.println("Timeout stopping script - aborting..."); abort(); } @@ -515,7 +517,7 @@ public class Correlation2 extends Panel { private void buttonElogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonElogActionPerformed try{ - String snapshotFile = getContext().getSetup().expandPath("{context}/correlation_plot.png"); + String snapshotFile = Setup.expandPath("{context}/correlation_plot.png"); plot.saveSnapshot(snapshotFile, "png"); JPanel panel = new JPanel(); GridBagLayout layout = new GridBagLayout(); diff --git a/plugins/GunEnergyScan.java b/plugins/GunEnergyScan.java index 87fcf77..8e063e4 100755 --- a/plugins/GunEnergyScan.java +++ b/plugins/GunEnergyScan.java @@ -3,9 +3,9 @@ */ import ch.psi.pshell.plot.LinePlot; -import ch.psi.pshell.ui.Panel; -import ch.psi.utils.State; -import ch.psi.utils.swing.SwingUtils; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.swing.SwingUtils; +import ch.psi.pshell.utils.State; import java.util.ArrayList; import java.util.List; import javax.swing.JSpinner; diff --git a/plugins/GunSolenoidAlignment.java b/plugins/GunSolenoidAlignment.java index 105103b..e88279e 100755 --- a/plugins/GunSolenoidAlignment.java +++ b/plugins/GunSolenoidAlignment.java @@ -2,15 +2,11 @@ * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ -import ch.psi.pshell.core.Context; import ch.psi.pshell.plot.LinePlot; -import ch.psi.pshell.plot.LinePlotJFree; -import ch.psi.pshell.ui.Panel; -import ch.psi.utils.State; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.utils.State; import java.awt.Component; import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JPanel; /** @@ -39,7 +35,7 @@ public class GunSolenoidAlignment extends Panel { } return ret; }); - } catch (Context.ContextStateException ex) { + } catch (StateException ex) { showException((Exception) ex); } } diff --git a/plugins/Inventory.java b/plugins/Inventory.java deleted file mode 100755 index 9e0104c..0000000 --- a/plugins/Inventory.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - - -import ch.psi.pshell.core.JsonSerializer; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.jackson.JacksonFeature; - -/** - * - */ -public class Inventory { - - public static T inventoryRequest(String url, Map attributes, Class type) throws IOException { - String json = JsonSerializer.encode(attributes); - Client client = ClientBuilder.newClient(new ClientConfig().register(JacksonFeature.class)); - try { - WebTarget resource = client.target(url); - Response r = resource.request().accept(MediaType.TEXT_HTML).post(Entity.json(json)); - json = r.readEntity(String.class); - if (r.getStatus() != Response.Status.OK.getStatusCode()) { - throw new IOException("Inventory returned error: " + json); - } - Map ret = (Map) JsonSerializer.decode(json, Map.class); - return (T) ret.get("d"); - } finally { - client.close(); - } - } - - public static String findPartidByHoly(String holy_name, String type) throws IOException { - if (type == null) { - type = "DSCR"; - } - Map query = new HashMap(); - Map qn = new HashMap(); - Map qt = new HashMap(); - qn.put("Field", "Holy List Name"); - qn.put("Operator", "Is"); - qn.put("Value", holy_name); - qt.put("Field", "Type"); - qt.put("Operator", "Is"); - qt.put("Value", type); - query.put("query", Arrays.asList(new Map[]{qn, qt})); - query.put("columns", Arrays.asList(new String[]{"Label"})); - - Map attr = new HashMap(); - attr.put("search", query); - Map ret = (Map) inventoryRequest("https://inventory.psi.ch/DataAccess.asmx/FindObjects", attr, Map.class); - try { - return (String) ((List) (((List) ret.get("Rows")).get(0))).get(0); - } catch (Exception ex) { - return null; - } - } - - public static List findAllByType(String type, String column) throws IOException { - if (type == null) { - type = "DSCR"; - } - if (column == null) { - column = "Holy List Name"; - } - - Map query = new HashMap(); - Map q = new HashMap(); - q.put("Field", "Type"); - q.put("Operator", "Is"); - q.put("Value", type); - query.put("query", Arrays.asList(new Map[]{q})); - query.put("columns", Arrays.asList(new String[]{"Label"})); - - Map attr = new HashMap(); - attr.put("search", query); - Map r = (Map) inventoryRequest("https://inventory.psi.ch/DataAccess.asmx/FindObjects", attr, Map.class); - List rows = (List) (r.get("Rows")); - List ret = new ArrayList(); - for (Object list : rows) { - ret.add(((List) list).get(0)); - } - return ret; - } - - public static List getPartAttributesFromInventory(String part_label, String holy_name) throws IOException { - if ((holy_name != null) && !holy_name.isEmpty()) { - part_label = findPartidByHoly(holy_name, "DSCR"); - if ((part_label == null) || part_label.isEmpty()) { - throw new IOException("Could not find inventory part for: " + holy_name); - } - } - Map map = new HashMap(); - map.put("psiLabel", part_label); - return (List) inventoryRequest("https://inventory.psi.ch/DataAccess.asmx/GetPartAttributes", map, List.class); - } - - public static List getCalibFromInventory(String part_label, String holy_name) throws IOException { - double horizontal_dist = 0.0; - double vertical_dist = 0.0; - double horizontal_tilt = 0.0; - double vertical_tilt = 0.0; - - List attributes = getPartAttributesFromInventory(part_label, holy_name); - - for (Map a : attributes) { - String name = (String) a.get("Name"); - Double val = 0.0; - try { - val = Double.valueOf(a.get("Value").toString()); - } catch (Exception ex) { - } - - switch (name) { - case "Crystal angle in x (e-beam system) [deg]": - horizontal_tilt = val; - break; - case "Crystal angle in y (e-beam system) [deg]": - vertical_tilt = val; - break; - case "Mark distance in x (e-beam system) [mm]": - horizontal_dist = val; - break; - case "Mark distance in y (e-beam system) [mm]": - vertical_dist = val; - break; - } - } - - return Arrays.asList(new Double[]{horizontal_dist, vertical_dist, horizontal_tilt, vertical_tilt}); - } - - public static void main(String[] args) throws IOException { - System.out.println(getCalibFromInventory("SINEG01-DSCR190", "SINEG01-DSCR190")); - System.out.println(findAllByType(null, null)); - } -} diff --git a/plugins/LaserGunAlignment.java b/plugins/LaserGunAlignment.java index 41bb277..c9a7d6e 100755 --- a/plugins/LaserGunAlignment.java +++ b/plugins/LaserGunAlignment.java @@ -2,10 +2,9 @@ * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ -import ch.psi.pshell.core.Context; import ch.psi.pshell.plot.LinePlot; -import ch.psi.pshell.ui.Panel; -import ch.psi.utils.State; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.utils.State; import java.awt.Component; import java.util.HashMap; import javax.swing.JPanel; @@ -36,7 +35,7 @@ public class LaserGunAlignment extends Panel { } return ret; }); - } catch (Context.ContextStateException ex) { + } catch (StateException ex) { showException((Exception) ex); } } diff --git a/plugins/SchottkyScan.java b/plugins/SchottkyScan.java index 45086eb..3eef3e1 100755 --- a/plugins/SchottkyScan.java +++ b/plugins/SchottkyScan.java @@ -11,10 +11,10 @@ import ch.psi.pshell.plot.Plot; import ch.psi.pshell.scan.Scan; import ch.psi.pshell.scan.ScanListener; import ch.psi.pshell.scan.ScanRecord; -import ch.psi.pshell.ui.Panel; -import ch.psi.utils.Convert; -import ch.psi.utils.State; -import ch.psi.utils.swing.SwingUtils; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.utils.Convert; +import ch.psi.pshell.utils.State; +import ch.psi.pshell.swing.SwingUtils; import java.awt.Color; import java.awt.Component; import java.util.ArrayList; diff --git a/plugins/ScreenPanel.form b/plugins/ScreenPanel.form deleted file mode 100755 index d917500..0000000 --- a/plugins/ScreenPanel.form +++ /dev/null @@ -1,1099 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java deleted file mode 100755 index 91c8f34..0000000 --- a/plugins/ScreenPanel.java +++ /dev/null @@ -1,3367 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.bs.CameraServer; -import ch.psi.pshell.core.Context; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.PipelineServer; -import ch.psi.pshell.bs.StreamValue; -import ch.psi.pshell.core.JsonSerializer; -import ch.psi.pshell.data.DataManager; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.DiscretePositioner; -import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.imaging.Colormap; -import ch.psi.pshell.imaging.ColormapSource; -import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.DimensionDouble; -import ch.psi.pshell.imaging.Histogram; -import ch.psi.pshell.imaging.ImageBuffer; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.PointDouble; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Convert; -import ch.psi.utils.swing.Editor.EditorDialog; -import ch.psi.utils.swing.MainFrame; -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.StandardDialog.StandardDialogListener; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.FileInputStream; -import java.lang.reflect.Array; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.table.DefaultTableModel; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.PolynomialCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; - -/** - * - */ -public class ScreenPanel extends Panel { - - final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useServerStats = true; - String userOverlaysConfigFile; - ColormapSource camera; - PipelineServer server; - String cameraName; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - boolean showProfile; - Overlay[] userOv; - Overlay[] fitOv; - Overlay[] profileOv; - Overlay errorOverlay; - boolean requestCameraListUpdate; - boolean goodRegion; - boolean slicing; - String serverUrl; - String camServerUrl; - String instanceName; - - Double getServerDouble(String name) { - return (Double) Convert.toDouble(server.getValue(name)); - } - - double[] getServerDoubleArray(String name) { - return (double[]) Convert.toDouble(server.getValue(name)); - } - - Double getServerDouble(String name, StreamValue cache) { - return (Double) Convert.toDouble(cache.__getitem__(name)); - } - - double[] getServerDoubleArray(String name, StreamValue cache) { - return (double[]) Convert.toDouble(cache.__getitem__(name)); - } - - class ImageData { - - ImageData() { - if (server != null) { - cache = server.getStream().take(); - String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getServerDouble(prefix + "x_fit_mean", cache); - y_fit_mean = getServerDouble(prefix + "y_fit_mean", cache); - x_fit_standard_deviation = getServerDouble(prefix + "x_fit_standard_deviation", cache); - y_fit_standard_deviation = getServerDouble(prefix + "y_fit_standard_deviation", cache); - x_fit_gauss_function = getServerDoubleArray(prefix + "x_fit_gauss_function", cache); - y_fit_gauss_function = getServerDoubleArray(prefix + "y_fit_gauss_function", cache); - x_profile = getServerDoubleArray("x_profile", cache); - y_profile = getServerDoubleArray("y_profile", cache); - x_center_of_mass = getServerDouble("x_center_of_mass", cache); - y_center_of_mass = getServerDouble("y_center_of_mass", cache); - x_rms = getServerDouble("x_rms", cache); - y_rms = getServerDouble("y_rms", cache); - if (goodRegion) { - double[] gX2 = new double[x_profile.length]; - Arrays.fill(gX2, Double.NaN); - try { - double x = getServerDoubleArray("gr_x_axis", cache)[0]; - System.arraycopy(x_fit_gauss_function, 0, gX2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x) : x), x_fit_gauss_function.length); - } catch (Exception ex) { - } - x_fit_gauss_function = gX2; - double[] gY2 = new double[y_profile.length]; - Arrays.fill(gY2, Double.NaN); - try { - double y = getServerDoubleArray("gr_y_axis", cache)[0]; - System.arraycopy(y_fit_gauss_function, 0, gY2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageY(y) : y), y_fit_gauss_function.length); - } catch (Exception ex) { - } - y_fit_gauss_function = gY2; - if (slicing) { - try { - int slices = getServerDouble("slice_amount").intValue(); - sliceCenters = new PointDouble[slices]; - for (int i = 0; i < slices; i++) { - double x = getServerDouble("slice_" + i + "_center_x"); - double y = getServerDouble("slice_" + i + "_center_y"); - sliceCenters[i] = new PointDouble(x, y); - } - } catch (Exception ex) { - } - } - } - } - } - public Double x_fit_mean; - public Double y_fit_mean; - public Double x_center_of_mass; - public Double x_rms; - public Double x_fit_standard_deviation; - public Double y_fit_standard_deviation; - public Double y_center_of_mass; - public Double y_rms; - public double[] x_profile; - public double[] x_fit_gauss_function; - public double[] y_profile; - public double[] y_fit_gauss_function; - public PointDouble[] sliceCenters; - public StreamValue cache; - } - - class Frame extends ImageData { - - Frame(Data data) { - this.data = data; - } - Data data; - } - - final ArrayList imageBuffer = new ArrayList(); - Frame currentFrame; - int imageBufferLenght = 1; - Text imageBufferOverlay; - - public ScreenPanel() { - initComponents(); - spinnerThreshold.setVisible(false); - btFixColormapRange.setVisible(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - JComponent editor = spinnerSlOrientation.getEditor(); - if (editor instanceof JSpinner.DefaultEditor) { - ((JSpinner.DefaultEditor) editor).getTextField().setHorizontalAlignment(JTextField.RIGHT); - } - //spinnerMin.setVisible(false); labelMin.setVisible(false); - //spinnerMax.setVisible(false); labelMax.setVisible(false); - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - setPersistedComponents(new Component[]{buttonServer, buttonDirect}); - comboCameras.setEnabled(false); - SwingUtils.setEnumCombo(comboColormap, Colormap.class); - if (App.hasArgument("poll")) { - try { - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try { - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("buf")) { - try { - imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("usr_ov")) { - try { - userOverlaysConfigFile = App.getArgumentValue("usr_ov"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_url")) { - serverUrl = App.getArgumentValue("srv_url"); - } - - if (App.hasArgument("cam_srv_url")) { - camServerUrl = App.getArgumentValue("cam_srv_url"); - } - - - if (App.hasArgument("calc")) { - useServerStats = false; - } - - renderer.setProfileNormalized(true); - renderer.setShowProfileLimits(false); - - JMenuItem menuCalibrate = new JMenuItem("Calibrate..."); - menuCalibrate.addActionListener((ActionEvent e) -> { - try { - calibrate(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuCameraConfig = new JMenuItem("Renderer Config"); - menuCameraConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuShowStreamData = new JMenuItem("Show Stream Data"); - menuShowStreamData.addActionListener((ActionEvent e) -> { - try { - showStreamData(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSaveStack = new JMenuItem("Save Stack"); - menuSaveStack.addActionListener((ActionEvent e) -> { - try { - saveStack(); - } catch (Exception ex) { - showException(ex); - } - }); - menuSaveStack.setEnabled(imageBufferLenght > 0); - - JMenuItem menuSetROI = new JMenuItem("Set ROI..."); - menuSetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); - renderer.addListener(new RendererListener() { - @Override - public void onSelectionFinished(Renderer renderer, Overlay overlay) { - try { - renderer.setShowReticle(false); - Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (server.isRoiEnabled()) { - int[] cur = server.getRoi(); - server.setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); - } else { - server.setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); - } - } catch (Exception ex) { - } finally { - renderer.removeListener(this); - } - } - - @Override - public void onSelectionAborted(Renderer renderer, Overlay overlay) { - renderer.removeListener(this); - } - }); - selection.setFixed(true); - renderer.startSelection(selection); - } - }); - - JMenuItem menuResetROI = new JMenuItem("Reset ROI"); - menuResetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - try { - renderer.setShowReticle(false); - server.resetRoi(); - } catch (IOException ex) { - showException(ex); - } - } - }); - - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuCameraConfig); - renderer.getPopupMenu().add(menuShowStreamData); - renderer.getPopupMenu().add(menuCalibrate); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuSetROI); - renderer.getPopupMenu().add(menuResetROI); - renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(server != null); - menuSetROI.setEnabled(server != null); - menuShowStreamData.setVisible(server != null); - menuCalibrate.setVisible(server != null); - menuCalibrate.setEnabled((calibrationDialolg == null) || (!calibrationDialolg.isShowing())); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - } - }); - renderer.getPopupMenu().setVisible(false); - - showFit = buttonFit.isSelected(); - showProfile = buttonProfile.isSelected(); - - pauseSelection.setVisible(false); - pauseSelection.setMinValue(1); - pauseSelection.addListener(new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - if (editing && (value >= 1) && (value <= imageBuffer.size())) { - updatePause(); - } - } - }); - imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 20)); - imageBufferOverlay.setFixed(true); - imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_RIGHT); - if (MainFrame.isDark()) { - textState.setEnabled(true); - textType.setEnabled(true); - } - } - - @Override - public void onStart() { - super.onStart(); - if (App.hasArgument("ct")) { - boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonServer.setSelected(!direct); - buttonDirect.setSelected(direct); - } - } - - @Override - public void onStop() { - try { - if (camera != null) { - camera.close(); - camera = null; - server = null; - } - } catch (Exception ex) { - ex.printStackTrace(); - } - super.onStop(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - if (App.hasArgument("s")) { - renderer.setDevice((Source) getDevice("image")); - renderer.setAutoScroll(true); - ((Source) getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - manageFit(bi, data); - manageUserOverlays(bi, data); - } - - @Override - public void onError(Object o, Exception ex) { - } - } - ); - - } else { - usingServer = buttonServer.isSelected(); - updateCameraList(); - comboCameras.setEnabled(true); - setComboCameraSelection(-1); - - if (comboCameras.getModel().getSize() > 0) { - try { - if (App.hasArgument("cam")) { - setComboCameraSelection(App.getArgumentValue("cam")); - comboCamerasActionPerformed(null); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - startTimer(1000); - } - - DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - if (fromServer) { - try (PipelineServer srv = newServer()) { - srv.initialize(); - List cameras = srv.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - model.addElement(camera); - } - } - - } else { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - for (String cam : cameras) { - model.addElement(cam); - } - } - return model; - } - - PipelineServer newServer() throws IOException { - if (serverUrl != null) { - System.out.println("Connecting to server: " + serverUrl); - server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl); - } else { - System.out.println("Connecting to server"); - server = new PipelineServer(CAMERA_DEVICE_NAME); - } - return server; - } - - boolean updatingCameraSelection; - - void setComboCameraSelection(Object selection) { - updatingCameraSelection = true; - try { - comboCameras.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - - boolean usingServer; - - void updateCameraList() { - try { - String selected = (String) comboCameras.getSelectedItem(); - DefaultComboBoxModel model = getCameraList(usingServer); - if (App.hasArgument("cam")) { - String cam = App.getArgumentValue("cam"); - if (model.getIndexOf(cam) < 0) { - model.addElement(cam); - } - } - comboCameras.setModel(model); - if (selected != null) { - setComboCameraSelection(selected); - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateStop(); - } - } - - final Object lockOverlays = new Object(); - - void manageFit(BufferedImage bi, Data data) { - Overlay[][] fo = null; - if ((showFit || showProfile)){ - try{ - fo=getFitOverlays(data); - } catch (Exception ex){ - System.err.println(ex); - } - } - synchronized (lockOverlays) { - fo = (fo == null) ? new Overlay[][]{null, null} : fo; - renderer.updateOverlays(fo[0], profileOv); - profileOv = fo[0]; - renderer.updateOverlays(fo[1], fitOv); - fitOv = fo[1]; - } - } - - void manageUserOverlays(BufferedImage bi, Data data) { - Overlay[] fo = (bi == null) ? null : getUserOverlays(data); - synchronized (lockOverlays) { - renderer.updateOverlays(fo, userOv); - userOv = fo; - } - } - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - Thread devicesInitTask; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Initializing"); - parseUserOverlays(); - errorOverlay = null; - - if (dataTableDialog != null) { - dataTableDialog.dispose(); - dataTableDialog = null; - } - dataTableModel = null; - - if (calibrationDialolg != null) { - calibrationDialolg.dispose(); - calibrationDialolg = null; - } - - boolean was_server = false; - if (camera != null) { - //camera.removeAllListeners(); - was_server = (server != null); - camera.close(); - camera = null; - server = null; - } - instanceName = null; - renderer.setDevice(null); - - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.removeOverlays(profileOv); - renderer.removeOverlays(userOv); - renderer.clear(); - renderer.resetZoom(); - - boolean changed = !String.valueOf(cameraName).equals(this.cameraName); - this.cameraName = cameraName; - textType.setText(getCameraType(cameraName)); - - if (changed || buttonDirect.isSelected()) { - spinnerThreshold.setVisible(false); - checkThreshold.setEnabled(false); - checkGoodRegion.setEnabled(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - } - if (changed) { - checkBackground.setEnabled(false); - if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { - devicesInitTask.interrupt(); - } - if (screen != null) { - screen.close(); - screen = null; - } - if (filter != null) { - filter.close(); - filter = null; - } - } - if (cameraName == null) { - return; - } - - System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]"); - - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - - try { - if (buttonServer.isSelected()) { - camera = newServer(); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - //camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName); - camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName}); - } - camera.initialize(); - camera.assertInitialized(); - System.out.println("Camera initialization OK"); - if (server != null) { - //server.start(cameraName, false); - String pipelineName = cameraName + "_sp"; - instanceName = cameraName + "_sp1"; - if (!server.getPipelines().contains(pipelineName)) { - System.out.println("Creating pipeline: " + pipelineName); - HashMap config = new HashMap<>(); - config.put("camera_name", cameraName); - //server.createFromConfig(config, pipelineName); - server.savePipelineConfig(pipelineName, config); - } - server.start(pipelineName, instanceName); - - updateServerControls(); - checkThreshold.setEnabled(true); - checkGoodRegion.setEnabled(true); - } else { - checkThreshold.setSelected(false); - checkGoodRegion.setSelected(false); - if (polling <= 0) { - camera.setMonitored(true); - } else { - camera.setPolling(polling); - } - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - - buttonReticle.setEnabled(camera.getConfig().isCalibrated()); - camera.getConfig().save(); - renderer.setDevice(camera); - renderer.setAutoScroll(true); - renderer.setMarker(marker); - imageSize = null; - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi != null) { - if ((imageSize == null) || imageSize.width != bi.getWidth() || imageSize.height != bi.getHeight()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { - centralizeRenderer(); - } - checkReticle(); - } - }); - imageSize = new Dimension(bi.getWidth(), bi.getHeight()); - } - renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); - } - //renderer.setCalibration(camera.getCalibration()); - if (!renderer.isPaused()) { - if (data != null) { - synchronized (imageBuffer) { - currentFrame = new Frame(data); - if (imageBufferLenght >= 1) { - imageBuffer.add(currentFrame); - if (imageBuffer.size() > imageBufferLenght) { - imageBuffer.remove(0); - } - } - } - } - manageFit(bi, data); - manageUserOverlays(bi, data); - } - //updateImageData(); - } - - @Override - public void onError(Object o, Exception ex) { - //System.err.println(ex); - } - }); - - } catch (Exception ex) { - showException(ex); - renderer.clearOverlays(); - updateServerControls(); - if (renderer.getDevice() == null) { - //renderer.setZoom(1.0); - //renderer.setMode(RendererMode.Zoom); - errorOverlay = new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - errorOverlay.setFixed(true); - errorOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - renderer.addOverlay(errorOverlay); - } - } finally { - //checkReticle(); - onTimer(); - } - onChangeColormap(null); - checkBackground.setEnabled(true); - if (changed) { - comboScreen.setModel(new DefaultComboBoxModel()); - comboScreen.setEnabled(false); - comboFilter.setModel(new DefaultComboBoxModel()); - comboFilter.setEnabled(false); - if (getCameraType(cameraName).equals("Electrons")) { - //Parallelizing initialization - devicesInitTask = new Thread(() -> { - try { - if (cameraName.contains("DSRM")) { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); - } else { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); - } - screen.setMonitored(true); - screen.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : screen.getPositions()) { - model.addElement(pos); - } - comboScreen.setModel(model); - comboScreen.setSelectedItem(screen.read()); - - } catch (Exception ex) { - comboScreen.setModel(new DefaultComboBoxModel()); - System.err.println(ex.getMessage()); - screen = null; - } - comboScreen.setEnabled(screen != null); - valueScreen.setDevice(screen); - - try { - filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); - filter.setMonitored(true); - filter.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : filter.getPositions()) { - model.addElement(pos); - } - comboFilter.setModel(model); - comboFilter.setSelectedItem(filter.read()); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - filter = null; - } - comboFilter.setEnabled(filter != null); - valueFilter.setDevice(filter); - }); - devicesInitTask.start(); - } - } - } - - volatile Dimension imageSize; - - void checkReticle() { - if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) { - //renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800, 800), 200); - renderer.setShowReticle(true); - } else { - //renderer.setCalibration(null); - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - void checkMarker() { - if (camera != null) { - if (buttonMarker.isSelected()) { - Dimension d = renderer.getImageSize(); - Point p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - marker.setPassive(false); - } else { - marker = null; - } - renderer.setMarker(marker); - } - } - - void updateZoom() { - try { - buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom) { - if (renderer.getZoom() == 1) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getZoom() == 0.5) { - buttonZoom05.setSelected(true); - } else if (renderer.getZoom() == 0.25) { - buttonZoom025.setSelected(true); - } else if (renderer.getZoom() == 2.0) { - buttonZoom2.setSelected(true); - } else { - buttonGroup1.clearSelection(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - boolean updatingColormap; - - void updateColormap() { - updatingColormap = true; - try { - if ((camera != null) && (camera instanceof ColormapSource)) { - ColormapSourceConfig config = ((ColormapSource) camera).getConfig(); - comboColormap.setSelectedItem(config.colormap); - if (config.isDefaultColormap()) { - buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic) { - buttonAutomatic.setSelected(true); - } else { - buttonManual.setSelected(true); - } - btFixColormapRange.setVisible(buttonAutomatic.isSelected()); - - //spinnerMin.setVisible(buttonManual.isSelected()); labelMin.setVisible(spinnerMin.isVisible()); - //spinnerMax.setVisible(buttonManual.isSelected()); labelMax.setVisible(spinnerMax.isVisible()); - spinnerMin.setEnabled(buttonManual.isSelected()); - spinnerMax.setEnabled(buttonManual.isSelected()); - //spinnerMin.setValue(Double.isNaN(config.colormapMin) ? 0 : Math.min(Math.max((int) config.colormapMin, 0), 65535)); - //spinnerMax.setValue(Double.isNaN(config.colormapMax) ? 0 : Math.min(Math.max((int) config.colormapMax, 0), 65535)); - if (!Double.isNaN(config.colormapMin)) { - spinnerMin.setValue(Math.min(Math.max((int) config.colormapMin, 0), 65535)); - } - if (!Double.isNaN(config.colormapMax)) { - spinnerMax.setValue(Math.min(Math.max((int) config.colormapMax, 0), 65535)); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatingColormap = false; - } - - boolean updatingServerControls; - - void updateServerControls() { - if (server != null) { - updatingServerControls = true; - try { - checkBackground.setSelected(server.getBackgroundSubtraction()); - Double threshold = (server.getThreshold()); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (server.getGoodRegion()); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - spinnerGrThreshold.setValue(((Number) gr.get("threshold")).doubleValue()); - spinnerGrScale.setValue(((Number) gr.get("gfscale")).doubleValue()); - } - Map slicing = (server.getSlicing()); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - spinnerSlNumber.setValue(((Number) slicing.get("number_of_slices")).intValue()); - spinnerSlScale.setValue(((Number) slicing.get("scale")).doubleValue()); - spinnerSlOrientation.setValue((String) slicing.get("orientation")); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - goodRegion = checkGoodRegion.isSelected(); - spinnerThreshold.setVisible(checkThreshold.isSelected()); - setGoodRegionOptionsVisible(goodRegion); - slicing = goodRegion && checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - updatingServerControls = false; - } - } - - void setGoodRegionOptionsVisible(boolean visible) { - spinnerGrThreshold.setVisible(visible); - labelGrThreshold.setVisible(visible); - spinnerGrScale.setVisible(visible); - labelGrScale.setVisible(visible); - panelSlicing.setVisible(visible); - } - - void setSlicingOptionsVisible(boolean visible) { - spinnerSlNumber.setVisible(visible); - labelSlNumber.setVisible(visible); - spinnerSlScale.setVisible(visible); - labelSlScale.setVisible(visible); - spinnerSlOrientation.setVisible(visible); - labelSlOrientation.setVisible(visible); - } - - boolean isCameraStopped() { - if (server != null) { - if (!server.isStarted()) { - return true; - } - } - return ((camera == null) || (camera.isClosed()) || !buttonStop.isEnabled()); - } - - void updateStop() { - buttonStop.setEnabled(comboCameras.getSelectedItem() != null); - buttonStop.setText(isCameraStopped() ? "Start" : "Stop"); - - } - - @Override - protected void onTimer() { - for (Device dev : new Device[]{screen, filter}) { - if (dev != null) { - dev.request(); - } - } - - textState.setText((camera == null) ? "" : camera.getState().toString()); - buttonArgs.setEnabled(camera != null); - if (App.hasArgument("s")) { - try { - ((Source) getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex); - } - } - if (renderer.isPaused() != buttonPause.isSelected()) { - buttonPause.setSelected(renderer.isPaused()); - buttonPauseActionPerformed(null); - } - if (renderer.getShowReticle() != buttonReticle.isSelected()) { - //buttonReticle.setSelected(renderer.getShowReticle()); - } - if ((renderer.getMarker() == null) && buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - } - if (!renderer.isPaused() && (dataTableDialog != null) && (dataTableDialog.isShowing())) { - updateStreamData(); - } - updateZoom(); - updateColormap(); - updateStop(); - buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); - } - - Pen penFit = new Pen(new Color(192, 105, 0), 0); - Pen penCross = new Pen(new Color(192, 105, 0), 0); - Pen penSlices = new Pen(Color.CYAN.darker(), 1); - - Frame getCurrentFrame() { - if ((imageBufferLenght > 1) && (renderer.isPaused())) { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - return (index < imageBuffer.size()) ? imageBuffer.get(index) : null; - } - } - return currentFrame; - } - - Frame getFrame(Data data) { - synchronized (imageBuffer) { - for (Frame f : imageBuffer) { - if (f.data == data) { - return f; - } - } - } - return null; - } - - Overlay[][] getFitOverlays(Data data) { - Overlays.Polyline hgaussian = null; - Overlays.Polyline vgaussian = null; - Overlays.Polyline hprofile = null; - Overlays.Polyline vprofile = null; - Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null; - Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null; - double[] pX = null, pY = null, gX = null, gY = null; - int height = data.getHeight(); - int width = data.getWidth(); - PointDouble[] sliceCenters = null; - //Double xCom=null, yCom=null; - if (data != null) { - int profileSize = renderer.getProfileSize(); - if ((useServerStats) && (server != null)) { - try { - - ImageData id = getFrame(data); - if (id == null) { - return null; - } - xMean = id.x_fit_mean; - xSigma = id.x_fit_standard_deviation; - yMean = id.y_fit_mean; - ySigma = id.y_fit_standard_deviation; - gX = id.x_fit_gauss_function; - gY = id.y_fit_gauss_function; - pX = id.x_profile; - pY = id.y_profile; - xCom = id.x_center_of_mass; - xRms = id.x_rms; - yCom = id.y_center_of_mass; - yRms = id.y_rms; - sliceCenters = id.sliceCenters; - - profileSize /= 4; - if (pX != null) { - int[] x = Arr.indexesInt(pX.length); - int[] y = new int[pX.length]; - int[] p = new int[pX.length]; - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - Double min = Collections.min(l); - Double max = Collections.max(l); - double minPlot = min; - double rangePlot = max - min; - - for (int i = 0; i < x.length; i++) { - if (gX != null) { - y[i] = (int) (height - 1 - (((gX[i] - minPlot) / rangePlot) * profileSize)); - } - p[i] = (int) (height - 1 - (((pX[i] - minPlot) / rangePlot) * profileSize)); - } - - if (goodRegion) { - for (int i = 0; i < x.length; i++) { - y[i] = (Double.isNaN(gX[i])) ? 100000 : y[i]; - } - } - - vgaussian = new Overlays.Polyline(penFit, x, y); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - - if (pY != null) { - int[] y = Arr.indexesInt(pY.length); - int[] x = new int[pY.length]; - int[] p = new int[pY.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - Double min = Collections.min(l); - Double max = Collections.max(l); - double minPlot = min; - double rangePlot = max - min; - - for (int i = 0; i < x.length; i++) { - if (gY != null) { - x[i] = (int) (((gY[i] - minPlot) / rangePlot) * profileSize); - } - p[i] = (int) (((pY[i] - minPlot) / rangePlot) * profileSize); - } - - if (goodRegion) { - for (int i = 0; i < x.length; i++) { - x[i] = (Double.isNaN(gY[i])) ? -1 : x[i]; - } - } - hgaussian = new Overlays.Polyline(penFit, x, y); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, y); - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - return null; - } - } else { - ArrayProperties properties = data.getProperties(); - double maxPlot = properties.max; - double minPlot = properties.min; - double rangePlot = maxPlot - minPlot; - - if (rangePlot <= 0) { - return null; - } - if (renderer.getCalibration() != null) { - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height - minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - if (xSigma != null) { - xSigma *= renderer.getCalibration().getScaleX(); - } - if (ySigma != null) { - ySigma *= renderer.getCalibration().getScaleY(); - } - if (xMean != null) { - xMean = data.getX((int) Math.round(xMean)); - } - if (yMean != null) { - yMean = data.getY((int) Math.round(yMean)); - } - } - } - final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px"; - final String fmt = "%7.1f" + units; - Overlays.Text textCom = null; - Overlay[] pOv = null, fOv = null; - Font fontInfoText = new Font(Font.MONOSPACED, 0, 14); - Point textPosition = new Point(12, 20); - if (showProfile) { - if ((xCom != null) && (yCom != null)) { - String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt, xCom, xRms, yCom, yRms); - textCom = new Overlays.Text(renderer.getPenProfile(), text, fontInfoText, textPosition); - textCom.setFixed(true); - textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - } - pOv = new Overlay[]{hprofile, vprofile, textCom}; - textPosition = new Point(textPosition.x, textPosition.y + 34); - } - if (showFit) { - Overlays.Crosshairs cross = null; - Overlays.Text textFit = null; - if ((xMean != null) && (yMean != null)) { - String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt, xMean, xSigma, yMean, ySigma); - textFit = new Overlays.Text(penFit, text, fontInfoText, textPosition); - textFit.setFixed(true); - textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - Point center = new Point(xMean.intValue(), yMean.intValue()); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean)); - xSigma /= renderer.getCalibration().getScaleX(); - ySigma /= renderer.getCalibration().getScaleY(); - } - cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue()))); - } - textPosition = new Point(textPosition.x, textPosition.y + 34); - fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit}; - - if (goodRegion) { - try { - double[] x = getServerDoubleArray("gr_x_axis"); - double[] y = getServerDoubleArray("gr_y_axis"); - double x1 = x[0]; - double x2 = x[x.length - 1]; - double y1 = y[0]; - double y2 = y[y.length - 1]; - Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); - goodRegionOv.setCalibration(renderer.getCalibration()); - goodRegionOv.setAbsolutePosition(new PointDouble(x1, y1)); - goodRegionOv.setAbsoluteSize(new DimensionDouble(x2 - x1, y2 - y1)); - fOv = Arr.append(fOv, goodRegionOv); - - if (slicing) { - if (sliceCenters != null) { - for (PointDouble sliceCenter : sliceCenters) { - Overlays.Crosshairs center = new Overlays.Crosshairs(penSlices); - center.setCalibration(renderer.getCalibration()); - center.setAbsolutePosition(sliceCenter); - center.setSize(new Dimension(10, 10)); - fOv = Arr.append(fOv, center); - } - if (sliceCenters.length > 1) { - double[] fit = fitPolynomial(sliceCenters, 1); - double angle = Math.toDegrees(Math.atan(fit[1])); - Overlays.Text text = new Overlays.Text(penSlices, String.format("slice: \u03B8= %5.1fdeg", angle), fontInfoText, textPosition); - text.setFixed(true); - text.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - fOv = Arr.append(fOv, text); - } - } - } - } catch (Exception ex) { - } - } - - } - return new Overlay[][]{pOv, fOv}; - } - return null; - } - - class UserOverlay { - - String name; - Overlay obj; - String[] channels; - } - ArrayList userOverlayConfig; - - void parseUserOverlays() { - Properties userOverlays = new Properties(); - userOverlayConfig = new ArrayList<>(); - if (userOverlaysConfigFile != null) { - try { - try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { - userOverlays.load(in); - - for (String name : userOverlays.stringPropertyNames()) { - String val = userOverlays.getProperty(name); - try { - UserOverlay uo = new UserOverlay(); - uo.name = name; - String type = val.substring(0, val.indexOf("(")).trim(); - String pars = val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")).trim(); - String[] tokens = pars.split(","); - for (int i = 0; i < tokens.length; i++) { - tokens[i] = tokens[i].trim(); - } - Color color = Color.GRAY; - try { - color = (Color) Color.class.getField(tokens[tokens.length - 1].toUpperCase()).get(null); - } catch (Exception ex) { - } - Pen pen = new Pen(color); - try { - String[] penTokens = tokens[tokens.length - 1].split(":"); - color = (Color) Color.class.getField(penTokens[0].toUpperCase()).get(null); - int width = Integer.valueOf(penTokens[1]); - Pen.LineStyle style = Pen.LineStyle.valueOf(penTokens[2]); - pen = new Pen(color, width, style); - } catch (Exception ex) { - } - switch (type) { - case "Point": - uo.obj = new Overlays.Crosshairs(); - uo.obj.setSize(new Dimension(Integer.valueOf(tokens[2]), Integer.valueOf(tokens[3]))); - break; - case "Line": - uo.obj = new Overlays.Line(); - break; - case "Arrow": - uo.obj = new Overlays.Arrow(); - break; - case "Rect": - uo.obj = new Overlays.Rect(); - break; - case "Ellipse": - uo.obj = new Overlays.Ellipse(); - break; - case "Polyline": - uo.obj = new Overlays.Polyline(); - break; - } - if (type.equals("Polyline") || type.equals("Point")) { - uo.channels = new String[]{tokens[0], tokens[1]}; - } else { - uo.channels = new String[]{tokens[0], tokens[1], tokens[2], tokens[3]}; - } - uo.obj.setPen(pen); - userOverlayConfig.add(uo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - Overlay[] getUserOverlays(Data data) { - ArrayList ret = new ArrayList<>(); - if (server != null) { - for (UserOverlay uo : userOverlayConfig) { - try { - Overlay ov = uo.obj; - //Overlay ov = (Overlay)uo.cls.newInstance(); - ov.setCalibration(renderer.getCalibration()); - boolean valid = false; - if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : getServerDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : getServerDoubleArray(uo.channels[1]); - if ((x != null) || (y != null)) { - if (x == null) { - x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); - } - if (y == null) { - y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length); - } - ((Overlays.Polyline) ov).updateAbsolute(x, y); - valid = true; - } - } else { - Double x = getServerDouble(uo.channels[0]); - Double y = getServerDouble(uo.channels[1]); - if ((x != null) && (y != null)) { - PointDouble position = new PointDouble(x, y); - ov.setAbsolutePosition(position); - if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = getServerDouble(uo.channels[2]); - Double y2 = getServerDouble(uo.channels[3]); - if ((x != null) && (y != null)) { - DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); - ov.setAbsoluteSize(size); - valid = true; - } - } else { - valid = true; - } - } - } - if (valid) { - ret.add(ov); - } - } catch (Exception ex) { - //ex.printStackTrace(); - } - } - } - return ret.toArray(new Overlay[0]); - } - - double[] getComRms(double[] arr, double[] x) { - if (arr != null) { - double xmd = 0; - double xmd2 = 0; - double total = 0; - for (int i = 0; i < arr.length; i++) { - double v = (arr[i] * x[i]); - xmd += v; - xmd2 += (v * x[i]); - total += arr[i]; - } - if (total > 0) { - double com = xmd / total; - double com2 = xmd2 / total; - double rms = Math.sqrt(Math.abs(com2 - com * com)); - return new double[]{com, rms}; - } - } - return new double[]{Double.NaN, Double.NaN}; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] fitPolynomial(PointDouble[] points, int order) { - double[] y = new double[points.length]; - double[] x = new double[points.length]; - for (int i = 0; i < points.length; i++) { - x[i] = points[i].x; - y[i] = points[i].y; - } - return fitPolynomial(y, x, order); - } - - double[] fitPolynomial(double[] y, double[] x, int order) { - try { - ArrayProperties pY = ArrayProperties.get(y); - PolynomialCurveFitter fitter = PolynomialCurveFitter.create(order).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - void setHistogramVisible(boolean value) { - if (value) { - if ((histogramDialog == null) || (!histogramDialog.isShowing())) { - Histogram histogram = new Histogram(true); - histogram.setRenderer(renderer); - histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram); - renderer.refresh(); - } - } else { - if (histogramDialog != null) { - histogramDialog.setVisible(false); - histogramDialog = null; - } - } - } - - void setLaserState(boolean value) throws Exception { - System.out.println("Setting laser state: " + value); - Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); - Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); - Thread.sleep(3000); - } - - boolean getLaserState() throws Exception { - return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); - } - - void elog(String logbook, String title, String message, String[] attachments) throws Exception { - String domain = ""; - String category = "Info"; - String entry = ""; - StringBuffer cmd = new StringBuffer(); - - cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); - cmd.append("-a \"Author=ScreenPanel\" "); - cmd.append("-a \"Type=pshell\" "); - cmd.append("-a \"Entry=").append(entry).append("\" "); - cmd.append("-a \"Title=").append(title).append("\" "); - cmd.append("-a \"Category=").append(category).append("\" "); - cmd.append("-a \"Domain=").append(domain).append("\" "); - for (String attachment : attachments) { - cmd.append("-f \"").append(attachment).append("\" "); - } - cmd.append("-n 1 "); - cmd.append("\"").append(message).append("\" "); - System.out.println(cmd.toString()); - - final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); - new Thread(() -> { - try { - process.waitFor(); - int bytes = process.getInputStream().available(); - byte[] arr = new byte[bytes]; - process.getInputStream().read(arr, 0, bytes); - System.out.println(new String(arr)); - bytes = process.getErrorStream().available(); - arr = new byte[bytes]; - process.getErrorStream().read(arr, 0, bytes); - System.err.println(new String(arr)); - } catch (Exception ex) { - System.err.println(ex); - } - }).start(); - } - - void centralizeRenderer() { - Point center = null; - Dimension size = renderer.getImageSize(); - double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom(); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().getCenter(); - } else if (size != null) { - center = new Point(size.width / 2, size.height / 2); - } - if (center != null) { - Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0), - Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0)); - renderer.setViewPosition(topleft); - } - } - - void updatePause() { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - if (index < imageBuffer.size()) { - Data data = imageBuffer.get(index).data; - BufferedImage image = camera.generateImage(data); - renderer.setImage(renderer.getOrigin(), image, data); - imageBufferOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS")); - manageFit(image, data); - manageUserOverlays(image, data); - } - } - } - - void saveSnapshot() throws Exception { - String snapshotFile = null; - synchronized (imageBuffer) { - Frame frame = getCurrentFrame(); - if (frame == null) { - throw new Exception("No current image"); - } - ArrayList frames = new ArrayList<>(); - frames.add(frame); - this.saveFrames("camera_snapshot", frames); - - //Enforce the same timestamp to data & image files. - snapshotFile = getContext().getExecutionPars().getPath() + ".png"; - ImageBuffer.saveImage(SwingUtils.createImage(renderer), snapshotFile, "png"); - } - - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{0, 180}; //Minimum width - layout.rowHeights = new int[]{30, 30, 30}; //Minimum height - panel.setLayout(layout); - JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); - JTextField textComment = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Data file:"), c); - c.gridy = 1; - panel.add(new JLabel("Logbook:"), c); - c.gridy = 2; - panel.add(new JLabel("Comment:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(textComment, c); - c.gridy = 1; - panel.add(comboLogbook, c); - c.gridy = 0; - panel.add(new JLabel(getContext().getExecutionPars().getPath()), c); - - if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes) { - StringBuilder message = new StringBuilder(); - message.append("Camera: ").append(cameraName).append(" ("). - append((server != null) ? "server" : "direct").append(")").append("\n"); - message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); - message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); - message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); - message.append("Comment: ").append(textComment.getText()).append("\n"); - if ((fitOv != null) && (fitOv.length > 5)) { - Overlays.Text text = (Overlays.Text) fitOv[5]; - message.append(text.getText()).append("\n"); - } - elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - } - - void saveStack() throws Exception { - synchronized (imageBuffer) { - saveFrames("camera_stack", imageBuffer); - } - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000); - } - - public static String getCameraType(String name) { - if (name == null) { - return ""; - } - for (String s : new String[]{"LCAM"}) { - if (name.contains(s)) { - return "Laser"; - } - } - for (String s : new String[]{"DSCR", "DSRM", "DLAC"}) { - if (name.contains(s)) { - return "Electrons"; - } - } - for (String s : new String[]{"PROF", "PPRM", "PSSS", "PSCR", "PSRD"}) { - if (name.contains(s)) { - return "Photonics"; - } - } - return "Unknown"; - } - - public Map getProcessingParameters(StreamValue value) throws IOException { - return (Map) JsonSerializer.decode(value.getValue("processing_parameters").toString(), Map.class); - } - - void saveFrames(String name, ArrayList frames) throws IOException { - ArrayList values = new ArrayList<>(); - for (Frame frame : frames) { - values.add(frame.cache); - } - saveImages(name, values); - } - - void saveImages(String name, ArrayList images) throws IOException { - int depth = images.size(); - if (depth == 0) { - return; - } - StreamValue first = images.get(0); - String pathRoot = "/camera1/"; - String pathImage = pathRoot + "image"; - String pathPid = pathRoot + "pulse_id"; - String pathTimestampStr = pathRoot + "timestamp_str"; - Map processingPars = getProcessingParameters(first); - String camera = (String) processingPars.get("camera_name"); - String type = getCameraType(camera); - - int width = ((Number) first.getValue("width")).intValue(); - int height = ((Number) first.getValue("height")).intValue(); - Class dataType = first.getValue("image").getClass().getComponentType(); - - getContext().setExecutionPars(name); - DataManager dm = getContext().getDataManager(); - - //Create tables - dm.createDataset(pathImage, dataType, new int[]{depth, height, width}); - dm.createDataset(pathPid, Long.class, new int[]{depth}); - dm.createDataset(pathTimestampStr, String.class, new int[]{depth}); - for (String id : first.getIdentifiers()) { - Object val = first.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(first); - for (String key : pars.keySet()) { - if ((pars.get(key) != null) && (pars.get(key) instanceof Map)) { - for (Object k : ((Map) pars.get(key)).keySet()) { - Object v = ((Map) pars.get(key)).get(k); - dm.setAttribute(pathImage, key + " " + k, (v == null) ? "" : v); - } - } else { - Object value = pars.get(key); - if (value == null){ - value = ""; - } else if (value instanceof List){ - Class cls = (((List) value).size()>0) ? ((List) value).get(0).getClass() : double.class; - value = Convert.toPrimitiveArray(value, cls); - //value = Convert.toDouble(value); - } - dm.setAttribute(pathImage, key, value); - } - } - } else if (val.getClass().isArray()) { - dm.createDataset(pathRoot + id, Double.class, new int[]{depth, Array.getLength(val)}); - } else { - dm.createDataset(pathRoot + id, val.getClass(), new int[]{depth}); - } - } - - //Add metadata - dm.setAttribute(pathRoot, "Camera", camera); - dm.setAttribute(pathRoot, "Images", depth); - dm.setAttribute(pathRoot, "Interval", -1); - dm.setAttribute(pathRoot, "Type", type); - if (type.equals("Electrons")) { - dm.setAttribute(pathRoot, "Screen", String.valueOf(valueScreen.getLabel().getText())); - dm.setAttribute(pathRoot, "Filter", String.valueOf(valueFilter.getLabel().getText())); - } - - //Save data - for (int index = 0; index < depth; index++) { - StreamValue streamValue = images.get(index); - dm.setItem(pathImage, streamValue.getValue("image"), new long[]{index, 0, 0}, new int[]{1, height, width}); - dm.setItem(pathPid, streamValue.getPulseId(), index); - dm.setItem(pathTimestampStr, Chrono.getTimeStr(streamValue.getTimestamp(), "YYYY-MM-dd HH:mm:ss.SSS"), index); - - for (String id : streamValue.getIdentifiers()) { - Object val = streamValue.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - } else if (val.getClass().isArray()) { - dm.setItem(pathRoot + id, val, index); - } else { - dm.setItem(pathRoot + id, val, index); - } - } - } - getContext().getDataManager().closeOutput(); - } - - StandardDialog calibrationDialolg; - - void calibrate() throws Exception { - if (server != null) { - server.resetRoi(); - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraCalibrationDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), server.getCurrentCamera(), renderer}); - SwingUtils.centerComponent(getTopLevel(), calibrationDialolg); - calibrationDialolg.setVisible(true); - calibrationDialolg.setListener(new StandardDialogListener() { - @Override - public void onWindowOpened(StandardDialog dlg) { - } - - @Override - public void onWindowClosed(StandardDialog dlg, boolean accepted) { - if (accepted) { - //comboCamerasActionPerformed(null); - } - } - }); - } - } - - StandardDialog dataTableDialog; - DefaultTableModel dataTableModel; - - void showStreamData() { - dataTableModel = null; - if (server != null) { - - if ((dataTableDialog != null) && (dataTableDialog.isShowing())) { - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.requestFocus(); - return; - } - //String msg = String.join("\n", ids); - //SwingUtils.showMessage(getTopLevel(), "Image Data", msg); - dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) { - public Class getColumnClass(int columnIndex) { - return String.class; - } - - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - }; - updateStreamData(); - StreamValue val = server.getStream().take(); - JTable dataTable = new JTable(dataTableModel); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.setCellSelectionEnabled(true); - dataTable.getTableHeader().setReorderingAllowed(false); - dataTable.getTableHeader().setResizingAllowed(true); - dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); - dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(dataTable); - scrollPane.setPreferredSize(new Dimension(300, 400)); - dataTableDialog.setContentPane(scrollPane); - dataTableDialog.pack(); - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.setVisible(true); - dataTableDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - dataTableModel = null; - } - }); - } - } - - void updateStreamData() { - if ((dataTableModel != null) && (server != null)) { - StreamValue value = server.getValue(); - - List ids = (value == null) ? new ArrayList<>() : new ArrayList(value.getIdentifiers()); - if (ids.size() + 2 != dataTableModel.getRowCount()) { - dataTableModel.setNumRows(0); - try { - dataTableModel.addRow(new Object[]{"Locator", server.getUrl() + "/" + ((value == null) ? instanceName : server.getCurrentInstance())}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Locator", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"Stream", server.getStreamAddress()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Stream", ex.getMessage()}); - } - Collections.sort(ids); - for (String id : ids) { - dataTableModel.addRow(new Object[]{id, ""}); - } - } - for (int i = 2; i < dataTableModel.getRowCount(); i++) { - String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - Object obj = server.getValue(id); - if (obj != null) { - if (obj.getClass().isArray()) { - obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; - } else if (obj instanceof Double) { - obj = Convert.roundDouble((Double) obj, 1); - } else if (obj instanceof Float) { - obj = Convert.roundDouble((Float) obj, 1); - } - } - dataTableModel.setValueAt(String.valueOf(obj), i, 1); - } - } - } - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - buttonGroup4 = new javax.swing.ButtonGroup(); - jProgressBar1 = new javax.swing.JProgressBar(); - jPanel1 = new javax.swing.JPanel(); - jPanel7 = new javax.swing.JPanel(); - buttonMarker = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonFit = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonPause = new javax.swing.JToggleButton(); - buttonProfile = new javax.swing.JToggleButton(); - jPanel6 = new javax.swing.JPanel(); - textState = new javax.swing.JTextField(); - jLabel2 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - jLabel1 = new javax.swing.JLabel(); - buttonArgs = new javax.swing.JButton(); - buttonStop = new javax.swing.JButton(); - jLabel5 = new javax.swing.JLabel(); - textType = new javax.swing.JTextField(); - renderer = new ch.psi.pshell.imaging.Renderer(); - jPanel4 = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - buttonZoomFit = new javax.swing.JRadioButton(); - buttonZoomStretch = new javax.swing.JRadioButton(); - buttonZoomNormal = new javax.swing.JRadioButton(); - buttonZoom025 = new javax.swing.JRadioButton(); - buttonZoom05 = new javax.swing.JRadioButton(); - buttonZoom2 = new javax.swing.JRadioButton(); - jPanel2 = new javax.swing.JPanel(); - checkHistogram = new javax.swing.JCheckBox(); - comboColormap = new javax.swing.JComboBox(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - buttonFullRange = new javax.swing.JRadioButton(); - buttonManual = new javax.swing.JRadioButton(); - buttonAutomatic = new javax.swing.JRadioButton(); - labelMin = new javax.swing.JLabel(); - spinnerMin = new javax.swing.JSpinner(); - spinnerMax = new javax.swing.JSpinner(); - labelMax = new javax.swing.JLabel(); - btFixColormapRange = new javax.swing.JButton(); - jPanel5 = new javax.swing.JPanel(); - buttonServer = new javax.swing.JRadioButton(); - buttonDirect = new javax.swing.JRadioButton(); - panelScreen = new javax.swing.JPanel(); - valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); - comboScreen = new javax.swing.JComboBox(); - panelScreen1 = new javax.swing.JPanel(); - valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); - comboFilter = new javax.swing.JComboBox(); - pauseSelection = new ch.psi.pshell.swing.ValueSelection(); - panelScreen2 = new javax.swing.JPanel(); - checkThreshold = new javax.swing.JCheckBox(); - spinnerThreshold = new javax.swing.JSpinner(); - checkBackground = new javax.swing.JCheckBox(); - checkGoodRegion = new javax.swing.JCheckBox(); - spinnerGrScale = new javax.swing.JSpinner(); - spinnerGrThreshold = new javax.swing.JSpinner(); - labelGrThreshold = new javax.swing.JLabel(); - labelGrScale = new javax.swing.JLabel(); - panelSlicing = new javax.swing.JPanel(); - checkSlicing = new javax.swing.JCheckBox(); - labelSlScale = new javax.swing.JLabel(); - spinnerSlScale = new javax.swing.JSpinner(); - labelSlNumber = new javax.swing.JLabel(); - spinnerSlNumber = new javax.swing.JSpinner(); - labelSlOrientation = new javax.swing.JLabel(); - spinnerSlOrientation = new javax.swing.JSpinner(); - - setPreferredSize(new java.awt.Dimension(873, 600)); - - buttonMarker.setText("Marker"); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - - buttonGrabBackground.setText("Grab Background"); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - - buttonSave.setText("Save Snapshot"); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - - buttonFit.setSelected(true); - buttonFit.setText("Fit"); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - - buttonReticle.setSelected(true); - buttonReticle.setText("Reticle"); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - - buttonPause.setText("Pause"); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - - buttonProfile.setSelected(true); - buttonProfile.setText("Profile"); - buttonProfile.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonProfileActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); - jPanel7.setLayout(jPanel7Layout); - jPanel7Layout.setHorizontalGroup( - jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel7Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(buttonPause) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonMarker) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonProfile) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonFit) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonReticle) - .addGap(18, 18, Short.MAX_VALUE) - .addComponent(buttonGrabBackground) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonSave) - .addGap(0, 0, 0)) - ); - - jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonProfile, buttonReticle}); - - jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave}); - - jPanel7Layout.setVerticalGroup( - jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel7Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonPause) - .addComponent(buttonFit) - .addComponent(buttonMarker) - .addComponent(buttonSave) - .addComponent(buttonReticle) - .addComponent(buttonGrabBackground) - .addComponent(buttonProfile)) - .addGap(0, 0, 0)) - ); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - jLabel2.setText("State:"); - - comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboCameras.setMaximumRowCount(30); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - jLabel1.setText("Camera:"); - - buttonArgs.setText("Setup"); - buttonArgs.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonArgsActionPerformed(evt); - } - }); - - buttonStop.setText("Stop"); - buttonStop.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStopActionPerformed(evt); - } - }); - - jLabel5.setText("Type:"); - - textType.setEditable(false); - textType.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textType.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textType.setEnabled(false); - - javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); - jPanel6.setLayout(jPanel6Layout); - jPanel6Layout.setHorizontalGroup( - jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel6Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboCameras, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jLabel5) - .addGap(6, 6, 6) - .addComponent(textType, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(buttonArgs) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonStop) - .addGap(18, 18, 18) - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - - jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonArgs, buttonStop}); - - jPanel6Layout.setVerticalGroup( - jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel6Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel2) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonArgs) - .addComponent(buttonStop) - .addComponent(jLabel5) - .addComponent(textType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0)) - ); - - jPanel6Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState, textType}); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); - - buttonGroup1.add(buttonZoomFit); - buttonZoomFit.setText("Fit"); - buttonZoomFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomFitActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomStretch); - buttonZoomStretch.setText("Stretch"); - buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomStretchActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomNormal); - buttonZoomNormal.setText("Normal"); - buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomNormalActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("1/4"); - buttonZoom025.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom025ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("1/2"); - buttonZoom05.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom05ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom2); - buttonZoom2.setText("2"); - buttonZoom2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoomStretch)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05) - .addComponent(buttonZoom2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomFit) - .addComponent(buttonZoom05)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoom2)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap")); - - checkHistogram.setText("Histogram"); - checkHistogram.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkHistogramActionPerformed(evt); - } - }); - - comboColormap.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Type:"); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Range:"); - - buttonGroup3.add(buttonFullRange); - buttonFullRange.setText("Full"); - buttonFullRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonManual); - buttonManual.setText("Manual"); - buttonManual.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonAutomatic); - buttonAutomatic.setText("Automatic"); - buttonAutomatic.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - labelMin.setText("Min:"); - - spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); - spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); - spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - labelMax.setText("Max:"); - - btFixColormapRange.setText("Fix"); - btFixColormapRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btFixColormapRangeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonAutomatic) - .addComponent(buttonFullRange) - .addComponent(buttonManual) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMax) - .addGap(2, 2, 2) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMin) - .addGap(2, 2, 2) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(spinnerMin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFixColormapRange, spinnerMax, spinnerMin}); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3) - .addComponent(checkHistogram)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAutomatic) - .addComponent(jLabel4) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelMin) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonFullRange)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonManual) - .addComponent(labelMax) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - - buttonGroup4.add(buttonServer); - buttonServer.setSelected(true); - buttonServer.setText("Server"); - buttonServer.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonServerActionPerformed(evt); - } - }); - - buttonGroup4.add(buttonDirect); - buttonDirect.setText("Direct"); - buttonDirect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDirectActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonServer) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonDirect) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonServer) - .addComponent(buttonDirect)) - .addContainerGap()) - ); - - panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); - - comboScreen.setEnabled(false); - comboScreen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboScreenActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); - panelScreen.setLayout(panelScreenLayout); - panelScreenLayout.setHorizontalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreenLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreenLayout.setVerticalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelScreen1.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); - - comboFilter.setEnabled(false); - comboFilter.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboFilterActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreen1Layout = new javax.swing.GroupLayout(panelScreen1); - panelScreen1.setLayout(panelScreen1Layout); - panelScreen1Layout.setHorizontalGroup( - panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreen1Layout.setVerticalGroup( - panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen1Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pauseSelection.setDecimals(0); - - panelScreen2.setBorder(javax.swing.BorderFactory.createTitledBorder("Pipeline")); - - checkThreshold.setText("Threshold"); - checkThreshold.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkThresholdActionPerformed(evt); - } - }); - - spinnerThreshold.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 99999.0d, 1.0d)); - spinnerThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerThresholdonChange(evt); - } - }); - - checkBackground.setText("Subtract Background"); - checkBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkBackgroundActionPerformed(evt); - } - }); - - checkGoodRegion.setText("Good Region"); - checkGoodRegion.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkGoodRegionActionPerformed(evt); - } - }); - - spinnerGrScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerGrScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - spinnerGrThreshold.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.04d, 1.0d, 0.1d)); - spinnerGrThreshold.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerGrThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - labelGrThreshold.setText("Threshold:"); - - labelGrScale.setText("Scale:"); - - checkSlicing.setText("Slicing"); - checkSlicing.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkSlicingActionPerformed(evt); - } - }); - - labelSlScale.setText("Scale:"); - - spinnerSlScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerSlScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlNumber.setText("Slices:"); - - spinnerSlNumber.setModel(new javax.swing.SpinnerNumberModel(2, 0, 1000, 1)); - spinnerSlNumber.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlNumber.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlOrientation.setText("Orientation:"); - - spinnerSlOrientation.setModel(new javax.swing.SpinnerListModel(new String[] {"vertical", "horizontal"})); - spinnerSlOrientation.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlOrientation.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - javax.swing.GroupLayout panelSlicingLayout = new javax.swing.GroupLayout(panelSlicing); - panelSlicing.setLayout(panelSlicingLayout); - panelSlicingLayout.setHorizontalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addComponent(checkSlicing) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlNumber) - .addGap(2, 2, 2) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlScale) - .addGap(2, 2, 2) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelSlOrientation) - .addGap(2, 2, 2) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - panelSlicingLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerSlNumber, spinnerSlOrientation, spinnerSlScale}); - - panelSlicingLayout.setVerticalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(checkSlicing) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlNumber)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlScale)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlOrientation))) - ); - - javax.swing.GroupLayout panelScreen2Layout = new javax.swing.GroupLayout(panelScreen2); - panelScreen2.setLayout(panelScreen2Layout); - panelScreen2Layout.setHorizontalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkThreshold) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addComponent(checkGoodRegion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(labelGrScale)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelGrThreshold))) - .addGap(2, 2, 2))) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - .addComponent(panelSlicing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addGap(6, 6, 6) - .addComponent(checkBackground) - .addGap(106, 106, 106)) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerThreshold}); - - panelScreen2Layout.setVerticalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(checkBackground) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkThreshold) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkGoodRegion) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrScale)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrThreshold)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelSlicing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); - jPanel4.setLayout(jPanel4Layout); - jPanel4Layout.setHorizontalGroup( - jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel4Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel4Layout.setVerticalGroup( - jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel4Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - }// //GEN-END:initComponents - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - if (!updatingCameraSelection) { - if (!comboCameras.isEnabled()) { - throw new Exception("Invalid state"); - } - comboCameras.setEnabled(false); - buttonServer.setEnabled(false); - buttonDirect.setEnabled(false); - final String cameraName = (String) comboCameras.getSelectedItem(); - new Thread(new Runnable() { - @Override - public void run() { - if (requestCameraListUpdate) { - requestCameraListUpdate = false; - try { - updateCameraList(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - try { - setCamera(cameraName); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateStop(); - comboCameras.setEnabled(true); - buttonServer.setEnabled(true); - buttonDirect.setEnabled(true); - } - } - }).start(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonArgsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonArgsActionPerformed - try { - if (camera != null) { - String cameraConfigJson = null; - if (usingServer) { - String cameraServerUrl = (camServerUrl==null) ? server.getUrl().substring(0, server.getUrl().length() - 1) + "8": camServerUrl; - try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)) { - srv.initialize(); - //TODO: replace into encodeMultiline - cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true); - } - - } else { - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - } - TextEditor editor = new TextEditor(); - editor.setText(cameraConfigJson); - editor.setReadOnly(true); - editor.setTitle(cameraName); - EditorDialog dlg = editor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(getTopLevel(), dlg); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonArgsActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - renderer.removeOverlay(imageBufferOverlay); - if (camera != null) { - synchronized (imageBuffer) { - if (buttonPause.isSelected()) { - renderer.pause(); - } else { - imageBuffer.clear(); - renderer.resume(); - } - pauseSelection.setVisible(buttonPause.isSelected() && (imageBuffer.size() > 1)); - if (pauseSelection.isVisible()) { - renderer.addOverlay(imageBufferOverlay); - pauseSelection.setMaxValue(imageBuffer.size()); - pauseSelection.setValue(imageBuffer.size());; - } - } - updateStreamData(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - checkMarker(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - showFit = buttonFit.isSelected(); - if (showFit) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - saveSnapshot(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera != null) { - boolean laserOn = getLaserState(); - OptionResult ret = null; - if (laserOn) { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put laser on delay for capturing background?", OptionType.YesNoCancel); - if (ret == OptionResult.No) { - laserOn = false; - } - } else { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to capture background now?", OptionType.OkCancel); - } - - if (ret == OptionResult.Cancel) { - return; - } - - if (laserOn) { - setLaserState(false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - if (server != null) { - server.captureBackground(5); - } else { - camera.captureBackground(5, 0); - } - } finally { - if (laserOn) { - setLaserState(true); - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed - try { - renderer.setMode(RendererMode.Fit); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomFitActionPerformed - - private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed - try { - renderer.setMode(RendererMode.Stretch); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomStretchActionPerformed - - private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed - try { - renderer.setMode(RendererMode.Fixed); - centralizeRenderer(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomNormalActionPerformed - - private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap - try { - if ((camera != null) && (camera instanceof ColormapSource) && !updatingColormap) { - ColormapSource source = (ColormapSource) camera; - Color colorReticule = new Color(16, 16, 16); - Color colorMarker = new Color(128, 128, 128); - source.getConfig().colormap = (Colormap) comboColormap.getSelectedItem(); - switch (source.getConfig().colormap) { - case Grayscale: - case Inverted: - case Red: - case Green: - case Blue: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - case Flame: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - } - - renderer.setPenReticle(new Pen(colorReticule)); - renderer.setPenProfile(new Pen(colorReticule, 0)); - renderer.setPenMarker(new Pen(colorMarker, 2)); - renderer.setShowReticle(false); - checkReticle(); - source.getConfig().colormapAutomatic = buttonAutomatic.isSelected(); - source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); - source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); - try { - source.getConfig().save(); - } catch (Exception ex) { - Logger.getLogger(ScreenPanel.class.getName()).log(Level.WARNING, null, ex); - } - source.refresh(); - if (buttonPause.isSelected()) { - updatePause(); - } - updateColormap(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_onChangeColormap - - private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange - onChangeColormap(null); - }//GEN-LAST:event_onChangeColormapRange - - private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed - renderer.setZoom(0.25); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom025ActionPerformed - - private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed - renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom05ActionPerformed - - private void buttonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonServerActionPerformed - if (!usingServer) { - usingServer = true; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonServerActionPerformed - - private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingServer) { - usingServer = false; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonDirectActionPerformed - - private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed - - comboScreen.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - ChannelInteger setpoint = null; - try { - int index = comboScreen.getSelectedIndex(); - if (cameraName.contains("DSRM")) { - setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); - } else { - setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); - } - setpoint.initialize(); - if (setpoint.read() != index) { - setpoint.write(index); - //Must be threaded to control the laser because of sleep in setLaserState - /* - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - setpoint.write(index); - } finally { - if (laserOn) { - setLaserState(true); - } - } - */ - } - screen.read(); - } catch (Exception ex) { - showException(ex); - } finally { - comboScreen.setEnabled(true); - if (setpoint != null) { - setpoint.close(); - } - } - } - }).start(); - }//GEN-LAST:event_comboScreenActionPerformed - - private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed - try { - String setpoint = (String) comboFilter.getSelectedItem(); - if (!setpoint.equals(filter.read())) { - filter.write(setpoint); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboFilterActionPerformed - - private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed - try { - setHistogramVisible(checkHistogram.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_checkHistogramActionPerformed - - private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed - renderer.setZoom(2.0); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom2ActionPerformed - - private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setThreshold((Double) spinnerThreshold.getValue()); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_spinnerThresholdonChange - - private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (server != null) { - if (!updatingServerControls) { - try { - if (server.isStarted()) { - server.setBackgroundSubtraction(checkBackground.isSelected()); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - updatingServerControls = true; - checkBackground.setSelected(false); - updatingServerControls = false; - - } - } - } else { - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - }//GEN-LAST:event_checkBackgroundActionPerformed - - private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - spinnerThreshold.setVisible(checkThreshold.isSelected()); - server.setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_checkThresholdActionPerformed - - private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed - try { - if (buttonStop.getText().equals("Stop")) { - if ((camera != null) && !camera.isClosed()) { - camera.close(); - } - } else { - if (isCameraStopped()) { - comboCamerasActionPerformed(null); - } - } - } catch (Exception ex) { - showException(ex); - } finally { - updateStop(); - } - }//GEN-LAST:event_buttonStopActionPerformed - - private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed - try { - showProfile = buttonProfile.isSelected(); - if (showProfile) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(profileOv); - profileOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonProfileActionPerformed - - private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - goodRegion = checkGoodRegion.isSelected(); - setGoodRegionOptionsVisible(goodRegion); - if (goodRegion) { - server.setGoodRegion(((Number) spinnerGrThreshold.getValue()).doubleValue(), ((Number) spinnerGrScale.getValue()).doubleValue()); - } else { - server.setGoodRegion(null); - } - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_checkGoodRegionActionPerformed - - private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setGoodRegion((Double) spinnerGrThreshold.getValue(), (Double) spinnerGrScale.getValue()); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_spinnerGrThresholdonChange - - private void btFixColormapRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFixColormapRangeActionPerformed - try { - updatingColormap = true; - ArrayProperties properties = currentFrame.data.getProperties(); - spinnerMax.setValue(properties.max.intValue()); - spinnerMin.setValue(properties.min.intValue()); - buttonManual.setSelected(true); - } catch (Exception ex) { - showException(ex); - } finally { - updatingColormap = false; - onChangeColormap(null); - } - }//GEN-LAST:event_btFixColormapRangeActionPerformed - - private void checkSlicingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSlicingActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - slicing = checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - if (slicing) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } else { - server.setSlicing(null); - } - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_checkSlicingActionPerformed - - private void spinnerSlicingChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerSlicingChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_spinnerSlicingChange - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btFixColormapRange; - private javax.swing.JButton buttonArgs; - private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonDirect; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JRadioButton buttonFullRange; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JRadioButton buttonManual; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonProfile; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JRadioButton buttonServer; - private javax.swing.JButton buttonStop; - private javax.swing.JRadioButton buttonZoom025; - private javax.swing.JRadioButton buttonZoom05; - private javax.swing.JRadioButton buttonZoom2; - private javax.swing.JRadioButton buttonZoomFit; - private javax.swing.JRadioButton buttonZoomNormal; - private javax.swing.JRadioButton buttonZoomStretch; - private javax.swing.JCheckBox checkBackground; - private javax.swing.JCheckBox checkGoodRegion; - private javax.swing.JCheckBox checkHistogram; - private javax.swing.JCheckBox checkSlicing; - private javax.swing.JCheckBox checkThreshold; - private javax.swing.JComboBox comboCameras; - private javax.swing.JComboBox comboColormap; - private javax.swing.JComboBox comboFilter; - private javax.swing.JComboBox comboScreen; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel4; - private javax.swing.JPanel jPanel5; - private javax.swing.JPanel jPanel6; - private javax.swing.JPanel jPanel7; - private javax.swing.JProgressBar jProgressBar1; - private javax.swing.JLabel labelGrScale; - private javax.swing.JLabel labelGrThreshold; - private javax.swing.JLabel labelMax; - private javax.swing.JLabel labelMin; - private javax.swing.JLabel labelSlNumber; - private javax.swing.JLabel labelSlOrientation; - private javax.swing.JLabel labelSlScale; - private javax.swing.JPanel panelScreen; - private javax.swing.JPanel panelScreen1; - private javax.swing.JPanel panelScreen2; - private javax.swing.JPanel panelSlicing; - private ch.psi.pshell.swing.ValueSelection pauseSelection; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JSpinner spinnerGrScale; - private javax.swing.JSpinner spinnerGrThreshold; - private javax.swing.JSpinner spinnerMax; - private javax.swing.JSpinner spinnerMin; - private javax.swing.JSpinner spinnerSlNumber; - private javax.swing.JSpinner spinnerSlOrientation; - private javax.swing.JSpinner spinnerSlScale; - private javax.swing.JSpinner spinnerThreshold; - private javax.swing.JTextField textState; - private javax.swing.JTextField textType; - private ch.psi.pshell.swing.DeviceValuePanel valueFilter; - private ch.psi.pshell.swing.DeviceValuePanel valueScreen; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/ScreenPanel2.form b/plugins/ScreenPanel2.form deleted file mode 100755 index c08702e..0000000 --- a/plugins/ScreenPanel2.form +++ /dev/null @@ -1,1163 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/ScreenPanel2.java b/plugins/ScreenPanel2.java deleted file mode 100755 index fe8c921..0000000 --- a/plugins/ScreenPanel2.java +++ /dev/null @@ -1,3658 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.bs.CameraServer; -import ch.psi.pshell.core.Context; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.PipelineServer; -import ch.psi.pshell.bs.StreamValue; -import ch.psi.pshell.core.JsonSerializer; -import ch.psi.pshell.data.DataManager; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.device.Readable.ReadableArray; -import ch.psi.pshell.device.Readable.ReadableNumber; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterArray; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterNumber; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.DiscretePositioner; -import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.imaging.Colormap; -import ch.psi.pshell.imaging.ColormapSource; -import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.DimensionDouble; -import ch.psi.pshell.imaging.Histogram; -import ch.psi.pshell.imaging.ImageBuffer; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.PointDouble; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.pshell.swing.DeviceValueChart; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Convert; -import ch.psi.utils.Str; -import ch.psi.utils.swing.Editor.EditorDialog; -import ch.psi.utils.swing.MainFrame; -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.StandardDialog.StandardDialogListener; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.lang.reflect.Array; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.table.DefaultTableModel; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.PolynomialCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; - -/** - * - */ -public class ScreenPanel2 extends Panel { - - public static final String LASER_TYPE = "Laser"; - public static final String ELECTRONS_TYPE = "Electrons"; - public static final String PHOTONICS_TYPE = "Photonics"; - - final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useServerStats = true; - String userOverlaysConfigFile; - ColormapSource camera; - PipelineServer server; - String cameraName; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - boolean showProfile; - Overlay[] userOv; - Overlay[] fitOv; - Overlay[] profileOv; - Overlay errorOverlay; - boolean requestCameraListUpdate; - boolean goodRegion; - boolean slicing; - String serverUrl; - String camServerUrl; - String instanceName; - Overlay titleOv = null; - - String pipelineSuffix = "_sp"; - - Double getServerDouble(String name) { - return (Double) Convert.toDouble(server.getValue(name)); - } - - double[] getServerDoubleArray(String name) { - return (double[]) Convert.toDouble(server.getValue(name)); - } - - Double getServerDouble(String name, StreamValue cache) { - return (Double) Convert.toDouble(cache.__getitem__(name)); - } - - double[] getServerDoubleArray(String name, StreamValue cache) { - return (double[]) Convert.toDouble(cache.__getitem__(name)); - } - - class ImageData { - - ImageData() { - if (server != null) { - cache = server.getStream().take(); - String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getServerDouble(prefix + "x_fit_mean", cache); - y_fit_mean = getServerDouble(prefix + "y_fit_mean", cache); - x_fit_standard_deviation = getServerDouble(prefix + "x_fit_standard_deviation", cache); - y_fit_standard_deviation = getServerDouble(prefix + "y_fit_standard_deviation", cache); - x_fit_gauss_function = getServerDoubleArray(prefix + "x_fit_gauss_function", cache); - y_fit_gauss_function = getServerDoubleArray(prefix + "y_fit_gauss_function", cache); - x_profile = getServerDoubleArray("x_profile", cache); - y_profile = getServerDoubleArray("y_profile", cache); - x_center_of_mass = getServerDouble("x_center_of_mass", cache); - y_center_of_mass = getServerDouble("y_center_of_mass", cache); - x_rms = getServerDouble("x_rms", cache); - y_rms = getServerDouble("y_rms", cache); - if (goodRegion) { - double[] gX2 = new double[x_profile.length]; - Arrays.fill(gX2, Double.NaN); - try { - double x = getServerDoubleArray("gr_x_axis", cache)[0]; - gr_size_x = x_fit_gauss_function.length; - gr_pos_x = (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x) : x); - System.arraycopy(x_fit_gauss_function, 0, gX2, gr_pos_x , gr_size_x); - } catch (Exception ex) { - } - x_fit_gauss_function = gX2; - double[] gY2 = new double[y_profile.length]; - Arrays.fill(gY2, Double.NaN); - try { - double y = getServerDoubleArray("gr_y_axis", cache)[0]; - gr_size_y = y_fit_gauss_function.length; - gr_pos_y = (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageY(y) : y); - System.arraycopy(y_fit_gauss_function, 0, gY2, gr_pos_y, y_fit_gauss_function.length); - } catch (Exception ex) { - } - y_fit_gauss_function = gY2; - if (slicing) { - try { - int slices = getServerDouble("slice_amount").intValue(); - sliceCenters = new PointDouble[slices]; - for (int i = 0; i < slices; i++) { - double x = getServerDouble("slice_" + i + "_center_x"); - double y = getServerDouble("slice_" + i + "_center_y"); - sliceCenters[i] = new PointDouble(x, y); - } - } catch (Exception ex) { - } - } - } - } - } - public Double x_fit_mean; - public Double y_fit_mean; - public Double x_center_of_mass; - public Double x_rms; - public Double x_fit_standard_deviation; - public Double y_fit_standard_deviation; - public Double y_center_of_mass; - public Double y_rms; - public double[] x_profile; - public double[] x_fit_gauss_function; - public double[] y_profile; - public double[] y_fit_gauss_function; - public int gr_size_x; - public int gr_pos_x; - public int gr_size_y; - public int gr_pos_y; - public PointDouble[] sliceCenters; - public StreamValue cache; - } - - class Frame extends ImageData { - - Frame(Data data) { - this.data = data; - } - Data data; - } - - final ArrayList imageBuffer = new ArrayList(); - Frame currentFrame; - int imageBufferLenght = 1; - Text imageBufferOverlay; - - public ScreenPanel2() { - try { - initComponents(); - spinnerThreshold.setVisible(false); - btFixColormapRange.setVisible(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - JComponent editor = spinnerSlOrientation.getEditor(); - if (editor instanceof JSpinner.DefaultEditor) { - ((JSpinner.DefaultEditor) editor).getTextField().setHorizontalAlignment(JTextField.RIGHT); - } - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - //setPersistedComponents(new Component[]{buttonServer, buttonDirect}); - comboCameras.setEnabled(false); - comboType.setEnabled(false); - - SwingUtils.setEnumCombo(comboColormap, Colormap.class); - if (App.hasArgument("poll")) { - try { - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try { - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("buf")) { - try { - imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("usr_ov")) { - try { - userOverlaysConfigFile = App.getArgumentValue("usr_ov"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_url")) { - serverUrl = App.getArgumentValue("srv_url"); - } - - if (App.hasArgument("cam_srv_url")) { - camServerUrl = App.getArgumentValue("cam_srv_url"); - } - - if (App.hasArgument("calc")) { - useServerStats = false; - } - if (App.hasArgument("suffix")) { - pipelineSuffix = App.getArgumentValue("suffix"); - } - - renderer.setProfileNormalized(true); - renderer.setShowProfileLimits(false); - - JMenuItem menuCalibrate = new JMenuItem("Calibrate..."); - menuCalibrate.addActionListener((ActionEvent e) -> { - try { - calibrate(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuRendererConfig = new JMenuItem("Renderer Parameters"); - menuRendererConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuCameraConfig = new JMenuItem("Camera Configurarion"); - menuCameraConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - String cameraConfigJson = null; - if (usingServer) { - String cameraServerUrl = (camServerUrl == null) ? server.getUrl().substring(0, server.getUrl().length() - 1) + "8" : camServerUrl; - try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)) { - srv.initialize(); - //TODO: replace into encodeMultiline - cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true); - } - - } else { - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - } - TextEditor configEditor = new TextEditor(); - configEditor.setText(cameraConfigJson); - configEditor.setReadOnly(true); - configEditor.setTitle(cameraName); - EditorDialog dlg = configEditor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(getTopLevel(), dlg); - } - } catch (Exception ex) { - showException(ex); - } - }); - - - - JMenuItem menuSetImageBufferSize = new JMenuItem("Set Stack Size..."); - menuSetImageBufferSize.addActionListener((ActionEvent e) -> { - try { - String ret = SwingUtils.getString(getTopLevel(), "Enter size of image buffer: ", String.valueOf(imageBufferLenght)); - if (ret!=null){ - this.setImageBufferSize(Integer.valueOf(ret)); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSaveStack = new JMenuItem("Save Stack"); - menuSaveStack.addActionListener((ActionEvent e) -> { - try { - saveStack(); - } catch (Exception ex) { - showException(ex); - } - }); - - - JMenuItem menuSetROI = new JMenuItem("Set ROI..."); - menuSetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); - renderer.addListener(new RendererListener() { - @Override - public void onSelectionFinished(Renderer renderer, Overlay overlay) { - try { - renderer.setShowReticle(false); - Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (server.isRoiEnabled()) { - int[] cur = server.getRoi(); - server.setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); - } else { - server.setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); - } - } catch (Exception ex) { - } finally { - renderer.removeListener(this); - } - } - - @Override - public void onSelectionAborted(Renderer renderer, Overlay overlay) { - renderer.removeListener(this); - } - }); - selection.setFixed(true); - renderer.startSelection(selection); - } - }); - - JMenuItem menuResetROI = new JMenuItem("Reset ROI"); - menuResetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - try { - renderer.setShowReticle(false); - server.resetRoi(); - } catch (IOException ex) { - showException(ex); - } - } - }); - - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuRendererConfig); - renderer.getPopupMenu().add(menuCameraConfig); - renderer.getPopupMenu().add(menuSetImageBufferSize); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuCalibrate); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuSetROI); - renderer.getPopupMenu().add(menuResetROI); - renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(server != null); - menuSetROI.setEnabled(server != null); - menuCalibrate.setVisible(server != null); - menuCalibrate.setEnabled((calibrationDialolg == null) || (!calibrationDialolg.isShowing())); - menuSaveStack.setEnabled(imageBufferLenght > 0); - menuSetImageBufferSize.setEnabled(!renderer.isPaused()); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - } - }); - renderer.getPopupMenu().setVisible(false); - - showFit = buttonFit.isSelected(); - showProfile = buttonProfile.isSelected(); - - pauseSelection.setVisible(false); - pauseSelection.setMinValue(1); - pauseSelection.addListener(new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - if (editing && (value >= 1) && (value <= imageBuffer.size())) { - updatePause(); - } - } - }); - imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 42)); - imageBufferOverlay.setFixed(true); - imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - if (MainFrame.isDark()) { - textState.setDisabledTextColor(textState.getForeground()); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - @Override - public void onStart() { - super.onStart(); - if (App.hasArgument("ct")) { - boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonServer.setSelected(!direct); - buttonDirect.setSelected(direct); - } - } - - @Override - public void onStop() { - try { - if (camera != null) { - camera.close(); - camera = null; - server = null; - updateButtons(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - super.onStop(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - comboType.setEnabled(false); - if (App.hasArgument("s")) { - renderer.setDevice((Source) getDevice("image")); - renderer.setAutoScroll(true); - ((Source) getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - manageFit(bi, data); - manageUserOverlays(bi, data); - } - - @Override - public void onError(Object o, Exception ex) { - } - } - ); - - } else { - usingServer = buttonServer.isSelected(); - updateCameraList(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - setComboCameraSelection(-1); - setComboTypeSelection(0); - - if (comboCameras.getModel().getSize() > 0) { - try { - if (App.hasArgument("cam")) { - setComboCameraSelection(App.getArgumentValue("cam")); - comboCamerasActionPerformed(null); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - updateButtons(); - startTimer(1000); - } - - boolean isVisible(String camera) { - return ((comboType.getSelectedIndex() == 0) || (getCameraType(camera).equals(comboType.getSelectedItem()))); - } - - DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - if (fromServer) { - try (PipelineServer srv = newServer()) { - srv.initialize(); - List cameras = srv.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - - } else { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - if (App.hasArgument("cam")) { - String camera = App.getArgumentValue("cam"); - if (model.getIndexOf(camera) < 0) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - model.addElement(""); - - return model; - } - - PipelineServer newServer() throws IOException { - if (serverUrl != null) { - System.out.println("Connecting to server: " + serverUrl); - server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl); - } else { - System.out.println("Connecting to server"); - server = new PipelineServer(CAMERA_DEVICE_NAME); - } - updateButtons(); - return server; - } - - boolean updatingCameraSelection; - - void setComboCameraSelection(Object selection) { - updatingCameraSelection = true; - try { - comboCameras.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - - void setComboTypeSelection(Object selection) { - updatingCameraSelection = true; - try { - comboType.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - boolean usingServer; - - void updateCameraList() { - try { - String selected = (String) comboCameras.getSelectedItem(); - comboCameras.setModel(getCameraList(usingServer)); - if (selected != null) { - if (((DefaultComboBoxModel) comboCameras.getModel()).getIndexOf(camera) < 0) { - setComboCameraSelection(selected); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - } - - final Object lockOverlays = new Object(); - - void manageFit(BufferedImage bi, Data data) { - Overlay[][] fo = null; - if ((showFit || showProfile)) { - try { - fo = getFitOverlays(data); - } catch (Exception ex) { - System.err.println(ex); - } - } - synchronized (lockOverlays) { - fo = (fo == null) ? new Overlay[][]{null, null} : fo; - renderer.updateOverlays(fo[0], profileOv); - profileOv = fo[0]; - renderer.updateOverlays(fo[1], fitOv); - fitOv = fo[1]; - } - } - - void manageUserOverlays(BufferedImage bi, Data data) { - Overlay[] fo = (bi == null) ? null : getUserOverlays(data); - synchronized (lockOverlays) { - renderer.updateOverlays(fo, userOv); - userOv = fo; - } - } - - void manageTitleOverlay() { - Overlay to = null; - if ((buttonTitle.isSelected()) && (cameraName != null)) { - Font font = new Font("Arial", Font.PLAIN, 28); - to = new Text(renderer.getPenErrorText(), cameraName, font, new Point(-SwingUtils.getTextSize(cameraName, renderer.getGraphics().getFontMetrics(font)).width - 14, 26)); - to.setFixed(true); - to.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - } - - synchronized (lockOverlays) { - renderer.updateOverlays(to, titleOv); - titleOv = to; - } - } - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - Thread devicesInitTask; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Initializing"); - parseUserOverlays(); - errorOverlay = null; - - if (dataTableDialog != null) { - dataTableDialog.dispose(); - dataTableDialog = null; - } - dataTableModel = null; - - if (calibrationDialolg != null) { - calibrationDialolg.dispose(); - calibrationDialolg = null; - } - - boolean was_server = false; - if (camera != null) { - //camera.removeAllListeners(); - was_server = (server != null); - camera.close(); - camera = null; - server = null; - } - updateButtons(); - instanceName = null; - renderer.setDevice(null); - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.removeOverlays(profileOv); - renderer.removeOverlays(userOv); - renderer.clear(); - renderer.resetZoom(); - - boolean changed = !String.valueOf(cameraName).equals(this.cameraName); - this.cameraName = cameraName; - - if (changed || buttonDirect.isSelected()) { - spinnerThreshold.setVisible(false); - checkThreshold.setEnabled(false); - checkGoodRegion.setEnabled(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - if (changed) { - checkBackground.setEnabled(false); - if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { - devicesInitTask.interrupt(); - } - if (screen != null) { - screen.close(); - screen = null; - } - if (filter != null) { - filter.close(); - filter = null; - } - if (renderer.isPaused()) { - renderer.resume(); - renderer.removeOverlay(imageBufferOverlay); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - manageTitleOverlay(); - if (App.isDetached()) { - getTopLevel().setTitle(cameraName == null ? "ScreenPanel" : cameraName); - } - if (cameraName == null) { - return; - } - - System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]"); - try { - if (buttonServer.isSelected()) { - camera = newServer(); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - //camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName); - camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName}); - } - camera.initialize(); - camera.assertInitialized(); - System.out.println("Camera initialization OK"); - if (server != null) { - //server.start(cameraName, false); - String pipelineName = cameraName + pipelineSuffix; - instanceName = cameraName + pipelineSuffix +"1"; - if (!server.getPipelines().contains(pipelineName)) { - System.out.println("Creating pipeline: " + pipelineName); - HashMap config = new HashMap<>(); - config.put("camera_name", cameraName); - //server.createFromConfig(config, pipelineName); - server.savePipelineConfig(pipelineName, config); - } - server.start(pipelineName, instanceName); - - updateServerControls(); - checkThreshold.setEnabled(true); - checkGoodRegion.setEnabled(true); - } else { - checkThreshold.setSelected(false); - checkGoodRegion.setSelected(false); - if (polling <= 0) { - camera.setMonitored(true); - } else { - camera.setPolling(polling); - } - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - updateButtons(); - camera.getConfig().save(); - renderer.setDevice(camera); - renderer.setAutoScroll(true); - renderer.setMarker(marker); - imageSize = null; - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi != null) { - if ((imageSize == null) || imageSize.width != bi.getWidth() || imageSize.height != bi.getHeight()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { - centralizeRenderer(); - } - checkReticle(); - } - }); - imageSize = new Dimension(bi.getWidth(), bi.getHeight()); - } - renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); - } - //renderer.setCalibration(camera.getCalibration()); - if (!renderer.isPaused()) { - if (data != null) { - synchronized (imageBuffer) { - currentFrame = new Frame(data); - if (imageBufferLenght >= 1) { - imageBuffer.add(currentFrame); - if (imageBuffer.size() > imageBufferLenght) { - imageBuffer.remove(0); - } - } - } - } - manageFit(bi, data); - manageUserOverlays(bi, data); - } - //updateImageData(); - } - - @Override - public void onError(Object o, Exception ex) { - //System.err.println(ex); - } - }); - - } catch (Exception ex) { - showException(ex); - renderer.clearOverlays(); - updateServerControls(); - if (renderer.getDevice() == null) { - //renderer.setZoom(1.0); - //renderer.setMode(RendererMode.Zoom); - errorOverlay = new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - errorOverlay.setFixed(true); - errorOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - renderer.addOverlay(errorOverlay); - } - } finally { - //checkReticle(); - onTimer(); - } - onChangeColormap(null); - checkBackground.setEnabled(true); - if (changed) { - boolean electrons = getCameraType(cameraName).equals(ELECTRONS_TYPE); - comboScreen.setModel(new DefaultComboBoxModel()); - comboScreen.setEnabled(false); - comboFilter.setModel(new DefaultComboBoxModel()); - comboFilter.setEnabled(false); - panelFilter.setVisible(electrons); - panelScreen.setVisible(electrons); - if (electrons) { - //Parallelizing initialization - devicesInitTask = new Thread(() -> { - try { - if (cameraName.contains("DSRM")) { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); - } else { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); - } - screen.setMonitored(true); - screen.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : screen.getPositions()) { - model.addElement(pos); - } - comboScreen.setModel(model); - comboScreen.setSelectedItem(screen.read()); - - } catch (Exception ex) { - comboScreen.setModel(new DefaultComboBoxModel()); - System.err.println(ex.getMessage()); - screen = null; - } - comboScreen.setEnabled(screen != null); - valueScreen.setDevice(screen); - - try { - filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); - filter.setMonitored(true); - filter.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : filter.getPositions()) { - model.addElement(pos); - } - comboFilter.setModel(model); - comboFilter.setSelectedItem(filter.read()); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - filter = null; - } - comboFilter.setEnabled(filter != null); - valueFilter.setDevice(filter); - }); - devicesInitTask.start(); - } - } - } - - volatile Dimension imageSize; - - void checkReticle() { - if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) { - //renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800, 800), 200); - renderer.setShowReticle(true); - } else { - //renderer.setCalibration(null); - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - void checkMarker() { - if (camera != null) { - if (buttonMarker.isSelected()) { - Dimension d = renderer.getImageSize(); - Point p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - marker.setPassive(false); - } else { - marker = null; - } - renderer.setMarker(marker); - } - } - - void updateZoom() { - try { - buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom) { - if (renderer.getZoom() == 1) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getZoom() == 0.5) { - buttonZoom05.setSelected(true); - } else if (renderer.getZoom() == 0.25) { - buttonZoom025.setSelected(true); - } else if (renderer.getZoom() == 2.0) { - buttonZoom2.setSelected(true); - } else { - buttonGroup1.clearSelection(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - boolean updatingColormap; - - void updateColormap() { - updatingColormap = true; - try { - if ((camera != null) && (camera instanceof ColormapSource)) { - ColormapSourceConfig config = ((ColormapSource) camera).getConfig(); - comboColormap.setSelectedItem(config.colormap); - if (config.isDefaultColormap()) { - buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic) { - buttonAutomatic.setSelected(true); - } else { - buttonManual.setSelected(true); - } - btFixColormapRange.setVisible(buttonAutomatic.isSelected()); - - //spinnerMin.setVisible(buttonManual.isSelected()); labelMin.setVisible(spinnerMin.isVisible()); - //spinnerMax.setVisible(buttonManual.isSelected()); labelMax.setVisible(spinnerMax.isVisible()); - spinnerMin.setEnabled(buttonManual.isSelected()); - spinnerMax.setEnabled(buttonManual.isSelected()); - //spinnerMin.setValue(Double.isNaN(config.colormapMin) ? 0 : Math.min(Math.max((int) config.colormapMin, 0), 65535)); - //spinnerMax.setValue(Double.isNaN(config.colormapMax) ? 0 : Math.min(Math.max((int) config.colormapMax, 0), 65535)); - if (!Double.isNaN(config.colormapMin)) { - spinnerMin.setValue(Math.min(Math.max((int) config.colormapMin, 0), 65535)); - } - if (!Double.isNaN(config.colormapMax)) { - spinnerMax.setValue(Math.min(Math.max((int) config.colormapMax, 0), 65535)); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatingColormap = false; - } - - boolean updatingServerControls; - - void updateServerControls() { - if (server != null) { - updatingServerControls = true; - try { - checkBackground.setSelected(server.getBackgroundSubtraction()); - Double threshold = (server.getThreshold()); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (server.getGoodRegion()); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - spinnerGrThreshold.setValue(((Number) gr.get("threshold")).doubleValue()); - spinnerGrScale.setValue(((Number) gr.get("gfscale")).doubleValue()); - } - Map slicing = (server.getSlicing()); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - spinnerSlNumber.setValue(((Number) slicing.get("number_of_slices")).intValue()); - spinnerSlScale.setValue(((Number) slicing.get("scale")).doubleValue()); - spinnerSlOrientation.setValue((String) slicing.get("orientation")); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - goodRegion = checkGoodRegion.isSelected(); - spinnerThreshold.setVisible(checkThreshold.isSelected()); - setGoodRegionOptionsVisible(goodRegion); - slicing = goodRegion && checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - updatingServerControls = false; - } - } - - void setGoodRegionOptionsVisible(boolean visible) { - spinnerGrThreshold.setVisible(visible); - labelGrThreshold.setVisible(visible); - spinnerGrScale.setVisible(visible); - labelGrScale.setVisible(visible); - panelSlicing.setVisible(visible); - } - - void setSlicingOptionsVisible(boolean visible) { - spinnerSlNumber.setVisible(visible); - labelSlNumber.setVisible(visible); - spinnerSlScale.setVisible(visible); - labelSlScale.setVisible(visible); - spinnerSlOrientation.setVisible(visible); - labelSlOrientation.setVisible(visible); - } - - boolean isCameraStopped() { - if ((server != null) && !server.isStarted()) { - return true; - } - return ((camera == null) || camera.isClosed()); - } - - boolean updatingButtons; - - void updateButtons() { - updatingButtons = true; - try { - boolean active = !isCameraStopped();//(camera != null); - buttonSave.setEnabled(active); - buttonGrabBackground.setEnabled(active); - buttonMarker.setEnabled(active); - buttonProfile.setEnabled(active); - buttonFit.setEnabled(active); - buttonReticle.setEnabled(active && camera.getConfig().isCalibrated()); - buttonStreamData.setEnabled(active && (server != null)); - buttonPause.setEnabled(active); - //buttonPause.setIcon(getIcon("Play")); - //buttonPause.setToolTipText("Resume"); - //buttonPause.setIcon(getIcon("Pause")); - //buttonPause.setToolTipText("Pause"); - - if (renderer.isPaused() != buttonPause.isSelected()) { - buttonPause.setSelected(renderer.isPaused()); - buttonPauseActionPerformed(null); - } - if (renderer.getShowReticle() != buttonReticle.isSelected()) { - //buttonReticle.setSelected(renderer.getShowReticle()); - } - if ((renderer.getMarker() == null) && buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - } - buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - - } finally { - updatingButtons = false; - } - } - - @Override - protected void onTimer() { - for (Device dev : new Device[]{screen, filter}) { - if (dev != null) { - dev.request(); - } - } - - textState.setText((camera == null) ? "" : camera.getState().toString()); - if (App.hasArgument("s")) { - try { - ((Source) getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } - } - if (!renderer.isPaused() && (dataTableDialog != null) && (dataTableDialog.isShowing())) { - updateStreamData(); - } - updateZoom(); - updateColormap(); - updateButtons(); - checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); - } - - Pen penFit = new Pen(new Color(192, 105, 0), 0); - Pen penCross = new Pen(new Color(192, 105, 0), 0); - Pen penSlices = new Pen(Color.CYAN.darker(), 1); - - Frame getCurrentFrame() { - if ((imageBufferLenght > 1) && (renderer.isPaused())) { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - return (index < imageBuffer.size()) ? imageBuffer.get(index) : null; - } - } - return currentFrame; - } - - Frame getFrame(Data data) { - synchronized (imageBuffer) { - for (Frame f : imageBuffer) { - if (f.data == data) { - return f; - } - } - } - return null; - } - - void setImageBufferSize(int size) { - if (renderer.isPaused()) { - throw new RuntimeException("Cannot change buffer size whn paused"); - } - synchronized (imageBuffer) { - imageBufferLenght = size; - imageBuffer.clear(); - } - - } - - Overlay[][] getFitOverlays(Data data) { - Overlays.Polyline hgaussian = null; - Overlays.Polyline vgaussian = null; - Overlays.Polyline hprofile = null; - Overlays.Polyline vprofile = null; - Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null; - Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null; - double[] pX = null, pY = null, gX = null, gY = null; - PointDouble[] sliceCenters = null; - //Double xCom=null, yCom=null; - if (data != null) { - int height = data.getHeight(); - int width = data.getWidth(); - int profileSize = renderer.getProfileSize(); - if ((useServerStats) && (server != null)) { - try { - - ImageData id = getFrame(data); - if (id == null) { - return null; - } - xMean = id.x_fit_mean; - xSigma = id.x_fit_standard_deviation; - yMean = id.y_fit_mean; - ySigma = id.y_fit_standard_deviation; - gX = id.x_fit_gauss_function; - gY = id.y_fit_gauss_function; - pX = id.x_profile; - pY = id.y_profile; - xCom = id.x_center_of_mass; - xRms = id.x_rms; - yCom = id.y_center_of_mass; - yRms = id.y_rms; - sliceCenters = id.sliceCenters; - - profileSize /= 4; - if (pX != null) { - int[] xp = Arr.indexesInt(pX.length); - int[] xg = xp; - int[] yp = new int[pX.length]; - int[] yg = new int[pX.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_x>0){ - l = Arrays.asList( (Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gX, id.gr_pos_x, id.gr_pos_x + id.gr_size_x))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gX != null) { - yg[i] = (int) (height - 1 - (((gX[i] - minGauss) / rangeGauss) * profileSize)); - } - yp[i] = (int) (height - 1 - (((pX[i] - minProfile) / rangeProfile) * profileSize)); - } - - if (goodRegion && id.gr_size_x>0){ - xg = Arrays.copyOfRange(xg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - yg = Arrays.copyOfRange(yg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - } - - vgaussian = new Overlays.Polyline(penFit, xg, yg); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - - if (pY != null) { - int[] xp = new int[pY.length]; - int[] xg = new int[pY.length]; - int[] yp = Arr.indexesInt(pY.length); - int[] yg = yp; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_y>0){ - l = Arrays.asList( (Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gY, id.gr_pos_y, id.gr_pos_y + id.gr_size_y))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gY != null) { - xg[i] = (int) (((gY[i] - minGauss) / rangeGauss) * profileSize); - } - xp[i] = (int) (((pY[i] - minProfile) / rangeProfile) * profileSize); - } - - if (goodRegion && id.gr_size_x>0){ - xg = Arrays.copyOfRange(xg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - yg = Arrays.copyOfRange(yg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - } - hgaussian = new Overlays.Polyline(penFit, xg, yg); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - return null; - } - } else { - ArrayProperties properties = data.getProperties(); - double maxPlot = properties.max; - double minPlot = properties.min; - double rangePlot = maxPlot - minPlot; - - if (rangePlot <= 0) { - return null; - } - if (renderer.getCalibration() != null) { - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height - minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - if (xSigma != null) { - xSigma *= renderer.getCalibration().getScaleX(); - } - if (ySigma != null) { - ySigma *= renderer.getCalibration().getScaleY(); - } - if (xMean != null) { - xMean = data.getX((int) Math.round(xMean)); - } - if (yMean != null) { - yMean = data.getY((int) Math.round(yMean)); - } - } - } - final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px"; - final String fmt = "%7.1f" + units; - Overlays.Text textCom = null; - Overlay[] pOv = null, fOv = null; - Font fontInfoText = new Font(Font.MONOSPACED, 0, 14); - Point textPosition = new Point(12, 20); - if (showProfile) { - if ((xCom != null) && (yCom != null)) { - String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt, xCom, xRms, yCom, yRms); - textCom = new Overlays.Text(renderer.getPenProfile(), text, fontInfoText, textPosition); - textCom.setFixed(true); - textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - } - pOv = new Overlay[]{hprofile, vprofile, textCom}; - textPosition = new Point(textPosition.x, textPosition.y + 34); - } - if (showFit) { - Overlays.Crosshairs cross = null; - Overlays.Text textFit = null; - if ((xMean != null) && (yMean != null)) { - String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt, xMean, xSigma, yMean, ySigma); - textFit = new Overlays.Text(penFit, text, fontInfoText, textPosition); - textFit.setFixed(true); - textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - Point center = new Point(xMean.intValue(), yMean.intValue()); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean)); - xSigma /= renderer.getCalibration().getScaleX(); - ySigma /= renderer.getCalibration().getScaleY(); - } - cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue()))); - } - textPosition = new Point(textPosition.x, textPosition.y + 34); - fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit}; - - if (goodRegion) { - try { - double[] x = getServerDoubleArray("gr_x_axis"); - double[] y = getServerDoubleArray("gr_y_axis"); - double x1 = x[0]; - double x2 = x[x.length - 1]; - double y1 = y[0]; - double y2 = y[y.length - 1]; - Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); - goodRegionOv.setCalibration(renderer.getCalibration()); - goodRegionOv.setAbsolutePosition(new PointDouble(x1, y1)); - goodRegionOv.setAbsoluteSize(new DimensionDouble(x2 - x1, y2 - y1)); - fOv = Arr.append(fOv, goodRegionOv); - - if (slicing) { - if (sliceCenters != null) { - for (PointDouble sliceCenter : sliceCenters) { - Overlays.Crosshairs center = new Overlays.Crosshairs(penSlices); - center.setCalibration(renderer.getCalibration()); - center.setAbsolutePosition(sliceCenter); - center.setSize(new Dimension(10, 10)); - fOv = Arr.append(fOv, center); - } - if (sliceCenters.length > 1) { - double[] fit = fitPolynomial(sliceCenters, 1); - double angle = Math.toDegrees(Math.atan(fit[1])); - Overlays.Text text = new Overlays.Text(penSlices, String.format("slice: \u03B8= %5.1fdeg", angle), fontInfoText, textPosition); - text.setFixed(true); - text.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - fOv = Arr.append(fOv, text); - } - } - } - } catch (Exception ex) { - } - } - - } - return new Overlay[][]{pOv, fOv}; - } - return null; - } - - class UserOverlay { - - String name; - Overlay obj; - String[] channels; - } - ArrayList userOverlayConfig; - - void parseUserOverlays() { - Properties userOverlays = new Properties(); - userOverlayConfig = new ArrayList<>(); - if (userOverlaysConfigFile != null) { - try { - try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { - userOverlays.load(in); - - for (String name : userOverlays.stringPropertyNames()) { - String val = userOverlays.getProperty(name); - try { - UserOverlay uo = new UserOverlay(); - uo.name = name; - String type = val.substring(0, val.indexOf("(")).trim(); - String pars = val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")).trim(); - String[] tokens = pars.split(","); - for (int i = 0; i < tokens.length; i++) { - tokens[i] = tokens[i].trim(); - } - Color color = Color.GRAY; - try { - color = (Color) Color.class.getField(tokens[tokens.length - 1].toUpperCase()).get(null); - } catch (Exception ex) { - } - Pen pen = new Pen(color); - try { - String[] penTokens = tokens[tokens.length - 1].split(":"); - color = (Color) Color.class.getField(penTokens[0].toUpperCase()).get(null); - int width = Integer.valueOf(penTokens[1]); - Pen.LineStyle style = Pen.LineStyle.valueOf(penTokens[2]); - pen = new Pen(color, width, style); - } catch (Exception ex) { - } - switch (type) { - case "Point": - uo.obj = new Overlays.Crosshairs(); - uo.obj.setSize(new Dimension(Integer.valueOf(tokens[2]), Integer.valueOf(tokens[3]))); - break; - case "Line": - uo.obj = new Overlays.Line(); - break; - case "Arrow": - uo.obj = new Overlays.Arrow(); - break; - case "Rect": - uo.obj = new Overlays.Rect(); - break; - case "Ellipse": - uo.obj = new Overlays.Ellipse(); - break; - case "Polyline": - uo.obj = new Overlays.Polyline(); - break; - } - if (type.equals("Polyline") || type.equals("Point")) { - uo.channels = new String[]{tokens[0], tokens[1]}; - } else { - uo.channels = new String[]{tokens[0], tokens[1], tokens[2], tokens[3]}; - } - uo.obj.setPen(pen); - userOverlayConfig.add(uo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - Overlay[] getUserOverlays(Data data) { - ArrayList ret = new ArrayList<>(); - if (server != null) { - for (UserOverlay uo : userOverlayConfig) { - try { - Overlay ov = uo.obj; - //Overlay ov = (Overlay)uo.cls.newInstance(); - ov.setCalibration(renderer.getCalibration()); - boolean valid = false; - if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : getServerDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : getServerDoubleArray(uo.channels[1]); - if ((x != null) || (y != null)) { - if (x == null) { - x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); - } - if (y == null) { - y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length); - } - ((Overlays.Polyline) ov).updateAbsolute(x, y); - valid = true; - } - } else { - Double x = getServerDouble(uo.channels[0]); - Double y = getServerDouble(uo.channels[1]); - if ((x != null) && (y != null)) { - PointDouble position = new PointDouble(x, y); - ov.setAbsolutePosition(position); - if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = getServerDouble(uo.channels[2]); - Double y2 = getServerDouble(uo.channels[3]); - if ((x != null) && (y != null)) { - DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); - ov.setAbsoluteSize(size); - valid = true; - } - } else { - valid = true; - } - } - } - if (valid) { - ret.add(ov); - } - } catch (Exception ex) { - //ex.printStackTrace(); - } - } - } - return ret.toArray(new Overlay[0]); - } - - double[] getComRms(double[] arr, double[] x) { - if (arr != null) { - double xmd = 0; - double xmd2 = 0; - double total = 0; - for (int i = 0; i < arr.length; i++) { - double v = (arr[i] * x[i]); - xmd += v; - xmd2 += (v * x[i]); - total += arr[i]; - } - if (total > 0) { - double com = xmd / total; - double com2 = xmd2 / total; - double rms = Math.sqrt(Math.abs(com2 - com * com)); - return new double[]{com, rms}; - } - } - return new double[]{Double.NaN, Double.NaN}; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] fitPolynomial(PointDouble[] points, int order) { - double[] y = new double[points.length]; - double[] x = new double[points.length]; - for (int i = 0; i < points.length; i++) { - x[i] = points[i].x; - y[i] = points[i].y; - } - return fitPolynomial(y, x, order); - } - - double[] fitPolynomial(double[] y, double[] x, int order) { - try { - ArrayProperties pY = ArrayProperties.get(y); - PolynomialCurveFitter fitter = PolynomialCurveFitter.create(order).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - void setHistogramVisible(boolean value) { - if (value) { - if ((histogramDialog == null) || (!histogramDialog.isShowing())) { - Histogram histogram = new Histogram(true); - histogram.setRenderer(renderer); - histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram); - renderer.refresh(); - } - } else { - if (histogramDialog != null) { - histogramDialog.setVisible(false); - histogramDialog = null; - } - } - } - - void setLaserState(boolean value) throws Exception { - System.out.println("Setting laser state: " + value); - Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); - Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); - Thread.sleep(3000); - } - - boolean getLaserState() throws Exception { - return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); - } - - void elog(String logbook, String title, String message, String[] attachments) throws Exception { - String domain = ""; - String category = "Info"; - String entry = ""; - StringBuffer cmd = new StringBuffer(); - - cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); - cmd.append("-a \"Author=ScreenPanel\" "); - cmd.append("-a \"Type=pshell\" "); - cmd.append("-a \"Entry=").append(entry).append("\" "); - cmd.append("-a \"Title=").append(title).append("\" "); - cmd.append("-a \"Category=").append(category).append("\" "); - cmd.append("-a \"Domain=").append(domain).append("\" "); - for (String attachment : attachments) { - cmd.append("-f \"").append(attachment).append("\" "); - } - cmd.append("-n 1 "); - cmd.append("\"").append(message).append("\" "); - System.out.println(cmd.toString()); - - final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); - new Thread(() -> { - try { - process.waitFor(); - int bytes = process.getInputStream().available(); - byte[] arr = new byte[bytes]; - process.getInputStream().read(arr, 0, bytes); - System.out.println(new String(arr)); - bytes = process.getErrorStream().available(); - arr = new byte[bytes]; - process.getErrorStream().read(arr, 0, bytes); - System.err.println(new String(arr)); - } catch (Exception ex) { - System.err.println(ex); - } - }).start(); - } - - void centralizeRenderer() { - Point center = null; - Dimension size = renderer.getImageSize(); - double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom(); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().getCenter(); - } else if (size != null) { - center = new Point(size.width / 2, size.height / 2); - } - if (center != null) { - Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0), - Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0)); - renderer.setViewPosition(topleft); - } - } - - void updatePause() { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - if (index < imageBuffer.size()) { - Data data = imageBuffer.get(index).data; - BufferedImage image = camera.generateImage(data); - renderer.setImage(renderer.getOrigin(), image, data); - imageBufferOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS")); - manageFit(image, data); - manageUserOverlays(image, data); - } - } - if ((dataTableDialog != null) && (dataTableDialog.isShowing())) { - updateStreamData(); - } - } - - void saveSnapshot() throws Exception { - String snapshotFile = null; - synchronized (imageBuffer) { - Frame frame = getCurrentFrame(); - if (frame == null) { - throw new Exception("No current image"); - } - ArrayList frames = new ArrayList<>(); - frames.add(frame); - this.saveFrames("camera_snapshot", frames); - - //Enforce the same timestamp to data & image files. - snapshotFile = getContext().getExecutionPars().getPath() + ".png"; - ImageBuffer.saveImage(SwingUtils.createImage(renderer), snapshotFile, "png"); - } - - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{0, 180}; //Minimum width - layout.rowHeights = new int[]{30, 30, 30}; //Minimum height - panel.setLayout(layout); - JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); - JTextField textComment = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Data file:"), c); - c.gridy = 1; - panel.add(new JLabel("Logbook:"), c); - c.gridy = 2; - panel.add(new JLabel("Comment:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(textComment, c); - c.gridy = 1; - panel.add(comboLogbook, c); - c.gridy = 0; - panel.add(new JLabel(getContext().getExecutionPars().getPath()), c); - - if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes) { - StringBuilder message = new StringBuilder(); - message.append("Camera: ").append(cameraName).append(" ("). - append((server != null) ? "server" : "direct").append(")").append("\n"); - message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); - message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); - message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); - message.append("Comment: ").append(textComment.getText()).append("\n"); - if ((fitOv != null) && (fitOv.length > 5)) { - Overlays.Text text = (Overlays.Text) fitOv[5]; - message.append(text.getText()).append("\n"); - } - elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - } - - void saveStack() throws Exception { - synchronized (imageBuffer) { - saveFrames("camera_stack", imageBuffer); - } - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000); - } - - public static String getCameraType(String name) { - if (name == null) { - return ""; - } - for (String s : new String[]{"LCAM"}) { - if (name.contains(s)) { - return LASER_TYPE; - } - } - for (String s : new String[]{"DSCR", "DSRM", "DLAC"}) { - if (name.contains(s)) { - return ELECTRONS_TYPE; - } - } - for (String s : new String[]{"PROF", "PPRM", "PSSS", "PSCR", "PSRD"}) { - if (name.contains(s)) { - return PHOTONICS_TYPE; - } - } - return "Unknown"; - } - - public Map getProcessingParameters(StreamValue value) throws IOException { - return (Map) JsonSerializer.decode(value.getValue("processing_parameters").toString(), Map.class); - } - - void saveFrames(String name, ArrayList frames) throws IOException { - ArrayList values = new ArrayList<>(); - for (Frame frame : frames) { - values.add(frame.cache); - } - saveImages(name, values); - } - - void saveImages(String name, ArrayList images) throws IOException { - int depth = images.size(); - if (depth == 0) { - return; - } - StreamValue first = images.get(0); - String pathRoot = "/camera1/"; - String pathImage = pathRoot + "image"; - String pathPid = pathRoot + "pulse_id"; - String pathTimestampStr = pathRoot + "timestamp_str"; - Map processingPars = getProcessingParameters(first); - String camera = (String) processingPars.get("camera_name"); - String type = getCameraType(camera); - - int width = ((Number) first.getValue("width")).intValue(); - int height = ((Number) first.getValue("height")).intValue(); - Class dataType = first.getValue("image").getClass().getComponentType(); - - getContext().setExecutionPars(name); - DataManager dm = getContext().getDataManager(); - - //Create tables - dm.createDataset(pathImage, dataType, new int[]{depth, height, width}); - dm.createDataset(pathPid, Long.class, new int[]{depth}); - dm.createDataset(pathTimestampStr, String.class, new int[]{depth}); - for (String id : first.getIdentifiers()) { - Object val = first.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(first); - for (String key : pars.keySet()) { - if ((pars.get(key) != null) && (pars.get(key) instanceof Map)) { - for (Object k : ((Map) pars.get(key)).keySet()) { - Object v = ((Map) pars.get(key)).get(k); - dm.setAttribute(pathImage, key + " " + k, (v == null) ? "" : v); - } - } else { - Object value = pars.get(key); - if (value == null) { - value = ""; - } else if (value instanceof List) { - Class cls = (((List) value).size() > 0) ? ((List) value).get(0).getClass() : double.class; - value = Convert.toPrimitiveArray(value, cls); - //value = Convert.toDouble(value); - } - dm.setAttribute(pathImage, key, value); - } - } - } else if (val.getClass().isArray()) { - dm.createDataset(pathRoot + id, Double.class, new int[]{depth, Array.getLength(val)}); - } else { - dm.createDataset(pathRoot + id, val.getClass(), new int[]{depth}); - } - } - - //Add metadata - dm.setAttribute(pathRoot, "Camera", camera); - dm.setAttribute(pathRoot, "Images", depth); - dm.setAttribute(pathRoot, "Interval", -1); - dm.setAttribute(pathRoot, "Type", type); - if (type.equals(ELECTRONS_TYPE)) { - dm.setAttribute(pathRoot, "Screen", String.valueOf(valueScreen.getLabel().getText())); - dm.setAttribute(pathRoot, "Filter", String.valueOf(valueFilter.getLabel().getText())); - } - - //Save data - for (int index = 0; index < depth; index++) { - StreamValue streamValue = images.get(index); - dm.setItem(pathImage, streamValue.getValue("image"), new long[]{index, 0, 0}, new int[]{1, height, width}); - dm.setItem(pathPid, streamValue.getPulseId(), index); - dm.setItem(pathTimestampStr, Chrono.getTimeStr(streamValue.getTimestamp(), "YYYY-MM-dd HH:mm:ss.SSS"), index); - - for (String id : streamValue.getIdentifiers()) { - Object val = streamValue.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - } else if (val.getClass().isArray()) { - dm.setItem(pathRoot + id, val, index); - } else { - dm.setItem(pathRoot + id, val, index); - } - } - } - getContext().getDataManager().closeOutput(); - } - - StandardDialog calibrationDialolg; - - void calibrate() throws Exception { - if (server != null) { - server.resetRoi(); - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraCalibrationDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), server.getCurrentCamera(), renderer}); - SwingUtils.centerComponent(getTopLevel(), calibrationDialolg); - calibrationDialolg.setVisible(true); - calibrationDialolg.setListener(new StandardDialogListener() { - @Override - public void onWindowOpened(StandardDialog dlg) { - } - - @Override - public void onWindowClosed(StandardDialog dlg, boolean accepted) { - if (accepted) { - //comboCamerasActionPerformed(null); - } - } - }); - } - } - - StandardDialog dataTableDialog; - DefaultTableModel dataTableModel; - - void showStreamData() { - dataTableModel = null; - if (server != null) { - - if ((dataTableDialog != null) && (dataTableDialog.isShowing())) { - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.requestFocus(); - return; - } - //String msg = String.join("\n", ids); - //SwingUtils.showMessage(getTopLevel(), "Image Data", msg); - dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) { - public Class getColumnClass(int columnIndex) { - return String.class; - } - - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - }; - updateStreamData(); - StreamValue val = server.getStream().take(); - JTable dataTable = new JTable(dataTableModel); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.setCellSelectionEnabled(true); - dataTable.getTableHeader().setReorderingAllowed(false); - dataTable.getTableHeader().setResizingAllowed(true); - dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); - dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(dataTable); - scrollPane.setPreferredSize(new Dimension(300, 400)); - dataTableDialog.setContentPane(scrollPane); - dataTableDialog.pack(); - dataTableDialog.setVisible(true); - dataTableDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - dataTableModel = null; - } - }); - dataTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - try { - int index = dataTable.getSelectedRow(); - dataTable.setToolTipText(null); - if (index>1){ - String id = String.valueOf(dataTable.getModel().getValueAt(index, 0)); - String locator = String.valueOf(dataTable.getModel().getValueAt(0, 1)); - dataTable.setToolTipText(locator + " " + id); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - clipboard.setContents(new StringSelection(locator+ " " + id), (Clipboard clipboard1, Transferable contents) -> {}); - if ((e.getClickCount() == 2) && (!e.isPopupTrigger())) { - Object obj = getCurrentFrame().cache.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(getCurrentFrame().cache); - StringBuilder sb = new StringBuilder(); - for (String key : pars.keySet()) { - sb.append(key).append(" = ").append(Str.toString(pars.get(key), 10)).append("\n"); - } - SwingUtils.showMessage(dataTableDialog, "Processing Parameters", sb.toString()); - } else if ((obj!=null) && (obj.getClass().isArray() || (obj instanceof Number))) { - DeviceValueChart chart = new DeviceValueChart(); - Device dev = null; - if (obj.getClass().isArray()){ - dev = new ReadableRegisterArray(new ReadableArray() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - @Override - public int getSize() { - return Array.getLength(getCurrentFrame().cache.getValue(id)); - } - }); - } else { - dev = new ReadableRegisterNumber(new ReadableNumber() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - }); - } - dev.setPolling(1000); - chart.setDevice(dev); - JDialog dlg = SwingUtils.showDialog(dataTableDialog, cameraName +" " + id, null, chart); - } - } - } - } catch (Exception ex) { - showException(ex); - } - } - }); - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - } - } - - void updateStreamData() { - if ((dataTableModel != null) && (server != null)) { - StreamValue value = server.getValue(); - - List ids = (value == null) ? new ArrayList<>() : new ArrayList(value.getIdentifiers()); - if (ids.size() + 2 != dataTableModel.getRowCount()) { - dataTableModel.setNumRows(0); - try { - dataTableModel.addRow(new Object[]{"Locator", server.getUrl() + "/" + ((value == null) ? instanceName : server.getCurrentInstance())}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Locator", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"Stream", server.getStreamAddress()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Stream", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"PID", value.getPulseId()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"PID", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"Timestamp", value.getTimestamp()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Timestamp", ex.getMessage()}); - } - Collections.sort(ids); - for (String id : ids) { - dataTableModel.addRow(new Object[]{id, ""}); - } - } - Frame frame = getCurrentFrame(); - if ((frame != null) && (frame.cache!=null)){ - for (int i = 4; i < dataTableModel.getRowCount(); i++) { - String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - //Object obj = server.getValue(id); - Object obj = frame.cache.getValue(id); - if (obj != null) { - if (obj.getClass().isArray()) { - obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; - } else if (obj instanceof Double) { - obj = Convert.roundDouble((Double) obj, 1); - } else if (obj instanceof Float) { - obj = Convert.roundDouble((Float) obj, 1); - } - } - dataTableModel.setValueAt(String.valueOf(obj), i, 1); - } - } - } - } - - ImageIcon getIcon(String name) { - ImageIcon ret = null; - try { - //Path path = Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(),"resources", name + ".png"); - String dir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + "resources/"; - if (new File(dir + name + ".png").exists()) { - ret = new javax.swing.ImageIcon(dir + name + ".png"); - } else { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/" + name + ".png")); - if (MainFrame.isDark()) { - try { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/dark/" + name + ".png")); - } catch (Exception e) { - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return ret; - } - - String getIconName(JButton button) { - String ret = button.getIcon().toString(); - if (ret.indexOf(".") > 0) { - ret = ret.substring(0, ret.indexOf(".")); - } - return ret; - } - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - buttonGroup4 = new javax.swing.ButtonGroup(); - jProgressBar1 = new javax.swing.JProgressBar(); - sidePanel = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - buttonZoomFit = new javax.swing.JRadioButton(); - buttonZoomStretch = new javax.swing.JRadioButton(); - buttonZoomNormal = new javax.swing.JRadioButton(); - buttonZoom025 = new javax.swing.JRadioButton(); - buttonZoom05 = new javax.swing.JRadioButton(); - buttonZoom2 = new javax.swing.JRadioButton(); - jPanel2 = new javax.swing.JPanel(); - checkHistogram = new javax.swing.JCheckBox(); - comboColormap = new javax.swing.JComboBox(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - buttonFullRange = new javax.swing.JRadioButton(); - buttonManual = new javax.swing.JRadioButton(); - buttonAutomatic = new javax.swing.JRadioButton(); - labelMin = new javax.swing.JLabel(); - spinnerMin = new javax.swing.JSpinner(); - spinnerMax = new javax.swing.JSpinner(); - labelMax = new javax.swing.JLabel(); - btFixColormapRange = new javax.swing.JButton(); - jPanel5 = new javax.swing.JPanel(); - buttonServer = new javax.swing.JRadioButton(); - buttonDirect = new javax.swing.JRadioButton(); - textState = new javax.swing.JTextField(); - filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767)); - panelScreen = new javax.swing.JPanel(); - valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); - comboScreen = new javax.swing.JComboBox(); - panelFilter = new javax.swing.JPanel(); - valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); - comboFilter = new javax.swing.JComboBox(); - panelScreen2 = new javax.swing.JPanel(); - checkThreshold = new javax.swing.JCheckBox(); - spinnerThreshold = new javax.swing.JSpinner(); - checkBackground = new javax.swing.JCheckBox(); - checkGoodRegion = new javax.swing.JCheckBox(); - spinnerGrScale = new javax.swing.JSpinner(); - spinnerGrThreshold = new javax.swing.JSpinner(); - labelGrThreshold = new javax.swing.JLabel(); - labelGrScale = new javax.swing.JLabel(); - panelSlicing = new javax.swing.JPanel(); - checkSlicing = new javax.swing.JCheckBox(); - labelSlScale = new javax.swing.JLabel(); - spinnerSlScale = new javax.swing.JSpinner(); - labelSlNumber = new javax.swing.JLabel(); - spinnerSlNumber = new javax.swing.JSpinner(); - labelSlOrientation = new javax.swing.JLabel(); - spinnerSlOrientation = new javax.swing.JSpinner(); - topPanel = new javax.swing.JPanel(); - toolBar = new javax.swing.JToolBar(); - buttonSidePanel = new javax.swing.JToggleButton(); - buttonStreamData = new javax.swing.JButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - buttonPause = new javax.swing.JToggleButton(); - jSeparator6 = new javax.swing.JToolBar.Separator(); - buttonMarker = new javax.swing.JToggleButton(); - buttonProfile = new javax.swing.JToggleButton(); - buttonFit = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonTitle = new javax.swing.JToggleButton(); - pauseSelection = new ch.psi.pshell.swing.ValueSelection(); - panelCameraSelection = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - jLabel5 = new javax.swing.JLabel(); - comboType = new javax.swing.JComboBox(); - renderer = new ch.psi.pshell.imaging.Renderer(); - - setPreferredSize(new java.awt.Dimension(873, 600)); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); - - buttonGroup1.add(buttonZoomFit); - buttonZoomFit.setText("Fit"); - buttonZoomFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomFitActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomStretch); - buttonZoomStretch.setText("Stretch"); - buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomStretchActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomNormal); - buttonZoomNormal.setText("Normal"); - buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomNormalActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("1/4"); - buttonZoom025.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom025ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("1/2"); - buttonZoom05.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom05ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom2); - buttonZoom2.setText("2"); - buttonZoom2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoomStretch)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05) - .addComponent(buttonZoom2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomFit) - .addComponent(buttonZoom05)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoom2)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap")); - - checkHistogram.setText("Histogram"); - checkHistogram.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkHistogramActionPerformed(evt); - } - }); - - comboColormap.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Type:"); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Range:"); - - buttonGroup3.add(buttonFullRange); - buttonFullRange.setText("Full"); - buttonFullRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonManual); - buttonManual.setText("Manual"); - buttonManual.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonAutomatic); - buttonAutomatic.setText("Automatic"); - buttonAutomatic.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - labelMin.setText("Min:"); - - spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); - spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); - spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - labelMax.setText("Max:"); - - btFixColormapRange.setText("Fix"); - btFixColormapRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btFixColormapRangeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonAutomatic) - .addComponent(buttonFullRange) - .addComponent(buttonManual) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMax) - .addGap(2, 2, 2) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMin) - .addGap(2, 2, 2) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(spinnerMin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFixColormapRange, spinnerMax, spinnerMin}); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3) - .addComponent(checkHistogram)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAutomatic) - .addComponent(jLabel4) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelMin) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonFullRange)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonManual) - .addComponent(labelMax) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - - buttonGroup4.add(buttonServer); - buttonServer.setSelected(true); - buttonServer.setText("Server"); - buttonServer.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonServerActionPerformed(evt); - } - }); - - buttonGroup4.add(buttonDirect); - buttonDirect.setText("Direct"); - buttonDirect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDirectActionPerformed(evt); - } - }); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonServer) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonDirect) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(56, 56, 56)) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonServer) - .addComponent(buttonDirect))) - .addContainerGap()) - ); - - panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); - - comboScreen.setEnabled(false); - comboScreen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboScreenActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); - panelScreen.setLayout(panelScreenLayout); - panelScreenLayout.setHorizontalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreenLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreenLayout.setVerticalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelFilter.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); - - comboFilter.setEnabled(false); - comboFilter.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboFilterActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelFilterLayout = new javax.swing.GroupLayout(panelFilter); - panelFilter.setLayout(panelFilterLayout); - panelFilterLayout.setHorizontalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelFilterLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelFilterLayout.setVerticalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFilterLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - panelScreen2.setBorder(javax.swing.BorderFactory.createTitledBorder("Pipeline")); - - checkThreshold.setText("Threshold"); - checkThreshold.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkThresholdActionPerformed(evt); - } - }); - - spinnerThreshold.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 99999.0d, 1.0d)); - spinnerThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerThresholdonChange(evt); - } - }); - - checkBackground.setText("Subtract Background"); - checkBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkBackgroundActionPerformed(evt); - } - }); - - checkGoodRegion.setText("Good Region"); - checkGoodRegion.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkGoodRegionActionPerformed(evt); - } - }); - - spinnerGrScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerGrScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - spinnerGrThreshold.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.04d, 1.0d, 0.1d)); - spinnerGrThreshold.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerGrThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - labelGrThreshold.setText("Threshold:"); - - labelGrScale.setText("Scale:"); - - checkSlicing.setText("Slicing"); - checkSlicing.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkSlicingActionPerformed(evt); - } - }); - - labelSlScale.setText("Scale:"); - - spinnerSlScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerSlScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlNumber.setText("Slices:"); - - spinnerSlNumber.setModel(new javax.swing.SpinnerNumberModel(2, 0, 1000, 1)); - spinnerSlNumber.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlNumber.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlOrientation.setText("Orientation:"); - - spinnerSlOrientation.setModel(new javax.swing.SpinnerListModel(new String[] {"vertical", "horizontal"})); - spinnerSlOrientation.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlOrientation.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - javax.swing.GroupLayout panelSlicingLayout = new javax.swing.GroupLayout(panelSlicing); - panelSlicing.setLayout(panelSlicingLayout); - panelSlicingLayout.setHorizontalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addComponent(checkSlicing) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlNumber) - .addGap(2, 2, 2) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlScale) - .addGap(2, 2, 2) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelSlOrientation) - .addGap(2, 2, 2) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - panelSlicingLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerSlNumber, spinnerSlOrientation, spinnerSlScale}); - - panelSlicingLayout.setVerticalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(checkSlicing) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlNumber)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlScale)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlOrientation))) - ); - - javax.swing.GroupLayout panelScreen2Layout = new javax.swing.GroupLayout(panelScreen2); - panelScreen2.setLayout(panelScreen2Layout); - panelScreen2Layout.setHorizontalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkThreshold) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addComponent(checkGoodRegion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(labelGrScale)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelGrThreshold))) - .addGap(2, 2, 2))) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - .addComponent(panelSlicing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addGap(6, 6, 6) - .addComponent(checkBackground) - .addGap(106, 106, 106)) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerThreshold}); - - panelScreen2Layout.setVerticalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(checkBackground) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkThreshold) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkGoodRegion) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrScale)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrThreshold)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelSlicing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - javax.swing.GroupLayout sidePanelLayout = new javax.swing.GroupLayout(sidePanel); - sidePanel.setLayout(sidePanelLayout); - sidePanelLayout.setHorizontalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - sidePanelLayout.setVerticalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - toolBar.setFloatable(false); - toolBar.setRollover(true); - - buttonSidePanel.setIcon(getIcon("List")); - buttonSidePanel.setSelected(true); - buttonSidePanel.setText(" "); - buttonSidePanel.setToolTipText("Show Side Panel"); - buttonSidePanel.setFocusable(false); - buttonSidePanel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSidePanel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSidePanelActionPerformed(evt); - } - }); - toolBar.add(buttonSidePanel); - - buttonStreamData.setIcon(getIcon("Details")); - buttonStreamData.setText(" "); - buttonStreamData.setToolTipText("Show Data Window"); - buttonStreamData.setFocusable(false); - buttonStreamData.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonStreamData.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStreamDataActionPerformed(evt); - } - }); - toolBar.add(buttonStreamData); - - buttonSave.setIcon(getIcon("Save")); - buttonSave.setText(" "); - buttonSave.setToolTipText("Save Snapshot"); - buttonSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - toolBar.add(buttonSave); - - buttonGrabBackground.setIcon(getIcon("Background")); - buttonGrabBackground.setText(" "); - buttonGrabBackground.setToolTipText("Grab Background"); - buttonGrabBackground.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - toolBar.add(buttonGrabBackground); - - buttonPause.setIcon(getIcon("Pause")); - buttonPause.setText(" "); - buttonPause.setToolTipText("Pause"); - buttonPause.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - toolBar.add(buttonPause); - - jSeparator6.setMaximumSize(new java.awt.Dimension(20, 32767)); - jSeparator6.setPreferredSize(new java.awt.Dimension(20, 0)); - jSeparator6.setRequestFocusEnabled(false); - toolBar.add(jSeparator6); - - buttonMarker.setIcon(getIcon("Marker")); - buttonMarker.setText(" "); - buttonMarker.setToolTipText("Show Marker"); - buttonMarker.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - toolBar.add(buttonMarker); - - buttonProfile.setIcon(getIcon("Profile" - + "")); - buttonProfile.setSelected(true); - buttonProfile.setText(" "); - buttonProfile.setToolTipText("Show Image Profile"); - buttonProfile.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonProfile.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonProfileActionPerformed(evt); - } - }); - toolBar.add(buttonProfile); - - buttonFit.setIcon(getIcon("Fit")); - buttonFit.setSelected(true); - buttonFit.setText(" "); - buttonFit.setToolTipText("Show Fit"); - buttonFit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - toolBar.add(buttonFit); - - buttonReticle.setIcon(getIcon("Reticule")); - buttonReticle.setSelected(true); - buttonReticle.setText(" "); - buttonReticle.setToolTipText("Show Reticle"); - buttonReticle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - toolBar.add(buttonReticle); - - buttonTitle.setIcon(getIcon("Title")); - buttonTitle.setText(" "); - buttonTitle.setToolTipText("Show Camera Name"); - buttonTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonTitle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonTitleActionPerformed(evt); - } - }); - toolBar.add(buttonTitle); - - pauseSelection.setDecimals(0); - - jLabel1.setText("Camera:"); - - comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboCameras.setMaximumRowCount(30); - comboCameras.setMinimumSize(new java.awt.Dimension(127, 27)); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - jLabel5.setText("Type:"); - - comboType.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboType.setMaximumRowCount(30); - comboType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Laser", "Electrons", "Photonics" })); - comboType.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboTypeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelCameraSelectionLayout = new javax.swing.GroupLayout(panelCameraSelection); - panelCameraSelection.setLayout(panelCameraSelectionLayout); - panelCameraSelectionLayout.setHorizontalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addGap(0, 0, 0) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - panelCameraSelectionLayout.setVerticalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel5) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0)) - ); - - javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel); - topPanel.setLayout(topPanelLayout); - topPanelLayout.setHorizontalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup() - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - topPanelLayout.setVerticalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(topPanelLayout.createSequentialGroup() - .addGap(1, 1, 1) - .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(sidePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(topPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(sidePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - }// //GEN-END:initComponents - - private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed - try { - renderer.setMode(RendererMode.Fit); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomFitActionPerformed - - private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed - try { - renderer.setMode(RendererMode.Stretch); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomStretchActionPerformed - - private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed - try { - renderer.setMode(RendererMode.Fixed); - centralizeRenderer(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomNormalActionPerformed - - private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap - try { - if ((camera != null) && (camera instanceof ColormapSource) && !updatingColormap) { - ColormapSource source = (ColormapSource) camera; - Color colorReticule = new Color(16, 16, 16); - Color colorMarker = new Color(128, 128, 128); - Colormap colormap = (Colormap) comboColormap.getSelectedItem(); - source.getConfig().colormap = (colormap==null) ? Colormap.Flame: colormap; - switch (source.getConfig().colormap) { - case Grayscale: - case Inverted: - case Red: - case Green: - case Blue: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - case Flame: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - } - - renderer.setPenReticle(new Pen(colorReticule)); - renderer.setPenProfile(new Pen(colorReticule, 0)); - renderer.setPenMarker(new Pen(colorMarker, 2)); - renderer.setShowReticle(false); - checkReticle(); - source.getConfig().colormapAutomatic = buttonAutomatic.isSelected(); - source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); - source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); - try { - source.getConfig().save(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - } - source.refresh(); - if (buttonPause.isSelected()) { - updatePause(); - } - updateColormap(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_onChangeColormap - - private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange - onChangeColormap(null); - }//GEN-LAST:event_onChangeColormapRange - - private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed - renderer.setZoom(0.25); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom025ActionPerformed - - private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed - renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom05ActionPerformed - - private void buttonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonServerActionPerformed - if (!usingServer) { - usingServer = true; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonServerActionPerformed - - private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingServer) { - usingServer = false; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonDirectActionPerformed - - private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed - - comboScreen.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - ChannelInteger setpoint = null; - try { - int index = comboScreen.getSelectedIndex(); - if (cameraName.contains("DSRM")) { - setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); - } else { - setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); - } - setpoint.initialize(); - if (setpoint.read() != index) { - setpoint.write(index); - //Must be threaded to control the laser because of sleep in setLaserState - /* - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - setpoint.write(index); - } finally { - if (laserOn) { - setLaserState(true); - } - } - */ - } - screen.read(); - } catch (Exception ex) { - showException(ex); - } finally { - comboScreen.setEnabled(true); - if (setpoint != null) { - setpoint.close(); - } - } - } - }).start(); - }//GEN-LAST:event_comboScreenActionPerformed - - private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed - try { - String setpoint = (String) comboFilter.getSelectedItem(); - if (!setpoint.equals(filter.read())) { - filter.write(setpoint); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboFilterActionPerformed - - private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed - try { - setHistogramVisible(checkHistogram.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_checkHistogramActionPerformed - - private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed - renderer.setZoom(2.0); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom2ActionPerformed - - private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setThreshold((Double) spinnerThreshold.getValue()); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_spinnerThresholdonChange - - private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (server != null) { - if (!updatingServerControls) { - try { - if (server.isStarted()) { - server.setBackgroundSubtraction(checkBackground.isSelected()); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - updatingServerControls = true; - checkBackground.setSelected(false); - updatingServerControls = false; - - } - } - } else { - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - }//GEN-LAST:event_checkBackgroundActionPerformed - - private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - spinnerThreshold.setVisible(checkThreshold.isSelected()); - server.setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_checkThresholdActionPerformed - - private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - goodRegion = checkGoodRegion.isSelected(); - setGoodRegionOptionsVisible(goodRegion); - if (goodRegion) { - server.setGoodRegion(((Number) spinnerGrThreshold.getValue()).doubleValue(), ((Number) spinnerGrScale.getValue()).doubleValue()); - } else { - server.setGoodRegion(null); - } - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_checkGoodRegionActionPerformed - - private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setGoodRegion((Double) spinnerGrThreshold.getValue(), (Double) spinnerGrScale.getValue()); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_spinnerGrThresholdonChange - - private void btFixColormapRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFixColormapRangeActionPerformed - try { - updatingColormap = true; - ArrayProperties properties = currentFrame.data.getProperties(); - spinnerMax.setValue(properties.max.intValue()); - spinnerMin.setValue(properties.min.intValue()); - buttonManual.setSelected(true); - } catch (Exception ex) { - showException(ex); - } finally { - updatingColormap = false; - onChangeColormap(null); - } - }//GEN-LAST:event_btFixColormapRangeActionPerformed - - private void checkSlicingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSlicingActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - slicing = checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - if (slicing) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } else { - server.setSlicing(null); - } - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_checkSlicingActionPerformed - - private void spinnerSlicingChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerSlicingChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } - } catch (Exception ex) { - showException(ex); - updateServerControls(); - } - } - }//GEN-LAST:event_spinnerSlicingChange - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - showFit = buttonFit.isSelected(); - if (showFit) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed - try { - showProfile = buttonProfile.isSelected(); - if (showProfile) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(profileOv); - profileOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonProfileActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - checkMarker(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - if (!updatingButtons){ - renderer.removeOverlay(imageBufferOverlay); - if (camera != null) { - boolean pause = !renderer.isPaused(); - synchronized (imageBuffer) { - if (pause) { - renderer.pause(); - } else { - imageBuffer.clear(); - renderer.resume(); - } - - if (pause && (imageBuffer.size() > 1)) { - panelCameraSelection.setVisible(false); - pauseSelection.setVisible(true); - renderer.addOverlay(imageBufferOverlay); - pauseSelection.setMaxValue(imageBuffer.size()); - pauseSelection.setValue(imageBuffer.size());; - updatePause(); - } else { - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - updateStreamData(); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera != null) { - boolean laserOn = getLaserState(); - OptionResult ret = null; - if (laserOn) { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put laser on delay for capturing background?", OptionType.YesNoCancel); - if (ret == OptionResult.No) { - laserOn = false; - } - } else { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to capture background now?", OptionType.OkCancel); - } - - if (ret == OptionResult.Cancel) { - return; - } - - if (laserOn) { - setLaserState(false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - if (server != null) { - server.captureBackground(5); - } else { - camera.captureBackground(5, 0); - } - } finally { - if (laserOn) { - setLaserState(true); - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - saveSnapshot(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonStreamDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStreamDataActionPerformed - try { - showStreamData(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonStreamDataActionPerformed - - private void buttonSidePanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSidePanelActionPerformed - sidePanel.setVisible(buttonSidePanel.isSelected()); - }//GEN-LAST:event_buttonSidePanelActionPerformed - - private void comboTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTypeActionPerformed - try { - updateCameraList(); - if ((cameraName != null) && (!cameraName.equals(comboCameras.getSelectedItem()))) { - setCamera(null); - } else { - setCamera(cameraName); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - }//GEN-LAST:event_comboTypeActionPerformed - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - if (!updatingCameraSelection) { - if (!comboCameras.isEnabled()) { - throw new Exception("Invalid state"); - } - comboCameras.setEnabled(false); - comboType.setEnabled(false); - buttonServer.setEnabled(false); - buttonDirect.setEnabled(false); - final String cameraName = (String) comboCameras.getSelectedItem(); - new Thread(new Runnable() { - @Override - public void run() { - if (requestCameraListUpdate) { - requestCameraListUpdate = false; - try { - updateCameraList(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - try { - setCamera(cameraName.trim().isEmpty() ? null : cameraName); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - buttonServer.setEnabled(true); - buttonDirect.setEnabled(true); - } - } - }).start(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTitleActionPerformed - try { - manageTitleOverlay(); - } catch (Exception ex) { - showException(ex); - } finally { - } - }//GEN-LAST:event_buttonTitleActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btFixColormapRange; - private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonDirect; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JRadioButton buttonFullRange; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JRadioButton buttonManual; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonProfile; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JRadioButton buttonServer; - private javax.swing.JToggleButton buttonSidePanel; - private javax.swing.JButton buttonStreamData; - private javax.swing.JToggleButton buttonTitle; - private javax.swing.JRadioButton buttonZoom025; - private javax.swing.JRadioButton buttonZoom05; - private javax.swing.JRadioButton buttonZoom2; - private javax.swing.JRadioButton buttonZoomFit; - private javax.swing.JRadioButton buttonZoomNormal; - private javax.swing.JRadioButton buttonZoomStretch; - private javax.swing.JCheckBox checkBackground; - private javax.swing.JCheckBox checkGoodRegion; - private javax.swing.JCheckBox checkHistogram; - private javax.swing.JCheckBox checkSlicing; - private javax.swing.JCheckBox checkThreshold; - private javax.swing.JComboBox comboCameras; - private javax.swing.JComboBox comboColormap; - private javax.swing.JComboBox comboFilter; - private javax.swing.JComboBox comboScreen; - private javax.swing.JComboBox comboType; - private javax.swing.Box.Filler filler1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel5; - private javax.swing.JProgressBar jProgressBar1; - private javax.swing.JToolBar.Separator jSeparator6; - private javax.swing.JLabel labelGrScale; - private javax.swing.JLabel labelGrThreshold; - private javax.swing.JLabel labelMax; - private javax.swing.JLabel labelMin; - private javax.swing.JLabel labelSlNumber; - private javax.swing.JLabel labelSlOrientation; - private javax.swing.JLabel labelSlScale; - private javax.swing.JPanel panelCameraSelection; - private javax.swing.JPanel panelFilter; - private javax.swing.JPanel panelScreen; - private javax.swing.JPanel panelScreen2; - private javax.swing.JPanel panelSlicing; - private ch.psi.pshell.swing.ValueSelection pauseSelection; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JPanel sidePanel; - private javax.swing.JSpinner spinnerGrScale; - private javax.swing.JSpinner spinnerGrThreshold; - private javax.swing.JSpinner spinnerMax; - private javax.swing.JSpinner spinnerMin; - private javax.swing.JSpinner spinnerSlNumber; - private javax.swing.JSpinner spinnerSlOrientation; - private javax.swing.JSpinner spinnerSlScale; - private javax.swing.JSpinner spinnerThreshold; - private javax.swing.JTextField textState; - private javax.swing.JToolBar toolBar; - private javax.swing.JPanel topPanel; - private ch.psi.pshell.swing.DeviceValuePanel valueFilter; - private ch.psi.pshell.swing.DeviceValuePanel valueScreen; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/ScreenPanel3.form b/plugins/ScreenPanel3.form deleted file mode 100755 index 8f0edfa..0000000 --- a/plugins/ScreenPanel3.form +++ /dev/null @@ -1,1165 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/ScreenPanel3.java b/plugins/ScreenPanel3.java deleted file mode 100755 index 82f553c..0000000 --- a/plugins/ScreenPanel3.java +++ /dev/null @@ -1,4043 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.bs.CameraServer; -import ch.psi.pshell.core.Context; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.PipelineServer; -import ch.psi.pshell.bs.StreamValue; -import ch.psi.pshell.core.JsonSerializer; -import ch.psi.pshell.data.DataManager; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.device.Readable.ReadableArray; -import ch.psi.pshell.device.Readable.ReadableNumber; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterArray; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterNumber; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.DiscretePositioner; -import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.imaging.Colormap; -import ch.psi.pshell.imaging.ColormapSource; -import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.DimensionDouble; -import ch.psi.pshell.imaging.Histogram; -import ch.psi.pshell.imaging.ImageBuffer; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.PointDouble; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.plot.PlotBase; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.pshell.swing.DeviceValueChart; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import ch.psi.pshell.ui.Console; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Convert; -import ch.psi.utils.Str; -import ch.psi.utils.swing.Editor.EditorDialog; -import ch.psi.utils.swing.MainFrame; -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.StandardDialog.StandardDialogListener; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.lang.reflect.Array; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.table.DefaultTableModel; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.PolynomialCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; - -/** - * - */ -public class ScreenPanel3 extends Panel { - - public static final String LASER_TYPE = "Laser"; - public static final String ELECTRONS_TYPE = "Electrons"; - public static final String PHOTONICS_TYPE = "Photonics"; - - final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useServerStats = true; - String userOverlaysConfigFile; - ColormapSource camera; - PipelineServer server; - String cameraName; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - boolean showProfile; - Overlay[] userOv; - Overlay[] fitOv; - Overlay[] profileOv; - Overlay errorOverlay; - boolean requestCameraListUpdate; - boolean goodRegion; - boolean slicing; - String serverUrl; - String camServerUrl; - String instanceName; - Overlay titleOv = null; - int integration = 0; - - String pipelineSuffix = "_sp"; - - Double getServerDouble(String name) { - return (Double) Convert.toDouble(server.getValue(name)); - } - - double[] getServerDoubleArray(String name) { - return (double[]) Convert.toDouble(server.getValue(name)); - } - - Double getServerDouble(String name, StreamValue cache) { - return (Double) Convert.toDouble(cache.__getitem__(name)); - } - - double[] getServerDoubleArray(String name, StreamValue cache) { - return (double[]) Convert.toDouble(cache.__getitem__(name)); - } - - class ImageData { - - ImageData() { - if (server != null) { - cache = server.getStream().take(); - String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getServerDouble(prefix + "x_fit_mean", cache); - y_fit_mean = getServerDouble(prefix + "y_fit_mean", cache); - x_fit_standard_deviation = getServerDouble(prefix + "x_fit_standard_deviation", cache); - y_fit_standard_deviation = getServerDouble(prefix + "y_fit_standard_deviation", cache); - x_fit_gauss_function = getServerDoubleArray(prefix + "x_fit_gauss_function", cache); - y_fit_gauss_function = getServerDoubleArray(prefix + "y_fit_gauss_function", cache); - x_profile = getServerDoubleArray("x_profile", cache); - y_profile = getServerDoubleArray("y_profile", cache); - x_center_of_mass = getServerDouble("x_center_of_mass", cache); - y_center_of_mass = getServerDouble("y_center_of_mass", cache); - x_rms = getServerDouble("x_rms", cache); - y_rms = getServerDouble("y_rms", cache); - if (goodRegion) { - double[] gX2 = new double[x_profile.length]; - Arrays.fill(gX2, Double.NaN); - try { - double x = getServerDoubleArray("gr_x_axis", cache)[0]; - gr_size_x = x_fit_gauss_function.length; - gr_pos_x = (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x) : x); - System.arraycopy(x_fit_gauss_function, 0, gX2, gr_pos_x, gr_size_x); - } catch (Exception ex) { - } - x_fit_gauss_function = gX2; - double[] gY2 = new double[y_profile.length]; - Arrays.fill(gY2, Double.NaN); - try { - double y = getServerDoubleArray("gr_y_axis", cache)[0]; - gr_size_y = y_fit_gauss_function.length; - gr_pos_y = (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageY(y) : y); - System.arraycopy(y_fit_gauss_function, 0, gY2, gr_pos_y, y_fit_gauss_function.length); - } catch (Exception ex) { - } - y_fit_gauss_function = gY2; - if (slicing) { - try { - int slices = getServerDouble("slice_amount").intValue(); - sliceCenters = new PointDouble[slices]; - for (int i = 0; i < slices; i++) { - double x = getServerDouble("slice_" + i + "_center_x"); - double y = getServerDouble("slice_" + i + "_center_y"); - sliceCenters[i] = new PointDouble(x, y); - } - } catch (Exception ex) { - } - } - } - } - } - public Double x_fit_mean; - public Double y_fit_mean; - public Double x_center_of_mass; - public Double x_rms; - public Double x_fit_standard_deviation; - public Double y_fit_standard_deviation; - public Double y_center_of_mass; - public Double y_rms; - public double[] x_profile; - public double[] x_fit_gauss_function; - public double[] y_profile; - public double[] y_fit_gauss_function; - public int gr_size_x; - public int gr_pos_x; - public int gr_size_y; - public int gr_pos_y; - public PointDouble[] sliceCenters; - public StreamValue cache; - } - - class Frame extends ImageData { - - Frame(Data data) { - this.data = data; - } - Data data; - } - - final ArrayList imageBuffer = new ArrayList(); - Frame currentFrame; - int imageBufferLenght = 1; - Text imagePauseOverlay; - final Console console; - - public ScreenPanel3() { - try { - initComponents(); - spinnerThreshold.setVisible(false); - btFixColormapRange.setVisible(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - JComponent editor = spinnerSlOrientation.getEditor(); - if (editor instanceof JSpinner.DefaultEditor) { - ((JSpinner.DefaultEditor) editor).getTextField().setHorizontalAlignment(JTextField.RIGHT); - } - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - //setPersistedComponents(new Component[]{buttonServer, buttonDirect}); - comboCameras.setEnabled(false); - comboType.setEnabled(false); - - SwingUtils.setEnumCombo(comboColormap, Colormap.class); - if (App.hasArgument("poll")) { - try { - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try { - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("buf")) { - try { - imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("usr_ov")) { - try { - userOverlaysConfigFile = App.getArgumentValue("usr_ov"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_url")) { - serverUrl = App.getArgumentValue("srv_url"); - } - - if (App.hasArgument("cam_srv_url")) { - camServerUrl = App.getArgumentValue("cam_srv_url"); - } - - if (App.hasArgument("calc")) { - useServerStats = false; - } - if (App.hasArgument("suffix")) { - pipelineSuffix = App.getArgumentValue("suffix"); - } - if (App.hasArgument("integration")) { - try { - setIntegration(Integer.valueOf(App.getArgumentValue("integration"))); - if (integration != 0) { - buttonFit.setSelected(false); - buttonProfile.setSelected(false); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - renderer.setProfileNormalized(true); - renderer.setShowProfileLimits(false); - - JMenuItem menuCalibrate = new JMenuItem("Calibrate..."); - menuCalibrate.addActionListener((ActionEvent e) -> { - try { - calibrate(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuRendererConfig = new JMenuItem("Renderer Parameters"); - menuRendererConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuCameraConfig = new JMenuItem("Camera Configurarion"); - menuCameraConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - String cameraConfigJson = null; - if (usingServer) { - String cameraServerUrl = (camServerUrl == null) ? server.getUrl().substring(0, server.getUrl().length() - 1) + "8" : camServerUrl; - try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)) { - srv.initialize(); - //TODO: replace into encodeMultiline - cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true); - } - - } else { - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - } - TextEditor configEditor = new TextEditor(); - configEditor.setText(cameraConfigJson); - configEditor.setReadOnly(true); - configEditor.setTitle(cameraName); - EditorDialog dlg = configEditor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(getTopLevel(), dlg); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetImageBufferSize = new JMenuItem("Set Stack Size..."); - menuSetImageBufferSize.addActionListener((ActionEvent e) -> { - try { - String ret = SwingUtils.getString(getTopLevel(), "Enter size of image buffer: ", String.valueOf(imageBufferLenght)); - if (ret != null) { - this.setImageBufferSize(Integer.valueOf(ret)); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSaveStack = new JMenuItem("Save Stack"); - menuSaveStack.addActionListener((ActionEvent e) -> { - try { - saveStack(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetROI = new JMenuItem("Set ROI..."); - menuSetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); - renderer.addListener(new RendererListener() { - @Override - public void onSelectionFinished(Renderer renderer, Overlay overlay) { - try { - renderer.setShowReticle(false); - Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (server.isRoiEnabled()) { - int[] cur = server.getRoi(); - server.setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); - } else { - server.setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); - } - } catch (Exception ex) { - } finally { - renderer.removeListener(this); - } - } - - @Override - public void onSelectionAborted(Renderer renderer, Overlay overlay) { - renderer.removeListener(this); - } - }); - selection.setFixed(true); - renderer.startSelection(selection); - } - }); - - JMenuItem menuResetROI = new JMenuItem("Reset ROI"); - menuResetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - try { - renderer.setShowReticle(false); - server.resetRoi(); - } catch (IOException ex) { - showException(ex); - } - } - }); - - JCheckBoxMenuItem menuFrameIntegration = new JCheckBoxMenuItem("Multi-Frame", (integration != 0)); - menuFrameIntegration.addActionListener((ActionEvent e) -> { - if (integration == 0) { - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{150, 50}; //Minimum width - layout.rowHeights = new int[]{30, 30}; //Minimum height - panel.setLayout(layout); - JCheckBox checkContinuous = new JCheckBox(""); - JTextField textFrames = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Number of frames:"), c); - c.gridy = 1; - panel.add(new JLabel("Continuous:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(checkContinuous, c); - c.gridy = 0; - panel.add(textFrames, c); - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", panel, OptionType.OkCancel) == OptionResult.Yes) { - setIntegration(checkContinuous.isSelected() ? -(Integer.valueOf(textFrames.getText())) : (Integer.valueOf(textFrames.getText()))); - } - } else { - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", - "Do you want to disable " + ((integration < 0) ? "continuous " : "") + "multi-frame integration (" + Math.abs(integration) + ")?", OptionType.YesNo) == OptionResult.Yes) { - setIntegration(0); - } - } - }); - - for (Component cmp : SwingUtils.getComponentsByType(renderer.getPopupMenu(), JMenu.class)) { - JMenu menu = (JMenu) cmp; - if (menu.getText().equals("Integration")) { - menu.addSeparator(); - menu.add(menuFrameIntegration); - } - } - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuRendererConfig); - renderer.getPopupMenu().add(menuCameraConfig); - renderer.getPopupMenu().add(menuSetImageBufferSize); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuCalibrate); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuSetROI); - renderer.getPopupMenu().add(menuResetROI); - renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(server != null); - menuSetROI.setEnabled(server != null); - menuCalibrate.setVisible(server != null); - menuCalibrate.setEnabled((calibrationDialolg == null) || (!calibrationDialolg.isShowing())); - menuSaveStack.setEnabled(imageBufferLenght > 0); - menuSetImageBufferSize.setEnabled(!renderer.isPaused()); - menuFrameIntegration.setSelected(integration != 0); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - } - }); - renderer.getPopupMenu().setVisible(false); - clearMarker(); - - showFit = buttonFit.isSelected(); - showProfile = buttonProfile.isSelected(); - - pauseSelection.setVisible(false); - pauseSelection.setMinValue(1); - pauseSelection.addListener(new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - if (editing && (value >= 1) && (value <= imageBuffer.size())) { - updatePause(); - } - } - }); - renderer.addListener(new RendererListener() { - @Override - public void onMoveFinished(Renderer renderer, Overlay overlay) { - if (overlay == marker) { - try { - onMarkerChanged(); - } catch (IOException ex) { - Logger.getLogger(ScreenPanel3.class.getName()).log(Level.WARNING, null, ex); - } - } - } - }); - if (MainFrame.isDark()) { - textState.setDisabledTextColor(textState.getForeground()); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - - console = (!App.hasArgument("console")) ? null : new Console() { - /* - protected void onConsoleCommand(String name, String[] pars, String trimming) throws Exception { - switch (name) { - case "cam": - comboCameras.setSelectedItem(tokens[1]); - break; - } - }*/ - @Override - protected void onConsoleCommand(String command) { - String[] tokens = command.split(" "); - if ((tokens.length > 1) && tokens[0].equals("cam")){ - try{ - if (!tokens[1].equals(comboCameras.getSelectedItem())){ - setComboTypeSelection("All"); - updateCameraList(); - comboCameras.setSelectedItem(tokens[1]); - if (!tokens[1].equals(comboCameras.getSelectedItem())){ - throw new Exception("Invalid camera name : " + tokens[1]); - } - System.out.println("Console set camera: " + tokens[1]); - } - } catch (Exception ex){ - System.err.println(ex); - } - } else { - System.err.println("Invalid command: " + command); - } - } - }; - } - - void setIntegration(int frames) { - try { - if (integration != frames) { - integration = frames; - if (camera != null) { - if (Math.abs(integration) > 1) { - renderer.setDevice(new ImageIntegrator(integration)); - } else { - renderer.setDevice(camera); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - @Override - public void onStart() { - super.onStart(); - if (App.hasArgument("ct")) { - boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonServer.setSelected(!direct); - buttonDirect.setSelected(direct); - } - if (App.hasArgument("console")) { - console.start(); - } - } - - @Override - public void onStop() { - try { - if (camera != null) { - camera.close(); - camera = null; - server = null; - updateButtons(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - if (console != null) { - console.stop(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - super.onStop(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - comboType.setEnabled(false); - if (App.hasArgument("s")) { - renderer.setDevice((Source) getDevice("image")); - renderer.setAutoScroll(true); - ((Source) getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - manageFit(bi, data); - manageUserOverlays(bi, data); - } - - @Override - public void onError(Object o, Exception ex) { - } - } - ); - - } else { - usingServer = buttonServer.isSelected(); - updateCameraList(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - setComboCameraSelection(null); - setComboTypeSelection("All"); - - if (comboCameras.getModel().getSize() > 0) { - try { - if (App.hasArgument("cam")) { - setComboCameraSelection(App.getArgumentValue("cam")); - comboCamerasActionPerformed(null); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - updateButtons(); - startTimer(1000); - } - - boolean isVisible(String camera) { - return ((comboType.getSelectedIndex() == 0) || (getCameraType(camera).equals(comboType.getSelectedItem()))); - } - - DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - if (fromServer) { - try (PipelineServer srv = newServer()) { - srv.initialize(); - List cameras = srv.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - - } else { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - if (App.hasArgument("cam")) { - String camera = App.getArgumentValue("cam"); - if (model.getIndexOf(camera) < 0) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - model.addElement(""); - - return model; - } - - PipelineServer newServer() throws IOException { - if (serverUrl != null) { - System.out.println("Connecting to server: " + serverUrl); - server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl); - } else { - System.out.println("Connecting to server"); - server = new PipelineServer(CAMERA_DEVICE_NAME); - } - updateButtons(); - return server; - } - - boolean updatingCameraSelection; - - void setComboCameraSelection(Object selection) { - updatingCameraSelection = true; - try { - comboCameras.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - - void setComboTypeSelection(Object selection) { - updatingCameraSelection = true; - try { - comboType.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - boolean usingServer; - - void updateCameraList() { - try { - String selected = (String) comboCameras.getSelectedItem(); - comboCameras.setModel(getCameraList(usingServer)); - if (selected != null) { - if (((DefaultComboBoxModel) comboCameras.getModel()).getIndexOf(camera) < 0) { - setComboCameraSelection(selected); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - } - - final Object lockOverlays = new Object(); - - void manageFit(BufferedImage bi, Data data) { - Overlay[][] fo = null; - if ((showFit || showProfile)) { - try { - fo = getFitOverlays(data); - } catch (Exception ex) { - System.err.println(ex); - } - } - synchronized (lockOverlays) { - fo = (fo == null) ? new Overlay[][]{null, null} : fo; - renderer.updateOverlays(fo[0], profileOv); - profileOv = fo[0]; - renderer.updateOverlays(fo[1], fitOv); - fitOv = fo[1]; - } - } - - void manageUserOverlays(BufferedImage bi, Data data) { - Overlay[] fo = (bi == null) ? null : getUserOverlays(data); - synchronized (lockOverlays) { - renderer.updateOverlays(fo, userOv); - userOv = fo; - } - } - - void manageTitleOverlay() { - Overlay to = null; - if ((buttonTitle.isSelected()) && (cameraName != null)) { - Font font = new Font("Arial", Font.PLAIN, 28); - to = new Text(renderer.getPenErrorText(), cameraName, font, new Point(-SwingUtils.getTextSize(cameraName, renderer.getGraphics().getFontMetrics(font)).width - 14, 26)); - to.setFixed(true); - to.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - } - - synchronized (lockOverlays) { - renderer.updateOverlays(to, titleOv); - titleOv = to; - } - } - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - Thread devicesInitTask; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Initializing: " + cameraName); - parseUserOverlays(); - errorOverlay = null; - lastMarkerPos = null; - lastFrame = null; - lastPipelinePars = null; - - if (dataTableDialog != null) { - dataTableDialog.dispose(); - dataTableDialog = null; - } - dataTableModel = null; - - if (calibrationDialolg != null) { - calibrationDialolg.dispose(); - calibrationDialolg = null; - } - - boolean was_server = false; - if (camera != null) { - //camera.removeAllListeners(); - was_server = (server != null); - camera.close(); - camera = null; - server = null; - } - updateButtons(); - instanceName = null; - renderer.setDevice(null); - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.removeOverlays(profileOv); - renderer.removeOverlays(userOv); - renderer.clear(); - renderer.resetZoom(); - - boolean changed = !String.valueOf(cameraName).equals(this.cameraName); - this.cameraName = cameraName; - - if (changed || buttonDirect.isSelected()) { - spinnerThreshold.setVisible(false); - checkThreshold.setEnabled(false); - checkGoodRegion.setEnabled(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - if (changed) { - checkBackground.setEnabled(false); - if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { - devicesInitTask.interrupt(); - } - if (screen != null) { - screen.close(); - screen = null; - } - if (filter != null) { - filter.close(); - filter = null; - } - if (renderer.isPaused()) { - renderer.resume(); - removePauseOverlay(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - manageTitleOverlay(); - if (App.isDetached()) { - getTopLevel().setTitle(cameraName == null ? "ScreenPanel" : cameraName); - } - if (cameraName == null) { - return; - } - - System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]"); - try { - if (buttonServer.isSelected()) { - camera = newServer(); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - //camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName); - camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName}); - } - camera.initialize(); - camera.assertInitialized(); - System.out.println("Camera initialization OK"); - if (server != null) { - //server.start(cameraName, false); - String pipelineName = cameraName + pipelineSuffix; - instanceName = cameraName + pipelineSuffix + "1"; - if (!server.getPipelines().contains(pipelineName)) { - System.out.println("Creating pipeline: " + pipelineName); - HashMap config = new HashMap<>(); - config.put("camera_name", cameraName); - //server.createFromConfig(config, pipelineName); - server.savePipelineConfig(pipelineName, config); - } - server.start(pipelineName, instanceName); - - updatePipelineControls(); - checkThreshold.setEnabled(true); - checkGoodRegion.setEnabled(true); - } else { - checkThreshold.setSelected(false); - checkGoodRegion.setSelected(false); - if (polling <= 0) { - camera.setMonitored(true); - } else { - camera.setPolling(polling); - } - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - updateButtons(); - camera.getConfig().save(); - if (Math.abs(integration) > 1) { - renderer.setDevice(new ImageIntegrator(integration)); - } else { - renderer.setDevice(camera); - } - renderer.setAutoScroll(true); - //renderer.setMarker(marker); - clearMarker(); - imageSize = null; - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi != null) { - if ((imageSize == null) || imageSize.width != bi.getWidth() || imageSize.height != bi.getHeight()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { - centralizeRenderer(); - } - checkReticle(); - } - }); - imageSize = new Dimension(bi.getWidth(), bi.getHeight()); - } - renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); - } - //renderer.setCalibration(camera.getCalibration()); - if (!renderer.isPaused()) { - if (data != null) { - synchronized (imageBuffer) { - currentFrame = new Frame(data); - if (imageBufferLenght >= 1) { - imageBuffer.add(currentFrame); - if (imageBuffer.size() > imageBufferLenght) { - imageBuffer.remove(0); - } - } - //Update data - if (!renderer.isPaused()) { - updateStreamData(); - } - updateMarker(); - } - } - manageFit(bi, data); - manageUserOverlays(bi, data); - } - //updateImageData(); - } - - @Override - public void onError(Object o, Exception ex) { - //System.err.println(ex); - } - }); - - } catch (Exception ex) { - showException(ex); - renderer.clearOverlays(); - updatePipelineControls(); - if (renderer.getDevice() == null) { - //renderer.setZoom(1.0); - //renderer.setMode(RendererMode.Zoom); - errorOverlay = new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - errorOverlay.setFixed(true); - errorOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - renderer.addOverlay(errorOverlay); - } - } finally { - //checkReticle(); - onTimer(); - } - onChangeColormap(null); - checkBackground.setEnabled(true); - if (changed) { - boolean electrons = getCameraType(cameraName).equals(ELECTRONS_TYPE); - comboScreen.setModel(new DefaultComboBoxModel()); - comboScreen.setEnabled(false); - comboFilter.setModel(new DefaultComboBoxModel()); - comboFilter.setEnabled(false); - panelFilter.setVisible(electrons); - panelScreen.setVisible(electrons); - if (electrons) { - //Parallelizing initialization - devicesInitTask = new Thread(() -> { - try { - if (cameraName.contains("DSRM")) { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); - } else { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); - } - screen.setMonitored(true); - screen.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : screen.getPositions()) { - model.addElement(pos); - } - comboScreen.setModel(model); - comboScreen.setSelectedItem(screen.read()); - - } catch (Exception ex) { - comboScreen.setModel(new DefaultComboBoxModel()); - System.err.println(ex.getMessage()); - screen = null; - } - comboScreen.setEnabled(screen != null); - valueScreen.setDevice(screen); - - try { - filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); - filter.setMonitored(true); - filter.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : filter.getPositions()) { - model.addElement(pos); - } - comboFilter.setModel(model); - comboFilter.setSelectedItem(filter.read()); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - filter = null; - } - comboFilter.setEnabled(filter != null); - valueFilter.setDevice(filter); - }); - devicesInitTask.start(); - } - } - } - - class ImageIntegrator extends ColormapSource { - - ImageIntegrator(int num) { - super("Image Averager", camera.getConfig()); - boolean continuous = (num < 0); - final int numImages = Math.abs(num); - - camera.addListener(new ImageListener() { - final ArrayList buffer = new ArrayList(); - Data integration = null; - - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (continuous) { - buffer.add(data); - if (buffer.size() >= numImages) { - for (Data d : buffer) { - process(d); - } - } - } else { - buffer.add(null); //Just to count - process(data); - } - if (buffer.size() >= numImages) { - if (continuous) { - buffer.remove(0); - } else { - buffer.clear(); - } - if (integration != null) { - //integration.div(numImages); - ImageIntegrator.this.pushData(integration); - } - integration = null; - } - } - - void process(Data data) { - if (integration == null) { - integration = new Data(data); - } else { - integration.sum(data); - } - } - - @Override - public void onError(Object origin, Exception ex) { - } - }); - - } - } - - volatile Dimension imageSize; - - void checkReticle() { - if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) { - //renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800, 800), 200); - renderer.setShowReticle(true); - } else { - //renderer.setCalibration(null); - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - void checkMarker(Point p) throws IOException { - if (camera != null) { - if (buttonMarker.isSelected()) { - Dimension d = renderer.getImageSize(); - if (p==null){ - p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - } - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - marker.setPassive(false); - } else { - marker = null; - } - renderer.setMarker(marker); - onMarkerChanged(); - } - } - - Point lastMarkerPos; - void onMarkerChanged() throws IOException { - lastMarkerPos = getStreamMarkerPos(); - if (marker == null) { - setInstanceConfigValue("Marker", null); - } else { - setInstanceConfigValue("Marker", new int[]{marker.getPosition().x, marker.getPosition().y}); - } - } - - void updateMarker() { - try { - if (server != null) { - Point p = getStreamMarkerPos(); - if (p != null) { - //To prevent a local change being overriden by a message having the old settings. - //TODO: This is not bullet-proof, as one can have 2 changes between 2 frames... - if (!p.equals(lastMarkerPos)){ - if (p.x == Integer.MIN_VALUE) { - if (buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - checkMarker(null); - } - } else { - if (!buttonMarker.isSelected()) { - buttonMarker.setSelected(true); - checkMarker(p); - } else { - if (!p.equals(marker.getPosition())){ - marker.setPosition(p); - } - } - } - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - Point getStreamMarkerPos() throws IOException{ - //System.out.println(server.getInstanceConfig().get("Marker")); - Map pars = server.getProcessingParameters(); - if (pars != null) { - List markerPosition = (List) pars.get("Marker"); - if (markerPosition != null) { - return new Point((Integer)markerPosition.get(0), (Integer)markerPosition.get(1)); - } - return new Point(Integer.MIN_VALUE,Integer.MIN_VALUE); - } - return null; - } - void clearMarker(){ - marker = null; - renderer.setMarker(marker); - } - - void setInstanceConfigValue(String name, Object value) throws IOException { - if (server != null) { - Map map = server.getInstanceConfig(); - map.put(name, value); - server.setInstanceConfig(map); - } - } - - void updateZoom() { - try { - buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom) { - if (renderer.getZoom() == 1) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getZoom() == 0.5) { - buttonZoom05.setSelected(true); - } else if (renderer.getZoom() == 0.25) { - buttonZoom025.setSelected(true); - } else if (renderer.getZoom() == 2.0) { - buttonZoom2.setSelected(true); - } else { - buttonGroup1.clearSelection(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - boolean updatingColormap; - - void updateColormap() { - updatingColormap = true; - try { - if ((camera != null) && (camera instanceof ColormapSource)) { - ColormapSourceConfig config = ((ColormapSource) camera).getConfig(); - comboColormap.setSelectedItem(config.colormap); - if (config.isDefaultColormap()) { - buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic) { - buttonAutomatic.setSelected(true); - } else { - buttonManual.setSelected(true); - } - btFixColormapRange.setVisible(buttonAutomatic.isSelected()); - spinnerMin.setEnabled(buttonManual.isSelected()); - spinnerMax.setEnabled(buttonManual.isSelected()); - if (!Double.isNaN(config.colormapMin)) { - spinnerMin.setValue(Math.min(Math.max((int) config.colormapMin, 0), 65535)); - } - if (!Double.isNaN(config.colormapMax)) { - spinnerMax.setValue(Math.min(Math.max((int) config.colormapMax, 0), 65535)); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatingColormap = false; - } - - void updatePipelineProperties(){ - goodRegion = checkGoodRegion.isSelected(); - spinnerThreshold.setVisible(checkThreshold.isSelected()); - setGoodRegionOptionsVisible(goodRegion); - slicing = goodRegion && checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - updatingServerControls = false; - } - - boolean updatingServerControls; - - void updatePipelineControls() { - if (server != null) { - updatingServerControls = true; - if (server.isStarted()){ - try { - checkBackground.setSelected(server.getBackgroundSubtraction()); - Double threshold = (server.getThreshold()); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (server.getGoodRegion()); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - spinnerGrThreshold.setValue(((Number) gr.get("threshold")).doubleValue()); - spinnerGrScale.setValue(((Number) gr.get("gfscale")).doubleValue()); - } - Map slicing = (server.getSlicing()); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - spinnerSlNumber.setValue(((Number) slicing.get("number_of_slices")).intValue()); - spinnerSlScale.setValue(((Number) slicing.get("scale")).doubleValue()); - spinnerSlOrientation.setValue((String) slicing.get("orientation")); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - updatePipelineProperties(); - } - } - - boolean changedPipelinePars(Map pars1, Map pars2) { - String[] keys = new String[]{"image_background_enable", "image_threshold", "image_good_region", - "threshold", "gfscale", "image_slices", "number_of_slices", "scale", "orientation"}; - for (String key:keys){ - Object o1 = pars1.get(key); - Object o2 = pars2.get(key); - if (o1==null){ - if (o2!=null){ - return true; - } - } else if (!o1.equals(o2)){ - return true; - } - } - return false; - } - - void updatePipelineControls(Map pars) { - if (pars!=null){ - updatingServerControls = true; - try { - boolean background = (boolean) pars.get("image_background_enable"); - checkBackground.setSelected(background); - Double threshold = (Double) (pars.get("image_threshold")); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (Map) pars.get("image_good_region"); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - Double value = ((Number) gr.get("threshold")).doubleValue(); - spinnerGrThreshold.setValue(value); - Double scale = ((Number) gr.get("gfscale")).doubleValue(); - spinnerGrScale.setValue(scale); - } - Map slicing = (Map) (pars.get("image_slices")); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - int slices = ((Number) slicing.get("number_of_slices")).intValue(); - spinnerSlNumber.setValue(slices); - double scale = ((Number) slicing.get("scale")).doubleValue(); - spinnerSlScale.setValue(scale); - String orientation = (String) slicing.get("orientation"); - spinnerSlOrientation.setValue(orientation); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatePipelineProperties(); - } - } - - void setGoodRegionOptionsVisible(boolean visible) { - spinnerGrThreshold.setVisible(visible); - labelGrThreshold.setVisible(visible); - spinnerGrScale.setVisible(visible); - labelGrScale.setVisible(visible); - panelSlicing.setVisible(visible); - } - - void setSlicingOptionsVisible(boolean visible) { - spinnerSlNumber.setVisible(visible); - labelSlNumber.setVisible(visible); - spinnerSlScale.setVisible(visible); - labelSlScale.setVisible(visible); - spinnerSlOrientation.setVisible(visible); - labelSlOrientation.setVisible(visible); - } - - boolean isCameraStopped() { - if ((server != null) && !server.isStarted()) { - return true; - } - return ((camera == null) || camera.isClosed()); - } - - boolean updatingButtons; - - void updateButtons() { - updatingButtons = true; - try { - boolean active = !isCameraStopped();//(camera != null); - buttonSave.setEnabled(active); - buttonGrabBackground.setEnabled(active); - buttonMarker.setEnabled(active); - buttonProfile.setEnabled(active); - buttonFit.setEnabled(active); - buttonReticle.setEnabled(active && camera.getConfig().isCalibrated()); - buttonStreamData.setEnabled(active && (server != null)); - buttonPause.setEnabled(active); - - if (renderer.isPaused() != buttonPause.isSelected()) { - buttonPause.setSelected(renderer.isPaused()); - buttonPauseActionPerformed(null); - } - if (renderer.getShowReticle() != buttonReticle.isSelected()) { - //buttonReticle.setSelected(renderer.getShowReticle()); - } - if ((renderer.getMarker() == null) && buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - } - buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - - } finally { - updatingButtons = false; - } - } - - Frame lastFrame = null; - Map lastPipelinePars = null; - - - @Override - protected void onTimer() { - for (Device dev : new Device[]{screen, filter}) { - if (dev != null) { - dev.request(); - } - } - - textState.setText((camera == null) ? "" : camera.getState().toString()); - if (App.hasArgument("s")) { - try { - ((Source) getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } - } - updateZoom(); - updateColormap(); - updateButtons(); - checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); - - try{ - Frame frame = getCurrentFrame(); - if (frame!=lastFrame){ - lastFrame = frame; - if (frame!=null){ - Map pars = getProcessingParameters(frame.cache); - if((lastPipelinePars==null) || changedPipelinePars(pars, lastPipelinePars)){ - //System.out.println("Update pipeline: " + pars); - lastPipelinePars = pars; - updatePipelineControls(pars); - } - } - } - } catch (Exception ex){ - ex.printStackTrace(); - } - } - - Pen penFit = new Pen(new Color(192, 105, 0), 0); - Pen penCross = new Pen(new Color(192, 105, 0), 0); - Pen penSlices = new Pen(Color.CYAN.darker(), 1); - - Frame getCurrentFrame() { - if ((imageBufferLenght > 1) && (renderer.isPaused())) { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - return (index < imageBuffer.size()) ? imageBuffer.get(index) : null; - } - } - return currentFrame; - } - - Frame getFrame(Data data) { - synchronized (imageBuffer) { - for (Frame f : imageBuffer) { - if (f.data == data) { - return f; - } - } - } - return null; - } - - void setImageBufferSize(int size) { - if (renderer.isPaused()) { - throw new RuntimeException("Cannot change buffer size whn paused"); - } - synchronized (imageBuffer) { - imageBufferLenght = size; - imageBuffer.clear(); - } - - } - - Overlay[][] getFitOverlays(Data data) { - Overlays.Polyline hgaussian = null; - Overlays.Polyline vgaussian = null; - Overlays.Polyline hprofile = null; - Overlays.Polyline vprofile = null; - Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null; - Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null; - double[] pX = null, pY = null, gX = null, gY = null; - PointDouble[] sliceCenters = null; - if (data != null) { - int height = data.getHeight(); - int width = data.getWidth(); - int profileSize = renderer.getProfileSize(); - if ((useServerStats) && (server != null)) { - try { - - ImageData id = getFrame(data); - if (id == null) { - return null; - } - xMean = id.x_fit_mean; - xSigma = id.x_fit_standard_deviation; - yMean = id.y_fit_mean; - ySigma = id.y_fit_standard_deviation; - gX = id.x_fit_gauss_function; - gY = id.y_fit_gauss_function; - pX = id.x_profile; - pY = id.y_profile; - xCom = id.x_center_of_mass; - xRms = id.x_rms; - yCom = id.y_center_of_mass; - yRms = id.y_rms; - sliceCenters = id.sliceCenters; - - profileSize /= 4; - if (pX != null) { - int[] xp = Arr.indexesInt(pX.length); - int[] xg = xp; - int[] yp = new int[pX.length]; - int[] yg = new int[pX.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_x > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gX, id.gr_pos_x, id.gr_pos_x + id.gr_size_x))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gX != null) { - yg[i] = (int) (height - 1 - (((gX[i] - minGauss) / rangeGauss) * profileSize)); - } - yp[i] = (int) (height - 1 - (((pX[i] - minProfile) / rangeProfile) * profileSize)); - } - - if (goodRegion && id.gr_size_x > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - yg = Arrays.copyOfRange(yg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - } - - vgaussian = new Overlays.Polyline(penFit, xg, yg); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - - if (pY != null) { - int[] xp = new int[pY.length]; - int[] xg = new int[pY.length]; - int[] yp = Arr.indexesInt(pY.length); - int[] yg = yp; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_y > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gY, id.gr_pos_y, id.gr_pos_y + id.gr_size_y))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gY != null) { - xg[i] = (int) (((gY[i] - minGauss) / rangeGauss) * profileSize); - } - xp[i] = (int) (((pY[i] - minProfile) / rangeProfile) * profileSize); - } - - if (goodRegion && id.gr_size_x > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - yg = Arrays.copyOfRange(yg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - } - hgaussian = new Overlays.Polyline(penFit, xg, yg); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - return null; - } - } else { - ArrayProperties properties = data.getProperties(); - double maxPlot = properties.max; - double minPlot = properties.min; - double rangePlot = maxPlot - minPlot; - - if (rangePlot <= 0) { - return null; - } - if (renderer.getCalibration() != null) { - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height - minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - if (xSigma != null) { - xSigma *= renderer.getCalibration().getScaleX(); - } - if (ySigma != null) { - ySigma *= renderer.getCalibration().getScaleY(); - } - if (xMean != null) { - xMean = data.getX((int) Math.round(xMean)); - } - if (yMean != null) { - yMean = data.getY((int) Math.round(yMean)); - } - } - } - final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px"; - final String fmt = "%7.1f" + units; - Overlays.Text textCom = null; - Overlay[] pOv = null, fOv = null; - Font fontInfoText = new Font(Font.MONOSPACED, 0, 14); - Point textPosition = new Point(12, 20); - if (showProfile) { - if ((xCom != null) && (yCom != null)) { - String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt, xCom, xRms, yCom, yRms); - textCom = new Overlays.Text(renderer.getPenProfile(), text, fontInfoText, textPosition); - textCom.setFixed(true); - textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - } - pOv = new Overlay[]{hprofile, vprofile, textCom}; - textPosition = new Point(textPosition.x, textPosition.y + 34); - } - if (showFit) { - Overlays.Crosshairs cross = null; - Overlays.Text textFit = null; - if ((xMean != null) && (yMean != null)) { - String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt, xMean, xSigma, yMean, ySigma); - textFit = new Overlays.Text(penFit, text, fontInfoText, textPosition); - textFit.setFixed(true); - textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - Point center = new Point(xMean.intValue(), yMean.intValue()); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean)); - xSigma /= renderer.getCalibration().getScaleX(); - ySigma /= renderer.getCalibration().getScaleY(); - } - cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue()))); - } - textPosition = new Point(textPosition.x, textPosition.y + 34); - fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit}; - - if (goodRegion) { - try { - double[] x = getServerDoubleArray("gr_x_axis"); - double[] y = getServerDoubleArray("gr_y_axis"); - double x1 = x[0]; - double x2 = x[x.length - 1]; - double y1 = y[0]; - double y2 = y[y.length - 1]; - Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); - goodRegionOv.setCalibration(renderer.getCalibration()); - goodRegionOv.setAbsolutePosition(new PointDouble(x1, y1)); - goodRegionOv.setAbsoluteSize(new DimensionDouble(x2 - x1, y2 - y1)); - fOv = Arr.append(fOv, goodRegionOv); - - if (slicing) { - if (sliceCenters != null) { - for (PointDouble sliceCenter : sliceCenters) { - Overlays.Crosshairs center = new Overlays.Crosshairs(penSlices); - center.setCalibration(renderer.getCalibration()); - center.setAbsolutePosition(sliceCenter); - center.setSize(new Dimension(10, 10)); - fOv = Arr.append(fOv, center); - } - if (sliceCenters.length > 1) { - double[] fit = fitPolynomial(sliceCenters, 1); - double angle = Math.toDegrees(Math.atan(fit[1])); - Overlays.Text text = new Overlays.Text(penSlices, String.format("slice: \u03B8= %5.1fdeg", angle), fontInfoText, textPosition); - text.setFixed(true); - text.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - fOv = Arr.append(fOv, text); - } - } - } - } catch (Exception ex) { - } - } - - } - return new Overlay[][]{pOv, fOv}; - } - return null; - } - - class UserOverlay { - - String name; - Overlay obj; - String[] channels; - } - ArrayList userOverlayConfig; - - void parseUserOverlays() { - Properties userOverlays = new Properties(); - userOverlayConfig = new ArrayList<>(); - if (userOverlaysConfigFile != null) { - try { - try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { - userOverlays.load(in); - - for (String name : userOverlays.stringPropertyNames()) { - String val = userOverlays.getProperty(name); - try { - UserOverlay uo = new UserOverlay(); - uo.name = name; - String type = val.substring(0, val.indexOf("(")).trim(); - String pars = val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")).trim(); - String[] tokens = pars.split(","); - for (int i = 0; i < tokens.length; i++) { - tokens[i] = tokens[i].trim(); - } - Color color = Color.GRAY; - try { - color = (Color) Color.class.getField(tokens[tokens.length - 1].toUpperCase()).get(null); - } catch (Exception ex) { - } - Pen pen = new Pen(color); - try { - String[] penTokens = tokens[tokens.length - 1].split(":"); - color = (Color) Color.class.getField(penTokens[0].toUpperCase()).get(null); - int width = Integer.valueOf(penTokens[1]); - Pen.LineStyle style = Pen.LineStyle.valueOf(penTokens[2]); - pen = new Pen(color, width, style); - } catch (Exception ex) { - } - switch (type) { - case "Point": - uo.obj = new Overlays.Crosshairs(); - uo.obj.setSize(new Dimension(Integer.valueOf(tokens[2]), Integer.valueOf(tokens[3]))); - break; - case "Line": - uo.obj = new Overlays.Line(); - break; - case "Arrow": - uo.obj = new Overlays.Arrow(); - break; - case "Rect": - uo.obj = new Overlays.Rect(); - break; - case "Ellipse": - uo.obj = new Overlays.Ellipse(); - break; - case "Polyline": - uo.obj = new Overlays.Polyline(); - break; - } - if (type.equals("Polyline") || type.equals("Point")) { - uo.channels = new String[]{tokens[0], tokens[1]}; - } else { - uo.channels = new String[]{tokens[0], tokens[1], tokens[2], tokens[3]}; - } - uo.obj.setPen(pen); - userOverlayConfig.add(uo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - Overlay[] getUserOverlays(Data data) { - ArrayList ret = new ArrayList<>(); - if (server != null) { - for (UserOverlay uo : userOverlayConfig) { - try { - Overlay ov = uo.obj; - //Overlay ov = (Overlay)uo.cls.newInstance(); - ov.setCalibration(renderer.getCalibration()); - boolean valid = false; - if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : getServerDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : getServerDoubleArray(uo.channels[1]); - if ((x != null) || (y != null)) { - if (x == null) { - x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); - } - if (y == null) { - y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length); - } - ((Overlays.Polyline) ov).updateAbsolute(x, y); - valid = true; - } - } else { - Double x = getServerDouble(uo.channels[0]); - Double y = getServerDouble(uo.channels[1]); - if ((x != null) && (y != null)) { - PointDouble position = new PointDouble(x, y); - ov.setAbsolutePosition(position); - if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = getServerDouble(uo.channels[2]); - Double y2 = getServerDouble(uo.channels[3]); - if ((x != null) && (y != null)) { - DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); - ov.setAbsoluteSize(size); - valid = true; - } - } else { - valid = true; - } - } - } - if (valid) { - ret.add(ov); - } - } catch (Exception ex) { - //ex.printStackTrace(); - } - } - } - return ret.toArray(new Overlay[0]); - } - - double[] getComRms(double[] arr, double[] x) { - if (arr != null) { - double xmd = 0; - double xmd2 = 0; - double total = 0; - for (int i = 0; i < arr.length; i++) { - double v = (arr[i] * x[i]); - xmd += v; - xmd2 += (v * x[i]); - total += arr[i]; - } - if (total > 0) { - double com = xmd / total; - double com2 = xmd2 / total; - double rms = Math.sqrt(Math.abs(com2 - com * com)); - return new double[]{com, rms}; - } - } - return new double[]{Double.NaN, Double.NaN}; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] fitPolynomial(PointDouble[] points, int order) { - double[] y = new double[points.length]; - double[] x = new double[points.length]; - for (int i = 0; i < points.length; i++) { - x[i] = points[i].x; - y[i] = points[i].y; - } - return fitPolynomial(y, x, order); - } - - double[] fitPolynomial(double[] y, double[] x, int order) { - try { - ArrayProperties pY = ArrayProperties.get(y); - PolynomialCurveFitter fitter = PolynomialCurveFitter.create(order).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - void setHistogramVisible(boolean value) { - if (value) { - if ((histogramDialog == null) || (!histogramDialog.isShowing())) { - Histogram histogram = new Histogram(true); - histogram.setRenderer(renderer); - histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram); - renderer.refresh(); - } - } else { - if (histogramDialog != null) { - histogramDialog.setVisible(false); - histogramDialog = null; - } - } - } - - void setLaserState(boolean value) throws Exception { - System.out.println("Setting laser state: " + value); - Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); - Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); - Thread.sleep(3000); - } - - boolean getLaserState() throws Exception { - return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); - } - - void elog(String logbook, String title, String message, String[] attachments) throws Exception { - String domain = ""; - String category = "Info"; - String entry = ""; - StringBuffer cmd = new StringBuffer(); - - cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); - cmd.append("-a \"Author=ScreenPanel\" "); - cmd.append("-a \"Type=pshell\" "); - cmd.append("-a \"Entry=").append(entry).append("\" "); - cmd.append("-a \"Title=").append(title).append("\" "); - cmd.append("-a \"Category=").append(category).append("\" "); - cmd.append("-a \"Domain=").append(domain).append("\" "); - for (String attachment : attachments) { - cmd.append("-f \"").append(attachment).append("\" "); - } - cmd.append("-n 1 "); - cmd.append("\"").append(message).append("\" "); - System.out.println(cmd.toString()); - - final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); - new Thread(() -> { - try { - process.waitFor(); - int bytes = process.getInputStream().available(); - byte[] arr = new byte[bytes]; - process.getInputStream().read(arr, 0, bytes); - System.out.println(new String(arr)); - bytes = process.getErrorStream().available(); - arr = new byte[bytes]; - process.getErrorStream().read(arr, 0, bytes); - System.err.println(new String(arr)); - } catch (Exception ex) { - System.err.println(ex); - } - }).start(); - } - - void centralizeRenderer() { - Point center = null; - Dimension size = renderer.getImageSize(); - double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom(); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().getCenter(); - } else if (size != null) { - center = new Point(size.width / 2, size.height / 2); - } - if (center != null) { - Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0), - Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0)); - renderer.setViewPosition(topleft); - } - } - - void updatePause() { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - if (index < imageBuffer.size()) { - Data data = imageBuffer.get(index).data; - long pid = imageBuffer.get(index).cache.getPulseId(); - BufferedImage image = camera.generateImage(data); - renderer.setImage(renderer.getOrigin(), image, data); - - String text = "PID: " + pid; - if (imagePauseOverlay == null) { - Font font = new Font("Verdana", Font.PLAIN, 12); - Dimension d = SwingUtils.getTextSize(text, renderer.getFontMetrics(font)); - imagePauseOverlay = new Text(renderer.getPenErrorText(), "", font, new Point(-20 - d.width, 42)); - imagePauseOverlay.setFixed(true); - imagePauseOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - renderer.addOverlay(imagePauseOverlay); - } - //imagePauseOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS")); - imagePauseOverlay.update(text); - manageFit(image, data); - manageUserOverlays(image, data); - } - } - updateStreamData(); - } - - void removePauseOverlay() { - renderer.removeOverlay(imagePauseOverlay); - imagePauseOverlay = null; - } - - void saveSnapshot() throws Exception { - String snapshotFile = null; - synchronized (imageBuffer) { - Frame frame = getCurrentFrame(); - if (frame == null) { - throw new Exception("No current image"); - } - ArrayList frames = new ArrayList<>(); - frames.add(frame); - this.saveFrames(cameraName + "_camera_snapshot", frames); - - //Enforce the same timestamp to data & image files. - snapshotFile = getContext().getExecutionPars().getPath() + ".png"; - ImageBuffer.saveImage(SwingUtils.createImage(renderer), snapshotFile, "png"); - } - - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{0, 180}; //Minimum width - layout.rowHeights = new int[]{30, 30, 30}; //Minimum height - panel.setLayout(layout); - JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); - JTextField textComment = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Data file:"), c); - c.gridy = 1; - panel.add(new JLabel("Logbook:"), c); - c.gridy = 2; - panel.add(new JLabel("Comment:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(textComment, c); - c.gridy = 1; - panel.add(comboLogbook, c); - c.gridy = 0; - panel.add(new JLabel(getContext().getExecutionPars().getPath()), c); - - if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes) { - StringBuilder message = new StringBuilder(); - message.append("Camera: ").append(cameraName).append(" ("). - append((server != null) ? "server" : "direct").append(")").append("\n"); - message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); - message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); - message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); - message.append("Comment: ").append(textComment.getText()).append("\n"); - //Add slicing message - if ((fitOv != null) && (fitOv.length > 5) && (fitOv[fitOv.length-1] instanceof Overlays.Text)) { - Overlays.Text text = (Overlays.Text) fitOv[fitOv.length-1]; - message.append(text.getText()).append("\n"); - } - elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - } - - void saveStack() throws Exception { - synchronized (imageBuffer) { - saveFrames(cameraName + "_camera_stack", imageBuffer); - } - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath()); - } - - public static String getCameraType(String name) { - if (name == null) { - return ""; - } - for (String s : new String[]{"LCAM"}) { - if (name.contains(s)) { - return LASER_TYPE; - } - } - for (String s : new String[]{"DSCR", "DSRM", "DLAC"}) { - if (name.contains(s)) { - return ELECTRONS_TYPE; - } - } - for (String s : new String[]{"PROF", "PPRM", "PSSS", "PSCR", "PSRD"}) { - if (name.contains(s)) { - return PHOTONICS_TYPE; - } - } - return "Unknown"; - } - - public Map getProcessingParameters(StreamValue value) throws IOException { - return (Map) JsonSerializer.decode(value.getValue("processing_parameters").toString(), Map.class); - } - - void saveFrames(String name, ArrayList frames) throws IOException { - ArrayList values = new ArrayList<>(); - for (Frame frame : frames) { - values.add(frame.cache); - } - saveImages(name, values); - } - - void saveImages(String name, ArrayList images) throws IOException { - int depth = images.size(); - if (depth == 0) { - return; - } - StreamValue first = images.get(0); - String pathRoot = "/camera1/"; - String pathImage = pathRoot + "image"; - String pathPid = pathRoot + "pulse_id"; - String pathTimestampStr = pathRoot + "timestamp_str"; - Map processingPars = getProcessingParameters(first); - String camera = (String) processingPars.get("camera_name"); - String type = getCameraType(camera); - - int width = ((Number) first.getValue("width")).intValue(); - int height = ((Number) first.getValue("height")).intValue(); - Class dataType = first.getValue("image").getClass().getComponentType(); - - getContext().setExecutionPars(name); - DataManager dm = getContext().getDataManager(); - - //Create tables - dm.createDataset(pathImage, dataType, new int[]{depth, height, width}); - dm.createDataset(pathPid, Long.class, new int[]{depth}); - dm.createDataset(pathTimestampStr, String.class, new int[]{depth}); - for (String id : first.getIdentifiers()) { - Object val = first.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(first); - for (String key : pars.keySet()) { - if ((pars.get(key) != null) && (pars.get(key) instanceof Map)) { - for (Object k : ((Map) pars.get(key)).keySet()) { - Object v = ((Map) pars.get(key)).get(k); - dm.setAttribute(pathImage, key + " " + k, (v == null) ? "" : v); - } - } else { - Object value = pars.get(key); - if (value == null) { - value = ""; - } else if (value instanceof List) { - Class cls = (((List) value).size() > 0) ? ((List) value).get(0).getClass() : double.class; - value = Convert.toPrimitiveArray(value, cls); - //value = Convert.toDouble(value); - } - dm.setAttribute(pathImage, key, value); - } - } - } else if (val.getClass().isArray()) { - dm.createDataset(pathRoot + id, Double.class, new int[]{depth, Array.getLength(val)}); - } else { - dm.createDataset(pathRoot + id, val.getClass(), new int[]{depth}); - } - } - - //Add metadata - dm.setAttribute(pathRoot, "Camera", camera); - dm.setAttribute(pathRoot, "Images", depth); - dm.setAttribute(pathRoot, "Interval", -1); - dm.setAttribute(pathRoot, "Type", type); - if (type.equals(ELECTRONS_TYPE)) { - dm.setAttribute(pathRoot, "Screen", String.valueOf(valueScreen.getLabel().getText())); - dm.setAttribute(pathRoot, "Filter", String.valueOf(valueFilter.getLabel().getText())); - } - - //Save data - for (int index = 0; index < depth; index++) { - StreamValue streamValue = images.get(index); - dm.setItem(pathImage, streamValue.getValue("image"), new long[]{index, 0, 0}, new int[]{1, height, width}); - dm.setItem(pathPid, streamValue.getPulseId(), index); - dm.setItem(pathTimestampStr, Chrono.getTimeStr(streamValue.getTimestamp(), "YYYY-MM-dd HH:mm:ss.SSS"), index); - - for (String id : streamValue.getIdentifiers()) { - Object val = streamValue.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - } else if (val.getClass().isArray()) { - dm.setItem(pathRoot + id, val, index); - } else { - dm.setItem(pathRoot + id, val, index); - } - } - } - getContext().getDataManager().closeOutput(); - } - - StandardDialog calibrationDialolg; - - void calibrate() throws Exception { - if (server != null) { - server.resetRoi(); - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraCalibrationDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), server.getCurrentCamera(), renderer}); - SwingUtils.centerComponent(getTopLevel(), calibrationDialolg); - calibrationDialolg.setVisible(true); - calibrationDialolg.setListener(new StandardDialogListener() { - @Override - public void onWindowOpened(StandardDialog dlg) { - } - - @Override - public void onWindowClosed(StandardDialog dlg, boolean accepted) { - if (accepted) { - //comboCamerasActionPerformed(null); - } - } - }); - } - } - - StandardDialog dataTableDialog; - DefaultTableModel dataTableModel; - JTable dataTable; - - void showStreamData() { - dataTableModel = null; - if (server != null) { - - if ((dataTableDialog != null) && (dataTableDialog.isShowing())) { - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.requestFocus(); - return; - } - dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) { - public Class getColumnClass(int columnIndex) { - return String.class; - } - - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - }; - updateStreamData(); - StreamValue val = server.getStream().take(); - dataTable = new JTable(dataTableModel); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.setCellSelectionEnabled(true); - dataTable.getTableHeader().setReorderingAllowed(false); - dataTable.getTableHeader().setResizingAllowed(true); - dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); - dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(dataTable); - scrollPane.setPreferredSize(new Dimension(300, 400)); - dataTableDialog.setContentPane(scrollPane); - dataTableDialog.pack(); - dataTableDialog.setVisible(true); - dataTableDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - dataTableModel = null; - } - }); - dataTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - try { - int row = dataTable.getSelectedRow(); - int col = dataTable.getSelectedColumn(); - dataTable.setToolTipText(null); - if (row > 1) { - String id = String.valueOf(dataTable.getModel().getValueAt(row, 0)); - String locator = String.valueOf(dataTable.getModel().getValueAt(0, 1)); - String channelId = locator + " " + id; - dataTable.setToolTipText(channelId); - if ((e.getClickCount() == 2) && (!e.isPopupTrigger())) { - if (col == 0) { - SwingUtils.showMessage(dataTableDialog, "Channel Identifier", "Copied to clipboard: " + channelId); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - clipboard.setContents(new StringSelection(channelId), (Clipboard clipboard1, Transferable contents) -> { - }); - } else { - Object obj = getCurrentFrame().cache.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(getCurrentFrame().cache); - StringBuilder sb = new StringBuilder(); - for (String key : pars.keySet()) { - sb.append(key).append(" = ").append(Str.toString(pars.get(key), 10)).append("\n"); - } - SwingUtils.showMessage(dataTableDialog, "Processing Parameters", sb.toString()); - } else if ((obj != null) && (obj.getClass().isArray() || (obj instanceof Number))) { - DeviceValueChart chart = new DeviceValueChart(); - Device dev = null; - if (obj.getClass().isArray()) { - dev = new ReadableRegisterArray(new ReadableArray() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - - @Override - public int getSize() { - return Array.getLength(getCurrentFrame().cache.getValue(id)); - } - }); - } else { - dev = new ReadableRegisterNumber(new ReadableNumber() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - }); - } - dev.setPolling(1000); - chart.setDevice(dev); - JDialog dlg = SwingUtils.showDialog(dataTableDialog, cameraName + " " + id, null, chart); - //TODO: - //PlotBase plot = chart.getPlot(); - //if (plot!=null){ - // plot.setPlotBackgroundColor(Color.BLACK); - //} - } - } - } - } - } catch (Exception ex) { - showException(ex); - } - } - }); - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - updateStreamData(); - } - } - - volatile boolean updatingStreamData = false; - - void updateStreamData() { - if ((dataTableDialog == null) || !dataTableDialog.isShowing() || updatingStreamData) { - return; - } - updatingStreamData = true; - SwingUtilities.invokeLater(() -> { - updatingStreamData = false; - if ((dataTableModel != null) && (server != null)) { - StreamValue value = server.getValue(); - Frame frame = getCurrentFrame(); - int[] sel_rows = (dataTable == null) ? null : dataTable.getSelectedRows(); - int[] sel_cols = (dataTable == null) ? null : dataTable.getSelectedColumns(); - List ids = (value == null) ? new ArrayList<>() : new ArrayList(value.getIdentifiers()); - if (ids.size() + 4 != dataTableModel.getRowCount()) { - dataTableModel.setNumRows(0); - try { - dataTableModel.addRow(new Object[]{"Locator", server.getUrl() + "/" + ((value == null) ? instanceName : server.getCurrentInstance())}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Locator", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"Stream", server.getStreamAddress()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Stream", ex.getMessage()}); - } - dataTableModel.addRow(new Object[]{"PID", ""}); - dataTableModel.addRow(new Object[]{"Timestamp", ""}); - Collections.sort(ids); - for (String id : ids) { - dataTableModel.addRow(new Object[]{id, ""}); - } - } - - if ((frame != null) && (frame.cache != null)) { - dataTableModel.setValueAt(frame.cache.getPulseId(), 2, 1); //PID - dataTableModel.setValueAt(frame.cache.getTimestamp(), 3, 1); //Timestamp - for (int i = 4; i < dataTableModel.getRowCount(); i++) { - String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - //Object obj = server.getValue(id); - Object obj = frame.cache.getValue(id); - if (obj != null) { - if (obj.getClass().isArray()) { - obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; - } else if (obj instanceof Double) { - obj = Convert.roundDouble((Double) obj, 1); - } else if (obj instanceof Float) { - obj = Convert.roundDouble((Float) obj, 1); - } - } - dataTableModel.setValueAt(String.valueOf(obj), i, 1); - } - } - if ((sel_rows != null) && (sel_rows.length > 0)) { - //dataTable.setRowSelectionInterval((Integer)Arr.getMin(sel_rows), (Integer)Arr.getMax(sel_rows)); - dataTable.setRowSelectionInterval(sel_rows[0], sel_rows[sel_rows.length - 1]); - } - if ((sel_cols != null) && (sel_cols.length > 0)) { - //dataTable.setColumnSelectionInterval((Integer)Arr.getMin(sel_cols), (Integer)Arr.getMax(sel_cols)); - dataTable.setColumnSelectionInterval(sel_cols[0], sel_cols[sel_cols.length - 1]); - } - } - }); - } - - ImageIcon getIcon(String name) { - ImageIcon ret = null; - try { - //Path path = Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(),"resources", name + ".png"); - String dir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + "resources/"; - if (new File(dir + name + ".png").exists()) { - ret = new javax.swing.ImageIcon(dir + name + ".png"); - } else { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/" + name + ".png")); - if (MainFrame.isDark()) { - try { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/dark/" + name + ".png")); - } catch (Exception e) { - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return ret; - } - - String getIconName(JButton button) { - String ret = button.getIcon().toString(); - if (ret.indexOf(".") > 0) { - ret = ret.substring(0, ret.indexOf(".")); - } - return ret; - } - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - buttonGroup4 = new javax.swing.ButtonGroup(); - jProgressBar1 = new javax.swing.JProgressBar(); - sidePanel = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - buttonZoomFit = new javax.swing.JRadioButton(); - buttonZoomStretch = new javax.swing.JRadioButton(); - buttonZoomNormal = new javax.swing.JRadioButton(); - buttonZoom025 = new javax.swing.JRadioButton(); - buttonZoom05 = new javax.swing.JRadioButton(); - buttonZoom2 = new javax.swing.JRadioButton(); - jPanel2 = new javax.swing.JPanel(); - checkHistogram = new javax.swing.JCheckBox(); - comboColormap = new javax.swing.JComboBox(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - buttonFullRange = new javax.swing.JRadioButton(); - buttonManual = new javax.swing.JRadioButton(); - buttonAutomatic = new javax.swing.JRadioButton(); - labelMin = new javax.swing.JLabel(); - spinnerMin = new javax.swing.JSpinner(); - spinnerMax = new javax.swing.JSpinner(); - labelMax = new javax.swing.JLabel(); - btFixColormapRange = new javax.swing.JButton(); - jPanel5 = new javax.swing.JPanel(); - buttonServer = new javax.swing.JRadioButton(); - buttonDirect = new javax.swing.JRadioButton(); - textState = new javax.swing.JTextField(); - filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767)); - panelScreen = new javax.swing.JPanel(); - valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); - comboScreen = new javax.swing.JComboBox(); - panelFilter = new javax.swing.JPanel(); - valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); - comboFilter = new javax.swing.JComboBox(); - panelScreen2 = new javax.swing.JPanel(); - checkThreshold = new javax.swing.JCheckBox(); - spinnerThreshold = new javax.swing.JSpinner(); - checkBackground = new javax.swing.JCheckBox(); - checkGoodRegion = new javax.swing.JCheckBox(); - spinnerGrScale = new javax.swing.JSpinner(); - spinnerGrThreshold = new javax.swing.JSpinner(); - labelGrThreshold = new javax.swing.JLabel(); - labelGrScale = new javax.swing.JLabel(); - panelSlicing = new javax.swing.JPanel(); - checkSlicing = new javax.swing.JCheckBox(); - labelSlScale = new javax.swing.JLabel(); - spinnerSlScale = new javax.swing.JSpinner(); - labelSlNumber = new javax.swing.JLabel(); - spinnerSlNumber = new javax.swing.JSpinner(); - labelSlOrientation = new javax.swing.JLabel(); - spinnerSlOrientation = new javax.swing.JSpinner(); - topPanel = new javax.swing.JPanel(); - toolBar = new javax.swing.JToolBar(); - buttonSidePanel = new javax.swing.JToggleButton(); - buttonStreamData = new javax.swing.JButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - buttonPause = new javax.swing.JToggleButton(); - jSeparator6 = new javax.swing.JToolBar.Separator(); - buttonMarker = new javax.swing.JToggleButton(); - buttonProfile = new javax.swing.JToggleButton(); - buttonFit = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonTitle = new javax.swing.JToggleButton(); - pauseSelection = new ch.psi.pshell.swing.ValueSelection(); - panelCameraSelection = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - jLabel5 = new javax.swing.JLabel(); - comboType = new javax.swing.JComboBox(); - renderer = new ch.psi.pshell.imaging.Renderer(); - - setPreferredSize(new java.awt.Dimension(873, 600)); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); - - buttonGroup1.add(buttonZoomFit); - buttonZoomFit.setText("Fit"); - buttonZoomFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomFitActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomStretch); - buttonZoomStretch.setText("Stretch"); - buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomStretchActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomNormal); - buttonZoomNormal.setText("Normal"); - buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomNormalActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("1/4"); - buttonZoom025.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom025ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("1/2"); - buttonZoom05.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom05ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom2); - buttonZoom2.setText("2"); - buttonZoom2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoomStretch)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05) - .addComponent(buttonZoom2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomFit) - .addComponent(buttonZoom05)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoom2)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap")); - - checkHistogram.setText("Histogram"); - checkHistogram.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkHistogramActionPerformed(evt); - } - }); - - comboColormap.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Type:"); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Range:"); - - buttonGroup3.add(buttonFullRange); - buttonFullRange.setText("Full"); - buttonFullRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonManual); - buttonManual.setText("Manual"); - buttonManual.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonAutomatic); - buttonAutomatic.setText("Automatic"); - buttonAutomatic.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - labelMin.setText("Min:"); - - spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); - spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); - spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - labelMax.setText("Max:"); - - btFixColormapRange.setText("Fix"); - btFixColormapRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btFixColormapRangeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonAutomatic) - .addComponent(buttonFullRange) - .addComponent(buttonManual) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMax) - .addGap(2, 2, 2) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMin) - .addGap(2, 2, 2) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(spinnerMin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFixColormapRange, spinnerMax, spinnerMin}); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3) - .addComponent(checkHistogram)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAutomatic) - .addComponent(jLabel4) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelMin) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonFullRange)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonManual) - .addComponent(labelMax) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - - buttonGroup4.add(buttonServer); - buttonServer.setSelected(true); - buttonServer.setText("Server"); - buttonServer.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonServerActionPerformed(evt); - } - }); - - buttonGroup4.add(buttonDirect); - buttonDirect.setText("Direct"); - buttonDirect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDirectActionPerformed(evt); - } - }); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonServer) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonDirect) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(56, 56, 56)) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonServer) - .addComponent(buttonDirect))) - .addContainerGap()) - ); - - panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); - - comboScreen.setEnabled(false); - comboScreen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboScreenActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); - panelScreen.setLayout(panelScreenLayout); - panelScreenLayout.setHorizontalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreenLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreenLayout.setVerticalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelFilter.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); - - comboFilter.setEnabled(false); - comboFilter.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboFilterActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelFilterLayout = new javax.swing.GroupLayout(panelFilter); - panelFilter.setLayout(panelFilterLayout); - panelFilterLayout.setHorizontalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelFilterLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelFilterLayout.setVerticalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFilterLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - panelScreen2.setBorder(javax.swing.BorderFactory.createTitledBorder("Pipeline")); - - checkThreshold.setText("Threshold"); - checkThreshold.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkThresholdActionPerformed(evt); - } - }); - - spinnerThreshold.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 99999.0d, 1.0d)); - spinnerThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerThresholdonChange(evt); - } - }); - - checkBackground.setText("Subtract Background"); - checkBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkBackgroundActionPerformed(evt); - } - }); - - checkGoodRegion.setText("Good Region"); - checkGoodRegion.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkGoodRegionActionPerformed(evt); - } - }); - - spinnerGrScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerGrScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - spinnerGrThreshold.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.04d, 1.0d, 0.1d)); - spinnerGrThreshold.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerGrThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - labelGrThreshold.setText("Threshold:"); - - labelGrScale.setText("Scale:"); - - checkSlicing.setText("Slicing"); - checkSlicing.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkSlicingActionPerformed(evt); - } - }); - - labelSlScale.setText("Scale:"); - - spinnerSlScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerSlScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlNumber.setText("Slices:"); - - spinnerSlNumber.setModel(new javax.swing.SpinnerNumberModel(2, 0, 1000, 1)); - spinnerSlNumber.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlNumber.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlOrientation.setText("Orientation:"); - - spinnerSlOrientation.setModel(new javax.swing.SpinnerListModel(new String[] {"vertical", "horizontal"})); - spinnerSlOrientation.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlOrientation.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - javax.swing.GroupLayout panelSlicingLayout = new javax.swing.GroupLayout(panelSlicing); - panelSlicing.setLayout(panelSlicingLayout); - panelSlicingLayout.setHorizontalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addComponent(checkSlicing) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlNumber) - .addGap(2, 2, 2) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlScale) - .addGap(2, 2, 2) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelSlOrientation) - .addGap(2, 2, 2) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - panelSlicingLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerSlNumber, spinnerSlOrientation, spinnerSlScale}); - - panelSlicingLayout.setVerticalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(checkSlicing) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlNumber)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlScale)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlOrientation))) - ); - - javax.swing.GroupLayout panelScreen2Layout = new javax.swing.GroupLayout(panelScreen2); - panelScreen2.setLayout(panelScreen2Layout); - panelScreen2Layout.setHorizontalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkThreshold) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addComponent(checkGoodRegion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(labelGrScale)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelGrThreshold))) - .addGap(2, 2, 2))) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - .addComponent(panelSlicing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addGap(6, 6, 6) - .addComponent(checkBackground) - .addGap(106, 106, 106)) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerThreshold}); - - panelScreen2Layout.setVerticalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(checkBackground) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkThreshold) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkGoodRegion) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrScale)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrThreshold)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelSlicing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - javax.swing.GroupLayout sidePanelLayout = new javax.swing.GroupLayout(sidePanel); - sidePanel.setLayout(sidePanelLayout); - sidePanelLayout.setHorizontalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - sidePanelLayout.setVerticalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - toolBar.setFloatable(false); - toolBar.setRollover(true); - - buttonSidePanel.setIcon(getIcon("List")); - buttonSidePanel.setSelected(true); - buttonSidePanel.setText(" "); - buttonSidePanel.setToolTipText("Show Side Panel"); - buttonSidePanel.setFocusable(false); - buttonSidePanel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSidePanel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSidePanelActionPerformed(evt); - } - }); - toolBar.add(buttonSidePanel); - - buttonStreamData.setIcon(getIcon("Details")); - buttonStreamData.setText(" "); - buttonStreamData.setToolTipText("Show Data Window"); - buttonStreamData.setFocusable(false); - buttonStreamData.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonStreamData.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStreamDataActionPerformed(evt); - } - }); - toolBar.add(buttonStreamData); - - buttonSave.setIcon(getIcon("Save")); - buttonSave.setText(" "); - buttonSave.setToolTipText("Save Snapshot"); - buttonSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - toolBar.add(buttonSave); - - buttonGrabBackground.setIcon(getIcon("Background")); - buttonGrabBackground.setText(" "); - buttonGrabBackground.setToolTipText("Grab Background"); - buttonGrabBackground.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - toolBar.add(buttonGrabBackground); - - buttonPause.setIcon(getIcon("Pause")); - buttonPause.setText(" "); - buttonPause.setToolTipText("Pause"); - buttonPause.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - toolBar.add(buttonPause); - - jSeparator6.setMaximumSize(new java.awt.Dimension(20, 32767)); - jSeparator6.setPreferredSize(new java.awt.Dimension(20, 0)); - jSeparator6.setRequestFocusEnabled(false); - toolBar.add(jSeparator6); - - buttonMarker.setIcon(getIcon("Marker")); - buttonMarker.setText(" "); - buttonMarker.setToolTipText("Show Marker"); - buttonMarker.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - toolBar.add(buttonMarker); - - buttonProfile.setIcon(getIcon("Profile" - + "")); - buttonProfile.setSelected(true); - buttonProfile.setText(" "); - buttonProfile.setToolTipText("Show Image Profile"); - buttonProfile.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonProfile.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonProfileActionPerformed(evt); - } - }); - toolBar.add(buttonProfile); - - buttonFit.setIcon(getIcon("Fit")); - buttonFit.setSelected(true); - buttonFit.setText(" "); - buttonFit.setToolTipText("Show Fit"); - buttonFit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - toolBar.add(buttonFit); - - buttonReticle.setIcon(getIcon("Reticule")); - buttonReticle.setSelected(true); - buttonReticle.setText(" "); - buttonReticle.setToolTipText("Show Reticle"); - buttonReticle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - toolBar.add(buttonReticle); - - buttonTitle.setIcon(getIcon("Title")); - buttonTitle.setSelected(true); - buttonTitle.setText(" "); - buttonTitle.setToolTipText("Show Camera Name"); - buttonTitle.setFocusable(false); - buttonTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonTitle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonTitleActionPerformed(evt); - } - }); - toolBar.add(buttonTitle); - - pauseSelection.setDecimals(0); - - jLabel1.setText("Camera:"); - - comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboCameras.setMaximumRowCount(30); - comboCameras.setMinimumSize(new java.awt.Dimension(127, 27)); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - jLabel5.setText("Type:"); - - comboType.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboType.setMaximumRowCount(30); - comboType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Laser", "Electrons", "Photonics" })); - comboType.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboTypeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelCameraSelectionLayout = new javax.swing.GroupLayout(panelCameraSelection); - panelCameraSelection.setLayout(panelCameraSelectionLayout); - panelCameraSelectionLayout.setHorizontalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addGap(0, 0, 0) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - panelCameraSelectionLayout.setVerticalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel5) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0)) - ); - - javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel); - topPanel.setLayout(topPanelLayout); - topPanelLayout.setHorizontalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup() - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - topPanelLayout.setVerticalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(topPanelLayout.createSequentialGroup() - .addGap(1, 1, 1) - .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(sidePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(topPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(sidePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - }// //GEN-END:initComponents - - private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed - try { - renderer.setMode(RendererMode.Fit); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomFitActionPerformed - - private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed - try { - renderer.setMode(RendererMode.Stretch); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomStretchActionPerformed - - private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed - try { - renderer.setMode(RendererMode.Fixed); - centralizeRenderer(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomNormalActionPerformed - - private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap - try { - if ((camera != null) && (camera instanceof ColormapSource) && !updatingColormap) { - ColormapSource source = (ColormapSource) camera; - Color colorReticule = new Color(16, 16, 16); - Color colorMarker = new Color(128, 128, 128); - Colormap colormap = (Colormap) comboColormap.getSelectedItem(); - source.getConfig().colormap = (colormap == null) ? Colormap.Flame : colormap; - switch (source.getConfig().colormap) { - case Grayscale: - case Inverted: - case Red: - case Green: - case Blue: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - case Flame: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - } - - renderer.setPenReticle(new Pen(colorReticule)); - renderer.setPenProfile(new Pen(colorReticule, 0)); - renderer.setPenMarker(new Pen(colorMarker, 2)); - renderer.setShowReticle(false); - checkReticle(); - source.getConfig().colormapAutomatic = buttonAutomatic.isSelected(); - source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); - source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); - try { - source.getConfig().save(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - } - source.refresh(); - if (buttonPause.isSelected()) { - updatePause(); - } - updateColormap(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_onChangeColormap - - private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange - onChangeColormap(null); - }//GEN-LAST:event_onChangeColormapRange - - private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed - renderer.setZoom(0.25); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom025ActionPerformed - - private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed - renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom05ActionPerformed - - private void buttonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonServerActionPerformed - if (!usingServer) { - usingServer = true; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonServerActionPerformed - - private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingServer) { - usingServer = false; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonDirectActionPerformed - - private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed - - comboScreen.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - ChannelInteger setpoint = null; - try { - int index = comboScreen.getSelectedIndex(); - if (index>=0){ - if (cameraName.contains("DSRM")) { - setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); - } else { - setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); - } - setpoint.initialize(); - Integer readback = setpoint.read(); - if ((readback==null) || (setpoint.read() != index)) { - setpoint.write(index); - //Must be threaded to control the laser because of sleep in setLaserState - /* - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - setpoint.write(index); - } finally { - if (laserOn) { - setLaserState(true); - } - } - */ - } - screen.read(); - } - } catch (Exception ex) { - showException(ex); - } finally { - comboScreen.setEnabled(true); - if (setpoint != null) { - setpoint.close(); - } - } - } - }).start(); - }//GEN-LAST:event_comboScreenActionPerformed - - private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed - try { - String setpoint = (String) comboFilter.getSelectedItem(); - if (setpoint!=null){ - if (!setpoint.equals(filter.read())) { - filter.write(setpoint); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboFilterActionPerformed - - private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed - try { - setHistogramVisible(checkHistogram.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_checkHistogramActionPerformed - - private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed - renderer.setZoom(2.0); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom2ActionPerformed - - private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setThreshold((Double) spinnerThreshold.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerThresholdonChange - - private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (server != null) { - if (!updatingServerControls) { - try { - if (server.isStarted()) { - server.setBackgroundSubtraction(checkBackground.isSelected()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - updatingServerControls = true; - checkBackground.setSelected(false); - updatingServerControls = false; - - } - } - } else { - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - }//GEN-LAST:event_checkBackgroundActionPerformed - - private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - spinnerThreshold.setVisible(checkThreshold.isSelected()); - server.setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkThresholdActionPerformed - - private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - goodRegion = checkGoodRegion.isSelected(); - setGoodRegionOptionsVisible(goodRegion); - if (goodRegion) { - server.setGoodRegion(((Number) spinnerGrThreshold.getValue()).doubleValue(), ((Number) spinnerGrScale.getValue()).doubleValue()); - } else { - server.setGoodRegion(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkGoodRegionActionPerformed - - private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setGoodRegion((Double) spinnerGrThreshold.getValue(), (Double) spinnerGrScale.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerGrThresholdonChange - - private void btFixColormapRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFixColormapRangeActionPerformed - try { - updatingColormap = true; - ArrayProperties properties = currentFrame.data.getProperties(); - spinnerMax.setValue(properties.max.intValue()); - spinnerMin.setValue(properties.min.intValue()); - buttonManual.setSelected(true); - } catch (Exception ex) { - showException(ex); - } finally { - updatingColormap = false; - onChangeColormap(null); - } - }//GEN-LAST:event_btFixColormapRangeActionPerformed - - private void checkSlicingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSlicingActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - slicing = checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - if (slicing) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } else { - server.setSlicing(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkSlicingActionPerformed - - private void spinnerSlicingChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerSlicingChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerSlicingChange - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - showFit = buttonFit.isSelected(); - if (showFit) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed - try { - showProfile = buttonProfile.isSelected(); - if (showProfile) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(profileOv); - profileOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonProfileActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - checkMarker(null); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - if (!updatingButtons) { - removePauseOverlay(); - if (camera != null) { - boolean pause = !renderer.isPaused(); - synchronized (imageBuffer) { - if (pause) { - renderer.pause(); - panelCameraSelection.setVisible(false); - pauseSelection.setVisible(true); - if (imageBuffer.size() > 0) { - pauseSelection.setEnabled(true); - pauseSelection.setMaxValue(imageBuffer.size()); - pauseSelection.setValue(imageBuffer.size()); - updatePause(); - } else { - pauseSelection.setEnabled(false); - pauseSelection.setMaxValue(1); - pauseSelection.setValue(1); - } - } else { - imageBuffer.clear(); - renderer.resume(); - //renderer.clear(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - updateStreamData(); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera != null) { - boolean laserOn = getLaserState(); - OptionResult ret = null; - if (laserOn) { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put laser on delay for capturing background?", OptionType.YesNoCancel); - if (ret == OptionResult.No) { - laserOn = false; - } - } else { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to capture background now?", OptionType.OkCancel); - } - - if (ret == OptionResult.Cancel) { - return; - } - - if (laserOn) { - setLaserState(false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - if (server != null) { - server.captureBackground(5); - } else { - camera.captureBackground(5, 0); - } - } finally { - if (laserOn) { - setLaserState(true); - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - saveSnapshot(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonStreamDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStreamDataActionPerformed - try { - showStreamData(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonStreamDataActionPerformed - - private void buttonSidePanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSidePanelActionPerformed - sidePanel.setVisible(buttonSidePanel.isSelected()); - }//GEN-LAST:event_buttonSidePanelActionPerformed - - private void comboTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTypeActionPerformed - try { - if (!updatingCameraSelection) { - updateCameraList(); - if ((cameraName != null) && (!cameraName.equals(comboCameras.getSelectedItem()))) { - setCamera(null); - } else { - setCamera(cameraName); - } - } - - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - }//GEN-LAST:event_comboTypeActionPerformed - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - if (!updatingCameraSelection) { - if (!comboCameras.isEnabled()) { - throw new Exception("Invalid state"); - } - comboCameras.setEnabled(false); - comboType.setEnabled(false); - buttonServer.setEnabled(false); - buttonDirect.setEnabled(false); - final String cameraName = (String) comboCameras.getSelectedItem(); - new Thread(new Runnable() { - @Override - public void run() { - if (requestCameraListUpdate) { - requestCameraListUpdate = false; - try { - updateCameraList(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - try { - setCamera(cameraName.trim().isEmpty() ? null : cameraName); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - buttonServer.setEnabled(true); - buttonDirect.setEnabled(true); - } - } - }).start(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTitleActionPerformed - try { - manageTitleOverlay(); - } catch (Exception ex) { - showException(ex); - } finally { - } - }//GEN-LAST:event_buttonTitleActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btFixColormapRange; - private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonDirect; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JRadioButton buttonFullRange; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JRadioButton buttonManual; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonProfile; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JRadioButton buttonServer; - private javax.swing.JToggleButton buttonSidePanel; - private javax.swing.JButton buttonStreamData; - private javax.swing.JToggleButton buttonTitle; - private javax.swing.JRadioButton buttonZoom025; - private javax.swing.JRadioButton buttonZoom05; - private javax.swing.JRadioButton buttonZoom2; - private javax.swing.JRadioButton buttonZoomFit; - private javax.swing.JRadioButton buttonZoomNormal; - private javax.swing.JRadioButton buttonZoomStretch; - private javax.swing.JCheckBox checkBackground; - private javax.swing.JCheckBox checkGoodRegion; - private javax.swing.JCheckBox checkHistogram; - private javax.swing.JCheckBox checkSlicing; - private javax.swing.JCheckBox checkThreshold; - private javax.swing.JComboBox comboCameras; - private javax.swing.JComboBox comboColormap; - private javax.swing.JComboBox comboFilter; - private javax.swing.JComboBox comboScreen; - private javax.swing.JComboBox comboType; - private javax.swing.Box.Filler filler1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel5; - private javax.swing.JProgressBar jProgressBar1; - private javax.swing.JToolBar.Separator jSeparator6; - private javax.swing.JLabel labelGrScale; - private javax.swing.JLabel labelGrThreshold; - private javax.swing.JLabel labelMax; - private javax.swing.JLabel labelMin; - private javax.swing.JLabel labelSlNumber; - private javax.swing.JLabel labelSlOrientation; - private javax.swing.JLabel labelSlScale; - private javax.swing.JPanel panelCameraSelection; - private javax.swing.JPanel panelFilter; - private javax.swing.JPanel panelScreen; - private javax.swing.JPanel panelScreen2; - private javax.swing.JPanel panelSlicing; - private ch.psi.pshell.swing.ValueSelection pauseSelection; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JPanel sidePanel; - private javax.swing.JSpinner spinnerGrScale; - private javax.swing.JSpinner spinnerGrThreshold; - private javax.swing.JSpinner spinnerMax; - private javax.swing.JSpinner spinnerMin; - private javax.swing.JSpinner spinnerSlNumber; - private javax.swing.JSpinner spinnerSlOrientation; - private javax.swing.JSpinner spinnerSlScale; - private javax.swing.JSpinner spinnerThreshold; - private javax.swing.JTextField textState; - private javax.swing.JToolBar toolBar; - private javax.swing.JPanel topPanel; - private ch.psi.pshell.swing.DeviceValuePanel valueFilter; - private ch.psi.pshell.swing.DeviceValuePanel valueScreen; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/ScreenPanel4.form b/plugins/ScreenPanel4.form deleted file mode 100755 index 4584b9c..0000000 --- a/plugins/ScreenPanel4.form +++ /dev/null @@ -1,1180 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/ScreenPanel4.java b/plugins/ScreenPanel4.java deleted file mode 100755 index ade7489..0000000 --- a/plugins/ScreenPanel4.java +++ /dev/null @@ -1,4247 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.bs.CameraServer; -import ch.psi.pshell.core.Context; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.PipelineServer; -import ch.psi.pshell.bs.StreamValue; -import ch.psi.pshell.core.JsonSerializer; -import ch.psi.pshell.data.DataManager; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.device.Readable.ReadableArray; -import ch.psi.pshell.device.Readable.ReadableNumber; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterArray; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterNumber; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.DiscretePositioner; -import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.imaging.Colormap; -import ch.psi.pshell.imaging.ColormapSource; -import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.DimensionDouble; -import ch.psi.pshell.imaging.Histogram; -import ch.psi.pshell.imaging.ImageBuffer; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.PointDouble; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.pshell.swing.DeviceValueChart; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import ch.psi.pshell.ui.Console; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Config; -import ch.psi.utils.Convert; -import ch.psi.utils.Str; -import ch.psi.utils.swing.Editor.EditorDialog; -import ch.psi.utils.swing.MainFrame; -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.StandardDialog.StandardDialogListener; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.lang.reflect.Array; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.table.DefaultTableModel; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.PolynomialCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; - -/** - * - */ -public class ScreenPanel4 extends Panel { - - public static final String LASER_TYPE = "Laser"; - public static final String ELECTRONS_TYPE = "Electrons"; - public static final String PHOTONICS_TYPE = "Photonics"; - - final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useServerStats = true; - String userOverlaysConfigFile; - ColormapSource camera; - PipelineServer server; - String cameraName; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - boolean showProfile; - Overlay[] userOv; - Overlay[] fitOv; - Overlay[] profileOv; - Overlay errorOverlay; - boolean requestCameraListUpdate; - boolean goodRegion; - boolean slicing; - String serverUrl; - String camServerUrl; - String instanceName; - Overlay titleOv = null; - int integration = 0; - boolean persistCameraState; - - public class CameraState extends Config { - - public boolean valid; - public boolean showSidePanel; - //public boolean showMarker; Saved in the stream instance config - public boolean showProfile; - public boolean showFit; - public boolean showReticle; - public boolean showScale; - public boolean showTitle; - public double zoom; - public RendererMode mode; - public boolean colormapAutomatic; - public double colormapMin; - public double colormapMax; - public Colormap colormap; - public boolean colormapLogarithmic; - - String getFile() { - if (camera == null) { - return null; - } - return getContext().getSetup().expandPath("{context}/screen_panel/" + cameraName + ".properties"); - } - } - - void loadCameraState() { - if (persistCameraState) { - try { - CameraState state = new CameraState(); - state.load(state.getFile()); - if (state.valid) { - buttonSidePanel.setSelected(state.showSidePanel); - buttonSidePanelActionPerformed(null); - buttonProfile.setSelected(state.showProfile); - buttonProfileActionPerformed(null); - buttonFit.setSelected(state.showFit); - buttonFitActionPerformed(null); - buttonReticle.setSelected(state.showReticle); - buttonReticleActionPerformed(null); - buttonScale.setSelected(state.showScale); - buttonScaleActionPerformed(null); - buttonTitle.setSelected(state.showTitle); - buttonTitleActionPerformed(null); - renderer.setMode(state.mode); - renderer.setZoom(state.zoom); - if (camera instanceof ColormapSource) { - camera.getConfig().colormap = state.colormap; - camera.getConfig().colormapAutomatic = state.colormapAutomatic; - camera.getConfig().colormapLogarithmic = state.colormapLogarithmic; - camera.getConfig().colormapMax = state.colormapMax; - camera.getConfig().colormapMin = state.colormapMin; - updateColormap(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - void saveCameraState() { - if (persistCameraState) { - try { - CameraState state = new CameraState(); - state.valid = true; - if (camera instanceof ColormapSource) { - state.colormap = camera.getConfig().colormap; - state.colormapAutomatic = camera.getConfig().colormapAutomatic; - state.colormapLogarithmic = camera.getConfig().colormapLogarithmic; - state.colormapMax = camera.getConfig().colormapMax; - state.colormapMin = camera.getConfig().colormapMin; - } - state.mode = renderer.getMode(); - state.zoom = renderer.getZoom(); - - state.showSidePanel = buttonSidePanel.isSelected(); - state.showProfile = buttonProfile.isSelected(); - state.showFit = buttonFit.isSelected(); - state.showReticle = buttonReticle.isSelected(); - state.showScale = buttonScale.isSelected(); - state.showTitle = buttonTitle.isSelected(); - - state.save(state.getFile()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - String pipelineSuffix = "_sp"; - - Double getServerDouble(String name) { - return (Double) Convert.toDouble(server.getValue(name)); - } - - double[] getServerDoubleArray(String name) { - return (double[]) Convert.toDouble(server.getValue(name)); - } - - class ImageData { - - ImageData() { - if (server != null) { - cache = server.getStream().take(); - String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getDouble(prefix + "x_fit_mean"); - y_fit_mean = getDouble(prefix + "y_fit_mean"); - x_fit_standard_deviation = getDouble(prefix + "x_fit_standard_deviation"); - y_fit_standard_deviation = getDouble(prefix + "y_fit_standard_deviation"); - x_fit_gauss_function = getDoubleArray(prefix + "x_fit_gauss_function"); - y_fit_gauss_function = getDoubleArray(prefix + "y_fit_gauss_function"); - x_profile = getDoubleArray("x_profile"); - y_profile = getDoubleArray("y_profile"); - x_center_of_mass = getDouble("x_center_of_mass"); - y_center_of_mass = getDouble("y_center_of_mass"); - x_rms = getDouble("x_rms"); - y_rms = getDouble("y_rms"); - if (goodRegion) { - double[] gX2 = new double[x_profile.length]; - Arrays.fill(gX2, Double.NaN); - try { - double[] axis = getDoubleArray("x_axis"); - gr_x_axis = getDoubleArray("gr_x_axis"); - double x = gr_x_axis[0]; - gr_size_x = x_fit_gauss_function.length; - //If gr axis values are not identical, calculate the index... - gr_pos_x = (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x) : x); - //But prefer checking the value to avoid raounding errors - for (int i=0;i imageBuffer = new ArrayList(); - Frame currentFrame; - int imageBufferLenght = 1; - Text imagePauseOverlay; - final Console console; - - public ScreenPanel4() { - try { - initComponents(); - spinnerThreshold.setVisible(false); - btFixColormapRange.setVisible(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - JComponent editor = spinnerSlOrientation.getEditor(); - if (editor instanceof JSpinner.DefaultEditor) { - ((JSpinner.DefaultEditor) editor).getTextField().setHorizontalAlignment(JTextField.RIGHT); - } - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - //setPersistedComponents(new Component[]{buttonServer, buttonDirect}); - setPersistedComponents(new Component[]{buttonTitle}); - comboCameras.setEnabled(false); - comboType.setEnabled(false); - - SwingUtils.setEnumCombo(comboColormap, Colormap.class); - if (App.hasArgument("poll")) { - try { - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try { - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("buf")) { - try { - imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("usr_ov")) { - try { - userOverlaysConfigFile = App.getArgumentValue("usr_ov"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_url")) { - serverUrl = App.getArgumentValue("srv_url"); - } - - if (App.hasArgument("cam_srv_url")) { - camServerUrl = App.getArgumentValue("cam_srv_url"); - } - - if (App.hasArgument("calc")) { - useServerStats = false; - } - - if (App.hasArgument("persist")) { - persistCameraState = true; - } - - if (App.hasArgument("suffix")) { - pipelineSuffix = App.getArgumentValue("suffix"); - } - if (App.hasArgument("integration")) { - try { - setIntegration(Integer.valueOf(App.getArgumentValue("integration"))); - if (integration != 0) { - buttonFit.setSelected(false); - buttonProfile.setSelected(false); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - renderer.setProfileNormalized(true); - renderer.setShowProfileLimits(false); - - JMenuItem menuCalibrate = new JMenuItem("Calibrate..."); - menuCalibrate.addActionListener((ActionEvent e) -> { - try { - calibrate(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuRendererConfig = new JMenuItem("Renderer Parameters"); - menuRendererConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuCameraConfig = new JMenuItem("Camera Configurarion"); - menuCameraConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - String cameraConfigJson = null; - if (usingServer) { - String cameraServerUrl = (camServerUrl == null) ? server.getUrl().substring(0, server.getUrl().length() - 1) + "8" : camServerUrl; - try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)) { - srv.initialize(); - //TODO: replace into encodeMultiline - cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true); - } - - } else { - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - } - TextEditor configEditor = new TextEditor(); - configEditor.setText(cameraConfigJson); - configEditor.setReadOnly(true); - configEditor.setTitle(cameraName); - EditorDialog dlg = configEditor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(getTopLevel(), dlg); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetImageBufferSize = new JMenuItem("Set Stack Size..."); - menuSetImageBufferSize.addActionListener((ActionEvent e) -> { - try { - String ret = SwingUtils.getString(getTopLevel(), "Enter size of image buffer: ", String.valueOf(imageBufferLenght)); - if (ret != null) { - this.setImageBufferSize(Integer.valueOf(ret)); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSaveStack = new JMenuItem("Save Stack"); - menuSaveStack.addActionListener((ActionEvent e) -> { - try { - saveStack(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetROI = new JMenuItem("Set ROI..."); - menuSetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); - renderer.addListener(new RendererListener() { - @Override - public void onSelectionFinished(Renderer renderer, Overlay overlay) { - try { - renderer.setShowReticle(false); - Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (server.isRoiEnabled()) { - int[] cur = server.getRoi(); - server.setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); - } else { - server.setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); - } - } catch (Exception ex) { - } finally { - renderer.removeListener(this); - } - } - - @Override - public void onSelectionAborted(Renderer renderer, Overlay overlay) { - renderer.removeListener(this); - } - }); - selection.setFixed(true); - renderer.startSelection(selection); - } - }); - - JMenuItem menuResetROI = new JMenuItem("Reset ROI"); - menuResetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - try { - renderer.setShowReticle(false); - server.resetRoi(); - } catch (IOException ex) { - showException(ex); - } - } - }); - - JCheckBoxMenuItem menuFrameIntegration = new JCheckBoxMenuItem("Multi-Frame", (integration != 0)); - menuFrameIntegration.addActionListener((ActionEvent e) -> { - if (integration == 0) { - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{150, 50}; //Minimum width - layout.rowHeights = new int[]{30, 30}; //Minimum height - panel.setLayout(layout); - JCheckBox checkContinuous = new JCheckBox(""); - checkContinuous.setSelected(true); - JTextField textFrames = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Number of frames:"), c); - c.gridy = 1; - panel.add(new JLabel("Continuous:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(checkContinuous, c); - c.gridy = 0; - panel.add(textFrames, c); - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", panel, OptionType.OkCancel) == OptionResult.Yes) { - setIntegration(checkContinuous.isSelected() ? -(Integer.valueOf(textFrames.getText())) : (Integer.valueOf(textFrames.getText()))); - } - } else { - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", - "Do you want to disable " + ((integration < 0) ? "continuous " : "") + "multi-frame integration (" + Math.abs(integration) + ")?", OptionType.YesNo) == OptionResult.Yes) { - setIntegration(0); - } - } - }); - - for (Component cmp : SwingUtils.getComponentsByType(renderer.getPopupMenu(), JMenu.class)) { - JMenu menu = (JMenu) cmp; - if (menu.getText().equals("Integration")) { - menu.addSeparator(); - menu.add(menuFrameIntegration); - } - } - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuRendererConfig); - renderer.getPopupMenu().add(menuCameraConfig); - renderer.getPopupMenu().add(menuSetImageBufferSize); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuCalibrate); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuSetROI); - renderer.getPopupMenu().add(menuResetROI); - renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(server != null); - menuSetROI.setEnabled(server != null); - menuCalibrate.setVisible(server != null); - menuCalibrate.setEnabled((calibrationDialolg == null) || (!calibrationDialolg.isShowing())); - menuSaveStack.setEnabled(imageBufferLenght > 0); - menuSetImageBufferSize.setEnabled(!renderer.isPaused()); - menuFrameIntegration.setSelected(integration != 0); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - } - }); - renderer.getPopupMenu().setVisible(false); - buttonScale.setSelected(renderer.getShowColormapScale()); - clearMarker(); - - showFit = buttonFit.isSelected(); - showProfile = buttonProfile.isSelected(); - - pauseSelection.setVisible(false); - pauseSelection.setMinValue(1); - pauseSelection.addListener(new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - if (editing && (value >= 1) && (value <= imageBuffer.size())) { - updatePause(); - } - } - }); - renderer.addListener(new RendererListener() { - @Override - public void onMoveFinished(Renderer renderer, Overlay overlay) { - if (overlay == marker) { - try { - onMarkerChanged(); - } catch (IOException ex) { - Logger.getLogger(ScreenPanel4.class.getName()).log(Level.WARNING, null, ex); - } - } - } - }); - if (MainFrame.isDark()) { - textState.setDisabledTextColor(textState.getForeground()); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - - console = (!App.hasArgument("console")) ? null : new Console() { - /* - protected void onConsoleCommand(String name, String[] pars, String trimming) throws Exception { - switch (name) { - case "cam": - comboCameras.setSelectedItem(tokens[1]); - break; - } - }*/ - @Override - protected void onConsoleCommand(String command) { - String[] tokens = command.split(" "); - if ((tokens.length > 1) && tokens[0].equals("cam")) { - try { - if (!tokens[1].equals(comboCameras.getSelectedItem())) { - setComboTypeSelection("All"); - updateCameraList(); - comboCameras.setSelectedItem(tokens[1]); - if (!tokens[1].equals(comboCameras.getSelectedItem())) { - comboCameras.setSelectedItem(""); - throw new Exception("Invalid camera name : " + tokens[1]); - } - System.out.println("Console set camera: " + tokens[1]); - } - } catch (Exception ex) { - System.err.println(ex); - } - } else { - System.err.println("Invalid command: " + command); - } - } - }; - } - - void setIntegration(int frames) { - try { - if (integration != frames) { - integration = frames; - if (camera != null) { - if (Math.abs(integration) > 1) { - renderer.setDevice(new ImageIntegrator(integration)); - } else { - renderer.setDevice(camera); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - @Override - public void onStart() { - super.onStart(); - updateDialogTitle(); - if (App.hasArgument("ct")) { - boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonServer.setSelected(!direct); - buttonDirect.setSelected(direct); - } - if (App.hasArgument("console")) { - console.start(); - } - } - - @Override - public void onStop() { - try { - if (camera != null) { - saveCameraState(); - camera.close(); - camera = null; - server = null; - updateButtons(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - if (console != null) { - console.stop(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - super.onStop(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - comboType.setEnabled(false); - if (App.hasArgument("s")) { - renderer.setDevice((Source) getDevice("image")); - renderer.setAutoScroll(true); - ((Source) getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - manageFit(bi, data); - manageUserOverlays(bi, data); - } - - @Override - public void onError(Object o, Exception ex) { - } - } - ); - - } else { - usingServer = buttonServer.isSelected(); - updateCameraList(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - setComboCameraSelection(null); - setComboTypeSelection("All"); - - if (comboCameras.getModel().getSize() > 0) { - try { - if (App.hasArgument("cam")) { - setComboCameraSelection(App.getArgumentValue("cam")); - comboCamerasActionPerformed(null); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - updateButtons(); - startTimer(1000); - } - - boolean isVisible(String camera) { - return ((comboType.getSelectedIndex() == 0) || (getCameraType(camera).equals(comboType.getSelectedItem()))); - } - - DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - if (fromServer) { - try (PipelineServer srv = newServer()) { - srv.initialize(); - List cameras = srv.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - - } else { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - if (App.hasArgument("cam")) { - String camera = App.getArgumentValue("cam"); - if (model.getIndexOf(camera) < 0) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - model.addElement(""); - - return model; - } - - PipelineServer newServer() throws IOException { - if (serverUrl != null) { - System.out.println("Connecting to server: " + serverUrl); - server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl); - } else { - System.out.println("Connecting to server"); - server = new PipelineServer(CAMERA_DEVICE_NAME); - } - updateButtons(); - return server; - } - - boolean updatingCameraSelection; - - void setComboCameraSelection(Object selection) { - updatingCameraSelection = true; - try { - comboCameras.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - - void setComboTypeSelection(Object selection) { - updatingCameraSelection = true; - try { - comboType.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - boolean usingServer; - - void updateCameraList() { - try { - String selected = (String) comboCameras.getSelectedItem(); - comboCameras.setModel(getCameraList(usingServer)); - if (selected != null) { - if (((DefaultComboBoxModel) comboCameras.getModel()).getIndexOf(camera) < 0) { - setComboCameraSelection(selected); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - } - - final Object lockOverlays = new Object(); - - void manageFit(BufferedImage bi, Data data) { - Overlay[][] fo = null; - if ((showFit || showProfile)) { - try { - fo = getFitOverlays(data); - } catch (Exception ex) { - System.err.println(ex); - } - } - synchronized (lockOverlays) { - fo = (fo == null) ? new Overlay[][]{null, null} : fo; - renderer.updateOverlays(fo[0], profileOv); - profileOv = fo[0]; - renderer.updateOverlays(fo[1], fitOv); - fitOv = fo[1]; - } - } - - void manageUserOverlays(BufferedImage bi, Data data) { - Overlay[] fo = (bi == null) ? null : getUserOverlays(data); - synchronized (lockOverlays) { - renderer.updateOverlays(fo, userOv); - userOv = fo; - } - } - - void updateDialogTitle() { - if (App.isDetached()) { - getTopLevel().setTitle(cameraName == null ? "ScreenPanel" : cameraName); - } - } - - void manageTitleOverlay() { - Overlay to = null; - if ((buttonTitle.isSelected()) && (cameraName != null)) { - Font font = new Font("Arial", Font.PLAIN, 28); - to = new Text(renderer.getPenErrorText(), cameraName, font, new Point(-SwingUtils.getTextSize(cameraName, renderer.getGraphics().getFontMetrics(font)).width - 14, 26)); - to.setFixed(true); - to.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - } - - synchronized (lockOverlays) { - renderer.updateOverlays(to, titleOv); - titleOv = to; - } - } - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - Thread devicesInitTask; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Initializing: " + cameraName); - parseUserOverlays(); - errorOverlay = null; - lastMarkerPos = null; - lastFrame = null; - lastPipelinePars = null; - - if (dataTableDialog != null) { - dataTableDialog.dispose(); - dataTableDialog = null; - } - dataTableModel = null; - - if (calibrationDialolg != null) { - calibrationDialolg.dispose(); - calibrationDialolg = null; - } - - boolean was_server = false; - if (camera != null) { - saveCameraState(); - //camera.removeAllListeners(); - was_server = (server != null); - camera.close(); - camera = null; - server = null; - } - updateButtons(); - instanceName = null; - renderer.setDevice(null); - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.removeOverlays(profileOv); - renderer.removeOverlays(userOv); - renderer.clear(); - renderer.resetZoom(); - - boolean changed = !String.valueOf(cameraName).equals(this.cameraName); - this.cameraName = cameraName; - - if (changed || buttonDirect.isSelected()) { - spinnerThreshold.setVisible(false); - checkThreshold.setEnabled(false); - checkGoodRegion.setEnabled(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - if (changed) { - checkBackground.setEnabled(false); - if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { - devicesInitTask.interrupt(); - } - if (screen != null) { - screen.close(); - screen = null; - } - if (filter != null) { - filter.close(); - filter = null; - } - if (renderer.isPaused()) { - renderer.resume(); - removePauseOverlay(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - manageTitleOverlay(); - updateDialogTitle(); - - if (cameraName == null) { - return; - } - - System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]"); - try { - if (buttonServer.isSelected()) { - camera = newServer(); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - //camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName); - camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName}); - } - camera.initialize(); - camera.assertInitialized(); - System.out.println("Camera initialization OK"); - loadCameraState(); - if (server != null) { - //server.start(cameraName, false); - String pipelineName = cameraName + pipelineSuffix; - instanceName = cameraName + pipelineSuffix + "1"; - if (!server.getPipelines().contains(pipelineName)) { - System.out.println("Creating pipeline: " + pipelineName); - HashMap config = new HashMap<>(); - config.put("camera_name", cameraName); - //server.createFromConfig(config, pipelineName); - server.savePipelineConfig(pipelineName, config); - } - server.start(pipelineName, instanceName); - - updatePipelineControls(); - checkThreshold.setEnabled(true); - checkGoodRegion.setEnabled(true); - } else { - checkThreshold.setSelected(false); - checkGoodRegion.setSelected(false); - if (polling <= 0) { - camera.setMonitored(true); - } else { - camera.setPolling(polling); - } - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - updateButtons(); - camera.getConfig().save(); - if (Math.abs(integration) > 1) { - renderer.setDevice(new ImageIntegrator(integration)); - } else { - renderer.setDevice(camera); - } - renderer.setAutoScroll(true); - //renderer.setMarker(marker); - clearMarker(); - imageSize = null; - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi != null) { - if ((imageSize == null) || imageSize.width != bi.getWidth() || imageSize.height != bi.getHeight()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { - centralizeRenderer(); - } - checkReticle(); - } - }); - imageSize = new Dimension(bi.getWidth(), bi.getHeight()); - } - renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); - } - //renderer.setCalibration(camera.getCalibration()); - if (!renderer.isPaused()) { - if (data != null) { - synchronized (imageBuffer) { - currentFrame = new Frame(data); - if (imageBufferLenght >= 1) { - imageBuffer.add(currentFrame); - if (imageBuffer.size() > imageBufferLenght) { - imageBuffer.remove(0); - setBufferFull(true); - } else { - setBufferFull(false); - } - } else { - setBufferFull(true); - } - //Update data - if (!renderer.isPaused()) { - updateStreamData(); - } - updateMarker(); - } - } - manageFit(bi, data); - manageUserOverlays(bi, data); - } - //updateImageData(); - } - - @Override - public void onError(Object o, Exception ex) { - //System.err.println(ex); - } - }); - - } catch (Exception ex) { - showException(ex); - renderer.clearOverlays(); - updatePipelineControls(); - if (renderer.getDevice() == null) { - //renderer.setZoom(1.0); - //renderer.setMode(RendererMode.Zoom); - errorOverlay = new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - errorOverlay.setFixed(true); - errorOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - renderer.addOverlay(errorOverlay); - } - } finally { - //checkReticle(); - onTimer(); - } - onChangeColormap(null); - checkBackground.setEnabled(true); - if (changed) { - boolean electrons = getCameraType(cameraName).equals(ELECTRONS_TYPE); - comboScreen.setModel(new DefaultComboBoxModel()); - comboScreen.setEnabled(false); - comboFilter.setModel(new DefaultComboBoxModel()); - comboFilter.setEnabled(false); - panelFilter.setVisible(electrons); - panelScreen.setVisible(electrons); - if (electrons) { - //Parallelizing initialization - devicesInitTask = new Thread(() -> { - try { - if (cameraName.contains("DSRM")) { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); - } else { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); - } - screen.setMonitored(true); - screen.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : screen.getPositions()) { - model.addElement(pos); - } - comboScreen.setModel(model); - comboScreen.setSelectedItem(screen.read()); - - } catch (Exception ex) { - comboScreen.setModel(new DefaultComboBoxModel()); - System.err.println(ex.getMessage()); - screen = null; - } - comboScreen.setEnabled(screen != null); - valueScreen.setDevice(screen); - - try { - filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); - filter.setMonitored(true); - filter.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : filter.getPositions()) { - model.addElement(pos); - } - comboFilter.setModel(model); - comboFilter.setSelectedItem(filter.read()); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - filter = null; - } - comboFilter.setEnabled(filter != null); - valueFilter.setDevice(filter); - }); - devicesInitTask.start(); - } - } - } - - class ImageIntegrator extends ColormapSource { - - ImageIntegrator(int num) { - super("Image Averager", camera.getConfig()); - boolean continuous = (num < 0); - final int numImages = Math.abs(num); - - camera.addListener(new ImageListener() { - final ArrayList buffer = new ArrayList(); - Data integration = null; - - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - try { - if (continuous) { - buffer.add(data); - if (buffer.size() >= numImages) { - for (Data d : buffer) { - process(d); - } - } - } else { - buffer.add(null); //Just to count - process(data); - } - } catch (Exception ex) { - buffer.clear(); - integration = null; - ImageIntegrator.this.pushData(null); - ex.printStackTrace(); - return; - } - if (buffer.size() >= numImages) { - if (continuous) { - buffer.remove(0); - } else { - buffer.clear(); - } - if (integration != null) { - //integration.div(numImages); - ImageIntegrator.this.pushData(integration); - } - integration = null; - } - } - - void process(Data data) { - if (integration == null) { - integration = new Data(data); - } else { - integration.sum(data); - } - } - - @Override - public void onError(Object origin, Exception ex) { - } - }); - - } - } - - boolean bufferFull = true; - - void setBufferFull(boolean value) { - if (value != bufferFull) { - SwingUtilities.invokeLater(() -> { - buttonPause.setBackground(value ? buttonSave.getBackground() : buttonSave.getBackground().brighter()); - }); - bufferFull = value; - } - } - - volatile Dimension imageSize; - - void checkReticle() { - if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) { - //renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800, 800), 200); - renderer.setShowReticle(true); - } else { - //renderer.setCalibration(null); - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - void checkMarker(Point p) throws IOException { - if (camera != null) { - if (buttonMarker.isSelected()) { - Dimension d = renderer.getImageSize(); - if (p == null) { - p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - } - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - marker.setPassive(false); - } else { - marker = null; - } - renderer.setMarker(marker); - onMarkerChanged(); - } - } - - Point lastMarkerPos; - - void onMarkerChanged() throws IOException { - lastMarkerPos = getStreamMarkerPos(); - if (marker == null) { - setInstanceConfigValue("Marker", null); - } else { - setInstanceConfigValue("Marker", new int[]{marker.getPosition().x, marker.getPosition().y}); - } - } - - void updateMarker() { - try { - if (server != null) { - Point p = getStreamMarkerPos(); - if (p != null) { - //To prevent a local change being overriden by a message having the old settings. - //TODO: This is not bullet-proof, as one can have 2 changes between 2 frames... - if (!p.equals(lastMarkerPos)) { - if (p.x == Integer.MIN_VALUE) { - if (buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - checkMarker(null); - } - } else { - if (!buttonMarker.isSelected()) { - buttonMarker.setSelected(true); - checkMarker(p); - } else { - if (!p.equals(marker.getPosition())) { - marker.setPosition(p); - } - } - } - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - Point getStreamMarkerPos() throws IOException { - //System.out.println(server.getInstanceConfig().get("Marker")); - Map pars = server.getProcessingParameters(); - if (pars != null) { - List markerPosition = (List) pars.get("Marker"); - if (markerPosition != null) { - return new Point((Integer) markerPosition.get(0), (Integer) markerPosition.get(1)); - } - return new Point(Integer.MIN_VALUE, Integer.MIN_VALUE); - } - return null; - } - - void clearMarker() { - marker = null; - renderer.setMarker(marker); - } - - void setInstanceConfigValue(String name, Object value) throws IOException { - if (server != null) { - Map map = server.getInstanceConfig(); - map.put(name, value); - server.setInstanceConfig(map); - } - } - - void updateZoom() { - try { - buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom) { - if (renderer.getZoom() == 1) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getZoom() == 0.5) { - buttonZoom05.setSelected(true); - } else if (renderer.getZoom() == 0.25) { - buttonZoom025.setSelected(true); - } else if (renderer.getZoom() == 2.0) { - buttonZoom2.setSelected(true); - } else { - buttonGroup1.clearSelection(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - boolean updatingColormap; - - void updateColormap() { - updatingColormap = true; - try { - if ((camera != null) && (camera instanceof ColormapSource)) { - ColormapSourceConfig config = ((ColormapSource) camera).getConfig(); - comboColormap.setSelectedItem(config.colormap); - if (config.isDefaultColormap()) { - buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic) { - buttonAutomatic.setSelected(true); - } else { - buttonManual.setSelected(true); - } - btFixColormapRange.setVisible(buttonAutomatic.isSelected()); - spinnerMin.setEnabled(buttonManual.isSelected()); - spinnerMax.setEnabled(buttonManual.isSelected()); - if (!Double.isNaN(config.colormapMin)) { - spinnerMin.setValue(Math.min(Math.max((int) config.colormapMin, 0), 65535)); - } - if (!Double.isNaN(config.colormapMax)) { - spinnerMax.setValue(Math.min(Math.max((int) config.colormapMax, 0), 65535)); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatingColormap = false; - } - - void updatePipelineProperties() { - goodRegion = checkGoodRegion.isSelected(); - spinnerThreshold.setVisible(checkThreshold.isSelected()); - setGoodRegionOptionsVisible(goodRegion); - slicing = goodRegion && checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - updatingServerControls = false; - } - - boolean updatingServerControls; - - void updatePipelineControls() { - if (server != null) { - updatingServerControls = true; - if (server.isStarted()) { - try { - checkBackground.setSelected(server.getBackgroundSubtraction()); - Double threshold = (server.getThreshold()); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (server.getGoodRegion()); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - spinnerGrThreshold.setValue(((Number) gr.get("threshold")).doubleValue()); - spinnerGrScale.setValue(((Number) gr.get("gfscale")).doubleValue()); - } - Map slicing = (server.getSlicing()); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - spinnerSlNumber.setValue(((Number) slicing.get("number_of_slices")).intValue()); - spinnerSlScale.setValue(((Number) slicing.get("scale")).doubleValue()); - spinnerSlOrientation.setValue((String) slicing.get("orientation")); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - updatePipelineProperties(); - } - } - - boolean changedPipelinePars(Map pars1, Map pars2) { - String[] keys = new String[]{"image_background_enable", "image_threshold", "image_good_region", - "threshold", "gfscale", "image_slices", "number_of_slices", "scale", "orientation"}; - for (String key : keys) { - Object o1 = pars1.get(key); - Object o2 = pars2.get(key); - if (o1 == null) { - if (o2 != null) { - return true; - } - } else if (!o1.equals(o2)) { - return true; - } - } - return false; - } - - void updatePipelineControls(Map pars) { - if (pars != null) { - updatingServerControls = true; - try { - boolean background = (boolean) pars.get("image_background_enable"); - checkBackground.setSelected(background); - Double threshold = (Double) (pars.get("image_threshold")); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (Map) pars.get("image_good_region"); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - Double value = ((Number) gr.get("threshold")).doubleValue(); - spinnerGrThreshold.setValue(value); - Double scale = ((Number) gr.get("gfscale")).doubleValue(); - spinnerGrScale.setValue(scale); - } - Map slicing = (Map) (pars.get("image_slices")); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - int slices = ((Number) slicing.get("number_of_slices")).intValue(); - spinnerSlNumber.setValue(slices); - double scale = ((Number) slicing.get("scale")).doubleValue(); - spinnerSlScale.setValue(scale); - String orientation = (String) slicing.get("orientation"); - spinnerSlOrientation.setValue(orientation); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatePipelineProperties(); - } - } - - void setGoodRegionOptionsVisible(boolean visible) { - spinnerGrThreshold.setVisible(visible); - labelGrThreshold.setVisible(visible); - spinnerGrScale.setVisible(visible); - labelGrScale.setVisible(visible); - panelSlicing.setVisible(visible); - } - - void setSlicingOptionsVisible(boolean visible) { - spinnerSlNumber.setVisible(visible); - labelSlNumber.setVisible(visible); - spinnerSlScale.setVisible(visible); - labelSlScale.setVisible(visible); - spinnerSlOrientation.setVisible(visible); - labelSlOrientation.setVisible(visible); - } - - boolean isCameraStopped() { - if ((server != null) && !server.isStarted()) { - return true; - } - return ((camera == null) || camera.isClosed()); - } - - boolean updatingButtons; - - void updateButtons() { - updatingButtons = true; - try { - boolean active = !isCameraStopped();//(camera != null); - buttonSave.setEnabled(active); - buttonGrabBackground.setEnabled(active); - buttonMarker.setEnabled(active); - buttonProfile.setEnabled(active); - buttonFit.setEnabled(active); - buttonReticle.setEnabled(active && camera.getConfig().isCalibrated()); - buttonStreamData.setEnabled(active && (server != null)); - buttonPause.setEnabled(active); - - if (renderer.isPaused() != buttonPause.isSelected()) { - buttonPause.setSelected(renderer.isPaused()); - buttonPauseActionPerformed(null); - } - if (renderer.getShowReticle() != buttonReticle.isSelected()) { - //buttonReticle.setSelected(renderer.getShowReticle()); - } - if ((renderer.getMarker() == null) && buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - } - buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - - } finally { - updatingButtons = false; - } - } - - Frame lastFrame = null; - Map lastPipelinePars = null; - - @Override - protected void onTimer() { - for (Device dev : new Device[]{screen, filter}) { - if (dev != null) { - dev.request(); - } - } - - textState.setText((camera == null) ? "" : camera.getState().toString()); - if (App.hasArgument("s")) { - try { - ((Source) getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } - } - updateZoom(); - updateColormap(); - updateButtons(); - checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); - buttonScale.setSelected(renderer.getShowColormapScale()); - try { - Frame frame = getCurrentFrame(); - if (frame != lastFrame) { - lastFrame = frame; - if (frame != null) { - Map pars = getProcessingParameters(frame.cache); - if ((lastPipelinePars == null) || changedPipelinePars(pars, lastPipelinePars)) { - //System.out.println("Update pipeline: " + pars); - lastPipelinePars = pars; - updatePipelineControls(pars); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - Pen penFit = new Pen(new Color(192, 105, 0), 0); - Pen penCross = new Pen(new Color(192, 105, 0), 0); - Pen penSlices = new Pen(Color.CYAN.darker(), 1); - - Frame getCurrentFrame() { - if ((imageBufferLenght > 1) && (renderer.isPaused())) { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - return (index < imageBuffer.size()) ? imageBuffer.get(index) : null; - } - } - return currentFrame; - } - - Frame getFrame(Data data) { - synchronized (imageBuffer) { - for (Frame f : imageBuffer) { - if (f.data == data) { - return f; - } - } - } - return null; - } - - void setImageBufferSize(int size) { - if (renderer.isPaused()) { - throw new RuntimeException("Cannot change buffer size whn paused"); - } - synchronized (imageBuffer) { - imageBufferLenght = size; - imageBuffer.clear(); - } - - } - - Overlay[][] getFitOverlays(Data data) { - Overlays.Polyline hgaussian = null; - Overlays.Polyline vgaussian = null; - Overlays.Polyline hprofile = null; - Overlays.Polyline vprofile = null; - Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null; - Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null; - double[] pX = null, pY = null, gX = null, gY = null; - PointDouble[] sliceCenters = null; - if (data != null) { - int height = data.getHeight(); - int width = data.getWidth(); - int profileSize = renderer.getProfileSize(); - ImageData id = null; - if ((useServerStats) && (server != null)) { - try { - id = getFrame(data); - if (id == null) { - return null; - } - xMean = id.x_fit_mean; - xSigma = id.x_fit_standard_deviation; - yMean = id.y_fit_mean; - ySigma = id.y_fit_standard_deviation; - gX = id.x_fit_gauss_function; - gY = id.y_fit_gauss_function; - pX = id.x_profile; - pY = id.y_profile; - xCom = id.x_center_of_mass; - xRms = id.x_rms; - yCom = id.y_center_of_mass; - yRms = id.y_rms; - sliceCenters = id.sliceCenters; - - profileSize /= 4; - if (pX != null) { - int[] xp = Arr.indexesInt(pX.length); - int[] xg = xp; - int[] yp = new int[pX.length]; - int[] yg = new int[pX.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_x > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gX, id.gr_pos_x, id.gr_pos_x + id.gr_size_x))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gX != null) { - yg[i] = (int) (height - 1 - (((gX[i] - minGauss) / rangeGauss) * profileSize)); - } - yp[i] = (int) (height - 1 - (((pX[i] - minProfile) / rangeProfile) * profileSize)); - } - - if (goodRegion && id.gr_size_x > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - yg = Arrays.copyOfRange(yg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - } - - vgaussian = new Overlays.Polyline(penFit, xg, yg); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - - if (pY != null) { - int[] xp = new int[pY.length]; - int[] xg = new int[pY.length]; - int[] yp = Arr.indexesInt(pY.length); - int[] yg = yp; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_y > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gY, id.gr_pos_y, id.gr_pos_y + id.gr_size_y))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gY != null) { - xg[i] = (int) (((gY[i] - minGauss) / rangeGauss) * profileSize); - } - xp[i] = (int) (((pY[i] - minProfile) / rangeProfile) * profileSize); - } - - if (goodRegion && id.gr_size_y > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - yg = Arrays.copyOfRange(yg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - } - hgaussian = new Overlays.Polyline(penFit, xg, yg); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - return null; - } - } else { - ArrayProperties properties = data.getProperties(); - double maxPlot = properties.max; - double minPlot = properties.min; - double rangePlot = maxPlot - minPlot; - - if (rangePlot <= 0) { - return null; - } - if (renderer.getCalibration() != null) { - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height - minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - if (xSigma != null) { - xSigma *= renderer.getCalibration().getScaleX(); - } - if (ySigma != null) { - ySigma *= renderer.getCalibration().getScaleY(); - } - if (xMean != null) { - xMean = data.getX((int) Math.round(xMean)); - } - if (yMean != null) { - yMean = data.getY((int) Math.round(yMean)); - } - } - } - final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px"; - final String fmt = "%7.1f" + units; - Overlays.Text textCom = null; - Overlay[] pOv = null, fOv = null; - Font fontInfoText = new Font(Font.MONOSPACED, 0, 14); - Point textPosition = new Point(12, 20); - if (showProfile) { - if ((xCom != null) && (yCom != null)) { - String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt, xCom, xRms, yCom, yRms); - textCom = new Overlays.Text(renderer.getPenProfile(), text, fontInfoText, textPosition); - textCom.setFixed(true); - textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - } - pOv = new Overlay[]{hprofile, vprofile, textCom}; - textPosition = new Point(textPosition.x, textPosition.y + 34); - } - if (showFit) { - Overlays.Crosshairs cross = null; - Overlays.Text textFit = null; - if ((xMean != null) && (yMean != null)) { - String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt, xMean, xSigma, yMean, ySigma); - textFit = new Overlays.Text(penFit, text, fontInfoText, textPosition); - textFit.setFixed(true); - textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - Point center = new Point(xMean.intValue(), yMean.intValue()); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean)); - xSigma /= renderer.getCalibration().getScaleX(); - ySigma /= renderer.getCalibration().getScaleY(); - } - cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue()))); - } - textPosition = new Point(textPosition.x, textPosition.y + 34); - fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit}; - - if (goodRegion && (id != null)) { - try { - double[] x = id.gr_x_axis; - double[] y = id.gr_y_axis; - Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); - goodRegionOv.setCalibration(renderer.getCalibration()); - goodRegionOv.setPosition(new Point(id.gr_pos_x, id.gr_pos_y)); - goodRegionOv.setSize(new Dimension(id.gr_x_axis.length, id.gr_y_axis.length)); - fOv = Arr.append(fOv, goodRegionOv); - - if (slicing) { - if (sliceCenters != null) { - for (PointDouble sliceCenter : sliceCenters) { - Overlays.Crosshairs center = new Overlays.Crosshairs(penSlices); - center.setCalibration(renderer.getCalibration()); - center.setAbsolutePosition(sliceCenter); - center.setSize(new Dimension(10, 10)); - fOv = Arr.append(fOv, center); - } - if (sliceCenters.length > 1) { - double[] fit = fitPolynomial(sliceCenters, 1); - double angle = Math.toDegrees(Math.atan(fit[1])); - Overlays.Text text = new Overlays.Text(penSlices, String.format("slice: \u03B8= %5.1fdeg", angle), fontInfoText, textPosition); - text.setFixed(true); - text.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - fOv = Arr.append(fOv, text); - } - } - } - } catch (Exception ex) { - } - } - - } - return new Overlay[][]{pOv, fOv}; - } - return null; - } - - class UserOverlay { - - String name; - Overlay obj; - String[] channels; - } - ArrayList userOverlayConfig; - - void parseUserOverlays() { - Properties userOverlays = new Properties(); - userOverlayConfig = new ArrayList<>(); - if (userOverlaysConfigFile != null) { - try { - try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { - userOverlays.load(in); - - for (String name : userOverlays.stringPropertyNames()) { - String val = userOverlays.getProperty(name); - try { - UserOverlay uo = new UserOverlay(); - uo.name = name; - String type = val.substring(0, val.indexOf("(")).trim(); - String pars = val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")).trim(); - String[] tokens = pars.split(","); - for (int i = 0; i < tokens.length; i++) { - tokens[i] = tokens[i].trim(); - } - Color color = Color.GRAY; - try { - color = (Color) Color.class.getField(tokens[tokens.length - 1].toUpperCase()).get(null); - } catch (Exception ex) { - } - Pen pen = new Pen(color); - try { - String[] penTokens = tokens[tokens.length - 1].split(":"); - color = (Color) Color.class.getField(penTokens[0].toUpperCase()).get(null); - int width = Integer.valueOf(penTokens[1]); - Pen.LineStyle style = Pen.LineStyle.valueOf(penTokens[2]); - pen = new Pen(color, width, style); - } catch (Exception ex) { - } - switch (type) { - case "Point": - uo.obj = new Overlays.Crosshairs(); - uo.obj.setSize(new Dimension(Integer.valueOf(tokens[2]), Integer.valueOf(tokens[3]))); - break; - case "Line": - uo.obj = new Overlays.Line(); - break; - case "Arrow": - uo.obj = new Overlays.Arrow(); - break; - case "Rect": - uo.obj = new Overlays.Rect(); - break; - case "Ellipse": - uo.obj = new Overlays.Ellipse(); - break; - case "Polyline": - uo.obj = new Overlays.Polyline(); - break; - } - if (type.equals("Polyline") || type.equals("Point")) { - uo.channels = new String[]{tokens[0], tokens[1]}; - } else { - uo.channels = new String[]{tokens[0], tokens[1], tokens[2], tokens[3]}; - } - uo.obj.setPen(pen); - userOverlayConfig.add(uo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - Overlay[] getUserOverlays(Data data) { - ArrayList ret = new ArrayList<>(); - if (server != null) { - ImageData id = getFrame(data); - for (UserOverlay uo : userOverlayConfig) { - try { - Overlay ov = uo.obj; - //Overlay ov = (Overlay)uo.cls.newInstance(); - ov.setCalibration(renderer.getCalibration()); - boolean valid = false; - if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : id.getDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : id.getDoubleArray(uo.channels[1]); - if ((x != null) || (y != null)) { - if (x == null) { - x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); - } - if (y == null) { - y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length); - } - ((Overlays.Polyline) ov).updateAbsolute(x, y); - valid = true; - } - } else { - Double x = id.getDouble(uo.channels[0]); - Double y = id.getDouble(uo.channels[1]); - if ((x != null) && (y != null)) { - PointDouble position = new PointDouble(x, y); - ov.setAbsolutePosition(position); - if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = id.getDouble(uo.channels[2]); - Double y2 = id.getDouble(uo.channels[3]); - if ((x != null) && (y != null)) { - DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); - ov.setAbsoluteSize(size); - valid = true; - } - } else { - valid = true; - } - } - } - if (valid) { - ret.add(ov); - } - } catch (Exception ex) { - //ex.printStackTrace(); - } - } - } - return ret.toArray(new Overlay[0]); - } - - double[] getComRms(double[] arr, double[] x) { - if (arr != null) { - double xmd = 0; - double xmd2 = 0; - double total = 0; - for (int i = 0; i < arr.length; i++) { - double v = (arr[i] * x[i]); - xmd += v; - xmd2 += (v * x[i]); - total += arr[i]; - } - if (total > 0) { - double com = xmd / total; - double com2 = xmd2 / total; - double rms = Math.sqrt(Math.abs(com2 - com * com)); - return new double[]{com, rms}; - } - } - return new double[]{Double.NaN, Double.NaN}; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] fitPolynomial(PointDouble[] points, int order) { - double[] y = new double[points.length]; - double[] x = new double[points.length]; - for (int i = 0; i < points.length; i++) { - x[i] = points[i].x; - y[i] = points[i].y; - } - return fitPolynomial(y, x, order); - } - - double[] fitPolynomial(double[] y, double[] x, int order) { - try { - ArrayProperties pY = ArrayProperties.get(y); - PolynomialCurveFitter fitter = PolynomialCurveFitter.create(order).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - void setHistogramVisible(boolean value) { - if (value) { - if ((histogramDialog == null) || (!histogramDialog.isShowing())) { - Histogram histogram = new Histogram(true); - histogram.setRenderer(renderer); - histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram); - renderer.refresh(); - } - } else { - if (histogramDialog != null) { - histogramDialog.setVisible(false); - histogramDialog = null; - } - } - } - - void setLaserState(boolean value) throws Exception { - System.out.println("Setting laser state: " + value); - Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); - Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); - Thread.sleep(3000); - } - - boolean getLaserState() throws Exception { - return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); - } - - void elog(String logbook, String title, String message, String[] attachments) throws Exception { - String domain = ""; - String category = "Info"; - String entry = ""; - StringBuffer cmd = new StringBuffer(); - - cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); - cmd.append("-a \"Author=ScreenPanel\" "); - cmd.append("-a \"Type=pshell\" "); - cmd.append("-a \"Entry=").append(entry).append("\" "); - cmd.append("-a \"Title=").append(title).append("\" "); - cmd.append("-a \"Category=").append(category).append("\" "); - cmd.append("-a \"Domain=").append(domain).append("\" "); - for (String attachment : attachments) { - cmd.append("-f \"").append(attachment).append("\" "); - } - cmd.append("-n 1 "); - cmd.append("\"").append(message).append("\" "); - System.out.println(cmd.toString()); - - final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); - new Thread(() -> { - try { - process.waitFor(); - int bytes = process.getInputStream().available(); - byte[] arr = new byte[bytes]; - process.getInputStream().read(arr, 0, bytes); - System.out.println(new String(arr)); - bytes = process.getErrorStream().available(); - arr = new byte[bytes]; - process.getErrorStream().read(arr, 0, bytes); - System.err.println(new String(arr)); - } catch (Exception ex) { - System.err.println(ex); - } - }).start(); - } - - void centralizeRenderer() { - Point center = null; - Dimension size = renderer.getImageSize(); - double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom(); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().getCenter(); - } else if (size != null) { - center = new Point(size.width / 2, size.height / 2); - } - if (center != null) { - Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0), - Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0)); - renderer.setViewPosition(topleft); - } - } - - void updatePause() { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - if (index < imageBuffer.size()) { - Data data = imageBuffer.get(index).data; - long pid = imageBuffer.get(index).cache.getPulseId(); - BufferedImage image = camera.generateImage(data); - renderer.setImage(renderer.getOrigin(), image, data); - - String text = "PID: " + pid; - if (imagePauseOverlay == null) { - Font font = new Font("Verdana", Font.PLAIN, 12); - Dimension d = SwingUtils.getTextSize(text, renderer.getFontMetrics(font)); - imagePauseOverlay = new Text(renderer.getPenErrorText(), "", font, new Point(-20 - d.width, 42)); - imagePauseOverlay.setFixed(true); - imagePauseOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - renderer.addOverlay(imagePauseOverlay); - } - //imagePauseOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS")); - imagePauseOverlay.update(text); - manageFit(image, data); - manageUserOverlays(image, data); - } - } - updateStreamData(); - } - - void removePauseOverlay() { - renderer.removeOverlay(imagePauseOverlay); - imagePauseOverlay = null; - } - - void saveSnapshot() throws Exception { - boolean paused = isPaused(); - try{ - if (!paused){ - setPaused(true); - } - String snapshotFile = null; - synchronized (imageBuffer) { - Frame frame = getCurrentFrame(); - if (frame == null) { - throw new Exception("No current image"); - } - ArrayList frames = new ArrayList<>(); - frames.add(frame); - this.saveFrames(cameraName + "_camera_snapshot", frames); - - //Enforce the same timestamp to data & image files. - snapshotFile = getContext().getExecutionPars().getPath() + ".png"; - //renderer.saveSnapshot(snapshotFile, "png", true); - ImageBuffer.saveImage(SwingUtils.createImage(renderer), snapshotFile, "png"); - } - - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{0, 180}; //Minimum width - layout.rowHeights = new int[]{30, 30, 30}; //Minimum height - panel.setLayout(layout); - JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); - JTextField textComment = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Data file:"), c); - c.gridy = 1; - panel.add(new JLabel("Logbook:"), c); - c.gridy = 2; - panel.add(new JLabel("Comment:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(textComment, c); - c.gridy = 1; - panel.add(comboLogbook, c); - c.gridy = 0; - panel.add(new JLabel(getContext().getExecutionPars().getPath()), c); - - if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes) { - StringBuilder message = new StringBuilder(); - message.append("Camera: ").append(cameraName).append(" ("). - append((server != null) ? "server" : "direct").append(")").append("\n"); - message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); - message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); - message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); - message.append("Comment: ").append(textComment.getText()).append("\n"); - //Add slicing message - if ((fitOv != null) && (fitOv.length > 5) && (fitOv[fitOv.length - 1] instanceof Overlays.Text)) { - Overlays.Text text = (Overlays.Text) fitOv[fitOv.length - 1]; - message.append(text.getText()).append("\n"); - } - elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - } finally{ - if (!paused){ - setPaused(false); - } - } - } - - void saveStack() throws Exception { - synchronized (imageBuffer) { - saveFrames(cameraName + "_camera_stack", imageBuffer); - } - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath()); - } - - public static String getCameraType(String name) { - if (name == null) { - return ""; - } - for (String s : new String[]{"LCAM"}) { - if (name.contains(s)) { - return LASER_TYPE; - } - } - for (String s : new String[]{"DSCR", "DSRM", "DLAC"}) { - if (name.contains(s)) { - return ELECTRONS_TYPE; - } - } - for (String s : new String[]{"PROF", "PPRM", "PSSS", "PSCR", "PSRD"}) { - if (name.contains(s)) { - return PHOTONICS_TYPE; - } - } - return "Unknown"; - } - - public Map getProcessingParameters(StreamValue value) throws IOException { - return (Map) JsonSerializer.decode(value.getValue("processing_parameters").toString(), Map.class); - } - - void saveFrames(String name, ArrayList frames) throws IOException { - ArrayList values = new ArrayList<>(); - for (Frame frame : frames) { - values.add(frame.cache); - } - saveImages(name, values); - } - - void saveImages(String name, ArrayList images) throws IOException { - int depth = images.size(); - if (depth == 0) { - return; - } - StreamValue first = images.get(0); - String pathRoot = "/camera1/"; - String pathImage = pathRoot + "image"; - String pathPid = pathRoot + "pulse_id"; - String pathTimestampStr = pathRoot + "timestamp_str"; - Map processingPars = getProcessingParameters(first); - String camera = (String) processingPars.get("camera_name"); - String type = getCameraType(camera); - - int width = ((Number) first.getValue("width")).intValue(); - int height = ((Number) first.getValue("height")).intValue(); - Class dataType = first.getValue("image").getClass().getComponentType(); - - getContext().setExecutionPars(name); - DataManager dm = getContext().getDataManager(); - - //Create tables - dm.createDataset(pathImage, dataType, new int[]{depth, height, width}); - dm.createDataset(pathPid, Long.class, new int[]{depth}); - dm.createDataset(pathTimestampStr, String.class, new int[]{depth}); - for (String id : first.getIdentifiers()) { - Object val = first.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(first); - for (String key : pars.keySet()) { - if ((pars.get(key) != null) && (pars.get(key) instanceof Map)) { - for (Object k : ((Map) pars.get(key)).keySet()) { - Object v = ((Map) pars.get(key)).get(k); - dm.setAttribute(pathImage, key + " " + k, (v == null) ? "" : v); - } - } else { - Object value = pars.get(key); - if (value == null) { - value = ""; - } else if (value instanceof List) { - Class cls = (((List) value).size() > 0) ? ((List) value).get(0).getClass() : double.class; - value = Convert.toPrimitiveArray(value, cls); - //value = Convert.toDouble(value); - } - dm.setAttribute(pathImage, key, value); - } - } - } else if (val.getClass().isArray()) { - dm.createDataset(pathRoot + id, Double.class, new int[]{depth, Array.getLength(val)}); - } else { - dm.createDataset(pathRoot + id, val.getClass(), new int[]{depth}); - } - } - - //Add metadata - dm.setAttribute(pathRoot, "Camera", camera); - dm.setAttribute(pathRoot, "Images", depth); - dm.setAttribute(pathRoot, "Interval", -1); - dm.setAttribute(pathRoot, "Type", type); - if (type.equals(ELECTRONS_TYPE)) { - dm.setAttribute(pathRoot, "Screen", String.valueOf(valueScreen.getLabel().getText())); - dm.setAttribute(pathRoot, "Filter", String.valueOf(valueFilter.getLabel().getText())); - } - - //Save data - for (int index = 0; index < depth; index++) { - StreamValue streamValue = images.get(index); - dm.setItem(pathImage, streamValue.getValue("image"), new long[]{index, 0, 0}, new int[]{1, height, width}); - dm.setItem(pathPid, streamValue.getPulseId(), index); - dm.setItem(pathTimestampStr, Chrono.getTimeStr(streamValue.getTimestamp(), "YYYY-MM-dd HH:mm:ss.SSS"), index); - - for (String id : streamValue.getIdentifiers()) { - Object val = streamValue.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - } else if (val.getClass().isArray()) { - dm.setItem(pathRoot + id, val, index); - } else { - dm.setItem(pathRoot + id, val, index); - } - } - } - getContext().getDataManager().closeOutput(); - } - - StandardDialog calibrationDialolg; - - void calibrate() throws Exception { - if (server != null) { - server.resetRoi(); - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraCalibrationDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), server.getCurrentCamera(), renderer}); - SwingUtils.centerComponent(getTopLevel(), calibrationDialolg); - calibrationDialolg.setVisible(true); - calibrationDialolg.setListener(new StandardDialogListener() { - @Override - public void onWindowOpened(StandardDialog dlg) { - } - - @Override - public void onWindowClosed(StandardDialog dlg, boolean accepted) { - if (accepted) { - //comboCamerasActionPerformed(null); - } - } - }); - } - } - - StandardDialog dataTableDialog; - DefaultTableModel dataTableModel; - JTable dataTable; - - void showStreamData() { - dataTableModel = null; - if (server != null) { - - if ((dataTableDialog != null) && (dataTableDialog.isShowing())) { - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.requestFocus(); - return; - } - dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) { - public Class getColumnClass(int columnIndex) { - return String.class; - } - - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - }; - updateStreamData(); - StreamValue val = server.getStream().take(); - dataTable = new JTable(dataTableModel); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.setCellSelectionEnabled(true); - dataTable.getTableHeader().setReorderingAllowed(false); - dataTable.getTableHeader().setResizingAllowed(true); - dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); - dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(dataTable); - scrollPane.setPreferredSize(new Dimension(300, 400)); - dataTableDialog.setContentPane(scrollPane); - dataTableDialog.pack(); - dataTableDialog.setVisible(true); - dataTableDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - dataTableModel = null; - } - }); - dataTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - try { - int row = dataTable.getSelectedRow(); - int col = dataTable.getSelectedColumn(); - dataTable.setToolTipText(null); - if (row > 1) { - String id = String.valueOf(dataTable.getModel().getValueAt(row, 0)); - String locator = String.valueOf(dataTable.getModel().getValueAt(0, 1)); - String channelId = locator + " " + id; - dataTable.setToolTipText(channelId); - if ((e.getClickCount() == 2) && (!e.isPopupTrigger())) { - if (col == 0) { - SwingUtils.showMessage(dataTableDialog, "Channel Identifier", "Copied to clipboard: " + channelId); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - clipboard.setContents(new StringSelection(channelId), (Clipboard clipboard1, Transferable contents) -> { - }); - } else { - Object obj = getCurrentFrame().cache.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(getCurrentFrame().cache); - StringBuilder sb = new StringBuilder(); - for (String key : pars.keySet()) { - sb.append(key).append(" = ").append(Str.toString(pars.get(key), 10)).append("\n"); - } - SwingUtils.showMessage(dataTableDialog, "Processing Parameters", sb.toString()); - } else if ((obj != null) && (obj.getClass().isArray() || (obj instanceof Number))) { - DeviceValueChart chart = new DeviceValueChart(); - Device dev = null; - if (obj.getClass().isArray()) { - dev = new ReadableRegisterArray(new ReadableArray() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - - @Override - public int getSize() { - return Array.getLength(getCurrentFrame().cache.getValue(id)); - } - }); - } else { - dev = new ReadableRegisterNumber(new ReadableNumber() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - }); - } - dev.setPolling(1000); - chart.setDevice(dev); - JDialog dlg = SwingUtils.showDialog(dataTableDialog, cameraName + " " + id, null, chart); - //TODO: - //PlotBase plot = chart.getPlot(); - //if (plot!=null){ - // plot.setPlotBackgroundColor(Color.BLACK); - //} - } - } - } - } - } catch (Exception ex) { - showException(ex); - } - } - }); - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - updateStreamData(); - } - } - - volatile boolean updatingStreamData = false; - - void updateStreamData() { - if ((dataTableDialog == null) || !dataTableDialog.isShowing() || updatingStreamData) { - return; - } - updatingStreamData = true; - SwingUtilities.invokeLater(() -> { - updatingStreamData = false; - if ((dataTableModel != null) && (server != null)) { - StreamValue value = server.getValue(); - Frame frame = getCurrentFrame(); - int[] sel_rows = (dataTable == null) ? null : dataTable.getSelectedRows(); - int[] sel_cols = (dataTable == null) ? null : dataTable.getSelectedColumns(); - List ids = (value == null) ? new ArrayList<>() : new ArrayList(value.getIdentifiers()); - if (ids.size() + 4 != dataTableModel.getRowCount()) { - dataTableModel.setNumRows(0); - try { - dataTableModel.addRow(new Object[]{"Locator", server.getUrl() + "/" + ((value == null) ? instanceName : server.getCurrentInstance())}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Locator", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"Stream", server.getStreamAddress()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Stream", ex.getMessage()}); - } - dataTableModel.addRow(new Object[]{"PID", ""}); - dataTableModel.addRow(new Object[]{"Timestamp", ""}); - Collections.sort(ids); - for (String id : ids) { - dataTableModel.addRow(new Object[]{id, ""}); - } - } - - if ((frame != null) && (frame.cache != null)) { - dataTableModel.setValueAt(frame.cache.getPulseId(), 2, 1); //PID - dataTableModel.setValueAt(frame.cache.getTimestamp(), 3, 1); //Timestamp - for (int i = 4; i < dataTableModel.getRowCount(); i++) { - String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - //Object obj = server.getValue(id); - Object obj = frame.cache.getValue(id); - if (obj != null) { - if (obj.getClass().isArray()) { - obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; - } else if (obj instanceof Double) { - obj = Convert.roundDouble((Double) obj, 1); - } else if (obj instanceof Float) { - obj = Convert.roundDouble((Float) obj, 1); - } - } - dataTableModel.setValueAt(String.valueOf(obj), i, 1); - } - } - if ((sel_rows != null) && (sel_rows.length > 0)) { - //dataTable.setRowSelectionInterval((Integer)Arr.getMin(sel_rows), (Integer)Arr.getMax(sel_rows)); - dataTable.setRowSelectionInterval(sel_rows[0], sel_rows[sel_rows.length - 1]); - } - if ((sel_cols != null) && (sel_cols.length > 0)) { - //dataTable.setColumnSelectionInterval((Integer)Arr.getMin(sel_cols), (Integer)Arr.getMax(sel_cols)); - dataTable.setColumnSelectionInterval(sel_cols[0], sel_cols[sel_cols.length - 1]); - } - } - }); - } - - ImageIcon getIcon(String name) { - ImageIcon ret = null; - try { - //Path path = Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(),"resources", name + ".png"); - String dir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + "resources/"; - if (new File(dir + name + ".png").exists()) { - ret = new javax.swing.ImageIcon(dir + name + ".png"); - } else { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/" + name + ".png")); - if (MainFrame.isDark()) { - try { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/dark/" + name + ".png")); - } catch (Exception e) { - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return ret; - } - - String getIconName(JButton button) { - String ret = button.getIcon().toString(); - if (ret.indexOf(".") > 0) { - ret = ret.substring(0, ret.indexOf(".")); - } - return ret; - } - - void setPaused(boolean paused){ - removePauseOverlay(); - if (camera != null) { - synchronized (imageBuffer) { - if (paused) { - renderer.pause(); - panelCameraSelection.setVisible(false); - pauseSelection.setVisible(true); - if (imageBuffer.size() > 0) { - pauseSelection.setEnabled(true); - pauseSelection.setMaxValue(imageBuffer.size()); - pauseSelection.setValue(imageBuffer.size()); - updatePause(); - } else { - pauseSelection.setEnabled(false); - pauseSelection.setMaxValue(1); - pauseSelection.setValue(1); - } - } else { - imageBuffer.clear(); - renderer.resume(); - //renderer.clear(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - updateStreamData(); - } - } - - boolean isPaused(){ - return renderer.isPaused(); - } - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - buttonGroup4 = new javax.swing.ButtonGroup(); - jProgressBar1 = new javax.swing.JProgressBar(); - sidePanel = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - buttonZoomFit = new javax.swing.JRadioButton(); - buttonZoomStretch = new javax.swing.JRadioButton(); - buttonZoomNormal = new javax.swing.JRadioButton(); - buttonZoom025 = new javax.swing.JRadioButton(); - buttonZoom05 = new javax.swing.JRadioButton(); - buttonZoom2 = new javax.swing.JRadioButton(); - jPanel2 = new javax.swing.JPanel(); - checkHistogram = new javax.swing.JCheckBox(); - comboColormap = new javax.swing.JComboBox(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - buttonFullRange = new javax.swing.JRadioButton(); - buttonManual = new javax.swing.JRadioButton(); - buttonAutomatic = new javax.swing.JRadioButton(); - labelMin = new javax.swing.JLabel(); - spinnerMin = new javax.swing.JSpinner(); - spinnerMax = new javax.swing.JSpinner(); - labelMax = new javax.swing.JLabel(); - btFixColormapRange = new javax.swing.JButton(); - jPanel5 = new javax.swing.JPanel(); - buttonServer = new javax.swing.JRadioButton(); - buttonDirect = new javax.swing.JRadioButton(); - textState = new javax.swing.JTextField(); - filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767)); - panelScreen = new javax.swing.JPanel(); - valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); - comboScreen = new javax.swing.JComboBox(); - panelFilter = new javax.swing.JPanel(); - valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); - comboFilter = new javax.swing.JComboBox(); - panelScreen2 = new javax.swing.JPanel(); - checkThreshold = new javax.swing.JCheckBox(); - spinnerThreshold = new javax.swing.JSpinner(); - checkBackground = new javax.swing.JCheckBox(); - checkGoodRegion = new javax.swing.JCheckBox(); - spinnerGrScale = new javax.swing.JSpinner(); - spinnerGrThreshold = new javax.swing.JSpinner(); - labelGrThreshold = new javax.swing.JLabel(); - labelGrScale = new javax.swing.JLabel(); - panelSlicing = new javax.swing.JPanel(); - checkSlicing = new javax.swing.JCheckBox(); - labelSlScale = new javax.swing.JLabel(); - spinnerSlScale = new javax.swing.JSpinner(); - labelSlNumber = new javax.swing.JLabel(); - spinnerSlNumber = new javax.swing.JSpinner(); - labelSlOrientation = new javax.swing.JLabel(); - spinnerSlOrientation = new javax.swing.JSpinner(); - topPanel = new javax.swing.JPanel(); - toolBar = new javax.swing.JToolBar(); - buttonSidePanel = new javax.swing.JToggleButton(); - buttonStreamData = new javax.swing.JButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - buttonPause = new javax.swing.JToggleButton(); - jSeparator6 = new javax.swing.JToolBar.Separator(); - buttonMarker = new javax.swing.JToggleButton(); - buttonProfile = new javax.swing.JToggleButton(); - buttonFit = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonScale = new javax.swing.JToggleButton(); - buttonTitle = new javax.swing.JToggleButton(); - pauseSelection = new ch.psi.pshell.swing.ValueSelection(); - panelCameraSelection = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - jLabel5 = new javax.swing.JLabel(); - comboType = new javax.swing.JComboBox(); - renderer = new ch.psi.pshell.imaging.Renderer(); - - setPreferredSize(new java.awt.Dimension(873, 600)); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); - - buttonGroup1.add(buttonZoomFit); - buttonZoomFit.setText("Fit"); - buttonZoomFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomFitActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomStretch); - buttonZoomStretch.setText("Stretch"); - buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomStretchActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomNormal); - buttonZoomNormal.setText("Normal"); - buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomNormalActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("1/4"); - buttonZoom025.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom025ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("1/2"); - buttonZoom05.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom05ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom2); - buttonZoom2.setText("2"); - buttonZoom2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoomStretch)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05) - .addComponent(buttonZoom2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomFit) - .addComponent(buttonZoom05)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoom2)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap")); - - checkHistogram.setText("Histogram"); - checkHistogram.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkHistogramActionPerformed(evt); - } - }); - - comboColormap.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Type:"); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Range:"); - - buttonGroup3.add(buttonFullRange); - buttonFullRange.setText("Full"); - buttonFullRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonManual); - buttonManual.setText("Manual"); - buttonManual.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonAutomatic); - buttonAutomatic.setText("Automatic"); - buttonAutomatic.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - labelMin.setText("Min:"); - - spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); - spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); - spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - labelMax.setText("Max:"); - - btFixColormapRange.setText("Fix"); - btFixColormapRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btFixColormapRangeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonAutomatic) - .addComponent(buttonFullRange) - .addComponent(buttonManual) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMax) - .addGap(2, 2, 2) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMin) - .addGap(2, 2, 2) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(spinnerMin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFixColormapRange, spinnerMax, spinnerMin}); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3) - .addComponent(checkHistogram)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAutomatic) - .addComponent(jLabel4) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelMin) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonFullRange)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonManual) - .addComponent(labelMax) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - - buttonGroup4.add(buttonServer); - buttonServer.setSelected(true); - buttonServer.setText("Server"); - buttonServer.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonServerActionPerformed(evt); - } - }); - - buttonGroup4.add(buttonDirect); - buttonDirect.setText("Direct"); - buttonDirect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDirectActionPerformed(evt); - } - }); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonServer) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonDirect) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(56, 56, 56)) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonServer) - .addComponent(buttonDirect))) - .addContainerGap()) - ); - - panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); - - comboScreen.setEnabled(false); - comboScreen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboScreenActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); - panelScreen.setLayout(panelScreenLayout); - panelScreenLayout.setHorizontalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreenLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreenLayout.setVerticalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelFilter.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); - - comboFilter.setEnabled(false); - comboFilter.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboFilterActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelFilterLayout = new javax.swing.GroupLayout(panelFilter); - panelFilter.setLayout(panelFilterLayout); - panelFilterLayout.setHorizontalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelFilterLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelFilterLayout.setVerticalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFilterLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - panelScreen2.setBorder(javax.swing.BorderFactory.createTitledBorder("Pipeline")); - - checkThreshold.setText("Threshold"); - checkThreshold.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkThresholdActionPerformed(evt); - } - }); - - spinnerThreshold.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 99999.0d, 1.0d)); - spinnerThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerThresholdonChange(evt); - } - }); - - checkBackground.setText("Subtract Background"); - checkBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkBackgroundActionPerformed(evt); - } - }); - - checkGoodRegion.setText("Good Region"); - checkGoodRegion.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkGoodRegionActionPerformed(evt); - } - }); - - spinnerGrScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerGrScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - spinnerGrThreshold.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.04d, 1.0d, 0.1d)); - spinnerGrThreshold.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerGrThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - labelGrThreshold.setText("Threshold:"); - - labelGrScale.setText("Scale:"); - - checkSlicing.setText("Slicing"); - checkSlicing.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkSlicingActionPerformed(evt); - } - }); - - labelSlScale.setText("Scale:"); - - spinnerSlScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerSlScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlNumber.setText("Slices:"); - - spinnerSlNumber.setModel(new javax.swing.SpinnerNumberModel(2, 0, 1000, 1)); - spinnerSlNumber.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlNumber.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlOrientation.setText("Orientation:"); - - spinnerSlOrientation.setModel(new javax.swing.SpinnerListModel(new String[] {"vertical", "horizontal"})); - spinnerSlOrientation.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlOrientation.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - javax.swing.GroupLayout panelSlicingLayout = new javax.swing.GroupLayout(panelSlicing); - panelSlicing.setLayout(panelSlicingLayout); - panelSlicingLayout.setHorizontalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addComponent(checkSlicing) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlNumber) - .addGap(2, 2, 2) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlScale) - .addGap(2, 2, 2) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelSlOrientation) - .addGap(2, 2, 2) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - panelSlicingLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerSlNumber, spinnerSlOrientation, spinnerSlScale}); - - panelSlicingLayout.setVerticalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(checkSlicing) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlNumber)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlScale)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlOrientation))) - ); - - javax.swing.GroupLayout panelScreen2Layout = new javax.swing.GroupLayout(panelScreen2); - panelScreen2.setLayout(panelScreen2Layout); - panelScreen2Layout.setHorizontalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkThreshold) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addComponent(checkGoodRegion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(labelGrScale)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelGrThreshold))) - .addGap(2, 2, 2))) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - .addComponent(panelSlicing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addGap(6, 6, 6) - .addComponent(checkBackground) - .addGap(106, 106, 106)) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerThreshold}); - - panelScreen2Layout.setVerticalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(checkBackground) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkThreshold) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkGoodRegion) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrScale)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrThreshold)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelSlicing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - javax.swing.GroupLayout sidePanelLayout = new javax.swing.GroupLayout(sidePanel); - sidePanel.setLayout(sidePanelLayout); - sidePanelLayout.setHorizontalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - sidePanelLayout.setVerticalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - toolBar.setFloatable(false); - toolBar.setRollover(true); - - buttonSidePanel.setIcon(getIcon("List")); - buttonSidePanel.setSelected(true); - buttonSidePanel.setText(" "); - buttonSidePanel.setToolTipText("Show Side Panel"); - buttonSidePanel.setFocusable(false); - buttonSidePanel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSidePanel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSidePanelActionPerformed(evt); - } - }); - toolBar.add(buttonSidePanel); - - buttonStreamData.setIcon(getIcon("Details")); - buttonStreamData.setText(" "); - buttonStreamData.setToolTipText("Show Data Window"); - buttonStreamData.setFocusable(false); - buttonStreamData.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonStreamData.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStreamDataActionPerformed(evt); - } - }); - toolBar.add(buttonStreamData); - - buttonSave.setIcon(getIcon("Save")); - buttonSave.setText(" "); - buttonSave.setToolTipText("Save Snapshot"); - buttonSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - toolBar.add(buttonSave); - - buttonGrabBackground.setIcon(getIcon("Background")); - buttonGrabBackground.setText(" "); - buttonGrabBackground.setToolTipText("Grab Background"); - buttonGrabBackground.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - toolBar.add(buttonGrabBackground); - - buttonPause.setIcon(getIcon("Pause")); - buttonPause.setText(" "); - buttonPause.setToolTipText("Pause"); - buttonPause.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - toolBar.add(buttonPause); - - jSeparator6.setMaximumSize(new java.awt.Dimension(20, 32767)); - jSeparator6.setPreferredSize(new java.awt.Dimension(20, 0)); - jSeparator6.setRequestFocusEnabled(false); - toolBar.add(jSeparator6); - - buttonMarker.setIcon(getIcon("Marker")); - buttonMarker.setText(" "); - buttonMarker.setToolTipText("Show Marker"); - buttonMarker.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - toolBar.add(buttonMarker); - - buttonProfile.setIcon(getIcon("Profile" - + "")); - buttonProfile.setSelected(true); - buttonProfile.setText(" "); - buttonProfile.setToolTipText("Show Image Profile"); - buttonProfile.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonProfile.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonProfileActionPerformed(evt); - } - }); - toolBar.add(buttonProfile); - - buttonFit.setIcon(getIcon("Fit")); - buttonFit.setSelected(true); - buttonFit.setText(" "); - buttonFit.setToolTipText("Show Fit"); - buttonFit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - toolBar.add(buttonFit); - - buttonReticle.setIcon(getIcon("Reticule")); - buttonReticle.setSelected(true); - buttonReticle.setText(" "); - buttonReticle.setToolTipText("Show Reticle"); - buttonReticle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - toolBar.add(buttonReticle); - - buttonScale.setIcon(getIcon("Scale")); - buttonScale.setSelected(true); - buttonScale.setText(" "); - buttonScale.setToolTipText("Show Colormap Scale"); - buttonScale.setFocusable(false); - buttonScale.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonScale.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonScaleActionPerformed(evt); - } - }); - toolBar.add(buttonScale); - - buttonTitle.setIcon(getIcon("Title")); - buttonTitle.setSelected(true); - buttonTitle.setText(" "); - buttonTitle.setToolTipText("Show Camera Name"); - buttonTitle.setFocusable(false); - buttonTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonTitle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonTitleActionPerformed(evt); - } - }); - toolBar.add(buttonTitle); - - pauseSelection.setDecimals(0); - - jLabel1.setText("Camera:"); - - comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboCameras.setMaximumRowCount(30); - comboCameras.setMinimumSize(new java.awt.Dimension(127, 27)); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - jLabel5.setText("Type:"); - - comboType.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboType.setMaximumRowCount(30); - comboType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Laser", "Electrons", "Photonics" })); - comboType.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboTypeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelCameraSelectionLayout = new javax.swing.GroupLayout(panelCameraSelection); - panelCameraSelection.setLayout(panelCameraSelectionLayout); - panelCameraSelectionLayout.setHorizontalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addGap(0, 0, 0) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - panelCameraSelectionLayout.setVerticalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel5) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0)) - ); - - javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel); - topPanel.setLayout(topPanelLayout); - topPanelLayout.setHorizontalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup() - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - topPanelLayout.setVerticalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(topPanelLayout.createSequentialGroup() - .addGap(1, 1, 1) - .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(sidePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(topPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(sidePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - }// //GEN-END:initComponents - - private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed - try { - renderer.setMode(RendererMode.Fit); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomFitActionPerformed - - private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed - try { - renderer.setMode(RendererMode.Stretch); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomStretchActionPerformed - - private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed - try { - renderer.setMode(RendererMode.Fixed); - centralizeRenderer(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomNormalActionPerformed - - private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap - try { - if ((camera != null) && (camera instanceof ColormapSource) && !updatingColormap) { - ColormapSource source = (ColormapSource) camera; - Color colorReticule = new Color(16, 16, 16); - Color colorMarker = new Color(128, 128, 128); - Colormap colormap = (Colormap) comboColormap.getSelectedItem(); - source.getConfig().colormap = (colormap == null) ? Colormap.Flame : colormap; - switch (source.getConfig().colormap) { - case Grayscale: - case Inverted: - case Red: - case Green: - case Blue: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - case Flame: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - } - - renderer.setPenReticle(new Pen(colorReticule)); - renderer.setPenProfile(new Pen(colorReticule, 0)); - renderer.setPenMarker(new Pen(colorMarker, 2)); - renderer.setShowReticle(false); - checkReticle(); - source.getConfig().colormapAutomatic = buttonAutomatic.isSelected(); - source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); - source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); - try { - source.getConfig().save(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - } - source.refresh(); - if (buttonPause.isSelected()) { - updatePause(); - } - updateColormap(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_onChangeColormap - - private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange - onChangeColormap(null); - }//GEN-LAST:event_onChangeColormapRange - - private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed - renderer.setZoom(0.25); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom025ActionPerformed - - private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed - renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom05ActionPerformed - - private void buttonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonServerActionPerformed - if (!usingServer) { - usingServer = true; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonServerActionPerformed - - private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingServer) { - usingServer = false; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonDirectActionPerformed - - private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed - - comboScreen.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - ChannelInteger setpoint = null; - try { - int index = comboScreen.getSelectedIndex(); - if (index >= 0) { - if (cameraName.contains("DSRM")) { - setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); - } else { - setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); - } - setpoint.initialize(); - Integer readback = setpoint.read(); - if ((readback == null) || (setpoint.read() != index)) { - setpoint.write(index); - //Must be threaded to control the laser because of sleep in setLaserState - /* - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - setpoint.write(index); - } finally { - if (laserOn) { - setLaserState(true); - } - } - */ - } - screen.read(); - } - } catch (Exception ex) { - showException(ex); - } finally { - comboScreen.setEnabled(true); - if (setpoint != null) { - setpoint.close(); - } - } - } - }).start(); - }//GEN-LAST:event_comboScreenActionPerformed - - private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed - try { - String setpoint = (String) comboFilter.getSelectedItem(); - if (setpoint != null) { - if (!setpoint.equals(filter.read())) { - filter.write(setpoint); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboFilterActionPerformed - - private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed - try { - setHistogramVisible(checkHistogram.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_checkHistogramActionPerformed - - private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed - renderer.setZoom(2.0); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom2ActionPerformed - - private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setThreshold((Double) spinnerThreshold.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerThresholdonChange - - private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (server != null) { - if (!updatingServerControls) { - try { - if (server.isStarted()) { - server.setBackgroundSubtraction(checkBackground.isSelected()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - updatingServerControls = true; - checkBackground.setSelected(false); - updatingServerControls = false; - - } - } - } else { - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - }//GEN-LAST:event_checkBackgroundActionPerformed - - private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - spinnerThreshold.setVisible(checkThreshold.isSelected()); - server.setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkThresholdActionPerformed - - private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - goodRegion = checkGoodRegion.isSelected(); - setGoodRegionOptionsVisible(goodRegion); - if (goodRegion) { - server.setGoodRegion(((Number) spinnerGrThreshold.getValue()).doubleValue(), ((Number) spinnerGrScale.getValue()).doubleValue()); - } else { - server.setGoodRegion(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkGoodRegionActionPerformed - - private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setGoodRegion((Double) spinnerGrThreshold.getValue(), (Double) spinnerGrScale.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerGrThresholdonChange - - private void btFixColormapRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFixColormapRangeActionPerformed - try { - updatingColormap = true; - ArrayProperties properties = currentFrame.data.getProperties(); - spinnerMax.setValue(properties.max.intValue()); - spinnerMin.setValue(properties.min.intValue()); - buttonManual.setSelected(true); - } catch (Exception ex) { - showException(ex); - } finally { - updatingColormap = false; - onChangeColormap(null); - } - }//GEN-LAST:event_btFixColormapRangeActionPerformed - - private void checkSlicingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSlicingActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - slicing = checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - if (slicing) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } else { - server.setSlicing(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkSlicingActionPerformed - - private void spinnerSlicingChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerSlicingChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerSlicingChange - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - showFit = buttonFit.isSelected(); - if (showFit) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed - try { - showProfile = buttonProfile.isSelected(); - if (showProfile) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(profileOv); - profileOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonProfileActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - checkMarker(null); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - if (!updatingButtons) { - setPaused(buttonPause.isSelected()); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera != null) { - boolean laserOn = getLaserState(); - OptionResult ret = null; - if (laserOn) { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put laser on delay for capturing background?", OptionType.YesNoCancel); - if (ret == OptionResult.No) { - laserOn = false; - } - } else { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to capture background now?", OptionType.OkCancel); - } - - if (ret == OptionResult.Cancel) { - return; - } - - if (laserOn) { - setLaserState(false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - if (server != null) { - server.captureBackground(5); - } else { - camera.captureBackground(5, 0); - } - } finally { - if (laserOn) { - setLaserState(true); - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - saveSnapshot(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonStreamDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStreamDataActionPerformed - try { - showStreamData(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonStreamDataActionPerformed - - private void buttonSidePanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSidePanelActionPerformed - sidePanel.setVisible(buttonSidePanel.isSelected()); - }//GEN-LAST:event_buttonSidePanelActionPerformed - - private void comboTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTypeActionPerformed - try { - if (!updatingCameraSelection) { - updateCameraList(); - if ((cameraName != null) && (!cameraName.equals(comboCameras.getSelectedItem()))) { - setCamera(null); - } else { - setCamera(cameraName); - } - } - - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - }//GEN-LAST:event_comboTypeActionPerformed - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - if (!updatingCameraSelection) { - if (!comboCameras.isEnabled()) { - throw new Exception("Invalid state"); - } - comboCameras.setEnabled(false); - comboType.setEnabled(false); - buttonServer.setEnabled(false); - buttonDirect.setEnabled(false); - final String cameraName = (String) comboCameras.getSelectedItem(); - new Thread(new Runnable() { - @Override - public void run() { - if (requestCameraListUpdate) { - requestCameraListUpdate = false; - try { - updateCameraList(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - try { - setCamera(cameraName.trim().isEmpty() ? null : cameraName); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - buttonServer.setEnabled(true); - buttonDirect.setEnabled(true); - } - } - }).start(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTitleActionPerformed - try { - manageTitleOverlay(); - } catch (Exception ex) { - showException(ex); - } finally { - } - }//GEN-LAST:event_buttonTitleActionPerformed - - private void buttonScaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScaleActionPerformed - try { - renderer.setShowColormapScale(buttonScale.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonScaleActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btFixColormapRange; - private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonDirect; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JRadioButton buttonFullRange; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JRadioButton buttonManual; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonProfile; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JToggleButton buttonScale; - private javax.swing.JRadioButton buttonServer; - private javax.swing.JToggleButton buttonSidePanel; - private javax.swing.JButton buttonStreamData; - private javax.swing.JToggleButton buttonTitle; - private javax.swing.JRadioButton buttonZoom025; - private javax.swing.JRadioButton buttonZoom05; - private javax.swing.JRadioButton buttonZoom2; - private javax.swing.JRadioButton buttonZoomFit; - private javax.swing.JRadioButton buttonZoomNormal; - private javax.swing.JRadioButton buttonZoomStretch; - private javax.swing.JCheckBox checkBackground; - private javax.swing.JCheckBox checkGoodRegion; - private javax.swing.JCheckBox checkHistogram; - private javax.swing.JCheckBox checkSlicing; - private javax.swing.JCheckBox checkThreshold; - private javax.swing.JComboBox comboCameras; - private javax.swing.JComboBox comboColormap; - private javax.swing.JComboBox comboFilter; - private javax.swing.JComboBox comboScreen; - private javax.swing.JComboBox comboType; - private javax.swing.Box.Filler filler1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel5; - private javax.swing.JProgressBar jProgressBar1; - private javax.swing.JToolBar.Separator jSeparator6; - private javax.swing.JLabel labelGrScale; - private javax.swing.JLabel labelGrThreshold; - private javax.swing.JLabel labelMax; - private javax.swing.JLabel labelMin; - private javax.swing.JLabel labelSlNumber; - private javax.swing.JLabel labelSlOrientation; - private javax.swing.JLabel labelSlScale; - private javax.swing.JPanel panelCameraSelection; - private javax.swing.JPanel panelFilter; - private javax.swing.JPanel panelScreen; - private javax.swing.JPanel panelScreen2; - private javax.swing.JPanel panelSlicing; - private ch.psi.pshell.swing.ValueSelection pauseSelection; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JPanel sidePanel; - private javax.swing.JSpinner spinnerGrScale; - private javax.swing.JSpinner spinnerGrThreshold; - private javax.swing.JSpinner spinnerMax; - private javax.swing.JSpinner spinnerMin; - private javax.swing.JSpinner spinnerSlNumber; - private javax.swing.JSpinner spinnerSlOrientation; - private javax.swing.JSpinner spinnerSlScale; - private javax.swing.JSpinner spinnerThreshold; - private javax.swing.JTextField textState; - private javax.swing.JToolBar toolBar; - private javax.swing.JPanel topPanel; - private ch.psi.pshell.swing.DeviceValuePanel valueFilter; - private ch.psi.pshell.swing.DeviceValuePanel valueScreen; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/ScreenPanel5.form b/plugins/ScreenPanel5.form deleted file mode 100755 index d6332ab..0000000 --- a/plugins/ScreenPanel5.form +++ /dev/null @@ -1,1299 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/ScreenPanel5.java b/plugins/ScreenPanel5.java deleted file mode 100755 index 3b3919a..0000000 --- a/plugins/ScreenPanel5.java +++ /dev/null @@ -1,4447 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.bs.CameraServer; -import ch.psi.pshell.core.Context; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.PipelineServer; -import ch.psi.pshell.bs.StreamValue; -import ch.psi.pshell.core.JsonSerializer; -import ch.psi.pshell.data.DataManager; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.device.Readable.ReadableArray; -import ch.psi.pshell.device.Readable.ReadableNumber; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterArray; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterNumber; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.DiscretePositioner; -import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.imaging.Colormap; -import ch.psi.pshell.imaging.ColormapSource; -import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.DimensionDouble; -import ch.psi.pshell.imaging.Histogram; -import ch.psi.pshell.imaging.ImageBuffer; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.PointDouble; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.pshell.swing.DeviceValueChart; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import ch.psi.pshell.ui.Console; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Config; -import ch.psi.utils.Convert; -import ch.psi.utils.Str; -import ch.psi.utils.swing.Editor.EditorDialog; -import ch.psi.utils.swing.MainFrame; -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.StandardDialog.StandardDialogListener; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.lang.reflect.Array; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.table.DefaultTableModel; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.PolynomialCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; - -/** - * - */ -public class ScreenPanel5 extends Panel { - - public static final String LASER_TYPE = "Laser"; - public static final String ELECTRONS_TYPE = "Electrons"; - public static final String PHOTONICS_TYPE = "Photonics"; - - final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useServerStats = true; - String userOverlaysConfigFile; - ColormapSource camera; - PipelineServer server; - String cameraName; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - boolean showProfile; - Overlay[] userOv; - Overlay[] fitOv; - Overlay[] profileOv; - Overlay errorOverlay; - boolean requestCameraListUpdate; - boolean goodRegion; - boolean slicing; - String serverUrl; - String camServerUrl; - String instanceName; - Overlay titleOv = null; - int integration = 0; - boolean persistCameraState; - - public class CameraState extends Config { - - public boolean valid; - public boolean showSidePanel; - //public boolean showMarker; Saved in the stream instance config - public boolean showProfile; - public boolean showFit; - public boolean showReticle; - public boolean showScale; - public boolean showTitle; - public double zoom; - public RendererMode mode; - public boolean colormapAutomatic; - public double colormapMin; - public double colormapMax; - public Colormap colormap; - public boolean colormapLogarithmic; - - String getFile() { - if (camera == null) { - return null; - } - return getContext().getSetup().expandPath("{context}/screen_panel/" + cameraName + ".properties"); - } - } - - void loadCameraState() { - if (persistCameraState) { - try { - CameraState state = new CameraState(); - state.load(state.getFile()); - if (state.valid) { - buttonSidePanel.setSelected(state.showSidePanel); - buttonSidePanelActionPerformed(null); - buttonProfile.setSelected(state.showProfile); - buttonProfileActionPerformed(null); - buttonFit.setSelected(state.showFit); - buttonFitActionPerformed(null); - buttonReticle.setSelected(state.showReticle); - buttonReticleActionPerformed(null); - buttonScale.setSelected(state.showScale); - buttonScaleActionPerformed(null); - buttonTitle.setSelected(state.showTitle); - buttonTitleActionPerformed(null); - renderer.setMode(state.mode); - renderer.setZoom(state.zoom); - if (camera instanceof ColormapSource) { - camera.getConfig().colormap = state.colormap; - camera.getConfig().colormapAutomatic = state.colormapAutomatic; - camera.getConfig().colormapLogarithmic = state.colormapLogarithmic; - camera.getConfig().colormapMax = state.colormapMax; - camera.getConfig().colormapMin = state.colormapMin; - updateColormap(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - void saveCameraState() { - if (persistCameraState) { - try { - CameraState state = new CameraState(); - state.valid = true; - if (camera instanceof ColormapSource) { - state.colormap = camera.getConfig().colormap; - state.colormapAutomatic = camera.getConfig().colormapAutomatic; - state.colormapLogarithmic = camera.getConfig().colormapLogarithmic; - state.colormapMax = camera.getConfig().colormapMax; - state.colormapMin = camera.getConfig().colormapMin; - } - state.mode = renderer.getMode(); - state.zoom = renderer.getZoom(); - - state.showSidePanel = buttonSidePanel.isSelected(); - state.showProfile = buttonProfile.isSelected(); - state.showFit = buttonFit.isSelected(); - state.showReticle = buttonReticle.isSelected(); - state.showScale = buttonScale.isSelected(); - state.showTitle = buttonTitle.isSelected(); - - state.save(state.getFile()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - String pipelineSuffix = "_sp"; - - Double getServerDouble(String name) { - return (Double) Convert.toDouble(server.getValue(name)); - } - - double[] getServerDoubleArray(String name) { - return (double[]) Convert.toDouble(server.getValue(name)); - } - - class ImageData { - - ImageData() { - if (server != null) { - cache = server.getStream().take(); - String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getDouble(prefix + "x_fit_mean"); - y_fit_mean = getDouble(prefix + "y_fit_mean"); - x_fit_standard_deviation = getDouble(prefix + "x_fit_standard_deviation"); - y_fit_standard_deviation = getDouble(prefix + "y_fit_standard_deviation"); - x_fit_gauss_function = getDoubleArray(prefix + "x_fit_gauss_function"); - y_fit_gauss_function = getDoubleArray(prefix + "y_fit_gauss_function"); - x_profile = getDoubleArray("x_profile"); - y_profile = getDoubleArray("y_profile"); - x_center_of_mass = getDouble("x_center_of_mass"); - y_center_of_mass = getDouble("y_center_of_mass"); - x_rms = getDouble("x_rms"); - y_rms = getDouble("y_rms"); - if (goodRegion) { - double[] gX2 = new double[x_profile.length]; - Arrays.fill(gX2, Double.NaN); - try { - double[] axis = getDoubleArray("x_axis"); - gr_x_axis = getDoubleArray("gr_x_axis"); - double x = gr_x_axis[0]; - gr_size_x = x_fit_gauss_function.length; - //If gr axis values are not identical, calculate the index... - gr_pos_x = (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x) : x); - //But prefer checking the value to avoid raounding errors - for (int i=0;i imageBuffer = new ArrayList(); - Frame currentFrame; - int imageBufferLenght = 1; - Text imagePauseOverlay; - final Console console; - - public ScreenPanel5() { - try { - initComponents(); - spinnerThreshold.setVisible(false); - btFixColormapRange.setVisible(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - setRotationOptionsVisible(false); - JComponent editor = spinnerSlOrientation.getEditor(); - if (editor instanceof JSpinner.DefaultEditor) { - ((JSpinner.DefaultEditor) editor).getTextField().setHorizontalAlignment(JTextField.RIGHT); - } - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - //setPersistedComponents(new Component[]{buttonServer, buttonDirect}); - setPersistedComponents(new Component[]{buttonTitle}); - comboCameras.setEnabled(false); - comboType.setEnabled(false); - - SwingUtils.setEnumCombo(comboColormap, Colormap.class); - if (App.hasArgument("poll")) { - try { - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try { - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("buf")) { - try { - imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("usr_ov")) { - try { - userOverlaysConfigFile = App.getArgumentValue("usr_ov"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_url")) { - serverUrl = App.getArgumentValue("srv_url"); - } - - if (App.hasArgument("cam_srv_url")) { - camServerUrl = App.getArgumentValue("cam_srv_url"); - } - - if (App.hasArgument("calc")) { - useServerStats = false; - } - - if (App.hasArgument("persist")) { - persistCameraState = true; - } - - if (App.hasArgument("suffix")) { - pipelineSuffix = App.getArgumentValue("suffix"); - } - if (App.hasArgument("integration")) { - try { - setIntegration(Integer.valueOf(App.getArgumentValue("integration"))); - if (integration != 0) { - buttonFit.setSelected(false); - buttonProfile.setSelected(false); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - renderer.setProfileNormalized(true); - renderer.setShowProfileLimits(false); - - JMenuItem menuCalibrate = new JMenuItem("Calibrate..."); - menuCalibrate.addActionListener((ActionEvent e) -> { - try { - calibrate(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuRendererConfig = new JMenuItem("Renderer Parameters"); - menuRendererConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuCameraConfig = new JMenuItem("Camera Configurarion"); - menuCameraConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - String cameraConfigJson = null; - if (usingServer) { - String cameraServerUrl = (camServerUrl == null) ? server.getUrl().substring(0, server.getUrl().length() - 1) + "8" : camServerUrl; - try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)) { - srv.initialize(); - //TODO: replace into encodeMultiline - cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true); - } - - } else { - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - } - TextEditor configEditor = new TextEditor(); - configEditor.setText(cameraConfigJson); - configEditor.setReadOnly(true); - configEditor.setTitle(cameraName); - EditorDialog dlg = configEditor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(getTopLevel(), dlg); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetImageBufferSize = new JMenuItem("Set Stack Size..."); - menuSetImageBufferSize.addActionListener((ActionEvent e) -> { - try { - String ret = SwingUtils.getString(getTopLevel(), "Enter size of image buffer: ", String.valueOf(imageBufferLenght)); - if (ret != null) { - this.setImageBufferSize(Integer.valueOf(ret)); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSaveStack = new JMenuItem("Save Stack"); - menuSaveStack.addActionListener((ActionEvent e) -> { - try { - saveStack(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetROI = new JMenuItem("Set ROI..."); - menuSetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); - renderer.addListener(new RendererListener() { - @Override - public void onSelectionFinished(Renderer renderer, Overlay overlay) { - try { - renderer.setShowReticle(false); - Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (server.isRoiEnabled()) { - int[] cur = server.getRoi(); - server.setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); - } else { - server.setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); - } - } catch (Exception ex) { - } finally { - renderer.removeListener(this); - } - } - - @Override - public void onSelectionAborted(Renderer renderer, Overlay overlay) { - renderer.removeListener(this); - } - }); - selection.setFixed(true); - renderer.startSelection(selection); - } - }); - - JMenuItem menuResetROI = new JMenuItem("Reset ROI"); - menuResetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - try { - renderer.setShowReticle(false); - server.resetRoi(); - } catch (IOException ex) { - showException(ex); - } - } - }); - - JCheckBoxMenuItem menuFrameIntegration = new JCheckBoxMenuItem("Multi-Frame", (integration != 0)); - menuFrameIntegration.addActionListener((ActionEvent e) -> { - if (integration == 0) { - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{150, 50}; //Minimum width - layout.rowHeights = new int[]{30, 30}; //Minimum height - panel.setLayout(layout); - JCheckBox checkContinuous = new JCheckBox(""); - checkContinuous.setSelected(true); - JTextField textFrames = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Number of frames:"), c); - c.gridy = 1; - panel.add(new JLabel("Continuous:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(checkContinuous, c); - c.gridy = 0; - panel.add(textFrames, c); - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", panel, OptionType.OkCancel) == OptionResult.Yes) { - setIntegration(checkContinuous.isSelected() ? -(Integer.valueOf(textFrames.getText())) : (Integer.valueOf(textFrames.getText()))); - } - } else { - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", - "Do you want to disable " + ((integration < 0) ? "continuous " : "") + "multi-frame integration (" + Math.abs(integration) + ")?", OptionType.YesNo) == OptionResult.Yes) { - setIntegration(0); - } - } - }); - - for (Component cmp : SwingUtils.getComponentsByType(renderer.getPopupMenu(), JMenu.class)) { - JMenu menu = (JMenu) cmp; - if (menu.getText().equals("Integration")) { - menu.addSeparator(); - menu.add(menuFrameIntegration); - } - } - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuRendererConfig); - renderer.getPopupMenu().add(menuCameraConfig); - renderer.getPopupMenu().add(menuSetImageBufferSize); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuCalibrate); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuSetROI); - renderer.getPopupMenu().add(menuResetROI); - renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(server != null); - menuSetROI.setEnabled(server != null); - menuCalibrate.setVisible(server != null); - menuCalibrate.setEnabled((calibrationDialolg == null) || (!calibrationDialolg.isShowing())); - menuSaveStack.setEnabled(imageBufferLenght > 0); - menuSetImageBufferSize.setEnabled(!renderer.isPaused()); - menuFrameIntegration.setSelected(integration != 0); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - } - }); - renderer.getPopupMenu().setVisible(false); - buttonScale.setSelected(renderer.getShowColormapScale()); - clearMarker(); - - showFit = buttonFit.isSelected(); - showProfile = buttonProfile.isSelected(); - - pauseSelection.setVisible(false); - pauseSelection.setMinValue(1); - pauseSelection.addListener(new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - if (editing && (value >= 1) && (value <= imageBuffer.size())) { - updatePause(); - } - } - }); - renderer.addListener(new RendererListener() { - @Override - public void onMoveFinished(Renderer renderer, Overlay overlay) { - if (overlay == marker) { - try { - onMarkerChanged(); - } catch (IOException ex) { - Logger.getLogger(ScreenPanel5.class.getName()).log(Level.WARNING, null, ex); - } - } - } - }); - if (MainFrame.isDark()) { - textState.setDisabledTextColor(textState.getForeground()); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - - console = (!App.hasArgument("console")) ? null : new Console() { - /* - protected void onConsoleCommand(String name, String[] pars, String trimming) throws Exception { - switch (name) { - case "cam": - comboCameras.setSelectedItem(tokens[1]); - break; - } - }*/ - @Override - protected void onConsoleCommand(String command) { - String[] tokens = command.split(" "); - if ((tokens.length > 1) && tokens[0].equals("cam")) { - try { - if (!tokens[1].equals(comboCameras.getSelectedItem())) { - setComboTypeSelection("All"); - updateCameraList(); - comboCameras.setSelectedItem(tokens[1]); - if (!tokens[1].equals(comboCameras.getSelectedItem())) { - comboCameras.setSelectedItem(""); - throw new Exception("Invalid camera name : " + tokens[1]); - } - System.out.println("Console set camera: " + tokens[1]); - } - } catch (Exception ex) { - System.err.println(ex); - } - } else { - System.err.println("Invalid command: " + command); - } - } - }; - } - - void setIntegration(int frames) { - try { - if (integration != frames) { - integration = frames; - if (camera != null) { - if (Math.abs(integration) > 1) { - renderer.setDevice(new ImageIntegrator(integration)); - } else { - renderer.setDevice(camera); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - @Override - public void onStart() { - super.onStart(); - updateDialogTitle(); - if (App.hasArgument("ct")) { - boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonServer.setSelected(!direct); - buttonDirect.setSelected(direct); - } - if (App.hasArgument("console")) { - console.start(); - } - } - - @Override - public void onStop() { - try { - if (camera != null) { - saveCameraState(); - camera.close(); - camera = null; - server = null; - updateButtons(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - if (console != null) { - console.stop(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - super.onStop(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - comboType.setEnabled(false); - if (App.hasArgument("s")) { - renderer.setDevice((Source) getDevice("image")); - renderer.setAutoScroll(true); - ((Source) getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - manageFit(bi, data); - manageUserOverlays(bi, data); - } - - @Override - public void onError(Object o, Exception ex) { - } - } - ); - - } else { - usingServer = buttonServer.isSelected(); - updateCameraList(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - setComboCameraSelection(null); - setComboTypeSelection("All"); - - if (comboCameras.getModel().getSize() > 0) { - try { - if (App.hasArgument("cam")) { - setComboCameraSelection(App.getArgumentValue("cam")); - comboCamerasActionPerformed(null); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - updateButtons(); - startTimer(1000); - } - - boolean isVisible(String camera) { - return ((comboType.getSelectedIndex() == 0) || (getCameraType(camera).equals(comboType.getSelectedItem()))); - } - - DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - if (fromServer) { - try (PipelineServer srv = newServer()) { - srv.initialize(); - List cameras = srv.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - - } else { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - if (App.hasArgument("cam")) { - String camera = App.getArgumentValue("cam"); - if (model.getIndexOf(camera) < 0) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - model.addElement(""); - - return model; - } - - PipelineServer newServer() throws IOException { - if (serverUrl != null) { - System.out.println("Connecting to server: " + serverUrl); - server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl); - } else { - System.out.println("Connecting to server"); - server = new PipelineServer(CAMERA_DEVICE_NAME); - } - updateButtons(); - return server; - } - - boolean updatingCameraSelection; - - void setComboCameraSelection(Object selection) { - updatingCameraSelection = true; - try { - comboCameras.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - - void setComboTypeSelection(Object selection) { - updatingCameraSelection = true; - try { - comboType.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - boolean usingServer; - - void updateCameraList() { - try { - String selected = (String) comboCameras.getSelectedItem(); - comboCameras.setModel(getCameraList(usingServer)); - if (selected != null) { - if (((DefaultComboBoxModel) comboCameras.getModel()).getIndexOf(camera) < 0) { - setComboCameraSelection(selected); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - } - - final Object lockOverlays = new Object(); - - void manageFit(BufferedImage bi, Data data) { - Overlay[][] fo = null; - if ((showFit || showProfile)) { - try { - fo = getFitOverlays(data); - } catch (Exception ex) { - System.err.println(ex); - } - } - synchronized (lockOverlays) { - fo = (fo == null) ? new Overlay[][]{null, null} : fo; - renderer.updateOverlays(fo[0], profileOv); - profileOv = fo[0]; - renderer.updateOverlays(fo[1], fitOv); - fitOv = fo[1]; - } - } - - void manageUserOverlays(BufferedImage bi, Data data) { - Overlay[] fo = (bi == null) ? null : getUserOverlays(data); - synchronized (lockOverlays) { - renderer.updateOverlays(fo, userOv); - userOv = fo; - } - } - - void updateDialogTitle() { - if (App.isDetached()) { - getTopLevel().setTitle(cameraName == null ? "ScreenPanel" : cameraName); - } - } - - void manageTitleOverlay() { - Overlay to = null; - if ((buttonTitle.isSelected()) && (cameraName != null)) { - Font font = new Font("Arial", Font.PLAIN, 28); - to = new Text(renderer.getPenErrorText(), cameraName, font, new Point(-SwingUtils.getTextSize(cameraName, renderer.getGraphics().getFontMetrics(font)).width - 14, 26)); - to.setFixed(true); - to.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - } - - synchronized (lockOverlays) { - renderer.updateOverlays(to, titleOv); - titleOv = to; - } - } - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - Thread devicesInitTask; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Initializing: " + cameraName); - parseUserOverlays(); - errorOverlay = null; - lastMarkerPos = null; - lastFrame = null; - lastPipelinePars = null; - - if (dataTableDialog != null) { - dataTableDialog.dispose(); - dataTableDialog = null; - } - dataTableModel = null; - - if (calibrationDialolg != null) { - calibrationDialolg.dispose(); - calibrationDialolg = null; - } - - boolean was_server = false; - if (camera != null) { - saveCameraState(); - //camera.removeAllListeners(); - was_server = (server != null); - camera.close(); - camera = null; - server = null; - } - updateButtons(); - instanceName = null; - renderer.setDevice(null); - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.removeOverlays(profileOv); - renderer.removeOverlays(userOv); - renderer.clear(); - renderer.resetZoom(); - - boolean changed = !String.valueOf(cameraName).equals(this.cameraName); - this.cameraName = cameraName; - - if (changed || buttonDirect.isSelected()) { - spinnerThreshold.setVisible(false); - checkThreshold.setEnabled(false); - checkRotation.setEnabled(false); - checkGoodRegion.setEnabled(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - setRotationOptionsVisible(false); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - if (changed) { - checkBackground.setEnabled(false); - if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { - devicesInitTask.interrupt(); - } - if (screen != null) { - screen.close(); - screen = null; - } - if (filter != null) { - filter.close(); - filter = null; - } - if (renderer.isPaused()) { - renderer.resume(); - removePauseOverlay(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - manageTitleOverlay(); - updateDialogTitle(); - - if (cameraName == null) { - return; - } - - System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]"); - try { - if (buttonServer.isSelected()) { - camera = newServer(); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - //camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName); - camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName}); - } - camera.initialize(); - camera.assertInitialized(); - System.out.println("Camera initialization OK"); - loadCameraState(); - if (server != null) { - //server.start(cameraName, false); - String pipelineName = cameraName + pipelineSuffix; - instanceName = cameraName + pipelineSuffix + "1"; - if (!server.getPipelines().contains(pipelineName)) { - System.out.println("Creating pipeline: " + pipelineName); - HashMap config = new HashMap<>(); - config.put("camera_name", cameraName); - //server.createFromConfig(config, pipelineName); - server.savePipelineConfig(pipelineName, config); - } - server.start(pipelineName, instanceName); - - updatePipelineControls(); - checkThreshold.setEnabled(true); - checkRotation.setEnabled(true); - checkGoodRegion.setEnabled(true); - } else { - checkThreshold.setSelected(false); - checkRotation.setSelected(false); - checkGoodRegion.setSelected(false); - if (polling <= 0) { - camera.setMonitored(true); - } else { - camera.setPolling(polling); - } - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - updateButtons(); - camera.getConfig().save(); - if (Math.abs(integration) > 1) { - renderer.setDevice(new ImageIntegrator(integration)); - } else { - renderer.setDevice(camera); - } - renderer.setAutoScroll(true); - //renderer.setMarker(marker); - clearMarker(); - imageSize = null; - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi != null) { - if ((imageSize == null) || imageSize.width != bi.getWidth() || imageSize.height != bi.getHeight()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { - centralizeRenderer(); - } - checkReticle(); - } - }); - imageSize = new Dimension(bi.getWidth(), bi.getHeight()); - } - renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); - } - //renderer.setCalibration(camera.getCalibration()); - if (!renderer.isPaused()) { - if (data != null) { - synchronized (imageBuffer) { - currentFrame = new Frame(data); - if (imageBufferLenght >= 1) { - imageBuffer.add(currentFrame); - if (imageBuffer.size() > imageBufferLenght) { - imageBuffer.remove(0); - setBufferFull(true); - } else { - setBufferFull(false); - } - } else { - setBufferFull(true); - } - //Update data - if (!renderer.isPaused()) { - updateStreamData(); - } - updateMarker(); - } - } - manageFit(bi, data); - manageUserOverlays(bi, data); - } - //updateImageData(); - } - - @Override - public void onError(Object o, Exception ex) { - //System.err.println(ex); - } - }); - - } catch (Exception ex) { - showException(ex); - renderer.clearOverlays(); - updatePipelineControls(); - if (renderer.getDevice() == null) { - //renderer.setZoom(1.0); - //renderer.setMode(RendererMode.Zoom); - errorOverlay = new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - errorOverlay.setFixed(true); - errorOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - renderer.addOverlay(errorOverlay); - } - } finally { - //checkReticle(); - onTimer(); - } - onChangeColormap(null); - checkBackground.setEnabled(true); - if (changed) { - boolean electrons = getCameraType(cameraName).equals(ELECTRONS_TYPE); - comboScreen.setModel(new DefaultComboBoxModel()); - comboScreen.setEnabled(false); - comboFilter.setModel(new DefaultComboBoxModel()); - comboFilter.setEnabled(false); - panelFilter.setVisible(electrons); - panelScreen.setVisible(electrons); - if (electrons) { - //Parallelizing initialization - devicesInitTask = new Thread(() -> { - try { - if (cameraName.contains("DSRM")) { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); - } else { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); - } - screen.setMonitored(true); - screen.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : screen.getPositions()) { - model.addElement(pos); - } - comboScreen.setModel(model); - comboScreen.setSelectedItem(screen.read()); - - } catch (Exception ex) { - comboScreen.setModel(new DefaultComboBoxModel()); - System.err.println(ex.getMessage()); - screen = null; - } - comboScreen.setEnabled(screen != null); - valueScreen.setDevice(screen); - - try { - filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); - filter.setMonitored(true); - filter.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : filter.getPositions()) { - model.addElement(pos); - } - comboFilter.setModel(model); - comboFilter.setSelectedItem(filter.read()); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - filter = null; - } - comboFilter.setEnabled(filter != null); - valueFilter.setDevice(filter); - }); - devicesInitTask.start(); - } - } - } - - class ImageIntegrator extends ColormapSource { - - ImageIntegrator(int num) { - super("Image Averager", camera.getConfig()); - boolean continuous = (num < 0); - final int numImages = Math.abs(num); - - camera.addListener(new ImageListener() { - final ArrayList buffer = new ArrayList(); - Data integration = null; - - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - try { - if (continuous) { - buffer.add(data); - if (buffer.size() >= numImages) { - for (Data d : buffer) { - process(d); - } - } - } else { - buffer.add(null); //Just to count - process(data); - } - } catch (Exception ex) { - buffer.clear(); - integration = null; - ImageIntegrator.this.pushData(null); - ex.printStackTrace(); - return; - } - if (buffer.size() >= numImages) { - if (continuous) { - buffer.remove(0); - } else { - buffer.clear(); - } - if (integration != null) { - //integration.div(numImages); - ImageIntegrator.this.pushData(integration); - } - integration = null; - } - } - - void process(Data data) { - if (integration == null) { - integration = new Data(data); - } else { - integration.sum(data); - } - } - - @Override - public void onError(Object origin, Exception ex) { - } - }); - - } - } - - boolean bufferFull = true; - - void setBufferFull(boolean value) { - if (value != bufferFull) { - SwingUtilities.invokeLater(() -> { - buttonPause.setBackground(value ? buttonSave.getBackground() : buttonSave.getBackground().brighter()); - }); - bufferFull = value; - } - } - - volatile Dimension imageSize; - - void checkReticle() { - if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) { - //renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800, 800), 200); - renderer.setShowReticle(true); - } else { - //renderer.setCalibration(null); - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - void checkMarker(Point p) throws IOException { - if (camera != null) { - if (buttonMarker.isSelected()) { - Dimension d = renderer.getImageSize(); - if (p == null) { - p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - } - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - marker.setPassive(false); - } else { - marker = null; - } - renderer.setMarker(marker); - onMarkerChanged(); - } - } - - Point lastMarkerPos; - - void onMarkerChanged() throws IOException { - lastMarkerPos = getStreamMarkerPos(); - if (marker == null) { - setInstanceConfigValue("Marker", null); - } else { - setInstanceConfigValue("Marker", new int[]{marker.getPosition().x, marker.getPosition().y}); - } - } - - void updateMarker() { - try { - if (server != null) { - Point p = getStreamMarkerPos(); - if (p != null) { - //To prevent a local change being overriden by a message having the old settings. - //TODO: This is not bullet-proof, as one can have 2 changes between 2 frames... - if (!p.equals(lastMarkerPos)) { - if (p.x == Integer.MIN_VALUE) { - if (buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - checkMarker(null); - } - } else { - if (!buttonMarker.isSelected()) { - buttonMarker.setSelected(true); - checkMarker(p); - } else { - if (!p.equals(marker.getPosition())) { - marker.setPosition(p); - } - } - } - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - Point getStreamMarkerPos() throws IOException { - //System.out.println(server.getInstanceConfig().get("Marker")); - Map pars = server.getProcessingParameters(); - if (pars != null) { - List markerPosition = (List) pars.get("Marker"); - if (markerPosition != null) { - return new Point((Integer) markerPosition.get(0), (Integer) markerPosition.get(1)); - } - return new Point(Integer.MIN_VALUE, Integer.MIN_VALUE); - } - return null; - } - - void clearMarker() { - marker = null; - renderer.setMarker(marker); - } - - void setInstanceConfigValue(String name, Object value) throws IOException { - if (server != null) { - Map map = server.getInstanceConfig(); - map.put(name, value); - server.setInstanceConfig(map); - } - } - - void updateZoom() { - try { - buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom) { - if (renderer.getZoom() == 1) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getZoom() == 0.5) { - buttonZoom05.setSelected(true); - } else if (renderer.getZoom() == 0.25) { - buttonZoom025.setSelected(true); - } else if (renderer.getZoom() == 2.0) { - buttonZoom2.setSelected(true); - } else { - buttonGroup1.clearSelection(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - boolean updatingColormap; - - void updateColormap() { - updatingColormap = true; - try { - if ((camera != null) && (camera instanceof ColormapSource)) { - ColormapSourceConfig config = ((ColormapSource) camera).getConfig(); - comboColormap.setSelectedItem(config.colormap); - if (config.isDefaultColormap()) { - buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic) { - buttonAutomatic.setSelected(true); - } else { - buttonManual.setSelected(true); - } - btFixColormapRange.setVisible(buttonAutomatic.isSelected()); - spinnerMin.setEnabled(buttonManual.isSelected()); - spinnerMax.setEnabled(buttonManual.isSelected()); - if (!Double.isNaN(config.colormapMin)) { - spinnerMin.setValue(Math.min(Math.max((int) config.colormapMin, 0), 65535)); - } - if (!Double.isNaN(config.colormapMax)) { - spinnerMax.setValue(Math.min(Math.max((int) config.colormapMax, 0), 65535)); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatingColormap = false; - } - - void updatePipelineProperties() { - goodRegion = checkGoodRegion.isSelected(); - spinnerThreshold.setVisible(checkThreshold.isSelected()); - setGoodRegionOptionsVisible(goodRegion); - slicing = goodRegion && checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - updatingServerControls = false; - boolean rotation = checkRotation.isSelected(); - setRotationOptionsVisible(rotation); - } - - boolean updatingServerControls; - - void updatePipelineControls() { - if (server != null) { - updatingServerControls = true; - if (server.isStarted()) { - try { - checkBackground.setSelected(server.getBackgroundSubtraction()); - Double threshold = (server.getThreshold()); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (server.getGoodRegion()); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - spinnerGrThreshold.setValue(((Number) gr.get("threshold")).doubleValue()); - spinnerGrScale.setValue(((Number) gr.get("gfscale")).doubleValue()); - } - Map rotation = server.getRotation(); - checkRotation.setSelected(rotation != null); - if (rotation!=null){ - spinnerRotationAngle.setValue(((Number) rotation.get("angle")).doubleValue()); - spinnerRotationOrder.setValue(((Number) rotation.get("order")).intValue()); - String mode = (String) rotation.get("mode"); - try{ - spinnerRotationConstant.setValue(Double.valueOf(mode)); - spinnerRotationMode.setValue("constant"); - } catch (Exception ex){ - spinnerRotationConstant.setValue(0); - spinnerRotationMode.setValue(mode); - } - } - - Map slicing = (server.getSlicing()); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - spinnerSlNumber.setValue(((Number) slicing.get("number_of_slices")).intValue()); - spinnerSlScale.setValue(((Number) slicing.get("scale")).doubleValue()); - spinnerSlOrientation.setValue((String) slicing.get("orientation")); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - updatePipelineProperties(); - } - } - - boolean changedPipelinePars(Map pars1, Map pars2) { - String[] keys = new String[]{"image_background_enable", "image_threshold", "image_good_region", - "threshold", "gfscale", "image_slices", "number_of_slices", "scale", "orientation"}; - for (String key : keys) { - Object o1 = pars1.get(key); - Object o2 = pars2.get(key); - if (o1 == null) { - if (o2 != null) { - return true; - } - } else if (!o1.equals(o2)) { - return true; - } - } - return false; - } - - void updatePipelineControls(Map pars) { - if (pars != null) { - updatingServerControls = true; - try { - boolean background = (boolean) pars.get("image_background_enable"); - checkBackground.setSelected(background); - Double threshold = (Double) (pars.get("image_threshold")); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (Map) pars.get("image_good_region"); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - Double value = ((Number) gr.get("threshold")).doubleValue(); - spinnerGrThreshold.setValue(value); - Double scale = ((Number) gr.get("gfscale")).doubleValue(); - spinnerGrScale.setValue(scale); - } - Map slicing = (Map) (pars.get("image_slices")); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - int slices = ((Number) slicing.get("number_of_slices")).intValue(); - spinnerSlNumber.setValue(slices); - double scale = ((Number) slicing.get("scale")).doubleValue(); - spinnerSlScale.setValue(scale); - String orientation = (String) slicing.get("orientation"); - spinnerSlOrientation.setValue(orientation); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatePipelineProperties(); - } - } - - void setGoodRegionOptionsVisible(boolean visible) { - spinnerGrThreshold.setVisible(visible); - labelGrThreshold.setVisible(visible); - spinnerGrScale.setVisible(visible); - labelGrScale.setVisible(visible); - panelSlicing.setVisible(visible); - } - - void setSlicingOptionsVisible(boolean visible) { - spinnerSlNumber.setVisible(visible); - labelSlNumber.setVisible(visible); - spinnerSlScale.setVisible(visible); - labelSlScale.setVisible(visible); - spinnerSlOrientation.setVisible(visible); - labelSlOrientation.setVisible(visible); - } - - void setRotationOptionsVisible(boolean visible) { - labelAngle.setVisible(visible); - labelOrder.setVisible(visible); - labelMode.setVisible(visible); - labelConstant.setVisible(visible); - spinnerRotationAngle.setVisible(visible); - spinnerRotationOrder.setVisible(visible); - spinnerRotationMode.setVisible(visible); - spinnerRotationConstant.setVisible(visible); - } - - boolean isCameraStopped() { - if ((server != null) && !server.isStarted()) { - return true; - } - return ((camera == null) || camera.isClosed()); - } - - boolean updatingButtons; - - void updateButtons() { - updatingButtons = true; - try { - boolean active = !isCameraStopped();//(camera != null); - buttonSave.setEnabled(active); - buttonGrabBackground.setEnabled(active); - buttonMarker.setEnabled(active); - buttonProfile.setEnabled(active); - buttonFit.setEnabled(active); - buttonReticle.setEnabled(active && camera.getConfig().isCalibrated()); - buttonStreamData.setEnabled(active && (server != null)); - buttonPause.setEnabled(active); - - if (renderer.isPaused() != buttonPause.isSelected()) { - buttonPause.setSelected(renderer.isPaused()); - buttonPauseActionPerformed(null); - } - if (renderer.getShowReticle() != buttonReticle.isSelected()) { - //buttonReticle.setSelected(renderer.getShowReticle()); - } - if ((renderer.getMarker() == null) && buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - } - buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - - } finally { - updatingButtons = false; - } - } - - Frame lastFrame = null; - Map lastPipelinePars = null; - - @Override - protected void onTimer() { - for (Device dev : new Device[]{screen, filter}) { - if (dev != null) { - dev.request(); - } - } - - textState.setText((camera == null) ? "" : camera.getState().toString()); - if (App.hasArgument("s")) { - try { - ((Source) getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } - } - updateZoom(); - updateColormap(); - updateButtons(); - checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); - buttonScale.setSelected(renderer.getShowColormapScale()); - try { - Frame frame = getCurrentFrame(); - if (frame != lastFrame) { - lastFrame = frame; - if (frame != null) { - Map pars = getProcessingParameters(frame.cache); - if ((lastPipelinePars == null) || changedPipelinePars(pars, lastPipelinePars)) { - //System.out.println("Update pipeline: " + pars); - lastPipelinePars = pars; - updatePipelineControls(pars); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - Pen penFit = new Pen(new Color(192, 105, 0), 0); - Pen penCross = new Pen(new Color(192, 105, 0), 0); - Pen penSlices = new Pen(Color.CYAN.darker(), 1); - - Frame getCurrentFrame() { - if ((imageBufferLenght > 1) && (renderer.isPaused())) { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - return (index < imageBuffer.size()) ? imageBuffer.get(index) : null; - } - } - return currentFrame; - } - - Frame getFrame(Data data) { - synchronized (imageBuffer) { - for (Frame f : imageBuffer) { - if (f.data == data) { - return f; - } - } - } - return null; - } - - void setImageBufferSize(int size) { - if (renderer.isPaused()) { - throw new RuntimeException("Cannot change buffer size whn paused"); - } - synchronized (imageBuffer) { - imageBufferLenght = size; - imageBuffer.clear(); - } - - } - - Overlay[][] getFitOverlays(Data data) { - Overlays.Polyline hgaussian = null; - Overlays.Polyline vgaussian = null; - Overlays.Polyline hprofile = null; - Overlays.Polyline vprofile = null; - Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null; - Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null; - double[] pX = null, pY = null, gX = null, gY = null; - PointDouble[] sliceCenters = null; - if (data != null) { - int height = data.getHeight(); - int width = data.getWidth(); - int profileSize = renderer.getProfileSize(); - ImageData id = null; - if ((useServerStats) && (server != null)) { - try { - id = getFrame(data); - if (id == null) { - return null; - } - xMean = id.x_fit_mean; - xSigma = id.x_fit_standard_deviation; - yMean = id.y_fit_mean; - ySigma = id.y_fit_standard_deviation; - gX = id.x_fit_gauss_function; - gY = id.y_fit_gauss_function; - pX = id.x_profile; - pY = id.y_profile; - xCom = id.x_center_of_mass; - xRms = id.x_rms; - yCom = id.y_center_of_mass; - yRms = id.y_rms; - sliceCenters = id.sliceCenters; - - profileSize /= 4; - if (pX != null) { - int[] xp = Arr.indexesInt(pX.length); - int[] xg = xp; - int[] yp = new int[pX.length]; - int[] yg = new int[pX.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_x > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gX, id.gr_pos_x, id.gr_pos_x + id.gr_size_x))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gX != null) { - yg[i] = (int) (height - 1 - (((gX[i] - minGauss) / rangeGauss) * profileSize)); - } - yp[i] = (int) (height - 1 - (((pX[i] - minProfile) / rangeProfile) * profileSize)); - } - - if (goodRegion && id.gr_size_x > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - yg = Arrays.copyOfRange(yg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - } - - vgaussian = new Overlays.Polyline(penFit, xg, yg); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - - if (pY != null) { - int[] xp = new int[pY.length]; - int[] xg = new int[pY.length]; - int[] yp = Arr.indexesInt(pY.length); - int[] yg = yp; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_y > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gY, id.gr_pos_y, id.gr_pos_y + id.gr_size_y))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gY != null) { - xg[i] = (int) (((gY[i] - minGauss) / rangeGauss) * profileSize); - } - xp[i] = (int) (((pY[i] - minProfile) / rangeProfile) * profileSize); - } - - if (goodRegion && id.gr_size_y > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - yg = Arrays.copyOfRange(yg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - } - hgaussian = new Overlays.Polyline(penFit, xg, yg); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - return null; - } - } else { - ArrayProperties properties = data.getProperties(); - double maxPlot = properties.max; - double minPlot = properties.min; - double rangePlot = maxPlot - minPlot; - - if (rangePlot <= 0) { - return null; - } - if (renderer.getCalibration() != null) { - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height - minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - if (xSigma != null) { - xSigma *= renderer.getCalibration().getScaleX(); - } - if (ySigma != null) { - ySigma *= renderer.getCalibration().getScaleY(); - } - if (xMean != null) { - xMean = data.getX((int) Math.round(xMean)); - } - if (yMean != null) { - yMean = data.getY((int) Math.round(yMean)); - } - } - } - final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px"; - final String fmt = "%7.1f" + units; - Overlays.Text textCom = null; - Overlay[] pOv = null, fOv = null; - Font fontInfoText = new Font(Font.MONOSPACED, 0, 14); - Point textPosition = new Point(12, 20); - if (showProfile) { - if ((xCom != null) && (yCom != null)) { - String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt, xCom, xRms, yCom, yRms); - textCom = new Overlays.Text(renderer.getPenProfile(), text, fontInfoText, textPosition); - textCom.setFixed(true); - textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - } - pOv = new Overlay[]{hprofile, vprofile, textCom}; - textPosition = new Point(textPosition.x, textPosition.y + 34); - } - if (showFit) { - Overlays.Crosshairs cross = null; - Overlays.Text textFit = null; - if ((xMean != null) && (yMean != null)) { - String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt, xMean, xSigma, yMean, ySigma); - textFit = new Overlays.Text(penFit, text, fontInfoText, textPosition); - textFit.setFixed(true); - textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - Point center = new Point(xMean.intValue(), yMean.intValue()); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean)); - xSigma /= renderer.getCalibration().getScaleX(); - ySigma /= renderer.getCalibration().getScaleY(); - } - cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue()))); - } - textPosition = new Point(textPosition.x, textPosition.y + 34); - fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit}; - - if (goodRegion && (id != null)) { - try { - double[] x = id.gr_x_axis; - double[] y = id.gr_y_axis; - Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); - goodRegionOv.setCalibration(renderer.getCalibration()); - goodRegionOv.setPosition(new Point(id.gr_pos_x, id.gr_pos_y)); - goodRegionOv.setSize(new Dimension(id.gr_x_axis.length, id.gr_y_axis.length)); - fOv = Arr.append(fOv, goodRegionOv); - - if (slicing) { - if (sliceCenters != null) { - for (PointDouble sliceCenter : sliceCenters) { - Overlays.Crosshairs center = new Overlays.Crosshairs(penSlices); - center.setCalibration(renderer.getCalibration()); - center.setAbsolutePosition(sliceCenter); - center.setSize(new Dimension(10, 10)); - fOv = Arr.append(fOv, center); - } - if (sliceCenters.length > 1) { - double[] fit = fitPolynomial(sliceCenters, 1); - double angle = Math.toDegrees(Math.atan(fit[1])); - Overlays.Text text = new Overlays.Text(penSlices, String.format("slice: \u03B8= %5.1fdeg", angle), fontInfoText, textPosition); - text.setFixed(true); - text.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - fOv = Arr.append(fOv, text); - } - } - } - } catch (Exception ex) { - } - } - - } - return new Overlay[][]{pOv, fOv}; - } - return null; - } - - class UserOverlay { - - String name; - Overlay obj; - String[] channels; - } - ArrayList userOverlayConfig; - - void parseUserOverlays() { - Properties userOverlays = new Properties(); - userOverlayConfig = new ArrayList<>(); - if (userOverlaysConfigFile != null) { - try { - try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { - userOverlays.load(in); - - for (String name : userOverlays.stringPropertyNames()) { - String val = userOverlays.getProperty(name); - try { - UserOverlay uo = new UserOverlay(); - uo.name = name; - String type = val.substring(0, val.indexOf("(")).trim(); - String pars = val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")).trim(); - String[] tokens = pars.split(","); - for (int i = 0; i < tokens.length; i++) { - tokens[i] = tokens[i].trim(); - } - Color color = Color.GRAY; - try { - color = (Color) Color.class.getField(tokens[tokens.length - 1].toUpperCase()).get(null); - } catch (Exception ex) { - } - Pen pen = new Pen(color); - try { - String[] penTokens = tokens[tokens.length - 1].split(":"); - color = (Color) Color.class.getField(penTokens[0].toUpperCase()).get(null); - int width = Integer.valueOf(penTokens[1]); - Pen.LineStyle style = Pen.LineStyle.valueOf(penTokens[2]); - pen = new Pen(color, width, style); - } catch (Exception ex) { - } - switch (type) { - case "Point": - uo.obj = new Overlays.Crosshairs(); - uo.obj.setSize(new Dimension(Integer.valueOf(tokens[2]), Integer.valueOf(tokens[3]))); - break; - case "Line": - uo.obj = new Overlays.Line(); - break; - case "Arrow": - uo.obj = new Overlays.Arrow(); - break; - case "Rect": - uo.obj = new Overlays.Rect(); - break; - case "Ellipse": - uo.obj = new Overlays.Ellipse(); - break; - case "Polyline": - uo.obj = new Overlays.Polyline(); - break; - } - if (type.equals("Polyline") || type.equals("Point")) { - uo.channels = new String[]{tokens[0], tokens[1]}; - } else { - uo.channels = new String[]{tokens[0], tokens[1], tokens[2], tokens[3]}; - } - uo.obj.setPen(pen); - userOverlayConfig.add(uo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - Overlay[] getUserOverlays(Data data) { - ArrayList ret = new ArrayList<>(); - if (server != null) { - ImageData id = getFrame(data); - for (UserOverlay uo : userOverlayConfig) { - try { - Overlay ov = uo.obj; - //Overlay ov = (Overlay)uo.cls.newInstance(); - ov.setCalibration(renderer.getCalibration()); - boolean valid = false; - if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : id.getDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : id.getDoubleArray(uo.channels[1]); - if ((x != null) || (y != null)) { - if (x == null) { - x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); - } - if (y == null) { - y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length); - } - ((Overlays.Polyline) ov).updateAbsolute(x, y); - valid = true; - } - } else { - Double x = id.getDouble(uo.channels[0]); - Double y = id.getDouble(uo.channels[1]); - if ((x != null) && (y != null)) { - PointDouble position = new PointDouble(x, y); - ov.setAbsolutePosition(position); - if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = id.getDouble(uo.channels[2]); - Double y2 = id.getDouble(uo.channels[3]); - if ((x != null) && (y != null)) { - DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); - ov.setAbsoluteSize(size); - valid = true; - } - } else { - valid = true; - } - } - } - if (valid) { - ret.add(ov); - } - } catch (Exception ex) { - //ex.printStackTrace(); - } - } - } - return ret.toArray(new Overlay[0]); - } - - double[] getComRms(double[] arr, double[] x) { - if (arr != null) { - double xmd = 0; - double xmd2 = 0; - double total = 0; - for (int i = 0; i < arr.length; i++) { - double v = (arr[i] * x[i]); - xmd += v; - xmd2 += (v * x[i]); - total += arr[i]; - } - if (total > 0) { - double com = xmd / total; - double com2 = xmd2 / total; - double rms = Math.sqrt(Math.abs(com2 - com * com)); - return new double[]{com, rms}; - } - } - return new double[]{Double.NaN, Double.NaN}; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] fitPolynomial(PointDouble[] points, int order) { - double[] y = new double[points.length]; - double[] x = new double[points.length]; - for (int i = 0; i < points.length; i++) { - x[i] = points[i].x; - y[i] = points[i].y; - } - return fitPolynomial(y, x, order); - } - - double[] fitPolynomial(double[] y, double[] x, int order) { - try { - ArrayProperties pY = ArrayProperties.get(y); - PolynomialCurveFitter fitter = PolynomialCurveFitter.create(order).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - void setHistogramVisible(boolean value) { - if (value) { - if ((histogramDialog == null) || (!histogramDialog.isShowing())) { - Histogram histogram = new Histogram(true); - histogram.setRenderer(renderer); - histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram); - renderer.refresh(); - } - } else { - if (histogramDialog != null) { - histogramDialog.setVisible(false); - histogramDialog = null; - } - } - } - - void setLaserState(int bunch, boolean value) throws Exception { - System.out.println("Setting laser state: " + value + " - bunch" + bunch); - //Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); - if ((bunch<=0) || (bunch==1)){ - Epics.putq("SWISSFEL-STATUS:Bunch-1-OnDelay-Sel", value ? 0 : 1); - } - if ((bunch<=0) || (bunch==2)){ - Epics.putq("SWISSFEL-STATUS:Bunch-2-OnDelay-Sel", value ? 0 : 1); - } - - Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); - Thread.sleep(3000); - } - - boolean getLaserState(int bunch) throws Exception { - //return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); - if (bunch<=0){ - return getLaserState(1) && getLaserState(2); - } - if (bunch==2){ - return (Epics.get("SWISSFEL-STATUS:Bunch-2-OnDelay-Sel", Integer.class) == 0); - } - return (Epics.get("SWISSFEL-STATUS:Bunch-1-OnDelay-Sel", Integer.class) == 0); - } - - void elog(String logbook, String title, String message, String[] attachments) throws Exception { - String domain = ""; - String category = "Info"; - String entry = ""; - StringBuffer cmd = new StringBuffer(); - - cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); - cmd.append("-a \"Author=ScreenPanel\" "); - cmd.append("-a \"Type=pshell\" "); - cmd.append("-a \"Entry=").append(entry).append("\" "); - cmd.append("-a \"Title=").append(title).append("\" "); - cmd.append("-a \"Category=").append(category).append("\" "); - cmd.append("-a \"Domain=").append(domain).append("\" "); - for (String attachment : attachments) { - cmd.append("-f \"").append(attachment).append("\" "); - } - cmd.append("-n 1 "); - cmd.append("\"").append(message).append("\" "); - System.out.println(cmd.toString()); - - final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); - new Thread(() -> { - try { - process.waitFor(); - int bytes = process.getInputStream().available(); - byte[] arr = new byte[bytes]; - process.getInputStream().read(arr, 0, bytes); - System.out.println(new String(arr)); - bytes = process.getErrorStream().available(); - arr = new byte[bytes]; - process.getErrorStream().read(arr, 0, bytes); - System.err.println(new String(arr)); - } catch (Exception ex) { - System.err.println(ex); - } - }).start(); - } - - void centralizeRenderer() { - Point center = null; - Dimension size = renderer.getImageSize(); - double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom(); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().getCenter(); - } else if (size != null) { - center = new Point(size.width / 2, size.height / 2); - } - if (center != null) { - Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0), - Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0)); - renderer.setViewPosition(topleft); - } - } - - void updatePause() { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - if (index < imageBuffer.size()) { - Data data = imageBuffer.get(index).data; - long pid = imageBuffer.get(index).cache.getPulseId(); - BufferedImage image = camera.generateImage(data); - renderer.setImage(renderer.getOrigin(), image, data); - - String text = "PID: " + pid; - if (imagePauseOverlay == null) { - Font font = new Font("Verdana", Font.PLAIN, 12); - Dimension d = SwingUtils.getTextSize(text, renderer.getFontMetrics(font)); - imagePauseOverlay = new Text(renderer.getPenErrorText(), "", font, new Point(-20 - d.width, 42)); - imagePauseOverlay.setFixed(true); - imagePauseOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - renderer.addOverlay(imagePauseOverlay); - } - //imagePauseOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS")); - imagePauseOverlay.update(text); - manageFit(image, data); - manageUserOverlays(image, data); - } - } - updateStreamData(); - } - - void removePauseOverlay() { - renderer.removeOverlay(imagePauseOverlay); - imagePauseOverlay = null; - } - - void saveSnapshot() throws Exception { - boolean paused = isPaused(); - try{ - if (!paused){ - setPaused(true); - } - String snapshotFile = null; - synchronized (imageBuffer) { - Frame frame = getCurrentFrame(); - if (frame == null) { - throw new Exception("No current image"); - } - ArrayList frames = new ArrayList<>(); - frames.add(frame); - this.saveFrames(cameraName + "_camera_snapshot", frames); - - //Enforce the same timestamp to data & image files. - snapshotFile = getContext().getExecutionPars().getPath() + ".png"; - //renderer.saveSnapshot(snapshotFile, "png", true); - ImageBuffer.saveImage(SwingUtils.createImage(renderer), snapshotFile, "png"); - } - - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{0, 180}; //Minimum width - layout.rowHeights = new int[]{30, 30, 30}; //Minimum height - panel.setLayout(layout); - JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); - JTextField textComment = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Data file:"), c); - c.gridy = 1; - panel.add(new JLabel("Logbook:"), c); - c.gridy = 2; - panel.add(new JLabel("Comment:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(textComment, c); - c.gridy = 1; - panel.add(comboLogbook, c); - c.gridy = 0; - panel.add(new JLabel(getContext().getExecutionPars().getPath()), c); - - if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes) { - StringBuilder message = new StringBuilder(); - message.append("Camera: ").append(cameraName).append(" ("). - append((server != null) ? "server" : "direct").append(")").append("\n"); - message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); - message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); - message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); - message.append("Comment: ").append(textComment.getText()).append("\n"); - //Add slicing message - if ((fitOv != null) && (fitOv.length > 5) && (fitOv[fitOv.length - 1] instanceof Overlays.Text)) { - Overlays.Text text = (Overlays.Text) fitOv[fitOv.length - 1]; - message.append(text.getText()).append("\n"); - } - elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - } finally{ - if (!paused){ - setPaused(false); - } - } - } - - void saveStack() throws Exception { - synchronized (imageBuffer) { - saveFrames(cameraName + "_camera_stack", imageBuffer); - } - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath()); - } - - public static String getCameraType(String name) { - if (name == null) { - return ""; - } - for (String s : new String[]{"LCAM"}) { - if (name.contains(s)) { - return LASER_TYPE; - } - } - for (String s : new String[]{"DSCR", "DSRM", "DLAC"}) { - if (name.contains(s)) { - return ELECTRONS_TYPE; - } - } - for (String s : new String[]{"PROF", "PPRM", "PSSS", "PSCR", "PSRD"}) { - if (name.contains(s)) { - return PHOTONICS_TYPE; - } - } - return "Unknown"; - } - - public Map getProcessingParameters(StreamValue value) throws IOException { - return (Map) JsonSerializer.decode(value.getValue("processing_parameters").toString(), Map.class); - } - - void saveFrames(String name, ArrayList frames) throws IOException { - ArrayList values = new ArrayList<>(); - for (Frame frame : frames) { - values.add(frame.cache); - } - saveImages(name, values); - } - - void saveImages(String name, ArrayList images) throws IOException { - int depth = images.size(); - if (depth == 0) { - return; - } - StreamValue first = images.get(0); - String pathRoot = "/camera1/"; - String pathImage = pathRoot + "image"; - String pathPid = pathRoot + "pulse_id"; - String pathTimestampStr = pathRoot + "timestamp_str"; - Map processingPars = getProcessingParameters(first); - String camera = (String) processingPars.get("camera_name"); - String type = getCameraType(camera); - - int width = ((Number) first.getValue("width")).intValue(); - int height = ((Number) first.getValue("height")).intValue(); - Class dataType = first.getValue("image").getClass().getComponentType(); - - getContext().setExecutionPars(name); - DataManager dm = getContext().getDataManager(); - - //Create tables - dm.createDataset(pathImage, dataType, new int[]{depth, height, width}); - dm.createDataset(pathPid, Long.class, new int[]{depth}); - dm.createDataset(pathTimestampStr, String.class, new int[]{depth}); - for (String id : first.getIdentifiers()) { - Object val = first.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(first); - for (String key : pars.keySet()) { - if ((pars.get(key) != null) && (pars.get(key) instanceof Map)) { - for (Object k : ((Map) pars.get(key)).keySet()) { - Object v = ((Map) pars.get(key)).get(k); - dm.setAttribute(pathImage, key + " " + k, (v == null) ? "" : v); - } - } else { - Object value = pars.get(key); - if (value == null) { - value = ""; - } else if (value instanceof List) { - Class cls = (((List) value).size() > 0) ? ((List) value).get(0).getClass() : double.class; - value = Convert.toPrimitiveArray(value, cls); - //value = Convert.toDouble(value); - } - dm.setAttribute(pathImage, key, value); - } - } - } else if (val.getClass().isArray()) { - dm.createDataset(pathRoot + id, Double.class, new int[]{depth, Array.getLength(val)}); - } else { - dm.createDataset(pathRoot + id, val.getClass(), new int[]{depth}); - } - } - - //Add metadata - dm.setAttribute(pathRoot, "Camera", camera); - dm.setAttribute(pathRoot, "Images", depth); - dm.setAttribute(pathRoot, "Interval", -1); - dm.setAttribute(pathRoot, "Type", type); - if (type.equals(ELECTRONS_TYPE)) { - dm.setAttribute(pathRoot, "Screen", String.valueOf(valueScreen.getLabel().getText())); - dm.setAttribute(pathRoot, "Filter", String.valueOf(valueFilter.getLabel().getText())); - } - - //Save data - for (int index = 0; index < depth; index++) { - StreamValue streamValue = images.get(index); - dm.setItem(pathImage, streamValue.getValue("image"), new long[]{index, 0, 0}, new int[]{1, height, width}); - dm.setItem(pathPid, streamValue.getPulseId(), index); - dm.setItem(pathTimestampStr, Chrono.getTimeStr(streamValue.getTimestamp(), "YYYY-MM-dd HH:mm:ss.SSS"), index); - - for (String id : streamValue.getIdentifiers()) { - Object val = streamValue.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - } else if (val.getClass().isArray()) { - dm.setItem(pathRoot + id, val, index); - } else { - dm.setItem(pathRoot + id, val, index); - } - } - } - getContext().getDataManager().closeOutput(); - } - - StandardDialog calibrationDialolg; - - void calibrate() throws Exception { - if (server != null) { - server.resetRoi(); - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraCalibrationDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), server.getCurrentCamera(), renderer}); - SwingUtils.centerComponent(getTopLevel(), calibrationDialolg); - calibrationDialolg.setVisible(true); - calibrationDialolg.setListener(new StandardDialogListener() { - @Override - public void onWindowOpened(StandardDialog dlg) { - } - - @Override - public void onWindowClosed(StandardDialog dlg, boolean accepted) { - if (accepted) { - //comboCamerasActionPerformed(null); - } - } - }); - } - } - - StandardDialog dataTableDialog; - DefaultTableModel dataTableModel; - JTable dataTable; - - void showStreamData() { - dataTableModel = null; - if (server != null) { - - if ((dataTableDialog != null) && (dataTableDialog.isShowing())) { - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.requestFocus(); - return; - } - dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) { - public Class getColumnClass(int columnIndex) { - return String.class; - } - - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - }; - updateStreamData(); - StreamValue val = server.getStream().take(); - dataTable = new JTable(dataTableModel); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.setCellSelectionEnabled(true); - dataTable.getTableHeader().setReorderingAllowed(false); - dataTable.getTableHeader().setResizingAllowed(true); - dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); - dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(dataTable); - scrollPane.setPreferredSize(new Dimension(300, 400)); - dataTableDialog.setContentPane(scrollPane); - dataTableDialog.pack(); - dataTableDialog.setVisible(true); - dataTableDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - dataTableModel = null; - } - }); - dataTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - try { - int row = dataTable.getSelectedRow(); - int col = dataTable.getSelectedColumn(); - dataTable.setToolTipText(null); - if (row > 1) { - String id = String.valueOf(dataTable.getModel().getValueAt(row, 0)); - String locator = String.valueOf(dataTable.getModel().getValueAt(0, 1)); - String channelId = locator + " " + id; - dataTable.setToolTipText(channelId); - if ((e.getClickCount() == 2) && (!e.isPopupTrigger())) { - if (col == 0) { - SwingUtils.showMessage(dataTableDialog, "Channel Identifier", "Copied to clipboard: " + channelId); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - clipboard.setContents(new StringSelection(channelId), (Clipboard clipboard1, Transferable contents) -> { - }); - } else { - Object obj = getCurrentFrame().cache.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(getCurrentFrame().cache); - StringBuilder sb = new StringBuilder(); - for (String key : pars.keySet()) { - sb.append(key).append(" = ").append(Str.toString(pars.get(key), 10)).append("\n"); - } - SwingUtils.showMessage(dataTableDialog, "Processing Parameters", sb.toString()); - } else if ((obj != null) && (obj.getClass().isArray() || (obj instanceof Number))) { - DeviceValueChart chart = new DeviceValueChart(); - Device dev = null; - if (obj.getClass().isArray()) { - dev = new ReadableRegisterArray(new ReadableArray() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - - @Override - public int getSize() { - return Array.getLength(getCurrentFrame().cache.getValue(id)); - } - }); - } else { - dev = new ReadableRegisterNumber(new ReadableNumber() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - }); - } - dev.setPolling(1000); - chart.setDevice(dev); - JDialog dlg = SwingUtils.showDialog(dataTableDialog, cameraName + " " + id, null, chart); - //TODO: - //PlotBase plot = chart.getPlot(); - //if (plot!=null){ - // plot.setPlotBackgroundColor(Color.BLACK); - //} - } - } - } - } - } catch (Exception ex) { - showException(ex); - } - } - }); - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - updateStreamData(); - } - } - - volatile boolean updatingStreamData = false; - - void updateStreamData() { - if ((dataTableDialog == null) || !dataTableDialog.isShowing() || updatingStreamData) { - return; - } - updatingStreamData = true; - SwingUtilities.invokeLater(() -> { - updatingStreamData = false; - if ((dataTableModel != null) && (server != null)) { - StreamValue value = server.getValue(); - Frame frame = getCurrentFrame(); - int[] sel_rows = (dataTable == null) ? null : dataTable.getSelectedRows(); - int[] sel_cols = (dataTable == null) ? null : dataTable.getSelectedColumns(); - List ids = (value == null) ? new ArrayList<>() : new ArrayList(value.getIdentifiers()); - if (ids.size() + 4 != dataTableModel.getRowCount()) { - dataTableModel.setNumRows(0); - try { - dataTableModel.addRow(new Object[]{"Locator", server.getUrl() + "/" + ((value == null) ? instanceName : server.getCurrentInstance())}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Locator", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"Stream", server.getStreamAddress()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Stream", ex.getMessage()}); - } - dataTableModel.addRow(new Object[]{"PID", ""}); - dataTableModel.addRow(new Object[]{"Timestamp", ""}); - Collections.sort(ids); - for (String id : ids) { - dataTableModel.addRow(new Object[]{id, ""}); - } - } - - if ((frame != null) && (frame.cache != null)) { - dataTableModel.setValueAt(frame.cache.getPulseId(), 2, 1); //PID - dataTableModel.setValueAt(frame.cache.getTimestamp(), 3, 1); //Timestamp - for (int i = 4; i < dataTableModel.getRowCount(); i++) { - String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - //Object obj = server.getValue(id); - Object obj = frame.cache.getValue(id); - if (obj != null) { - if (obj.getClass().isArray()) { - obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; - } else if (obj instanceof Double) { - obj = Convert.roundDouble((Double) obj, 1); - } else if (obj instanceof Float) { - obj = Convert.roundDouble((Float) obj, 1); - } - } - dataTableModel.setValueAt(String.valueOf(obj), i, 1); - } - } - if ((sel_rows != null) && (sel_rows.length > 0)) { - //dataTable.setRowSelectionInterval((Integer)Arr.getMin(sel_rows), (Integer)Arr.getMax(sel_rows)); - dataTable.setRowSelectionInterval(sel_rows[0], sel_rows[sel_rows.length - 1]); - } - if ((sel_cols != null) && (sel_cols.length > 0)) { - //dataTable.setColumnSelectionInterval((Integer)Arr.getMin(sel_cols), (Integer)Arr.getMax(sel_cols)); - dataTable.setColumnSelectionInterval(sel_cols[0], sel_cols[sel_cols.length - 1]); - } - } - }); - } - - ImageIcon getIcon(String name) { - ImageIcon ret = null; - try { - //Path path = Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(),"resources", name + ".png"); - String dir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + "resources/"; - if (new File(dir + name + ".png").exists()) { - ret = new javax.swing.ImageIcon(dir + name + ".png"); - } else { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/" + name + ".png")); - if (MainFrame.isDark()) { - try { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/dark/" + name + ".png")); - } catch (Exception e) { - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return ret; - } - - String getIconName(JButton button) { - String ret = button.getIcon().toString(); - if (ret.indexOf(".") > 0) { - ret = ret.substring(0, ret.indexOf(".")); - } - return ret; - } - - void setPaused(boolean paused){ - removePauseOverlay(); - if (camera != null) { - synchronized (imageBuffer) { - if (paused) { - renderer.pause(); - panelCameraSelection.setVisible(false); - pauseSelection.setVisible(true); - if (imageBuffer.size() > 0) { - pauseSelection.setEnabled(true); - pauseSelection.setMaxValue(imageBuffer.size()); - pauseSelection.setValue(imageBuffer.size()); - updatePause(); - } else { - pauseSelection.setEnabled(false); - pauseSelection.setMaxValue(1); - pauseSelection.setValue(1); - } - } else { - imageBuffer.clear(); - renderer.resume(); - //renderer.clear(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - updateStreamData(); - } - } - - boolean isPaused(){ - return renderer.isPaused(); - } - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - buttonGroup4 = new javax.swing.ButtonGroup(); - jProgressBar1 = new javax.swing.JProgressBar(); - sidePanel = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - buttonZoomFit = new javax.swing.JRadioButton(); - buttonZoomStretch = new javax.swing.JRadioButton(); - buttonZoomNormal = new javax.swing.JRadioButton(); - buttonZoom025 = new javax.swing.JRadioButton(); - buttonZoom05 = new javax.swing.JRadioButton(); - buttonZoom2 = new javax.swing.JRadioButton(); - jPanel2 = new javax.swing.JPanel(); - checkHistogram = new javax.swing.JCheckBox(); - comboColormap = new javax.swing.JComboBox(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - buttonFullRange = new javax.swing.JRadioButton(); - buttonManual = new javax.swing.JRadioButton(); - buttonAutomatic = new javax.swing.JRadioButton(); - labelMin = new javax.swing.JLabel(); - spinnerMin = new javax.swing.JSpinner(); - spinnerMax = new javax.swing.JSpinner(); - labelMax = new javax.swing.JLabel(); - btFixColormapRange = new javax.swing.JButton(); - jPanel5 = new javax.swing.JPanel(); - buttonServer = new javax.swing.JRadioButton(); - buttonDirect = new javax.swing.JRadioButton(); - textState = new javax.swing.JTextField(); - filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767)); - panelScreen = new javax.swing.JPanel(); - valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); - comboScreen = new javax.swing.JComboBox(); - panelFilter = new javax.swing.JPanel(); - valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); - comboFilter = new javax.swing.JComboBox(); - panelScreen2 = new javax.swing.JPanel(); - checkThreshold = new javax.swing.JCheckBox(); - spinnerThreshold = new javax.swing.JSpinner(); - checkBackground = new javax.swing.JCheckBox(); - checkGoodRegion = new javax.swing.JCheckBox(); - spinnerGrScale = new javax.swing.JSpinner(); - spinnerGrThreshold = new javax.swing.JSpinner(); - labelGrThreshold = new javax.swing.JLabel(); - labelGrScale = new javax.swing.JLabel(); - panelSlicing = new javax.swing.JPanel(); - checkSlicing = new javax.swing.JCheckBox(); - labelSlScale = new javax.swing.JLabel(); - spinnerSlScale = new javax.swing.JSpinner(); - labelSlNumber = new javax.swing.JLabel(); - spinnerSlNumber = new javax.swing.JSpinner(); - labelSlOrientation = new javax.swing.JLabel(); - spinnerSlOrientation = new javax.swing.JSpinner(); - checkRotation = new javax.swing.JCheckBox(); - spinnerRotationAngle = new javax.swing.JSpinner(); - spinnerRotationOrder = new javax.swing.JSpinner(); - labelOrder = new javax.swing.JLabel(); - labelMode = new javax.swing.JLabel(); - spinnerRotationMode = new javax.swing.JSpinner(); - labelAngle = new javax.swing.JLabel(); - labelConstant = new javax.swing.JLabel(); - spinnerRotationConstant = new javax.swing.JSpinner(); - topPanel = new javax.swing.JPanel(); - toolBar = new javax.swing.JToolBar(); - buttonSidePanel = new javax.swing.JToggleButton(); - buttonStreamData = new javax.swing.JButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - buttonPause = new javax.swing.JToggleButton(); - jSeparator6 = new javax.swing.JToolBar.Separator(); - buttonMarker = new javax.swing.JToggleButton(); - buttonProfile = new javax.swing.JToggleButton(); - buttonFit = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonScale = new javax.swing.JToggleButton(); - buttonTitle = new javax.swing.JToggleButton(); - pauseSelection = new ch.psi.pshell.swing.ValueSelection(); - panelCameraSelection = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - jLabel5 = new javax.swing.JLabel(); - comboType = new javax.swing.JComboBox(); - renderer = new ch.psi.pshell.imaging.Renderer(); - - setPreferredSize(new java.awt.Dimension(873, 600)); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); - - buttonGroup1.add(buttonZoomFit); - buttonZoomFit.setText("Fit"); - buttonZoomFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomFitActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomStretch); - buttonZoomStretch.setText("Stretch"); - buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomStretchActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomNormal); - buttonZoomNormal.setText("Normal"); - buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomNormalActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("1/4"); - buttonZoom025.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom025ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("1/2"); - buttonZoom05.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom05ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom2); - buttonZoom2.setText("2"); - buttonZoom2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoomStretch)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05) - .addComponent(buttonZoom2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomFit) - .addComponent(buttonZoom05)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoom2)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap")); - - checkHistogram.setText("Histogram"); - checkHistogram.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkHistogramActionPerformed(evt); - } - }); - - comboColormap.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Type:"); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Range:"); - - buttonGroup3.add(buttonFullRange); - buttonFullRange.setText("Full"); - buttonFullRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonManual); - buttonManual.setText("Manual"); - buttonManual.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonAutomatic); - buttonAutomatic.setText("Automatic"); - buttonAutomatic.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - labelMin.setText("Min:"); - - spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); - spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); - spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - labelMax.setText("Max:"); - - btFixColormapRange.setText("Fix"); - btFixColormapRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btFixColormapRangeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonAutomatic) - .addComponent(buttonFullRange) - .addComponent(buttonManual) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMax) - .addGap(2, 2, 2) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMin) - .addGap(2, 2, 2) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(spinnerMin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFixColormapRange, spinnerMax, spinnerMin}); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3) - .addComponent(checkHistogram)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAutomatic) - .addComponent(jLabel4) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelMin) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonFullRange)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonManual) - .addComponent(labelMax) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - - buttonGroup4.add(buttonServer); - buttonServer.setSelected(true); - buttonServer.setText("Server"); - buttonServer.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonServerActionPerformed(evt); - } - }); - - buttonGroup4.add(buttonDirect); - buttonDirect.setText("Direct"); - buttonDirect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDirectActionPerformed(evt); - } - }); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonServer) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonDirect) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(56, 56, 56)) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonServer) - .addComponent(buttonDirect))) - .addContainerGap()) - ); - - panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); - - comboScreen.setEnabled(false); - comboScreen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboScreenActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); - panelScreen.setLayout(panelScreenLayout); - panelScreenLayout.setHorizontalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreenLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreenLayout.setVerticalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelFilter.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); - - comboFilter.setEnabled(false); - comboFilter.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboFilterActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelFilterLayout = new javax.swing.GroupLayout(panelFilter); - panelFilter.setLayout(panelFilterLayout); - panelFilterLayout.setHorizontalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelFilterLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelFilterLayout.setVerticalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFilterLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - panelScreen2.setBorder(javax.swing.BorderFactory.createTitledBorder("Pipeline")); - - checkThreshold.setText("Threshold"); - checkThreshold.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkThresholdActionPerformed(evt); - } - }); - - spinnerThreshold.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 99999.0d, 1.0d)); - spinnerThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerThresholdonChange(evt); - } - }); - - checkBackground.setText("Subtract Background"); - checkBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkBackgroundActionPerformed(evt); - } - }); - - checkGoodRegion.setText("Good Region"); - checkGoodRegion.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkGoodRegionActionPerformed(evt); - } - }); - - spinnerGrScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerGrScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - spinnerGrThreshold.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.04d, 1.0d, 0.1d)); - spinnerGrThreshold.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerGrThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - labelGrThreshold.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelGrThreshold.setText("Threshold:"); - - labelGrScale.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelGrScale.setText("Scale:"); - - checkSlicing.setText("Slicing"); - checkSlicing.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkSlicingActionPerformed(evt); - } - }); - - labelSlScale.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelSlScale.setText("Scale:"); - - spinnerSlScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerSlScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlNumber.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelSlNumber.setText("Slices:"); - - spinnerSlNumber.setModel(new javax.swing.SpinnerNumberModel(2, 0, 1000, 1)); - spinnerSlNumber.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlNumber.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlOrientation.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelSlOrientation.setText("Orientation:"); - - spinnerSlOrientation.setModel(new javax.swing.SpinnerListModel(new String[] {"vertical", "horizontal"})); - spinnerSlOrientation.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlOrientation.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - javax.swing.GroupLayout panelSlicingLayout = new javax.swing.GroupLayout(panelSlicing); - panelSlicing.setLayout(panelSlicingLayout); - panelSlicingLayout.setHorizontalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addComponent(checkSlicing) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlNumber) - .addGap(2, 2, 2) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlScale) - .addGap(2, 2, 2) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelSlOrientation) - .addGap(2, 2, 2) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - panelSlicingLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerSlNumber, spinnerSlOrientation, spinnerSlScale}); - - panelSlicingLayout.setVerticalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(checkSlicing) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlNumber)) - .addGap(0, 0, 0) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlScale)))) - .addGap(0, 0, 0) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlOrientation))) - ); - - panelSlicingLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {spinnerSlNumber, spinnerSlOrientation, spinnerSlScale}); - - checkRotation.setText("Rotation"); - checkRotation.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkRotationActionPerformed(evt); - } - }); - - spinnerRotationAngle.setModel(new javax.swing.SpinnerNumberModel(0.0d, -360.0d, 360.0d, 1.0d)); - spinnerRotationAngle.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerRotationAngleStateChanged(evt); - } - }); - - spinnerRotationOrder.setModel(new javax.swing.SpinnerNumberModel(1, 1, 5, 1)); - spinnerRotationOrder.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerRotationAngleStateChanged(evt); - } - }); - - labelOrder.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelOrder.setText("Order:"); - - labelMode.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelMode.setText("Mode:"); - - spinnerRotationMode.setModel(new javax.swing.SpinnerListModel(new String[] {"constant", "reflect", "nearest", "mirror", "wrap"})); - spinnerRotationMode.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerRotationAngleStateChanged(evt); - } - }); - - labelAngle.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelAngle.setText("Angle:"); - - labelConstant.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelConstant.setText("Constant:"); - - spinnerRotationConstant.setModel(new javax.swing.SpinnerNumberModel(0, 0, 99999, 1)); - spinnerRotationConstant.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerRotationAngleStateChanged(evt); - } - }); - - javax.swing.GroupLayout panelScreen2Layout = new javax.swing.GroupLayout(panelScreen2); - panelScreen2.setLayout(panelScreen2Layout); - panelScreen2Layout.setHorizontalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addComponent(checkGoodRegion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(labelOrder) - .addComponent(labelGrScale) - .addComponent(labelMode))) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkThreshold) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkRotation) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(labelAngle)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(labelGrThreshold, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addComponent(labelConstant) - .addGap(3, 3, 3))))) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(spinnerGrScale) - .addComponent(spinnerThreshold) - .addComponent(spinnerRotationOrder) - .addComponent(spinnerRotationMode) - .addComponent(spinnerRotationAngle) - .addComponent(spinnerRotationConstant)) - .addContainerGap()) - .addComponent(panelSlicing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addGap(6, 6, 6) - .addComponent(checkBackground) - .addGap(106, 106, 106)) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerRotationAngle, spinnerRotationConstant, spinnerRotationMode, spinnerRotationOrder, spinnerThreshold}); - - panelScreen2Layout.setVerticalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(checkBackground) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkThreshold) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkRotation) - .addComponent(spinnerRotationAngle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelAngle)) - .addGap(0, 0, 0) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerRotationOrder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelOrder)) - .addGap(0, 0, 0) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerRotationMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelMode)) - .addGap(0, 0, 0) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerRotationConstant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelConstant)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkGoodRegion) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrScale)) - .addGap(0, 0, 0) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrThreshold)) - .addGap(2, 2, 2) - .addComponent(panelSlicing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerRotationAngle, spinnerRotationConstant, spinnerRotationMode, spinnerRotationOrder, spinnerThreshold}); - - javax.swing.GroupLayout sidePanelLayout = new javax.swing.GroupLayout(sidePanel); - sidePanel.setLayout(sidePanelLayout); - sidePanelLayout.setHorizontalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - sidePanelLayout.setVerticalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - toolBar.setFloatable(false); - toolBar.setRollover(true); - - buttonSidePanel.setIcon(getIcon("List")); - buttonSidePanel.setSelected(true); - buttonSidePanel.setText(" "); - buttonSidePanel.setToolTipText("Show Side Panel"); - buttonSidePanel.setFocusable(false); - buttonSidePanel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSidePanel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSidePanelActionPerformed(evt); - } - }); - toolBar.add(buttonSidePanel); - - buttonStreamData.setIcon(getIcon("Details")); - buttonStreamData.setText(" "); - buttonStreamData.setToolTipText("Show Data Window"); - buttonStreamData.setFocusable(false); - buttonStreamData.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonStreamData.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStreamDataActionPerformed(evt); - } - }); - toolBar.add(buttonStreamData); - - buttonSave.setIcon(getIcon("Save")); - buttonSave.setText(" "); - buttonSave.setToolTipText("Save Snapshot"); - buttonSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - toolBar.add(buttonSave); - - buttonGrabBackground.setIcon(getIcon("Background")); - buttonGrabBackground.setText(" "); - buttonGrabBackground.setToolTipText("Grab Background"); - buttonGrabBackground.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - toolBar.add(buttonGrabBackground); - - buttonPause.setIcon(getIcon("Pause")); - buttonPause.setText(" "); - buttonPause.setToolTipText("Pause"); - buttonPause.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - toolBar.add(buttonPause); - - jSeparator6.setMaximumSize(new java.awt.Dimension(20, 32767)); - jSeparator6.setPreferredSize(new java.awt.Dimension(20, 0)); - jSeparator6.setRequestFocusEnabled(false); - toolBar.add(jSeparator6); - - buttonMarker.setIcon(getIcon("Marker")); - buttonMarker.setText(" "); - buttonMarker.setToolTipText("Show Marker"); - buttonMarker.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - toolBar.add(buttonMarker); - - buttonProfile.setIcon(getIcon("Profile" - + "")); - buttonProfile.setSelected(true); - buttonProfile.setText(" "); - buttonProfile.setToolTipText("Show Image Profile"); - buttonProfile.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonProfile.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonProfileActionPerformed(evt); - } - }); - toolBar.add(buttonProfile); - - buttonFit.setIcon(getIcon("Fit")); - buttonFit.setSelected(true); - buttonFit.setText(" "); - buttonFit.setToolTipText("Show Fit"); - buttonFit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - toolBar.add(buttonFit); - - buttonReticle.setIcon(getIcon("Reticule")); - buttonReticle.setSelected(true); - buttonReticle.setText(" "); - buttonReticle.setToolTipText("Show Reticle"); - buttonReticle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - toolBar.add(buttonReticle); - - buttonScale.setIcon(getIcon("Scale")); - buttonScale.setSelected(true); - buttonScale.setText(" "); - buttonScale.setToolTipText("Show Colormap Scale"); - buttonScale.setFocusable(false); - buttonScale.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonScale.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonScaleActionPerformed(evt); - } - }); - toolBar.add(buttonScale); - - buttonTitle.setIcon(getIcon("Title")); - buttonTitle.setSelected(true); - buttonTitle.setText(" "); - buttonTitle.setToolTipText("Show Camera Name"); - buttonTitle.setFocusable(false); - buttonTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonTitle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonTitleActionPerformed(evt); - } - }); - toolBar.add(buttonTitle); - - pauseSelection.setDecimals(0); - - jLabel1.setText("Camera:"); - - comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboCameras.setMaximumRowCount(30); - comboCameras.setMinimumSize(new java.awt.Dimension(127, 27)); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - jLabel5.setText("Type:"); - - comboType.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboType.setMaximumRowCount(30); - comboType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Laser", "Electrons", "Photonics" })); - comboType.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboTypeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelCameraSelectionLayout = new javax.swing.GroupLayout(panelCameraSelection); - panelCameraSelection.setLayout(panelCameraSelectionLayout); - panelCameraSelectionLayout.setHorizontalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addGap(0, 0, 0) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - panelCameraSelectionLayout.setVerticalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel5) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0)) - ); - - javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel); - topPanel.setLayout(topPanelLayout); - topPanelLayout.setHorizontalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup() - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - topPanelLayout.setVerticalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(topPanelLayout.createSequentialGroup() - .addGap(1, 1, 1) - .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(sidePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(topPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(sidePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - }// //GEN-END:initComponents - - private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed - try { - renderer.setMode(RendererMode.Fit); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomFitActionPerformed - - private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed - try { - renderer.setMode(RendererMode.Stretch); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomStretchActionPerformed - - private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed - try { - renderer.setMode(RendererMode.Fixed); - centralizeRenderer(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomNormalActionPerformed - - private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap - try { - if ((camera != null) && (camera instanceof ColormapSource) && !updatingColormap) { - ColormapSource source = (ColormapSource) camera; - Color colorReticule = new Color(16, 16, 16); - Color colorMarker = new Color(128, 128, 128); - Colormap colormap = (Colormap) comboColormap.getSelectedItem(); - source.getConfig().colormap = (colormap == null) ? Colormap.Flame : colormap; - switch (source.getConfig().colormap) { - case Grayscale: - case Inverted: - case Red: - case Green: - case Blue: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - case Flame: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - } - - renderer.setPenReticle(new Pen(colorReticule)); - renderer.setPenProfile(new Pen(colorReticule, 0)); - renderer.setPenMarker(new Pen(colorMarker, 2)); - renderer.setShowReticle(false); - checkReticle(); - source.getConfig().colormapAutomatic = buttonAutomatic.isSelected(); - source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); - source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); - try { - source.getConfig().save(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - } - source.refresh(); - if (buttonPause.isSelected()) { - updatePause(); - } - updateColormap(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_onChangeColormap - - private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange - onChangeColormap(null); - }//GEN-LAST:event_onChangeColormapRange - - private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed - renderer.setZoom(0.25); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom025ActionPerformed - - private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed - renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom05ActionPerformed - - private void buttonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonServerActionPerformed - if (!usingServer) { - usingServer = true; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonServerActionPerformed - - private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingServer) { - usingServer = false; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonDirectActionPerformed - - private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed - - comboScreen.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - ChannelInteger setpoint = null; - try { - int index = comboScreen.getSelectedIndex(); - if (index >= 0) { - if (cameraName.contains("DSRM")) { - setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); - } else { - setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); - } - setpoint.initialize(); - Integer readback = setpoint.read(); - if ((readback == null) || (setpoint.read() != index)) { - setpoint.write(index); - //Must be threaded to control the laser because of sleep in setLaserState - /* - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - setpoint.write(index); - } finally { - if (laserOn) { - setLaserState(true); - } - } - */ - } - screen.read(); - } - } catch (Exception ex) { - showException(ex); - } finally { - comboScreen.setEnabled(true); - if (setpoint != null) { - setpoint.close(); - } - } - } - }).start(); - }//GEN-LAST:event_comboScreenActionPerformed - - private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed - try { - String setpoint = (String) comboFilter.getSelectedItem(); - if (setpoint != null) { - if (!setpoint.equals(filter.read())) { - filter.write(setpoint); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboFilterActionPerformed - - private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed - try { - setHistogramVisible(checkHistogram.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_checkHistogramActionPerformed - - private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed - renderer.setZoom(2.0); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom2ActionPerformed - - private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setThreshold((Double) spinnerThreshold.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerThresholdonChange - - private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (server != null) { - if (!updatingServerControls) { - try { - if (server.isStarted()) { - server.setBackgroundSubtraction(checkBackground.isSelected()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - updatingServerControls = true; - checkBackground.setSelected(false); - updatingServerControls = false; - - } - } - } else { - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - }//GEN-LAST:event_checkBackgroundActionPerformed - - private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - spinnerThreshold.setVisible(checkThreshold.isSelected()); - server.setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkThresholdActionPerformed - - private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - goodRegion = checkGoodRegion.isSelected(); - setGoodRegionOptionsVisible(goodRegion); - if (goodRegion) { - server.setGoodRegion(((Number) spinnerGrThreshold.getValue()).doubleValue(), ((Number) spinnerGrScale.getValue()).doubleValue()); - } else { - server.setGoodRegion(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkGoodRegionActionPerformed - - private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setGoodRegion((Double) spinnerGrThreshold.getValue(), (Double) spinnerGrScale.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerGrThresholdonChange - - private void btFixColormapRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFixColormapRangeActionPerformed - try { - updatingColormap = true; - ArrayProperties properties = currentFrame.data.getProperties(); - spinnerMax.setValue(properties.max.intValue()); - spinnerMin.setValue(properties.min.intValue()); - buttonManual.setSelected(true); - } catch (Exception ex) { - showException(ex); - } finally { - updatingColormap = false; - onChangeColormap(null); - } - }//GEN-LAST:event_btFixColormapRangeActionPerformed - - private void checkSlicingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSlicingActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - slicing = checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - if (slicing) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } else { - server.setSlicing(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkSlicingActionPerformed - - private void spinnerSlicingChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerSlicingChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerSlicingChange - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - showFit = buttonFit.isSelected(); - if (showFit) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed - try { - showProfile = buttonProfile.isSelected(); - if (showProfile) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(profileOv); - profileOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonProfileActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - checkMarker(null); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - if (!updatingButtons) { - setPaused(buttonPause.isSelected()); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera != null) { - boolean laserOn1 = getLaserState(1); - boolean laserOn2 = getLaserState(2); - OptionResult ret = null; - if (laserOn1 || laserOn2) { - if (laserOn1){ - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put Bunch 1 laser on delay for capturing background?", OptionType.YesNoCancel); - if (ret == OptionResult.No) { - laserOn1 = false; - } - if (ret == OptionResult.Cancel) { - return; - } - } - if (laserOn2){ - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put Bunch 2 laser on delay for capturing background?", OptionType.YesNoCancel); - if (ret == OptionResult.No) { - laserOn2= false; - } - } - } else { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to capture background now?", OptionType.OkCancel); - } - - if (ret == OptionResult.Cancel) { - return; - } - - if (laserOn1) { - setLaserState(1,false); - } - if (laserOn2) { - setLaserState(2,false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - if (server != null) { - server.captureBackground(5); - } else { - camera.captureBackground(5, 0); - } - } finally { - if (laserOn1) { - setLaserState(1,true); - } - if (laserOn2) { - setLaserState(2,true); - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - saveSnapshot(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonStreamDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStreamDataActionPerformed - try { - showStreamData(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonStreamDataActionPerformed - - private void buttonSidePanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSidePanelActionPerformed - sidePanel.setVisible(buttonSidePanel.isSelected()); - }//GEN-LAST:event_buttonSidePanelActionPerformed - - private void comboTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTypeActionPerformed - try { - if (!updatingCameraSelection) { - updateCameraList(); - if ((cameraName != null) && (!cameraName.equals(comboCameras.getSelectedItem()))) { - setCamera(null); - } else { - setCamera(cameraName); - } - } - - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - }//GEN-LAST:event_comboTypeActionPerformed - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - if (!updatingCameraSelection) { - if (!comboCameras.isEnabled()) { - throw new Exception("Invalid state"); - } - comboCameras.setEnabled(false); - comboType.setEnabled(false); - buttonServer.setEnabled(false); - buttonDirect.setEnabled(false); - final String cameraName = (String) comboCameras.getSelectedItem(); - new Thread(new Runnable() { - @Override - public void run() { - if (requestCameraListUpdate) { - requestCameraListUpdate = false; - try { - updateCameraList(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - try { - setCamera(cameraName.trim().isEmpty() ? null : cameraName); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - buttonServer.setEnabled(true); - buttonDirect.setEnabled(true); - } - } - }).start(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTitleActionPerformed - try { - manageTitleOverlay(); - } catch (Exception ex) { - showException(ex); - } finally { - } - }//GEN-LAST:event_buttonTitleActionPerformed - - private void buttonScaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScaleActionPerformed - try { - renderer.setShowColormapScale(buttonScale.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonScaleActionPerformed - - private void checkRotationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkRotationActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - boolean rotation = checkRotation.isSelected(); - setRotationOptionsVisible(rotation); - if (rotation) { - spinnerRotationAngleStateChanged(null); - } else { - server.setRotation(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkRotationActionPerformed - - private void spinnerRotationAngleStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerRotationAngleStateChanged - try { - String mode = String.valueOf(spinnerRotationMode.getValue()); - server.setRotation(((Number) spinnerRotationAngle.getValue()).doubleValue(), - ((Number) spinnerRotationOrder.getValue()).intValue(), - mode.equals("constant") ? String.valueOf(spinnerRotationConstant.getValue()): mode); - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - }//GEN-LAST:event_spinnerRotationAngleStateChanged - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btFixColormapRange; - private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonDirect; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JRadioButton buttonFullRange; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JRadioButton buttonManual; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonProfile; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JToggleButton buttonScale; - private javax.swing.JRadioButton buttonServer; - private javax.swing.JToggleButton buttonSidePanel; - private javax.swing.JButton buttonStreamData; - private javax.swing.JToggleButton buttonTitle; - private javax.swing.JRadioButton buttonZoom025; - private javax.swing.JRadioButton buttonZoom05; - private javax.swing.JRadioButton buttonZoom2; - private javax.swing.JRadioButton buttonZoomFit; - private javax.swing.JRadioButton buttonZoomNormal; - private javax.swing.JRadioButton buttonZoomStretch; - private javax.swing.JCheckBox checkBackground; - private javax.swing.JCheckBox checkGoodRegion; - private javax.swing.JCheckBox checkHistogram; - private javax.swing.JCheckBox checkRotation; - private javax.swing.JCheckBox checkSlicing; - private javax.swing.JCheckBox checkThreshold; - private javax.swing.JComboBox comboCameras; - private javax.swing.JComboBox comboColormap; - private javax.swing.JComboBox comboFilter; - private javax.swing.JComboBox comboScreen; - private javax.swing.JComboBox comboType; - private javax.swing.Box.Filler filler1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel5; - private javax.swing.JProgressBar jProgressBar1; - private javax.swing.JToolBar.Separator jSeparator6; - private javax.swing.JLabel labelAngle; - private javax.swing.JLabel labelConstant; - private javax.swing.JLabel labelGrScale; - private javax.swing.JLabel labelGrThreshold; - private javax.swing.JLabel labelMax; - private javax.swing.JLabel labelMin; - private javax.swing.JLabel labelMode; - private javax.swing.JLabel labelOrder; - private javax.swing.JLabel labelSlNumber; - private javax.swing.JLabel labelSlOrientation; - private javax.swing.JLabel labelSlScale; - private javax.swing.JPanel panelCameraSelection; - private javax.swing.JPanel panelFilter; - private javax.swing.JPanel panelScreen; - private javax.swing.JPanel panelScreen2; - private javax.swing.JPanel panelSlicing; - private ch.psi.pshell.swing.ValueSelection pauseSelection; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JPanel sidePanel; - private javax.swing.JSpinner spinnerGrScale; - private javax.swing.JSpinner spinnerGrThreshold; - private javax.swing.JSpinner spinnerMax; - private javax.swing.JSpinner spinnerMin; - private javax.swing.JSpinner spinnerRotationAngle; - private javax.swing.JSpinner spinnerRotationConstant; - private javax.swing.JSpinner spinnerRotationMode; - private javax.swing.JSpinner spinnerRotationOrder; - private javax.swing.JSpinner spinnerSlNumber; - private javax.swing.JSpinner spinnerSlOrientation; - private javax.swing.JSpinner spinnerSlScale; - private javax.swing.JSpinner spinnerThreshold; - private javax.swing.JTextField textState; - private javax.swing.JToolBar toolBar; - private javax.swing.JPanel topPanel; - private ch.psi.pshell.swing.DeviceValuePanel valueFilter; - private ch.psi.pshell.swing.DeviceValuePanel valueScreen; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/ScreenPanel6.form b/plugins/ScreenPanel6.form deleted file mode 100755 index 8fede15..0000000 --- a/plugins/ScreenPanel6.form +++ /dev/null @@ -1,1359 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/ScreenPanel6.java b/plugins/ScreenPanel6.java deleted file mode 100755 index 86ca079..0000000 --- a/plugins/ScreenPanel6.java +++ /dev/null @@ -1,4554 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.bs.CameraServer; -import ch.psi.pshell.core.Context; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.PipelineServer; -import ch.psi.pshell.bs.StreamValue; -import ch.psi.pshell.core.JsonSerializer; -import ch.psi.pshell.data.DataManager; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.device.Readable.ReadableArray; -import ch.psi.pshell.device.Readable.ReadableNumber; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterArray; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterNumber; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.DiscretePositioner; -import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.imaging.Colormap; -import ch.psi.pshell.imaging.ColormapSource; -import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.DimensionDouble; -import ch.psi.pshell.imaging.Histogram; -import ch.psi.pshell.imaging.ImageBuffer; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.PointDouble; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.pshell.swing.DeviceValueChart; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import ch.psi.pshell.ui.Console; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Config; -import ch.psi.utils.Convert; -import ch.psi.utils.Str; -import ch.psi.utils.swing.Editor.EditorDialog; -import ch.psi.utils.swing.MainFrame; -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.StandardDialog.StandardDialogListener; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.lang.reflect.Array; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.table.DefaultTableModel; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.PolynomialCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; - -/** - * - */ -public class ScreenPanel6 extends Panel { - - public static final String LASER_TYPE = "Laser"; - public static final String ELECTRONS_TYPE = "Electrons"; - public static final String PHOTONICS_TYPE = "Photonics"; - - final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useServerStats = true; - String userOverlaysConfigFile; - ColormapSource camera; - PipelineServer server; - String cameraName; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - boolean showProfile; - Overlay[] userOv; - Overlay[] fitOv; - Overlay[] profileOv; - Overlay errorOverlay; - boolean requestCameraListUpdate; - boolean goodRegion; - boolean slicing; - String serverUrl; - String camServerUrl; - String instanceName; - Overlay titleOv = null; - //int integration = 0; - boolean persistCameraState; - - public class CameraState extends Config { - - public boolean valid; - public boolean showSidePanel; - //public boolean showMarker; Saved in the stream instance config - public boolean showProfile; - public boolean showFit; - public boolean showReticle; - public boolean showScale; - public boolean showTitle; - public double zoom; - public RendererMode mode; - public boolean colormapAutomatic; - public double colormapMin; - public double colormapMax; - public Colormap colormap; - public boolean colormapLogarithmic; - - String getFile() { - if (camera == null) { - return null; - } - return getContext().getSetup().expandPath("{context}/screen_panel/" + cameraName + ".properties"); - } - } - - void loadCameraState() { - if (persistCameraState) { - try { - CameraState state = new CameraState(); - state.load(state.getFile()); - if (state.valid) { - buttonSidePanel.setSelected(state.showSidePanel); - buttonSidePanelActionPerformed(null); - buttonProfile.setSelected(state.showProfile); - buttonProfileActionPerformed(null); - buttonFit.setSelected(state.showFit); - buttonFitActionPerformed(null); - buttonReticle.setSelected(state.showReticle); - buttonReticleActionPerformed(null); - buttonScale.setSelected(state.showScale); - buttonScaleActionPerformed(null); - buttonTitle.setSelected(state.showTitle); - buttonTitleActionPerformed(null); - renderer.setMode(state.mode); - renderer.setZoom(state.zoom); - if (camera instanceof ColormapSource) { - camera.getConfig().colormap = state.colormap; - camera.getConfig().colormapAutomatic = state.colormapAutomatic; - camera.getConfig().colormapLogarithmic = state.colormapLogarithmic; - camera.getConfig().colormapMax = state.colormapMax; - camera.getConfig().colormapMin = state.colormapMin; - updateColormap(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - void saveCameraState() { - if (persistCameraState) { - try { - CameraState state = new CameraState(); - state.valid = true; - if (camera instanceof ColormapSource) { - state.colormap = camera.getConfig().colormap; - state.colormapAutomatic = camera.getConfig().colormapAutomatic; - state.colormapLogarithmic = camera.getConfig().colormapLogarithmic; - state.colormapMax = camera.getConfig().colormapMax; - state.colormapMin = camera.getConfig().colormapMin; - } - state.mode = renderer.getMode(); - state.zoom = renderer.getZoom(); - - state.showSidePanel = buttonSidePanel.isSelected(); - state.showProfile = buttonProfile.isSelected(); - state.showFit = buttonFit.isSelected(); - state.showReticle = buttonReticle.isSelected(); - state.showScale = buttonScale.isSelected(); - state.showTitle = buttonTitle.isSelected(); - - state.save(state.getFile()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - String pipelineSuffix = "_sp"; - - Double getServerDouble(String name) { - return (Double) Convert.toDouble(server.getValue(name)); - } - - double[] getServerDoubleArray(String name) { - return (double[]) Convert.toDouble(server.getValue(name)); - } - - class ImageData { - - ImageData() { - if (server != null) { - cache = server.getStream().take(); - String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getDouble(prefix + "x_fit_mean"); - y_fit_mean = getDouble(prefix + "y_fit_mean"); - x_fit_standard_deviation = getDouble(prefix + "x_fit_standard_deviation"); - y_fit_standard_deviation = getDouble(prefix + "y_fit_standard_deviation"); - x_fit_gauss_function = getDoubleArray(prefix + "x_fit_gauss_function"); - y_fit_gauss_function = getDoubleArray(prefix + "y_fit_gauss_function"); - x_profile = getDoubleArray("x_profile"); - y_profile = getDoubleArray("y_profile"); - x_center_of_mass = getDouble("x_center_of_mass"); - y_center_of_mass = getDouble("y_center_of_mass"); - x_rms = getDouble("x_rms"); - y_rms = getDouble("y_rms"); - if (goodRegion) { - double[] gX2 = new double[x_profile.length]; - Arrays.fill(gX2, Double.NaN); - try { - double[] axis = getDoubleArray("x_axis"); - gr_x_axis = getDoubleArray("gr_x_axis"); - double x = gr_x_axis[0]; - gr_size_x = x_fit_gauss_function.length; - //If gr axis values are not identical, calculate the index... - gr_pos_x = (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x) : x); - //But prefer checking the value to avoid raounding errors - for (int i=0;i imageBuffer = new ArrayList(); - Frame currentFrame; - int imageBufferLenght = 1; - Text imagePauseOverlay; - final Console console; - - public ScreenPanel6() { - try { - initComponents(); - spinnerThreshold.setVisible(false); - btFixColormapRange.setVisible(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - setRotationOptionsVisible(false); - setAveragingOptionsVisible(false); - JComponent editor = spinnerSlOrientation.getEditor(); - if (editor instanceof JSpinner.DefaultEditor) { - ((JSpinner.DefaultEditor) editor).getTextField().setHorizontalAlignment(JTextField.RIGHT); - } - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - //setPersistedComponents(new Component[]{buttonServer, buttonDirect}); - setPersistedComponents(new Component[]{buttonTitle}); - comboCameras.setEnabled(false); - comboType.setEnabled(false); - - SwingUtils.setEnumCombo(comboColormap, Colormap.class); - if (App.hasArgument("poll")) { - try { - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try { - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("buf")) { - try { - imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("usr_ov")) { - try { - userOverlaysConfigFile = App.getArgumentValue("usr_ov"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_url")) { - serverUrl = App.getArgumentValue("srv_url"); - } - - if (App.hasArgument("cam_srv_url")) { - camServerUrl = App.getArgumentValue("cam_srv_url"); - } - - if (App.hasArgument("calc")) { - useServerStats = false; - } - - if (App.hasArgument("persist")) { - persistCameraState = true; - } - - if (App.hasArgument("suffix")) { - pipelineSuffix = App.getArgumentValue("suffix"); - } - /* - if (App.hasArgument("integration")) { - try { - setIntegration(Integer.valueOf(App.getArgumentValue("integration"))); - if (integration != 0) { - buttonFit.setSelected(false); - buttonProfile.setSelected(false); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - */ - - renderer.setProfileNormalized(true); - renderer.setShowProfileLimits(false); - - JMenuItem menuCalibrate = new JMenuItem("Calibrate..."); - menuCalibrate.addActionListener((ActionEvent e) -> { - try { - calibrate(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuRendererConfig = new JMenuItem("Renderer Parameters"); - menuRendererConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuCameraConfig = new JMenuItem("Camera Configurarion"); - menuCameraConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - String cameraConfigJson = null; - if (usingServer) { - String cameraServerUrl = (camServerUrl == null) ? server.getUrl().substring(0, server.getUrl().length() - 1) + "8" : camServerUrl; - try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)) { - srv.initialize(); - //TODO: replace into encodeMultiline - cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true); - } - - } else { - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - } - TextEditor configEditor = new TextEditor(); - configEditor.setText(cameraConfigJson); - configEditor.setReadOnly(true); - configEditor.setTitle(cameraName); - EditorDialog dlg = configEditor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(getTopLevel(), dlg); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetImageBufferSize = new JMenuItem("Set Stack Size..."); - menuSetImageBufferSize.addActionListener((ActionEvent e) -> { - try { - String ret = SwingUtils.getString(getTopLevel(), "Enter size of image buffer: ", String.valueOf(imageBufferLenght)); - if (ret != null) { - this.setImageBufferSize(Integer.valueOf(ret)); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSaveStack = new JMenuItem("Save Stack"); - menuSaveStack.addActionListener((ActionEvent e) -> { - try { - saveStack(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetROI = new JMenuItem("Set ROI..."); - menuSetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); - renderer.addListener(new RendererListener() { - @Override - public void onSelectionFinished(Renderer renderer, Overlay overlay) { - try { - renderer.setShowReticle(false); - Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (server.isRoiEnabled()) { - int[] cur = server.getRoi(); - server.setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); - } else { - server.setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); - } - } catch (Exception ex) { - } finally { - renderer.removeListener(this); - } - } - - @Override - public void onSelectionAborted(Renderer renderer, Overlay overlay) { - renderer.removeListener(this); - } - }); - selection.setFixed(true); - renderer.startSelection(selection); - } - }); - - JMenuItem menuResetROI = new JMenuItem("Reset ROI"); - menuResetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - try { - renderer.setShowReticle(false); - server.resetRoi(); - } catch (IOException ex) { - showException(ex); - } - } - }); - /* - JCheckBoxMenuItem menuFrameIntegration = new JCheckBoxMenuItem("Multi-Frame", (integration != 0)); - menuFrameIntegration.addActionListener((ActionEvent e) -> { - if (integration == 0) { - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{150, 50}; //Minimum width - layout.rowHeights = new int[]{30, 30}; //Minimum height - panel.setLayout(layout); - JCheckBox checkContinuous = new JCheckBox(""); - checkContinuous.setSelected(true); - JTextField textFrames = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Number of frames:"), c); - c.gridy = 1; - panel.add(new JLabel("Continuous:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(checkContinuous, c); - c.gridy = 0; - panel.add(textFrames, c); - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", panel, OptionType.OkCancel) == OptionResult.Yes) { - setIntegration(checkContinuous.isSelected() ? -(Integer.valueOf(textFrames.getText())) : (Integer.valueOf(textFrames.getText()))); - } - } else { - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", - "Do you want to disable " + ((integration < 0) ? "continuous " : "") + "multi-frame integration (" + Math.abs(integration) + ")?", OptionType.YesNo) == OptionResult.Yes) { - setIntegration(0); - } - } - }); - - for (Component cmp : SwingUtils.getComponentsByType(renderer.getPopupMenu(), JMenu.class)) { - JMenu menu = (JMenu) cmp; - if (menu.getText().equals("Integration")) { - menu.addSeparator(); - menu.add(menuFrameIntegration); - } - } - */ - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuRendererConfig); - renderer.getPopupMenu().add(menuCameraConfig); - renderer.getPopupMenu().add(menuSetImageBufferSize); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuCalibrate); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuSetROI); - renderer.getPopupMenu().add(menuResetROI); - renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(server != null); - menuSetROI.setEnabled(server != null); - menuCalibrate.setVisible(server != null); - menuCalibrate.setEnabled((calibrationDialolg == null) || (!calibrationDialolg.isShowing())); - menuSaveStack.setEnabled(imageBufferLenght > 0); - menuSetImageBufferSize.setEnabled(!renderer.isPaused()); - //menuFrameIntegration.setSelected(integration != 0); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - } - }); - renderer.getPopupMenu().setVisible(false); - buttonScale.setSelected(renderer.getShowColormapScale()); - clearMarker(); - - showFit = buttonFit.isSelected(); - showProfile = buttonProfile.isSelected(); - - pauseSelection.setVisible(false); - pauseSelection.setMinValue(1); - pauseSelection.addListener(new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - if (editing && (value >= 1) && (value <= imageBuffer.size())) { - updatePause(); - } - } - }); - renderer.addListener(new RendererListener() { - @Override - public void onMoveFinished(Renderer renderer, Overlay overlay) { - if (overlay == marker) { - try { - onMarkerChanged(); - } catch (IOException ex) { - Logger.getLogger(ScreenPanel6.class.getName()).log(Level.WARNING, null, ex); - } - } - } - }); - if (MainFrame.isDark()) { - textState.setDisabledTextColor(textState.getForeground()); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - - console = (!App.hasArgument("console")) ? null : new Console() { - /* - protected void onConsoleCommand(String name, String[] pars, String trimming) throws Exception { - switch (name) { - case "cam": - comboCameras.setSelectedItem(tokens[1]); - break; - } - }*/ - @Override - protected void onConsoleCommand(String command) { - String[] tokens = command.split(" "); - if ((tokens.length > 1) && tokens[0].equals("cam")) { - try { - if (!tokens[1].equals(comboCameras.getSelectedItem())) { - setComboTypeSelection("All"); - updateCameraList(); - comboCameras.setSelectedItem(tokens[1]); - if (!tokens[1].equals(comboCameras.getSelectedItem())) { - comboCameras.setSelectedItem(""); - throw new Exception("Invalid camera name : " + tokens[1]); - } - System.out.println("Console set camera: " + tokens[1]); - } - } catch (Exception ex) { - System.err.println(ex); - } - } else { - System.err.println("Invalid command: " + command); - } - } - }; - } - - /* - void setIntegration(int frames) { - try { - if (integration != frames) { - integration = frames; - if (camera != null) { - if (Math.abs(integration) > 1) { - renderer.setDevice(new ImageIntegrator(integration)); - } else { - renderer.setDevice(camera); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - */ - - @Override - public void onStart() { - super.onStart(); - updateDialogTitle(); - if (App.hasArgument("ct")) { - boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonServer.setSelected(!direct); - buttonDirect.setSelected(direct); - } - if (App.hasArgument("console")) { - console.start(); - } - } - - @Override - public void onStop() { - try { - if (camera != null) { - saveCameraState(); - camera.close(); - camera = null; - server = null; - updateButtons(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - if (console != null) { - console.stop(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - super.onStop(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - comboType.setEnabled(false); - if (App.hasArgument("s")) { - renderer.setDevice((Source) getDevice("image")); - renderer.setAutoScroll(true); - ((Source) getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - manageFit(bi, data); - manageUserOverlays(bi, data); - } - - @Override - public void onError(Object o, Exception ex) { - } - } - ); - - } else { - usingServer = buttonServer.isSelected(); - updateCameraList(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - setComboCameraSelection(null); - setComboTypeSelection("All"); - - if (comboCameras.getModel().getSize() > 0) { - try { - if (App.hasArgument("cam")) { - setComboCameraSelection(App.getArgumentValue("cam")); - comboCamerasActionPerformed(null); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - updateButtons(); - startTimer(1000); - } - - boolean isVisible(String camera) { - return ((comboType.getSelectedIndex() == 0) || (getCameraType(camera).equals(comboType.getSelectedItem()))); - } - - DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - if (fromServer) { - try (PipelineServer srv = newServer()) { - srv.initialize(); - List cameras = srv.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - - } else { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - if (App.hasArgument("cam")) { - String camera = App.getArgumentValue("cam"); - if (model.getIndexOf(camera) < 0) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - model.addElement(""); - - return model; - } - - PipelineServer newServer() throws IOException { - if (serverUrl != null) { - System.out.println("Connecting to server: " + serverUrl); - server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl); - } else { - System.out.println("Connecting to server"); - server = new PipelineServer(CAMERA_DEVICE_NAME); - } - updateButtons(); - return server; - } - - boolean updatingCameraSelection; - - void setComboCameraSelection(Object selection) { - updatingCameraSelection = true; - try { - comboCameras.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - - void setComboTypeSelection(Object selection) { - updatingCameraSelection = true; - try { - comboType.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - boolean usingServer; - - void updateCameraList() { - try { - String selected = (String) comboCameras.getSelectedItem(); - comboCameras.setModel(getCameraList(usingServer)); - if (selected != null) { - if (((DefaultComboBoxModel) comboCameras.getModel()).getIndexOf(camera) < 0) { - setComboCameraSelection(selected); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - } - - final Object lockOverlays = new Object(); - - void manageFit(BufferedImage bi, Data data) { - Overlay[][] fo = null; - if ((showFit || showProfile)) { - try { - fo = getFitOverlays(data); - } catch (Exception ex) { - System.err.println(ex); - } - } - synchronized (lockOverlays) { - fo = (fo == null) ? new Overlay[][]{null, null} : fo; - renderer.updateOverlays(fo[0], profileOv); - profileOv = fo[0]; - renderer.updateOverlays(fo[1], fitOv); - fitOv = fo[1]; - } - } - - void manageUserOverlays(BufferedImage bi, Data data) { - Overlay[] fo = (bi == null) ? null : getUserOverlays(data); - synchronized (lockOverlays) { - renderer.updateOverlays(fo, userOv); - userOv = fo; - } - } - - void updateDialogTitle() { - if (App.isDetached()) { - getTopLevel().setTitle(cameraName == null ? "ScreenPanel" : cameraName); - } - } - - void manageTitleOverlay() { - Overlay to = null; - if ((buttonTitle.isSelected()) && (cameraName != null)) { - Font font = new Font("Arial", Font.PLAIN, 28); - to = new Text(renderer.getPenErrorText(), cameraName, font, new Point(-SwingUtils.getTextSize(cameraName, renderer.getGraphics().getFontMetrics(font)).width - 14, 26)); - to.setFixed(true); - to.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - } - - synchronized (lockOverlays) { - renderer.updateOverlays(to, titleOv); - titleOv = to; - } - } - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - Thread devicesInitTask; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Initializing: " + cameraName); - parseUserOverlays(); - errorOverlay = null; - lastMarkerPos = null; - lastFrame = null; - lastPipelinePars = null; - - if (dataTableDialog != null) { - dataTableDialog.dispose(); - dataTableDialog = null; - } - dataTableModel = null; - - if (calibrationDialolg != null) { - calibrationDialolg.dispose(); - calibrationDialolg = null; - } - - boolean was_server = false; - if (camera != null) { - saveCameraState(); - //camera.removeAllListeners(); - was_server = (server != null); - camera.close(); - camera = null; - server = null; - } - updateButtons(); - instanceName = null; - renderer.setDevice(null); - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.removeOverlays(profileOv); - renderer.removeOverlays(userOv); - renderer.clear(); - renderer.resetZoom(); - - boolean changed = !String.valueOf(cameraName).equals(this.cameraName); - this.cameraName = cameraName; - - if (changed || buttonDirect.isSelected()) { - spinnerThreshold.setVisible(false); - checkThreshold.setEnabled(false); - checkRotation.setEnabled(false); - checkAveraging.setEnabled(false); - checkGoodRegion.setEnabled(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - setRotationOptionsVisible(false); - setAveragingOptionsVisible(false); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - if (changed) { - checkBackground.setEnabled(false); - if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { - devicesInitTask.interrupt(); - } - if (screen != null) { - screen.close(); - screen = null; - } - if (filter != null) { - filter.close(); - filter = null; - } - if (renderer.isPaused()) { - renderer.resume(); - removePauseOverlay(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - manageTitleOverlay(); - updateDialogTitle(); - - if (cameraName == null) { - return; - } - - System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]"); - try { - if (buttonServer.isSelected()) { - camera = newServer(); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - //camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName); - camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName}); - } - camera.initialize(); - camera.assertInitialized(); - System.out.println("Camera initialization OK"); - loadCameraState(); - if (server != null) { - //server.start(cameraName, false); - String pipelineName = cameraName + pipelineSuffix; - instanceName = cameraName + pipelineSuffix + "1"; - if (!server.getPipelines().contains(pipelineName)) { - System.out.println("Creating pipeline: " + pipelineName); - HashMap config = new HashMap<>(); - config.put("camera_name", cameraName); - //server.createFromConfig(config, pipelineName); - server.savePipelineConfig(pipelineName, config); - } - server.start(pipelineName, instanceName); - - updatePipelineControls(); - checkThreshold.setEnabled(true); - checkRotation.setEnabled(true); - checkAveraging.setEnabled(true); - checkGoodRegion.setEnabled(true); - } else { - checkThreshold.setSelected(false); - checkRotation.setSelected(false); - checkAveraging.setSelected(false); - checkGoodRegion.setSelected(false); - if (polling <= 0) { - camera.setMonitored(true); - } else { - camera.setPolling(polling); - } - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - updateButtons(); - camera.getConfig().save(); - - //if (Math.abs(integration) > 1) { - // renderer.setDevice(new ImageIntegrator(integration)); - //} else { - renderer.setDevice(camera); - //} - - renderer.setAutoScroll(true); - //renderer.setMarker(marker); - clearMarker(); - imageSize = null; - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi != null) { - if ((imageSize == null) || imageSize.width != bi.getWidth() || imageSize.height != bi.getHeight()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { - centralizeRenderer(); - } - checkReticle(); - } - }); - imageSize = new Dimension(bi.getWidth(), bi.getHeight()); - } - renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); - } - //renderer.setCalibration(camera.getCalibration()); - if (!renderer.isPaused()) { - if (data != null) { - synchronized (imageBuffer) { - currentFrame = new Frame(data); - if (imageBufferLenght >= 1) { - imageBuffer.add(currentFrame); - if (imageBuffer.size() > imageBufferLenght) { - imageBuffer.remove(0); - setBufferFull(true); - } else { - setBufferFull(false); - } - } else { - setBufferFull(true); - } - //Update data - if (!renderer.isPaused()) { - updateStreamData(); - } - updateMarker(); - } - } - manageFit(bi, data); - manageUserOverlays(bi, data); - } - //updateImageData(); - } - - @Override - public void onError(Object o, Exception ex) { - //System.err.println(ex); - } - }); - - } catch (Exception ex) { - showException(ex); - renderer.clearOverlays(); - updatePipelineControls(); - if (renderer.getDevice() == null) { - //renderer.setZoom(1.0); - //renderer.setMode(RendererMode.Zoom); - errorOverlay = new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - errorOverlay.setFixed(true); - errorOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - renderer.addOverlay(errorOverlay); - } - } finally { - //checkReticle(); - onTimer(); - } - onChangeColormap(null); - checkBackground.setEnabled(true); - if (changed) { - boolean electrons = getCameraType(cameraName).equals(ELECTRONS_TYPE); - comboScreen.setModel(new DefaultComboBoxModel()); - comboScreen.setEnabled(false); - comboFilter.setModel(new DefaultComboBoxModel()); - comboFilter.setEnabled(false); - panelFilter.setVisible(electrons); - panelScreen.setVisible(electrons); - if (electrons) { - //Parallelizing initialization - devicesInitTask = new Thread(() -> { - try { - if (cameraName.contains("DSRM")) { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); - } else { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); - } - screen.setMonitored(true); - screen.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : screen.getPositions()) { - model.addElement(pos); - } - comboScreen.setModel(model); - comboScreen.setSelectedItem(screen.read()); - - } catch (Exception ex) { - comboScreen.setModel(new DefaultComboBoxModel()); - System.err.println(ex.getMessage()); - screen = null; - } - comboScreen.setEnabled(screen != null); - valueScreen.setDevice(screen); - - try { - filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); - filter.setMonitored(true); - filter.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : filter.getPositions()) { - model.addElement(pos); - } - comboFilter.setModel(model); - comboFilter.setSelectedItem(filter.read()); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - filter = null; - } - comboFilter.setEnabled(filter != null); - valueFilter.setDevice(filter); - }); - devicesInitTask.start(); - } - } - } - /* - class ImageIntegrator extends ColormapSource { - - ImageIntegrator(int num) { - super("Image Averager", camera.getConfig()); - boolean continuous = (num < 0); - final int numImages = Math.abs(num); - - camera.addListener(new ImageListener() { - final ArrayList buffer = new ArrayList(); - Data integration = null; - - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - try { - if (continuous) { - buffer.add(data); - if (buffer.size() >= numImages) { - for (Data d : buffer) { - process(d); - } - } - } else { - buffer.add(null); //Just to count - process(data); - } - } catch (Exception ex) { - buffer.clear(); - integration = null; - ImageIntegrator.this.pushData(null); - ex.printStackTrace(); - return; - } - if (buffer.size() >= numImages) { - if (continuous) { - buffer.remove(0); - } else { - buffer.clear(); - } - if (integration != null) { - //integration.div(numImages); - ImageIntegrator.this.pushData(integration); - } - integration = null; - } - } - - void process(Data data) { - if (integration == null) { - integration = new Data(data); - } else { - integration.sum(data); - } - } - - @Override - public void onError(Object origin, Exception ex) { - } - }); - - } - } - */ - - boolean bufferFull = true; - - void setBufferFull(boolean value) { - if (value != bufferFull) { - SwingUtilities.invokeLater(() -> { - buttonPause.setBackground(value ? buttonSave.getBackground() : buttonSave.getBackground().brighter()); - }); - bufferFull = value; - } - } - - volatile Dimension imageSize; - - void checkReticle() { - if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) { - //renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800, 800), 200); - renderer.setShowReticle(true); - } else { - //renderer.setCalibration(null); - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - void checkMarker(Point p) throws IOException { - if (camera != null) { - if (buttonMarker.isSelected()) { - Dimension d = renderer.getImageSize(); - if (p == null) { - p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - } - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - marker.setPassive(false); - } else { - marker = null; - } - renderer.setMarker(marker); - onMarkerChanged(); - } - } - - Point lastMarkerPos; - - void onMarkerChanged() throws IOException { - lastMarkerPos = getStreamMarkerPos(); - if (marker == null) { - setInstanceConfigValue("Marker", null); - } else { - setInstanceConfigValue("Marker", new int[]{marker.getPosition().x, marker.getPosition().y}); - } - } - - void updateMarker() { - try { - if (server != null) { - Point p = getStreamMarkerPos(); - if (p != null) { - //To prevent a local change being overriden by a message having the old settings. - //TODO: This is not bullet-proof, as one can have 2 changes between 2 frames... - if (!p.equals(lastMarkerPos)) { - if (p.x == Integer.MIN_VALUE) { - if (buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - checkMarker(null); - } - } else { - if (!buttonMarker.isSelected()) { - buttonMarker.setSelected(true); - checkMarker(p); - } else { - if (!p.equals(marker.getPosition())) { - marker.setPosition(p); - } - } - } - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - Point getStreamMarkerPos() throws IOException { - //System.out.println(server.getInstanceConfig().get("Marker")); - Map pars = server.getProcessingParameters(); - if (pars != null) { - List markerPosition = (List) pars.get("Marker"); - if (markerPosition != null) { - return new Point((Integer) markerPosition.get(0), (Integer) markerPosition.get(1)); - } - return new Point(Integer.MIN_VALUE, Integer.MIN_VALUE); - } - return null; - } - - void clearMarker() { - marker = null; - renderer.setMarker(marker); - } - - void setInstanceConfigValue(String name, Object value) throws IOException { - if (server != null) { - Map map = server.getInstanceConfig(); - map.put(name, value); - server.setInstanceConfig(map); - } - } - - void updateZoom() { - try { - buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom) { - if (renderer.getZoom() == 1) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getZoom() == 0.5) { - buttonZoom05.setSelected(true); - } else if (renderer.getZoom() == 0.25) { - buttonZoom025.setSelected(true); - } else if (renderer.getZoom() == 2.0) { - buttonZoom2.setSelected(true); - } else { - buttonGroup1.clearSelection(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - boolean updatingColormap; - - void updateColormap() { - updatingColormap = true; - try { - if ((camera != null) && (camera instanceof ColormapSource)) { - ColormapSourceConfig config = ((ColormapSource) camera).getConfig(); - comboColormap.setSelectedItem(config.colormap); - if (config.isDefaultColormap()) { - buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic) { - buttonAutomatic.setSelected(true); - } else { - buttonManual.setSelected(true); - } - btFixColormapRange.setVisible(buttonAutomatic.isSelected()); - spinnerMin.setEnabled(buttonManual.isSelected()); - spinnerMax.setEnabled(buttonManual.isSelected()); - if (!Double.isNaN(config.colormapMin)) { - spinnerMin.setValue(Math.min(Math.max((int) config.colormapMin, 0), 65535)); - } - if (!Double.isNaN(config.colormapMax)) { - spinnerMax.setValue(Math.min(Math.max((int) config.colormapMax, 0), 65535)); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatingColormap = false; - } - - void updatePipelineProperties() { - goodRegion = checkGoodRegion.isSelected(); - spinnerThreshold.setVisible(checkThreshold.isSelected()); - setGoodRegionOptionsVisible(goodRegion); - slicing = goodRegion && checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - updatingServerControls = false; - boolean rotation = checkRotation.isSelected(); - setRotationOptionsVisible(rotation); - boolean averaging = checkAveraging.isSelected(); - setAveragingOptionsVisible(averaging); - } - - boolean updatingServerControls; - - void updatePipelineControls() { - if (server != null) { - updatingServerControls = true; - if (server.isStarted()) { - try { - checkBackground.setSelected(server.getBackgroundSubtraction()); - Double threshold = (server.getThreshold()); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (server.getGoodRegion()); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - spinnerGrThreshold.setValue(((Number) gr.get("threshold")).doubleValue()); - spinnerGrScale.setValue(((Number) gr.get("gfscale")).doubleValue()); - } - Map rotation = server.getRotation(); - checkRotation.setSelected(rotation != null); - if (rotation!=null){ - spinnerRotationAngle.setValue(((Number) rotation.get("angle")).doubleValue()); - spinnerRotationOrder.setValue(((Number) rotation.get("order")).intValue()); - String mode = (String) rotation.get("mode"); - try{ - spinnerRotationConstant.setValue(Double.valueOf(mode)); - spinnerRotationMode.setValue("constant"); - } catch (Exception ex){ - spinnerRotationConstant.setValue(0); - spinnerRotationMode.setValue(mode); - } - } - - Number averaging = (Number) server.getInstanceConfig().get("averaging"); - checkAveraging.setSelected(averaging != null); - if (averaging!=null){ - spinnerAvFrames.setValue(Math.abs(averaging.intValue())); - spinnerAvMode.setValue(averaging.intValue()<0 ? "window" : "single"); - } - - - Map slicing = (server.getSlicing()); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - spinnerSlNumber.setValue(((Number) slicing.get("number_of_slices")).intValue()); - spinnerSlScale.setValue(((Number) slicing.get("scale")).doubleValue()); - spinnerSlOrientation.setValue((String) slicing.get("orientation")); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - updatePipelineProperties(); - } - } - - boolean changedPipelinePars(Map pars1, Map pars2) { - String[] keys = new String[]{"image_background_enable", "image_threshold", "image_good_region", - "threshold", "gfscale", "image_slices", "number_of_slices", "scale", "orientation"}; - for (String key : keys) { - Object o1 = pars1.get(key); - Object o2 = pars2.get(key); - if (o1 == null) { - if (o2 != null) { - return true; - } - } else if (!o1.equals(o2)) { - return true; - } - } - return false; - } - - void updatePipelineControls(Map pars) { - if (pars != null) { - updatingServerControls = true; - try { - boolean background = (boolean) pars.get("image_background_enable"); - checkBackground.setSelected(background); - Double threshold = (Double) (pars.get("image_threshold")); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (Map) pars.get("image_good_region"); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - Double value = ((Number) gr.get("threshold")).doubleValue(); - spinnerGrThreshold.setValue(value); - Double scale = ((Number) gr.get("gfscale")).doubleValue(); - spinnerGrScale.setValue(scale); - } - Map slicing = (Map) (pars.get("image_slices")); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - int slices = ((Number) slicing.get("number_of_slices")).intValue(); - spinnerSlNumber.setValue(slices); - double scale = ((Number) slicing.get("scale")).doubleValue(); - spinnerSlScale.setValue(scale); - String orientation = (String) slicing.get("orientation"); - spinnerSlOrientation.setValue(orientation); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatePipelineProperties(); - } - } - - void setGoodRegionOptionsVisible(boolean visible) { - spinnerGrThreshold.setVisible(visible); - labelGrThreshold.setVisible(visible); - spinnerGrScale.setVisible(visible); - labelGrScale.setVisible(visible); - panelSlicing.setVisible(visible); - } - - void setSlicingOptionsVisible(boolean visible) { - spinnerSlNumber.setVisible(visible); - labelSlNumber.setVisible(visible); - spinnerSlScale.setVisible(visible); - labelSlScale.setVisible(visible); - spinnerSlOrientation.setVisible(visible); - labelSlOrientation.setVisible(visible); - } - - void setAveragingOptionsVisible(boolean visible) { - labelAvMode.setVisible(visible); - labelAvFrames.setVisible(visible); - spinnerAvMode.setVisible(visible); - spinnerAvFrames.setVisible(visible); - } - - void setRotationOptionsVisible(boolean visible) { - labelAngle.setVisible(visible); - labelOrder.setVisible(visible); - labelMode.setVisible(visible); - labelConstant.setVisible(visible); - spinnerRotationAngle.setVisible(visible); - spinnerRotationOrder.setVisible(visible); - spinnerRotationMode.setVisible(visible); - spinnerRotationConstant.setVisible(visible); - } - - boolean isCameraStopped() { - if ((server != null) && !server.isStarted()) { - return true; - } - return ((camera == null) || camera.isClosed()); - } - - boolean updatingButtons; - - void updateButtons() { - updatingButtons = true; - try { - boolean active = !isCameraStopped();//(camera != null); - buttonSave.setEnabled(active); - buttonGrabBackground.setEnabled(active); - buttonMarker.setEnabled(active); - buttonProfile.setEnabled(active); - buttonFit.setEnabled(active); - buttonReticle.setEnabled(active && camera.getConfig().isCalibrated()); - buttonStreamData.setEnabled(active && (server != null)); - buttonPause.setEnabled(active); - - if (renderer.isPaused() != buttonPause.isSelected()) { - buttonPause.setSelected(renderer.isPaused()); - buttonPauseActionPerformed(null); - } - if (renderer.getShowReticle() != buttonReticle.isSelected()) { - //buttonReticle.setSelected(renderer.getShowReticle()); - } - if ((renderer.getMarker() == null) && buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - } - buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - - } finally { - updatingButtons = false; - } - } - - Frame lastFrame = null; - Map lastPipelinePars = null; - - @Override - protected void onTimer() { - for (Device dev : new Device[]{screen, filter}) { - if (dev != null) { - dev.request(); - } - } - - textState.setText((camera == null) ? "" : camera.getState().toString()); - if (App.hasArgument("s")) { - try { - ((Source) getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } - } - updateZoom(); - updateColormap(); - updateButtons(); - checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); - buttonScale.setSelected(renderer.getShowColormapScale()); - try { - Frame frame = getCurrentFrame(); - if (frame != lastFrame) { - lastFrame = frame; - if (frame != null) { - Map pars = getProcessingParameters(frame.cache); - if ((lastPipelinePars == null) || changedPipelinePars(pars, lastPipelinePars)) { - //System.out.println("Update pipeline: " + pars); - lastPipelinePars = pars; - updatePipelineControls(pars); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - Pen penFit = new Pen(new Color(192, 105, 0), 0); - Pen penCross = new Pen(new Color(192, 105, 0), 0); - Pen penSlices = new Pen(Color.CYAN.darker(), 1); - - Frame getCurrentFrame() { - if ((imageBufferLenght > 1) && (renderer.isPaused())) { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - return (index < imageBuffer.size()) ? imageBuffer.get(index) : null; - } - } - return currentFrame; - } - - Frame getFrame(Data data) { - synchronized (imageBuffer) { - for (Frame f : imageBuffer) { - if (f.data == data) { - return f; - } - } - } - return null; - } - - void setImageBufferSize(int size) { - if (renderer.isPaused()) { - throw new RuntimeException("Cannot change buffer size whn paused"); - } - synchronized (imageBuffer) { - imageBufferLenght = size; - imageBuffer.clear(); - } - - } - - Overlay[][] getFitOverlays(Data data) { - Overlays.Polyline hgaussian = null; - Overlays.Polyline vgaussian = null; - Overlays.Polyline hprofile = null; - Overlays.Polyline vprofile = null; - Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null; - Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null; - double[] pX = null, pY = null, gX = null, gY = null; - PointDouble[] sliceCenters = null; - if (data != null) { - int height = data.getHeight(); - int width = data.getWidth(); - int profileSize = renderer.getProfileSize(); - ImageData id = null; - if ((useServerStats) && (server != null)) { - try { - id = getFrame(data); - if (id == null) { - return null; - } - xMean = id.x_fit_mean; - xSigma = id.x_fit_standard_deviation; - yMean = id.y_fit_mean; - ySigma = id.y_fit_standard_deviation; - gX = id.x_fit_gauss_function; - gY = id.y_fit_gauss_function; - pX = id.x_profile; - pY = id.y_profile; - xCom = id.x_center_of_mass; - xRms = id.x_rms; - yCom = id.y_center_of_mass; - yRms = id.y_rms; - sliceCenters = id.sliceCenters; - - profileSize /= 4; - if (pX != null) { - int[] xp = Arr.indexesInt(pX.length); - int[] xg = xp; - int[] yp = new int[pX.length]; - int[] yg = new int[pX.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_x > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gX, id.gr_pos_x, id.gr_pos_x + id.gr_size_x))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gX != null) { - yg[i] = (int) (height - 1 - (((gX[i] - minGauss) / rangeGauss) * profileSize)); - } - yp[i] = (int) (height - 1 - (((pX[i] - minProfile) / rangeProfile) * profileSize)); - } - - if (goodRegion && id.gr_size_x > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - yg = Arrays.copyOfRange(yg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - } - - vgaussian = new Overlays.Polyline(penFit, xg, yg); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - - if (pY != null) { - int[] xp = new int[pY.length]; - int[] xg = new int[pY.length]; - int[] yp = Arr.indexesInt(pY.length); - int[] yg = yp; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_y > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gY, id.gr_pos_y, id.gr_pos_y + id.gr_size_y))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gY != null) { - xg[i] = (int) (((gY[i] - minGauss) / rangeGauss) * profileSize); - } - xp[i] = (int) (((pY[i] - minProfile) / rangeProfile) * profileSize); - } - - if (goodRegion && id.gr_size_y > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - yg = Arrays.copyOfRange(yg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - } - hgaussian = new Overlays.Polyline(penFit, xg, yg); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - return null; - } - } else { - ArrayProperties properties = data.getProperties(); - double maxPlot = properties.max; - double minPlot = properties.min; - double rangePlot = maxPlot - minPlot; - - if (rangePlot <= 0) { - return null; - } - if (renderer.getCalibration() != null) { - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height - minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - if (xSigma != null) { - xSigma *= renderer.getCalibration().getScaleX(); - } - if (ySigma != null) { - ySigma *= renderer.getCalibration().getScaleY(); - } - if (xMean != null) { - xMean = data.getX((int) Math.round(xMean)); - } - if (yMean != null) { - yMean = data.getY((int) Math.round(yMean)); - } - } - } - final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px"; - final String fmt = "%7.1f" + units; - Overlays.Text textCom = null; - Overlay[] pOv = null, fOv = null; - Font fontInfoText = new Font(Font.MONOSPACED, 0, 14); - Point textPosition = new Point(12, 20); - if (showProfile) { - if ((xCom != null) && (yCom != null)) { - String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt, xCom, xRms, yCom, yRms); - textCom = new Overlays.Text(renderer.getPenProfile(), text, fontInfoText, textPosition); - textCom.setFixed(true); - textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - } - pOv = new Overlay[]{hprofile, vprofile, textCom}; - textPosition = new Point(textPosition.x, textPosition.y + 34); - } - if (showFit) { - Overlays.Crosshairs cross = null; - Overlays.Text textFit = null; - if ((xMean != null) && (yMean != null)) { - String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt, xMean, xSigma, yMean, ySigma); - textFit = new Overlays.Text(penFit, text, fontInfoText, textPosition); - textFit.setFixed(true); - textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - Point center = new Point(xMean.intValue(), yMean.intValue()); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean)); - xSigma /= renderer.getCalibration().getScaleX(); - ySigma /= renderer.getCalibration().getScaleY(); - } - cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue()))); - } - textPosition = new Point(textPosition.x, textPosition.y + 34); - fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit}; - - if (goodRegion && (id != null)) { - try { - double[] x = id.gr_x_axis; - double[] y = id.gr_y_axis; - Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); - goodRegionOv.setCalibration(renderer.getCalibration()); - goodRegionOv.setPosition(new Point(id.gr_pos_x, id.gr_pos_y)); - goodRegionOv.setSize(new Dimension(id.gr_x_axis.length, id.gr_y_axis.length)); - fOv = Arr.append(fOv, goodRegionOv); - - if (slicing) { - if (sliceCenters != null) { - for (PointDouble sliceCenter : sliceCenters) { - Overlays.Crosshairs center = new Overlays.Crosshairs(penSlices); - center.setCalibration(renderer.getCalibration()); - center.setAbsolutePosition(sliceCenter); - center.setSize(new Dimension(10, 10)); - fOv = Arr.append(fOv, center); - } - if (sliceCenters.length > 1) { - double[] fit = fitPolynomial(sliceCenters, 1); - double angle = Math.toDegrees(Math.atan(fit[1])); - Overlays.Text text = new Overlays.Text(penSlices, String.format("slice: \u03B8= %5.1fdeg", angle), fontInfoText, textPosition); - text.setFixed(true); - text.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - fOv = Arr.append(fOv, text); - } - } - } - } catch (Exception ex) { - } - } - - } - return new Overlay[][]{pOv, fOv}; - } - return null; - } - - class UserOverlay { - - String name; - Overlay obj; - String[] channels; - } - ArrayList userOverlayConfig; - - void parseUserOverlays() { - Properties userOverlays = new Properties(); - userOverlayConfig = new ArrayList<>(); - if (userOverlaysConfigFile != null) { - try { - try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { - userOverlays.load(in); - - for (String name : userOverlays.stringPropertyNames()) { - String val = userOverlays.getProperty(name); - try { - UserOverlay uo = new UserOverlay(); - uo.name = name; - String type = val.substring(0, val.indexOf("(")).trim(); - String pars = val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")).trim(); - String[] tokens = pars.split(","); - for (int i = 0; i < tokens.length; i++) { - tokens[i] = tokens[i].trim(); - } - Color color = Color.GRAY; - try { - color = (Color) Color.class.getField(tokens[tokens.length - 1].toUpperCase()).get(null); - } catch (Exception ex) { - } - Pen pen = new Pen(color); - try { - String[] penTokens = tokens[tokens.length - 1].split(":"); - color = (Color) Color.class.getField(penTokens[0].toUpperCase()).get(null); - int width = Integer.valueOf(penTokens[1]); - Pen.LineStyle style = Pen.LineStyle.valueOf(penTokens[2]); - pen = new Pen(color, width, style); - } catch (Exception ex) { - } - switch (type) { - case "Point": - uo.obj = new Overlays.Crosshairs(); - uo.obj.setSize(new Dimension(Integer.valueOf(tokens[2]), Integer.valueOf(tokens[3]))); - break; - case "Line": - uo.obj = new Overlays.Line(); - break; - case "Arrow": - uo.obj = new Overlays.Arrow(); - break; - case "Rect": - uo.obj = new Overlays.Rect(); - break; - case "Ellipse": - uo.obj = new Overlays.Ellipse(); - break; - case "Polyline": - uo.obj = new Overlays.Polyline(); - break; - } - if (type.equals("Polyline") || type.equals("Point")) { - uo.channels = new String[]{tokens[0], tokens[1]}; - } else { - uo.channels = new String[]{tokens[0], tokens[1], tokens[2], tokens[3]}; - } - uo.obj.setPen(pen); - userOverlayConfig.add(uo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - Overlay[] getUserOverlays(Data data) { - ArrayList ret = new ArrayList<>(); - if (server != null) { - ImageData id = getFrame(data); - for (UserOverlay uo : userOverlayConfig) { - try { - Overlay ov = uo.obj; - //Overlay ov = (Overlay)uo.cls.newInstance(); - ov.setCalibration(renderer.getCalibration()); - boolean valid = false; - if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : id.getDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : id.getDoubleArray(uo.channels[1]); - if ((x != null) || (y != null)) { - if (x == null) { - x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); - } - if (y == null) { - y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length); - } - ((Overlays.Polyline) ov).updateAbsolute(x, y); - valid = true; - } - } else { - Double x = id.getDouble(uo.channels[0]); - Double y = id.getDouble(uo.channels[1]); - if ((x != null) && (y != null)) { - PointDouble position = new PointDouble(x, y); - ov.setAbsolutePosition(position); - if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = id.getDouble(uo.channels[2]); - Double y2 = id.getDouble(uo.channels[3]); - if ((x != null) && (y != null)) { - DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); - ov.setAbsoluteSize(size); - valid = true; - } - } else { - valid = true; - } - } - } - if (valid) { - ret.add(ov); - } - } catch (Exception ex) { - //ex.printStackTrace(); - } - } - } - return ret.toArray(new Overlay[0]); - } - - double[] getComRms(double[] arr, double[] x) { - if (arr != null) { - double xmd = 0; - double xmd2 = 0; - double total = 0; - for (int i = 0; i < arr.length; i++) { - double v = (arr[i] * x[i]); - xmd += v; - xmd2 += (v * x[i]); - total += arr[i]; - } - if (total > 0) { - double com = xmd / total; - double com2 = xmd2 / total; - double rms = Math.sqrt(Math.abs(com2 - com * com)); - return new double[]{com, rms}; - } - } - return new double[]{Double.NaN, Double.NaN}; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] fitPolynomial(PointDouble[] points, int order) { - double[] y = new double[points.length]; - double[] x = new double[points.length]; - for (int i = 0; i < points.length; i++) { - x[i] = points[i].x; - y[i] = points[i].y; - } - return fitPolynomial(y, x, order); - } - - double[] fitPolynomial(double[] y, double[] x, int order) { - try { - ArrayProperties pY = ArrayProperties.get(y); - PolynomialCurveFitter fitter = PolynomialCurveFitter.create(order).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - void setHistogramVisible(boolean value) { - if (value) { - if ((histogramDialog == null) || (!histogramDialog.isShowing())) { - Histogram histogram = new Histogram(true); - histogram.setRenderer(renderer); - histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram); - renderer.refresh(); - } - } else { - if (histogramDialog != null) { - histogramDialog.setVisible(false); - histogramDialog = null; - } - } - } - - void setLaserState(int bunch, boolean value) throws Exception { - System.out.println("Setting laser state: " + value + " - bunch" + bunch); - //Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); - if ((bunch<=0) || (bunch==1)){ - Epics.putq("SIN-TIMAST-TMA:Bunch-1-OnDelay-Sel", value ? 0 : 1); - } - if ((bunch<=0) || (bunch==2)){ - Epics.putq("SIN-TIMAST-TMA:Bunch-2-OnDelay-Sel", value ? 0 : 1); - } - - Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); - Thread.sleep(3000); - } - - boolean getLaserState(int bunch) throws Exception { - //return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); - if (bunch<=0){ - return getLaserState(1) && getLaserState(2); - } - if (bunch==2){ - return (Epics.get("SWISSFEL-STATUS:Bunch-2-OnDelay-Sel", Integer.class) == 0); - } - return (Epics.get("SWISSFEL-STATUS:Bunch-1-OnDelay-Sel", Integer.class) == 0); - } - - void elog(String logbook, String title, String message, String[] attachments) throws Exception { - String domain = ""; - String category = "Info"; - String entry = ""; - StringBuffer cmd = new StringBuffer(); - - cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); - cmd.append("-a \"Author=ScreenPanel\" "); - cmd.append("-a \"Type=pshell\" "); - cmd.append("-a \"Entry=").append(entry).append("\" "); - cmd.append("-a \"Title=").append(title).append("\" "); - cmd.append("-a \"Category=").append(category).append("\" "); - cmd.append("-a \"Domain=").append(domain).append("\" "); - for (String attachment : attachments) { - cmd.append("-f \"").append(attachment).append("\" "); - } - cmd.append("-n 1 "); - cmd.append("\"").append(message).append("\" "); - System.out.println(cmd.toString()); - - final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); - new Thread(() -> { - try { - process.waitFor(); - int bytes = process.getInputStream().available(); - byte[] arr = new byte[bytes]; - process.getInputStream().read(arr, 0, bytes); - System.out.println(new String(arr)); - bytes = process.getErrorStream().available(); - arr = new byte[bytes]; - process.getErrorStream().read(arr, 0, bytes); - System.err.println(new String(arr)); - } catch (Exception ex) { - System.err.println(ex); - } - }).start(); - } - - void centralizeRenderer() { - Point center = null; - Dimension size = renderer.getImageSize(); - double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom(); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().getCenter(); - } else if (size != null) { - center = new Point(size.width / 2, size.height / 2); - } - if (center != null) { - Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0), - Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0)); - renderer.setViewPosition(topleft); - } - } - - void updatePause() { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - if (index < imageBuffer.size()) { - Data data = imageBuffer.get(index).data; - long pid = imageBuffer.get(index).cache.getPulseId(); - BufferedImage image = camera.generateImage(data); - renderer.setImage(renderer.getOrigin(), image, data); - - String text = "PID: " + pid; - if (imagePauseOverlay == null) { - Font font = new Font("Verdana", Font.PLAIN, 12); - Dimension d = SwingUtils.getTextSize(text, renderer.getFontMetrics(font)); - imagePauseOverlay = new Text(renderer.getPenErrorText(), "", font, new Point(-20 - d.width, 42)); - imagePauseOverlay.setFixed(true); - imagePauseOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - renderer.addOverlay(imagePauseOverlay); - } - //imagePauseOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS")); - imagePauseOverlay.update(text); - manageFit(image, data); - manageUserOverlays(image, data); - } - } - updateStreamData(); - } - - void removePauseOverlay() { - renderer.removeOverlay(imagePauseOverlay); - imagePauseOverlay = null; - } - - void saveSnapshot() throws Exception { - boolean paused = isPaused(); - try{ - if (!paused){ - setPaused(true); - } - String snapshotFile = null; - synchronized (imageBuffer) { - Frame frame = getCurrentFrame(); - if (frame == null) { - throw new Exception("No current image"); - } - ArrayList frames = new ArrayList<>(); - frames.add(frame); - this.saveFrames(cameraName + "_camera_snapshot", frames); - - //Enforce the same timestamp to data & image files. - snapshotFile = getContext().getExecutionPars().getPath() + ".png"; - //renderer.saveSnapshot(snapshotFile, "png", true); - ImageBuffer.saveImage(SwingUtils.createImage(renderer), snapshotFile, "png"); - } - - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{0, 180}; //Minimum width - layout.rowHeights = new int[]{30, 30, 30}; //Minimum height - panel.setLayout(layout); - JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); - JTextField textComment = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Data file:"), c); - c.gridy = 1; - panel.add(new JLabel("Logbook:"), c); - c.gridy = 2; - panel.add(new JLabel("Comment:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(textComment, c); - c.gridy = 1; - panel.add(comboLogbook, c); - c.gridy = 0; - panel.add(new JLabel(getContext().getExecutionPars().getPath()), c); - - if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes) { - StringBuilder message = new StringBuilder(); - message.append("Camera: ").append(cameraName).append(" ("). - append((server != null) ? "server" : "direct").append(")").append("\n"); - message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); - message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); - message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); - message.append("Comment: ").append(textComment.getText()).append("\n"); - //Add slicing message - if ((fitOv != null) && (fitOv.length > 5) && (fitOv[fitOv.length - 1] instanceof Overlays.Text)) { - Overlays.Text text = (Overlays.Text) fitOv[fitOv.length - 1]; - message.append(text.getText()).append("\n"); - } - elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - } finally{ - if (!paused){ - setPaused(false); - } - } - } - - void saveStack() throws Exception { - synchronized (imageBuffer) { - saveFrames(cameraName + "_camera_stack", imageBuffer); - } - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath()); - } - - public static String getCameraType(String name) { - if (name == null) { - return ""; - } - for (String s : new String[]{"LCAM"}) { - if (name.contains(s)) { - return LASER_TYPE; - } - } - for (String s : new String[]{"DSCR", "DSRM", "DLAC"}) { - if (name.contains(s)) { - return ELECTRONS_TYPE; - } - } - for (String s : new String[]{"PROF", "PPRM", "PSSS", "PSCR", "PSRD"}) { - if (name.contains(s)) { - return PHOTONICS_TYPE; - } - } - return "Unknown"; - } - - public Map getProcessingParameters(StreamValue value) throws IOException { - return (Map) JsonSerializer.decode(value.getValue("processing_parameters").toString(), Map.class); - } - - void saveFrames(String name, ArrayList frames) throws IOException { - ArrayList values = new ArrayList<>(); - for (Frame frame : frames) { - values.add(frame.cache); - } - saveImages(name, values); - } - - void saveImages(String name, ArrayList images) throws IOException { - int depth = images.size(); - if (depth == 0) { - return; - } - StreamValue first = images.get(0); - String pathRoot = "/camera1/"; - String pathImage = pathRoot + "image"; - String pathPid = pathRoot + "pulse_id"; - String pathTimestampStr = pathRoot + "timestamp_str"; - Map processingPars = getProcessingParameters(first); - String camera = (String) processingPars.get("camera_name"); - String type = getCameraType(camera); - - int width = ((Number) first.getValue("width")).intValue(); - int height = ((Number) first.getValue("height")).intValue(); - Class dataType = first.getValue("image").getClass().getComponentType(); - - getContext().setExecutionPars(name); - DataManager dm = getContext().getDataManager(); - - //Create tables - dm.createDataset(pathImage, dataType, new int[]{depth, height, width}); - dm.createDataset(pathPid, Long.class, new int[]{depth}); - dm.createDataset(pathTimestampStr, String.class, new int[]{depth}); - for (String id : first.getIdentifiers()) { - Object val = first.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(first); - for (String key : pars.keySet()) { - if ((pars.get(key) != null) && (pars.get(key) instanceof Map)) { - for (Object k : ((Map) pars.get(key)).keySet()) { - Object v = ((Map) pars.get(key)).get(k); - dm.setAttribute(pathImage, key + " " + k, (v == null) ? "" : v); - } - } else { - Object value = pars.get(key); - if (value == null) { - value = ""; - } else if (value instanceof List) { - Class cls = (((List) value).size() > 0) ? ((List) value).get(0).getClass() : double.class; - value = Convert.toPrimitiveArray(value, cls); - //value = Convert.toDouble(value); - } - dm.setAttribute(pathImage, key, value); - } - } - } else if (val.getClass().isArray()) { - dm.createDataset(pathRoot + id, Double.class, new int[]{depth, Array.getLength(val)}); - } else { - dm.createDataset(pathRoot + id, val.getClass(), new int[]{depth}); - } - } - - //Add metadata - dm.setAttribute(pathRoot, "Camera", camera); - dm.setAttribute(pathRoot, "Images", depth); - dm.setAttribute(pathRoot, "Interval", -1); - dm.setAttribute(pathRoot, "Type", type); - if (type.equals(ELECTRONS_TYPE)) { - dm.setAttribute(pathRoot, "Screen", String.valueOf(valueScreen.getLabel().getText())); - dm.setAttribute(pathRoot, "Filter", String.valueOf(valueFilter.getLabel().getText())); - } - - //Save data - for (int index = 0; index < depth; index++) { - StreamValue streamValue = images.get(index); - dm.setItem(pathImage, streamValue.getValue("image"), new long[]{index, 0, 0}, new int[]{1, height, width}); - dm.setItem(pathPid, streamValue.getPulseId(), index); - dm.setItem(pathTimestampStr, Chrono.getTimeStr(streamValue.getTimestamp(), "YYYY-MM-dd HH:mm:ss.SSS"), index); - - for (String id : streamValue.getIdentifiers()) { - Object val = streamValue.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - } else if (val.getClass().isArray()) { - dm.setItem(pathRoot + id, val, index); - } else { - dm.setItem(pathRoot + id, val, index); - } - } - } - getContext().getDataManager().closeOutput(); - } - - StandardDialog calibrationDialolg; - - void calibrate() throws Exception { - if (server != null) { - server.resetRoi(); - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraCalibrationDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), server.getCurrentCamera(), renderer}); - SwingUtils.centerComponent(getTopLevel(), calibrationDialolg); - calibrationDialolg.setVisible(true); - calibrationDialolg.setListener(new StandardDialogListener() { - @Override - public void onWindowOpened(StandardDialog dlg) { - } - - @Override - public void onWindowClosed(StandardDialog dlg, boolean accepted) { - if (accepted) { - //comboCamerasActionPerformed(null); - } - } - }); - } - } - - StandardDialog dataTableDialog; - DefaultTableModel dataTableModel; - JTable dataTable; - - void showStreamData() { - dataTableModel = null; - if (server != null) { - - if ((dataTableDialog != null) && (dataTableDialog.isShowing())) { - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.requestFocus(); - return; - } - dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) { - public Class getColumnClass(int columnIndex) { - return String.class; - } - - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - }; - updateStreamData(); - StreamValue val = server.getStream().take(); - dataTable = new JTable(dataTableModel); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.setCellSelectionEnabled(true); - dataTable.getTableHeader().setReorderingAllowed(false); - dataTable.getTableHeader().setResizingAllowed(true); - dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); - dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(dataTable); - scrollPane.setPreferredSize(new Dimension(300, 400)); - dataTableDialog.setContentPane(scrollPane); - dataTableDialog.pack(); - dataTableDialog.setVisible(true); - dataTableDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - dataTableModel = null; - } - }); - dataTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - try { - int row = dataTable.getSelectedRow(); - int col = dataTable.getSelectedColumn(); - dataTable.setToolTipText(null); - if (row > 1) { - String id = String.valueOf(dataTable.getModel().getValueAt(row, 0)); - String locator = String.valueOf(dataTable.getModel().getValueAt(0, 1)); - String channelId = locator + " " + id; - dataTable.setToolTipText(channelId); - if ((e.getClickCount() == 2) && (!e.isPopupTrigger())) { - if (col == 0) { - SwingUtils.showMessage(dataTableDialog, "Channel Identifier", "Copied to clipboard: " + channelId); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - clipboard.setContents(new StringSelection(channelId), (Clipboard clipboard1, Transferable contents) -> { - }); - } else { - Object obj = getCurrentFrame().cache.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(getCurrentFrame().cache); - StringBuilder sb = new StringBuilder(); - for (String key : pars.keySet()) { - sb.append(key).append(" = ").append(Str.toString(pars.get(key), 10)).append("\n"); - } - SwingUtils.showMessage(dataTableDialog, "Processing Parameters", sb.toString()); - } else if ((obj != null) && (obj.getClass().isArray() || (obj instanceof Number))) { - DeviceValueChart chart = new DeviceValueChart(); - Device dev = null; - if (obj.getClass().isArray()) { - dev = new ReadableRegisterArray(new ReadableArray() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - - @Override - public int getSize() { - return Array.getLength(getCurrentFrame().cache.getValue(id)); - } - }); - } else { - dev = new ReadableRegisterNumber(new ReadableNumber() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - }); - } - dev.setPolling(1000); - chart.setDevice(dev); - JDialog dlg = SwingUtils.showDialog(dataTableDialog, cameraName + " " + id, null, chart); - //TODO: - //PlotBase plot = chart.getPlot(); - //if (plot!=null){ - // plot.setPlotBackgroundColor(Color.BLACK); - //} - } - } - } - } - } catch (Exception ex) { - showException(ex); - } - } - }); - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - updateStreamData(); - } - } - - volatile boolean updatingStreamData = false; - - void updateStreamData() { - if ((dataTableDialog == null) || !dataTableDialog.isShowing() || updatingStreamData) { - return; - } - updatingStreamData = true; - SwingUtilities.invokeLater(() -> { - updatingStreamData = false; - if ((dataTableModel != null) && (server != null)) { - StreamValue value = server.getValue(); - Frame frame = getCurrentFrame(); - int[] sel_rows = (dataTable == null) ? null : dataTable.getSelectedRows(); - int[] sel_cols = (dataTable == null) ? null : dataTable.getSelectedColumns(); - List ids = (value == null) ? new ArrayList<>() : new ArrayList(value.getIdentifiers()); - if (ids.size() + 4 != dataTableModel.getRowCount()) { - dataTableModel.setNumRows(0); - try { - dataTableModel.addRow(new Object[]{"Locator", server.getUrl() + "/" + ((value == null) ? instanceName : server.getCurrentInstance())}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Locator", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"Stream", server.getStreamAddress()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Stream", ex.getMessage()}); - } - dataTableModel.addRow(new Object[]{"PID", ""}); - dataTableModel.addRow(new Object[]{"Timestamp", ""}); - Collections.sort(ids); - for (String id : ids) { - dataTableModel.addRow(new Object[]{id, ""}); - } - } - - if ((frame != null) && (frame.cache != null)) { - dataTableModel.setValueAt(frame.cache.getPulseId(), 2, 1); //PID - dataTableModel.setValueAt(frame.cache.getTimestamp(), 3, 1); //Timestamp - for (int i = 4; i < dataTableModel.getRowCount(); i++) { - String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - //Object obj = server.getValue(id); - Object obj = frame.cache.getValue(id); - if (obj != null) { - if (obj.getClass().isArray()) { - obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; - } else if (obj instanceof Double) { - obj = Convert.roundDouble((Double) obj, 1); - } else if (obj instanceof Float) { - obj = Convert.roundDouble((Float) obj, 1); - } - } - dataTableModel.setValueAt(String.valueOf(obj), i, 1); - } - } - if ((sel_rows != null) && (sel_rows.length > 0)) { - //dataTable.setRowSelectionInterval((Integer)Arr.getMin(sel_rows), (Integer)Arr.getMax(sel_rows)); - dataTable.setRowSelectionInterval(sel_rows[0], sel_rows[sel_rows.length - 1]); - } - if ((sel_cols != null) && (sel_cols.length > 0)) { - //dataTable.setColumnSelectionInterval((Integer)Arr.getMin(sel_cols), (Integer)Arr.getMax(sel_cols)); - dataTable.setColumnSelectionInterval(sel_cols[0], sel_cols[sel_cols.length - 1]); - } - } - }); - } - - ImageIcon getIcon(String name) { - ImageIcon ret = null; - try { - //Path path = Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(),"resources", name + ".png"); - String dir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + "resources/"; - if (new File(dir + name + ".png").exists()) { - ret = new javax.swing.ImageIcon(dir + name + ".png"); - } else { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/" + name + ".png")); - if (MainFrame.isDark()) { - try { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/dark/" + name + ".png")); - } catch (Exception e) { - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return ret; - } - - String getIconName(JButton button) { - String ret = button.getIcon().toString(); - if (ret.indexOf(".") > 0) { - ret = ret.substring(0, ret.indexOf(".")); - } - return ret; - } - - void setPaused(boolean paused){ - removePauseOverlay(); - if (camera != null) { - synchronized (imageBuffer) { - if (paused) { - renderer.pause(); - panelCameraSelection.setVisible(false); - pauseSelection.setVisible(true); - if (imageBuffer.size() > 0) { - pauseSelection.setEnabled(true); - pauseSelection.setMaxValue(imageBuffer.size()); - pauseSelection.setValue(imageBuffer.size()); - updatePause(); - } else { - pauseSelection.setEnabled(false); - pauseSelection.setMaxValue(1); - pauseSelection.setValue(1); - } - } else { - imageBuffer.clear(); - renderer.resume(); - //renderer.clear(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - updateStreamData(); - } - } - - boolean isPaused(){ - return renderer.isPaused(); - } - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - buttonGroup4 = new javax.swing.ButtonGroup(); - jProgressBar1 = new javax.swing.JProgressBar(); - sidePanel = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - buttonZoomFit = new javax.swing.JRadioButton(); - buttonZoomStretch = new javax.swing.JRadioButton(); - buttonZoomNormal = new javax.swing.JRadioButton(); - buttonZoom025 = new javax.swing.JRadioButton(); - buttonZoom05 = new javax.swing.JRadioButton(); - buttonZoom2 = new javax.swing.JRadioButton(); - jPanel2 = new javax.swing.JPanel(); - checkHistogram = new javax.swing.JCheckBox(); - comboColormap = new javax.swing.JComboBox(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - buttonFullRange = new javax.swing.JRadioButton(); - buttonManual = new javax.swing.JRadioButton(); - buttonAutomatic = new javax.swing.JRadioButton(); - labelMin = new javax.swing.JLabel(); - spinnerMin = new javax.swing.JSpinner(); - spinnerMax = new javax.swing.JSpinner(); - labelMax = new javax.swing.JLabel(); - btFixColormapRange = new javax.swing.JButton(); - jPanel5 = new javax.swing.JPanel(); - buttonServer = new javax.swing.JRadioButton(); - buttonDirect = new javax.swing.JRadioButton(); - textState = new javax.swing.JTextField(); - filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767)); - panelScreen = new javax.swing.JPanel(); - valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); - comboScreen = new javax.swing.JComboBox(); - panelFilter = new javax.swing.JPanel(); - valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); - comboFilter = new javax.swing.JComboBox(); - panelScreen2 = new javax.swing.JPanel(); - checkThreshold = new javax.swing.JCheckBox(); - spinnerThreshold = new javax.swing.JSpinner(); - checkBackground = new javax.swing.JCheckBox(); - checkGoodRegion = new javax.swing.JCheckBox(); - spinnerGrScale = new javax.swing.JSpinner(); - spinnerGrThreshold = new javax.swing.JSpinner(); - labelGrThreshold = new javax.swing.JLabel(); - labelGrScale = new javax.swing.JLabel(); - panelSlicing = new javax.swing.JPanel(); - checkSlicing = new javax.swing.JCheckBox(); - labelSlScale = new javax.swing.JLabel(); - spinnerSlScale = new javax.swing.JSpinner(); - labelSlNumber = new javax.swing.JLabel(); - spinnerSlNumber = new javax.swing.JSpinner(); - labelSlOrientation = new javax.swing.JLabel(); - spinnerSlOrientation = new javax.swing.JSpinner(); - checkRotation = new javax.swing.JCheckBox(); - spinnerRotationAngle = new javax.swing.JSpinner(); - spinnerRotationOrder = new javax.swing.JSpinner(); - labelOrder = new javax.swing.JLabel(); - labelMode = new javax.swing.JLabel(); - spinnerRotationMode = new javax.swing.JSpinner(); - labelAngle = new javax.swing.JLabel(); - labelConstant = new javax.swing.JLabel(); - spinnerRotationConstant = new javax.swing.JSpinner(); - checkAveraging = new javax.swing.JCheckBox(); - spinnerAvFrames = new javax.swing.JSpinner(); - labelAvFrames = new javax.swing.JLabel(); - labelAvMode = new javax.swing.JLabel(); - spinnerAvMode = new javax.swing.JSpinner(); - topPanel = new javax.swing.JPanel(); - toolBar = new javax.swing.JToolBar(); - buttonSidePanel = new javax.swing.JToggleButton(); - buttonStreamData = new javax.swing.JButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - buttonPause = new javax.swing.JToggleButton(); - jSeparator6 = new javax.swing.JToolBar.Separator(); - buttonMarker = new javax.swing.JToggleButton(); - buttonProfile = new javax.swing.JToggleButton(); - buttonFit = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonScale = new javax.swing.JToggleButton(); - buttonTitle = new javax.swing.JToggleButton(); - pauseSelection = new ch.psi.pshell.swing.ValueSelection(); - panelCameraSelection = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - jLabel5 = new javax.swing.JLabel(); - comboType = new javax.swing.JComboBox(); - renderer = new ch.psi.pshell.imaging.Renderer(); - - setPreferredSize(new java.awt.Dimension(873, 600)); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); - - buttonGroup1.add(buttonZoomFit); - buttonZoomFit.setText("Fit"); - buttonZoomFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomFitActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomStretch); - buttonZoomStretch.setText("Stretch"); - buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomStretchActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomNormal); - buttonZoomNormal.setText("Normal"); - buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomNormalActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("1/4"); - buttonZoom025.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom025ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("1/2"); - buttonZoom05.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom05ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom2); - buttonZoom2.setText("2"); - buttonZoom2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoomStretch)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05) - .addComponent(buttonZoom2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomFit) - .addComponent(buttonZoom05)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoom2)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap")); - - checkHistogram.setText("Histogram"); - checkHistogram.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkHistogramActionPerformed(evt); - } - }); - - comboColormap.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Type:"); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Range:"); - - buttonGroup3.add(buttonFullRange); - buttonFullRange.setText("Full"); - buttonFullRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonManual); - buttonManual.setText("Manual"); - buttonManual.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonAutomatic); - buttonAutomatic.setText("Automatic"); - buttonAutomatic.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - labelMin.setText("Min:"); - - spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); - spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); - spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - labelMax.setText("Max:"); - - btFixColormapRange.setText("Fix"); - btFixColormapRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btFixColormapRangeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonAutomatic) - .addComponent(buttonFullRange) - .addComponent(buttonManual) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMax) - .addGap(2, 2, 2) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMin) - .addGap(2, 2, 2) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(spinnerMin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFixColormapRange, spinnerMax, spinnerMin}); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3) - .addComponent(checkHistogram)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAutomatic) - .addComponent(jLabel4) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelMin) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonFullRange)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonManual) - .addComponent(labelMax) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - - buttonGroup4.add(buttonServer); - buttonServer.setSelected(true); - buttonServer.setText("Server"); - buttonServer.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonServerActionPerformed(evt); - } - }); - - buttonGroup4.add(buttonDirect); - buttonDirect.setText("Direct"); - buttonDirect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDirectActionPerformed(evt); - } - }); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonServer) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonDirect) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(56, 56, 56)) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonServer) - .addComponent(buttonDirect))) - .addContainerGap()) - ); - - panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); - - comboScreen.setEnabled(false); - comboScreen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboScreenActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); - panelScreen.setLayout(panelScreenLayout); - panelScreenLayout.setHorizontalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreenLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreenLayout.setVerticalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelFilter.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); - - comboFilter.setEnabled(false); - comboFilter.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboFilterActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelFilterLayout = new javax.swing.GroupLayout(panelFilter); - panelFilter.setLayout(panelFilterLayout); - panelFilterLayout.setHorizontalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelFilterLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelFilterLayout.setVerticalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFilterLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - panelScreen2.setBorder(javax.swing.BorderFactory.createTitledBorder("Pipeline")); - - checkThreshold.setText("Threshold"); - checkThreshold.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkThresholdActionPerformed(evt); - } - }); - - spinnerThreshold.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 99999.0d, 1.0d)); - spinnerThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerThresholdonChange(evt); - } - }); - - checkBackground.setText("Subtract Background"); - checkBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkBackgroundActionPerformed(evt); - } - }); - - checkGoodRegion.setText("Good Region"); - checkGoodRegion.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkGoodRegionActionPerformed(evt); - } - }); - - spinnerGrScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerGrScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - spinnerGrThreshold.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.04d, 1.0d, 0.1d)); - spinnerGrThreshold.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerGrThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - labelGrThreshold.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelGrThreshold.setText("Threshold:"); - - labelGrScale.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelGrScale.setText("Scale:"); - - checkSlicing.setText("Slicing"); - checkSlicing.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkSlicingActionPerformed(evt); - } - }); - - labelSlScale.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelSlScale.setText("Scale:"); - - spinnerSlScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerSlScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlNumber.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelSlNumber.setText("Slices:"); - - spinnerSlNumber.setModel(new javax.swing.SpinnerNumberModel(2, 0, 1000, 1)); - spinnerSlNumber.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlNumber.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlOrientation.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelSlOrientation.setText("Orientation:"); - - spinnerSlOrientation.setModel(new javax.swing.SpinnerListModel(new String[] {"vertical", "horizontal"})); - spinnerSlOrientation.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlOrientation.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - javax.swing.GroupLayout panelSlicingLayout = new javax.swing.GroupLayout(panelSlicing); - panelSlicing.setLayout(panelSlicingLayout); - panelSlicingLayout.setHorizontalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addComponent(checkSlicing) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlNumber) - .addGap(2, 2, 2) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlScale) - .addGap(2, 2, 2) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelSlOrientation) - .addGap(2, 2, 2) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - panelSlicingLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerSlNumber, spinnerSlOrientation, spinnerSlScale}); - - panelSlicingLayout.setVerticalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(checkSlicing) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlNumber)) - .addGap(0, 0, 0) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlScale)))) - .addGap(0, 0, 0) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlOrientation))) - ); - - panelSlicingLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {spinnerSlNumber, spinnerSlOrientation, spinnerSlScale}); - - checkRotation.setText("Rotation"); - checkRotation.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkRotationActionPerformed(evt); - } - }); - - spinnerRotationAngle.setModel(new javax.swing.SpinnerNumberModel(0.0d, -360.0d, 360.0d, 1.0d)); - spinnerRotationAngle.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerRotationAngleStateChanged(evt); - } - }); - - spinnerRotationOrder.setModel(new javax.swing.SpinnerNumberModel(1, 1, 5, 1)); - spinnerRotationOrder.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerRotationAngleStateChanged(evt); - } - }); - - labelOrder.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelOrder.setText("Order:"); - - labelMode.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelMode.setText("Mode:"); - - spinnerRotationMode.setModel(new javax.swing.SpinnerListModel(new String[] {"constant", "reflect", "nearest", "mirror", "wrap"})); - spinnerRotationMode.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerRotationAngleStateChanged(evt); - } - }); - - labelAngle.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelAngle.setText("Angle:"); - - labelConstant.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelConstant.setText("Constant:"); - - spinnerRotationConstant.setModel(new javax.swing.SpinnerNumberModel(0, 0, 99999, 1)); - spinnerRotationConstant.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerRotationAngleStateChanged(evt); - } - }); - - checkAveraging.setText("Averaging"); - checkAveraging.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkAveragingActionPerformed(evt); - } - }); - - spinnerAvFrames.setModel(new javax.swing.SpinnerNumberModel(1, 1, 1000, 1)); - spinnerAvFrames.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerAvFramesStateChanged(evt); - } - }); - - labelAvFrames.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelAvFrames.setText("Frames:"); - - labelAvMode.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelAvMode.setText("Mode:"); - - spinnerAvMode.setModel(new javax.swing.SpinnerListModel(new String[] {"single", "window"})); - spinnerAvMode.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerAvModeonChange(evt); - } - }); - - javax.swing.GroupLayout panelScreen2Layout = new javax.swing.GroupLayout(panelScreen2); - panelScreen2.setLayout(panelScreen2Layout); - panelScreen2Layout.setHorizontalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(checkAveraging) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(labelAvFrames, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(labelAvMode, javax.swing.GroupLayout.Alignment.TRAILING))) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(checkGoodRegion) - .addComponent(checkRotation) - .addComponent(checkThreshold)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(labelOrder, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(labelAngle, javax.swing.GroupLayout.Alignment.TRAILING)) - .addComponent(labelGrScale, javax.swing.GroupLayout.Alignment.TRAILING))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(labelConstant, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(labelMode, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(labelGrThreshold, javax.swing.GroupLayout.Alignment.TRAILING)))) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(spinnerGrScale) - .addComponent(spinnerThreshold) - .addComponent(spinnerRotationOrder) - .addComponent(spinnerRotationMode) - .addComponent(spinnerRotationAngle) - .addComponent(spinnerRotationConstant) - .addComponent(spinnerAvFrames) - .addComponent(spinnerAvMode)) - .addContainerGap()) - .addComponent(panelSlicing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(checkBackground) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerAvFrames, spinnerAvMode, spinnerGrScale, spinnerGrThreshold, spinnerRotationAngle, spinnerRotationConstant, spinnerRotationMode, spinnerRotationOrder, spinnerThreshold}); - - panelScreen2Layout.setVerticalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(checkBackground) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkThreshold) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkAveraging) - .addComponent(spinnerAvFrames, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelAvFrames)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerAvMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelAvMode)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkRotation) - .addComponent(spinnerRotationAngle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelAngle)) - .addGap(0, 0, 0) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerRotationOrder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelOrder)) - .addGap(0, 0, 0) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerRotationMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelMode)) - .addGap(0, 0, 0) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerRotationConstant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelConstant)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkGoodRegion) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrScale)) - .addGap(0, 0, 0) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrThreshold)) - .addGap(2, 2, 2) - .addComponent(panelSlicing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerRotationAngle, spinnerRotationConstant, spinnerRotationMode, spinnerRotationOrder, spinnerThreshold}); - - javax.swing.GroupLayout sidePanelLayout = new javax.swing.GroupLayout(sidePanel); - sidePanel.setLayout(sidePanelLayout); - sidePanelLayout.setHorizontalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - sidePanelLayout.setVerticalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - toolBar.setFloatable(false); - toolBar.setRollover(true); - - buttonSidePanel.setIcon(getIcon("List")); - buttonSidePanel.setSelected(true); - buttonSidePanel.setText(" "); - buttonSidePanel.setToolTipText("Show Side Panel"); - buttonSidePanel.setFocusable(false); - buttonSidePanel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSidePanel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSidePanelActionPerformed(evt); - } - }); - toolBar.add(buttonSidePanel); - - buttonStreamData.setIcon(getIcon("Details")); - buttonStreamData.setText(" "); - buttonStreamData.setToolTipText("Show Data Window"); - buttonStreamData.setFocusable(false); - buttonStreamData.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonStreamData.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStreamDataActionPerformed(evt); - } - }); - toolBar.add(buttonStreamData); - - buttonSave.setIcon(getIcon("Save")); - buttonSave.setText(" "); - buttonSave.setToolTipText("Save Snapshot"); - buttonSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - toolBar.add(buttonSave); - - buttonGrabBackground.setIcon(getIcon("Background")); - buttonGrabBackground.setText(" "); - buttonGrabBackground.setToolTipText("Grab Background"); - buttonGrabBackground.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - toolBar.add(buttonGrabBackground); - - buttonPause.setIcon(getIcon("Pause")); - buttonPause.setText(" "); - buttonPause.setToolTipText("Pause"); - buttonPause.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - toolBar.add(buttonPause); - - jSeparator6.setMaximumSize(new java.awt.Dimension(20, 32767)); - jSeparator6.setPreferredSize(new java.awt.Dimension(20, 0)); - jSeparator6.setRequestFocusEnabled(false); - toolBar.add(jSeparator6); - - buttonMarker.setIcon(getIcon("Marker")); - buttonMarker.setText(" "); - buttonMarker.setToolTipText("Show Marker"); - buttonMarker.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - toolBar.add(buttonMarker); - - buttonProfile.setIcon(getIcon("Profile" - + "")); - buttonProfile.setSelected(true); - buttonProfile.setText(" "); - buttonProfile.setToolTipText("Show Image Profile"); - buttonProfile.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonProfile.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonProfileActionPerformed(evt); - } - }); - toolBar.add(buttonProfile); - - buttonFit.setIcon(getIcon("Fit")); - buttonFit.setSelected(true); - buttonFit.setText(" "); - buttonFit.setToolTipText("Show Fit"); - buttonFit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - toolBar.add(buttonFit); - - buttonReticle.setIcon(getIcon("Reticule")); - buttonReticle.setSelected(true); - buttonReticle.setText(" "); - buttonReticle.setToolTipText("Show Reticle"); - buttonReticle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - toolBar.add(buttonReticle); - - buttonScale.setIcon(getIcon("Scale")); - buttonScale.setSelected(true); - buttonScale.setText(" "); - buttonScale.setToolTipText("Show Colormap Scale"); - buttonScale.setFocusable(false); - buttonScale.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonScale.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonScaleActionPerformed(evt); - } - }); - toolBar.add(buttonScale); - - buttonTitle.setIcon(getIcon("Title")); - buttonTitle.setSelected(true); - buttonTitle.setText(" "); - buttonTitle.setToolTipText("Show Camera Name"); - buttonTitle.setFocusable(false); - buttonTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonTitle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonTitleActionPerformed(evt); - } - }); - toolBar.add(buttonTitle); - - pauseSelection.setDecimals(0); - - jLabel1.setText("Camera:"); - - comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboCameras.setMaximumRowCount(30); - comboCameras.setMinimumSize(new java.awt.Dimension(127, 27)); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - jLabel5.setText("Type:"); - - comboType.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboType.setMaximumRowCount(30); - comboType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Laser", "Electrons", "Photonics" })); - comboType.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboTypeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelCameraSelectionLayout = new javax.swing.GroupLayout(panelCameraSelection); - panelCameraSelection.setLayout(panelCameraSelectionLayout); - panelCameraSelectionLayout.setHorizontalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addGap(0, 0, 0) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - panelCameraSelectionLayout.setVerticalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel5) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0)) - ); - - javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel); - topPanel.setLayout(topPanelLayout); - topPanelLayout.setHorizontalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup() - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - topPanelLayout.setVerticalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(topPanelLayout.createSequentialGroup() - .addGap(1, 1, 1) - .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(sidePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(topPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(sidePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - }// //GEN-END:initComponents - - private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed - try { - renderer.setMode(RendererMode.Fit); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomFitActionPerformed - - private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed - try { - renderer.setMode(RendererMode.Stretch); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomStretchActionPerformed - - private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed - try { - renderer.setMode(RendererMode.Fixed); - centralizeRenderer(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomNormalActionPerformed - - private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap - try { - if ((camera != null) && (camera instanceof ColormapSource) && !updatingColormap) { - ColormapSource source = (ColormapSource) camera; - Color colorReticule = new Color(16, 16, 16); - Color colorMarker = new Color(128, 128, 128); - Colormap colormap = (Colormap) comboColormap.getSelectedItem(); - source.getConfig().colormap = (colormap == null) ? Colormap.Flame : colormap; - switch (source.getConfig().colormap) { - case Grayscale: - case Inverted: - case Red: - case Green: - case Blue: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - case Flame: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - } - - renderer.setPenReticle(new Pen(colorReticule)); - renderer.setPenProfile(new Pen(colorReticule, 0)); - renderer.setPenMarker(new Pen(colorMarker, 2)); - renderer.setShowReticle(false); - checkReticle(); - source.getConfig().colormapAutomatic = buttonAutomatic.isSelected(); - source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); - source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); - try { - source.getConfig().save(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - } - source.refresh(); - if (buttonPause.isSelected()) { - updatePause(); - } - updateColormap(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_onChangeColormap - - private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange - onChangeColormap(null); - }//GEN-LAST:event_onChangeColormapRange - - private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed - renderer.setZoom(0.25); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom025ActionPerformed - - private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed - renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom05ActionPerformed - - private void buttonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonServerActionPerformed - if (!usingServer) { - usingServer = true; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonServerActionPerformed - - private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingServer) { - usingServer = false; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonDirectActionPerformed - - private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed - - comboScreen.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - ChannelInteger setpoint = null; - try { - int index = comboScreen.getSelectedIndex(); - if (index >= 0) { - if (cameraName.contains("DSRM")) { - setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); - } else { - setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); - } - setpoint.initialize(); - Integer readback = setpoint.read(); - if ((readback == null) || (setpoint.read() != index)) { - setpoint.write(index); - //Must be threaded to control the laser because of sleep in setLaserState - /* - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - setpoint.write(index); - } finally { - if (laserOn) { - setLaserState(true); - } - } - */ - } - screen.read(); - } - } catch (Exception ex) { - showException(ex); - } finally { - comboScreen.setEnabled(true); - if (setpoint != null) { - setpoint.close(); - } - } - } - }).start(); - }//GEN-LAST:event_comboScreenActionPerformed - - private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed - try { - String setpoint = (String) comboFilter.getSelectedItem(); - if (setpoint != null) { - if (!setpoint.equals(filter.read())) { - filter.write(setpoint); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboFilterActionPerformed - - private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed - try { - setHistogramVisible(checkHistogram.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_checkHistogramActionPerformed - - private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed - renderer.setZoom(2.0); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom2ActionPerformed - - private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setThreshold((Double) spinnerThreshold.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerThresholdonChange - - private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (server != null) { - if (!updatingServerControls) { - try { - if (server.isStarted()) { - server.setBackgroundSubtraction(checkBackground.isSelected()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - updatingServerControls = true; - checkBackground.setSelected(false); - updatingServerControls = false; - - } - } - } else { - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - }//GEN-LAST:event_checkBackgroundActionPerformed - - private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - spinnerThreshold.setVisible(checkThreshold.isSelected()); - server.setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkThresholdActionPerformed - - private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - goodRegion = checkGoodRegion.isSelected(); - setGoodRegionOptionsVisible(goodRegion); - if (goodRegion) { - server.setGoodRegion(((Number) spinnerGrThreshold.getValue()).doubleValue(), ((Number) spinnerGrScale.getValue()).doubleValue()); - } else { - server.setGoodRegion(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkGoodRegionActionPerformed - - private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setGoodRegion((Double) spinnerGrThreshold.getValue(), (Double) spinnerGrScale.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerGrThresholdonChange - - private void btFixColormapRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFixColormapRangeActionPerformed - try { - updatingColormap = true; - ArrayProperties properties = currentFrame.data.getProperties(); - spinnerMax.setValue(properties.max.intValue()); - spinnerMin.setValue(properties.min.intValue()); - buttonManual.setSelected(true); - } catch (Exception ex) { - showException(ex); - } finally { - updatingColormap = false; - onChangeColormap(null); - } - }//GEN-LAST:event_btFixColormapRangeActionPerformed - - private void checkSlicingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSlicingActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - slicing = checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - if (slicing) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } else { - server.setSlicing(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkSlicingActionPerformed - - private void spinnerSlicingChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerSlicingChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerSlicingChange - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - showFit = buttonFit.isSelected(); - if (showFit) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed - try { - showProfile = buttonProfile.isSelected(); - if (showProfile) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(profileOv); - profileOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonProfileActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - checkMarker(null); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - if (!updatingButtons) { - setPaused(buttonPause.isSelected()); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera != null) { - boolean laserOn1 = getLaserState(1); - boolean laserOn2 = getLaserState(2); - OptionResult ret = null; - if (laserOn1 || laserOn2) { - if (laserOn1){ - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put Bunch 1 laser on delay for capturing background?", OptionType.YesNoCancel); - if (ret == OptionResult.No) { - laserOn1 = false; - } - if (ret == OptionResult.Cancel) { - return; - } - } - if (laserOn2){ - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put Bunch 2 laser on delay for capturing background?", OptionType.YesNoCancel); - if (ret == OptionResult.No) { - laserOn2= false; - } - if (ret == OptionResult.Cancel) { - return; - } - } - } else { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to capture background now?", OptionType.OkCancel); - } - - if (ret == OptionResult.Cancel) { - return; - } - - if (laserOn1) { - setLaserState(1,false); - } - if (laserOn2) { - setLaserState(2,false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - if (server != null) { - server.captureBackground(5); - } else { - camera.captureBackground(5, 0); - } - } finally { - if (laserOn1) { - setLaserState(1,true); - } - if (laserOn2) { - setLaserState(2,true); - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - saveSnapshot(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonStreamDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStreamDataActionPerformed - try { - showStreamData(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonStreamDataActionPerformed - - private void buttonSidePanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSidePanelActionPerformed - sidePanel.setVisible(buttonSidePanel.isSelected()); - }//GEN-LAST:event_buttonSidePanelActionPerformed - - private void comboTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTypeActionPerformed - try { - if (!updatingCameraSelection) { - updateCameraList(); - if ((cameraName != null) && (!cameraName.equals(comboCameras.getSelectedItem()))) { - setCamera(null); - } else { - setCamera(cameraName); - } - } - - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - }//GEN-LAST:event_comboTypeActionPerformed - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - if (!updatingCameraSelection) { - if (!comboCameras.isEnabled()) { - throw new Exception("Invalid state"); - } - comboCameras.setEnabled(false); - comboType.setEnabled(false); - buttonServer.setEnabled(false); - buttonDirect.setEnabled(false); - final String cameraName = (String) comboCameras.getSelectedItem(); - new Thread(new Runnable() { - @Override - public void run() { - if (requestCameraListUpdate) { - requestCameraListUpdate = false; - try { - updateCameraList(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - try { - setCamera(cameraName.trim().isEmpty() ? null : cameraName); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - buttonServer.setEnabled(true); - buttonDirect.setEnabled(true); - } - } - }).start(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTitleActionPerformed - try { - manageTitleOverlay(); - } catch (Exception ex) { - showException(ex); - } finally { - } - }//GEN-LAST:event_buttonTitleActionPerformed - - private void buttonScaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScaleActionPerformed - try { - renderer.setShowColormapScale(buttonScale.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonScaleActionPerformed - - private void checkRotationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkRotationActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - boolean rotation = checkRotation.isSelected(); - setRotationOptionsVisible(rotation); - if (rotation) { - spinnerRotationAngleStateChanged(null); - } else { - server.setRotation(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkRotationActionPerformed - - private void spinnerRotationAngleStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerRotationAngleStateChanged - try { - String mode = String.valueOf(spinnerRotationMode.getValue()); - server.setRotation(((Number) spinnerRotationAngle.getValue()).doubleValue(), - ((Number) spinnerRotationOrder.getValue()).intValue(), - mode.equals("constant") ? String.valueOf(spinnerRotationConstant.getValue()): mode); - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - }//GEN-LAST:event_spinnerRotationAngleStateChanged - - private void checkAveragingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkAveragingActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - setAveragingOptionsVisible(checkAveraging.isSelected()); - Integer av = spinnerAvMode.getValue().equals("window") ? - (Integer)spinnerAvFrames.getValue() : (Integer)spinnerAvFrames.getValue(); - setInstanceConfigValue("averaging", checkAveraging.isSelected() ? av : null); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkAveragingActionPerformed - - private void spinnerAvModeonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerAvModeonChange - checkAveragingActionPerformed(null); - }//GEN-LAST:event_spinnerAvModeonChange - - private void spinnerAvFramesStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerAvFramesStateChanged - checkAveragingActionPerformed(null); - }//GEN-LAST:event_spinnerAvFramesStateChanged - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btFixColormapRange; - private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonDirect; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JRadioButton buttonFullRange; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JRadioButton buttonManual; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonProfile; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JToggleButton buttonScale; - private javax.swing.JRadioButton buttonServer; - private javax.swing.JToggleButton buttonSidePanel; - private javax.swing.JButton buttonStreamData; - private javax.swing.JToggleButton buttonTitle; - private javax.swing.JRadioButton buttonZoom025; - private javax.swing.JRadioButton buttonZoom05; - private javax.swing.JRadioButton buttonZoom2; - private javax.swing.JRadioButton buttonZoomFit; - private javax.swing.JRadioButton buttonZoomNormal; - private javax.swing.JRadioButton buttonZoomStretch; - private javax.swing.JCheckBox checkAveraging; - private javax.swing.JCheckBox checkBackground; - private javax.swing.JCheckBox checkGoodRegion; - private javax.swing.JCheckBox checkHistogram; - private javax.swing.JCheckBox checkRotation; - private javax.swing.JCheckBox checkSlicing; - private javax.swing.JCheckBox checkThreshold; - private javax.swing.JComboBox comboCameras; - private javax.swing.JComboBox comboColormap; - private javax.swing.JComboBox comboFilter; - private javax.swing.JComboBox comboScreen; - private javax.swing.JComboBox comboType; - private javax.swing.Box.Filler filler1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel5; - private javax.swing.JProgressBar jProgressBar1; - private javax.swing.JToolBar.Separator jSeparator6; - private javax.swing.JLabel labelAngle; - private javax.swing.JLabel labelAvFrames; - private javax.swing.JLabel labelAvMode; - private javax.swing.JLabel labelConstant; - private javax.swing.JLabel labelGrScale; - private javax.swing.JLabel labelGrThreshold; - private javax.swing.JLabel labelMax; - private javax.swing.JLabel labelMin; - private javax.swing.JLabel labelMode; - private javax.swing.JLabel labelOrder; - private javax.swing.JLabel labelSlNumber; - private javax.swing.JLabel labelSlOrientation; - private javax.swing.JLabel labelSlScale; - private javax.swing.JPanel panelCameraSelection; - private javax.swing.JPanel panelFilter; - private javax.swing.JPanel panelScreen; - private javax.swing.JPanel panelScreen2; - private javax.swing.JPanel panelSlicing; - private ch.psi.pshell.swing.ValueSelection pauseSelection; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JPanel sidePanel; - private javax.swing.JSpinner spinnerAvFrames; - private javax.swing.JSpinner spinnerAvMode; - private javax.swing.JSpinner spinnerGrScale; - private javax.swing.JSpinner spinnerGrThreshold; - private javax.swing.JSpinner spinnerMax; - private javax.swing.JSpinner spinnerMin; - private javax.swing.JSpinner spinnerRotationAngle; - private javax.swing.JSpinner spinnerRotationConstant; - private javax.swing.JSpinner spinnerRotationMode; - private javax.swing.JSpinner spinnerRotationOrder; - private javax.swing.JSpinner spinnerSlNumber; - private javax.swing.JSpinner spinnerSlOrientation; - private javax.swing.JSpinner spinnerSlScale; - private javax.swing.JSpinner spinnerThreshold; - private javax.swing.JTextField textState; - private javax.swing.JToolBar toolBar; - private javax.swing.JPanel topPanel; - private ch.psi.pshell.swing.DeviceValuePanel valueFilter; - private ch.psi.pshell.swing.DeviceValuePanel valueScreen; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/ScreenPanelBack.form b/plugins/ScreenPanelBack.form deleted file mode 100755 index 4584b9c..0000000 --- a/plugins/ScreenPanelBack.form +++ /dev/null @@ -1,1180 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/ScreenPanelBack.java b/plugins/ScreenPanelBack.java deleted file mode 100755 index c8cc5a8..0000000 --- a/plugins/ScreenPanelBack.java +++ /dev/null @@ -1,4218 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.bs.CameraServer; -import ch.psi.pshell.core.Context; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.PipelineServer; -import ch.psi.pshell.bs.StreamValue; -import ch.psi.pshell.core.JsonSerializer; -import ch.psi.pshell.data.DataManager; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.device.Readable.ReadableArray; -import ch.psi.pshell.device.Readable.ReadableNumber; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterArray; -import ch.psi.pshell.device.ReadableRegister.ReadableRegisterNumber; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.DiscretePositioner; -import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.imaging.Colormap; -import ch.psi.pshell.imaging.ColormapSource; -import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.DimensionDouble; -import ch.psi.pshell.imaging.Histogram; -import ch.psi.pshell.imaging.ImageBuffer; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.PointDouble; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.pshell.swing.DeviceValueChart; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import ch.psi.pshell.ui.Console; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Config; -import ch.psi.utils.Convert; -import ch.psi.utils.Str; -import ch.psi.utils.swing.Editor.EditorDialog; -import ch.psi.utils.swing.MainFrame; -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.StandardDialog.StandardDialogListener; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.lang.reflect.Array; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.table.DefaultTableModel; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.PolynomialCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; - -/** - * - */ -public class ScreenPanelBack extends Panel { - - public static final String LASER_TYPE = "Laser"; - public static final String ELECTRONS_TYPE = "Electrons"; - public static final String PHOTONICS_TYPE = "Photonics"; - - final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useServerStats = true; - String userOverlaysConfigFile; - ColormapSource camera; - PipelineServer server; - String cameraName; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - boolean showProfile; - Overlay[] userOv; - Overlay[] fitOv; - Overlay[] profileOv; - Overlay errorOverlay; - boolean requestCameraListUpdate; - boolean goodRegion; - boolean slicing; - String serverUrl; - String camServerUrl; - String instanceName; - Overlay titleOv = null; - int integration = 0; - boolean persistCameraState; - - public class CameraState extends Config { - - public boolean valid; - public boolean showSidePanel; - //public boolean showMarker; Saved in the stream instance config - public boolean showProfile; - public boolean showFit; - public boolean showReticle; - public boolean showScale; - public boolean showTitle; - public double zoom; - public RendererMode mode; - public boolean colormapAutomatic; - public double colormapMin; - public double colormapMax; - public Colormap colormap; - public boolean colormapLogarithmic; - - String getFile() { - if (camera == null) { - return null; - } - return getContext().getSetup().expandPath("{context}/screen_panel/" + cameraName + ".properties"); - } - } - - void loadCameraState() { - if (persistCameraState) { - try { - CameraState state = new CameraState(); - state.load(state.getFile()); - if (state.valid) { - buttonSidePanel.setSelected(state.showSidePanel); - buttonSidePanelActionPerformed(null); - buttonProfile.setSelected(state.showProfile); - buttonProfileActionPerformed(null); - buttonFit.setSelected(state.showFit); - buttonFitActionPerformed(null); - buttonReticle.setSelected(state.showReticle); - buttonReticleActionPerformed(null); - buttonScale.setSelected(state.showScale); - buttonScaleActionPerformed(null); - buttonTitle.setSelected(state.showTitle); - buttonTitleActionPerformed(null); - renderer.setMode(state.mode); - renderer.setZoom(state.zoom); - if (camera instanceof ColormapSource) { - camera.getConfig().colormap = state.colormap; - camera.getConfig().colormapAutomatic = state.colormapAutomatic; - camera.getConfig().colormapLogarithmic = state.colormapLogarithmic; - camera.getConfig().colormapMax = state.colormapMax; - camera.getConfig().colormapMin = state.colormapMin; - updateColormap(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - void saveCameraState() { - if (persistCameraState) { - try { - CameraState state = new CameraState(); - state.valid = true; - if (camera instanceof ColormapSource) { - state.colormap = camera.getConfig().colormap; - state.colormapAutomatic = camera.getConfig().colormapAutomatic; - state.colormapLogarithmic = camera.getConfig().colormapLogarithmic; - state.colormapMax = camera.getConfig().colormapMax; - state.colormapMin = camera.getConfig().colormapMin; - } - state.mode = renderer.getMode(); - state.zoom = renderer.getZoom(); - - state.showSidePanel = buttonSidePanel.isSelected(); - state.showProfile = buttonProfile.isSelected(); - state.showFit = buttonFit.isSelected(); - state.showReticle = buttonReticle.isSelected(); - state.showScale = buttonScale.isSelected(); - state.showTitle = buttonTitle.isSelected(); - - state.save(state.getFile()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - String pipelineSuffix = "_sp"; - - Double getServerDouble(String name) { - return (Double) Convert.toDouble(server.getValue(name)); - } - - double[] getServerDoubleArray(String name) { - return (double[]) Convert.toDouble(server.getValue(name)); - } - - Double getServerDouble(String name, StreamValue cache) { - return (Double) Convert.toDouble(cache.__getitem__(name)); - } - - double[] getServerDoubleArray(String name, StreamValue cache) { - return (double[]) Convert.toDouble(cache.__getitem__(name)); - } - - class ImageData { - - ImageData() { - if (server != null) { - cache = server.getStream().take(); - String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getServerDouble(prefix + "x_fit_mean", cache); - y_fit_mean = getServerDouble(prefix + "y_fit_mean", cache); - x_fit_standard_deviation = getServerDouble(prefix + "x_fit_standard_deviation", cache); - y_fit_standard_deviation = getServerDouble(prefix + "y_fit_standard_deviation", cache); - x_fit_gauss_function = getServerDoubleArray(prefix + "x_fit_gauss_function", cache); - y_fit_gauss_function = getServerDoubleArray(prefix + "y_fit_gauss_function", cache); - x_profile = getServerDoubleArray("x_profile", cache); - y_profile = getServerDoubleArray("y_profile", cache); - x_center_of_mass = getServerDouble("x_center_of_mass", cache); - y_center_of_mass = getServerDouble("y_center_of_mass", cache); - x_rms = getServerDouble("x_rms", cache); - y_rms = getServerDouble("y_rms", cache); - if (goodRegion) { - double[] gX2 = new double[x_profile.length]; - Arrays.fill(gX2, Double.NaN); - try { - double x = getServerDoubleArray("gr_x_axis", cache)[0]; - gr_size_x = x_fit_gauss_function.length; - gr_pos_x = (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x) : x); - System.arraycopy(x_fit_gauss_function, 0, gX2, gr_pos_x, gr_size_x); - } catch (Exception ex) { - } - x_fit_gauss_function = gX2; - double[] gY2 = new double[y_profile.length]; - Arrays.fill(gY2, Double.NaN); - try { - double y = getServerDoubleArray("gr_y_axis", cache)[0]; - gr_size_y = y_fit_gauss_function.length; - gr_pos_y = (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageY(y) : y); - System.arraycopy(y_fit_gauss_function, 0, gY2, gr_pos_y, y_fit_gauss_function.length); - } catch (Exception ex) { - } - y_fit_gauss_function = gY2; - if (slicing) { - try { - int slices = getServerDouble("slice_amount").intValue(); - sliceCenters = new PointDouble[slices]; - for (int i = 0; i < slices; i++) { - double x = getServerDouble("slice_" + i + "_center_x"); - double y = getServerDouble("slice_" + i + "_center_y"); - sliceCenters[i] = new PointDouble(x, y); - } - } catch (Exception ex) { - } - } - } - } - } - public Double x_fit_mean; - public Double y_fit_mean; - public Double x_center_of_mass; - public Double x_rms; - public Double x_fit_standard_deviation; - public Double y_fit_standard_deviation; - public Double y_center_of_mass; - public Double y_rms; - public double[] x_profile; - public double[] x_fit_gauss_function; - public double[] y_profile; - public double[] y_fit_gauss_function; - public int gr_size_x; - public int gr_pos_x; - public int gr_size_y; - public int gr_pos_y; - public PointDouble[] sliceCenters; - public StreamValue cache; - } - - class Frame extends ImageData { - - Frame(Data data) { - this.data = data; - } - Data data; - } - - final ArrayList imageBuffer = new ArrayList(); - Frame currentFrame; - int imageBufferLenght = 1; - Text imagePauseOverlay; - final Console console; - - public ScreenPanelBack() { - try { - initComponents(); - spinnerThreshold.setVisible(false); - btFixColormapRange.setVisible(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - JComponent editor = spinnerSlOrientation.getEditor(); - if (editor instanceof JSpinner.DefaultEditor) { - ((JSpinner.DefaultEditor) editor).getTextField().setHorizontalAlignment(JTextField.RIGHT); - } - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - //setPersistedComponents(new Component[]{buttonServer, buttonDirect}); - setPersistedComponents(new Component[]{buttonTitle}); - comboCameras.setEnabled(false); - comboType.setEnabled(false); - - SwingUtils.setEnumCombo(comboColormap, Colormap.class); - if (App.hasArgument("poll")) { - try { - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try { - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("buf")) { - try { - imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("usr_ov")) { - try { - userOverlaysConfigFile = App.getArgumentValue("usr_ov"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_url")) { - serverUrl = App.getArgumentValue("srv_url"); - } - - if (App.hasArgument("cam_srv_url")) { - camServerUrl = App.getArgumentValue("cam_srv_url"); - } - - if (App.hasArgument("calc")) { - useServerStats = false; - } - - if (App.hasArgument("persist")) { - persistCameraState = true; - } - - if (App.hasArgument("suffix")) { - pipelineSuffix = App.getArgumentValue("suffix"); - } - if (App.hasArgument("integration")) { - try { - setIntegration(Integer.valueOf(App.getArgumentValue("integration"))); - if (integration != 0) { - buttonFit.setSelected(false); - buttonProfile.setSelected(false); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - renderer.setProfileNormalized(true); - renderer.setShowProfileLimits(false); - - JMenuItem menuCalibrate = new JMenuItem("Calibrate..."); - menuCalibrate.addActionListener((ActionEvent e) -> { - try { - calibrate(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuRendererConfig = new JMenuItem("Renderer Parameters"); - menuRendererConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuCameraConfig = new JMenuItem("Camera Configurarion"); - menuCameraConfig.addActionListener((ActionEvent e) -> { - try { - if (camera != null) { - String cameraConfigJson = null; - if (usingServer) { - String cameraServerUrl = (camServerUrl == null) ? server.getUrl().substring(0, server.getUrl().length() - 1) + "8" : camServerUrl; - try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)) { - srv.initialize(); - //TODO: replace into encodeMultiline - cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true); - } - - } else { - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - } - TextEditor configEditor = new TextEditor(); - configEditor.setText(cameraConfigJson); - configEditor.setReadOnly(true); - configEditor.setTitle(cameraName); - EditorDialog dlg = configEditor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(getTopLevel(), dlg); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetImageBufferSize = new JMenuItem("Set Stack Size..."); - menuSetImageBufferSize.addActionListener((ActionEvent e) -> { - try { - String ret = SwingUtils.getString(getTopLevel(), "Enter size of image buffer: ", String.valueOf(imageBufferLenght)); - if (ret != null) { - this.setImageBufferSize(Integer.valueOf(ret)); - } - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSaveStack = new JMenuItem("Save Stack"); - menuSaveStack.addActionListener((ActionEvent e) -> { - try { - saveStack(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSetROI = new JMenuItem("Set ROI..."); - menuSetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); - renderer.addListener(new RendererListener() { - @Override - public void onSelectionFinished(Renderer renderer, Overlay overlay) { - try { - renderer.setShowReticle(false); - Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (server.isRoiEnabled()) { - int[] cur = server.getRoi(); - server.setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); - } else { - server.setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); - } - } catch (Exception ex) { - } finally { - renderer.removeListener(this); - } - } - - @Override - public void onSelectionAborted(Renderer renderer, Overlay overlay) { - renderer.removeListener(this); - } - }); - selection.setFixed(true); - renderer.startSelection(selection); - } - }); - - JMenuItem menuResetROI = new JMenuItem("Reset ROI"); - menuResetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (server != null) { - try { - renderer.setShowReticle(false); - server.resetRoi(); - } catch (IOException ex) { - showException(ex); - } - } - }); - - JCheckBoxMenuItem menuFrameIntegration = new JCheckBoxMenuItem("Multi-Frame", (integration != 0)); - menuFrameIntegration.addActionListener((ActionEvent e) -> { - if (integration == 0) { - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{150, 50}; //Minimum width - layout.rowHeights = new int[]{30, 30}; //Minimum height - panel.setLayout(layout); - JCheckBox checkContinuous = new JCheckBox(""); - checkContinuous.setSelected(true); - JTextField textFrames = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Number of frames:"), c); - c.gridy = 1; - panel.add(new JLabel("Continuous:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(checkContinuous, c); - c.gridy = 0; - panel.add(textFrames, c); - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", panel, OptionType.OkCancel) == OptionResult.Yes) { - setIntegration(checkContinuous.isSelected() ? -(Integer.valueOf(textFrames.getText())) : (Integer.valueOf(textFrames.getText()))); - } - } else { - if (SwingUtils.showOption(getTopLevel(), "Multi-Frame Integration", - "Do you want to disable " + ((integration < 0) ? "continuous " : "") + "multi-frame integration (" + Math.abs(integration) + ")?", OptionType.YesNo) == OptionResult.Yes) { - setIntegration(0); - } - } - }); - - for (Component cmp : SwingUtils.getComponentsByType(renderer.getPopupMenu(), JMenu.class)) { - JMenu menu = (JMenu) cmp; - if (menu.getText().equals("Integration")) { - menu.addSeparator(); - menu.add(menuFrameIntegration); - } - } - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuRendererConfig); - renderer.getPopupMenu().add(menuCameraConfig); - renderer.getPopupMenu().add(menuSetImageBufferSize); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuCalibrate); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuSetROI); - renderer.getPopupMenu().add(menuResetROI); - renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(server != null); - menuSetROI.setEnabled(server != null); - menuCalibrate.setVisible(server != null); - menuCalibrate.setEnabled((calibrationDialolg == null) || (!calibrationDialolg.isShowing())); - menuSaveStack.setEnabled(imageBufferLenght > 0); - menuSetImageBufferSize.setEnabled(!renderer.isPaused()); - menuFrameIntegration.setSelected(integration != 0); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - } - }); - renderer.getPopupMenu().setVisible(false); - buttonScale.setSelected(renderer.getShowColormapScale()); - clearMarker(); - - showFit = buttonFit.isSelected(); - showProfile = buttonProfile.isSelected(); - - pauseSelection.setVisible(false); - pauseSelection.setMinValue(1); - pauseSelection.addListener(new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - if (editing && (value >= 1) && (value <= imageBuffer.size())) { - updatePause(); - } - } - }); - renderer.addListener(new RendererListener() { - @Override - public void onMoveFinished(Renderer renderer, Overlay overlay) { - if (overlay == marker) { - try { - onMarkerChanged(); - } catch (IOException ex) { - Logger.getLogger(ScreenPanel4.class.getName()).log(Level.WARNING, null, ex); - } - } - } - }); - if (MainFrame.isDark()) { - textState.setDisabledTextColor(textState.getForeground()); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - - console = (!App.hasArgument("console")) ? null : new Console() { - /* - protected void onConsoleCommand(String name, String[] pars, String trimming) throws Exception { - switch (name) { - case "cam": - comboCameras.setSelectedItem(tokens[1]); - break; - } - }*/ - @Override - protected void onConsoleCommand(String command) { - String[] tokens = command.split(" "); - if ((tokens.length > 1) && tokens[0].equals("cam")) { - try { - if (!tokens[1].equals(comboCameras.getSelectedItem())) { - setComboTypeSelection("All"); - updateCameraList(); - comboCameras.setSelectedItem(tokens[1]); - if (!tokens[1].equals(comboCameras.getSelectedItem())) { - comboCameras.setSelectedItem(""); - throw new Exception("Invalid camera name : " + tokens[1]); - } - System.out.println("Console set camera: " + tokens[1]); - } - } catch (Exception ex) { - System.err.println(ex); - } - } else { - System.err.println("Invalid command: " + command); - } - } - }; - } - - void setIntegration(int frames) { - try { - if (integration != frames) { - integration = frames; - if (camera != null) { - if (Math.abs(integration) > 1) { - renderer.setDevice(new ImageIntegrator(integration)); - } else { - renderer.setDevice(camera); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - @Override - public void onStart() { - super.onStart(); - updateDialogTitle(); - if (App.hasArgument("ct")) { - boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonServer.setSelected(!direct); - buttonDirect.setSelected(direct); - } - if (App.hasArgument("console")) { - console.start(); - } - } - - @Override - public void onStop() { - try { - if (camera != null) { - saveCameraState(); - camera.close(); - camera = null; - server = null; - updateButtons(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - if (console != null) { - console.stop(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - super.onStop(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - comboType.setEnabled(false); - if (App.hasArgument("s")) { - renderer.setDevice((Source) getDevice("image")); - renderer.setAutoScroll(true); - ((Source) getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - manageFit(bi, data); - manageUserOverlays(bi, data); - } - - @Override - public void onError(Object o, Exception ex) { - } - } - ); - - } else { - usingServer = buttonServer.isSelected(); - updateCameraList(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - setComboCameraSelection(null); - setComboTypeSelection("All"); - - if (comboCameras.getModel().getSize() > 0) { - try { - if (App.hasArgument("cam")) { - setComboCameraSelection(App.getArgumentValue("cam")); - comboCamerasActionPerformed(null); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - updateButtons(); - startTimer(1000); - } - - boolean isVisible(String camera) { - return ((comboType.getSelectedIndex() == 0) || (getCameraType(camera).equals(comboType.getSelectedItem()))); - } - - DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - if (fromServer) { - try (PipelineServer srv = newServer()) { - srv.initialize(); - List cameras = srv.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - - } else { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - for (String camera : cameras) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - if (App.hasArgument("cam")) { - String camera = App.getArgumentValue("cam"); - if (model.getIndexOf(camera) < 0) { - if (isVisible(camera)) { - model.addElement(camera); - } - } - } - model.addElement(""); - - return model; - } - - PipelineServer newServer() throws IOException { - if (serverUrl != null) { - System.out.println("Connecting to server: " + serverUrl); - server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl); - } else { - System.out.println("Connecting to server"); - server = new PipelineServer(CAMERA_DEVICE_NAME); - } - updateButtons(); - return server; - } - - boolean updatingCameraSelection; - - void setComboCameraSelection(Object selection) { - updatingCameraSelection = true; - try { - comboCameras.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - - void setComboTypeSelection(Object selection) { - updatingCameraSelection = true; - try { - comboType.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - boolean usingServer; - - void updateCameraList() { - try { - String selected = (String) comboCameras.getSelectedItem(); - comboCameras.setModel(getCameraList(usingServer)); - if (selected != null) { - if (((DefaultComboBoxModel) comboCameras.getModel()).getIndexOf(camera) < 0) { - setComboCameraSelection(selected); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - } - - final Object lockOverlays = new Object(); - - void manageFit(BufferedImage bi, Data data) { - Overlay[][] fo = null; - if ((showFit || showProfile)) { - try { - fo = getFitOverlays(data); - } catch (Exception ex) { - System.err.println(ex); - } - } - synchronized (lockOverlays) { - fo = (fo == null) ? new Overlay[][]{null, null} : fo; - renderer.updateOverlays(fo[0], profileOv); - profileOv = fo[0]; - renderer.updateOverlays(fo[1], fitOv); - fitOv = fo[1]; - } - } - - void manageUserOverlays(BufferedImage bi, Data data) { - Overlay[] fo = (bi == null) ? null : getUserOverlays(data); - synchronized (lockOverlays) { - renderer.updateOverlays(fo, userOv); - userOv = fo; - } - } - - void updateDialogTitle() { - if (App.isDetached()) { - getTopLevel().setTitle(cameraName == null ? "ScreenPanel" : cameraName); - } - } - - void manageTitleOverlay() { - Overlay to = null; - if ((buttonTitle.isSelected()) && (cameraName != null)) { - Font font = new Font("Arial", Font.PLAIN, 28); - to = new Text(renderer.getPenErrorText(), cameraName, font, new Point(-SwingUtils.getTextSize(cameraName, renderer.getGraphics().getFontMetrics(font)).width - 14, 26)); - to.setFixed(true); - to.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - } - - synchronized (lockOverlays) { - renderer.updateOverlays(to, titleOv); - titleOv = to; - } - } - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - Thread devicesInitTask; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Initializing: " + cameraName); - parseUserOverlays(); - errorOverlay = null; - lastMarkerPos = null; - lastFrame = null; - lastPipelinePars = null; - - if (dataTableDialog != null) { - dataTableDialog.dispose(); - dataTableDialog = null; - } - dataTableModel = null; - - if (calibrationDialolg != null) { - calibrationDialolg.dispose(); - calibrationDialolg = null; - } - - boolean was_server = false; - if (camera != null) { - saveCameraState(); - //camera.removeAllListeners(); - was_server = (server != null); - camera.close(); - camera = null; - server = null; - } - updateButtons(); - instanceName = null; - renderer.setDevice(null); - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.removeOverlays(profileOv); - renderer.removeOverlays(userOv); - renderer.clear(); - renderer.resetZoom(); - - boolean changed = !String.valueOf(cameraName).equals(this.cameraName); - this.cameraName = cameraName; - - if (changed || buttonDirect.isSelected()) { - spinnerThreshold.setVisible(false); - checkThreshold.setEnabled(false); - checkGoodRegion.setEnabled(false); - setGoodRegionOptionsVisible(false); - setSlicingOptionsVisible(false); - } - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - if (changed) { - checkBackground.setEnabled(false); - if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { - devicesInitTask.interrupt(); - } - if (screen != null) { - screen.close(); - screen = null; - } - if (filter != null) { - filter.close(); - filter = null; - } - if (renderer.isPaused()) { - renderer.resume(); - removePauseOverlay(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - manageTitleOverlay(); - updateDialogTitle(); - - if (cameraName == null) { - return; - } - - System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]"); - try { - if (buttonServer.isSelected()) { - camera = newServer(); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - //camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName); - camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName}); - } - camera.initialize(); - camera.assertInitialized(); - System.out.println("Camera initialization OK"); - loadCameraState(); - if (server != null) { - //server.start(cameraName, false); - String pipelineName = cameraName + pipelineSuffix; - instanceName = cameraName + pipelineSuffix + "1"; - if (!server.getPipelines().contains(pipelineName)) { - System.out.println("Creating pipeline: " + pipelineName); - HashMap config = new HashMap<>(); - config.put("camera_name", cameraName); - //server.createFromConfig(config, pipelineName); - server.savePipelineConfig(pipelineName, config); - } - server.start(pipelineName, instanceName); - - updatePipelineControls(); - checkThreshold.setEnabled(true); - checkGoodRegion.setEnabled(true); - } else { - checkThreshold.setSelected(false); - checkGoodRegion.setSelected(false); - if (polling <= 0) { - camera.setMonitored(true); - } else { - camera.setPolling(polling); - } - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - updateButtons(); - camera.getConfig().save(); - if (Math.abs(integration) > 1) { - renderer.setDevice(new ImageIntegrator(integration)); - } else { - renderer.setDevice(camera); - } - renderer.setAutoScroll(true); - //renderer.setMarker(marker); - clearMarker(); - imageSize = null; - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi != null) { - if ((imageSize == null) || imageSize.width != bi.getWidth() || imageSize.height != bi.getHeight()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { - centralizeRenderer(); - } - checkReticle(); - } - }); - imageSize = new Dimension(bi.getWidth(), bi.getHeight()); - } - renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); - } - //renderer.setCalibration(camera.getCalibration()); - if (!renderer.isPaused()) { - if (data != null) { - synchronized (imageBuffer) { - currentFrame = new Frame(data); - if (imageBufferLenght >= 1) { - imageBuffer.add(currentFrame); - if (imageBuffer.size() > imageBufferLenght) { - imageBuffer.remove(0); - setBufferFull(true); - } else { - setBufferFull(false); - } - } else { - setBufferFull(true); - } - //Update data - if (!renderer.isPaused()) { - updateStreamData(); - } - updateMarker(); - } - } - manageFit(bi, data); - manageUserOverlays(bi, data); - } - //updateImageData(); - } - - @Override - public void onError(Object o, Exception ex) { - //System.err.println(ex); - } - }); - - } catch (Exception ex) { - showException(ex); - renderer.clearOverlays(); - updatePipelineControls(); - if (renderer.getDevice() == null) { - //renderer.setZoom(1.0); - //renderer.setMode(RendererMode.Zoom); - errorOverlay = new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - errorOverlay.setFixed(true); - errorOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - renderer.addOverlay(errorOverlay); - } - } finally { - //checkReticle(); - onTimer(); - } - onChangeColormap(null); - checkBackground.setEnabled(true); - if (changed) { - boolean electrons = getCameraType(cameraName).equals(ELECTRONS_TYPE); - comboScreen.setModel(new DefaultComboBoxModel()); - comboScreen.setEnabled(false); - comboFilter.setModel(new DefaultComboBoxModel()); - comboFilter.setEnabled(false); - panelFilter.setVisible(electrons); - panelScreen.setVisible(electrons); - if (electrons) { - //Parallelizing initialization - devicesInitTask = new Thread(() -> { - try { - if (cameraName.contains("DSRM")) { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); - } else { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); - } - screen.setMonitored(true); - screen.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : screen.getPositions()) { - model.addElement(pos); - } - comboScreen.setModel(model); - comboScreen.setSelectedItem(screen.read()); - - } catch (Exception ex) { - comboScreen.setModel(new DefaultComboBoxModel()); - System.err.println(ex.getMessage()); - screen = null; - } - comboScreen.setEnabled(screen != null); - valueScreen.setDevice(screen); - - try { - filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); - filter.setMonitored(true); - filter.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : filter.getPositions()) { - model.addElement(pos); - } - comboFilter.setModel(model); - comboFilter.setSelectedItem(filter.read()); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - filter = null; - } - comboFilter.setEnabled(filter != null); - valueFilter.setDevice(filter); - }); - devicesInitTask.start(); - } - } - } - - class ImageIntegrator extends ColormapSource { - - ImageIntegrator(int num) { - super("Image Averager", camera.getConfig()); - boolean continuous = (num < 0); - final int numImages = Math.abs(num); - - camera.addListener(new ImageListener() { - final ArrayList buffer = new ArrayList(); - Data integration = null; - - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - try { - if (continuous) { - buffer.add(data); - if (buffer.size() >= numImages) { - for (Data d : buffer) { - process(d); - } - } - } else { - buffer.add(null); //Just to count - process(data); - } - } catch (Exception ex) { - buffer.clear(); - integration = null; - ImageIntegrator.this.pushData(null); - ex.printStackTrace(); - return; - } - if (buffer.size() >= numImages) { - if (continuous) { - buffer.remove(0); - } else { - buffer.clear(); - } - if (integration != null) { - //integration.div(numImages); - ImageIntegrator.this.pushData(integration); - } - integration = null; - } - } - - void process(Data data) { - if (integration == null) { - integration = new Data(data); - } else { - integration.sum(data); - } - } - - @Override - public void onError(Object origin, Exception ex) { - } - }); - - } - } - - boolean bufferFull = true; - - void setBufferFull(boolean value) { - if (value != bufferFull) { - SwingUtilities.invokeLater(() -> { - buttonPause.setBackground(value ? buttonSave.getBackground() : buttonSave.getBackground().brighter()); - }); - bufferFull = value; - } - } - - volatile Dimension imageSize; - - void checkReticle() { - if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) { - //renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800, 800), 200); - renderer.setShowReticle(true); - } else { - //renderer.setCalibration(null); - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - void checkMarker(Point p) throws IOException { - if (camera != null) { - if (buttonMarker.isSelected()) { - Dimension d = renderer.getImageSize(); - if (p == null) { - p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - } - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - marker.setPassive(false); - } else { - marker = null; - } - renderer.setMarker(marker); - onMarkerChanged(); - } - } - - Point lastMarkerPos; - - void onMarkerChanged() throws IOException { - lastMarkerPos = getStreamMarkerPos(); - if (marker == null) { - setInstanceConfigValue("Marker", null); - } else { - setInstanceConfigValue("Marker", new int[]{marker.getPosition().x, marker.getPosition().y}); - } - } - - void updateMarker() { - try { - if (server != null) { - Point p = getStreamMarkerPos(); - if (p != null) { - //To prevent a local change being overriden by a message having the old settings. - //TODO: This is not bullet-proof, as one can have 2 changes between 2 frames... - if (!p.equals(lastMarkerPos)) { - if (p.x == Integer.MIN_VALUE) { - if (buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - checkMarker(null); - } - } else { - if (!buttonMarker.isSelected()) { - buttonMarker.setSelected(true); - checkMarker(p); - } else { - if (!p.equals(marker.getPosition())) { - marker.setPosition(p); - } - } - } - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - Point getStreamMarkerPos() throws IOException { - //System.out.println(server.getInstanceConfig().get("Marker")); - Map pars = server.getProcessingParameters(); - if (pars != null) { - List markerPosition = (List) pars.get("Marker"); - if (markerPosition != null) { - return new Point((Integer) markerPosition.get(0), (Integer) markerPosition.get(1)); - } - return new Point(Integer.MIN_VALUE, Integer.MIN_VALUE); - } - return null; - } - - void clearMarker() { - marker = null; - renderer.setMarker(marker); - } - - void setInstanceConfigValue(String name, Object value) throws IOException { - if (server != null) { - Map map = server.getInstanceConfig(); - map.put(name, value); - server.setInstanceConfig(map); - } - } - - void updateZoom() { - try { - buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom) { - if (renderer.getZoom() == 1) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getZoom() == 0.5) { - buttonZoom05.setSelected(true); - } else if (renderer.getZoom() == 0.25) { - buttonZoom025.setSelected(true); - } else if (renderer.getZoom() == 2.0) { - buttonZoom2.setSelected(true); - } else { - buttonGroup1.clearSelection(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - boolean updatingColormap; - - void updateColormap() { - updatingColormap = true; - try { - if ((camera != null) && (camera instanceof ColormapSource)) { - ColormapSourceConfig config = ((ColormapSource) camera).getConfig(); - comboColormap.setSelectedItem(config.colormap); - if (config.isDefaultColormap()) { - buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic) { - buttonAutomatic.setSelected(true); - } else { - buttonManual.setSelected(true); - } - btFixColormapRange.setVisible(buttonAutomatic.isSelected()); - spinnerMin.setEnabled(buttonManual.isSelected()); - spinnerMax.setEnabled(buttonManual.isSelected()); - if (!Double.isNaN(config.colormapMin)) { - spinnerMin.setValue(Math.min(Math.max((int) config.colormapMin, 0), 65535)); - } - if (!Double.isNaN(config.colormapMax)) { - spinnerMax.setValue(Math.min(Math.max((int) config.colormapMax, 0), 65535)); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatingColormap = false; - } - - void updatePipelineProperties() { - goodRegion = checkGoodRegion.isSelected(); - spinnerThreshold.setVisible(checkThreshold.isSelected()); - setGoodRegionOptionsVisible(goodRegion); - slicing = goodRegion && checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - updatingServerControls = false; - } - - boolean updatingServerControls; - - void updatePipelineControls() { - if (server != null) { - updatingServerControls = true; - if (server.isStarted()) { - try { - checkBackground.setSelected(server.getBackgroundSubtraction()); - Double threshold = (server.getThreshold()); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (server.getGoodRegion()); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - spinnerGrThreshold.setValue(((Number) gr.get("threshold")).doubleValue()); - spinnerGrScale.setValue(((Number) gr.get("gfscale")).doubleValue()); - } - Map slicing = (server.getSlicing()); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - spinnerSlNumber.setValue(((Number) slicing.get("number_of_slices")).intValue()); - spinnerSlScale.setValue(((Number) slicing.get("scale")).doubleValue()); - spinnerSlOrientation.setValue((String) slicing.get("orientation")); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - updatePipelineProperties(); - } - } - - boolean changedPipelinePars(Map pars1, Map pars2) { - String[] keys = new String[]{"image_background_enable", "image_threshold", "image_good_region", - "threshold", "gfscale", "image_slices", "number_of_slices", "scale", "orientation"}; - for (String key : keys) { - Object o1 = pars1.get(key); - Object o2 = pars2.get(key); - if (o1 == null) { - if (o2 != null) { - return true; - } - } else if (!o1.equals(o2)) { - return true; - } - } - return false; - } - - void updatePipelineControls(Map pars) { - if (pars != null) { - updatingServerControls = true; - try { - boolean background = (boolean) pars.get("image_background_enable"); - checkBackground.setSelected(background); - Double threshold = (Double) (pars.get("image_threshold")); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (Map) pars.get("image_good_region"); - checkGoodRegion.setSelected(gr != null); - if (gr != null) { - Double value = ((Number) gr.get("threshold")).doubleValue(); - spinnerGrThreshold.setValue(value); - Double scale = ((Number) gr.get("gfscale")).doubleValue(); - spinnerGrScale.setValue(scale); - } - Map slicing = (Map) (pars.get("image_slices")); - checkSlicing.setSelected(slicing != null); - if (slicing != null) { - int slices = ((Number) slicing.get("number_of_slices")).intValue(); - spinnerSlNumber.setValue(slices); - double scale = ((Number) slicing.get("scale")).doubleValue(); - spinnerSlScale.setValue(scale); - String orientation = (String) slicing.get("orientation"); - spinnerSlOrientation.setValue(orientation); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatePipelineProperties(); - } - } - - void setGoodRegionOptionsVisible(boolean visible) { - spinnerGrThreshold.setVisible(visible); - labelGrThreshold.setVisible(visible); - spinnerGrScale.setVisible(visible); - labelGrScale.setVisible(visible); - panelSlicing.setVisible(visible); - } - - void setSlicingOptionsVisible(boolean visible) { - spinnerSlNumber.setVisible(visible); - labelSlNumber.setVisible(visible); - spinnerSlScale.setVisible(visible); - labelSlScale.setVisible(visible); - spinnerSlOrientation.setVisible(visible); - labelSlOrientation.setVisible(visible); - } - - boolean isCameraStopped() { - if ((server != null) && !server.isStarted()) { - return true; - } - return ((camera == null) || camera.isClosed()); - } - - boolean updatingButtons; - - void updateButtons() { - updatingButtons = true; - try { - boolean active = !isCameraStopped();//(camera != null); - buttonSave.setEnabled(active); - buttonGrabBackground.setEnabled(active); - buttonMarker.setEnabled(active); - buttonProfile.setEnabled(active); - buttonFit.setEnabled(active); - buttonReticle.setEnabled(active && camera.getConfig().isCalibrated()); - buttonStreamData.setEnabled(active && (server != null)); - buttonPause.setEnabled(active); - - if (renderer.isPaused() != buttonPause.isSelected()) { - buttonPause.setSelected(renderer.isPaused()); - buttonPauseActionPerformed(null); - } - if (renderer.getShowReticle() != buttonReticle.isSelected()) { - //buttonReticle.setSelected(renderer.getShowReticle()); - } - if ((renderer.getMarker() == null) && buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - } - buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - - } finally { - updatingButtons = false; - } - } - - Frame lastFrame = null; - Map lastPipelinePars = null; - - @Override - protected void onTimer() { - for (Device dev : new Device[]{screen, filter}) { - if (dev != null) { - dev.request(); - } - } - - textState.setText((camera == null) ? "" : camera.getState().toString()); - if (App.hasArgument("s")) { - try { - ((Source) getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } - } - updateZoom(); - updateColormap(); - updateButtons(); - checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); - buttonScale.setSelected(renderer.getShowColormapScale()); - try { - Frame frame = getCurrentFrame(); - if (frame != lastFrame) { - lastFrame = frame; - if (frame != null) { - Map pars = getProcessingParameters(frame.cache); - if ((lastPipelinePars == null) || changedPipelinePars(pars, lastPipelinePars)) { - //System.out.println("Update pipeline: " + pars); - lastPipelinePars = pars; - updatePipelineControls(pars); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - Pen penFit = new Pen(new Color(192, 105, 0), 0); - Pen penCross = new Pen(new Color(192, 105, 0), 0); - Pen penSlices = new Pen(Color.CYAN.darker(), 1); - - Frame getCurrentFrame() { - if ((imageBufferLenght > 1) && (renderer.isPaused())) { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - return (index < imageBuffer.size()) ? imageBuffer.get(index) : null; - } - } - return currentFrame; - } - - Frame getFrame(Data data) { - synchronized (imageBuffer) { - for (Frame f : imageBuffer) { - if (f.data == data) { - return f; - } - } - } - return null; - } - - void setImageBufferSize(int size) { - if (renderer.isPaused()) { - throw new RuntimeException("Cannot change buffer size whn paused"); - } - synchronized (imageBuffer) { - imageBufferLenght = size; - imageBuffer.clear(); - } - - } - - Overlay[][] getFitOverlays(Data data) { - Overlays.Polyline hgaussian = null; - Overlays.Polyline vgaussian = null; - Overlays.Polyline hprofile = null; - Overlays.Polyline vprofile = null; - Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null; - Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null; - double[] pX = null, pY = null, gX = null, gY = null; - PointDouble[] sliceCenters = null; - if (data != null) { - int height = data.getHeight(); - int width = data.getWidth(); - int profileSize = renderer.getProfileSize(); - if ((useServerStats) && (server != null)) { - try { - - ImageData id = getFrame(data); - if (id == null) { - return null; - } - xMean = id.x_fit_mean; - xSigma = id.x_fit_standard_deviation; - yMean = id.y_fit_mean; - ySigma = id.y_fit_standard_deviation; - gX = id.x_fit_gauss_function; - gY = id.y_fit_gauss_function; - pX = id.x_profile; - pY = id.y_profile; - xCom = id.x_center_of_mass; - xRms = id.x_rms; - yCom = id.y_center_of_mass; - yRms = id.y_rms; - sliceCenters = id.sliceCenters; - - profileSize /= 4; - if (pX != null) { - int[] xp = Arr.indexesInt(pX.length); - int[] xg = xp; - int[] yp = new int[pX.length]; - int[] yg = new int[pX.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_x > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gX, id.gr_pos_x, id.gr_pos_x + id.gr_size_x))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gX != null) { - yg[i] = (int) (height - 1 - (((gX[i] - minGauss) / rangeGauss) * profileSize)); - } - yp[i] = (int) (height - 1 - (((pX[i] - minProfile) / rangeProfile) * profileSize)); - } - - if (goodRegion && id.gr_size_x > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - yg = Arrays.copyOfRange(yg, id.gr_pos_x, id.gr_pos_x + id.gr_size_x); - } - - vgaussian = new Overlays.Polyline(penFit, xg, yg); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - - if (pY != null) { - int[] xp = new int[pY.length]; - int[] xg = new int[pY.length]; - int[] yp = Arr.indexesInt(pY.length); - int[] yg = yp; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - double minProfile = Collections.min(l); - double maxProfile = Collections.max(l); - double rangeProfile = maxProfile - minProfile; - double minGauss = minProfile; - double rangeGauss = rangeProfile; - //If not good region, range of profile and fit are similar so save this calcultion - if (goodRegion && id.gr_size_y > 0) { - l = Arrays.asList((Double[]) Convert.toWrapperArray(Arrays.copyOfRange(gY, id.gr_pos_y, id.gr_pos_y + id.gr_size_y))); - minGauss = Collections.min(l); - rangeGauss = Collections.max(l) - minGauss; - } - - for (int i = 0; i < xp.length; i++) { - if (gY != null) { - xg[i] = (int) (((gY[i] - minGauss) / rangeGauss) * profileSize); - } - xp[i] = (int) (((pY[i] - minProfile) / rangeProfile) * profileSize); - } - - if (goodRegion && id.gr_size_x > 0) { - xg = Arrays.copyOfRange(xg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - yg = Arrays.copyOfRange(yg, id.gr_pos_y, id.gr_pos_y + id.gr_size_y); - } - hgaussian = new Overlays.Polyline(penFit, xg, yg); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), xp, yp); - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - return null; - } - } else { - ArrayProperties properties = data.getProperties(); - double maxPlot = properties.max; - double minPlot = properties.min; - double rangePlot = maxPlot - minPlot; - - if (rangePlot <= 0) { - return null; - } - if (renderer.getCalibration() != null) { - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height - minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit) { - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile) { - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - if (xSigma != null) { - xSigma *= renderer.getCalibration().getScaleX(); - } - if (ySigma != null) { - ySigma *= renderer.getCalibration().getScaleY(); - } - if (xMean != null) { - xMean = data.getX((int) Math.round(xMean)); - } - if (yMean != null) { - yMean = data.getY((int) Math.round(yMean)); - } - } - } - final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px"; - final String fmt = "%7.1f" + units; - Overlays.Text textCom = null; - Overlay[] pOv = null, fOv = null; - Font fontInfoText = new Font(Font.MONOSPACED, 0, 14); - Point textPosition = new Point(12, 20); - if (showProfile) { - if ((xCom != null) && (yCom != null)) { - String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt, xCom, xRms, yCom, yRms); - textCom = new Overlays.Text(renderer.getPenProfile(), text, fontInfoText, textPosition); - textCom.setFixed(true); - textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - } - pOv = new Overlay[]{hprofile, vprofile, textCom}; - textPosition = new Point(textPosition.x, textPosition.y + 34); - } - if (showFit) { - Overlays.Crosshairs cross = null; - Overlays.Text textFit = null; - if ((xMean != null) && (yMean != null)) { - String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt, xMean, xSigma, yMean, ySigma); - textFit = new Overlays.Text(penFit, text, fontInfoText, textPosition); - textFit.setFixed(true); - textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - Point center = new Point(xMean.intValue(), yMean.intValue()); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean)); - xSigma /= renderer.getCalibration().getScaleX(); - ySigma /= renderer.getCalibration().getScaleY(); - } - cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue()))); - } - textPosition = new Point(textPosition.x, textPosition.y + 34); - fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit}; - - if (goodRegion) { - try { - double[] x = getServerDoubleArray("gr_x_axis"); - double[] y = getServerDoubleArray("gr_y_axis"); - double x1 = x[0]; - double x2 = x[x.length - 1]; - double y1 = y[0]; - double y2 = y[y.length - 1]; - Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); - goodRegionOv.setCalibration(renderer.getCalibration()); - goodRegionOv.setAbsolutePosition(new PointDouble(x1, y1)); - goodRegionOv.setAbsoluteSize(new DimensionDouble(x2 - x1, y2 - y1)); - fOv = Arr.append(fOv, goodRegionOv); - - if (slicing) { - if (sliceCenters != null) { - for (PointDouble sliceCenter : sliceCenters) { - Overlays.Crosshairs center = new Overlays.Crosshairs(penSlices); - center.setCalibration(renderer.getCalibration()); - center.setAbsolutePosition(sliceCenter); - center.setSize(new Dimension(10, 10)); - fOv = Arr.append(fOv, center); - } - if (sliceCenters.length > 1) { - double[] fit = fitPolynomial(sliceCenters, 1); - double angle = Math.toDegrees(Math.atan(fit[1])); - Overlays.Text text = new Overlays.Text(penSlices, String.format("slice: \u03B8= %5.1fdeg", angle), fontInfoText, textPosition); - text.setFixed(true); - text.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - fOv = Arr.append(fOv, text); - } - } - } - } catch (Exception ex) { - } - } - - } - return new Overlay[][]{pOv, fOv}; - } - return null; - } - - class UserOverlay { - - String name; - Overlay obj; - String[] channels; - } - ArrayList userOverlayConfig; - - void parseUserOverlays() { - Properties userOverlays = new Properties(); - userOverlayConfig = new ArrayList<>(); - if (userOverlaysConfigFile != null) { - try { - try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { - userOverlays.load(in); - - for (String name : userOverlays.stringPropertyNames()) { - String val = userOverlays.getProperty(name); - try { - UserOverlay uo = new UserOverlay(); - uo.name = name; - String type = val.substring(0, val.indexOf("(")).trim(); - String pars = val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")).trim(); - String[] tokens = pars.split(","); - for (int i = 0; i < tokens.length; i++) { - tokens[i] = tokens[i].trim(); - } - Color color = Color.GRAY; - try { - color = (Color) Color.class.getField(tokens[tokens.length - 1].toUpperCase()).get(null); - } catch (Exception ex) { - } - Pen pen = new Pen(color); - try { - String[] penTokens = tokens[tokens.length - 1].split(":"); - color = (Color) Color.class.getField(penTokens[0].toUpperCase()).get(null); - int width = Integer.valueOf(penTokens[1]); - Pen.LineStyle style = Pen.LineStyle.valueOf(penTokens[2]); - pen = new Pen(color, width, style); - } catch (Exception ex) { - } - switch (type) { - case "Point": - uo.obj = new Overlays.Crosshairs(); - uo.obj.setSize(new Dimension(Integer.valueOf(tokens[2]), Integer.valueOf(tokens[3]))); - break; - case "Line": - uo.obj = new Overlays.Line(); - break; - case "Arrow": - uo.obj = new Overlays.Arrow(); - break; - case "Rect": - uo.obj = new Overlays.Rect(); - break; - case "Ellipse": - uo.obj = new Overlays.Ellipse(); - break; - case "Polyline": - uo.obj = new Overlays.Polyline(); - break; - } - if (type.equals("Polyline") || type.equals("Point")) { - uo.channels = new String[]{tokens[0], tokens[1]}; - } else { - uo.channels = new String[]{tokens[0], tokens[1], tokens[2], tokens[3]}; - } - uo.obj.setPen(pen); - userOverlayConfig.add(uo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - Overlay[] getUserOverlays(Data data) { - ArrayList ret = new ArrayList<>(); - if (server != null) { - for (UserOverlay uo : userOverlayConfig) { - try { - Overlay ov = uo.obj; - //Overlay ov = (Overlay)uo.cls.newInstance(); - ov.setCalibration(renderer.getCalibration()); - boolean valid = false; - if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : getServerDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : getServerDoubleArray(uo.channels[1]); - if ((x != null) || (y != null)) { - if (x == null) { - x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); - } - if (y == null) { - y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length); - } - ((Overlays.Polyline) ov).updateAbsolute(x, y); - valid = true; - } - } else { - Double x = getServerDouble(uo.channels[0]); - Double y = getServerDouble(uo.channels[1]); - if ((x != null) && (y != null)) { - PointDouble position = new PointDouble(x, y); - ov.setAbsolutePosition(position); - if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = getServerDouble(uo.channels[2]); - Double y2 = getServerDouble(uo.channels[3]); - if ((x != null) && (y != null)) { - DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); - ov.setAbsoluteSize(size); - valid = true; - } - } else { - valid = true; - } - } - } - if (valid) { - ret.add(ov); - } - } catch (Exception ex) { - //ex.printStackTrace(); - } - } - } - return ret.toArray(new Overlay[0]); - } - - double[] getComRms(double[] arr, double[] x) { - if (arr != null) { - double xmd = 0; - double xmd2 = 0; - double total = 0; - for (int i = 0; i < arr.length; i++) { - double v = (arr[i] * x[i]); - xmd += v; - xmd2 += (v * x[i]); - total += arr[i]; - } - if (total > 0) { - double com = xmd / total; - double com2 = xmd2 / total; - double rms = Math.sqrt(Math.abs(com2 - com * com)); - return new double[]{com, rms}; - } - } - return new double[]{Double.NaN, Double.NaN}; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] fitPolynomial(PointDouble[] points, int order) { - double[] y = new double[points.length]; - double[] x = new double[points.length]; - for (int i = 0; i < points.length; i++) { - x[i] = points[i].x; - y[i] = points[i].y; - } - return fitPolynomial(y, x, order); - } - - double[] fitPolynomial(double[] y, double[] x, int order) { - try { - ArrayProperties pY = ArrayProperties.get(y); - PolynomialCurveFitter fitter = PolynomialCurveFitter.create(order).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - void setHistogramVisible(boolean value) { - if (value) { - if ((histogramDialog == null) || (!histogramDialog.isShowing())) { - Histogram histogram = new Histogram(true); - histogram.setRenderer(renderer); - histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram); - renderer.refresh(); - } - } else { - if (histogramDialog != null) { - histogramDialog.setVisible(false); - histogramDialog = null; - } - } - } - - void setLaserState(boolean value) throws Exception { - System.out.println("Setting laser state: " + value); - Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); - Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); - Thread.sleep(3000); - } - - boolean getLaserState() throws Exception { - return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); - } - - void elog(String logbook, String title, String message, String[] attachments) throws Exception { - String domain = ""; - String category = "Info"; - String entry = ""; - StringBuffer cmd = new StringBuffer(); - - cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); - cmd.append("-a \"Author=ScreenPanel\" "); - cmd.append("-a \"Type=pshell\" "); - cmd.append("-a \"Entry=").append(entry).append("\" "); - cmd.append("-a \"Title=").append(title).append("\" "); - cmd.append("-a \"Category=").append(category).append("\" "); - cmd.append("-a \"Domain=").append(domain).append("\" "); - for (String attachment : attachments) { - cmd.append("-f \"").append(attachment).append("\" "); - } - cmd.append("-n 1 "); - cmd.append("\"").append(message).append("\" "); - System.out.println(cmd.toString()); - - final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); - new Thread(() -> { - try { - process.waitFor(); - int bytes = process.getInputStream().available(); - byte[] arr = new byte[bytes]; - process.getInputStream().read(arr, 0, bytes); - System.out.println(new String(arr)); - bytes = process.getErrorStream().available(); - arr = new byte[bytes]; - process.getErrorStream().read(arr, 0, bytes); - System.err.println(new String(arr)); - } catch (Exception ex) { - System.err.println(ex); - } - }).start(); - } - - void centralizeRenderer() { - Point center = null; - Dimension size = renderer.getImageSize(); - double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom(); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().getCenter(); - } else if (size != null) { - center = new Point(size.width / 2, size.height / 2); - } - if (center != null) { - Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0), - Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0)); - renderer.setViewPosition(topleft); - } - } - - void updatePause() { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - if (index < imageBuffer.size()) { - Data data = imageBuffer.get(index).data; - long pid = imageBuffer.get(index).cache.getPulseId(); - BufferedImage image = camera.generateImage(data); - renderer.setImage(renderer.getOrigin(), image, data); - - String text = "PID: " + pid; - if (imagePauseOverlay == null) { - Font font = new Font("Verdana", Font.PLAIN, 12); - Dimension d = SwingUtils.getTextSize(text, renderer.getFontMetrics(font)); - imagePauseOverlay = new Text(renderer.getPenErrorText(), "", font, new Point(-20 - d.width, 42)); - imagePauseOverlay.setFixed(true); - imagePauseOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); - renderer.addOverlay(imagePauseOverlay); - } - //imagePauseOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS")); - imagePauseOverlay.update(text); - manageFit(image, data); - manageUserOverlays(image, data); - } - } - updateStreamData(); - } - - void removePauseOverlay() { - renderer.removeOverlay(imagePauseOverlay); - imagePauseOverlay = null; - } - - void saveSnapshot() throws Exception { - boolean paused = isPaused(); - try{ - if (!paused){ - setPaused(true); - } - String snapshotFile = null; - synchronized (imageBuffer) { - Frame frame = getCurrentFrame(); - if (frame == null) { - throw new Exception("No current image"); - } - ArrayList frames = new ArrayList<>(); - frames.add(frame); - this.saveFrames(cameraName + "_camera_snapshot", frames); - - //Enforce the same timestamp to data & image files. - snapshotFile = getContext().getExecutionPars().getPath() + ".png"; - //renderer.saveSnapshot(snapshotFile, "png", true); - ImageBuffer.saveImage(SwingUtils.createImage(renderer), snapshotFile, "png"); - } - - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{0, 180}; //Minimum width - layout.rowHeights = new int[]{30, 30, 30}; //Minimum height - panel.setLayout(layout); - JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); - JTextField textComment = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Data file:"), c); - c.gridy = 1; - panel.add(new JLabel("Logbook:"), c); - c.gridy = 2; - panel.add(new JLabel("Comment:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(textComment, c); - c.gridy = 1; - panel.add(comboLogbook, c); - c.gridy = 0; - panel.add(new JLabel(getContext().getExecutionPars().getPath()), c); - - if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes) { - StringBuilder message = new StringBuilder(); - message.append("Camera: ").append(cameraName).append(" ("). - append((server != null) ? "server" : "direct").append(")").append("\n"); - message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); - message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); - message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); - message.append("Comment: ").append(textComment.getText()).append("\n"); - //Add slicing message - if ((fitOv != null) && (fitOv.length > 5) && (fitOv[fitOv.length - 1] instanceof Overlays.Text)) { - Overlays.Text text = (Overlays.Text) fitOv[fitOv.length - 1]; - message.append(text.getText()).append("\n"); - } - elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - } finally{ - if (!paused){ - setPaused(false); - } - } - } - - void saveStack() throws Exception { - synchronized (imageBuffer) { - saveFrames(cameraName + "_camera_stack", imageBuffer); - } - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath()); - } - - public static String getCameraType(String name) { - if (name == null) { - return ""; - } - for (String s : new String[]{"LCAM"}) { - if (name.contains(s)) { - return LASER_TYPE; - } - } - for (String s : new String[]{"DSCR", "DSRM", "DLAC"}) { - if (name.contains(s)) { - return ELECTRONS_TYPE; - } - } - for (String s : new String[]{"PROF", "PPRM", "PSSS", "PSCR", "PSRD"}) { - if (name.contains(s)) { - return PHOTONICS_TYPE; - } - } - return "Unknown"; - } - - public Map getProcessingParameters(StreamValue value) throws IOException { - return (Map) JsonSerializer.decode(value.getValue("processing_parameters").toString(), Map.class); - } - - void saveFrames(String name, ArrayList frames) throws IOException { - ArrayList values = new ArrayList<>(); - for (Frame frame : frames) { - values.add(frame.cache); - } - saveImages(name, values); - } - - void saveImages(String name, ArrayList images) throws IOException { - int depth = images.size(); - if (depth == 0) { - return; - } - StreamValue first = images.get(0); - String pathRoot = "/camera1/"; - String pathImage = pathRoot + "image"; - String pathPid = pathRoot + "pulse_id"; - String pathTimestampStr = pathRoot + "timestamp_str"; - Map processingPars = getProcessingParameters(first); - String camera = (String) processingPars.get("camera_name"); - String type = getCameraType(camera); - - int width = ((Number) first.getValue("width")).intValue(); - int height = ((Number) first.getValue("height")).intValue(); - Class dataType = first.getValue("image").getClass().getComponentType(); - - getContext().setExecutionPars(name); - DataManager dm = getContext().getDataManager(); - - //Create tables - dm.createDataset(pathImage, dataType, new int[]{depth, height, width}); - dm.createDataset(pathPid, Long.class, new int[]{depth}); - dm.createDataset(pathTimestampStr, String.class, new int[]{depth}); - for (String id : first.getIdentifiers()) { - Object val = first.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(first); - for (String key : pars.keySet()) { - if ((pars.get(key) != null) && (pars.get(key) instanceof Map)) { - for (Object k : ((Map) pars.get(key)).keySet()) { - Object v = ((Map) pars.get(key)).get(k); - dm.setAttribute(pathImage, key + " " + k, (v == null) ? "" : v); - } - } else { - Object value = pars.get(key); - if (value == null) { - value = ""; - } else if (value instanceof List) { - Class cls = (((List) value).size() > 0) ? ((List) value).get(0).getClass() : double.class; - value = Convert.toPrimitiveArray(value, cls); - //value = Convert.toDouble(value); - } - dm.setAttribute(pathImage, key, value); - } - } - } else if (val.getClass().isArray()) { - dm.createDataset(pathRoot + id, Double.class, new int[]{depth, Array.getLength(val)}); - } else { - dm.createDataset(pathRoot + id, val.getClass(), new int[]{depth}); - } - } - - //Add metadata - dm.setAttribute(pathRoot, "Camera", camera); - dm.setAttribute(pathRoot, "Images", depth); - dm.setAttribute(pathRoot, "Interval", -1); - dm.setAttribute(pathRoot, "Type", type); - if (type.equals(ELECTRONS_TYPE)) { - dm.setAttribute(pathRoot, "Screen", String.valueOf(valueScreen.getLabel().getText())); - dm.setAttribute(pathRoot, "Filter", String.valueOf(valueFilter.getLabel().getText())); - } - - //Save data - for (int index = 0; index < depth; index++) { - StreamValue streamValue = images.get(index); - dm.setItem(pathImage, streamValue.getValue("image"), new long[]{index, 0, 0}, new int[]{1, height, width}); - dm.setItem(pathPid, streamValue.getPulseId(), index); - dm.setItem(pathTimestampStr, Chrono.getTimeStr(streamValue.getTimestamp(), "YYYY-MM-dd HH:mm:ss.SSS"), index); - - for (String id : streamValue.getIdentifiers()) { - Object val = streamValue.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - } else if (val.getClass().isArray()) { - dm.setItem(pathRoot + id, val, index); - } else { - dm.setItem(pathRoot + id, val, index); - } - } - } - getContext().getDataManager().closeOutput(); - } - - StandardDialog calibrationDialolg; - - void calibrate() throws Exception { - if (server != null) { - server.resetRoi(); - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraCalibrationDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), server.getCurrentCamera(), renderer}); - SwingUtils.centerComponent(getTopLevel(), calibrationDialolg); - calibrationDialolg.setVisible(true); - calibrationDialolg.setListener(new StandardDialogListener() { - @Override - public void onWindowOpened(StandardDialog dlg) { - } - - @Override - public void onWindowClosed(StandardDialog dlg, boolean accepted) { - if (accepted) { - //comboCamerasActionPerformed(null); - } - } - }); - } - } - - StandardDialog dataTableDialog; - DefaultTableModel dataTableModel; - JTable dataTable; - - void showStreamData() { - dataTableModel = null; - if (server != null) { - - if ((dataTableDialog != null) && (dataTableDialog.isShowing())) { - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.requestFocus(); - return; - } - dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) { - public Class getColumnClass(int columnIndex) { - return String.class; - } - - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - }; - updateStreamData(); - StreamValue val = server.getStream().take(); - dataTable = new JTable(dataTableModel); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.setCellSelectionEnabled(true); - dataTable.getTableHeader().setReorderingAllowed(false); - dataTable.getTableHeader().setResizingAllowed(true); - dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); - dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(dataTable); - scrollPane.setPreferredSize(new Dimension(300, 400)); - dataTableDialog.setContentPane(scrollPane); - dataTableDialog.pack(); - dataTableDialog.setVisible(true); - dataTableDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - dataTableModel = null; - } - }); - dataTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - try { - int row = dataTable.getSelectedRow(); - int col = dataTable.getSelectedColumn(); - dataTable.setToolTipText(null); - if (row > 1) { - String id = String.valueOf(dataTable.getModel().getValueAt(row, 0)); - String locator = String.valueOf(dataTable.getModel().getValueAt(0, 1)); - String channelId = locator + " " + id; - dataTable.setToolTipText(channelId); - if ((e.getClickCount() == 2) && (!e.isPopupTrigger())) { - if (col == 0) { - SwingUtils.showMessage(dataTableDialog, "Channel Identifier", "Copied to clipboard: " + channelId); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - clipboard.setContents(new StringSelection(channelId), (Clipboard clipboard1, Transferable contents) -> { - }); - } else { - Object obj = getCurrentFrame().cache.getValue(id); - if (id.equals("image")) { - } else if (id.equals("processing_parameters")) { - Map pars = getProcessingParameters(getCurrentFrame().cache); - StringBuilder sb = new StringBuilder(); - for (String key : pars.keySet()) { - sb.append(key).append(" = ").append(Str.toString(pars.get(key), 10)).append("\n"); - } - SwingUtils.showMessage(dataTableDialog, "Processing Parameters", sb.toString()); - } else if ((obj != null) && (obj.getClass().isArray() || (obj instanceof Number))) { - DeviceValueChart chart = new DeviceValueChart(); - Device dev = null; - if (obj.getClass().isArray()) { - dev = new ReadableRegisterArray(new ReadableArray() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - - @Override - public int getSize() { - return Array.getLength(getCurrentFrame().cache.getValue(id)); - } - }); - } else { - dev = new ReadableRegisterNumber(new ReadableNumber() { - @Override - public Object read() throws IOException, InterruptedException { - return Convert.toDouble(getCurrentFrame().cache.getValue(id)); - } - }); - } - dev.setPolling(1000); - chart.setDevice(dev); - JDialog dlg = SwingUtils.showDialog(dataTableDialog, cameraName + " " + id, null, chart); - //TODO: - //PlotBase plot = chart.getPlot(); - //if (plot!=null){ - // plot.setPlotBackgroundColor(Color.BLACK); - //} - } - } - } - } - } catch (Exception ex) { - showException(ex); - } - } - }); - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - updateStreamData(); - } - } - - volatile boolean updatingStreamData = false; - - void updateStreamData() { - if ((dataTableDialog == null) || !dataTableDialog.isShowing() || updatingStreamData) { - return; - } - updatingStreamData = true; - SwingUtilities.invokeLater(() -> { - updatingStreamData = false; - if ((dataTableModel != null) && (server != null)) { - StreamValue value = server.getValue(); - Frame frame = getCurrentFrame(); - int[] sel_rows = (dataTable == null) ? null : dataTable.getSelectedRows(); - int[] sel_cols = (dataTable == null) ? null : dataTable.getSelectedColumns(); - List ids = (value == null) ? new ArrayList<>() : new ArrayList(value.getIdentifiers()); - if (ids.size() + 4 != dataTableModel.getRowCount()) { - dataTableModel.setNumRows(0); - try { - dataTableModel.addRow(new Object[]{"Locator", server.getUrl() + "/" + ((value == null) ? instanceName : server.getCurrentInstance())}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Locator", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"Stream", server.getStreamAddress()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Stream", ex.getMessage()}); - } - dataTableModel.addRow(new Object[]{"PID", ""}); - dataTableModel.addRow(new Object[]{"Timestamp", ""}); - Collections.sort(ids); - for (String id : ids) { - dataTableModel.addRow(new Object[]{id, ""}); - } - } - - if ((frame != null) && (frame.cache != null)) { - dataTableModel.setValueAt(frame.cache.getPulseId(), 2, 1); //PID - dataTableModel.setValueAt(frame.cache.getTimestamp(), 3, 1); //Timestamp - for (int i = 4; i < dataTableModel.getRowCount(); i++) { - String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - //Object obj = server.getValue(id); - Object obj = frame.cache.getValue(id); - if (obj != null) { - if (obj.getClass().isArray()) { - obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; - } else if (obj instanceof Double) { - obj = Convert.roundDouble((Double) obj, 1); - } else if (obj instanceof Float) { - obj = Convert.roundDouble((Float) obj, 1); - } - } - dataTableModel.setValueAt(String.valueOf(obj), i, 1); - } - } - if ((sel_rows != null) && (sel_rows.length > 0)) { - //dataTable.setRowSelectionInterval((Integer)Arr.getMin(sel_rows), (Integer)Arr.getMax(sel_rows)); - dataTable.setRowSelectionInterval(sel_rows[0], sel_rows[sel_rows.length - 1]); - } - if ((sel_cols != null) && (sel_cols.length > 0)) { - //dataTable.setColumnSelectionInterval((Integer)Arr.getMin(sel_cols), (Integer)Arr.getMax(sel_cols)); - dataTable.setColumnSelectionInterval(sel_cols[0], sel_cols[sel_cols.length - 1]); - } - } - }); - } - - ImageIcon getIcon(String name) { - ImageIcon ret = null; - try { - //Path path = Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(),"resources", name + ".png"); - String dir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + "resources/"; - if (new File(dir + name + ".png").exists()) { - ret = new javax.swing.ImageIcon(dir + name + ".png"); - } else { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/" + name + ".png")); - if (MainFrame.isDark()) { - try { - ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/dark/" + name + ".png")); - } catch (Exception e) { - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return ret; - } - - String getIconName(JButton button) { - String ret = button.getIcon().toString(); - if (ret.indexOf(".") > 0) { - ret = ret.substring(0, ret.indexOf(".")); - } - return ret; - } - - void setPaused(boolean paused){ - removePauseOverlay(); - if (camera != null) { - synchronized (imageBuffer) { - if (paused) { - renderer.pause(); - panelCameraSelection.setVisible(false); - pauseSelection.setVisible(true); - if (imageBuffer.size() > 0) { - pauseSelection.setEnabled(true); - pauseSelection.setMaxValue(imageBuffer.size()); - pauseSelection.setValue(imageBuffer.size()); - updatePause(); - } else { - pauseSelection.setEnabled(false); - pauseSelection.setMaxValue(1); - pauseSelection.setValue(1); - } - } else { - imageBuffer.clear(); - renderer.resume(); - //renderer.clear(); - pauseSelection.setVisible(false); - panelCameraSelection.setVisible(true); - } - } - updateStreamData(); - } - } - - boolean isPaused(){ - return renderer.isPaused(); - } - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - buttonGroup4 = new javax.swing.ButtonGroup(); - jProgressBar1 = new javax.swing.JProgressBar(); - sidePanel = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - buttonZoomFit = new javax.swing.JRadioButton(); - buttonZoomStretch = new javax.swing.JRadioButton(); - buttonZoomNormal = new javax.swing.JRadioButton(); - buttonZoom025 = new javax.swing.JRadioButton(); - buttonZoom05 = new javax.swing.JRadioButton(); - buttonZoom2 = new javax.swing.JRadioButton(); - jPanel2 = new javax.swing.JPanel(); - checkHistogram = new javax.swing.JCheckBox(); - comboColormap = new javax.swing.JComboBox(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - buttonFullRange = new javax.swing.JRadioButton(); - buttonManual = new javax.swing.JRadioButton(); - buttonAutomatic = new javax.swing.JRadioButton(); - labelMin = new javax.swing.JLabel(); - spinnerMin = new javax.swing.JSpinner(); - spinnerMax = new javax.swing.JSpinner(); - labelMax = new javax.swing.JLabel(); - btFixColormapRange = new javax.swing.JButton(); - jPanel5 = new javax.swing.JPanel(); - buttonServer = new javax.swing.JRadioButton(); - buttonDirect = new javax.swing.JRadioButton(); - textState = new javax.swing.JTextField(); - filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767)); - panelScreen = new javax.swing.JPanel(); - valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); - comboScreen = new javax.swing.JComboBox(); - panelFilter = new javax.swing.JPanel(); - valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); - comboFilter = new javax.swing.JComboBox(); - panelScreen2 = new javax.swing.JPanel(); - checkThreshold = new javax.swing.JCheckBox(); - spinnerThreshold = new javax.swing.JSpinner(); - checkBackground = new javax.swing.JCheckBox(); - checkGoodRegion = new javax.swing.JCheckBox(); - spinnerGrScale = new javax.swing.JSpinner(); - spinnerGrThreshold = new javax.swing.JSpinner(); - labelGrThreshold = new javax.swing.JLabel(); - labelGrScale = new javax.swing.JLabel(); - panelSlicing = new javax.swing.JPanel(); - checkSlicing = new javax.swing.JCheckBox(); - labelSlScale = new javax.swing.JLabel(); - spinnerSlScale = new javax.swing.JSpinner(); - labelSlNumber = new javax.swing.JLabel(); - spinnerSlNumber = new javax.swing.JSpinner(); - labelSlOrientation = new javax.swing.JLabel(); - spinnerSlOrientation = new javax.swing.JSpinner(); - topPanel = new javax.swing.JPanel(); - toolBar = new javax.swing.JToolBar(); - buttonSidePanel = new javax.swing.JToggleButton(); - buttonStreamData = new javax.swing.JButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - buttonPause = new javax.swing.JToggleButton(); - jSeparator6 = new javax.swing.JToolBar.Separator(); - buttonMarker = new javax.swing.JToggleButton(); - buttonProfile = new javax.swing.JToggleButton(); - buttonFit = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonScale = new javax.swing.JToggleButton(); - buttonTitle = new javax.swing.JToggleButton(); - pauseSelection = new ch.psi.pshell.swing.ValueSelection(); - panelCameraSelection = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - jLabel5 = new javax.swing.JLabel(); - comboType = new javax.swing.JComboBox(); - renderer = new ch.psi.pshell.imaging.Renderer(); - - setPreferredSize(new java.awt.Dimension(873, 600)); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); - - buttonGroup1.add(buttonZoomFit); - buttonZoomFit.setText("Fit"); - buttonZoomFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomFitActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomStretch); - buttonZoomStretch.setText("Stretch"); - buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomStretchActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomNormal); - buttonZoomNormal.setText("Normal"); - buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomNormalActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("1/4"); - buttonZoom025.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom025ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("1/2"); - buttonZoom05.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom05ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom2); - buttonZoom2.setText("2"); - buttonZoom2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoomStretch)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05) - .addComponent(buttonZoom2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomFit) - .addComponent(buttonZoom05)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoom2)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap")); - - checkHistogram.setText("Histogram"); - checkHistogram.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkHistogramActionPerformed(evt); - } - }); - - comboColormap.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Type:"); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Range:"); - - buttonGroup3.add(buttonFullRange); - buttonFullRange.setText("Full"); - buttonFullRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonManual); - buttonManual.setText("Manual"); - buttonManual.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonAutomatic); - buttonAutomatic.setText("Automatic"); - buttonAutomatic.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - labelMin.setText("Min:"); - - spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); - spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); - spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - labelMax.setText("Max:"); - - btFixColormapRange.setText("Fix"); - btFixColormapRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btFixColormapRangeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonAutomatic) - .addComponent(buttonFullRange) - .addComponent(buttonManual) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMax) - .addGap(2, 2, 2) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMin) - .addGap(2, 2, 2) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(spinnerMin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFixColormapRange, spinnerMax, spinnerMin}); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3) - .addComponent(checkHistogram)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAutomatic) - .addComponent(jLabel4) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelMin) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonFullRange)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonManual) - .addComponent(labelMax) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - - buttonGroup4.add(buttonServer); - buttonServer.setSelected(true); - buttonServer.setText("Server"); - buttonServer.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonServerActionPerformed(evt); - } - }); - - buttonGroup4.add(buttonDirect); - buttonDirect.setText("Direct"); - buttonDirect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDirectActionPerformed(evt); - } - }); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonServer) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonDirect) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(56, 56, 56)) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonServer) - .addComponent(buttonDirect))) - .addContainerGap()) - ); - - panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); - - comboScreen.setEnabled(false); - comboScreen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboScreenActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); - panelScreen.setLayout(panelScreenLayout); - panelScreenLayout.setHorizontalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreenLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreenLayout.setVerticalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelFilter.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); - - comboFilter.setEnabled(false); - comboFilter.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboFilterActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelFilterLayout = new javax.swing.GroupLayout(panelFilter); - panelFilter.setLayout(panelFilterLayout); - panelFilterLayout.setHorizontalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelFilterLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelFilterLayout.setVerticalGroup( - panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFilterLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - panelScreen2.setBorder(javax.swing.BorderFactory.createTitledBorder("Pipeline")); - - checkThreshold.setText("Threshold"); - checkThreshold.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkThresholdActionPerformed(evt); - } - }); - - spinnerThreshold.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 99999.0d, 1.0d)); - spinnerThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerThresholdonChange(evt); - } - }); - - checkBackground.setText("Subtract Background"); - checkBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkBackgroundActionPerformed(evt); - } - }); - - checkGoodRegion.setText("Good Region"); - checkGoodRegion.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkGoodRegionActionPerformed(evt); - } - }); - - spinnerGrScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerGrScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - spinnerGrThreshold.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.04d, 1.0d, 0.1d)); - spinnerGrThreshold.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerGrThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - labelGrThreshold.setText("Threshold:"); - - labelGrScale.setText("Scale:"); - - checkSlicing.setText("Slicing"); - checkSlicing.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkSlicingActionPerformed(evt); - } - }); - - labelSlScale.setText("Scale:"); - - spinnerSlScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 99999.0d, 1.0d)); - spinnerSlScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlNumber.setText("Slices:"); - - spinnerSlNumber.setModel(new javax.swing.SpinnerNumberModel(2, 0, 1000, 1)); - spinnerSlNumber.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlNumber.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - labelSlOrientation.setText("Orientation:"); - - spinnerSlOrientation.setModel(new javax.swing.SpinnerListModel(new String[] {"vertical", "horizontal"})); - spinnerSlOrientation.setPreferredSize(new java.awt.Dimension(92, 20)); - spinnerSlOrientation.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerSlicingChange(evt); - } - }); - - javax.swing.GroupLayout panelSlicingLayout = new javax.swing.GroupLayout(panelSlicing); - panelSlicing.setLayout(panelSlicingLayout); - panelSlicingLayout.setHorizontalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addComponent(checkSlicing) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlNumber) - .addGap(2, 2, 2) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addComponent(labelSlScale) - .addGap(2, 2, 2) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSlicingLayout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelSlOrientation) - .addGap(2, 2, 2) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - panelSlicingLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerSlNumber, spinnerSlOrientation, spinnerSlScale}); - - panelSlicingLayout.setVerticalGroup( - panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(checkSlicing) - .addGroup(panelSlicingLayout.createSequentialGroup() - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlNumber)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlScale)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSlicingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerSlOrientation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelSlOrientation))) - ); - - javax.swing.GroupLayout panelScreen2Layout = new javax.swing.GroupLayout(panelScreen2); - panelScreen2.setLayout(panelScreen2Layout); - panelScreen2Layout.setHorizontalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkThreshold) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addComponent(checkGoodRegion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(labelGrScale)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelGrThreshold))) - .addGap(2, 2, 2))) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - .addComponent(panelSlicing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addGap(6, 6, 6) - .addComponent(checkBackground) - .addGap(106, 106, 106)) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerThreshold}); - - panelScreen2Layout.setVerticalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(checkBackground) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkThreshold) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkGoodRegion) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrScale)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrThreshold)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelSlicing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - javax.swing.GroupLayout sidePanelLayout = new javax.swing.GroupLayout(sidePanel); - sidePanel.setLayout(sidePanelLayout); - sidePanelLayout.setHorizontalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - sidePanelLayout.setVerticalGroup( - sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(sidePanelLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - toolBar.setFloatable(false); - toolBar.setRollover(true); - - buttonSidePanel.setIcon(getIcon("List")); - buttonSidePanel.setSelected(true); - buttonSidePanel.setText(" "); - buttonSidePanel.setToolTipText("Show Side Panel"); - buttonSidePanel.setFocusable(false); - buttonSidePanel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSidePanel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSidePanelActionPerformed(evt); - } - }); - toolBar.add(buttonSidePanel); - - buttonStreamData.setIcon(getIcon("Details")); - buttonStreamData.setText(" "); - buttonStreamData.setToolTipText("Show Data Window"); - buttonStreamData.setFocusable(false); - buttonStreamData.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonStreamData.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStreamDataActionPerformed(evt); - } - }); - toolBar.add(buttonStreamData); - - buttonSave.setIcon(getIcon("Save")); - buttonSave.setText(" "); - buttonSave.setToolTipText("Save Snapshot"); - buttonSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - toolBar.add(buttonSave); - - buttonGrabBackground.setIcon(getIcon("Background")); - buttonGrabBackground.setText(" "); - buttonGrabBackground.setToolTipText("Grab Background"); - buttonGrabBackground.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - toolBar.add(buttonGrabBackground); - - buttonPause.setIcon(getIcon("Pause")); - buttonPause.setText(" "); - buttonPause.setToolTipText("Pause"); - buttonPause.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - toolBar.add(buttonPause); - - jSeparator6.setMaximumSize(new java.awt.Dimension(20, 32767)); - jSeparator6.setPreferredSize(new java.awt.Dimension(20, 0)); - jSeparator6.setRequestFocusEnabled(false); - toolBar.add(jSeparator6); - - buttonMarker.setIcon(getIcon("Marker")); - buttonMarker.setText(" "); - buttonMarker.setToolTipText("Show Marker"); - buttonMarker.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - toolBar.add(buttonMarker); - - buttonProfile.setIcon(getIcon("Profile" - + "")); - buttonProfile.setSelected(true); - buttonProfile.setText(" "); - buttonProfile.setToolTipText("Show Image Profile"); - buttonProfile.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonProfile.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonProfileActionPerformed(evt); - } - }); - toolBar.add(buttonProfile); - - buttonFit.setIcon(getIcon("Fit")); - buttonFit.setSelected(true); - buttonFit.setText(" "); - buttonFit.setToolTipText("Show Fit"); - buttonFit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - toolBar.add(buttonFit); - - buttonReticle.setIcon(getIcon("Reticule")); - buttonReticle.setSelected(true); - buttonReticle.setText(" "); - buttonReticle.setToolTipText("Show Reticle"); - buttonReticle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - toolBar.add(buttonReticle); - - buttonScale.setIcon(getIcon("Scale")); - buttonScale.setSelected(true); - buttonScale.setText(" "); - buttonScale.setToolTipText("Show Colormap Scale"); - buttonScale.setFocusable(false); - buttonScale.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonScale.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonScaleActionPerformed(evt); - } - }); - toolBar.add(buttonScale); - - buttonTitle.setIcon(getIcon("Title")); - buttonTitle.setSelected(true); - buttonTitle.setText(" "); - buttonTitle.setToolTipText("Show Camera Name"); - buttonTitle.setFocusable(false); - buttonTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - buttonTitle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonTitleActionPerformed(evt); - } - }); - toolBar.add(buttonTitle); - - pauseSelection.setDecimals(0); - - jLabel1.setText("Camera:"); - - comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboCameras.setMaximumRowCount(30); - comboCameras.setMinimumSize(new java.awt.Dimension(127, 27)); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - jLabel5.setText("Type:"); - - comboType.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N - comboType.setMaximumRowCount(30); - comboType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Laser", "Electrons", "Photonics" })); - comboType.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboTypeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelCameraSelectionLayout = new javax.swing.GroupLayout(panelCameraSelection); - panelCameraSelection.setLayout(panelCameraSelectionLayout); - panelCameraSelectionLayout.setHorizontalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addGap(0, 0, 0) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - panelCameraSelectionLayout.setVerticalGroup( - panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCameraSelectionLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel5) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0)) - ); - - javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel); - topPanel.setLayout(topPanelLayout); - topPanelLayout.setHorizontalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup() - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - topPanelLayout.setVerticalGroup( - topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(topPanelLayout.createSequentialGroup() - .addGap(1, 1, 1) - .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(sidePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(topPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(sidePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - }// //GEN-END:initComponents - - private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed - try { - renderer.setMode(RendererMode.Fit); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomFitActionPerformed - - private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed - try { - renderer.setMode(RendererMode.Stretch); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomStretchActionPerformed - - private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed - try { - renderer.setMode(RendererMode.Fixed); - centralizeRenderer(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomNormalActionPerformed - - private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap - try { - if ((camera != null) && (camera instanceof ColormapSource) && !updatingColormap) { - ColormapSource source = (ColormapSource) camera; - Color colorReticule = new Color(16, 16, 16); - Color colorMarker = new Color(128, 128, 128); - Colormap colormap = (Colormap) comboColormap.getSelectedItem(); - source.getConfig().colormap = (colormap == null) ? Colormap.Flame : colormap; - switch (source.getConfig().colormap) { - case Grayscale: - case Inverted: - case Red: - case Green: - case Blue: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - case Flame: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - } - - renderer.setPenReticle(new Pen(colorReticule)); - renderer.setPenProfile(new Pen(colorReticule, 0)); - renderer.setPenMarker(new Pen(colorMarker, 2)); - renderer.setShowReticle(false); - checkReticle(); - source.getConfig().colormapAutomatic = buttonAutomatic.isSelected(); - source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); - source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); - try { - source.getConfig().save(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - } - source.refresh(); - if (buttonPause.isSelected()) { - updatePause(); - } - updateColormap(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_onChangeColormap - - private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange - onChangeColormap(null); - }//GEN-LAST:event_onChangeColormapRange - - private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed - renderer.setZoom(0.25); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom025ActionPerformed - - private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed - renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom05ActionPerformed - - private void buttonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonServerActionPerformed - if (!usingServer) { - usingServer = true; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonServerActionPerformed - - private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingServer) { - usingServer = false; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonDirectActionPerformed - - private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed - - comboScreen.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - ChannelInteger setpoint = null; - try { - int index = comboScreen.getSelectedIndex(); - if (index >= 0) { - if (cameraName.contains("DSRM")) { - setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); - } else { - setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); - } - setpoint.initialize(); - Integer readback = setpoint.read(); - if ((readback == null) || (setpoint.read() != index)) { - setpoint.write(index); - //Must be threaded to control the laser because of sleep in setLaserState - /* - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - setpoint.write(index); - } finally { - if (laserOn) { - setLaserState(true); - } - } - */ - } - screen.read(); - } - } catch (Exception ex) { - showException(ex); - } finally { - comboScreen.setEnabled(true); - if (setpoint != null) { - setpoint.close(); - } - } - } - }).start(); - }//GEN-LAST:event_comboScreenActionPerformed - - private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed - try { - String setpoint = (String) comboFilter.getSelectedItem(); - if (setpoint != null) { - if (!setpoint.equals(filter.read())) { - filter.write(setpoint); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboFilterActionPerformed - - private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed - try { - setHistogramVisible(checkHistogram.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_checkHistogramActionPerformed - - private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed - renderer.setZoom(2.0); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom2ActionPerformed - - private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setThreshold((Double) spinnerThreshold.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerThresholdonChange - - private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (server != null) { - if (!updatingServerControls) { - try { - if (server.isStarted()) { - server.setBackgroundSubtraction(checkBackground.isSelected()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - updatingServerControls = true; - checkBackground.setSelected(false); - updatingServerControls = false; - - } - } - } else { - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - }//GEN-LAST:event_checkBackgroundActionPerformed - - private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - spinnerThreshold.setVisible(checkThreshold.isSelected()); - server.setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkThresholdActionPerformed - - private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - goodRegion = checkGoodRegion.isSelected(); - setGoodRegionOptionsVisible(goodRegion); - if (goodRegion) { - server.setGoodRegion(((Number) spinnerGrThreshold.getValue()).doubleValue(), ((Number) spinnerGrScale.getValue()).doubleValue()); - } else { - server.setGoodRegion(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkGoodRegionActionPerformed - - private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setGoodRegion((Double) spinnerGrThreshold.getValue(), (Double) spinnerGrScale.getValue()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerGrThresholdonChange - - private void btFixColormapRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFixColormapRangeActionPerformed - try { - updatingColormap = true; - ArrayProperties properties = currentFrame.data.getProperties(); - spinnerMax.setValue(properties.max.intValue()); - spinnerMin.setValue(properties.min.intValue()); - buttonManual.setSelected(true); - } catch (Exception ex) { - showException(ex); - } finally { - updatingColormap = false; - onChangeColormap(null); - } - }//GEN-LAST:event_btFixColormapRangeActionPerformed - - private void checkSlicingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSlicingActionPerformed - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - slicing = checkSlicing.isSelected(); - setSlicingOptionsVisible(slicing); - if (slicing) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } else { - server.setSlicing(null); - } - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_checkSlicingActionPerformed - - private void spinnerSlicingChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerSlicingChange - if (!updatingServerControls) { - try { - if ((server != null) && (server.isStarted())) { - server.setSlicing((Integer) spinnerSlNumber.getValue(), (Double) spinnerSlScale.getValue(), spinnerSlOrientation.getValue().toString()); - } - } catch (Exception ex) { - showException(ex); - updatePipelineControls(); - } - } - }//GEN-LAST:event_spinnerSlicingChange - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - showFit = buttonFit.isSelected(); - if (showFit) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed - try { - showProfile = buttonProfile.isSelected(); - if (showProfile) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(profileOv); - profileOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonProfileActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - checkMarker(null); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - if (!updatingButtons) { - setPaused(buttonPause.isSelected()); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera != null) { - boolean laserOn = getLaserState(); - OptionResult ret = null; - if (laserOn) { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put laser on delay for capturing background?", OptionType.YesNoCancel); - if (ret == OptionResult.No) { - laserOn = false; - } - } else { - ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to capture background now?", OptionType.OkCancel); - } - - if (ret == OptionResult.Cancel) { - return; - } - - if (laserOn) { - setLaserState(false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - if (server != null) { - server.captureBackground(5); - } else { - camera.captureBackground(5, 0); - } - } finally { - if (laserOn) { - setLaserState(true); - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - saveSnapshot(); - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex); - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonStreamDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStreamDataActionPerformed - try { - showStreamData(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonStreamDataActionPerformed - - private void buttonSidePanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSidePanelActionPerformed - sidePanel.setVisible(buttonSidePanel.isSelected()); - }//GEN-LAST:event_buttonSidePanelActionPerformed - - private void comboTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTypeActionPerformed - try { - if (!updatingCameraSelection) { - updateCameraList(); - if ((cameraName != null) && (!cameraName.equals(comboCameras.getSelectedItem()))) { - setCamera(null); - } else { - setCamera(cameraName); - } - } - - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - } - }//GEN-LAST:event_comboTypeActionPerformed - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - if (!updatingCameraSelection) { - if (!comboCameras.isEnabled()) { - throw new Exception("Invalid state"); - } - comboCameras.setEnabled(false); - comboType.setEnabled(false); - buttonServer.setEnabled(false); - buttonDirect.setEnabled(false); - final String cameraName = (String) comboCameras.getSelectedItem(); - new Thread(new Runnable() { - @Override - public void run() { - if (requestCameraListUpdate) { - requestCameraListUpdate = false; - try { - updateCameraList(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - try { - setCamera(cameraName.trim().isEmpty() ? null : cameraName); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateButtons(); - comboCameras.setEnabled(true); - comboType.setEnabled(true); - buttonServer.setEnabled(true); - buttonDirect.setEnabled(true); - } - } - }).start(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTitleActionPerformed - try { - manageTitleOverlay(); - } catch (Exception ex) { - showException(ex); - } finally { - } - }//GEN-LAST:event_buttonTitleActionPerformed - - private void buttonScaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScaleActionPerformed - try { - renderer.setShowColormapScale(buttonScale.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonScaleActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btFixColormapRange; - private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonDirect; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JRadioButton buttonFullRange; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JRadioButton buttonManual; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonProfile; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JToggleButton buttonScale; - private javax.swing.JRadioButton buttonServer; - private javax.swing.JToggleButton buttonSidePanel; - private javax.swing.JButton buttonStreamData; - private javax.swing.JToggleButton buttonTitle; - private javax.swing.JRadioButton buttonZoom025; - private javax.swing.JRadioButton buttonZoom05; - private javax.swing.JRadioButton buttonZoom2; - private javax.swing.JRadioButton buttonZoomFit; - private javax.swing.JRadioButton buttonZoomNormal; - private javax.swing.JRadioButton buttonZoomStretch; - private javax.swing.JCheckBox checkBackground; - private javax.swing.JCheckBox checkGoodRegion; - private javax.swing.JCheckBox checkHistogram; - private javax.swing.JCheckBox checkSlicing; - private javax.swing.JCheckBox checkThreshold; - private javax.swing.JComboBox comboCameras; - private javax.swing.JComboBox comboColormap; - private javax.swing.JComboBox comboFilter; - private javax.swing.JComboBox comboScreen; - private javax.swing.JComboBox comboType; - private javax.swing.Box.Filler filler1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel5; - private javax.swing.JProgressBar jProgressBar1; - private javax.swing.JToolBar.Separator jSeparator6; - private javax.swing.JLabel labelGrScale; - private javax.swing.JLabel labelGrThreshold; - private javax.swing.JLabel labelMax; - private javax.swing.JLabel labelMin; - private javax.swing.JLabel labelSlNumber; - private javax.swing.JLabel labelSlOrientation; - private javax.swing.JLabel labelSlScale; - private javax.swing.JPanel panelCameraSelection; - private javax.swing.JPanel panelFilter; - private javax.swing.JPanel panelScreen; - private javax.swing.JPanel panelScreen2; - private javax.swing.JPanel panelSlicing; - private ch.psi.pshell.swing.ValueSelection pauseSelection; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JPanel sidePanel; - private javax.swing.JSpinner spinnerGrScale; - private javax.swing.JSpinner spinnerGrThreshold; - private javax.swing.JSpinner spinnerMax; - private javax.swing.JSpinner spinnerMin; - private javax.swing.JSpinner spinnerSlNumber; - private javax.swing.JSpinner spinnerSlOrientation; - private javax.swing.JSpinner spinnerSlScale; - private javax.swing.JSpinner spinnerThreshold; - private javax.swing.JTextField textState; - private javax.swing.JToolBar toolBar; - private javax.swing.JPanel topPanel; - private ch.psi.pshell.swing.DeviceValuePanel valueFilter; - private ch.psi.pshell.swing.DeviceValuePanel valueScreen; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/ScreenPanelOld.form b/plugins/ScreenPanelOld.form deleted file mode 100755 index 21f7673..0000000 --- a/plugins/ScreenPanelOld.form +++ /dev/null @@ -1,957 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/ScreenPanelOld.java b/plugins/ScreenPanelOld.java deleted file mode 100755 index ac33de4..0000000 --- a/plugins/ScreenPanelOld.java +++ /dev/null @@ -1,3071 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.core.Context; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.Camtool; -import ch.psi.pshell.bs.StreamValue; -import ch.psi.pshell.device.DescStatsDouble; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.DiscretePositioner; -import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.imaging.Calibration; -import ch.psi.pshell.imaging.Colormap; -import ch.psi.pshell.imaging.ColormapSource; -import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.DimensionDouble; -import ch.psi.pshell.imaging.Histogram; -import ch.psi.pshell.imaging.ImageBuffer; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.PointDouble; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Convert; -import ch.psi.utils.TcpClient; -import ch.psi.utils.swing.Editor.EditorDialog; -import ch.psi.utils.swing.MainFrame; -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.StandardDialog.StandardDialogListener; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.FileInputStream; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.net.ServerSocket; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.table.DefaultTableModel; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; - -/** - * - */ -public class ScreenPanelOld extends Panel { - - final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useCamtoolStats = true; - - String userOverlaysConfigFile; - ColormapSource camera; - String cameraName; - String cameraConfigJson; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - boolean showProfile; - Overlay[] userOv; - Overlay[] fitOv; - Overlay[] profileOv; - Overlay errorOverlay; - boolean requestCameraListUpdate; - Integer localServerPort; - Process privateServer; - String serverUrl; - boolean goodRegion; - - Double getCamtoolDouble(String name) { - return (Double) Convert.toDouble(((Camtool) camera).getValue(name)); - } - - double[] getCamtoolDoubleArray(String name) { - return (double[]) Convert.toDouble(((Camtool) camera).getValue(name)); - } - - Double getCamtoolDouble(String name, StreamValue cache) { - return (Double) Convert.toDouble(cache.__getitem__(name)); - } - - double[] getCamtoolDoubleArray(String name, StreamValue cache) { - return (double[]) Convert.toDouble(cache.__getitem__(name)); - } - - - class ImageData { - ImageData(){ - if (camera instanceof Camtool) { - StreamValue cache = ((Camtool) camera).getStream().take(); - - String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getCamtoolDouble(prefix + "x_fit_mean", cache); - y_fit_mean = getCamtoolDouble(prefix + "y_fit_mean", cache); - x_fit_standard_deviation = getCamtoolDouble(prefix + "x_fit_standard_deviation", cache); - y_fit_standard_deviation = getCamtoolDouble(prefix + "y_fit_standard_deviation", cache); - x_fit_gauss_function = getCamtoolDoubleArray(prefix +"x_fit_gauss_function", cache); - y_fit_gauss_function = getCamtoolDoubleArray(prefix +"y_fit_gauss_function", cache); - x_profile = getCamtoolDoubleArray("x_profile", cache); - y_profile = getCamtoolDoubleArray("y_profile", cache); - x_center_of_mass = getCamtoolDouble("x_center_of_mass", cache); - y_center_of_mass = getCamtoolDouble("y_center_of_mass", cache); - x_rms = getCamtoolDouble("x_rms", cache); - y_rms = getCamtoolDouble("y_rms", cache); - if (goodRegion){ - double[] gX2 = new double[x_profile.length]; - Arrays.fill(gX2, Double.NaN); - try{ - double x = getCamtoolDoubleArray("gr_x_axis", cache)[0]; - System.arraycopy(x_fit_gauss_function, 0, gX2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x): x), x_fit_gauss_function.length); - } catch (Exception ex){ - } - x_fit_gauss_function = gX2; - double[] gY2 = new double[y_profile.length]; - Arrays.fill(gY2, Double.NaN); - try{ - double y = getCamtoolDoubleArray("gr_y_axis", cache)[0]; - System.arraycopy(y_fit_gauss_function, 0, gY2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageY(y): y), y_fit_gauss_function.length); - } catch (Exception ex){ - } - y_fit_gauss_function = gY2; - } - } - } - public Double x_fit_mean; - public Double y_fit_mean; - public Double x_center_of_mass; - public Double x_rms; - public Double x_fit_standard_deviation; - public Double y_fit_standard_deviation; - public Double y_center_of_mass; - public Double y_rms; - public double[] x_profile; - public double[] x_fit_gauss_function; - public double[] y_profile; - public double[] y_fit_gauss_function; - - } - - class Frame extends ImageData{ - - Frame(Data data) { - this.data = data; - } - Data data; - } - - final ArrayList imageBuffer = new ArrayList(); - Frame currentFrame; - int imageBufferLenght = 0; - Text imageBufferOverlay; - - public ScreenPanelOld() { - initComponents(); - spinnerThreshold.setVisible(false); - btFixColormapRange.setVisible(false); - spinnerGrThreshold.setVisible(false); labelGrThreshold.setVisible(false); - spinnerGrScale.setVisible(false); labelGrScale.setVisible(false); - //spinnerMin.setVisible(false); labelMin.setVisible(false); - //spinnerMax.setVisible(false); labelMax.setVisible(false); - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - setPersistedComponents(new Component[]{buttonCamtool, buttonDirect}); - comboCameras.setEnabled(false); - SwingUtils.setEnumCombo(comboColormap, Colormap.class); - if (App.hasArgument("poll")) { - try { - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try { - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("buf")) { - try { - imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("usr_ov")) { - try { - userOverlaysConfigFile = App.getArgumentValue("usr_ov"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("priv_srv")) { - try { - try(ServerSocket s = new ServerSocket(0)){ - localServerPort = s.getLocalPort(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_port")) { - localServerPort = Integer.valueOf(App.getArgumentValue("srv_port")); - } - - if (App.hasArgument("srv_url")) { - serverUrl = App.getArgumentValue("srv_url"); - } - - if (App.hasArgument("calc")) { - useCamtoolStats = false; - } - - renderer.setProfileNormalized(true); - renderer.setShowProfileLimits(false); - - JMenuItem menuCalibrate = new JMenuItem("Calibrate..."); - menuCalibrate.addActionListener((ActionEvent e) -> { - try { - calibrate(); - } catch (Exception ex) { - ex.printStackTrace(); - showException(ex); - } - }); - - JMenuItem menuShowImageData = new JMenuItem("Show Image Data"); - menuShowImageData.addActionListener((ActionEvent e) -> { - try { - showImageData(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSaveStack = new JMenuItem("Save Stack"); - menuSaveStack.addActionListener((ActionEvent e) -> { - try { - saveStack(); - } catch (Exception ex) { - showException(ex); - } - }); - menuSaveStack.setEnabled(imageBufferLenght > 0); - - JMenuItem menuSetROI = new JMenuItem("Set ROI..."); - menuSetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (camera instanceof Camtool) { - final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); - renderer.addListener(new RendererListener() { - @Override - public void onSelectionFinished(Renderer renderer, Overlay overlay) { - try { - renderer.setShowReticle(false); - Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (((Camtool) camera).isRoiEnabled()) { - int[] cur = ((Camtool) camera).getRoi(); - ((Camtool) camera).setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); - } else { - ((Camtool) camera).setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); - } - } catch (Exception ex) { - } finally { - renderer.removeListener(this); - } - } - - @Override - public void onSelectionAborted(Renderer renderer, Overlay overlay) { - renderer.removeListener(this); - } - }); - selection.setFixed(true); - renderer.startSelection(selection); - } - }); - - JMenuItem menuResetROI = new JMenuItem("Reset ROI"); - menuResetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (camera instanceof Camtool) { - try { - renderer.setShowReticle(false); - ((Camtool) camera).resetRoi(); - } catch (IOException ex) { - showException(ex); - } - } - }); - - renderer.getPopupMenu().add(menuShowImageData); - renderer.getPopupMenu().add(menuCalibrate); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuSetROI); - renderer.getPopupMenu().add(menuResetROI); - renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(camera instanceof Camtool); - menuSetROI.setEnabled(camera instanceof Camtool); - menuShowImageData.setVisible(camera instanceof Camtool); - menuCalibrate.setVisible(camera instanceof Camtool); - menuCalibrate.setEnabled((calibrationDialolg==null) || (!calibrationDialolg.isShowing()) ); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - } - }); - renderer.getPopupMenu().setVisible(false); - - showFit = buttonFit.isSelected(); - showProfile = buttonProfile.isSelected(); - - pauseSelection.setVisible(false); - pauseSelection.setMinValue(1); - pauseSelection.addListener(new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - if (editing && (value >= 1) && (value <= imageBuffer.size())) { - updatePause(); - } - } - }); - imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 20)); - imageBufferOverlay.setFixed(true); - imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_RIGHT); - if (MainFrame.isDark()) { - textState.setEnabled(true); - } - } - - @Override - public void onStart() { - super.onStart(); - if (App.hasArgument("ct")) { - boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonCamtool.setSelected(!direct); - buttonDirect.setSelected(direct); - } - if (App.hasArgument("priv_srv")) { - try { - System.out.println("Starting camtool server on port: " + localServerPort); - //Was creating sub-processes which cannot be destroyed. - //String cmd = "cam_server"; - //cmd = "source /opt/gfa/python\n" + cmd; - //privateServer = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd}); - String cmd = "/opt/gfa/python-3.5/2.4.1/bin/python /opt/gfa/python-3.5/latest/bin/cam_server"; - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - cmd = cmd + " -p " + localServerPort + " -b " + configFolder; - privateServer = Runtime.getRuntime().exec(cmd); - //System.out.println("pid = " + Sys.getPid(privateServer)); - long start = System.currentTimeMillis(); - while (true){ - try (TcpClient c = new TcpClient("localhost", localServerPort)){ - try{ - c.connect(); - System.out.println("Connected to camtool server on port: " + localServerPort); - break; - } catch (Exception ex){ - } - } - Thread.sleep(10); - if ((System.currentTimeMillis() - start) > 5000){ - errorOverlay = new Text(renderer.getPenErrorText(), "Error connecting to server at port " + localServerPort , new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - renderer.addOverlay(errorOverlay); - break; - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - } - - - - @Override - public void onStop() { - try{ - if (camera != null) { - camera.close(); - camera = null; - } - if (privateServer!=null){ - System.out.println("Closing camtool server"); - //int pid = Sys.getPid(privateServer); - privateServer.destroyForcibly(); - //if (pid>0){ - // System.out.println("Killing pid = " + pid); - // Runtime.getRuntime().exec("kill " + pid); - // - //} - privateServer = null; - } - } catch (Exception ex) { - ex.printStackTrace(); - } - super.onStop(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - if (App.hasArgument("s")) { - renderer.setDevice((Source) getDevice("image")); - renderer.setAutoScroll(true); - ((Source) getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - manageFit(bi, data); - manageUserOverlays(bi, data); - } - - @Override - public void onError(Object o, Exception ex) { - } - } - ); - - } else { - usingCamtool = buttonCamtool.isSelected(); - updateCameraList(); - comboCameras.setEnabled(true); - setComboCameraSelection(-1); - - if (comboCameras.getModel().getSize() > 0) { - try { - if (App.hasArgument("cam")) { - setComboCameraSelection(App.getArgumentValue("cam")); - comboCamerasActionPerformed(null); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - startTimer(1000); - } - - DefaultComboBoxModel getCameraListFromFolder() throws Exception { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String cam:cameras) { - model.addElement(cam); - } - return model; - } - - DefaultComboBoxModel getCameraListFromCamtool() throws IOException, InterruptedException { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - Camtool camtool = newCamtool(); - try { - camtool.initialize(); - List cameras = camtool.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - model.addElement(camera); - } - //model.addElement(Camtool.SIMULATION); - } finally { - camtool.close(); - } - return model; - } - - Camtool newCamtool(){ - if (serverUrl!=null){ - return new Camtool(CAMERA_DEVICE_NAME, serverUrl); - } - return (localServerPort != null) ? new Camtool(CAMERA_DEVICE_NAME, "localhost:"+localServerPort) : new Camtool(CAMERA_DEVICE_NAME); - } - - boolean updatingCameraSelection; - - void setComboCameraSelection(Object selection) { - updatingCameraSelection = true; - try { - comboCameras.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - - boolean usingCamtool; - - void updateCameraList() { - try { - String selected = (String) comboCameras.getSelectedItem(); - DefaultComboBoxModel model = usingCamtool ? getCameraListFromCamtool() : getCameraListFromFolder(); - if (App.hasArgument("cam")) { - String cam = App.getArgumentValue("cam"); - if (model.getIndexOf(cam) < 0) { - model.addElement(cam); - } - } - comboCameras.setModel(model); - if (selected != null) { - setComboCameraSelection(selected); - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateStop(); - } - } - - final Object lockOverlays = new Object(); - - void manageFit(BufferedImage bi, Data data) { - Overlay[][] fo = ((bi == null) || ((!showFit && !showProfile))) ? null : getFitOverlays(data); - synchronized(lockOverlays){ - fo = (fo==null) ? new Overlay[][]{null, null} : fo; - renderer.updateOverlays(fo[0], profileOv); - profileOv = fo[0]; - renderer.updateOverlays(fo[1], fitOv); - fitOv = fo[1]; - } - } - - void manageUserOverlays(BufferedImage bi, Data data) { - Overlay[] fo = (bi == null) ? null : getUserOverlays(data); - synchronized(lockOverlays){ - renderer.updateOverlays(fo, userOv); - userOv = fo; - } - } - - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - Thread devicesInitTask; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Setting camera: " + cameraName + " [" + (buttonCamtool.isSelected() ? "camtool" : "direct") + "]"); - parseUserOverlays(); - errorOverlay = null; - - if (dataTableDialog!=null){ - dataTableDialog.dispose(); - dataTableDialog = null; - } - dataTableModel = null; - - if (calibrationDialolg!=null){ - calibrationDialolg.dispose(); - calibrationDialolg = null; - } - - boolean was_camtool = false; - if (camera != null) { - //camera.removeAllListeners(); - was_camtool = camera instanceof Camtool; - camera.close(); - camera = null; - } - renderer.setDevice(null); - - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.removeOverlays(profileOv); - renderer.removeOverlays(userOv); - renderer.clear(); - renderer.resetZoom(); - - boolean changed = !String.valueOf(cameraName).equals(this.cameraName); - this.cameraName = cameraName; - - if (changed || buttonDirect.isSelected()) { - spinnerThreshold.setVisible(false); - spinnerGrThreshold.setVisible(false); labelGrThreshold.setVisible(false); - spinnerGrScale.setVisible(false); labelGrScale.setVisible(false); - checkThreshold.setEnabled(false); - checkGoodRegion.setEnabled(false); - } - if (changed) { - checkBackground.setEnabled(false); - if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { - devicesInitTask.interrupt(); - } - if (screen != null) { - screen.close(); - screen = null; - } - if (filter != null) { - filter.close(); - filter = null; - } - } - if (cameraName == null) { - return; - } - - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - - - try { - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - - if (buttonCamtool.isSelected()) { - camera = newCamtool(); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - //camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName); - camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName}); - } - camera.initialize(); - camera.assertInitialized(); - System.out.println("Camera initialization OK"); - if (camera instanceof Camtool) { - //Managing no background exception. Can be done in a better way? -// if (changed) { - ((Camtool) camera).startPipeline(cameraName, null); - updateCamtoolControls(); -// } else { -// ((Camtool) camera).startPipeline(cameraName, null, checkBackground.isSelected(), null, null, null); -// } - // HashMap gr = null; - // if (goodRegion){ - // gr = new HashMap<>(); - // gr.put("threshold", spinnerGrThreshold.getValue()); - // gr.put("gfscale", spinnerGrScale.getValue()); - // } - // ((Camtool) camera).startPipeline(cameraName, null, checkBackground.isSelected(), null, checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null, gr); - //} - - checkThreshold.setEnabled(true); - checkGoodRegion.setEnabled(true); - - ((Camtool) camera).startReceiver(); - } else { - checkThreshold.setSelected(false); - checkGoodRegion.setSelected(false); - if (polling <= 0) { - camera.setMonitored(true); - } else { - camera.setPolling(polling); - } - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - - buttonReticle.setEnabled(camera.getConfig().isCalibrated()); - camera.getConfig().save(); - renderer.setDevice(camera); - renderer.setAutoScroll(true); - renderer.setMarker(marker); - imageSize = null; - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi != null) { - if ((imageSize== null) || imageSize.width!=bi.getWidth() || imageSize.height!=bi.getHeight()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { - centralizeRenderer(); - } - checkReticle(); - } - }); - imageSize = new Dimension (bi.getWidth(), bi.getHeight()); - } - renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); - } - //renderer.setCalibration(camera.getCalibration()); - if (!renderer.isPaused()) { - if (data != null) { - synchronized (imageBuffer) { - currentFrame =new Frame(data); - if (imageBufferLenght > 1) { - imageBuffer.add(currentFrame); - if (imageBuffer.size() > imageBufferLenght) { - imageBuffer.remove(0); - } - } - } - } - manageFit(bi, data); - manageUserOverlays(bi, data); - } - //updateImageData(); - } - - @Override - public void onError(Object o, Exception ex) { - ex.printStackTrace(); - } - }); - - } catch (Exception ex) { - ex.printStackTrace(); - showException(ex); - renderer.clearOverlays(); - updateCamtoolControls(); - if (renderer.getDevice() == null) { - //renderer.setZoom(1.0); - //renderer.setMode(RendererMode.Zoom); - errorOverlay = new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - errorOverlay.setFixed(true); - errorOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - renderer.addOverlay(errorOverlay); - } - } finally { - //checkReticle(); - onTimer(); - } - onChangeColormap(null); - checkBackground.setEnabled(true); - if (changed) { - comboScreen.setModel(new DefaultComboBoxModel()); - comboFilter.setModel(new DefaultComboBoxModel()); - - //Parallelizing initialization - devicesInitTask = new Thread(() -> { - try { - if (cameraName.contains("DSRM")){ - screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); - } else { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); - } - screen.setMonitored(true); - screen.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : screen.getPositions()) { - model.addElement(pos); - } - comboScreen.setModel(model); - comboScreen.setSelectedItem(screen.read()); - - } catch (Exception ex) { - comboScreen.setModel(new DefaultComboBoxModel()); - System.err.println(ex.getMessage()); - screen = null; - } - comboScreen.setEnabled(screen != null); - valueScreen.setDevice(screen); - - try { - filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); - filter.setMonitored(true); - filter.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : filter.getPositions()) { - model.addElement(pos); - } - comboFilter.setModel(model); - comboFilter.setSelectedItem(filter.read()); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - filter = null; - } - comboFilter.setEnabled(filter != null); - valueFilter.setDevice(filter); - }); - devicesInitTask.start(); - } - - } - - volatile Dimension imageSize; - - void checkReticle() { - if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) { - //renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800, 800), 200); - renderer.setShowReticle(true); - } else { - //renderer.setCalibration(null); - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - void checkMarker() { - if (camera != null) { - if (buttonMarker.isSelected()) { - Dimension d = renderer.getImageSize(); - Point p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - marker.setPassive(false); - } else { - marker = null; - } - renderer.setMarker(marker); - } - } - - void updateZoom() { - try { - buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom) { - if (renderer.getZoom() == 1) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getZoom() == 0.5) { - buttonZoom05.setSelected(true); - } else if (renderer.getZoom() == 0.25) { - buttonZoom025.setSelected(true); - } else if (renderer.getZoom() == 2.0) { - buttonZoom2.setSelected(true); - } else { - buttonGroup1.clearSelection(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - boolean updatingColormap; - - void updateColormap() { - updatingColormap = true; - try { - if ((camera != null) && (camera instanceof ColormapSource)) { - ColormapSourceConfig config = ((ColormapSource) camera).getConfig(); - comboColormap.setSelectedItem(config.colormap); - if (config.isDefaultColormap()) { - buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic) { - buttonAutomatic.setSelected(true); - } else { - buttonManual.setSelected(true); - } - btFixColormapRange.setVisible(buttonAutomatic.isSelected()); - - //spinnerMin.setVisible(buttonManual.isSelected()); labelMin.setVisible(spinnerMin.isVisible()); - //spinnerMax.setVisible(buttonManual.isSelected()); labelMax.setVisible(spinnerMax.isVisible()); - spinnerMin.setEnabled(buttonManual.isSelected()); - spinnerMax.setEnabled(buttonManual.isSelected()); - //spinnerMin.setValue(Double.isNaN(config.colormapMin) ? 0 : Math.min(Math.max((int) config.colormapMin, 0), 65535)); - //spinnerMax.setValue(Double.isNaN(config.colormapMax) ? 0 : Math.min(Math.max((int) config.colormapMax, 0), 65535)); - if (!Double.isNaN(config.colormapMin) ){ - spinnerMin.setValue(Math.min(Math.max((int) config.colormapMin, 0), 65535)); - } - if (!Double.isNaN(config.colormapMax) ){ - spinnerMax.setValue(Math.min(Math.max((int) config.colormapMax, 0), 65535)); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatingColormap = false; - } - - boolean updatingCamtoolControls; - - void updateCamtoolControls() { - if ((camera != null) && (camera instanceof Camtool)) { - updatingCamtoolControls = true; - try { - checkBackground.setSelected(((Camtool) camera).getBackgroundSubtraction()); - Double threshold = ((Camtool) camera).getThreshold(); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = ((Camtool) camera).getGoodRegion(); - checkGoodRegion.setSelected(gr != null); - if (gr != null){ - spinnerGrThreshold.setValue(gr.get("threshold")); - spinnerGrScale.setValue(gr.get("gfscale")); - } - } catch (Exception ex) { - } - goodRegion = checkGoodRegion.isSelected(); - spinnerThreshold.setVisible(checkThreshold.isSelected()); - spinnerGrThreshold.setVisible(goodRegion); labelGrThreshold.setVisible(spinnerGrThreshold.isVisible()); - spinnerGrScale.setVisible(goodRegion); labelGrScale.setVisible(spinnerGrScale.isVisible()); - updatingCamtoolControls = false; - } - } - - boolean isCameraStopped() { - if ((camera != null) && (camera instanceof Camtool)) { - if (!((Camtool) camera).isPipelineStarted()) { - return true; - } - } - return ((camera == null) || (camera.isClosed()) || !buttonStop.isEnabled()); - } - - void updateStop() { - buttonStop.setEnabled(comboCameras.getSelectedItem() != null); - buttonStop.setText(isCameraStopped() ? "Start" : "Stop"); - - } - - @Override - protected void onTimer() { - for (Device dev : new Device[]{screen, filter}) { - if (dev != null) { - dev.request(); - } - } - - textState.setText((camera == null) ? "" : camera.getState().toString()); - buttonArgs.setEnabled(camera != null); - if (App.hasArgument("s")) { - try { - ((Source) getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(ScreenPanelOld.class.getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(ScreenPanelOld.class.getName()).log(Level.SEVERE, null, ex); - } - } - if (renderer.isPaused() != buttonPause.isSelected()) { - buttonPause.setSelected(renderer.isPaused()); - buttonPauseActionPerformed(null); - } - if (renderer.getShowReticle() != buttonReticle.isSelected()) { - //buttonReticle.setSelected(renderer.getShowReticle()); - } - if ((renderer.getMarker() == null) && buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - } - if (!renderer.isPaused() && (dataTableDialog!=null) && (dataTableDialog.isShowing())){ - updateImageData(); - } - updateZoom(); - updateColormap(); - updateStop(); - buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); - } - - Pen penFit = new Pen(new Color(192, 105, 0), 0); - Pen penCross = new Pen(new Color(192, 105, 0), 0); - - - Frame getCurrentFrame(){ - if ((imageBufferLenght > 1) && (renderer.isPaused())) { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - return (index < imageBuffer.size()) ? imageBuffer.get(index) : null; - } - } - return currentFrame; - } - - Frame getFrame(Data data){ - synchronized (imageBuffer) { - for (Frame f : imageBuffer) { - if (f.data == data) { - return f; - } - } - } - return null; - } - - Overlay[][] getFitOverlays(Data data) { - Overlays.Polyline hgaussian = null; - Overlays.Polyline vgaussian = null; - Overlays.Polyline hprofile = null; - Overlays.Polyline vprofile = null; - Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null; - Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null; - double[] pX = null, pY = null, gX = null, gY = null; - int height = data.getHeight(); - int width = data.getWidth(); - //Double xCom=null, yCom=null; - if (data != null) { - int profileSize = renderer.getProfileSize(); - if ((useCamtoolStats) && (camera instanceof Camtool)) { - try { - - ImageData id = getFrame(data); - if (id==null){ - return null; - } - xMean = id.x_fit_mean; xSigma = id.x_fit_standard_deviation;yMean = id.y_fit_mean;ySigma = id.y_fit_standard_deviation; - gX = id.x_fit_gauss_function; gY = id.y_fit_gauss_function; - pX = id.x_profile; pY = id.y_profile; - xCom = id.x_center_of_mass; xRms = id.x_rms; yCom = id.y_center_of_mass; yRms = id.y_rms; - - profileSize /= 4; - if (pX != null) { - int[] x = Arr.indexesInt(pX.length); - int[] y = new int[pX.length]; - int[] p = new int[pX.length]; - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - Double min = Collections.min(l); - Double max = Collections.max(l); - double minPlot = min; - double rangePlot = max - min; - - for (int i = 0; i < x.length; i++) { - if (gX != null) { - y[i] = (int) (height - 1 - (((gX[i] - minPlot) / rangePlot) * profileSize)); - } - p[i] = (int) (height - 1 - (((pX[i] - minPlot) / rangePlot) * profileSize)); - } - - if (goodRegion){ - for (int i = 0; i < x.length; i++) { - y[i] = (Double.isNaN(gX[i])) ? 100000 : y[i]; - } - } - - vgaussian = new Overlays.Polyline(penFit, x, y); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - - if (pY != null) { - int[] y = Arr.indexesInt(pY.length); - int[] x = new int[pY.length]; - int[] p = new int[pY.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - Double min = Collections.min(l); - Double max = Collections.max(l); - double minPlot = min; - double rangePlot = max - min; - - for (int i = 0; i < x.length; i++) { - if (gY != null) { - x[i] = (int) (((gY[i] - minPlot) / rangePlot) * profileSize); - } - p[i] = (int) (((pY[i] - minPlot) / rangePlot) * profileSize); - } - - if (goodRegion){ - for (int i = 0; i < x.length; i++) { - x[i] = (Double.isNaN(gY[i])) ? -1 :x[i]; - } - } - hgaussian = new Overlays.Polyline(penFit, x, y); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, y); - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - return null; - } - } else { - ArrayProperties properties = data.getProperties(); - double maxPlot = properties.max; - double minPlot = properties.min; - double rangePlot = maxPlot - minPlot; - - if (rangePlot <= 0) { - return null; - } - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit){ - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - } - } - } - if (showProfile){ - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit){ - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile){ - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - if (renderer.getCalibration() != null) { - if (xSigma != null) { - xSigma *= renderer.getCalibration().getScaleX(); - } - if (ySigma != null) { - ySigma *= renderer.getCalibration().getScaleY(); - } - if (xMean != null) { - xMean = data.getX((int) Math.round(xMean)); - } - if (yMean != null) { - yMean = data.getY((int) Math.round(yMean)); - } - } - } - final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px"; - final String fmt = "%7.1f" + units; - Overlays.Text textCom = null; - Overlay[] pOv=null, fOv=null; - Point textPosition = new Point(12, 20); - if (showProfile){ - if ((xCom != null) && (yCom != null)) { - String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt,xCom, xRms,yCom, yRms); - textCom = new Overlays.Text(renderer.getPenProfile(), text, new Font(Font.MONOSPACED, 0, 14), textPosition); - textCom.setFixed(true); - textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - } - pOv = new Overlay[]{hprofile, vprofile, textCom}; - } - if (showFit){ - Overlays.Crosshairs cross = null; - Overlays.Text textFit = null; - if ((xMean != null) && (yMean != null)) { - String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt,xMean, xSigma, yMean, ySigma); - textFit = new Overlays.Text(penFit, text, new Font(Font.MONOSPACED, 0, 14), showProfile ? new Point(12, 54) : textPosition ); - textFit.setFixed(true); - textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - Point center = new Point(xMean.intValue(), yMean.intValue()); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean)); - xSigma /= renderer.getCalibration().getScaleX(); - ySigma /= renderer.getCalibration().getScaleY(); - } - cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue()))); - } - fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit}; - - if (goodRegion){ - try{ - double[] x = getCamtoolDoubleArray("gr_x_axis"); double[] y = getCamtoolDoubleArray("gr_y_axis"); - double x1 = x[0]; double x2 = x[x.length-1]; double y1 = y[0]; double y2 = y[y.length-1]; - Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); - goodRegionOv.setCalibration(renderer.getCalibration()); - goodRegionOv.setAbsolutePosition(new PointDouble(x1, y1)); - goodRegionOv.setAbsoluteSize(new DimensionDouble(x2-x1, y2-y1)); - fOv = Arr.append(fOv, goodRegionOv); - } catch (Exception ex){ - } - } - - } - return new Overlay[][]{pOv, fOv}; - } - return null; - } - - class UserOverlay { - - String name; - Overlay obj; - String[] channels; - } - ArrayList userOverlayConfig; - - void parseUserOverlays() { - Properties userOverlays = new Properties(); - userOverlayConfig = new ArrayList<>(); - if (userOverlaysConfigFile != null) { - try { - try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { - userOverlays.load(in); - - for (String name : userOverlays.stringPropertyNames()) { - String val = userOverlays.getProperty(name); - try { - UserOverlay uo = new UserOverlay(); - uo.name = name; - String type = val.substring(0, val.indexOf("(")).trim(); - String pars = val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")).trim(); - String[] tokens = pars.split(","); - for (int i = 0; i < tokens.length; i++) { - tokens[i] = tokens[i].trim(); - } - Color color = Color.GRAY; - try { - color = (Color) Color.class.getField(tokens[tokens.length - 1].toUpperCase()).get(null); - } catch (Exception ex) { - } - Pen pen = new Pen(color); - try { - String[] penTokens = tokens[tokens.length - 1].split(":"); - color = (Color) Color.class.getField(penTokens[0].toUpperCase()).get(null); - int width = Integer.valueOf(penTokens[1]); - Pen.LineStyle style = Pen.LineStyle.valueOf(penTokens[2]); - pen = new Pen(color, width, style); - } catch (Exception ex) { - } - switch (type) { - case "Point": - uo.obj = new Overlays.Crosshairs(); - uo.obj.setSize(new Dimension(Integer.valueOf(tokens[2]), Integer.valueOf(tokens[3]))); - break; - case "Line": - uo.obj = new Overlays.Line(); - break; - case "Arrow": - uo.obj = new Overlays.Arrow(); - break; - case "Rect": - uo.obj = new Overlays.Rect(); - break; - case "Ellipse": - uo.obj = new Overlays.Ellipse(); - break; - case "Polyline": - uo.obj = new Overlays.Polyline(); - break; - } - if (type.equals("Polyline") || type.equals("Point")) { - uo.channels = new String[]{tokens[0], tokens[1]}; - } else { - uo.channels = new String[]{tokens[0], tokens[1], tokens[2], tokens[3]}; - } - uo.obj.setPen(pen); - userOverlayConfig.add(uo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - Overlay[] getUserOverlays(Data data) { - ArrayList ret = new ArrayList<>(); - if (camera instanceof Camtool) { - for (UserOverlay uo : userOverlayConfig) { - try { - Overlay ov = uo.obj; - //Overlay ov = (Overlay)uo.cls.newInstance(); - ov.setCalibration(renderer.getCalibration()); - boolean valid = false; - if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[1]); - if ((x != null) || (y !=null)) { - if (x == null) { - x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); - } - if (y == null) { - y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length); - } - ((Overlays.Polyline) ov).updateAbsolute(x, y); - valid = true; - } - } else { - Double x = getCamtoolDouble(uo.channels[0]); Double y = getCamtoolDouble(uo.channels[1]); - if ((x != null) && (y !=null)) { - PointDouble position = new PointDouble(x,y); - ov.setAbsolutePosition(position); - if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = getCamtoolDouble(uo.channels[2]); Double y2 = getCamtoolDouble(uo.channels[3]); - if ((x != null) && (y !=null)) { - DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); - ov.setAbsoluteSize(size); - valid = true; - } - } else { - valid = true; - } - } - } - if (valid){ - ret.add(ov); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - return ret.toArray(new Overlay[0]); - } - - double[] getComRms(double[] arr, double[] x) { - if (arr != null) { - double xmd = 0; - double xmd2 = 0; - double total = 0; - for (int i=0; i< arr.length; i++) { - double v = (arr[i] * x[i]); - xmd += v; - xmd2 += (v * x[i]); - total += arr[i]; - } - if (total > 0) { - double com = xmd / total; - double com2 = xmd2 / total; - double rms = Math.sqrt(Math.abs(com2 - com * com)); - return new double[] {com, rms}; - } - } - return new double[]{Double.NaN, Double.NaN}; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - void setHistogramVisible(boolean value) { - if (value) { - if ((histogramDialog == null) || (!histogramDialog.isShowing())) { - Histogram histogram = new Histogram(true); - histogram.setRenderer(renderer); - histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram); - renderer.refresh(); - } - } else { - if (histogramDialog != null) { - histogramDialog.setVisible(false); - histogramDialog = null; - } - } - } - - void setLaserState(boolean value) throws Exception { - System.out.println( "Setting laser state: " + value); - Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); - Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); - Thread.sleep(3000); - } - - boolean getLaserState() throws Exception { - return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); - } - - void elog(String logbook, String title, String message, String[] attachments) throws Exception { - String domain = ""; - String category = "Info"; - String entry = ""; - StringBuffer cmd = new StringBuffer(); - - cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); - cmd.append("-a \"Author=ScreenPanel\" "); - cmd.append("-a \"Type=pshell\" "); - cmd.append("-a \"Entry=").append(entry).append("\" "); - cmd.append("-a \"Title=").append(title).append("\" "); - cmd.append("-a \"Category=").append(category).append("\" "); - cmd.append("-a \"Domain=").append(domain).append("\" "); - for (String attachment : attachments) { - cmd.append("-f \"").append(attachment).append("\" "); - } - cmd.append("-n 1 "); - cmd.append("\"").append(message).append("\" "); - System.out.println(cmd.toString()); - - final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); - new Thread(() -> { - try { - process.waitFor(); - int bytes = process.getInputStream().available(); - byte[] arr = new byte[bytes]; - process.getInputStream().read(arr, 0, bytes); - System.out.println(new String(arr)); - bytes = process.getErrorStream().available(); - arr = new byte[bytes]; - process.getErrorStream().read(arr, 0, bytes); - System.err.println(new String(arr)); - } catch (Exception ex) { - System.err.println(ex); - } - }).start(); - } - - void centralizeRenderer() { - Point center = null; - Dimension size = renderer.getImageSize(); - double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom(); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().getCenter(); - } else if (size != null) { - center = new Point(size.width / 2, size.height / 2); - } - if (center != null) { - Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0), - Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0)); - renderer.setViewPosition(topleft); - } - } - - void updatePause() { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - if (index < imageBuffer.size()) { - Data data = imageBuffer.get(index).data; - BufferedImage image = camera.generateImage(data); - renderer.setImage(renderer.getOrigin(), image, data); - imageBufferOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS")); - manageFit(image, data); - manageUserOverlays(image, data); - } - } - } - - void writeFrameMetadata(String path, Frame frame) throws Exception{ - getContext().getDataManager().setAttribute("/", "Camera", String.valueOf(cameraName)); - getContext().getDataManager().setAttribute("/", "Screen", String.valueOf(valueScreen.getLabel().getText())); - getContext().getDataManager().setAttribute("/", "Filter", String.valueOf(valueFilter.getLabel().getText())); - Calibration cal = renderer.getCalibration(); - getContext().getDataManager().setAttribute("/", "Calibration", cal == null ? new double[]{1,1,0,0} : - new double[]{cal.getScaleX(), cal.getScaleY(), cal.getOffsetX(), cal.getOffsetY()}); - getContext().getDataManager().setAttribute(path, "Timestamp", Chrono.getTimeStr(frame.data.getTimestamp(), "HH:mm:ss.SSS")); - if (camera instanceof Camtool){ - try{ - getContext().getDataManager().setAttribute("/", "ROI", ((Camtool) camera).getRoi()); - } catch (Exception ex){ - getContext().getDataManager().setAttribute("/", "ROI", new int[]{0,0,-1,-1}); - } - if (frame!=null){ - for (Field f:ImageData.class.getFields()){ - Object value = f.get(frame); - getContext().getDataManager().setAttribute(path, f.getName(), (value == null) ? Double.NaN : value); - } - } - for (String name : new String[]{"x_axis", "y_axis", "gr_x_axis", "gr_y_axis"}){ - double[] val = getCamtoolDoubleArray(name); - getContext().getDataManager().setAttribute("/", "GoodRegion", goodRegion); - if (val!=null){ - getContext().getDataManager().setAttribute("/", name, val); - } - } - } - } - - void saveSnapshot() throws Exception { - getContext().setExecutionPars("snapshot"); - String path = "/data"; - String snapshotFile = null; - synchronized (imageBuffer) { - Frame id = getCurrentFrame(); - if (id==null){ - throw new Exception("No current image"); - } - Object data = id.data.getMatrix(); - getContext().getDataManager().setDataset(path, data, id.data.isUnsigned()); - writeFrameMetadata(path, id); - getContext().getDataManager().closeOutput(); - //Enforce the same timestamp to data & image files. - //snapshotFile = getContext().getSetup().expandPath("{images}/{date}_{time}_snapshot.png", getContext().getExecutionPars().getStart()); - snapshotFile = getContext().getExecutionPars().getPath() + ".png"; - //renderer.saveSnapshot(snapshotFile, "png", true); - ImageBuffer.saveImage(SwingUtils.createImage(renderer), snapshotFile, "png"); - - } - - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{0, 180}; //Minimum width - layout.rowHeights = new int[]{30, 30, 30}; //Minimum height - panel.setLayout(layout); - JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); - JTextField textComment = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Data file:"), c); - c.gridy = 1; - panel.add(new JLabel("Logbook:"), c); - c.gridy = 2; - panel.add(new JLabel("Comment:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(textComment, c); - c.gridy = 1; - panel.add(comboLogbook, c); - c.gridy = 0; - panel.add(new JLabel(getContext().getExecutionPars().getPath()), c); - - if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes){ - StringBuilder message = new StringBuilder(); - message.append("Camera: ").append(cameraName).append(" ("). - append((camera instanceof Camtool) ? "camtool" : "direct").append(")").append("\n"); - message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); - message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); - message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); - message.append("Comment: ").append(textComment.getText()).append("\n"); - if ((fitOv != null) && (fitOv.length > 5)) { - Overlays.Text text = (Overlays.Text) fitOv[5]; - message.append(text.getText()).append("\n"); - } - elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - //SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000); - //elog("SwissFEL commissioning data", "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - - void saveStack() throws Exception { - getContext().setExecutionPars("snapshot"); - ArrayList x = new ArrayList<>(); - ArrayList y = new ArrayList<>(); - synchronized (imageBuffer) { - for (int i = 0; i < imageBuffer.size(); i++) { - Frame frame = imageBuffer.get(i); - String path = "/data_" + i; - getContext().getDataManager().setDataset(path, frame.data.getMatrix(), frame.data.isUnsigned()); - writeFrameMetadata(path, frame); - x.add(frame.x_fit_mean); - y.add(frame.y_fit_mean); - } - } - DescStatsDouble xs = new DescStatsDouble(x.toArray(new Double[0]), -1); - DescStatsDouble ys = new DescStatsDouble(y.toArray(new Double[0]), -1); - - getContext().getDataManager().closeOutput(); - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000); - } - - StandardDialog calibrationDialolg; - void calibrate() throws Exception{ - if (camera instanceof Camtool){ - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraConfigDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), camera, renderer}); - SwingUtils.centerComponent(this, calibrationDialolg); - calibrationDialolg.setVisible(true); - calibrationDialolg.setListener(new StandardDialogListener() { - @Override - public void onWindowOpened(StandardDialog dlg) { - } - @Override - public void onWindowClosed(StandardDialog dlg, boolean accepted) { - if (accepted){ - comboCamerasActionPerformed(null); - } - } - }); - } - } - - StandardDialog dataTableDialog; - DefaultTableModel dataTableModel; - void showImageData(){ - dataTableModel = null; - if (camera instanceof Camtool){ - - if ((dataTableDialog!=null) && (dataTableDialog.isShowing())){ - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.requestFocus(); - return; - } - //String msg = String.join("\n", ids); - //SwingUtils.showMessage(getTopLevel(), "Image Data", msg); - dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) { - public Class getColumnClass(int columnIndex) { - return String.class; - } - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - }; - updateImageData(); - StreamValue val = ((Camtool)camera).getStream().take(); - JTable dataTable = new JTable(dataTableModel); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.getTableHeader().setReorderingAllowed(false); - dataTable.getTableHeader().setResizingAllowed(true); - dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); - dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE ); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(dataTable); - scrollPane.setPreferredSize(new Dimension(300, 400)); - dataTableDialog.setContentPane(scrollPane); - dataTableDialog.pack(); - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.setVisible(true); - dataTableDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - dataTableModel = null; - } - }); - } - } - - void updateImageData(){ - if ((dataTableModel!=null)&&(camera instanceof Camtool)){ - List ids = new ArrayList(((Camtool)camera).getValue().getIdentifiers()); - if (ids.size() != dataTableModel.getRowCount()){ - dataTableModel.setNumRows(0); - Collections.sort(ids); - for (String id : ids){ - dataTableModel.addRow(new Object[]{id, ""}); - } - } - for (int i = 0 ; i< dataTableModel.getRowCount(); i++){ - String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - Object obj = ((Camtool)camera).getValue(id); - if (obj!=null){ - if (obj.getClass().isArray()){ - obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; - } else if (obj instanceof Double){ - obj = Convert.roundDouble((Double) obj, 1); - } else if (obj instanceof Float){ - obj = Convert.roundDouble((Float) obj, 1); - } - } - dataTableModel.setValueAt(String.valueOf(obj), i, 1); - } - } - } - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - buttonGroup4 = new javax.swing.ButtonGroup(); - jProgressBar1 = new javax.swing.JProgressBar(); - jPanel1 = new javax.swing.JPanel(); - jPanel7 = new javax.swing.JPanel(); - buttonMarker = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonFit = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonPause = new javax.swing.JToggleButton(); - buttonProfile = new javax.swing.JToggleButton(); - jPanel6 = new javax.swing.JPanel(); - textState = new javax.swing.JTextField(); - jLabel2 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - buttonConfig = new javax.swing.JButton(); - jLabel1 = new javax.swing.JLabel(); - buttonArgs = new javax.swing.JButton(); - buttonStop = new javax.swing.JButton(); - renderer = new ch.psi.pshell.imaging.Renderer(); - jPanel4 = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - buttonZoomFit = new javax.swing.JRadioButton(); - buttonZoomStretch = new javax.swing.JRadioButton(); - buttonZoomNormal = new javax.swing.JRadioButton(); - buttonZoom025 = new javax.swing.JRadioButton(); - buttonZoom05 = new javax.swing.JRadioButton(); - buttonZoom2 = new javax.swing.JRadioButton(); - jPanel2 = new javax.swing.JPanel(); - checkHistogram = new javax.swing.JCheckBox(); - comboColormap = new javax.swing.JComboBox(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - buttonFullRange = new javax.swing.JRadioButton(); - buttonManual = new javax.swing.JRadioButton(); - buttonAutomatic = new javax.swing.JRadioButton(); - labelMin = new javax.swing.JLabel(); - spinnerMin = new javax.swing.JSpinner(); - spinnerMax = new javax.swing.JSpinner(); - labelMax = new javax.swing.JLabel(); - btFixColormapRange = new javax.swing.JButton(); - jPanel5 = new javax.swing.JPanel(); - buttonCamtool = new javax.swing.JRadioButton(); - buttonDirect = new javax.swing.JRadioButton(); - panelScreen = new javax.swing.JPanel(); - valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); - comboScreen = new javax.swing.JComboBox(); - panelScreen1 = new javax.swing.JPanel(); - valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); - comboFilter = new javax.swing.JComboBox(); - pauseSelection = new ch.psi.pshell.swing.ValueSelection(); - panelScreen2 = new javax.swing.JPanel(); - checkThreshold = new javax.swing.JCheckBox(); - spinnerThreshold = new javax.swing.JSpinner(); - checkBackground = new javax.swing.JCheckBox(); - checkGoodRegion = new javax.swing.JCheckBox(); - spinnerGrScale = new javax.swing.JSpinner(); - spinnerGrThreshold = new javax.swing.JSpinner(); - labelGrThreshold = new javax.swing.JLabel(); - labelGrScale = new javax.swing.JLabel(); - - setPreferredSize(new java.awt.Dimension(873, 600)); - - buttonMarker.setText("Marker"); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - - buttonGrabBackground.setText("Grab Background"); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - - buttonSave.setText("Save Snapshot"); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - - buttonFit.setSelected(true); - buttonFit.setText("Fit"); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - - buttonReticle.setSelected(true); - buttonReticle.setText("Reticle"); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - - buttonPause.setText("Pause"); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - - buttonProfile.setSelected(true); - buttonProfile.setText("Profile"); - buttonProfile.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonProfileActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); - jPanel7.setLayout(jPanel7Layout); - jPanel7Layout.setHorizontalGroup( - jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel7Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(buttonPause) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonMarker) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonProfile) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonFit) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonReticle) - .addGap(18, 18, Short.MAX_VALUE) - .addComponent(buttonGrabBackground) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonSave) - .addGap(0, 0, 0)) - ); - - jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonProfile, buttonReticle}); - - jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave}); - - jPanel7Layout.setVerticalGroup( - jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel7Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonPause) - .addComponent(buttonFit) - .addComponent(buttonMarker) - .addComponent(buttonSave) - .addComponent(buttonReticle) - .addComponent(buttonGrabBackground) - .addComponent(buttonProfile)) - .addGap(0, 0, 0)) - ); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - jLabel2.setText("State:"); - - comboCameras.setMaximumRowCount(30); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - buttonConfig.setText("Config"); - buttonConfig.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonConfigActionPerformed(evt); - } - }); - - jLabel1.setText("Camera:"); - - buttonArgs.setText("Setup"); - buttonArgs.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonArgsActionPerformed(evt); - } - }); - - buttonStop.setText("Stop"); - buttonStop.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStopActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); - jPanel6.setLayout(jPanel6Layout); - jPanel6Layout.setHorizontalGroup( - jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel6Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboCameras, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonArgs) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonConfig) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonStop) - .addGap(18, 18, 18) - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - - jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonArgs, buttonConfig, buttonStop}); - - jPanel6Layout.setVerticalGroup( - jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel6Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel2) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonArgs) - .addComponent(buttonConfig) - .addComponent(buttonStop)) - .addGap(0, 0, 0)) - ); - - jPanel6Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState}); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); - - buttonGroup1.add(buttonZoomFit); - buttonZoomFit.setText("Fit"); - buttonZoomFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomFitActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomStretch); - buttonZoomStretch.setText("Stretch"); - buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomStretchActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomNormal); - buttonZoomNormal.setText("Normal"); - buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomNormalActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("1/4"); - buttonZoom025.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom025ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("1/2"); - buttonZoom05.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom05ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom2); - buttonZoom2.setText("2"); - buttonZoom2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoomStretch)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05) - .addComponent(buttonZoom2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomFit) - .addComponent(buttonZoom05)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoom2)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap")); - - checkHistogram.setText("Histogram"); - checkHistogram.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkHistogramActionPerformed(evt); - } - }); - - comboColormap.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Type:"); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Range:"); - - buttonGroup3.add(buttonFullRange); - buttonFullRange.setText("Full"); - buttonFullRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonManual); - buttonManual.setText("Manual"); - buttonManual.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonAutomatic); - buttonAutomatic.setText("Automatic"); - buttonAutomatic.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - labelMin.setText("Min:"); - - spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); - spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); - spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - labelMax.setText("Max:"); - - btFixColormapRange.setText("Fix"); - btFixColormapRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btFixColormapRangeActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonAutomatic) - .addComponent(buttonFullRange) - .addComponent(buttonManual) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMax) - .addGap(2, 2, 2) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMin) - .addGap(2, 2, 2) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(spinnerMin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFixColormapRange, spinnerMax, spinnerMin}); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3) - .addComponent(checkHistogram)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAutomatic) - .addComponent(jLabel4) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, 0) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelMin) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonFullRange)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonManual) - .addComponent(labelMax) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - - buttonGroup4.add(buttonCamtool); - buttonCamtool.setSelected(true); - buttonCamtool.setText("Camtool"); - buttonCamtool.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonCamtoolActionPerformed(evt); - } - }); - - buttonGroup4.add(buttonDirect); - buttonDirect.setText("Direct"); - buttonDirect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDirectActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonCamtool) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonDirect) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonCamtool) - .addComponent(buttonDirect)) - .addContainerGap()) - ); - - panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); - - comboScreen.setEnabled(false); - comboScreen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboScreenActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); - panelScreen.setLayout(panelScreenLayout); - panelScreenLayout.setHorizontalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreenLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreenLayout.setVerticalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelScreen1.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); - - comboFilter.setEnabled(false); - comboFilter.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboFilterActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreen1Layout = new javax.swing.GroupLayout(panelScreen1); - panelScreen1.setLayout(panelScreen1Layout); - panelScreen1Layout.setHorizontalGroup( - panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreen1Layout.setVerticalGroup( - panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen1Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pauseSelection.setDecimals(0); - - panelScreen2.setBorder(javax.swing.BorderFactory.createTitledBorder("Image")); - - checkThreshold.setText("Threshold"); - checkThreshold.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkThresholdActionPerformed(evt); - } - }); - - spinnerThreshold.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 99999.0d, 1.0d)); - spinnerThreshold.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerThresholdonChange(evt); - } - }); - - checkBackground.setText("Subtract Background"); - checkBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkBackgroundActionPerformed(evt); - } - }); - - checkGoodRegion.setText("Good Region"); - checkGoodRegion.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkGoodRegionActionPerformed(evt); - } - }); - - spinnerGrScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 100.0d, 1.0d)); - spinnerGrScale.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerGrScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - spinnerGrThreshold.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.04d, 1.0d, 0.1d)); - spinnerGrThreshold.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerGrThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - labelGrThreshold.setText("Threshold:"); - - labelGrScale.setText("Scale:"); - - javax.swing.GroupLayout panelScreen2Layout = new javax.swing.GroupLayout(panelScreen2); - panelScreen2.setLayout(panelScreen2Layout); - panelScreen2Layout.setHorizontalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addComponent(checkGoodRegion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(labelGrScale) - .addGap(2, 2, 2) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelGrThreshold) - .addGap(2, 2, 2) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkBackground) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkThreshold) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerThreshold}); - - panelScreen2Layout.setVerticalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(checkBackground) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkThreshold) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkGoodRegion) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrScale)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrThreshold)) - .addContainerGap()) - ); - - javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); - jPanel4.setLayout(jPanel4Layout); - jPanel4Layout.setHorizontalGroup( - jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel4Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel4Layout.setVerticalGroup( - jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel4Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - }// //GEN-END:initComponents - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - if (!updatingCameraSelection) { - if (!comboCameras.isEnabled()) { - throw new Exception("Invalid state"); - } - comboCameras.setEnabled(false); - buttonCamtool.setEnabled(false); - buttonDirect.setEnabled(false); - final String cameraName = (String) comboCameras.getSelectedItem(); - new Thread(new Runnable() { - @Override - public void run() { - if (requestCameraListUpdate) { - requestCameraListUpdate = false; - try { - updateCameraList(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - try { - setCamera(cameraName); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateStop(); - comboCameras.setEnabled(true); - buttonCamtool.setEnabled(true); - buttonDirect.setEnabled(true); - } - } - }).start(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonArgsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonArgsActionPerformed - try { - if (camera != null) { - TextEditor editor = new TextEditor(); - editor.setText(cameraConfigJson); - editor.setReadOnly(true); - editor.setTitle(cameraName); - EditorDialog dlg = editor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(this, dlg); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonArgsActionPerformed - - private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonConfigActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - renderer.removeOverlay(imageBufferOverlay); - if (camera != null) { - synchronized (imageBuffer) { - if (buttonPause.isSelected()) { - renderer.pause(); - } else { - imageBuffer.clear(); - renderer.resume(); - } - pauseSelection.setVisible(buttonPause.isSelected() && (imageBuffer.size() > 0)); - if (pauseSelection.isVisible()) { - renderer.addOverlay(imageBufferOverlay); - pauseSelection.setMaxValue(imageBuffer.size()); - pauseSelection.setValue(imageBuffer.size());; - } - } - updateImageData(); - } - } catch (Exception ex) { - ex.printStackTrace(); - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - checkMarker(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - showFit = buttonFit.isSelected(); - if (showFit) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - saveSnapshot(); - } catch (Exception ex) { - ex.printStackTrace(); - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera != null) { - if (SwingUtils.showOption(getTopLevel(), "Background", "Do you want to capture background now?", OptionType.YesNo) == OptionResult.Yes) { - boolean laserOn = getLaserState(); - if (camera instanceof Camtool){ - boolean rendering = (!camera.isClosed()); - if (rendering) { - camera.close(); - } - if (laserOn) { - setLaserState(false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - ((Camtool) camera).grabBackground(cameraName, 5); - } finally { - if (laserOn) { - setLaserState(true); - } - if (rendering) { - comboCamerasActionPerformed(null); - } - updateStop(); - } - } else { - if (laserOn) { - setLaserState(false); - } - try { - camera.captureBackground(5, 0); - } finally { - if (laserOn) { - setLaserState(true); - } - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed - try { - renderer.setMode(RendererMode.Fit); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomFitActionPerformed - - private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed - try { - renderer.setMode(RendererMode.Stretch); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomStretchActionPerformed - - private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed - try { - renderer.setMode(RendererMode.Fixed); - centralizeRenderer(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomNormalActionPerformed - - private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap - try { - if ((camera != null) && (camera instanceof ColormapSource) && !updatingColormap) { - ColormapSource source = (ColormapSource) camera; - Color colorReticule = new Color(16, 16, 16); - Color colorMarker = new Color(128, 128, 128); - source.getConfig().colormap = (Colormap)comboColormap.getSelectedItem(); - switch (source.getConfig().colormap){ - case Grayscale: - case Inverted: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - case Flame: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - } - - renderer.setPenReticle(new Pen(colorReticule)); - renderer.setPenProfile(new Pen(colorReticule, 0)); - renderer.setPenMarker(new Pen(colorMarker, 2)); - renderer.setShowReticle(false); - checkReticle(); - source.getConfig().colormapAutomatic = buttonAutomatic.isSelected(); - source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); - source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); - source.getConfig().save(); - source.refresh(); - if (buttonPause.isSelected()) { - updatePause(); - } - updateColormap(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_onChangeColormap - - private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange - onChangeColormap(null); - }//GEN-LAST:event_onChangeColormapRange - - private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed - renderer.setZoom(0.25); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom025ActionPerformed - - private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed - renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom05ActionPerformed - - private void buttonCamtoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCamtoolActionPerformed - if (!usingCamtool) { - usingCamtool = true; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonCamtoolActionPerformed - - private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingCamtool) { - usingCamtool = false; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonDirectActionPerformed - - private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed - - comboScreen.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - ChannelInteger setpoint = null; - try { - int index = comboScreen.getSelectedIndex(); - if (cameraName.contains("DSRM")){ - setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); - } else { - setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); - } - setpoint.initialize(); - if (setpoint.read() != index) { - setpoint.write(index); - //Must be threaded to control the laser because of sleep in setLaserState - /* - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - setpoint.write(index); - } finally { - if (laserOn) { - setLaserState(true); - } - } - */ - } - screen.read(); - } catch (Exception ex) { - showException(ex); - } finally { - comboScreen.setEnabled(true); - if (setpoint != null) { - setpoint.close(); - } - } - } - }).start(); - }//GEN-LAST:event_comboScreenActionPerformed - - private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed - try { - String setpoint = (String) comboFilter.getSelectedItem(); - if (!setpoint.equals(filter.read())) { - filter.write(setpoint); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboFilterActionPerformed - - private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed - try { - setHistogramVisible(checkHistogram.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_checkHistogramActionPerformed - - private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed - renderer.setZoom(2.0); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom2ActionPerformed - - private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingCamtoolControls) { - try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - ((Camtool) camera).setThreshold((Double) spinnerThreshold.getValue()); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - } - } - }//GEN-LAST:event_spinnerThresholdonChange - - private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (camera instanceof Camtool){ - if (!updatingCamtoolControls) { - try { - if (((Camtool) camera).isPipelineStarted()) { - ((Camtool) camera).setBackgroundSubtraction(checkBackground.isSelected()); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - //There is a bug in camtool: it will flag bg extraction as on: - updatingCamtoolControls = true; - checkBackground.setSelected(false); - updatingCamtoolControls = false; - - } - } - } else { - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - }//GEN-LAST:event_checkBackgroundActionPerformed - - private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingCamtoolControls) { - try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - spinnerThreshold.setVisible(checkThreshold.isSelected()); - ((Camtool) camera).setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - } - } - }//GEN-LAST:event_checkThresholdActionPerformed - - private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed - try { - if (buttonStop.getText().equals("Stop")) { - if ((camera != null) && !camera.isClosed()) { - camera.close(); - } - } else { - if (isCameraStopped()) { - comboCamerasActionPerformed(null); - } - } - } catch (Exception ex) { - showException(ex); - } finally { - updateStop(); - } - }//GEN-LAST:event_buttonStopActionPerformed - - private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed - try { - showProfile = buttonProfile.isSelected(); - if (showProfile) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(profileOv); - profileOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonProfileActionPerformed - - private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingCamtoolControls) { - try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - spinnerGrScale.setVisible(checkGoodRegion.isSelected()); labelGrScale.setVisible(spinnerGrScale.isVisible()); - spinnerGrThreshold.setVisible(checkGoodRegion.isSelected()); labelGrThreshold.setVisible(spinnerGrThreshold.isVisible()); - if (checkGoodRegion.isSelected()){ - ((Camtool) camera).setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); - } else { - ((Camtool) camera).setGoodRegion(null); - } - goodRegion = checkGoodRegion.isSelected(); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - } - } - }//GEN-LAST:event_checkGoodRegionActionPerformed - - private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingCamtoolControls) { - try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - ((Camtool) camera).setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - } - } - }//GEN-LAST:event_spinnerGrThresholdonChange - - private void btFixColormapRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFixColormapRangeActionPerformed - try { - updatingColormap = true; - ArrayProperties properties = currentFrame.data.getProperties(); - spinnerMax.setValue(properties.max.intValue()); - spinnerMin.setValue(properties.min.intValue()); - buttonManual.setSelected(true); - } catch (Exception ex) { - showException(ex); - } finally{ - updatingColormap = false; - onChangeColormap(null); - } - }//GEN-LAST:event_btFixColormapRangeActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btFixColormapRange; - private javax.swing.JButton buttonArgs; - private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonCamtool; - private javax.swing.JButton buttonConfig; - private javax.swing.JRadioButton buttonDirect; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JRadioButton buttonFullRange; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JRadioButton buttonManual; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonProfile; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JButton buttonStop; - private javax.swing.JRadioButton buttonZoom025; - private javax.swing.JRadioButton buttonZoom05; - private javax.swing.JRadioButton buttonZoom2; - private javax.swing.JRadioButton buttonZoomFit; - private javax.swing.JRadioButton buttonZoomNormal; - private javax.swing.JRadioButton buttonZoomStretch; - private javax.swing.JCheckBox checkBackground; - private javax.swing.JCheckBox checkGoodRegion; - private javax.swing.JCheckBox checkHistogram; - private javax.swing.JCheckBox checkThreshold; - private javax.swing.JComboBox comboCameras; - private javax.swing.JComboBox comboColormap; - private javax.swing.JComboBox comboFilter; - private javax.swing.JComboBox comboScreen; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel4; - private javax.swing.JPanel jPanel5; - private javax.swing.JPanel jPanel6; - private javax.swing.JPanel jPanel7; - private javax.swing.JProgressBar jProgressBar1; - private javax.swing.JLabel labelGrScale; - private javax.swing.JLabel labelGrThreshold; - private javax.swing.JLabel labelMax; - private javax.swing.JLabel labelMin; - private javax.swing.JPanel panelScreen; - private javax.swing.JPanel panelScreen1; - private javax.swing.JPanel panelScreen2; - private ch.psi.pshell.swing.ValueSelection pauseSelection; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JSpinner spinnerGrScale; - private javax.swing.JSpinner spinnerGrThreshold; - private javax.swing.JSpinner spinnerMax; - private javax.swing.JSpinner spinnerMin; - private javax.swing.JSpinner spinnerThreshold; - private javax.swing.JTextField textState; - private ch.psi.pshell.swing.DeviceValuePanel valueFilter; - private ch.psi.pshell.swing.DeviceValuePanel valueScreen; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/SfCamera.java b/plugins/SfCamera.java index 5b79455..16d4667 100755 --- a/plugins/SfCamera.java +++ b/plugins/SfCamera.java @@ -1,7 +1,7 @@ -import ch.psi.pshell.core.JsonSerializer; +import ch.psi.pshell.utils.EncoderJson; import ch.psi.pshell.epics.PsiCamera; -import ch.psi.utils.IO; +import ch.psi.pshell.utils.IO; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -178,7 +178,7 @@ public class SfCamera extends PsiCamera{ throw new IOException("Cannot open camera config file: " + configFile.toFile()); } json = new String(Files.readAllBytes(configFile)); - setup = (CameraConfig) JsonSerializer.decode(json, CameraConfig.class); + setup = (CameraConfig) EncoderJson.decode(json, CameraConfig.class); CameraPars cameraPars = null; getConfig().roiX = 0; getConfig().roiY = 0; @@ -188,7 +188,7 @@ public class SfCamera extends PsiCamera{ Path parsFile = Paths.get(configFolder, prefix + "_parameters.json"); if (parsFile.toFile().exists()){ String cameraParsJson = new String(Files.readAllBytes(parsFile)); - cameraPars = (CameraPars) JsonSerializer.decode(cameraParsJson, CameraPars.class); + cameraPars = (CameraPars) EncoderJson.decode(cameraParsJson, CameraPars.class); if (cameraPars.getRoiEnable()){ ArrayList roi = cameraPars.getRoi(); if ((roi.get(1)>0) && (roi.get(3)>0)){ diff --git a/plugins/Tst.form b/plugins/Tst.form deleted file mode 100755 index ff9cfab..0000000 --- a/plugins/Tst.form +++ /dev/null @@ -1,28 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/Tst.java b/plugins/Tst.java deleted file mode 100755 index 990227c..0000000 --- a/plugins/Tst.java +++ /dev/null @@ -1,52 +0,0 @@ -import ch.psi.pshell.ui.Panel; -import ch.psi.utils.State; - -/** - * - */ -public class Tst extends Panel { - - public Tst() { - initComponents(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - - } - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 449, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 137, Short.MAX_VALUE) - ); - }// //GEN-END:initComponents - - // Variables declaration - do not modify//GEN-BEGIN:variables - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/WireScan.java b/plugins/WireScan.java index bb2040e..fd0f57e 100755 --- a/plugins/WireScan.java +++ b/plugins/WireScan.java @@ -2,35 +2,31 @@ * Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved. */ +import ch.psi.pshell.framework.App; import ch.psi.pshell.device.Device; -import ch.psi.pshell.device.DeviceAdapter; import ch.psi.pshell.device.DeviceListener; import ch.psi.pshell.epics.ChannelDouble; -import ch.psi.pshell.epics.ChannelInteger; import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.swing.DevicePanel; import ch.psi.pshell.swing.DeviceValueChart; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.ui.Plugin; -import ch.psi.utils.Convert; -import ch.psi.utils.State; -import ch.psi.utils.swing.SwingUtils; +import ch.psi.pshell.framework.Context; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.framework.Plugin; +import ch.psi.pshell.framework.Setup; +import ch.psi.pshell.utils.Convert; +import ch.psi.pshell.utils.State; +import ch.psi.pshell.swing.SwingUtils; import java.awt.Color; import java.awt.Dimension; import java.awt.Window; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JDialog; -import javax.swing.JFrame; /** * @@ -92,8 +88,8 @@ public class WireScan extends Panel { cb.setModel(model); } - if (App.hasArgument("ws")){ - comboWireScanner.setSelectedItem(App.getArgumentValue("ws")); + if (App.hasAdditionalArgument("ws")){ + comboWireScanner.setSelectedItem(App.getAdditionalArgumentValue("ws")); } comboWireScannerActionPerformed(null); updatePanelRepRate(); @@ -1015,7 +1011,7 @@ public class WireScan extends Panel { panelStatus.setDevice(scannerInfo); Device dev = new ChannelDouble (null, currentScannner + ":ENC_1_BS", 3); dev.setMonitored(true); - dev.addListener(new DeviceAdapter() { + dev.addListener(new DeviceListener() { @Override public void onValueChanged(Device device, Object value, Object former) { updatePosition((Double)value); @@ -1079,25 +1075,25 @@ ChannelDouble channelEndY; channelStartY.initialize(); channelStartY.setMonitored(true); channelEndY.initialize(); channelEndY.setMonitored(true); - channelStartX.addListener(new DeviceAdapter() { + channelStartX.addListener(new DeviceListener() { @Override public void onValueChanged(Device device, Object value, Object former) { spinnerStartX.setValue(((Number)value).doubleValue()); } }); - channelEndX.addListener(new DeviceAdapter() { + channelEndX.addListener(new DeviceListener() { @Override public void onValueChanged(Device device, Object value, Object former) { spinnerEndX.setValue(((Number)value).doubleValue()); } }); - channelStartY.addListener(new DeviceAdapter() { + channelStartY.addListener(new DeviceListener() { @Override public void onValueChanged(Device device, Object value, Object former) { spinnerStartY.setValue(((Number)value).doubleValue()); } }); - channelEndY.addListener(new DeviceAdapter() { + channelEndY.addListener(new DeviceListener() { @Override public void onValueChanged(Device device, Object value, Object former) { spinnerEndY.setValue(((Number)value).doubleValue()); @@ -1182,12 +1178,12 @@ ChannelDouble channelEndY; getLogger().info("Exception executing scan: " + ex); showException((Exception) ex); } else { - //SwingUtils.showMessage(WireScan.this, "Success", "Data file: \n" + getContext().getDataManager().getLastOutput()); + //SwingUtils.showMessage(WireScan.this, "Success", "Data file: \n" + Context.getDataManager().getLastOutput()); /* JPanel pn = new JPanel(new BorderLayout()); ((BorderLayout) pn.getLayout()).setHgap(5); pn.add(new JLabel("Generated data file:"), BorderLayout.NORTH); - JTextField tf = new JTextField(getContext().getDataManager().getLastOutput()); + JTextField tf = new JTextField(Context.getDataManager().getLastOutput()); tf.setPreferredSize(new Dimension(600, tf.getPreferredSize().height)); tf.setEditable(false); pn.add(tf, BorderLayout.SOUTH); @@ -1238,15 +1234,15 @@ ChannelDouble channelEndY; //String caqtdm = "caqtdm -noMsg -stylefile sfop.qss -attach"; //String caqtdm = "startDM -noMsg -stylefile sfop.qss"; - ch.psi.pshell.core.Plugin calibrationPlugin; + ch.psi.pshell.extension.Plugin calibrationPlugin; private void buttonCalibrationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCalibrationActionPerformed try { //String cmd = caqtdm + " -macro 'P=" + comboWireScanner.getSelectedItem() + ":,M=MOTOR_1' /sf/common/config/qt/motorx_all.ui"; //Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()});false WireScanCalibration.java if (calibrationPlugin!=null){ - getContext().getPluginManager().unloadPlugin(calibrationPlugin); + Context.getExtensions().unloadPlugin(calibrationPlugin); } - calibrationPlugin = getContext().getPluginManager().loadInitializePlugin(getContext().getSetup().expandPath("{plugins}/WireScanCalibration.java")); + calibrationPlugin = Context.getExtensions().loadInitializePlugin(Setup.expandPath("{plugins}/WireScanCalibration.java")); } catch (Exception ex) { showException(ex); } diff --git a/plugins/WireScanCalibration.java b/plugins/WireScanCalibration.java index a6253a5..ec79794 100755 --- a/plugins/WireScanCalibration.java +++ b/plugins/WireScanCalibration.java @@ -2,16 +2,13 @@ * Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved. */ -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.ui.Plugin; -import ch.psi.utils.State; -import ch.psi.utils.swing.SwingUtils; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.framework.Plugin; +import ch.psi.pshell.swing.SwingUtils; +import ch.psi.pshell.utils.State; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.DefaultComboBoxModel; -import javax.swing.JComboBox; /** * diff --git a/plugins/back/ScreenPanel.form b/plugins/back/ScreenPanel.form deleted file mode 100755 index f185ced..0000000 --- a/plugins/back/ScreenPanel.form +++ /dev/null @@ -1,954 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/back/ScreenPanel.java b/plugins/back/ScreenPanel.java deleted file mode 100755 index 44489e2..0000000 --- a/plugins/back/ScreenPanel.java +++ /dev/null @@ -1,3128 +0,0 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.core.Context; -import java.io.IOException; -import java.nio.file.Paths; -import javax.swing.DefaultComboBoxModel; -import ch.psi.pshell.ui.Panel; -import ch.psi.pshell.imaging.ImageListener; -import ch.psi.utils.State; -import ch.psi.utils.Chrono; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.Camtool; -import ch.psi.pshell.bs.StreamValue; -import ch.psi.pshell.device.DescStatsDouble; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.DiscretePositioner; -import ch.psi.pshell.epics.Epics; -import ch.psi.pshell.imaging.Calibration; -import ch.psi.pshell.imaging.Colormap; -import ch.psi.pshell.imaging.ColormapSource; -import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig; -import ch.psi.pshell.ui.App; -import ch.psi.pshell.imaging.Data; -import ch.psi.pshell.imaging.DimensionDouble; -import ch.psi.pshell.imaging.Histogram; -import ch.psi.pshell.imaging.Overlay; -import ch.psi.pshell.imaging.Overlays; -import ch.psi.pshell.imaging.Overlays.Text; -import ch.psi.pshell.imaging.Pen; -import ch.psi.pshell.imaging.PointDouble; -import ch.psi.pshell.imaging.Renderer; -import ch.psi.pshell.imaging.RendererListener; -import ch.psi.pshell.imaging.RendererMode; -import ch.psi.pshell.imaging.Source; -import ch.psi.pshell.scripting.InterpreterResult; -import ch.psi.pshell.scripting.ScriptManager; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import ch.psi.utils.Arr; -import ch.psi.utils.ArrayProperties; -import ch.psi.utils.Convert; -import ch.psi.utils.TcpClient; -import ch.psi.utils.swing.Editor.EditorDialog; -import ch.psi.utils.swing.MainFrame; -import ch.psi.utils.swing.StandardDialog; -import ch.psi.utils.swing.SwingUtils.OptionResult; -import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.FileInputStream; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.net.ServerSocket; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.table.DefaultTableModel; -import org.apache.commons.math3.analysis.function.Gaussian; -import org.apache.commons.math3.fitting.GaussianCurveFitter; -import org.apache.commons.math3.fitting.WeightedObservedPoint; -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; - -/** - * - */ -public class ScreenPanel extends Panel { - - final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useCamtoolStats = true; - - String userOverlaysConfigFile; - ColormapSource camera; - String cameraName; - String cameraConfigJson; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - boolean showProfile; - Overlay[] userOv; - Overlay[] fitOv; - Overlay[] profileOv; - Overlay errorOverlay; - boolean requestCameraListUpdate; - Integer localServerPort; - Process privateServer; - String serverUrl; - boolean goodRegion; - - Double getCamtoolDouble(String name) { - return (Double) Convert.toDouble(((Camtool) camera).getValue(name)); - } - - double[] getCamtoolDoubleArray(String name) { - return (double[]) Convert.toDouble(((Camtool) camera).getValue(name)); - } - - Double getCamtoolDouble(String name, StreamValue cache) { - return (Double) Convert.toDouble(cache.__getitem__(name)); - } - - double[] getCamtoolDoubleArray(String name, StreamValue cache) { - return (double[]) Convert.toDouble(cache.__getitem__(name)); - } - - - class ImageData { - ImageData(){ - if (camera instanceof Camtool) { - StreamValue cache = ((Camtool) camera).getStream().take(); - - String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getCamtoolDouble(prefix + "x_fit_mean", cache); - y_fit_mean = getCamtoolDouble(prefix + "y_fit_mean", cache); - x_fit_standard_deviation = getCamtoolDouble(prefix + "x_fit_standard_deviation", cache); - y_fit_standard_deviation = getCamtoolDouble(prefix + "y_fit_standard_deviation", cache); - x_fit_gauss_function = getCamtoolDoubleArray(prefix +"x_fit_gauss_function", cache); - y_fit_gauss_function = getCamtoolDoubleArray(prefix +"y_fit_gauss_function", cache); - x_profile = getCamtoolDoubleArray("x_profile", cache); - y_profile = getCamtoolDoubleArray("y_profile", cache); - x_center_of_mass = getCamtoolDouble("x_center_of_mass", cache); - y_center_of_mass = getCamtoolDouble("y_center_of_mass", cache); - x_rms = getCamtoolDouble("x_rms", cache); - y_rms = getCamtoolDouble("y_rms", cache); - if (goodRegion){ - double[] gX2 = new double[x_profile.length]; - Arrays.fill(gX2, Double.NaN); - try{ - double x = getCamtoolDoubleArray("gr_x_axis", cache)[0]; - System.arraycopy(x_fit_gauss_function, 0, gX2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x): x), x_fit_gauss_function.length); - } catch (Exception ex){ - } - x_fit_gauss_function = gX2; - double[] gY2 = new double[y_profile.length]; - Arrays.fill(gY2, Double.NaN); - try{ - double y = getCamtoolDoubleArray("gr_y_axis", cache)[0]; - System.arraycopy(y_fit_gauss_function, 0, gY2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageY(y): y), y_fit_gauss_function.length); - } catch (Exception ex){ - } - y_fit_gauss_function = gY2; - } - } - } - public Double x_fit_mean; - public Double y_fit_mean; - public Double x_center_of_mass; - public Double x_rms; - public Double x_fit_standard_deviation; - public Double y_fit_standard_deviation; - public Double y_center_of_mass; - public Double y_rms; - public double[] x_profile; - public double[] x_fit_gauss_function; - public double[] y_profile; - public double[] y_fit_gauss_function; - - } - - class Frame extends ImageData{ - - Frame(Data data) { - this.data = data; - } - Data data; - } - - final ArrayList imageBuffer = new ArrayList(); - Frame currentFrame; - int imageBufferLenght = 0; - Text imageBufferOverlay; - - public ScreenPanel() { - initComponents(); - spinnerThreshold.setVisible(false); - btFixColormapRange.setVisible(false); - spinnerGrThreshold.setVisible(false); labelGrThreshold.setVisible(false); - spinnerGrScale.setVisible(false); labelGrScale.setVisible(false); - //spinnerMin.setVisible(false); labelMin.setVisible(false); - //spinnerMax.setVisible(false); labelMax.setVisible(false); - renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - setPersistedComponents(new Component[]{buttonCamtool, buttonDirect}); - comboCameras.setEnabled(false); - SwingUtils.setEnumCombo(comboColormap, Colormap.class); - if (App.hasArgument("poll")) { - try { - polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("zoom")) { - try { - renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); - renderer.resetZoom(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (App.hasArgument("buf")) { - try { - imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("usr_ov")) { - try { - userOverlaysConfigFile = App.getArgumentValue("usr_ov"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("priv_srv")) { - try { - try(ServerSocket s = new ServerSocket(0)){ - localServerPort = s.getLocalPort(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_port")) { - localServerPort = Integer.valueOf(App.getArgumentValue("srv_port")); - } - - if (App.hasArgument("srv_url")) { - serverUrl = App.getArgumentValue("srv_url"); - } - - if (App.hasArgument("calc")) { - useCamtoolStats = false; - } - - renderer.setProfileNormalized(true); - renderer.setShowProfileLimits(false); - - JMenuItem menuCalibrate = new JMenuItem("Calibrate..."); - menuCalibrate.addActionListener((ActionEvent e) -> { - try { - calibrate(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuShowImageData = new JMenuItem("Show Image Data"); - menuShowImageData.addActionListener((ActionEvent e) -> { - try { - showImageData(); - } catch (Exception ex) { - showException(ex); - } - }); - - JMenuItem menuSaveStack = new JMenuItem("Save Stack"); - menuSaveStack.addActionListener((ActionEvent e) -> { - try { - saveStack(); - } catch (Exception ex) { - showException(ex); - } - }); - menuSaveStack.setEnabled(imageBufferLenght > 0); - - JMenuItem menuSetROI = new JMenuItem("Set ROI..."); - menuSetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (camera instanceof Camtool) { - final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); - renderer.addListener(new RendererListener() { - @Override - public void onSelectionFinished(Renderer renderer, Overlay overlay) { - try { - renderer.setShowReticle(false); - Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (((Camtool) camera).isRoiEnabled()) { - int[] cur = ((Camtool) camera).getRoi(); - ((Camtool) camera).setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); - } else { - ((Camtool) camera).setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); - } - } catch (Exception ex) { - } finally { - renderer.removeListener(this); - } - } - - @Override - public void onSelectionAborted(Renderer renderer, Overlay overlay) { - renderer.removeListener(this); - } - }); - selection.setFixed(true); - renderer.startSelection(selection); - } - }); - - JMenuItem menuResetROI = new JMenuItem("Reset ROI"); - menuResetROI.addActionListener((ActionEvent e) -> { - renderer.abortSelection(); - if (camera instanceof Camtool) { - try { - renderer.setShowReticle(false); - ((Camtool) camera).resetRoi(); - } catch (IOException ex) { - showException(ex); - } - } - }); - - renderer.getPopupMenu().add(menuShowImageData); - renderer.getPopupMenu().add(menuCalibrate); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuSetROI); - renderer.getPopupMenu().add(menuResetROI); - renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(camera instanceof Camtool); - menuSetROI.setEnabled(camera instanceof Camtool); - menuShowImageData.setVisible(camera instanceof Camtool); - menuCalibrate.setVisible(camera instanceof Camtool); - menuCalibrate.setEnabled(calibrationOverlays==null); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - } - }); - renderer.getPopupMenu().setVisible(false); - - showFit = buttonFit.isSelected(); - showProfile = buttonProfile.isSelected(); - - pauseSelection.setVisible(false); - pauseSelection.setMinValue(1); - pauseSelection.addListener(new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - if (editing && (value >= 1) && (value <= imageBuffer.size())) { - updatePause(); - } - } - }); - imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 20)); - imageBufferOverlay.setFixed(true); - imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_RIGHT); - if (MainFrame.isDark()) { - textState.setEnabled(true); - } - } - - @Override - public void onStart() { - super.onStart(); - if (App.hasArgument("ct")) { - boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonCamtool.setSelected(!direct); - buttonDirect.setSelected(direct); - } - if (App.hasArgument("priv_srv")) { - try { - System.out.println("Starting camtool server on port: " + localServerPort); - //Was creating sub-processes which cannot be destroyed. - //String cmd = "cam_server"; - //cmd = "source /opt/gfa/python\n" + cmd; - //privateServer = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd}); - String cmd = "/opt/gfa/python-3.5/2.4.1/bin/python /opt/gfa/python-3.5/latest/bin/cam_server"; - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - cmd = cmd + " -p " + localServerPort + " -b " + configFolder; - privateServer = Runtime.getRuntime().exec(cmd); - //System.out.println("pid = " + Sys.getPid(privateServer)); - long start = System.currentTimeMillis(); - while (true){ - try (TcpClient c = new TcpClient("localhost", localServerPort)){ - try{ - c.connect(); - System.out.println("Connected to camtool server on port: " + localServerPort); - break; - } catch (Exception ex){ - } - } - Thread.sleep(10); - if ((System.currentTimeMillis() - start) > 5000){ - errorOverlay = new Text(renderer.getPenErrorText(), "Error connecting to server at port " + localServerPort , new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - renderer.addOverlay(errorOverlay); - break; - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - } - - - - @Override - public void onStop() { - try{ - if (camera != null) { - camera.close(); - camera = null; - } - if (privateServer!=null){ - System.out.println("Closing camtool server"); - //int pid = Sys.getPid(privateServer); - privateServer.destroyForcibly(); - //if (pid>0){ - // System.out.println("Killing pid = " + pid); - // Runtime.getRuntime().exec("kill " + pid); - // - //} - privateServer = null; - } - } catch (Exception ex) { - ex.printStackTrace(); - } - super.onStop(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - comboCameras.setEnabled(false); - if (App.hasArgument("s")) { - renderer.setDevice((Source) getDevice("image")); - renderer.setAutoScroll(true); - ((Source) getDevice("image")).addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - manageFit(bi, data); - manageUserOverlays(bi, data); - } - - @Override - public void onError(Object o, Exception excptn) { - } - } - ); - - } else { - usingCamtool = buttonCamtool.isSelected(); - updateCameraList(); - comboCameras.setEnabled(true); - setComboCameraSelection(-1); - - if (comboCameras.getModel().getSize() > 0) { - try { - if (App.hasArgument("cam")) { - setComboCameraSelection(App.getArgumentValue("cam")); - comboCamerasActionPerformed(null); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - startTimer(1000); - } - - DefaultComboBoxModel getCameraListFromFolder() throws Exception { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String cam:cameras) { - model.addElement(cam); - } - return model; - } - - DefaultComboBoxModel getCameraListFromCamtool() throws IOException, InterruptedException { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - Camtool camtool = newCamtool(); - try { - camtool.initialize(); - List cameras = camtool.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - model.addElement(camera); - } - //model.addElement(Camtool.SIMULATION); - } finally { - camtool.close(); - } - return model; - } - - Camtool newCamtool(){ - if (serverUrl!=null){ - return new Camtool(CAMERA_DEVICE_NAME, serverUrl); - } - return (localServerPort != null) ? new Camtool(CAMERA_DEVICE_NAME, "localhost:"+localServerPort) : new Camtool(CAMERA_DEVICE_NAME); - } - - boolean updatingCameraSelection; - - void setComboCameraSelection(Object selection) { - updatingCameraSelection = true; - try { - comboCameras.setSelectedItem(selection); - } finally { - updatingCameraSelection = false; - } - } - - boolean usingCamtool; - - void updateCameraList() { - try { - String selected = (String) comboCameras.getSelectedItem(); - DefaultComboBoxModel model = usingCamtool ? getCameraListFromCamtool() : getCameraListFromFolder(); - if (App.hasArgument("cam")) { - String cam = App.getArgumentValue("cam"); - if (model.getIndexOf(cam) < 0) { - model.addElement(cam); - } - } - comboCameras.setModel(model); - if (selected != null) { - setComboCameraSelection(selected); - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateStop(); - } - } - - final Object lockOverlays = new Object(); - - void manageFit(BufferedImage bi, Data data) { - Overlay[][] fo = ((bi == null) || ((!showFit && !showProfile))) ? null : getFitOverlays(data); - synchronized(lockOverlays){ - fo = (fo==null) ? new Overlay[][]{null, null} : fo; - renderer.updateOverlays(fo[0], profileOv); - profileOv = fo[0]; - renderer.updateOverlays(fo[1], fitOv); - fitOv = fo[1]; - } - } - - void manageUserOverlays(BufferedImage bi, Data data) { - Overlay[] fo = (bi == null) ? null : getUserOverlays(data); - synchronized(lockOverlays){ - renderer.updateOverlays(fo, userOv); - userOv = fo; - } - } - - - @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - Thread devicesInitTask; - - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Setting camera: " + cameraName + " [" + (buttonCamtool.isSelected() ? "camtool" : "direct") + "]"); - parseUserOverlays(); - errorOverlay = null; - - if (dataTableDialog!=null){ - dataTableDialog.dispose(); - dataTableDialog = null; - } - dataTableModel = null; - - if (calibrationDialolg!=null){ - calibrationDialolg.dispose(); - calibrationDialolg = null; - } - - boolean was_camtool = false; - if (camera != null) { - //camera.removeAllListeners(); - was_camtool = camera instanceof Camtool; - camera.close(); - camera = null; - } - renderer.setDevice(null); - - renderer.setShowReticle(false); - renderer.removeOverlays(fitOv); - renderer.removeOverlays(profileOv); - renderer.removeOverlays(userOv); - renderer.clear(); - renderer.resetZoom(); - - boolean changed = !String.valueOf(cameraName).equals(this.cameraName); - this.cameraName = cameraName; - - if (changed || buttonDirect.isSelected()) { - spinnerThreshold.setVisible(false); - spinnerGrThreshold.setVisible(false); labelGrThreshold.setVisible(false); - spinnerGrScale.setVisible(false); labelGrScale.setVisible(false); - checkThreshold.setEnabled(false); - checkGoodRegion.setEnabled(false); - } - if (changed) { - checkBackground.setEnabled(false); - if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { - devicesInitTask.interrupt(); - } - if (screen != null) { - screen.close(); - screen = null; - } - if (filter != null) { - filter.close(); - filter = null; - } - } - if (cameraName == null) { - return; - } - - synchronized (imageBuffer) { - currentFrame = null; - imageBuffer.clear(); - } - - - try { - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - Path configFile = Paths.get(configFolder, cameraName + ".json"); - cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - - if (buttonCamtool.isSelected()) { - camera = newCamtool(); - camera.getConfig().flipHorizontally = false; - camera.getConfig().flipVertically = false; - camera.getConfig().rotation = 0.0; - camera.getConfig().roiX = 0; - camera.getConfig().roiY = 0; - camera.getConfig().roiWidth = -1; - camera.getConfig().roiHeight = -1; - } else { - //camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName); - camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName}); - } - camera.initialize(); - camera.assertInitialized(); - System.out.println("Camera initialization OK"); - if (camera instanceof Camtool) { - //Managing no background exception. Can be done in a better way? -// if (changed) { - ((Camtool) camera).startPipeline(cameraName, null); - updateCamtoolControls(); -// } else { -// ((Camtool) camera).startPipeline(cameraName, null, checkBackground.isSelected(), null, null, null); -// } - // HashMap gr = null; - // if (goodRegion){ - // gr = new HashMap<>(); - // gr.put("threshold", spinnerGrThreshold.getValue()); - // gr.put("gfscale", spinnerGrScale.getValue()); - // } - // ((Camtool) camera).startPipeline(cameraName, null, checkBackground.isSelected(), null, checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null, gr); - //} - - checkThreshold.setEnabled(true); - checkGoodRegion.setEnabled(true); - - ((Camtool) camera).startReceiver(); - } else { - checkThreshold.setSelected(false); - checkGoodRegion.setSelected(false); - if (polling <= 0) { - camera.setMonitored(true); - } else { - camera.setPolling(polling); - } - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - - buttonReticle.setEnabled(camera.getConfig().isCalibrated()); - camera.getConfig().save(); - renderer.setDevice(camera); - renderer.setAutoScroll(true); - renderer.setMarker(marker); - imageSize = null; - - camera.addListener(new ImageListener() { - @Override - public void onImage(Object o, BufferedImage bi, Data data) { - if (bi != null) { - if ((imageSize== null) || imageSize.width!=bi.getWidth() || imageSize.height!=bi.getHeight()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { - centralizeRenderer(); - } - checkReticle(); - } - }); - imageSize = new Dimension (bi.getWidth(), bi.getHeight()); - } - renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); - } - //renderer.setCalibration(camera.getCalibration()); - if (!renderer.isPaused()) { - if (data != null) { - synchronized (imageBuffer) { - currentFrame =new Frame(data); - if (imageBufferLenght > 1) { - imageBuffer.add(currentFrame); - if (imageBuffer.size() > imageBufferLenght) { - imageBuffer.remove(0); - } - } - } - } - manageFit(bi, data); - manageUserOverlays(bi, data); - } - //updateImageData(); - } - - @Override - public void onError(Object o, Exception excptn) { - } - }); - - } catch (Exception ex) { - ex.printStackTrace(); - showException(ex); - renderer.clearOverlays(); - updateCamtoolControls(); - if (renderer.getDevice() == null) { - //renderer.setZoom(1.0); - //renderer.setMode(RendererMode.Zoom); - errorOverlay = new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - errorOverlay.setFixed(true); - errorOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - renderer.addOverlay(errorOverlay); - } - } finally { - //checkReticle(); - onTimer(); - } - onChangeColormap(null); - checkBackground.setEnabled(true); - if (changed) { - comboScreen.setModel(new DefaultComboBoxModel()); - comboFilter.setModel(new DefaultComboBoxModel()); - - //Parallelizing initialization - devicesInitTask = new Thread(() -> { - try { - if (cameraName.contains("DSRM")){ - screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); - } else { - screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); - } - screen.setMonitored(true); - screen.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : screen.getPositions()) { - model.addElement(pos); - } - comboScreen.setModel(model); - comboScreen.setSelectedItem(screen.read()); - - } catch (Exception ex) { - comboScreen.setModel(new DefaultComboBoxModel()); - System.err.println(ex.getMessage()); - screen = null; - } - comboScreen.setEnabled(screen != null); - valueScreen.setDevice(screen); - - try { - filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); - filter.setMonitored(true); - filter.initialize(); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos : filter.getPositions()) { - model.addElement(pos); - } - comboFilter.setModel(model); - comboFilter.setSelectedItem(filter.read()); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - filter = null; - } - comboFilter.setEnabled(filter != null); - valueFilter.setDevice(filter); - }); - devicesInitTask.start(); - } - - } - - volatile Dimension imageSize; - - void checkReticle() { - if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) { - //renderer.setCalibration(camera.getCalibration()); - renderer.configureReticle(new Dimension(800, 800), 200); - renderer.setShowReticle(true); - } else { - //renderer.setCalibration(null); - renderer.setShowReticle(false); - } - renderer.refresh(); - } - - void checkMarker() { - if (camera != null) { - if (buttonMarker.isSelected()) { - Dimension d = renderer.getImageSize(); - Point p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2); - Overlay ov = null; - marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100)); - marker.setMovable(true); - marker.setPassive(false); - } else { - marker = null; - } - renderer.setMarker(marker); - } - } - - void updateZoom() { - try { - buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom) { - if (renderer.getZoom() == 1) { - buttonZoomNormal.setSelected(true); - } else if (renderer.getZoom() == 0.5) { - buttonZoom05.setSelected(true); - } else if (renderer.getZoom() == 0.25) { - buttonZoom025.setSelected(true); - } else if (renderer.getZoom() == 2.0) { - buttonZoom2.setSelected(true); - } else { - buttonGroup1.clearSelection(); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - boolean updatingColormap; - - void updateColormap() { - updatingColormap = true; - try { - if ((camera != null) && (camera instanceof ColormapSource)) { - ColormapSourceConfig config = ((ColormapSource) camera).getConfig(); - comboColormap.setSelectedItem(config.colormap); - if (config.isDefaultColormap()) { - buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic) { - buttonAutomatic.setSelected(true); - } else { - buttonManual.setSelected(true); - } - - //spinnerMin.setVisible(buttonManual.isSelected()); labelMin.setVisible(spinnerMin.isVisible()); - //spinnerMax.setVisible(buttonManual.isSelected()); labelMax.setVisible(spinnerMax.isVisible()); - spinnerMin.setEnabled(buttonManual.isSelected()); - spinnerMax.setEnabled(buttonManual.isSelected()); - spinnerMin.setValue(Double.isNaN(config.colormapMin) ? 0 : Math.min(Math.max((int) config.colormapMin, 0), 65535)); - spinnerMax.setValue(Double.isNaN(config.colormapMax) ? 0 : Math.min(Math.max((int) config.colormapMax, 0), 65535)); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - updatingColormap = false; - } - - boolean updatingCamtoolControls; - - void updateCamtoolControls() { - if ((camera != null) && (camera instanceof Camtool)) { - updatingCamtoolControls = true; - try { - checkBackground.setSelected(((Camtool) camera).getBackgroundSubtraction()); - Double threshold = ((Camtool) camera).getThreshold(); - checkThreshold.setSelected(threshold != null); - spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = ((Camtool) camera).getGoodRegion(); - checkGoodRegion.setSelected(gr != null); - if (gr != null){ - spinnerGrThreshold.setValue(gr.get("threshold")); - spinnerGrScale.setValue(gr.get("gfscale")); - } - } catch (Exception ex) { - } - goodRegion = checkGoodRegion.isSelected(); - spinnerThreshold.setVisible(checkThreshold.isSelected()); - spinnerGrThreshold.setVisible(goodRegion); labelGrThreshold.setVisible(spinnerGrThreshold.isVisible()); - spinnerGrScale.setVisible(goodRegion); labelGrScale.setVisible(spinnerGrScale.isVisible()); - updatingCamtoolControls = false; - } - } - - boolean isCameraStopped() { - if ((camera != null) && (camera instanceof Camtool)) { - if (!((Camtool) camera).isPipelineStarted()) { - return true; - } - } - return ((camera == null) || (camera.isClosed()) || !buttonStop.isEnabled()); - } - - void updateStop() { - buttonStop.setEnabled(comboCameras.getSelectedItem() != null); - buttonStop.setText(isCameraStopped() ? "Start" : "Stop"); - - } - - @Override - protected void onTimer() { - for (Device dev : new Device[]{screen, filter}) { - if (dev != null) { - dev.request(); - } - } - - textState.setText((camera == null) ? "" : camera.getState().toString()); - buttonArgs.setEnabled(camera != null); - if (App.hasArgument("s")) { - try { - ((Source) getDevice("image")).initialize(); - } catch (IOException ex) { - Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex); - } - } - if (renderer.isPaused() != buttonPause.isSelected()) { - buttonPause.setSelected(renderer.isPaused()); - buttonPauseActionPerformed(null); - } - if (renderer.getShowReticle() != buttonReticle.isSelected()) { - //buttonReticle.setSelected(renderer.getShowReticle()); - } - if ((renderer.getMarker() == null) && buttonMarker.isSelected()) { - buttonMarker.setSelected(false); - } - if (!renderer.isPaused() && (dataTableDialog!=null) && (dataTableDialog.isShowing())){ - updateImageData(); - } - updateZoom(); - updateColormap(); - updateStop(); - buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); - } - - Pen penFit = new Pen(new Color(192, 105, 0), 1); - Pen penCross = new Pen(new Color(192, 105, 0), 1); - - - Frame getCurrentFrame(){ - if ((imageBufferLenght > 1) && (renderer.isPaused())) { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - return (index < imageBuffer.size()) ? imageBuffer.get(index) : null; - } - } - return currentFrame; - } - - Frame getFrame(Data data){ - synchronized (imageBuffer) { - for (Frame f : imageBuffer) { - if (f.data == data) { - return f; - } - } - } - return null; - } - - Overlay[][] getFitOverlays(Data data) { - Overlays.Polyline hgaussian = null; - Overlays.Polyline vgaussian = null; - Overlays.Polyline hprofile = null; - Overlays.Polyline vprofile = null; - Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null; - Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null; - double[] pX = null, pY = null, gX = null, gY = null; - int height = data.getHeight(); - int width = data.getWidth(); - //Double xCom=null, yCom=null; - if (data != null) { - int profileSize = renderer.getProfileSize(); - if ((useCamtoolStats) && (camera instanceof Camtool)) { - try { - - ImageData id = getFrame(data); - if (id==null){ - return null; - } - xMean = id.x_fit_mean; xSigma = id.x_fit_standard_deviation;yMean = id.y_fit_mean;ySigma = id.y_fit_standard_deviation; - gX = id.x_fit_gauss_function; gY = id.y_fit_gauss_function; - pX = id.x_profile; pY = id.y_profile; - xCom = id.x_center_of_mass; xRms = id.x_rms; yCom = id.y_center_of_mass; yRms = id.y_rms; - - profileSize /= 4; - if (pX != null) { - int[] x = Arr.indexesInt(pX.length); - int[] y = new int[pX.length]; - int[] p = new int[pX.length]; - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - Double min = Collections.min(l); - Double max = Collections.max(l); - double minPlot = min; - double rangePlot = max - min; - - for (int i = 0; i < x.length; i++) { - if (gX != null) { - y[i] = (int) (height - 1 - (((gX[i] - minPlot) / rangePlot) * profileSize)); - } - p[i] = (int) (height - 1 - (((pX[i] - minPlot) / rangePlot) * profileSize)); - } - - if (goodRegion){ - for (int i = 0; i < x.length; i++) { - y[i] = (Double.isNaN(gX[i])) ? 100000 : y[i]; - } - } - - vgaussian = new Overlays.Polyline(penFit, x, y); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - - if (pY != null) { - int[] y = Arr.indexesInt(pY.length); - int[] x = new int[pY.length]; - int[] p = new int[pY.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - Double min = Collections.min(l); - Double max = Collections.max(l); - double minPlot = min; - double rangePlot = max - min; - - for (int i = 0; i < x.length; i++) { - if (gY != null) { - x[i] = (int) (((gY[i] - minPlot) / rangePlot) * profileSize); - } - p[i] = (int) (((pY[i] - minPlot) / rangePlot) * profileSize); - } - - if (goodRegion){ - for (int i = 0; i < x.length; i++) { - x[i] = (Double.isNaN(gY[i])) ? -1 :x[i]; - } - } - hgaussian = new Overlays.Polyline(penFit, x, y); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, y); - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - return null; - } - } else { - ArrayProperties properties = data.getProperties(); - double maxPlot = properties.max; - double minPlot = properties.min; - double rangePlot = maxPlot - minPlot; - - if (rangePlot <= 0) { - return null; - } - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit){ - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - } - } - } - if (showProfile){ - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit){ - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile){ - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - if (renderer.getCalibration() != null) { - if (xSigma != null) { - xSigma *= renderer.getCalibration().getScaleX(); - } - if (ySigma != null) { - ySigma *= renderer.getCalibration().getScaleY(); - } - if (xMean != null) { - xMean = data.getX((int) Math.round(xMean)); - } - if (yMean != null) { - yMean = data.getY((int) Math.round(yMean)); - } - } - } - final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px"; - final String fmt = "%7.1f" + units; - Overlays.Text textCom = null; - Overlay[] pOv=null, fOv=null; - Point textPosition = new Point(12, 20); - if (showProfile){ - if ((xCom != null) && (yCom != null)) { - String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt,xCom, xRms,yCom, yRms); - textCom = new Overlays.Text(renderer.getPenProfile(), text, new Font(Font.MONOSPACED, 0, 14), textPosition); - textCom.setFixed(true); - textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - } - pOv = new Overlay[]{hprofile, vprofile, textCom}; - } - if (showFit){ - Overlays.Crosshairs cross = null; - Overlays.Text textFit = null; - if ((xMean != null) && (yMean != null)) { - String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt,xMean, xSigma, yMean, ySigma); - textFit = new Overlays.Text(penFit, text, new Font(Font.MONOSPACED, 0, 14), showProfile ? new Point(12, 54) : textPosition ); - textFit.setFixed(true); - textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); - Point center = new Point(xMean.intValue(), yMean.intValue()); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean)); - xSigma /= renderer.getCalibration().getScaleX(); - ySigma /= renderer.getCalibration().getScaleY(); - } - cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue()))); - } - fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit}; - - if (goodRegion){ - try{ - double[] x = getCamtoolDoubleArray("gr_x_axis"); double[] y = getCamtoolDoubleArray("gr_y_axis"); - double x1 = x[0]; double x2 = x[x.length-1]; double y1 = y[0]; double y2 = y[y.length-1]; - Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); - goodRegionOv.setCalibration(renderer.getCalibration()); - goodRegionOv.setAbsolutePosition(new PointDouble(x1, y1)); - goodRegionOv.setAbsoluteSize(new DimensionDouble(x2-x1, y2-y1)); - fOv = Arr.append(fOv, goodRegionOv); - } catch (Exception ex){ - } - } - - } - return new Overlay[][]{pOv, fOv}; - } - return null; - } - - class UserOverlay { - - String name; - Overlay obj; - String[] channels; - } - ArrayList userOverlayConfig; - - void parseUserOverlays() { - Properties userOverlays = new Properties(); - userOverlayConfig = new ArrayList<>(); - if (userOverlaysConfigFile != null) { - try { - try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { - userOverlays.load(in); - - for (String name : userOverlays.stringPropertyNames()) { - String val = userOverlays.getProperty(name); - try { - UserOverlay uo = new UserOverlay(); - uo.name = name; - String type = val.substring(0, val.indexOf("(")).trim(); - String pars = val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")).trim(); - String[] tokens = pars.split(","); - for (int i = 0; i < tokens.length; i++) { - tokens[i] = tokens[i].trim(); - } - Color color = Color.GRAY; - try { - color = (Color) Color.class.getField(tokens[tokens.length - 1].toUpperCase()).get(null); - } catch (Exception ex) { - } - Pen pen = new Pen(color); - try { - String[] penTokens = tokens[tokens.length - 1].split(":"); - color = (Color) Color.class.getField(penTokens[0].toUpperCase()).get(null); - int width = Integer.valueOf(penTokens[1]); - Pen.LineStyle style = Pen.LineStyle.valueOf(penTokens[2]); - pen = new Pen(color, width, style); - } catch (Exception ex) { - } - switch (type) { - case "Point": - uo.obj = new Overlays.Crosshairs(); - uo.obj.setSize(new Dimension(Integer.valueOf(tokens[2]), Integer.valueOf(tokens[3]))); - break; - case "Line": - uo.obj = new Overlays.Line(); - break; - case "Arrow": - uo.obj = new Overlays.Arrow(); - break; - case "Rect": - uo.obj = new Overlays.Rect(); - break; - case "Ellipse": - uo.obj = new Overlays.Ellipse(); - break; - case "Polyline": - uo.obj = new Overlays.Polyline(); - break; - } - if (type.equals("Polyline") || type.equals("Point")) { - uo.channels = new String[]{tokens[0], tokens[1]}; - } else { - uo.channels = new String[]{tokens[0], tokens[1], tokens[2], tokens[3]}; - } - uo.obj.setPen(pen); - userOverlayConfig.add(uo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - Overlay[] getUserOverlays(Data data) { - ArrayList ret = new ArrayList<>(); - if (camera instanceof Camtool) { - for (UserOverlay uo : userOverlayConfig) { - try { - Overlay ov = uo.obj; - //Overlay ov = (Overlay)uo.cls.newInstance(); - ov.setCalibration(renderer.getCalibration()); - boolean valid = false; - if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[1]); - if ((x != null) || (y !=null)) { - if (x == null) { - x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); - } - if (y == null) { - y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length); - } - ((Overlays.Polyline) ov).updateAbsolute(x, y); - valid = true; - } - } else { - Double x = getCamtoolDouble(uo.channels[0]); Double y = getCamtoolDouble(uo.channels[1]); - if ((x != null) && (y !=null)) { - PointDouble position = new PointDouble(x,y); - ov.setAbsolutePosition(position); - if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = getCamtoolDouble(uo.channels[2]); Double y2 = getCamtoolDouble(uo.channels[3]); - if ((x != null) && (y !=null)) { - DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); - ov.setAbsoluteSize(size); - valid = true; - } - } else { - valid = true; - } - } - } - if (valid){ - ret.add(ov); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - return ret.toArray(new Overlay[0]); - } - - double[] getComRms(double[] arr, double[] x) { - if (arr != null) { - double xmd = 0; - double xmd2 = 0; - double total = 0; - for (int i=0; i< arr.length; i++) { - double v = (arr[i] * x[i]); - xmd += v; - xmd2 += (v * x[i]); - total += arr[i]; - } - if (total > 0) { - double com = xmd / total; - double com2 = xmd2 / total; - double rms = Math.sqrt(Math.abs(com2 - com * com)); - return new double[] {com, rms}; - } - } - return new double[]{Double.NaN, Double.NaN}; - } - - double[] fitGaussianScript(int[] y, int[] x) { - ScriptManager sm = Context.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); - sm.setVar("y", y); - sm.setVar("x", x); - InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])"); - if (r.exception != null) { - r.exception.printStackTrace(); - } else { - List ret = (List) sm.getVar("r"); - if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) { - double norm = (Double) ((List) ret.get(0)).get(0); - double mean = (Double) ((List) ret.get(0)).get(1); - double sigma = (Double) ((List) ret.get(0)).get(2); - return new double[]{norm, mean, sigma}; - } - } - return null; - } - - double[] fitGaussian(double[] y, int[] x) { - try { - ArrayProperties pY = ArrayProperties.get(y); - GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000); - ArrayList values = new ArrayList<>(); - for (int i = 0; i < y.length; i++) { - values.add(new WeightedObservedPoint(1.0, x[i], y[i])); - } - return fitter.fit(values); - } catch (Exception ex) { - return null; - } - - } - - double[] getFitFunction(double[] pars, int[] x) { - double[] fit = new double[x.length]; - Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); - for (int i = 0; i < x.length; i++) { - fit[i] = g.value(x[i]); - } - return fit; - } - - void setHistogramVisible(boolean value) { - if (value) { - if ((histogramDialog == null) || (!histogramDialog.isShowing())) { - Histogram histogram = new Histogram(true); - histogram.setRenderer(renderer); - histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram); - renderer.refresh(); - } - } else { - if (histogramDialog != null) { - histogramDialog.setVisible(false); - histogramDialog = null; - } - } - } - - void setLaserState(boolean value) throws Exception { - System.out.println( "Setting laser state: " + value); - Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); - Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); - Thread.sleep(3000); - } - - boolean getLaserState() throws Exception { - return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); - } - - void elog(String logbook, String title, String message, String[] attachments) throws Exception { - String domain = ""; - String category = "Info"; - String entry = ""; - StringBuffer cmd = new StringBuffer(); - - cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); - cmd.append("-a \"Author=ScreenPanel\" "); - cmd.append("-a \"Type=pshell\" "); - cmd.append("-a \"Entry=").append(entry).append("\" "); - cmd.append("-a \"Title=").append(title).append("\" "); - cmd.append("-a \"Category=").append(category).append("\" "); - cmd.append("-a \"Domain=").append(domain).append("\" "); - for (String attachment : attachments) { - cmd.append("-f \"").append(attachment).append("\" "); - } - cmd.append("-n 1 "); - cmd.append("\"").append(message).append("\" "); - System.out.println(cmd.toString()); - - final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); - new Thread(() -> { - try { - process.waitFor(); - int bytes = process.getInputStream().available(); - byte[] arr = new byte[bytes]; - process.getInputStream().read(arr, 0, bytes); - System.out.println(new String(arr)); - bytes = process.getErrorStream().available(); - arr = new byte[bytes]; - process.getErrorStream().read(arr, 0, bytes); - System.err.println(new String(arr)); - } catch (Exception ex) { - System.err.println(ex); - } - }).start(); - } - - void centralizeRenderer() { - Point center = null; - Dimension size = renderer.getImageSize(); - double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom(); - if (renderer.getCalibration() != null) { - center = renderer.getCalibration().getCenter(); - } else if (size != null) { - center = new Point(size.width / 2, size.height / 2); - } - if (center != null) { - Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0), - Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0)); - renderer.setViewPosition(topleft); - } - } - - void updatePause() { - int index = ((int) pauseSelection.getValue()) - 1; - synchronized (imageBuffer) { - if (index < imageBuffer.size()) { - Data data = imageBuffer.get(index).data; - BufferedImage image = camera.generateImage(data); - renderer.setImage(renderer.getOrigin(), image, data); - imageBufferOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS")); - manageFit(image, data); - manageUserOverlays(image, data); - } - } - } - - void writeFrameMetadata(String path, Frame frame) throws Exception{ - getContext().getDataManager().setAttribute("/", "Camera", String.valueOf(cameraName)); - getContext().getDataManager().setAttribute("/", "Screen", String.valueOf(valueScreen.getLabel().getText())); - getContext().getDataManager().setAttribute("/", "Filter", String.valueOf(valueFilter.getLabel().getText())); - Calibration cal = renderer.getCalibration(); - getContext().getDataManager().setAttribute("/", "Calibration", cal == null ? new double[]{1,1,0,0} : - new double[]{cal.getScaleX(), cal.getScaleY(), cal.getOffsetX(), cal.getOffsetY()}); - getContext().getDataManager().setAttribute(path, "Timestamp", Chrono.getTimeStr(frame.data.getTimestamp(), "HH:mm:ss.SSS")); - if (camera instanceof Camtool){ - try{ - getContext().getDataManager().setAttribute("/", "ROI", ((Camtool) camera).getRoi()); - } catch (Exception ex){ - getContext().getDataManager().setAttribute("/", "ROI", new int[]{0,0,-1,-1}); - } - if (frame!=null){ - for (Field f:ImageData.class.getFields()){ - Object value = f.get(frame); - getContext().getDataManager().setAttribute(path, f.getName(), (value == null) ? Double.NaN : value); - } - } - for (String name : new String[]{"x_axis", "y_axis", "gr_x_axis", "gr_y_axis"}){ - double[] val = getCamtoolDoubleArray(name); - getContext().getDataManager().setAttribute("/", "GoodRegion", goodRegion); - if (val!=null){ - getContext().getDataManager().setAttribute("/", name, val); - } - } - } - } - - void saveSnapshot() throws Exception { - getContext().setExecutionPars("snapshot"); - String path = "/data"; - String snapshotFile = null; - synchronized (imageBuffer) { - Frame id = getCurrentFrame(); - if (id==null){ - throw new Exception("No current image"); - } - Object data = id.data.getMatrix(); - getContext().getDataManager().setDataset(path, data, id.data.isUnsigned()); - writeFrameMetadata(path, id); - getContext().getDataManager().closeOutput(); - //Enforce the same timestamp to data & image files. - //snapshotFile = getContext().getSetup().expandPath("{images}/{date}_{time}_snapshot.png", getContext().getExecutionPars().getStart()); - snapshotFile = getContext().getExecutionPars().getPath() + ".png"; - renderer.saveSnapshot(snapshotFile, "png", true); - } - - JPanel panel = new JPanel(); - GridBagLayout layout = new GridBagLayout(); - layout.columnWidths = new int[]{0, 180}; //Minimum width - layout.rowHeights = new int[]{30, 30, 30}; //Minimum height - panel.setLayout(layout); - JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); - JTextField textComment = new JTextField(); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - panel.add(new JLabel("Data file:"), c); - c.gridy = 1; - panel.add(new JLabel("Logbook:"), c); - c.gridy = 2; - panel.add(new JLabel("Comment:"), c); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - panel.add(textComment, c); - c.gridy = 1; - panel.add(comboLogbook, c); - c.gridy = 0; - panel.add(new JLabel(getContext().getExecutionPars().getPath()), c); - - if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes){ - StringBuilder message = new StringBuilder(); - message.append("Camera: ").append(cameraName).append(" ("). - append((camera instanceof Camtool) ? "camtool" : "direct").append(")").append("\n"); - message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); - message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); - message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); - message.append("Comment: ").append(textComment.getText()).append("\n"); - if ((fitOv != null) && (fitOv.length > 5)) { - Overlays.Text text = (Overlays.Text) fitOv[5]; - message.append(text.getText()).append("\n"); - } - elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - //SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000); - //elog("SwissFEL commissioning data", "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); - } - - void saveStack() throws Exception { - getContext().setExecutionPars("snapshot"); - ArrayList x = new ArrayList<>(); - ArrayList y = new ArrayList<>(); - synchronized (imageBuffer) { - for (int i = 0; i < imageBuffer.size(); i++) { - Frame frame = imageBuffer.get(i); - String path = "/data_" + i; - getContext().getDataManager().setDataset(path, frame.data.getMatrix(), frame.data.isUnsigned()); - writeFrameMetadata(path, frame); - x.add(frame.x_fit_mean); - y.add(frame.y_fit_mean); - } - } - DescStatsDouble xs = new DescStatsDouble(x.toArray(new Double[0]), -1); - DescStatsDouble ys = new DescStatsDouble(y.toArray(new Double[0]), -1); - - getContext().getDataManager().closeOutput(); - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000); - } - - JDialog calibrationDialolg; - Overlay[] calibrationOverlays; - void calibrate() throws IOException{ - if ( (camera instanceof Camtool) && (calibrationOverlays==null)) { - Map calibration = ((Camtool) camera).getCalibration(cameraName); - //Map calibration = (Map) ((Camtool) camera).getConfig(cameraName).get("calibration"); - ((Camtool) camera).resetRoi(); - renderer.setMode(RendererMode.Fit); - Pen pen = new Pen(new Color(128, 0, 128), 1, Pen.LineStyle.solid); - Overlays.Crosshairs top = new Overlays.Crosshairs(pen, new Dimension(-1, 1)); - Overlays.Crosshairs bottom = new Overlays.Crosshairs(pen, new Dimension(-1, 1)); - Overlays.Crosshairs left = new Overlays.Crosshairs(pen, new Dimension(1, -1)); - Overlays.Crosshairs right = new Overlays.Crosshairs(pen, new Dimension(1, -1)); - calibrationOverlays = new Overlay[]{top, bottom, left, right}; - for (Overlay ov : calibrationOverlays){ - ov.setMovable(true); - } - renderer.addOverlays(calibrationOverlays); - - try{ - List refMarker = ((List)calibration.get("reference_marker")); - Rectangle r = new Rectangle(); - left.update(new Point(Math.max((Integer)refMarker.get(0), 0), 0)); - top.update(new Point(0, Math.max((Integer)refMarker.get(1), 0))); - right.update(new Point(Math.max((Integer)refMarker.get(2), 0), 0)); - bottom.update(new Point(0, Math.max((Integer)refMarker.get(3),0))); - } catch (Exception ex){ - SwingUtils.invokeDelayed(() -> { - Dimension size = renderer.getImageSize(); - top.update(new Point(0, size.height/8)); - bottom.update(new Point(0, 7*size.height/8)); - left.update(new Point(size.width/8, 0)); - right.update(new Point(7*size.width/8, 0)); - }, 500); - } - - JPanel panel = new JPanel(new BorderLayout()); - JTextField textWidth = new JTextField(); - JTextField textHeight= new JTextField(); - if (calibration!=null){ - textWidth.setText(String.valueOf(calibration.get("reference_marker_width"))); - textHeight.setText(String.valueOf(calibration.get("reference_marker_height"))); - } - ((BorderLayout) panel.getLayout()).setVgap(10); - JPanel p1 = new JPanel(new BorderLayout()); - ((BorderLayout) p1.getLayout()).setHgap(5); - p1.add(new JLabel("Move the lines to the reference marks"), BorderLayout.NORTH); - p1.add(new JLabel("and press 'OK' to update the calibration."), BorderLayout.SOUTH); - panel.add(p1, BorderLayout.NORTH); - JPanel p2 = new JPanel(new BorderLayout()); - ((BorderLayout) p2.getLayout()).setHgap(5); - p2.add(new JLabel("Reference marker width (um): "), BorderLayout.WEST); - p2.add(textWidth, BorderLayout.EAST); - panel.add(p2, BorderLayout.CENTER); - JPanel p3 = new JPanel(new BorderLayout()); - ((BorderLayout) p3.getLayout()).setHgap(5); - p3.add(new JLabel("Reference marker height(um): "), BorderLayout.WEST); - p3.add(textHeight, BorderLayout.EAST); - panel.add(p3, BorderLayout.SOUTH); - textWidth.setPreferredSize(new Dimension(70, textWidth.getPreferredSize().height)); - textHeight.setPreferredSize(new Dimension(70, textHeight.getPreferredSize().height)); - - JOptionPane calibrationMessage = new JOptionPane(panel,JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,null, null); - calibrationDialolg = calibrationMessage.createDialog(getTopLevel(), "Calibration"); - calibrationDialolg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - calibrationDialolg.setModal(false); - calibrationDialolg.addWindowListener(new java.awt.event.WindowAdapter() { - @Override - public void windowClosed(WindowEvent e) { - if (calibrationOverlays!=null){ - try { - renderer.removeOverlays(calibrationOverlays); - calibrationOverlays = null; - calibrationDialolg = null; - if (calibrationMessage.getValue().equals(0)){ //If pressed OK - int x1 = Math.min(left.getPosition().x, right.getPosition().x); - int x2 = Math.max(left.getPosition().x, right.getPosition().x); - int y1 = Math.min(top.getPosition().y, bottom.getPosition().y); - int y2 = Math.max(top.getPosition().y, bottom.getPosition().y); - if ((x1!=-1) && (x2!=-1) && (y1!=-1) && (y2!=-1)){ - System.out.println("Updating " + cameraName + " calibration: " + x1 + ", "+ x2 + ", " + y1 + ", " + y2); - HashMap c = new HashMap(); - c.put("reference_marker", Arrays.asList(new Integer[]{x1, y1, x2, y2})); - if (textWidth.getText().trim().length() > 0){ - c.put("reference_marker_width", Double.valueOf(textWidth.getText())); - } - if (textHeight.getText().trim().length() > 0){ - c.put("reference_marker_height", Double.valueOf(textHeight.getText())); - } - ((Camtool) camera).setCalibration(cameraName, c); - Logger.getLogger(ScreenPanel.class.getName()).warning("Updated " + cameraName + " calibration: " + x1 + ", "+ x2 + ", " + y1 + ", " + y2); - } - } - } catch (IOException ex) { - Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - @Override - public void windowDeactivated(java.awt.event.WindowEvent e) { - if (!calibrationDialolg.isShowing()){ //windowClosed is not called if window closed with ok/cancel - windowClosed(e); - } - } - }); - calibrationDialolg.setVisible(true); - } - } - - StandardDialog dataTableDialog; - DefaultTableModel dataTableModel; - void showImageData(){ - dataTableModel = null; - if (camera instanceof Camtool){ - - if ((dataTableDialog!=null) && (dataTableDialog.isShowing())){ - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.requestFocus(); - return; - } - //String msg = String.join("\n", ids); - //SwingUtils.showMessage(getTopLevel(), "Image Data", msg); - dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) { - public Class getColumnClass(int columnIndex) { - return String.class; - } - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - }; - updateImageData(); - StreamValue val = ((Camtool)camera).getStream().take(); - JTable dataTable = new JTable(dataTableModel); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.getTableHeader().setReorderingAllowed(false); - dataTable.getTableHeader().setResizingAllowed(true); - dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); - dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE ); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(dataTable); - scrollPane.setPreferredSize(new Dimension(300, 400)); - dataTableDialog.setContentPane(scrollPane); - dataTableDialog.pack(); - SwingUtils.centerComponent(getTopLevel(), dataTableDialog); - dataTableDialog.setVisible(true); - dataTableDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - dataTableModel = null; - } - }); - } - } - - void updateImageData(){ - if ((dataTableModel!=null)&&(camera instanceof Camtool)){ - List ids = new ArrayList(((Camtool)camera).getValue().getIdentifiers()); - if (ids.size() != dataTableModel.getRowCount()){ - dataTableModel.setNumRows(0); - Collections.sort(ids); - for (String id : ids){ - dataTableModel.addRow(new Object[]{id, ""}); - } - } - for (int i = 0 ; i< dataTableModel.getRowCount(); i++){ - String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - Object obj = ((Camtool)camera).getValue(id); - if (obj!=null){ - if (obj.getClass().isArray()){ - obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; - } else if (obj instanceof Double){ - obj = Convert.roundDouble((Double) obj, 1); - } else if (obj instanceof Float){ - obj = Convert.roundDouble((Float) obj, 1); - } - } - dataTableModel.setValueAt(String.valueOf(obj), i, 1); - } - } - } - - //////// - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - buttonGroup4 = new javax.swing.ButtonGroup(); - jProgressBar1 = new javax.swing.JProgressBar(); - jPanel1 = new javax.swing.JPanel(); - jPanel7 = new javax.swing.JPanel(); - buttonMarker = new javax.swing.JToggleButton(); - buttonGrabBackground = new javax.swing.JButton(); - buttonSave = new javax.swing.JToggleButton(); - buttonFit = new javax.swing.JToggleButton(); - buttonReticle = new javax.swing.JToggleButton(); - buttonPause = new javax.swing.JToggleButton(); - buttonProfile = new javax.swing.JToggleButton(); - jPanel6 = new javax.swing.JPanel(); - textState = new javax.swing.JTextField(); - jLabel2 = new javax.swing.JLabel(); - comboCameras = new javax.swing.JComboBox(); - buttonConfig = new javax.swing.JButton(); - jLabel1 = new javax.swing.JLabel(); - buttonArgs = new javax.swing.JButton(); - buttonStop = new javax.swing.JButton(); - renderer = new ch.psi.pshell.imaging.Renderer(); - jPanel4 = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - buttonZoomFit = new javax.swing.JRadioButton(); - buttonZoomStretch = new javax.swing.JRadioButton(); - buttonZoomNormal = new javax.swing.JRadioButton(); - buttonZoom025 = new javax.swing.JRadioButton(); - buttonZoom05 = new javax.swing.JRadioButton(); - buttonZoom2 = new javax.swing.JRadioButton(); - jPanel2 = new javax.swing.JPanel(); - checkHistogram = new javax.swing.JCheckBox(); - comboColormap = new javax.swing.JComboBox(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - buttonFullRange = new javax.swing.JRadioButton(); - buttonManual = new javax.swing.JRadioButton(); - buttonAutomatic = new javax.swing.JRadioButton(); - labelMin = new javax.swing.JLabel(); - spinnerMin = new javax.swing.JSpinner(); - spinnerMax = new javax.swing.JSpinner(); - labelMax = new javax.swing.JLabel(); - btFixColormapRange = new javax.swing.JButton(); - jPanel5 = new javax.swing.JPanel(); - buttonCamtool = new javax.swing.JRadioButton(); - buttonDirect = new javax.swing.JRadioButton(); - panelScreen = new javax.swing.JPanel(); - valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); - comboScreen = new javax.swing.JComboBox(); - panelScreen1 = new javax.swing.JPanel(); - valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); - comboFilter = new javax.swing.JComboBox(); - pauseSelection = new ch.psi.pshell.swing.ValueSelection(); - panelScreen2 = new javax.swing.JPanel(); - checkThreshold = new javax.swing.JCheckBox(); - spinnerThreshold = new javax.swing.JSpinner(); - checkBackground = new javax.swing.JCheckBox(); - checkGoodRegion = new javax.swing.JCheckBox(); - spinnerGrScale = new javax.swing.JSpinner(); - spinnerGrThreshold = new javax.swing.JSpinner(); - labelGrThreshold = new javax.swing.JLabel(); - labelGrScale = new javax.swing.JLabel(); - - setPreferredSize(new java.awt.Dimension(873, 600)); - - buttonMarker.setText("Marker"); - buttonMarker.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonMarkerActionPerformed(evt); - } - }); - - buttonGrabBackground.setText("Grab Background"); - buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonGrabBackgroundActionPerformed(evt); - } - }); - - buttonSave.setText("Save Snapshot"); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - - buttonFit.setSelected(true); - buttonFit.setText("Fit"); - buttonFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonFitActionPerformed(evt); - } - }); - - buttonReticle.setSelected(true); - buttonReticle.setText("Reticle"); - buttonReticle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonReticleActionPerformed(evt); - } - }); - - buttonPause.setText("Pause"); - buttonPause.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPauseActionPerformed(evt); - } - }); - - buttonProfile.setSelected(true); - buttonProfile.setText("Profile"); - buttonProfile.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonProfileActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); - jPanel7.setLayout(jPanel7Layout); - jPanel7Layout.setHorizontalGroup( - jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel7Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(buttonPause) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonMarker) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonProfile) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonFit) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonReticle) - .addGap(18, 18, Short.MAX_VALUE) - .addComponent(buttonGrabBackground) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonSave) - .addGap(0, 0, 0)) - ); - - jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonProfile, buttonReticle}); - - jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave}); - - jPanel7Layout.setVerticalGroup( - jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel7Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonPause) - .addComponent(buttonFit) - .addComponent(buttonMarker) - .addComponent(buttonSave) - .addComponent(buttonReticle) - .addComponent(buttonGrabBackground) - .addComponent(buttonProfile)) - .addGap(0, 0, 0)) - ); - - textState.setEditable(false); - textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); - textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); - textState.setEnabled(false); - - jLabel2.setText("State:"); - - comboCameras.setMaximumRowCount(30); - comboCameras.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboCamerasActionPerformed(evt); - } - }); - - buttonConfig.setText("Config"); - buttonConfig.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonConfigActionPerformed(evt); - } - }); - - jLabel1.setText("Camera:"); - - buttonArgs.setText("Setup"); - buttonArgs.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonArgsActionPerformed(evt); - } - }); - - buttonStop.setText("Stop"); - buttonStop.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStopActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); - jPanel6.setLayout(jPanel6Layout); - jPanel6Layout.setHorizontalGroup( - jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel6Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboCameras, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonArgs) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonConfig) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonStop) - .addGap(18, 18, 18) - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - - jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonArgs, buttonConfig, buttonStop}); - - jPanel6Layout.setVerticalGroup( - jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel6Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel2) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonArgs) - .addComponent(buttonConfig) - .addComponent(buttonStop)) - .addGap(0, 0, 0)) - ); - - jPanel6Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState}); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); - - buttonGroup1.add(buttonZoomFit); - buttonZoomFit.setText("Fit"); - buttonZoomFit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomFitActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomStretch); - buttonZoomStretch.setText("Stretch"); - buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomStretchActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoomNormal); - buttonZoomNormal.setText("Normal"); - buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoomNormalActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("1/4"); - buttonZoom025.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom025ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("1/2"); - buttonZoom05.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom05ActionPerformed(evt); - } - }); - - buttonGroup1.add(buttonZoom2); - buttonZoom2.setText("2"); - buttonZoom2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonZoom2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); - jPanel3.setLayout(jPanel3Layout); - jPanel3Layout.setHorizontalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoomStretch)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05) - .addComponent(buttonZoom2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel3Layout.setVerticalGroup( - jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomFit) - .addComponent(buttonZoom05)) - .addGap(0, 0, 0) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoom2)) - .addContainerGap()) - ); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap")); - - checkHistogram.setText("Histogram"); - checkHistogram.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkHistogramActionPerformed(evt); - } - }); - - comboColormap.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel3.setText("Type:"); - - jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel4.setText("Range:"); - - buttonGroup3.add(buttonFullRange); - buttonFullRange.setText("Full"); - buttonFullRange.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonManual); - buttonManual.setText("Manual"); - buttonManual.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - buttonGroup3.add(buttonAutomatic); - buttonAutomatic.setText("Automatic"); - buttonAutomatic.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - onChangeColormap(evt); - } - }); - - labelMin.setText("Min:"); - - spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); - spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); - spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - onChangeColormapRange(evt); - } - }); - - labelMax.setText("Max:"); - - btFixColormapRange.setText("Fix"); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonAutomatic) - .addComponent(buttonFullRange) - .addComponent(buttonManual) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMax) - .addGap(2, 2, 2) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addComponent(labelMin) - .addGap(2, 2, 2) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(btFixColormapRange, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(spinnerMin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFixColormapRange, spinnerMax, spinnerMin}); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboColormap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3) - .addComponent(checkHistogram)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAutomatic) - .addComponent(jLabel4) - .addComponent(btFixColormapRange)) - .addGap(0, 0, 0) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelMin) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonFullRange)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonManual) - .addComponent(labelMax) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - - buttonGroup4.add(buttonCamtool); - buttonCamtool.setSelected(true); - buttonCamtool.setText("Camtool"); - buttonCamtool.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonCamtoolActionPerformed(evt); - } - }); - - buttonGroup4.add(buttonDirect); - buttonDirect.setText("Direct"); - buttonDirect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDirectActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonCamtool) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonDirect) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonCamtool) - .addComponent(buttonDirect)) - .addContainerGap()) - ); - - panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); - - comboScreen.setEnabled(false); - comboScreen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboScreenActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); - panelScreen.setLayout(panelScreenLayout); - panelScreenLayout.setHorizontalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreenLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreenLayout.setVerticalGroup( - panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelScreen1.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); - - comboFilter.setEnabled(false); - comboFilter.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboFilterActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelScreen1Layout = new javax.swing.GroupLayout(panelScreen1); - panelScreen1.setLayout(panelScreen1Layout); - panelScreen1Layout.setHorizontalGroup( - panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - panelScreen1Layout.setVerticalGroup( - panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen1Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pauseSelection.setDecimals(0); - - panelScreen2.setBorder(javax.swing.BorderFactory.createTitledBorder("Image")); - - checkThreshold.setText("Threshold"); - checkThreshold.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkThresholdActionPerformed(evt); - } - }); - - spinnerThreshold.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 99999.0d, 1.0d)); - spinnerThreshold.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerThresholdonChange(evt); - } - }); - - checkBackground.setText("Subtract Background"); - checkBackground.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkBackgroundActionPerformed(evt); - } - }); - - checkGoodRegion.setText("Good Region"); - checkGoodRegion.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - checkGoodRegionActionPerformed(evt); - } - }); - - spinnerGrScale.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.01d, 100.0d, 1.0d)); - spinnerGrScale.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerGrScale.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - spinnerGrThreshold.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.04d, 1.0d, 0.1d)); - spinnerGrThreshold.setPreferredSize(new java.awt.Dimension(77, 20)); - spinnerGrThreshold.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spinnerGrThresholdonChange(evt); - } - }); - - labelGrThreshold.setText("Threshold:"); - - labelGrScale.setText("Scale:"); - - javax.swing.GroupLayout panelScreen2Layout = new javax.swing.GroupLayout(panelScreen2); - panelScreen2.setLayout(panelScreen2Layout); - panelScreen2Layout.setHorizontalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addComponent(checkGoodRegion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(labelGrScale) - .addGap(2, 2, 2) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(labelGrThreshold) - .addGap(2, 2, 2) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkBackground) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(panelScreen2Layout.createSequentialGroup() - .addComponent(checkThreshold) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - panelScreen2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerGrScale, spinnerGrThreshold, spinnerThreshold}); - - panelScreen2Layout.setVerticalGroup( - panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen2Layout.createSequentialGroup() - .addGap(4, 4, 4) - .addComponent(checkBackground) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkThreshold) - .addComponent(spinnerThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkGoodRegion) - .addComponent(spinnerGrScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrScale)) - .addGap(2, 2, 2) - .addGroup(panelScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(spinnerGrThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(labelGrThreshold)) - .addContainerGap()) - ); - - javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); - jPanel4.setLayout(jPanel4Layout); - jPanel4Layout.setHorizontalGroup( - jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel4Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelScreen1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel4Layout.setVerticalGroup( - jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel4Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - }// //GEN-END:initComponents - - private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed - try { - if (!updatingCameraSelection) { - if (!comboCameras.isEnabled()) { - throw new Exception("Invalid state"); - } - comboCameras.setEnabled(false); - buttonCamtool.setEnabled(false); - buttonDirect.setEnabled(false); - final String cameraName = (String) comboCameras.getSelectedItem(); - new Thread(new Runnable() { - @Override - public void run() { - if (requestCameraListUpdate) { - requestCameraListUpdate = false; - try { - updateCameraList(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - try { - setCamera(cameraName); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - updateStop(); - comboCameras.setEnabled(true); - buttonCamtool.setEnabled(true); - buttonDirect.setEnabled(true); - } - } - }).start(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboCamerasActionPerformed - - private void buttonArgsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonArgsActionPerformed - try { - if (camera != null) { - TextEditor editor = new TextEditor(); - editor.setText(cameraConfigJson); - editor.setReadOnly(true); - editor.setTitle(cameraName); - EditorDialog dlg = editor.getDialog(getTopLevel(), false); - dlg.setSize(480, 640); - dlg.setVisible(true); - SwingUtils.centerComponent(this, dlg); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonArgsActionPerformed - - private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed - try { - if (camera != null) { - this.showDeviceConfigDialog(camera, false); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonConfigActionPerformed - - private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed - try { - renderer.removeOverlay(imageBufferOverlay); - if (camera != null) { - synchronized (imageBuffer) { - if (buttonPause.isSelected()) { - renderer.pause(); - } else { - imageBuffer.clear(); - renderer.resume(); - } - pauseSelection.setVisible(buttonPause.isSelected() && (imageBuffer.size() > 0)); - if (pauseSelection.isVisible()) { - renderer.addOverlay(imageBufferOverlay); - pauseSelection.setMaxValue(imageBuffer.size()); - pauseSelection.setValue(imageBuffer.size());; - } - } - updateImageData(); - } - } catch (Exception ex) { - ex.printStackTrace(); - showException(ex); - } - }//GEN-LAST:event_buttonPauseActionPerformed - - private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed - try { - checkMarker(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonMarkerActionPerformed - - private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed - try { - showFit = buttonFit.isSelected(); - if (showFit) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(fitOv); - fitOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonFitActionPerformed - - private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed - try { - checkReticle(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonReticleActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try { - saveSnapshot(); - } catch (Exception ex) { - ex.printStackTrace(); - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed - try { - if (camera != null) { - if (SwingUtils.showOption(getTopLevel(), "Background", "Do you want to capture background now?", OptionType.YesNo) == OptionResult.Yes) { - boolean laserOn = getLaserState(); - if (camera instanceof Camtool){ - boolean rendering = (!camera.isClosed()); - if (rendering) { - camera.close(); - } - if (laserOn) { - setLaserState(false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - ((Camtool) camera).grabBackground(cameraName, 5); - } finally { - if (laserOn) { - setLaserState(true); - } - if (rendering) { - comboCamerasActionPerformed(null); - } - updateStop(); - } - } else { - if (laserOn) { - setLaserState(false); - } - try { - camera.captureBackground(5, 0); - } finally { - if (laserOn) { - setLaserState(true); - } - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonGrabBackgroundActionPerformed - - private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed - try { - renderer.setMode(RendererMode.Fit); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomFitActionPerformed - - private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed - try { - renderer.setMode(RendererMode.Stretch); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomStretchActionPerformed - - private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed - try { - renderer.setMode(RendererMode.Fixed); - centralizeRenderer(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonZoomNormalActionPerformed - - private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap - try { - if ((camera != null) && (camera instanceof ColormapSource) && !updatingColormap) { - ColormapSource source = (ColormapSource) camera; - Color colorReticule = new Color(16, 16, 16); - Color colorMarker = new Color(128, 128, 128); - source.getConfig().colormap = (Colormap)comboColormap.getSelectedItem(); - switch (source.getConfig().colormap){ - case Grayscale: - case Inverted: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - case Flame: - colorReticule = new Color(0, 192, 0); - colorMarker = new Color(64, 255, 64); - break; - } - - renderer.setPenReticle(new Pen(colorReticule)); - renderer.setPenProfile(new Pen(colorReticule, 0)); - renderer.setPenMarker(new Pen(colorMarker, 2)); - renderer.setShowReticle(false); - checkReticle(); - source.getConfig().colormapAutomatic = buttonAutomatic.isSelected(); - source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); - source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); - source.getConfig().save(); - source.refresh(); - if (buttonPause.isSelected()) { - updatePause(); - } - updateColormap(); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_onChangeColormap - - private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange - onChangeColormap(null); - }//GEN-LAST:event_onChangeColormapRange - - private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed - renderer.setZoom(0.25); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom025ActionPerformed - - private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed - renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom05ActionPerformed - - private void buttonCamtoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCamtoolActionPerformed - if (!usingCamtool) { - usingCamtool = true; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonCamtoolActionPerformed - - private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingCamtool) { - usingCamtool = false; - requestCameraListUpdate = true; - } - comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonDirectActionPerformed - - private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed - - comboScreen.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - ChannelInteger setpoint = null; - try { - int index = comboScreen.getSelectedIndex(); - if (cameraName.contains("DSRM")){ - setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); - } else { - setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); - } - setpoint.initialize(); - if (setpoint.read() != index) { - setpoint.write(index); - //Must be threaded to control the laser because of sleep in setLaserState - /* - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - setpoint.write(index); - } finally { - if (laserOn) { - setLaserState(true); - } - } - */ - } - screen.read(); - } catch (Exception ex) { - showException(ex); - } finally { - comboScreen.setEnabled(true); - if (setpoint != null) { - setpoint.close(); - } - } - } - }).start(); - }//GEN-LAST:event_comboScreenActionPerformed - - private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed - try { - String setpoint = (String) comboFilter.getSelectedItem(); - if (!setpoint.equals(filter.read())) { - filter.write(setpoint); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_comboFilterActionPerformed - - private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed - try { - setHistogramVisible(checkHistogram.isSelected()); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_checkHistogramActionPerformed - - private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed - renderer.setZoom(2.0); - renderer.setMode(RendererMode.Zoom); - centralizeRenderer(); - }//GEN-LAST:event_buttonZoom2ActionPerformed - - private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingCamtoolControls) { - try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - ((Camtool) camera).setThreshold((Double) spinnerThreshold.getValue()); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - } - } - }//GEN-LAST:event_spinnerThresholdonChange - - private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (camera instanceof Camtool){ - if (!updatingCamtoolControls) { - try { - if (((Camtool) camera).isPipelineStarted()) { - ((Camtool) camera).setBackgroundSubtraction(checkBackground.isSelected()); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - //There is a bug in camtool: it will flag bg extraction as on: - updatingCamtoolControls = true; - checkBackground.setSelected(false); - updatingCamtoolControls = false; - - } - } - } else { - camera.setBackgroundEnabled(checkBackground.isSelected()); - } - }//GEN-LAST:event_checkBackgroundActionPerformed - - private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingCamtoolControls) { - try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - spinnerThreshold.setVisible(checkThreshold.isSelected()); - ((Camtool) camera).setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - } - } - }//GEN-LAST:event_checkThresholdActionPerformed - - private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed - try { - if (buttonStop.getText().equals("Stop")) { - if ((camera != null) && !camera.isClosed()) { - camera.close(); - } - } else { - if (isCameraStopped()) { - comboCamerasActionPerformed(null); - } - } - } catch (Exception ex) { - showException(ex); - } finally { - updateStop(); - } - }//GEN-LAST:event_buttonStopActionPerformed - - private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed - try { - showProfile = buttonProfile.isSelected(); - if (showProfile) { - renderer.setProfile(Renderer.Profile.None); - } else { - renderer.removeOverlays(profileOv); - profileOv = null; - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonProfileActionPerformed - - private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingCamtoolControls) { - try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - spinnerGrScale.setVisible(checkGoodRegion.isSelected()); labelGrScale.setVisible(spinnerGrScale.isVisible()); - spinnerGrThreshold.setVisible(checkGoodRegion.isSelected()); labelGrThreshold.setVisible(spinnerGrThreshold.isVisible()); - if (checkGoodRegion.isSelected()){ - ((Camtool) camera).setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); - } else { - ((Camtool) camera).setGoodRegion(null); - } - goodRegion = checkGoodRegion.isSelected(); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - } - } - }//GEN-LAST:event_checkGoodRegionActionPerformed - - private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingCamtoolControls) { - try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - ((Camtool) camera).setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); - } - } catch (Exception ex) { - showException(ex); - updateCamtoolControls(); - } - } - }//GEN-LAST:event_spinnerGrThresholdonChange - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btFixColormapRange; - private javax.swing.JButton buttonArgs; - private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonCamtool; - private javax.swing.JButton buttonConfig; - private javax.swing.JRadioButton buttonDirect; - private javax.swing.JToggleButton buttonFit; - private javax.swing.JRadioButton buttonFullRange; - private javax.swing.JButton buttonGrabBackground; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JRadioButton buttonManual; - private javax.swing.JToggleButton buttonMarker; - private javax.swing.JToggleButton buttonPause; - private javax.swing.JToggleButton buttonProfile; - private javax.swing.JToggleButton buttonReticle; - private javax.swing.JToggleButton buttonSave; - private javax.swing.JButton buttonStop; - private javax.swing.JRadioButton buttonZoom025; - private javax.swing.JRadioButton buttonZoom05; - private javax.swing.JRadioButton buttonZoom2; - private javax.swing.JRadioButton buttonZoomFit; - private javax.swing.JRadioButton buttonZoomNormal; - private javax.swing.JRadioButton buttonZoomStretch; - private javax.swing.JCheckBox checkBackground; - private javax.swing.JCheckBox checkGoodRegion; - private javax.swing.JCheckBox checkHistogram; - private javax.swing.JCheckBox checkThreshold; - private javax.swing.JComboBox comboCameras; - private javax.swing.JComboBox comboColormap; - private javax.swing.JComboBox comboFilter; - private javax.swing.JComboBox comboScreen; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel4; - private javax.swing.JPanel jPanel5; - private javax.swing.JPanel jPanel6; - private javax.swing.JPanel jPanel7; - private javax.swing.JProgressBar jProgressBar1; - private javax.swing.JLabel labelGrScale; - private javax.swing.JLabel labelGrThreshold; - private javax.swing.JLabel labelMax; - private javax.swing.JLabel labelMin; - private javax.swing.JPanel panelScreen; - private javax.swing.JPanel panelScreen1; - private javax.swing.JPanel panelScreen2; - private ch.psi.pshell.swing.ValueSelection pauseSelection; - private ch.psi.pshell.imaging.Renderer renderer; - private javax.swing.JSpinner spinnerGrScale; - private javax.swing.JSpinner spinnerGrThreshold; - private javax.swing.JSpinner spinnerMax; - private javax.swing.JSpinner spinnerMin; - private javax.swing.JSpinner spinnerThreshold; - private javax.swing.JTextField textState; - private ch.psi.pshell.swing.DeviceValuePanel valueFilter; - private ch.psi.pshell.swing.DeviceValuePanel valueScreen; - // End of variables declaration//GEN-END:variables -} diff --git a/plugins/errors b/plugins/errors deleted file mode 100644 index d28fb4b..0000000 --- a/plugins/errors +++ /dev/null @@ -1,59 +0,0 @@ - -javax.script.ScriptException: Exception: Scan didn't conmplete in