Revision 1987
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/bookmarkshistory/DefaultHistoryController.java | ||
---|---|---|
30 | 30 |
* @author jjdelcerro |
31 | 31 |
*/ |
32 | 32 |
public class DefaultHistoryController<T> extends DefaultActionListenerSupport implements HistoryController<T> { |
33 |
public class HistoryEventImpl<T> extends ActionEvent implements HistoryEvent<T> { |
|
33 | 34 |
|
35 |
private T currentValue; |
|
36 |
|
|
37 |
public HistoryEventImpl(Object source, int id, String command) { |
|
38 |
super(source, id, command); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public void setCurrentValue(T value) { |
|
43 |
this.currentValue = value; |
|
44 |
} |
|
45 |
|
|
46 |
public T getCurrentValue() { |
|
47 |
return this.currentValue; |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
|
|
34 | 53 |
public static void selfRegister() { |
35 |
URL imageResource = DatePickerControllerImpl.class.getClassLoader().getResource("org/gvsig/tools/swing/bookmarkandhistory/history.png"); |
|
54 |
URL imageResource = DatePickerControllerImpl.class.getClassLoader().getResource("org/gvsig/tools/swing/bookmarkandhistory/history-clock.png");
|
|
36 | 55 |
if (imageResource != null) { |
37 | 56 |
IconThemeManager iconThemeManager = ToolsSwingLocator.getIconThemeManager(); |
38 | 57 |
IconTheme theme = iconThemeManager.getCurrent(); |
39 | 58 |
ImageIcon icon = new ImageIcon(imageResource); |
40 |
theme.registerDefault("tools", "bookmarkandhistory", "history", icon, imageResource); |
|
59 |
theme.registerDefault("tools", "bookmarkandhistory", "history-clock", icon, imageResource);
|
|
41 | 60 |
}} |
42 | 61 |
|
43 | 62 |
private final JButton button; |
... | ... | |
51 | 70 |
this.button = button; |
52 | 71 |
if (this.button != null) { |
53 | 72 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
54 |
this.button.setIcon(iconTheme.get("history")); |
|
73 |
this.button.setIcon(iconTheme.get("history-clock"));
|
|
55 | 74 |
this.button.addActionListener(new ActionListener() { |
56 | 75 |
@Override |
57 | 76 |
public void actionPerformed(ActionEvent e) { |
... | ... | |
94 | 113 |
item.addActionListener(new ActionListener() { |
95 | 114 |
@Override |
96 | 115 |
public void actionPerformed(ActionEvent e) { |
97 |
ActionEvent event = new ActionEvent(value, 1, "set-value"); |
|
116 |
HistoryEventImpl event = new HistoryEventImpl(this, HistoryController.ID_SETVALUE, "set-value"); |
|
117 |
event.setCurrentValue(value); |
|
98 | 118 |
DefaultHistoryController.this.fireActionEvent(event); |
99 | 119 |
} |
100 | 120 |
}); |
... | ... | |
118 | 138 |
} |
119 | 139 |
T currentValue = panel.getSelectedValue(); |
120 | 140 |
if (currentValue != null) { |
121 |
ActionEvent event = new ActionEvent(currentValue, 1, "set-value"); |
|
141 |
HistoryEventImpl event = new HistoryEventImpl(this, HistoryController.ID_SETVALUE, "set-value"); |
|
142 |
event.setCurrentValue(currentValue); |
|
122 | 143 |
DefaultHistoryController.this.fireActionEvent(event); |
123 | 144 |
// updateValue((T) bookmark.getValue()); |
124 | 145 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/bookmarkshistory/DefaultBookmarksPanel.java | ||
---|---|---|
112 | 112 |
} |
113 | 113 |
|
114 | 114 |
private BookmarkListModel createBookmarksModel() { |
115 |
//Bookmarks bookmarks = ExpressionEvaluatorLocator.getManager().getBookmarks(); |
|
116 | 115 |
BookmarkListModel model = new BookmarkListModel(); |
117 | 116 |
for (Object bookmark : bookmarks) { |
118 |
model.addElement((Bookmark) bookmark); //TODO cast?
|
|
117 |
model.addElement((Bookmark) bookmark); |
|
119 | 118 |
} |
120 | 119 |
return model; |
121 | 120 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/bookmarkshistory/DefaultBookmarksController.java | ||
---|---|---|
77 | 77 |
}); |
78 | 78 |
} |
79 | 79 |
} |
80 |
|
|
80 |
|
|
81 | 81 |
public static void selfRegister() { |
82 | 82 |
URL imageResource = DatePickerControllerImpl.class.getClassLoader().getResource("org/gvsig/tools/swing/bookmarkandhistory/bookmarks.png"); |
83 | 83 |
if (imageResource != null) { |
... | ... | |
87 | 87 |
theme.registerDefault("tools", "bookmarkandhistory", "bookmarks", icon, imageResource); |
88 | 88 |
} |
89 | 89 |
} |
90 |
|
|
90 |
|
|
91 | 91 |
private void doBookmarks() { |
92 | 92 |
JPopupMenu popup = this.createMenu().getPopupMenu(); |
93 | 93 |
Point p = this.btnBookmarks.getLocationOnScreen(); |
... | ... | |
112 | 112 |
menu.add(addToBookmarks); |
113 | 113 |
separator = false; |
114 | 114 |
} |
115 |
List<Bookmark<T>> filteredBookmarks = bookmarks.filter(this.filter); |
|
115 |
// List<Bookmark<T>> filteredBookmarks = bookmarks.filter(this.filter);
|
|
116 | 116 |
|
117 |
if (!filteredBookmarks.isEmpty()) {
|
|
117 |
if (!bookmarks.isEmpty()) {
|
|
118 | 118 |
if (!separator) { |
119 | 119 |
menu.addSeparator(); |
120 | 120 |
separator = true; |
121 | 121 |
} |
122 |
for (Bookmark bookmark : filteredBookmarks) { |
|
123 |
menu.add(createBookmarkMenuItem(bookmark)); |
|
122 |
for (Bookmark<T> bookmark : bookmarks) { |
|
123 |
boolean validService; |
|
124 |
if (this.filter == null) { |
|
125 |
validService = true; |
|
126 |
} else { |
|
127 |
validService = this.filter.test(bookmark); |
|
128 |
} |
|
129 |
JMenuItem disabledBookmark = createBookmarkMenuItem(bookmark); |
|
130 |
disabledBookmark.setEnabled(validService); |
|
131 |
menu.add(disabledBookmark); |
|
124 | 132 |
separator = false; |
133 |
|
|
125 | 134 |
} |
135 |
|
|
136 |
// for (Bookmark bookmark : filteredBookmarks) { |
|
137 |
// menu.add(createBookmarkMenuItem(bookmark)); |
|
138 |
// separator = false; |
|
139 |
// } |
|
126 | 140 |
} |
127 | 141 |
if (!separator) { |
128 | 142 |
menu.addSeparator(); |
... | ... | |
147 | 161 |
@Override |
148 | 162 |
public void actionPerformed(ActionEvent e) { |
149 | 163 |
// updateValue((T) bookmark.getValue()); |
150 |
BookmarkEventImpl<T> event = new BookmarkEventImpl(DefaultBookmarksController.this, ID_SETVALUE, "set-value");
|
|
164 |
BookmarkEventImpl<T> event = new BookmarkEventImpl(DefaultBookmarksController.this, ID_SETVALUE, "set-value"); |
|
151 | 165 |
event.setCurrentValue(bookmark.getValue()); |
152 | 166 |
DefaultBookmarksController.this.fireActionEvent(event); |
153 | 167 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/pickercontroller/FilePickerControllerImpl.java | ||
---|---|---|
29 | 29 |
* |
30 | 30 |
* @author jjdelcerro |
31 | 31 |
*/ |
32 |
public class FilePickerControllerImpl |
|
33 |
extends AbstractPickerController<File> |
|
34 |
implements FilePickerController |
|
35 |
{ |
|
36 |
|
|
32 |
public class FilePickerControllerImpl |
|
33 |
extends AbstractPickerController<File> |
|
34 |
implements FilePickerController { |
|
35 |
|
|
37 | 36 |
private final JButton btnFile; |
38 | 37 |
private final JTextField txtFile; |
39 | 38 |
private final File initialPath; |
... | ... | |
41 | 40 |
private final String dialogTitle; |
42 | 41 |
private File value; |
43 | 42 |
private FileFilter filter; |
44 |
|
|
43 |
|
|
45 | 44 |
public static void selfRegister() { |
46 | 45 |
URL imageResource = DatePickerControllerImpl.class.getClassLoader().getResource("org/gvsig/tools/swing/picker/picker-file.png"); |
47 | 46 |
if (imageResource != null) { |
... | ... | |
59 | 58 |
} |
60 | 59 |
} |
61 | 60 |
private final JButton btnClear; |
62 |
|
|
61 |
|
|
63 | 62 |
public FilePickerControllerImpl(JTextField txtFile, JButton btnFile, String dialogTitle) { |
64 | 63 |
this(txtFile, btnFile, dialogTitle, null, null, true); |
65 | 64 |
} |
66 |
|
|
65 |
|
|
67 | 66 |
public FilePickerControllerImpl(JTextField txtFile, JButton btnFile) { |
68 | 67 |
this(txtFile, btnFile, null, null, null, true); |
69 | 68 |
} |
... | ... | |
74 | 73 |
this.btnFile = btnFile; |
75 | 74 |
this.fileChooserID = fileChooserID; |
76 | 75 |
this.initialPath = initialPath; |
77 |
if( dialogTitle==null ) {
|
|
76 |
if (dialogTitle == null) {
|
|
78 | 77 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
79 | 78 |
this.dialogTitle = i18n.getTranslation("_Select_file"); |
80 | 79 |
} else { |
81 | 80 |
this.dialogTitle = dialogTitle; |
82 | 81 |
} |
83 |
if( seticon ) {
|
|
82 |
if (seticon) {
|
|
84 | 83 |
this.btnFile.setIcon(this.getIcon("picker-file")); |
85 | 84 |
this.btnFile.setText(""); |
86 | 85 |
} |
... | ... | |
91 | 90 |
} |
92 | 91 |
}); |
93 | 92 |
this.btnClear = new JButton(getIcon("picker-cleartext")); |
94 |
btnClear.setBorderPainted( false );
|
|
95 |
btnClear.setFocusPainted( false );
|
|
96 |
btnClear.setContentAreaFilled( false );
|
|
97 |
btnClear.setOpaque(false);
|
|
93 |
btnClear.setBorderPainted(false);
|
|
94 |
btnClear.setFocusPainted(false);
|
|
95 |
btnClear.setContentAreaFilled(false);
|
|
96 |
btnClear.setOpaque(false); |
|
98 | 97 |
btnClear.addActionListener(new ActionListener() { |
99 | 98 |
@Override |
100 | 99 |
public void actionPerformed(ActionEvent e) { |
... | ... | |
107 | 106 |
this.txtFile.addKeyListener(new KeyAdapter() { |
108 | 107 |
@Override |
109 | 108 |
public void keyPressed(KeyEvent e) { |
110 |
if( e.getKeyCode()==KeyEvent.VK_ENTER ) {
|
|
109 |
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
|
111 | 110 |
coerceAndSet(txtFile.getText()); |
112 | 111 |
fireChangeEvent(); |
113 | 112 |
} |
... | ... | |
119 | 118 |
private void doClear() { |
120 | 119 |
this.set(null); |
121 | 120 |
} |
122 |
|
|
121 |
|
|
123 | 122 |
@Override |
124 | 123 |
public boolean isEmpty() { |
125 |
return this.value==null;
|
|
124 |
return this.value == null;
|
|
126 | 125 |
} |
127 |
|
|
126 |
|
|
128 | 127 |
@Override |
129 | 128 |
public File get() { |
129 |
coerceAndSet(txtFile.getText()); |
|
130 | 130 |
return this.value; |
131 | 131 |
} |
132 | 132 |
|
133 | 133 |
@Override |
134 | 134 |
public void set(File value) { |
135 | 135 |
this.value = value; |
136 |
if( value==null ) {
|
|
136 |
if (value == null) {
|
|
137 | 137 |
this.txtFile.setText(""); |
138 | 138 |
} else { |
139 | 139 |
this.txtFile.setText(value.toString()); |
... | ... | |
145 | 145 |
super.setEditable(editable); |
146 | 146 |
this.txtFile.setEditable(editable); |
147 | 147 |
} |
148 |
|
|
148 |
|
|
149 | 149 |
@Override |
150 | 150 |
public void setEnabled(boolean enabled) { |
151 | 151 |
this.btnFile.setEnabled(enabled); |
... | ... | |
159 | 159 |
} |
160 | 160 |
|
161 | 161 |
private void doSelectFile() { |
162 |
if( !this.isEditable() ) {
|
|
162 |
if (!this.isEditable()) {
|
|
163 | 163 |
return; |
164 | 164 |
} |
165 | 165 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
166 | 166 |
FoldersManager folderManager = ToolsLocator.getFoldersManager(); |
167 |
File pathToUse = initialPath; |
|
168 |
if (this.value != null) { |
|
169 |
pathToUse = this.value; |
|
170 |
} |
|
167 | 171 |
File[] f = dialogs.showChooserDialog( |
168 |
this.dialogTitle,
|
|
169 |
JFileChooser.OPEN_DIALOG,
|
|
170 |
JFileChooser.FILES_ONLY,
|
|
171 |
true,
|
|
172 |
this.dialogTitle, |
|
173 |
JFileChooser.OPEN_DIALOG, |
|
174 |
JFileChooser.FILES_ONLY, |
|
175 |
true, |
|
172 | 176 |
folderManager.getLastPath( |
173 |
this.fileChooserID,
|
|
174 |
this.initialPath
|
|
177 |
this.fileChooserID, |
|
178 |
pathToUse
|
|
175 | 179 |
), |
176 |
this.filter,
|
|
180 |
this.filter, |
|
177 | 181 |
true |
178 | 182 |
); |
179 |
|
|
180 |
if( ArrayUtils.isEmpty(f) ) {
|
|
183 |
|
|
184 |
if (ArrayUtils.isEmpty(f)) {
|
|
181 | 185 |
return; |
182 | 186 |
} |
183 | 187 |
this.set(f[0]); |
... | ... | |
193 | 197 |
public void setFileFilter(FileFilter filter) { |
194 | 198 |
this.filter = filter; |
195 | 199 |
} |
196 |
|
|
200 |
|
|
197 | 201 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/bookmarkshistory/HistoryController.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.tools.swing.api.bookmarkshistory; |
7 | 7 |
|
8 |
import java.awt.event.ActionEvent; |
|
8 | 9 |
import java.util.function.Predicate; |
9 | 10 |
import org.gvsig.tools.bookmarksandhistory.History; |
10 | 11 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
... | ... | |
15 | 16 |
* @param <T> |
16 | 17 |
*/ |
17 | 18 |
public interface HistoryController<T> extends ActionListenerSupport { |
18 |
|
|
19 |
|
|
20 |
public static final int ID_SETVALUE = ActionEvent.ACTION_FIRST; |
|
21 |
|
|
22 |
public interface HistoryEvent<T> { |
|
23 |
|
|
24 |
public void setCurrentValue(T value); |
|
25 |
|
|
26 |
public T getCurrentValue(); |
|
27 |
|
|
28 |
public String getActionCommand(); |
|
29 |
|
|
30 |
public int getID(); |
|
31 |
|
|
32 |
public Object getSource(); |
|
33 |
|
|
34 |
} |
|
35 |
|
|
19 | 36 |
public void setFilter(Predicate filter); |
20 |
|
|
37 |
|
|
21 | 38 |
public void setNewValueWithOutHistory(T newValue); |
22 |
|
|
39 |
|
|
23 | 40 |
public History<T> get(); |
24 | 41 |
|
25 | 42 |
} |
Also available in: Unified diff