1
0
Fork 0

PDF Export implemented

master
MrMcX vor 8 Jahren
Ursprung d1ee0362e6
Commit c5746dddcd

1
.gitignore vendored

@ -214,3 +214,4 @@ pip-log.txt
#Mr Developer
.mr.developer.cfg
/dist/

Binäre Datei nicht angezeigt.

Binäre Datei nicht angezeigt.

Binäre Datei nicht angezeigt.

Binäre Datei nicht angezeigt.

@ -3,17 +3,8 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/dungeon/Room.java</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/dungeon/Exit.java</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/.gitignore</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/dungeon/Dungeon.java</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/build.xml</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/nbproject/build-impl.xml</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/main/DungeonGeneratorUI.java</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/util/Counter.java</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/dungeon/Enemy.java</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/util/Dice.java</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/dungeon/Trap.java</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/Dungeon.java</file>
<file>file:/C:/Users/MrMcX/ownCloud/Rollenspiel/DSA/Meister/DungeonGenerator/src/eu/smoser/dungeongenerator/main/DungeonGeneratorUI.java</file>
</group>
</open-files>
</project-private>

@ -30,12 +30,12 @@ dist.jar=${dist.dir}/DungeonGenerator.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.itext-2.1.7.jar=lib/itext-2.1.7.jar
file.reference.jgraph-5.13.0.0.jar=lib/jgraph-5.13.0.0.jar
file.reference.jgrapht-core-0.9.2.jar=lib/jgrapht-core-0.9.2.jar
file.reference.jgrapht-demo-0.9.2.jar=lib/jgrapht-demo-0.9.2.jar
file.reference.jgrapht-ext-0.9.2-uber.jar=lib/jgrapht-ext-0.9.2-uber.jar
file.reference.jgrapht-ext-0.9.2.jar=lib/jgrapht-ext-0.9.2.jar
file.reference.jgraphx-2.0.0.1.jar=lib/jgraphx-2.0.0.1.jar
file.reference.pdfbox-app-2.0.2.jar=lib/pdfbox-app-2.0.2.jar
file.reference.resources-images=resources/images
includes=**
jar.archive.disabled=${jnlp.enabled}
@ -43,13 +43,13 @@ jar.compress=false
jar.index=${jnlp.enabled}
javac.classpath=\
${libs.absolutelayout.classpath}:\
${file.reference.resources-images}:\
${file.reference.jgraph-5.13.0.0.jar}:\
${file.reference.jgrapht-core-0.9.2.jar}:\
${file.reference.jgrapht-demo-0.9.2.jar}:\
${file.reference.jgrapht-ext-0.9.2-uber.jar}:\
${file.reference.jgrapht-ext-0.9.2.jar}:\
${file.reference.jgraphx-2.0.0.1.jar}:\
${file.reference.resources-images}
${file.reference.itext-2.1.7.jar}:\
${file.reference.pdfbox-app-2.0.2.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false

@ -21,42 +21,70 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuNewActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="jMenuSave">
<Menu class="javax.swing.JMenu" name="jMenuDescription">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+S"/>
</Property>
<Property name="text" type="java.lang.String" value="Beschreibung speichern"/>
<Property name="text" type="java.lang.String" value="Beschreibung exportieren"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuDescriptionActionPerformed"/>
</Events>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="jMenuDescTxt">
<Properties>
<Property name="text" type="java.lang.String" value="Textdokument"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuSaveActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuDescTxtActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="jMenuDescPdf">
<Properties>
<Property name="text" type="java.lang.String" value="PDF-Dokument"/>
</Properties>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="jMenuGraph">
<Properties>
<Property name="text" type="java.lang.String" value="Graph exportieren"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="jMenuExport">
<MenuItem class="javax.swing.JMenuItem" name="jMenuGraphGml">
<Properties>
<Property name="text" type="java.lang.String" value=".GML-Datei"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuExportActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuGraphGmlActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="jMenuImage">
<MenuItem class="javax.swing.JMenuItem" name="jMenuGraphPng">
<Properties>
<Property name="text" type="java.lang.String" value="Bilddatei"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuImageActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuGraphPngActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="jMenuGraphPdf">
<Properties>
<Property name="text" type="java.lang.String" value="PDF-Dokument"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuGraphPdfActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<MenuItem class="javax.swing.JMenuItem" name="jMenuPdf">
<Properties>
<Property name="text" type="java.lang.String" value="PDF erstellen"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuPdfActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="jMenuClose">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
@ -229,9 +257,6 @@
<Properties>
<Property name="text" type="java.lang.String" value="&lt;html&gt;&#xa;&lt;b&gt;Experimenteller Modus&lt;/b&gt;&lt;br/&gt;&#xa;schr&#xe4;nkt Raumzahl nicht direkt ein, sondern &#xe4;ndert die Zufallsfunktion so, dass ihr Erwartungswert der Raumanzahl entspricht"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jCheckBoxExpActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>

@ -23,10 +23,17 @@
*/
package eu.smoser.dungeongenerator.main;
import com.lowagie.text.BadElementException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import eu.smoser.dungeongenerator.dungeon.Dungeon;
import javax.swing.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.*;
@ -34,12 +41,20 @@ import java.util.logging.*;
import com.mxgraph.layout.*;
import com.mxgraph.util.*;
import com.mxgraph.swing.mxGraphComponent;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.HeadlessException;
import java.awt.Label;
import java.nio.file.*;
import javax.imageio.ImageIO;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.jgrapht.UndirectedGraph;
import org.jgrapht.ext.*;
import java.awt.image.BufferedImage;
import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.multipdf.PDFMergerUtility;
/**
*
@ -95,10 +110,14 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
jMenuBar = new javax.swing.JMenuBar();
jMenu = new javax.swing.JMenu();
jMenuNew = new javax.swing.JMenuItem();
jMenuSave = new javax.swing.JMenuItem();
jMenuDescription = new javax.swing.JMenu();
jMenuDescTxt = new javax.swing.JMenuItem();
jMenuDescPdf = new javax.swing.JMenuItem();
jMenuGraph = new javax.swing.JMenu();
jMenuExport = new javax.swing.JMenuItem();
jMenuImage = new javax.swing.JMenuItem();
jMenuGraphGml = new javax.swing.JMenuItem();
jMenuGraphPng = new javax.swing.JMenuItem();
jMenuGraphPdf = new javax.swing.JMenuItem();
jMenuPdf = new javax.swing.JMenuItem();
jMenuClose = new javax.swing.JMenuItem();
jMenuHelp = new javax.swing.JMenu();
jMenuItemHelp = new javax.swing.JMenuItem();
@ -137,11 +156,6 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
jPanelSettings.add(filler1);
jCheckBoxExp.setText("<html>\n<b>Experimenteller Modus</b><br/>\nschränkt Raumzahl nicht direkt ein, sondern ändert die Zufallsfunktion so, dass ihr Erwartungswert der Raumanzahl entspricht");
jCheckBoxExp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBoxExpActionPerformed(evt);
}
});
jPanelSettings.add(jCheckBoxExp);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
@ -211,37 +225,64 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
});
jMenu.add(jMenuNew);
jMenuSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
jMenuSave.setText("Beschreibung speichern");
jMenuSave.setEnabled(false);
jMenuSave.addActionListener(new java.awt.event.ActionListener() {
jMenuDescription.setText("Beschreibung exportieren");
jMenuDescription.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuSaveActionPerformed(evt);
jMenuDescriptionActionPerformed(evt);
}
});
jMenu.add(jMenuSave);
jMenuDescTxt.setText("Textdokument");
jMenuDescTxt.setEnabled(false);
jMenuDescTxt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuDescTxtActionPerformed(evt);
}
});
jMenuDescription.add(jMenuDescTxt);
jMenuDescPdf.setText("PDF-Dokument");
jMenuDescription.add(jMenuDescPdf);
jMenu.add(jMenuDescription);
jMenuGraph.setText("Graph exportieren");
jMenuGraph.setEnabled(false);
jMenuExport.setText(".GML-Datei");
jMenuExport.addActionListener(new java.awt.event.ActionListener() {
jMenuGraphGml.setText(".GML-Datei");
jMenuGraphGml.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuGraphGmlActionPerformed(evt);
}
});
jMenuGraph.add(jMenuGraphGml);
jMenuGraphPng.setText("Bilddatei");
jMenuGraphPng.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuExportActionPerformed(evt);
jMenuGraphPngActionPerformed(evt);
}
});
jMenuGraph.add(jMenuExport);
jMenuGraph.add(jMenuGraphPng);
jMenuImage.setText("Bilddatei");
jMenuImage.addActionListener(new java.awt.event.ActionListener() {
jMenuGraphPdf.setText("PDF-Dokument");
jMenuGraphPdf.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuImageActionPerformed(evt);
jMenuGraphPdfActionPerformed(evt);
}
});
jMenuGraph.add(jMenuImage);
jMenuGraph.add(jMenuGraphPdf);
jMenu.add(jMenuGraph);
jMenuPdf.setText("PDF erstellen");
jMenuPdf.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuPdfActionPerformed(evt);
}
});
jMenu.add(jMenuPdf);
jMenuClose.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
jMenuClose.setText("Beenden");
jMenuClose.addActionListener(new java.awt.event.ActionListener() {
@ -332,16 +373,16 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
jLabelStatus2.setText("Type: " + type.toString());
jLabelStatus3.setText("Mode: " + mode.toString());
jMenuSave.setEnabled(true);
jMenuNew.setEnabled(true);
jMenuDescription.setEnabled(true);
jMenuGraph.setEnabled(true);
CardLayout cl = (CardLayout) jPanelCards.getLayout();
cl.show(jPanelCards, "show");
}//GEN-LAST:event_jButtonGenerateActionPerformed
private void jMenuNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuNewActionPerformed
jMenuSave.setEnabled(false);
jMenuNew.setEnabled(false);
jMenuDescription.setEnabled(false);
jMenuGraph.setEnabled(false);
CardLayout cl = (CardLayout) jPanelCards.getLayout();
cl.show(jPanelCards, "new");
@ -351,7 +392,7 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
jLabelStatus3.setText("Mode: -");
}//GEN-LAST:event_jMenuNewActionPerformed
private void jMenuSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuSaveActionPerformed
private void jMenuDescTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuDescTxtActionPerformed
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Textdateien", "txt");
fileChooser.setFileFilter(filter);
@ -377,9 +418,9 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
Logger.getLogger(DungeonGeneratorUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_jMenuSaveActionPerformed
}//GEN-LAST:event_jMenuDescTxtActionPerformed
private void jMenuExportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuExportActionPerformed
private void jMenuGraphGmlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuGraphGmlActionPerformed
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Graph Modelling Files", "gml");
fileChooser.setFileFilter(filter);
@ -409,9 +450,9 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
Logger.getLogger(DungeonGeneratorUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_jMenuExportActionPerformed
}//GEN-LAST:event_jMenuGraphGmlActionPerformed
private void jMenuImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuImageActionPerformed
private void jMenuGraphPngActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuGraphPngActionPerformed
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Bilddateien", ".png");
fileChooser.setFileFilter(filter);
@ -430,14 +471,14 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
}
file.delete();
}
BufferedImage image = mxCellRenderer.createBufferedImage(mGraphComponent.getGraph(), null, 1, Color.WHITE, true, null);
BufferedImage image = mxCellRenderer.createBufferedImage(mGraphComponent.getGraph(), null, 10, Color.WHITE, true, null);
ImageIO.write(image, "PNG", file);
JOptionPane.showMessageDialog(this, "Gespeichert!");
} catch (IOException ex) {
Logger.getLogger(DungeonGeneratorUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_jMenuImageActionPerformed
}//GEN-LAST:event_jMenuGraphPngActionPerformed
private void jMenuItemAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAboutActionPerformed
ResourceBundle vprops = ResourceBundle.getBundle("version", Locale.getDefault());
@ -475,13 +516,6 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
+ "<html>Icons made by <a href='http://www.flaticon.com/authors/revicon'>Revicon</a>", "Über", JOptionPane.QUESTION_MESSAGE);
}//GEN-LAST:event_jMenuItemAboutActionPerformed
private void jCheckBoxExpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxExpActionPerformed
int a = JOptionPane.showConfirmDialog(this, "Diese Option kann zu einer Endlosschleife führen", "Achtung", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (a == JOptionPane.CANCEL_OPTION) {
jCheckBoxExp.setSelected(false);
}
}//GEN-LAST:event_jCheckBoxExpActionPerformed
private void jMenuItemContactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemContactActionPerformed
try {
Desktop.getDesktop().mail(new URI("mailto:info@smoser.eu?subject=DungeonGenerator"));
@ -506,6 +540,128 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
}
}//GEN-LAST:event_jMenuItemGithubActionPerformed
private void jMenuPdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuPdfActionPerformed
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Portable Document Format", ".pdf");
fileChooser.setFileFilter(filter);
fileChooser.setDialogTitle("Speicherort wählen");
int userSelection = fileChooser.showSaveDialog(this);
if (userSelection == JFileChooser.APPROVE_OPTION) {
try {
File file = fileChooser.getSelectedFile();
if (!file.getName().endsWith(".pdf")) {
file = new File(file.getCanonicalPath() + ".pdf");
}
if (file.exists()) {
int result = JOptionPane.showConfirmDialog(this, "Existierende Datei überschreiben?");
if (result != JOptionPane.YES_OPTION) {
return;
}
file.delete();
}
File tmpDesc = File.createTempFile("desc", ".pdf");
File tmpGraph = File.createTempFile("graph", ".pdf");
CreateDescPDF(tmpDesc);
CreateGraphPDF(tmpGraph);
PDFMergerUtility merger = new PDFMergerUtility();
merger.setDestinationFileName(file.getCanonicalPath());
merger.addSource(tmpGraph);
merger.addSource(tmpDesc);
merger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
tmpDesc.delete();
tmpGraph.delete();
JOptionPane.showMessageDialog(this, "Gespeichert!");
} catch (IOException | HeadlessException | DocumentException ex) {
Logger.getLogger(DungeonGeneratorUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_jMenuPdfActionPerformed
private void jMenuGraphPdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuGraphPdfActionPerformed
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Portable Document Format", ".pdf");
fileChooser.setFileFilter(filter);
fileChooser.setDialogTitle("Speicherort wählen");
int userSelection = fileChooser.showSaveDialog(this);
if (userSelection == JFileChooser.APPROVE_OPTION) {
try {
File file = fileChooser.getSelectedFile();
if (!file.getName().endsWith(".pdf")) {
file = new File(file.getCanonicalPath() + ".pdf");
}
if (file.exists()) {
int result = JOptionPane.showConfirmDialog(this, "Existierende Datei überschreiben?");
if (result != JOptionPane.YES_OPTION) {
return;
}
file.delete();
}
CreateGraphPDF(file);
JOptionPane.showMessageDialog(this, "Gespeichert!");
} catch (IOException | HeadlessException | DocumentException ex) {
Logger.getLogger(DungeonGeneratorUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_jMenuGraphPdfActionPerformed
private void jMenuDescriptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuDescriptionActionPerformed
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Portable Document Format", ".pdf");
fileChooser.setFileFilter(filter);
fileChooser.setDialogTitle("Speicherort wählen");
int userSelection = fileChooser.showSaveDialog(this);
if (userSelection == JFileChooser.APPROVE_OPTION) {
try {
File file = fileChooser.getSelectedFile();
if (!file.getName().endsWith(".pdf")) {
file = new File(file.getCanonicalPath() + ".pdf");
}
if (file.exists()) {
int result = JOptionPane.showConfirmDialog(this, "Existierende Datei überschreiben?");
if (result != JOptionPane.YES_OPTION) {
return;
}
file.delete();
}
CreateDescPDF(file);
JOptionPane.showMessageDialog(this, "Gespeichert!");
} catch (IOException | HeadlessException | DocumentException ex) {
Logger.getLogger(DungeonGeneratorUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_jMenuDescriptionActionPerformed
private void CreateGraphPDF(File file) throws BadElementException, IOException, DocumentException {
Document document = new Document(PageSize.A4);
Image image = Image.getInstance(mxCellRenderer.createBufferedImage(mGraphComponent.getGraph(), null, 10, Color.WHITE, true, null), Color.WHITE);
image.scaleToFit(document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(), document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin());
PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
document.add(image);
document.close();
}
private void CreateDescPDF(File file) throws BadElementException, IOException, DocumentException {
Document document = new Document(PageSize.A4);
Image image = Image.getInstance(mxCellRenderer.createBufferedImage(mGraphComponent.getGraph(), null, 10, Color.WHITE, true, null), Color.WHITE);
image.scaleToFit(document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(), document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin());
PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
Font myfont = new Font();
myfont.setStyle(Font.NORMAL);
myfont.setSize(11);
document.add(new Paragraph("\n"));
String[] outputString = mDungeon.toString().split("\n");
for (String s : outputString) {
Paragraph para = new Paragraph(s + "\n", myfont);
para.setAlignment(Element.ALIGN_JUSTIFIED);
document.add(para);
}
document.close();
}
/**
* @param args the command line arguments
*/
@ -580,16 +736,20 @@ public class DungeonGeneratorUI extends javax.swing.JFrame {
private javax.swing.JMenu jMenu;
private javax.swing.JMenuBar jMenuBar;
private javax.swing.JMenuItem jMenuClose;
private javax.swing.JMenuItem jMenuExport;
private javax.swing.JMenuItem jMenuDescPdf;
private javax.swing.JMenuItem jMenuDescTxt;
private javax.swing.JMenu jMenuDescription;
private javax.swing.JMenu jMenuGraph;
private javax.swing.JMenuItem jMenuGraphGml;
private javax.swing.JMenuItem jMenuGraphPdf;
private javax.swing.JMenuItem jMenuGraphPng;
private javax.swing.JMenu jMenuHelp;
private javax.swing.JMenuItem jMenuImage;
private javax.swing.JMenuItem jMenuItemAbout;
private javax.swing.JMenuItem jMenuItemContact;
private javax.swing.JMenuItem jMenuItemGithub;
private javax.swing.JMenuItem jMenuItemHelp;
private javax.swing.JMenuItem jMenuNew;
private javax.swing.JMenuItem jMenuSave;
private javax.swing.JMenuItem jMenuPdf;
private javax.swing.JPanel jPanelCardDraw;
private javax.swing.JPanel jPanelCardNew;
private javax.swing.JPanel jPanelCardShow;

@ -1,4 +1,4 @@
#Sat, 10 Sep 2016 19:10:07 +0200
BUILDNUMBER=9
BUILDDATE=2016-09-10 19\:10\:07 MESZ
#Sun, 11 Sep 2016 19:38:34 +0200
BUILDNUMBER=10
BUILDDATE=2016-09-11 19\:38\:33 MESZ

Laden…
Abbrechen
Speichern