Author Archive

Show /Hide hidden characters

Type > show hidden charcters

Comments No Comments »

JFreeChart is a very handy charting API for Java. Here are some hints on how to use it correctly.

ScatterPlot Fast version verus XYPlot

The fast scatter plot is easily created but cannot change the data item shape size and color, it is always 1×1 pixel. The data format is a 2d float array


package temp;

import java.awt.RenderingHints;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.FastScatterPlot;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class ScatterPlotFast extends ApplicationFrame {
private float[][] data;

public ScatterPlotFast(final String title) {
super(title);
}

public void setData(float scatterData[][]) {
this.data = scatterData;
}

public void renderAndDisplay() {
final NumberAxis domainAxis = new NumberAxis("X");
domainAxis.setAutoRangeIncludesZero(false);
final NumberAxis rangeAxis = new NumberAxis("Y");
rangeAxis.setAutoRangeIncludesZero(false);
final FastScatterPlot plot = new FastScatterPlot(data, domainAxis, rangeAxis);
final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
// force aliasing of the rendered content..
chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
renderChartInPanel(chart);
}

private void renderChartInPanel(final JFreeChart chart) {
final ChartPanel panel = new ChartPanel(chart, true);
panel.setPreferredSize(new java.awt.Dimension(500, 270));
//      panel.setHorizontalZoom(true);
//    panel.setVerticalZoom(true);
panel.setMinimumDrawHeight(10);
panel.setMaximumDrawHeight(2000);
panel.setMinimumDrawWidth(20);
panel.setMaximumDrawWidth(2000);
setContentPane(panel);
pack();
RefineryUtilities.centerFrameOnScreen(this);
setVisible(true);
}
}

The slow version is a XYPlot and uses XYSeries to collect data tuplets.


package temp;

import java.awt.Color;
import java.awt.RenderingHints;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class ScatterPlotSlow extends ApplicationFrame {
private static final long serialVersionUID = -5045238125844119782L;
XYSeries data;

public ScatterPlotSlow(String title) {
super(title);
}

public void setData(float scatterData[][]) {
data = new XYSeries("Midi Note Values");
int size = 0;
if (scatterData.length > 0) {
size = scatterData[0].length;
for (int i = 0; i < size; i++) {
final double x = scatterData[0][i];
final double y = scatterData[1][i];
data.add(x, y);
}
}
}

public void renderAndDisplay() {
final XYDataset dataSet = new XYSeriesCollection(data);
final JFreeChart chart = ChartFactory.createScatterPlot("Slow Scatter Plot", "X", "Y",
dataSet, PlotOrientation.VERTICAL, true, false, false);
final XYPlot plot = chart.getXYPlot();
//dot renderer cannot be set because it has only 1 pixel dot size
//        plot.setRenderer(new XYDotRenderer());
plot.setBackgroundPaint(Color.WHITE);
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) plot.getRenderer();
xylineandshaperenderer.setSeriesShape(0, new java.awt.Rectangle(-2, -2, 2, 2));
xylineandshaperenderer.setSeriesPaint(0, Color.BLUE);
// force aliasing of the rendered content..
chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
renderChartInPanel(chart);
}

private void renderChartInPanel(final JFreeChart chart) {
final ChartPanel panel = new ChartPanel(chart, true);
panel.setPreferredSize(new java.awt.Dimension(500, 270));
//      panel.setHorizontalZoom(true);
//    panel.setVerticalZoom(true);
panel.setMinimumDrawHeight(10);
panel.setMaximumDrawHeight(2000);
panel.setMinimumDrawWidth(20);
panel.setMaximumDrawWidth(2000);
setContentPane(panel);
pack();
RefineryUtilities.centerFrameOnScreen(this);
setVisible(true);
}
}

Comments No Comments »

EclipseAuto Format

Define a Formatter File once according to your preferred settings and use it to auto format in Eclipse after save. Enable the following settings for each project desired.

Comments Comments Off

10 things to know about web development nowadays

http://robcubbon.com/10-things-i-wish-i-had-known-about-web-designing-10-years-ago

Comments Comments Off

One of my favorite musician in a free concert web stream – John Butler Trio @ ARTE

http://liveweb.arte.tv/fr/video/John_Butler_Trio_au_Printemps_de_Bourges/

Comments Comments Off

Interfacing with the control gateway Device CKOZ 00/03 we got an API from Moeller to communicate to their wireless dimmer actuators. The device offers a RS232/RJ11 connector or per default a USB one.

