From: jtauber Date: Thu, 25 Nov 1999 19:21:12 +0000 (+0000) Subject: Added AWT Viewer contributed by Albers+Frommberger (af-software.de) X-Git-Tag: RELEASE_0_12_0~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a476ff2b906f937cdead665a3b30472c4dc21f1d;p=xmlgraphics-fop.git Added AWT Viewer contributed by Albers+Frommberger (af-software.de) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193244 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/STATUS b/STATUS index 1937a1cfe..b377a8fef 100644 --- a/STATUS +++ b/STATUS @@ -11,8 +11,25 @@ Get images working [PARTIAL] Implement basic keeps [DONE]Incorporate Eric Schaeffer's fix to tables in static-content [DONE] Incorporate Kelly Campell's fixes to GifJpegImage +Incorporate Eric Schaeffer's further table fixes +Incorporate Eric Schaeffer's background colour implementation Other Bugs to fix: colour not continued onto subsequent pages if coloured block goes over page +Todo's and problems with AWT Previewer: + +- currently the layout process uses PDF fonts. This gives sometimes + trouble with java.awt.Font +- we need some progress messages even if the process itself is fast +- GIF format is supported by the viewer, but disabled in FOP. BMP is + not done, because there are no standard libraries. +- more comments/english comments +- print output using AWT +- i18n for the user interface (yes, now we need this stuff) +- toolbar images directory is not configurable +- first preview is painted twice (flashing screen) +- should "preview" be an option when calling FOP instead of having + it's own main method? + diff --git a/src/org/apache/fop/Makefile b/src/org/apache/fop/Makefile index 173fad8d4..38b1af938 100644 --- a/src/org/apache/fop/Makefile +++ b/src/org/apache/fop/Makefile @@ -10,7 +10,8 @@ SUBDIRS=apps \ layout \ pdf \ render \ - svg + svg \ + viewer all: $(CLASSES) allsubs diff --git a/src/org/apache/fop/apps/AWTCommandLine.java b/src/org/apache/fop/apps/AWTCommandLine.java new file mode 100644 index 000000000..ee1e1c25a --- /dev/null +++ b/src/org/apache/fop/apps/AWTCommandLine.java @@ -0,0 +1,171 @@ + +package org.apache.fop.apps; +/* + 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 org.apache.fop.viewer.*; +import org.apache.fop.render.awt.*; + +import javax.swing.UIManager; +import java.awt.*; + +// SAX +import org.xml.sax.Parser; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + + + +// Java +import java.io.FileReader; +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.net.URL; + + + + +/** + * initialize AWT previewer + */ + +public class AWTCommandLine { + + + public AWTCommandLine(AWTRenderer aRenderer) { + + 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); + } + + + static Parser createParser() { + String parserClassName = + System.getProperty("org.xml.sax.parser"); + if (parserClassName == null) { + parserClassName = "com.jclark.xml.sax.Driver"; + } + System.err.println("using SAX parser " + parserClassName); + + try { + return (Parser) + Class.forName(parserClassName).newInstance(); + } catch (ClassNotFoundException e) { + System.err.println("Could not find " + parserClassName); + } catch (InstantiationException e) { + System.err.println("Could not instantiate " + + parserClassName); + } catch (IllegalAccessException e) { + System.err.println("Could not access " + parserClassName); + } catch (ClassCastException e) { + System.err.println(parserClassName + " is not a SAX driver"); + } + return null; + } + + /** + * create an InputSource from a file name + * + * @param filename the name of the file + * @return the InputSource created + */ + protected static InputSource fileInputSource(String filename) { + + /* this code adapted from James Clark's in XT */ + File file = new File(filename); + String path = file.getAbsolutePath(); + String fSep = System.getProperty("file.separator"); + if (fSep != null && fSep.length() == 1) + path = path.replace(fSep.charAt(0), '/'); + if (path.length() > 0 && path.charAt(0) != '/') + path = '/' + path; + try { + return new InputSource(new URL("file", null, + path).toString()); + } + catch (java.net.MalformedURLException e) { + throw new Error("unexpected MalformedURLException"); + } + } + + + + /* main + */ + public static void main(String[] args) { + try { + UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel()); + } catch (Exception e) { + e.printStackTrace(); + } + + String srcPath = null; + + System.err.println(Version.getVersion()); + if (args.length == 1) { + srcPath = args[0]; + } + else { + System.err.println("usage: java " + + "AWTCommandLine " + + "formatting-object-file"); + + System.exit(1); + } + + + 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(); + +// render: time + driver.render(); + + } catch (Exception e) { + System.err.println("FATAL ERROR: " + e.getMessage()); + System.exit(1); + } + + } // main +} // AWTCommandLine + diff --git a/src/org/apache/fop/apps/Makefile b/src/org/apache/fop/apps/Makefile index f1cd6126a..1ad0c6717 100644 --- a/src/org/apache/fop/apps/Makefile +++ b/src/org/apache/fop/apps/Makefile @@ -5,7 +5,8 @@ include $(BASEDIR)/Makefile.rules SUBDIRS= -SOURCES=CommandLine.java \ +SOURCES=AWTCommandLine.java \ + CommandLine.java \ Driver.java \ ErrorHandler.java \ FOPException.java \ diff --git a/src/org/apache/fop/render/Makefile b/src/org/apache/fop/render/Makefile index 16807e584..64dd5613b 100644 --- a/src/org/apache/fop/render/Makefile +++ b/src/org/apache/fop/render/Makefile @@ -3,7 +3,8 @@ BASEDIR:=../../../../.. include $(BASEDIR)/Makefile.rules -SUBDIRS=pdf \ +SUBDIRS=awt \ + pdf \ xml SOURCES=Renderer.java diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java new file mode 100644 index 000000000..656b36679 --- /dev/null +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -0,0 +1,453 @@ + + +package org.apache.fop.render.awt; + +/* + 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 org.apache.fop.layout.*; +import org.apache.fop.image.*; +import org.apache.fop.svg.*; +import org.apache.fop.render.pdf.*; +import org.apache.fop.viewer.*; + + +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; +import java.awt.font.*; +import java.util.*; +import java.io.*; +import javax.swing.*; + + +public class AWTRenderer implements org.apache.fop.render.Renderer { + + protected int pageWidth = 0; + protected int pageHeight = 0; + protected double scaleFactor = 100.0; + protected int pageNumber = 0; + + protected Hashtable fontNames = new Hashtable(); + protected Hashtable fontStyles = new Hashtable(); + + + + + protected Graphics2D graphics = null; + + protected DocumentPanel documentPanel = null; + + + /** the current (internal) font name */ + protected String currentFontName; + + /** the current font size in millipoints */ + protected int currentFontSize; + + /** the current colour's red component */ + protected float currentRed = 0; + + /** the current colour's green component */ + protected float currentGreen = 0; + + /** the current colour's blue component */ + protected float currentBlue = 0; + + /** the current vertical position in millipoints from bottom */ + protected int currentYPosition = 0; + + /** the current horizontal position in millipoints from left */ + protected int currentXPosition = 0; + + /** the horizontal position of the current area container */ + private int currentAreaContainerXPosition = 0; + + + public AWTRenderer() { + } + + public void setGraphics(Graphics2D g) { + graphics = g; + if (graphics != null) { + graphics = g; + graphics.setColor(Color.red); + } + } + + public int getPageNumber() { + return pageNumber; + } + + public void setPageNumber(int aValue) { + pageNumber = aValue; + if (documentPanel == null) + return; + documentPanel.updateSize(pageNumber, scaleFactor / 100.0); + } + + public void setScaleFactor(double newScaleFactor) { + scaleFactor = newScaleFactor; + if (documentPanel == null) + return; + documentPanel.updateSize(pageNumber, scaleFactor / 100.0); + } + + + public double getScaleFactor() { + return scaleFactor; + } + + + /** + * Vor dem Druck einzustellen: + * + * Seite/Seiten wählen + * Zoomfaktor + * Seitenformat / Quer- oder Hoch + **/ + public void transform(Graphics2D g2d, double zoomPercent, double angle) { + AffineTransform at = g2d.getTransform(); + at.rotate(angle); + at.scale(zoomPercent/100.0, zoomPercent/100.0); + g2d.setTransform(at); + } + + protected void drawFrame() { + + int width = pageWidth; + int height = pageHeight; + + graphics.setColor(Color.white); + graphics.fillRect(0, 0, width, height); + graphics.setColor(Color.black); + graphics.drawRect(-1, -1, width+2, height+2); + graphics.drawLine(width+2, 0, width+2, height+2); + graphics.drawLine(width+3, 1, width+3, height+3); + + graphics.drawLine(0, height+2, width+2, height+2); + graphics.drawLine(1, height+3, width+3, height+3); + + } + + + public void render(AreaTree areaTree, PrintWriter writer) throws IOException { + documentPanel.setAreaTree(areaTree); + documentPanel.setPageCount(areaTree.getPages().size()); + documentPanel.updateSize(pageNumber, scaleFactor/100.0); + render(areaTree, 0); + } + + public void render(AreaTree areaTree, int aPageNumber) throws IOException { + Page page = (Page)areaTree.getPages().elementAt(aPageNumber); + + pageWidth = (int)((float)page.getWidth() / 1000f); + pageHeight = (int)((float)page.getHeight() / 1000f); + + transform(graphics, scaleFactor, 0); + drawFrame(); + + renderPage(page); + } + + public void renderPage(Page page) { + AreaContainer body, before, after; + + body = page.getBody(); + before = page.getBefore(); + after = page.getAfter(); + + this.currentFontName = ""; + this.currentFontSize = 0; + + renderAreaContainer(body); + + if (before != null) { + renderAreaContainer(before); + } + + if (after != null) { + renderAreaContainer(after); + } + + } + + + public void renderAreaContainer(AreaContainer area) { + + + this.currentYPosition = area.getYPosition(); + this.currentAreaContainerXPosition = area.getXPosition(); + + Enumeration e = area.getChildren().elements(); + while (e.hasMoreElements()) { + org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement(); + b.render(this); + } + } + + + + protected Rectangle2D getBounds(org.apache.fop.layout.Area a) { + return new Rectangle2D.Double(currentAreaContainerXPosition, + currentYPosition, + a.getAllocationWidth(), + a.getHeight()); + } + + public void renderBlockArea(BlockArea area) { + int rx = this.currentAreaContainerXPosition + + area.getStartIndent(); + int ry = this.currentYPosition; + int w = area.getContentWidth(); + int h = area.getHeight(); + Enumeration e = area.getChildren().elements(); + while (e.hasMoreElements()) { + org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement(); + b.render(this); + } + } + + + public void setupFontInfo(FontInfo 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(); + f = (org.apache.fop.render.pdf.Font)hash.get(key); + name = f.fontName(); + + if (name.toUpperCase().indexOf("BOLD") > 0) { + fontStyle += java.awt.Font.BOLD; + } + if (name.toUpperCase().indexOf("ITALIC") > 0 || + name.toUpperCase().indexOf("OBLIQUE") > 0) { + fontStyle += java.awt.Font.ITALIC; + } + + int hyphenIndex = name.indexOf("-"); + + hyphenIndex = (hyphenIndex < 0) ? name.length() : hyphenIndex; + fontNames.put(key, name.substring(0, hyphenIndex)); + fontStyles.put(key, new Integer(fontStyle)); + } + + } + + + + public void renderDisplaySpace(DisplaySpace space) { + int d = space.getSize(); + this.currentYPosition -= d; + } + + + public void renderImageArea(ImageArea area) { + int x = this.currentAreaContainerXPosition + + area.getXOffset(); + int y = this.currentYPosition; + int w = area.getContentWidth(); + int h = area.getHeight(); + + + FopImage img = area.getImage(); + + if (img == null) { + System.out.println("area.getImage() is null"); + } + + int[] map = img.getimagemap(); + + String path = img.gethref(); + // path = "c:/any.gif"; + + ImageIcon icon = new ImageIcon(path); + + Image imgage = icon.getImage(); + + graphics.drawImage(imgage, currentXPosition / 1000, + pageHeight - y / 1000, + img.getWidth() / 1000, + img.getHeight() / 1000, + 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) { + char ch; + StringBuffer pdf = new StringBuffer(); + + String name = area.getFontState().getFontName(); + int size = area.getFontState().getFontSize(); + + float red = area.getRed(); + float green = area.getGreen(); + float blue = area.getBlue(); + + if ((!name.equals(this.currentFontName)) + || (size != this.currentFontSize)) { + this.currentFontName = name; + this.currentFontSize = size; + } + + if ((red != this.currentRed) + || (green != this.currentGreen) + || (blue != this.currentBlue)) { + this.currentRed = red; + this.currentGreen = green; + this.currentBlue = blue; + } + + int rx = this.currentXPosition; + int bl = this.currentYPosition; + + + 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(), + ((Integer)fontStyles.get(name)).intValue(), + (int)(size / 1000f)); + + + graphics.setColor(new Color(red, green, blue)); + + graphics.setFont(f); + graphics.drawString(s, rx / 1000f, (int)(pageHeight - bl / 1000f)); + graphics.setFont(oldFont); + graphics.setColor(oldColor); + + + this.currentXPosition += area.getContentWidth(); + } + + public void renderInlineSpace(InlineSpace space) { + this.currentXPosition += space.getSize(); + } + + + public void renderLineArea(LineArea area) { + int rx = this.currentAreaContainerXPosition + + area.getStartIndent(); + int ry = this.currentYPosition; + int w = area.getContentWidth(); + int h = area.getHeight(); + + this.currentYPosition -= area.getPlacementOffset(); + this.currentXPosition = rx; + + int bl = this.currentYPosition; + + Enumeration e = area.getChildren().elements(); + while (e.hasMoreElements()) { + org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement(); + b.render(this); + } + + this.currentYPosition = ry-h; + } + + /** + * render rule area into PDF + * + * @param area area to render + */ + public void renderRuleArea(RuleArea area) { + int rx = this.currentAreaContainerXPosition + + area.getStartIndent(); + int ry = this.currentYPosition; + int w = area.getContentWidth(); + int h = area.getHeight(); + int th = area.getRuleThickness(); + float r = area.getRed(); + float g = area.getGreen(); + float b = area.getBlue(); + + + Color oldColor = graphics.getColor(); + + graphics.setColor(new Color(r, g, b)); + + graphics.fillRect((int)(rx / 1000f), (int)(pageHeight - ry / 1000f), + (int)(w / 1000f), (int)(th / 1000f)); + graphics.setColor(oldColor); + + + + } + + + public void renderSVGArea(SVGArea area) { + int x = this.currentAreaContainerXPosition; + int y = this.currentYPosition; + int w = area.getContentWidth(); + int h = area.getHeight(); + this.currentYPosition -= h; + /* + Enumeration e = area.getChildren().elements(); + while (e.hasMoreElements()) { + Object o = e.nextElement(); + if (o instanceof RectGraphic) { + int rx = ((RectGraphic)o).x; + int ry = ((RectGraphic)o).y; + int rw = ((RectGraphic)o).width; + int rh = ((RectGraphic)o).height; + addRect(x+rx,y-ry,rw,-rh,0,0,0); + } else if (o instanceof LineGraphic) { + int x1 = ((LineGraphic)o).x1; + int y1 = ((LineGraphic)o).y1; + int x2 = ((LineGraphic)o).x2; + int y2 = ((LineGraphic)o).y2; + addLine(x+x1,y-y1,x+x2,y-y2,0,0,0,0); + } else if (o instanceof TextGraphic) { + int tx = ((TextGraphic)o).x; + int ty = ((TextGraphic)o).y; + String s = ((TextGraphic)o).s; + currentStream.add("1 0 0 1 " + + ((x+tx)/1000f) + " " + + ((y-ty)/1000f) + " Tm " + + "(" + s + ") Tj\n"); + } + } */ + } + + + public void setProducer(String producer) { + // this.pdfDoc.setProducer(producer); + } + + + public void setComponent(DocumentPanel comp) { + documentPanel = comp; + } + +} + + + + + diff --git a/src/org/apache/fop/render/awt/Makefile b/src/org/apache/fop/render/awt/Makefile new file mode 100644 index 000000000..d55807acf --- /dev/null +++ b/src/org/apache/fop/render/awt/Makefile @@ -0,0 +1,23 @@ + + +BASEDIR:=../../../../../.. +include $(BASEDIR)/Makefile.rules + +SUBDIRS= + +SOURCES=AWTRenderer.java + +CLASSES=$(SOURCES:.java=.class) + +all: $(CLASSES) allsubs + +clean: cleanme cleansubs + +cleanme: + rm -f *.class + +$(TARGETS:%=%subs): %subs : + for dir in $(SUBDIRS) ; do \ + (cd $$dir && pwd && $(MAKE) $(MFLAGS) $*) || exit 1 ; \ + done + diff --git a/src/org/apache/fop/viewer/Command.java b/src/org/apache/fop/viewer/Command.java new file mode 100644 index 000000000..81e5826b2 --- /dev/null +++ b/src/org/apache/fop/viewer/Command.java @@ -0,0 +1,62 @@ +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.event.ActionEvent; +import javax.swing.AbstractAction; +import javax.swing.ImageIcon; +import java.io.File; + + +/** + * Klasse für UI-Kommandos. Die Kommandos können in das Menüsystem oder + * in eine Toolbar eingefügt werden.
+ * Commands unterstützen mehrsprachigkeit.
+ * Durch überschreiben der Methode doit kann die Klasse customisiert werden. + * Über die Methode undoit kann Undo-Funktionalität unterstützt werden.
+ * + * @author Juergen.Verwohlt@af-software.de + * @version 1.0 18.03.99 + */ +public class Command extends AbstractAction { + + public static final String IMAGE_DIR = "../viewer/images/"; + + public Command(String name) { + this(name, (ImageIcon)null); + } + + public Command(String name, ImageIcon anIcon) { + super(name, anIcon); + } + + + public Command(String name, ImageIcon anIcon, String path) { + this(name, anIcon); + File f = new File (IMAGE_DIR + path + ".gif"); + if (!f.exists()) { + System.err.println("Icon not found: " + f.getAbsolutePath()); + } + + } + + public Command(String name, String iconName) { + this(name, new ImageIcon(IMAGE_DIR + iconName + ".gif"), iconName); + } + + public void actionPerformed(ActionEvent e) { + doit(); + } + + public void doit() { + System.err.println("Not implemented."); + } + + public void undoit() { + System.err.println("Not implemented."); + } +} diff --git a/src/org/apache/fop/viewer/DocumentPanel.java b/src/org/apache/fop/viewer/DocumentPanel.java new file mode 100644 index 000000000..8255bc1da --- /dev/null +++ b/src/org/apache/fop/viewer/DocumentPanel.java @@ -0,0 +1,91 @@ +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.*; +import javax.swing.*; + + +import org.apache.fop.layout.*; +import org.apache.fop.render.awt.*; + + + /** + * Diese Komponente stellt im Dialog das Dokument dar. + */ +public class DocumentPanel extends JComponent { + static final int V_BORDER = 80; + static final int H_BORDER = 70; + + protected AWTRenderer renderer; + protected PreviewDialog previewDialog; + protected AreaTree areaTree; + protected int pageNumber = 0; + + protected int docWidth; + protected int docHeight; + protected Color myColor = Color.lightGray; + + public DocumentPanel(AWTRenderer aRenderer, PreviewDialog p) { + previewDialog = p; + renderer = aRenderer; + renderer.setComponent(this); + } + + public void updateSize(int aPageNumber, double aFactor) { + if (areaTree == null) + return; + + Page aPage = (Page)areaTree.getPages().elementAt(aPageNumber); + docWidth = aPage.getWidth() / 1000; + docHeight = aPage.getHeight() / 1000; + setSize((int)(aFactor * aPage.getWidth() / 1000.0 + 2*V_BORDER), + (int)(aFactor * aPage.getHeight()/ 1000.0 + 2*H_BORDER)); + } + + public void setAreaTree(AreaTree tree) { + areaTree = tree; + updateSize(pageNumber, 1.0); + getParent().getParent().doLayout(); + } + + + public void paintComponent(Graphics g) { + Color ownColor = g.getColor(); + g.setColor(myColor); + g.fillRect(0, 0, getWidth(), getHeight()); + g.setColor(ownColor); + g.translate(V_BORDER, H_BORDER); + + renderer.setGraphics((Graphics2D)g); + if (areaTree != null) { + try { + renderer.render(areaTree, pageNumber); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + g.translate(-V_BORDER, -H_BORDER); + } + + public void setPageNumber(int number) { + pageNumber = number; + } + + public Dimension getPreferredSize() { + return getSize(); + } + + public void setPageCount(int pageCount) { + previewDialog.setPageCount(pageCount); + } + +} + diff --git a/src/org/apache/fop/viewer/IconToolBar.java b/src/org/apache/fop/viewer/IconToolBar.java new file mode 100644 index 000000000..7b5a09e11 --- /dev/null +++ b/src/org/apache/fop/viewer/IconToolBar.java @@ -0,0 +1,35 @@ +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 javax.swing.*; +import java.beans.PropertyChangeListener; + +public class IconToolBar extends JToolBar { + + public JButton add(Action a) { + String name = (String) a.getValue(Action.NAME); + Icon icon = (Icon) a.getValue(Action.SMALL_ICON); + return add(a, name, icon); + } + + public JButton add(Action a, String name, Icon icon) { + JButton b = new JButton(icon); + b.setToolTipText(name); + b.setEnabled(a.isEnabled()); + b.addActionListener(a); + add(b); + PropertyChangeListener actionPropertyChangeListener = + createActionChangeListener(b); + a.addPropertyChangeListener(actionPropertyChangeListener); + return b; + } +} + + diff --git a/src/org/apache/fop/viewer/Images/Print.gif b/src/org/apache/fop/viewer/Images/Print.gif new file mode 100644 index 000000000..e715fe67f Binary files /dev/null and b/src/org/apache/fop/viewer/Images/Print.gif differ diff --git a/src/org/apache/fop/viewer/Images/firstpg.gif b/src/org/apache/fop/viewer/Images/firstpg.gif new file mode 100644 index 000000000..1d0315d74 Binary files /dev/null and b/src/org/apache/fop/viewer/Images/firstpg.gif differ diff --git a/src/org/apache/fop/viewer/Images/lastpg.gif b/src/org/apache/fop/viewer/Images/lastpg.gif new file mode 100644 index 000000000..082f13a26 Binary files /dev/null and b/src/org/apache/fop/viewer/Images/lastpg.gif differ diff --git a/src/org/apache/fop/viewer/Images/nextpg.gif b/src/org/apache/fop/viewer/Images/nextpg.gif new file mode 100644 index 000000000..2e3a2d7b3 Binary files /dev/null and b/src/org/apache/fop/viewer/Images/nextpg.gif differ diff --git a/src/org/apache/fop/viewer/Images/prevpg.gif b/src/org/apache/fop/viewer/Images/prevpg.gif new file mode 100644 index 000000000..3c8cce4b6 Binary files /dev/null and b/src/org/apache/fop/viewer/Images/prevpg.gif differ diff --git a/src/org/apache/fop/viewer/Makefile b/src/org/apache/fop/viewer/Makefile new file mode 100644 index 000000000..cf46558c2 --- /dev/null +++ b/src/org/apache/fop/viewer/Makefile @@ -0,0 +1,27 @@ + + +BASEDIR:=../../../../.. +include $(BASEDIR)/Makefile.rules + +SUBDIRS= + +SOURCES=Command.java \ + DocumentPanel.java \ + IconToolBar.java \ + PreviewDialog.java \ + PreviewDialogAboutBox.java + +CLASSES=$(SOURCES:.java=.class) + +all: $(CLASSES) allsubs + +clean: cleanme cleansubs + +cleanme: + rm -f *.class + +$(TARGETS:%=%subs): %subs : + for dir in $(SUBDIRS) ; do \ + (cd $$dir && pwd && $(MAKE) $(MFLAGS) $*) || exit 1 ; \ + done + diff --git a/src/org/apache/fop/viewer/PreviewDialog.java b/src/org/apache/fop/viewer/PreviewDialog.java new file mode 100644 index 000000000..f2dd658d2 --- /dev/null +++ b/src/org/apache/fop/viewer/PreviewDialog.java @@ -0,0 +1,292 @@ + +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.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.*; +import java.beans.PropertyChangeListener; + +import org.apache.fop.layout.*; +import org.apache.fop.render.awt.*; + + + + +/** + * Frame and User Interface for Preview + */ +public class PreviewDialog extends JFrame { + + + protected int currentPage = 0; + protected int pageCount = 0; + + protected AWTRenderer renderer; + + 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 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 DocumentPanel docPanel; + + + + + public PreviewDialog(AWTRenderer aRenderer) { + renderer = aRenderer; + + + 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"); + + scale.addItem("25"); + scale.addItem("50"); + scale.addItem("75"); + scale.addItem("100"); + scale.addItem("150"); + scale.addItem("200"); + + scale.setMaximumSize(new Dimension(80, 24)); + scale.setPreferredSize(new Dimension(80, 24)); + + scale.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + scale_actionPerformed(e); + } + }); + + scale.setSelectedItem("100"); + renderer.setScaleFactor(100.0); + + zoomLabel.setText("Zoom"); + + this.setJMenuBar(setupMenue()); + + this.getContentPane().add(toolBar, BorderLayout.NORTH); + this.getContentPane().add(statusBar, BorderLayout.SOUTH); + + toolBar.add(printAction); + toolBar.addSeparator(); + toolBar.add(firstPageAction); + toolBar.add(previousPageAction); + toolBar.add(nextPageAction); + toolBar.add(lastPageAction); + toolBar.addSeparator(); + toolBar.add(zoomLabel, null); + toolBar.addSeparator(); + toolBar.add(scale, null); + + this.getContentPane().add(previewArea, BorderLayout.CENTER); + + docPanel = new DocumentPanel(renderer, this); + + + previewArea.setSize(docPanel.getSize()); + previewArea.getViewport().add(docPanel); + statusBar.setText("FOTree --> AreaTree ..."); + + } + + + JMenuBar setupMenue() { + JMenuBar menuBar; + JMenuItem menuItem; + JMenu menu; + JMenu subMenu; + + menuBar = new JMenuBar(); + menu = new JMenu("File"); + subMenu = new JMenu("OutputFormat"); + subMenu.add(new Command("mHTML")); + subMenu.add(new Command("mPDF")); + subMenu.add(new Command("mRTF")); + subMenu.add(new Command("mTEXT")); + // menu.add(subMenu); + // menu.addSeparator(); + menu.add(new Command("Print")); + menu.addSeparator(); + menu.add(new Command("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.addSeparator(); + subMenu = new JMenu("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);}} ); + subMenu.add(new Command("100%") { public void doit() {setScale(100.0);}} ); + subMenu.add(new Command("150%") { public void doit() {setScale(150.0);}} ); + 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);}} ); + menuBar.add(menu); + menu = new JMenu("Help"); + menu.add(new Command("Index")); + menu.addSeparator(); + menu.add(new Command("Introduction")); + menu.addSeparator(); + menu.add(new Command("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) { + PreviewDialogAboutBox dlg = new PreviewDialogAboutBox(this); + Dimension dlgSize = dlg.getPreferredSize(); + Dimension frmSize = getSize(); + Point loc = getLocation(); + dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); + dlg.setModal(true); + dlg.show(); + } + + void goToPage(int number) { + docPanel.setPageNumber(number); + repaint(); + previewArea.repaint(); + statusBar.setText("Page " + (number + 1) + " of " + pageCount); + } + + /** + * Shows the previous page. + */ + void goToPreviousPage(ActionEvent e) { + if (currentPage <= 0) + return; + currentPage--; + goToPage(currentPage); + } + + + /** + * Shows the next page. + */ + void goToNextPage(ActionEvent e) { + if (currentPage >= pageCount - 1) + return; + currentPage++; + goToPage(currentPage); + } + + /** + * Shows the last page. + */ + void goToLastPage(ActionEvent e) { + + if (currentPage == pageCount - 1) return; + currentPage = pageCount - 1; + + goToPage(currentPage); + } + + /** + * Shows the first page. + */ + void goToFirstPage(ActionEvent e) { + if (currentPage == 0) + return; + currentPage = 0; + goToPage(currentPage); + } + + void print(ActionEvent e) { + Properties p = null; + + Container parent = this.getRootPane(); + while ( !( parent instanceof Frame )) parent = parent.getParent(); + Frame f = (Frame)parent; + + PrintJob pj = f.getToolkit().getPrintJob(f, getTitle(), p); + if(pj == null) return; + Graphics pg = pj.getGraphics(); + if (pg != null) { + docPanel.paintAll(pg); + pg.dispose(); + } + pj.end(); + } + + public void setScale(double scaleFactor) { + + if (scaleFactor == 25.0) + scale.setSelectedIndex(0); + else if (scaleFactor == 50.0) + scale.setSelectedIndex(1); + else if (scaleFactor == 75.0) + scale.setSelectedIndex(2); + else if (scaleFactor == 100.0) + scale.setSelectedIndex(3); + else if (scaleFactor == 150.0) + scale.setSelectedIndex(4); + else if (scaleFactor == 200.0) + scale.setSelectedIndex(5); + + renderer.setScaleFactor(scaleFactor); + previewArea.invalidate(); + previewArea.repaint(); + } + + void scale_actionPerformed(ActionEvent e) { + setScale(new Double((String)scale.getSelectedItem()).doubleValue()); + } + + + public void setPageCount(int aPageCount) { + pageCount = aPageCount; + statusBar.setText("Page 1 of " + pageCount); + } + +} // class PreviewDialog + + + + + + + + + + + + + + + + + + + diff --git a/src/org/apache/fop/viewer/PreviewDialogAboutBox.java b/src/org/apache/fop/viewer/PreviewDialogAboutBox.java new file mode 100644 index 000000000..2d272203d --- /dev/null +++ b/src/org/apache/fop/viewer/PreviewDialogAboutBox.java @@ -0,0 +1,99 @@ + +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.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.*; + +import org.apache.fop.apps.Version; + + + +public class PreviewDialogAboutBox extends Dialog implements ActionListener { + + JPanel panel1 = new JPanel(); + JPanel panel2 = new JPanel(); + JPanel insetsPanel1 = new JPanel(); + JPanel insetsPanel2 = new JPanel(); + JPanel insetsPanel3 = new JPanel(); + JButton button1 = new JButton(); + JLabel imageControl1 = new JLabel(); + ImageIcon imageIcon; + JLabel label1 = new JLabel(); + JLabel label2 = new JLabel(); + JLabel label3 = new JLabel(); + JLabel label4 = new JLabel(); + BorderLayout borderLayout1 = new BorderLayout(); + BorderLayout borderLayout2 = new BorderLayout(); + FlowLayout flowLayout1 = new FlowLayout(); + FlowLayout flowLayout2 = new FlowLayout(); + GridLayout gridLayout1 = new GridLayout(); + String product = "FOP AWT-Preview"; + String version = "Version: " + Version.getVersion(); + String copyright = "See xml.apache.org"; + String comments = "";//"Print Preview"; + + public PreviewDialogAboutBox(Frame parent) { + super(parent); + enableEvents(AWTEvent.WINDOW_EVENT_MASK); + + //imageIcon = new ImageIcon(getClass().getResource("Hier der Grafikname")); + this.setTitle("Info"); + setResizable(false); + panel1.setLayout(borderLayout1); + panel2.setLayout(borderLayout2); + insetsPanel1.setLayout(flowLayout1); + insetsPanel2.setLayout(flowLayout1); + insetsPanel2.setBorder(new EmptyBorder(10, 10, 10, 10)); + gridLayout1.setRows(4); + gridLayout1.setColumns(1); + label1.setText(product); + label2.setText(version); + label3.setText(copyright); + label4.setText(comments); + insetsPanel3.setLayout(gridLayout1); + insetsPanel3.setBorder(new EmptyBorder(10, 60, 10, 10)); + button1.setText("OK"); + button1.addActionListener(this); + insetsPanel2.add(imageControl1, null); + panel2.add(insetsPanel2, BorderLayout.WEST); + this.add(panel1, null); + insetsPanel3.add(label1, null); + insetsPanel3.add(label2, null); + insetsPanel3.add(label3, null); + insetsPanel3.add(label4, null); + panel2.add(insetsPanel3, BorderLayout.CENTER); + insetsPanel1.add(button1, null); + panel1.add(insetsPanel1, BorderLayout.SOUTH); + panel1.add(panel2, BorderLayout.NORTH); + pack(); + } + + protected void processWindowEvent(WindowEvent e) { + if (e.getID() == WindowEvent.WINDOW_CLOSING) { + cancel(); + } + super.processWindowEvent(e); + } + + void cancel() { + dispose(); + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == button1) { + cancel(); + } + } +} +