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:es.emergya.cliente.constants.LogicConstantsUI.java

private static Font getFont(Integer type, String font) {
    Font f;//  ww w  .  ja v  a  2  s.  c  o  m
    try {
        f = Font.createFont(Font.TRUETYPE_FONT, LogicConstantsUI.class.getResourceAsStream(font));
    } catch (Exception e) {
        LogicConstantsUI.LOG.error("No se pudo cargar el font bold", e);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontNames = ge.getAvailableFontFamilyNames();
        if (fontNames.length > 0) {
            f = Font.decode(fontNames[0]);
            if (type != null) {
                f = f.deriveFont(type);
            }
        } else {
            throw new NullPointerException("There is no font available: " + font);
        }
    }
    return f;
}

From source file:springTest.tests.Assume.java

/**
 * Assume that we can load fonts./*from  w ww .  j  a va2  s.c o  m*/
 * <p>See <a href="https://java.net/jira/browse/MACOSX_PORT-355">MACOSX_PORT-355</a>
 * issue.
 * @throws AssumptionViolatedException if the assumption fails
 */
public static void canLoadNativeDirFonts() {
    try {
        GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
        Class<?> parserClass = ClassUtils.forName("net.sf.jasperreports.engine.util.JRStyledTextParser",
                Assume.class.getClassLoader());
        Method method = parserClass.getMethod("getInstance");
        method.setAccessible(true);
        method.invoke(null);
    } catch (Throwable ex) {
        throw new AssumptionViolatedException("Requires GraphicsEnvironment that can load fonts", ex);
    }
}

From source file:net.team2xh.crt.gui.util.GUIToolkit.java

/**
 * Provides a BufferedImage in the format most compatible with current graphics card.
 *
 * @param  w Width of the image/*ww  w.ja v  a2s .c o m*/
 * @param  h Height of the image
 * @return   Optimized BufferedImage
 */
public static BufferedImage getEfficientBuffer(int w, int h) {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = env.getDefaultScreenDevice();
    GraphicsConfiguration config = device.getDefaultConfiguration();
    return config.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
}

From source file:CutAndPasteDemo.java

public CutAndPasteDemo() {
    super("Cut And Paste Demonstration");

    clipboard = getToolkit().getSystemClipboard();

    GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font font = new Font("LucidaSans", Font.PLAIN, 15);
    textArea1 = new JTextArea(davidMessage + andyMessage, 5, 25);
    textArea2 = new JTextArea("<Paste text here>", 5, 25);
    textArea1.setFont(font);/*  w  w  w  .ja va 2s. c  o  m*/
    textArea2.setFont(font);

    JPanel jPanel = new JPanel();
    JMenuBar jMenuBar = new JMenuBar();
    JMenuItem cutItem = new JMenuItem("Cut");
    JMenuItem pasteItem = new JMenuItem("Paste");
    JMenu jMenu = new JMenu("Edit");
    jMenu.add(cutItem);
    jMenu.add(pasteItem);

    cutItem.addActionListener(new CutActionListener());
    pasteItem.addActionListener(new PasteActionListener());

    jMenuBar.add(jMenu);
    jPanel.add(jMenuBar);

    jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
    jPanel.add(textArea1);
    jPanel.add(Box.createRigidArea(new Dimension(0, 10)));
    jPanel.add(textArea2);

    getContentPane().add(jPanel, BorderLayout.CENTER);
}

From source file:es.emergya.cliente.constants.LogicConstants.java

private static Font getFont(Integer type, String font) {
    Font f;//from   w w w  . j a  va 2  s. c o  m
    try {
        f = Font.createFont(Font.TRUETYPE_FONT, LogicConstants.class.getResourceAsStream(font));
    } catch (Exception e) {
        LogicConstants.LOG.error("No se pudo cargar el font bold", e);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontNames = ge.getAvailableFontFamilyNames();
        if (fontNames.length > 0) {
            f = Font.decode(fontNames[0]);
            if (type != null) {
                f = f.deriveFont(type);
            }
        } else {
            throw new NullPointerException("There is no font available: " + font);
        }
    }
    return f;
}

From source file:org.omegat.util.StaticUtils.java

/**
 * Returns the names of all font families available.
 */// w  w w.  j a va 2  s  .co  m
