Changeset 7075 in josm


Ignore:
Timestamp:
2014-05-08T02:40:40+02:00 (10 years ago)
Author:
Don-vip
Message:

Robustness to allow to run more unit tests in headless mode

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/GettingStarted.java

    r6935 r7075  
    77import java.awt.BorderLayout;
    88import java.awt.EventQueue;
     9import java.awt.GraphicsEnvironment;
    910import java.awt.event.InputEvent;
    1011import java.awt.event.KeyEvent;
     
    126127        getMOTD();
    127128
    128         new FileDrop(scroller);
     129        if (!GraphicsEnvironment.isHeadless()) {
     130            new FileDrop(scroller);
     131        }
    129132    }
    130133
  • trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java

    r7005 r7075  
    66
    77import java.awt.Component;
     8import java.awt.GraphicsEnvironment;
    89import java.awt.MenuComponent;
    910import java.awt.Toolkit;
     
    104105        MainMenu.add(subMenu, rectaction);
    105106    }
    106    
     107
    107108    private void setupMenuScroller() {
    108         int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    109         int menuItemHeight = singleOffset.getPreferredSize().height;
    110         MenuScroller.setScrollerFor(this, (screenHeight / menuItemHeight)-1);
     109        if (!GraphicsEnvironment.isHeadless()) {
     110            int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
     111            int menuItemHeight = singleOffset.getPreferredSize().height;
     112            MenuScroller.setScrollerFor(this, (screenHeight / menuItemHeight)-1);
     113        }
    111114    }
    112115
     
    234237
    235238    /**
    236      * Collection to store temporary menu items. They will be deleted 
     239     * Collection to store temporary menu items. They will be deleted
    237240     * (and possibly recreated) when refreshImageryMenu() is called.
    238241     * @since 5803
    239242     */
    240243    private List <Object> dynamicItems = new ArrayList<>(20);
    241    
     244
    242245    /**
    243246     * Remove all the items in @field dynamicItems collection
     
    264267        add(s);
    265268    }
    266    
     269
    267270    private void addDynamic(Action a) {
    268271        dynamicItems.add( this.add(a) );
    269272    }
    270    
     273
    271274    private void addDynamic(JMenuItem it) {
    272275        dynamicItems.add( this.add(it) );
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r7026 r7075  
    77
    88import java.awt.Component;
     9import java.awt.GraphicsEnvironment;
    910import java.awt.Toolkit;
    1011import java.awt.event.KeyEvent;
     
    567568    public JMenu addMenu(String name, int mnemonicKey, int position, String relativeHelpTopic) {
    568569        final JMenu menu = new JMenu(tr(name));
    569         int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    570         int menuItemHeight = new JMenu().add(newAction).getPreferredSize().height;
    571         MenuScroller.setScrollerFor(menu, screenHeight / menuItemHeight);
     570        if (!GraphicsEnvironment.isHeadless()) {
     571            int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
     572            int menuItemHeight = new JMenu().add(newAction).getPreferredSize().height;
     573            MenuScroller.setScrollerFor(menu, screenHeight / menuItemHeight);
     574        }
    572575        return addMenu(menu, name, mnemonicKey, position, relativeHelpTopic);
    573576    }
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r7005 r7075  
    99import java.awt.Dimension;
    1010import java.awt.Font;
     11import java.awt.GraphicsEnvironment;
    1112import java.awt.GridBagLayout;
    1213import java.awt.Rectangle;
     
    5354import org.openstreetmap.josm.actions.mapmode.ZoomAction;
    5455import org.openstreetmap.josm.data.Preferences;
    55 import org.openstreetmap.josm.data.ViewportData;
    5656import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    5757import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     58import org.openstreetmap.josm.data.ViewportData;
    5859import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    5960import org.openstreetmap.josm.gui.dialogs.ChangesetDialog;
     
    161162
    162163        mapView = new MapView(contentPane, viewportData);
    163         new FileDrop(mapView);
     164        if (!GraphicsEnvironment.isHeadless()) {
     165            new FileDrop(mapView);
     166        }
    164167
    165168        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
     
    599602
    600603    /**
    601      * Remove panel from top of MapView by class     
     604     * Remove panel from top of MapView by class
    602605     */
    603606    public void removeTopPanel(Class<?> type) {
  • trunk/src/org/openstreetmap/josm/io/auth/AbstractCredentialsAgent.java

    r7067 r7075  
    22package org.openstreetmap.josm.io.auth;
    33
     4import java.awt.GraphicsEnvironment;
    45import java.net.Authenticator.RequestorType;
    56import java.net.PasswordAuthentication;
     
    4445         */
    4546        } else if (noSuccessWithLastResponse || username.isEmpty() || password.isEmpty()) {
    46             GuiHelper.runInEDTAndWait(new Runnable() {
    47                 @Override
    48                 public void run() {
    49                     CredentialDialog dialog = null;
    50                     if (requestorType.equals(RequestorType.PROXY))
    51                         dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText());
    52                     else
    53                         dialog = CredentialDialog.getOsmApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText());
    54                     dialog.setVisible(true);
    55                     response.setCanceled(dialog.isCanceled());
    56                     if (dialog.isCanceled())
    57                         return;
    58                     response.setUsername(dialog.getUsername());
    59                     response.setPassword(dialog.getPassword());
    60                     response.setSaveCredentials(dialog.isSaveCredentials());
    61                 }
    62             });
     47            if (!GraphicsEnvironment.isHeadless()) {
     48                GuiHelper.runInEDTAndWait(new Runnable() {
     49                    @Override
     50                    public void run() {
     51                        CredentialDialog dialog = null;
     52                        if (requestorType.equals(RequestorType.PROXY))
     53                            dialog = CredentialDialog.getHttpProxyCredentialDialog(
     54                                    username, password, host, getSaveUsernameAndPasswordCheckboxText());
     55                        else
     56                            dialog = CredentialDialog.getOsmApiCredentialDialog(
     57                                    username, password, host, getSaveUsernameAndPasswordCheckboxText());
     58                        dialog.setVisible(true);
     59                        response.setCanceled(dialog.isCanceled());
     60                        if (dialog.isCanceled())
     61                            return;
     62                        response.setUsername(dialog.getUsername());
     63                        response.setPassword(dialog.getPassword());
     64                        response.setSaveCredentials(dialog.isSaveCredentials());
     65                    }
     66                });
     67            }
    6368            if (response.isCanceled() || response.getUsername() == null || response.getPassword() == null) {
    6469                return response;
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r7033 r7075  
    88import java.awt.Graphics;
    99import java.awt.Graphics2D;
    10 import java.awt.GraphicsConfiguration;
    1110import java.awt.GraphicsEnvironment;
    1211import java.awt.Image;
     
    1413import java.awt.RenderingHints;
    1514import java.awt.Toolkit;
    16 import java.awt.Transparency;
    1715import java.awt.image.BufferedImage;
    1816import java.io.ByteArrayInputStream;
     
    793791            img = overlay(img, ImageProvider.get("cursor/modifier/" + overlay), OverlayPosition.SOUTHEAST);
    794792        }
     793        if (GraphicsEnvironment.isHeadless()) {
     794            Main.warn("Cursors are not available in headless mode. Returning null for '"+name+"'");
     795            return null;
     796        }
    795797        return Toolkit.getDefaultToolkit().createCustomCursor(img.getImage(),
    796798                "crosshair".equals(name) ? new Point(10, 10) : new Point(3, 2), "Cursor");
     
    808810     */
    809811    public static ImageIcon overlay(Icon ground, Icon overlay, OverlayPosition pos) {
    810         GraphicsConfiguration conf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
    811                 .getDefaultConfiguration();
    812812        int w = ground.getIconWidth();
    813813        int h = ground.getIconHeight();
    814814        int wo = overlay.getIconWidth();
    815815        int ho = overlay.getIconHeight();
    816         BufferedImage img = conf.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
     816        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    817817        Graphics g = img.createGraphics();
    818818        ground.paintIcon(null, g, 0, 0);
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r7037 r7075  
    9999    @Override
    100100    public boolean canFullscreen() {
    101         return GraphicsEnvironment.getLocalGraphicsEnvironment()
     101        return !GraphicsEnvironment.isHeadless() &&
     102                GraphicsEnvironment.getLocalGraphicsEnvironment()
    102103        .getDefaultScreenDevice().isFullScreenSupported();
    103104    }
     
    328329    }
    329330
    330     // Method kept because strings have already been translated. To enable for Java 8 migration somewhere in 2016 
     331    // Method kept because strings have already been translated. To enable for Java 8 migration somewhere in 2016
    331332    protected void askUpdateJava(final String version, final String url) {
    332333        GuiHelper.runInEDTAndWait(new Runnable() {
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java

    r7070 r7075  
    44import java.io.File;
    55import java.io.IOException;
    6 import java.util.Collection;
    76import java.util.Collections;
    87import java.util.HashMap;
     
    1918import org.openstreetmap.josm.gui.layer.Layer;
    2019import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     20import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
     21import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
    2122import org.openstreetmap.josm.tools.MultiMap;
    2223
     
    7576        Main.initApplicationPreferences();
    7677        Main.determinePlatformHook();
    77         Main.preConstructorInit(new HashMap<MainApplication.Option, Collection<String>>());
     78        ProjectionPreference.setProjection();
     79        Main.toolbar = new ToolbarPreferences();
    7880        new MainApplication();
    7981        Main.main.createMapFrame(null, null);
Note: See TracChangeset for help on using the changeset viewer.