Changeset 35647 in osm for applications/editors/josm/plugins
- Timestamp:
- 2020-11-16T17:45:08+01:00 (4 years ago)
- Location:
- applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/preferences
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/preferences/RasterFiltersPreferences.java
r34550 r35647 1 1 package org.openstreetmap.josm.plugins.rasterfilters.preferences; 2 2 3 import java.awt.GridBagConstraints; 3 import static java.awt.GridBagConstraints.BOTH; 4 import static java.awt.GridBagConstraints.EAST; 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 4 7 import java.awt.GridBagLayout; 5 8 import java.util.List; 6 import java.util.Objects;7 9 8 import javax.json.JsonObject;9 10 import javax.swing.JButton; 10 11 import javax.swing.JPanel; … … 12 13 import javax.swing.JTable; 13 14 import javax.swing.border.EmptyBorder; 14 import javax.swing.event.TableModelEvent;15 import javax.swing.event.TableModelListener;16 15 import javax.swing.table.AbstractTableModel; 17 16 import javax.swing.table.TableModel; … … 20 19 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 21 20 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 22 import org.openstreetmap.josm.gui.preferences.map.MapPreference;23 21 import org.openstreetmap.josm.spi.preferences.Config; 24 22 import org.openstreetmap.josm.tools.GBC; … … 31 29 public class RasterFiltersPreferences implements SubPreferenceSetting { 32 30 33 private FiltersDownloader downloader = new FiltersDownloader(); 34 AbstractTableModel model; 35 JPanel holder; 31 private AbstractTableModel model; 32 private JPanel holder; 36 33 37 34 @Override 38 35 public void addGui(PreferenceTabbedPane gui) { 39 40 36 model = new FiltersTableModel(); 41 37 42 38 if (holder == null) { 43 holder = new JPanel(); 44 holder.setLayout(new GridBagLayout()); 45 39 holder = new JPanel(new GridBagLayout()); 46 40 holder.setBorder(new EmptyBorder(10, 10, 10, 10)); 47 48 model.addTableModelListener(new TableModelListener() { 49 50 @Override 51 public void tableChanged(TableModelEvent e) { 52 int row = e.getFirstRow(); 53 int col = e.getColumn(); 54 TableModel model = (TableModel) e.getSource(); 55 56 Boolean isDownloadedUpdate = (Boolean) model.getValueAt( 57 row, col); 58 List<FilterInfo> filtersList = ((FiltersTableModel) model).filtersInfoList; 59 60 filtersList.get(row).setNeedToDownload(isDownloadedUpdate); 61 62 } 41 model.addTableModelListener(e -> { 42 int row = e.getFirstRow(); 43 int col = e.getColumn(); 44 TableModel tmodel = (TableModel) e.getSource(); 45 ((FiltersTableModel) tmodel).filtersInfoList.get(row).setNeedToDownload((Boolean) tmodel.getValueAt(row, col)); 63 46 }); 64 47 … … 68 51 JScrollPane pane = new JScrollPane(table); 69 52 70 holder.add(pane, GBC.eol().fill( GBC.BOTH));53 holder.add(pane, GBC.eol().fill(BOTH)); 71 54 72 GridBagConstraints c = GBC.eol(); 73 c.anchor = GBC.EAST; 74 75 JButton download = new JButton("Download"); 76 download.addActionListener(downloader); 77 holder.add(download, c); 55 JButton download = new JButton(tr("Download")); 56 download.addActionListener(new FiltersDownloader()); 57 holder.add(download, GBC.eol().anchor(EAST)); 78 58 } 79 59 80 MapPreference pref = gui.getMapPreference(); 81 pref.addSubTab(this, "Image Filters", holder); 82 60 getTabPreferenceSetting(gui).addSubTab(this, tr("Image Filters"), holder); 83 61 } 84 62 85 63 @Override 86 64 public boolean ok() { 87 List<FilterInfo> filtersInfoList = ((FiltersTableModel) model).getFiltersInfoList(); 88 89 for (FilterInfo temp : filtersInfoList) { 90 JsonObject meta = temp.getMeta(); 91 String paramName = meta.getString("name"); 92 paramName = "rasterfilters." + paramName; 93 Config.getPref().putBoolean(paramName, temp.isNeedToDownload()); 65 for (FilterInfo temp : ((FiltersTableModel) model).getFiltersInfoList()) { 66 Config.getPref().putBoolean("rasterfilters." + temp.getMeta().getString("name"), temp.isNeedToDownload()); 94 67 } 95 96 68 return false; 97 69 } … … 99 71 @Override 100 72 public boolean isExpert() { 101 // TODO Auto-generated method stub102 73 return false; 103 74 } … … 105 76 @Override 106 77 public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) { 107 return gui.get MapPreference();78 return gui.getImageryPreference(); 108 79 } 109 80 110 static class FiltersTableModel extends AbstractTableModel {81 private static class FiltersTableModel extends AbstractTableModel { 111 82 112 String[] columnNames = {"Filter Name", "Author", "Description", ""};113 Class<?>[] columnClasses = {String.class, String.class, String.class, Boolean.class};114 List<FilterInfo> filtersInfoList;115 Object[][] data;83 private final String[] columnNames = {tr("Filter Name"), tr("Author"), tr("Description"), ""}; 84 private final Class<?>[] columnClasses = {String.class, String.class, String.class, Boolean.class}; 85 private final List<FilterInfo> filtersInfoList = FiltersDownloader.downloadFiltersInfoList(); 86 private final Object[][] data = new Object[filtersInfoList.size()][4]; 116 87 117 88 FiltersTableModel() { 118 119 filtersInfoList = FiltersDownloader.downloadFiltersInfoList();120 data = new Object[filtersInfoList.size()][4];121 122 89 for (int i = 0; i < filtersInfoList.size(); i++) { 123 90 data[i][0] = filtersInfoList.get(i).getName(); … … 126 93 data[i][3] = filtersInfoList.get(i).isNeedToDownload(); 127 94 } 128 129 95 } 130 96 … … 167 133 @Override 168 134 public boolean isCellEditable(int row, int col) { 169 if (col == 3) { 170 return true; 171 } 172 173 return false; 135 return col == 3; 174 136 } 175 137 … … 186 148 } 187 149 } 188 189 150 } 190 191 class FilterInfo {192 private String name;193 private String description;194 private JsonObject meta;195 private boolean needToDownload;196 private String owner;197 198 FilterInfo(String name, String description, JsonObject meta, boolean needToDownload) {199 this.setName(name);200 this.setDescription(description);201 this.meta = meta;202 this.setNeedToDownload(needToDownload);203 }204 205 public String getName() {206 return name;207 }208 209 public void setName(String name) {210 this.name = name;211 }212 213 public String getDescription() {214 return description;215 }216 217 public void setDescription(String description) {218 this.description = description;219 }220 221 public JsonObject getMeta() {222 return meta;223 }224 225 public void setMeta(JsonObject meta) {226 this.meta = meta;227 }228 229 public boolean isNeedToDownload() {230 return needToDownload;231 }232 233 public void setNeedToDownload(boolean needToDownload) {234 this.needToDownload = needToDownload;235 }236 237 public String getOwner() {238 return owner;239 }240 241 public void setOwner(String owner) {242 this.owner = owner;243 }244 245 @Override246 public String toString() {247 return "name: " + getName() + "\nDescription: " + getDescription() + "\nMeta: " + getMeta();248 }249 250 @Override251 public int hashCode() {252 return Objects.hash(name, meta, description);253 }254 255 @Override256 public boolean equals(Object o) {257 return (o instanceof FilterInfo) && name.equals(((FilterInfo) o).getName())258 && meta.equals(((FilterInfo) o).getMeta()) && description.equals(((FilterInfo) o).getDescription());259 }260 }
Note:
See TracChangeset
for help on using the changeset viewer.