Old News: NetBeans Tips

Have you ever wondered that there are no “tips of the day” for NetBeans available? Maybe these two sides could satisfy your needs:

  • NetBeans Hacks (Part1) Here the following was new to me: Out-Smart Search & Replace
  • NetBeans Hacks (Part2) Here I suggest you to read Activate Anti-Aliasing Font Rendering in the Editor, Define Shortcuts for Ant Targets and Depend on Other Projects.

But both are for older versions of NetBeans. So are there any plans for newer tips? Yes, there are! Ruth says sun even plans to publish a book (at JavaOne) about this topic.

NetBeans of the year 2010

I am really happy with NetBeans 6.0, but through my usage of other IDEs I noticed that there could be even more features in NetBeans. Namely:

  1. Spell-checking while editing. I know that there is an existing module. But the module isn’t in the final release! (And nbextras is down.)
  2. Serial Version Generator. Even here is an existing modul. But as always I would prefer that a working version will be shipped with the IDE.
  3. A simple binding of an ant-task to a menu entry (to define keyboard shortcuts). E.g. Provide a ‘Create new menu from ant-task’- wizard.
  4. Formatting of several files. E.g. via right clicking on a package->Tools->Formatting.
  5. Searching through keyboard shortcuts should be possible.
  6. One should be able to select specific moduls for the update process. And the process should be done in background.

I know that there is an issue tracker for NetBeans. And here is a quite extensive list. But I want to discuss wether these features are important and if you have suggestions for further improvements. Please do not only mention things that other IDE’s can do.

Instead we should think about a NetBeans of the year 2010 like other people did here and here. (Keep your eyes on the date in both posts!)

Software Patents in Europe – WebShop Example

Yesterday ( 25.04.2008 ) was the day of the intellectual property.

But does software fall into this category?

In my opinion you cannot grant patents to ideas – only e.g. to devices. I think you cannot grant a patent like ‘enter the code for the sales discount’. You can only put a copyright on the code (e.g. which queries the database), but copyright means that others cannot (easily) make a duplicate – it doesn’t mean that others cannot ‘use’ this idea (plagiates are forbidden of course). If the granted patents on software can be executed in europe, then many open source programmer – like me – gets a lot of trouble!

Today I discovered a good (english or german) example at ffii.de to demonstrate which patents could be violated if you develop a simple webshop. It was really impressive for me that these patents are actually granted.

To look for the mentioned patent numbers you can use espacenet.com.

Java’s Success on the International Timetabling Competition 2007/08

It is really amazing! Thomas Müller is the definitive winner of the International Timetabling Competition 2007/08. Although the group from Japan (Atsuta et al.) was nearly as successful.

Congratulations!

It is really nice to see that Mr. Müller and Atsuta et al. had success in all three kinds of problems. The great thing about Thomas Müller’s effort is that his solver is open source (LGPL) and its written in Java! Here you can download it.

The goal of the competition was to solve different timetabling problems with an optimization routine. If you don’t know what timetabling is please look here for a definition of School timetabling at wikipedia. For more information on a special type of optimization look here for tabu search.

I know that it was really hard to achieve these good solutions, because I took part without success in track 2 (with my own little project).

Ruby 4 Java Programmers and Extreme Test Driven Development

Ruby 4 Java Programmers

I thought Ruby is just another language like Java to express things in a different syntax, but now I know that I was wrong. Look into these old, but really nice slides I discovered yesterday:

http://onestepback.org/articles/10things

Let me know some other good articles about ruby!

Now I understand the ‘ruby hype’ a little bit better. Thank you Jim Weirich!

Extreme Test Driven Development

Did you write unit tests? Do you actually write unit tests?

Do you like TDD? If not then look here!

But what about these lines that are untested? Do you know them? Do you actually need them? Maybe you don’t need them, then you should have a look at this tool! It will remove all the untested code!

To discuss the political incorrect name of the project please feel free to post your opinion here.

Do you want to create decoupled unit tests? Then have a look at this tool, which uses the SecurityManager to ensure this!

You want to know if your unit tests are subtle enough? Try out jester! “It modifies your source code, runs the tests and reports if the tests pass despite the changes to the code. This can indicate missing tests or redundant code.” taken from the sourceforge mainpage of jester.

Old Hat: Java Logging

Nearly all projects need to log something. You can use System.out.println(String) for that. But if you want to write the message to a file later you have to change all the logging statements in your code.

So it is recommended to use at least the Logger provided by the jdk:

java.util.logging.Logger

Other projects for logging exist e.g. the popular log4j. But this library is complex and the jar file is too big for my purposes.

