1 package jp.sourceforge.stigmata.ui.swing;
7 import java.awt.BorderLayout;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.awt.event.MouseAdapter;
11 import java.awt.event.MouseEvent;
13 import javax.swing.AbstractAction;
14 import javax.swing.Action;
15 import javax.swing.Box;
16 import javax.swing.DefaultListModel;
17 import javax.swing.JButton;
18 import javax.swing.JComboBox;
19 import javax.swing.JList;
20 import javax.swing.JPanel;
21 import javax.swing.JPopupMenu;
22 import javax.swing.JScrollPane;
23 import javax.swing.ListSelectionModel;
24 import javax.swing.event.ListSelectionEvent;
25 import javax.swing.event.ListSelectionListener;
27 import jp.sourceforge.stigmata.ExtractionResultSet;
28 import jp.sourceforge.stigmata.result.history.ExtractedBirthmarkHistory;
29 import jp.sourceforge.stigmata.result.history.ExtractedBirthmarkServiceManager;
30 import jp.sourceforge.stigmata.ui.swing.actions.PopupShowAction;
31 import jp.sourceforge.talisman.i18n.Messages;
34 * Birthmark extraction history viewer.
36 * @author Haruaki Tamada
38 public class ExtractedHistoryPane extends JPanel{
39 private static final long serialVersionUID = 4070750464486981964L;
41 private StigmataFrame stigmata;
42 private JComboBox combo;
44 private DefaultListModel model;
45 private ExtractedBirthmarkServiceManager historyManager;
46 private ExtractedBirthmarkHistory currentHistory;
48 public ExtractedHistoryPane(StigmataFrame stigmata){
49 this.stigmata = stigmata;
55 private void updateList(){
56 String historyId = (String)combo.getSelectedItem();
57 currentHistory = historyManager.getHistory(historyId);
60 for(String id: currentHistory){
65 private void initData(){
66 historyManager = new ExtractedBirthmarkServiceManager(stigmata.getEnvironment());
68 for(String id: historyManager.getHistoryIds()){
73 private void showAction(String id){
74 ExtractionResultSet ers = currentHistory.getResultSet(id);
75 stigmata.showExtractionResult(ers);
78 private void initLayouts(){
79 final Messages messages = stigmata.getMessages();
80 setLayout(new BorderLayout());
82 final Action showAction = new AbstractAction(){
83 private static final long serialVersionUID = 2156350514762218963L;
86 public void actionPerformed(ActionEvent e){
87 showAction((String)model.get(list.getSelectedIndex()));
90 final Action refreshAction = new AbstractAction(){
91 private static final long serialVersionUID = 214765021455345371L;
94 public void actionPerformed(ActionEvent e){
98 final Action deleteAction = new AbstractAction(){
99 private static final long serialVersionUID = 8145188292702648924L;
102 public void actionPerformed(ActionEvent e){
103 int[] indeces = list.getSelectedIndices();
104 for(int i = indeces.length - 1; i >= 0; i--){
105 String id = (String)model.get(indeces[i]);
106 currentHistory.deleteResultSet(id);
107 model.remove(indeces[i]);
109 list.clearSelection();
112 model = new DefaultListModel();
113 list = new JList(model);
114 combo = new JComboBox();
115 list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
116 GUIUtility.decorateJComponent(messages, list, "historylist");
117 GUIUtility.decorateJComponent(messages, combo, "historylocation");
119 JButton showButton = GUIUtility.createButton(messages, "showhistory", showAction);
120 JButton refreshButton = GUIUtility.createButton(messages, "refreshhistory", refreshAction);
121 JButton deleteButton = GUIUtility.createButton(messages, "deletehistory", deleteAction);
122 deleteAction.setEnabled(false);
123 showAction.setEnabled(false);
125 list.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
127 public void valueChanged(ListSelectionEvent e){
128 int[] indeces = list.getSelectedIndices();
129 showAction.setEnabled(currentHistory != null && indeces.length == 1);
130 deleteAction.setEnabled(currentHistory != null && indeces.length > 0);
133 list.addMouseListener(new MouseAdapter(){
135 public void mouseClicked(MouseEvent e){
136 int index = list.locationToIndex(e.getPoint());
137 if(index >= 0 && e.getClickCount() == 2){
138 showAction((String)model.get(index));
142 combo.addActionListener(new ActionListener(){
144 public void actionPerformed(ActionEvent e){
148 JScrollPane scroll = new JScrollPane();
149 scroll.setViewportView(list);
151 Box south = Box.createHorizontalBox();
152 south.add(Box.createHorizontalGlue());
153 south.add(showButton);
154 south.add(Box.createHorizontalGlue());
155 south.add(refreshButton);
156 south.add(Box.createHorizontalGlue());
157 south.add(deleteButton);
158 south.add(Box.createHorizontalGlue());
160 add(combo, BorderLayout.NORTH);
161 add(scroll, BorderLayout.CENTER);
162 add(south, BorderLayout.SOUTH);
164 JPopupMenu popup = new JPopupMenu();
165 popup.add(GUIUtility.createJMenuItem(messages, "showhistory"), showAction);
166 popup.add(GUIUtility.createJMenuItem(messages, "refreshhistory"), refreshAction);
167 popup.add(GUIUtility.createJMenuItem(messages, "deletehistory"), deleteAction);
168 list.addMouseListener(new PopupShowAction(popup));