Sending files to mobile phone using Bluetooth and OBEX

My previous posting “Using Bluetooth stack in desktop application” was quite a success if measured by the number of comments. It seems that there aren’t many tutorials or articles about the Desktop usage of Bluetooth.

Here is a next chapter in the same category: using Bluetooth to send files from a computer to a mobile phone.

Bluetooth file sender application

Read on if you are interested…

Continue reading

Charting with JFreeChart

I’ve been coding dashboard applications lately with Java SE. I have used JFreeChart library to generate all pie, line and bar charts. The library is awesome and is also Open Source. It would be very nice to see similar projects in the .NET world.

It was very easy to create first charts with JFreeChart mostly because it is so commonly used so there are many resources available in the Internet including tutorials and tips&tricks.

Here is a small sample how to create a simple pie chart and use it in your Swing application:

  1. // First create dataset
  2. DefaultPieDataset dataset = new DefaultPieDataset();
  3. dataset.setValue("Finland", 5300367);
  4. dataset.setValue("Sweden", 9107649);
  5. dataset.setValue("Norway", 4606363);
  6. dataset.setValue("Denmark", 5427459);
  7. dataset.setValue("Iceland", 309699);
  8.  
  9. // Create chart using the ChartFactory
  10. JFreeChart chart = ChartFactory.createPieChart(
  11. "the Nordic countries", // Title
  12. dataset, // Dataset
  13. false, // Don’t show legend
  14. false,
  15. false);

The following code adjusts chart appearance and section colors. This is not mandatory but shows how easily you can customize the visual parts of the chart.

  1. // Adjust appearance (optional)
  2. chart.getTitle().setPaint(Color.LIGHT_GRAY);
  3. chart.setAntiAlias(true);
  4. PiePlot plot = (PiePlot)chart.getPlot();
  5. plot.setShadowPaint(Color.DARK_GRAY);
  6. plot.setBackgroundPaint(
  7. new GradientPaint(0,0,Color.DARK_GRAY,0,100,Color.GRAY) );
  8. plot.setLabelBackgroundPaint(Color.GRAY);
  9. plot.setLabelLinkPaint(Color.LIGHT_GRAY);
  10. plot.setLabelOutlinePaint(Color.LIGHT_GRAY);
  11. plot.setLabelShadowPaint(Color.DARK_GRAY);
  12.  
  13. // Adjust section colors (optional)
  14. Color[] colors = {
  15.     new Color(0xB0CC99),
  16.     new Color(0x677E52),
  17.     new Color(0xB7CA79),
  18.     new Color(0xF6E8B1),
  19.     new Color(0x89725B)
  20. };
  21. for(int i=0; i<dataset.getItemCount(); i++) {
  22.     Color sectionColor = colors[i%colors.length];
  23.     plot.setSectionPaint(i, sectionColor);
  24. }

That is all you have to do to create a chart object. Then if you wish to display this chart for example in your Swing application you’ll need to do the following:

  1. ChartPanel chartPanel = new ChartPanel( chart );
  2. yourPanel.add( chartPanel );

And this is the result:

JFreeChart example of PieChart