Today I discovered slf4j, which is small (<25KB) and provides wrappers for the jdk-Logger and log4j. The nice thing about this library is that you can simply put the jar files into the classpath and slf4j will use e.g. the jdk-Logger. I like it more than the jdk-Logger because slf4j offers a nice interface for logging (the methods are easier to use) e.g.:

  • info(String)
  • info(String, Throwable)
  • warn(String)
  • warn(String, Throwable)
  • error(String)
  • error(String, Throwable)

But all logger don’t have a feature to log directly to the user. So I implemented a Handler that prints a JDialog with the message and the full stack trace. The stack trace will be available if the user clicks on the details button.

/*
 * This file is part of the timefinder project.
 * Visit http://www.timefinder.de for more information.
 * Copyright (C) 2008 Peter Karich.
 *
 * This project is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 2.1 of the License.
 *
 * This project is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this project; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 * or look at http://www.gnu.org
 */
package de.timefinder.framework;

import java.awt.BorderLayout;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 * This class provides a Log Handler to be publish directly to the user via
 * a JDialog, which offers a details Button.
 * 
 * @author Peter Karich, peat_halatusersdotsourceforgedotnet
 */
public class SwingHandler extends Handler {

    @Override
    public void publish(LogRecord record) {
        if (!isLoggable(record)) {
            return;
        }
        int level = record.getLevel().intValue();
        int jOptLevel;

        if (level >= Level.SEVERE.intValue()) {
            jOptLevel = JOptionPane.ERROR_MESSAGE;
        } else if (level >= Level.WARNING.intValue()) {
            jOptLevel = JOptionPane.WARNING_MESSAGE;
        } else {
            jOptLevel = JOptionPane.INFORMATION_MESSAGE;
        }

        logIntoDialog(jOptLevel, record.getMessage(), record.getThrown());
    }

    @Override
    public void flush() {
    }

    @Override
    public void close() throws SecurityException {
    }

    private static void logIntoDialog(final int messageLevel,
            final String errorMessage,
            final Throwable th) {

        if (!SwingUtilities.isEventDispatchThread()) {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {

                    public void run() {
                        logIntoDialog(messageLevel, errorMessage, th);
                    }
                });
            } catch (Exception ex) {
                JOptionPane.showConfirmDialog(null, errorMessage);
            }

            return;
        }

        StringBuilder sb = new StringBuilder();
        sb.append(errorMessage);
        if (errorMessage == null || errorMessage.length() == 0) {
            if (th != null) {
                sb.append(th.getClass().getName());
                sb.append(": ");
            }
            // TODO I18N
            sb.append("Error-Message Not Available>");
        }

        String newErrMessage = sb.toString();
        if (th != null) {
            TFFormatter.printReason(sb, th);
        }

        JScrollPane scroll = new JScrollPane(new JTextArea(sb.toString(), 20, 40));
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(new JTextField(newErrMessage), BorderLayout.CENTER);
        panel.add(scroll, BorderLayout.SOUTH);
        // TODO I18N
        Object[] options = {"Okay", "Details"};
        int n = JOptionPane.NO_OPTION;
        Icon icon;

        switch (messageLevel) {
            case JOptionPane.WARNING_MESSAGE:
                icon = UIManager.getIcon("OptionPane.warningIcon");//NO I18N
                break;
            case JOptionPane.ERROR_MESSAGE:
                icon = UIManager.getIcon("OptionPane.errorIcon");//NO I18N
                break;
            case JOptionPane.INFORMATION_MESSAGE:
                icon = UIManager.getIcon("OptionPane.informationIcon");//NO I18N
                break;
            default:
                icon = UIManager.getIcon("OptionPane.questionIcon");//NO I18N
        }

        boolean visible = false;
        //Switch between Details and No-Details:
        while (n != JOptionPane.YES_OPTION) {
            scroll.setVisible(visible);
            panel.revalidate();

            n = JOptionPane.showOptionDialog(
                    null,
                    panel,
                    newErrMessage,
                    JOptionPane.YES_NO_OPTION,
                    messageLevel,
                    icon,
                    options,
                    options[0]);

            visible = !visible;
        }
    }
}

No OOXML

OOXML is now ISO standard!

OOXML will divide the (internet) communication into a Microsoft-world and the rest. With the doc-format MS started the ‘way of division’ and now they will be successful!?

Finally I call on users all around the world to look to Norway and follow the example we have set. Raise a storm of protest! Uncover the irregularities that have taken place in your country! Insist that your Governments change their vote to reflect the interests of ordinary people and not the interests of monopolists and bureaucrats.” — Steve Pepper

So, nevertheless go to http://www.noooxml.org/petition and see the reasons, why OOXML shouldn’t be a standard.