2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
41
package org.openide.text;
43
import org.openide.options.ContextSystemOption;
44
import org.openide.util.HelpCtx;
45
import org.openide.util.NbBundle;
47
import java.awt.print.PageFormat;
48
import java.awt.print.PrinterJob;
49
import java.io.IOException;
50
import java.io.ObjectInput;
51
import java.io.ObjectOutput;
53
/** Settings for output window.
57
public final class PrintSettings extends ContextSystemOption {
58
// final because overrides Externalizable methods
60
/** serialVersionUID */
61
static final long serialVersionUID = -9102470021814206818L;
63
/** Constant for center position of page header. */
64
public static final int CENTER = 0x1;
66
/** Constant for right position of page header. */
67
public static final int RIGHT = 0x2;
69
/** Constant for left position of page header. */
70
public static final int LEFT = 0x0;
72
/** Property name of the wrap property */
73
public static final String PROP_PAGE_FORMAT = "pageFormat"; // NOI18N
75
/** Property name of the wrap property */
76
public static final String PROP_WRAP = "wrap"; // NOI18N
78
/** Property name of the header format property */
79
public static final String PROP_HEADER_FORMAT = "headerFormat"; // NOI18N
81
/** Property name of the footer format property */
82
public static final String PROP_FOOTER_FORMAT = "footerFormat"; // NOI18N
84
/** Property name of the header font property */
85
public static final String PROP_HEADER_FONT = "headerFont"; // NOI18N
87
/** Property name of the footer font property */
88
public static final String PROP_FOOTER_FONT = "footerFont"; // NOI18N
90
/** Property name of the header alignment property */
91
public static final String PROP_HEADER_ALIGNMENT = "headerAlignment"; // NOI18N
93
/** Property name of the footer alignment property */
94
public static final String PROP_FOOTER_ALIGNMENT = "footerAlignment"; // NOI18N
96
/** Property name of the line ascent correction property */
97
public static final String PROP_LINE_ASCENT_CORRECTION = "lineAscentCorrection"; // NOI18N
98
private static final String HELP_ID = "editing.printing"; // !!! NOI18N
101
public String displayName() {
102
return NbBundle.getMessage(PrintSettings.class, "CTL_Print_settings");
105
public HelpCtx getHelpCtx() {
106
return new HelpCtx(HELP_ID);
109
/** @return an instance of PageFormat
110
* The returned page format is either previously set by
111
* PageSetupAction or is acquired as a default PageFormat
112
* from supported PrinterJob
114
public static PageFormat getPageFormat(PrinterJob pj) {
115
return PrintPreferences.getPageFormat(pj);
118
/** @deprecated Use {@link #getPageFormat(PrinterJob)} instead. */
119
public PageFormat getPageFormat() {
120
return getPageFormat(PrinterJob.getPrinterJob());
123
/** sets page format */
124
public void setPageFormat(PageFormat pf) {
125
PrintPreferences.setPageFormat(pf);
126
firePropertyChange(PROP_PAGE_FORMAT, null, pf);
129
public boolean getWrap() {
130
return PrintPreferences.getWrap();
133
public void setWrap(boolean b) {
134
PrintPreferences.setWrap(b);
135
firePropertyChange(PROP_WRAP, (b ? Boolean.FALSE : Boolean.TRUE), (b ? Boolean.TRUE : Boolean.FALSE));
138
public String getHeaderFormat() {
139
return PrintPreferences.getHeaderFormat();
142
public void setHeaderFormat(String s) {
143
PrintPreferences.setHeaderFormat(s);
144
firePropertyChange(PROP_HEADER_FORMAT, null, s);
147
public String getFooterFormat() {
148
return PrintPreferences.getFooterFormat();
151
public void setFooterFormat(String s) {
152
PrintPreferences.setFooterFormat(s);
153
firePropertyChange(PROP_FOOTER_FORMAT, null, s);
156
public Font getHeaderFont() {
157
return PrintPreferences.getHeaderFont();
160
public void setHeaderFont(Font f) {
161
PrintPreferences.setHeaderFont(f);
162
firePropertyChange(PROP_HEADER_FONT, null, f);
165
public Font getFooterFont() {
166
return PrintPreferences.getFooterFont();
169
public void setFooterFont(Font f) {
170
PrintPreferences.setFooterFont(f);
171
firePropertyChange(PROP_FOOTER_FONT, null, f);
174
public int getHeaderAlignment() {
175
return fromAlignment(PrintPreferences.getHeaderAlignment());
178
public void setHeaderAlignment(int alignment) {
179
PrintPreferences.setHeaderAlignment(toAlignment(alignment));
180
firePropertyChange(PROP_HEADER_ALIGNMENT, null, new Integer(alignment));
183
private PrintPreferences.Alignment toAlignment(int alignment) {
184
PrintPreferences.Alignment retval = PrintPreferences.Alignment.CENTER;
187
retval = PrintPreferences.Alignment.CENTER;
190
retval = PrintPreferences.Alignment.LEFT;
193
retval = PrintPreferences.Alignment.RIGHT;
199
private int fromAlignment(PrintPreferences.Alignment alignment) {
201
if (PrintPreferences.Alignment.CENTER.equals(alignment)) {
203
} else if (PrintPreferences.Alignment.LEFT.equals(alignment)) {
205
} else if (PrintPreferences.Alignment.RIGHT.equals(alignment)) {
212
public int getFooterAlignment() {
213
return fromAlignment(PrintPreferences.getFooterAlignment());
216
public void setFooterAlignment(int alignment) {
217
PrintPreferences.setFooterAlignment(toAlignment(alignment));
218
firePropertyChange(PROP_FOOTER_ALIGNMENT, null, new Integer(alignment));
221
/** Getter for lineAscentCorrection property. */
222
public float getLineAscentCorrection() {
223
return PrintPreferences.getLineAscentCorrection();
226
/** Setter for lineAscentCorrection property.
227
* @param correction the correction
228
* @exception IllegalArgumentException if <tt>correction</tt> is less than 0.
230
public void setLineAscentCorrection(float correction) {
231
PrintPreferences.setLineAscentCorrection(correction);
232
firePropertyChange(PROP_LINE_ASCENT_CORRECTION, null, new Float(correction));
235
public void writeExternal(ObjectOutput obtos) throws IOException {
236
// no-op, nobody should be externalizing this option, but if they do
237
// just do not store anything
240
public void readExternal(ObjectInput obtis) throws IOException, ClassNotFoundException {
241
// no-op, to ignore previously serialized options
244
/** Property editor for alignment properties */
245
public static class AlignmentEditor extends java.beans.PropertyEditorSupport {
246
private String sCENTER;
247
private String sRIGHT;
248
private String sLEFT;
249
private String[] tags = new String[] {
250
sLEFT = NbBundle.getMessage(PrintSettings.class, "CTL_LEFT"),
251
sCENTER = NbBundle.getMessage(PrintSettings.class, "CTL_CENTER"),
252
sRIGHT = NbBundle.getMessage(PrintSettings.class, "CTL_RIGHT")
255
public String[] getTags() {
259
public String getAsText() {
260
return tags[((Integer) getValue()).intValue()];
263
public void setAsText(String s) {
264
if (s.equals(sLEFT)) {
265
setValue(new Integer(0));
266
} else if (s.equals(sCENTER)) {
267
setValue(new Integer(1));
269
setValue(new Integer(2));
274
/** Property editor for PageFormat instances */
275
public static class PageFormatEditor extends java.beans.PropertyEditorSupport {
277
public String getAsText() {
281
/* @return <tt>true</tt> */
282
public boolean supportsCustomEditor() {
287
* @return <tt>null</tt> Shows pageDialog, however.
289
public java.awt.Component getCustomEditor() {
290
PageFormat pf = (PageFormat) getValue();
291
PrinterJob pj = PrinterJob.getPrinterJob();
292
PageFormat npf = pj.pageDialog(pf);
295
((PrintSettings)PrintSettings.findObject(PrintSettings.class)).setPageFormat((PageFormat) npf.clone());