Ignore:
Timestamp:
2011-03-31T12:02:52+02:00 (13 years ago)
Author:
beata.jancso
Message:

Fix for: Ticket #6158 .

Location:
applications/editors/josm/plugins/mapdust/src/org/openstreetmap/josm/plugins/mapdust
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapdust/src/org/openstreetmap/josm/plugins/mapdust/MapdustLayer.java

    r25656 r25754  
    8989
    9090    /**
     91     * Updates the <code>MapdustLayer</code> with the new
     92     * <code>MapdustGUI</code> and <code>MapdustBug</code> list.
     93     *
     94     * @param mapdustGUI The <code>MapdustGUI</code>
     95     * @param mapdustBugList The <code>MapdustBug</code> list
     96     */
     97    public void update(MapdustGUI mapdustGUI, List<MapdustBug> mapdustBugList) {
     98        this.mapdustGUI = mapdustGUI;
     99        this.mapdustBugList = mapdustBugList;
     100        this.bugSelected = null;
     101    }
     102
     103    /**
    91104     * Returns the icon of the MapDust layer.
    92105     *
     
    169182    public void paint(Graphics2D g, MapView mv, Bounds bounds) {
    170183        JToolTip tooltip = new JToolTip();
    171         if (mapdustBugList != null && mapdustBugList.size()>0) {
     184        if (mapdustBugList != null && mapdustBugList.size() > 0) {
    172185            /* draw the current visible bugs */
    173186            for (MapdustBug bug : mapdustBugList) {
     
    203216            MapdustBug bugSelected = getMapdustGUI().getSelectedBug();
    204217            if (bugSelected == null) {
    205                     bugSelected = clickedBug;
     218                bugSelected = clickedBug;
    206219            }
    207220            setBugSelected(bugSelected);
  • applications/editors/josm/plugins/mapdust/src/org/openstreetmap/josm/plugins/mapdust/MapdustPlugin.java

    r25656 r25754  
    418418     */
    419419    @Override
    420     public void layerAdded(Layer layer) {
    421         if (layer instanceof MapdustLayer) {
    422             /* download the MapDust bugs and update the plugin */
    423             if (mapdustBugList == null) {
    424                 updatePluginData();
    425             }
    426         }
    427     }
     420    public void layerAdded(Layer layer) {}
    428421
    429422    /**
     
    508501    private BoundingBox getBBox() {
    509502        MapView mapView = Main.map.mapView;
    510         Bounds bounds =
    511                 new Bounds(mapView.getLatLon(0, mapView.getHeight()),
    512                         mapView.getLatLon(mapView.getWidth(), 0));
     503        Bounds bounds = new Bounds(mapView.getLatLon(0, mapView.getHeight()),
     504                mapView.getLatLon(mapView.getWidth(), 0));
    513505        return new BoundingBox(bounds.getMin().lon(), bounds.getMin().lat(),
    514506                bounds.getMax().lon(), bounds.getMax().lat());
     
    522514    private void updatePluginData() {
    523515        Main.worker.execute(new Runnable() {
    524 
    525516            @Override
    526517            public void run() {
     
    549540            /* update the view */
    550541            SwingUtilities.invokeLater(new Runnable() {
    551 
    552542                @Override
    553543                public void run() {
     
    562552    }
    563553
     554
    564555    /**
    565556     * Updates the current view ( map and MapDust bug list), with the given list
     
    567558     */
    568559    protected void updateView() {
    569         /* update the dialog with the new data */
    570         mapdustGUI.update(mapdustBugList, this);
    571         /* update the MapdustLayer */
    572         if (mapdustLayer == null) {
    573             /* create and add the layer */
    574             mapdustLayer =
    575                     new MapdustLayer("MapDust", mapdustGUI, mapdustBugList);
    576             Main.main.addLayer(this.mapdustLayer);
    577             Main.map.mapView.moveLayer(this.mapdustLayer, 0);
    578             Main.map.mapView.addMouseListener(this);
    579             NavigatableComponent.addZoomChangeListener(this);
    580         } else {
    581             /* re-set the properties */
    582             mapdustLayer.destroy();
    583             mapdustLayer.setMapdustGUI(mapdustGUI);
    584             mapdustLayer.setMapdustBugList(mapdustBugList);
    585             mapdustLayer.setBugSelected(null);
    586         }
    587         /* repaint */
    588         mapdustGUI.revalidate();
    589         Main.map.mapView.revalidate();
    590         Main.map.repaint();
     560        if (Main.map != null && Main.map.mapView != null) {
     561            /* update the MapdustLayer */
     562            boolean needRepaint = false;
     563            if (!containsMapdustLayer()) {
     564                /* first start or layer was deleted */
     565                if (mapdustGUI.isDownloaded()) {
     566                    mapdustGUI.update(mapdustBugList, this);
     567                    /* create and add the layer */
     568                    mapdustLayer = new MapdustLayer("MapDust", mapdustGUI,
     569                            mapdustBugList);
     570                    Main.main.addLayer(this.mapdustLayer);
     571                    Main.map.mapView.moveLayer(this.mapdustLayer, 0);
     572                    Main.map.mapView.addMouseListener(this);
     573                    NavigatableComponent.addZoomChangeListener(this);
     574                    needRepaint = true;
     575                }
     576            } else {
     577                if (mapdustLayer != null) {
     578                    /* MapDust data was changed */
     579                    mapdustGUI.update(mapdustBugList, this);
     580                    mapdustLayer.destroy();
     581                    mapdustLayer.update(mapdustGUI, mapdustBugList);
     582                    needRepaint = true;
     583                }
     584            }
     585            if (needRepaint) {
     586                /* force repaint */
     587                mapdustGUI.revalidate();
     588                Main.map.mapView.revalidate();
     589                Main.map.repaint();
     590            }
     591        }
     592    }
     593
     594    /**
     595     * Verifies if the <code>MapView</code> contains or not the
     596     * <code>MapdustLayer</code> layer.
     597     *
     598     * @return true if the <code>MapView</code> contains the
     599     * <code>MapdustLayer</code> false otherwise
     600     */
     601    private boolean containsMapdustLayer() {
     602        boolean contains = false;
     603        List<Layer> all = Main.map.mapView.getAllLayersAsList();
     604        if (mapdustLayer != null && all.contains(mapdustLayer)) {
     605            contains = true;
     606        }
     607        return contains;
    591608    }
    592609
  • applications/editors/josm/plugins/mapdust/src/org/openstreetmap/josm/plugins/mapdust/gui/MapdustGUI.java

    r25656 r25754  
    9696    private boolean downloaded = false;
    9797
    98     /** Specifies if the MapDust layer was or not before deleted */
    99     boolean wasDeleted = false;
    100 
    10198    /**
    10299     * Builds a <code>MapdustGUi</code> based on the given parameters.
     
    125122            notifyObservers(null, true);
    126123            downloaded = true;
    127         }
    128         if (wasDeleted) {
    129             notifyObservers(null, true);
    130             wasDeleted = false;
    131124        }
    132125        super.showDialog();
     
    147140            mainPanel = null;
    148141            panel = null;
     142            actionPanel = null;
    149143        } else {
    150144            /* from online to offline */
    151             remove(mainPanel);
    152             mainPanel = null;
    153             panel = null;
    154         }
    155         wasDeleted = true;
     145            if (mainPanel != null) {
     146                remove(mainPanel);
     147                mainPanel = null;
     148                panel = null;
     149                detailsPanel = null;
     150            }
     151        }
     152        downloaded = false;
     153        button.setSelected(false);
    156154        super.destroy();
     155    }
     156
     157    @Override
     158    protected void toggleButtonHook() {
     159        if (isVisible()) {
     160            setVisible(false);
     161            button.setSelected(false);
     162        } else {
     163            setVisible(true);
     164        }
    157165    }
    158166
     
    168176        actionList.add(action);
    169177        List<MapdustBug> mapdustBugs = panel.getMapdustBugsList();
    170         boolean showBug =
    171                 shouldDisplay(action.getMapdustBug(), mapdustPlugin.getFilter());
     178        boolean showBug = shouldDisplay(action.getMapdustBug(),
     179                mapdustPlugin.getFilter());
    172180        mapdustBugs = modifyBug(mapdustBugs, action.getMapdustBug(), showBug);
    173 
    174181        /* update panels */
    175182        updateMapdustPanel(mapdustBugs);
    176183        updateMapdustActionPanel(actionList);
    177         if (showBug
    178                 && !action.getCommand().equals(MapdustServiceCommand.ADD_BUG)) {
     184        if (showBug && !action.getCommand().equals(MapdustServiceCommand.ADD_BUG)) {
    179185            panel.resetSelectedBug(0);
    180186        } else {
     
    246252
    247253            /* update panels */
    248             List<MapdustBug> bugs =
    249                     filterMapdustBugList(mapdustBugs, actionList,
    250                             mapdustPlugin.getFilter());
     254            List<MapdustBug> bugs = filterMapdustBugList(mapdustBugs,
     255                    actionList,mapdustPlugin.getFilter());
    251256            updateMapdustPanel(bugs);
    252257            updateMapdustActionPanel(actionList);
     
    256261        }
    257262    }
    258 
    259263
    260264    /**
     
    272276        }
    273277        if (panel == null) {
    274             panel =
    275                     new MapdustBugListPanel(mapdustBugs, "Bug reports",
    276                             mapdustPlugin);
     278            panel = new MapdustBugListPanel(mapdustBugs, "Bug reports",
     279                    mapdustPlugin);
    277280            panel.addObserver(detailsPanel);
    278281        } else {
     
    289292    private void updateMapdustActionPanel(List<MapdustAction> actionList) {
    290293        if (actionPanel == null) {
    291             actionPanel =
    292                     new MapdustActionPanel(actionList, "Offline Contribution",
    293                             mapdustPlugin);
     294            actionPanel = new MapdustActionPanel(actionList,
     295                    "Offline Contribution", mapdustPlugin);
    294296        } else {
    295297            actionPanel.updateComponents(actionList);
     
    446448    }
    447449
     450
    448451    /**
    449452     * Adds a new MapDust bug details observer to the list of observers.
     
    516519                this.initialUpdateObservers.iterator();
    517520        while (elements.hasNext()) {
    518             (elements.next()).update(null, true);
     521            (elements.next()).update(filter, first);
    519522        }
    520523    }
     
    552555    }
    553556
     557    /**
     558     * Returns the downloaded flag
     559     *
     560     * @return the downloaded
     561     */
     562    public boolean isDownloaded() {
     563        return downloaded;
     564    }
     565
    554566}
  • applications/editors/josm/plugins/mapdust/src/org/openstreetmap/josm/plugins/mapdust/gui/component/panel/MapdustButtonPanel.java

    r25657 r25754  
    112112                imagePath = "dialogs/online.png";
    113113            }
    114             AbstractAction action =
    115                     new ExecuteWorkOffline(mapdustPlugin.getMapdustGUI());
     114            AbstractAction action = new ExecuteWorkOffline(
     115                    mapdustPlugin.getMapdustGUI());
    116116            ((ExecuteWorkOffline) action).addObserver(mapdustPlugin);
    117             btnWorkOffline =
    118                     ComponentUtil.createJButton("Work offline", tooltipText,
    119                             imagePath, action);
     117            btnWorkOffline = ComponentUtil.createJButton("Work offline",
     118                    tooltipText, imagePath, action);
    120119            btnWorkOffline.setSelected(false);
    121120            btnWorkOffline.setFocusTraversalKeysEnabled(false);
     
    124123        if (btnFilter == null) {
    125124            AbstractAction action = new ShowFilterBugAction(mapdustPlugin);
    126             btnFilter =
    127                     ComponentUtil.createJButton("Filter bug reports",
    128                             "Filter bug reports",
    129                             "dialogs/mapdust_bug_filter.png", action);
     125            btnFilter = ComponentUtil.createJButton("Filter bug reports",
     126                    "Filter bug reports", "dialogs/mapdust_bug_filter.png",
     127                    action);
    130128            btnFilter.setEnabled(true);
    131129            btnFilter.setFocusTraversalKeysEnabled(false);
     
    134132        if (btnAddComment == null) {
    135133            AbstractAction action = new ShowCommentBugAction(mapdustPlugin);
    136             btnAddComment =
    137                     ComponentUtil
    138                             .createJButton("Comment bug report",
    139                                     "Comment bug report",
    140                                     "dialogs/comment.png", action);
     134            btnAddComment = ComponentUtil.createJButton("Comment bug report",
     135                    "Comment bug report", "dialogs/comment.png", action);
    141136            btnAddComment.setEnabled(false);
    142137            btnAddComment.setFocusTraversalKeysEnabled(false);
     
    145140        if (btnFixBugReport == null) {
    146141            AbstractAction action = new ShowCloseBugAction(mapdustPlugin);
    147             btnFixBugReport =
    148                     ComponentUtil.createJButton("Close bug report",
    149                             "Close bug report", "dialogs/fixed.png", action);
     142            btnFixBugReport = ComponentUtil.createJButton("Close bug report",
     143                    "Close bug report", "dialogs/fixed.png", action);
    150144            btnFixBugReport.setEnabled(false);
    151145            btnFixBugReport.setFocusTraversalKeysEnabled(false);
     
    154148        if (btnInvalidateBugReport == null) {
    155149            AbstractAction action = new ShowInvalidateBugAction(mapdustPlugin);
    156             btnInvalidateBugReport =
    157                     ComponentUtil.createJButton("Invalidate bug report",
    158                             "Invalidate bug report", "dialogs/invalid.png",
    159                             action);
     150            btnInvalidateBugReport = ComponentUtil.createJButton(
     151                    "Invalidate bug report", "Invalidate bug report",
     152                    "dialogs/invalid.png", action);
    160153            btnInvalidateBugReport.setEnabled(false);
    161154            btnInvalidateBugReport.setFocusTraversalKeysEnabled(false);
     
    164157        if (btnReOpenBugReport == null) {
    165158            AbstractAction action = new ShowReOpenBugAction(mapdustPlugin);
    166             btnReOpenBugReport =
    167                     ComponentUtil.createJButton("Re-open bug report",
    168                             "Re-open bug report", "dialogs/reopen.png", action);
     159            btnReOpenBugReport = ComponentUtil.createJButton(
     160                    "Re-open bug report", "Re-open bug report",
     161                    "dialogs/reopen.png", action);
    169162            btnReOpenBugReport.setEnabled(false);
    170163            btnReOpenBugReport.setFocusTraversalKeysEnabled(false);
     
    175168            AbstractAction action = new ExecuteRefresh();
    176169            ((ExecuteRefresh) action).addObserver(mapdustPlugin);
    177             btnRefresh =
    178                     ComponentUtil.createJButton("Refresh", "Refresh",
    179                             "dialogs/mapdust_refresh.png", action);
     170            btnRefresh = ComponentUtil.createJButton("Refresh", "Refresh",
     171                    "dialogs/mapdust_refresh.png", action);
    180172            if (pluginState.equals(MapdustPluginState.OFFLINE.getValue())) {
    181173                btnRefresh.setEnabled(false);
     
    241233     * other buttons will be disabled.
    242234     *
    243      * @param onlyBasic If true then the not basic buttons will be disabled
     235     * @param onlyBasic If true then the not basic buttons will be enabled
    244236     */
    245237    public void enableBasicComponents(boolean onlyBasic) {
  • applications/editors/josm/plugins/mapdust/src/org/openstreetmap/josm/plugins/mapdust/gui/component/panel/MapdustDescriptionPanel.java

    r25591 r25754  
    8080     */
    8181    private void addComponents(String description) {
    82         if (description != null && !description.isEmpty()) {
    83             JTextArea txtDescription = new JTextArea(description);
    84             txtDescription.setLineWrap(true);
    85             txtDescription.setFont(new Font("Times New Roman", Font.BOLD, 12));
    86             txtDescription.setEditable(false);
    87             JScrollPane cmpDescription = ComponentUtil.createJScrollPane(
    88                     txtDescription, null, Color.white, true, true);
    89             cmpDescription.setPreferredSize(new Dimension(100, 100));
    90             add(cmpDescription, BorderLayout.CENTER);
    91         }
     82        description = (description != null ? description : "");
     83        JTextArea txtDescription = new JTextArea(description);
     84        txtDescription.setLineWrap(true);
     85        txtDescription.setFont(new Font("Times New Roman", Font.BOLD, 12));
     86        txtDescription.setEditable(false);
     87        JScrollPane cmpDescription = ComponentUtil.createJScrollPane(
     88                txtDescription, null, Color.white, true, true);
     89        cmpDescription.setPreferredSize(new Dimension(100, 100));
     90        add(cmpDescription, BorderLayout.CENTER);
    9291    }
    9392
  • applications/editors/josm/plugins/mapdust/src/org/openstreetmap/josm/plugins/mapdust/gui/observer/MapdustUpdateObserver.java

    r25591 r25754  
    4747     * Updates the MapDust bugs based on the given filters. If the initialUpdate
    4848     * flag is true then the filters will not be applied to the MapDust bug
    49      * data.
     49     * data. The initialUpdate flag can be true in one the following cases:
     50     * 1) After JOSM startup , 2) If the MapDust layer was re-added after a
     51     * previous deletion.
    5052     *
    5153     * @param filter The <code>MapdustBugFilter</code> object
Note: See TracChangeset for help on using the changeset viewer.