Search

Dark theme | Light theme

December 25, 2008

VirtuaWin is my Virtual Desktop Manager for Windows

I like to have multiple virtual desktops. I put my e-mail application on one desktop and my development environment on the other. This way I can keep my window list for one desktop minimal. Otherwise I have to use Alt-TAB all the time to get to the correct window. With VirtuaWin I can have multiple desktops and switch to them with simple shortcuts, like Win+1 for desktop 1. Or Win+right arrow to get to the next desktop. VirtuaWin is very fast on my machine and therefore very useful.

December 19, 2008

Use regular expressions for search and replace in NetBeans

NetBeans supports regular expressions for searching and replacing text in the editor. In my last project I had to replace a bit of HTML code with an array. Here is the source HTML code:

<option value="/en/gb/overview.html">United Kingdom</option>
<option value="/en/us/overview.html">United States</option>
<option value="/en/ca/overview.html">Canada</option>
<option value="/nl/nl/overview.html">The Netherlands</option>
<option value="/nl/be/overview.html">Belgium (Dutch)</option>

And this needed to be changed to the following code:

locales["gb_en"] = "index_en_gb.html"
locales["us_en"] = "index_en_us.html"
locales["ca_en"] = "index_en_ca.html"
locales["nl_nl"] = "index_nl_nl.html"
locales["be_nl"] = "index_nl_be.html"

I started out by changing each line, but then I realized I was doing the same thing over and over again (the real list was much bigger than the one in this example). There must be a better way and in NetBeans there is!

We go to Edit | Replace. NetBeans shows the Replace dialog window. In the Find What field we type the following regular expression: ^<option value="/(.*)/(.*)/overview.html">.*</option>.  Notice we define 2 groups between the parenthesis. We use these in the Replace With field where we type locales["$2_$1"] = "index_$1_$2.html". We are almost done, we only must check Regular Expressions and click on the Replace All button.

December 16, 2008

Using QuickSearch to find options in NetBeans

The new QuickSearch function in NetBeans 6.5 also allows us to search for options from the Options dialog. Suppose we want to set formatting options we only have to type this in the QuickSearch field. NetBeans shows at the Options section the Formatting Options choice. We select this option and NetBeans will open the Options dialog window at the correct location.

Using QuickSearch to invoke actions in NetBeans

In NetBeans 6.5 we have a new feature: QuickSearch. With QuickSearch we can search in the Help system, but also search for actions and invoke them. The QuickSearch input field is at the top right of the NetBeans IDE. We can invoke it quickly with the shortcut key Ctrl+I in Windows.

Suppose we want to compile a Java source file we are working on. We can do this by using the shortcut key F9 or go to Run | Compile. Or we use QuickSearch and type compile. NetBeans shows the search results for compile and among them is the Compile File action. We can select the action from the list and execute it.

This is also a great way to learn about the NetBeans IDE without searching through all the menus.

December 15, 2008

Create a Groovy 1.5.7 script in NetBeans 6.5

In a previous post we saw how we can invoke a external process and how to use date ranges in Groovy 1.5.7. In this post we will write this little script using NetBeans 6.5. NetBeans has Groovy (and Grails) support. We will see how we can use the latest Groovy version, 1.5.7, to support our script.

Groovy support in NetBeans is coupled to Java projects. There is no special Groovy project or anything. So we start to create a new Java project. We go to File | New Project and select Java from the Categories and Java Application from the Projects:

We click the Next button and we can fill in a project name. For this example we fill in GroovyScripts. We can uncheck Create Main Class, because we only want this project to contains Groovy scripts. We can check or uncheck Set as Main Project depending if we want this project to be the main project for NetBeans:

We can now press the Finish button and NetBeans will create a new Java project for us. Now we can add a new Groovy script to the project. We go to File | New File and select Groovy from Categories and then select Groovy Script from the File Types:

We click on the Next button and we get a new dialog window. Here we can type the Class Name. We type curlrange for the class name. We must check Location is set to Source Packages:

Now we can press the Finish button. NetBeans creates a sample Groovy script file in our project. And NetBeans enables Groovy support for our Java project. Because we add a Groovy script file to the project NetBeans enables Groovy support automatically! The sample Groovy script file display a string on the output window when we run the file. We can run a Groovy script file via Run | Run File or the shortcut key Shift+F6 in Windows.

We copy the code from the previous post in the code editor of NetBeans, replacing the sample code NetBeans generated. We can run the Groovy script, but we get an error. NetBeans doesn't recognize the format method for a Date object. This is because NetBeans support Groovy 1.5.5 and the format method is added in Groovy 1.5.7. So we need to tell NetBeans to support Groovy 1.5.7.

