Java Code Examples for java.awt.GraphicsEnvironment#isHeadless()

The following examples show how to use java.awt.GraphicsEnvironment#isHeadless() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeFont.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException - if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}
 
Example 2
Source File: CredentialsDialog.java    From swift-k with Apache License 2.0 6 votes vote down vote up
public static char[][] showCredentialsDialog(String title,
        Prompt[] prompts, boolean forceTextMode) {
    org.globus.cog.abstraction.impl.common.CredentialsDialog cd;
    try {
        if (GraphicsEnvironment.isHeadless() || forceTextMode) {
            cd = new ConsoleCredentialsDialog(title, prompts);
        }
        else {
            cd = new SwingCredentialsDialog(title, prompts);
        }
    }
    catch (InternalError e) {
        cd = new ConsoleCredentialsDialog(title, prompts);
    }
    return cd.getResults();
}
 
Example 3
Source File: ImageWebReporter.java    From ApprovalTests.Java with Apache License 2.0 5 votes vote down vote up
/**
 * We assume any environment that is not headless will have a web browser to display the image in a web page.
 */
@Override
public boolean isWorkingInThisEnvironment(String forFile)
{
  return !GraphicsEnvironment.isHeadless()
      && GenericDiffReporter.isFileExtensionValid(forFile, GenericDiffReporter.IMAGE_FILE_EXTENSIONS);
}
 
Example 4
Source File: PropertyPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** The constructor all the other constructors call */
private PropertyPanel(Node.Property p, int preferences, PropertyModel mdl) {
    if (p == null) {
        prop = ModelProperty.toProperty(mdl);
    } else {
        prop = p;
    }

    this.preferences = preferences;
    initializing = true;
    setModel(mdl);
    initializing = false;
    setOpaque(true);

    if (!GraphicsEnvironment.isHeadless()) {
        //for debugging, allow CTRL-. to dump the state to stderr
        getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
            KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "dump"
        );
    }
    getActionMap().put(
        "dump",
        new AbstractAction() { //NOI18N
            public void actionPerformed(ActionEvent ae) {
                System.err.println(""); //NOI18N
                System.err.println(PropertyPanel.this);
                System.err.println(""); //NOI18N
            }
        }
    );

    //#44226 - Unpretty, but this allows the TreeTableView to invoke a custom editor dialog when
    //necessary - with the TTV rewrite, all cell editor infrastructure will be moved to
    //org.netbeans.modules.openide.explorer, and they will simply share editor classes.  Since that
    //involves an API change (some package private methods of PropertyEnv need to be accessible to
    //the editor classes), this will have to wait for after 4.0 - Tim
    getActionMap().put("invokeCustomEditor", new CustomEditorProxyAction()); //NOI18N

    PropertyPanelBridge.register(this, new BridgeAccessor(this));
}
 
Example 5
Source File: TestGuiAvailable.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    if (Beans.isGuiAvailable() == GraphicsEnvironment.isHeadless()) {
        throw new Error("unexpected GuiAvailable property");
    }
    Beans.setGuiAvailable(!Beans.isGuiAvailable());
    ThreadGroup group = new ThreadGroup("$$$");
    Thread thread = new Thread(group, new TestGuiAvailable());
    thread.start();
    thread.join();
}
 
Example 6
Source File: DragSource.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static Cursor load(String name) {
    if (GraphicsEnvironment.isHeadless()) {
        return null;
    }

    try {
        return (Cursor)Toolkit.getDefaultToolkit().getDesktopProperty(name);
    } catch (Exception e) {
        e.printStackTrace();

        throw new RuntimeException("failed to load system cursor: " + name + " : " + e.getMessage());
    }
}
 
Example 7
Source File: InputMethodContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static Window createInputMethodWindow(String title, InputContext context, boolean isSwing) {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    if (isSwing) {
        return new InputMethodJFrame(title, context);
    } else {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        if (toolkit instanceof InputMethodSupport) {
            return ((InputMethodSupport)toolkit).createInputMethodWindow(
                title, context);
        }
    }
    throw new InternalError("Input methods must be supported");
}
 
Example 8
Source File: NbEvents.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void notify(String text, boolean warn) {
    if (GraphicsEnvironment.isHeadless() || Boolean.getBoolean("netbeans.full.hack")) { // NOI18N
        // #21773: interferes with automated GUI testing.
        logger.log(Level.WARNING, "{0}\n", text);
    } else {
        // Normal - display dialog.
        new Notifier(text, warn).show();
    }
}
 
Example 9
Source File: DashZeroWidth.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    BufferedImage img = new BufferedImage(200, 40, TYPE_INT_ARGB);
    draw(img);
    validate(img);

    if (GraphicsEnvironment.isHeadless()) {
        return;
    }

    GraphicsConfiguration gc =
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                    .getDefaultScreenDevice().getDefaultConfiguration();

    VolatileImage vi = gc.createCompatibleVolatileImage(200, 40);
    BufferedImage snapshot;
    int attempt = 0;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        draw(vi);
        snapshot = vi.getSnapshot();
        if (!vi.contentsLost()) {
            break;
        }
    }
    validate(snapshot);
}
 
Example 10
Source File: InputMethodContext.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static Window createInputMethodWindow(String title, InputContext context, boolean isSwing) {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    if (isSwing) {
        return new InputMethodJFrame(title, context);
    } else {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        if (toolkit instanceof InputMethodSupport) {
            return ((InputMethodSupport)toolkit).createInputMethodWindow(
                title, context);
        }
    }
    throw new InternalError("Input methods must be supported");
}
 
