| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
package net.mtu.eggplant.util.gui; |
| 29 | |
|
| 30 | |
import java.awt.Color; |
| 31 | |
import java.awt.GridBagConstraints; |
| 32 | |
import java.awt.GridBagLayout; |
| 33 | |
import java.awt.event.ActionEvent; |
| 34 | |
import java.awt.event.ActionListener; |
| 35 | |
import java.awt.event.FocusEvent; |
| 36 | |
import java.awt.event.FocusListener; |
| 37 | |
import java.beans.PropertyChangeListener; |
| 38 | |
import java.beans.PropertyChangeSupport; |
| 39 | |
import java.text.DecimalFormat; |
| 40 | |
import java.util.Calendar; |
| 41 | |
import java.util.Locale; |
| 42 | |
|
| 43 | |
import javax.swing.BorderFactory; |
| 44 | |
import javax.swing.Box; |
| 45 | |
import javax.swing.BoxLayout; |
| 46 | |
import javax.swing.JLabel; |
| 47 | |
import javax.swing.JPanel; |
| 48 | |
import javax.swing.JTextField; |
| 49 | |
import javax.swing.UIManager; |
| 50 | |
import javax.swing.plaf.basic.BasicArrowButton; |
| 51 | |
|
| 52 | |
import org.slf4j.Logger; |
| 53 | |
import org.slf4j.LoggerFactory; |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | 0 | public class DateEditor extends JPanel { |
| 67 | |
|
| 68 | 0 | private static final Logger LOGGER = LoggerFactory |
| 69 | 0 | .getLogger(DateEditor.class); |
| 70 | |
|
| 71 | |
public static void main(final String[] args) { |
| 72 | 0 | DateEditor de = new DateEditor(Locale.getDefault(), Calendar.getInstance(), |
| 73 | |
false, true, true, true, true, true, false); |
| 74 | 0 | GraphicsUtils.basicGUIMain(de, false); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
public static final int SECOND = 1; |
| 78 | |
public static final int MINUTE = 2; |
| 79 | |
public static final int HOUR = 3; |
| 80 | |
public static final int DAY = 4; |
| 81 | |
public static final int MONTH = 5; |
| 82 | |
public static final int YEAR = 6; |
| 83 | |
public static final int DATESEPARATOR = 7; |
| 84 | |
public static final int TIMESEPARATOR = 8; |
| 85 | |
public static final int SPACER = 9; |
| 86 | |
public static final int AMPM = 10; |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
public DateEditor(final Locale locale, |
| 112 | |
final Calendar cal, |
| 113 | |
final boolean military, |
| 114 | |
final boolean month, |
| 115 | |
final boolean day, |
| 116 | |
final boolean year, |
| 117 | |
final boolean hour, |
| 118 | |
final boolean minute, |
| 119 | |
final boolean second) { |
| 120 | 0 | super(); |
| 121 | 0 | _month = month; |
| 122 | 0 | _day = day; |
| 123 | 0 | _year = year; |
| 124 | 0 | _hour = hour; |
| 125 | 0 | _minute = minute; |
| 126 | 0 | _second = second; |
| 127 | 0 | _dateListener = new PropertyChangeSupport(this); |
| 128 | 0 | _military = military; |
| 129 | 0 | _twoFormat = new DecimalFormat(); |
| 130 | 0 | _twoFormat.setMinimumIntegerDigits(2); |
| 131 | 0 | _twoFormat.setGroupingUsed(false); |
| 132 | |
|
| 133 | 0 | setLayout(new GridBagLayout()); |
| 134 | |
GridBagConstraints gbc; |
| 135 | 0 | _internalPanel = new JPanel(); |
| 136 | 0 | _internalPanel.setBackground(Color.white); |
| 137 | 0 | _internalPanel.setLayout(new BoxLayout(_internalPanel, BoxLayout.X_AXIS)); |
| 138 | 0 | gbc = new GridBagConstraints(); |
| 139 | 0 | gbc.fill = GridBagConstraints.NONE; |
| 140 | 0 | gbc.weightx = 0.0; |
| 141 | 0 | gbc.weighty = 0.0; |
| 142 | 0 | gbc.anchor = GridBagConstraints.WEST; |
| 143 | 0 | add(_internalPanel, gbc); |
| 144 | 0 | gbc = new GridBagConstraints(); |
| 145 | 0 | gbc.fill = GridBagConstraints.HORIZONTAL; |
| 146 | 0 | gbc.weightx = 1.0; |
| 147 | 0 | gbc.weighty = 0.0; |
| 148 | 0 | add(new JPanel(), gbc); |
| 149 | |
|
| 150 | 0 | createFields(); |
| 151 | |
|
| 152 | 0 | addFields(locale); |
| 153 | |
|
| 154 | 0 | setCalendar(cal); |
| 155 | 0 | populate(); |
| 156 | 0 | } |
| 157 | |
|
| 158 | |
protected void createFields() { |
| 159 | 0 | _monthText = new JTextField(2); |
| 160 | 0 | _monthText.setBorder(BorderFactory.createEmptyBorder()); |
| 161 | 0 | _monthText.setHorizontalAlignment(JTextField.CENTER); |
| 162 | 0 | _monthText.addFocusListener(new FocusListener() { |
| 163 | |
public void focusGained(final FocusEvent fe) { |
| 164 | 0 | if (!fe.isTemporary()) { |
| 165 | 0 | _monthText.setBackground(_textSelectedColor); |
| 166 | 0 | _currentField = MONTH; |
| 167 | |
} |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
public void focusLost(final FocusEvent fe) { |
| 171 | 0 | if (!fe.isTemporary()) { |
| 172 | 0 | _monthText.setBackground(_textUnselectedColor); |
| 173 | 0 | check(MONTH, _monthText.getText()); |
| 174 | |
} |
| 175 | 0 | } |
| 176 | |
}); |
| 177 | |
|
| 178 | 0 | _dayText = new JTextField(2); |
| 179 | 0 | _dayText.setBorder(BorderFactory.createEmptyBorder()); |
| 180 | 0 | _dayText.setHorizontalAlignment(JTextField.CENTER); |
| 181 | 0 | _dayText.addFocusListener(new FocusListener() { |
| 182 | |
public void focusGained(final FocusEvent fe) { |
| 183 | 0 | if (!fe.isTemporary()) { |
| 184 | 0 | _dayText.setBackground(_textSelectedColor); |
| 185 | 0 | _currentField = DAY; |
| 186 | |
} |
| 187 | 0 | } |
| 188 | |
|
| 189 | |
public void focusLost(final FocusEvent fe) { |
| 190 | 0 | if (!fe.isTemporary()) { |
| 191 | 0 | _dayText.setBackground(_textUnselectedColor); |
| 192 | 0 | check(DAY, _dayText.getText()); |
| 193 | |
} |
| 194 | 0 | } |
| 195 | |
}); |
| 196 | |
|
| 197 | 0 | _yearText = new JTextField(4); |
| 198 | 0 | _yearText.setBorder(BorderFactory.createEmptyBorder()); |
| 199 | 0 | _yearText.setHorizontalAlignment(JTextField.CENTER); |
| 200 | 0 | _yearText.addFocusListener(new FocusListener() { |
| 201 | |
public void focusGained(final FocusEvent fe) { |
| 202 | 0 | if (!fe.isTemporary()) { |
| 203 | 0 | _yearText.setBackground(_textSelectedColor); |
| 204 | 0 | _currentField = YEAR; |
| 205 | |
} |
| 206 | 0 | } |
| 207 | |
|
| 208 | |
public void focusLost(final FocusEvent fe) { |
| 209 | 0 | if (!fe.isTemporary()) { |
| 210 | 0 | _yearText.setBackground(_textUnselectedColor); |
| 211 | 0 | check(YEAR, _yearText.getText()); |
| 212 | |
} |
| 213 | 0 | } |
| 214 | |
}); |
| 215 | |
|
| 216 | 0 | _hourText = new JTextField(2); |
| 217 | 0 | _hourText.setBorder(BorderFactory.createEmptyBorder()); |
| 218 | 0 | _hourText.setHorizontalAlignment(JTextField.CENTER); |
| 219 | 0 | _hourText.addFocusListener(new FocusListener() { |
| 220 | |
public void focusGained(final FocusEvent fe) { |
| 221 | 0 | if (!fe.isTemporary()) { |
| 222 | 0 | _hourText.setBackground(_textSelectedColor); |
| 223 | 0 | _currentField = HOUR; |
| 224 | |
} |
| 225 | 0 | } |
| 226 | |
|
| 227 | |
public void focusLost(final FocusEvent fe) { |
| 228 | 0 | if (!fe.isTemporary()) { |
| 229 | 0 | _hourText.setBackground(_textUnselectedColor); |
| 230 | 0 | check(HOUR, _hourText.getText()); |
| 231 | |
} |
| 232 | 0 | } |
| 233 | |
}); |
| 234 | |
|
| 235 | 0 | _minuteText = new JTextField(2); |
| 236 | 0 | _minuteText.setBorder(BorderFactory.createEmptyBorder()); |
| 237 | 0 | _minuteText.setHorizontalAlignment(JTextField.CENTER); |
| 238 | 0 | _minuteText.addFocusListener(new FocusListener() { |
| 239 | |
public void focusGained(final FocusEvent fe) { |
| 240 | 0 | if (!fe.isTemporary()) { |
| 241 | 0 | _minuteText.setBackground(_textSelectedColor); |
| 242 | 0 | _currentField = MINUTE; |
| 243 | |
} |
| 244 | 0 | } |
| 245 | |
|
| 246 | |
public void focusLost(final FocusEvent fe) { |
| 247 | 0 | if (!fe.isTemporary()) { |
| 248 | 0 | _minuteText.setBackground(_textUnselectedColor); |
| 249 | 0 | check(MINUTE, _minuteText.getText()); |
| 250 | |
} |
| 251 | 0 | } |
| 252 | |
}); |
| 253 | |
|
| 254 | 0 | _secondText = new JTextField(2); |
| 255 | 0 | _secondText.setBorder(BorderFactory.createEmptyBorder()); |
| 256 | 0 | _secondText.setHorizontalAlignment(JTextField.CENTER); |
| 257 | 0 | _secondText.addFocusListener(new FocusListener() { |
| 258 | |
public void focusGained(final FocusEvent fe) { |
| 259 | 0 | if (!fe.isTemporary()) { |
| 260 | 0 | _secondText.setBackground(_textSelectedColor); |
| 261 | 0 | _currentField = SECOND; |
| 262 | |
} |
| 263 | 0 | } |
| 264 | |
|
| 265 | |
public void focusLost(final FocusEvent fe) { |
| 266 | 0 | if (!fe.isTemporary()) { |
| 267 | 0 | _secondText.setBackground(_textUnselectedColor); |
| 268 | 0 | check(SECOND, _secondText.getText()); |
| 269 | |
} |
| 270 | 0 | } |
| 271 | |
}); |
| 272 | |
|
| 273 | 0 | _ampmText = new JTextField(2); |
| 274 | 0 | _ampmText.setBorder(BorderFactory.createEmptyBorder()); |
| 275 | 0 | _ampmText.setHorizontalAlignment(JTextField.CENTER); |
| 276 | 0 | _ampmText.addFocusListener(new FocusListener() { |
| 277 | |
public void focusGained(final FocusEvent fe) { |
| 278 | 0 | if (!fe.isTemporary()) { |
| 279 | 0 | _ampmText.setBackground(_textSelectedColor); |
| 280 | 0 | _currentField = AMPM; |
| 281 | |
} |
| 282 | 0 | } |
| 283 | |
|
| 284 | |
public void focusLost(final FocusEvent fe) { |
| 285 | 0 | if (!fe.isTemporary()) { |
| 286 | 0 | _ampmText.setBackground(_textUnselectedColor); |
| 287 | 0 | check(AMPM, _ampmText.getText()); |
| 288 | |
} |
| 289 | 0 | } |
| 290 | |
}); |
| 291 | |
|
| 292 | 0 | } |
| 293 | |
|
| 294 | |
protected void addFields(final Locale locale) { |
| 295 | |
|
| 296 | 0 | boolean europe = false; |
| 297 | |
|
| 298 | |
|
| 299 | 0 | if (europe) { |
| 300 | 0 | if (_day) { |
| 301 | 0 | addField(DAY); |
| 302 | 0 | if (_month || _year) { |
| 303 | 0 | addField(DATESEPARATOR); |
| 304 | |
} |
| 305 | |
} |
| 306 | 0 | if (_month) { |
| 307 | 0 | addField(MONTH); |
| 308 | 0 | if (_year) { |
| 309 | 0 | addField(DATESEPARATOR); |
| 310 | |
} |
| 311 | |
} |
| 312 | |
} else { |
| 313 | 0 | if (_month) { |
| 314 | 0 | addField(MONTH); |
| 315 | 0 | if (_day || _year) { |
| 316 | 0 | addField(DATESEPARATOR); |
| 317 | |
} |
| 318 | |
} |
| 319 | 0 | if (_day) { |
| 320 | 0 | addField(DAY); |
| 321 | 0 | if (_year) { |
| 322 | 0 | addField(DATESEPARATOR); |
| 323 | |
} |
| 324 | |
} |
| 325 | |
} |
| 326 | 0 | if (_year) { |
| 327 | 0 | addField(YEAR); |
| 328 | 0 | if (_hour || _minute || _second) { |
| 329 | 0 | addField(SPACER); |
| 330 | |
} |
| 331 | |
} |
| 332 | 0 | if (_hour) { |
| 333 | 0 | addField(HOUR); |
| 334 | 0 | if (_minute || _second) { |
| 335 | 0 | addField(TIMESEPARATOR); |
| 336 | |
} |
| 337 | |
} |
| 338 | 0 | if (_minute) { |
| 339 | 0 | addField(MINUTE); |
| 340 | 0 | if (_second) { |
| 341 | 0 | addField(TIMESEPARATOR); |
| 342 | |
} |
| 343 | |
} |
| 344 | 0 | if (_second) { |
| 345 | 0 | addField(SECOND); |
| 346 | |
} |
| 347 | 0 | if (!_military) { |
| 348 | 0 | addField(AMPM); |
| 349 | |
} |
| 350 | |
|
| 351 | |
|
| 352 | 0 | JPanel buttonBox = new JPanel(); |
| 353 | 0 | buttonBox.setLayout(new BoxLayout(buttonBox, BoxLayout.Y_AXIS)); |
| 354 | 0 | BasicArrowButton upArrow = new BasicArrowButton(BasicArrowButton.NORTH); |
| 355 | 0 | upArrow.addActionListener(new ActionListener() { |
| 356 | |
public void actionPerformed(final ActionEvent ae) { |
| 357 | 0 | increment(_currentField, 1); |
| 358 | 0 | } |
| 359 | |
}); |
| 360 | 0 | buttonBox.add(upArrow); |
| 361 | 0 | BasicArrowButton downArrow = new BasicArrowButton(BasicArrowButton.SOUTH); |
| 362 | 0 | downArrow.addActionListener(new ActionListener() { |
| 363 | |
public void actionPerformed(final ActionEvent ae) { |
| 364 | 0 | increment(_currentField, -1); |
| 365 | 0 | } |
| 366 | |
}); |
| 367 | 0 | buttonBox.add(downArrow); |
| 368 | |
|
| 369 | 0 | _internalPanel.add(buttonBox); |
| 370 | |
|
| 371 | 0 | } |
| 372 | |
|
| 373 | |
public Calendar getCalendar() { |
| 374 | 0 | return (Calendar) _currentCalendar.clone(); |
| 375 | |
} |
| 376 | |
|
| 377 | |
public void setCalendar(final Calendar cal) { |
| 378 | 0 | final Calendar old = (Calendar) _currentCalendar.clone(); |
| 379 | 0 | _currentCalendar = (Calendar) cal.clone(); |
| 380 | 0 | fireDateChange(old, (Calendar) _currentCalendar.clone()); |
| 381 | 0 | populate(); |
| 382 | 0 | } |
| 383 | |
|
| 384 | |
protected void addField(final int field) { |
| 385 | 0 | switch (field) { |
| 386 | |
case SECOND: |
| 387 | 0 | _internalPanel.add(_secondText); |
| 388 | 0 | break; |
| 389 | |
case MINUTE: |
| 390 | 0 | _internalPanel.add(_minuteText); |
| 391 | 0 | break; |
| 392 | |
case HOUR: |
| 393 | 0 | _internalPanel.add(_hourText); |
| 394 | 0 | break; |
| 395 | |
case DAY: |
| 396 | 0 | _internalPanel.add(_dayText); |
| 397 | 0 | break; |
| 398 | |
case MONTH: |
| 399 | 0 | _internalPanel.add(_monthText); |
| 400 | 0 | break; |
| 401 | |
case YEAR: |
| 402 | 0 | _internalPanel.add(_yearText); |
| 403 | 0 | break; |
| 404 | |
case SPACER: |
| 405 | 0 | _internalPanel.add(Box.createHorizontalStrut(3)); |
| 406 | 0 | break; |
| 407 | |
case TIMESEPARATOR: |
| 408 | 0 | _internalPanel.add(new JLabel(_timeSeparator, JLabel.CENTER)); |
| 409 | 0 | break; |
| 410 | |
case DATESEPARATOR: |
| 411 | 0 | _internalPanel.add(new JLabel(_dateSeparator, JLabel.CENTER)); |
| 412 | 0 | break; |
| 413 | |
case AMPM: |
| 414 | 0 | _internalPanel.add(_ampmText); |
| 415 | 0 | break; |
| 416 | |
default: |
| 417 | 0 | throw new IllegalArgumentException("Unknown constant: " + field); |
| 418 | |
} |
| 419 | 0 | } |
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
public void populate() { |
| 425 | 0 | long offset = 0; |
| 426 | 0 | long value = _currentCalendar.get(Calendar.YEAR); |
| 427 | 0 | if (_year) { |
| 428 | 0 | _yearText.setText(_twoFormat.format(value)); |
| 429 | |
} else { |
| 430 | 0 | offset = value * 12; |
| 431 | 0 | if (LOGGER.isDebugEnabled()) { |
| 432 | 0 | LOGGER.debug("months offset " + offset); |
| 433 | |
} |
| 434 | 0 | _monthText.setColumns(8); |
| 435 | |
} |
| 436 | 0 | value = _currentCalendar.get(Calendar.MONTH) + offset; |
| 437 | 0 | if (_month) { |
| 438 | 0 | _monthText.setText(_twoFormat.format(value + 1)); |
| 439 | 0 | offset = 0; |
| 440 | |
} else { |
| 441 | 0 | Calendar foo = (Calendar) _currentCalendar.clone(); |
| 442 | 0 | foo.set(Calendar.DATE, 1); |
| 443 | |
|
| 444 | 0 | offset = Math.round(offset * 365.25) + foo.get(Calendar.DAY_OF_YEAR) - 1; |
| 445 | 0 | if (LOGGER.isDebugEnabled()) { |
| 446 | 0 | LOGGER.debug("days offset " + offset); |
| 447 | |
} |
| 448 | 0 | _dayText.setColumns(8); |
| 449 | |
} |
| 450 | 0 | value = offset + _currentCalendar.get(Calendar.DATE); |
| 451 | 0 | if (_day) { |
| 452 | 0 | _dayText.setText(_twoFormat.format(value)); |
| 453 | 0 | offset = 0; |
| 454 | |
} else { |
| 455 | 0 | offset *= 24; |
| 456 | 0 | if (LOGGER.isDebugEnabled()) { |
| 457 | 0 | LOGGER.debug("hours offset " + offset); |
| 458 | |
} |
| 459 | |
|
| 460 | |
|
| 461 | 0 | _hourText.setColumns(8); |
| 462 | |
} |
| 463 | 0 | if (_military) { |
| 464 | 0 | value = _currentCalendar.get(Calendar.HOUR_OF_DAY) + offset; |
| 465 | |
} else { |
| 466 | 0 | value = _currentCalendar.get(Calendar.HOUR) + offset; |
| 467 | |
} |
| 468 | 0 | if (_hour) { |
| 469 | 0 | _hourText.setText(_twoFormat.format(value)); |
| 470 | 0 | offset = 0; |
| 471 | |
} else { |
| 472 | 0 | offset += _currentCalendar.get(Calendar.HOUR_OF_DAY) * 60L; |
| 473 | 0 | _minuteText.setColumns(8); |
| 474 | |
} |
| 475 | 0 | value = _currentCalendar.get(Calendar.MINUTE) + offset; |
| 476 | 0 | if (_minute) { |
| 477 | 0 | _minuteText.setText(_twoFormat.format(value)); |
| 478 | 0 | offset = 0; |
| 479 | |
} else { |
| 480 | 0 | offset += _currentCalendar.get(Calendar.MINUTE) * 60L; |
| 481 | 0 | _secondText.setColumns(8); |
| 482 | |
} |
| 483 | 0 | value = _currentCalendar.get(Calendar.SECOND) + offset; |
| 484 | 0 | if (_second) { |
| 485 | 0 | _secondText.setText(_twoFormat.format(value)); |
| 486 | 0 | offset = 0; |
| 487 | |
} |
| 488 | |
|
| 489 | |
|
| 490 | 0 | if (!_military) { |
| 491 | 0 | _ampmText |
| 492 | 0 | .setText(_currentCalendar.get(Calendar.AM_PM) == Calendar.AM ? "AM" |
| 493 | |
: "PM"); |
| 494 | |
} |
| 495 | 0 | } |
| 496 | |
|
| 497 | |
public void increment(final int field, |
| 498 | |
final int amount) { |
| 499 | 0 | final Object old = _currentCalendar.clone(); |
| 500 | 0 | switch (field) { |
| 501 | |
case SECOND: |
| 502 | 0 | _currentCalendar.add(Calendar.SECOND, amount); |
| 503 | 0 | break; |
| 504 | |
case MINUTE: |
| 505 | 0 | _currentCalendar.add(Calendar.MINUTE, amount); |
| 506 | 0 | break; |
| 507 | |
case HOUR: |
| 508 | 0 | _currentCalendar.add(Calendar.HOUR_OF_DAY, amount); |
| 509 | 0 | break; |
| 510 | |
case DAY: |
| 511 | 0 | _currentCalendar.add(Calendar.DATE, amount); |
| 512 | 0 | break; |
| 513 | |
case MONTH: |
| 514 | 0 | _currentCalendar.add(Calendar.MONTH, amount); |
| 515 | 0 | break; |
| 516 | |
case YEAR: |
| 517 | 0 | _currentCalendar.add(Calendar.YEAR, amount); |
| 518 | 0 | break; |
| 519 | |
case AMPM: |
| 520 | 0 | if (Math.IEEEremainder(amount, 2) != 0) { |
| 521 | 0 | if (_currentCalendar.get(Calendar.AM_PM) == Calendar.AM) { |
| 522 | 0 | _currentCalendar.add(Calendar.HOUR_OF_DAY, 12); |
| 523 | |
} else { |
| 524 | 0 | _currentCalendar.add(Calendar.HOUR_OF_DAY, -12); |
| 525 | |
} |
| 526 | |
} |
| 527 | |
break; |
| 528 | |
default: |
| 529 | 0 | throw new IllegalArgumentException("Unknown constant: " + field); |
| 530 | |
} |
| 531 | 0 | populate(); |
| 532 | 0 | fireDateChange((Calendar) old, _currentCalendar); |
| 533 | 0 | } |
| 534 | |
|
| 535 | |
protected boolean check(final int field, |
| 536 | |
final String text) { |
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
int value; |
| 541 | |
try { |
| 542 | 0 | value = Integer.parseInt(text); |
| 543 | 0 | } catch (final NumberFormatException nfe) { |
| 544 | 0 | populate(); |
| 545 | 0 | return false; |
| 546 | 0 | } |
| 547 | 0 | switch (field) { |
| 548 | |
case SECOND: |
| 549 | 0 | _currentCalendar.set(Calendar.SECOND, value); |
| 550 | 0 | break; |
| 551 | |
case MINUTE: |
| 552 | 0 | _currentCalendar.set(Calendar.MINUTE, value); |
| 553 | 0 | break; |
| 554 | |
case HOUR: |
| 555 | 0 | if (_military) { |
| 556 | 0 | _currentCalendar.set(Calendar.HOUR_OF_DAY, value); |
| 557 | |
} else { |
| 558 | 0 | _currentCalendar.set(Calendar.HOUR, value); |
| 559 | |
} |
| 560 | 0 | break; |
| 561 | |
case DAY: |
| 562 | 0 | _currentCalendar.set(Calendar.DATE, value); |
| 563 | 0 | break; |
| 564 | |
case MONTH: |
| 565 | 0 | _currentCalendar.set(Calendar.MONTH, value); |
| 566 | 0 | break; |
| 567 | |
case YEAR: |
| 568 | 0 | _currentCalendar.set(Calendar.YEAR, value); |
| 569 | 0 | break; |
| 570 | |
default: |
| 571 | 0 | populate(); |
| 572 | 0 | return false; |
| 573 | |
} |
| 574 | 0 | return true; |
| 575 | |
} |
| 576 | |
|
| 577 | |
protected void fireDateChange(final Calendar old, |
| 578 | |
final Calendar clone) { |
| 579 | 0 | _dateListener.firePropertyChange("date", old, clone); |
| 580 | 0 | } |
| 581 | |
|
| 582 | |
public void addDateListener(final PropertyChangeListener l) { |
| 583 | 0 | _dateListener.addPropertyChangeListener(l); |
| 584 | 0 | } |
| 585 | |
|
| 586 | |
public void removeDateListener(final PropertyChangeListener l) { |
| 587 | 0 | _dateListener.removePropertyChangeListener(l); |
| 588 | 0 | } |
| 589 | |
|
| 590 | |
private JPanel _internalPanel; |
| 591 | 0 | private Calendar _currentCalendar = Calendar.getInstance(); |
| 592 | |
private boolean _military; |
| 593 | |
private PropertyChangeSupport _dateListener; |
| 594 | 0 | private String _dateSeparator = "/"; |
| 595 | 0 | private String _timeSeparator = ":"; |
| 596 | |
private JTextField _monthText; |
| 597 | |
private JTextField _dayText; |
| 598 | |
private JTextField _hourText; |
| 599 | |
private JTextField _minuteText; |
| 600 | |
private JTextField _secondText; |
| 601 | |
private JTextField _yearText; |
| 602 | 0 | private boolean _hour = true; |
| 603 | 0 | private boolean _minute = true; |
| 604 | 0 | private boolean _second = true; |
| 605 | 0 | private boolean _month = true; |
| 606 | 0 | private boolean _day = true; |
| 607 | 0 | private boolean _year = true; |
| 608 | |
private DecimalFormat _twoFormat; |
| 609 | |
private JTextField _ampmText; |
| 610 | 0 | private int _currentField = 0; |
| 611 | 0 | private static Color _textSelectedColor = UIManager |
| 612 | 0 | .getColor("TextField.selectionBackground"); |
| 613 | 0 | private static Color _textUnselectedColor = UIManager |
| 614 | 0 | .getColor("TextField.background"); |
| 615 | |
} |