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:info.magnolia.imaging.caching.CachingImageStreamerRepositoryTest.java

@Override
@Before/*from www.j  a  v  a  2 s. c om*/
public void setUp() throws Exception {
    // this used to set autostart to false, but I'm not sure why.
    // It seems fine as is.

    super.setUp();

    // Now replace JcrSessionStrategy instances (current ctx and system ctx) with a wrapper than ensures we only save once, for the purpose of these tests.
    final MockContext systemContext = (MockContext) MgnlContext.getSystemContext();
    systemContext.setRepositoryStrategy(new DelegatingSessionStrategy(systemContext.getRepositoryStrategy()));

    final MockContext regularContext = (MockContext) MgnlContext.getInstance();
    regularContext.setRepositoryStrategy(new DelegatingSessionStrategy(regularContext.getRepositoryStrategy()));

    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    if (!ge.isHeadless()) {
        log.warn("This test should run in headless mode as the server will likely run headless too!!!!!");
    }
}

From source file:net.pms.util.CodecUtil.java

/**
 * Check the font file or font name if registered in the OS
 *
 * @param fontName font represented by font file or by the font name
 *
 * @return the registered font name or null when not found
 *//*from w  ww.ja v a 2s  .  c o m*/
public static String isFontRegisteredInOS(String fontName) {
    if (isNotBlank(fontName)) {
        File fontFile = new File(fontName);
        if (fontFile.exists()) { // Test if the font is specified by the file.
            try {
                fontName = Font.createFont(Font.TRUETYPE_FONT, fontFile).getFontName();
            } catch (FontFormatException | IOException e) {
                LOGGER.debug("Exception when implementing the custom font: ", e.getMessage());
            }
        }

        // The font is specified by the name. Check if it is registered in the OS.
        String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
        for (String font : fonts) {
            if (font.equals(fontName)) {
                return font;
            }
        }
    }

    LOGGER.debug("Font name not found. Check if it is properly specified or installed in the OS");
    return null;
}

From source file:RasterTest.java

protected Canvas3D createCanvas3D() {
    // create a custom Canvas3D with postSwap overidden
    GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D();
    gc3D.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED);
    GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

    RasterCanvas3D c3d = new RasterCanvas3D(this, gd[0].getBestConfiguration(gc3D));
    c3d.setSize(getCanvas3dWidth(c3d), getCanvas3dHeight(c3d));

    return c3d;// w  ww. java2  s  . co m
}

From source file:net.landora.video.utils.UIUtils.java

public static String getFirstAvaliableFamily(String... fontFamilies) {
    Map<String, String> families = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    for (String family : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()) {
        families.put(family, family);//from   w  w w. j  ava 2s. c  o m
    }

    for (String family : fontFamilies) {
        String result = families.get(family);
        if (result != null) {
            return result;
        }
    }

    return null;
}

From source file:com.sshtools.powervnc.PowerVNCFullScreenWindowContainer.java

public void setContainerVisible(boolean visible) {
    if (visible && !isContainerVisible()) {
        try {// www.  jav  a 2  s .  c om
            setVisible(true);
            GraphicsDevice device = panel.getGraphicsConfiguration().getDevice();
            //device.setFullScreenWindow(this);
            log.debug("Full screen container made visible");
            // ( (SshVNCPanel) panel).setAutoHideTools(true);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
        }
    } else if (!visible && isContainerVisible()) {
        try {
            GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
            //device.setFullScreenWindow(null);
            setVisible(false);
            log.debug("Full screen container made invisible");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
        }
    }
}

From source file:library.functions.WebFunctions.java

public void startRecording() throws Exception {
    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration();/* w  ww .j  a  va  2  s .  c om*/
    this.screenRecorder = new ScreenRecorder(gc,
            new Format(MediaTypeKey, FormatKeys.MediaType.FILE, MimeTypeKey, MIME_AVI),
            new Format(MediaTypeKey, FormatKeys.MediaType.VIDEO, EncodingKey,
                    ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, CompressorNameKey,
                    ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, DepthKey, 24, FrameRateKey, Rational.valueOf(15),
                    QualityKey, 1.0f, KeyFrameIntervalKey, 15 * 60),
            new Format(MediaTypeKey, FormatKeys.MediaType.VIDEO, EncodingKey, "black", FrameRateKey,
                    Rational.valueOf(30)),
            null);
    this.screenRecorder.start();
}

From source file:pcgen.gui2.tools.Utility.java

/**
 * Centers a {@code Component} to the screen.
 *
 * @param dialog JDialog dialog to center
 *//*w ww .j  av  a 2 s  .  c  o  m*/
