Thursday, March 29, 2007

Java finalize function

Using peer classes and implementation pointers to call C++ classes from java using JNI seems to work out ok so far. Forget the finalize function I talked about in my last post though. Apparently sometimes the finalize function is called and sometimes the finalize function is not called. It's very unpredictable. This behavior was verified when I did some debugging. My finalize function never got called, so the implementation pointer I created in the JNI was never released.
Instead you need to specify a Java function in your peer class to release the memory in the JNI and explicitly call it yourself. For my java application, I have a JFrame to which I added a windowClosing action listener:

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
// call the destroy method of the Java peer class
peerclassname.destroy();

System.exit(0); //calling this method is a must
}
});


This function is automatically called when the JFrame exits. The destroy function in the peer class calls the JNI destroy function which releases the C++ pointer.



Tuesday, March 27, 2007

JNI, C++ object instantiation

So my next task is to create a java gui using a C++ library.
The library is pretty simple. There is one main class with a few supporting classes. The supporting classes are basically just structs which hold variables.
The first thing to be done is create a Java class similar to the main C++ class. This is called a peer class. The methods in the java class are native functions whose implementations will be done using the Java Native Interface (JNI).
In the java class constructor, a jni call to create the C++ class will need to be made. The java class will also need to override the finalize function in which it will have a jni call to delete the C++ class.
The java class also needs to contain a variable which will be used to contain the pointer to the C++ class.
Now my first problem: How do I implement the JNI function which creates the C++ class? If anyone knows the answer, feel free to leave me a comment.
According to this link, a reinterpret cast is involved.

C++ class:

#include "CPPObject.h"
#include


CppObject::CppObject(int aFoo) {
foo = aFoo;
}


void CppObject::printFoo() {
printf ("Value of foo is: %i\n", foo);
}

Java peer class:

public class CppObjectPeer {
static {
System.loadLibrary("cppobjects");
}
protected long ptr;
public CppObjectPeer(int aFoo) {
this.ptr = createCppObject(aFoo); //create object in native code
}
public void printFoo() {
printFoo(this.ptr); //print from native code
}
//native methods
private final native long createCppObject(int aFoo);
private native void printFoo(long ptr);
}


Jni implementations:

JNIEXPORT jlong JNICALL Java_CppObjectPeer_createCppObject
(JNIEnv *env, jobject obj, jint fooValue) {
CppObject *cppObj = new CppObject(fooValue);
return reinterpret_cast(cppObj);
}


JNIEXPORT void JNICALL Java_CppObjectPeer_printFoo
(JNIEnv *env, jobject obj, jlong ptr) {
CppObject *cppObj = reinterpret_cast(ptr);
cppObj->printFoo();
}


Well, it looks simple enough. Just not sure why the book: Essential Jni: Java Native Interface (Essential Java), by Rob Gordon doesn't use this technique. Is this a new technique?

The book uses a Registry class and a hash code function to store the pointer to the C++ object. This method seems like a lot of work for what I need. As an alternative, he suggests using get/setCID functions which call get/setLongField functions. The set functions requires an int val be passed in and I don't understand where the val comes from. I guess for now I'm going to try the reinterpret_cast method.
Stay tuned for how it works out.




Thursday, March 22, 2007

Sketsa 4.2

The SVG graphics editor Sketsa 4.2 has been released.
It includes the following updates:

- Add Dropper Tool
- Add Canvas PopupMenu
- Add Menu - File - Revert
- Small Text Tool improvement
- Some Optimisation
- Fix startup active TopComponent
- Fix DocumentLoader
- Fix some memory leak
- Other bug fixes and enhancements


You can download it here. In order to run Sketsa, you will need Java 1.5 installed.


Ultra Hot* SpywareBot: #1 AntiSpyware

Monday, March 19, 2007

AVG Anti-Virus, Anti-Spyware

My sister bought a new Dell desktop about 6 months ago. It came with free virus software for 6 months. 6 months is about over, so she was wondering where to get free unlimited virus software. I referred her to AVG Anti-Virus. I've been using it for a few months now and have had no problems with it. Daily updates are automatically done, so that's good.
I also use AVG's free Anti-Spyware software. Definitely a must have if you dowload and install files or even just surf the web.
Lots of MySpace profiles have comments about downloading profile watcher 2.0, which turns out to be spyware. You have to be careful, you just never know what you could be getting. The only place I trust to download programs from is download.com I've been using them for years without a problem.
Some of the best software is free.

Friday, March 16, 2007

Use C++ to pass a function a base class and return a derived class, user defined variables

