Archive

Archive for February, 2009

Second Week on Cuba

February 24th, 2009 6 comments

It’s now Tuesday of the second week on Cuba. Today is a free day we used for Internet, later we want to go to the Plaza de la Revolucion. Once you get used to the fact that western standards (like hot water or clean cooking environments) don’t apply everywhere, one can really have a good time here. The people are friendly, the weather is nice (though I prefer cold weather) and everything is just relaxed. Germany is much richer, but people also seem to have more worries. Though, of course, it’s difficult for me as a non-Spanish speaker to be sure about of the moods and worries of people here.

Speaking of that, one of the thing I enjoy most about this trip is learning the Spanish language. My knowledge of it was very basic before coming here and has improved steadily since then. At first, when not with our Spanish speaking colleague, asking people for the correct bus was a big problem (of course, there is no schedule or reliable information on how and where what buses will drive – after all, this is still Cuba 😉 ). But now, it became rather easy, learning a few words every day, but most importantly, getting used to listening. Reading Spanish is rather easy, as it’s so similar to English and especially Latin. Even so, I am of course not yet able to have any real discussion and if something new appears, I am “lost in translation”. But when my colleague speaks to the Spanish guys, understanding what they are talking about got more and more easy. Back in Germany, I hopefully will find some time to improve my Spanish some more. In the end, my professor was born in Spain and it’s good to know what he’s talking about, when he switches languages 😉 .

Now, one thing I dislike: Being a (old-school) computer scientist I have problems being without fast access to Internet. One of my colleagues whom I was with in Syria can confirm this 😉 . All ways of communication with Germany are very expensive and the Internet connection in Cuba is especially bad. If I understood correctly, the entire university here has a 2Mbit connection. For comparison: In my apartment in Germany there is a 8Mbit connection. So, it’s a major pain in the ass just to check emails from some servers in Germany (btw. sorry if I don’t answer all emails, I just cannot spend all day on that). And writing a blog article every now and then… Of course I prepare it on my notebook and then copy&paste it in the university. But: no access to websites I’m just used to, like dict.leo.org. My otherwise marvellous English 😉 is really hindered by the fact, that there’s not a second tab open just for checking a word every now and then. At least, there’s off line spell checking. And I can’t read what was written in the first article, because I deleted in from my notebook. Very clever, I know. And and and… Ok, I’m just a spoiled German informatics guy, jaja.

Anyway, enough for the second article. I really wished, there was a possibility to include some of the pictures, but I will do that when being back in Germany, promised.

Categories: Abroad, English Tags: , ,

First Impressions from Cuba

February 20th, 2009 1 comment

I am currently on a three week trip on Cuba under terms of a PhD Exchange. Since Internet is really slow here (like 2Mbit for the entire university) and hard to get by anyway, this will be a short entry only. I am preparing this text on my notebook, but pictures won’t do until I’m back to Germany.

I wanted to give a first impression, but it’s somehow really hard for me, because I haven’t made up my mind yet about the situation here. Before traveling, we were warned of a really poor country and especially bad apartments. While this country is truthfully poor, the apartments are not nearly as bad as we were told. Ok, they’re rather dirty and there’s no hot water, but otherwise they’re fine, even with refrigerator and tv.

The prices in this country are going from incredibly cheap (in Cuban areas) to waaay to expensive (in tourist areas). Upon arrival, we were in the tourist part in Havannah, before going to the dormitories next day. We tried to find something to eat in that area, and the first offers went from around 13-17 Euro per person, which is not affordable for us at all. After some time and asking around, we finally found a rather nice restaurant which had offers at around 2-3 Euro, which is more like it. To give a comparison, near the university there is a (really dirty) street, where they offer pizza for 10 Peso, which is around 40 cent, as well as fresh Batida de Guyaba for 8-12 cent. That one is so tasty, it will probably be the thing I will miss most back in Germany 🙂 . One more thing about traveling: We use the bus several times, it took the five of us approximately 8 cent for a 45 minutes trip (but you don’t have to pay in most buses anyway, people just hop in in the middle entrance).

