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:com.itemanalysis.jmetrik.gui.Jmetrik.java

public static void main(String args[]) {

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                Color SELECTED_COLOR = new Color(184, 204, 217);
                Color BASE_COLOR = new Color(220, 231, 243, 50);
                Color ALT_COLOR = new Color(220, 231, 243, 115);

                //                    Insets MENU_INSETS = new Insets(1,12,2,5);//default values
                //                    Font MENU_FONT = new Font("SansSerif ", Font.PLAIN, 12);//default values

                //                    UIManager.put("nimbusBase", BASE_COLOR);
                UIManager.put("nimbusSelection", SELECTED_COLOR);
                UIManager.put("nimbusSelectionBackground", SELECTED_COLOR);
                UIManager.put("Menu[Enabled+Selected].backgroundPainter", SELECTED_COLOR);

                //override defaults
                for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                    if (info.getName().equals("Nimbus")) {
                        UIManager.setLookAndFeel(info.getClassName());
                        UIDefaults defaults = UIManager.getLookAndFeelDefaults();
                        defaults.put("Table.gridColor", Color.lightGray);
                        defaults.put("Table.disabled", false);
                        defaults.put("Table.showGrid", true);
                        defaults.put("Table.intercellSpacing", new Dimension(1, 1));
                        break;
                    }/*  w  ww .ja  va2s. c  om*/
                }

                //                    UIManager.put("TitledBorder.position", TitledBorder.TOP);

                //                    UIManager.put("Table.showGrid", true);
                //                    UIManager.put("Table.gridColor", Color.RED);
                //                    UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
            } catch (UnsupportedLookAndFeelException ulafe) {
                //                    logger.fatal("Substance failed to set", ulafe);
            } catch (Exception ex) {
                //                    logger.fatal(ex.getMessage(), ex);
            }

            JFrame frame = new Jmetrik();

            //            set window to maximum size but account for taskbar
            GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
            Rectangle rect = env.getMaximumWindowBounds();
            int width = Double.valueOf(rect.getWidth() - 1.0).intValue();
            int height = Double.valueOf(rect.getHeight() - 1.0).intValue();
            frame.setMaximizedBounds(new Rectangle(0, 0, width, height));
            frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            frame.pack();
            //            frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
            frame.setVisible(true);

            //check for updates to jmetrik
            ((Jmetrik) frame).checkForUpdates();
        }
    });

}

From source file:com.aurel.track.attachment.AttachBL.java

private static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/*from  www. java  2s.c  om*/

    // 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 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;
        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;
}

From source file:com.jaspersoft.studio.utils.ModelUtils.java

/**
 * Return the font names, the names can be split in more array to categorize them. In this way when represented, the
 * category can be graphically divided (for example with a separator)
 * //  w  w  w.j  a  v a 2s  .c  om
 * @param jContext
 * @return
 */
public static List<String[]> getFontNames(JasperReportsConfiguration jContext) {
    java.util.List<String[]> classes = new ArrayList<String[]>();
    java.util.List<String> elements = new ArrayList<String>();
    Collection<?> extensionFonts = FontUtil.getInstance(jContext).getFontFamilyNames();
    for (Iterator<?> it = extensionFonts.iterator(); it.hasNext();) {
        String fname = (String) it.next();
        elements.add(fname);
    }
    classes.add(elements.toArray(new String[elements.size()]));
    elements = new ArrayList<String>();
    String[] names = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int i = 0; i < names.length; i++) {
        String name = names[i];
        elements.add(name);
    }
    classes.add(elements.toArray(new String[elements.size()]));
    return classes;
}

From source file:net.pms.medialibrary.commons.helpers.FileImportHelper.java

/**
 * Creates a buffered image from an image
 * @param image the image/*from w  w  w .j ava2s  . co  m*/
 * @return the buffered image
 */
public static BufferedImage getBufferedImage(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 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;
        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;
}

From source file:spectrogram.Spectrogram.java

