svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / BookmarkList.java @ 2312
History | View | Annotate | Download (5.51 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 |
|
67 |
public BookmarkList(CQApp mainApp) {
|
68 |
app = mainApp; |
69 |
loadList(); |
70 |
} |
71 |
|
72 |
public void loadList() { |
73 |
} |
74 |
|
75 |
public void addEntry(String fld, String n, String f, IProjection p) { |
76 |
addEntry(new Bookmark(fld, n, f, p));
|
77 |
} |
78 |
|
79 |
public void addEntry(String fld, String n, String [] f, IProjection p) { |
80 |
addEntry(new Bookmark(fld, n, f, p));
|
81 |
} |
82 |
|
83 |
public void addEntry(Bookmark bookmark) { |
84 |
Vector vector;
|
85 |
if (containsKey(bookmark.folder)) {
|
86 |
vector = (Vector) get(bookmark.folder);
|
87 |
} else {
|
88 |
vector = new Vector(); |
89 |
} |
90 |
vector.add(bookmark); |
91 |
put(bookmark.folder, vector); |
92 |
} |
93 |
|
94 |
public JMenu getJMenu() { |
95 |
JMenuItem it = null; |
96 |
JMenu menu = null, menu2 = null; |
97 |
ClassLoader loader = this.getClass().getClassLoader(); |
98 |
//loader.getResource("images/"+"folderXP.gif");
|
99 |
//System.err.println("URL="+loader.getResource("images/"+"folderXP.gif"));
|
100 |
ImageIcon folderIcon = new ImageIcon(loader.getResource("images/"+"folderXP.gif")); |
101 |
ImageIcon dxfIcon = new ImageIcon(loader.getResource("images/"+"fileXPdxf.gif")); |
102 |
ImageIcon gmlIcon = new ImageIcon(loader.getResource("images/"+"fileXPgml.gif")); |
103 |
ImageIcon ecwIcon = new ImageIcon(loader.getResource("images/"+"fileXPecw.gif")); |
104 |
ImageIcon tifIcon = new ImageIcon(loader.getResource("images/"+"fileXPtif.gif")); |
105 |
ImageIcon fileIcon = new ImageIcon(loader.getResource("images/"+"fileXP.gif")); |
106 |
|
107 |
menu = new JMenu("Favoritos"); |
108 |
menu.setMnemonic('F');
|
109 |
|
110 |
// Arbol de carpetas
|
111 |
TreeMap menuMap = new TreeMap(); |
112 |
String [] menuNames; |
113 |
JMenu parentMenu = null; |
114 |
String mName = null, key = null;; |
115 |
|
116 |
Iterator mIter = keySet().iterator();
|
117 |
while (mIter.hasNext()) {
|
118 |
key = (String) mIter.next();
|
119 |
System.out.println("Key:"+key); |
120 |
menuNames = key.split("\\|");
|
121 |
|
122 |
parentMenu = menu; |
123 |
mName = "";
|
124 |
for (int i=0; i<menuNames.length; i++) { |
125 |
if (i>0) mName += "|"; |
126 |
mName += menuNames[i]; |
127 |
if (menuMap.containsKey(mName)) {
|
128 |
//System.out.println(" mName:"+mName+", parent:"+parentMenu.getText());
|
129 |
parentMenu = (JMenu) menuMap.get(mName);
|
130 |
} else {
|
131 |
//System.out.println("+mName:"+mName+", parent:"+parentMenu.getText());
|
132 |
menu2 = new JMenu(menuNames[i]); |
133 |
menu2.setIcon(folderIcon); |
134 |
parentMenu.add(menu2); |
135 |
menuMap.put(mName, menu2); |
136 |
parentMenu = menu2; |
137 |
} |
138 |
} |
139 |
} |
140 |
|
141 |
// Entradas (Bookmarks)
|
142 |
mIter = entrySet().iterator(); |
143 |
while (mIter.hasNext()) {
|
144 |
Map.Entry entry = (Map.Entry) mIter.next(); |
145 |
String folder = (String) entry.getKey(); |
146 |
|
147 |
/*menu2 = new JMenu(folder);
|
148 |
menu2.setIcon(folderIcon);
|
149 |
menu.add(menu2);*/
|
150 |
menu2 = (JMenu) menuMap.get(folder);
|
151 |
|
152 |
Vector vector = ((Vector) entry.getValue()); |
153 |
Bookmark bookmark; |
154 |
for (int i=0; i<vector.size(); i++) { |
155 |
bookmark = (Bookmark) vector.get(i); |
156 |
it = new JMenuItem(bookmark.name); |
157 |
it.setActionCommand(i+"|"+folder);
|
158 |
it.addActionListener(this);
|
159 |
if (bookmark.fName[0].endsWith("tif")) |
160 |
it.setIcon(tifIcon); |
161 |
else if (bookmark.fName[0].endsWith("ecw")) |
162 |
it.setIcon(ecwIcon); |
163 |
else if (bookmark.fName[0].endsWith("gml")) |
164 |
it.setIcon(gmlIcon); |
165 |
else if (bookmark.fName[0].endsWith("dxf") || bookmark.fName[0].endsWith("DXF")) |
166 |
it.setIcon(dxfIcon); |
167 |
else
|
168 |
it.setIcon(fileIcon); |
169 |
|
170 |
menu2.add(it); |
171 |
} |
172 |
} |
173 |
//menu.add(menu2);
|
174 |
return menu;
|
175 |
} |
176 |
|
177 |
public void actionPerformed(ActionEvent event) { |
178 |
IProjection proj = null;
|
179 |
String cmd = event.getActionCommand();
|
180 |
int mark = cmd.indexOf('|'); |
181 |
int vectorPos = Integer.parseInt(cmd.substring(0,mark)); |
182 |
cmd = cmd.substring(mark+1);
|
183 |
Bookmark bookmark = (Bookmark) ((Vector) get(cmd)).get(vectorPos);
|
184 |
if (bookmark.fName.length == 1) |
185 |
app.loadFile(bookmark.fName[0], bookmark.proj);
|
186 |
else
|
187 |
app.loadFile(bookmark.fName, bookmark.proj); |
188 |
} |
189 |
} |
190 |
|