I have to admit, this is not a very well structured article. I would like to write about confusing currency exchange, the people, buildings etc., but it’s difficult without (fast) Internet and enough time to think about it. So this is more for telling everyone, I’m still alive. So, just to give a short conclusion, this is indeed a poor country, but people seem to be very happy nonetheless and everyone is just relaxed, which is a nice change from Germany. Everyone is enjoying life despite of troubles.

’til later!

Categories: Abroad, English Tags: , ,

Embedding Windows in Linux with VirtualBox

February 10th, 2009 3 comments

I am obviously a big fan of Linux and use it at home as well as in my office. But in both places I still require Windows for two reason:

  • At home I require it for gaming. Wine is ok, but can still be a major pain in the ass with configuration and lesser known games.
  • In the office I am obliged to use Microsoft Office. I prefer LaTeX, but compared to OpenOffice the 2007 version of MsOffice is the big winner in my opinion.  But since working under Windows otherwise is out of question for me (I am way more productive with Linux/Gnome), a dual-boot like I use for gaming is no option.

So, in my office, I use VirtualBox to embed Windows inside my Linux desktop. Formerly I used VMware, which admittedly is more powerful, but provides a less appealing user interface and, at that time, did not provide the seamless mode, which I will make use of. To give an impression, here is a screenshot of my desktop:

Using VirtualBox to embed Windows inside Gnome

Using VirtualBox to embed Windows inside Gnome

I will not go through the installation process, as it’s pretty self-explanatory. But what VirtualBox additionally offers is the aforementioned seamless mode (default combination: Right-CTRL + L), which gives you the taskbar over your normal gnome panel. This is really nice, since it allows easy access and switching between Windows and Linux applications. While Alt-Tab is not used optimally (it only lets you access applications of one OS at a time), you can switch between Windows and Linux applications by pressing Right-CTRL before using Alt-Tab.

Another great feature is embedding any host folder (e.g. your home folder) directly inside the Windows explorer as seen on the screenshot. This is achieved by setting a shared folder in Devices->Shared Folders and then adding a network drive. This is as simple as right-clicking on My Computer (unsure about the name, I only have German Windows 😉 ) and adding the drive. From now it’s possible to modify and share files between host and virtual machine without any hassle.

Also, I configured cups to allow web access to the printers configured in Linux, so the Windows VM could easily print by using these. But I haven’t configured this yet since my last installation, so I cannot give a howto right now 😉 .

I hope you enjoy the progress of free VMs like VirtualBox as much as I do, as it allows Windows apps, that are sadly still required, to be used inside your Linux without a hassle and with nice integration. I hope that Alt-Tab is improved, then the whole thing would feel like a natural part of your Linux desktop. Additionally, VirtualBox now has Direct3D support (which I haven’t tested yet), so maybe one day we will be able to even do gaming inside our Linux distributions without any more need for a dual boot.

Update:

For all this, you need to install the Guest additions. You can find these in the menu devices.

A Java Wizard Toolkit

February 5th, 2009 No comments

Well, here goes my first post. This is a toolkit I started developing back in 2006. I am sure there are other, better implementations and I did not develop this small project any further, but I think it’s also a good example on how to program in OO (though I am sure there is much room for improvement, any flames appreciated 😉 ). So, here it goes:

Introduction

The Wizard Toolkit is a java framework / toolkit for the easy use and creation of wizards. This toolkit lets you focus on defining and validating input fields while the control flow and data storage is automated by the surrounding toolkit.

Wizards are a useful way to gather information for different purposes. They interact in form of dialogs, allowing step-by-step data input. Wizards can be used to gather information, for creating specific output or for setting preferences.

Tutorial

The following example serves as a step-by-step tutorial demonstrating the possibilities provided by the toolkit and how to implement a custom wizard based on it. It will consist of three parts, which will be found in most wizards:

  • A welcome dialog
  • Some input forms
  • A final dialog for checking / presenting all input

The toolkit provides two classes for implementing a wizard:

  • Wizard: The main class of any wizard, extending JDialog. Manages the control flow and displays the panels provided. After finishing the input process, it contains the data entered.
  • WizardPanel: An extension of JPanel. Every WizardPanel stands for one step in the dialog process. It may contain everything a JPanel can contain, usually text or input fields.

The welcome dialog

The first step in a dialog system should always be a welcoming screen, describing what needs to be done in the next steps. This way the user can get an overview of the data required or the process he is about to start. So we create a first class extending WizardPanel:

