Search in sources :

Example 61 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project ffx by mjschnie.

the class MainPanel method initialize.

/**
 * <p>
 * initialize</p>
 */
public void initialize() {
    if (init) {
        return;
    }
    init = true;
    String dir = System.getProperty("user.dir", FileSystemView.getFileSystemView().getDefaultDirectory().getAbsolutePath());
    setCWD(new File(dir));
    locale = new FFXLocale("en", "US");
    JDialog splashScreen = null;
    ClassLoader loader = getClass().getClassLoader();
    if (!GraphicsEnvironment.isHeadless()) {
        // Splash Screen
        JFrame.setDefaultLookAndFeelDecorated(true);
        splashScreen = new JDialog(frame, false);
        ImageIcon logo = new ImageIcon(loader.getResource("ffx/ui/icons/splash.png"));
        JLabel ffxLabel = new JLabel(logo);
        ffxLabel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
        Container contentpane = splashScreen.getContentPane();
        contentpane.setLayout(new BorderLayout());
        contentpane.add(ffxLabel, BorderLayout.CENTER);
        splashScreen.setUndecorated(true);
        splashScreen.pack();
        Dimension screenDimension = getToolkit().getScreenSize();
        Dimension splashDimension = splashScreen.getSize();
        splashScreen.setLocation((screenDimension.width - splashDimension.width) / 2, (screenDimension.height - splashDimension.height) / 2);
        splashScreen.setResizable(false);
        splashScreen.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        splashScreen.setVisible(true);
        // Make all pop-up Menus Heavyweight so they play nicely with Java3D
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    }
    // Create the Root Node
    dataRoot = new MSRoot();
    Border bb = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
    statusLabel = new JLabel("  ");
    JLabel stepLabel = new JLabel("  ");
    stepLabel.setHorizontalAlignment(JLabel.RIGHT);
    JLabel energyLabel = new JLabel("  ");
    energyLabel.setHorizontalAlignment(JLabel.RIGHT);
    JPanel statusPanel = new JPanel(new GridLayout(1, 3));
    statusPanel.setBorder(bb);
    statusPanel.add(statusLabel);
    statusPanel.add(stepLabel);
    statusPanel.add(energyLabel);
    if (!GraphicsEnvironment.isHeadless()) {
        GraphicsConfigTemplate3D template3D = new GraphicsConfigTemplate3D();
        // template3D.setDoubleBuffer(GraphicsConfigTemplate.PREFERRED);
        GraphicsConfiguration gc = null;
        try {
            gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(template3D);
        // gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        } catch (Exception e) {
            e.fillInStackTrace();
            e.printStackTrace();
            logger.log(Level.SEVERE, " Exception encountered when trying to get the best GraphicsConfiguration", e);
        }
        try {
            graphicsCanvas = new GraphicsCanvas(gc, this);
        } catch (Exception e) {
            e.fillInStackTrace();
            e.printStackTrace();
            logger.log(Level.SEVERE, " Exception encountered when trying to create the GraphicsCanvas", e);
        }
        graphicsPanel = new GraphicsPanel(graphicsCanvas, statusPanel);
    }
    // Initialize various Panels
    hierarchy = new Hierarchy(this);
    hierarchy.setStatus(statusLabel, stepLabel, energyLabel);
    keywordPanel = new KeywordPanel(this);
    modelingPanel = new ModelingPanel(this);
    JPanel treePane = new JPanel(new BorderLayout());
    JScrollPane scrollPane = new JScrollPane(hierarchy, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    treePane.add(scrollPane, BorderLayout.CENTER);
    tabbedPane = new JTabbedPane();
    ImageIcon graphicsIcon = new ImageIcon(loader.getResource("ffx/ui/icons/monitor.png"));
    ImageIcon keywordIcon = new ImageIcon(loader.getResource("ffx/ui/icons/key.png"));
    ImageIcon modelingIcon = new ImageIcon(loader.getResource("ffx/ui/icons/cog.png"));
    tabbedPane.addTab(locale.getValue("Graphics"), graphicsIcon, graphicsPanel);
    tabbedPane.addTab(locale.getValue("KeywordEditor"), keywordIcon, keywordPanel);
    tabbedPane.addTab(locale.getValue("ModelingCommands"), modelingIcon, modelingPanel);
    tabbedPane.addChangeListener(this);
    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, treePane, tabbedPane);
    /* splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false,
         treePane, graphicsPanel); */
    splitPane.setResizeWeight(0.25);
    splitPane.setOneTouchExpandable(true);
    setLayout(new BorderLayout());
    add(splitPane, BorderLayout.CENTER);
    if (!GraphicsEnvironment.isHeadless()) {
        mainMenu = new MainMenu(this);
        add(mainMenu.getToolBar(), BorderLayout.NORTH);
        getModelingShell();
        loadPrefs();
        SwingUtilities.updateComponentTreeUI(SwingUtilities.getRoot(this));
        splashScreen.dispose();
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) JTabbedPane(javax.swing.JTabbedPane) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) GraphicsConfiguration(java.awt.GraphicsConfiguration) Container(java.awt.Container) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) GraphicsConfigTemplate3D(javax.media.j3d.GraphicsConfigTemplate3D) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) FFXLocale(ffx.ui.properties.FFXLocale) MSRoot(ffx.potential.bonded.MSRoot) JSplitPane(javax.swing.JSplitPane) File(java.io.File) Border(javax.swing.border.Border) EtchedBorder(javax.swing.border.EtchedBorder) JDialog(javax.swing.JDialog)

