Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.xml2db / org.gvsig.xml2db.swing / org.gvsig.xml2db.swing.impl / src / main / java / org / gvsig / xml2db / swing / impl / Xml2dbSwingCommons.java @ 47607

History | View | Annotate | Download (4.19 KB)

1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2023 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22

    
23
package org.gvsig.xml2db.swing.impl;
24

    
25
import java.awt.Color;
26
import java.awt.Component;
27
import java.awt.Font;
28
import java.awt.font.TextAttribute;
29
import java.util.Map;
30
import javax.swing.ComboBoxModel;
31
import javax.swing.DefaultComboBoxModel;
32
import org.apache.commons.lang3.StringUtils;
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataFactory;
35
import org.gvsig.fmap.dal.PersonalDatabaseServerExplorerFactory;
36
import org.gvsig.fmap.dal.feature.FeatureStore;
37
import org.gvsig.tools.util.LabeledValue;
38
import org.gvsig.tools.util.LabeledValueImpl;
39
import org.slf4j.LoggerFactory;
40

    
41
/**
42
 *
43
 * @author gvSIG Team
44
 */
45
public class Xml2dbSwingCommons {
46
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Xml2dbSwingCommons.class);
47

    
48
    
49
    public static String getHTMLColorTag(Color color, String text) {
50
        return getHTMLColorTag(color, false, text);
51
    }
52
    
53
    public static String getHTMLColorTag(Color color, boolean bold, String text) {
54
        return getHTMLColorTag(color, bold, false, text);
55
    }
56
    
57
    public static String getHTMLColorTag(Color color, boolean bold, boolean strikethrough, String text) {
58
        String pattern;
59
        if( bold && strikethrough ) {
60
            pattern = "<html><font color='rgb(%s, %s, %s)'><i><s>%s</i></s></font></html>";
61
        } else if( bold ) {
62
            pattern = "<html><font color='rgb(%s, %s, %s)'><i>%s</i></font></html>";
63
        } else if( strikethrough ) {
64
                pattern = "<html><font color='rgb(%s, %s, %s)'><s>%s</s></font></html>";            
65
        } else {
66
            pattern = "<html><font color='rgb(%s, %s, %s)'>%s</font></html>";
67
        }
68
        String tag = String.format(pattern, 
69
            color.getRed(),
70
            color.getGreen(),
71
            color.getBlue(),
72
            text
73
        );
74
        return tag;
75
    }
76
    
77
    public static void setColorCompoment(Component c, Color color, boolean bold) {
78
        setColorCompoment(c, color, bold, false);
79
    }
80
    
81
    public static void setColorCompoment(Component c, Color color, boolean bold, boolean strikethrough) {
82
        if( bold ) {
83
            Font f = c.getFont();
84
            Map attributes = f.getAttributes();
85
            attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
86
            c.setFont(c.getFont().deriveFont(attributes));
87
        }
88
        c.setForeground(color);
89
    }
90

    
91
    public static ComboBoxModel<LabeledValue<PersonalDatabaseServerExplorerFactory>> getPersonalDatabaseServerExplorersComboModel() {
92
        DefaultComboBoxModel<LabeledValue<PersonalDatabaseServerExplorerFactory>> model = new DefaultComboBoxModel<>();
93
        for (DataFactory explorerFactory : DALLocator.getDataManager().getServerExplorerRegister()) {
94
            if( explorerFactory instanceof PersonalDatabaseServerExplorerFactory ) {
95
                LabeledValueImpl<PersonalDatabaseServerExplorerFactory> element = new LabeledValueImpl<>(
96
                        explorerFactory.getDescription(), 
97
                        (PersonalDatabaseServerExplorerFactory) explorerFactory
98
                );
99
                model.addElement(element);
100
                if( StringUtils.equalsIgnoreCase(explorerFactory.getName(), FeatureStore.H2SPATIAL_PROVIDER_NAME)) {
101
                    model.setSelectedItem(element);
102
                }
103
            }            
104
        }
105
        return model;
106
    }
107
}