Java Code Examples for java.awt.HeadlessException

The following examples show how to use java.awt.HeadlessException. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
public static void main(final String[] args) throws HeadlessException {
    final Frame frame = new Frame("Test Frame");
    final List list = new List();
    frame.setSize(300, 200);
    list.add(ITEM_NAME);
    list.select(0);
    frame.add(list);
    frame.validate();
    frame.setVisible(true);
    sleep();
    if (!ITEM_NAME.equals(list.getSelectedItem())) {
        throw new RuntimeException("List item not selected item.");
    }
    list.removeAll();
    frame.dispose();
}
 
Example 2
@Test
public void testStuff()
    throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException {
  try {
    if (ImprovedFileChooser.isMacOs) {
      System.setProperty("apple.laf.useScreenMenuBar", "true");
    } else {
      for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    }
    ImprovedFileChooser fileChooser = new ImprovedFileChooser();
    fileChooser.setPreferredSize(new Dimension(1000, 750));
    fileChooser.showDialog(null, "Choose");
  } catch (HeadlessException e) {
    // ok to fail if there is no display
  }
}
 
Example 3
/**
 * Test the processing of modFeat. Checks that when in select single and
 * close mode, only one instance of a feat with a sub-choice is added.
 */
@Test
public void testModFeat()
{
	readyToRun();
	final PlayerCharacter character = new PlayerCharacter();
	character.setRace(human);
	character.incrementClassLevel(1, pcClass, true);

	UIPropertyContext.setSingleChoiceAction(Constants.CHOOSER_SINGLE_CHOICE_METHOD_SELECT_EXIT);
	ChooserFactory.useRandomChooser();

	assertEquals(
			2, (int)character.getRemainingFeatPoints(true),
			"Start with 2 feats"
	);
	try
	{
		AbstractCharacterTestCase.applyAbility(character, BuildUtilities.getFeatCat(), toughness, "");
	}
	catch (HeadlessException e)
	{
		Logging.debugPrint("Ignoring Headless exception.");
	}
	assertEquals(1, (int)character.getRemainingFeatPoints(true), "Only 1 feat used");
}
 
Example 4
public static void main(final String[] args) throws HeadlessException {
    final Frame frame = new Frame("Test Frame");
    final List list = new List();
    frame.setSize(300, 200);
    list.add(ITEM_NAME);
    list.select(0);
    frame.add(list);
    frame.validate();
    frame.setVisible(true);
    sleep();
    if (!ITEM_NAME.equals(list.getSelectedItem())) {
        throw new RuntimeException("List item not selected item.");
    }
    list.removeAll();
    frame.dispose();
}
 
Example 5
Source Project: Spark   Source File: SparkTrustManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
    try {
        doTheChecks(chain, authType);
    } catch (CertPathValidatorException e) {
        try {
            SwingUtilities.invokeLater(new Runnable() {
                
                @Override
                public void run() {
                certControll.addChain(chain);
                }
            });

        } catch (HeadlessException e1) {
            Log.error("Couldn't add certificate from presented chain");
        }
        throw new CertificateException(e);
    }
}
 
Example 6
Source Project: Spark   Source File: MutualAuthenticationSettingsPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void createSelfSignedCertificate() {
idControll.setUpData(commonNameField.getText(), organizationUnitField.getText(), organizationField.getText(), countryField.getText(),
	cityField.getText());
try {
    KeyPair keyPair = idControll.createKeyPair();

    X509Certificate cert = idControll.createSelfSignedCertificate(keyPair);
           if (saveCertToFile.isSelected()) {
               PemBuilder pemBuilder = new PemHelper().new PemBuilder();
               pemBuilder.add(keyPair.getPrivate());
               pemBuilder.add(cert);
               pemBuilder.saveToPemFile(IdentityController.CERT_FILE);
               JOptionPane.showMessageDialog(null,
                       Res.getString("dialog.self.signed.certificate.has.been.created") + IdentityController.SECURITY_DIRECTORY.toString());
           } else {
               try {
                   idControll.addEntryToKeyStore(cert, keyPair.getPrivate());
               } catch (HeadlessException | InvalidNameException | KeyStoreException e) {
                       Log.error("Couldn't save entry to IdentityStore", e);
               }
           }
} catch (NoSuchAlgorithmException | NoSuchProviderException | IOException | OperatorCreationException | CertificateException e1) {
    Log.error("Couldn't create Self Signed Certificate", e1);
}
   }
 
Example 7
@Test
public void testPanel() {
  try {
    PrefPanel pp = new PrefPanel("title", (PreferencesExt) store.node("test"));
    pp.addTextField("name", "name", "defValue");
    Field.Text longF = pp.addTextField("Longname", "Longname",
        "defValue really long name for to be with starting value gotta adjust the thing");
    Field.Int iu = pp.addIntField("testIU", "number of times to barf", 2);
    pp.finish();
  } catch (HeadlessException e) {
    // ok to fail if there is no display
  }
}
 
