< prev index next >
test/java/awt/image/multiresolution/MultiResolutionTrayIconTest/MultiResolutionTrayIconTest.java
Print this page
*** 24,33 ****
--- 24,34 ----
/*
@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,69 ****
import java.awt.image.*;
public class MultiResolutionTrayIconTest extends Applet {
! private SystemTray tray;
! private TrayIcon icon, iconMRI;
! public void init() { this.setLayout(new BorderLayout()); }
public void start() {
boolean trayIsSupported = SystemTray.isSupported();
! Button b = new Button("Start");
if (trayIsSupported) {
prepareIcons();
b.addActionListener(new ActionListener() {
@Override
! public void actionPerformed(ActionEvent e) { doTest(); }
});
} else {
b.setLabel("not supported");
b.setEnabled(false);
System.out.println("system tray is not supported");
}
! add(b, BorderLayout.CENTER);
validate();
setVisible(true);
}
--- 39,77 ----
import java.awt.image.*;
public class MultiResolutionTrayIconTest extends Applet {
! private volatile SystemTray tray;
! private volatile TrayIcon icon, iconMRI;
! private Button b;
! public void init() { this.setLayout(new GridLayout(1, 2)); }
public void start() {
boolean trayIsSupported = SystemTray.isSupported();
! 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(auto.getState());
! }
});
} else {
b.setLabel("not supported");
b.setEnabled(false);
System.out.println("system tray is not supported");
}
! add(auto);
! add(b);
validate();
setVisible(true);
}
*** 79,89 ****
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"
--- 87,96 ----
*** 92,116 ****
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
try {
tray.add(icon);
tray.add(iconMRI);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
! public void stop() {
// check for null, just in case
if (tray != null) {
tray.remove(icon);
tray.remove(iconMRI);
}
}
}
--- 99,135 ----
new BaseMultiResolutionImage(new BufferedImage[] {nok, img});
icon = new TrayIcon(img);
iconMRI = new TrayIcon(mri);
}
! private void showIcons() {
try {
tray.add(icon);
tray.add(iconMRI);
+ b.setLabel("hide icons");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
! 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 >