Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / AbstractPanel.java @ 7738

History | View | Annotate | Download (1.84 KB)

1 7304 caballero
package com.iver.cit.gvsig.project.documents.view.legend.gui;
2
3 7738 jaume
import javax.swing.JOptionPane;
4
import javax.swing.JPanel;
5
6 7304 caballero
import com.iver.andami.PluginServices;
7
import com.iver.andami.messages.Messages;
8
import com.iver.cit.gvsig.fmap.layers.FLayer;
9
import com.iver.cit.gvsig.fmap.layers.FLayers;
10
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
11
import com.iver.cit.gvsig.fmap.rendering.Legend;
12
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
13
14
15
/**
16
 * Clase utilizada para reutilizar m?todos.
17
 *
18
 * @author Vicente Caballero Navarro
19
 */
20
public abstract class AbstractPanel extends JPanel {
21
        /**
22
         * Cuando hay varios capas vectoriales seleccionados, devolver? el ?ltimo.
23
         *
24
         * @param layers Grupo de layers.
25
         *
26
         * @return la primera flayer seleccionada.
27
         */
28
        protected FLayer getFirstActiveLayerVect(FLayers layers) {
29
                // Comprobar en openLegendManager que hay alg?n capa activo!
30
                FLayer[] activeLyrs = layers.getActives();
31
32
                if (activeLyrs.length == 0) {
33
                        JOptionPane.showMessageDialog(null,
34
                                Messages.getString("necesita_una_capa_activa"), "",
35
                                JOptionPane.ERROR_MESSAGE);
36
37
                        return null;
38
                }
39
40
                FLayer lyr = null;
41
42
                for (int i = 0; i < activeLyrs.length; i++) {
43
                        if (activeLyrs[i] instanceof FLayers) {
44
                                lyr = getFirstActiveLayerVect((FLayers) activeLyrs[i]);
45
                        }
46
47
                        if (activeLyrs[i] instanceof Classifiable) {
48
                                Classifiable auxC = (Classifiable) activeLyrs[i];
49
                                Legend theLegend = auxC.getLegend();
50
51
                                if (theLegend instanceof VectorialLegend) {
52
                                        lyr = (FLayer) auxC;
53
                                }
54
                        }
55
                }
56
57
                if (lyr == null) {
58
                        System.out.println(PluginServices.getText(this,
59
                                        "Por_favor_active_la_capa") + ".");
60
                        JOptionPane.showMessageDialog(null,
61
                                Messages.getString(PluginServices.getText(this,
62
                                                "necesita_una_capa_vectorial_activa")), "",
63
                                JOptionPane.ERROR_MESSAGE);
64
65
                        return null;
66
                }
67
68
                return lyr;
69
        }
70
}