2009年9月24日 星期四

set font for UI

ex:

Font font = label.getFont();
label.setFont(font.deriveFont(12f) );
label.setFont(font.deriveFont(font.getStyle() ^ Font.BOLD) );

UI alignment

TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT,

LEFT_ALIGNMENT, RIGHT_ALIGNMENT

ex:

testLabel.setAlignmentX(Component.CENTER_ALIGNMENT);


eclise problem in snow leopard when running java 1.6

error:
"java.lang.NoClassDefFoundError: apple/laf/CoreUIControl"

solution:
add /System/Library/Frameworks/JavaVM.framework/Versions/A/Frameworks/JavaRuntimeSupport.framework/Versions/A/Resources/Java/JavaRuntimeSupport.jar
to classpath of run configuration

enable root user in mac

open "Directory Utility"
click on Edit, click on "Enable root user"

2009年9月23日 星期三

java jtree

1. simple jtree example

public class SimpleTree extends JFrame {
public static void main(String[] args) {
new SimpleTree();
}

public SimpleTree() {
super("Creating a Simple JTree");

DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child 1");
root.add(child1);
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child 2");
root.add(child2);
JTree tree = new JTree(root);
getContentPane().add(new JScrollPane(tree));
setSize(275, 300);
setVisible(true);
}
}

show directory size

du -h -d 1
-d means directory depth

install mac os from dmg file

need 2 partitions, one for installer, one will be where you install os
1. open disk utility
2. click restore tab
3. drag dmg file in source field
4. drag the partition for installer in destination field
5. click erase destination
6. click restore
7. open system preference --> startup disk --> installer partiton
8. restart to install os

cp

-V: show info when coping files

driver extension

mac: .kext

linux: .ko

windows: .sys

2009年9月22日 星期二

call javascript function from html

test.html
<script src="test.js"></script>
<script language="JavaScript">
test();
</script>

test.js
function test() {
alert("test");
}

regular expression

+: {1, }
*: {0, }
?: { 0, 1}
^: beginning of input
$: end of input
\w: any alphanumerical character including _
\W: any non-word character
\d: any digit
\D: any non-digit
\s: any whitespace
\S: anything but whitespace

search rpm

http://rpm.pbone.net/

2009年9月21日 星期一

tar

unpack test.tar
tar -xvf test.tar

unpack an bz2 file

bunzip2 test.bz2

unpack an rpm

rpm2cpio HPDMmultipath-tools-4.1.0-SLES10.2.src.rpm | cpio -idmv

how to use a com object

obtain object's interface

Call QueryInterface to Request a New Interface:

Interface Definition Language (IDL)

Interface definition language (IDL) files are a structured way to define interfaces and objects.

ex:
[
object,
uuid(),
helpstring("IWDFObject Interface"),
local,
restricted,
pointer_default(unique)
]
interface IWDFObject : IUnknown
{

HRESULT
DeleteWdfObject(
void
);

HRESULT
AssignContext(
[in, unique, annotation("__in_opt")] IObjectCleanup * pCleanupCallback,
[in, unique, annotation("__in_opt")] void * pContext
);

HRESULT
RetrieveContext(
[out, annotation("__out")] void ** ppvContext
);

void
AcquireLock(
void
);

void
ReleaseLock(
void
);
};

Active Template Library (ATL)

a set of template-based C++ classes that are often used to simplify the creation of COM objects

HRESULT & com

a 32-bit type
three field:
(1) severity bit:
indicate success or error
(2) facility
(3) return code

success codes are assigned names that begin with S, such as S_OK
failure codes are assigned names that begin with E

use FAILED(hr) or SUCCEEDED(hr) to check success or failure

GUID & com

Globally unique identifiers (GUIDs)
1.Interface ID (IID)
a GUID that uniquely identifies a particular COM interface

2.Class ID (CLSID)
a GUID that uniquely identifies a particular COM object

com & interface

An interface is the COM mechanism for exposing public methods on an object

If an object exposes a standard interface, the object must implement every method in that interface.

A typical COM object exposes at least two and sometimes many interfaces.

IUnknown
IUnknown is the key COM interface. Every COM object must expose this interface

package windows driver

