netbeans - matisse - convert panel to form
Friday, April 17, 2009
The Swing GUI editor in NetBeans is great. It has a number of samples to build from as well, one of which is the Master/Detail template. That's an example of one that generates a JPanel, and I wanted to convert to a JFrame. Here are the steps, assuming a form named NewForm (with NetBeans 6.5):
- In NewForm.java:
- Change extends JPanel to extends JFrame.
- Change the static void main.. method content to be:java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewForm().setVisible(true);
}
});
- In NewForm.form (may need to edit this outside of NetBeans):
- Change the type attribute of Form (near the top) from type="org.netbeans.modules.form.forminfo.JPanelFormInfo" to type="org.netbeans.modules.form.forminfo.JFrameFormInfo".
- In the graphical editor, select the Frame and choose the Code tab. Under Form Size Policy, change to Generate pack().
That should be it, good to go. May need to recompile, and/or open close the form to get NetBeans to recognise the changes.
checkpoint secureclient for mac
Thursday, April 09, 2009
It's great that CheckPoint has a SecureClient for the Mac. It works really well. What doesn't work, is making it stop.
There is no way to prevent it booting at startup. Oh, there are ways referred to by CheckPoint's docs, but as they say in the fine print, that just stops the gui from starting - any security policies (read: complete firewall lockdown) will still be in place. And if you do have the gui up and choose 'Stop VPN-1 SecureClient', again it's only the gui that goes, and you go mad like me having lost your svn, http, etc server, not knowing why. There are ways to control it via the command line which you could script, but your admins have to have allowed it to allow that via some centralised settings at their end.
So, if you do need SC, always launch the gui. If you need access to services on that box, then always choose 'Tools>Disable Security Policy' in SC. And if you don't need it anymore, then say goodbye to it, like I'm about to do.
use eclipse to autowrap an object
Tuesday, April 07, 2009
I'm sure there's a better design methodology to do this, but I have an issue in Java where the PostgreSQL JDBC driver can't execute createBlob() (in JDBC3 spec), so I want to overwrite its Connection. I can't subclass it, as it's returned from the call DriverManager.getConnection(...). So what I need to do is use the Wrapper design pattern, aka Decorator, aka Delegator. Oh wouldn't it be great to use via? But alas, until my cry is heard, or someone corrects me, the solution is to:
- Create a new class that also implements Connection.
- Use this class to wrap the obtained PostgreSQLConnection
- Painstakingly implement each and every method in Connection to pass through to the wrapped connection, except for the methods I want to meddle with.
- Pass out of my Connection-obtainer class, not the raw Connection, but my new wrapper.
- Accept resignedly that when the Connection interface changes, my Connection wrapper will now not fulfil the new interface and will break. Really good reason for via.
To fix all wrapped method calls that return a value:
In the new class, Ctrl-F to bring up the find/replace dialog. Make sure 'Wrap search' and 'Regular expression' are ticked, and 'Scope' is 'All', then copy and paste into Find:
This searches for any lines having the word public, not followed by class, and having a return statement.
Hit Find a few times to validate it's matching correctly.
Now, in Replace:
Takes the first match (\1) and appends the method call (\2) to the field name.
Click 'Replace All' to see it happen.
To fix the remaining method calls with no return value (ie void)
In Find:
Now, in Replace:
And 'Replace All' again.
As yet the above regex statements don't remove parameter types from the calling statements, so you will have to go through and remove them, but that should be relatively little work.
SQuirreL SQL
Thursday, March 19, 2009
For a long time I have been looking for an open source database management tool that would be able to access any JDBC compliant database. I've used the great Oracle product, SQLDeveloper, for a long time and found it great for SQL Server management (usually performing quicker than using Microsoft's own Management Studio!). But now I've started using Derby (aka JavaDB aka Cloudscape) and SQLDeveloper is limited to Oracle, SQL Server, and MySQL.
Step in SQuirreL SQL. It has a pretty smooth interface, with great features like SQL syntax highlighting and even code completion. Released under the LGPL license, it is open source and contributions are welcomed, particularly for plugins. The plugins are important as JDBC is obviously a restricted subset of a database's functionality - a number of the existing plugins enable extra features for specific database types (eg. Derby's triggers).
Another very notable plugin is called graph which enables production of simple entity relationship diagrams (ERD) from a database connection. While it doesn't display multiplicity indicators, and some of the image exporting is a bit clunky, it is great to have this functionality in an open source product. (I now use NetBeans' UML Modeling which is great for the common UML diagrams, but lacking ERDs).
secure svn server on osx tiger
Sunday, February 08, 2009
My notes to help remember the processes to get a secure svn server using Apache 2 on OS X Tiger. I know these are documented in lots of places, but it seemed that parts of various HowTos were required in order to do it with current Apache (2.2) and with Tiger. For anyone with Leopard onwards, you can skip the installation of Apache2 as this is now standard from Leopard on (Tiger and earlier used Apache 1.3 and earlier) and here is probably your best bet.
Edit: I drafted this a year ago and never finished (or published) it. Now the server has reverted back to apache1.3 after an update and my ssl cert had expired - time to revive the post! Unfortunately I didn't capture all the steps, especially the setting up of mods-enabled etc, but I'll just use my install as reference. Ask if you need those bits. Meantime, this link may be helpful. Brad.
Edit 2 (16/4/2009): It did it again. If svn access starts to fail, log in to a directory-displaying page or any page that gives the apache http server version - if it says 1.3 then it's reverted back from 2.0 (alternatively, if ls -l /usr/sbin/apachectl shows a single file rather than a symlink to /sw/sbin directory, that also is an indicator it's reverted). Easy fix is (after stopping 'Personal Web Sharing' in System Prefs): sudo ln -sf /sw/sbin/apache2ctl /usr/sbin/apachectl as below. Then start web sharing again; should now be 2.0 running.
Installing Apache httpd 2
1. Apache2 Installation
The bulk of this guide comes from Tim Fanelli's great howto (just the Fink, Apache2, Subversion, and WebDav steps for now). If you don't have XCode Tools installed prior to this, you can get them here (requires free registration). Extra notes to the sections in Tim's guide follow:
- Apache2: At the end of this section you can start up Apache2. Be sure to shut down the 1.3 WebServer first via the Sharing panel of SysPrefs, if it is running. You should then be able to view the Apache2 welcome screen by browsing to http://localhost. You probably won't be able to access this from another machine yet though (even within LAN) as the Mac's firewall won't be allowing it. We'll get to that later.
- Subversion: If you will be carrying this on to use svn, you might as well do this and the WebDAV steps now. You'll need svn-ssl, but may not require svn-client-ssl. I didn't install it.
2. Apache2 Configuration
Next we'll configure Apache2 to be handled by the Sharing panel of SysPrefs, instead of old 1.3.
- cd /usr/sbin
- mv apachectl apachectl1.3 {–> This renames default apache1.3/apachectl command}
- ln -s /sw/sbin/apache2ctl apachectl {–> This creates symlink for Apache2/apachectl command}
Edit /sw/etc/apache2/apache2.conf:
- Change the pidfile location to:/private/var/run/httpd.pid
- In order to easily view logs from Console, and to get free log rotation, change the ErrorLog parameter to:/var/log/httpd/error_log
- And add a new entry:CustomLog /var/log/httpd/access_log common
3. SSL Certificate
Go back to Tim's post and the SSL step. You'll want to follow the link and generate the certificate Important: Ensure you create a CommonName attribute in the certificate. If it is missing then many svn clients will fail to access the site. After doing that though, a couple of the commands given back in the main howto are wrong. Change sudo cp ~/server.key /sw/etc/apache2/ssl.key/ to sudo cp ~/sslcert/server.key /sw/etc/apache2/ssl.key/ and the same for .crt.
Edit (13/5/2009): Looks like Tim's blog is having some technical issues. Here are the ssl certificate creation and installation steps:
- cd /tmp
- openssl genrsa -des3 -out server.key {generates the key}
- openssl req -new -key server.key -out server.csr {generates a certificate-signing request (CSR; holds the information about the certificate) using the created key}
- openssl x509 -req [-days 365] server.csr -signkey server.key -out server.crt {generates the certificate, with information in the CSR, using our key. The bit in the square brackets is optional, and is if you want the certificate to expire.}
- sudo mv server.key /sw/etc/apache2/ssl.key/
- sudo mv server.crt /sw/etc/apache2/ssl.crt/
- sudo chmod 0400 /sw/etc/apache2/ssl.key/ {if server won't start later, try also: sudo chmod u+xw on this path}
- sudo chmod 0400 /sw/etc/apache2/ssl.crt/
For better security, don't do the decryption suggested. However, for
pragmatism and to be able to control the server via the SysPrefs, just
do it :)
mysql quick reference
Sunday, January 25, 2009
Launch mysqld (server) on Linux (if not already running):
sudo /etc/init.d/mysql start
Connect to server [specific database]:
mysql [-h host] -u user -p [dbname to use]
Use the SHOW statement to find out what databases currently exist on the server:
mysql> SHOW DATABASES;
Pick one:
mysql> USE dbname
Create new one:
mysql> CREATE DATABASE dbname;
List tables:
mysql> SHOW TABLES;
Create table:
mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
-> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
List tables columns:
mysql> DESCRIBE tablename;
Generate schema:
mysql> SHOW CREATE TABLE tablename;
use jndi with spring to access external properties file
Tuesday, January 13, 2009
On the surface, external configuration files in a JEE environment provide a simple mechanism to store environment-specific data, but they can be a pain to access. How to access it when file system access isn't allowed? Since it's outside the classpath, where is the file in each environment? If I'm using Spring, how do I access this movable file?
The best solution I've found is to use jndi resources. The following is a solution using Websphere (6) and Spring (2.01).
Step 1: Configure the jndi reference for Websphere
This step was based on information from IBM's page "Using URL resources to manage J2EE property files in IBM WebSphere Application Server V5", steps A and B. Websphere Studio isn't required, however, so briefly:
a) Navigate to Resources > URL > URLs and create a new URL. Make up a JNDI name starting with "url/". In 'specification', enter the path to the properties file as a URI, eg. "file:///E:/project.properties". So now Websphere has a URL Resource pointing to the properties file for this environment.
b) In the code, edit web.xml. Configure a new resource-ref as shown in IBM's figure 6. 'res-ref-name' is the jndi name we set up in a). Then in ibm-web-bnd.xmi, add a new resRefBindings as shown in IBM's figure 7.
That completes the configuration of Websphere and the jndi configuration in the code.
Step 2: Next Spring needs to be able to load the properties file by looking up the jndi location.
c) I'll assume that you want the properties file to be set as a property on a class 'pkg.MyClass'. To do this, we use a PropertyFactoryBean to convert from properties file to Properties class. The PropertyFactoryBean takes a Resource as location property, so we create a UrlResource bean for this, with the java.net.Url as constructor argument. This java.net.Url is the result of using a JndiObjectFactoryBean to look up the jndi name and return the Url object. The following bean config shows these conversions:
<bean class="myclass">
<property name="props">
<!-- Load from the .properties file-->
<bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<!-- Generate a UrlResource from the java.net.Url -->
<bean class="org.springframework.core.io.UrlResource">
<constructor-arg>
<!-- use jndi to look up the location of the parameters.properties file -->
<bean class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/url/analysisParametersURL" />
</bean>
</constructor-arg>
</bean>
</property>
</bean>
</property>
</bean>
And that's it. In summary, Spring looks up a jndi URL reference to a properties file, configured in the JEE server. Spring beans are created that convert the URL to a URLResource to a Properties object, available for injection into your custom class.
mobile phone as modem
Sunday, October 26, 2008
There are a number of posts around the place on getting gprs or 3g cellphone connections working on linux. I wasn't interested in bluetooth as I have limited batteries and a usb cable. And you don't always know what your locla settings should be.
Here's all I did on Xubuntu Hardy:
- Plug the phone into the computer using the usb cable.
- In a terminal, type "sudo wvdialconf". (This sets up available baud rates, etc)
- In a terminal, type "sudo vi /etc/wvdial.conf".
- Edit this file with:
- phone = [for my nokia on Vodafone New Zealand, the number is "*99#". I phoned them to find out.]
- name = [the login name, if your mobile company requires it. Vfone NZ doesn't, but wvdial needed something here. I used "name"].
- password = [as with name. I used "password"].
- Save and close the file.
- Connect to the internet via your mobile by typing "wvdial" in a terminal window.
- When done, press ctrl-c in that window.
java modulus for floating point numbers
Thursday, October 09, 2008
The java modulus (or remainder) operator (%) truncates instead of rounds with floating point numbers (ie float, double), so the solution is to use Math.IEEEremainder instead. It's fine to use % for ints.
linux tools
Monday, September 29, 2008
What I use on xubuntu linux for specific tasks:....
| Task | Tool | Date | Ubuntu Package | Comment |
|---|---|---|---|---|
| pdf annotating | flpsed | Sep 2008 | flpsed | Very basic app that enables load/save of ps and pdf. Multi-line text can be added to the docs. No highlighting option or editing of existing content. |
| pdf editing | pdfedit | Sep 2008 | pdfedit | Allows editing of any part of multi-page PDF documents. Can be very slow to use on long documents. New content such as highlighting and single-line text can be added also. |
| vector graphics / single-page pdf annotating | inkscape | Sep 2008 | inkscape | Great tool for vector graphics, quick and easy results. Can import a single page of PDF documents. |
| xml viewing / formatting | XML Copy Editor | Sep 2008 | xmlcopyeditor | Load and view xml. Validate form and against dtd etc, plus nicely format. Quick and easy. |
| diff | meld | Sep 2008 | meld | Excellent visual diff/merge tool. |
| text/source editor | SciTE | Sep 2008 | SciTE | Excellent text editor with awareness of many languages and markups. Tabbed view. |