Revision 43592 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.coreplugin.app/org.gvsig.coreplugin.app.mainplugin/src/main/java/org/gvsig/coreplugin/preferences/general/appearance/AppearancePage.java

View differences:

AppearancePage.java
24 24
package org.gvsig.coreplugin.preferences.general.appearance;
25 25

  
26 26
import java.util.ArrayList;
27
import java.util.Collections;
28
import java.util.Comparator;
27 29
import java.util.List;
28 30
import javax.swing.DefaultComboBoxModel;
29 31
import javax.swing.ImageIcon;
......
45 47
import org.gvsig.tools.ToolsLocator;
46 48
import org.gvsig.tools.dynobject.DynObject;
47 49
import org.gvsig.tools.i18n.I18nManager;
50
import org.gvsig.tools.swing.api.ListElement;
48 51
import org.gvsig.tools.util.ToolsUtilLocator;
49 52
import org.slf4j.Logger;
50 53
import org.slf4j.LoggerFactory;
......
68 71
    private boolean enableLookAndFeel = true;
69 72
    private final String defaultLookAndFeel;
70 73

  
71
    public static class ListElement<T> {
72

  
73
        private final String label;
74
        private final T value;
75

  
76
        public ListElement(String label, T value) {
77
            this.label = label;
78
            this.value = value;
79
        }
80

  
81
        @Override
82
        public String toString() {
83
            return this.label;
84
        }
85

  
86
        public T getValue() {
87
            return this.value;
88
        }
89
    }
90

  
91 74
    public AppearancePage() {
92 75
        setParentID(GeneralPage.id);
93 76
        installDefaultLookAndFeel();       
......
102 85
    }
103 86

  
104 87
    private void installDefaultLookAndFeel() {
105
        try {
106
            // install the plastic look and feel before getting the laf combobox
107
            UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
108
            // install the extra LAF's before getting the LAF combobox
109
            String osName = System.getProperty("os.name");
110
            if( osName.toLowerCase().startsWith("mac os x") ) {
111
                UIManager.installLookAndFeel("Quaqua", "ch.randelshofer.quaqua.QuaquaLookAndFeel");
88
        String[][] lafs = {
89
            { "Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel" },
90
            { "Quaqua", "ch.randelshofer.quaqua.QuaquaLookAndFeel" },
91
            { "Web", "com.alee.laf.WebLookAndFeel" },
92
            { "Sea Glass", "com.seaglasslookandfeel.SeaGlassLookAndFeel" },
93
//            Substance da errores en la carga de gvSIG y el L&F no funciona 
94
//            { "Substance", "org.pushingpixels.substance.api.SubstanceLookAndFeel" },
95
//            { "SubstanceAutumn", "org.pushingpixels.substance.api.skin.SubstanceAutumnLookAndFeel" },
96
//            { "SubstanceOfficeBlue2007", "org.pushingpixels.substance.api.skin.SubstanceOfficeBlue2007LookAndFeel" },
97
//            { "SubstanceBusiness", "org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel" },
98
//            { "SubstanceMistAqua", "org.pushingpixels.substance.api.skin.SubstanceMistAquaLookAndFeel" },
99
            { "Acryl", "com.jtattoo.plaf.acryl.AcrylLookAndFeel" },
100
            { "Fast", "com.jtattoo.plaf.fast.FastLookAndFeel" },
101
            { "Bernstein", "com.jtattoo.plaf.bernstein.BernsteinLookAndFeel" },
102
            { "Aluminium", "com.jtattoo.plaf.aluminium.AluminiumLookAndFeel" },
103
            { "Aero", "com.jtattoo.plaf.aero.AeroLookAndFeel"  },
104
            { "HiFi", "com.jtattoo.plaf.hifi.HiFiLookAndFeel" },
105
            { "McWin", "com.jtattoo.plaf.mcwin.McWinLookAndFeel" },
106
            { "Mint", "com.jtattoo.plaf.mint.MintLookAndFeel" },
107
            { "Noire", "com.jtattoo.plaf.noire.NoireLookAndFeel" },
108
            { "Smart", "com.jtattoo.plaf.smart.SmartLookAndFeel" },
109
            { "Luna", "com.jtattoo.plaf.luna.LunaLookAndFeel" },
110
            { "Texture", "com.jtattoo.plaf.texture.TextureLookAndFeel" }
111
        };            
112

  
113
        for( String[] laf : lafs ) {
114
            try {
115
                UIManager.installLookAndFeel(laf[0], laf[1]);
116
            } catch (Throwable th) {
117
                logger.info("Problems installing look and feel '"+laf[1]+"'", th);
112 118
            }
113
        } catch (Throwable th) {
114
            logger.warn("Problems installing default look and feel", th);
115 119
        }
116 120
    }
117 121

  
......
139 143
        if( supporteds.isEmpty() ) {
140 144
            return null;
141 145
        }
146
        Collections.sort(supporteds, new Comparator<LookAndFeelInfo>() {
147
            @Override
148
            public int compare(LookAndFeelInfo o1, LookAndFeelInfo o2) {
149
                return StringUtils.compare(o1.getName(),o2.getName());
150
            }
151
        });
142 152
        return supporteds.toArray(new LookAndFeelInfo[supporteds.size()]);
143 153
    }
144 154

  
......
154 164
            }