Example 8
Source Project: openjdk-jdk8u   Source File: DropTarget.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 9
Source Project: jdk1.8-source-analysis   Source File: DropTarget.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 10
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
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 12
Source Project: hottub   Source File: InputMethodContext.java    License: 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 13
Source Project: gama   Source File: StyleAttribute.java    License: GNU General Public License v3.0 5 votes vote down vote up
static public float convertUnitsToPixels(final int unitType, final float value) {
	if (unitType == NumberWithUnits.UT_UNITLESS || unitType == NumberWithUnits.UT_PERCENT) { return value; }

	float pixPerInch;
	try {
		pixPerInch = Toolkit.getDefaultToolkit().getScreenResolution();
	} catch (final HeadlessException ex) {
		// default to 72 dpi
		pixPerInch = 72;
	}
	final float inchesPerCm = .3936f;

	switch (unitType) {
		case NumberWithUnits.UT_IN:
			return value * pixPerInch;
		case NumberWithUnits.UT_CM:
			return value * inchesPerCm * pixPerInch;
		case NumberWithUnits.UT_MM:
			return value * .1f * inchesPerCm * pixPerInch;
		case NumberWithUnits.UT_PT:
			return value * (1f / 72f) * pixPerInch;
		case NumberWithUnits.UT_PC:
			return value * (1f / 6f) * pixPerInch;
	}

	return value;
}
 
Example 14
Source Project: dsworkbench   Source File: SupportRefillSourcePanel.java    License: Apache License 2.0 5 votes vote down vote up
private void pasteFromClipboard() {
    try {
        String data = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor);
        List<Village> villages = PluginManager.getSingleton().executeVillageParser(data);
        if (!villages.isEmpty()) {
            addVillages(villages.toArray(new Village[villages.size()]));
        }
    } catch (HeadlessException | IOException | UnsupportedFlavorException ignored) {
    }
}
 
Example 15
Source Project: jdk8u-jdk   Source File: InputMethodContext.java    License: 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 16
Source Project: stendhal   Source File: SpriteStore.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected SpriteStore() {
	try {
		gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
	} catch (HeadlessException e) {
		logger.warn("Cannot initialize graphic user interface: " + e);
	}
}
 
Example 17
Source Project: openjdk-8-source   Source File: DropTarget.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 18
Source Project: Bytecoder   Source File: InputMethodContext.java    License: Apache License 2.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 19
Source Project: JDKSourceCode1.8   Source File: DropTarget.java    License: MIT License 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 20
Source Project: tutorials   Source File: HeadlessModeUnitTest.java    License: MIT License 5 votes vote down vote up
@Test
public void whenHeadlessmode_thenFrameThrowsHeadlessException() {
    assertThatExceptionOfType(HeadlessException.class).isThrownBy(() -> {
        Frame frame = new Frame();
        frame.setVisible(true);
        frame.setSize(120, 120);
    });
}
 
Example 21
Source Project: dsworkbench   Source File: DefenseSourcePanel.java    License: Apache License 2.0 5 votes vote down vote up
private void pasteFromClipboard() {
    String data = "";
    try {
        data = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor);
        List<Village> villages = PluginManager.getSingleton().executeVillageParser(data);
        if (!villages.isEmpty()) {
            addVillages(villages.toArray(new Village[villages.size()]));
        }
    } catch (HeadlessException | IOException | UnsupportedFlavorException ignored) {
    }
}
 
Example 22
Source Project: netbeans   Source File: UtilitiesTest.java    License: Apache License 2.0 4 votes vote down vote up
public int getScreenResolution() throws HeadlessException {
    return Toolkit.getDefaultToolkit().getScreenResolution();
}
 
Example 23
Source Project: netbeans   Source File: UtilitiesTest.java    License: Apache License 2.0 4 votes vote down vote up
public Clipboard getSystemClipboard() throws HeadlessException {
    return Toolkit.getDefaultToolkit().getSystemClipboard();
}
 
Example 24
public GraphicsDevice[] getScreenDevices()
    throws HeadlessException {
    throw new HeadlessException();
}
 
Example 25
Source Project: netbeans   Source File: UtilitiesTest.java    License: Apache License 2.0 4 votes vote down vote up
protected ListPeer createList(java.awt.List target) throws HeadlessException {
    throw new IllegalStateException("Method not implemented");
}
 
Example 26
public PropertySheetDialog(Frame owner, boolean modal)
  throws HeadlessException {
  super(owner, modal);
}
 
Example 27
public BaseDialog(Frame owner) throws HeadlessException {
  super(owner);
  buildUI();
}
 
Example 28
Source Project: Bytecoder   Source File: JFileChooser.java    License: Apache License 2.0 4 votes vote down vote up
private static void checkDragEnabled(boolean b) {
    if (b && GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
}
 
Example 29
public Rectangle getMaximumWindowBounds() throws HeadlessException {
    throw new HeadlessException();
}
 
Example 30
Source Project: Spark   Source File: CertificateController.java    License: Apache License 2.0 4 votes vote down vote up
public void addCertificateAsExempted(CertificateModel certModel) throws HeadlessException, InvalidNameException, KeyStoreException {
    addEntryToKeyStoreImpl(certModel, true);
}