package caltool.view.schedule; import caltool.model.schedule.*; import caltool.view.*; import mvp.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class CategoriesEditor extends CalendarToolWindow { public CategoriesEditor(Screen screen, Model model, CalendarToolUI calToolUI) { super(screen, model, calToolUI); } public Component compose() { JPanel panel = new JPanel(); window.add(panel); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(Box.createVerticalStrut(15)); panel.add(composeList()); panel.add(Box.createVerticalStrut(25)); panel.add(composeButtonRow1()); panel.add(Box.createVerticalStrut(15)); panel.add(composeButtonRow2()); panel.add(Box.createVerticalStrut(15)); window.setTitle("Edit Categories"); window.pack(); return window; } /** * Compose the labeled list of cateogries. */ protected Box composeList() { Box hbox = Box.createHorizontalBox(); Box vbox = Box.createVerticalBox(); JLabel label = new JLabel("Current Categories:"); label.setAlignmentX(Component.LEFT_ALIGNMENT); vbox.add(label); /* * Build a list with some dummy blank elements. This will be refined * later to add model data. */ String[] dummyData = { " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }; JList list = new JList(dummyData); list.setAlignmentX(Component.LEFT_ALIGNMENT); list.setBorder(BorderFactory.createLineBorder(Color.black)); vbox.add(list); hbox.add(Box.createHorizontalStrut(25)); hbox.add(vbox); hbox.add(Box.createHorizontalStrut(25)); return hbox; } /** * Compose the first row of buttons, consisting of Add, Change, and Delete. */ protected Box composeButtonRow1() { Box hbox = Box.createHorizontalBox(); /* * Construct the three buttons. */ JButton addButton = new JButton("Add"); JButton changeButton = new JButton("Change"); JButton deleteButton = new JButton("Delete"); /* * Attach the appropriate action listeners to each button. */ addButton.addActionListener( new CategoriesAddButtonListener((Schedule) model, this)); changeButton.addActionListener( new CategoriesChangeButtonListener((Schedule) model, this)); deleteButton.addActionListener( new CategoriesDeleteButtonListener((Schedule) model, this)); /* * Add them to the hbox and return it. */ hbox.add(Box.createHorizontalStrut(15)); hbox.add(addButton); hbox.add(Box.createHorizontalStrut(20)); hbox.add(changeButton); hbox.add(Box.createHorizontalStrut(20)); hbox.add(deleteButton); hbox.add(Box.createHorizontalStrut(15)); return hbox; } /** * Compose the second row of buttons, consisting of Save As, Load, and * Done. */ protected Box composeButtonRow2() { Box hbox = Box.createHorizontalBox(); /* * Construct the buttons. */ JButton saveAsButton = new JButton("Save As ..."); JButton loadButton = new JButton("Load ..."); JButton doneButton = new JButton("Done"); /* * Attach the appropriate action listeners to each button. */ saveAsButton.addActionListener( new CategoriesSaveAsButtonListener((Schedule) model, this)); loadButton.addActionListener( new CategoriesLoadButtonListener((Schedule) model, this)); doneButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { hide(); } } ); /* * Add them to the hbox and return it. */ hbox.add(Box.createHorizontalStrut(15)); hbox.add(saveAsButton); hbox.add(Box.createHorizontalStrut(20)); hbox.add(loadButton); hbox.add(Box.createHorizontalStrut(20)); hbox.add(doneButton); hbox.add(Box.createHorizontalStrut(15)); return hbox; } }