Example usage for java.awt GraphicsEnvironment getLocalGraphicsEnvironment

List of usage examples for java.awt GraphicsEnvironment getLocalGraphicsEnvironment

Introduction

In this page you can find the example usage for java.awt GraphicsEnvironment getLocalGraphicsEnvironment.

Prototype

public static GraphicsEnvironment getLocalGraphicsEnvironment() 

Source Link

Document

Returns the local GraphicsEnvironment .

Usage

From source file:statechum.analysis.learning.Visualiser.java

/**
 * Public constructor//  w ww  .ja  va 2  s .  co m
 *
 * @param windowPropName
 *            the name under which to store configuration information.
 */
public Visualiser(int windowPropName) {
    super(GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[GlobalConfiguration
            .getConfiguration().loadFrame(windowPropName).getScreenDevice()].getDefaultConfiguration());
    propName = windowPropName;
}

From source file:pcgen.system.Main.java

private static void initPrintPreviewFonts() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String fontDir = ConfigurationSettings.getOutputSheetsDir() + File.separator + "fonts" + File.separator
            + "NotoSans" + File.separator;
    try {//ww  w  . j  a va  2s.  c  o  m
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Regular.ttf")));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Bold.ttf")));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Italic.ttf")));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-BoldItalic.ttf")));
    } catch (IOException | FontFormatException ex) {
        Logging.errorPrint("Unexpected exception loading fonts fo print p", ex);
    }
}

From source file:org.dishevelled.brainstorm.BrainStorm.java

/** {@inheritDoc} */
public void run() {
    JFrame f = new JFrame("Brain storm");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add("Center", this);
    f.setResizable(false);// www . j a v  a  2 s  .  c  o m
    f.setUndecorated(true);
    // hide cursor on linux and windows platforms
    f.setCursor(hiddenCursor);
    GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(f);
    f.validate();

    SwingUtilities.invokeLater(new Runnable() {
        /** {@inheritDoc} */
        public void run() {
            calculatePlaceholderSize();
            calculateTextAreaSize();
            validate();
            textArea.scrollRectToVisible(
                    new Rectangle(0, textArea.getHeight() - 1, textArea.getWidth(), textArea.getHeight()));
        }
    });

    // save every five minutes
    Timer t = new Timer(5 * 60 * 1000, new ActionListener() {
        /** {@inheritDoc} */
        public void actionPerformed(final ActionEvent event) {
            save();
        }
    });
    t.setRepeats(true);
    t.start();
}

From source file:com.jug.MoMA.java

/**
 * PROJECT MAIN/*from   w w  w  .  j av a  2  s .c  o  m*/
 *
 * @param args
 */