Note: All following sources are excerpts from the example files. For copyright issues look in the according java files.

public class Panel1 extends WizardPanel {
  public Panel1() {
    super(“Welcome”);
    add(new JLabel(“Welcome to the Wizard toolkit demonstration!));
  }
}

The title Welcome is set in the constructor. It is used for the header and for the menu. You might add further welcome information or for example add licence information here.

Theoretically one WizardPanel is sufficient to create the Wizard class, but in the next step we will add the skeleton of the other two panels and then create the Wizard.

Starting the Wizard

public class Panel2 extends WizardPanel {
  public Panel2() {
    super("Options");
  }
}
public class Panel3 extends WizardPanel {
  public Panel3() {
    super(“Finish”);
  }
}
public class WizardExample {
  public static void main(String[] args) {
    WizardPanel[] panels = new WizardPanel[] { new Panel1(),
        new Panel2(), new Panel3() };
    Wizard wizard = new Wizard((JFrame) null, “Wizard Example”, panels);
    wizard.setVisible (true);
    System.out.println(wizard.getProperties());
  }
}

The Wizard class needs three arguments: A parent dialog or frame (may be null), a title and an array with WizardPanels to display. The constructor automatically initializes everything needed for the process and starts after being set visible. When the user finished using the wizard, all data may be gathered via getProperties. With the WizardPanels implemented so far, calling the constructor will open the following dialog:

Welcoming Screen of the Wizard

Welcoming Screen of the Wizard

Menu, header and buttons are created and managed by the toolkit. Only the main panel / content panel needs to be implemented. Back and Finish cannot be selected, as there is no previous WizardPanel and this is not the last WizardPanel. The buttons behaviour may be modified. Selecting Next will display the next dialog, which will be further implemented now.

The options dialog

After the first dialog, the data input forms begin. In this tutorial a WizardPanel with some sample input fields will be implemented, including verification and storage of the data entered. At first, some input components will be added in the panel’s constructor:

public class Panel2 extends WizardPanel {
  private JCheckBox box1, box2;
  private JRadioButton rbutton1, rbutton2;
  private JTextField textField;
 
  public Panel2() {
    super("Options");
 
    box1 = new JCheckBox("Some option");
    box2 = new JCheckBox(
        "If this radio button is selected, you cannot select "next"");
    rbutton1 = new JRadioButton("Select me");
    rbutton2 = new JRadioButton(
        "If this button is selected, clicking "next" will open a Dialog Box.");
    textField = new JTextField(30);
 
    rbutton1.setSelected(true);
 
    setLayout(new GridBagLayout());
 
    GridBagConstraints gc = new GridBagConstraints();
    ButtonGroup rbuttons = new ButtonGroup();
 
    rbuttons.add(rbutton1);
    rbuttons.add(rbutton2);
 
    gc.gridx = gc.gridy = 0;
    gc.anchor = GridBagConstraints.NORTHWEST;
    add(new JLabel("Checkbox options:"), gc);
 
    gc.gridy++;
    add(box1, gc);
 
    // Add other Components
    // ...
  }

The toolkit enables the Back-Button as there is a previous dialog. But we do not want the user to go back, as there is only a welcome screen. On the other hand, we want to disable the forward button if box2 is selected (as described in its text). The toolkit’s control over the buttons may be overridden to implement panel-specific behaviour:

  protected boolean backButtonEnabled() {
    return false;
  }
 
  protected boolean nextButtonEnabled() {
    return !box2.isSelected();
  }

The Wizard toolkit must be specifically told when to refresh the buttons. Therefore it is necessary to add an ActionListener to the component and tell it to refresh the buttons upon selection:

public class Panel2 extends WizardPanel implements ActionListener {
  // ...
 
  public Panel2() {
    // ...
 
    // Refresh buttons upon selecting / deselecting this checkbox
    box2.addActionListener(this);
    box2.setActionCommand("box1");
 
    // ...
  }
 
  public void actionPerformed(ActionEvent e) {
    refreshButtons();
  }
}

If the second radio button is selected, a confirmation box will be opened upon clicking Next. This can be done via verification of the data input. To use this method, all data must be made available to the toolkit. Every information that needs to be stored must be added to a Property object. This data is gathered by the toolkit.