public static void centerComponent(Component dialog) {
    // since the Toolkit.getScreenSize() method is broken in the Linux implementation
    // of Java 5  (it returns double the screen size under xinerama), this method is
    // encapsulated to accomodate this with a hack.
    // TODO: remove the hack, once Java fixed this.
    // final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    final Rectangle screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration().getBounds();

    final Dimension dialogSize = dialog.getSize();

    if (dialogSize.height > screenSize.height) {
        dialogSize.height = screenSize.height;
    }

    if (dialogSize.width > screenSize.width) {
        dialogSize.width = screenSize.width;
    }
    dialog.setSize(dialogSize);

    dialog.setLocation(screenSize.x + ((screenSize.width - dialogSize.width) / 2),
            screenSize.y + ((screenSize.height - dialogSize.height) / 2));
}

From source file:com.lfv.lanzius.server.WorkspaceView.java

/**
 * Set up the ISA chart//from   w w w.j  av  a 2 s . co m
 * @param selectionList selected terminals
 */
public void initIsaChart() {
    if (isaChart == null) {
        // Create a chart:
        isaChart = new ZoomableChart();
    }

    if (isaFrame == null) {
        // Make it visible:
        // Create a frame.
        isaFrame = new JFrame("ISADynamicChart");
        // add the chart to the frame:
        isaChart.getAxisY().setPaintGrid(true);
        isaChart.setGridColor(Color.LIGHT_GRAY);
        isaChart.getAxisX().setRangePolicy(new RangePolicyHighestValues());
        if (server.getIsaExtendedMode()) {
            isaChart.getAxisY().setRangePolicy(new RangePolicyFixedViewport(new Range(0, 9)));
        } else {
            isaChart.getAxisY().setRangePolicy(new RangePolicyFixedViewport(new Range(0, 5)));
        }
        isaChart.getAxisX().setAxisTitle(new AxisTitle("Time (minutes)"));
        isaChart.getAxisY().setAxisTitle(new AxisTitle("ISA value"));

        isaFrame.getContentPane().add(isaChart);

        // Add popup menues to the pane
        isaFrame.getContentPane().add(new ChartPanel(isaChart));

        if (server.getIsaExtendedMode()) {
            isaFrame.setSize(1000, 300);
        } else {
            isaFrame.setSize(1000, 205);
        }
        isaFrame.setAlwaysOnTop(true);
        GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Rectangle rect = graphicsEnvironment.getMaximumWindowBounds();
        isaFrame.setLocation(rect.width - 1020, rect.height - 370);
        // Enable the termination button [cross on the upper right edge]:
        isaFrame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                panel.updateButtons(false, null);
            }
        });
        server.setIsaStartTime(System.currentTimeMillis());
    }
    isaFrame.setVisible(true);
}

From source file:fr.gouv.diplomatie.applitutoriel.utility.Graphique.java

/**
 * Creer camember3 d./*from w ww .ja  v  a2 s  . co  m*/
 *
 * @param title
 *            the title
 * @param dataset
 *            the dataset
 * @param legend
 *            the legend
 * @param tooltips
 *            the tooltips
 * @param urls
 *            the urls
 * @return the j free chart
 * @throws FontFormatException
 *             the font format exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static JFreeChart creerCamember3D(final String title, final DefaultPieDataset dataset,
        final boolean legend, final boolean tooltips, final boolean urls)
        throws FontFormatException, IOException {

    dataset.sortByValues(SortOrder.DESCENDING);
    final JFreeChart jfreeChart = ChartFactory.createPieChart3D(title, dataset, legend, tooltips, urls);

    jfreeChart.setBackgroundPaint(Color.white);
    jfreeChart.setBorderVisible(true);
    jfreeChart.getLegend().setPosition(RectangleEdge.LEFT);
    final GraphicsEnvironment graph = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final InputStream inputStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("hornet/framework/font/LiberationSans-Bold.ttf");
    final Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
    graph.registerFont(font);
    jfreeChart.getLegend().setItemFont(new Font("Liberation Sans", Font.BOLD, 11));
    jfreeChart.getLegend().setHeight(400);
    jfreeChart.getLegend().setBorder(0, 0, 0, 0);
    jfreeChart.setTitle(new TextTitle(title, new Font("Liberation Sans", Font.BOLD, 16)));
    final PiePlot piePlot = (PiePlot) jfreeChart.getPlot();

    final int nbData = dataset.getItemCount();
    int cptColor = 0;
    for (int x = 0; x < nbData; x++) {
        if (cptColor >= listColor.size()) {
            cptColor = 0;
        }
        piePlot.setSectionPaint(dataset.getKey(x), listColor.get(cptColor));

        cptColor++;

    }

    piePlot.setForegroundAlpha(0.5f);
    piePlot.setLabelFont(new Font("Liberation Sans", Font.BOLD, 12));
    piePlot.setLabelOutlineStroke(null);
    piePlot.setLabelLinkStroke(new BasicStroke(0.4f));
    piePlot.setLabelBackgroundPaint(Color.WHITE);
    piePlot.setLabelLinkStyle(PieLabelLinkStyle.STANDARD);
    piePlot.setBackgroundAlpha(0);
    piePlot.setOutlineVisible(false);
    piePlot.setForegroundAlpha(1); // transparence
    piePlot.setInteriorGap(0); // le camembert occupe plus de place
    piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}"));
    piePlot.setStartAngle(70);
    piePlot.setCircular(true); // force pour avoir un cercle et pas un oval
    piePlot.setMaximumLabelWidth(0.20);
    piePlot.setBaseSectionOutlinePaint(Color.BLACK); // bordure du camembert

    return jfreeChart;

}

