001package icy.gui.dialog; 002 003import java.awt.GridBagConstraints; 004import java.awt.GridBagLayout; 005import java.awt.Insets; 006 007import javax.swing.JCheckBox; 008import javax.swing.JLabel; 009import javax.swing.JPanel; 010import javax.swing.SwingConstants; 011 012import icy.gui.component.NumberTextField; 013import icy.gui.component.NumberTextField.ValueChangeListener; 014import icy.math.MathUtil; 015 016public class SaverOptionPanel extends JPanel 017{ 018 private JLabel overwriteMetaLabel; 019 private JLabel fpsLabel; 020 private JLabel multipleFilesLabel; 021 private JCheckBox overwriteMetaCheckbox; 022 private NumberTextField fpsField; 023 private JCheckBox multipleFilesCheckbox; 024 private NumberTextField msField; 025 private JLabel msLabel; 026 027 private boolean synching; 028 029 public SaverOptionPanel() 030 { 031 super(); 032 033 initialize(); 034 035 fpsField.addValueListener(new ValueChangeListener() 036 { 037 public void valueChanged(double newValue, boolean validate) 038 { 039 if (validate) 040 syncTime(true); 041 } 042 }); 043 msField.addValueListener(new ValueChangeListener() 044 { 045 public void valueChanged(double newValue, boolean validate) 046 { 047 if (validate) 048 syncTime(false); 049 } 050 }); 051 052 synching = false; 053 } 054 055 private void initialize() 056 { 057 GridBagLayout gridBagLayout = new GridBagLayout(); 058 gridBagLayout.columnWidths = new int[] {0, 50, 0}; 059 gridBagLayout.rowHeights = new int[] {0, 0, 0, 0, 0}; 060 gridBagLayout.columnWeights = new double[] {1.0, 0.0, Double.MIN_VALUE}; 061 gridBagLayout.rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; 062 setLayout(gridBagLayout); 063 064 multipleFilesLabel = new JLabel(" Save as multiple files"); 065 multipleFilesLabel.setToolTipText("Save each slice/frame in a separate file"); 066 GridBagConstraints gbc_lblNewLabel = new GridBagConstraints(); 067 gbc_lblNewLabel.anchor = GridBagConstraints.WEST; 068 gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5); 069 gbc_lblNewLabel.gridx = 0; 070 gbc_lblNewLabel.gridy = 0; 071 add(multipleFilesLabel, gbc_lblNewLabel); 072 073 multipleFilesCheckbox = new JCheckBox(""); 074 multipleFilesCheckbox.setToolTipText("Save each slice/frame in a separate file"); 075 GridBagConstraints gbc_multipleFilesCheckbox = new GridBagConstraints(); 076 gbc_multipleFilesCheckbox.anchor = GridBagConstraints.EAST; 077 gbc_multipleFilesCheckbox.insets = new Insets(0, 0, 5, 0); 078 gbc_multipleFilesCheckbox.gridx = 1; 079 gbc_multipleFilesCheckbox.gridy = 0; 080 add(multipleFilesCheckbox, gbc_multipleFilesCheckbox); 081 082 fpsLabel = new JLabel(" Frame per second"); 083 fpsLabel.setToolTipText("Number of frame per second"); 084 GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints(); 085 gbc_lblNewLabel_1.anchor = GridBagConstraints.WEST; 086 gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5); 087 gbc_lblNewLabel_1.gridx = 0; 088 gbc_lblNewLabel_1.gridy = 1; 089 add(fpsLabel, gbc_lblNewLabel_1); 090 091 fpsField = new NumberTextField(); 092 fpsField.setInteger(true); 093 fpsField.setHorizontalAlignment(SwingConstants.RIGHT); 094 fpsField.setNumericValue(20.0); 095 fpsField.setToolTipText("Number of frame per second"); 096 GridBagConstraints gbc_fpsField = new GridBagConstraints(); 097 gbc_fpsField.fill = GridBagConstraints.HORIZONTAL; 098 gbc_fpsField.insets = new Insets(0, 0, 5, 0); 099 gbc_fpsField.gridx = 1; 100 gbc_fpsField.gridy = 1; 101 add(fpsField, gbc_fpsField); 102 103 msLabel = new JLabel(" Time interval (ms)"); 104 msLabel.setToolTipText("Time interval between 2 frames (ms)"); 105 GridBagConstraints gbc_msLabel = new GridBagConstraints(); 106 gbc_msLabel.anchor = GridBagConstraints.WEST; 107 gbc_msLabel.insets = new Insets(0, 0, 5, 5); 108 gbc_msLabel.gridx = 0; 109 gbc_msLabel.gridy = 2; 110 add(msLabel, gbc_msLabel); 111 112 msField = new NumberTextField(); 113 msField.setHorizontalAlignment(SwingConstants.RIGHT); 114 msField.setToolTipText("Time interval between 2 frames (ms)"); 115 GridBagConstraints gbc_msField = new GridBagConstraints(); 116 gbc_msField.fill = GridBagConstraints.HORIZONTAL; 117 gbc_msField.insets = new Insets(0, 0, 5, 0); 118 gbc_msField.gridx = 1; 119 gbc_msField.gridy = 2; 120 add(msField, gbc_msField); 121 122 overwriteMetaLabel = new JLabel(" Overwrite metadata name"); 123 overwriteMetaLabel.setToolTipText("Overwrite metadata name with filename"); 124 GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints(); 125 gbc_lblNewLabel_2.anchor = GridBagConstraints.WEST; 126 gbc_lblNewLabel_2.insets = new Insets(0, 0, 0, 5); 127 gbc_lblNewLabel_2.gridx = 0; 128 gbc_lblNewLabel_2.gridy = 3; 129 add(overwriteMetaLabel, gbc_lblNewLabel_2); 130 131 overwriteMetaCheckbox = new JCheckBox(""); 132 overwriteMetaCheckbox.setToolTipText("Overwrite metadata name with filename"); 133 GridBagConstraints gbc_overwriteMetaCheckbox = new GridBagConstraints(); 134 gbc_overwriteMetaCheckbox.anchor = GridBagConstraints.NORTHEAST; 135 gbc_overwriteMetaCheckbox.gridx = 1; 136 gbc_overwriteMetaCheckbox.gridy = 3; 137 add(overwriteMetaCheckbox, gbc_overwriteMetaCheckbox); 138 } 139 140 void syncTime(boolean fromFPS) 141 { 142 if (synching) 143 return; 144 145 synching = true; 146 try 147 { 148 if (fromFPS) 149 { 150 final double v = fpsField.getNumericValue(); 151 152 if (v > 0d) 153 msField.setNumericValue(MathUtil.roundSignificant(1000d / v, 5, true)); 154 } 155 else 156 { 157 final double v = msField.getNumericValue(); 158 if (v > 0d) 159 fpsField.setNumericValue(MathUtil.roundSignificant(1000d / v, 5, true)); 160 } 161 } 162 finally 163 { 164 synching = false; 165 } 166 } 167 168 public boolean isFramePerSecondVisible() 169 { 170 return fpsField.isVisible(); 171 } 172 173 public void setFramePerSecondVisible(boolean value) 174 { 175 fpsLabel.setVisible(value); 176 fpsField.setVisible(value); 177 msLabel.setVisible(value); 178 msField.setVisible(value); 179 } 180 181 public boolean isMultipleFilesVisible() 182 { 183 return multipleFilesCheckbox.isVisible(); 184 } 185 186 public void setMultipleFilesVisible(boolean value) 187 { 188 multipleFilesLabel.setVisible(value); 189 multipleFilesCheckbox.setVisible(value); 190 } 191 192 public void setForcedMultipleFilesOn() 193 { 194 multipleFilesCheckbox.setEnabled(false); 195 multipleFilesCheckbox.setSelected(true); 196 } 197 198 public void setForcedMultipleFilesOff() 199 { 200 multipleFilesCheckbox.setEnabled(false); 201 multipleFilesCheckbox.setSelected(false); 202 } 203 204 public void removeForcedMultipleFiles() 205 { 206 multipleFilesCheckbox.setEnabled(true); 207 multipleFilesCheckbox.setSelected(false); 208 } 209 210 public boolean isOverwriteMetadataVisible() 211 { 212 return overwriteMetaCheckbox.isVisible(); 213 } 214 215 public void setOverwriteMetadataVisible(boolean value) 216 { 217 overwriteMetaLabel.setVisible(value); 218 overwriteMetaCheckbox.setVisible(value); 219 } 220 221 public int getFramePerSecond() 222 { 223 return (int) fpsField.getNumericValue(); 224 } 225 226 public void setFramePerSecond(int value) 227 { 228 fpsField.setNumericValue(value); 229 } 230 231 /** 232 * Return Time Interval in ms 233 */ 234 public double getTimeInterval() 235 { 236 return msField.getNumericValue(); 237 } 238 239 /** 240 * Set Time Interval in ms 241 */ 242 public void setTimeInterval(double value) 243 { 244 msField.setNumericValue(value); 245 } 246 247 public boolean getMultipleFiles() 248 { 249 return multipleFilesCheckbox.isSelected(); 250 } 251 252 public void setMultipleFiles(boolean value) 253 { 254 multipleFilesCheckbox.setSelected(value); 255 } 256 257 public boolean getOverwriteMetadata() 258 { 259 return overwriteMetaCheckbox.isSelected(); 260 } 261 262 public void setOverwriteMetadata(boolean value) 263 { 264 overwriteMetaCheckbox.setSelected(value); 265 } 266}