Example 62 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jmulticard by ctt-gob-es.

the class ResizingAdaptor method iconToImage.

private static Image iconToImage(final Icon icon, final Dimension d) {
    if (icon instanceof ImageIcon) {
        return ((ImageIcon) icon).getImage();
    }
    final int w = d.width;
    final int h = d.height;
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final BufferedImage image = gc.createCompatibleImage(w, h);
    final Graphics2D g = image.createGraphics();
    icon.paintIcon(null, g, 0, 0);
    g.dispose();
    return image;
}
Also used : ImageIcon(javax.swing.ImageIcon) GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 63 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project darkFunction-Editor by darkFunction.

the class AnimationCell method draw.

public void draw(final Graphics g, final Rectangle destRect) {
    if (vImage == null)
        return;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    int valid = vImage.validate(gc);
    if (valid == VolatileImage.IMAGE_INCOMPATIBLE) {
        rebuild();
    }
    if (vImage != null) {
        Rectangle r = destRect;
        g.drawImage(vImage, r.x, r.y, r.width, r.height, null);
    }
}
Also used : Rectangle(java.awt.Rectangle) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 64 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project darkFunction-Editor by darkFunction.

the class ImageUtil method createVolatileImage.

public static VolatileImage createVolatileImage(int width, int height, int transparency) {
    if (width == 0 || height == 0)
        return null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage image = null;
    image = gc.createCompatibleVolatileImage(width, height, transparency);
    int valid = image.validate(gc);
    if (valid == VolatileImage.IMAGE_INCOMPATIBLE) {
        image = createVolatileImage(width, height, transparency);
    }
    return image;
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 65 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project darkFunction-Editor by darkFunction.

the class ImageUtil method createVolatileImage.

public static VolatileImage createVolatileImage(BufferedImage bi) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vimage = createVolatileImage(bi.getWidth(), bi.getHeight(), java.awt.Transparency.TRANSLUCENT);
    java.awt.Graphics2D g = null;
    try {
        g = vimage.createGraphics();
        // clear to transparent
        g.setComposite(AlphaComposite.Src);
        g.setColor(new Color(0, 0, 0, 0));
        g.fillRect(0, 0, vimage.getWidth(), vimage.getHeight());
        g.drawImage(bi, null, 0, 0);
    } finally {
        g.dispose();
    }
    return vimage;
}
Also used : VolatileImage(java.awt.image.VolatileImage) Color(java.awt.Color) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Aggregations

GraphicsConfiguration (java.awt.GraphicsConfiguration)134 GraphicsEnvironment (java.awt.GraphicsEnvironment)55 BufferedImage (java.awt.image.BufferedImage)46 Rectangle (java.awt.Rectangle)43 GraphicsDevice (java.awt.GraphicsDevice)38 Graphics2D (java.awt.Graphics2D)33 VolatileImage (java.awt.image.VolatileImage)31 Point (java.awt.Point)29 Dimension (java.awt.Dimension)21 Insets (java.awt.Insets)16 File (java.io.File)16 Graphics (java.awt.Graphics)13 IOException (java.io.IOException)13 Frame (java.awt.Frame)11 JFrame (javax.swing.JFrame)8 HeadlessException (java.awt.HeadlessException)7 Window (java.awt.Window)7 ImageIcon (javax.swing.ImageIcon)7 Color (java.awt.Color)6 AffineTransform (java.awt.geom.AffineTransform)6