155 165
            this.cboLookAndFeel.setModel(model);
156 166
            this.cboLookAndFeel.setEnabled(true);
167
            this.cboLookAndFeel.setSelectedItem(Launcher.getAndamiConfig().getLookAndFeel());
157 168
        }
158 169
        this.translateAll();
159 170
    }
......
187 198

  
188 199
        if( this.cboLookAndFeel.getModel().getSize()>0 ) {
189 200
            this.cboLookAndFeel.setSelectedIndex(0);
190
            if( !StringUtils.isEmpty(defaultLookAndFeel) ) {
201
            String currentLaF = getCurrentLookAndFeel();
202
            if( !StringUtils.isEmpty(currentLaF) ) {
191 203
                DefaultComboBoxModel<ListElement<LookAndFeelInfo>> model = (DefaultComboBoxModel<ListElement<LookAndFeelInfo>>) this.cboLookAndFeel.getModel();
192 204
                for( int i=0; i<model.getSize() ; i++ ) {
193 205
                    ListElement<LookAndFeelInfo> element = model.getElementAt(i);
194
                    if( defaultLookAndFeel.equals(element.getValue().getClassName()) ) {
206
                    if( currentLaF.equals(element.getValue().getClassName()) ) {
195 207
                        this.cboLookAndFeel.setSelectedIndex(i);
196 208
                        break;
197 209
                    }
......
202 214
            this.cboLookAndFeel.setEnabled(false);
203 215
        }
204 216
    }
217
    
218
    private String getCurrentLookAndFeel() {
219
        String s = Launcher.getAndamiConfig().getLookAndFeel();
220
        if( StringUtils.isBlank(s) ) {
221
            s = defaultLookAndFeel;
222
        }
223
        return s;
224
    }
205 225

  
206 226
    @Override
207 227
    public String getID() {
......
255 275
        if( !changed ) {
256 276
            changed = this.chkUseNativeFileChooser.isSelected() != ToolsUtilLocator.getFileDialogChooserManager().useNativeFileChooser();
257 277
        }
258
        if( changed ) {
278
        if( !changed ) {
259 279
            if( this.cboLookAndFeel.isEnabled() ) {
260 280
               ListElement<LookAndFeelInfo> element = (ListElement<LookAndFeelInfo>) this.cboLookAndFeel.getSelectedItem();
261 281
               if( element!=null ) {
262
                   changed = element.getValue().getClassName().equalsIgnoreCase(defaultLookAndFeel);
282
                   changed = !element.getValue().getClassName().equalsIgnoreCase(getCurrentLookAndFeel());
263 283
               }
264 284
            }
265 285
        }

Also available in: Unified diff