public static void main(final String[] args) {
    if (showIJ)
        new ImageJ();

    //      // ===== set look and feel ========================================================================
    //      try {
    //         // Set cross-platform Java L&F (also called "Metal")
    //         UIManager.setLookAndFeel(
    //               UIManager.getCrossPlatformLookAndFeelClassName() );
    //      } catch ( final UnsupportedLookAndFeelException e ) {
    //         // handle exception
    //      } catch ( final ClassNotFoundException e ) {
    //         // handle exception
    //      } catch ( final InstantiationException e ) {
    //         // handle exception
    //      } catch ( final IllegalAccessException e ) {
    //         // handle exception
    //      }

    // ===== command line parsing ======================================================================

    // create Options object & the parser
    final Options options = new Options();
    final CommandLineParser parser = new BasicParser();
    // defining command line options
    final Option help = new Option("help", "print this message");

    final Option headless = new Option("h", "headless", false,
            "start without user interface (note: input-folder must be given!)");
    headless.setRequired(false);

    final Option timeFirst = new Option("tmin", "min_time", true, "first time-point to be processed");
    timeFirst.setRequired(false);

    final Option timeLast = new Option("tmax", "max_time", true, "last time-point to be processed");
    timeLast.setRequired(false);

    final Option optRange = new Option("orange", "opt_range", true, "initial optimization range");
    optRange.setRequired(false);

    final Option numChannelsOption = new Option("c", "channels", true,
            "number of channels to be loaded and analyzed.");
    numChannelsOption.setRequired(true);

    final Option minChannelIdxOption = new Option("cmin", "min_channel", true,
            "the smallest channel index (usually 0 or 1, default is 1).");
    minChannelIdxOption.setRequired(false);

    final Option infolder = new Option("i", "infolder", true, "folder to read data from");
    infolder.setRequired(false);

    final Option outfolder = new Option("o", "outfolder", true,
            "folder to write preprocessed data to (equals infolder if not given)");
    outfolder.setRequired(false);

    final Option userProps = new Option("p", "props", true, "properties file to be loaded (mm.properties)");
    userProps.setRequired(false);

    options.addOption(help);
    options.addOption(headless);
    options.addOption(numChannelsOption);
    options.addOption(minChannelIdxOption);
    options.addOption(timeFirst);
    options.addOption(timeLast);
    options.addOption(optRange);
    options.addOption(infolder);
    options.addOption(outfolder);
    options.addOption(userProps);
    // get the commands parsed
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (final ParseException e1) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(
                "... [-p props-file] -i in-folder [-o out-folder] -c <num-channels> [-cmin start-channel-ids] [-tmin idx] [-tmax idx] [-orange num-frames] [-headless]",
                "", options, "Error: " + e1.getMessage());
        System.exit(0);
    }

    if (cmd.hasOption("help")) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("... -i <in-folder> -o [out-folder] [-headless]", options);
        System.exit(0);
    }

    if (cmd.hasOption("h")) {
        System.out.println(">>> Starting MM in headless mode.");
        HEADLESS = true;
        if (!cmd.hasOption("i")) {
            final HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Headless-mode requires option '-i <in-folder>'...", options);
            System.exit(0);
        }
    }

    File inputFolder = null;
    if (cmd.hasOption("i")) {
        inputFolder = new File(cmd.getOptionValue("i"));

        if (!inputFolder.isDirectory()) {
            System.out.println("Error: Input folder is not a directory!");
            System.exit(2);
        }
        if (!inputFolder.canRead()) {
            System.out.println("Error: Input folder cannot be read!");
            System.exit(2);
        }
    }

    File outputFolder = null;
    if (!cmd.hasOption("o")) {
        if (inputFolder == null) {
            System.out.println(
                    "Error: Output folder would be set to a 'null' input folder! Please check your command line arguments...");
            System.exit(3);
        }
        outputFolder = inputFolder;
        STATS_OUTPUT_PATH = outputFolder.getAbsolutePath();
    } else {
        outputFolder = new File(cmd.getOptionValue("o"));

        if (!outputFolder.isDirectory()) {
            System.out.println("Error: Output folder is not a directory!");
            System.exit(3);
        }
        if (!inputFolder.canWrite()) {
            System.out.println("Error: Output folder cannot be written to!");
            System.exit(3);
        }

        STATS_OUTPUT_PATH = outputFolder.getAbsolutePath();
    }

    fileUserProps = null;
    if (cmd.hasOption("p")) {
        fileUserProps = new File(cmd.getOptionValue("p"));
    }

    if (cmd.hasOption("cmin")) {
        minChannelIdx = Integer.parseInt(cmd.getOptionValue("cmin"));
    }
    if (cmd.hasOption("c")) {
        numChannels = Integer.parseInt(cmd.getOptionValue("c"));
    }

    if (cmd.hasOption("tmin")) {
        minTime = Integer.parseInt(cmd.getOptionValue("tmin"));
    }
    if (cmd.hasOption("tmax")) {
        maxTime = Integer.parseInt(cmd.getOptionValue("tmax"));
    }

    if (cmd.hasOption("orange")) {
        initOptRange = Integer.parseInt(cmd.getOptionValue("orange"));
    }

    // ******** CHECK GUROBI ********* CHECK GUROBI ********* CHECK GUROBI *********
    final String jlp = System.getProperty("java.library.path");
    //      System.out.println( jlp );
    try {
        new GRBEnv("MoMA_gurobi.log");
    } catch (final GRBException e) {
        final String msgs = "Initial Gurobi test threw exception... check your Gruobi setup!\n\nJava library path: "
                + jlp;
        if (HEADLESS) {
            System.out.println(msgs);
        } else {
            JOptionPane.showMessageDialog(MoMA.guiFrame, msgs, "Gurobi Error?", JOptionPane.ERROR_MESSAGE);
        }
        e.printStackTrace();
        System.exit(98);
    } catch (final UnsatisfiedLinkError ulr) {
        final String msgs = "Could initialize Gurobi.\n"
                + "You might not have installed Gurobi properly or you miss a valid license.\n"
                + "Please visit 'www.gurobi.com' for further information.\n\n" + ulr.getMessage()
                + "\nJava library path: " + jlp;
        if (HEADLESS) {
            System.out.println(msgs);
        } else {
            JOptionPane.showMessageDialog(MoMA.guiFrame, msgs, "Gurobi Error?", JOptionPane.ERROR_MESSAGE);
            ulr.printStackTrace();
        }
        System.out.println("\n>>>>> Java library path: " + jlp + "\n");
        System.exit(99);
    }
    // ******* END CHECK GUROBI **** END CHECK GUROBI **** END CHECK GUROBI ********

    final MoMA main = new MoMA();
    if (!HEADLESS) {
        guiFrame = new JFrame();
        main.initMainWindow(guiFrame);
    }

    System.out.println("VERSION: " + VERSION_STRING);

    props = main.loadParams();
    BGREM_TEMPLATE_XMIN = Integer
            .parseInt(props.getProperty("BGREM_TEMPLATE_XMIN", Integer.toString(BGREM_TEMPLATE_XMIN)));
    BGREM_TEMPLATE_XMAX = Integer
            .parseInt(props.getProperty("BGREM_TEMPLATE_XMAX", Integer.toString(BGREM_TEMPLATE_XMAX)));
    BGREM_X_OFFSET = Integer.parseInt(props.getProperty("BGREM_X_OFFSET", Integer.toString(BGREM_X_OFFSET)));
    GL_WIDTH_IN_PIXELS = Integer
            .parseInt(props.getProperty("GL_WIDTH_IN_PIXELS", Integer.toString(GL_WIDTH_IN_PIXELS)));
    MOTHER_CELL_BOTTOM_TRICK_MAX_PIXELS = Integer.parseInt(props.getProperty(
            "MOTHER_CELL_BOTTOM_TRICK_MAX_PIXELS", Integer.toString(MOTHER_CELL_BOTTOM_TRICK_MAX_PIXELS)));
    GL_FLUORESCENCE_COLLECTION_WIDTH_IN_PIXELS = Integer
            .parseInt(props.getProperty("GL_FLUORESCENCE_COLLECTION_WIDTH_IN_PIXELS",
                    Integer.toString(GL_FLUORESCENCE_COLLECTION_WIDTH_IN_PIXELS)));
    GL_OFFSET_BOTTOM = Integer
            .parseInt(props.getProperty("GL_OFFSET_BOTTOM", Integer.toString(GL_OFFSET_BOTTOM)));
    if (GL_OFFSET_BOTTOM == -1) {
        GL_OFFSET_BOTTOM_AUTODETECT = true;
    } else {
        GL_OFFSET_BOTTOM_AUTODETECT = false;
    }
    GL_OFFSET_TOP = Integer.parseInt(props.getProperty("GL_OFFSET_TOP", Integer.toString(GL_OFFSET_TOP)));
    GL_OFFSET_LATERAL = Integer
            .parseInt(props.getProperty("GL_OFFSET_LATERAL", Integer.toString(GL_OFFSET_LATERAL)));
    MIN_CELL_LENGTH = Integer.parseInt(props.getProperty("MIN_CELL_LENGTH", Integer.toString(MIN_CELL_LENGTH)));
    MIN_GAP_CONTRAST = Float
            .parseFloat(props.getProperty("MIN_GAP_CONTRAST", Float.toString(MIN_GAP_CONTRAST)));
    SIGMA_PRE_SEGMENTATION_X = Float.parseFloat(
            props.getProperty("SIGMA_PRE_SEGMENTATION_X", Float.toString(SIGMA_PRE_SEGMENTATION_X)));
    SIGMA_PRE_SEGMENTATION_Y = Float.parseFloat(
            props.getProperty("SIGMA_PRE_SEGMENTATION_Y", Float.toString(SIGMA_PRE_SEGMENTATION_Y)));
    SIGMA_GL_DETECTION_X = Float
            .parseFloat(props.getProperty("SIGMA_GL_DETECTION_X", Float.toString(SIGMA_GL_DETECTION_X)));
    SIGMA_GL_DETECTION_Y = Float
            .parseFloat(props.getProperty("SIGMA_GL_DETECTION_Y", Float.toString(SIGMA_GL_DETECTION_Y)));
    SEGMENTATION_MIX_CT_INTO_PMFRF = Float.parseFloat(props.getProperty("SEGMENTATION_MIX_CT_INTO_PMFRF",
            Float.toString(SEGMENTATION_MIX_CT_INTO_PMFRF)));
    SEGMENTATION_CLASSIFIER_MODEL_FILE = props.getProperty("SEGMENTATION_CLASSIFIER_MODEL_FILE",
            SEGMENTATION_CLASSIFIER_MODEL_FILE);
    CELLSIZE_CLASSIFIER_MODEL_FILE = props.getProperty("CELLSIZE_CLASSIFIER_MODEL_FILE",
            CELLSIZE_CLASSIFIER_MODEL_FILE);
    DEFAULT_PATH = props.getProperty("DEFAULT_PATH", DEFAULT_PATH);

    GUROBI_TIME_LIMIT = Double
            .parseDouble(props.getProperty("GUROBI_TIME_LIMIT", Double.toString(GUROBI_TIME_LIMIT)));
    GUROBI_MAX_OPTIMALITY_GAP = Double.parseDouble(
            props.getProperty("GUROBI_MAX_OPTIMALITY_GAP", Double.toString(GUROBI_MAX_OPTIMALITY_GAP)));

    GUI_POS_X = Integer.parseInt(props.getProperty("GUI_POS_X", Integer.toString(DEFAULT_GUI_POS_X)));
    GUI_POS_Y = Integer.parseInt(props.getProperty("GUI_POS_Y", Integer.toString(DEFAULT_GUI_POS_X)));
    GUI_WIDTH = Integer.parseInt(props.getProperty("GUI_WIDTH", Integer.toString(GUI_WIDTH)));
    GUI_HEIGHT = Integer.parseInt(props.getProperty("GUI_HEIGHT", Integer.toString(GUI_HEIGHT)));
    GUI_CONSOLE_WIDTH = Integer
            .parseInt(props.getProperty("GUI_CONSOLE_WIDTH", Integer.toString(GUI_CONSOLE_WIDTH)));

    if (!HEADLESS) {
        // Iterate over all currently attached monitors and check if sceen
        // position is actually possible,
        // otherwise fall back to the DEFAULT values and ignore the ones
        // coming from the properties-file.
        boolean pos_ok = false;
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice[] gs = ge.getScreenDevices();
        for (int i = 0; i < gs.length; i++) {
            if (gs[i].getDefaultConfiguration().getBounds()
                    .contains(new java.awt.Point(GUI_POS_X, GUI_POS_Y))) {
                pos_ok = true;
            }
        }
        // None of the screens contained the top-left window coordinates -->
        // fall back onto default values...
        if (!pos_ok) {
            GUI_POS_X = DEFAULT_GUI_POS_X;
            GUI_POS_Y = DEFAULT_GUI_POS_Y;
        }
    }

    String path = props.getProperty("import_path", System.getProperty("user.home"));
    if (inputFolder == null || inputFolder.equals("")) {
        inputFolder = main.showStartupDialog(guiFrame, path);
    }
    System.out.println("Default filename decoration = " + inputFolder.getName());
    defaultFilenameDecoration = inputFolder.getName();
    path = inputFolder.getAbsolutePath();
    props.setProperty("import_path", path);

    GrowthLineSegmentationMagic.setClassifier(SEGMENTATION_CLASSIFIER_MODEL_FILE, "");

    if (!HEADLESS) {
        // Setting up console window...
        main.initConsoleWindow();
        main.showConsoleWindow(true);
    }

    // ------------------------------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------------------------------
    final MoMAModel mmm = new MoMAModel(main);
    instance = main;
    try {
        main.processDataFromFolder(path, minTime, maxTime, minChannelIdx, numChannels);
    } catch (final Exception e) {
        e.printStackTrace();
        System.exit(11);
    }
    // ------------------------------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------------------------------

    // show loaded and annotated data
    if (showIJ) {
        new ImageJ();
        ImageJFunctions.show(main.imgRaw, "Rotated & cropped raw data");
        // ImageJFunctions.show( main.imgTemp, "Temporary" );
        // ImageJFunctions.show( main.imgAnnotated, "Annotated ARGB data" );

        // main.getCellSegmentedChannelImgs()
        // ImageJFunctions.show( main.imgClassified, "Classification" );
        // ImageJFunctions.show( main.getCellSegmentedChannelImgs(), "Segmentation" );
    }

    gui = new MoMAGui(mmm);

    if (!HEADLESS) {
        System.out.print("Build GUI...");
        main.showConsoleWindow(false);

        //         final JFrameSnapper snapper = new JFrameSnapper();
        //         snapper.addFrame( main.frameConsoleWindow );
        //         snapper.addFrame( guiFrame );

        gui.setVisible(true);
        guiFrame.add(gui);
        guiFrame.setSize(GUI_WIDTH, GUI_HEIGHT);
        guiFrame.setLocation(GUI_POS_X, GUI_POS_Y);
        guiFrame.setVisible(true);

        //         SwingUtilities.invokeLater( new Runnable() {
        //
        //            @Override
        //            public void run() {
        //               snapper.snapFrames( main.frameConsoleWindow, guiFrame, JFrameSnapper.EAST );
        //            }
        //         } );
        System.out.println(" done!");
    } else {
        //         final String name = inputFolder.getName();

        gui.exportHtmlOverview();
        gui.exportDataFiles();

        instance.saveParams();

        System.exit(0);
    }
}

