- previewer is internationalized - translations included - support for printing git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193273 13f79535-47bb-0310-9956-ffa450edef68tags/pre-columns
@@ -29,8 +29,9 @@ import java.io.FileWriter; | |||
import java.io.PrintWriter; | |||
import java.io.IOException; | |||
import java.io.FileNotFoundException; | |||
import java.io.FileInputStream; | |||
import java.net.URL; | |||
import java.util.*; | |||
@@ -41,34 +42,85 @@ import java.net.URL; | |||
public class AWTCommandLine { | |||
public AWTCommandLine(AWTRenderer aRenderer) { | |||
public static String DEFAULT_TRANSLATION_PATH | |||
= "../viewer/resources/resources." + | |||
System.getProperty("user.language"); | |||
PreviewDialog frame = new PreviewDialog(aRenderer); | |||
frame.validate(); | |||
// center window | |||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | |||
Dimension frameSize = frame.getSize(); | |||
if (frameSize.height > screenSize.height) | |||
frameSize.height = screenSize.height; | |||
if (frameSize.width > screenSize.width) | |||
frameSize.width = screenSize.width; | |||
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); | |||
frame.setVisible(true); | |||
private Translator resource; | |||
public AWTCommandLine(String srcFile, String translationPath) { | |||
resource = getResourceBundle(translationPath); | |||
String messPath = new File(translationPath).getAbsoluteFile().getParent(); | |||
if (!messPath.endsWith(System.getProperty("file.separator"))) | |||
messPath += System.getProperty("file.separator"); | |||
messPath += "messages." + System.getProperty("user.language"); | |||
System.out.println("Set messages resource: " + messPath); | |||
UserMessage.setTranslator(getResourceBundle(messPath)); | |||
resource.setMissingEmphasized(false); | |||
if (!resource.isSourceFound()) | |||
UserMessage.show("TRANSLATION_SOURCE_NOT_FOUND", | |||
new File(translationPath).getAbsolutePath()); | |||
AWTRenderer renderer = new AWTRenderer(resource); | |||
PreviewDialog frame = createPreviewDialog(renderer, resource); | |||
renderer.setProgressListener(frame); | |||
//init parser | |||
frame.progress(resource.getString("Init parser") + " ..."); | |||
Parser parser = createParser(); | |||
if (parser == null) { | |||
System.err.println("ERROR: Unable to create SAX parser"); | |||
System.exit(1); | |||
} | |||
try { | |||
Driver driver = new Driver(); | |||
driver.setRenderer(renderer); | |||
// init mappings: time | |||
frame.progress(resource.getString("Init mappings") + " ..."); | |||
driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); | |||
driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); | |||
// build FO tree: time | |||
frame.progress(resource.getString("Build FO tree") + " ..."); | |||
driver.buildFOTree(parser, fileInputSource(srcFile)); | |||
// layout FO tree: time | |||
frame.progress(resource.getString("Layout FO tree") + " ..."); | |||
driver.format(); | |||
// render: time | |||
frame.progress(resource.getString("Render") + " ..."); | |||
driver.render(); | |||
frame.progress(resource.getString("Show")); | |||
} catch (Exception e) { | |||
System.err.println("FATAL ERROR: " + e.getMessage()); | |||
e.printStackTrace(); | |||
System.exit(1); | |||
} | |||
} | |||
/** | |||
* creates a SAX parser, using the value of org.xml.sax.parser | |||
* defaulting to org.apache.xerces.parsers.SAXParser | |||
* | |||
* @return the created SAX parser | |||
*/ | |||
static Parser createParser() { | |||
String parserClassName = | |||
System.getProperty("org.xml.sax.parser"); | |||
if (parserClassName == null) { | |||
parserClassName = "org.apache.xerces.parsers.SAXParser"; | |||
parserClassName = "com.jclark.xml.sax.Driver"; | |||
} | |||
System.err.println("using SAX parser " + parserClassName); | |||
@@ -88,6 +140,26 @@ public class AWTCommandLine { | |||
return null; | |||
} | |||
protected PreviewDialog createPreviewDialog(AWTRenderer renderer, Translator res) { | |||
PreviewDialog frame = new PreviewDialog(renderer, res); | |||
frame.validate(); | |||
// center window | |||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | |||
Dimension frameSize = frame.getSize(); | |||
if (frameSize.height > screenSize.height) | |||
frameSize.height = screenSize.height; | |||
if (frameSize.width > screenSize.width) | |||
frameSize.width = screenSize.width; | |||
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); | |||
frame.setVisible(true); | |||
return frame; | |||
} | |||
/** | |||
* create an InputSource from a file name | |||
* | |||
@@ -114,6 +186,17 @@ public class AWTCommandLine { | |||
} | |||
private SecureResourceBundle getResourceBundle(String path) { | |||
FileInputStream in = null; | |||
try { | |||
in = new FileInputStream(path); | |||
} catch(Exception ex) { | |||
System.out.println("Abgefangene Exception: " + ex.getMessage()); | |||
} | |||
return new SecureResourceBundle(in); | |||
} | |||
/* main | |||
*/ | |||
@@ -125,52 +208,34 @@ public class AWTCommandLine { | |||
} | |||
String srcPath = null; | |||
String translationFile = null; | |||
String imageDir = null; | |||
System.err.println(Version.getVersion()); | |||
if (args.length == 1) { | |||
srcPath = args[0]; | |||
} | |||
else { | |||
System.err.println("usage: java " + | |||
"AWTCommandLine " + | |||
"formatting-object-file"); | |||
if (args.length < 1 || args.length > 3) { | |||
System.err.println("usage: java AWTCommandLine " + | |||
"formatting-object-file [translation-file] " + | |||
"[image-dir]"); | |||
System.exit(1); | |||
} | |||
srcPath = args[0]; | |||
if (args.length > 1) { | |||
translationFile = args[1]; | |||
} | |||
if (args.length > 2) { | |||
imageDir = args[2]; | |||
if (!imageDir.endsWith(System.getProperty("file.separator"))) | |||
imageDir += System.getProperty("file.separator"); | |||
Command.IMAGE_DIR = imageDir; | |||
} | |||
AWTRenderer renderer = new AWTRenderer(); | |||
new AWTCommandLine(renderer); | |||
//init parser | |||
Parser parser = createParser(); | |||
if (parser == null) { | |||
System.err.println("ERROR: Unable to create SAX parser"); | |||
System.exit(1); | |||
} | |||
try { | |||
Driver driver = new Driver(); | |||
driver.setRenderer(renderer); | |||
// init mappings: time | |||
driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); | |||
driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); | |||
// build FO tree: time | |||
driver.buildFOTree(parser, fileInputSource(srcPath)); | |||
// layout FO tree: time | |||
driver.format(); | |||
if (translationFile == null) | |||
translationFile = DEFAULT_TRANSLATION_PATH; | |||
// render: time | |||
driver.render(); | |||
} catch (Exception e) { | |||
System.err.println("FATAL ERROR: " + e.getMessage()); | |||
System.exit(1); | |||
} | |||
new AWTCommandLine(srcPath, translationFile); | |||
} // main | |||
} // AWTCommandLine |
@@ -69,7 +69,7 @@ import java.net.URL; | |||
* mainline class. | |||
* | |||
* Gets input and output filenames from the command line. | |||
* Creates a SAX Parser (defaulting to XP). | |||
* Creates a SAX Parser (defaulting to Xerces). | |||
* | |||
*/ | |||
public class CommandLine { |
@@ -9,12 +9,16 @@ package org.apache.fop.render.awt; | |||
Stanislav Gorkhover: Stanislav.Gorkhover@af-software.de | |||
*/ | |||
import org.apache.fop.layout.*; | |||
import org.apache.fop.datatypes.*; | |||
import org.apache.fop.image.*; | |||
import org.apache.fop.svg.*; | |||
import org.apache.fop.render.pdf.*; | |||
import org.apache.fop.viewer.*; | |||
import org.apache.fop.apps.*; | |||
import java.awt.*; | |||
@@ -23,20 +27,28 @@ import java.awt.geom.*; | |||
import java.awt.font.*; | |||
import java.util.*; | |||
import java.io.*; | |||
import java.beans.*; | |||
import javax.swing.*; | |||
import java.awt.print.*; | |||
public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
public class AWTRenderer implements org.apache.fop.render.Renderer, Printable, Pageable { | |||
protected int pageWidth = 0; | |||
protected int pageHeight = 0; | |||
protected double scaleFactor = 100.0; | |||
protected int pageNumber = 0; | |||
protected AreaTree tree; | |||
protected ProgressListener progressListener = null; | |||
protected Translator res = null; | |||
protected Hashtable fontNames = new Hashtable(); | |||
protected Hashtable fontStyles = new Hashtable(); | |||
// Key - Font name, Value - java Font name. | |||
protected static Hashtable JAVA_FONT_NAMES; | |||
protected Graphics2D graphics = null; | |||
@@ -69,7 +81,21 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
private int currentAreaContainerXPosition = 0; | |||
public AWTRenderer() { | |||
// String oldFontName = null; | |||
static { | |||
JAVA_FONT_NAMES = new Hashtable(); | |||
JAVA_FONT_NAMES.put("Times", "serif"); | |||
JAVA_FONT_NAMES.put("Times-Roman", "serif"); | |||
JAVA_FONT_NAMES.put("Courier", "monospaced"); | |||
JAVA_FONT_NAMES.put("Helvetica", "sansserif"); | |||
// JAVA_FONT_NAMES.put("Serif", "sansserif"); | |||
} | |||
public AWTRenderer(Translator aRes) { | |||
res = aRes; | |||
} | |||
public void setGraphics(Graphics2D g) { | |||
@@ -137,13 +163,15 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
public void render(AreaTree areaTree, PrintWriter writer) throws IOException { | |||
tree = areaTree; | |||
documentPanel.setAreaTree(areaTree); | |||
documentPanel.setPageCount(areaTree.getPages().size()); | |||
documentPanel.setPageNumber(0); | |||
documentPanel.updateSize(pageNumber, scaleFactor/100.0); | |||
render(areaTree, 0); | |||
} | |||
public void render(AreaTree areaTree, int aPageNumber) throws IOException { | |||
tree = areaTree; | |||
Page page = (Page)areaTree.getPages().elementAt(aPageNumber); | |||
pageWidth = (int)((float)page.getWidth() / 1000f); | |||
@@ -206,6 +234,17 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
int ry = this.currentYPosition; | |||
int w = area.getContentWidth(); | |||
int h = area.getHeight(); | |||
ColorType bg = area.getBackgroundColor(); | |||
if ((bg != null) && (bg.alpha() == 0)) { | |||
Color oldColor = graphics.getColor(); | |||
// Color bgColor = new Color(bg.red(), bg.green(), bg.blue()); | |||
Color bgColor = colorType2Color(bg); | |||
graphics.setColor(bgColor); | |||
graphics.fillRect((int)(rx / 1000f), (int)(pageHeight - ry/ 1000f), | |||
(int)(w / 1000f), (int)(h / 1000f)); | |||
graphics.setColor(oldColor); | |||
} | |||
Enumeration e = area.getChildren().elements(); | |||
while (e.hasMoreElements()) { | |||
org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement(); | |||
@@ -215,12 +254,13 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
public void setupFontInfo(FontInfo fontInfo) { | |||
FontSetup.setup(fontInfo); | |||
FontSetup.setup(fontInfo); | |||
Hashtable hash = fontInfo.getFonts(); | |||
org.apache.fop.render.pdf.Font f; | |||
String name; | |||
Object key; | |||
int fontStyle; | |||
for (Enumeration e = hash.keys(); e.hasMoreElements();) { | |||
fontStyle = java.awt.Font.PLAIN; | |||
key = e.nextElement(); | |||
@@ -271,7 +311,7 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
String path = img.gethref(); | |||
// path = "c:/any.gif"; | |||
ImageIcon icon = new ImageIcon(path); | |||
ImageIcon icon = new ImageIcon(path); | |||
Image imgage = icon.getImage(); | |||
@@ -282,22 +322,12 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
null); | |||
currentYPosition -= h; | |||
/* int xObjectNum = this.pdfDoc.addImage(img); | |||
currentStream.add("ET\nq\n" + (img.getWidth()/1000f) + " 0 0 " + | |||
(img.getHeight()/1000f) + " " + | |||
((x + img.getX())/1000f) + " " + | |||
(((y - h) - img.getY())/1000f) + " cm\n" + | |||
"/Im" + xObjectNum + " Do\nQ\nBT\n"); | |||
*/ | |||
} | |||
public void renderInlineArea(InlineArea area) { | |||
public void renderInlineArea(InlineArea area) { | |||
char ch; | |||
StringBuffer pdf = new StringBuffer(); | |||
@@ -329,16 +359,34 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
String s = area.getText(); | |||
Color oldColor = graphics.getColor(); | |||
java.awt.Font oldFont = graphics.getFont(); | |||
java.awt.Font f = new java.awt.Font(fontNames.get(name).toString(), | |||
String aFontName = fontNames.get(name).toString(); | |||
aFontName = getJavaFontName(aFontName); | |||
java.awt.Font f = new java.awt.Font(aFontName, | |||
((Integer)fontStyles.get(name)).intValue(), | |||
(int)(size / 1000f)); | |||
graphics.setColor(new Color(red, green, blue)); | |||
/* | |||
Die KLasse TextLayout nimmt für die Ausgabe eigenen Schriftsatz, | |||
der i.R. breiter ist. Deshalb wird bis diese Tatsache sich geklärt/ | |||
geregelt hat weniger schöne Ausgabe über Graphics benutzt. | |||
*/ | |||
/* | |||
FontRenderContext newContext = new FontRenderContext(null, true, false); | |||
TextLayout layout = new TextLayout(s, f, newContext); | |||
layout.draw(graphics, rx / 1000f, (int)(pageHeight - bl / 1000f)); | |||
*/ | |||
graphics.setFont(f); | |||
graphics.drawString(s, rx / 1000f, (int)(pageHeight - bl / 1000f)); | |||
graphics.setFont(oldFont); | |||
graphics.setColor(oldColor); | |||
@@ -396,8 +444,6 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
(int)(w / 1000f), (int)(th / 1000f)); | |||
graphics.setColor(oldColor); | |||
} | |||
@@ -436,8 +482,17 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
} | |||
protected String getJavaFontName(String aName) { | |||
if (aName == null) | |||
return null; | |||
Object o = JAVA_FONT_NAMES.get(aName); | |||
return (o == null) ? aName : o.toString(); | |||
} | |||
public void setProducer(String producer) { | |||
// this.pdfDoc.setProducer(producer); | |||
} | |||
@@ -445,6 +500,54 @@ public class AWTRenderer implements org.apache.fop.render.Renderer { | |||
documentPanel = comp; | |||
} | |||
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { | |||
if (pageIndex >= tree.getPages().size()) | |||
return NO_SUCH_PAGE; | |||
Graphics2D oldGraphics = graphics; | |||
int oldPageNumber = pageNumber; | |||
graphics = (Graphics2D)g; | |||
Page aPage = (Page)tree.getPages().elementAt(pageIndex); | |||
renderPage(aPage); | |||
graphics = oldGraphics; | |||
return PAGE_EXISTS; | |||
} | |||
public int getNumberOfPages() { | |||
return tree.getPages().size(); | |||
} | |||
public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException { | |||
if (pageIndex >= tree.getPages().size()) | |||
return null; | |||
Page page = (Page)tree.getPages().elementAt(pageIndex); | |||
PageFormat pageFormat = new PageFormat(); | |||
Paper paper = new Paper(); | |||
paper.setImageableArea(0, 0, page.getWidth() / 1000d, page.getHeight() / 1000d); | |||
paper.setSize(page.getWidth() / 1000d, page.getHeight() / 1000d); | |||
pageFormat.setPaper(paper); | |||
return pageFormat; | |||
} | |||
public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException { | |||
return this; | |||
} | |||
public void setProgressListener(ProgressListener l) { | |||
progressListener = l; | |||
} | |||
public static Color colorType2Color(ColorType ct) { | |||
if (ct == null) | |||
return null; | |||
return new Color(ct.red(), ct.green(), ct.blue()); | |||
} | |||
} | |||
@@ -24,7 +24,7 @@ import java.io.File; | |||
*/ | |||
public class Command extends AbstractAction { | |||
public static final String IMAGE_DIR = "../viewer/images/"; | |||
public static String IMAGE_DIR = "../viewer/images/"; | |||
public Command(String name) { | |||
this(name, (ImageIcon)null); |
@@ -1,12 +1,5 @@ | |||
package org.apache.fop.viewer; | |||
/* | |||
originally contributed by | |||
Juergen Verwohlt: Juergen.Verwohlt@af-software.de, | |||
Rainer Steinkuhle: Rainer.Steinkuhle@af-software.de, | |||
Stanislav Gorkhover: Stanislav.Gorkhover@af-software.de | |||
*/ | |||
import java.awt.*; | |||
@@ -31,12 +24,14 @@ public class DocumentPanel extends JComponent { | |||
protected int docWidth; | |||
protected int docHeight; | |||
protected Color myColor = Color.lightGray; | |||
protected Color myColor; | |||
protected int pageCount = 0; | |||
public DocumentPanel(AWTRenderer aRenderer, PreviewDialog p) { | |||
previewDialog = p; | |||
renderer = aRenderer; | |||
renderer.setComponent(this); | |||
myColor = previewDialog.getBackground(); | |||
} | |||
public void updateSize(int aPageNumber, double aFactor) { | |||
@@ -46,6 +41,7 @@ public class DocumentPanel extends JComponent { | |||
Page aPage = (Page)areaTree.getPages().elementAt(aPageNumber); | |||
docWidth = aPage.getWidth() / 1000; | |||
docHeight = aPage.getHeight() / 1000; | |||
// Ruft paintComponent auf. | |||
setSize((int)(aFactor * aPage.getWidth() / 1000.0 + 2*V_BORDER), | |||
(int)(aFactor * aPage.getHeight()/ 1000.0 + 2*H_BORDER)); | |||
} | |||
@@ -83,7 +79,8 @@ public class DocumentPanel extends JComponent { | |||
return getSize(); | |||
} | |||
public void setPageCount(int pageCount) { | |||
public void setPageCount(int aPageCount) { | |||
pageCount = aPageCount; | |||
previewDialog.setPageCount(pageCount); | |||
} | |||
@@ -0,0 +1,79 @@ | |||
package org.apache.fop.viewer; | |||
import java.io.*; | |||
import java.util.*; | |||
/** | |||
* Erweitert Hashtable um die Methode load. | |||
* Die Zeilen der Textdatei, die mit # oder ! anfangen sind Kommentarzeilen. | |||
* Eine gültige Zeile ist entweder eine Kommentarzeile oder eine Zeile mit dem | |||
* Gleichheitszeichen "in der Mitte". | |||
* Die Klasse LoadableProperties lässt im Gegensatz zu der Klasse Properties die | |||
* Schlüsselwerte mit Leerzeichen zu. | |||
* | |||
* @version 02.12.99 | |||
* @author Stanislav.Gorkhover@af-software.de | |||
* | |||
*/ | |||
public class LoadableProperties extends Hashtable { | |||
public LoadableProperties() { | |||
super(); | |||
} | |||
public void load(InputStream inStream) throws IOException { | |||
BufferedReader in = new BufferedReader(new InputStreamReader(inStream, "8859_1")); | |||
String aKey; | |||
String aValue; | |||
int index; | |||
String line = getNextLine(in); | |||
while (line != null) { | |||
line = line.trim(); | |||
if (isValid(line)) { | |||
index = line.indexOf("="); | |||
aKey = line.substring(0, index); | |||
aValue = line.substring(index + 1); | |||
put(aKey, aValue); | |||
} | |||
line = getNextLine(in); | |||
} | |||
} | |||
private boolean isValid(String str) { | |||
if (str == null) | |||
return false; | |||
if (str.length() > 0) { | |||
if (str.startsWith("#") || str.startsWith("!")) { | |||
return false; | |||
} | |||
} | |||
else { | |||
return false; | |||
} | |||
int index = str.indexOf("="); | |||
if (index > 0 && str.length() > index) { | |||
return true; | |||
} | |||
else { | |||
System.out.println(getClass().getName() + ": load(): invalid line " + | |||
str + "." + " Character '=' missed."); | |||
return false; | |||
} | |||
} | |||
private String getNextLine(BufferedReader br) { | |||
try { | |||
return br.readLine(); | |||
} catch (Exception e) { | |||
return null; | |||
} | |||
} | |||
} |
@@ -0,0 +1,68 @@ | |||
package org.apache.fop.viewer; | |||
import java.lang.Exception; | |||
/** | |||
* Die Klasse <code>MessageException</code> ist eine Exception, die | |||
* mit einer Meldung und deren Parametern versehen werden kann. | |||
* Dadurch kann die Meldung über den Exception-Mechanismus an die | |||
* Aufrufer hochgereicht werden, bis schliesslich ein Aufrufer die | |||
* Meldung zur Anzeige bringt. | |||
* | |||
* @author Juergen.Verwohlt@af-software.de | |||
* @version 1.0 28.05.99 | |||
* | |||
*/ | |||
public class MessageException extends Exception { | |||
/** Angabe der auslösenden Exception, wie z.B. NullPointerException. | |||
* Dieses Feld ist optional. | |||
*/ | |||
protected Exception exception; | |||
/** | |||
* ID der Meldung, die für diese Exception ausgegeben werden soll | |||
*/ | |||
protected String messageId; | |||
/** | |||
* Parameterliste zur Meldung | |||
*/ | |||
protected String[] parameterList; | |||
// Konstruktoren | |||
public MessageException() { | |||
this("UNKNOWN_EXCEPTION"); | |||
} | |||
public MessageException(String aMessageId) { | |||
this(aMessageId, null); | |||
} | |||
public MessageException(String aMessageId, String[] aParameterList) { | |||
this(aMessageId, aParameterList, null); | |||
} | |||
public MessageException(String aMessageId, String[] aParameterList, Exception anException) { | |||
super(aMessageId); | |||
messageId = aMessageId; | |||
parameterList = aParameterList; | |||
exception = anException; | |||
} | |||
// Zugriffsmethoden | |||
public String getMessageId() { | |||
return messageId; | |||
} | |||
public String[] getParameterList() { | |||
return parameterList; | |||
} | |||
public Exception getException() { | |||
return exception; | |||
} | |||
} |
@@ -0,0 +1,230 @@ | |||
package org.apache.fop.viewer; | |||
import javax.swing.*; | |||
import java.beans.*; | |||
import java.io.*; | |||
import java.util.*; | |||
import java.awt.*; | |||
import java.awt.event.*; | |||
import org.apache.fop.apps.*; | |||
/** | |||
* Die Klasse <code>MessagesDialog</code> dient der Anzeige von Meldungen. | |||
* Die Klasse erweitert <code>JOptionPane</code> um die Möglichkeit, auf Knopfdruck | |||
* eine Detailanzeige einzublenden, in der z.B. bei Fehlern der StackTrace ausgegeben | |||
* werden kann. | |||
* | |||
* @author Juergen.Verwohlt@af-software.de | |||
* @version 1.0 09.06.99 | |||
*/ | |||
public class MessagesDialog extends JOptionPane { | |||
static Translator res; | |||
public static void setTranslator(Translator aRes) { | |||
res = aRes; | |||
iniConstants(); | |||
} | |||
static String DETAIL_OPTION; | |||
static String YES_OPTION; | |||
static String NO_OPTION; | |||
static String CANCEL_OPTION; | |||
static String OK_OPTION; | |||
static String[] defaultDetailOption; | |||
static String[] yesNoDetailOption; | |||
static String[] yesNoCancelDetailOption; | |||
static String[] okCancelDetailOption; | |||
static String[] defaultOption; | |||
static String[] yesNoOption; | |||
static String[] yesNoCancelOption; | |||
static String[] okCancelOption; | |||
private static void iniConstants() { | |||
DETAIL_OPTION = res.getString("Details"); | |||
YES_OPTION = res.getString("Yes"); | |||
NO_OPTION = res.getString("No"); | |||
CANCEL_OPTION = res.getString("Cancel"); | |||
OK_OPTION = res.getString("Ok"); | |||
defaultDetailOption = new String[] { OK_OPTION, DETAIL_OPTION }; | |||
yesNoDetailOption = new String[] { YES_OPTION, NO_OPTION, DETAIL_OPTION }; | |||
yesNoCancelDetailOption = new String[] { YES_OPTION, NO_OPTION, CANCEL_OPTION, DETAIL_OPTION }; | |||
okCancelDetailOption = new String[] { OK_OPTION, CANCEL_OPTION, DETAIL_OPTION }; | |||
defaultOption = new String[] { OK_OPTION }; | |||
yesNoOption = new String[] { YES_OPTION, NO_OPTION }; | |||
yesNoCancelOption = new String[] { YES_OPTION, NO_OPTION, CANCEL_OPTION }; | |||
okCancelOption = new String[] { OK_OPTION, CANCEL_OPTION }; | |||
} | |||
protected String detailInformation = null; | |||
protected JDialog dialog = null; | |||
protected boolean showsDetails = false; | |||
// MessagesDialog.showConfirmDialog(null,preparedMes,title, | |||
// optionTypeIndex,messageTypeIndex); | |||
public MessagesDialog(Object message, int messageType, int optionType, | |||
Icon icon, Object[] options, Object initialValue) { | |||
super(message, messageType, optionType, icon, options, initialValue); | |||
setMinimumSize(new Dimension(240, 96)); | |||
} | |||
public static int showConfirmDialog(Component parentComponent, Object message, | |||
String title, int optionType, int messageType) { | |||
Object[] options; | |||
switch (optionType) { | |||
case JOptionPane.YES_NO_OPTION: | |||
options = yesNoOption; break; | |||
case JOptionPane.YES_NO_CANCEL_OPTION: | |||
options = yesNoCancelOption; break; | |||
case JOptionPane.OK_CANCEL_OPTION: | |||
options = okCancelOption; break; | |||
default: | |||
options = defaultOption; | |||
} | |||
MessagesDialog pane = new MessagesDialog(message, messageType, | |||
JOptionPane.DEFAULT_OPTION, null, | |||
options, options[0]); | |||
pane.setInitialValue(options[0]); | |||
JDialog dialog = pane.createDialog(parentComponent, title); | |||
pane.setDialog(dialog); | |||
pane.selectInitialValue(); | |||
dialog.show(); | |||
Object selectedValue = pane.getValue(); | |||
if(selectedValue == null) | |||
return CLOSED_OPTION; | |||
if (selectedValue.equals(OK_OPTION)) | |||
return JOptionPane.OK_OPTION; | |||
if (selectedValue.equals(CANCEL_OPTION)) | |||
return JOptionPane.CANCEL_OPTION; | |||
if (selectedValue.equals(YES_OPTION)) | |||
return JOptionPane.YES_OPTION; | |||
if (selectedValue.equals(NO_OPTION)) | |||
return JOptionPane.NO_OPTION; | |||
return CLOSED_OPTION; | |||
} | |||
/** | |||
* Öffnet ein Dialogfenster, bei dem zusätzlich zu den spez. Buttons noch ein | |||
* 'Detail'-Button erscheint. Wird dieser Knopf vom Benutzer betätigt, erscheint | |||
* die übergebene Detailinformation in einem scrollbaren Bereich des Dialogs. | |||
*/ | |||
public static int showDetailDialog(Component parentComponent, Object message, String title, int optionType, | |||
int messageType, Icon icon, String newDetailInformation) { | |||
Object[] options; | |||
switch (optionType) { | |||
case JOptionPane.YES_NO_OPTION: | |||
options = yesNoDetailOption; break; | |||
case JOptionPane.YES_NO_CANCEL_OPTION: | |||
options = yesNoCancelDetailOption; break; | |||
case JOptionPane.OK_CANCEL_OPTION: | |||
options = okCancelDetailOption; break; | |||
default: | |||
options = defaultDetailOption; | |||
} | |||
MessagesDialog pane = new MessagesDialog(message, messageType, | |||
JOptionPane.DEFAULT_OPTION, icon, | |||
options, options[0]); | |||
pane.setDetailInformation(newDetailInformation); | |||
pane.setInitialValue(options[0]); | |||
JDialog dialog = pane.createDialog(parentComponent, title); | |||
pane.setDialog(dialog); | |||
pane.selectInitialValue(); | |||
dialog.show(); | |||
Object selectedValue = pane.getValue(); | |||
if(selectedValue == null) | |||
return CLOSED_OPTION; | |||
if (((String)selectedValue).equals(DETAIL_OPTION)) | |||
return CLOSED_OPTION; | |||
if (selectedValue.equals(OK_OPTION)) | |||
return JOptionPane.OK_OPTION; | |||
if (selectedValue.equals(CANCEL_OPTION)) | |||
return JOptionPane.CANCEL_OPTION; | |||
if (selectedValue.equals(YES_OPTION)) | |||
return JOptionPane.YES_OPTION; | |||
if (selectedValue.equals(NO_OPTION)) | |||
return JOptionPane.NO_OPTION; | |||
return CLOSED_OPTION; | |||
} | |||
/** | |||
* Die Methode fügt in den übergebenen Dialog eine scrollbare Textkomponente ein, | |||
* in der die Detailinformation angezeigt wird. | |||
* | |||
* @param JDialog dialog Der Dialog, in den die Textkomponente eingefügt werden soll | |||
*/ | |||
protected void displayDetails(JDialog dialog) { | |||
if (getDetailInformation() != null && dialog != null && showsDetails == false) { | |||
showsDetails = true; | |||
JScrollPane aScrollPane = new JScrollPane(); | |||
JTextArea aTextArea = new JTextArea(); | |||
StringWriter aStringWriter = new StringWriter(); | |||
aTextArea.setText(getDetailInformation()); | |||
aTextArea.setEditable(false); | |||
aScrollPane.getViewport().add(aTextArea, null); | |||
dialog.getContentPane().add(aScrollPane, BorderLayout.SOUTH); | |||
aScrollPane.setPreferredSize(new Dimension(320, 240)); | |||
dialog.pack(); | |||
} | |||
} | |||
// Zugriff | |||
public void setValue(Object aValue) { | |||
if (aValue != null && DETAIL_OPTION.equals(aValue)) | |||
displayDetails(getDialog()); | |||
else | |||
super.setValue(aValue); | |||
} | |||
public String getDetailInformation() { | |||
return detailInformation; | |||
} | |||
public void setDetailInformation(String aValue) { | |||
detailInformation = aValue; | |||
} | |||
public JDialog getDialog() { | |||
return dialog; | |||
} | |||
public void setDialog(JDialog aValue) { | |||
dialog = aValue; | |||
} | |||
} |
@@ -10,11 +10,13 @@ package org.apache.fop.viewer; | |||
import java.awt.*; | |||
import java.awt.print.*; | |||
import java.awt.event.*; | |||
import java.util.*; | |||
import javax.swing.*; | |||
import java.beans.PropertyChangeListener; | |||
import java.beans.*; | |||
import org.apache.fop.apps.AWTCommandLine; | |||
import org.apache.fop.layout.*; | |||
import org.apache.fop.render.awt.*; | |||
@@ -24,8 +26,9 @@ import org.apache.fop.render.awt.*; | |||
/** | |||
* Frame and User Interface for Preview | |||
*/ | |||
public class PreviewDialog extends JFrame { | |||
public class PreviewDialog extends JFrame implements ProgressListener { | |||
protected Translator res; | |||
protected int currentPage = 0; | |||
protected int pageCount = 0; | |||
@@ -34,32 +37,47 @@ public class PreviewDialog extends JFrame { | |||
protected IconToolBar toolBar = new IconToolBar(); | |||
protected Command printAction = new Command("Print", "Print");// { public void doit() {}} | |||
protected Command firstPageAction = new Command("First page", "firstpg") { public void doit() {goToFirstPage(null);}}; | |||
protected Command previousPageAction = new Command("Previous page", "prevpg") { public void doit() {goToPreviousPage(null);}}; | |||
protected Command nextPageAction = new Command("Next page", "nextpg") { public void doit() {goToNextPage(null);}}; | |||
protected Command lastPageAction = new Command("Last page", "lastpg") { public void doit() {goToLastPage(null);}}; | |||
protected Command printAction; | |||
protected Command firstPageAction; | |||
protected Command previousPageAction; | |||
protected Command nextPageAction; | |||
protected Command lastPageAction; | |||
protected JLabel zoomLabel = new JLabel(); //{public float getAlignmentY() { return 0.0f; }}; | |||
protected JComboBox scale = new JComboBox() {public float getAlignmentY() { return 0.5f; }}; | |||
protected JScrollPane previewArea = new JScrollPane(); | |||
protected JLabel statusBar = new JLabel(); | |||
// protected JLabel statusBar = new JLabel(); | |||
protected JPanel statusBar = new JPanel(); | |||
protected GridBagLayout statusBarLayout = new GridBagLayout(); | |||
protected JLabel statisticsStatus = new JLabel(); | |||
protected JLabel processStatus = new JLabel(); | |||
protected JLabel infoStatus = new JLabel(); | |||
protected DocumentPanel docPanel; | |||
public PreviewDialog(AWTRenderer aRenderer) { | |||
public PreviewDialog(AWTRenderer aRenderer, Translator aRes) { | |||
res = aRes; | |||
renderer = aRenderer; | |||
printAction = new Command(res.getString("Print"), "Print") { public void doit() {print();}}; | |||
firstPageAction = new Command(res.getString("First page"), "firstpg") { public void doit() {goToFirstPage(null);}}; | |||
previousPageAction = new Command(res.getString("Previous page"), "prevpg") { public void doit() {goToPreviousPage(null);}}; | |||
nextPageAction = new Command(res.getString("Next page"), "nextpg") { public void doit() {goToNextPage(null);}}; | |||
lastPageAction = new Command(res.getString("Last page"), "lastpg") { public void doit() {goToLastPage(null);}}; | |||
setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
this.setSize(new Dimension(379, 476)); | |||
previewArea.setMinimumSize(new Dimension(50, 50)); | |||
statusBar.setText(""); | |||
statusBar.setBackground(new Color(0, 0, 231)); | |||
this.setTitle("FOP: AWT-Preview"); | |||
this.setTitle("FOP: AWT-" + res.getString("Preview")); | |||
scale.addItem("25"); | |||
scale.addItem("50"); | |||
@@ -80,12 +98,11 @@ public class PreviewDialog extends JFrame { | |||
scale.setSelectedItem("100"); | |||
renderer.setScaleFactor(100.0); | |||
zoomLabel.setText("Zoom"); | |||
zoomLabel.setText(res.getString("Zoom")); | |||
this.setJMenuBar(setupMenue()); | |||
this.getContentPane().add(toolBar, BorderLayout.NORTH); | |||
this.getContentPane().add(statusBar, BorderLayout.SOUTH); | |||
toolBar.add(printAction); | |||
toolBar.addSeparator(); | |||
@@ -99,14 +116,33 @@ public class PreviewDialog extends JFrame { | |||
toolBar.add(scale, null); | |||
this.getContentPane().add(previewArea, BorderLayout.CENTER); | |||
this.getContentPane().add(statusBar, BorderLayout.SOUTH); | |||
docPanel = new DocumentPanel(renderer, this); | |||
statisticsStatus.setBorder(BorderFactory.createEtchedBorder()); | |||
processStatus.setBorder(BorderFactory.createEtchedBorder()); | |||
infoStatus.setBorder(BorderFactory.createEtchedBorder()); | |||
statusBar.setLayout(statusBarLayout); | |||
processStatus.setPreferredSize(new Dimension(200, 21)); | |||
statisticsStatus.setPreferredSize(new Dimension(100, 21)); | |||
infoStatus.setPreferredSize(new Dimension(100, 21)); | |||
processStatus.setMinimumSize(new Dimension(200, 21)); | |||
statisticsStatus.setMinimumSize(new Dimension(100, 21)); | |||
infoStatus.setMinimumSize(new Dimension(100, 21)); | |||
statusBar.add(processStatus, new GridBagConstraints(0, 0, 2, 1, 2.0, 0.0 | |||
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 5), 0, 0)); | |||
statusBar.add(statisticsStatus, new GridBagConstraints(2, 0, 1, 2, 1.0, 0.0 | |||
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 5), 0, 0)); | |||
statusBar.add(infoStatus, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0 | |||
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); | |||
docPanel = new DocumentPanel(renderer, this); | |||
previewArea.setSize(docPanel.getSize()); | |||
previewArea.getViewport().add(docPanel); | |||
statusBar.setText("FOTree --> AreaTree ..."); | |||
} | |||
@@ -117,7 +153,7 @@ public class PreviewDialog extends JFrame { | |||
JMenu subMenu; | |||
menuBar = new JMenuBar(); | |||
menu = new JMenu("File"); | |||
menu = new JMenu(res.getString("File")); | |||
subMenu = new JMenu("OutputFormat"); | |||
subMenu.add(new Command("mHTML")); | |||
subMenu.add(new Command("mPDF")); | |||
@@ -125,17 +161,17 @@ public class PreviewDialog extends JFrame { | |||
subMenu.add(new Command("mTEXT")); | |||
// menu.add(subMenu); | |||
// menu.addSeparator(); | |||
menu.add(new Command("Print")); | |||
menu.add(new Command(res.getString("Print")) {public void doit(){print();}}); | |||
menu.addSeparator(); | |||
menu.add(new Command("Exit") { public void doit() {dispose();}} ); | |||
menu.add(new Command(res.getString("Exit")){ public void doit() {dispose();}} ); | |||
menuBar.add(menu); | |||
menu = new JMenu("View"); | |||
menu.add(new Command("First page") { public void doit() {goToFirstPage(null);}} ); | |||
menu.add(new Command("Previous page") { public void doit() {goToPreviousPage(null);}} ); | |||
menu.add(new Command("Next page") { public void doit() {goToNextPage(null);}} ); | |||
menu.add(new Command("Last page") { public void doit() {goToLastPage(null);}} ); | |||
menu = new JMenu(res.getString("View")); | |||
menu.add(new Command(res.getString("First page")) { public void doit() {goToFirstPage(null);}} ); | |||
menu.add(new Command(res.getString("Previous page")) { public void doit() {goToPreviousPage(null);}} ); | |||
menu.add(new Command(res.getString("Next page")) { public void doit() {goToNextPage(null);}} ); | |||
menu.add(new Command(res.getString("Last page")) { public void doit() {goToLastPage(null);}} ); | |||
menu.addSeparator(); | |||
subMenu = new JMenu("Zoom"); | |||
subMenu = new JMenu(res.getString("Zoom")); | |||
subMenu.add(new Command("25%") { public void doit() {setScale(25.0);}} ); | |||
subMenu.add(new Command("50%") { public void doit() {setScale(50.0);}} ); | |||
subMenu.add(new Command("75%") { public void doit() {setScale(75.0);}} ); | |||
@@ -144,24 +180,22 @@ public class PreviewDialog extends JFrame { | |||
subMenu.add(new Command("200%") { public void doit() {setScale(200.0);}} ); | |||
menu.add(subMenu); | |||
menu.addSeparator(); | |||
menu.add(new Command("Default zoom") { public void doit() {setScale(100.0);}} ); | |||
menu.add(new Command(res.getString("Default zoom")) { public void doit() {setScale(100.0);}} ); | |||
menuBar.add(menu); | |||
menu = new JMenu("Help"); | |||
menu.add(new Command("Index")); | |||
menu = new JMenu(res.getString("Help")); | |||
menu.add(new Command(res.getString("Index"))); | |||
menu.addSeparator(); | |||
menu.add(new Command("Introduction")); | |||
menu.add(new Command(res.getString("Introduction"))); | |||
menu.addSeparator(); | |||
menu.add(new Command("About"){ public void doit() {startHelpAbout(null);}} ); | |||
menu.add(new Command(res.getString("About")){ public void doit() {startHelpAbout(null);}} ); | |||
menuBar.add(menu); | |||
return menuBar; | |||
} | |||
public void dispose() { | |||
System.exit(0); | |||
} | |||
//Aktion Hilfe | Info durchgeführt | |||
public void startHelpAbout(ActionEvent e) { | |||
@@ -178,7 +212,8 @@ public class PreviewDialog extends JFrame { | |||
docPanel.setPageNumber(number); | |||
repaint(); | |||
previewArea.repaint(); | |||
statusBar.setText("Page " + (number + 1) + " of " + pageCount); | |||
statisticsStatus.setText(res.getString("Page") + " " + (currentPage + 1) + " " + res.getString("of") + " " + | |||
pageCount); | |||
} | |||
/** | |||
@@ -223,21 +258,20 @@ public class PreviewDialog extends JFrame { | |||
goToPage(currentPage); | |||
} | |||
void print(ActionEvent e) { | |||
Properties p = null; | |||
void print() { | |||
Container parent = this.getRootPane(); | |||
while ( !( parent instanceof Frame )) parent = parent.getParent(); | |||
Frame f = (Frame)parent; | |||
PrinterJob pj = PrinterJob.getPrinterJob(); | |||
// Nicht nötig, Pageable get a Printable. | |||
// pj.setPrintable(renderer); | |||
pj.setPageable(renderer); | |||
PrintJob pj = f.getToolkit().getPrintJob(f, getTitle(), p); | |||
if(pj == null) return; | |||
Graphics pg = pj.getGraphics(); | |||
if (pg != null) { | |||
docPanel.paintAll(pg); | |||
pg.dispose(); | |||
if (pj.printDialog()) { | |||
try { | |||
pj.print(); | |||
} catch(PrinterException pe) { | |||
pe.printStackTrace(); | |||
} | |||
} | |||
pj.end(); | |||
} | |||
public void setScale(double scaleFactor) { | |||
@@ -267,26 +301,24 @@ public class PreviewDialog extends JFrame { | |||
public void setPageCount(int aPageCount) { | |||
pageCount = aPageCount; | |||
statusBar.setText("Page 1 of " + pageCount); | |||
statisticsStatus.setText(res.getString("Page") + " " + (currentPage + 1) + | |||
" " + res.getString("of") + " " + pageCount); | |||
} | |||
} // class PreviewDialog | |||
public void progress(int percentage) { | |||
processStatus.setText(percentage + "%"); | |||
} | |||
public void progress(int percentage, String message) { | |||
processStatus.setText(message + " " + percentage + "%"); | |||
} | |||
public void progress(String message) { | |||
processStatus.setText(message); | |||
} | |||
} // class PreviewDialog | |||
@@ -0,0 +1,17 @@ | |||
package org.apache.fop.viewer; | |||
/* | |||
originally contributed by | |||
Juergen Verwohlt: Juergen.Verwohlt@af-software.de, | |||
Rainer Steinkuhle: Rainer.Steinkuhle@af-software.de, | |||
Stanislav Gorkhover: Stanislav.Gorkhover@af-software.de | |||
*/ | |||
public interface ProgressListener { | |||
public void progress(int percentage); | |||
public void progress(String message); | |||
public void progress(int percentage, String message); | |||
} | |||
@@ -0,0 +1,97 @@ | |||
package org.apache.fop.viewer; | |||
import java.util.*; | |||
import java.io.*; | |||
/** | |||
* Die Klasse <code>SecureResourceBundle</code> ist ein Resourceundle, das im Falle eines fehlenden | |||
* Eintrages keinen Absturz verursacht, sondern die Meldung | |||
* <strong>Key <i>key</i> not found</strong> zurückgibt. | |||
* @see PropertyResourceBundle | |||
* | |||
* @author Stanislav.Gorkhover@af-software.de | |||
* @version 1.0 18.03.1999 | |||
*/ | |||
public class SecureResourceBundle extends ResourceBundle implements Translator { | |||
// Fehlende keys mit einer Meldung zurückgeben. | |||
private boolean isMissingEmphasized = false; | |||
//private Properties lookup = new Properties(); | |||
private LoadableProperties lookup = new LoadableProperties(); | |||
private boolean isSourceFound = true; | |||
public void setMissingEmphasized(boolean flag) { | |||
isMissingEmphasized = flag; | |||
} | |||
/** | |||
* Kreiert ein ResourceBundle mit der Quelle in <strong>in</strong>. | |||
*/ | |||
public SecureResourceBundle(InputStream in) { | |||
try { | |||
lookup.load(in); | |||
} catch(Exception ex) { | |||
System.out.println("Abgefangene Exception: " + ex.getMessage()); | |||
isSourceFound = false; | |||
} | |||
} | |||
public Enumeration getKeys() { | |||
return lookup.keys(); | |||
} | |||
/** | |||
* Händelt den abgefragten Key, liefert entweder den zugehörigen Wert oder eine Meldung. | |||
* Die <strong>null</strong> wird nie zurückgegeben. | |||
* Schreibt die fehlenden Suchschlüssel in die Protokoll-Datei. | |||
* @return <code>Object</code><UL> | |||
* <LI>den zu dem Suchschlüssel <strong>key</strong> gefundenen Wert, falls vorhanden, <br> | |||
* <LI>Meldung <strong>Key <i>key</i> not found</strong>, falls der Suchschlüssel fehlt | |||
* und die Eigenschaft "jCatalog.DevelopmentStartModus" in der ini-Datei aus true gesetzt ist. | |||
* <LI>Meldung <strong>Key is null</strong>, falls der Suchschlüssel <code>null</code> ist. | |||
* </UL> | |||
* | |||
*/ | |||
public Object handleGetObject(String key) { | |||
if (key == null) | |||
return "Key is null"; | |||
Object obj = lookup.get(key); | |||
if (obj != null) | |||
return obj; | |||
else { | |||
if (isMissingEmphasized) { | |||
System.out.println(getClass().getName() + ": missing key: " + key); | |||
return getMissedRepresentation(key.toString()); | |||
} | |||
else | |||
return key.toString(); | |||
} | |||
} | |||
/** | |||
* Stellt fest, ob es den Key gibt. | |||
*/ | |||
public boolean contains(String key) { | |||
return (key == null || lookup.get(key) == null) ? false : true; | |||
} | |||
private String getMissedRepresentation(String str) { | |||
return "<!" + str + "!>"; | |||
} | |||
public boolean isSourceFound() { | |||
return isSourceFound; | |||
} | |||
} |
@@ -0,0 +1,29 @@ | |||
package org.apache.fop.viewer; | |||
/** | |||
* Definition für die Übersetzer-Klassen. | |||
* | |||
* @version 03.12.99 | |||
* @author Stanislav.Gorkhover@af-software.de | |||
* | |||
*/ | |||
public interface Translator { | |||
/** | |||
* Übersetzt ein Wort. | |||
*/ | |||
public String getString(String key); | |||
/** | |||
* Ein Translator soll die fehlenden keys hervorheben können. | |||
*/ | |||
public void setMissingEmphasized(boolean b); | |||
/** | |||
* Gibt an ob die Übersetzungsquelle gefunden ist. | |||
*/ | |||
public boolean isSourceFound(); | |||
/** | |||
* Gibt an ob ein Key in der Übersetzungsquelle vorhanden ist. | |||
*/ | |||
public boolean contains(String key); | |||
} |
@@ -0,0 +1,345 @@ | |||
package org.apache.fop.viewer; | |||
import java.awt.*; | |||
import java.io.*; | |||
import java.awt.event.*; | |||
import java.util.*; | |||
import javax.swing.*; | |||
import javax.swing.JComponent.*; | |||
/** | |||
* Klasse <code>UserMessage</code> ist ein utility zum Abfragen oder zum Informieren des Benutzers.<br> | |||
* Eine Meldung besteht aus dem Identifikator (Suchschlüssel im Meldungspool), einem Dialogtitel, einem Buttonset und | |||
* dem Meldungstext mit eventuellen Platzhaltern für die Parameter. | |||
* | |||
* @author S. Gorkhover | |||
* @version 18.03.1999 | |||
* | |||
* @changed 23.04.99 Juergen.Verwohlt@af-software.de | |||
* @subject Weitere Ausgabemethoden: show(String, String) und show(String,String,Frame) | |||
* | |||
* @changed 28.05.99 Juergen.Verwohlt@af-software.de | |||
* @subject MessageException unterstützen | |||
* | |||
* @changed 09.06.99 Juergen.Verwohlt@af-software.de | |||
* @subject Neue Klasse MessagesException zur Anzeige verwenden | |||
*/ | |||
public class UserMessage { | |||
private static Translator res = null; | |||
public static void setTranslator(Translator aRes) { | |||
res = aRes; | |||
if (res == null) { | |||
System.out.println("UserMessage: setTranslator(null) !"); | |||
res = new SecureResourceBundle(null); | |||
} | |||
MessagesDialog.setTranslator(res); | |||
} | |||
// Zulässige Werte für Dialogart: | |||
/** | |||
* Möglicher Wert des Meldungstypes. Fenster-Title "Info" (de). | |||
*/ | |||
private static final int INFO = JOptionPane.PLAIN_MESSAGE; | |||
/** | |||
* Möglicher Wert des Meldungstypes. Fenster-Title "Warnung" (de). | |||
*/ | |||
private static final int WARNING = JOptionPane.WARNING_MESSAGE; | |||
/** | |||
* Möglicher Wert des Meldungstypes. Fenster-Title "Frage" (de). | |||
*/ | |||
private static final int QUESTION = JOptionPane.QUESTION_MESSAGE; | |||
/** | |||
* Möglicher Wert des Meldungstypes. Fenster-Title "Fehler" (de). | |||
*/ | |||
private static final int ERROR = JOptionPane.ERROR_MESSAGE; | |||
/** | |||
* Möglicher Wert des Meldungstypes. Fenster-Title "Systemfehler" (de). | |||
*/ | |||
private static final int SYS_ERROR = JOptionPane.ERROR_MESSAGE; | |||
/* Style Constanten orientieren sich auf die | |||
* Constanten der ButtonDialog-Klasse und legen das Dialog-ButtonSet fest. | |||
*/ | |||
/** Wert für Setzten keines Buttons */ | |||
public static final int STYLE_NOBUTTON = -2; | |||
/** Wert für Setzten von nur Ja-Button.*/ | |||
public static final int STYLE_Y = JOptionPane.DEFAULT_OPTION; | |||
//ButtonDialog.YES; // = 1 | |||
/** Wert für Setzten von Ja- und Nein-Buttons.*/ | |||
public static final int STYLE_Y_N = JOptionPane.YES_NO_OPTION; | |||
//ButtonDialog.YES_NO; // = 2; | |||
/** Wert für Setzten von Ja-, Nein-und Abbruch Buttons.*/ | |||
public static final int STYLE_Y_N_C = JOptionPane.YES_NO_CANCEL_OPTION; | |||
//ButtonDialog.YES_NO_CANCEL; // = 3; | |||
// Platzhalter für Parameter in der Properties-Datei | |||
private static final String PARAMETER_TAG = "&&&"; | |||
/** | |||
* Benutzer-Antwort-Constanten orientieren sich auf die | |||
* Constanten der ButtonDialog-Klasse | |||
*/ | |||
/**Möglicher Rückgabewert @see ButtonDialog*/ | |||
public static final int YES = JOptionPane.YES_OPTION; | |||
//ButtonDialog.YES; // = 2 | |||
/**Möglicher Rückgabewert @see ButtonDialog*/ | |||
public static final int NO = JOptionPane.NO_OPTION; | |||
//ButtonDialog.NO; // = 4; | |||
/**Möglicher Rückgabewert @see ButtonDialog*/ | |||
public static final int CANCEL = JOptionPane.CANCEL_OPTION; | |||
//ButtonDialog.CANCEL; // = 8; | |||
// Default-Values | |||
private static int buttonType = STYLE_Y; | |||
private static int iconType = WARNING; | |||
private static String currentIconName = ""; | |||
private static String actMessId = null; | |||
// private static MessagesDialog nobuttonDialog = null; | |||
/** | |||
* Ersetzt die eventuellen Platzhalter durch die übergebenen Parameter | |||
*/ | |||
static String prepareMessage(String rawText, String[] par) { | |||
System.out.println("prepareMessage(): " + rawText + ", parameter: " + par); | |||
int index = rawText.indexOf(PARAMETER_TAG); | |||
String composedMess = ""; | |||
if ((index == -1) && (par == null)) return rawText; | |||
if ((index != -1) && (par == null)) { | |||
System.out.println("Message " + actMessId+ " erwartet Parameter. Aufgerufen ohne Parameter"); | |||
return rawText; | |||
} | |||
if ((index == -1) && (par != null)) { | |||
System.out.println("Message " + actMessId + " erwartet keine Parameter. Aufgerufen mit folgenden Parametern:"); | |||
for(int i = 0; i < par.length; ++i) | |||
System.out.println(par[i].toString()); | |||
return rawText; | |||
} | |||
int tagCount = 0; | |||
while (rawText.indexOf(PARAMETER_TAG) != -1) { | |||
index = rawText.indexOf(PARAMETER_TAG); | |||
try { | |||
composedMess += rawText.substring(0, index) + par[tagCount]; | |||
} catch(ArrayIndexOutOfBoundsException ex) { | |||
System.out.println("Anzahl der übergebenen Parameter zu der Meldung " + actMessId + " ist weniger als erwartet."); | |||
ex.printStackTrace(); | |||
return composedMess + rawText; | |||
} | |||
rawText = rawText.substring(index+PARAMETER_TAG.length()); | |||
tagCount++; | |||
} | |||
composedMess += rawText; | |||
if (tagCount != par.length) | |||
System.out.println("Die zu der Meldung " + actMessId + " übergebenen Parameter sind mehr als die Meldung vorsieht."); | |||
return composedMess; | |||
} | |||
/** | |||
* Gibt den Title fürs Dialogfenster. | |||
* Dieser wird durch die Dialogart festgelegt | |||
* (erster Teil in der MeldungsDefinition in der Properties-Datei). | |||
*/ | |||
static String getTitle(String strVal) { | |||
String title = null; | |||
int choice = getValue(strVal); | |||
switch (choice) { | |||
case INFO : title = "Info"; currentIconName = "info.gif"; break; | |||
case WARNING : title = "Warning"; currentIconName = "warn.gif"; break; | |||
case QUESTION : title = "Question"; currentIconName = "quest.gif"; break; | |||
case ERROR : title = "Error"; currentIconName = "error.gif"; break; | |||
default : title = "Ungültiger IonType für diese Meldung. Prüfen in Übersetzungsdatei."; | |||
} | |||
return title; | |||
} | |||
/** | |||
* Liefert den Wert der über den Nemen übergebenen Klassenvariablen. | |||
*/ | |||
static int getValue(String fieldName) { | |||
int val = -1; | |||
if (fieldName.equals("INFO")) return INFO; | |||
else if (fieldName.equals("WARNING")) return WARNING; | |||
else if (fieldName.equals("ERROR")) return ERROR; | |||
else if (fieldName.equals("SYS_ERROR")) return SYS_ERROR; | |||
else if (fieldName.equals("QUESTION")) return QUESTION; | |||
else if (fieldName.equals("STYLE_NOBUTTON")) return STYLE_NOBUTTON; | |||
else if (fieldName.equals("STYLE_Y")) return STYLE_Y; | |||
else if (fieldName.equals("STYLE_Y_N")) return STYLE_Y_N; | |||
else if (fieldName.equals("STYLE_Y_N_C")) return STYLE_Y_N_C; | |||
return val; | |||
} | |||
private static String getStackTrace(Exception exception) { | |||
if (exception == null) | |||
return "null"; | |||
String stack = ""; | |||
StringWriter strWriter = new StringWriter(); | |||
exception.printStackTrace(new PrintWriter(strWriter)); | |||
stack = strWriter.toString(); | |||
stack = stack.replace('\r', ' '); | |||
stack = stack.replace('\t', ' '); | |||
return stack; | |||
} | |||
private static int display(String textID, String[] param, Exception exception, Frame frame) { | |||
String translatedMes = ""; | |||
String preparedMes = ""; | |||
String messageType = ""; | |||
String optionType = ""; | |||
String title = ""; | |||
MessagesDialog dialog = null; | |||
actMessId = textID; | |||
boolean messageFound = res.contains(textID); | |||
translatedMes = res.getString(textID); | |||
if (messageFound) { | |||
try { | |||
messageType = translatedMes.substring(0, translatedMes.indexOf(':')); | |||
translatedMes = translatedMes.substring(translatedMes.indexOf(':')+1); | |||
optionType = translatedMes.substring(0, translatedMes.indexOf(':')); | |||
translatedMes = translatedMes.substring(translatedMes.indexOf(':')+1); | |||
} catch(Exception ex) { | |||
System.out.println("FALSCHES FORMAT: MESSAGE: " + textID); | |||
} | |||
} | |||
else { // Message not found | |||
System.out.println("UserMessage: textID '" + textID + "' not found. Return " + | |||
"value 'CANCEL' = " + CANCEL); | |||
//return CANCEL; | |||
messageType = "ERROR"; | |||
optionType = "STYLE_Y"; | |||
translatedMes = "textID '"+textID +"' not found." + | |||
"\nIt is possible the message file not found."; | |||
} | |||
preparedMes = prepareMessage(translatedMes, param); | |||
// Exception exception = getException(param); | |||
// WARNING -> nach Warnung übersetzen | |||
title = res.getString(getTitle(messageType)); | |||
// WARNING -> JOptionPane.WARNING_MESSAGE | |||
int messageTypeIndex = getValue(messageType); | |||
// Button Set idetifizieren | |||
int optionTypeIndex = getValue(optionType); | |||
int result = CANCEL; | |||
if (exception != null) { | |||
String str = getStackTrace(exception); | |||
if (exception instanceof MessageException ) { | |||
MessageException ex = (MessageException)exception; | |||
if (ex.getException() != null) | |||
str += "\n" + getStackTrace(ex.getException()); | |||
} | |||
result = MessagesDialog.showDetailDialog(null, preparedMes, title, | |||
optionTypeIndex, messageTypeIndex, null, str); | |||
} | |||
else { | |||
if (optionTypeIndex == STYLE_NOBUTTON) { | |||
// Wird nicht mehr unterstützt | |||
System.out.println("UserMessage: STYLE_NOBUTTON wird nicht unterstützt"); | |||
return result; | |||
} | |||
else { | |||
result = MessagesDialog.showConfirmDialog(null,preparedMes,title, | |||
optionTypeIndex,messageTypeIndex); | |||
} | |||
} | |||
return result; | |||
} | |||
/** | |||
* Öffnet das Dialogfenster mit der Übersetzung der per Suchschlüssel übergebenen Meldung | |||
* mit eingesetzten Parametern. Für die Übersetzung der Parameter trägt die aufrufende Stelle die Sorge. | |||
* Der Dialog ist modal zum Frame <code>frame</code>. | |||
* @param <UL> | |||
* <LI> textID - Suchschlüssel der Meldung im Meldungspool, | |||
* <LI> param - Array der in die Meldung einzusetztenden Parameter, | |||
* <LI> frame - das Fenster, zu dem der Dialog modal ist. | |||
* </UL> | |||
* @return <UL> | |||
* <LI> -1 wenn keine Rückgabe möglich ist oder Dialog NICHT MODAL ist. | |||
* <LI> ButtonDialog.YES = 2 | |||
* <LI> ButtonDialog.NO = 4 | |||
* <LI> ButtonDialog.CANCEL = 8 | |||
* <LI> Wird das Dialog-Fenster ohne Buttonklick geschlossen (Kreuzchen oben rechts), so ist die Rückgabe gleich ButtonDialog.CANCEL. | |||
* </UL> | |||
*/ | |||
public static int show(String messageId, String[] parameterList, | |||
Exception anException, Frame parentFrame) { | |||
return display(messageId, parameterList, anException, parentFrame); | |||
} | |||
public static int show(String messageId, String[] parameterList, | |||
Exception anException) { | |||
return display(messageId, parameterList, anException, (Frame)null); | |||
} | |||
public static int show(String messageId, String[] parameterList, | |||
Frame parentFrame) { | |||
return display(messageId, parameterList, (Exception)null, parentFrame); | |||
} | |||
public static int show(String messageId, String[] parameterList) { | |||
return display(messageId, parameterList, (Exception)null, (Frame)null); | |||
} | |||
public static int show(String messageId, String parameter, | |||
Frame parentFrame) { | |||
return display(messageId, new String[] { parameter }, (Exception)null, parentFrame); | |||
} | |||
public static int show(String messageId, String parameter) { | |||
return display(messageId, new String[] { parameter }, (Exception)null, (Frame)null); | |||
} | |||
public static int show(String messageId, Frame parentFrame) { | |||
return display(messageId, (String[])null, (Exception)null, parentFrame); | |||
} | |||
public static int show(String messageId) { | |||
return display(messageId, (String[])null, (Exception)null, (Frame)null); | |||
} | |||
public static int show(String messageId, Exception anException, Frame aFrame) { | |||
return display(messageId, (String[])null, anException, aFrame); | |||
} | |||
public static int show(String messageId, Exception anException) { | |||
return display(messageId, (String[])null, anException, (Frame)null); | |||
} | |||
public static int show(Exception anException, Frame aFrame) { | |||
if (anException instanceof MessageException) { | |||
MessageException ex = (MessageException)anException; | |||
return show(ex.getMessageId(), ex.getParameterList(), ex, aFrame); | |||
} | |||
else | |||
return show("UNHANDLED_EXCEPTION", (String[])null, anException, aFrame); | |||
} | |||
} | |||
@@ -0,0 +1,78 @@ | |||
############################################################################### | |||
# | |||
# In dieser Datei werden im Abschnitt "Messages" Meldungen auf deutsch | |||
# definiert. | |||
# Zu beachten: Beim Definieren einer neuen neuen Meldung, diese soweit möglich | |||
# in allen Sprachen anlegen. | |||
# | |||
# | |||
# | |||
# MELDUNG DEFINIEREN | |||
# ================== | |||
# | |||
# Eine Meldung hat eine eindeutige textuelle ID. Diese steht links vom Gleichheitszeichen. | |||
# Zu jeder Meldung wird angegeben: | |||
# - iconType (Typen siehe unten) | |||
# - buttonType (Typen siehe unten) | |||
# - Meldungstext mit evtl. Platzhaltern für Parameter. | |||
# | |||
# Ein Parameterplatzhalter ist ein dreifaches kaumänisches "und". Siehe Beispielmeldung | |||
# "No_Records_found". | |||
# | |||
# Die Angaben erfolgen in einer Zeile, jeweils durch einen Doppelpunkt getrennt. | |||
# | |||
# Format: | |||
# <MESSAGE_ID>=<iconType>:<buttonType>:<Meldungstext> | |||
# | |||
# Zulässige Werte für: | |||
# iconType: | |||
# INFO | |||
# WARNING | |||
# ERROR | |||
# QUESTION | |||
# | |||
# buttonType: | |||
# STYLE_Y ("yes" Button) | |||
# STYLE_Y_N ("yes" and "no" Buttons) | |||
# STYLE_Y_N_C ("yes", "no" and "cancel" Buttons) | |||
# | |||
# | |||
# Beispiel mit einem String-Array: | |||
# ================================ | |||
# Messagedefinition: | |||
# No_Records_found=WARNING:STYLE_Y:Die Tabelle &&& enthält keinen Eintrag. Erwartet mind. &&&. Weitermachen? | |||
# Aufruf: | |||
# answer = UserMessage.show("No_Records_found", new String[] {"Mitarbeiter", "" + minNumber}, aShowFrame); | |||
# if (answer == UserMessage.NO) | |||
# return; | |||
# | |||
# Beispiel mit einer Exception: | |||
# ============================= | |||
# Messagedefinition: | |||
# UNEXPECTED_EXCEPTION=ERROR:STYLE_Y:Wow! An exception! | |||
# | |||
# Aufruf: | |||
# try { | |||
# String str = null; | |||
# int index = str.indexOf("abc"); | |||
# } catch (Exception ex) { | |||
# UserMessage.show("UNEXPECTED_EXCEPTION", ex); | |||
# } | |||
# | |||
# | |||
# | |||
# | |||
################################################################################################# | |||
# Titles | |||
Info=Info | |||
Warning=Warnung | |||
Question=Frage | |||
Error=Fehler | |||
# Messages | |||
TRANSLATION_SOURCE_NOT_FOUND=WARNING:STYLE_Y:Die Übersetzungsdatei &&& ist nicht gefunden. | |||
UNKNOWN_EXCEPTION=ERROR:STYLE_Y:Unbekannter Fehler | |||
UNHANDLED_EXCEPTION=ERROR:STYLE_Y:Interner Fehler | |||
@@ -0,0 +1,80 @@ | |||
############################################################################### | |||
# | |||
# This file contains the english messages. | |||
# | |||
# NOTICE: When defining a new message it has to be created in message files for each language. | |||
# | |||
# | |||
# | |||
# | |||
# DEFINING A MESSAGE | |||
# ================== | |||
# | |||
# A message has a uinique CHARACTER ID. It is placed on the left hand side of the equation. | |||
# For each message there are additional switches: | |||
# - iconType (see below) | |||
# - buttonType (see below) | |||
# - messageText may contain placeholders for parameters. | |||
# A placeholder pattern is a "&&&" . See Examplemessage "No_Records_found". | |||
# | |||
# A messsage definition is placed within a single row, its switches are seperated by a colon ":". | |||
# | |||
# Format: | |||
# ======= | |||
# <MESSAGE_ID>=<iconType>:<buttonType>:<message text> | |||
# | |||
# | |||
# Allowed values for: | |||
# =================== | |||
# iconType: | |||
# INFO | |||
# WARNING | |||
# ERROR | |||
# QUESTION | |||
# | |||
# buttonType: | |||
# STYLE_Y ("yes" Button) | |||
# STYLE_Y_N ("yes" and "no" Buttons) | |||
# STYLE_Y_N_C ("yes", "no" and "cancel" Buttons) | |||
# | |||
# | |||
# Example with a parameter array: | |||
# ================================ | |||
# Message definition: | |||
# No_Records_found=WARNING:STYLE_Y:The Table &&& has no records. Expected at least &&&. Continue? | |||
# Aufruf: | |||
# answer = UserMessage.show("No_Records_found", new String[] {"Employee", "" + minNumber}, aShowFrame); | |||
# if (answer == UserMessage.NO) | |||
# return; | |||
# | |||
# Example with an Exception: | |||
# ============================= | |||
# Message definition: | |||
# UNEXPECTED_EXCEPTION=ERROR:STYLE_Y:Wow! An exception! | |||
# | |||
# Aufruf: | |||
# try { | |||
# String str = null; | |||
# int index = str.indexOf("abc"); | |||
# } catch (Exception ex) { | |||
# UserMessage.show("UNEXPECTED_EXCEPTION", ex); | |||
# } | |||
# | |||
# | |||
# | |||
# | |||
################################################################################################# | |||
# Titles | |||
Info=Info | |||
Warning=Warning | |||
Question=Question | |||
Error=Error | |||
# Messages | |||
TRANSLATION_SOURCE_NOT_FOUND=WARNING:STYLE_Y:The translation file &&& is not found. | |||
UNKNOWN_EXCEPTION=ERROR:STYLE_Y:Unknown error. | |||
UNHANDLED_EXCEPTION=ERROR:STYLE_Y:Internal error. | |||
@@ -0,0 +1,21 @@ | |||
File=Datei | |||
Exit=Beenden | |||
View=Anzeige | |||
Previous page=Vorherige Seite | |||
Next page=Nächste Seite | |||
Last page=Letzte Seite | |||
Help=Hilfe | |||
Default zoom=Standardzoom | |||
Introduction=Einleitung | |||
About=Über | |||
Show=Anzeigen | |||
Preview=Vorschau | |||
First page=Erste Seite | |||
Print=Drucken | |||
Page=Seite | |||
of=von | |||
Init parser=Initializiere Parser | |||
Init mappings=Initializiere Abbildung | |||
Build FO tree=Baue FO-Baum | |||
Layout FO tree=Formatiere FO-Baum | |||
Render=Gebe aus |
@@ -0,0 +1,4 @@ | |||
# Diese Datei ist nur dafür da, daß die Warnung | |||
# "Übersetzungsdatei nicht gefunden" nicht hochkommt. | |||
# Die Suchschlüssel für die zu übersetzenden Begriffe sind | |||
# englisch. Daher wäre eine Übersetzung redundant. |
@@ -0,0 +1,16 @@ | |||
File=Tiedosto | |||
Print=Tulosta | |||
Exit=Poistu | |||
View=Näytä | |||
First page=Ensimmäinen sivu | |||
Previous page=Edellinen sivu | |||
Next page=Seuraava sivu | |||
Last page=Viimeinen sivu | |||
Default zoom=Normaali zoom | |||
Help=Ohje | |||
Index=Sisällys | |||
Introduction=Esittely | |||
About=Tietoja | |||
Page=Sivu | |||
@@ -0,0 +1,13 @@ | |||
File=Fichier | |||
Print=Imprimer | |||
Exit=Quitter | |||
View=Affichage | |||
First page=Première page | |||
Previous page=Page précédente | |||
Next page=Page suivante | |||
Last page=Dernière page | |||
Help=Aide | |||
Default zoom=Zoom par défaut | |||
Introduction=Introduction | |||
About=A propos | |||
@@ -0,0 +1,14 @@ | |||
File=File | |||
Exit=Esci | |||
View=Vista | |||
First page=Prima pagina | |||
Previous page=Pagina precedente | |||
Next page=Pagina seguente | |||
Last page=Ultima pagina | |||
Help=Aiuto | |||
Default zoom=Zoom di default | |||
Introduction=Introduzione | |||
About=Riguardo a... | |||
Index=Indice | |||
Print=Stampa | |||
@@ -0,0 +1,17 @@ | |||
File=Plik | |||
Print=Drukuj | |||
Exit=Zakończ | |||
View=Widok | |||
First page=Pierwsza strona | |||
Previous page=Poprzednia strona | |||
Next page=Następna strona | |||
Last page=Ostatnia strona | |||
Zoom=Powiększenie | |||
Default zoom=Domyślne powiekszenie | |||
Help=Pomoc | |||
Index=Indeks | |||
Introduction=Wstęp | |||
About=O programie | |||
Page=Strona | |||
@@ -0,0 +1,17 @@ | |||
File=Файл | |||
Exit=Закончить | |||
View=Вид | |||
First page=Первая страница | |||
Previous page=Прелылущая страница | |||
Next page=Следующая страница | |||
Last page=Последняя страница | |||
Help=Помощь | |||
Default zoom=Стандаотный масштаб | |||
Introduction=Введение | |||
About=О программе | |||
Show=Показ | |||
Preview=Просмотр | |||
Print=Печатать | |||
Page=Стоаница | |||
of=из | |||
Zoom=Масштаб |