root / tags / Root_CqCMSGisPlanet / libraries / libCq CMS for java.old / src / org / cresques / io / BookmarkList.java @ 1933
History | View | Annotate | Download (4.66 KB)
1 | 109 | luisw | /*
|
---|---|---|---|
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 | 210 | luisw | String [] fName; |
27 | 109 | luisw | String projName;
|
28 | IProjection proj; |
||
29 | |||
30 | public Bookmark(String fld, String n, String f, IProjection p) { |
||
31 | projName = null;
|
||
32 | 210 | luisw | fName = new String[1]; |
33 | folder = fld; name = n; fName[0] = f; proj = p;
|
||
34 | 109 | luisw | } |
35 | 210 | luisw | public Bookmark(String fld, String n, String [] f, IProjection p) { |
36 | projName = null;
|
||
37 | fName = new String[f.length]; |
||
38 | folder = fld; name = n; proj = p; |
||
39 | for (int i=0; i<f.length; i++) |
||
40 | fName[i] = f[i]; |
||
41 | } |
||
42 | 109 | luisw | } |
43 | |||
44 | public class BookmarkList extends TreeMap implements ActionListener { |
||
45 | CQApp app = null;
|
||
46 | |||
47 | public BookmarkList(CQApp mainApp) {
|
||
48 | app = mainApp; |
||
49 | loadList(); |
||
50 | } |
||
51 | |||
52 | public void loadList() { |
||
53 | } |
||
54 | |||
55 | public void addEntry(String fld, String n, String f, IProjection p) { |
||
56 | addEntry(new Bookmark(fld, n, f, p));
|
||
57 | } |
||
58 | |||
59 | 210 | luisw | public void addEntry(String fld, String n, String [] f, IProjection p) { |
60 | addEntry(new Bookmark(fld, n, f, p));
|
||
61 | } |
||
62 | |||
63 | 109 | luisw | public void addEntry(Bookmark bookmark) { |
64 | Vector vector;
|
||
65 | if (containsKey(bookmark.folder)) {
|
||
66 | vector = (Vector) get(bookmark.folder);
|
||
67 | } else {
|
||
68 | vector = new Vector(); |
||
69 | } |
||
70 | vector.add(bookmark); |
||
71 | put(bookmark.folder, vector); |
||
72 | } |
||
73 | |||
74 | public JMenu getJMenu() { |
||
75 | JMenuItem it = null; |
||
76 | JMenu menu = null, menu2 = null; |
||
77 | ClassLoader loader = this.getClass().getClassLoader(); |
||
78 | //loader.getResource("images/"+"folderXP.gif");
|
||
79 | //System.err.println("URL="+loader.getResource("images/"+"folderXP.gif"));
|
||
80 | ImageIcon folderIcon = new ImageIcon(loader.getResource("images/"+"folderXP.gif")); |
||
81 | ImageIcon dxfIcon = new ImageIcon(loader.getResource("images/"+"fileXPdxf.gif")); |
||
82 | ImageIcon gmlIcon = new ImageIcon(loader.getResource("images/"+"fileXPgml.gif")); |
||
83 | ImageIcon ecwIcon = new ImageIcon(loader.getResource("images/"+"fileXPecw.gif")); |
||
84 | ImageIcon tifIcon = new ImageIcon(loader.getResource("images/"+"fileXPtif.gif")); |
||
85 | ImageIcon fileIcon = new ImageIcon(loader.getResource("images/"+"fileXP.gif")); |
||
86 | |||
87 | menu = new JMenu("Favoritos"); |
||
88 | menu.setMnemonic('F');
|
||
89 | |||
90 | // Arbol de carpetas
|
||
91 | TreeMap menuMap = new TreeMap(); |
||
92 | String [] menuNames; |
||
93 | JMenu parentMenu = null; |
||
94 | String mName = null, key = null;; |
||
95 | |||
96 | Iterator mIter = keySet().iterator();
|
||
97 | while (mIter.hasNext()) {
|
||
98 | key = (String) mIter.next();
|
||
99 | System.out.println("Key:"+key); |
||
100 | menuNames = key.split("\\|");
|
||
101 | |||
102 | parentMenu = menu; |
||
103 | mName = "";
|
||
104 | for (int i=0; i<menuNames.length; i++) { |
||
105 | if (i>0) mName += "|"; |
||
106 | mName += menuNames[i]; |
||
107 | if (menuMap.containsKey(mName)) {
|
||
108 | //System.out.println(" mName:"+mName+", parent:"+parentMenu.getText());
|
||
109 | parentMenu = (JMenu) menuMap.get(mName);
|
||
110 | } else {
|
||
111 | //System.out.println("+mName:"+mName+", parent:"+parentMenu.getText());
|
||
112 | menu2 = new JMenu(menuNames[i]); |
||
113 | menu2.setIcon(folderIcon); |
||
114 | parentMenu.add(menu2); |
||
115 | menuMap.put(mName, menu2); |
||
116 | parentMenu = menu2; |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 | |||
121 | // Entradas (Bookmarks)
|
||
122 | mIter = entrySet().iterator(); |
||
123 | while (mIter.hasNext()) {
|
||
124 | Map.Entry entry = (Map.Entry) mIter.next(); |
||
125 | String folder = (String) entry.getKey(); |
||
126 | |||
127 | /*menu2 = new JMenu(folder);
|
||
128 | menu2.setIcon(folderIcon);
|
||
129 | menu.add(menu2);*/
|
||
130 | menu2 = (JMenu) menuMap.get(folder);
|
||
131 | |||
132 | Vector vector = ((Vector) entry.getValue()); |
||
133 | Bookmark bookmark; |
||
134 | for (int i=0; i<vector.size(); i++) { |
||
135 | bookmark = (Bookmark) vector.get(i); |
||
136 | it = new JMenuItem(bookmark.name); |
||
137 | it.setActionCommand(i+"|"+folder);
|
||
138 | it.addActionListener(this);
|
||
139 | 210 | luisw | if (bookmark.fName[0].endsWith("tif")) |
140 | 109 | luisw | it.setIcon(tifIcon); |
141 | 210 | luisw | else if (bookmark.fName[0].endsWith("ecw")) |
142 | 109 | luisw | it.setIcon(ecwIcon); |
143 | 210 | luisw | else if (bookmark.fName[0].endsWith("gml")) |
144 | 109 | luisw | it.setIcon(gmlIcon); |
145 | 210 | luisw | else if (bookmark.fName[0].endsWith("dxf") || bookmark.fName[0].endsWith("DXF")) |
146 | 109 | luisw | it.setIcon(dxfIcon); |
147 | else
|
||
148 | it.setIcon(fileIcon); |
||
149 | |||
150 | menu2.add(it); |
||
151 | } |
||
152 | } |
||
153 | //menu.add(menu2);
|
||
154 | return menu;
|
||
155 | } |
||
156 | |||
157 | public void actionPerformed(ActionEvent event) { |
||
158 | IProjection proj = null;
|
||
159 | String cmd = event.getActionCommand();
|
||
160 | int mark = cmd.indexOf('|'); |
||
161 | int vectorPos = Integer.parseInt(cmd.substring(0,mark)); |
||
162 | cmd = cmd.substring(mark+1);
|
||
163 | Bookmark bookmark = (Bookmark) ((Vector) get(cmd)).get(vectorPos);
|
||
164 | 1345 | luisw | if (bookmark.fName.length == 1) |
165 | app.loadFile(bookmark.fName[0], bookmark.proj);
|
||
166 | else
|
||
167 | app.loadFile(bookmark.fName, bookmark.proj); |
||
168 | 109 | luisw | } |
169 | } |