WDF driver package consists of the following components
1. driver binaries
2. either or both WDF co-installer
3. INF
a text file that contains directives that instruct Windows how to install the driver
use .inx file to create .inf files for different architecture

2009年9月20日 星期日

compile windows project

1. open a build environment window
start -> all programs -> windows driver kits -> wdk 7600.16385.0 -> build environments -> windows 7 -> x64 free build environment

2. In the project directory, two supporting files are needed
1. Makefile
2. sources
This file contains project-specific information that is used to build the driver, such as the list of source files.

options files:
Makefile.inc:
the directives for building the custom targets are placed in Makefile.inc. Makefile itself should never be modified.

.inx file:
An INX file is an architecture-independent INF file. When the appropriate instructions are specified, the Build utility uses the data in an INX file to produce an appropriate INF file for the project.

3. compile driver
in the project directory, type "build -g"
-g:Uses colored text to display warnings, errors, and summaries.
usually use "build -ceZ"
4. the file created from building
a output directory :
ex: objfre_wxp_x86\i386 for windows xp
objfre_wnet_x86\i386 for windows 2003
files in the directory:
(1) driver binary:
for KMDF, it is .sys file
for UMDF, it is .dll file
(2) object files for source file
(3)symbol file
.pdf file, for debugging

check out project(not created from xcode) from cvs in xcode

1. check out project Test
2. create new project Test
command line utility --> standard tool
this will add Test.xcodeproj in the Test directory
3. add all files in Test directory to Source of Test project
4. set project's SCM repository as CVS path

call java from native program

1. create Java VM
JavaVM *jvm = NULL;
JNIEnv *env = NULL;
JavaVMInitArgs vm_args;
JavaVMOption options[2];
args.nOptions = 2;
args.version = JNI_VERSION_1_6;
options[0].optionString = "-Xmx512m";
options[1].optionString ="-Djava.class.path=test.jar:test2.jar";
args.options = options;
#ifdef FOR_MAC_OS
setenv("JAVA_JVM_VERSION", "1.6",1);
#endif
JNI_CreateJavaVM(&jvm, (void **)&env, &args);

(2) get class & method of class
jclass aClass = (*env)->FindClass(env, "Test");
jmethodID aid = (*env)->GetStaticMethodID(env, aClass,"main","([Ljava/lang/String;)V");


(3) call method of class
jobjectArray applicationArgs;
jstring applicationArg0;
applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL);
applicationArg0 = (*env)->NewStringUTF(env, "Test");
(*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0);
(*env)->CallStaticVoidMethod(env, aClass, aid, applicationArgs);

pthread example

void *Test(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
pthread_t myThread;
int rc;
long t;
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&myThread, NULL, Test, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
pthread_exit(NULL);
}

2009年9月18日 星期五

PackageMaker

create install package for mac app

create java app on mac

use "Jar Bundler"

2009年9月17日 星期四

set working directory

1. for cocoa
[[NSFileManager defaultManager] changeCurrentDirectoryPath:@"/test"];

2. linux api ( also for mac)
chdir("/test");


man command

ex:
man 2 open
show man page for open section 2

let java menu bar replace app menu bar

method 1:
-Dcom.apple.macos.useScreenMenuBar="true"

method 2:
System.setProperty("com.apple.macos.useScreenMenuBar","true");

2009年9月16日 星期三

compile jni program on xcode

1. set header search path for app target from build panel:
/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Headers

2. add JavaVM.framework

java location in mac

/System/Library/Frameworks/JavaVM.framework

2009年9月15日 星期二

compile program with core foundation framework

gcc test.c -framework CoreFoundation -o test.o

show content of jar file

ex:
jar tvf test.jar

show file is 64 bit or 32 bits

ex:
file test.0
--> test.o: Mach-O universal binary with 2 architectures
test.o (for architecture x86_64): Mach-O 64-bit executable x86_64
test.o (for architecture i386): Mach-O executable i386

create x86_64 & i386 binary on mac

gcc -o test.o test.c -arch x86_64 -arch i386

compile JNI program on mac

gcc -o launch.o -I/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Headers -framework JavaVM launch.c -m64

java -cp

ex:
java -cp .:test.jar:test2.jar MyClass 16
main class is MyClass, argument for MyClass is 16