关键词: HSQL DB, Eclipse 3.1, Apache Commons, Swing Hacks
16:59 2005-7-23
在HSQL DB里,一个Database由四个文件组成:(如数据库test)
test.properties
test.script
test.log
test.data
test.backup
propertiest文件定义数据库的基本设置;
script包含数据库表和数据库对象的定义,还有non-cached tables的数据;
log包含最近对数据库进行的操作;
data包含被缓存表(cached tables)
HSqlDB的JDBC方法分为:
连接相关的方法
元数据方法
数据库访问方法
用Hsql建立数据库:
在一个项目里执行建立数据库的代码,生成的数据库在Workspace对应的项目文件夹下;
而在一个项目里调用另一个项目的生成数据库的方法,生成的数据库在Eclipse Home文件夹下
Indicate things are happening in the view –only through jobs
***getSite().getAdapter(IWorkbenchSiteProgressService.class)***
Eclipse3.1的一些新特性:
Open Untitled File
A text editor can be opened without creating a file first.
Simply go to File > New > Untitled Text File.
Text编辑器也开始支持超链接了,按住Ctrl键,将鼠标放在URL的上面就可以了
我以前写过一篇制作和使用库插件的文章,制作库插件得花一点时间,但在3.1里做就非常方便了,
可以直接将第三方库转换为库插件:
Create a plug-in from existing JAR
PDE now provides a wizard that creates a plug-in from existing JAR archives.
This wizard is ideal if you would like to package third-party non-Eclipse JARs as an
Eclipse plug-in.
The wizard can be invoked via File > New > Project > Plug-in from existing JAR archives.
Java SE6(Mustang)要提供中文的Doc了,尽管用英文的Doc已经习惯了,但对于大多数程序员来说
也是一件好事啊。呵呵(见blog图Excellence)
18:03 2005-8-3
Apache Commons Lang中的一些方法
首字母大写打印字符串:StringUtils.capitalize(string);
打印布尔值,用Yes或No表示:BooleanUtils.toStringYesNo(true);
求一个数值数组中的最大值: NumberUtils.max(array);
打印数组:ArrayUtils.toString(array);
测试数值是否在某一范围:
Range range = new DoubleRange(90,120);
range.containsDouble(102.5);
随机数:RandomUtils.nextInt(100);
测试字符串是否为数值:NumberUtils.isNumber(string/*eg. 0x3F*/);
String的split方法有时会得到意外的结果:
"aaa|bbb|ccc".split("|") 结果:{,a,a,a,}
用"aaa|bbb|ccc".split("\\|")才能得到正确结果,*和+也是如此
6:58 2005-8-6
w.k. Eclipse3.1垃圾回收后只占18M内存,我现在可以一直开着Eclipse了,呵呵
11:19 2005-8-7
找出Java反编译利器DJ,打算破解IDEA。
9:09 2005-8-8
晕,发现Eclipse的帮助不能显示了,显示找不着org.eclipse.help.internal.webapp.data包,
找到webapp的插件目录,发现里面的web-inf目录是小写的,里面lib目录包含的servlet.jar
刚好包括了org.eclipse.help.internal.webapp.data包,可以肯定是web-inf目录小写的缘故,
但为什么会变成小写的呢,我的D盘数据通过ghost从俱乐部的机器上拷过来的,以前好像听说过
一些软件不支持大小写,不出意外的话,就是ghost帮我改的咯。
16:00 2005-8-10
看一个项目的源代码时,如果出现字符方面的错误,有可能是Encoding没有设置好,
看看Readme要求怎么设(一般要设为UTF-8)
19:30 2005-8-11
运行程序和浏览URL(包括mailto:):
/** Launch default browser on Windows */
if (GlobalSettings.isWindows())
{
Program.launch(localHref);
}
19:38 2005-8-11
mailto:?body=TheEmailBody&subject=TheSubject
15:14 2005-8-12
将Shell最小化:shell.setMinimized(true);
18:19 2005-8-18
JDK5.0文档,CHM版本的:
http://www.matrix.org.cn/resource/upload/content/2005_07_30_191519_vorbArhhNZ.chm
22:47 2005-8-25
Get Large File Icons
Not to leave Windows lonely, here is an undocumented class that will let you obtain large desktop icons and other file information. The FileSystemView only provides access to file icons of a "default" size, which usually means 16 by 16 pixels. If you look at your operating system desktop, however, you may see icons that are much bigger, with more detail. There is no standardized way of getting to the larger icons, but on Windows you can use the hidden class called sun.awt.shell.ShellFolder to retrieve larger (32 by 32) desktop file icons. This class is only available in Sun's JVM, so it won't work with other vendors, or on other platforms.
The code below will take a filename and show the file's large icon in a window.
public class LargeIconTest {
public static void main(String[] args) throws Exception {
// Create a File instance of an existing file
File file = new File(args[0]);
// Get metadata and create an icon
sun.awt.shell.ShellFolder sf =
sun.awt.shell.ShellFolder.getShellFolder(file);
Icon icon = new ImageIcon(sf.getIcon(true));
System.out.println("type = " + sf.getFolderType());
// show the icon
JLabel label = new JLabel(icon);
JFrame frame = new JFrame();
frame.getContentPane().add(label);
frame.pack();
frame.show();
}
}
ShellFolder is a wrapper for the metadata of the selected file. From this object, you can retrieve both the icon and a text description of the file's type. If you run this on an MP3 file, it might print the string "type = MPEG Layer 3 Audio" and show a 32 by 32 pixel iTunes MP3 icon.
Change the Look and Feel of an App from the Command Line
Sometimes, Swing applications don't provide a way to change a look and feel at runtime. When using an application like this, you can override the default look and feel with your own setting from the command line using the swing.defaultlaf property.
java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel
myapp.MainClass
You can also use this technique to apply a new look and feel that the original developer never thought of.
Hacks for the Metal Look and Feel
There are a variety of undocumented properties that control the look of Metal, Swing's cross-platform look and feel. JTree nodes can have lines connecting children to their parent, but depending on your current setup, the lines may or may not be showing. You can control the lines with a client property called JTree.lineStyle. Add this code after you create your JTree.
// show the lines in a JTree
tree.putClientProperty("JTree.lineStyle", "Angled");
// hide the lines in a jtree
tree.putClientProperty("JTree.lineStyle", "None");
One of the big complaints about Metal is that the menus and labels use bold fonts. With another quick undocumented system property, you can turn that off.
java -Dswing.boldMetal=false myapp.MainClass
You can also turn on the rollover for JToolBar buttons by using a secret property. A rollover is useful because it gives the user visual feedback that the mouse cursor is over the right place. Given the size of the typical toolbar button, this feedback is essential.
toolbar.putClientProperty("JToolBar.isRollover",Boolean.TRUE);
There is a longer (though, by no means comprehensive) list of properties on this wiki page. Swing, and Metal in particular, has lots of undocumented system properties. As you discover them, please add your own comments to the wiki page. Also remember that these are undocumented for a reason, and could easily change or go away in the future. Use them at your own risk.
Conclusion
Swing is a powerful toolkit with lots of hidden features that you can use to bring out the best in your application. This article documents just a few interesting techniques. Swing Hacks from O'Reilly covers another 100 hacks to improve your software. None of the techniques I've shown are required features, but they can add a level of polish that will make your apps stand out from the rest. And in a crowded software marketplace, anything that makes your program better than the competition is a good thing.