From source file:Unicode.java

/** Construct the object including its GUI */
public Unicode() {
    super("Unicode");

    Container cp = getContentPane();

    // Used both for Buttons and Menus
    ResourceBundle b = ResourceBundle.getBundle("UnicodeWidgets");

    JButton quitButton, nextButton, prevButton;
    Panel p = new Panel();
    // Make a grid, add one for labels.
    p.setLayout(new GridLayout(ROWS + 1, COLUMNS + 1));
    DecimalFormat df2d = new DecimalFormat("00");

    // Add first row, just column labels.
    p.add(new JLabel(""));
    for (int i = 0; i < COLUMNS; i++)
        p.add(new JLabel(Integer.toString(i, 16), JLabel.CENTER));

    // Add subsequent rows, each with an offset label
    for (int i = 0; i < ROWS; i++) {
        JLabel l = new JLabel("0000"); // room for max, i.e. \uFFFF
        p.add(l);//from   w  ww . jav a  2  s. c o m
        rowLabs[i] = l;
        for (int j = 0; j < COLUMNS; j++) {
            JLabel pb = new JLabel(" ");
            buttons[j][i] = pb;
            p.add(pb);
        }
    }

    // ActionListeners for jumping around; used by buttons and menus
    ActionListener firster = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            gotoPage(startNum = 0);
        }
    };
    ActionListener previouser = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (startNum > 0)
                gotoPage(startNum -= QUADSIZE);
        }
    };
    ActionListener nexter = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (startNum < 65535)
                gotoPage(startNum += QUADSIZE);
        }
    };
    ActionListener laster = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            gotoPage(65536 - QUADSIZE);
        }
    };

    cp.add(BorderLayout.NORTH, p);
    fontName = new JLabel("Default font", JLabel.CENTER);
    cp.add(BorderLayout.CENTER, fontName);
    Panel q = new Panel();
    cp.add(BorderLayout.SOUTH, q);
    q.add(prevButton = mkButton(b, "page.prev"));
    prevButton.addActionListener(previouser);

    q.add(nextButton = mkButton(b, "page.next"));
    nextButton.addActionListener(nexter);

    q.add(quitButton = mkButton(b, "exit"));
    quitButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
            dispose();
            System.exit(0);
        }
    });
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
            System.exit(0);
        }
    });

    MenuItem mi; // used in various spots

    MenuBar mb = new MenuBar();
    setMenuBar(mb);

    String titlebar;
    try {
        titlebar = b.getString("program" + ".title");
    } catch (MissingResourceException e) {
        titlebar = "Unicode Demo";
    }
    setTitle(titlebar);

    ActionListener fontSelector = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String font = e.getActionCommand();
            mySetFont(font, FONTSIZE);
        }
    };

    Menu fontMenu = mkMenu(b, "font");
    // String[] fontList = Toolkit.getDefaultToolkit().getFontList();
    String[] fontList = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int i = 0; i < fontList.length; i++) {
        fontMenu.add(mi = new MenuItem(fontList[i]));
        mi.addActionListener(fontSelector);
    }
    mb.add(fontMenu);

    gotoPageUI = new GoToPage("Unicode Page");
    centre(gotoPageUI);

    Menu vm = mkMenu(b, "page");
    vm.add(mi = mkMenuItem(b, "page", "first"));
    mi.addActionListener(firster);
    vm.add(mi = mkMenuItem(b, "page", "prev"));
    mi.addActionListener(previouser);
    vm.add(mi = mkMenuItem(b, "page", "next"));
    mi.addActionListener(nexter);
    vm.add(mi = mkMenuItem(b, "page", "last"));
    mi.addActionListener(laster);
    vm.add(mi = mkMenuItem(b, "page", "goto"));
    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Unicode.this.gotoPageUI.setVisible(true);
        }
    });
    mb.add(vm);

    Menu hm = mkMenu(b, "help");
    hm.add(mi = mkMenuItem(b, "help", "about"));
    mb.setHelpMenu(hm); // needed for portability (Motif, etc.).

    pack();
    // After packing the Frame, centre it on the screen.
    centre(this);

    // start at a known place
    mySetFont(fontList[0], FONTSIZE);
    gotoPage(startNum);
}