Search in sources :

Example 16 with HeadlessException

use of java.awt.HeadlessException in project bigbluebutton by bigbluebutton.

the class ScreenCapture method getMouseLocation.

private Point getMouseLocation() {
    PointerInfo pInfo;
    Point pointerLocation = new Point(0, 0);
    try {
        pInfo = MouseInfo.getPointerInfo();
    } catch (HeadlessException e) {
        pInfo = null;
    } catch (SecurityException e) {
        pInfo = null;
    }
    if (pInfo == null)
        return pointerLocation;
    return pInfo.getLocation();
}
Also used : PointerInfo(java.awt.PointerInfo) HeadlessException(java.awt.HeadlessException) Point(java.awt.Point)

Example 17 with HeadlessException

use of java.awt.HeadlessException in project eweb4j-framework by laiweiwei.

the class FileUtil method toBufferedImage.

private static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }
    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();
    // Determine if the image has transparent pixels; for this method's
    // implementation, see e661 Determining If an Image Has Transparent
    // Pixels
    // boolean hasAlpha = hasAlpha(image);
    // Create a buffered image with a format that's compatible with the
    // screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the new buffered image
        int transparency = Transparency.OPAQUE;
        /*
			 * if (hasAlpha) { transparency = Transparency.BITMASK; }
			 */
        // Create the buffered image
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
    // The system does not have a screen
    }
    if (bimage == null) {
        // Create a buffered image using the default color model
        int type = BufferedImage.TYPE_INT_RGB;
        // int type = BufferedImage.TYPE_3BYTE_BGR;//by wang
        /*
			 * if (hasAlpha) { type = BufferedImage.TYPE_INT_ARGB; }
			 */
        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }
    // Copy image to buffered image
    Graphics g = bimage.createGraphics();
    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return bimage;
}
Also used : Graphics(java.awt.Graphics) ImageIcon(javax.swing.ImageIcon) GraphicsDevice(java.awt.GraphicsDevice) HeadlessException(java.awt.HeadlessException) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 18 with HeadlessException

use of java.awt.HeadlessException in project GNS by MobilityFirst.

the class ReplicaLatencyTest method main.

/**
   * The main routine run from the command line.
   *
   * @param args
   * @throws Exception
   */
public static void main(String[] args) throws Exception {
    try {
        CommandLine parser = initializeOptions(args);
        if (parser.hasOption("help") || args.length == 0) {
            printUsage();
            System.exit(1);
        }
        String alias = parser.getOptionValue("alias");
        String host = parser.getOptionValue("host");
        String port = parser.getOptionValue("port");
        boolean debug = parser.hasOption("debug");
        String closeActiveReplica = parser.getOptionValue("closeAR");
        ReplicaLatencyTest test = new ReplicaLatencyTest(alias, host, port);
        // Need this on to read the which replica is responding
        //client.setEnableInstrumentation(true);
        test.findSlowGuid(closeActiveReplica);
        // send the reads and writes
        test.readsAndWrites(closeActiveReplica);
        //test.removeSubGuid();
        client.close();
        System.exit(0);
    } catch (HeadlessException e) {
        System.out.println("When running headless you'll need to specify the host and port on the command line");
        printUsage();
        System.exit(1);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) HeadlessException(java.awt.HeadlessException) RandomString(edu.umass.cs.gnscommon.utils.RandomString)

Example 19 with HeadlessException

use of java.awt.HeadlessException in project GNS by MobilityFirst.

the class CreateGuidTest method main.

/**
   * The main routine run from the command line.
   *
   * @param args
   * @throws Exception
   */
public static void main(String[] args) throws Exception {
    try {
        CommandLine parser = initializeOptions(args);
        if (parser.hasOption("help") || args.length == 0) {
            printUsage();
            System.exit(1);
        }
        String alias = parser.getOptionValue("alias");
        new CreateGuidTest(alias != null ? alias : ACCOUNT_ALIAS);
        System.exit(0);
    } catch (HeadlessException e) {
        System.out.println("When running headless you'll need to specify the host and port on the command line");
        printUsage();
        System.exit(1);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) HeadlessException(java.awt.HeadlessException) RandomString(edu.umass.cs.gnscommon.utils.RandomString)

Example 20 with HeadlessException

use of java.awt.HeadlessException in project GNS by MobilityFirst.

the class UserAuthPubKey method main.

/**
   *
   * @param arg
   */
public static void main(String[] arg) {
    try {
        JSch jsch = new JSch();
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Choose your privatekey(ex. ~/.ssh/id_dsa)");
        chooser.setFileHidingEnabled(false);
        int returnVal = chooser.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            System.out.println("You chose " + chooser.getSelectedFile().getAbsolutePath() + ".");
            //			 , "passphrase"
            jsch.addIdentity(//			 , "passphrase"
            chooser.getSelectedFile().getAbsolutePath());
        }
        String host = null;
        if (arg.length > 0) {
            host = arg[0];
        } else {
            host = JOptionPane.showInputDialog("Enter username@hostname", System.getProperty("user.name") + "@localhost");
        }
        String user = host.substring(0, host.indexOf('@'));
        host = host.substring(host.indexOf('@') + 1);
        Session session = jsch.getSession(user, host, 22);
        // username and passphrase will be given via UserInfo interface.
        UserInfo ui = new UserInfoPrompted();
        session.setUserInfo(ui);
        session.connect();
        Channel channel = session.openChannel("shell");
        channel.setInputStream(System.in);
        channel.setOutputStream(System.out);
        channel.connect();
    } catch (HeadlessException | JSchException e) {
        System.out.println(e);
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) JFileChooser(javax.swing.JFileChooser) UserInfoPrompted(edu.umass.cs.aws.networktools.UserInfoPrompted) HeadlessException(java.awt.HeadlessException) Channel(com.jcraft.jsch.Channel) UserInfo(com.jcraft.jsch.UserInfo) JSch(com.jcraft.jsch.JSch) Session(com.jcraft.jsch.Session)

Aggregations

HeadlessException (java.awt.HeadlessException)29 IOException (java.io.IOException)9 File (java.io.File)6 GraphicsConfiguration (java.awt.GraphicsConfiguration)5 Point (java.awt.Point)5 PrintService (javax.print.PrintService)5 StreamPrintService (javax.print.StreamPrintService)5 Rectangle (java.awt.Rectangle)4 PrinterException (java.awt.print.PrinterException)4 DialogTypeSelection (javax.print.attribute.standard.DialogTypeSelection)4 RandomString (edu.umass.cs.gnscommon.utils.RandomString)3 GraphicsDevice (java.awt.GraphicsDevice)3 GraphicsEnvironment (java.awt.GraphicsEnvironment)3 PageFormat (java.awt.print.PageFormat)3 Destination (javax.print.attribute.standard.Destination)3 Channel (com.jcraft.jsch.Channel)2 JSch (com.jcraft.jsch.JSch)2 JSchException (com.jcraft.jsch.JSchException)2 Session (com.jcraft.jsch.Session)2 UserInfo (com.jcraft.jsch.UserInfo)2