1 package jp.sourceforge.stigmata.ui.swing;
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.awt.event.MouseAdapter;
8 import java.awt.event.MouseEvent;
9 import java.util.Iterator;
11 import javax.swing.Box;
12 import javax.swing.DefaultListModel;
13 import javax.swing.JButton;
14 import javax.swing.JCheckBox;
15 import javax.swing.JList;
16 import javax.swing.JScrollPane;
17 import javax.swing.ListCellRenderer;
18 import javax.swing.UIManager;
19 import javax.swing.border.Border;
20 import javax.swing.border.EmptyBorder;
22 import jp.sourceforge.stigmata.spi.BirthmarkSpi;
26 * @author Haruaki TAMADA
28 public class BirthmarkSelectionListPane extends BirthmarkSelectablePane{
29 private static final long serialVersionUID = 3209854654743223453L;
31 private DefaultListModel model;
34 public BirthmarkSelectionListPane(StigmataFrame stigmata){
41 public void serviceRemoved(BirthmarkSpi service){
42 BirthmarkSelection elem = getSelection(service.getType());
43 model.removeElement(elem);
45 super.serviceRemoved(service);
48 private void initLayouts(){
49 setLayout(new BorderLayout());
50 list = new JList(model = new DefaultListModel());
51 JScrollPane scroll = new JScrollPane(list);
52 add(scroll, BorderLayout.CENTER);
53 list.setCellRenderer(new Renderer());
54 list.setVisibleRowCount(5);
55 JButton checkAll = GUIUtility.createButton(getMessages(), "checkall");
56 JButton uncheckAll = GUIUtility.createButton(getMessages(), "uncheckall");
58 Box box = Box.createHorizontalBox();
59 box.add(Box.createHorizontalGlue());
61 box.add(Box.createHorizontalGlue());
63 box.add(Box.createHorizontalGlue());
64 add(box, BorderLayout.SOUTH);
66 ActionListener listener = new ActionListener(){
68 public void actionPerformed(ActionEvent e){
69 boolean flag = e.getActionCommand().equals("checkall");
70 for(Iterator<BirthmarkSelection> i = birthmarkSelections(); i.hasNext(); ){
71 BirthmarkSelection le = i.next();
78 checkAll.addActionListener(listener);
79 uncheckAll.addActionListener(listener);
80 list.addMouseListener(new MouseAdapter(){
82 public void mouseClicked(MouseEvent e){
83 int index = list.locationToIndex(e.getPoint());
84 list.setSelectedIndex(index);
85 BirthmarkSelection elem = (BirthmarkSelection)model.getElementAt(index);
86 elem.setSelected(!elem.isSelected());
93 * update layouts and update selected birthmarks list.
96 protected void updateLayouts(){
97 model.removeAllElements();
99 for(Iterator<BirthmarkSelection> i = birthmarkSelections(); i.hasNext(); ){
100 BirthmarkSelection elem = i.next();
101 if(elem.isVisible(isExperimentalMode())){
102 model.addElement(elem);
105 select(elem.getType(), elem.isVisible(isExperimentalMode()) && elem.isSelected());
110 public static class Renderer extends JCheckBox implements ListCellRenderer{
111 private static final long serialVersionUID = -324432943654654L;
112 private static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
119 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean forcus){
120 BirthmarkSelection elem = (BirthmarkSelection)value;
121 setText(elem.getService().getDisplayType());
122 setToolTipText(elem.getService().getDescription());
123 setSelected(elem.isSelected());
126 setBackground(list.getSelectionBackground());
127 setForeground(list.getSelectionForeground());
130 setBackground(list.getBackground());
131 setForeground(list.getForeground());
134 Border border = null;
137 border = UIManager.getBorder("List.focusSelectedCellHighlightBorder");
139 if (border == null) {
140 border = UIManager.getBorder("List.focusCellHighlightBorder");
143 border = noFocusBorder;