~josejuan-sanchez/+junk/original-jhv-experimental-version

« back to all changes in this revision

Viewing changes to src/jhv/src/org/helioviewer/jhv/gui/components/layerTable/LayerTableSelectionModel.java

  • Committer: José Juan Sánchez Hernández
  • Date: 2013-02-05 13:32:08 UTC
  • Revision ID: josejuan.sanchez@gmail.com-20130205133208-dfz1sh1uge5pjkny
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.helioviewer.jhv.gui.components.layerTable;
 
2
 
 
3
import javax.swing.DefaultListSelectionModel;
 
4
import javax.swing.SwingUtilities;
 
5
 
 
6
import org.helioviewer.jhv.layers.LayersListener;
 
7
import org.helioviewer.jhv.layers.LayersModel;
 
8
import org.helioviewer.viewmodel.view.View;
 
9
 
 
10
/**
 
11
 * SelectionModel reflecting the "activeLayer" property of the LayersModel
 
12
 * 
 
13
 * @author Malte Nuhn
 
14
 */
 
15
public class LayerTableSelectionModel extends DefaultListSelectionModel implements LayersListener {
 
16
 
 
17
    private static final long serialVersionUID = 2276237017135257828L;
 
18
 
 
19
    /** The sole instance of this class. */
 
20
    private static final LayerTableSelectionModel layerTableSelectionModel = new LayerTableSelectionModel();
 
21
 
 
22
    /**
 
23
     * Returns the only instance of this class.
 
24
     * 
 
25
     * @return the only instance of this class.
 
26
     * */
 
27
    public static LayerTableSelectionModel getSingletonInstance() {
 
28
        return layerTableSelectionModel;
 
29
    }
 
30
 
 
31
    /**
 
32
     * Default constructor
 
33
     */
 
34
    private LayerTableSelectionModel() {
 
35
        this.setSelectionMode(LayerTableSelectionModel.SINGLE_SELECTION);
 
36
        LayersModel.getSingletonInstance().addLayersListener(this);
 
37
    }
 
38
 
 
39
    /**
 
40
     * {@inheritDoc}
 
41
     * 
 
42
     * Update internal state and the underlying LayersModel state
 
43
     */
 
44
    @Override
 
45
    public void setSelectionInterval(int index0, int index1) {
 
46
        super.setSelectionInterval(index0, index1);
 
47
        LayersModel.getSingletonInstance().setActiveLayer(index0);
 
48
    }
 
49
 
 
50
    /**
 
51
     * Helper needed to call the super.setSelectionInterval method from within
 
52
     * another thread
 
53
     * <p>
 
54
     * 
 
55
     * @see javax.swing.DefaultListSelectionModel#setSelectionInterval(int,int)
 
56
     *      setSelectionInterval
 
57
     */
 
58
    public void superSetSelectionInterval(int index0, int index1) {
 
59
        super.setSelectionInterval(index0, index1);
 
60
    }
 
61
 
 
62
    public void activeLayerChanged(int index) {
 
63
        SwingUtilities.invokeLater(new Runnable() {
 
64
            public void run() {
 
65
                superSetSelectionInterval(LayersModel.getSingletonInstance().getActiveLayer(), LayersModel.getSingletonInstance().getActiveLayer());
 
66
            }
 
67
        });
 
68
    }
 
69
 
 
70
    /**
 
71
     * {@inheritDoc}
 
72
     */
 
73
    public void layerAdded(int newIndex) {
 
74
        // Log.debug("LayerTableSelection: Layer Added, selecting " +
 
75
        // layersModel.getActiveLayer());
 
76
    }
 
77
 
 
78
    /**
 
79
     * {@inheritDoc}
 
80
     */
 
81
    public void layerChanged(int index) {
 
82
    }
 
83
 
 
84
    /**
 
85
     * {@inheritDoc}
 
86
     */
 
87
    public void layerRemoved(View oldView, int oldIndex) {
 
88
        // Log.debug("LayerTableSelection: Layer Removed");
 
89
    }
 
90
 
 
91
    /**
 
92
     * {@inheritDoc}
 
93
     */
 
94
    public void viewportGeometryChanged() {
 
95
    }
 
96
 
 
97
    /**
 
98
     * {@inheritDoc}
 
99
     */
 
100
    public void subImageDataChanged() {
 
101
    }
 
102
 
 
103
    /**
 
104
     * {@inheritDoc}
 
105
     */
 
106
    public void timestampChanged(int idx) {
 
107
    }
 
108
 
 
109
    /**
 
110
     * {@inheritDoc}
 
111
     */
 
112
    public void layerDownloaded(int idx) {
 
113
    }
 
114
}