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;
}
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);
}
}
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();
}
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();
}
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);
}
}
Aggregations