1 /* Copyright (C) 2005-2011 Fabio Riccardi */
2 
3 package com.lightcrafts.ui.browser.view;
4 
5 import com.lightcrafts.ui.browser.model.ImageDatum;
6 import static com.lightcrafts.ui.browser.view.Locale.LOCALE;
7 
8 import javax.swing.*;
9 
10 /**
11  * An AbstractAction that listens to browser selection events, enables and
12  * disables according to whether the selection includes a lead selection, and
13  * updates its name with the name of the lead selection.
14  */
15 abstract class LeadSelectionAction
16     extends AbstractAction implements ImageBrowserListener
17 {
18     private ImageDatum lead;
19 
LeadSelectionAction( String key, AbstractImageBrowser browser, boolean enabled )20     LeadSelectionAction(
21         String key, AbstractImageBrowser browser, boolean enabled
22     ) {
23         putValue(Action.NAME, LOCALE.get(key));
24         setEnabled(false);
25         if (enabled) {
26             browser.addBrowserListener(this);
27         }
28     }
29 
selectionChanged(ImageBrowserEvent event)30     public void selectionChanged(ImageBrowserEvent event) {
31         lead = event.getLead();
32         update();
33     }
34 
imageDoubleClicked(ImageBrowserEvent event)35     public void imageDoubleClicked(ImageBrowserEvent event) {
36         // do nothing
37     }
38 
browserError(String message)39     public void browserError(String message) {
40         // do nothing
41     }
42 
getLeadDatum()43     ImageDatum getLeadDatum() {
44         return lead;
45     }
46 
update()47     void update() {
48         setEnabled(lead != null);
49     }
50 }
51