2008年11月27日星期四

Swing 的 Validate, Invalidate, Revalidate

Validate/Invalidate/Revalidate in Swing

Class Hierarchy

Component.invalidate():
Invalidates this component. This component and all parents above it are marked as needing to be laid out.





Component.validate()
Ensures that this component has a valid layout. This method is primarily intended to operate on instances of Container





Container.validate()
Validates this container and all of its subcomponents.
The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed.
Set valid=true and call Container.validateTree().
Container.validateTree() will call all its sub containers’ validateTree() recursively, so all sub components’ Component.validate() method will be called.



Container.validateTree()





Container.invalidate()
Basically do the same thing as super class Component.invalidate except for notifying the layout manager the changes, since the major difference between Component and Container is that Container can contains objects with layout manager.
LayoutManager2.invalidate() will discard the cached size information about the layout, so next time the layout will be re-calculated.



Conclusion on validate/invalidate
Invalidate() causes the component hierarchy to be marked as needing to be laid out again, and the validate() causes that to be done. It may be expensive, but is a way of getting the peers to recalculate size and to do what is needed to bring the display up to date. It has limitations: it doesn't cause an immediate screen update when invoked from an event handler, where paintImmediately() does.

JComponent.revalidate()
Supports deferred automatic layout.
Calls invalidate and then adds this component's validateRoot to a list of components that need to be validated. Validation will occur after all currently pending events have been dispatched. In other words after this method is called, the first validateRoot (if any) found when walking up the containment hierarchy of this component will be validated. By default, JRootPane, JScrollPane, and JTextField return true from isValidateRoot.



Conclusion on revalidate
This method will automatically be called on this component when a property value changes such that size, location, or internal layout of this component has been affected. This automatic updating differs from the AWT because programs generally no longer need to invoke validate to get the contents of the GUI to update. Because RepaintManger.addInvalidComponent() will validate them.

2008年11月24日星期一

OpenSSL转换PEM(Base64 DER)格式到PFX(PKCS12)格式

Convert PEM (Base64 DER) key pair into PFX (PKCS12)

C:\>openssl pkcs12 -export -in ca.cer -inkey ca.pem -out ca.pfx
Loading 'screen' into random state - done
Enter pass phrase for ca.pem:
Enter Export Password:
Verifying - Enter Export Password:

签名试一下
C:\>signtool sign /f ca.pfx /p password test.js
Done Adding Additional Store
Successfully signed: test.js

导入到JKS格式试一下
C:\Temp>keytool -importkeystore -srckeystore ca.pfx -srcstoretype PKCS12 -destkeystore ca.jks
Enter destination keystore password:
Re-enter new password:
Enter source keystore password:
Entry for alias 1 successfully imported.
Import command completed: 1 entries successfully imported, 0 entries failed or cancelled

2008年11月13日星期四

添加JarFinder.com按钮到google bar

如果你的项目没有Maven2那么classNotFound可能经常会遇到,推荐一个网站jarfinder.com

