use of java.awt.Toolkit in project open-ecard by ecsec.
the class GUIDefaults method initialize.
public static void initialize() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Toolkit toolkit = Toolkit.getDefaultToolkit();
GUIProperties guiProps = new GUIProperties();
Properties props = guiProps.properties();
for (String property : props.stringPropertyNames()) {
try {
String propertyName = property.substring(0, property.indexOf('.'));
String propertyAttribute = property.substring(propertyName.length() + 1, property.length());
String value = (String) props.getProperty(property);
// Parse color property
if (colorProperties.contains(propertyAttribute)) {
validateHexColor(value);
if (value.length() == 4) {
StringBuilder sb = new StringBuilder("#");
for (int i = 1; i < value.length(); i++) {
sb.append(value.substring(i, i + 1));
sb.append(value.substring(i, i + 1));
}
value = sb.toString();
}
Color color = Color.decode(value);
defaults.put(property, color);
ownDefaults.put(property, color);
} else // Parse font propertiy
if (fontProperties.contains(propertyAttribute)) {
Font font = Font.decode(value);
defaults.put(property, font);
ownDefaults.put(property, font);
} else // Parse icon propertiy
if (iconProperties.contains(propertyAttribute)) {
URL url = FileUtils.resolveResourceAsURL(guiProps.getClass(), value);
if (url == null) {
logger.error("Cannot parse the property: " + property);
} else {
Image image = toolkit.getImage(url);
ImageIcon icon = new ImageIcon(image);
defaults.put(property, icon);
ownDefaults.put(property, icon);
}
}
} catch (Exception e) {
logger.error("Cannot parse the property: " + property);
}
}
} catch (Exception e) {
logger.error(e.getMessage());
}
}
use of java.awt.Toolkit in project zaproxy by zaproxy.
the class GuiBootstrap method setX11AwtAppClassName.
private void setX11AwtAppClassName() {
Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
// See JDK-6528430 : need system property to override default WM_CLASS
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6528430
// Based on NetBeans workaround linked from the issue:
Class<?> toolkitClass = defaultToolkit.getClass();
if ("sun.awt.X11.XToolkit".equals(toolkitClass.getName())) {
try {
Field awtAppClassName = toolkitClass.getDeclaredField("awtAppClassName");
awtAppClassName.setAccessible(true);
awtAppClassName.set(null, Constant.PROGRAM_NAME);
} catch (Exception e) {
logger.warn("Failed to set awt app class name: " + e.getMessage());
}
}
}
use of java.awt.Toolkit in project openblocks by mikaelhg.
the class ImageManager method createImage.
public BufferedImage createImage(String file) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
URL u = ImageManager.class.getResource(file);
if (u == null) {
System.out.println("Could not find resource " + file);
return null;
}
Image img = toolkit.createImage(u);
if (img == null) {
System.out.println("Couldn't load image " + file);
return null;
}
MediaTracker mt = new MediaTracker(comp);
try {
mt.addImage(img, 0);
mt.waitForAll();
} catch (Exception e) {
System.out.println("Couldn't load image " + file);
System.out.println(e);
return null;
}
if (mt.isErrorAny()) {
System.out.println("Couldn't load image " + file);
return null;
}
// ImageObserver observer = new ImageObserver() {
// public boolean imageUpdate(Image img,int flags,int x,int y,int w,int h) {
// if ((flags & (ALLBITS | FRAMEBITS | ABORT)) != 0) {
// synchronized (this) { notify(); }
// return false;
// }
// return true;
// }
// };
// try {
// synchronized (observer) {
// while (!toolkit.prepareImage(img,-1,-1,observer)) { observer.wait(); }
// }
// }
// catch (InterruptedException e) {
// System.out.println("Couldn't load image "+file);
// return null;
// }
// System.out.println("image width "+ img.getWidth(comp) +
// " height " + img.getHeight(comp));
BufferedImage bimg = comp.getGraphicsConfiguration().createCompatibleImage(img.getWidth(comp), img.getHeight(comp), Transparency.TRANSLUCENT);
bimg.getGraphics().drawImage(img, 0, 0, comp);
return bimg;
}
use of java.awt.Toolkit in project mzmine2 by mzmine.
the class MainWindow method initModule.
public void initModule() {
assert SwingUtilities.isEventDispatchThread();
try {
final InputStream mzmineIconStream = DesktopSetup.class.getClassLoader().getResourceAsStream("MZmineIcon.png");
this.mzmineIcon = ImageIO.read(mzmineIconStream);
mzmineIconStream.close();
setIconImage(mzmineIcon);
} catch (Throwable e) {
e.printStackTrace();
logger.log(Level.WARNING, "Could not set application icon", e);
}
DesktopSetup desktopSetup = new DesktopSetup();
desktopSetup.init();
setLayout(new BorderLayout());
mainPanel = new MainPanel();
add(mainPanel, BorderLayout.CENTER);
statusBar = new StatusBar();
add(statusBar, BorderLayout.SOUTH);
// Construct menu
menuBar = new MainMenu();
setJMenuBar(menuBar);
// Initialize window listener for responding to user events
addWindowListener(this);
pack();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
// Set initial window size to 1000x700 pixels, but check the screen size
// first
int width = Math.min(screenSize.width, 1000);
int height = Math.min(screenSize.height, 700);
setBounds(0, 0, width, height);
setLocationRelativeTo(null);
// Application wants to control closing by itself
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
updateTitle();
// get the window settings parameter
ParameterSet paramSet = MZmineCore.getConfiguration().getPreferences();
WindowSettingsParameter settings = paramSet.getParameter(MZminePreferences.windowSetttings);
// listen for changes
this.addComponentListener(settings);
}
use of java.awt.Toolkit in project freeplane by freeplane.
the class UITools method getDesktopBounds.
public static Rectangle getDesktopBounds(Component frame) {
final Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
final Insets screenInsets = defaultToolkit.getScreenInsets(frame.getGraphicsConfiguration());
final Dimension screenSize = defaultToolkit.getScreenSize();
final int screenWidth = screenSize.width - screenInsets.left - screenInsets.right;
final int screenHeight = screenSize.height - screenInsets.top - screenInsets.bottom;
return new Rectangle(screenInsets.left, screenInsets.top, screenWidth, screenHeight);
}
Aggregations