ENSDF++ 1.1
An easy, fast and simple way to run querys towards the ENSDF database, written in C++.
EpsDocument.java
Go to the documentation of this file.
00001 /* 
00002 Copyright Paul James Mutton, 2001-2004, http://www.jibble.org/
00003 
00004 This file is part of EpsGraphics2D.
00005 
00006 This software is dual-licensed, allowing you to choose between the GNU
00007 General Public License (GPL) and the www.jibble.org Commercial License.
00008 Since the GPL may be too restrictive for use in a proprietary application,
00009 a commercial license is also provided. Full license information can be
00010 found at http://www.jibble.org/licenses/
00011 
00012 $Author: pjm2 $
00013 $Id: EpsDocument.java,v 1.9 2004/07/20 17:42:29 pjm2 Exp $
00014 
00015 */
00016 
00017 
00023 import java.util.*;
00024 import java.io.*;
00025 
00026 
00035 public class EpsDocument {
00036     
00037     
00041     public EpsDocument(String title) {
00042         _title = title;
00043         minX = Float.POSITIVE_INFINITY;
00044         minY = Float.POSITIVE_INFINITY;
00045         maxX = Float.NEGATIVE_INFINITY;
00046         maxY = Float.NEGATIVE_INFINITY;
00047         _stringWriter = new StringWriter();
00048         _bufferedWriter = new BufferedWriter(_stringWriter);
00049     }
00050     
00055     public EpsDocument(String title, OutputStream outputStream, int minX, int minY, int maxX, int maxY) throws IOException {
00056         _title = title;
00057         this.minX = minX;
00058         this.minY = minY;
00059         this.maxX = maxX;
00060         this.maxY = maxY;
00061         _bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
00062         write(_bufferedWriter);
00063     }
00064     
00065     
00069     public synchronized String getTitle() {
00070         return _title;
00071     }
00072     
00073     
00077     public synchronized void updateBounds(double x, double y) {
00078         if (x > maxX) {
00079             maxX = (float) x;
00080         }
00081         if (x < minX) {
00082             minX = (float) x;
00083         }
00084         if (y > maxY) {
00085             maxY = (float) y;
00086         }
00087         if (y < minY) {
00088             minY = (float) y;
00089         }
00090     }
00091     
00092     
00097     public synchronized void append(EpsGraphics2D g, String line) {
00098         if (_lastG == null) {
00099             _lastG = g;
00100         }
00101         else if (g != _lastG) {
00102             EpsGraphics2D lastG = _lastG;
00103             _lastG = g;
00104             // We are being drawn on with a different EpsGraphics2D context.
00105             // We may need to update the clip, etc from this new context.
00106             if (g.getClip() != lastG.getClip()) {
00107                 g.setClip(g.getClip());
00108             }
00109             if (!g.getColor().equals(lastG.getColor())) {
00110                 g.setColor(g.getColor());
00111             }
00112             if (!g.getBackground().equals(lastG.getBackground())) {
00113                 g.setBackground(g.getBackground());
00114             }
00115             // We don't need this, as this only affects the stroke and font,
00116             // which are dealt with separately later on.
00117             //if (!g.getTransform().equals(lastG.getTransform())) {
00118             //    g.setTransform(g.getTransform());
00119             //}
00120             if (!g.getPaint().equals(lastG.getPaint())) {
00121                 g.setPaint(g.getPaint());
00122             }
00123             if (!g.getComposite().equals(lastG.getComposite())) {
00124                 g.setComposite(g.getComposite());
00125             }
00126             if (!g.getComposite().equals(lastG.getComposite())) {
00127                 g.setComposite(g.getComposite());
00128             }
00129             if (!g.getFont().equals(lastG.getFont())) {
00130                 g.setFont(g.getFont());
00131             }
00132             if (!g.getStroke().equals(lastG.getStroke())) {
00133                 g.setStroke(g.getStroke());
00134             }
00135         }
00136         _lastG = g;
00137         
00138         try {
00139             _bufferedWriter.write(line + "\n");
00140         }
00141         catch (IOException e) {
00142             throw new EpsException("Could not write to the output file: " + e);
00143         }
00144     }
00145     
00146     
00151     public synchronized void write(Writer writer) throws IOException {
00152         float offsetX = -minX;
00153         float offsetY = -minY;
00154         
00155         writer.write("%!PS-Adobe-3.0 EPSF-3.0\n");
00156         writer.write("%%Creator: EpsGraphics2D " + EpsGraphics2D.VERSION + " by Paul Mutton, http://www.jibble.org/\n");
00157         writer.write("%%Title: " + _title + "\n");
00158         writer.write("%%CreationDate: " + new Date() + "\n");
00159         writer.write("%%BoundingBox: 0 0 " + ((int) Math.ceil(maxX + offsetX)) + " " + ((int) Math.ceil(maxY + offsetY)) + "\n");
00160         writer.write("%%DocumentData: Clean7Bit\n");
00161         writer.write("%%DocumentProcessColors: Black\n");
00162         writer.write("%%ColorUsage: Color\n");
00163         writer.write("%%Origin: 0 0\n");
00164         writer.write("%%Pages: 1\n");
00165         writer.write("%%Page: 1 1\n");
00166         writer.write("%%EndComments\n\n");
00167         
00168         writer.write("gsave\n");
00169         
00170         if (_stringWriter != null) {
00171             writer.write(offsetX + " " + (offsetY) + " translate\n");
00172             
00173             _bufferedWriter.flush();
00174             StringBuffer buffer = _stringWriter.getBuffer();
00175             for (int i = 0; i < buffer.length(); i++) {
00176                 writer.write(buffer.charAt(i));
00177             }
00178             
00179             writeFooter(writer);
00180         }
00181         else {
00182             writer.write(offsetX + " " + ((maxY - minY) - offsetY) + " translate\n");
00183         }
00184         
00185         writer.flush();
00186     }
00187     
00188     
00189     private void writeFooter(Writer writer) throws IOException {
00190         writer.write("grestore\n");
00191         if (isClipSet()) {
00192             writer.write("grestore\n");
00193         }
00194         writer.write("showpage\n");
00195         writer.write("\n");
00196         writer.write("%%EOF");
00197         writer.flush();
00198     }
00199     
00200     
00201     public synchronized void flush() throws IOException {
00202         _bufferedWriter.flush();
00203     }
00204     
00205     public synchronized void close() throws IOException {
00206         if (_stringWriter == null) {
00207             writeFooter(_bufferedWriter);
00208             _bufferedWriter.flush();
00209             _bufferedWriter.close();
00210         }
00211     }
00212     
00213     
00214     public boolean isClipSet() {
00215         return _isClipSet;
00216     }
00217     
00218     public void setClipSet(boolean isClipSet) {
00219         _isClipSet = isClipSet;
00220     }
00221     
00222     
00223     private float minX;
00224     private float minY;
00225     private float maxX;
00226     private float maxY;
00227     
00228     private boolean _isClipSet = false;
00229 
00230     private String _title;
00231     private StringWriter _stringWriter;
00232     private BufferedWriter _bufferedWriter = null;
00233     
00234     // We need to remember which was the last EpsGraphics2D object to use
00235     // us, as we need to replace the clipping region if another EpsGraphics2D
00236     // object tries to use us.
00237     private EpsGraphics2D _lastG = null;
00238     
00239 }
 All Classes Files Functions Variables Enumerations Enumerator Defines

Back to the main page of the Precalibrated Ion Beam Identification Detector project

Created by Rikard Lundmark