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
39 public class ExtractedHistoryPane extends JPanel{
40 private static final long serialVersionUID = 4070750464486981964L;
42 private StigmataFrame stigmata;
43 private JComboBox combo;
45 private DefaultListModel model;
46 private ExtractedBirthmarkServiceManager historyManager;
47 private ExtractedBirthmarkHistory currentHistory;
49 public ExtractedHistoryPane(StigmataFrame stigmata){
50 this.stigmata = stigmata;
56 private void updateList(){
57 String historyId = (String)combo.getSelectedItem();
58 currentHistory = historyManager.getHistory(historyId);
61 for(String id: currentHistory){
66 private void initData(){
67 historyManager = new ExtractedBirthmarkServiceManager(stigmata.getEnvironment());
69 for(String id: historyManager.getHistoryIds()){
74 private void showAction(String id){
75 ExtractionResultSet ers = currentHistory.getResultSet(id);
76 stigmata.showExtractionResult(ers);
79 private void initLayouts(){
80 final Messages messages = stigmata.getMessages();
81 setLayout(new BorderLayout());
83 final Action showAction = new AbstractAction(){
84 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;
93 public void actionPerformed(ActionEvent e){
97 final Action deleteAction = new AbstractAction(){
98 private static final long serialVersionUID = 8145188292702648924L;
100 public void actionPerformed(ActionEvent e){
101 int[] indeces = list.getSelectedIndices();
102 for(int i = indeces.length - 1; i >= 0; i--){
103 String id = (String)model.get(indeces[i]);
104 currentHistory.deleteResultSet(id);
105 model.remove(indeces[i]);
107 list.clearSelection();
110 model = new DefaultListModel();
111 list = new JList(model);
112 combo = new JComboBox();
113 list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
114 GUIUtility.decorateJComponent(messages, list, "historylist");
115 GUIUtility.decorateJComponent(messages, combo, "historylocation");
117 JButton showButton = GUIUtility.createButton(messages, "showhistory", showAction);
118 JButton refreshButton = GUIUtility.createButton(messages, "refreshhistory", refreshAction);
119 JButton deleteButton = GUIUtility.createButton(messages, "deletehistory", deleteAction);
120 deleteAction.setEnabled(false);
121 showAction.setEnabled(false);
123 list.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
124 public void valueChanged(ListSelectionEvent e){
125 int[] indeces = list.getSelectedIndices();
126 showAction.setEnabled(currentHistory != null && indeces.length == 1);
127 deleteAction.setEnabled(currentHistory != null && indeces.length > 0);
130 list.addMouseListener(new MouseAdapter(){
132 public void mouseClicked(MouseEvent e){
133 int index = list.locationToIndex(e.getPoint());
134 if(index >= 0 && e.getClickCount() == 2){
135 showAction((String)model.get(index));
139 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));