public static String[] getFontNames() {
    GraphicsEnvironment graphics;
    graphics = GraphicsEnvironment.getLocalGraphicsEnvironment();
    return graphics.getAvailableFontFamilyNames();
}

From source file:coolmap.canvas.datarenderer.renderer.impl.NumberComposite.java

private void updateLegend() {
    try {/*from ww  w.j  ava  2 s . com*/
        ArrayList<Image> legends = new ArrayList<Image>(4);
        if (singleRenderer != null && singleRenderer.getLegend() != null) {
            legends.add(singleRenderer.getLegend());
        }
        if (rowGroupRenderer != null && rowGroupRenderer.getLegend() != null) {
            legends.add(rowGroupRenderer.getLegend());
        }
        if (columnGroupRenderer != null && columnGroupRenderer.getLegend() != null) {
            legends.add(columnGroupRenderer.getLegend());
        }
        if (rowColumnGroupRenderer != null && rowColumnGroupRenderer.getLegend() != null) {
            legends.add(rowColumnGroupRenderer.getLegend());
        }

        if (!legends.isEmpty()) {
            int margin = 5;
            int imageWidth = 0;
            int imageHeight = 0;
            for (Image l : legends) {
                imageHeight += margin * 2 + l.getHeight(null);
                if (imageWidth < l.getWidth(null)) {
                    imageWidth = l.getWidth(null);
                }
            }

            imageWidth += margin * 2;

            if (imageWidth > 0 && imageHeight > 0) {
                legend = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                        .getDefaultConfiguration()
                        .createCompatibleImage(imageWidth, imageHeight, Transparency.TRANSLUCENT);
                Graphics2D g2D = legend.createGraphics();
                g2D.translate(margin, 0);
                for (Image l : legends) {
                    g2D.translate(0, margin);
                    g2D.drawImage(l, 0, 0, null);
                    g2D.translate(0, margin + l.getHeight(null));
                }
                g2D.dispose();
            }

        }
    } catch (Exception e) {

    }
}

From source file:Main.java

/**
 * Computes the maximum bounds of the current screen device. If this method is
 * called on JDK 1.4, Xinerama-aware results are returned. (See Sun-Bug-ID
 * 4463949 for details)./*w  ww.  j  a va  2  s.c  o m*/
 * 
 * @return the maximum bounds of the current screen.
 */
public static Rectangle getMaximumWindowBounds() {
    final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        final Method method = GraphicsEnvironment.class.getMethod("getMaximumWindowBounds", (Class[]) null);
        return (Rectangle) method.invoke(localGraphicsEnvironment, (Object[]) null);
    } catch (Exception e) {
        // ignore ... will fail if this is not a JDK 1.4 ..
    }

    final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
    return new Rectangle(0, 0, s.width, s.height);
}

From source file:org.polymap.styler.ui.TextSymbolizerEditorComposite.java

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it./*  ww  w.jav a2s . c o m*/
 */