From source file:com.actelion.research.table.view.JVisualization.java

/**
 * Checks HiDPI support for Java 7 and newer.
 *
 * @return factor != 1 if HiDPI feature is enabled.
 *//*from  w w w  .  j  av  a  2  s  .  c om*/
public static float getContentScaleFactor() {
    /* with Apple-Java-6 this was:
    Object sContentScaleFactorObject = Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor");
     private static final float sRetinaFactor = (sContentScaleFactorObject == null) ? 1f : ((Float)sContentScaleFactorObject).floatValue();
    */
    if (sRetinaFactor != -1f)
        return sRetinaFactor;

    sRetinaFactor = 1f;

    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice device = env.getDefaultScreenDevice();

    try {
        Field field = device.getClass().getDeclaredField("scale");
        if (field != null) {
            field.setAccessible(true);
            Object scale = field.get(device);

            if (scale instanceof Integer) {
                sRetinaFactor = (Integer) scale;
            }
        }
    } catch (Throwable e) {
    }

    return sRetinaFactor;
}

From source file:com.itemanalysis.jmetrik.gui.JmetrikPreferencesManager.java

private String getDefaultFont() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = ge.getAvailableFontFamilyNames();

    for (String s : fontNames) {
        if (s.equals("Courier"))
            return "Courier";
        if (s.equals("Courier New"))
            return "Courier New";
        if (s.equals("Menlo"))
            return "Menlo";
        if (s.equals("Monaco"))
            return "Monaco";
        if (s.equals("Lucida Sans Typewriter"))
            return "Lucida Sans Typewriter";
    }// w  w w.j  a va 2  s. co  m
    return "Lucida Sans Typewriter";//preferred default font
}

