Changeset 32850 in osm for applications/editors
- Timestamp:
- 2016-08-20T14:47:26+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters
- Files:
-
- 1 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/RasterFiltersPlugin.java
r32503 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters; 2 3 import java.awt.Container;4 import java.io.File;5 import java.io.IOException;6 7 import javax.swing.JPanel;8 2 9 3 import org.openstreetmap.josm.Main; … … 26 20 import org.openstreetmap.josm.plugins.rasterfilters.preferences.RasterFiltersPreferences; 27 21 22 import javax.swing.*; 23 import java.awt.*; 24 import java.io.File; 25 import java.io.IOException; 26 28 27 /** 29 28 * Main Plugin class. This class embed new plugin button for adding filter and … … 35 34 public class RasterFiltersPlugin extends Plugin implements LayerChangeListener, ActiveLayerChangeListener { 36 35 37 38 39 36 private SideButton filterButton; 37 private ShowLayerFiltersDialog action; 38 private PreferenceSetting setting; 40 39 41 42 43 40 public RasterFiltersPlugin(PluginInformation info) { 41 super(info); 42 Main.debug("Loading RasterFiltersPlugin"); 44 43 45 46 44 File file = new File(getPluginDir()); 45 if (file.mkdir()) { 47 46 48 49 50 51 52 53 54 55 56 57 47 // opening file with last user's settings 48 file = new File(file.getAbsoluteFile(), "urls.map"); 49 if (!file.exists()) { 50 try { 51 file.createNewFile(); 52 } catch (IOException e) { 53 Main.debug("Cannot create file" + file.getAbsolutePath() + "\n" + e.getMessage()); 54 } 55 } 56 } 58 57 59 60 58 FiltersDownloader.setPluginDir(getPluginDir()); 59 } 61 60 62 63 64 65 61 @Override 62 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 63 if (Main.isDisplayingMapView()) { 64 Main.getLayerManager().addLayerChangeListener(this); 66 65 Main.getLayerManager().addActiveLayerChangeListener(this); 67 68 66 } 67 } 69 68 70 71 72 73 74 75 76 77 69 @Override 70 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 71 if (!(Main.getLayerManager().getActiveLayer() instanceof ImageryLayer)) { 72 filterButton.setEnabled(false); 73 } else { 74 filterButton.setEnabled(true); 75 } 76 } 78 77 79 80 78 @Override 79 public void layerAdded(LayerAddEvent e) { 81 80 82 81 if (filterButton == null) { 83 82 84 85 86 83 // filter reading and adding to the collections of FilterDownloader 84 FiltersDownloader.downloadFiltersInfoList(); 85 FiltersDownloader.initFilters(); 87 86 88 89 90 87 if (action == null) { 88 action = new ShowLayerFiltersDialog(); 89 } 91 90 92 93 94 95 96 97 98 91 if (e.getAddedLayer() instanceof ImageryLayer) { 92 filterButton = new SideButton(action, false); 93 filterButton.setEnabled(true); 94 } else { 95 filterButton = new SideButton(action, false); 96 filterButton.setEnabled(false); 97 } 99 98 100 99 LayerListDialog dialog = LayerListDialog.getInstance(); 101 100 102 103 104 101 JPanel buttonRowPanel = (JPanel) ((JPanel) dialog.getComponent(2)).getComponent(0); 102 buttonRowPanel.add(filterButton); 103 } 105 104 106 107 108 109 105 if (e.getAddedLayer() instanceof ImageryLayer) { 106 FiltersDialog dialog = new FiltersDialog((ImageryLayer) e.getAddedLayer()); 107 action.addFiltersDialog(dialog); 108 } 110 109 111 110 } 112 111 113 114 112 @Override 113 public void layerRemoving(LayerRemoveEvent e) { 115 114 116 117 118 119 120 121 115 if (e.getRemovedLayer() instanceof ImageryLayer) { 116 FiltersDialog dialog = action.getDialogByLayer(e.getRemovedLayer()); 117 ((ImageryLayer) e.getRemovedLayer()).removeImageProcessor(dialog.getFiltersManager()); 118 dialog.closeFrame(); 119 action.removeFiltersDialog(dialog); 120 } 122 121 123 if (Main.getLayerManager().getLayers().isEmpty()) { 122 if (Main.getLayerManager().getLayers().isEmpty()) { 123 Container container = filterButton.getParent(); 124 if (container != null) 125 container.remove(filterButton); 124 126 125 Container container = filterButton.getParent(); 126 if (container != null) 127 container.remove(filterButton); 128 129 FiltersDownloader.destroyFilters(); 130 filterButton = null; 127 FiltersDownloader.destroyFilters(); 128 filterButton = null; 129 } 131 130 132 } 133 } 131 Main.getLayerManager().removeLayerChangeListener(this); 132 Main.getLayerManager().removeActiveLayerChangeListener(this); 133 } 134 134 135 135 @Override 136 136 public void layerOrderChanged(LayerOrderChangeEvent e) { 137 137 // Do nothing … … 139 139 140 140 @Override 141 142 143 144 141 public PreferenceSetting getPreferenceSetting() { 142 if (setting == null) { 143 setting = new RasterFiltersPreferences(); 144 } 145 145 146 147 146 return setting; 147 } 148 148 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/actions/ShowLayerFiltersDialog.java
r32503 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.actions; 2 3 import static org.openstreetmap.josm.tools.I18n.tr;4 5 import java.awt.Component;6 import java.awt.event.ActionEvent;7 import java.net.MalformedURLException;8 import java.util.ArrayList;9 import java.util.List;10 11 import javax.swing.AbstractAction;12 import javax.swing.JMenuItem;13 2 14 3 import org.openstreetmap.josm.Main; … … 19 8 import org.openstreetmap.josm.tools.ImageProvider; 20 9 10 import javax.swing.*; 11 import java.awt.*; 12 import java.awt.event.ActionEvent; 13 import java.net.MalformedURLException; 14 import java.util.ArrayList; 15 import java.util.List; 16 17 import static org.openstreetmap.josm.tools.I18n.tr; 18 21 19 /** 22 20 * The action that is called when user click on 'Choose filters' button 23 * 21 * <p> 24 22 * and sets image on that button 25 23 * 26 24 * @author Nipel-Crumple 27 *28 25 */ 29 26 public final class ShowLayerFiltersDialog extends AbstractAction implements LayerAction { 30 27 31 28 private List<FiltersDialog> dialogs = new ArrayList<>(); 32 29 33 34 35 36 37 38 39 40 30 /** 31 * Constructs a new {@code ShowLayerFiltersDialog}. 32 */ 33 public ShowLayerFiltersDialog() { 34 putValue(NAME, tr("Filters")); 35 putValue(SHORT_DESCRIPTION, tr("Choose Filter")); 36 putValue(SMALL_ICON, ImageProvider.get("josm_filters_48.png")); 37 } 41 38 42 43 44 39 public void addFiltersDialog(FiltersDialog dialog) { 40 dialogs.add(dialog); 41 } 45 42 46 47 48 43 public void removeFiltersDialog(FiltersDialog dialog) { 44 dialogs.remove(dialog); 45 } 49 46 50 51 47 @Override 48 public void actionPerformed(ActionEvent e) { 52 49 53 50 Layer layer = Main.getLayerManager().getActiveLayer(); 54 51 55 56 52 if (layer instanceof ImageryLayer) { 53 for (FiltersDialog temp : dialogs) { 57 54 58 59 60 61 62 63 64 65 55 if (temp.getLayer().equals(layer)) { 56 try { 57 temp.createAndShowGUI(); 58 } catch (MalformedURLException e1) { 59 e1.printStackTrace(); 60 } 61 break; 62 } 66 63 67 68 69 64 } 65 } 66 } 70 67 71 72 68 public FiltersDialog getDialogByLayer(Layer layer) { 69 for (FiltersDialog dialog : dialogs) { 73 70 74 75 76 71 if (dialog.getLayer().equals(layer)) { 72 return dialog; 73 } 77 74 78 75 } 79 76 80 81 77 return null; 78 } 82 79 83 84 85 86 80 @Override 81 public boolean supportLayers(List<Layer> layers) { 82 return true; 83 } 87 84 88 89 90 91 85 @Override 86 public Component createMenuComponent() { 87 return new JMenuItem(this); 88 } 92 89 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/filters/Filter.java
r31504 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.filters; 2 2 3 import javax.json.JsonObject; 3 4 import java.awt.image.BufferedImage; 4 5 import java.rmi.server.UID; 5 6 6 import javax.json.JsonObject;7 7 /** 8 8 * The Filter interface is inherited by all filters which are implemented. 9 * 9 * <p> 10 10 * This interface has four methods that should be overrided in 11 * 11 * <p> 12 12 * implementation. 13 13 * 14 14 * @author Nipel-Crumple 15 *16 15 */ 17 16 public interface Filter { 18 17 19 /** 20 * This method should take external fields values of filter's parameters 21 * which should be described in the meta-information. In other words, if you have 3 22 * controls of type 'linear_slider' and if state at least one of these 23 * controls has changed, you will get new filter state in the form of 24 * json object 'filterState', then parse it and 25 * store given parameters' values in class. 26 * 27 * @param filterState json that has information about current filter state 28 * 29 * @return json object 'filterState' 30 */ 31 public JsonObject changeFilterState(JsonObject filterState); 18 /** 19 * This method should take external fields values of filter's parameters 20 * which should be described in the meta-information. In other words, if you have 3 21 * controls of type 'linear_slider' and if state at least one of these 22 * controls has changed, you will get new filter state in the form of 23 * json object 'filterState', then parse it and 24 * store given parameters' values in class. 25 * 26 * @param filterState json that has information about current filter state 27 * @return json object 'filterState' 28 */ 29 public JsonObject changeFilterState(JsonObject filterState); 32 30 33 /** 34 * This method processes given image and returns 35 * updated version of the image. Algorithm and implementation of 36 * this method depends on your needs and wishes. 37 * 38 * @param img image to process 39 * 40 * @return processed image 41 */ 42 public BufferedImage applyFilter(BufferedImage img); 31 /** 32 * This method processes given image and returns 33 * updated version of the image. Algorithm and implementation of 34 * this method depends on your needs and wishes. 35 * 36 * @param img image to process 37 * @return processed image 38 */ 39 public BufferedImage applyFilter(BufferedImage img); 43 40 44 45 46 47 48 49 50 41 /** 42 * Every filter must have his own unique ID number. 43 * In case of rasterfilters plugin it ID is the type of UID. 44 * 45 * @param id sets value of ID field 46 */ 47 public void setId(UID id); 51 48 52 53 54 55 56 57 49 /** 50 * Getter for filter's ID field. 51 * 52 * @return id of filter 53 */ 54 public UID getId(); 58 55 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/gui/FilterGuiListener.java
r31948 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.gui; 2 2 3 import java.awt.Color; 3 import com.bric.swing.ColorPicker; 4 import org.openstreetmap.josm.plugins.rasterfilters.model.FilterStateModel; 5 import org.openstreetmap.josm.plugins.rasterfilters.model.StateChangeListener; 6 import org.openstreetmap.josm.plugins.rasterfilters.values.BooleanValue; 7 import org.openstreetmap.josm.plugins.rasterfilters.values.ColorValue; 8 import org.openstreetmap.josm.plugins.rasterfilters.values.SelectValue; 9 import org.openstreetmap.josm.plugins.rasterfilters.values.SliderValue; 10 11 import javax.swing.*; 12 import javax.swing.event.ChangeEvent; 13 import javax.swing.event.ChangeListener; 14 import java.awt.*; 4 15 import java.awt.event.ActionEvent; 5 16 import java.awt.event.ActionListener; … … 12 23 import java.util.Set; 13 24 14 import javax.swing.ComboBoxModel;15 import javax.swing.JCheckBox;16 import javax.swing.JComboBox;17 import javax.swing.JSlider;18 import javax.swing.event.ChangeEvent;19 import javax.swing.event.ChangeListener;20 21 import org.openstreetmap.josm.plugins.rasterfilters.model.FilterStateModel;22 import org.openstreetmap.josm.plugins.rasterfilters.model.StateChangeListener;23 import org.openstreetmap.josm.plugins.rasterfilters.values.BooleanValue;24 import org.openstreetmap.josm.plugins.rasterfilters.values.ColorValue;25 import org.openstreetmap.josm.plugins.rasterfilters.values.SelectValue;26 import org.openstreetmap.josm.plugins.rasterfilters.values.SliderValue;27 28 import com.bric.swing.ColorPicker;29 30 25 /** 31 26 * This class is GUI listener which tracks all changes of GUI controls 32 27 * elements: sliders, checkboxes, color pickers and select lists. 28 * 33 29 * @author Nipel-Crumple 34 *35 30 */ 36 31 public class FilterGuiListener implements ChangeListener, ItemListener, 37 32 ActionListener, PropertyChangeListener, FilterStateOwner { 38 33 39 40 41 42 34 private StateChangeListener handler; 35 private FilterStateModel filterState; 36 private Set<ComboBoxModel<String>> models = new HashSet<>(); 37 private UID filterId; 43 38 44 45 46 39 public FilterGuiListener(StateChangeListener handler) { 40 this.handler = handler; 41 } 47 42 48 49 50 43 public void setFilterState(FilterStateModel state) { 44 this.filterState = state; 45 } 51 46 52 53 54 55 56 47 /** 48 * Listener which responds on any changes of sliders values. 49 */ 50 @Override 51 public void stateChanged(ChangeEvent e) { 57 52 58 53 JSlider slider = (JSlider) e.getSource(); 59 54 60 61 62 55 if (!slider.getValueIsAdjusting()) { 56 slider.setToolTipText(String.valueOf((double) slider.getValue() / 100)); 57 } 63 58 64 59 String parameterName = slider.getName(); 65 60 66 61 if (filterState.getParams().containsKey(parameterName)) { 67 62 68 69 70 63 @SuppressWarnings("unchecked") 64 SliderValue<Number> value = (SliderValue<Number>) filterState 65 .getParams().get(parameterName); 71 66 72 73 74 75 76 67 if (value.isDouble()) { 68 value.setValue((double) slider.getValue() / 100); 69 } else { 70 value.setValue(slider.getValue()); 71 } 77 72 78 79 73 filterState.getParams().put(parameterName, value); 74 } 80 75 81 82 83 76 // notifies about state is changed now and sends msg to FiltersManager 77 handler.filterStateChanged(filterId, filterState); 78 } 84 79 85 86 87 88 80 @Override 81 public FilterStateModel getState() { 82 return filterState; 83 } 89 84 90 91 92 93 85 public ComboBoxModel<String> addModel(ComboBoxModel<String> model) { 86 models.add(model); 87 return model; 88 } 94 89 95 96 97 90 public void setFilterId(UID filterId) { 91 this.filterId = filterId; 92 } 98 93 99 100 101 94 public UID getFilterId() { 95 return filterId; 96 } 102 97 103 104 105 106 107 98 /** 99 * Method reacts on changes of checkbox GUI elements. 100 */ 101 @Override 102 public void itemStateChanged(ItemEvent e) { 108 103 109 104 JCheckBox box = (JCheckBox) e.getSource(); 110 105 111 106 String parameterName = box.getName(); 112 107 113 114 115 108 BooleanValue value = (BooleanValue) filterState.getParams().get( 109 parameterName); 110 value.setValue(box.isSelected()); 116 111 117 112 handler.filterStateChanged(filterId, filterState); 118 113 119 114 } 120 115 121 122 123 124 125 126 116 /** 117 * Methods tracks all changes of select lists 118 */ 119 @SuppressWarnings("unchecked") 120 @Override 121 public void actionPerformed(ActionEvent e) { 127 122 128 123 JComboBox<String> box = (JComboBox<String>) e.getSource(); 129 124 130 131 132 125 String parameterName = box.getName(); 126 SelectValue<String> value = (SelectValue<String>) filterState 127 .getParams().get(parameterName); 133 128 134 135 129 ComboBoxModel<String> model = box.getModel(); 130 String selectedItem = (String) model.getSelectedItem(); 136 131 137 132 value.setValue(selectedItem); 138 133 139 140 141 134 // notify about state is changed now so send msg to FiltersManager 135 if (handler != null) 136 handler.filterStateChanged(filterId, filterState); 142 137 143 138 } 144 139 145 146 147 148 149 150 151 140 /** 141 * This listener's method is for responding on some 142 * color pick changes. 143 */ 144 @Override 145 public void propertyChange(PropertyChangeEvent evt) { 146 ColorPicker picker = (ColorPicker) evt.getSource(); 152 147 153 154 155 148 int r = picker.getColor().getRed(); 149 int g = picker.getColor().getGreen(); 150 int b = picker.getColor().getBlue(); 156 151 157 152 String parameterName = picker.getName(); 158 153 159 160 161 162 154 @SuppressWarnings("unchecked") 155 ColorValue<Color> value = (ColorValue<Color>) filterState.getParams() 156 .get(parameterName); 157 value.setValue(new Color(r, g, b)); 163 158 164 165 159 handler.filterStateChanged(filterId, filterState); 160 } 166 161 167 162 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/gui/FilterPanel.java
r32754 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.gui; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.awt.Color; 6 import java.awt.Component; 7 import java.awt.Dimension; 8 import java.awt.FlowLayout; 9 import java.awt.Font; 3 import com.bric.swing.ColorPicker; 4 import org.openstreetmap.josm.Main; 5 import org.openstreetmap.josm.plugins.rasterfilters.model.FiltersManager; 6 7 import javax.json.JsonArray; 8 import javax.json.JsonObject; 9 import javax.swing.*; 10 import javax.swing.border.Border; 11 import javax.swing.border.EmptyBorder; 12 import java.awt.*; 10 13 import java.awt.event.ActionListener; 11 14 import java.awt.event.ItemListener; … … 13 16 import java.util.Hashtable; 14 17 15 import javax.json.JsonArray; 16 import javax.json.JsonObject; 17 import javax.swing.BorderFactory; 18 import javax.swing.Box; 19 import javax.swing.BoxLayout; 20 import javax.swing.DefaultComboBoxModel; 21 import javax.swing.JButton; 22 import javax.swing.JCheckBox; 23 import javax.swing.JComboBox; 24 import javax.swing.JComponent; 25 import javax.swing.JLabel; 26 import javax.swing.JOptionPane; 27 import javax.swing.JPanel; 28 import javax.swing.JSlider; 29 import javax.swing.border.Border; 30 import javax.swing.border.EmptyBorder; 31 32 import org.openstreetmap.josm.Main; 33 import org.openstreetmap.josm.plugins.rasterfilters.model.FiltersManager; 34 35 import com.bric.swing.ColorPicker; 18 import static org.openstreetmap.josm.tools.I18n.tr; 36 19 37 20 /** … … 41 24 * 42 25 * @author Nipel-Crumple 43 *44 26 */ 45 27 public class FilterPanel extends JPanel { 46 28 47 private static final long serialVersionUID = 1L; 48 private UID filterId; 49 private int neededHeight; 50 51 public FilterPanel() { 52 super(); 53 setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); 54 setBackground(Color.white); 55 } 56 57 /** 58 * Methods adds GUI element on filter's panel according to meta-information and 59 * automatically resizes the given filter's panel. 60 * 61 * @param json filter's meta-information 62 * 63 * @return added GUI element 64 */ 65 public JComponent addGuiElement(JsonObject json) { 66 String type = json.getString("type"); 67 68 if (type.equals("linear_slider")) { 69 70 setNeededHeight(getNeededHeight() + 70); 71 72 return createSlider(json); 73 74 } else if (type.equals("checkbox")) { 75 76 setNeededHeight(getNeededHeight() + 30); 77 78 JCheckBox checkBox = createCheckBox(json.getString("title")); 79 checkBox.setSelected(json.getBoolean("default")); 80 checkBox.setName(json.getString("name")); 81 82 return checkBox; 83 84 } else if (type.equals("select")) { 85 86 setNeededHeight(getNeededHeight() + 50); 87 88 return createSelect(json); 89 90 } else if (type.equals("colorpicker")) { 91 92 setNeededHeight(getNeededHeight() + 220); 93 94 return createColorPicker(json); 95 } 96 return null; 97 } 98 99 private JComponent createSelect(JsonObject json) { 100 101 Font font = new Font("Arial", Font.PLAIN, 14); 102 103 JPanel selectPanel = new JPanel(); 104 105 selectPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); 106 selectPanel.setBackground(Color.white); 107 selectPanel.setLayout(new BoxLayout(selectPanel, BoxLayout.X_AXIS)); 108 selectPanel.setMaximumSize(new Dimension(300, 40)); 109 110 JLabel selectTitle = new JLabel(json.getString("title")); 111 112 selectTitle.setFont(font); 113 selectTitle.setBackground(Color.white); 114 115 JsonArray valuesArray = json.getJsonArray("values"); 116 117 DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(); 118 119 model.setSelectedItem(json.getString("default")); 120 121 for (int i = 0; i < valuesArray.size(); i++) { 122 model.addElement(valuesArray.getString(i)); 123 } 124 125 JComboBox<String> selectBox = new JComboBox<>(model); 126 selectBox.setMinimumSize(new Dimension(140, 30)); 127 128 selectPanel.add(selectTitle); 129 selectPanel.add(Box.createHorizontalGlue()); 130 selectPanel.add(selectBox); 131 selectBox.setName(json.getString("name")); 132 133 this.add(selectPanel); 134 135 return selectBox; 136 } 137 138 public JComponent createColorPicker(JsonObject json) { 139 140 ColorPicker picker = new ColorPicker(false, false); 141 picker.setPreferredSize(new Dimension(200,180)); 142 picker.setMode(ColorPicker.HUE); 143 picker.setName(json.getString("name")); 144 145 addControlTitle(json.getString("title")); 146 147 this.add(picker); 148 149 return picker; 150 } 151 152 public JCheckBox createCheckBox(String text) { 153 154 JPanel checkBoxPanel = new JPanel(); 155 checkBoxPanel.setMaximumSize(new Dimension(300, 30)); 156 checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.X_AXIS)); 157 checkBoxPanel.setBackground(Color.white); 158 159 JCheckBox checkBox = new JCheckBox(text); 160 Font font = new Font("Arial", Font.PLAIN, 12); 161 162 checkBox.setFont(font); 163 checkBox.setBackground(Color.white); 164 checkBox.setName(text); 165 166 checkBoxPanel.add(checkBox); 167 168 this.add(checkBoxPanel); 169 170 return checkBox; 171 } 172 173 private JCheckBox createDisableBox(ItemListener listener) { 174 JCheckBox disable = new JCheckBox("Disable"); 175 Font font = new Font("Arial", Font.PLAIN, 12); 176 177 disable.addItemListener(listener); 178 disable.setFont(font); 179 180 return disable; 181 } 182 183 private JButton createRemoveButton(ActionListener listener) { 184 JButton removeButton = new JButton("Remove"); 185 Font font = new Font("Arial", Font.PLAIN, 12); 186 187 removeButton.setFont(font); 188 removeButton.setName("remove"); 189 190 removeButton.addActionListener(listener); 191 192 return removeButton; 193 } 194 195 public JPanel createBottomPanel(FiltersManager listener) { 196 197 this.add(Box.createRigidArea(new Dimension(0, 10))); 198 JPanel bottom = new JPanel(); 199 200 bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS)); 201 bottom.setMaximumSize(new Dimension(300, 40)); 202 bottom.setBorder(BorderFactory 203 .createMatteBorder(2, 0, 0, 0, Color.gray)); 204 205 bottom.add(createDisableBox(listener)); 206 bottom.add(Box.createHorizontalGlue()); 207 bottom.add(createRemoveButton(listener)); 208 209 this.add(bottom); 210 211 return bottom; 212 } 213 214 private void addControlTitle(String labelText) { 215 Font labelFont = new Font("Arial", Font.PLAIN, 14); 216 217 JPanel sliderLabelPanel = new JPanel(); 218 sliderLabelPanel.setMaximumSize(new Dimension(400, 30)); 219 sliderLabelPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); 220 sliderLabelPanel.setBackground(Color.white); 221 222 JLabel sliderLabel = new JLabel(labelText, JLabel.LEFT); 223 sliderLabel.setFont(labelFont); 224 sliderLabel.setAlignmentX(Component.LEFT_ALIGNMENT); 225 sliderLabel.setVisible(true); 226 227 sliderLabelPanel.add(sliderLabel); 228 229 this.add(sliderLabelPanel); 230 } 231 232 public JSlider createSlider(JsonObject json) { 233 234 Border sliderBorder = new EmptyBorder(5, 5, 5, 5); 235 236 addControlTitle(json.getString("title")); 237 238 Hashtable<Integer, JLabel> labelTable = new Hashtable<>(); 239 240 JsonArray array = json.getJsonArray("scale"); 241 242 String valueType = json.getString("value_type"); 243 244 JSlider slider = null; 245 if (valueType.equals("integer")) { 246 int minValue = array.getInt(0); 247 int maxValue = array.getInt(1); 248 int initValue = json.getInt("default"); 249 250 Main.debug("Slider is integer\n"); 251 Main.debug("minValue: " + String.valueOf(minValue) + 252 "maxValue: " + String.valueOf(maxValue)); 253 try { 254 slider = new JSlider(JSlider.HORIZONTAL, minValue, maxValue, 255 initValue); 256 slider.setName(json.getString("name")); 257 slider.setToolTipText(String.valueOf(slider.getValue())); 258 slider.setMinorTickSpacing(maxValue / 4); 259 } catch(IllegalArgumentException e) { 260 261 JOptionPane.showMessageDialog( 262 Main.parent, 263 tr("JSlider initialization error. Make sure your meta-inf is correct."), 264 tr("Error"), 265 JOptionPane.ERROR_MESSAGE); 266 } 267 268 } else if (valueType.equals("float")) { 269 270 Main.debug("Slider is float\n"); 271 // every value is supplied by 10 to be integer for slider 272 double minValueDouble = array.getJsonNumber(0).doubleValue(); 273 double maxValueDouble = array.getJsonNumber(1).doubleValue(); 274 Main.debug("DminValue: " + String.valueOf(minValueDouble) + 275 "DmaxValue: " + String.valueOf(maxValueDouble)); 276 277 int minValue = (int) (minValueDouble * 100); 278 int maxValue = (int) (maxValueDouble * 100); 279 280 281 double initValue = json.getJsonNumber("default").doubleValue() * 100; 282 double delta = (maxValue - minValue) / 100; 283 284 for (int i = 0; i <= maxValue; i++) { 285 286 if ((i % 20) == 0) { 287 288 labelTable.put(Integer.valueOf(i), 289 new JLabel(String.valueOf(i * delta / 100))); 290 291 } 292 } 293 294 try { 295 296 slider = new JSlider(JSlider.HORIZONTAL, minValue, maxValue, (int) initValue); 297 slider.setMinorTickSpacing(maxValue / 4); 298 slider.setName(json.getString("name")); 299 slider.setToolTipText(String.valueOf((double) slider.getValue() / 100)); 300 301 302 } catch (IllegalArgumentException e) { 303 304 JOptionPane.showMessageDialog( 305 Main.parent, 306 tr("JSlider initialization error. Make sure your meta-inf is correct."), 307 tr("Error"), 308 JOptionPane.ERROR_MESSAGE); 309 } 310 } 311 312 slider.setBackground(this.getBackground()); 313 slider.setBorder(sliderBorder); 314 slider.setPaintTicks(true); 315 slider.setPaintLabels(true); 316 this.add(slider); 317 318 return slider; 319 } 320 321 public void setFilterId(UID filterId) { 322 this.filterId = filterId; 323 } 324 325 public UID getFilterId() { 326 return filterId; 327 } 328 329 public int getNeededHeight() { 330 return neededHeight; 331 } 332 333 public void setNeededHeight(int neededHeight) { 334 this.neededHeight = neededHeight; 335 } 29 private static final long serialVersionUID = 1L; 30 private UID filterId; 31 private int neededHeight; 32 33 public FilterPanel() { 34 super(); 35 setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); 36 setBackground(Color.white); 37 } 38 39 /** 40 * Methods adds GUI element on filter's panel according to meta-information and 41 * automatically resizes the given filter's panel. 42 * 43 * @param json filter's meta-information 44 * @return added GUI element 45 */ 46 public JComponent addGuiElement(JsonObject json) { 47 String type = json.getString("type"); 48 49 if (type.equals("linear_slider")) { 50 51 setNeededHeight(getNeededHeight() + 70); 52 53 return createSlider(json); 54 55 } else if (type.equals("checkbox")) { 56 57 setNeededHeight(getNeededHeight() + 30); 58 59 JCheckBox checkBox = createCheckBox(json.getString("title")); 60 checkBox.setSelected(json.getBoolean("default")); 61 checkBox.setName(json.getString("name")); 62 63 return checkBox; 64 65 } else if (type.equals("select")) { 66 67 setNeededHeight(getNeededHeight() + 50); 68 69 return createSelect(json); 70 71 } else if (type.equals("colorpicker")) { 72 73 setNeededHeight(getNeededHeight() + 220); 74 75 return createColorPicker(json); 76 } 77 return null; 78 } 79 80 private JComponent createSelect(JsonObject json) { 81 82 Font font = new Font("Arial", Font.PLAIN, 14); 83 84 JPanel selectPanel = new JPanel(); 85 86 selectPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); 87 selectPanel.setBackground(Color.white); 88 selectPanel.setLayout(new BoxLayout(selectPanel, BoxLayout.X_AXIS)); 89 selectPanel.setMaximumSize(new Dimension(300, 40)); 90 91 JLabel selectTitle = new JLabel(json.getString("title")); 92 93 selectTitle.setFont(font); 94 selectTitle.setBackground(Color.white); 95 96 JsonArray valuesArray = json.getJsonArray("values"); 97 98 DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(); 99 100 model.setSelectedItem(json.getString("default")); 101 102 for (int i = 0; i < valuesArray.size(); i++) { 103 model.addElement(valuesArray.getString(i)); 104 } 105 106 JComboBox<String> selectBox = new JComboBox<>(model); 107 selectBox.setMinimumSize(new Dimension(140, 30)); 108 109 selectPanel.add(selectTitle); 110 selectPanel.add(Box.createHorizontalGlue()); 111 selectPanel.add(selectBox); 112 selectBox.setName(json.getString("name")); 113 114 this.add(selectPanel); 115 116 return selectBox; 117 } 118 119 public JComponent createColorPicker(JsonObject json) { 120 121 ColorPicker picker = new ColorPicker(false, false); 122 picker.setPreferredSize(new Dimension(200, 180)); 123 picker.setMode(ColorPicker.HUE); 124 picker.setName(json.getString("name")); 125 126 addControlTitle(json.getString("title")); 127 128 this.add(picker); 129 130 return picker; 131 } 132 133 public JCheckBox createCheckBox(String text) { 134 135 JPanel checkBoxPanel = new JPanel(); 136 checkBoxPanel.setMaximumSize(new Dimension(300, 30)); 137 checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.X_AXIS)); 138 checkBoxPanel.setBackground(Color.white); 139 140 JCheckBox checkBox = new JCheckBox(text); 141 Font font = new Font("Arial", Font.PLAIN, 12); 142 143 checkBox.setFont(font); 144 checkBox.setBackground(Color.white); 145 checkBox.setName(text); 146 147 checkBoxPanel.add(checkBox); 148 149 this.add(checkBoxPanel); 150 151 return checkBox; 152 } 153 154 private JCheckBox createDisableBox(ItemListener listener) { 155 JCheckBox disable = new JCheckBox("Disable"); 156 Font font = new Font("Arial", Font.PLAIN, 12); 157 158 disable.addItemListener(listener); 159 disable.setFont(font); 160 161 return disable; 162 } 163 164 private JButton createRemoveButton(ActionListener listener) { 165 JButton removeButton = new JButton("Remove"); 166 Font font = new Font("Arial", Font.PLAIN, 12); 167 168 removeButton.setFont(font); 169 removeButton.setName("remove"); 170 171 removeButton.addActionListener(listener); 172 173 return removeButton; 174 } 175 176 public JPanel createBottomPanel(FiltersManager listener) { 177 178 this.add(Box.createRigidArea(new Dimension(0, 10))); 179 JPanel bottom = new JPanel(); 180 181 bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS)); 182 bottom.setMaximumSize(new Dimension(300, 40)); 183 bottom.setBorder(BorderFactory 184 .createMatteBorder(2, 0, 0, 0, Color.gray)); 185 186 bottom.add(createDisableBox(listener)); 187 bottom.add(Box.createHorizontalGlue()); 188 bottom.add(createRemoveButton(listener)); 189 190 this.add(bottom); 191 192 return bottom; 193 } 194 195 private void addControlTitle(String labelText) { 196 Font labelFont = new Font("Arial", Font.PLAIN, 14); 197 198 JPanel sliderLabelPanel = new JPanel(); 199 sliderLabelPanel.setMaximumSize(new Dimension(400, 30)); 200 sliderLabelPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); 201 sliderLabelPanel.setBackground(Color.white); 202 203 JLabel sliderLabel = new JLabel(labelText, JLabel.LEFT); 204 sliderLabel.setFont(labelFont); 205 sliderLabel.setAlignmentX(Component.LEFT_ALIGNMENT); 206 sliderLabel.setVisible(true); 207 208 sliderLabelPanel.add(sliderLabel); 209 210 this.add(sliderLabelPanel); 211 } 212 213 public JSlider createSlider(JsonObject json) { 214 215 Border sliderBorder = new EmptyBorder(5, 5, 5, 5); 216 217 addControlTitle(json.getString("title")); 218 219 Hashtable<Integer, JLabel> labelTable = new Hashtable<>(); 220 221 JsonArray array = json.getJsonArray("scale"); 222 223 String valueType = json.getString("value_type"); 224 225 JSlider slider = null; 226 if (valueType.equals("integer")) { 227 int minValue = array.getInt(0); 228 int maxValue = array.getInt(1); 229 int initValue = json.getInt("default"); 230 231 Main.debug("Slider is integer\n"); 232 Main.debug("minValue: " + String.valueOf(minValue) + 233 "maxValue: " + String.valueOf(maxValue)); 234 try { 235 slider = new JSlider(JSlider.HORIZONTAL, minValue, maxValue, 236 initValue); 237 slider.setName(json.getString("name")); 238 slider.setToolTipText(String.valueOf(slider.getValue())); 239 slider.setMinorTickSpacing(maxValue / 4); 240 } catch (IllegalArgumentException e) { 241 242 JOptionPane.showMessageDialog( 243 Main.parent, 244 tr("JSlider initialization error. Make sure your meta-inf is correct."), 245 tr("Error"), 246 JOptionPane.ERROR_MESSAGE); 247 } 248 249 } else if (valueType.equals("float")) { 250 251 Main.debug("Slider is float\n"); 252 // every value is supplied by 10 to be integer for slider 253 double minValueDouble = array.getJsonNumber(0).doubleValue(); 254 double maxValueDouble = array.getJsonNumber(1).doubleValue(); 255 Main.debug("DminValue: " + String.valueOf(minValueDouble) + 256 "DmaxValue: " + String.valueOf(maxValueDouble)); 257 258 int minValue = (int) (minValueDouble * 100); 259 int maxValue = (int) (maxValueDouble * 100); 260 261 262 double initValue = json.getJsonNumber("default").doubleValue() * 100; 263 double delta = (maxValue - minValue) / 100; 264 265 for (int i = 0; i <= maxValue; i++) { 266 267 if ((i % 20) == 0) { 268 269 labelTable.put(Integer.valueOf(i), 270 new JLabel(String.valueOf(i * delta / 100))); 271 272 } 273 } 274 275 try { 276 277 slider = new JSlider(JSlider.HORIZONTAL, minValue, maxValue, (int) initValue); 278 slider.setMinorTickSpacing(maxValue / 4); 279 slider.setName(json.getString("name")); 280 slider.setToolTipText(String.valueOf((double) slider.getValue() / 100)); 281 282 283 } catch (IllegalArgumentException e) { 284 285 JOptionPane.showMessageDialog( 286 Main.parent, 287 tr("JSlider initialization error. Make sure your meta-inf is correct."), 288 tr("Error"), 289 JOptionPane.ERROR_MESSAGE); 290 } 291 } 292 293 slider.setBackground(this.getBackground()); 294 slider.setBorder(sliderBorder); 295 slider.setPaintTicks(true); 296 slider.setPaintLabels(true); 297 this.add(slider); 298 299 return slider; 300 } 301 302 public void setFilterId(UID filterId) { 303 this.filterId = filterId; 304 } 305 306 public UID getFilterId() { 307 return filterId; 308 } 309 310 public int getNeededHeight() { 311 return neededHeight; 312 } 313 314 public void setNeededHeight(int neededHeight) { 315 this.neededHeight = neededHeight; 316 } 336 317 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/gui/FilterStateOwner.java
r31504 r32850 2 2 3 3 import org.openstreetmap.josm.plugins.rasterfilters.model.FilterStateModel; 4 4 5 /** 5 6 * Filter state's keeper. This interface is implemented by {@link FilterGuiListeener}. 6 7 * 7 8 * @author Nipel-Crumple 8 *9 9 */ 10 10 public interface FilterStateOwner { 11 11 12 12 public FilterStateModel getState(); 13 13 14 14 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/gui/FiltersDialog.java
r32503 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.gui; 2 2 3 import java.awt.Color; 4 import java.awt.Component; 5 import java.awt.Dimension; 3 import org.openstreetmap.josm.gui.layer.ImageryLayer; 4 import org.openstreetmap.josm.gui.layer.Layer; 5 import org.openstreetmap.josm.plugins.rasterfilters.model.FiltersManager; 6 import org.openstreetmap.josm.plugins.rasterfilters.preferences.FiltersDownloader; 7 8 import javax.swing.*; 9 import javax.swing.border.EmptyBorder; 10 import java.awt.*; 6 11 import java.awt.event.ActionEvent; 7 12 import java.awt.event.ActionListener; … … 10 15 import java.util.Set; 11 16 12 import javax.swing.Box;13 import javax.swing.BoxLayout;14 import javax.swing.DefaultComboBoxModel;15 import javax.swing.JButton;16 import javax.swing.JComboBox;17 import javax.swing.JFrame;18 import javax.swing.JLabel;19 import javax.swing.JPanel;20 import javax.swing.JScrollPane;21 import javax.swing.border.EmptyBorder;22 23 import org.openstreetmap.josm.gui.layer.ImageryLayer;24 import org.openstreetmap.josm.gui.layer.Layer;25 import org.openstreetmap.josm.plugins.rasterfilters.model.FiltersManager;26 import org.openstreetmap.josm.plugins.rasterfilters.preferences.FiltersDownloader;27 28 17 /** 29 18 * This filters is responsible for creating filter's dialog where user can … … 31 20 * 32 21 * @author Nipel-Crumple 33 *34 22 */ 35 23 public class FiltersDialog { 36 24 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 25 public JFrame frame; 26 private JComboBox<String> filterChooser; 27 private JPanel pane; 28 private JButton addButton; 29 private DefaultComboBoxModel<String> listModel = new DefaultComboBoxModel<>(); 30 private Set<String> showedFiltersTitles = new HashSet<>(); 31 private JPanel filterContainer; 32 private Layer layer; 33 private FiltersManager filtersManager; 34 private JScrollPane filterContainerScroll; 35 36 public FiltersDialog(ImageryLayer layer) { 37 this.layer = layer; 38 this.filtersManager = new FiltersManager(this); 39 layer.addImageProcessor(filtersManager); 40 } 41 42 public JPanel createFilterContainer() { 43 if (filterContainer == null) { 44 45 filterContainer = new JPanel(); 46 filterContainer.setLayout(new BoxLayout(getFilterContainer(), 47 BoxLayout.Y_AXIS)); 48 filterContainer.setBackground(Color.white); 49 50 filterContainerScroll = new JScrollPane(getFilterContainer(), 51 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 52 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 53 54 pane.add(filterContainerScroll); 55 56 } 57 58 return filterContainer; 59 } 60 61 public void deleteFilterContainer() { 62 63 Component parent = filterContainerScroll.getParent(); 64 filterContainerScroll.removeAll(); 65 ((JPanel) parent).remove(filterContainerScroll); 66 67 filterContainer = null; 68 69 parent.revalidate(); 70 parent.repaint(); 71 } 72 73 public JFrame createAndShowGUI() throws MalformedURLException { 74 listModel.removeAllElements(); 75 76 Set<String> filterTitles = FiltersDownloader.filterTitles; 77 78 for (String temp : filterTitles) { 79 80 if (!showedFiltersTitles.contains(temp)) { 81 listModel.addElement(temp); 82 } 83 84 } 85 86 if (frame != null) { 87 88 filterChooser.setModel(listModel); 89 filterChooser.revalidate(); 90 frame.setVisible(true); 91 92 } else { 93 94 frame = new JFrame(); 95 String title = "Filters | " + layer.getName(); 96 frame.setTitle(title); 97 frame.setMinimumSize(new Dimension(350, 420)); 98 frame.setPreferredSize(new Dimension(350, 420)); 99 100 pane = new JPanel(); 101 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); 102 103 pane.setBorder(new EmptyBorder(10, 5, 10, 5)); 104 pane.setPreferredSize(new Dimension(300, 400)); 105 pane.setBackground(Color.white); 106 107 JPanel topPanel = new JPanel(); 108 topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS)); 109 topPanel.setMaximumSize(new Dimension(300, 50)); 110 topPanel.setMinimumSize(new Dimension(300, 50)); 111 topPanel.setBackground(Color.white); 112 113 JPanel labelPanel = new JPanel(); 114 labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.X_AXIS)); 115 labelPanel.setMaximumSize(new Dimension(300, 20)); 116 labelPanel.setBackground(Color.white); 117 118 JLabel label = new JLabel("Add filter"); 119 labelPanel.add(label); 120 // pane.add(labelPanel); 121 122 // TODO why after add clicked the top panel is resized??? 123 124 // panel that contains the checkBox and add button 125 JPanel chooseFilterPanel = new JPanel(); 126 chooseFilterPanel.setMinimumSize(new Dimension(300, 30)); 127 chooseFilterPanel.setLayout(new BoxLayout(chooseFilterPanel, 128 BoxLayout.X_AXIS)); 129 chooseFilterPanel.setBackground(Color.white); 130 131 filterChooser = new JComboBox<>(getListModel()); 132 filterChooser.setMaximumSize(new Dimension(200, 30)); 133 chooseFilterPanel.add(filterChooser); 134 135 // empty space area between select and add button 136 chooseFilterPanel.add(Box.createRigidArea(new Dimension(10, 0))); 137 138 addButton = new JButton(); 139 addButton.setText("add"); 140 addButton.setAlignmentX(Component.CENTER_ALIGNMENT); 141 addButton.setMaximumSize(new Dimension(90, 30)); 142 addButton.addActionListener(new AddFilterToPanelListener()); 143 // 144 // // check if there is no meta information 145 // Main.debug("Empty " + 146 // String.valueOf(FiltersDownloader.filterTitles.isEmpty())); 147 // if (FiltersDownloader.filterTitles.isEmpty() || 148 // listModel.getSize() == 0) { 149 // addButton.setEnabled(false); 150 // filterChooser.setEnabled(false); 151 // } else { 152 // addButton.setEnabled(true); 153 // filterChooser.setEnabled(true); 154 // } 155 156 chooseFilterPanel.add(getAddButton()); 157 158 topPanel.add(labelPanel); 159 topPanel.add(chooseFilterPanel); 160 pane.add(topPanel); 161 // pane.add(chooseFilterPanel); 162 // pane.add(Box.createRigidArea(new Dimension(0, 20))); 163 164 frame.setContentPane(pane); 165 frame.pack(); 166 frame.setVisible(true); 167 } 168 169 if (FiltersDownloader.filterTitles.isEmpty() 170 || listModel.getSize() == 0) { 171 addButton.setEnabled(false); 172 filterChooser.setEnabled(false); 173 } else { 174 addButton.setEnabled(true); 175 filterChooser.setEnabled(true); 176 } 177 178 return frame; 179 } 180 181 public FiltersManager createFilterManager() { 182 return new FiltersManager(this); 183 } 184 185 public void closeFrame() { 186 if (frame != null) { 187 if (frame.isShowing()) { 188 frame.dispose(); 189 } 190 } 191 } 192 193 public FiltersManager getFiltersManager() { 194 return filtersManager; 195 } 196 197 class AddFilterToPanelListener implements ActionListener { 198 199 @Override 200 public void actionPerformed(ActionEvent e) { 201 202 String title = (String) listModel.getSelectedItem(); 203 JPanel panel = null; 204 205 panel = filtersManager.createPanelByTitle(title); 206 207 if (panel != null) { 208 filterContainer = createFilterContainer(); 209 filterContainer.add(panel); 210 } 211 212 listModel.removeElement(title); 213 showedFiltersTitles.add(title); 214 215 if (listModel.getSize() == 0) { 216 filterChooser.setEnabled(false); 217 addButton.setEnabled(false); 218 } 219 220 } 221 } 222 223 public Set<String> getShowedFiltersTitles() { 224 return showedFiltersTitles; 225 } 226 227 public Layer getLayer() { 228 return layer; 229 } 230 231 public JPanel getFilterContainer() { 232 return filterContainer; 233 } 234 235 public DefaultComboBoxModel<String> getListModel() { 236 return listModel; 237 } 238 239 public JComboBox<String> getFilterChooser() { 240 return filterChooser; 241 } 242 243 public JButton getAddButton() { 244 return addButton; 245 } 258 246 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/model/FilterStateModel.java
r31504 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.model; 2 2 3 import java.awt.Color; 3 import org.openstreetmap.josm.plugins.rasterfilters.values.*; 4 5 import javax.json.Json; 6 import javax.json.JsonObject; 7 import javax.json.JsonObjectBuilder; 8 import java.awt.*; 4 9 import java.util.HashMap; 5 10 import java.util.Map; 6 11 import java.util.Map.Entry; 7 12 8 import javax.json.Json;9 import javax.json.JsonObject;10 import javax.json.JsonObjectBuilder;11 12 import org.openstreetmap.josm.plugins.rasterfilters.values.BooleanValue;13 import org.openstreetmap.josm.plugins.rasterfilters.values.ColorValue;14 import org.openstreetmap.josm.plugins.rasterfilters.values.SelectValue;15 import org.openstreetmap.josm.plugins.rasterfilters.values.SliderValue;16 import org.openstreetmap.josm.plugins.rasterfilters.values.Value;17 13 /** 18 14 * Filter state's model which stores all parameters of … … 22 18 * 23 19 * @author Nipel-Crumple 24 *25 20 */ 26 21 public class FilterStateModel { 27 22 28 29 23 private Map<String, Value<?>> params = new HashMap<>(); 24 private String filterClassName; 30 25 31 26 public FilterStateModel() { 32 27 33 28 } 34 29 35 36 37 30 public Map<String, Value<?>> getParams() { 31 return params; 32 } 38 33 39 40 41 34 public String getFilterClassName() { 35 return filterClassName; 36 } 42 37 43 44 45 38 public void setFilterClassName(String filterClassName) { 39 this.filterClassName = filterClassName; 40 } 46 41 47 42 public void addParams(JsonObject json) { 48 43 49 50 44 String parameterName = json.getString("name"); 45 String valueType = json.getString("value_type"); 51 46 52 53 54 47 // setting up the beginning state of filter 48 // according to its metainfo 49 if (json.getString("type").equals("linear_slider")) { 55 50 56 51 if (valueType.equals("float") || valueType.equals("double")) { 57 52 58 59 53 double defaultValue = json.getJsonNumber("default") 54 .doubleValue(); 60 55 61 62 63 56 SliderValue<Double> value = new SliderValue<>(parameterName, 57 defaultValue); 58 params.put(parameterName, value); 64 59 65 60 } else if (valueType.equals("integer")) { 66 61 67 62 int defaultValue = json.getJsonNumber("default").intValue(); 68 63 69 70 71 64 SliderValue<Integer> value = new SliderValue<>(parameterName, 65 defaultValue); 66 params.put(parameterName, value); 72 67 73 68 } 74 69 75 70 } else if (json.getString("type").equals("checkbox")) { 76 71 77 72 boolean defaultValue = json.getBoolean("default"); 78 73 79 80 74 BooleanValue value = new BooleanValue(parameterName, defaultValue); 75 params.put(parameterName, value); 81 76 82 77 } else if (json.getString("type").equals("select")) { 83 78 84 79 String defaultValue = json.getString("default"); 85 80 86 87 88 81 SelectValue<String> value = new SelectValue<>(parameterName, 82 defaultValue); 83 params.put(parameterName, value); 89 84 90 85 } else if (json.getString("type").equals("colorpicker")) { 91 86 92 93 94 95 87 JsonObject defaultColorJson = json.getJsonObject("default"); 88 int r = defaultColorJson.getInt("red"); 89 int g = defaultColorJson.getInt("green"); 90 int b = defaultColorJson.getInt("blue"); 96 91 97 92 Color defaultColor = new Color(r, g, b); 98 93 99 100 101 94 ColorValue<Color> value = new ColorValue<>(parameterName, 95 defaultColor); 96 params.put(parameterName, value); 102 97 103 104 98 } 99 } 105 100 106 107 108 109 110 111 101 /** 102 * Method generates json from the current filter's model state. 103 * 104 * @return encoded json which describes current filter's state 105 */ 106 public JsonObject encodeJson() { 112 107 113 108 JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); 114 109 115 110 for (Entry<String, Value<?>> entry : params.entrySet()) { 116 111 117 112 Object value = entry.getValue().getValue(); 118 113 119 114 if (value instanceof String) { 120 115 121 122 123 116 jsonBuilder.add(entry.getKey(), 117 Json.createObjectBuilder().add("value", (String) value) 118 .build()); 124 119 125 120 } 126 121 127 128 129 130 131 122 if (value instanceof Boolean) { 123 jsonBuilder.add(entry.getKey(), 124 Json.createObjectBuilder() 125 .add("value", (Boolean) value).build()); 126 } 132 127 133 128 if (value instanceof Number) { 134 129 135 130 if (value instanceof Double) { 136 131 137 138 132 jsonBuilder.add(entry.getKey(), Json.createObjectBuilder() 133 .add("value", (Double) value).build()); 139 134 140 135 } else if (value instanceof Integer) { 141 136 142 143 137 jsonBuilder.add(entry.getKey(), Json.createObjectBuilder() 138 .add("value", (Integer) value).build()); 144 139 145 146 140 } 141 } 147 142 148 143 if (value instanceof Color) { 149 144 150 151 152 153 154 155 156 157 145 jsonBuilder.add(entry.getKey(), 146 Json.createObjectBuilder() 147 .add("value", Json.createObjectBuilder() 148 .add("red", ((Color) value).getRed()) 149 .add("green", ((Color) value).getGreen()) 150 .add("blue", ((Color) value).getBlue()) 151 .build()) 152 .build()); 158 153 159 160 154 } 155 } 161 156 162 163 157 return jsonBuilder.build(); 158 } 164 159 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/model/FiltersManager.java
r32754 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.model; 2 2 3 import java.awt.Dimension; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.ActionListener; 6 import java.awt.event.ItemEvent; 7 import java.awt.event.ItemListener; 8 import java.awt.image.BufferedImage; 9 import java.rmi.server.UID; 10 import java.util.HashSet; 11 import java.util.Iterator; 12 import java.util.LinkedHashMap; 13 import java.util.Map; 14 import java.util.Set; 15 16 import javax.json.JsonArray; 17 import javax.json.JsonObject; 18 import javax.swing.BorderFactory; 19 import javax.swing.JButton; 20 import javax.swing.JCheckBox; 21 import javax.swing.JComboBox; 22 import javax.swing.JComponent; 23 import javax.swing.JPanel; 24 import javax.swing.JSlider; 25 3 import com.bric.swing.ColorPicker; 26 4 import org.openstreetmap.josm.Main; 27 5 import org.openstreetmap.josm.gui.layer.ImageProcessor; … … 32 10 import org.openstreetmap.josm.plugins.rasterfilters.preferences.FiltersDownloader; 33 11 34 import com.bric.swing.ColorPicker; 12 import javax.json.JsonArray; 13 import javax.json.JsonObject; 14 import javax.swing.*; 15 import java.awt.*; 16 import java.awt.event.ActionEvent; 17 import java.awt.event.ActionListener; 18 import java.awt.event.ItemEvent; 19 import java.awt.event.ItemListener; 20 import java.awt.image.BufferedImage; 21 import java.rmi.server.UID; 22 import java.util.*; 23 35 24 /** 36 25 * This class adds filter to the dialog and can also remove … … 38 27 * 39 28 * @author Nipel-Crumple 40 *41 29 */ 42 30 public class FiltersManager implements StateChangeListener, ImageProcessor, 43 ActionListener, ItemListener { 44 45 public Map<UID, Filter> filtersMap = new LinkedHashMap<>(); 46 public Set<Filter> disabledFilters = new HashSet<>(); 47 public FiltersDialog dialog; 48 49 public FiltersManager(FiltersDialog dialog) { 50 this.dialog = dialog; 51 } 52 53 @SuppressWarnings("unchecked") 54 private JPanel createFilterWithPanel(JsonObject meta) { 55 56 FilterPanel fp = new FilterPanel(); 57 58 // listener to track sliders and checkbox of creating filter 59 FilterGuiListener filterListener = new FilterGuiListener(this); 60 61 String filterClassName = meta.getString("classname"); 62 63 String filterTitle = meta.getString("title"); 64 65 fp.setName(filterTitle); 66 67 // creating model of the filter 68 FilterStateModel filterState = new FilterStateModel(); 69 filterState.setFilterClassName(filterClassName); 70 71 // loading jar with filter at runtime 72 Class<?> clazz; 73 74 // filter for adding to map states 75 Filter filter = null; 76 77 try { 78 Main.debug("ClassName for loading " + filterState.getFilterClassName()); 79 clazz = FiltersDownloader.loader.loadClass(filterState 80 .getFilterClassName()); 81 filter = (Filter) clazz.getConstructor().newInstance(); 82 83 } catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) { 84 e.printStackTrace(); 85 } 86 87 if (filter != null) { 88 89 UID filterId = new UID(); 90 fp.setFilterId(filterId); 91 filterListener.setFilterId(filterId); 92 filter.setId(filterId); 93 filtersMap.put(filterId, filter); 94 95 // all filters enabled in the beggining by default 96 } 97 98 fp.setBorder(BorderFactory.createTitledBorder(meta.getString("title"))); 99 100 JsonArray controls = meta.getJsonArray("controls"); 101 102 for (int i = 0; i < controls.size(); i++) { 103 104 JsonObject temp = controls.getJsonObject(i); 105 // Main.debug(temp.toString()); 106 107 JComponent component = fp.addGuiElement(temp); 108 109 if (component != null) { 110 111 if (component instanceof JSlider) { 112 ((JSlider) component).addChangeListener(filterListener); 113 } else if (component instanceof JCheckBox) { 114 ((JCheckBox) component).addItemListener(filterListener); 115 } else if (component instanceof JComboBox) { 116 ((JComboBox<String>) component).addActionListener(filterListener); 117 } else if (component instanceof ColorPicker) { 118 ((ColorPicker) component).addPropertyChangeListener(filterListener); 119 } 120 121 // adding parameters to the filter instance 122 filterState.addParams(temp); 123 } 124 } 125 126 fp.setNeededHeight(fp.getNeededHeight() + 60); 127 fp.setMaximumSize(new Dimension(300, fp.getNeededHeight())); 128 fp.setPreferredSize(new Dimension(300, fp.getNeededHeight())); 129 130 if (filter != null) { 131 filter.changeFilterState(filterState.encodeJson()); 132 } 133 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 134 135 fp.createBottomPanel(this); 136 137 filterListener.setFilterState(filterState); 138 139 Main.debug("The number of elems in the Filters map is equal \n" 140 + filtersMap.size()); 141 142 return fp; 143 } 144 145 /** 146 * The method notifies about changes in the filter's status. 147 * 148 * @param filterState 149 * - model that contains info about filter which was changed 150 */ 151 @Override 152 public void filterStateChanged(UID filterId, FilterStateModel filterState) { 153 154 if (filtersMap.get(filterId) != null) 155 filtersMap.get(filterId).changeFilterState(filterState.encodeJson()); 156 157 if (Main.getLayerManager().getActiveLayer() != null) { 158 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 159 } 160 161 } 162 163 public JPanel createPanelByTitle(String title) { 164 165 for (JsonObject json : FiltersDownloader.filtersMeta) { 166 167 if (json.getString("title").equals(title)) { 168 return createFilterWithPanel(json); 169 } 170 } 171 172 return null; 173 } 174 175 @Override 176 public BufferedImage process(BufferedImage image) { 177 178 Iterator<Filter> it = filtersMap.values().iterator(); 179 180 // iterating through map of filters according to the order 181 while (it.hasNext()) { 182 183 Filter curFilter = it.next(); 184 185 if (!disabledFilters.contains(curFilter)) { 186 // if next filter will return null 187 // we should take an old example of the image 188 BufferedImage oldImg = image; 189 190 // applying filter to the current image 191 image = curFilter.applyFilter(image); 192 193 if (image == null) { 194 image = oldImg; 195 } 196 } 197 } 198 199 return image; 200 } 201 202 @Override 203 public void actionPerformed(ActionEvent e) { 204 205 FilterPanel filterPanel = (FilterPanel) ((JButton) e.getSource()) 206 .getParent().getParent(); 207 208 UID filterId = filterPanel.getFilterId(); 209 210 // removing filter from the filters chain 211 filtersMap.remove(filterId); 212 213 dialog.getShowedFiltersTitles().remove(filterPanel.getName()); 214 215 // add filterTitle to the 'choose list' on the top 216 dialog.getListModel().addElement(filterPanel.getName()); 217 218 // removing panel from filterContainer 219 filterPanel.removeAll(); 220 dialog.getFilterContainer().remove(filterPanel); 221 222 if (dialog.getFilterContainer().getComponentCount() == 0) { 223 224 dialog.deleteFilterContainer(); 225 226 } else { 227 228 dialog.getFilterContainer().revalidate(); 229 dialog.getFilterContainer().repaint(); 230 231 } 232 233 // if there were no elements in the list 234 // but then it appeared 235 // button should be enabled 236 if (!dialog.getAddButton().isEnabled()) { 237 dialog.getFilterChooser().setEnabled(true); 238 dialog.getAddButton().setEnabled(true); 239 } 240 241 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 242 243 } 244 245 @Override 246 public void itemStateChanged(ItemEvent e) { 247 248 JCheckBox enableFilter = (JCheckBox) e.getSource(); 249 FilterPanel filterPanel = (FilterPanel) enableFilter.getParent() 250 .getParent(); 251 252 if (enableFilter.isSelected()) { 253 254 UID filterId = filterPanel.getFilterId(); 255 disabledFilters.add(filtersMap.get(filterId)); 256 257 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 258 259 } else { 260 261 UID filterId = filterPanel.getFilterId(); 262 disabledFilters.remove(filtersMap.get(filterId)); 263 264 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 265 266 } 267 } 31 ActionListener, ItemListener { 32 33 public Map<UID, Filter> filtersMap = new LinkedHashMap<>(); 34 public Set<Filter> disabledFilters = new HashSet<>(); 35 public FiltersDialog dialog; 36 37 public FiltersManager(FiltersDialog dialog) { 38 this.dialog = dialog; 39 } 40 41 @SuppressWarnings("unchecked") 42 private JPanel createFilterWithPanel(JsonObject meta) { 43 44 FilterPanel fp = new FilterPanel(); 45 46 // listener to track sliders and checkbox of creating filter 47 FilterGuiListener filterListener = new FilterGuiListener(this); 48 49 String filterClassName = meta.getString("classname"); 50 51 String filterTitle = meta.getString("title"); 52 53 fp.setName(filterTitle); 54 55 // creating model of the filter 56 FilterStateModel filterState = new FilterStateModel(); 57 filterState.setFilterClassName(filterClassName); 58 59 // loading jar with filter at runtime 60 Class<?> clazz; 61 62 // filter for adding to map states 63 Filter filter = null; 64 65 try { 66 Main.debug("ClassName for loading " + filterState.getFilterClassName()); 67 clazz = FiltersDownloader.loader.loadClass(filterState 68 .getFilterClassName()); 69 filter = (Filter) clazz.getConstructor().newInstance(); 70 71 } catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) { 72 e.printStackTrace(); 73 } 74 75 if (filter != null) { 76 77 UID filterId = new UID(); 78 fp.setFilterId(filterId); 79 filterListener.setFilterId(filterId); 80 filter.setId(filterId); 81 filtersMap.put(filterId, filter); 82 83 // all filters enabled in the beggining by default 84 } 85 86 fp.setBorder(BorderFactory.createTitledBorder(meta.getString("title"))); 87 88 JsonArray controls = meta.getJsonArray("controls"); 89 90 for (int i = 0; i < controls.size(); i++) { 91 92 JsonObject temp = controls.getJsonObject(i); 93 // Main.debug(temp.toString()); 94 95 JComponent component = fp.addGuiElement(temp); 96 97 if (component != null) { 98 99 if (component instanceof JSlider) { 100 ((JSlider) component).addChangeListener(filterListener); 101 } else if (component instanceof JCheckBox) { 102 ((JCheckBox) component).addItemListener(filterListener); 103 } else if (component instanceof JComboBox) { 104 ((JComboBox<String>) component).addActionListener(filterListener); 105 } else if (component instanceof ColorPicker) { 106 ((ColorPicker) component).addPropertyChangeListener(filterListener); 107 } 108 109 // adding parameters to the filter instance 110 filterState.addParams(temp); 111 } 112 } 113 114 fp.setNeededHeight(fp.getNeededHeight() + 60); 115 fp.setMaximumSize(new Dimension(300, fp.getNeededHeight())); 116 fp.setPreferredSize(new Dimension(300, fp.getNeededHeight())); 117 118 if (filter != null) { 119 filter.changeFilterState(filterState.encodeJson()); 120 } 121 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 122 123 fp.createBottomPanel(this); 124 125 filterListener.setFilterState(filterState); 126 127 Main.debug("The number of elems in the Filters map is equal \n" 128 + filtersMap.size()); 129 130 return fp; 131 } 132 133 /** 134 * The method notifies about changes in the filter's status. 135 * 136 * @param filterState - model that contains info about filter which was changed 137 */ 138 @Override 139 public void filterStateChanged(UID filterId, FilterStateModel filterState) { 140 141 if (filtersMap.get(filterId) != null) 142 filtersMap.get(filterId).changeFilterState(filterState.encodeJson()); 143 144 if (Main.getLayerManager().getActiveLayer() != null) { 145 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 146 } 147 148 } 149 150 public JPanel createPanelByTitle(String title) { 151 152 for (JsonObject json : FiltersDownloader.filtersMeta) { 153 154 if (json.getString("title").equals(title)) { 155 return createFilterWithPanel(json); 156 } 157 } 158 159 return null; 160 } 161 162 @Override 163 public BufferedImage process(BufferedImage image) { 164 165 Iterator<Filter> it = filtersMap.values().iterator(); 166 167 // iterating through map of filters according to the order 168 while (it.hasNext()) { 169 170 Filter curFilter = it.next(); 171 172 if (!disabledFilters.contains(curFilter)) { 173 // if next filter will return null 174 // we should take an old example of the image 175 BufferedImage oldImg = image; 176 177 // applying filter to the current image 178 image = curFilter.applyFilter(image); 179 180 if (image == null) { 181 image = oldImg; 182 } 183 } 184 } 185 186 return image; 187 } 188 189 @Override 190 public void actionPerformed(ActionEvent e) { 191 192 FilterPanel filterPanel = (FilterPanel) ((JButton) e.getSource()) 193 .getParent().getParent(); 194 195 UID filterId = filterPanel.getFilterId(); 196 197 // removing filter from the filters chain 198 filtersMap.remove(filterId); 199 200 dialog.getShowedFiltersTitles().remove(filterPanel.getName()); 201 202 // add filterTitle to the 'choose list' on the top 203 dialog.getListModel().addElement(filterPanel.getName()); 204 205 // removing panel from filterContainer 206 filterPanel.removeAll(); 207 dialog.getFilterContainer().remove(filterPanel); 208 209 if (dialog.getFilterContainer().getComponentCount() == 0) { 210 211 dialog.deleteFilterContainer(); 212 213 } else { 214 215 dialog.getFilterContainer().revalidate(); 216 dialog.getFilterContainer().repaint(); 217 218 } 219 220 // if there were no elements in the list 221 // but then it appeared 222 // button should be enabled 223 if (!dialog.getAddButton().isEnabled()) { 224 dialog.getFilterChooser().setEnabled(true); 225 dialog.getAddButton().setEnabled(true); 226 } 227 228 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 229 230 } 231 232 @Override 233 public void itemStateChanged(ItemEvent e) { 234 235 JCheckBox enableFilter = (JCheckBox) e.getSource(); 236 FilterPanel filterPanel = (FilterPanel) enableFilter.getParent() 237 .getParent(); 238 239 if (enableFilter.isSelected()) { 240 241 UID filterId = filterPanel.getFilterId(); 242 disabledFilters.add(filtersMap.get(filterId)); 243 244 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 245 246 } else { 247 248 UID filterId = filterPanel.getFilterId(); 249 disabledFilters.remove(filtersMap.get(filterId)); 250 251 Main.getLayerManager().getActiveLayer().setFilterStateChanged(); 252 253 } 254 } 268 255 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/model/StateChangeListener.java
r31504 r32850 6 6 * Interface that notifies about filter's state is changed. 7 7 * This interface is implemented by {@link FiltersManager}. 8 * 8 9 * @author Nipel-Crumple 9 *10 10 */ 11 11 public interface StateChangeListener { 12 12 13 13 public void filterStateChanged(UID filterId, FilterStateModel filterState); 14 14 15 15 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/preferences/FiltersDownloader.java
r32754 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.preferences; 2 3 import java.awt.event.ActionEvent;4 import java.awt.event.ActionListener;5 import java.io.BufferedInputStream;6 import java.io.BufferedOutputStream;7 import java.io.BufferedReader;8 import java.io.BufferedWriter;9 import java.io.File;10 import java.io.FileOutputStream;11 import java.io.FileReader;12 import java.io.FileWriter;13 import java.io.IOException;14 import java.io.InputStreamReader;15 import java.io.OutputStream;16 import java.io.StringReader;17 import java.net.HttpURLConnection;18 import java.net.MalformedURLException;19 import java.net.URL;20 import java.net.URLClassLoader;21 import java.net.URLConnection;22 import java.nio.charset.StandardCharsets;23 import java.nio.file.Files;24 import java.util.ArrayList;25 import java.util.HashMap;26 import java.util.HashSet;27 import java.util.List;28 import java.util.Map;29 import java.util.Random;30 import java.util.Set;31 import java.util.TreeSet;32 import java.util.regex.Matcher;33 import java.util.regex.Pattern;34 35 import javax.json.Json;36 import javax.json.JsonArray;37 import javax.json.JsonObject;38 import javax.json.JsonReader;39 2 40 3 import org.jsoup.Jsoup; … … 43 6 import org.jsoup.select.Elements; 44 7 import org.openstreetmap.josm.Main; 8 9 import javax.json.Json; 10 import javax.json.JsonArray; 11 import javax.json.JsonObject; 12 import javax.json.JsonReader; 13 import java.awt.event.ActionEvent; 14 import java.awt.event.ActionListener; 15 import java.io.*; 16 import java.net.*; 17 import java.nio.charset.StandardCharsets; 18 import java.nio.file.Files; 19 import java.util.*; 20 import java.util.regex.Matcher; 21 import java.util.regex.Pattern; 22 45 23 /** 46 24 * This class is responsible for downloading jars which contains … … 52 30 */ 53 31 public class FiltersDownloader implements ActionListener { 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 32 private static volatile String pluginDir; 33 34 public static Set<JsonObject> filtersMeta = new HashSet<>(); 35 public static Set<String> filterTitles = new TreeSet<>(); 36 public static Set<URL> binariesLocalUrls = new HashSet<>(); 37 public static ClassLoader loader; 38 public static Map<String, String> urlsMap = new HashMap<>(); 39 40 private static Set<JsonObject> filtersMetaToLoad = new HashSet<>(); 41 static List<FilterInfo> filtersInfoList = new ArrayList<>(); 42 43 public static List<FilterInfo> downloadFiltersInfoList() { 44 45 JsonObject jsonRequest = Json 46 .createObjectBuilder() 47 .add("id", new Random().nextInt()) 48 .add("method", "wiki.getPageHTML") 49 .add("params", 50 Json.createArrayBuilder().add("ImageFilters").build()) 51 .build(); 52 53 String jsonRequestString = jsonRequest.toString(); 54 55 URL wikiApi; 56 HttpURLConnection wikiConnection; 57 try { 58 wikiApi = new URL("https://josm.openstreetmap.de/jsonrpc"); 59 wikiConnection = (HttpURLConnection) wikiApi.openConnection(); 60 wikiConnection.setDoOutput(true); 61 wikiConnection.setDoInput(true); 62 63 wikiConnection.setRequestProperty("Content-Type", 64 "application/json"); 65 wikiConnection.setRequestProperty("Method", "POST"); 66 wikiConnection.connect(); 67 68 OutputStream os = wikiConnection.getOutputStream(); 69 os.write(jsonRequestString.getBytes("UTF-8")); 70 os.close(); 71 72 int HttpResult = wikiConnection.getResponseCode(); 73 if (HttpResult == HttpURLConnection.HTTP_OK) { 74 75 JsonReader jsonStream = Json 76 .createReader(new InputStreamReader(wikiConnection 77 .getInputStream(), "utf-8")); 78 79 JsonObject jsonResponse = jsonStream.readObject(); 80 jsonStream.close(); 81 82 Elements trTagElems = Jsoup.parse( 83 jsonResponse.getString("result")) 84 .getElementsByTag("tr"); 85 for (Element element : trTagElems) { 86 87 Elements elems = element.getElementsByTag("td"); 88 if (!elems.isEmpty()) { 89 String name = elems.get(0).text(); 90 String owner = elems.get(1).text(); 91 String description = elems.get(2).text(); 92 93 String link = elems.get(0).getElementsByTag("a") 94 .attr("href"); 95 96 JsonObject meta = loadMeta(link); 97 98 String paramName = "rasterfilters." 99 + meta.getString("name"); 100 101 boolean needToLoad = Main.pref.getBoolean(paramName); 102 103 if (needToLoad) { 104 JsonArray binaries = meta.getJsonArray("binaries"); 105 filterTitles.add(meta.getString("title")); 106 for (int i = 0; i < binaries.size(); i++) { 107 filtersMetaToLoad.add(meta); 108 loadBinaryToFile(binaries.getString(i)); 109 } 110 } 111 FilterInfo newFilterInfo = new FilterInfo(name, 112 description, meta, needToLoad); 113 newFilterInfo.setOwner(owner); 114 115 if (!filtersInfoList.contains(newFilterInfo)) { 116 filtersInfoList.add(newFilterInfo); 117 } 118 } 119 } 120 121 } else { 122 Main.debug("Error happenned while requesting for the list of filters"); 123 } 124 } catch (IOException e1) { 125 // TODO Auto-generated catch block 126 e1.printStackTrace(); 127 } 128 129 loadBinariesFromMeta(filtersMetaToLoad); 130 131 return filtersInfoList; 132 } 133 134 public static JsonObject loadMeta(String link) { 135 136 Pattern p = Pattern.compile("ImageFilters/\\w.*"); 137 Matcher m = p.matcher(link); 138 139 if (m.find()) { 140 link = link.substring(m.start()); 141 } 142 143 JsonObject jsonRequest = Json.createObjectBuilder() 144 .add("id", new Random().nextInt()) 145 .add("method", "wiki.getPageHTML") 146 .add("params", Json.createArrayBuilder().add(link).build()) 147 .build(); 148 149 String jsonStringRequest = jsonRequest.toString(); 150 151 URL wikiApi; 152 HttpURLConnection wikiConnection; 153 JsonObject meta = null; 154 155 try { 156 wikiApi = new URL("https://josm.openstreetmap.de/jsonrpc"); 157 wikiConnection = (HttpURLConnection) wikiApi.openConnection(); 158 wikiConnection.setDoOutput(true); 159 wikiConnection.setDoInput(true); 160 161 wikiConnection.setRequestProperty("Content-Type", 162 "application/json"); 163 wikiConnection.setRequestProperty("Method", "POST"); 164 wikiConnection.connect(); 165 166 OutputStream os = wikiConnection.getOutputStream(); 167 os.write(jsonStringRequest.getBytes("UTF-8")); 168 os.close(); 169 170 int HttpResult = wikiConnection.getResponseCode(); 171 if (HttpResult == HttpURLConnection.HTTP_OK) { 172 173 JsonReader jsonStream = Json 174 .createReader(new InputStreamReader(wikiConnection 175 .getInputStream(), "UTF-8")); 176 177 JsonObject jsonResponse = jsonStream.readObject(); 178 jsonStream.close(); 179 180 String jsonPage = jsonResponse.getString("result"); 181 182 Document doc = Jsoup.parse(jsonPage, "UTF-8"); 183 String json = doc.getElementsByTag("pre").first().text(); 184 185 JsonReader reader = Json.createReader(new StringReader(json)); 186 meta = reader.readObject(); 187 reader.close(); 188 189 } else { 190 Main.debug(wikiConnection.getResponseMessage()); 191 } 192 } catch (IOException e1) { 193 e1.printStackTrace(); 194 } 195 196 filtersMeta.add(meta); 197 198 return meta; 199 } 200 201 public static void initFilters() { 202 File file = new File(pluginDir, "urls.map"); 203 Main.debug("EXIST FILE? " + file.exists()); 204 205 try (BufferedReader br = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) { 206 String temp; 207 208 while ((temp = br.readLine()) != null) { 209 String[] mapEntry = temp.split("\\t"); 210 File fileUrl = new File(mapEntry[1]); 211 if (fileUrl.exists()) { 212 URL url; 213 try { 214 url = new URL("jar", "", fileUrl.toURI().toURL() + "!/"); 215 Main.debug("binaryUrl: " + url.toString()); 216 binariesLocalUrls.add(url); 217 } catch (MalformedURLException e) { 218 Main.debug("Initializing filters with unknown protocol. \n" 219 + e.getMessage()); 220 } 221 } 222 } 223 } catch (IOException e) { 224 e.printStackTrace(); 225 } 226 227 Main.debug("BinariesLocal : " + binariesLocalUrls.toString()); 228 229 loader = new URLClassLoader( 230 binariesLocalUrls.toArray(new URL[binariesLocalUrls.size()]), 231 FiltersDownloader.class.getClassLoader()); 232 } 233 234 public static void destroyFilters() { 235 filterTitles.clear(); 236 binariesLocalUrls.clear(); 237 FiltersDownloader.filtersMeta.clear(); 238 } 239 240 @Override 241 public void actionPerformed(ActionEvent e) { 242 243 for (FilterInfo temp : filtersInfoList) { 244 if (temp.isNeedToDownload()) { 245 246 if (!filtersMetaToLoad.contains(temp.getMeta())) { 247 filtersMetaToLoad.add(temp.getMeta()); 248 } 249 250 filterTitles.add(temp.getMeta().getString("title")); 251 } else { 252 filterTitles.remove(temp.getMeta().getString("title")); 253 } 254 } 255 256 loadBinariesFromMeta(filtersMetaToLoad); 257 258 filtersMetaToLoad.clear(); 259 } 260 261 public static void loadBinariesFromMeta(Set<JsonObject> metaList) { 262 263 File file = new File(pluginDir, "urls.map"); 264 Main.debug("pluginDir and urls map" + file.getAbsoluteFile()); 265 266 try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) { 267 for (JsonObject temp : metaList) { 268 JsonArray binaries = temp.getJsonArray("binaries"); 269 270 for (int i = 0; i < binaries.size(); i++) { 271 272 String localFile = loadBinaryToFile(binaries.getString(i)); 273 274 try { 275 writer.append(binaries.getString(i)); 276 writer.append("\t"); 277 writer.append(localFile); 278 writer.append("\n"); 279 } catch (IOException e) { 280 e.printStackTrace(); 281 } 282 } 283 } 284 } catch (IOException e) { 285 e.printStackTrace(); 286 } 287 } 288 289 public static void setPluginDir(String dir) { 290 pluginDir = dir; 291 } 292 293 public static String loadBinaryToFile(String fromUrl) { 294 295 // Main.debug("Need to load binary from " + fromUrl); 296 297 URL url = null; 298 URLConnection con = null; 299 300 Pattern p = Pattern.compile("\\w.*/"); 301 Matcher m = p.matcher(fromUrl); 302 303 String localFile = null; 304 File plugin = new File(pluginDir); 305 Main.debug("plugin dir" + plugin.getAbsolutePath()); 306 307 if (m.find()) { 308 309 if (plugin.exists()) { 310 311 localFile = fromUrl.substring(m.end()); 312 Main.debug("localFile: " + localFile); 313 } 314 } 315 316 try { 317 url = new URL(fromUrl); 318 con = url.openConnection(); 319 String plugDir = plugin.getAbsolutePath(); 320 File file = new File(plugDir, localFile); 321 Main.debug("Binary file: " + file.getAbsolutePath()); 322 323 if (file.exists()) { 324 Main.debug("File " + localFile + " already exists"); 325 326 return file.getAbsolutePath(); 327 } else { 328 329 BufferedInputStream in = new BufferedInputStream( 330 con.getInputStream()); 331 BufferedOutputStream out = new BufferedOutputStream( 332 new FileOutputStream(file)); 333 int i; 334 335 while ((i = in.read()) != -1) { 336 out.write(i); 337 } 338 339 out.flush(); 340 out.close(); 341 in.close(); 342 343 return localFile; 344 } 345 } catch (MalformedURLException e1) { 346 e1.printStackTrace(); 347 } catch (IOException e) { 348 e.printStackTrace(); 349 } 350 351 return null; 352 } 375 353 376 354 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/preferences/RasterFiltersPreferences.java
r32754 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.preferences; 2 3 import java.awt.GridBagConstraints;4 import java.awt.GridBagLayout;5 import java.util.List;6 7 import javax.json.JsonObject;8 import javax.swing.JButton;9 import javax.swing.JPanel;10 import javax.swing.JScrollPane;11 import javax.swing.JTable;12 import javax.swing.border.EmptyBorder;13 import javax.swing.event.TableModelEvent;14 import javax.swing.event.TableModelListener;15 import javax.swing.table.AbstractTableModel;16 import javax.swing.table.TableModel;17 2 18 3 import org.openstreetmap.josm.Main; … … 23 8 import org.openstreetmap.josm.tools.GBC; 24 9 10 import javax.json.JsonObject; 11 import javax.swing.*; 12 import javax.swing.border.EmptyBorder; 13 import javax.swing.event.TableModelEvent; 14 import javax.swing.event.TableModelListener; 15 import javax.swing.table.AbstractTableModel; 16 import javax.swing.table.TableModel; 17 import java.awt.*; 18 import java.util.List; 19 25 20 /** 26 21 * This class draws subtab 'Image Filters' in the Preferences menu. 27 22 * 28 23 * @author Nipel-Crumple 29 *30 24 */ 31 25 public class RasterFiltersPreferences implements SubPreferenceSetting { 32 26 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 String[] columnNames = { "Filter Name", "Author", "Description", ""};113 Class<?>[] columnClasses = { String.class, String.class, String.class, Boolean.class};114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 27 private FiltersDownloader downloader = new FiltersDownloader(); 28 AbstractTableModel model; 29 JPanel holder; 30 31 @Override 32 public void addGui(PreferenceTabbedPane gui) { 33 34 model = new FiltersTableModel(); 35 36 if (holder == null) { 37 holder = new JPanel(); 38 holder.setLayout(new GridBagLayout()); 39 40 holder.setBorder(new EmptyBorder(10, 10, 10, 10)); 41 42 model.addTableModelListener(new TableModelListener() { 43 44 @Override 45 public void tableChanged(TableModelEvent e) { 46 int row = e.getFirstRow(); 47 int col = e.getColumn(); 48 TableModel model = (TableModel) e.getSource(); 49 50 Boolean isDownloadedUpdate = (Boolean) model.getValueAt( 51 row, col); 52 List<FilterInfo> filtersList = ((FiltersTableModel) model).filtersInfoList; 53 54 filtersList.get(row).setNeedToDownload(isDownloadedUpdate); 55 56 } 57 }); 58 59 JTable table = new JTable(model); 60 table.getTableHeader().setReorderingAllowed(false); 61 table.getColumnModel().getColumn(3).setMaxWidth(20); 62 JScrollPane pane = new JScrollPane(table); 63 64 holder.add(pane, GBC.eol().fill(GBC.BOTH)); 65 66 GridBagConstraints c = GBC.eol(); 67 c.anchor = GBC.EAST; 68 69 JButton download = new JButton("Download"); 70 download.addActionListener(downloader); 71 holder.add(download, c); 72 } 73 74 MapPreference pref = gui.getMapPreference(); 75 pref.addSubTab(this, "Image Filters", holder); 76 77 } 78 79 @Override 80 public boolean ok() { 81 List<FilterInfo> filtersInfoList = ((FiltersTableModel) model).getFiltersInfoList(); 82 83 for (FilterInfo temp : filtersInfoList) { 84 JsonObject meta = temp.getMeta(); 85 String paramName = meta.getString("name"); 86 paramName = "rasterfilters." + paramName; 87 Main.pref.put(paramName, temp.isNeedToDownload()); 88 } 89 90 return false; 91 } 92 93 @Override 94 public boolean isExpert() { 95 // TODO Auto-generated method stub 96 return false; 97 } 98 99 @Override 100 public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) { 101 return gui.getMapPreference(); 102 } 103 104 static class FiltersTableModel extends AbstractTableModel { 105 106 String[] columnNames = {"Filter Name", "Author", "Description", ""}; 107 Class<?>[] columnClasses = {String.class, String.class, String.class, Boolean.class}; 108 List<FilterInfo> filtersInfoList; 109 Object[][] data; 110 111 public FiltersTableModel() { 112 113 filtersInfoList = FiltersDownloader.downloadFiltersInfoList(); 114 data = new Object[filtersInfoList.size()][4]; 115 116 for (int i = 0; i < filtersInfoList.size(); i++) { 117 data[i][0] = filtersInfoList.get(i).getName(); 118 data[i][1] = filtersInfoList.get(i).getOwner(); 119 data[i][2] = filtersInfoList.get(i).getDescription(); 120 data[i][3] = filtersInfoList.get(i).isNeedToDownload(); 121 } 122 123 } 124 125 @Override 126 public int getRowCount() { 127 return filtersInfoList.size(); 128 } 129 130 @Override 131 public int getColumnCount() { 132 return columnNames.length; 133 } 134 135 @Override 136 public Object getValueAt(int rowIndex, int columnIndex) { 137 switch (columnIndex) { 138 case 0: 139 return filtersInfoList.get(rowIndex).getName(); 140 case 1: 141 return filtersInfoList.get(rowIndex).getOwner(); 142 case 2: 143 return filtersInfoList.get(rowIndex).getDescription(); 144 case 3: 145 return filtersInfoList.get(rowIndex).isNeedToDownload(); 146 default: 147 return null; 148 } 149 } 150 151 @Override 152 public String getColumnName(int col) { 153 return columnNames[col]; 154 } 155 156 @Override 157 public Class<?> getColumnClass(int col) { 158 return columnClasses[col]; 159 } 160 161 @Override 162 public boolean isCellEditable(int row, int col) { 163 if (col == 3) { 164 return true; 165 } 166 167 return false; 168 } 169 170 @Override 171 public void setValueAt(Object value, int row, int col) { 172 if (col == 3) { 173 filtersInfoList.get(row).setNeedToDownload((boolean) value); 174 fireTableCellUpdated(row, col); 175 } 176 } 177 178 public List<FilterInfo> getFiltersInfoList() { 179 return filtersInfoList; 180 } 181 } 188 182 189 183 } 190 184 191 185 class FilterInfo { 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 186 private String name; 187 private String description; 188 private JsonObject meta; 189 private boolean needToDownload; 190 private String owner; 191 192 public FilterInfo() { 193 194 } 195 196 public FilterInfo(String name, String description, JsonObject meta, 197 boolean needToDownload) { 198 this.setName(name); 199 this.setDescription(description); 200 this.meta = meta; 201 this.setNeedToDownload(needToDownload); 202 } 203 204 public String getName() { 205 return name; 206 } 207 208 public void setName(String name) { 209 this.name = name; 210 } 211 212 public String getDescription() { 213 return description; 214 } 215 216 public void setDescription(String description) { 217 this.description = description; 218 } 219 220 public JsonObject getMeta() { 221 return meta; 222 } 223 224 public void setMeta(JsonObject meta) { 225 this.meta = meta; 226 } 227 228 public boolean isNeedToDownload() { 229 return needToDownload; 230 } 231 232 public void setNeedToDownload(boolean needToDownload) { 233 this.needToDownload = needToDownload; 234 } 235 236 public String getOwner() { 237 return owner; 238 } 239 240 public void setOwner(String owner) { 241 this.owner = owner; 242 } 243 244 @Override 245 public String toString() { 246 return "name: " + getName() + "\nDescription: " + getDescription() 247 + "\nMeta: " + getMeta(); 248 } 249 250 @Override 251 public boolean equals(Object o) { 252 if (o instanceof FilterInfo) { 253 if (name.equals(((FilterInfo) o).getName()) && 254 meta.equals(((FilterInfo) o).getMeta()) && 255 description.equals(((FilterInfo) o).getDescription())) { 256 return true; 257 } 258 } 259 260 return false; 261 } 268 262 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/values/BooleanValue.java
r31470 r32850 3 3 public class BooleanValue implements Value<Boolean> { 4 4 5 6 5 private Boolean value; 6 private String parameterName; 7 7 8 public BooleanValue(String parameterName, Boolean value) { 9 this.value = value; 10 this.parameterName = parameterName; 11 } 12 13 @Override 14 public Boolean getValue() { 15 return value; 16 } 8 public BooleanValue(String parameterName, Boolean value) { 9 this.value = value; 10 this.parameterName = parameterName; 11 } 17 12 18 19 public void setValue(Boolean value) {20 this.value =value;21 13 @Override 14 public Boolean getValue() { 15 return value; 16 } 22 17 23 24 public String getParameterName() {25 return parameterName;26 18 @Override 19 public void setValue(Boolean value) { 20 this.value = value; 21 } 27 22 28 @Override 29 public void setParameterName(String name) { 30 this.parameterName = name; 31 } 23 @Override 24 public String getParameterName() { 25 return parameterName; 26 } 27 28 @Override 29 public void setParameterName(String name) { 30 this.parameterName = name; 31 } 32 32 33 33 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/values/ColorValue.java
r31470 r32850 1 1 package org.openstreetmap.josm.plugins.rasterfilters.values; 2 2 3 public class ColorValue<Color> implements Value<Color> {3 public class ColorValue<Color> implements Value<Color> { 4 4 5 6 5 private Color value; 6 private String parameterName; 7 7 8 9 10 11 8 public ColorValue(String parameterName, Color color) { 9 this.parameterName = parameterName; 10 this.value = color; 11 } 12 12 13 14 15 16 13 @Override 14 public Color getValue() { 15 return value; 16 } 17 17 18 19 20 21 18 @Override 19 public void setValue(Color value) { 20 this.value = value; 21 } 22 22 23 24 25 26 23 @Override 24 public String getParameterName() { 25 return parameterName; 26 } 27 27 28 29 30 31 28 @Override 29 public void setParameterName(String name) { 30 this.parameterName = name; 31 } 32 32 33 33 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/values/SelectValue.java
r31470 r32850 3 3 public class SelectValue<T> implements Value<T> { 4 4 5 private T selectedItem; 6 private String parameterName; 7 8 public SelectValue(String parameterName, T value) { 9 this.selectedItem = value; 10 this.parameterName = parameterName; 11 } 12 13 @Override 14 public T getValue() { 15 return selectedItem; 16 } 5 private T selectedItem; 6 private String parameterName; 17 7 18 @Override 19 public void setValue(T value) { 20 this.selectedItem = value;21 8 public SelectValue(String parameterName, T value) { 9 this.selectedItem = value; 10 this.parameterName = parameterName; 11 } 22 12 23 24 public String getParameterName() {25 return parameterName;26 13 @Override 14 public T getValue() { 15 return selectedItem; 16 } 27 17 28 @Override 29 public void setParameterName(String name) { 30 this.parameterName = name; 31 } 18 @Override 19 public void setValue(T value) { 20 this.selectedItem = value; 21 } 22 23 @Override 24 public String getParameterName() { 25 return parameterName; 26 } 27 28 @Override 29 public void setParameterName(String name) { 30 this.parameterName = name; 31 } 32 32 33 33 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/values/SliderValue.java
r31470 r32850 3 3 public class SliderValue<Number> implements Value<Number> { 4 4 5 private String parameterName; 6 private Number value; 7 8 public SliderValue(String parameterName, Number value) { 9 this.value = value; 10 this.parameterName = parameterName; 11 } 12 13 @Override 14 public Number getValue() { 15 return value; 16 } 5 private String parameterName; 6 private Number value; 17 7 18 @Override 19 public void setValue(Number value) { 20 this.value = value;21 8 public SliderValue(String parameterName, Number value) { 9 this.value = value; 10 this.parameterName = parameterName; 11 } 22 12 23 @Override 24 public String getParameterName() { 25 return parameterName; 26 } 27 28 @Override 29 public void setParameterName(String name) { 30 this.parameterName = name;; 31 } 32 33 public boolean isDouble() { 34 if (value instanceof Double) 35 return true; 36 return false; 37 } 13 @Override 14 public Number getValue() { 15 return value; 16 } 17 18 @Override 19 public void setValue(Number value) { 20 this.value = value; 21 } 22 23 @Override 24 public String getParameterName() { 25 return parameterName; 26 } 27 28 @Override 29 public void setParameterName(String name) { 30 this.parameterName = name; 31 ; 32 } 33 34 public boolean isDouble() { 35 if (value instanceof Double) 36 return true; 37 return false; 38 } 38 39 } -
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/values/Value.java
r31504 r32850 6 6 * Generic values which are used by {@link FilterStateModel}. 7 7 * 8 * @param <T> generic class of the value 8 9 * @author Nipel-Crumple 9 *10 * @param <T> generic class of the value11 10 */ 12 11 public interface Value<T extends Object> { 13 12 14 13 public T getValue(); 15 14 16 15 public void setValue(T value); 17 16 18 17 public String getParameterName(); 19 18 20 19 public void setParameterName(String name); 21 20 }
Note:
See TracChangeset
for help on using the changeset viewer.