Example 11
Source File: NetigsoUsesSwingTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static Test suite() {
    return GraphicsEnvironment.isHeadless() ? new TestSuite() : new TestSuite(NetigsoUsesSwingTest.class);
}
 
Example 12
Source File: GraphicsUtilities.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static boolean isHeadless() {
    return GraphicsEnvironment.isHeadless();
}
 
Example 13
Source File: PasteActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static Test suite() {
    return GraphicsEnvironment.isHeadless() ? new TestSuite() : new TestSuite(PasteActionTest.class);
}
 
Example 14
Source File: MergeSummarizeAndView.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean report() {

        boolean hasScaryBugs = !scaryBugs.getCollection().isEmpty();
        if (hasScaryBugs) {
            System.out.printf("%4s%n", "days");
            System.out.printf("%4s %4s %s%n", "old", "rank", "issue");
            for (BugInstance warning : scaryBugs) {
                int rank = BugRanker.findRank(warning);

                System.out.printf("%4d %s%n", rank, warning.getMessageWithoutPrefix());
            }
        }

        if (numLowConfidence > 0 || tooOld > 0) {
            if (hasScaryBugs) {
                System.out.println();
                System.out.print("plus ");
                if (numLowConfidence > 0) {
                    System.out.printf("%d less scary recent issues", numLowConfidence);
                }
                if (numLowConfidence > 0 && tooOld > 0) {
                    System.out.printf(" and ");
                }
                if (tooOld > 0) {
                    System.out.printf("%d older issues", tooOld);
                }
                System.out.println();
            }
        }

        if (hasScaryBugs || (options.alwaysShowGui && results.getCollection().size() > 0)) {
            if (GraphicsEnvironment.isHeadless()) {
                System.out.println("Running in GUI headless mode, can't open GUI");
                return false;
            }

            LaunchGUI.launchGUI(results);
            return true;
        }
        return false;

    }
 
Example 15
Source File: JFileChooser.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private static void checkDragEnabled(boolean b) {
    if (b && GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
}
 
Example 16
Source File: DragSource.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the <code>DragSource</code> object associated with
 * the underlying platform.
 *
 * @return the platform DragSource
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public static DragSource getDefaultDragSource() {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    } else {
        return dflt;
    }
}
 
Example 17
Source File: JFileChooser.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the <code>dragEnabled</code> property,
 * which must be <code>true</code> to enable
 * automatic drag handling (the first part of drag and drop)
 * on this component.
 * The <code>transferHandler</code> property needs to be set
 * to a non-<code>null</code> value for the drag to do
 * anything.  The default value of the <code>dragEnabled</code>
 * property
 * is <code>false</code>.
 *
 * <p>
 *
 * When automatic drag handling is enabled,
 * most look and feels begin a drag-and-drop operation
 * whenever the user presses the mouse button over an item
 * and then moves the mouse a few pixels.
 * Setting this property to <code>true</code>
 * can therefore have a subtle effect on
 * how selections behave.
 *
 * <p>
 *
 * Some look and feels might not support automatic drag and drop;
 * they will ignore this property.  You can work around such
 * look and feels by modifying the component
 * to directly call the <code>exportAsDrag</code> method of a
 * <code>TransferHandler</code>.
 *
 * @param b the value to set the <code>dragEnabled</code> property to
 * @exception HeadlessException if
 *            <code>b</code> is <code>true</code> and
 *            <code>GraphicsEnvironment.isHeadless()</code>
 *            returns <code>true</code>
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @see #getDragEnabled
 * @see #setTransferHandler
 * @see TransferHandler
 * @since 1.4
 *
 * @beaninfo
 *  description: determines whether automatic drag handling is enabled
 *        bound: false
 */
public void setDragEnabled(boolean b) {
    if (b && GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    dragEnabled = b;
}
 
Example 18
Source File: JFileChooser.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the <code>dragEnabled</code> property,
 * which must be <code>true</code> to enable
 * automatic drag handling (the first part of drag and drop)
 * on this component.
 * The <code>transferHandler</code> property needs to be set
 * to a non-<code>null</code> value for the drag to do
 * anything.  The default value of the <code>dragEnabled</code>
 * property
 * is <code>false</code>.
 *
 * <p>
 *
 * When automatic drag handling is enabled,
 * most look and feels begin a drag-and-drop operation
 * whenever the user presses the mouse button over an item
 * and then moves the mouse a few pixels.
 * Setting this property to <code>true</code>
 * can therefore have a subtle effect on
 * how selections behave.
 *
 * <p>
 *
 * Some look and feels might not support automatic drag and drop;
 * they will ignore this property.  You can work around such
 * look and feels by modifying the component
 * to directly call the <code>exportAsDrag</code> method of a
 * <code>TransferHandler</code>.
 *
 * @param b the value to set the <code>dragEnabled</code> property to
 * @exception HeadlessException if
 *            <code>b</code> is <code>true</code> and
 *            <code>GraphicsEnvironment.isHeadless()</code>
 *            returns <code>true</code>
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @see #getDragEnabled
 * @see #setTransferHandler
 * @see TransferHandler
 * @since 1.4
 *
 * @beaninfo
 *  description: determines whether automatic drag handling is enabled
 *        bound: false
 */
public void setDragEnabled(boolean b) {
    if (b && GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    dragEnabled = b;
}
 
Example 19
Source File: DragSource.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a new <code>DragSource</code>.
 *
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DragSource() throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
}
 
Example 20
Source File: DragSource.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a new <code>DragSource</code>.
 *
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DragSource() throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
}