< prev index next >
test/java/awt/image/multiresolution/MultiResolutionTrayIconTest/MultiResolutionTrayIconTest.java
Print this page
@@ -24,10 +24,11 @@
/*
@test
@bug 8150176
@ignore 8150176
+
@summary Check if correct resolution variant is used for tray icon.
@author a.stepanov
@run applet/manual=yesno MultiResolutionTrayIconTest.html
*/
@@ -38,32 +39,39 @@
import java.awt.image.*;
public class MultiResolutionTrayIconTest extends Applet {
- private SystemTray tray;
- private TrayIcon icon, iconMRI;
+ private volatile SystemTray tray;
+ private volatile TrayIcon icon, iconMRI;
+ private Button b;
- public void init() { this.setLayout(new BorderLayout()); }
+ public void init() { this.setLayout(new GridLayout(1, 2)); }
public void start() {
boolean trayIsSupported = SystemTray.isSupported();
- Button b = new Button("Start");
+ tray = SystemTray.getSystemTray();
+ b = new Button("show icons");
+ Checkbox auto = new Checkbox("auto size", true);
if (trayIsSupported) {
prepareIcons();
+
b.addActionListener(new ActionListener() {
@Override
- public void actionPerformed(ActionEvent e) { doTest(); }
+ public void actionPerformed(ActionEvent e) {
+ doTest(auto.getState());
+ }
});
} else {
b.setLabel("not supported");
b.setEnabled(false);
System.out.println("system tray is not supported");
}
- add(b, BorderLayout.CENTER);
+ add(auto);
+ add(b);
validate();
setVisible(true);
}
@@ -79,11 +87,10 @@
return img;
}
private void prepareIcons() {
- tray = SystemTray.getSystemTray();
Dimension d = tray.getTrayIconSize();
int w = d.width, h = d.height;
BufferedImage img = generateImage(w, h, Color.BLUE);
// use wrong icon size for "nok"
@@ -92,25 +99,37 @@
new BaseMultiResolutionImage(new BufferedImage[] {nok, img});
icon = new TrayIcon(img);
iconMRI = new TrayIcon(mri);
}
- private void doTest() {
-
- if (tray.getTrayIcons().length > 0) { return; } // icons were added already
+ private void showIcons() {
try {
tray.add(icon);
tray.add(iconMRI);
+ b.setLabel("hide icons");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
- public void stop() {
+ private void removeIcons() {
// check for null, just in case
if (tray != null) {
tray.remove(icon);
tray.remove(iconMRI);
+ b.setLabel("show icons");
}
}
+
+ private void doTest(boolean autoSize) {
+
+ if (tray.getTrayIcons().length > 0) { // icons were added already
+ removeIcons();
+ } else {
+ iconMRI.setImageAutoSize(autoSize);
+ showIcons();
+ }
+ }
+
+ public void stop() { removeIcons(); }
}
< prev index next >