1 package jp.sourceforge.stigmata.ui.swing;
3 import java.awt.BorderLayout;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.awt.event.MouseAdapter;
7 import java.awt.event.MouseEvent;
9 import javax.swing.AbstractAction;
10 import javax.swing.Action;
11 import javax.swing.Box;
12 import javax.swing.DefaultListModel;
13 import javax.swing.JButton;
14 import javax.swing.JComboBox;
15 import javax.swing.JList;
16 import javax.swing.JPanel;
17 import javax.swing.JPopupMenu;
18 import javax.swing.JScrollPane;
19 import javax.swing.ListSelectionModel;
20 import javax.swing.event.ListSelectionEvent;
21 import javax.swing.event.ListSelectionListener;
23 import jp.sourceforge.stigmata.ExtractionResultSet;
24 import jp.sourceforge.stigmata.result.history.ExtractedBirthmarkHistory;
25 import jp.sourceforge.stigmata.result.history.ExtractedBirthmarkServiceManager;
26 import jp.sourceforge.stigmata.ui.swing.actions.PopupShowAction;
27 import jp.sourceforge.talisman.i18n.Messages;
30 * Birthmark extraction history viewer.
32 * @author Haruaki Tamada
34 public class ExtractedHistoryPane extends JPanel{
35 private static final long serialVersionUID = 4070750464486981964L;
37 private StigmataFrame stigmata;
38 private JComboBox combo;
40 private DefaultListModel model;
41 private ExtractedBirthmarkServiceManager historyManager;
42 private ExtractedBirthmarkHistory currentHistory;
44 public ExtractedHistoryPane(StigmataFrame stigmata){
45 this.stigmata = stigmata;
51 private void updateList(){
52 String historyId = (String)combo.getSelectedItem();
53 currentHistory = historyManager.getHistory(historyId);
56 for(String id: currentHistory){
61 private void initData(){
62 historyManager = new ExtractedBirthmarkServiceManager(stigmata.getEnvironment());
64 for(String id: historyManager.getHistoryIds()){
69 private void showAction(String id){
70 ExtractionResultSet ers = currentHistory.getResultSet(id);
71 stigmata.showExtractionResult(ers);
74 private void initLayouts(){
75 final Messages messages = stigmata.getMessages();
76 setLayout(new BorderLayout());
78 final Action showAction = new AbstractAction(){
79 private static final long serialVersionUID = 2156350514762218963L;
82 public void actionPerformed(ActionEvent e){
83 showAction((String)model.get(list.getSelectedIndex()));
86 final Action refreshAction = new AbstractAction(){
87 private static final long serialVersionUID = 214765021455345371L;
90 public void actionPerformed(ActionEvent e){
94 final Action deleteAction = new AbstractAction(){
95 private static final long serialVersionUID = 8145188292702648924L;
98 public void actionPerformed(ActionEvent e){
99 int[] indeces = list.getSelectedIndices();
100 for(int i = indeces.length - 1; i >= 0; i--){
101 String id = (String)model.get(indeces[i]);
102 currentHistory.deleteResultSet(id);
103 model.remove(indeces[i]);
105 list.clearSelection();
108 model = new DefaultListModel();
109 list = new JList(model);
110 combo = new JComboBox();
111 list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
112 GUIUtility.decorateJComponent(messages, list, "historylist");
113 GUIUtility.decorateJComponent(messages, combo, "historylocation");
115 JButton showButton = GUIUtility.createButton(messages, "showhistory", showAction);
116 JButton refreshButton = GUIUtility.createButton(messages, "refreshhistory", refreshAction);
117 JButton deleteButton = GUIUtility.createButton(messages, "deletehistory", deleteAction);
118 deleteAction.setEnabled(false);
119 showAction.setEnabled(false);
121 list.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
123 public void valueChanged(ListSelectionEvent e){
124 int[] indeces = list.getSelectedIndices();
125 showAction.setEnabled(currentHistory != null && indeces.length == 1);
126 deleteAction.setEnabled(currentHistory != null && indeces.length > 0);
129 list.addMouseListener(new MouseAdapter(){
131 public void mouseClicked(MouseEvent e){
132 int index = list.locationToIndex(e.getPoint());
133 if(index >= 0 && e.getClickCount() == 2){
134 showAction((String)model.get(index));
138 combo.addActionListener(new ActionListener(){
140 public void actionPerformed(ActionEvent e){
144 JScrollPane scroll = new JScrollPane();
145 scroll.setViewportView(list);
147 Box south = Box.createHorizontalBox();
148 south.add(Box.createHorizontalGlue());
149 south.add(showButton);
150 south.add(Box.createHorizontalGlue());
151 south.add(refreshButton);
152 south.add(Box.createHorizontalGlue());
153 south.add(deleteButton);
154 south.add(Box.createHorizontalGlue());
156 add(combo, BorderLayout.NORTH);
157 add(scroll, BorderLayout.CENTER);
158 add(south, BorderLayout.SOUTH);
160 JPopupMenu popup = new JPopupMenu();
161 popup.add(GUIUtility.createJMenuItem(messages, "showhistory"), showAction);
162 popup.add(GUIUtility.createJMenuItem(messages, "refreshhistory"), refreshAction);
163 popup.add(GUIUtility.createJMenuItem(messages, "deletehistory"), deleteAction);
164 list.addMouseListener(new PopupShowAction(popup));