你可以把JarFinder作为一个google bar的search按钮。只要随便添加一个google按钮,然后选择编辑,use the advanced editor (关于google bar 的教程请访问 http://toolbar.google.com/buttons/apis)

<?xml version="1.0" encoding="UTF-8"?>
<custombuttons xmlns="http://toolbar.google.com/custombuttons/">
<button>
<search method="get">http://www.jarfinder.com/index.php/java/search/~{query}~</search>
<site>http://www.jarfinder.com</site>
<title>JarFinder</title>
<icon type="image/x-icon" mode="base64">
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABGdBTUEAAK/INwWK6QAAABl0RVh0
U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAaHSURBVEhLdZULUFTnGYYPN7Xaqk2T1kmn
ztTpxIypGKgm02hjRDPVDDadXGqqsZXmAqJogEQNUoGCjYpiFBI02gIhXI2AAUyCARHkIiKSEhRY
ri6wsO4FlsvCwvL0OwvWxNgz885/zn/Oed/v+n9OyNXV1aWMjY0pzs7Oyr3XBIoyZFMUV2eUh384
qtgnFKV7cLqC4qTMmqYozk7f+0URSgfmz5+vKP39/Xh6egqNgqur6//g5Owqe5NY+pBC0BMKl997
hK/Cf8VWD4XHfyIaU+8Vp7v/qRwq17Rp02hvb0exWCx4eHg4Nu/FdiFKXKvQmv4C6D7D0HoO+0A5
dGfRnPJHktYpBHgquN3nXycnp7sCjy1Z6iB/UDxfvUAhN2A2I2lLsbccFk97BPWCr6nMCpG1SlAh
aBD0Ym+OxpK6jNJ3ZvP8IoVf/OiOoa4i0IFi7rfw+vrf8PaTCtejH8H21Z8ZqQnD1vMpg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6mr68f
g8FER0cn5eVlmCRvw/K+tcPEqeN+Uhz7wRwtJ4E04ciHWG8fw2f5A9/1YHR0lJ6eHvR6vRD2OYhV
0aGhIcwSxt5eg3igo0QsDw4OJiIinNraJk7F+8OY9Mew9MeolDCJWPXx/PWp+wio5GqYBgYGUAUn
JiYcqyqg1xtkMOkoLCwiMjKS+voGfLZs41ZbJExIV9v/LeQfC1IY609my4qfotG0TOZADdG9HqjW
q3uqJ98WKC0tIykpmY0bNzFkOSqE0uEOqIWSLvFP5ub5N3hxyRyaW+WoUAXS09MdSdbpdI4wGY1G
1EmnDiN1NRiMsq+XEHVx4UIxu3e/KcLxQpgtOI/dlkTj50GcO7COLct+zOJZCnNnutHaJgIqgSqg
XgaDAa1W60i2eq8KqSFTn7u7Vei4dKmC+NNSMZQw1HWEwoPeHHhpIYsecGHmtyabs4urFIUMHJVo
/fo/cPJkgkygNrG010FqlkpSk62uRqNB9kw0NrUQd/wEkQFreHfVz/j1jO+P2Ttj183NbVJAtXLe
vHm4uLjg7u6Jl9caNm/ejL+/Pzt2vIWvrx8bNrzC8uW/Y9FjS/j53GnfsfR+s/zOnkajQRkfH5fm
uSjdfFbOoAzSpInUkKn3mZmZjlV9VvfPnMkkKzuHc7l55OXnk/9/kJeXR05OjvSRlf8CR6xc66yG
aUcAAAAASUVORK5CYII=
</icon>
<description>JarFinder</description>
</button>
</custombuttons>

2008年11月11日星期二

免费杀毒软件AVG

最近被公司的Symantec Endpoint Protection折磨的实在不行了,在资源管理器里每打开一个文件夹都要延迟0.2秒左右,而卸载掉之后几乎没有任何延迟。对于普通用户来说这其实无所谓,但是对于我这样的开发人员,或者需要用QTab在资源管理器里经常大量文件操作的人来说,这种延迟实在是无法忍受,就算你禁止了SEP仍然速度非常慢。更气人的是,live Update的时候机器就像中毒一样,CPU两个核心占有率都保持50%以上,百般无奈,决定删之。回想当年Norton时代,Anti-Virus的运行效率多么令人敬佩,现在实在是失望。
找了一下免费的防病毒软件,综合对比了一下,觉得AVG的Basic版本比较适合我,免费而且轻量。
安装的时候我没有选择Link Scanner, E-Mail Scanner, Plugin for office, 因为我从来不轻易打开链接或者附件的,我需要的仅仅是文件系统实时保护。

装上之后感受了一下,资源管理器果然没有了延迟问题!估计查杀病毒的能力和功能肯定是不如SEP,但是对于我来说,够了。