  protected Properties getProperties() {
    Properties properties = new Properties();
 
    properties.setProperty("box1", String.valueOf(box1.isSelected()));
    properties.setProperty("box2", String.valueOf(box2.isSelected()));
    properties.setProperty("rbutton1", String
        .valueOf(rbutton1.isSelected()));
    properties.setProperty("rbutton2", String
        .valueOf(rbutton2.isSelected()));
    properties.setProperty("textfield", textField.getText());
 
    return properties;
  }
 
  protected boolean verifyChanges(Properties properties) {
    if (Boolean.parseBoolean(properties.getProperty("rbutton2"))) {
      return JOptionPane
          .showConfirmDialog(
              this,
              "Are you sure you want to continue with radio button 2 selected?",
              "Please confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
    }
 
    return ALLOW;
  }

Every WizardPanel which gathers information must provide the getProperties method to store its data. Every WizardPanel that needs verification must provide the verifyChanges method. This method either returns ALLOW (true) or DENY (false). If DENY is returned, the toolkit will do nothing upon selecting Next or Finish. Note: The properties given as parameter here are not only the properties of this WizardPanel but the properties of all Panels. This way, data can be verified over multiple steps.

Second Dialog of the Wizard

Second Dialog of the Wizard

Confirmation before Advancing to the next Step

Confirmation before Advancing to the next Step

The finish dialog

On the last dialog we want to display all information entered by the user so far. Therefore we cannot use the constructor for initializing the components, as we do not know what the user has entered previously. Even worse, the user may use the back button and change the data. So we need a way to update all components upon displaying the WizardPanel. This is done via setComponents, which is called upon every display of the WizardPanel and is provided all properties so far:

public class Panel3 extends WizardPanel {
  public Panel3() {
    super("Finish");
 
    setLayout(new GridBagLayout());
  }
 
  protected void setComponents(Properties properties) {
    removeAll();
 
    GridBagConstraints gc = new GridBagConstraints();
 
    gc.gridx = gc.gridy = 0;
    add(new JLabel("All required information have been entered."), gc);
 
    gc.gridy++;
    add(new JLabel(" "), gc);
 
    gc.anchor = GridBagConstraints.NORTHWEST;
    gc.gridy++;
    add(new JLabel("Boxes selected:"), gc);
 
    if (Boolean.valueOf(properties.getProperty("box1"))) {
      gc.gridy++;
      add(new JLabel("Checkbox 1"), gc);
    }
 
    if (Boolean.valueOf(properties.getProperty("box2"))) {
      gc.gridy++;
      add(new JLabel("Checkbox 2"), gc);
    }
 
    if (Boolean.valueOf(properties.getProperty("rbutton1"))) {
      gc.gridy++;
      add(new JLabel("Radio button 1"), gc);
    }
 
    if (Boolean.valueOf(properties.getProperty("rbutton2"))) {
      gc.gridy++;
      add(new JLabel("Radio button 2"), gc);
    }
 
    gc.gridy++;
    add(new JLabel(" "), gc);
 
    gc.gridy++;
    add(new JLabel("Text entered: "), gc);
 
    gc.gridy++;
    add(new JLabel(properties.getProperty("textfield")), gc);
  }
}

Final Dialog of the Wizard, showing Summary

Final Dialog of the Wizard, showing Summary

Conclusion

With this step, all implementation for the example is finished, showing all possibilities this framework provides. You may verify data on the fly or after selecting buttons and override the button behaviour. The toolkit lets you specify custom behaviour when necessary and provides standard control flow when applicable, supporting a very easy and structured way to implement Wizards.

Source code (SVN)

Sorry, this outdated information, if you need the source code, download it from the section below.

This software is developed as open source under the general public licence. You may freely use or modify this software in terms specified by the GPL. The source code is accessible via Subversion with the repository lying at:

feanorscurse.dyndns.org/home/svn/toolkit

Please inform me before publishing any code changes.

Download

The current stable version is 0.2. You may download the toolkit as jar-files or access the source. If you are planning to use this toolkit, it would be nice to leave a comment 🙂 .

Wizard Toolkit v0.2

Wizard Toolkit v0.2 with example application

Categories: English, Linux & Programming Tags: ,