/**
 * Select a font that a) looks good and b) is available on this system (Macs were getting me)
 * @return name of the font/*ww  w .ja v a2  s .  c  o  m*/
 */
private String getAGoodFont() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    String[] fontNames = ge.getAvailableFontFamilyNames();
    String ret = "";
    for (int idx = 0; idx < fontNames.length && ret.isEmpty(); idx++) {
        String font = fontNames[idx];
        if (font.equalsIgnoreCase("DejaVu Sans")) {
            ret = fontNames[idx];
        }
    }
    for (int idx = 0; idx < fontNames.length && ret.isEmpty(); idx++) {
        String font = fontNames[idx];
        if (font.toLowerCase().contains("century schoolbook l")) {
            ret = fontNames[idx];
        }
    }
    if (ret.isEmpty()) {
        ret = "Serif";
    }
    return ret;
}

From source file:net.sf.jasperreports.components.headertoolbar.json.HeaderToolbarElementJsonHandler.java

private Set<String> getSystemFontNames(JasperReportsContext jasperReportsContext) {
    Set<String> fontExtensionsFontNames = getFontExtensionsFontNames(jasperReportsContext);
    Set<String> classes = new TreeSet<String>();

    String[] names = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int i = 0; i < names.length; i++) {
        String name = names[i];//from   w  w w. ja v a 2s.  c o  m
        if (fontExtensionsFontNames.add(name)) {
            classes.add(name);
        }
    }

    return classes;
}

From source file:ded.ui.DiagramController.java

/** Get and log some details related to display scaling, particularly
  * to help diagnose the graphics bugs on HiDPI/Retina displays. */
public void logDisplayScaling() {
    // Based on code from
    // http://lubosplavucha.com/java/2013/09/02/retina-support-in-java-for-awt-swing/

    try {// w  w w  .ja  v  a2 s . co  m
        // Dump a bunch of possibly interesting JVM properties.
        String propertyNames[] = { "awt.toolkit", "java.awt.graphicsenv", "java.runtime.name",
                "java.runtime.version", "java.vendor", "java.version", "java.vm.name", "java.vm.vendor",
                "java.vm.version", };
        for (String name : propertyNames) {
            this.log("property " + name + ": " + System.getProperty(name));
        }

        // Try a property specific to the Apple JVM.
        this.log("apple.awt.contentScaleFactor: "
                + Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor"));

        // Try something specific to OpenJDK.  Here, we
        // reflectively query some private field.  Yuck.
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        try {
            Field field = gd.getClass().getDeclaredField("scale");
            field.setAccessible(true);
            this.log("GraphicsEnvironment.scale: " + field.get(gd));
        } catch (NoSuchFieldException e) {
            this.log("GraphicsEnvironment does not have a 'scale' field");
        }

        // Check some details of "compatible" images.
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        BufferedImage bi = gc.createCompatibleImage(64, 64);
        ColorModel cm = bi.getColorModel();
        this.log("compatible image color model: " + cm);

        // Do the same for a specific imageType that seems to be
        // commonly used, and that I am using when saving to PNG.
        bi = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
        cm = bi.getColorModel();
        this.log("TYPE_INT_ARGB color model: " + cm);

        // And one more.
        bi = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);
        cm = bi.getColorModel();
        this.log("TYPE_INT_RGB color model: " + cm);
    } catch (Exception e) {
        this.log("exception during logDisplayScaling(): " + Util.getExceptionMessage(e));
        this.logNoNewline(Util.getExceptionStackTrace(e));
    }
}

From source file:pcgen.gui2.PCGenFrame.java

/**
 * Create a component to display the message within the bounds of the 
 * screen. If the message is too big for the screen a suitably sized 
 * scroll pane will be returned.//from  w w w .  j a  v  a  2s  .c  om
 * @param message The text of the message.
 * @return The component containing the text.
 */