Sorry I haven't had any new apache batik/svg updates.
I'm into some C++ work now and haven't had time to work on it.
Pointers, I hate them, definitely a pain in the butt.
I searched all day on the internet and couldn't find any examples showing me how to do what I wanted. I finally took a look at some old third party code I have & figured out what I needed.
So here's a rundown of what I was trying to do and what I figured out.
I have a base class A with an int x.
I have a bunch of derived classes of A, each with their own set of variables.
Let's work with derived class B, which has a double i.
I have a function which accepts an A and sets an array of user defined variables for each derived class.
The array type is a struct, part of which is a union made up of pointers to each derived class.
class A
{
int x;
}

class B : public A
{
double i;
}

union P
{
B* b;
.
.
.
.
}

struct Row
{
int status;
P p;
}

Row values[2];

void setInfo( int index, A* _a )
{
// just for this example, i know _a is a B
values[index].p.b = static_cast(B*)(_a);
}

I call setInfo like this:
B* b1 = new B( 4, 5.2 ); // 4 gets passed to base class A, so x = 4, i = 5.2
BTW setInfo lives in another class c, so
c->setInfo( 0, b1 );

Ok. Now I want a get function to return B, but I need it returned in the parameter list, not the easy way by using the function return value. The reason for this is in my real work, I have multiple values which need to be returned.
So here's what my get function looks like:

getInfo( int index, A& _a )
{
// just for this example, i know _a is a B
(static_cast(A&)(_a)) = (*values[index].p.b);
}

I call getInfo like this:
B b2;
c->getInfo( 0, b2 );


Beautiful.

So this is how I pass a function multiple base class parameters and return multiple derived class parameters containing user defined variables. Easy enough I guess. I still hate pointers though.


Error Doctor 2007 ***Brand New 2007 Version

Tuesday, March 13, 2007

Firefox, FasterFox, Firetune, Maxthon

Firefox is a pretty popular browser, but I've just never been able to use it. I only have a dial up connection and Firefox just goes too slow & sometimes it times out before it even loads the page. I did install FasterFox. It is a plug in designed to load webpages faster. I guess it makes a difference, but pages still tend to not load. The other day I came across another Firefox plug in designed to load pages faster. This one is called FireTune. I installed it and so far it does seem to have made a difference. I haven't had a page not load yet. The page loading speed is better than it was too. I'm probably still not going to use Firefox full time though.
It's just not as fast as the browser I currently use, Maxthon. Maxthon is based on the Internet Explorer browser engine, but has more features such as:

Tabbed Browsing Interface
Mouse Gestures
Super Drag&Drop
Privacy Protection
AD Hunter
RSS Reader
IE Extensions Support
External Utility Bar
Skinning

On the downside, Maxthon does have a tendency to crash once in a while.
On the plus side, the tabbed browsing alone makes it worth the switch, not to mention the faster page loading. Maxthon is free, so if you're looking for a different browser, you might want to give this one a try.




Registry Cleaner And Optimizer

Saturday, March 10, 2007

Winamp

Well, if you took my advice and checked out Limewire, then you may need a media player. Windows comes preloaded with the Windows MediaPlayer. News Year Eve was the first time I actually used it in a few years. I was really surprised. It's come a long ways. You can create libraries, do sorting. A decent little app.
The reason for my non use of the Windows MediaPlayer, is because years ago I was turned onto another media player by a former coworker. What is this media player?
Winamp. It's very cool. It appears to be able to do all the things Windows MediaPlayer does and more. The part I like the best is you can change the skins. There are some really cool ones available.
Winamp can be broken down into 5 different sections.

Main Window:

Winamp 5 features our new Modern Skin that's easier to use and more powerful than ever
Easily access the Media Library (ML), Playlist Editor (PL), integrated Video or Visualizations (Video/Vis Drawer), or the EQ, Skin Options, and Color Themes (Config Drawer) from the Main Window
Includes over 50 color themes that suit nearly every mood or occasion!
Winamp 5 carries forward the unobtrusive "Window Shade"



Playlist Editor:

Drag and drop media directly into a Playlist from Windows Explorer or the Media Library
Jump directly to an item within the list by double clicking it or selecting the item and press Enter
Sort Playlists by title, file name, or path and file name
Easily Open and Save Playlists from the Manage Playlist button



Library:

Organize and find your favorite songs and videos in ONE place
Rip your favorite music CDs into AAC or MP3 (Ripping limited to 2x speeds for free users. MP3 encoding is only available in Winamp Pro)
Burn your favorite music compilations to CD (limited to 2x for free users)
Media Library "Views" allow you to easily create rule based lists of your media
Easily modify your music collections tags (Artist, Album, Song name, etc.)
Internet Radio and TV
Easily tune into user created Internet TV and Radio stations
Over 4000 Internet Radio stations and 40 Internet TV channels to choose from
Bookmark your favorite stations and channels for future access
Winamp Now Playing
View album art, artist biographies, discographies
Keep track of your favorite artists by browsing fan sites and news articles presented in the client
Easily buy your favorite CDs, memorabilia, or just sell your own



Video:

