Search in sources :

Example 61 with Toolkit

use of java.awt.Toolkit in project jdk8u_jdk by JetBrains.

the class bug8071705 method checkConfigs.

private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {
    GraphicsDevice correctDevice = null;
    if (devices.length < 2) {
        return correctDevice;
    }
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
    int halfScreen = screenBounds.height / 2;
    for (int i = 0; i < devices.length; i++) {
        if (devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
            GraphicsConfiguration conf = devices[i].getDefaultConfiguration();
            Rectangle bounds = conf.getBounds();
            if (bounds.y >= halfScreen) {
                // found
                correctDevice = devices[i];
                break;
            }
        }
    }
    return correctDevice;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Rectangle(java.awt.Rectangle) Toolkit(java.awt.Toolkit) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 62 with Toolkit

use of java.awt.Toolkit in project JMRI by JMRI.

the class HardcopyWriter method hardcopyWriter.

private void hardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean preview) throws HardcopyWriter.PrintCanceledException {
    isPreview = preview;
    this.frame = frame;
    // set default to color
    pageAttributes.setColor(PageAttributes.ColorType.COLOR);
    // skip printer selection if preview
    if (!isPreview) {
        Toolkit toolkit = frame.getToolkit();
        job = toolkit.getPrintJob(frame, jobname, jobAttributes, pageAttributes);
        if (job == null) {
            throw new PrintCanceledException("User cancelled print request");
        }
        pagesize = job.getPageDimension();
        pagedpi = job.getPageResolution();
        // selected is less than the total number of pages, that's the reason for the page null checks
        if (jobAttributes.getDefaultSelection().equals(DefaultSelectionType.RANGE)) {
            prFirst = jobAttributes.getPageRanges()[0][0];
        }
    }
    x0 = (int) (leftmargin * pagedpi);
    y0 = (int) (topmargin * pagedpi);
    width = pagesize.width - (int) ((leftmargin + rightmargin) * pagedpi);
    height = pagesize.height - (int) ((topmargin + bottommargin) * pagedpi);
    // get body font and font size
    font = new Font(fontName, fontStyle, fontsize);
    metrics = frame.getFontMetrics(font);
    lineheight = metrics.getHeight();
    lineascent = metrics.getAscent();
    charwidth = metrics.charWidth('m');
    // compute lines and columns within margins
    chars_per_line = width / charwidth;
    lines_per_page = height / lineheight;
    // header font info
    headerfont = new Font("SansSerif", Font.ITALIC, fontsize);
    headermetrics = frame.getFontMetrics(headerfont);
    headery = y0 - (int) (0.125 * pagedpi) - headermetrics.getHeight() + headermetrics.getAscent();
    // compute date/time for header
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
    df.setTimeZone(TimeZone.getDefault());
    time = df.format(new Date());
    this.jobname = jobname;
    this.fontsize = fontsize;
    if (isPreview) {
        previewFrame = new JmriJFrame("Print Preview: " + jobname);
        previewFrame.getContentPane().setLayout(new BorderLayout());
        toolBarInit();
        previewToolBar.setFloatable(false);
        previewFrame.getContentPane().add(previewToolBar, BorderLayout.NORTH);
        previewPanel = new JPanel();
        previewPanel.setSize(pagesize.width, pagesize.height);
        // add the panel to the frame and make visible, otherwise creating the image will fail.
        // use a scroll pane to handle print images bigger than the window
        previewFrame.getContentPane().add(new JScrollPane(previewPanel), BorderLayout.CENTER);
        // page width 660 for portrait
        previewFrame.setSize(pagesize.width + 48, pagesize.height + 100);
        previewFrame.setVisible(true);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JmriJFrame(jmri.util.JmriJFrame) DateFormat(java.text.DateFormat) Toolkit(java.awt.Toolkit) Font(java.awt.Font) Date(java.util.Date)

Example 63 with Toolkit

use of java.awt.Toolkit in project jdk8u_jdk by JetBrains.

the class LookAndFeel method provideErrorFeedback.

/**
     * Invoked when the user attempts an invalid operation,
     * such as pasting into an uneditable <code>JTextField</code>
     * that has focus. The default implementation beeps. Subclasses
     * that wish different behavior should override this and provide
     * the additional feedback.
     *
     * @param component the <code>Component</code> the error occurred in,
     *                  may be <code>null</code>
     *                  indicating the error condition is not directly
     *                  associated with a <code>Component</code>
     * @since 1.4
     */
public void provideErrorFeedback(Component component) {
    Toolkit toolkit = null;
    if (component != null) {
        toolkit = component.getToolkit();
    } else {
        toolkit = Toolkit.getDefaultToolkit();
    }
    toolkit.beep();
}
Also used : SunToolkit(sun.awt.SunToolkit) Toolkit(java.awt.Toolkit)

Example 64 with Toolkit

use of java.awt.Toolkit in project jdk8u_jdk by JetBrains.

the class UIManager method getSystemLookAndFeelClassName.

/**
     * Returns the name of the <code>LookAndFeel</code> class that implements
     * the native system look and feel if there is one, otherwise
     * the name of the default cross platform <code>LookAndFeel</code>
     * class. This value can be overriden by setting the
     * <code>swing.systemlaf</code> system property.
     *
     * @return the <code>String</code> of the <code>LookAndFeel</code>
     *          class
     *
     * @see #setLookAndFeel
     * @see #getCrossPlatformLookAndFeelClassName
     */
public static String getSystemLookAndFeelClassName() {
    String systemLAF = AccessController.doPrivileged(new GetPropertyAction("swing.systemlaf"));
    if (systemLAF != null) {
        return systemLAF;
    }
    OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
    if (osType == OSInfo.OSType.WINDOWS) {
        return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    } else {
        String desktop = AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        if ("gnome".equals(desktop) && toolkit instanceof SunToolkit && ((SunToolkit) toolkit).isNativeGTKAvailable()) {
            // May be set on Linux and Solaris boxs.
            return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
        }
        if (osType == OSInfo.OSType.MACOSX) {
            if (toolkit.getClass().getName().equals("sun.lwawt.macosx.LWCToolkit")) {
                return "com.apple.laf.AquaLookAndFeel";
            }
        }
        if (osType == OSInfo.OSType.SOLARIS) {
            return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
        }
    }
    return getCrossPlatformLookAndFeelClassName();
}
Also used : OSInfo(sun.awt.OSInfo) GetPropertyAction(sun.security.action.GetPropertyAction) SunToolkit(sun.awt.SunToolkit) SunToolkit(sun.awt.SunToolkit) Toolkit(java.awt.Toolkit)

Example 65 with Toolkit

use of java.awt.Toolkit in project pcgen by PCGen.

the class Utility method setApplicationTitle.

/**
	 * This method is used to set the name of the application for the window manager
	 *
	 * @param title Title to use
	 */
public static void setApplicationTitle(String title) {
    // macOS
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", title);
    System.setProperty("apple.awt.application.name", title);
    // X11
    Toolkit xToolkit = Toolkit.getDefaultToolkit();
    try {
        Field awtAppClassNameField = //$NON-NLS-1$
        xToolkit.getClass().getDeclaredField("awtAppClassName");
        awtAppClassNameField.setAccessible(true);
        awtAppClassNameField.set(xToolkit, title);
    } catch (NoSuchFieldException | IllegalAccessException e) {
    // Rather than do a OS system condition, just ignore this expected exception
    //Logging.log(Level.FINEST, "Can not set name of application for window manager", e);
    }
}
Also used : Field(java.lang.reflect.Field) Toolkit(java.awt.Toolkit)

Aggregations

Toolkit (java.awt.Toolkit)95 Dimension (java.awt.Dimension)29 Point (java.awt.Point)21 Image (java.awt.Image)19 BufferedImage (java.awt.image.BufferedImage)14 URL (java.net.URL)14 GraphicsDevice (java.awt.GraphicsDevice)8 Insets (java.awt.Insets)8 GraphicsEnvironment (java.awt.GraphicsEnvironment)7 Rectangle (java.awt.Rectangle)7 IOException (java.io.IOException)6 Field (java.lang.reflect.Field)6 MediaTracker (java.awt.MediaTracker)5 ImageIcon (javax.swing.ImageIcon)5 Frame (java.awt.Frame)4 Clipboard (java.awt.datatransfer.Clipboard)4 BorderLayout (java.awt.BorderLayout)3 Font (java.awt.Font)3 Graphics (java.awt.Graphics)3 GraphicsConfiguration (java.awt.GraphicsConfiguration)3