Changeset 9576 in josm


Ignore:
Timestamp:
2016-01-23T04:49:01+01:00 (4 years ago)
Author:
Don-vip
Message:

code refactoring for unit tests / headless mode

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

Legend:

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

    r9067 r9576  
    99import java.awt.GraphicsEnvironment;
    1010import java.awt.Rectangle;
    11 import java.awt.Toolkit;
    1211import java.awt.Window;
    1312import java.awt.event.ActionEvent;
     
    2120
    2221import org.openstreetmap.josm.Main;
     22import org.openstreetmap.josm.gui.util.GuiHelper;
    2323import org.openstreetmap.josm.tools.Shortcut;
    2424
     
    8484        if (selected) {
    8585            prevBounds = frame.getBounds();
    86             frame.setBounds(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
     86            frame.setBounds(new Rectangle(GuiHelper.getScreenSize()));
    8787        }
    8888
  • trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java

    r8978 r9576  
    99import java.awt.GridBagLayout;
    1010import java.awt.Insets;
    11 import java.awt.Toolkit;
    1211import java.awt.event.ActionEvent;
    1312import java.awt.event.KeyEvent;
     
    438437     */
    439438    protected Dimension findMaxDialogSize() {
    440         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     439        Dimension screenSize = GuiHelper.getScreenSize();
    441440        Dimension x = new Dimension(screenSize.width*2/3, screenSize.height*2/3);
    442441        if (parent != null) {
     
    626625        JMultilineLabel lbl = new JMultilineLabel(msg);
    627626        // Make it not wider than 1/2 of the screen
    628         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     627        Dimension screenSize = GuiHelper.getScreenSize();
    629628        lbl.setMaxWidth(screenSize.width/2);
    630629        // Disable default Enter key binding to allow dialog's one (then enables to hit default button from here)
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r9346 r9576  
    414414        private Popup popupCreatePopup(Component content, MouseState ms) {
    415415            Point p = mv.getLocationOnScreen();
    416             Dimension scrn = Toolkit.getDefaultToolkit().getScreenSize();
     416            Dimension scrn = GuiHelper.getScreenSize();
    417417
    418418            // Create a JScrollPane around the content, in case there's not enough space
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r9564 r9576  
    1414import java.awt.GridBagConstraints;
    1515import java.awt.GridBagLayout;
    16 import java.awt.Toolkit;
    1716import java.awt.datatransfer.Clipboard;
    1817import java.awt.datatransfer.Transferable;
     
    505504        private void selectACComboBoxSavingUnixBuffer(AutoCompletingComboBox cb) {
    506505            // select combobox with saving unix system selection (middle mouse paste)
    507             Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection();
     506            Clipboard sysSel = GuiHelper.getSystemSelection();
    508507            if (sysSel != null) {
    509508                Transferable old = Utils.getTransferableContent(sysSel);
  • trunk/src/org/openstreetmap/josm/gui/download/SlippyMapChooser.java

    r8932 r9576  
    55
    66import java.awt.Dimension;
    7 import java.awt.Toolkit;
    87import java.beans.PropertyChangeEvent;
    98import java.beans.PropertyChangeListener;
     
    1514import org.openstreetmap.josm.gui.bbox.BBoxChooser;
    1615import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
     16import org.openstreetmap.josm.gui.util.GuiHelper;
    1717
    1818/**
     
    5959
    6060            // retrieve the size of the display
    61             Dimension iScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
     61            Dimension iScreenSize = GuiHelper.getScreenSize();
    6262
    6363            if (iDownloadDialogDimension == null) {
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r9478 r9576  
    66import java.awt.Color;
    77import java.awt.Component;
     8import java.awt.Dimension;
    89import java.awt.Font;
    910import java.awt.Graphics;
    1011import java.awt.Graphics2D;
    11 import java.awt.GraphicsEnvironment;
    1212import java.awt.GridBagLayout;
    1313import java.awt.Image;
     
    8484import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    8585import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     86import org.openstreetmap.josm.gui.util.GuiHelper;
    8687import org.openstreetmap.josm.io.WMSLayerImporter;
    8788import org.openstreetmap.josm.tools.GBC;
     
    670671
    671672    protected int estimateTileCacheSize() {
    672         // Default screen size in headless mode, for unit tests
    673         int height = 800;
    674         int width = 600;
    675         if (!GraphicsEnvironment.isHeadless()) {
    676             height = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
    677             width = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
    678         }
     673        Dimension screenSize = GuiHelper.getScreenSize();
     674        int height = screenSize.height;
     675        int width = screenSize.width;
    679676        int tileSize = 256; // default tile size
    680677        if (tileSource != null) {
  • trunk/src/org/openstreetmap/josm/gui/layer/AlignImageryPanel.java

    r9391 r9576  
    77import java.awt.Font;
    88import java.awt.GridBagLayout;
    9 import java.awt.Toolkit;
    109import java.awt.event.ActionEvent;
    1110import java.awt.event.ActionListener;
     
    2120import org.openstreetmap.josm.data.imagery.ImageryInfo;
    2221import org.openstreetmap.josm.data.preferences.BooleanProperty;
     22import org.openstreetmap.josm.gui.util.GuiHelper;
    2323import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    2424import org.openstreetmap.josm.gui.widgets.UrlLabel;
     
    9090        if (Main.isDisplayingMapView() && showAgain.get() && !infoToAdd.isGeoreferenceValid()) {
    9191            if (Main.map.getTopPanel(AlignImageryPanel.class) == null) {
    92                 double w = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
     92                double w = GuiHelper.getScreenSize().getWidth();
    9393                AlignImageryPanel p = new AlignImageryPanel(w > 1300, showAgain, infoToAdd);
    9494                Main.map.addTopPanel(p);
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/CustomizeDrawingAction.java

    r8509 r9576  
    77import java.awt.Component;
    88import java.awt.Dimension;
    9 import java.awt.Toolkit;
    109import java.awt.event.ActionEvent;
    1110import java.util.LinkedList;
     
    8382        JScrollPane scrollpane = GuiHelper.embedInVerticalScrollPane(panel);
    8483        scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    85         int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
     84        int screenHeight = GuiHelper.getScreenSize().height;
    8685        if (screenHeight < 700) {
    8786            // to fit on screen 800x600
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackAction.java

    r8526 r9576  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.GraphicsEnvironment;
    67import java.awt.GridBagLayout;
    78import java.awt.event.ActionEvent;
    89import java.io.IOException;
    910import java.util.ArrayList;
    10 import java.util.Collection;
    1111import java.util.List;
    1212
     
    103103
    104104    protected AbstractTileSourceLayer askedLayer() {
    105         Collection<AbstractTileSourceLayer> targetLayers = Main.map.mapView.getLayersOfType(AbstractTileSourceLayer.class);
     105        List<AbstractTileSourceLayer> targetLayers = Main.map.mapView.getLayersOfType(AbstractTileSourceLayer.class);
    106106        if (targetLayers.isEmpty()) {
    107             warnNoImageryLayers();
     107            if (!GraphicsEnvironment.isHeadless()) {
     108                warnNoImageryLayers();
     109            }
    108110            return null;
    109111        }
     
    114116        pnl.add(new JLabel(tr("Please select the imagery layer.")), GBC.eol());
    115117        pnl.add(layerList, GBC.eol());
     118        if (GraphicsEnvironment.isHeadless()) {
     119            // return first layer in headless mode, for unit tests
     120            return targetLayers.get(0);
     121        }
    116122        ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Select imagery layer"), new String[]{tr("Download"), tr("Cancel")});
    117123        ed.setButtonIcons(new String[]{"dialogs/down", "cancel"});
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java

    r8836 r9576  
    1111import java.awt.GridBagLayout;
    1212import java.awt.Insets;
    13 import java.awt.Toolkit;
    1413import java.awt.event.ActionEvent;
    1514import java.awt.event.ActionListener;
     
    3231import org.openstreetmap.josm.gui.help.HelpUtil;
    3332import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener;
     33import org.openstreetmap.josm.gui.util.GuiHelper;
    3434import org.openstreetmap.josm.tools.GBC;
    3535import org.openstreetmap.josm.tools.ImageProvider;
     
    8484        // set the maximum width to the current screen. If the dialog is opened on a
    8585        // smaller screen than before, this will reset the stored preference.
    86         this.setMaximumSize(Toolkit.getDefaultToolkit().getScreenSize());
     86        this.setMaximumSize(GuiHelper.getScreenSize());
    8787    }
    8888
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java

    r9575 r9576  
    33
    44import java.awt.Component;
    5 import java.awt.GraphicsEnvironment;
    6 import java.awt.Toolkit;
    75import java.awt.datatransfer.Clipboard;
    86import java.awt.datatransfer.Transferable;
     
    2624
    2725import org.openstreetmap.josm.Main;
     26import org.openstreetmap.josm.gui.util.GuiHelper;
    2827import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    2928import org.openstreetmap.josm.tools.Utils;
     
    133132            final JTextComponent editorComponent = comboBox.getEditorComponent();
    134133            // save unix system selection (middle mouse paste)
    135             Clipboard sysSel = GraphicsEnvironment.isHeadless() ? null : Toolkit.getDefaultToolkit().getSystemSelection();
     134            Clipboard sysSel = GuiHelper.getSystemSelection();
    136135            if (sysSel != null) {
    137136                Transferable old = Utils.getTransferableContent(sysSel);
     
    198197                        }
    199198                        // save unix system selection (middle mouse paste)
    200                         Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection();
     199                        Clipboard sysSel = GuiHelper.getSystemSelection();
    201200                        if (sysSel != null) {
    202201                            Transferable old = Utils.getTransferableContent(sysSel);
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r9246 r9576  
    1111import java.awt.Dimension;
    1212import java.awt.Font;
     13import java.awt.GraphicsEnvironment;
    1314import java.awt.GridBagLayout;
    1415import java.awt.Image;
     
    1617import java.awt.Toolkit;
    1718import java.awt.Window;
     19import java.awt.datatransfer.Clipboard;
    1820import java.awt.event.ActionListener;
    1921import java.awt.event.HierarchyEvent;
     
    383385        c.setForeground(ColorHelper.getForegroundColor(background));
    384386    }
     387
     388    /**
     389     * Gets the size of the screen. On systems with multiple displays, the primary display is used.
     390     * This method returns always 800x600 in headless mode (useful for unit tests).
     391     * @return the size of this toolkit's screen, in pixels, or 800x600
     392     * @see Toolkit#getScreenSize
     393     * @since 9576
     394     */
     395    public static Dimension getScreenSize() {
     396        return GraphicsEnvironment.isHeadless() ? new Dimension(800, 600) : Toolkit.getDefaultToolkit().getScreenSize();
     397    }
     398
     399    /**
     400     * Gets the singleton instance of the system selection as a <code>Clipboard</code> object.
     401     * This allows an application to read and modify the current, system-wide selection.
     402     * @return the system selection as a <code>Clipboard</code>, or <code>null</code> if the native platform does not
     403     *         support a system selection <code>Clipboard</code> or if GraphicsEnvironment.isHeadless() returns true
     404     * @see Toolkit#getSystemSelection
     405     * @since 9576
     406     */
     407    public static Clipboard getSystemSelection() {
     408        return GraphicsEnvironment.isHeadless() ? null : Toolkit.getDefaultToolkit().getSystemSelection();
     409    }
    385410}
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmComboBox.java

    r9546 r9576  
    44import java.awt.Component;
    55import java.awt.Dimension;
    6 import java.awt.GraphicsEnvironment;
    7 import java.awt.Toolkit;
    86import java.awt.event.MouseAdapter;
    97import java.awt.event.MouseEvent;
     
    2422import javax.swing.plaf.basic.ComboPopup;
    2523import javax.swing.text.JTextComponent;
     24
     25import org.openstreetmap.josm.gui.util.GuiHelper;
    2626
    2727/**
     
    167167        if (prototype != null) {
    168168            setPrototypeDisplayValue(prototype);
    169             int screenHeight = GraphicsEnvironment.isHeadless() ? 600 : Toolkit.getDefaultToolkit().getScreenSize().height;
     169            int screenHeight = GuiHelper.getScreenSize().height;
    170170            // Compute maximum number of visible items based on the preferred size of the combo box.
    171171            // This assumes that items have the same height as the combo box, which is not granted by the look and feel
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r9230 r9576  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.HeadlessException;
    7 import java.awt.Toolkit;
     6import java.awt.Dimension;
    87import java.util.HashMap;
    98import java.util.Map;
     
    1312import org.openstreetmap.josm.data.coor.LatLon;
    1413import org.openstreetmap.josm.data.projection.Ellipsoid;
     14import org.openstreetmap.josm.gui.util.GuiHelper;
    1515
    1616public final class OsmUrlToBounds {
     
    191191    public static Bounds positionToBounds(final double lat, final double lon, final int zoom) {
    192192        int tileSizeInPixels = 256;
    193         int height;
    194         int width;
    195         try {
    196             height = Toolkit.getDefaultToolkit().getScreenSize().height;
    197             width = Toolkit.getDefaultToolkit().getScreenSize().width;
    198             if (Main.isDisplayingMapView()) {
    199                 height = Main.map.mapView.getHeight();
    200                 width = Main.map.mapView.getWidth();
    201             }
    202         } catch (HeadlessException he) {
    203             // in headless mode, when running tests
    204             height = 480;
    205             width = 640;
     193        Dimension screenSize = GuiHelper.getScreenSize();
     194        int height = screenSize.height;
     195        int width = screenSize.width;
     196        if (Main.isDisplayingMapView()) {
     197            height = Main.map.mapView.getHeight();
     198            width = Main.map.mapView.getWidth();
    206199        }
    207200        double scale = (1 << zoom) * tileSizeInPixels / (2 * Math.PI * Ellipsoid.WGS84.a);
  • trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java

    r9062 r9576  
    1212import java.awt.Point;
    1313import java.awt.Rectangle;
    14 import java.awt.Toolkit;
    1514import java.awt.Window;
    1615import java.util.regex.Matcher;
     
    2019
    2120import org.openstreetmap.josm.Main;
     21import org.openstreetmap.josm.gui.util.GuiHelper;
    2222
    2323/**
     
    468468     */
    469469    public static Rectangle getFullScreenInfo() {
    470         return new Rectangle(new Point(0, 0), Toolkit.getDefaultToolkit().getScreenSize());
     470        return new Rectangle(new Point(0, 0), GuiHelper.getScreenSize());
    471471    }
    472472
Note: See TracChangeset for help on using the changeset viewer.