Adding Verdana / Tahoma / winfonts LaTeX support in Ubuntu 9.04

September 28th, 2009

To be able to use windows fonts like Verdana, Tahoma and so forth in Latex documents on an Ubuntu Jaunty Jackelope you need to install the winfonts package from CTAN. The following steps explains what I undertook to use these fonts:

1. First download the winfonts package from CTAN
2. Find your Tahoma and/or Verdana fonts on the web or your Windows computer
3. Extract the files in your home
4. Copy the contents of the winfonts directories doc, fonts, tex, ttf2tfm to /usr/share/texmf-texlive/ respectively
5. Copy the fonts to /usr/share/texmf-texlive/fonts/truetype/public/msttcorefonts
6. Run the following commands

sudo update-texmf
sudo update-fmtutil
sudo update-updmap
sudo texhash
sudo updmap-sys --enable MixedMap winfonts.map

7. In your LaTeX document switch to Tahoma with the following commands:

\usepackage[T1]{fontenc}
\fontfamily{tahoma}\selectfont
\renewcommand{\sfdefault}{tahoma}
\renewcommand{\familydefault}{\sfdefault}

I solved this problem with some help from these entries:
http://www.latex-community.org/forum/viewtopic.php?f=5&t=2110&p=8558

Further the documentation for the winfonts is here.

Implementing Ajax push with RichFaces

August 18th, 2009

The following snippets illustrates how to implement an ajax push in a JSF application where RichFaces is set up. I am using this with a JSF application with Tomahawk extensions and RichFaces just for Ajax and Menus

Add the following in the XHTML:

<!-- Register an ajax listener on the bean -->
<a4j:push interval="1000" eventProducer="#{bean.addPushListener}"
    reRender="ajaxPanel" enabled="#{bean.pushing}" id="pushLstnr" />
<!-- the panel to be updated -->
<a4j:outputPanel id="ajaxPanel" ajaxRendered="true">
<h:messages layout="table" errorStyle="color:red"
      fatalStyle="color:red" infoStyle="color:blue" showDetail="true"
      showSummary="true" styleClass="loginError" />
</a4j:outputPanel>

Add the following to the Bean:

/**
  * Registers the ajax listener
  *
  * @param listener
  */
public void addPlanStatePushListener(EventListener listener) {
  synchronized (listener) {
    if (this.ajaxPushListener != listener) {
      this.ajaxPushListener = (PushEventListener) listener;
    }
  }
}

Now all you have to do is execute this call in your code where you need to update your browser:

// send event to browser:
ajaxPushListener.onEvent(new EventObject(this));

Have fun
Robert

DHCP Internet and own DNS Server

July 15th, 2009

If you’re running your own DNS Server and your internet connection is using DHCP to get the WAN IP, then you might run into the same problem I have.

I have configured my own LAN DNS-Server on a local IP and configured this in /etc/resolv.conf. Periodically the DHCP Client refreshes the WAN IP, thus overwriting my resolv.conf settings.

This problem can be resolved by adding the following line to your /etc/dhcp3/dhclient.conf file:


interface "eth0" {
prepend domain-name-servers 10.0.0.1;
}

In this way your DNS Client will first add your defined domain-name-server to the list sent from your provider

Creating icons for eclipse applications

February 17th, 2009

I’ve been starting to get quite annoyed with problems surrounding creating icons for use in eclipse applications. Windows needs either alot of icons in 8bit and 32bit or one ico containing all of those images. Anyhow after some trying I found out how I could get this done.

  1. First you create your icon in a large enough size so you don’t loose any information
  2. Then you use gimp and create all the 32bit versions by just resizing the image to 48×48, 32×32 and 16×16. These you can keep in the RGB mode and then save as BMP’s
  3. All the 8-bit images created nearly the same. You just need to change the mode to indexed and then change the maximum number of colours to 255 for 8bit.
  4. You can create an ico file with the imagemagick package in linux with the following command:
    convert image1_16_8bit.bmp image2_16_32bit.bmp.... -channel Alpha -negate image.ico
  5. Then go into the Eclipse product page and choose each icon respectively

Running Task asynchronously in Eclipse RCP and JFace

February 17th, 2009

These code snippets show how it is possible to executes task in Eclipse by showing a progress dialog, which is possible to hide

This is the code to start the job:

