/************************************************************************** /* This class /* /* Copyright (c) 2004 by Bernhard Bablok (mail@bablokb.de) /* /* This program is free software; you can redistribute it and/or modify /* it under the terms of the GNU General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This program 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 General Public License for more details. /* /* You should have received a copy of the GNU General Public License /* along with this program; see the file COPYING. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ import java.io.*; import org.jfree.chart.*; import org.jfree.chart.plot.*; import org.jfree.data.*; import org.jfree.data.xml.*; /** Display per-cent free space of an empty filesystem for two media and various Linux filesystems. */ public class FreeSpace { private static final String USB_STICK = "64MB USB-Stick", DVD_RAM = "4.3 GB DVD-RAM"; private CategoryDataset iSet; //////////////////////////////////////////////////////////////////////////// /** Create a dataset by hardwiring the data. */ private void createDataset() { DefaultCategoryDataset set = new DefaultCategoryDataset(); set.addValue(91.81,"ext2",USB_STICK); set.addValue(98.94,"minix",USB_STICK); set.addValue(99.78,"vfat",USB_STICK); set.addValue(48.68,"reiserfs",USB_STICK); set.addValue(97.86,"jfs",USB_STICK); set.addValue(92.40,"xfs",USB_STICK); set.addValue(93.43,"ext2",DVD_RAM); set.addValue(99.26,"reiserfs",DVD_RAM); set.addValue(99.57,"jfs",DVD_RAM); iSet = set; } //////////////////////////////////////////////////////////////////////////// /** Create a dataset by reading a xml data-file. */ private void createDatasetFromXML(String filename) throws Exception { FileInputStream in = new FileInputStream(filename); iSet = DatasetReader.readCategoryDatasetFromXML(in); in.close(); } //////////////////////////////////////////////////////////////////////////// /** Create a vertical barchart. */ private JFreeChart createChart() { JFreeChart chart = ChartFactory.createBarChart( "Freier Platz auf leerem Linux Filesystem", // chart title "Medium", // domain axis label "Freier Platz in %", // range axis label iSet, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tool-tips false); // URLs return chart; } //////////////////////////////////////////////////////////////////////////// /** Start the program. The first argument is interpreted as a filename with the xml data-file. If no argument is given, use the hardwired data. */ public static void main(String[] args) { FreeSpace fs = new FreeSpace(); String filename = null; boolean batchMode = false; try { if (args.length > 0) { if (args[0].equals("-b")) { batchMode = true; if (args.length > 1) filename = args[1]; } else filename = args[0]; } if (filename != null) fs.createDatasetFromXML(filename); else fs.createDataset(); JFreeChart chart = fs.createChart(); if (batchMode) { ChartRenderingInfo info = new ChartRenderingInfo(); ChartUtilities. saveChartAsPNG(new File("freespace.png"),chart,600,400,info); PrintWriter pw = new PrintWriter(System.out); ChartUtilities. writeImageMap(pw,"FreeSpace",info); pw.flush(); } else { ChartFrame frame = new ChartFrame("FreeSpace",chart); frame.pack(); frame.setVisible(true); } } catch (Exception e) { e.printStackTrace(); } } }