private JComponent getComponentForMessage(String message) {
    JLabel jLabel = new JLabel(message);
    JScrollPane scroller = new JScrollPane(jLabel);
    Dimension size = jLabel.getPreferredSize();
    final int decorationHeight = 80;
    final int decorationWidth = 70;
    Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    boolean scrollerNeeded = false;
    if (size.height > screenBounds.height - decorationHeight) {
        size.height = screenBounds.height - decorationHeight;
        scrollerNeeded = true;
    }
    if (size.width > screenBounds.width - decorationWidth) {
        size.width = screenBounds.width - decorationWidth;
        scrollerNeeded = true;
    } else if (scrollerNeeded) {
        scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    }
    scroller.setPreferredSize(size);
    return scrollerNeeded ? scroller : jLabel;
}

From source file:de.bwravencl.controllerbuddy.gui.Main.java

private void initOverlay() {
    if (!preferences.getBoolean(PREFERENCES_SHOW_OVERLAY, Toolkit.getDefaultToolkit().isAlwaysOnTopSupported()))
        return;/*from w ww.  jav  a2s .  c o m*/

    var longestDescription = "";
    for (final var mode : input.getProfile().getModes()) {
        final var description = mode.getDescription();
        if (description.length() > longestDescription.length())
            longestDescription = description;
    }

    final var fontMetrics = labelCurrentMode.getFontMetrics(labelCurrentMode.getFont());
    labelCurrentMode.setPreferredSize(
            new Dimension(fontMetrics.stringWidth(longestDescription), fontMetrics.getHeight()));
    labelCurrentMode.setForeground(Color.RED);
    labelCurrentMode.setText(input.getProfile().getActiveMode().getDescription());

    overlayFrame = new JFrame("Overlay");
    overlayFrame.setType(JFrame.Type.UTILITY);
    overlayFrame.setLayout(new BorderLayout());
    overlayFrame.setFocusableWindowState(false);
    overlayFrame.setUndecorated(true);
    overlayFrame.setBackground(TRANSPARENT);

    overlayFrame.add(labelCurrentMode, BorderLayout.PAGE_END);
    overlayFrame.setAlwaysOnTop(true);

    indicatorPanelFlowLayout = new FlowLayout();
    indicatorPanel = new JPanel(indicatorPanelFlowLayout);
    indicatorPanel.setBackground(TRANSPARENT);

    final var virtualAxisToOverlayAxisMap = input.getProfile().getVirtualAxisToOverlayAxisMap();
    for (final var virtualAxis : Input.VirtualAxis.values()) {
        final var overlayAxis = virtualAxisToOverlayAxisMap.get(virtualAxis);
        if (overlayAxis != null) {
            final var progressBar = new JProgressBar(SwingConstants.VERTICAL) {

                private static final long serialVersionUID = 8167193907929992395L;

                @Override
                public void setMaximum(final int n) {
                    if (overlayAxis.inverted)
                        super.setMinimum(-n);
                    else
                        super.setMaximum(n);
                }

                @Override
                public void setMinimum(final int n) {
                    if (overlayAxis.inverted)
                        super.setMaximum(-n);
                    else
                        super.setMinimum(n);
                }

                @Override
                public void setValue(final int n) {
                    super.setValue(overlayAxis.inverted ? -n : n);
                }
            };
            progressBar.setPreferredSize(new Dimension(21, 149));
            progressBar.setBorder(BorderFactory.createDashedBorder(Color.BLACK,
                    (float) progressBar.getPreferredSize().getWidth(),
                    (float) progressBar.getPreferredSize().getWidth()));
            progressBar.setBackground(Color.LIGHT_GRAY);
            progressBar.setForeground(overlayAxis.color);
            progressBar.setValue(1);
            indicatorPanel.add(progressBar);
            virtualAxisToProgressBarMap.put(virtualAxis, progressBar);
        }
    }

    overlayFrame.add(indicatorPanel);

    overlayFrameDragListener = new FrameDragListener(this, overlayFrame) {

        @Override
        public void mouseDragged(final MouseEvent e) {
            super.mouseDragged(e);
            final var maxWindowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment()
                    .getMaximumWindowBounds();
            updateOverlayAlignment(maxWindowBounds);
        }

    };
    overlayFrame.addMouseListener(overlayFrameDragListener);
    overlayFrame.addMouseMotionListener(overlayFrameDragListener);

    prevMaxWindowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    updateOverlayLocation(prevMaxWindowBounds);

    overlayFrame.setVisible(true);
}