// create action to be called after the action is completed
// this action shows a success dialog if the job executed without
// an exception, otherwise it shows an error dialog
final CompletionAction completionAction = new
        CompletionAction(AdminClientActivator.PLUGIN_ID, parent.getShell(), view);
completionAction.setOkTitle("Job sucess");
completionAction.setOkMsg("Sucessfully executed job");
completionAction.setFailTitle("Job failed");
completionAction.setFailMsg("There was an exception while executing job");

RSPClientJob job = new ClientJob("Long job...", completionAction);

// if short action, otherwise is long Job.LONG
job.setPriority(Job.SHORT);
// show a dialog immediately
job.setUser(true);
// start as soon as possible
job.schedule();

This snippet is the Job class:

/**
 * Abstract {@link Job} class for executing tasks with a progress dialog
 * @author Robert von Burg
 */
public class ClientJob extends Job {
  private CompletionAction completedAction;

  /**
   * @param name
   * @param completedAction
   */
  public ClientJob(String name, CompletionAction completedAction) {
    super(name);
    this.completedAction = completedAction;
  }

  protected IStatus run(IProgressMonitor monitor) {
    // activate the progress bar with an unknown amount of task work
    monitor.beginTask("Loading Hibernate configuration", IProgressMonitor.UNKNOWN);
    // perform the job
    try {
      // execute task work...
      Thread.sleep(10000);
      // at the end of the successfully ended work, set the completion
      // task to be ok
      completionAction.setOk(true);
    } catch (Exception e1) {
      logger.error(e1, e1);
      // if the work failed then set the completion
      // task to be NOT ok and set the exception so it
      // can be shown to the user
      completionAction.setThrowable(e1);
      completionAction.setOk(false);
    }
    // stop the monitor
    monitor.done();
    // execute the completion task
    complete();
    return Status.OK_STATUS;
  }

  /**
   * completes the task by showing the user a dialog about the execution
   * state of the job
   */
  protected void complete() {
    setProperty(IProgressConstants.ICON_PROPERTY, ImageFactory.
                getImg(ImageFactory.IMG_OK));
    Boolean isModal = (Boolean) this.getProperty(
                IProgressConstants.PROPERTY_IN_DIALOG);
    if (isModal != null && isModal.booleanValue()) {
      // The progress dialog is still open so
      // just open the message
      showResults(completedAction);
    } else {
      setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
      setProperty(IProgressConstants.ACTION_PROPERTY, completedAction);
    }
  }

  /**
   * Asynchronous execution of an {@link Action}
   * @param action
   */
  protected static void showResults(final Action action) {
    Display.getDefault().asyncExec(new Runnable() {
      public void run() {
        action.run();
      }
    });
  }
}

And since we want to notify the caller about task completion we use this interface:

/**
 * Interface for notifying objects to be refreshed
 * @author robertb
 */
public interface Refreshable {
  public void refresh();
}

And task completion is handled with this Action:

/**
 * The completion task, which either shows a success dialog, or an error dialog,
 * depending on the ok state set and then notifies the {@link Refreshable} to
 * refresh its contents
 * @author robertb
 */
public class CompletionAction extends Action {
  private boolean ok;
  private String okTitle;
  private String okMsg;
  private String failMsg;
  private String failTitle;
  private Throwable throwable;

  private Refreshable refreshable;
  private Shell shell;
  private String pluginId;

  /**
   * @param pluginId
   * @param shell
   * @param refreshable
   */
  public CompletionAction(String pluginId, Shell shell, Refreshable refreshable) {
    this.pluginId = pluginId;
    this.shell = shell;
    this.refreshable = refreshable;
  }

  public void setOk(boolean ok) {
    this.ok = ok;
  }

  public void setOkTitle(String okTitle) {
    this.okTitle = okTitle;
  }

  public void setOkMsg(String okMsg) {
    this.okMsg = okMsg;
  }

  public void setFailMsg(String failMsg) {
    this.failMsg = failMsg;
  }

  public void setFailTitle(String failTitle) {
    this.failTitle = failTitle;
  }

  public void setThrowable(Throwable throwable) {
    this.throwable = throwable;
  }

  public void run() {
    // first refresh
    refreshable.refresh();
    // then show the dialog
    if (ok) {
      MessageDialog.openInformation(shell, okTitle, okMsg);
    } else {
      Status status = new Status(IStatus.ERROR, pluginId,
                throwable.getLocalizedMessage(), throwable);
      ErrorDialog.openError(shell, failTitle, failMsg, status);
    }
  }
}