We go to File | Project Properies (GroovyScripts) | Libraries. Here we see the default Groovy 1.5.5 library. We press the Remove button to delete this library from the project. Next we press the Add Library button. NetBeans opens a dialog window where we can select from a list of available libraries. We press the Create button to create a new library for Groovy 1.5.7. NetBeans opens a dialog where we type Groovy_1.5.7 (spaces are not allowed in library names, so we use an underscore):

We press the OK button and we get a new dialog window. Here we can add the groovy-all-1.5.7.jar file from the embedabble directory of the Groovy 1.5.7 installation directory. If we don't have Groovy 1.5.7 already on our computer we can download it from the Groovy website. Now we can close the dialog by pressing the OK button.

We are still in the Project Properties dialog window. We go to the Compile Test tab and replace the Groovy 1.5.5 library with the Groovy_1.5.7 library. We click the OK button to close the project properties. We are ready to run our Groovy script again and this time we don't get an error anymore, because the format method is recognized. (Of course we still need to change the URL in the script to a real URL in order to run the file.).

December 12, 2008

Using Groovy to invoke cURL and use a date range

I want to learn more about Groovy, so I keep looking for ways to use Groovy in our project. The best way to learn something new is to use it in a real live situation.

For our project we have a Unix shell script to access a URL with a variable date. The URL is http://servername/import-data/{yyyy-MM-dd}, where {yyyy-MM-dd} is a date. So if we want to import data for the first of December 2008, we use http://servername/import-data/2008-12-01. In the shell script we access this URL for all dates from now to the next month. So let's say today is December 1st 2008 then the script invokes http://servername/import-data/2008-12-01, next the scripts invokes http://servername/import-data/2008-12-02 and so on.

The URL is accessed with the program cURL. This way we can save the output and have some nice feedback on the console. The complete command for a single day is curl -o log/2008-12-01.log http://servername/import-data/2008-12-01.

I was able to rewrite the script into the following Groovy script:

// Start from today.
def today = new Date()
// Determine date value for the next month.
// The TimeCategory makes it possible to use the 1.month syntax.
def nextMonth
use (org.codehaus.groovy.runtime.TimeCategory) {
  nextMonth = today + 1.month
}
// Loop through every day from now to the next month.
for (day in today..nextMonth) {
  println "Starting import for ${day.format('dd MMMM yyyy')}."
  // Define cURL process with correct arguments.
  def proc = "curl -o log/${day.format('yyyy-MM-dd')}.log "
           + "http://servername/import-data/${day.format('yyyy-MM-dd')}"
           .execute()
  // cURL uses error output stream for progress output.
  Thread.start { System.err << proc.err } 
  // Wait until cURL process finished and continue with the loop.
  proc.waitFor()
}

I am impressed by the power of Groovy to write small applications. The language contains nice features like date ranges, date related DSL and simple execution of external processes as demonstrated in this small application.

December 11, 2008

Total Commander as a Windows Explorer replacement

I was never satisfied with the Windows Explorer for my file manipulation needs. Especially copying or moving files can be cumbersome with the tree view in Explorer. A couple of years ago I discovered Total Commander. And now I cannot do without it. The two-pane view of directories makes it so easy to copy or move files. The tabbed directory views makes it easy to swich back and forth between directories. And there is so much more to make it a really useful piece of software.

X-Mouse behavior for Windows

When I worked on Linux I really liked how I could focus a window without bringing it to the front. It saved me a lot of mouse clicks and annoyance. Another nice feature is that text selected by the mouse is automatically placed in the clipboard. And by clicking the middle mouse button we can paste the text again. But then I had to use Windows again and I couldn't use these nice features. I thought...

TXMouse is a little utility to give Windows users the same mouse functionality as Linux. We only have to start TXMouse when Windows starts and we are ready to go. I can put the focus on windows without raising them to the front. I can select text and it is copied to the clipboard. I can use the middle mouse button to paste text from the clipboard. This saves a lot of mouse and keyboard clicks.

Weekly Sightings

Revolving doors to make energy
One of the things you would expect to be implemented already. A revolving door is already like a big generator being pushed round and round.

Smashing Magazine
A great website to just browse and browse. The site contains a lot of lists with beautiful (web) design examples. I just love to look around for fifteen minutes a day and get inspired.

December 3, 2008

Firebug add-on for Firefox

When I develop a web application I cannot do it without the Firefox add-on Firebug. Firebug is a add-on with great features like editing and debugging HTML, CSS and Javascript. Also a good monitoring tool to see which files are loaded for page, their sizes and download time. And much, much more.

FireCookie is an add-on to the Firebug add-on. With FireCookie we can easily see and change cookie values. On my latest project this would have been very helpful if I had known about this add-on earlier.