The USB connection however does not work on a COM Port but offers only standard USB HID connection. We needed a library to open up a connection to this USB Devices and talk to it. We used the Sourceforge LibUSBDotNet library for this ( http://libusbdotnet.sourceforge.net/ ) in an older version as described later in the belower forum entry. Problems arise not while connecting to a device but while finding and communicating with the right device endpoints. Here is a tutorial on how to do that:

- Read on FROM http://community.sharpdevelop.net/forums/p/7995/22800.aspx#22800 and take experimental source code from ttp://sourceforge.net/projects/xcom-hp
- Modify VID hex = 188A and PID Hex 1101 in Class USBPort
- Modify READ AND WRITE ENDPOINT in Class USBPort ,
since we get the Moeller endpoint ids from the helper tool  testlibusb-win.exe, we can see 2 endpoints
EP moeller 1 81h == 129  == READENDPOINT
P Moeller 2 02h == 2 == WRITERNDPOINT
From the Library LibUSBDotNet we see in class ReadEndpoints (start at 129 == 0×81 )and WriteEndpoints (start at 1), so it is clear which one has to be assigned
- in USBPort.openDevice() the lines device.SetConfiguration(1) and device.ClaimInterface(0) are crucial for working

When it all stopped working

Right the day after, the solution with the LibUSBDotNet Lib was not working anymore without a single code change tested on three Win XP PCs. The crucial line

[code lang="java"]device.SetConfiguration(1)[code] freezes the PC and requires a reboot to even close the application and reaccess the Moeller gateway once again. However the SimpleHID Write test application still could communicate to the Moller gateway. So set a broken device apart, we needed a new solution. We found the very handy Jan Axelson Lakeview Research - http://www.lvr.com/usb.htm that offers a bunch of resources to the USB topic.

With generic_hid_cs and usbhidio_V2.3.cs it offers free c# src for accessing generic USB devices. Both seem quite similar and are working with the obove Vendor and ProductID for our purpose. Finally this resolved the USB communication odyssey

Comments Comments Off

How to count words in Acrobat

One can use Acrobat JavaScript. Once you have opened the JavaScript debugging console, enter the following script:

var cnt=0;
for (var p = 0; p < this.numPages; p++)
cnt += getPageNumWords(p);
console.println(“There are ” + cnt + ” words in this doc.”);

Highlight the entire script, hold down the “Ctrl” key and press the keypad’s enter key and wait.

Comments Comments Off

Very handy Utils Library

http://ostermiller.org/utils/

Difference Java Streams and Readers/Writers

see http://openbook.galileocomputing.de/javainsel8/javainsel_14_004.htm#mj1d0203580263334d55e78601998800e5

Die Klassen InputStream und OutputStream bilden die Basisklassen für alle byte-orientierten Klassen und dienen somit als Bindeglied bei Methoden, die als Parameter ein Eingabe- und Ausgabe-Objekt verlangen. So ist ein InputStream nicht nur für Dateien denkbar, sondern auch für Daten, die über das Netzwerk kommen. Das Gleiche gilt für Reader und Writer; sie sind die abstrakten Basisklassen zum Lesen und Schreiben von Unicode-Zeichen und Unicode-Zeichenfolgen. Die Basisklassen geben abstrakte read()- oder write()-Methoden vor, die Unterklassen überschreiben, da nur sie wissen, wie etwas tatsächlich gelesen oder geschrieben wird.

DataInputStream - reads data primitives and also utf-8

BufferedStream there are four buffered stream classes used to wrap unbuffered streams: BufferedInputStream and BufferedOutputStream create buffered byte streams, while BufferedReader and BufferedWriter create buffered character streams.

InputStream - just byte wise no additional stuff

So the difference is streams are for byte wise read/write and readers/writers are for characters and primitives

Java fast FileIO using native IO (NIO)

http://stackoverflow.com/questions/2111749/fastest-way-of-processing-java-io-using-ascii-lines

Java – Application Freeze at JFileChooser

Obviously there seems to be a bug or a problem with file listings in Java sometimes. When creating a GUI instanciate a FileChooser always within a buttonPressed method instead of a global JFileChooser instance. The delay when pressing a button is more acceptable than a 5-6 sec delay when starting the apps GUI the first time. See http://forums.sun.com/thread.jspa?threadID=5436569

Comments Comments Off

OSGI Lazy Class Loading

Der OSGi Classloader lädt prinzipiell nur die Klassen, die benötigt werden (siehe Hakerl Activate this plug-in when one of its classes is loaded im Manifest). Es kann jedoch zu Problemen beim Classloaden kommen und es können Timeouts auftreten. Das OSGi Framework wirft eine nichtssagende BundleStatusException. Wenn man nun das besagte Hakerl im Manifest nicht setzt, werden alle Klassen beim Starten geladen und somit kein Lazy Loading durchgeführt.

Details dazu siehe

http://wiki.eclipse.org/Lazy_Start_Bundles

http://lubospeclipse.wordpress.com/eclipse-plugin-and-rcp-development-notes/

http://www.osgi.org/Specifications/HomePage

OSGI Awt and Swing issues

read about problems with OSGi and swing

http://lsd.luminis.nl/swing-and-osgi/

Comments Comments Off

Accelerometer based signal filtering

http://tom.pycke.be/mav/69/accelerometer-to-attitude

Kalman filter

Especially useful for signal smoothing in navigation and aeronautics

http://tom.pycke.be/mav/71/kalman-filtering-of-imu-data

http://stackoverflow.com/questions/1134579/smooth-gps-data

Comments Comments Off