From source file:Logi.GSeries.Service.LogiGSKService.java

private static boolean isReallyHeadless() {
    if (GraphicsEnvironment.isHeadless()) {
        //return true;
    }/*w ww  .  ja v a  2 s  .c  o m*/
    try {
        GraphicsDevice[] screenDevices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        return screenDevices == null || screenDevices.length == 0;
    } catch (HeadlessException e) {
        System.err.print(e);
        return true;
    }
}

From source file:cognitivej.vision.overlay.builder.ImageOverlayBuilder.java

private ImageOverlayBuilder(@NotNull BufferedImage bufferedImage) {
    this.bufferedImage = bufferedImage;
    try {//from   w  w w. j  a va2  s  . c o m
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT,
                new File("src/main/resources/font/notosans/NotoSans-Bold.ttf")));
    } catch (IOException | FontFormatException ignored) {
    }

}

From source file:repast.simphony.visualization.gui.styleBuilder.EditedStyleDialog.java

public void init(Class agentClass, String userStyleName, CartesianDisplayDescriptor descriptor) {
    this.agentClassName = agentClass.getCanonicalName();
    this.userStyleName = userStyleName;
    this.displayType = descriptor.getDisplayType();

    userStyleData = EditedStyleUtils.getStyle(descriptor.getEditedStyleName(agentClass.getName()));

    Method[] methods = agentClass.getMethods();
    for (Method method : methods) {
        if (!method.isSynthetic()) {
            if (method.getParameterTypes().length == 0 && (pTypes.contains(method.getReturnType())
                    || Number.class.isAssignableFrom(method.getReturnType()))) {
                methodList.add(method.getName());
            }//from  w ww  .  j a v  a2  s  . com

            if (method.getParameterTypes().length == 0 && (pTypes.contains(method.getReturnType())
                    || Number.class.isAssignableFrom(method.getReturnType())
                    || method.getReturnType().equals(String.class))) {
                labelMethodList.add(method.getName());
            }
        }
    }

    methodList.remove("hashCode");
    labelMethodList.remove("hashCode");
    labelMethodList.remove("toString");
    labelMethodList.add("Name");

    // TODO Projections: init from viz registry data entries
    // Set objects based on display type 2D/3D
    if (displayType.equals(DisplayType.TWO_D)) {
        if (userStyleData == null)
            userStyleData = new DefaultEditedStyleData2D();

        // TODO Eliminate GIS plugin depedency.
        shapeModel = new DefaultComboBoxModel(IconFactory2D.Shape_List);

        shapeModel.setSelectedItem(userStyleData.getShapeWkt());
    } else {
        if (userStyleData == null)
            userStyleData = new DefaultEditedStyleData3D();

        shapeModel = new DefaultComboBoxModel(new String[] { "sphere", "cube", "cylinder", "cone" });

        shapeModel.setSelectedItem(userStyleData.getShapeWkt());

    }

    sizeModel = new DefaultComboBoxModel();
    sizeMinModel = new DefaultComboBoxModel();
    sizeMaxModel = new DefaultComboBoxModel();
    sizeScaleModel = new DefaultComboBoxModel();
    labelModel = new DefaultComboBoxModel();
    labelFontFamilyModel = new DefaultComboBoxModel();
    variableIconRedColorValueModel = new DefaultComboBoxModel();
    variableIconGreenColorValueModel = new DefaultComboBoxModel();
    variableIconBlueColorValueModel = new DefaultComboBoxModel();
    variableIconRedColorMinModel = new DefaultComboBoxModel();
    variableIconGreenColorMinModel = new DefaultComboBoxModel();
    variableIconBlueColorMinModel = new DefaultComboBoxModel();
    variableIconRedColorMaxModel = new DefaultComboBoxModel();
    variableIconGreenColorMaxModel = new DefaultComboBoxModel();
    variableIconBlueColorMaxModel = new DefaultComboBoxModel();
    variableIconRedColorScaleModel = new DefaultComboBoxModel();
    variableIconGreenColorScaleModel = new DefaultComboBoxModel();
    variableIconBlueColorScaleModel = new DefaultComboBoxModel();

    //    sizeModel.addElement(ICON_SIZE);

    // Add available methods to appropriate combo box models
    for (String method : methodList) {
        sizeModel.addElement(method);
        sizeMinModel.addElement(method);
        sizeMaxModel.addElement(method);
        sizeScaleModel.addElement(method);

        variableIconRedColorValueModel.addElement(method);
        variableIconGreenColorValueModel.addElement(method);
        variableIconBlueColorValueModel.addElement(method);
        //         variableIconRedColorMinModel.addElement(method);
        //         variableIconGreenColorMinModel.addElement(method);
        //         variableIconBlueColorMinModel.addElement(method);
        //         variableIconRedColorMaxModel.addElement(method);
        //         variableIconGreenColorMaxModel.addElement(method);
        //         variableIconBlueColorMaxModel.addElement(method);
        //         variableIconRedColorScaleModel.addElement(method);
        //         variableIconGreenColorScaleModel.addElement(method);
        //         variableIconBlueColorScaleModel.addElement(method);
    }

    for (String method : labelMethodList)
        labelModel.addElement(method);

    if (userStyleData.getSizeMethodName() != null)
        sizeModel.setSelectedItem(userStyleData.getSizeMethodName());
    else {
        sizeModel.addElement(userStyleData.getSize());
        sizeModel.setSelectedItem(userStyleData.getSize());
    }
    if (userStyleData.getSizeMinMethodName() != null)
        sizeMinModel.setSelectedItem(userStyleData.getSizeMinMethodName());
    else {
        sizeMinModel.addElement(userStyleData.getSizeMin());
        sizeMinModel.setSelectedItem(userStyleData.getSizeMin());
    }
    if (userStyleData.getSizeMaxMethodName() != null)
        sizeMaxModel.setSelectedItem(userStyleData.getSizeMaxMethodName());
    else {
        sizeMaxModel.addElement(userStyleData.getSizeMax());
        sizeMaxModel.setSelectedItem(userStyleData.getSizeMax());
    }
    if (userStyleData.getSizeScaleMethodName() != null)
        sizeScaleModel.setSelectedItem(userStyleData.getSizeScaleMethodName());
    else {
        sizeScaleModel.addElement(userStyleData.getSizeScale());
        sizeScaleModel.setSelectedItem(userStyleData.getSizeScale());
    }
    if (userStyleData.getLabelMethod() != null) {

        if ("toString".equals(userStyleData.getLabelMethod()))
            labelModel.setSelectedItem("Name");
        else
            labelModel.setSelectedItem(userStyleData.getLabelMethod());
    } else {
        labelModel.addElement(userStyleData.getLabel());
        labelModel.setSelectedItem(userStyleData.getLabel());
    }

    if (userStyleData.getRedMethod() != null)
        variableIconRedColorValueModel.setSelectedItem(userStyleData.getRedMethod());
    else {
        variableIconRedColorValueModel.addElement(userStyleData.getColor()[0]);
        variableIconRedColorValueModel.setSelectedItem(userStyleData.getColor()[0]);
    }
    if (userStyleData.getGreenMethod() != null)
        variableIconGreenColorValueModel.setSelectedItem(userStyleData.getGreenMethod());
    else {
        variableIconGreenColorValueModel.addElement(userStyleData.getColor()[1]);
        variableIconGreenColorValueModel.setSelectedItem(userStyleData.getColor()[1]);
    }
    if (userStyleData.getBlueMethod() != null)
        variableIconBlueColorValueModel.setSelectedItem(userStyleData.getBlueMethod());
    else {
        variableIconBlueColorValueModel.addElement(userStyleData.getColor()[2]);
        variableIconBlueColorValueModel.setSelectedItem(userStyleData.getColor()[2]);
    }

    variableIconRedColorMinModel.addElement(userStyleData.getColorMin()[0]);
    variableIconRedColorMinModel.setSelectedItem(userStyleData.getColorMin()[0]);
    variableIconGreenColorMinModel.addElement(userStyleData.getColorMin()[1]);
    variableIconGreenColorMinModel.setSelectedItem(userStyleData.getColorMin()[1]);
    variableIconBlueColorMinModel.addElement(userStyleData.getColorMin()[2]);
    variableIconBlueColorMinModel.setSelectedItem(userStyleData.getColorMin()[2]);

    variableIconRedColorMaxModel.addElement(userStyleData.getColorMax()[0]);
    variableIconRedColorMaxModel.setSelectedItem(userStyleData.getColorMax()[0]);
    variableIconGreenColorMaxModel.addElement(userStyleData.getColorMax()[1]);
    variableIconGreenColorMaxModel.setSelectedItem(userStyleData.getColorMax()[1]);
    variableIconBlueColorMaxModel.addElement(userStyleData.getColorMax()[2]);
    variableIconBlueColorMaxModel.setSelectedItem(userStyleData.getColorMax()[2]);

    variableIconRedColorScaleModel.addElement(userStyleData.getColorScale()[0]);
    variableIconRedColorScaleModel.setSelectedItem(userStyleData.getColorScale()[0]);
    variableIconGreenColorScaleModel.addElement(userStyleData.getColorScale()[1]);
    variableIconGreenColorScaleModel.setSelectedItem(userStyleData.getColorScale()[1]);
    variableIconBlueColorScaleModel.addElement(userStyleData.getColorScale()[2]);
    variableIconBlueColorScaleModel.setSelectedItem(userStyleData.getColorScale()[2]);

    // Label font
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    String fontList[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    for (int i = 0; i < fontList.length; i++)
        labelFontFamilyModel.addElement(fontList[i]);

    if (labelFontFamilyModel.getIndexOf(userStyleData.getLabelFontFamily()) != -1)
        labelFontFamilyModel.setSelectedItem(userStyleData.getLabelFontFamily());

    initComponents();
    initMyComponents(displayType);
}

From source file:com.opendoorlogistics.studio.AppFrame.java

private void initWindowPosition() {
    WindowState screenState = PreferencesManager.getSingleton().getScreenState();
    boolean boundsSet = false;
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    if (screenState != null) {
        setExtendedState(screenState.getExtendedState());
        int safety = 20;
        int screenWidth = gd.getDisplayMode().getWidth();
        int screenHeight = gd.getDisplayMode().getHeight();
        if (getExtendedState() == JFrame.NORMAL && screenState.getX() < (screenWidth - safety)
                && (screenState.getY() < screenHeight - safety && screenState.getWidth() <= screenWidth
                        && screenState.getHeight() <= screenHeight)) {
            boundsSet = true;/* w  w w  . java 2s. com*/
            setBounds(screenState.getX(), screenState.getY(), screenState.getWidth(), screenState.getHeight());
        }
    }

    // make a fraction of the screen size by default
    if (!boundsSet && gd != null && getExtendedState() == JFrame.NORMAL) {
        int screenWidth = gd.getDisplayMode().getWidth();
        int screenHeight = gd.getDisplayMode().getHeight();
        setSize(3 * screenWidth / 4, 3 * screenHeight / 4);
    }
}