Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / BookmarkList.java @ 109

History | View | Annotate | Download (4.2 KB)

1
/*
2
 * Creado el 31-ago-2004
3
 */
4
package org.cresques.io;
5

    
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
8
import java.util.Iterator;
9
import java.util.Map;
10
import java.util.TreeMap;
11
import java.util.Vector;
12

    
13
import javax.swing.ImageIcon;
14
import javax.swing.JMenu;
15
import javax.swing.JMenuItem;
16

    
17
import org.cresques.cts.IProjection;
18
import org.cresques.ui.CQApp;
19

    
20
/**
21
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
22
 */
23
class Bookmark {
24
        String folder;
25
        String name;
26
        String fName;
27
        String projName;
28
        IProjection proj;
29
        
30
        public Bookmark(String fld, String n, String f, IProjection p) {
31
                projName = null;
32
                folder = fld; name = n; fName = f; proj = p;
33
        }
34
}
35

    
36
public class BookmarkList extends TreeMap implements ActionListener {
37
        CQApp app = null;
38
        
39
        public BookmarkList(CQApp mainApp) {
40
                app = mainApp;
41
                loadList();
42
        }
43
        
44
        public void loadList() {
45
        }
46
        
47
        public void addEntry(String fld, String n, String f, IProjection p) {
48
                addEntry(new Bookmark(fld, n, f, p));
49
        }
50
        
51
        public void addEntry(Bookmark bookmark) {
52
                Vector vector;
53
                if (containsKey(bookmark.folder)) {
54
                        vector = (Vector) get(bookmark.folder);
55
                } else {
56
                        vector = new Vector();
57
                }
58
                vector.add(bookmark);
59
                put(bookmark.folder, vector);
60
        }
61
        
62
        public JMenu getJMenu() {
63
                JMenuItem it = null;
64
                JMenu menu = null, menu2 = null;
65
                ClassLoader loader = this.getClass().getClassLoader();
66
                //loader.getResource("images/"+"folderXP.gif");
67
                //System.err.println("URL="+loader.getResource("images/"+"folderXP.gif"));
68
                ImageIcon folderIcon = new ImageIcon(loader.getResource("images/"+"folderXP.gif"));
69
                ImageIcon dxfIcon = new ImageIcon(loader.getResource("images/"+"fileXPdxf.gif"));
70
                ImageIcon gmlIcon = new ImageIcon(loader.getResource("images/"+"fileXPgml.gif"));
71
                ImageIcon ecwIcon = new ImageIcon(loader.getResource("images/"+"fileXPecw.gif"));
72
                ImageIcon tifIcon = new ImageIcon(loader.getResource("images/"+"fileXPtif.gif"));
73
                ImageIcon fileIcon = new ImageIcon(loader.getResource("images/"+"fileXP.gif"));
74
                
75
                menu = new JMenu("Favoritos");
76
                menu.setMnemonic('F');
77
                
78
                // Arbol de carpetas
79
                TreeMap menuMap = new TreeMap();
80
                String [] menuNames;
81
                JMenu parentMenu = null;
82
                String mName = null, key = null;;
83

    
84
                Iterator mIter = keySet().iterator();
85
                while (mIter.hasNext()) {
86
                        key = (String) mIter.next();
87
                        System.out.println("Key:"+key);
88
                        menuNames = key.split("\\|");
89
                        
90
                        parentMenu = menu;
91
                        mName = "";
92
                        for (int i=0; i<menuNames.length; i++) {
93
                                if (i>0) mName += "|";
94
                                mName += menuNames[i];
95
                                if (menuMap.containsKey(mName)) {
96
                                        //System.out.println(" mName:"+mName+", parent:"+parentMenu.getText());
97
                                        parentMenu = (JMenu) menuMap.get(mName);
98
                                } else {
99
                                        //System.out.println("+mName:"+mName+", parent:"+parentMenu.getText());
100
                                        menu2 = new JMenu(menuNames[i]);
101
                                        menu2.setIcon(folderIcon);
102
                                        parentMenu.add(menu2);
103
                                        menuMap.put(mName, menu2);
104
                                        parentMenu = menu2;
105
                                }
106
                        }
107
                }
108
                
109
                // Entradas (Bookmarks)
110
                mIter = entrySet().iterator();
111
                while (mIter.hasNext()) {
112
                        Map.Entry entry = (Map.Entry) mIter.next();
113
                        String folder = (String) entry.getKey();
114
                        
115
                        /*menu2 = new JMenu(folder);
116
                        menu2.setIcon(folderIcon);
117
                        menu.add(menu2);*/
118
                        menu2 = (JMenu) menuMap.get(folder);
119

    
120
                        Vector vector = ((Vector) entry.getValue());
121
                        Bookmark bookmark;
122
                        for (int i=0; i<vector.size(); i++) {
123
                                bookmark = (Bookmark) vector.get(i);
124
                                it = new JMenuItem(bookmark.name);
125
                                it.setActionCommand(i+"|"+folder);
126
                                it.addActionListener(this);
127
                                if (bookmark.fName.endsWith("tif"))
128
                                        it.setIcon(tifIcon);
129
                                else if (bookmark.fName.endsWith("ecw"))
130
                                        it.setIcon(ecwIcon);
131
                                else if (bookmark.fName.endsWith("gml"))
132
                                        it.setIcon(gmlIcon);
133
                                else if (bookmark.fName.endsWith("dxf") || bookmark.fName.endsWith("DXF"))
134
                                        it.setIcon(dxfIcon);
135
                                else
136
                                        it.setIcon(fileIcon);
137

    
138
                                menu2.add(it);
139
                        }
140
                }
141
                //menu.add(menu2);
142
                return menu;
143
        }
144
        
145
        public void actionPerformed(ActionEvent event) {
146
                IProjection proj = null;
147
                String cmd = event.getActionCommand();
148
                int mark = cmd.indexOf('|');
149
                int vectorPos = Integer.parseInt(cmd.substring(0,mark));
150
                cmd = cmd.substring(mark+1);
151
                Bookmark bookmark = (Bookmark) ((Vector) get(cmd)).get(vectorPos);
152
                app.loadFile(bookmark.fName, bookmark.proj);
153
        }
154
}
155