package demo;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.tree.*;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.ui.*;
// Referenced classes of package demo:
// MemoryUsageDemo, DemoDescription
public class SuperDemo extends ApplicationFrame
implements ActionListener, TreeSelectionListener
{
static class DisplayDemo
implements Runnable
{
public void run()
{
try
{
Class class1 = Class.forName(demoDescription.getClassName());
Method method = class1.getDeclaredMethod("createDemoPanel", null);
JPanel jpanel = (JPanel)method.invoke(null, null);
app.chartContainer.removeAll();
app.chartContainer.add(jpanel);
app.displayPanel.validate();
String s = class1.getName();
String s1 = s;
int i = s.lastIndexOf('.');
if(i > 0)
s1 = s.substring(i + 1);
s1 = s1 + ".html";
app.displayDescription(s1);
}
catch(ClassNotFoundException classnotfoundexception)
{
classnotfoundexception.printStackTrace();
}
catch(NoSuchMethodException nosuchmethodexception)
{
nosuchmethodexception.printStackTrace();
}
catch(InvocationTargetException invocationtargetexception)
{
invocationtargetexception.printStackTrace();
}
catch(IllegalAccessException illegalaccessexception)
{
illegalaccessexception.printStackTrace();
}
}
private SuperDemo app;
private DemoDescription demoDescription;
public DisplayDemo(SuperDemo superdemo, DemoDescription demodescription)
{
app = superdemo;
demoDescription = demodescription;
}
}
static class PDFExportTask
implements Runnable
{
public void run()
{
try
{
SuperDemo.saveChartAsPDF(file, chart, width, height, new DefaultFontMapper());
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
}
}
JFreeChart chart;
int width;
int height;
File file;
public PDFExportTask(JFreeChart jfreechart, int i, int j, File file1)
{
chart = jfreechart;
file = file1;
width = i;
height = j;
jfreechart.setBorderVisible(true);
jfreechart.setPadding(new RectangleInsets(2D, 2D, 2D, 2D));
}
}
public SuperDemo(String s)
{
super(s);
setContentPane(createContent());
setJMenuBar(createMenuBar());
}
private JComponent createContent()
{
JPanel jpanel = new JPanel(new BorderLayout());
JTabbedPane jtabbedpane = new JTabbedPane();
JPanel jpanel1 = new JPanel(new BorderLayout());
jpanel1.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
JSplitPane jsplitpane = new JSplitPane(1);
JTree jtree = new JTree(createTreeModel());
jtree.addTreeSelectionListener(this);
JScrollPane jscrollpane = new JScrollPane(jtree);
jscrollpane.setPreferredSize(new Dimension(300, 100));
jsplitpane.setLeftComponent(jscrollpane);
jsplitpane.setRightComponent(createChartDisplayPanel());
jpanel1.add(jsplitpane);
jtabbedpane.add("Demos", jpanel1);
MemoryUsageDemo memoryusagedemo = new MemoryUsageDemo(0x493e0);
(new MemoryUsageDemo.DataGenerator(memoryusagedemo, 1000)).start();
jtabbedpane.add("Memory Usage", memoryusagedemo);
jtabbedpane.add("Source Code", createSourceCodePanel());
jtabbedpane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
jpanel.add(jtabbedpane);
return jpanel;
}
private JMenuBar createMenuBar()
{
JMenuBar jmenubar = new JMenuBar();
JMenu jmenu = new JMenu("File", true);
jmenu.setMnemonic('F');
JMenuItem jmenuitem = new JMenuItem("Export to PDF...", 112);
jmenuitem.setActionCommand("EXPORT_TO_PDF");
jmenuitem.addActionListener(this);
jmenu.add(jmenuitem);
jmenu.addSeparator();
JMenuItem jmenuitem1 = new JMenuItem("Exit", 120);
jmenuitem1.setActionCommand("EXIT");
jmenuitem1.addActionListener(this);
jmenu.add(jmenuitem1);
jmenubar.add(jmenu);
return jmenubar;
}
private JPanel createSourceCodePanel()
{
JPanel jpanel = new JPanel(new BorderLayout());
jpanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
JEditorPane jeditorpane = new JEditorPane();
jeditorpane.setEditable(false);
java.net.URL url = (demo.SuperDemo.class).getResource("source.html");
if(url != null)
try
{
jeditorpane.setPage(url);
}
catch(IOException ioexception)
{
System.err.println("Attempted to read a bad URL: " + url);
}
else
System.err.println("Couldn't find file: source.html");
JScrollPane jscrollpane = new JScrollPane(jeditorpane);
jscrollpane.setVerticalScrollBarPolicy(20);
jscrollpane.setPreferredSize(new Dimension(250, 145));
jscrollpane.setMinimumSize(new Dimension(10, 10));
jpanel.add(jscrollpane);
return jpanel;
}
public void actionPerformed(ActionEvent actionevent)
{
String s = actionevent.getActionCommand();
if(s.equals("EXPORT_TO_PDF"))
exportToPDF();
else
if(s.equals("EXIT"))
attemptExit();
}
private void exportToPDF()
{
java.awt.Component component = chartContainer.getComponent(0);
if(component instanceof ChartPanel)
{
JFileChooser jfilechooser = new JFileChooser();
jfilechooser.setName("untitled.pdf");
jfilechooser.setFileFilter(new FileFilter() {
public boolean accept(File file)
{
return file.isDirectory() || file.getName().endsWith(".pdf");
}
public String getDescription()
{
return "Portable Document Format (PDF)";
}
}
);
int i = jfilechooser.showSaveDialog(this);
if(i == 0)
{
ChartPanel chartpanel = (ChartPanel)component;
try
{
JFreeChart jfreechart = (JFreeChart)chartpanel.getChart().clone();
PDFExportTask pdfexporttask = new PDFExportTask(jfreechart, chartpanel.getWidth(), chartpanel.getHeight(), jfilechooser.getSelectedFile());
Thread thread = new Thread(pdfexporttask);
thread.start();
}
catch(CloneNotSupportedException clonenotsupportedexception)
{
clonenotsupportedexception.printStackTrac