Play many major video formats (NSV, WMV, MPG, etc.) with ease
Easily resize video playback using the 1x, 2x, and Maximize window buttons
Watch your favorite videos in Full Screen mode
Quick access to dozens of Internet TV stations created by users
Detach the video window from the main player



Visualizer:

Winamp 5 comes bundled with the latest version of the ground breaking AVS (Advanced Visualization Studio) and Milkdrop visualizers
Enjoy over 100 bundled visualization presets created by users
Switch between presets manually or sit back and watch your presets on Random
Easily jump to Full Screen mode
Download new visualizations and presets from Winamp.com



Equalizer:

Shift the sound from both speakers to left or right using the Balance slider
Enable Cross Fading to transition the audio smoothly from one song to another
Select from the dozens of EQ presets to tune the sound
Create your own EQ settings and save them for future use


Version 5.33 has just been released. Did I mention you get this media player with all these features for free? Yup, Winamp is a free download, so check it out.

BTW, there is a pro version with even more features:

Unrestricted CD Burning

Winamp Pro enables you to burn your favorite music compilations at your computer's full potential. Once registered, Winamp Pro will allow you to burn your CDs at speeds up to 48x, 9 times the speed of Winamp 5! (Actual speeds may differ, depending on your computer's specifications.)



MP3 Encoding

With Winamp Pro, you can rip all your favorite music CDs into the industry leading MP3 format. When all your songs are encoded in MP3, it provides you the freedom to play them in all MP3 capable hardware and software media players.



Unrestricted CD Ripping

Buying Winamp Pro enables you to convert all of your favorite music CDs into digital files at your computer's maximum potential. Once registered, Winamp Pro can rip your CDs at speeds up to 48x, 9 times the speed of Winamp 5! (Actual speeds may differ, depending on your computer's specifications.)

Noadware.net - Spyware/Adware Remover

Wednesday, March 7, 2007

Askville

Amazon has just launched a new website called Askville.

"Askville is a place where you can ask any question on any topic and get real answers from real people. It’s a fun place to meet others with similar interests to you and a place where you can share what you know. You can learn something new everyday or help and meet others using your knowledge. It's new, and best of all, it's free!"

Lots of different categories with some good questions.


Sunday, March 4, 2007

Daylight Savings Time

Daylight savings time is 3 weeks early this year, March 11, and will last a week later, November 4. You know what that means? Potential computer problems, that's what. It could also affect VCR's, TiVo, Mac's & Windows PCs. Good news for Windows PCs. There is an update available. For Windows, go to: support.microsoft.com/kb/928388. Recently purchased Macs, should already have been updated. For all other devices, you will probably have to adjust the time manually. See the product website or manual for device specific info.
BTW, "this extra month of daylight is supposed to save energy by shifting the warmer part of the day an hour later".


Thursday, March 1, 2007

Limewire

Downloading free music. Yup, it's illegal, but people still do it. Once in a blue moon, I will download a song. New Year's Eve I was introduced to a file sharing application I had never heard of called Limewire. I tried it out & it works good. There is a free version & a paid version. I used the free version and was able to download songs relatively quickly, despite my dial up connection. You can also download other types of media, such as videos. It is also open source. Limewire contains the following features:

NO BUNDLED SOFTWARE OF ANY KIND!
No spyware. No adware. Guaranteed.
Firewall to Firewall Transfers.
Since about 60% of users are currently firewalled, this feature greatly increases the amount of content on the network.
Faster network connections.
Using new "UDP Host Caches", LimeWire starts up and connects faster then ever before!
Universal Plug 'N Play.
UPnP support allows LimeWire to find more search results and have faster downloads.
iTunes Integration.
Windows users can now take advantage of LimeWire's iTunes integration.
Creative Commons Integration.
LimeWire now recognizes OGGs and MP3s licensed under a Creative Commons License.
"What's New?" feature.
Users can browse the network for the most recent content additions.
Search drill down results.
Searches in LimeWire now immediately display the artists, albums and other information that fully describes files.
Proxy support.
Users can now use web proxies to route their downloads to protect their identity.
Support for International searches and International groups.
Users can now search in any language, and LimeWire ensures that a user will be connected to other users with their own language to aide international users to receive search results in their native language and to find content from sources that are close to home.
LimeWire still has the following great features:
Ease of use. Just install, run, and search.
Ability to search by artist, title, genre, or other meta-information.
Elegant multiple search tabbed interface.
"Swarm" downloads from multiple hosts help you get files faster.
iTunes integration for Mac users.

Unique "ultrapeer" technology reduces bandwidth requirements for most users.
Integrated chat.
Browse host feature. Even works through firewalls.
Added Bitzi metadata lookup.
International versions: Now available in many new languages.
Connects to the network using GWebCache, a distributed connection system.
Automatic local network searches for lightning-fast downloads. If you're on a corporate or university network, download files from other users on the same network almost instantaneously!
Support for MAGNET links that allow you to click on web page links that access Gnutella.