Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / BookmarkList.java @ 2664

History | View | Annotate | Download (5.57 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
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 2
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, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 * 
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25

    
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28
import java.util.Iterator;
29
import java.util.Map;
30
import java.util.TreeMap;
31
import java.util.Vector;
32

    
33
import javax.swing.ImageIcon;
34
import javax.swing.JMenu;
35
import javax.swing.JMenuItem;
36

    
37
import org.cresques.cts.IProjection;
38
import org.cresques.ui.CQApp;
39

    
40
/**
41
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
42
 */
43
class Bookmark {
44
        String folder;
45
        String name;
46
        String [] fName;
47
        String projName;
48
        IProjection proj;
49
        
50
        public Bookmark(String fld, String n, String f, IProjection p) {
51
                projName = null;
52
                fName = new String[1];
53
                folder = fld; name = n; fName[0] = f; proj = p;
54
        }
55
        public Bookmark(String fld, String n, String [] f, IProjection p) {
56
                projName = null;
57
                fName = new String[f.length];
58
                folder = fld; name = n; proj = p;
59
                for (int i=0; i<f.length; i++)
60
                        fName[i] = f[i];
61
        }
62
}
63

    
64
public class BookmarkList extends TreeMap implements ActionListener {
65
        CQApp app = null;
66
        final private static long serialVersionUID = -3370601314380922368L;
67
        
68
        public BookmarkList(CQApp mainApp) {
69
                app = mainApp;
70
                loadList();
71
        }
72
        
73
        public void loadList() {
74
        }
75
        
76
        public void addEntry(String fld, String n, String f, IProjection p) {
77
                addEntry(new Bookmark(fld, n, f, p));
78
        }
79
        
80
        public void addEntry(String fld, String n, String [] f, IProjection p) {
81
                addEntry(new Bookmark(fld, n, f, p));
82
        }
83
        
84
        public void addEntry(Bookmark bookmark) {
85
                Vector vector;
86
                if (containsKey(bookmark.folder)) {
87
                        vector = (Vector) get(bookmark.folder);
88
                } else {
89
                        vector = new Vector();
90
                }
91
                vector.add(bookmark);
92
                put(bookmark.folder, vector);
93
        }
94
        
95
        public JMenu getJMenu() {
96
                JMenuItem it = null;
97
                JMenu menu = null, menu2 = null;
98
                ClassLoader loader = this.getClass().getClassLoader();
99
                //loader.getResource("images/"+"folderXP.gif");
100
                //System.err.println("URL="+loader.getResource("images/"+"folderXP.gif"));
101
                ImageIcon folderIcon = new ImageIcon(loader.getResource("images/"+"folderXP.gif"));
102
                ImageIcon dxfIcon = new ImageIcon(loader.getResource("images/"+"fileXPdxf.gif"));
103
                ImageIcon gmlIcon = new ImageIcon(loader.getResource("images/"+"fileXPgml.gif"));
104
                ImageIcon ecwIcon = new ImageIcon(loader.getResource("images/"+"fileXPecw.gif"));
105
                ImageIcon tifIcon = new ImageIcon(loader.getResource("images/"+"fileXPtif.gif"));
106
                ImageIcon fileIcon = new ImageIcon(loader.getResource("images/"+"fileXP.gif"));
107
                
108
                menu = new JMenu("Favoritos");
109
                menu.setMnemonic('F');
110
                
111
                // Arbol de carpetas
112
                TreeMap menuMap = new TreeMap();
113
                String [] menuNames;
114
                JMenu parentMenu = null;
115
                String mName = null, key = null;;
116

    
117
                Iterator mIter = keySet().iterator();
118
                while (mIter.hasNext()) {
119
                        key = (String) mIter.next();
120
                        System.out.println("Key:"+key);
121
                        menuNames = key.split("\\|");
122
                        
123
                        parentMenu = menu;
124
                        mName = "";
125
                        for (int i=0; i<menuNames.length; i++) {
126
                                if (i>0) mName += "|";
127
                                mName += menuNames[i];
128
                                if (menuMap.containsKey(mName)) {
129
                                        //System.out.println(" mName:"+mName+", parent:"+parentMenu.getText());
130
                                        parentMenu = (JMenu) menuMap.get(mName);
131
                                } else {
132
                                        //System.out.println("+mName:"+mName+", parent:"+parentMenu.getText());
133
                                        menu2 = new JMenu(menuNames[i]);
134
                                        menu2.setIcon(folderIcon);
135
                                        parentMenu.add(menu2);
136
                                        menuMap.put(mName, menu2);
137
                                        parentMenu = menu2;
138
                                }
139
                        }
140
                }
141
                
142
                // Entradas (Bookmarks)
143
                mIter = entrySet().iterator();
144
                while (mIter.hasNext()) {
145
                        Map.Entry entry = (Map.Entry) mIter.next();
146
                        String folder = (String) entry.getKey();
147
                        
148
                        /*menu2 = new JMenu(folder);
149
                        menu2.setIcon(folderIcon);
150
                        menu.add(menu2);*/
151
                        menu2 = (JMenu) menuMap.get(folder);
152

    
153
                        Vector vector = ((Vector) entry.getValue());
154
                        Bookmark bookmark;
155
                        for (int i=0; i<vector.size(); i++) {
156
                                bookmark = (Bookmark) vector.get(i);
157
                                it = new JMenuItem(bookmark.name);
158
                                it.setActionCommand(i+"|"+folder);
159
                                it.addActionListener(this);
160
                                if (bookmark.fName[0].endsWith("tif"))
161
                                        it.setIcon(tifIcon);
162
                                else if (bookmark.fName[0].endsWith("ecw"))
163
                                        it.setIcon(ecwIcon);
164
                                else if (bookmark.fName[0].endsWith("gml"))
165
                                        it.setIcon(gmlIcon);
166
                                else if (bookmark.fName[0].endsWith("dxf") || bookmark.fName[0].endsWith("DXF"))
167
                                        it.setIcon(dxfIcon);
168
                                else
169
                                        it.setIcon(fileIcon);
170

    
171
                                menu2.add(it);
172
                        }
173
                }
174
                //menu.add(menu2);
175
                return menu;
176
        }
177
        
178
        public void actionPerformed(ActionEvent event) {
179
                IProjection proj = null;
180
                String cmd = event.getActionCommand();
181
                int mark = cmd.indexOf('|');
182
                int vectorPos = Integer.parseInt(cmd.substring(0,mark));
183
                cmd = cmd.substring(mark+1);
184
                Bookmark bookmark = (Bookmark) ((Vector) get(cmd)).get(vectorPos);
185
                if (bookmark.fName.length == 1)
186
                        app.loadFile(bookmark.fName[0], bookmark.proj);
187
                else
188
                        app.loadFile(bookmark.fName, bookmark.proj);
189
        }
190
}
191