From source file:com.biosis.biosislite.vistas.AsignarPermiso.java

private void imprimirBoletaViaje(AsignacionPermiso asignacion) {
    File reporte = new File("reportes/permiso_comision-servicios.jasper");

    List<AsignacionPermiso> listadoReporteAsignacion = new ArrayList();
    listadoReporteAsignacion.add(asignacion);

    Map<String, Object> parametros = new HashMap<>();
    parametros.put("reporte_ususario", UsuarioActivo.getUsuario().getLogin());

    Departamento area = asignacion.getEmpleado().getAreaEmpleadoList().get(0).getDepartamento();
    if (area != null) {
        parametros.put("area", area.getNombre());
    }/*from  w w  w.  j  a va 2 s. c  o m*/

    //        AsignarVacacion vac = new AsignarVacacion();
    long dias = this.fechasAlong(asignacion.getPermiso().getFechaInicio(),
            asignacion.getPermiso().getFechaFin());
    parametros.put("dias", dias);

    //Parametros del viaje
    Viaje viaje = vsc.buscarPorPermiso(asignacion.getPermiso());

    if (viaje != null) {
        parametros.put("alimentacion", viaje.getAlimentacion());
        parametros.put("alojamiento", viaje.getAlojamiento());
        parametros.put("movilidad", viaje.getMovilidad());
        parametros.put("combustible", viaje.getCombustible());
        parametros.put("dias_alimentacion", viaje.getDiasAlimentacion());
        parametros.put("dias_alojamiento", viaje.getDiasAlojamiento());
        parametros.put("dias_movilidad", viaje.getDiasMovLocal());
        //            if (asignacion.getEmpleado().getAreaEmpleadoList().get(0).getDepartamento().getDepartamento().getNombre() != null) {
        //                parametros.put("gerencia", asignacion.getEmpleado().getAreaEmpleadoList().get(0).getDepartamento().getDepartamento().getNombre());
        //            } else {
        parametros.put("gerencia",
                asignacion.getEmpleado().getAreaEmpleadoList().get(0).getGerencia().getNombre());
        //            }
        parametros.put("centro_costo", viaje.getCentroCosto());
        parametros.put("ubigeo", viaje.getDestino());
        parametros.put("cargo", asignacion.getEmpleado().getPuestoList().get(0).getPuesto().getNombre());

        double total = (viaje.getAlimentacion() * viaje.getDiasAlimentacion())
                + (viaje.getAlojamiento() * viaje.getDiasAlojamiento())
                + (viaje.getMovilidad() * viaje.getDiasMovLocal()) + viaje.getCombustible();

        parametros.put("total", total);
    }

    //Fin de parametros del viaje
    Component contentPane = reporteador.obtenerReporte(listadoReporteAsignacion, reporte, parametros);
    Frame principal = JOptionPane.getRootFrame();
    JDialog visor = new JDialog(principal, "Reporte", true);
    visor.setSize(contentPane.getSize());
    //        visor.setSize(ventana.getSize().width, ventana.getSize().height);
    visor.getContentPane().add(contentPane);
    visor.setLocationRelativeTo(this);

    //            visor.setUndecorated(true);
    visor.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
    visor.setVisible(true);
    visor.setAlwaysOnTop(true);
    //        reporteador.getReporte(reporte, parametros, listado) //        reporteador.setConn(controlador.getDao().getConexion());
    //        reporteador.generarReporte(reporte, parametros, JOptionPane.getFrameForComponent(this));
}