Ignore:
Timestamp:
2015-06-23T19:29:46+02:00 (10 years ago)
Author:
nokutu
Message:

Filter almost completed

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31297 r31300  
    156156    /**
    157157     * If the selected MapillaryImage is part of a MapillarySequence then the
    158      * following MapillaryImage is selected. In case there is none, does
     158     * following visible MapillaryImage is selected. In case there is none, does
    159159     * nothing.
    160160     */
     
    165165            if (((MapillaryImage) getSelectedImage()).getSequence() == null)
    166166                return;
    167             setSelectedImage(((MapillaryImage) getSelectedImage()).next(), true);
     167            if (selectedImage instanceof MapillaryImage && ((MapillaryImage) selectedImage).getSequence() != null) {
     168                                MapillaryImage tempImage = (MapillaryImage) selectedImage;
     169                                while (tempImage.next() != null) {
     170                                        tempImage = tempImage.next();
     171                                        if (tempImage.isVisible()) {
     172                                    setSelectedImage(tempImage, true);
     173                                                break;
     174                                        }
     175                                }
     176                        }
    168177        }
    169178    }
     
    171180    /**
    172181     * If the selected MapillaryImage is part of a MapillarySequence then the
    173      * previous MapillaryImage is selected. In case there is none, does nothing.
     182     * previous visible MapillaryImage is selected. In case there is none, does nothing.
    174183     */
    175184    public void selectPrevious() {
     
    179188            if (((MapillaryImage) getSelectedImage()).getSequence() == null)
    180189                throw new IllegalStateException();
    181             setSelectedImage(((MapillaryImage) getSelectedImage()).previous(),
    182                     true);
     190            if (selectedImage instanceof MapillaryImage && ((MapillaryImage) selectedImage).getSequence() != null) {
     191                                MapillaryImage tempImage = (MapillaryImage) selectedImage;
     192                                while (tempImage.previous() != null) {
     193                                        tempImage = tempImage.previous();
     194                                        if (tempImage.isVisible()) {
     195                                    setSelectedImage(tempImage, true);
     196                                                break;
     197                                        }
     198                                }
     199                        }
    183200        }
    184201    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31298 r31300  
    312312                                if (imageAbs instanceof MapillaryImage) {
    313313                                        MapillaryImage image = (MapillaryImage) imageAbs;
    314                                         Point nextp;
     314                                        Point nextp = null;
    315315                                        // Draw sequence line
    316                                         if (image.getSequence() != null && image.next() != null
    317                                                         && image.next().isVisible()) {
    318                                                 nextp = mv.getPoint(image.getSequence().next(image)
    319                                                                 .getLatLon());
    320                                                 g.drawLine(p.x, p.y, nextp.x, nextp.y);
     316                                        if (image.getSequence() != null) {
     317                                                MapillaryImage tempImage = image;
     318                                                while (tempImage.next() != null) {
     319                                                        tempImage = tempImage.next();
     320                                                        if (tempImage.isVisible()) {
     321                                                                nextp = mv.getPoint(tempImage.getLatLon());
     322                                                                break;
     323                                                        }
     324                                                }
     325                                                if (nextp != null)
     326                                                        g.drawLine(p.x, p.y, nextp.x, nextp.y);
    321327                                        }
    322328
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterChooseSigns.java

    r31297 r31300  
    1515        ActionListener {
    1616
    17     private final JCheckBox maxspeed = new JCheckBox();
    18     private final JCheckBox stop = new JCheckBox();
    19     private final JCheckBox giveWay = new JCheckBox();
    20     private final JCheckBox roundabout = new JCheckBox();
    21     private final JCheckBox access = new JCheckBox();
     17    public final JCheckBox maxspeed = new JCheckBox();
     18    public final JCheckBox stop = new JCheckBox();
     19    public final JCheckBox giveWay = new JCheckBox();
     20    public final JCheckBox roundabout = new JCheckBox();
     21    public final JCheckBox access = new JCheckBox();
    2222
    2323    private static MapillaryFilterChooseSigns INSTANCE;
    2424
    2525    public MapillaryFilterChooseSigns() {
     26        maxspeed.setSelected(true);
     27        stop.setSelected(true);
     28        giveWay.setSelected(true);
     29        roundabout.setSelected(true);
     30        access.setSelected(true);
     31
     32       
    2633        // Max speed sign
    2734        JPanel maxspeedPanel = new JPanel();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java

    r31297 r31300  
    3838 */
    3939public class MapillaryFilterDialog extends ToggleDialog implements
    40         MapillaryDataListener {
    41 
    42     public static MapillaryFilterDialog INSTANCE;
    43 
    44     private final static String[] TIME_LIST = { tr("All time"),
    45             tr("This year"), tr("This month"), tr("This week") };
    46 
    47     private final static int ROWS = 0;
    48     private final static int COLUMNS = 3;
    49 
    50     private final JPanel panel;
    51 
    52     private final JCheckBox imported;
    53     private final JCheckBox downloaded;
    54     private final JCheckBox onlySigns;
    55     private final JComboBox<String> time;
    56     private final JTextField user;
    57 
    58     private final SideButton updateButton;
    59     private final SideButton resetButton;
    60     private final JButton signChooser;
    61 
    62     public MapillaryFilterDialog() {
    63         super(tr("Mapillary filter"), "mapillaryfilter.png",
    64                 tr("Open Mapillary filter dialog"), Shortcut.registerShortcut(
    65                         tr("Mapillary filter"),
    66                         tr("Open Mapillary filter dialog"), KeyEvent.VK_M,
    67                         Shortcut.NONE), 200);
    68         panel = new JPanel(new GridLayout(ROWS, COLUMNS));
    69 
    70         imported = new JCheckBox("Imported images");
    71         downloaded = new JCheckBox(new downloadCheckBoxAction());
    72         onlySigns = new JCheckBox(new OnlySignsAction());
    73 
    74         signChooser = new JButton(new SignChooserAction());
    75         JPanel signChooserPanel = new JPanel();
    76         signChooserPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    77         signChooserPanel.add(signChooser);
    78 
    79         JPanel comboPanel = new JPanel();
    80         comboPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    81         comboPanel.add(new JLabel("From"));
    82         time = new JComboBox<>(TIME_LIST);
    83         comboPanel.add(time);
    84 
    85         JPanel userSearchPanel = new JPanel();
    86         userSearchPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    87         user = new JTextField(15);
    88         user.addActionListener(new UpdateAction());
    89         userSearchPanel.add(new JLabel("User"));
    90         userSearchPanel.add(user);
    91 
    92         imported.setSelected(true);
    93         downloaded.setSelected(true);
    94 
    95         updateButton = new SideButton(new UpdateAction());
    96         resetButton = new SideButton(new ResetAction());
    97 
    98         panel.add(downloaded);
    99         panel.add(imported);
    100         panel.add(onlySigns);
    101         panel.add(comboPanel);
    102         panel.add(userSearchPanel);
    103         panel.add(signChooserPanel);
    104 
    105         createLayout(panel, true,
    106                 Arrays.asList(new SideButton[] { updateButton, resetButton }));
    107     }
    108 
    109     public static MapillaryFilterDialog getInstance() {
    110         if (INSTANCE == null)
    111             INSTANCE = new MapillaryFilterDialog();
    112         return INSTANCE;
    113     }
    114 
    115     @Override
    116     public void imagesAdded() {
    117         refresh();
    118     }
    119 
    120     @Override
    121     public void selectedImageChanged(MapillaryAbstractImage oldImage,
    122             MapillaryAbstractImage newImage) {
    123     }
    124 
    125     public void reset() {
    126         imported.setSelected(true);
    127         downloaded.setSelected(true);
    128         onlySigns.setEnabled(true);
    129         onlySigns.setSelected(false);
    130         user.setText("");
    131         time.setSelectedItem(TIME_LIST[0]);
    132         refresh();
    133     }
    134 
    135     public void refresh() {
    136         boolean imported = this.imported.isSelected();
    137         boolean downloaded = this.downloaded.isSelected();
    138         boolean onlySigns = this.onlySigns.isSelected();
    139 
    140         for (MapillaryAbstractImage img : MapillaryData.getInstance()
    141                 .getImages()) {
    142             img.setVisible(true);
    143             if (img instanceof MapillaryImportedImage) {
    144                 if (!imported)
    145                     img.setVisible(false);
    146                 continue;
    147             } else if (img instanceof MapillaryImage) {
    148                 if (!downloaded) {
    149                     img.setVisible(false);
    150                     continue;
    151                 }
    152                 if (onlySigns) {
    153                     if (((MapillaryImage) img).getSigns().isEmpty()) {
    154                         img.setVisible(false);
    155                         continue;
    156                     }
    157                 }
    158                 if (!user.getText().equals("")
    159                         && !user.getText().equals(
    160                                 ((MapillaryImage) img).getUser())) {
    161                     img.setVisible(false);
    162                     continue;
    163                 }
    164             }
    165             // Calculates the amount of days since the image was taken
    166             Long currentTime = currentTime();
    167             if (time.getSelectedItem() == TIME_LIST[1]) {
    168                 if ((currentTime - img.getCapturedAt()) / (24 * 60 * 60 * 1000) > 365) {
    169                     img.setVisible(false);
    170                     continue;
    171                 }
    172             }
    173             if (time.getSelectedItem() == TIME_LIST[2]) {
    174                 if ((currentTime - img.getCapturedAt()) / (24 * 60 * 60 * 1000) > 30) {
    175                     img.setVisible(false);
    176                     continue;
    177                 }
    178             }
    179             if (time.getSelectedItem() == TIME_LIST[3]) {
    180                 if ((currentTime - img.getCapturedAt()) / (24 * 60 * 60 * 1000) > 7) {
    181                     img.setVisible(false);
    182                     continue;
    183                 }
    184             }
    185         }
    186         MapillaryData.getInstance().dataUpdated();
    187     }
    188 
    189     private long currentTime() {
    190         Calendar cal = Calendar.getInstance();
    191         return cal.getTimeInMillis();
    192     }
    193 
    194     private class downloadCheckBoxAction extends AbstractAction {
    195 
    196         public downloadCheckBoxAction() {
    197             putValue(NAME, tr("Downloaded images"));
    198         }
    199 
    200         @Override
    201         public void actionPerformed(ActionEvent arg0) {
    202             onlySigns.setEnabled(downloaded.isSelected());
    203         }
    204     }
    205 
    206     private class UpdateAction extends AbstractAction {
    207         public UpdateAction() {
    208             putValue(NAME, tr("Update"));
    209         }
    210 
    211         @Override
    212         public void actionPerformed(ActionEvent arg0) {
    213             MapillaryFilterDialog.getInstance().refresh();
    214         }
    215     }
    216 
    217     private class ResetAction extends AbstractAction {
    218         public ResetAction() {
    219             putValue(NAME, tr("Reset"));
    220         }
    221 
    222         @Override
    223         public void actionPerformed(ActionEvent arg0) {
    224             MapillaryFilterDialog.getInstance().reset();
    225         }
    226     }
    227 
    228     private class OnlySignsAction extends AbstractAction {
    229         public OnlySignsAction() {
    230             putValue(NAME, tr("Only images with signs"));
    231         }
    232 
    233         @Override
    234         public void actionPerformed(ActionEvent arg0) {
    235             signChooser.setEnabled(onlySigns.isSelected());
    236         }
    237     }
    238 
    239     /**
    240      * Opens a new window where you can specifically filter signs.
    241      *
    242      * @author nokutu
    243      *
    244      */
    245     private class SignChooserAction extends AbstractAction {
    246         public SignChooserAction() {
    247             putValue(NAME, tr("Choose signs"));
    248         }
    249 
    250         @Override
    251         public void actionPerformed(ActionEvent arg0) {
    252             JPanel dialog = MapillaryFilterChooseSigns.getInstance();
    253             JOptionPane pane = new JOptionPane(dialog,
    254                     JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    255             JDialog dlg = pane.createDialog(Main.parent, tr("Choose signs"));
    256             dlg.setMinimumSize(new Dimension(400, 150));
    257             dlg.setVisible(true);
    258             MapillaryFilterDialog.getInstance().refresh();
    259             dlg.dispose();
    260         }
    261     }
    262 
    263     public static void destroyInstance() {
    264         MapillaryFilterDialog.INSTANCE = null;
    265     }
     40                MapillaryDataListener {
     41
     42        public static MapillaryFilterDialog INSTANCE;
     43
     44        private final static String[] TIME_LIST = { tr("All time"),
     45                        tr("This year"), tr("This month"), tr("This week") };
     46
     47        private final static int ROWS = 0;
     48        private final static int COLUMNS = 3;
     49
     50        private final JPanel panel = new JPanel(new GridLayout(ROWS, COLUMNS));
     51
     52        private final JCheckBox imported = new JCheckBox("Imported images");
     53        private final JCheckBox downloaded = new JCheckBox(new downloadCheckBoxAction());
     54        private final JCheckBox onlySigns = new JCheckBox(new OnlySignsAction());
     55        private final JComboBox<String> time;
     56        private final JTextField user;
     57
     58        private final SideButton updateButton = new SideButton(new UpdateAction());
     59        private final SideButton resetButton = new SideButton(new ResetAction());
     60        private final JButton signChooser = new JButton(new SignChooserAction());
     61
     62        public final MapillaryFilterChooseSigns signFilter = MapillaryFilterChooseSigns
     63                        .getInstance();
     64
     65        public MapillaryFilterDialog() {
     66                super(tr("Mapillary filter"), "mapillaryfilter.png",
     67                                tr("Open Mapillary filter dialog"), Shortcut.registerShortcut(
     68                                                tr("Mapillary filter"),
     69                                                tr("Open Mapillary filter dialog"), KeyEvent.VK_M,
     70                                                Shortcut.NONE), 200);
     71
     72 
     73                signChooser.setEnabled(false);
     74                JPanel signChooserPanel = new JPanel();
     75                signChooserPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
     76                signChooserPanel.add(signChooser);
     77
     78                JPanel comboPanel = new JPanel();
     79                comboPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
     80                comboPanel.add(new JLabel("From"));
     81                time = new JComboBox<>(TIME_LIST);
     82                comboPanel.add(time);
     83
     84                JPanel userSearchPanel = new JPanel();
     85                userSearchPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
     86                user = new JTextField(15);
     87                user.addActionListener(new UpdateAction());
     88                userSearchPanel.add(new JLabel("User"));
     89                userSearchPanel.add(user);
     90
     91                imported.setSelected(true);
     92                downloaded.setSelected(true);
     93
     94                panel.add(downloaded);
     95                panel.add(imported);
     96                panel.add(onlySigns);
     97                panel.add(comboPanel);
     98                panel.add(userSearchPanel);
     99                panel.add(signChooserPanel);
     100
     101                createLayout(panel, true,
     102                                Arrays.asList(new SideButton[] { updateButton, resetButton }));
     103        }
     104
     105        public static MapillaryFilterDialog getInstance() {
     106                if (INSTANCE == null)
     107                        INSTANCE = new MapillaryFilterDialog();
     108                return INSTANCE;
     109        }
     110
     111        @Override
     112        public void imagesAdded() {
     113                refresh();
     114        }
     115
     116        @Override
     117        public void selectedImageChanged(MapillaryAbstractImage oldImage,
     118                        MapillaryAbstractImage newImage) {
     119        }
     120
     121        public void reset() {
     122                imported.setSelected(true);
     123                downloaded.setSelected(true);
     124                onlySigns.setEnabled(true);
     125                onlySigns.setSelected(false);
     126                user.setText("");
     127                time.setSelectedItem(TIME_LIST[0]);
     128                refresh();
     129        }
     130
     131        public void refresh() {
     132                boolean imported = this.imported.isSelected();
     133                boolean downloaded = this.downloaded.isSelected();
     134                boolean onlySigns = this.onlySigns.isSelected();
     135
     136                for (MapillaryAbstractImage img : MapillaryData.getInstance()
     137                                .getImages()) {
     138                        img.setVisible(true);
     139                        if (img instanceof MapillaryImportedImage) {
     140                                if (!imported)
     141                                        img.setVisible(false);
     142                                continue;
     143                        } else if (img instanceof MapillaryImage) {
     144                                if (!downloaded) {
     145                                        img.setVisible(false);
     146                                        continue;
     147                                }
     148                                if (onlySigns) {
     149                                        if (((MapillaryImage) img).getSigns().isEmpty()) {
     150                                                img.setVisible(false);
     151                                                continue;
     152                                        }
     153                                        if (!checkSigns((MapillaryImage) img)) {
     154                                                img.setVisible(false);
     155                                                continue;
     156                                        }
     157                                }
     158                                if (!user.getText().equals("")
     159                                                && !user.getText().equals(
     160                                                                ((MapillaryImage) img).getUser())) {
     161                                        img.setVisible(false);
     162                                        continue;
     163                                }
     164                        }
     165                        // Calculates the amount of days since the image was taken
     166                        Long currentTime = currentTime();
     167                        if (time.getSelectedItem() == TIME_LIST[1]) {
     168                                if ((currentTime - img.getCapturedAt()) / (24 * 60 * 60 * 1000) > 365) {
     169                                        img.setVisible(false);
     170                                        continue;
     171                                }
     172                        }
     173                        if (time.getSelectedItem() == TIME_LIST[2]) {
     174                                if ((currentTime - img.getCapturedAt()) / (24 * 60 * 60 * 1000) > 30) {
     175                                        img.setVisible(false);
     176                                        continue;
     177                                }
     178                        }
     179                        if (time.getSelectedItem() == TIME_LIST[3]) {
     180                                if ((currentTime - img.getCapturedAt()) / (24 * 60 * 60 * 1000) > 7) {
     181                                        img.setVisible(false);
     182                                        continue;
     183                                }
     184                        }
     185                }
     186                MapillaryData.getInstance().dataUpdated();
     187        }
     188
     189        private boolean checkSigns(MapillaryImage img) {
     190                // TODO move strings into an arraylist
     191                if (checkSign(img, signFilter.maxspeed, "prohibitory_speed_limit"))
     192                        return true;
     193               
     194                if (checkSign(img, signFilter.stop, "priority_stop"))
     195                        return true;
     196               
     197                if (checkSign(img, signFilter.giveWay, "other_give_way"))
     198                        return true;
     199               
     200                if (checkSign(img, signFilter.roundabout, "mandatory_roundabout"))
     201                        return true;
     202               
     203                if (checkSign(img, signFilter.access, "other_no_entry"))
     204                        return true;
     205
     206                return false;
     207        }
     208       
     209        private boolean checkSign(MapillaryImage img, JCheckBox signCheckBox, String singString) {
     210                boolean contains = false;
     211                for (String sign : img.getSigns()) {
     212                        if (sign.contains(singString))
     213                                contains = true;
     214                }
     215                if (contains == signCheckBox.isSelected() && contains)
     216                        return true;
     217                return false;
     218        }
     219
     220        private long currentTime() {
     221                Calendar cal = Calendar.getInstance();
     222                return cal.getTimeInMillis();
     223        }
     224
     225        private class downloadCheckBoxAction extends AbstractAction {
     226
     227                public downloadCheckBoxAction() {
     228                        putValue(NAME, tr("Downloaded images"));
     229                }
     230
     231                @Override
     232                public void actionPerformed(ActionEvent arg0) {
     233                        onlySigns.setEnabled(downloaded.isSelected());
     234                }
     235        }
     236
     237        private class UpdateAction extends AbstractAction {
     238                public UpdateAction() {
     239                        putValue(NAME, tr("Update"));
     240                }
     241
     242                @Override
     243                public void actionPerformed(ActionEvent arg0) {
     244                        MapillaryFilterDialog.getInstance().refresh();
     245                }
     246        }
     247
     248        private class ResetAction extends AbstractAction {
     249                public ResetAction() {
     250                        putValue(NAME, tr("Reset"));
     251                }
     252
     253                @Override
     254                public void actionPerformed(ActionEvent arg0) {
     255                        MapillaryFilterDialog.getInstance().reset();
     256                }
     257        }
     258
     259        private class OnlySignsAction extends AbstractAction {
     260                public OnlySignsAction() {
     261                        putValue(NAME, tr("Only images with signs"));
     262                }
     263
     264                @Override
     265                public void actionPerformed(ActionEvent arg0) {
     266                        signChooser.setEnabled(onlySigns.isSelected());
     267                }
     268        }
     269
     270        /**
     271         * Opens a new window where you can specifically filter signs.
     272         *
     273         * @author nokutu
     274         *
     275         */
     276        private class SignChooserAction extends AbstractAction {
     277                public SignChooserAction() {
     278                        putValue(NAME, tr("Choose signs"));
     279                }
     280
     281                @Override
     282                public void actionPerformed(ActionEvent arg0) {
     283                        JPanel dialog = MapillaryFilterChooseSigns.getInstance();
     284                        JOptionPane pane = new JOptionPane(dialog,
     285                                        JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
     286                        JDialog dlg = pane.createDialog(Main.parent, tr("Choose signs"));
     287                        dlg.setMinimumSize(new Dimension(400, 150));
     288                        dlg.setVisible(true);
     289                        if ((int) pane.getValue() == JOptionPane.OK_OPTION)
     290                                MapillaryFilterDialog.getInstance().refresh();
     291                        dlg.dispose();
     292                }
     293        }
     294
     295        public static void destroyInstance() {
     296                MapillaryFilterDialog.INSTANCE = null;
     297        }
    266298}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryToggleDialog.java

    r31298 r31300  
    125125                                        title += " -- " + mapillaryImage.getDate();
    126126                                setTitle(title);
    127                                 this.nextButton.setEnabled(true);
    128                                 this.previousButton.setEnabled(true);
    129                                 if (mapillaryImage.next() == null
    130                                                 || !mapillaryImage.next().isVisible())
    131                                         this.nextButton.setEnabled(false);
    132                                 if (mapillaryImage.previous() == null
    133                                                 || !mapillaryImage.previous().isVisible())
    134                                         this.previousButton.setEnabled(false);
     127                                this.nextButton.setEnabled(false);
     128                                this.previousButton.setEnabled(false);
     129                                // Enables/disables next/previous buttons
     130                                if (((MapillaryImage) image).getSequence() != null) {
     131                                        MapillaryImage tempImage = (MapillaryImage) image;
     132                                        while (tempImage.next() != null) {
     133                                                tempImage = tempImage.next();
     134                                                if (tempImage.isVisible()) {
     135                                                        this.nextButton.setEnabled(true);
     136                                                        break;
     137                                                }
     138                                        }
     139                                }
     140                                if (((MapillaryImage) image).getSequence() != null) {
     141                                        MapillaryImage tempImage = (MapillaryImage) image;
     142                                        while (tempImage.previous() != null) {
     143                                                tempImage = tempImage.previous();
     144                                                if (tempImage.isVisible()) {
     145                                                        this.previousButton.setEnabled(true);
     146                                                        break;
     147                                                }
     148                                        }
     149                                }
    135150
    136151                                mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey());
Note: See TracChangeset for help on using the changeset viewer.