Skip to content

Commit

Permalink
[pdf] remember export settings for pdf wizard page (#226)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Gasdorf <fgdrf@users.sourceforge.net>
  • Loading branch information
fgdrf committed Mar 21, 2017
1 parent e656848 commit 528f8f3
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 31 deletions.
Expand Up @@ -580,7 +580,7 @@ public class Messages extends NLS {

public static String ImageExportPage_leftMargin;

public static String ImageExportPage_lowerMargin;
public static String ImageExportPage_bottomMargin;

public static String ImageExportPage_marginsGroup;

Expand Down
Expand Up @@ -182,7 +182,7 @@ ImageExportPage_landscapeLabel = Landscape
ImageExportPage_leftMargin = left margin [mm]
ImageExportPage_lowerMargin = lower margin [mm]
ImageExportPage_bottomMargin = bottom margin [mm]
ImageExportPage_marginsGroup = Margins
Expand Down
Expand Up @@ -178,7 +178,7 @@ ImageExportPage_landscapeLabel = Querformat

ImageExportPage_leftMargin = Linker Rand [mm]

ImageExportPage_lowerMargin = Unterer Rand [mm]
ImageExportPage_bottomMargin = Unterer Rand [mm]

ImageExportPage_marginsGroup = Seitenr\u00E4nder

Expand Down
Expand Up @@ -74,7 +74,7 @@ ImageExportPage_ImageSettingsDescription=Mapak adierazitako formatura esportatuk
ImageExportPage_ImageWidth=Zabalera:
ImageExportPage_landscapeLabel=Paisaia
ImageExportPage_leftMargin=ezkerreko marjina [mm]
ImageExportPage_lowerMargin=beheko marjina [mm]
ImageExportPage_bottomMargin=beheko marjina [mm]
ImageExportPage_marginsGroup=Marjinak
ImageExportPage_PDF_Group_Description=PDF parametroak
ImageExportPage_png=png
Expand Down
Expand Up @@ -150,7 +150,7 @@ ImageExportPage_landscapeLabel = Orizzonatale
ImageExportPage_leftMargin = margine sinistro [mm]
ImageExportPage_lowerMargin = margine inferiore [mm]
ImageExportPage_bottomMargin = margine inferiore [mm]
ImageExportPage_marginsGroup = Margini
Expand Down
Expand Up @@ -174,7 +174,7 @@ ImageExportPage_landscapeLabel = \uac00\ub85c

ImageExportPage_leftMargin = \uc67c\ucabd \uc5ec\ubc31 [mm]

ImageExportPage_lowerMargin = \ud558\uc704 \uc5ec\ubc31 [mm]
ImageExportPage_bottomMargin = \ud558\uc704 \uc5ec\ubc31 [mm]

ImageExportPage_marginsGroup = \uc5ec\ubc31

Expand Down
Expand Up @@ -174,7 +174,7 @@ ImageExportPage_landscapeLabel = \u0410\u043b\u044c\u0431\u043e\u043c\u043d\u044

ImageExportPage_leftMargin = \u043b\u0435\u0432\u044b\u0439 \u043e\u0442\u0441\u0442\u0443\u043f [\u043c\u043c]

ImageExportPage_lowerMargin = \u043d\u0438\u0436\u043d\u0438\u0439 \u043e\u0442\u0441\u0442\u0443\u043f [\u043c\u043c]
ImageExportPage_bottomMargin = \u043d\u0438\u0436\u043d\u0438\u0439 \u043e\u0442\u0441\u0442\u0443\u043f [\u043c\u043c]

ImageExportPage_marginsGroup = \u041e\u0442\u0441\u0442\u0443\u043f

Expand Down
Expand Up @@ -13,6 +13,7 @@
import java.io.File;

import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
Expand All @@ -24,6 +25,7 @@
import org.eclipse.swt.widgets.Spinner;
import org.locationtech.udig.project.IMap;
import org.locationtech.udig.project.ui.internal.Messages;
import org.locationtech.udig.project.ui.internal.ProjectUIPlugin;

/**
* A strategy for exporting to PDF
Expand All @@ -34,13 +36,21 @@
*/
public class PDFImageExportFormat extends ImageExportFormat {


private static final int PDF_DEFAULT_USER_UNIT = 72;

private static final String PREFSTORE_PARAM_MARGIN_TOP = "MarginTop";
private static final String PREFSTORE_PARAM_MARGIN_BOTTOM = "MarginBottom";
private static final String PREFSTORE_PARAM_MARGIN_RIGHT = "MarginRight";
private static final String PREFSTORE_PARAM_MARGIN_LEFT = "MarginLeft";
private static final String PREFSTORE_PARAM_DPI = "DPI";
private static final String PREFSTORE_PARAM_PAGEFORMAT = "Pageformat";
private static final String PREFSTORE_PARAM_LANDSCAPE = "Landscape";

private Combo dpiCombo;
private Spinner topMarginSpinner;
private Spinner lowerMarginSpinner;
private Spinner leftMarginSpinner;
private Spinner rightMarginSpinner;
private Spinner marginTopSpinner;
private Spinner marginBottomSpinner;
private Spinner marginLeftSpinner;
private Spinner marginRightSpinner;
private Combo paperCombo;
private Button landscape;

Expand All @@ -59,12 +69,13 @@ public boolean useStandardDimensionControls() {

@Override
public void write( IMap map, BufferedImage image, File destination ) {
savePreferences();
Image2Pdf.write(image, destination.getAbsolutePath(), paper(),
new Insets(
Paper.toPixels(this.topMarginSpinner.getSelection(), PDF_DEFAULT_USER_UNIT),
Paper.toPixels(this.leftMarginSpinner.getSelection(), PDF_DEFAULT_USER_UNIT),
Paper.toPixels(this.lowerMarginSpinner.getSelection(), PDF_DEFAULT_USER_UNIT),
Paper.toPixels(this.rightMarginSpinner.getSelection(), PDF_DEFAULT_USER_UNIT)
Paper.toPixels(this.marginTopSpinner.getSelection(), PDF_DEFAULT_USER_UNIT),
Paper.toPixels(this.marginLeftSpinner.getSelection(), PDF_DEFAULT_USER_UNIT),
Paper.toPixels(this.marginBottomSpinner.getSelection(), PDF_DEFAULT_USER_UNIT),
Paper.toPixels(this.marginRightSpinner.getSelection(), PDF_DEFAULT_USER_UNIT)
), landscape());
}

Expand All @@ -81,6 +92,7 @@ public void createControl( Composite comp ) {
createDpiCombo(group);
createMarginsGroup(group);

loadAndApplyPreferences();
setControl(group);
}

Expand Down Expand Up @@ -114,20 +126,20 @@ private void createMarginsGroup(Group group) {
marginsGroup.setText(Messages.ImageExportPage_marginsGroup);
Label topLabel = new Label(marginsGroup, SWT.NONE);
topLabel.setText(Messages.ImageExportPage_topMargin);
topMarginSpinner = new Spinner(marginsGroup, SWT.NONE);
topMarginSpinner.setSelection(10);
Label lowerLabel = new Label(marginsGroup, SWT.NONE);
lowerLabel.setText(Messages.ImageExportPage_lowerMargin);
lowerMarginSpinner = new Spinner(marginsGroup, SWT.NONE);
lowerMarginSpinner.setSelection(10);
marginTopSpinner = new Spinner(marginsGroup, SWT.NONE);
marginTopSpinner.setSelection(10);
Label bottomLabel = new Label(marginsGroup, SWT.NONE);
bottomLabel.setText(Messages.ImageExportPage_bottomMargin);
marginBottomSpinner = new Spinner(marginsGroup, SWT.NONE);
marginBottomSpinner.setSelection(10);
Label leftLabel = new Label(marginsGroup, SWT.NONE);
leftLabel.setText(Messages.ImageExportPage_leftMargin);
leftMarginSpinner = new Spinner(marginsGroup, SWT.NONE);
leftMarginSpinner.setSelection(10);
marginLeftSpinner = new Spinner(marginsGroup, SWT.NONE);
marginLeftSpinner.setSelection(10);
Label rightLabel = new Label(marginsGroup, SWT.NONE);
rightLabel.setText(Messages.ImageExportPage_rightMargin);
rightMarginSpinner = new Spinner(marginsGroup, SWT.NONE);
rightMarginSpinner.setSelection(10);
marginRightSpinner = new Spinner(marginsGroup, SWT.NONE);
marginRightSpinner.setSelection(10);

}

Expand Down Expand Up @@ -180,20 +192,63 @@ public int getDPI() {
public int getHeight( double mapwidth, double mapheight ) {
// ignore viewport size of the current map and use paper format instead
int paperHeight = paper().getPixelHeight(landscape(), getDPI());
int topMargin = Paper.toPixels(topMarginSpinner.getSelection(), PDF_DEFAULT_USER_UNIT);
int lowerMargin = Paper.toPixels(lowerMarginSpinner.getSelection(), PDF_DEFAULT_USER_UNIT);
int topMargin = Paper.toPixels(marginTopSpinner.getSelection(), PDF_DEFAULT_USER_UNIT);
int bottomMargin = Paper.toPixels(marginBottomSpinner.getSelection(), PDF_DEFAULT_USER_UNIT);

return paperHeight - topMargin - lowerMargin;
return paperHeight - topMargin - bottomMargin;
}

@Override
public int getWidth( double mapwidth, double mapheight ) {
// ignore viewport size of the current map and use paper format instead
int paperWidth = paper().getPixelWidth(landscape(), getDPI());
int rightMargin = Paper.toPixels(rightMarginSpinner.getSelection(), PDF_DEFAULT_USER_UNIT);
int leftMargin = Paper.toPixels(leftMarginSpinner.getSelection(), PDF_DEFAULT_USER_UNIT);
int rightMargin = Paper.toPixels(marginRightSpinner.getSelection(), PDF_DEFAULT_USER_UNIT);
int leftMargin = Paper.toPixels(marginLeftSpinner.getSelection(), PDF_DEFAULT_USER_UNIT);

return paperWidth - rightMargin - leftMargin;
}

private void savePreferences() {
final IPreferenceStore prefStore = ProjectUIPlugin.getDefault().getPreferenceStore();
prefStore.setValue(PREFSTORE_PARAM_MARGIN_TOP, marginTopSpinner.getSelection());
prefStore.setValue(PREFSTORE_PARAM_MARGIN_BOTTOM, marginBottomSpinner.getSelection());
prefStore.setValue(PREFSTORE_PARAM_MARGIN_LEFT, marginLeftSpinner.getSelection());
prefStore.setValue(PREFSTORE_PARAM_MARGIN_RIGHT, marginRightSpinner.getSelection());
prefStore.setValue(PREFSTORE_PARAM_DPI, dpiCombo.getSelectionIndex());
prefStore.setValue(PREFSTORE_PARAM_LANDSCAPE, landscape());
prefStore.setValue(PREFSTORE_PARAM_PAGEFORMAT, paperCombo.getSelectionIndex());
}

private void loadAndApplyPreferences() {
final IPreferenceStore prefStore = ProjectUIPlugin.getDefault().getPreferenceStore();
final int dpiFromStore = prefStore.getInt(PREFSTORE_PARAM_DPI);
final int marginTop = prefStore.getInt(PREFSTORE_PARAM_MARGIN_TOP);
final int marginBottom = prefStore.getInt(PREFSTORE_PARAM_MARGIN_BOTTOM);
final int marginLeft = prefStore.getInt(PREFSTORE_PARAM_MARGIN_LEFT);
final int marginRight = prefStore.getInt(PREFSTORE_PARAM_MARGIN_RIGHT);
final boolean landscapeFromStore = prefStore.getBoolean(PREFSTORE_PARAM_LANDSCAPE);
final int pageFormatFromStore = prefStore.getInt(PREFSTORE_PARAM_PAGEFORMAT);

if (dpiFromStore != 0) {
dpiCombo.select(dpiFromStore);
}
if (marginTop != 0) {
marginTopSpinner.setSelection(marginTop);
}
if (marginBottom != 0) {
marginBottomSpinner.setSelection(marginBottom);
}
if (marginLeft != 0) {
marginLeftSpinner.setSelection(marginLeft);
}
if (marginRight != 0) {
marginRightSpinner.setSelection(marginRight);
}
if (landscapeFromStore) {
landscape.setSelection(true);
}
if (pageFormatFromStore != 0) {
paperCombo.select(pageFormatFromStore);
}
}
}

0 comments on commit 528f8f3

Please sign in to comment.