Author: thomasobrien95
Date: Thu Dec 18 13:16:01 2008
New Revision: 2890
Added:
trunk/src/ca/sqlpower/architect/swingui/PrintSettings.java
Modified:
trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
trunk/src/ca/sqlpower/architect/swingui/PrintPanel.java
trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java
Log:
Fix for bug 1534. The properties of the print dialog are now all saved. The
properties being saved that was missing before are: zoom, number of copies,
if page number are being printed, the page orientation, the paper size, the
borders, and the printer last printed on.
Modified:
trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
==============================================================================
---
trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
(original)
+++
trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Thu Dec 18 13:16:01 2008
@@ -69,6 +69,7 @@
private RecentMenu recent;
private ArchitectSession delegateSession;
private OLAPRootObject olapRootObject;
+ private PrintSettings printSettings;
private boolean showPkTag = true;
private boolean showFkTag = true;
@@ -112,6 +113,7 @@
kettleJob = new KettleJob(this);
+ printSettings = new PrintSettings();
}
public TestingArchitectSwingSession(ArchitectSwingSessionContext
context, SwingUIProject project) throws ArchitectException {
@@ -366,6 +368,10 @@
public JMenu createDataSourcesMenu() {
return new JMenu();
+ }
+
+ public PrintSettings getPrintSettings() {
+ return printSettings;
}
}
Modified: trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java Thu
Dec 18 13:16:01 2008
@@ -325,4 +325,6 @@
* and added to this session's DB Tree as a source database.
*/
public JMenu createDataSourcesMenu();
+
+ public PrintSettings getPrintSettings();
}
Modified:
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Thu Dec 18 13:16:01 2008
@@ -156,6 +156,11 @@
private final OLAPSchemaManager olapSchemaManager;
/**
+ * This will store the properties of the print panel.
+ */
+ private final PrintSettings printSettings;
+
+ /**
* Creates a new swing session, including a new visible architect
frame, with
* the given parent context and the given name.
*
@@ -218,6 +223,8 @@
swingWorkers = new HashSet<SPSwingWorker>();
olapEditSessions = new ArrayList<OLAPEditSession>();
+
+ printSettings = new PrintSettings();
}
public void initGUI() throws ArchitectException {
@@ -920,4 +927,9 @@
return dbcsMenu;
}
+
+ public PrintSettings getPrintSettings() {
+ return printSettings;
+ }
+
}
Modified: trunk/src/ca/sqlpower/architect/swingui/PrintPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/PrintPanel.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/PrintPanel.java Thu Dec 18
13:16:01 2008
@@ -84,11 +84,11 @@
private PageFormat pageFormat;
private JLabel pageFormatLabel;
private JButton pageFormatButton;
- private JLabel zoomLabel;
- private JSlider zoomSlider;
+ private final JLabel zoomLabel;
+ private final JSlider zoomSlider;
private JLabel pageCountLabel;
- private JCheckBox printPageNumbersBox;
- private JSpinner numOfCopies;
+ private final JCheckBox printPageNumbersBox;
+ private final JSpinner numOfCopies;
private PrintPreviewPanel previewPanel;
@@ -99,6 +99,7 @@
private final ArchitectSwingSession session;
+
public PrintPanel(ArchitectSwingSession session) {
super();
setOpaque(true);
@@ -109,26 +110,35 @@
// don't need this playpen to be interactive or respond to
SQLObject changes
pp.destroy();
- add(new PrintPreviewPanel());
+ previewPanel = new PrintPreviewPanel();
+ add(previewPanel);
job = PrinterJob.getPrinterJob();
jobAttributes = new HashPrintRequestAttributeSet();
pageFormat = new PageFormat();
- pageFormat.setPaper(new Paper());
- pageFormat.getPaper().setImageableArea(50, 50,
pageFormat.getWidth()-(50*2), pageFormat.getHeight()-(50*2));
+ Paper paper = new Paper();
+ PrintSettings printSettings = session.getPrintSettings();
+ paper.setSize(printSettings.getPaperWidth(),
printSettings.getPaperHeight());
+ paper.setImageableArea(printSettings.getLeftBorder(),
printSettings.getRightBorder(),
+ paper.getWidth() - printSettings.getLeftBorder() -
printSettings.getRightBorder(),
+ paper.getHeight() - printSettings.getTopBorder() -
printSettings.getBottomBorder());
+ pageFormat.setPaper(paper);
+ pageFormat.setOrientation(printSettings.getOrientation());
+ logger.debug("Page format has paper size " +
pageFormat.getPaper().getWidth() + "x" + pageFormat.getPaper().getHeight());
+ logger.debug("Page size saved as " + printSettings.getPaperWidth() + "x"
+ printSettings.getPaperHeight());
JPanel formPanel = new JPanel(new FormLayout());
formPanel.add(new
JLabel(Messages.getString("PrintPanel.printerLabel"))); //$NON-NLS-1$
formPanel.add(printerBox = new
JComboBox(PrinterJob.lookupPrintServices()));
- printerBox.setSelectedItem(getPreferredPrinter(session));
+ printerBox.setSelectedItem(getPreferredPrinter(session));
formPanel.add(new
JLabel(Messages.getString("PrintPanel.pageFormateLabel"))); //$NON-NLS-1$
String pf = paperToPrintable(pageFormat);
formPanel.add(pageFormatLabel = new JLabel(pf.toString()));
formPanel.add(new
JLabel(Messages.getString("PrintPanel.numCopiesLabel"))); //$NON-NLS-1$
- numOfCopies = new JSpinner(new SpinnerNumberModel(1, 1, null,
1));
+ numOfCopies = new JSpinner(new
SpinnerNumberModel(printSettings.getNumCopies(), 1, null, 1));
formPanel.add(numOfCopies);
formPanel.add(new
JLabel(Messages.getString("PrintPanel.changePageFormatLabel")));
//$NON-NLS-1$
@@ -138,14 +148,15 @@
setPageFormat(job.pageDialog(pageFormat));
}
});
- formPanel.add(zoomLabel = new
JLabel(Messages.getString("PrintPanel.scalingLabel"))); //$NON-NLS-1$
- formPanel.add(zoomSlider = new JSlider(JSlider.HORIZONTAL, 1,
300, 100));
+ zoomLabel = new
JLabel(Messages.getString("PrintPanel.scalingLabel"));
+ setZoom(printSettings.getZoom());
+ formPanel.add(zoomLabel); //$NON-NLS-1$
+ formPanel.add(zoomSlider = new JSlider(JSlider.HORIZONTAL, 1, 300,
(int)(zoom * 100)));
formPanel.add(new JLabel("")); //$NON-NLS-1$
formPanel.add(printPageNumbersBox = new
JCheckBox(Messages.getString("PrintPanel.printPageNumbersOption")));
//$NON-NLS-1$
- printPageNumbersBox.setSelected(true);
+
printPageNumbersBox.setSelected(printSettings.isPageNumbersPrinted());
- setZoom(1.0);
zoomSlider.addChangeListener(this);
pageCountLabel = new
JLabel(Messages.getString("PrintPanel.pageCountLabel",
String.valueOf(getNumberOfPages()))); //$NON-NLS-1$
formPanel.add(pageCountLabel);
@@ -177,9 +188,20 @@
* Called to determine what this user last printed from.
*/
PrintService getPreferredPrinter(ArchitectSwingSession session) {
+ String lastUsedPrinter =
session.getPrintSettings().getPrinterName();
+ if (lastUsedPrinter != null) {
+ Iterator<PrintService> it = Arrays.asList(
PrinterJob.lookupPrintServices() ).iterator();
+ while (it.hasNext()) {
+ PrintService ps = (PrintService) it.next();
+ if (ps.getName().equals(lastUsedPrinter)) {
+ return ps;
+ }
+ }
+ }
+
String defaultPrinterName =
session.getUserSettings().getPrintUserSettings().getDefaultPrinterName();
PrintService psRetVal = null;
- Iterator it = Arrays.asList( PrinterJob.lookupPrintServices()
).iterator();
+ Iterator<PrintService> it = Arrays.asList(
PrinterJob.lookupPrintServices() ).iterator();
while (it.hasNext() && psRetVal == null) {
PrintService ps = (PrintService) it.next();
if (ps.getName().equals(defaultPrinterName)) {
@@ -301,6 +323,20 @@
// --- architect panel ----
public boolean applyChanges() {
+ PrintSettings printSettings = session.getPrintSettings();
+ printSettings.setZoom(zoom);
+ printSettings.setNumCopies((Integer) numOfCopies.getValue());
+
printSettings.setPageNumbersPrinted(printPageNumbersBox.isSelected());
+ printSettings.setPrinterName(((PrintService)
printerBox.getSelectedItem()).getName());
+ printSettings.setOrientation(pageFormat.getOrientation());
+ Paper paper = pageFormat.getPaper();
+ printSettings.setPaperWidth(paper.getWidth());
+ printSettings.setPaperHeight(paper.getHeight());
+ printSettings.setLeftBorder(paper.getImageableX());
+ printSettings.setRightBorder(paper.getWidth() -
paper.getImageableWidth() - paper.getImageableX());
+ printSettings.setTopBorder(paper.getImageableY());
+ printSettings.setBottomBorder(paper.getHeight() -
paper.getImageableHeight() - paper.getImageableY());
+
try {
// set current printer as default
if (printerBox.getItemCount() > 0 && printerBox.getSelectedItem()
instanceof PrintService) {
@@ -460,6 +496,5 @@
// TODO return whether this panel has been changed
return true;
}
-
}
Added: trunk/src/ca/sqlpower/architect/swingui/PrintSettings.java
==============================================================================
--- (empty file)
+++ trunk/src/ca/sqlpower/architect/swingui/PrintSettings.java Thu Dec 18
13:16:01 2008
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2008, SQL Power Group Inc.
+ *
+ * This file is part of Power*Architect.
+ *
+ * Power*Architect is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Power*Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.swingui;
+
+import java.awt.print.PageFormat;
+
+/**
+ * A simple class for storing print settings.
+ */
+public class PrintSettings {
+
+ private String printerName;
+
+ private double zoom;
+
+ private int numCopies;
+
+ private boolean pageNumbersPrinted;
+
+ /**
+ * This is the orientation of the page. It's value is from
+ * {...@link PageFormat}.
+ */
+ private int orientation;
+
+ private double paperWidth;
+
+ private double paperHeight;
+
+ private double leftBorder;
+
+ private double rightBorder;
+
+ private double topBorder;
+
+ private double bottomBorder;
+
+ public PrintSettings() {
+ //generic defaults
+ zoom = 1.0;
+ numCopies = 1;
+ pageNumbersPrinted = true;
+ printerName = null;
+ orientation = PageFormat.PORTRAIT;
+ paperWidth = 8.5 * 72;
+ paperHeight = 11.0 * 72;
+ leftBorder = 50;
+ rightBorder = 50;
+ topBorder = 50;
+ bottomBorder = 50;
+ }
+
+ public double getPaperWidth() {
+ return paperWidth;
+ }
+
+ public void setPaperWidth(double paperWidth) {
+ this.paperWidth = paperWidth;
+ }
+
+ public double getPaperHeight() {
+ return paperHeight;
+ }
+
+ public void setPaperHeight(double paperHeight) {
+ this.paperHeight = paperHeight;
+ }
+
+ public String getPrinterName() {
+ return printerName;
+ }
+
+ public void setPrinterName(String printerName) {
+ this.printerName = printerName;
+ }
+
+ public double getZoom() {
+ return zoom;
+ }
+
+ public void setZoom(double zoom) {
+ this.zoom = zoom;
+ }
+
+ public int getNumCopies() {
+ return numCopies;
+ }
+
+ public void setNumCopies(int numCopies) {
+ this.numCopies = numCopies;
+ }
+
+ public boolean isPageNumbersPrinted() {
+ return pageNumbersPrinted;
+ }
+
+ public void setPageNumbersPrinted(boolean pageNumbersPrinted) {
+ this.pageNumbersPrinted = pageNumbersPrinted;
+ }
+
+ public void setOrientation(int orientation) {
+ this.orientation = orientation;
+ }
+
+ public int getOrientation() {
+ return orientation;
+ }
+
+ public double getLeftBorder() {
+ return leftBorder;
+ }
+
+ public void setLeftBorder(double leftBorder) {
+ this.leftBorder = leftBorder;
+ }
+
+ public double getRightBorder() {
+ return rightBorder;
+ }
+
+ public void setRightBorder(double rightBorder) {
+ this.rightBorder = rightBorder;
+ }
+
+ public double getTopBorder() {
+ return topBorder;
+ }
+
+ public void setTopBorder(double topBorder) {
+ this.topBorder = topBorder;
+ }
+
+ public double getBottomBorder() {
+ return bottomBorder;
+ }
+
+ public void setBottomBorder(double bottomBorder) {
+ this.bottomBorder = bottomBorder;
+ }
+
+}
Modified: trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java Thu Dec 18
13:16:01 2008
@@ -213,6 +213,10 @@
protected Digester setupDigester() throws
ParserConfigurationException, SAXException {
Digester d = super.setupDigester();
+
+ PrintSettingsFactory printSettingsFactory = new
PrintSettingsFactory();
+ d.addFactoryCreate("*/print-settings", printSettingsFactory);
+ d.addSetProperties("*/print-settings");
// the play pen
RelationalPlayPenFactory ppFactory = new
RelationalPlayPenFactory();
@@ -586,6 +590,14 @@
}
}
+ private class PrintSettingsFactory extends
AbstractObjectCreationFactory {
+ @Override
+ public Object createObject(Attributes arg0) throws Exception {
+ return getSession().getPrintSettings();
+ }
+
+ }
+
// ------------- WRITING THE PROJECT FILE ---------------
/**
@@ -689,6 +701,7 @@
ioo.println(out, "<architect-project version=\"1.0\"
appversion=\""+ArchitectVersion.APP_VERSION+"\">"); //$NON-NLS-1$
//$NON-NLS-2$
ioo.indent++;
ioo.println(out, "<project-name>"+SQLPowerUtils.escapeXML(getSession().getName())+"</project-name>");
//$NON-NLS-1$ //$NON-NLS-2$
+ savePrintSettings(out, getSession().getPrintSettings());
saveDataSources(out);
saveSourceDatabases(out);
saveTargetDatabase(out);
@@ -1313,6 +1326,28 @@
} else {
ioo.niprintln(out, "/>"); //$NON-NLS-1$
}
+ }
+
+ private void savePrintSettings(PrintWriter out, PrintSettings
settings) {
+ StringBuilder tagText = new StringBuilder();
+ tagText.append("<print-settings ");
+
+ if (settings.getPrinterName() != null) {
+ tagText.append("printerName=\"" + settings.getPrinterName()
+ "\" ");
+ }
+ tagText.append("numCopies=\"" + settings.getNumCopies() + "\" ");
+ tagText.append("zoom=\"" + settings.getZoom() + "\" ");
+ tagText.append("pageNumbersPrinted=\"" +
Boolean.toString(settings.isPageNumbersPrinted()) + "\" ");
+ tagText.append("orientation=\"" + settings.getOrientation()
+ "\" ");
+ tagText.append("paperWidth=\"" + settings.getPaperWidth() + "\" ");
+ tagText.append("paperHeight=\"" + settings.getPaperHeight()
+ "\" ");
+ tagText.append("leftBorder=\"" + settings.getLeftBorder() + "\" ");
+ tagText.append("rightBorder=\"" + settings.getRightBorder()
+ "\" ");
+ tagText.append("topBorder=\"" + settings.getTopBorder() + "\" ");
+ tagText.append("bottomBorder=\"" + settings.getBottomBorder()
+ "\" ");
+
+ tagText.append("/>"); //$NON-NLS-1$
+ ioo.println(out, tagText.toString());
}
private String quote(String str) {