Ignore:
Timestamp:
2016-03-23T22:36:15+01:00 (8 years ago)
Author:
Don-vip
Message:

code refactoring to ease creation of unit tests by avoiding as much as possible HeadlessException

File:
1 edited

Legend:

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

    r10024 r10035  
    1212import java.awt.DisplayMode;
    1313import java.awt.Font;
     14import java.awt.Frame;
    1415import java.awt.GraphicsDevice;
    1516import java.awt.GraphicsEnvironment;
     
    509510        });
    510511    }
     512
     513    /**
     514     * Returns the specified component's <code>Frame</code> without throwing exception in headless mode.
     515     *
     516     * @param parentComponent the <code>Component</code> to check for a <code>Frame</code>
     517     * @return the <code>Frame</code> that contains the component, or <code>getRootFrame</code>
     518     *         if the component is <code>null</code>, or does not have a valid <code>Frame</code> parent
     519     * @see JOptionPane#getFrameForComponent
     520     * @see GraphicsEnvironment#isHeadless
     521     * @since 10035
     522     */
     523    public static Frame getFrameForComponent(Component parentComponent) {
     524        if (parentComponent == null && GraphicsEnvironment.isHeadless()) {
     525            return null;
     526        }
     527        return JOptionPane.getFrameForComponent(parentComponent);
     528    }
    511529}
Note: See TracChangeset for help on using the changeset viewer.