I put this together with help from the following site:
Job Concurrency

Thanks
eitch

JAVA and JAR’s from the command line

January 23rd, 2009

This is a small little tutorial which will explain how to create your own little Java application which have dependencies which are in other JAR files

First create the following directory structure:

java_test
    |
    |__myapp
    |     |__src
    |     |   |__ch
    |     |       |__eitchnet
    |     |            |__java
    |     |                 |__Main.java
    |     |__META-INF
    |     |    |__MANIFEST.MF
    |     |__bin
    |
    |__mydep
    |     |__src
    |     |   |__ch
    |     |       |__eitchnet
    |     |            |__helloworld
    |     |                 |__HelloWorld.java
    |     |__bin
    |
    |__deploy
        |__lib

The MANIFEST.MF file has the following content:

	Main-Class: ch.eitchnet.java.Main
	Class-Path: mydep.jar

The Main.java file has the following content:

  package ch.eitchnet.java;

  import ch.eitchnet.helloworld.HelloWorld;

  public class Main {
      public static void main(String[] args) {
      HelloWorld hw = new HelloWorld();
      System.out.println("HelloWorld instances: " + hw.getInstancesCount());
    }
  }

The HelloWorld.java has the following content:

  package ch.eitchnet.helloworld;

  public class HelloWorld {
    private static int instances;

    public HelloWorld() {
      System.out.println("Created HelloWorld object");
      instances++;
    }

    public int getInstancesCount() {
      return instances;
    }

    protected void finalize() {
      instances--;
    }
  }

Change your directory to be in the root of our project

Compile the dependency first:

find mydep/src/ -name "*.java" | xargs javac -d mydep/bin/

Should you be using a windows system, then you have compile file by naming each one. See the java help file for more information

Create the jar:

jar cvf ./deploy/mydep.jar -C ./mydep/bin ./

Compile the app:

find myapp/src/ -name "*.java" | xargs javac -classpath ./deploy/*.jar -d myapp/bin/

Should you be using a windows system, then you have compile file by naming each one. See the java help file for more information

Create the jar:

jar cmvf ./myapp/META-INF/MANIFEST.MF ./deploy/myapp.jar -C ./myapp/bin ./

Run the app by specifying everything explicitly:

java -classpath ./deploy/myapp.jar:./deploy/mydep.jar ch.eitchnet.java.Main

Or by running directly allowing the MANIFEST.MF to do its magic:

java -jar ./deploy/myapp.jar

tutorial files

grretings eitch

JSF and PDF’s

January 22nd, 2009

This is a quick snipped on transmitting a PDF in a JSF context:

byte[] bytes = getPDFStreamAsArray();
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response =
(HttpServletResponse) faces.getExternalContext()
.getResponse();
response.reset();
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
response.setHeader("Content-disposition", "inline;filename=\"file.pdf\""); // inline or attachment
response.setHeader("Cache-Control", "cache, must-revalidate");
ServletOutputStream out = response.getOutputStream();
out.write(bytes);
faces.responseComplete();

JSF and EL (Expression Language) rant !

January 20th, 2009

Beware people… Referring to missing methods in a Bean from a XHTML page using the expression language yields an exception, but referring to a *private* method, doesn’t to nothing. No exception, no message, just plain and simply nothing.

I spent hours trying to understand why my application didn’t work, and now I know it: Be careful that your exposed method is not marked as *private* in your bean!!

eitch

Java RMI quick and dirty

January 16th, 2009

Your object which will be accessible through RMI must meet the following requirements:

  • have its own interfaces which extends java.rmi.Remote
  • all methods must “throws RemoteException
  • all returned returned objects must implement java.io.Serializable

Starting a RMI server:

  • Set system property: System.setProperty("java.rmi.server.hostname", "hostname");
  • create registry: Registry registry = LocateRegistry.createRegistry(1099);
  • export Object: RemotableObject stub = (RemotableObject) UnicastRemoteObject.exportObject(remoteObject, 0);
  • bind object: registry.rebind("RemoteName", stub);

Remote call:

  • get Registry: Registry registry = LocateRegistry.getRegistry("hostname");
  • get Remote object: RemotableObject remoteObject = (RemotableObject) registry.lookup("RemoteName");
  • call method: remoteObject.remoteMethod();

Protected: OpenAir St. Gallen

July 27th, 2008

This post is password protected. To view it please enter your password below: