Changeset 9804 in josm for trunk


Ignore:
Timestamp:
2016-02-14T23:11:00+01:00 (9 years ago)
Author:
Don-vip
Message:

robustness/code refactoring for unit tests

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DownloadAlongAction.java

    r8929 r9804  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.GraphicsEnvironment;
    67import java.awt.GridBagLayout;
    78import java.awt.geom.Area;
     
    110111                tr("<html>This action will require {0} individual<br>" + "download requests. Do you wish<br>to continue?</html>",
    111112                        toDownload.size())), GBC.eol());
    112         if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(Main.parent, msg, title,
    113                 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) {
     113        if (!GraphicsEnvironment.isHeadless() && JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(
     114                Main.parent, msg, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) {
    114115            return;
    115116        }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java

    r9243 r9804  
    77import java.awt.Component;
    88import java.awt.Dimension;
     9import java.awt.GraphicsEnvironment;
    910import java.awt.GridBagLayout;
    1011import java.awt.event.ActionEvent;
     
    271272        msg.add(scrollPane, GBC.eol().fill(GBC.BOTH));
    272273
    273         // build dialog
    274         ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Set track visibility for {0}", layer.getName()),
    275                 new String[]{tr("Show all"), tr("Show selected only"), tr("Cancel")});
    276         ed.setButtonIcons(new String[]{"eye", "dialogs/filter", "cancel"});
    277         ed.setContent(msg, false);
    278         ed.setDefaultButton(2);
    279         ed.setCancelButton(3);
    280         ed.configureContextsensitiveHelp("/Action/ChooseTrackVisibility", true);
    281         ed.setRememberWindowGeometry(getClass().getName() + ".geometry", WindowGeometry.centerInWindow(Main.parent, new Dimension(1000, 500)));
    282         ed.showDialog();
    283         dateFilter.saveInPrefs();
    284         int v = ed.getValue();
    285         // cancel for unknown buttons and copy back original settings
    286         if (v != 1 && v != 2) {
    287             layer.trackVisibility = Arrays.copyOf(trackVisibilityBackup, layer.trackVisibility.length);
    288             Main.map.repaint();
    289             return;
     274        int v = 1;
     275        if (!GraphicsEnvironment.isHeadless()) {
     276            // build dialog
     277            ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Set track visibility for {0}", layer.getName()),
     278                    new String[]{tr("Show all"), tr("Show selected only"), tr("Cancel")});
     279            ed.setButtonIcons(new String[]{"eye", "dialogs/filter", "cancel"});
     280            ed.setContent(msg, false);
     281            ed.setDefaultButton(2);
     282            ed.setCancelButton(3);
     283            ed.configureContextsensitiveHelp("/Action/ChooseTrackVisibility", true);
     284            ed.setRememberWindowGeometry(getClass().getName() + ".geometry",
     285                    WindowGeometry.centerInWindow(Main.parent, new Dimension(1000, 500)));
     286            ed.showDialog();
     287            dateFilter.saveInPrefs();
     288            v = ed.getValue();
     289            // cancel for unknown buttons and copy back original settings
     290            if (v != 1 && v != 2) {
     291                layer.trackVisibility = Arrays.copyOf(trackVisibilityBackup, layer.trackVisibility.length);
     292                Main.map.repaint();
     293                return;
     294            }
    290295        }
    291296        // set visibility (1 = show all, 2 = filter). If no tracks are selected
     
    299304        layer.setVisible(v == 1 || !s.isSelectionEmpty());
    300305
    301         Main.map.mapView.preferenceChanged(null);
    302         Main.map.repaint();
    303     }
    304 
     306        if (Main.isDisplayingMapView()) {
     307            Main.map.mapView.preferenceChanged(null);
     308        }
     309        if (Main.map != null) {
     310            Main.map.repaint();
     311        }
     312    }
    305313}
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongPanel.java

    r8672 r9804  
    55
    66import java.awt.Dimension;
     7import java.awt.GraphicsEnvironment;
    78import java.awt.GridBagLayout;
    89
     
    185186        });
    186187
    187         int ret = HelpAwareOptionPane.showOptionDialog(Main.parent, this, title,
    188                 JOptionPane.QUESTION_MESSAGE, null, options, options[0], helpTopic);
     188        int ret = 0;
     189        if (!GraphicsEnvironment.isHeadless()) {
     190            ret = HelpAwareOptionPane.showOptionDialog(Main.parent, this, title,
     191                    JOptionPane.QUESTION_MESSAGE, null, options, options[0], helpTopic);
     192        }
    189193        if (0 == ret) {
    190194            rememberSettings();
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackAction.java

    r9078 r9804  
    2323 *
    2424 * @author fred
     25 * @since 5715
    2526 */
    2627public class DownloadAlongTrackAction extends DownloadAlongAction {
     
    4849    }
    4950
    50     @Override
    51     public void actionPerformed(ActionEvent e) {
    52 
     51    PleaseWaitRunnable createTask() {
    5352        final DownloadAlongPanel panel = new DownloadAlongPanel(
    5453                PREF_DOWNLOAD_ALONG_TRACK_OSM, PREF_DOWNLOAD_ALONG_TRACK_GPS,
     
    5655
    5756        if (0 != panel.showInDownloadDialog(tr("Download from OSM along this track"), HelpUtil.ht("/Action/DownloadAlongTrack"))) {
    58             return;
     57            return null;
    5958        }
    6059
     
    186185        }
    187186
    188         Main.worker.submit(new CalculateDownloadArea());
     187        return new CalculateDownloadArea();
     188    }
     189
     190    @Override
     191    public void actionPerformed(ActionEvent e) {
     192        Main.worker.submit(createTask());
    189193    }
    190194}
Note: See TracChangeset for help on using the changeset viewer.