public TextSymbolizerEditorComposite(Composite parent, StyleChangeListenerInterface scl,
        SymbolizerWrapper _symbolizer_w) {

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    font_family_combo_items = ge.getAvailableFontFamilyNames();

    symbolizer_w = _symbolizer_w;

    final Display display = parent.getDisplay();

    log.info("creating style editor layout"); //$NON-NLS-1$
    style_change_listener = scl;

    if (symbolizer_w.hasLabel()) { // TODO chek if needed 
        Composite label_composite = LayoutHelper.subpart(parent, Messages.get().LABEL, 2);
        /*
        Text label = new Text(label_composite,SWT.BORDER);
        label.setSize(50,label.getSize().y);
                
        label.setText(symbolizer_w.getLabel());
                
        label.addModifyListener(new ModifyListener() {
                
           @Override
           public void modifyText(ModifyEvent event) {
              style_change_listener
             .label_changed(((Text) event.widget)
                   .getText() ,false );
                
           }
        });
        */
        Combo label_combo = new Combo(label_composite, SWT.NONE);
        label_combo.setItems(symbolizer_w.getFeatureAttributes());
        label_combo.setText(symbolizer_w.getLabel());
        label_combo.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent event) {
                style_change_listener.label_changed(((Combo) event.widget).getText(), true);

            }
        });

        //label_combo.select(1);
        //label_combo.addModifyListener(new ModifyListener() {

        //         Text attrs = new Text(label_composite,SWT.BORDER);
        //attrs.setText("" + symbolizer_w.get)
    }

    Composite font_composite = LayoutHelper.subpart(parent, Messages.get().FONT, 3);

    new FontAlignEditorComposite(parent, scl, symbolizer_w);
    /*
    Combo font_align_v_combo = new Combo(font_composite, SWT.NONE);
    font_align_v_combo.setItems(align_v_combo_items);
    font_align_v_combo.select( symbolizer_w.getLabelPlacementY());
    font_align_v_combo.addModifyListener(new ModifyListener() {
            
       @Override
       public void modifyText(ModifyEvent event) {
    // TODO Auto-generated method stub
    switch (((Combo) event.widget).getSelectionIndex()) {
    case 0:
       align_v_str = "t"; //$NON-NLS-1$
       break;
    case 1:
       align_v_str = "m"; //$NON-NLS-1$
       break;
    case 2:
       align_v_str = "b"; //$NON-NLS-1$
       break;
            
    }
    style_change_listener.font_align_changed(align_h_str
          + align_v_str);
            
       }
    });
            
    Combo font_align_h_combo = new Combo(font_composite, SWT.NONE);
    font_align_h_combo.setItems(align_h_combo_items);
    font_align_h_combo.select(symbolizer_w.getLabelPlacementX());
    font_align_h_combo.addModifyListener(new ModifyListener() {
            
       @Override
       public void modifyText(ModifyEvent event) {
    // TODO Auto-generated method stub
    switch (((Combo) event.widget).getSelectionIndex()) {
    case 0:
       align_h_str = "l"; //$NON-NLS-1$
       break;
    case 1:
       align_h_str = "c"; //$NON-NLS-1$
       break;
    case 2:
       align_h_str = "r"; //$NON-NLS-1$
       break;
            
    }
    style_change_listener.font_align_changed(align_h_str
          + align_v_str);
            
       }
    });
    */
    Combo font_weight_combo = new Combo(LayoutHelper.describingGroup(font_composite, Messages.get().WEIGHT),
            SWT.DROP_DOWN | SWT.READ_ONLY);
    font_weight_combo.setItems(font_weight_combo_items);
    font_weight_combo.select(0);

    font_weight_combo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            // TODO Auto-generated method stub

            style_change_listener.font_weight_changed(
                    font_weight_combo_items4sld[((Combo) event.widget).getSelectionIndex()]);

        }
    });

    Combo font_size_combo = new Combo(LayoutHelper.describingGroup(font_composite, Messages.get().SIZE),
            SWT.NONE);
    font_size_combo.setItems(width_combo_items);

    font_size_combo.setText("" + symbolizer_w.getFont().getSize()); //$NON-NLS-1$
    font_size_combo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            // TODO Auto-generated method stub
            int val = Integer.parseInt(((Combo) event.widget).getText());
            style_change_listener.font_size_changed(val);

        }
    });

    Combo font_family_combo = new Combo(LayoutHelper.describingGroup(font_composite, Messages.get().FAMILY),
            SWT.NONE);
    font_family_combo.setItems(font_family_combo_items);
    font_family_combo.setText(symbolizer_w.getFont().getFamily().get(0).toString());
    font_family_combo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            // TODO Auto-generated method stub

            style_change_listener.font_family_changed(((Combo) event.widget).getText());

        }
    });

    /*Button mod_font_color_btn = new Button(font_composite, SWT.PUSH);
    mod_font_color_btn.setText(Messages.get().COLOR);
            
    mod_font_color_btn.addSelectionListener(new SelectionAdapter() {
       public void widgetSelected(SelectionEvent e) {
    style_change_listener.font_color_changed((new ColorDialog(
          new Shell(display))).open());
       }
    });
            
    */
    /*
    final Button mod_font_color_btn = new Button(font_composite, SWT.PUSH);
    mod_font_color_btn.setText(Messages.get().COLOR);
            
    mod_font_color_btn.setImage( ImageHelper.createColorRectImage(SLD.color(symbolizer_w.getTextFill().getColor()))  );
            
    mod_font_color_btn.addSelectionListener(new SelectionAdapter() {
       public void widgetSelected(SelectionEvent e) {
    ColorDialog dialog=new ColorDialog(   new Shell(display));
            
    dialog.setRGB(ColorHelper.Color2RGB(SLD.color(symbolizer_w.getTextFill().getColor() ) ));
            
    RGB res=dialog.open();
    mod_font_color_btn.setImage(ImageHelper.createColorRectImage(res));
    style_change_listener.font_color_changed(res);
       }
    });
    */

    /* HALO Section */

    Composite halo_composite = LayoutHelper.subpart(parent, Messages.get().HALO, 3);

    Button halo_active = new Button(halo_composite, SWT.CHECK);
    halo_active.setData(symbolizer_w);

    halo_active.setSelection(symbolizer_w.hasHalo());

    final Spinner halo_opacity_spinner = LayoutHelper.createPercentageSpinner(

            LayoutHelper.describingGroup(halo_composite, Messages.get().OPACITY),
            (int) (symbolizer_w.getHaloOpacity() * 100));

    final Combo halo_radius_combo = new Combo(
            LayoutHelper.describingGroup(halo_composite, Messages.get().RADIUS), SWT.NONE);

    final Button mod_halo_color_btn = new Button(
            LayoutHelper.describingGroup(halo_composite, Messages.get().COLOR), SWT.PUSH);

    halo_active.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button thisButton = (Button) e.widget;

            if (thisButton.getSelection()) {
                ((SymbolizerWrapper) (e.widget.getData())).addDefaultHalo();

                mod_halo_color_btn.setImage(
                        ImageHelper.createColorRectImage(SLD.color(symbolizer_w.getHaloFill().getColor())));
                halo_opacity_spinner.setSelection(
                        (int) (((SymbolizerWrapper) (e.widget.getData())).getHaloOpacity() * 100));
                halo_radius_combo.setText("" + ((SymbolizerWrapper) (e.widget.getData())).getHaloRadius());

                mod_halo_color_btn.setEnabled(true);
                halo_opacity_spinner.setEnabled(true);
                halo_radius_combo.setEnabled(true);

            } else {
                ((SymbolizerWrapper) (e.widget.getData())).setHalo(null);
                mod_halo_color_btn.setEnabled(false);
                halo_opacity_spinner.setEnabled(false);
                halo_radius_combo.setEnabled(false);
            }
        }
    });

    halo_opacity_spinner.setEnabled(symbolizer_w.hasHalo());

    halo_opacity_spinner.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            style_change_listener.halo_opacity_changed(((Spinner) event.widget).getSelection() / 100.0);

        }
    });

    if (symbolizer_w.hasHalo())
        mod_halo_color_btn
                .setImage(ImageHelper.createColorRectImage(SLD.color(symbolizer_w.getHaloFill().getColor())));
    else
        mod_halo_color_btn.setEnabled(false);

    mod_halo_color_btn.setText("");

    mod_halo_color_btn.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ColorDialog dialog = new ColorDialog(new Shell(display));

            dialog.setRGB(ColorHelper.Color2RGB(SLD.color(symbolizer_w.getHaloFill().getColor())));

            RGB res = dialog.open();
            mod_halo_color_btn.setImage(ImageHelper.createColorRectImage(res));
            style_change_listener.halo_color_changed(res);
        }
    });

    halo_radius_combo.setItems(halo_radius_combo_items);

    halo_radius_combo.setText("" + symbolizer_w.getFont().getSize()); //$NON-NLS-1$
    halo_radius_combo.setEnabled(symbolizer_w.hasHalo());

    halo_radius_combo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            // TODO Auto-generated method stub
            double val = Double.parseDouble(((Combo) event.widget).getText());
            style_change_listener.halo_width_changed(val);

        }
    });

}

From source file:Main.java

  /**
 * Computes the maximum bounds of the current screen device. If this method is
 * called on JDK 1.4, Xinerama-aware results are returned. (See Sun-Bug-ID
 * 4463949 for details)./*from  w  w  w . j a v a2 s .  c  om*/
 * 
 * @return the maximum bounds of the current screen.
 */
public static Rectangle getMaximumWindowBounds() {
  final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment
      .getLocalGraphicsEnvironment();
  try {
    final Method method = GraphicsEnvironment.class.getMethod("getMaximumWindowBounds",
        (Class[]) null);
    return (Rectangle) method.invoke(localGraphicsEnvironment, (Object[]) null);
  } catch (Exception e) {
    // ignore ... will fail if this is not a JDK 1.4 ..
  }

  final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
  return new Rectangle(0, 0, s.width, s.height);
}