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