View Javadoc

1   // Copyright 2003-2007, FreeHEP.
2   package org.freehep.graphicsio.ps;
3   
4   import java.awt.Component;
5   import java.awt.Dimension;
6   import java.io.IOException;
7   import java.io.OutputStream;
8   import java.util.Properties;
9   
10  import javax.swing.JLabel;
11  import javax.swing.JPanel;
12  
13  import org.freehep.graphics2d.VectorGraphics;
14  import org.freehep.graphicsio.ImageConstants;
15  import org.freehep.graphicsio.InfoConstants;
16  import org.freehep.graphicsio.AbstractVectorGraphicsIO;
17  import org.freehep.graphicsio.exportchooser.AbstractExportFileType;
18  import org.freehep.graphicsio.exportchooser.BackgroundPanel;
19  import org.freehep.graphicsio.exportchooser.FontPanel;
20  import org.freehep.graphicsio.exportchooser.ImageTypePanel;
21  import org.freehep.graphicsio.exportchooser.InfoPanel;
22  import org.freehep.graphicsio.exportchooser.OptionCheckBox;
23  import org.freehep.graphicsio.exportchooser.OptionComboBox;
24  import org.freehep.graphicsio.exportchooser.OptionPanel;
25  import org.freehep.graphicsio.exportchooser.PageLayoutPanel;
26  import org.freehep.graphicsio.exportchooser.PageMarginPanel;
27  import org.freehep.swing.layout.TableLayout;
28  import org.freehep.util.UserProperties;
29  
30  /**
31   * 
32   * @author Charles Loomis, Simon Fischer
33   * @version $Id: AbstractPSExportFileType.java 12753 2007-06-12 22:32:31Z duns $
34   */
35  public abstract class AbstractPSExportFileType extends AbstractExportFileType {
36  
37  	protected static final String bitsList[] = { "1", "2", "4", "8" };
38  
39  	protected OptionPanel preview;
40  
41  	protected OptionCheckBox previewCheckBox;
42  
43  	public boolean hasOptionPanel() {
44  		return true;
45  	}
46  
47  	public String[] getMIMETypes() {
48  		return new String[] { "application/postscript" };
49  	}
50  
51  	public JPanel createOptionPanel(Properties user) {
52  		UserProperties options = new UserProperties(user, PSGraphics2D
53  				.getDefaultProperties());
54  		preview = new OptionPanel("Preview Image");
55  		previewCheckBox = new OptionCheckBox(options, PSGraphics2D.PREVIEW,
56  				"Include preview");
57  
58  		preview.add(TableLayout.FULL, previewCheckBox);
59  
60  		final JLabel previewLabel = new JLabel("Bits per sample");
61  		preview.add(TableLayout.LEFT, previewLabel);
62  		previewCheckBox.enables(previewLabel);
63  
64  		final OptionComboBox previewComboBox = new OptionComboBox(options,
65  				PSGraphics2D.PREVIEW_BITS, bitsList);
66  		preview.add(TableLayout.RIGHT, previewComboBox);
67  		previewCheckBox.enables(previewComboBox);
68  		preview.setVisible(false);
69  
70  		// rootKeys for FontProperties
71  		String rootKey = PSGraphics2D.class.getName();
72  		String abstractRootKey = AbstractVectorGraphicsIO.class.getName();
73  
74  		JPanel infoPanel = new InfoPanel(options, rootKey, new String[] {
75  				InfoConstants.FOR, InfoConstants.TITLE });
76  
77  		// TableLayout.LEFT Panel
78  		JPanel leftPanel = new OptionPanel();
79  		leftPanel
80  				.add(TableLayout.COLUMN, new PageLayoutPanel(options, rootKey));
81  		leftPanel
82  				.add(TableLayout.COLUMN, new PageMarginPanel(options, rootKey));
83  		leftPanel.add(TableLayout.COLUMN_FILL, new JLabel());
84  
85  		// TableLayout.RIGHT Panel
86  		JPanel rightPanel = new OptionPanel();
87  		rightPanel.add(TableLayout.COLUMN, new BackgroundPanel(options,
88  				rootKey, false));
89  		rightPanel.add(TableLayout.COLUMN, preview);
90  		rightPanel.add(TableLayout.COLUMN, new ImageTypePanel(options, rootKey,
91  				new String[] { ImageConstants.SMALLEST, ImageConstants.ZLIB,
92  						ImageConstants.JPG }));
93  		rightPanel.add(TableLayout.COLUMN, new FontPanel(options, rootKey,
94  				abstractRootKey));
95  		rightPanel.add(TableLayout.COLUMN_FILL, new JLabel());
96  
97  		// Make the full panel.
98  		OptionPanel optionsPanel = new OptionPanel();
99  		optionsPanel.add("0 0 [5 5 5 5] wt", leftPanel);
100 		optionsPanel.add("1 0 [5 5 5 5] wt", rightPanel);
101 		optionsPanel.add("0 1 2 1 [5 5 5 5] wt", infoPanel);
102 		optionsPanel.add(TableLayout.COLUMN_FILL, new JLabel());
103 
104 		return optionsPanel;
105 	}
106 
107 	public VectorGraphics getGraphics(OutputStream os, Component target)
108 			throws IOException {
109 
110 		return new PSGraphics2D(os, target);
111 	}
112 
113 	public VectorGraphics getGraphics(OutputStream os, Dimension dimension)
114 			throws IOException {
115 
116 		return new PSGraphics2D(os, dimension);
117 	}
118 }