package caltool.view.options; import caltool.model.options.*; import mvp.*; import javax.swing.*; import java.awt.*; public class TimesAndDatesOptionsPanel extends View { public TimesAndDatesOptionsPanel(Screen screen, Options options) { super(screen, options); maxTextFieldHeight = 1.9; } public Component compose() { /* * Make this' widget a vertically laid out JPanel. */ JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(composeTimeFormat()); panel.add(composeDateDisplayFormat()); panel.add(composeDateInputFormat()); return (widget = panel); } protected Component composeTimeFormat() { Box hbox = Box.createHorizontalBox(); hbox.add(Box.createHorizontalStrut(10)); JLabel label = new JLabel("Time Format: "); label.setAlignmentY(Component.BOTTOM_ALIGNMENT); hbox.add(label); hbox.add(Box.createHorizontalStrut(30)); hbox.add(composeClockButtons()); hbox.add(Box.createHorizontalStrut(30)); hbox.add(composeAMPMCheckBoxes()); hbox.add(Box.createHorizontalStrut(30)); hbox.add(composeAMPMPrefix()); hbox.add(Box.createHorizontalStrut(10)); return hbox; } protected Component composeClockButtons() { Box vbox = Box.createVerticalBox(); JRadioButton twelveHour = new JRadioButton("12-hour clock"); JRadioButton twentyFourHour = new JRadioButton("24-hour clock"); ButtonGroup group= new ButtonGroup(); group.add(twelveHour); group.add(twentyFourHour); twelveHour.setSelected(true); vbox.add(twelveHour); vbox.add(twentyFourHour); return vbox; } protected Component composeAMPMCheckBoxes() { Box vbox = Box.createVerticalBox(); JCheckBox showAM = new JCheckBox("Show AM"); JCheckBox showPM = new JCheckBox("Show PM"); showAM.setSelected(true); showPM.setSelected(true); vbox.add(showAM); vbox.add(showPM); return vbox; } protected Component composeAMPMPrefix() { Box hbox = Box.createHorizontalBox(); JLabel label = new JLabel("AM/PM Prefix: "); JTextField prefix = new JTextField(3); label.setAlignmentY(Component.BOTTOM_ALIGNMENT); prefix.setAlignmentY(Component.BOTTOM_ALIGNMENT); prefix.setMaximumSize( new Dimension( (int)(3 * prefix.getFont().getSize()), (int)(maxTextFieldHeight * prefix.getFont().getSize()))); prefix.setMinimumSize( new Dimension( (int)(3 * prefix.getFont().getSize()), (int)(maxTextFieldHeight * prefix.getFont().getSize()))); // Next line must wait for 1.4. // hbox.setAlignmentY(Component.BOTTOM_ALIGNMENT); hbox.add(label); hbox.add(prefix); return hbox; } protected Component composeDateDisplayFormat() { Box hbox = Box.createHorizontalBox(); JLabel label = new JLabel("Date Display Format: "); Box comboVbox = Box.createVerticalBox(); Box separatorVbox = Box.createVerticalBox(); String[] selections = { "day of week, full name", "day of week, three characters", "day of week, one or two characters", "date number", "month, full name", "month, short name", "month number", "year, four digits", "year, two digits", }; JComboBox dayCombo = new JComboBox(selections); JComboBox dateCombo = new JComboBox(selections); JComboBox monthCombo = new JComboBox(selections); JComboBox yearCombo = new JComboBox(selections); /* dayCombo.addItem("day of week, full name"); dayCombo.addItem("day of week, three characters"); dayCombo.addItem("day of week, one or two characters"); dayCombo.addItem(new JSeparator()); dayCombo.addItem("date number"); dayCombo.addItem(new JSeparator()); dayCombo.addItem("month, full name"); dayCombo.addItem("month, short name"); dayCombo.addItem("month number"); dayCombo.addItem(new JSeparator()); dayCombo.addItem("year, four digits"); dayCombo.addItem("year, two digits"); */ label.setAlignmentY(Component.TOP_ALIGNMENT); label.setAlignmentY(Component.LEFT_ALIGNMENT); dayCombo.setAlignmentY(Component.BOTTOM_ALIGNMENT); yearCombo.setAlignmentY(Component.TOP_ALIGNMENT); dayCombo.setMaximumSize( new Dimension( (int)(34 * dayCombo.getFont().getSize()), (int)(maxTextFieldHeight * dayCombo.getFont().getSize()))); dateCombo.setMaximumSize( new Dimension( (int)(34 * dayCombo.getFont().getSize()), (int)(maxTextFieldHeight * dayCombo.getFont().getSize()))); monthCombo.setMaximumSize( new Dimension( (int)(34 * dayCombo.getFont().getSize()), (int)(maxTextFieldHeight * dayCombo.getFont().getSize()))); yearCombo.setMaximumSize( new Dimension( (int)(34 * dayCombo.getFont().getSize()), (int)(maxTextFieldHeight * dayCombo.getFont().getSize()))); dayCombo.setSelectedItem("day of week, full name"); dateCombo.setSelectedItem("date number"); monthCombo.setSelectedItem("month, full name"); yearCombo.setSelectedItem("year, four digits"); comboVbox.add(dayCombo); comboVbox.add(Box.createVerticalStrut(8)); comboVbox.add(dateCombo); comboVbox.add(Box.createVerticalStrut(8)); comboVbox.add(monthCombo); comboVbox.add(Box.createVerticalStrut(8)); comboVbox.add(yearCombo); comboVbox.add(Box.createVerticalStrut(8)); comboVbox.setAlignmentY(Component.TOP_ALIGNMENT); hbox.add(label); hbox.setAlignmentY(Component.TOP_ALIGNMENT); hbox.add(comboVbox); return hbox; } protected Component composeDateInputFormat() { Box hbox = Box.createHorizontalBox(); return hbox; } /** The max height of a text field */ protected final double maxTextFieldHeight; }