class PieChartDemo5 extends JFrame {
private static final long serialVersionUID = 1L;
public PieChartDemo5(String applicationTitle, String chartTitle) {
super(applicationTitle);
// This will create the dataset
PieDataset dataset = createDataset();
// based on the dataset we create the chart
final JFreeChart chart = createChart(dataset, chartTitle);
// we put the chart into a panel
ChartPanel chartPanel = new ChartPanel(chart);
// default size
chartPanel.setPreferredSize(new java.awt.Dimension(500, 500));
// add it to our application
setContentPane(chartPanel);
StandardChartTheme.createLegacyTheme();
chart.setBackgroundPaint(Color.white);
JFrame main = new JFrame("NATEXmische :: Hauptdialog");
main.setSize(500, 75) ;
main.setLocation(190, 0);
main.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
JButton drehenbutton = new JButton("Drehen");
main.add(BorderLayout.SOUTH, drehenbutton);
drehenbutton.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
// Get a DOMImplementation and create an XML document
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// draw the chart in the SVG generator
chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 500, 500));
// Write svg file
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream("NATEXmische.svg");
} catch (FileNotFoundException e5) {
// TODO Auto-generated catch block
e5.printStackTrace();
}
Writer out = null;
try {
out = new OutputStreamWriter(outputStream, "UTF-8");
} catch (UnsupportedEncodingException e4) {
// TODO Auto-generated catch block
e4.printStackTrace();
}
try {
svgGenerator.stream(out, true /* use css */);
} catch (SVGGraphics2DIOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
try {
outputStream.flush();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
outputStream.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
BufferedImage image = null;
try {
image = ImageIO.read(new File("NATEXmische.jpg"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
BufferedImage result = rotateImage(image, 45);
JFrame f = new JFrame();
ImageIcon i = new ImageIcon(result);
f.getContentPane().add(new JLabel(i));
f.pack();
f.setVisible(true);
}
private BufferedImage rotateImage(BufferedImage src, double degrees)
{
double w = src.getWidth();
double h = src.getHeight();
double sw = Math.ceil(src.getWidth() * Math.sqrt(2));
double sh = Math.ceil(src.getHeight() * Math.sqrt(2) / 2);
AffineTransform affineTransform = new AffineTransform();
affineTransform.translate(sw/2, sh/2);
affineTransform.rotate(Math.toRadians(degrees));
affineTransform.translate(-w/2, -h/2);
BufferedImage rotatedImage = new BufferedImage((int)sw, (int)sh, BufferedImage.TYPE_INT_BGR);
Graphics2D g = (Graphics2D)rotatedImage.createGraphics();
g.setTransform(affineTransform);
g.drawImage(src, 0, 0, null);
g.dispose();
return rotatedImage;
}
}
);
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu( "Datei" );
fileMenu.addSeparator();
fileMenu.add( new AbstractAction() {
/**
*
*/
private static final long serialVersionUID = 1L;
{ putValue( Action.NAME, "Beenden" );
putValue( Action.DISPLAYED_MNEMONIC_INDEX_KEY, 0 );
}
@Override public void actionPerformed( ActionEvent e ) {
System.exit( 0 );
}
} );
menuBar.add( fileMenu );
JMenu helpMenu = new JMenu( "Hilfe" );
helpMenu.add( new JMenuItem("Über...") );
menuBar.add( helpMenu );
main.setJMenuBar( menuBar );
main.pack();
main.setVisible(true);
}
/** * Creates a sample dataset */
private PieDataset createDataset() {
final DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Sektor 1", new Double(43.2));
dataset.setValue("Sektor 2", new Double(10.0));
dataset.setValue("Sektor 3", new Double(27.5));
dataset.setValue("Sektor 4", new Double(17.5));
dataset.setValue("Sektor 5", new Double(11.0));
dataset.setValue("Sektor 6", new Double(19.4));
dataset.setValue("Sektor 7", new Double(43.2));
dataset.setValue("Sektor 8", new Double(10.0));
dataset.setValue("Sektor 9", new Double(27.5));
dataset.setValue("Sektor 10", new Double(17.5));
dataset.setValue("Sektor 11", new Double(11.0));
dataset.setValue("Sektor 12", new Double(19.4));
[hier wird das Interface zu Farb und Größenauswahl initialisiert]
}
}
public class V_0_3_6
{ public static void main( String[] args ) throws UnsupportedEncodingException, FileNotFoundException, SVGGraphics2DIOException
{PieChartDemo5 aktuelleEinstellungenWindow = new PieChartDemo5("", "");
aktuelleEinstellungenWindow.setTitle("NATEXmische :: Aktuelle Einstellungen");
aktuelleEinstellungenWindow.setLocation(190, 85);
aktuelleEinstellungenWindow.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
aktuelleEinstellungenWindow.pack();
aktuelleEinstellungenWindow.setVisible(true);} }