提交 f9198a75 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 91eb57ed
...@@ -26,10 +26,13 @@ import java.awt.event.MouseListener; ...@@ -26,10 +26,13 @@ import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
//#endif //#endif
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.constant.SysProperties;
import org.h2.server.ShutdownHandler; import org.h2.server.ShutdownHandler;
import org.h2.util.StartBrowser; import org.h2.util.StartBrowser;
...@@ -46,11 +49,12 @@ ShutdownHandler { ...@@ -46,11 +49,12 @@ ShutdownHandler {
//#ifdef AWT //#ifdef AWT
private Font font; private Font font;
private Image icon; private Image icon16, icon24;
private Frame frame; private Frame frame;
//#endif //#endif
private static final int EXIT_ERROR = 1; private static final int EXIT_ERROR = 1;
private Server web, tcp, pg; private Server web, tcp, pg;
private boolean isWindows;
/** /**
* The command line interface for this tool. * The command line interface for this tool.
...@@ -69,6 +73,7 @@ ShutdownHandler { ...@@ -69,6 +73,7 @@ ShutdownHandler {
} }
private int run(String[] args) { private int run(String[] args) {
isWindows = SysProperties.getStringSetting("os.name", "").startsWith("Windows");
int exitCode = 0; int exitCode = 0;
try { try {
web = Server.createWebServer(args); web = Server.createWebServer(args);
...@@ -103,13 +108,14 @@ ShutdownHandler { ...@@ -103,13 +108,14 @@ ShutdownHandler {
} }
//#ifdef AWT //#ifdef AWT
if (!GraphicsEnvironment.isHeadless()) { if (!GraphicsEnvironment.isHeadless()) {
font = new Font("Dialog", Font.PLAIN, 11); if (isWindows) {
font = new Font("Dialog", Font.PLAIN, 11);
} else {
font = new Font("Dialog", Font.PLAIN, 12);
}
try { try {
InputStream in = Console.class.getResourceAsStream("/org/h2/res/h2.png"); icon16 = loadImage("/org/h2/res/h2.png");
if (in != null) { icon24 = loadImage("/org/h2/res/h2b.png");
byte[] imageData = IOUtils.readBytesAndClose(in, -1);
icon = Toolkit.getDefaultToolkit().createImage(imageData);
}
if (!createTrayIcon()) { if (!createTrayIcon()) {
showWindow(true); showWindow(true);
} }
...@@ -129,6 +135,15 @@ ShutdownHandler { ...@@ -129,6 +135,15 @@ ShutdownHandler {
return exitCode; return exitCode;
} }
private Image loadImage(String name) throws IOException {
InputStream in = Console.class.getResourceAsStream(name);
if (in != null) {
byte[] imageData = IOUtils.readBytesAndClose(in, -1);
return Toolkit.getDefaultToolkit().createImage(imageData);
}
return null;
}
/** /**
* INTERNAL * INTERNAL
*/ */
...@@ -187,16 +202,23 @@ ShutdownHandler { ...@@ -187,16 +202,23 @@ ShutdownHandler {
itemExit.addActionListener(this); itemExit.addActionListener(this);
menuConsole.add(itemExit); menuConsole.add(itemExit);
// TrayIcon icon = new TrayIcon(image, "H2 Database Engine", menuConsole);
Object trayIcon = Class.forName("java.awt.TrayIcon").
getConstructor(new Class[] { Image.class, String.class, PopupMenu.class }).
newInstance(new Object[] { icon, "H2 Database Engine", menuConsole });
// SystemTray tray = SystemTray.getSystemTray(); // SystemTray tray = SystemTray.getSystemTray();
Object tray = Class.forName("java.awt.SystemTray"). Object tray = Class.forName("java.awt.SystemTray").
getMethod("getSystemTray", new Class[0]). getMethod("getSystemTray", new Class[0]).
invoke(null, new Object[0]); invoke(null, new Object[0]);
// Dimension d = tray.getTrayIconSize();
Dimension d = (Dimension) Class.forName("java.awt.SystemTray").
getMethod("getTrayIconSize", new Class[0]).
invoke(tray, new Object[0]);
Image icon = (d.width >= 24 && d.height >= 24) ? icon24 : icon16;
// TrayIcon icon = new TrayIcon(image, "H2 Database Engine", menuConsole);
Object trayIcon = Class.forName("java.awt.TrayIcon").
getConstructor(new Class[] { Image.class, String.class, PopupMenu.class }).
newInstance(new Object[] { icon, "H2 Database Engine", menuConsole });
// trayIcon.addMouseListener(this); // trayIcon.addMouseListener(this);
trayIcon.getClass(). trayIcon.getClass().
getMethod("addMouseListener", new Class[]{MouseListener.class}). getMethod("addMouseListener", new Class[]{MouseListener.class}).
...@@ -224,8 +246,8 @@ ShutdownHandler { ...@@ -224,8 +246,8 @@ ShutdownHandler {
} }
} }
}); });
if (icon != null) { if (icon16 != null) {
frame.setIconImage(icon); frame.setIconImage(icon16);
} }
frame.setResizable(false); frame.setResizable(false);
frame.setBackground(SystemColor.control); frame.setBackground(SystemColor.control);
...@@ -250,7 +272,9 @@ ShutdownHandler { ...@@ -250,7 +272,9 @@ ShutdownHandler {
text.setEditable(false); text.setEditable(false);
text.setFont(font); text.setFont(font);
text.setText(web.getURL()); text.setText(web.getURL());
text.setFocusable(false); if (isWindows) {
text.setFocusable(false);
}
c.anchor = GridBagConstraints.EAST; c.anchor = GridBagConstraints.EAST;
c.gridwidth = GridBagConstraints.REMAINDER; c.gridwidth = GridBagConstraints.REMAINDER;
frame.add(text, c); frame.add(text, c);
...@@ -269,7 +293,7 @@ ShutdownHandler { ...@@ -269,7 +293,7 @@ ShutdownHandler {
c.gridwidth = GridBagConstraints.REMAINDER; c.gridwidth = GridBagConstraints.REMAINDER;
frame.add(startBrowser, c); frame.add(startBrowser, c);
int width = 250, height = 120; int width = 300, height = 120;
frame.setSize(width, height); frame.setSize(width, height);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screenSize.width - width) / 2, (screenSize.height - height) / 2); frame.setLocation((screenSize.width - width) / 2, (screenSize.height - height) / 2);
......
...@@ -155,7 +155,11 @@ java org.h2.test.TestAll timer ...@@ -155,7 +155,11 @@ java org.h2.test.TestAll timer
/* /*
test startBrowser in Linux test startBrowser in Linux
larger H2 tray icon for ubuntu
Can not select URL
Strange font
fix or disable the linear hash index fix or disable the linear hash index
...@@ -165,8 +169,8 @@ link to new changelog and roadmap, remove pages from google groups ...@@ -165,8 +169,8 @@ link to new changelog and roadmap, remove pages from google groups
Can sometimes not delete log file? need test case Can sometimes not delete log file? need test case
History: History:
New function FILE_READ to read a file or from an URL. H2 Console: on Linux, Firefox is now started if available. This has been tested on Ubuntu.
Both binary and text data is supported.
Roadmap: Roadmap:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论