Statistics
| Revision:

root / trunk / extensions / extQuickInfo / src-test / org / gvsig / quickInfo / TestQuickInfoToolTipText.java @ 28223

History | View | Annotate | Download (3.48 KB)

1
package org.gvsig.quickInfo;
2

    
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

    
25
import java.awt.Dimension;
26
import java.util.Arrays;
27
import java.util.HashMap;
28
import java.util.Vector;
29

    
30
import javax.swing.JButton;
31
import javax.swing.JFrame;
32
import javax.swing.JOptionPane;
33
import javax.swing.JPanel;
34

    
35
import org.gvsig.quickInfo.i18n.Messages;
36
import org.gvsig.quickInfo.utils.xml.XML_DOM_Utilities;
37
import org.w3c.dom.Document;
38

    
39
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
40

    
41
/**
42
 * <p>Tests the creation of tool tip text according the style of the "quick information" tool.</p>
43
 * 
44
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
45
 */
46
public class TestQuickInfoToolTipText {
47
        public static void main(String args[]) {
48
                try {
49
                        FLyrVect v = new FLyrVect();
50
                        v.setName("CAPA VECTORIAL");
51
                        
52
                        QuickInfoFLayerSelected info = new QuickInfoFLayerSelected(v);
53
                        HashMap lfields = info.getLayerFields();
54
                        lfields.put("Campo1", new Vector(Arrays.asList(new String[]{"texto 1", "texto 4"})));
55
                        lfields.put("Campo2", new Vector(Arrays.asList(new String[]{"texto 2", "texto 5"})));
56
                        lfields.put("Campo3", new Vector(Arrays.asList(new String[]{"texto 3", "texto 6"})));
57
                        info.setAnyLayerFieldAdded(true);
58
                        
59
                        HashMap clfields = info.getCalculatedLayerFields();
60
                        
61
                        clfields.put("CampoOp1", new Vector(Arrays.asList(new String[]{"texto 7", "texto 9"})));
62
                        clfields.put("CampoOp2", new Vector(Arrays.asList(new String[]{"texto 8", "texto 10"})));
63
                        info.getGeometryIDs().addAll(Arrays.asList(new GeometryIDInfo[]{new GeometryIDInfo("GID1"), new GeometryIDInfo("GID2"), new GeometryIDInfo("GID3", false)}));
64
                        info.setAnyCalculatedLayerFieldsAdded(true);
65
                        String text = XML_DOM_Utilities.write_DOM_into_an_String(info.getToolTipStyledDocument(), "xsl/quick_information.xsl");
66

    
67
                        JFrame jFrame = new JFrame();
68
                        JButton jButton = new JButton("Bot?n 1: con datos almacenados.");
69
                        jButton.setToolTipText(text);
70
                        
71
                        JButton jButton2 = new JButton("Bot?n 2: desde fichero.");
72
                        Document d2 = XML_DOM_Utilities.parse_XML_file_and_create_DOM("xml/quick_information_sample.xml");
73
                        text = XML_DOM_Utilities.write_DOM_into_an_String(d2, "xsl/quick_information.xsl");
74
                        jButton2.setToolTipText(text);
75

    
76
                        JPanel panel = new JPanel();
77
                        panel.add(jButton);
78
                        panel.add(jButton2);
79

    
80
                        jFrame.getContentPane().add(panel);
81
                        jFrame.setPreferredSize(new Dimension(250, 100));
82
                        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
83
                        jFrame.pack();
84
                        jFrame.setVisible(true);
85
                } catch(Exception e) {
86
                        e.printStackTrace();
87
                        JOptionPane.showMessageDialog(null, Messages.getText("An_exception_happened"), Messages.getText("Error"), JOptionPane.ERROR_MESSAGE);
88
                }
89
        }
90
}