Skip to content

Commit

Permalink
close torakiki#70: split setting for PredefinedSetOfPages is now a combo
Browse files Browse the repository at this point in the history
  • Loading branch information
torakiki committed Jan 26, 2015
1 parent 6dddb50 commit 08eebc8
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
* Contains a pair of Strings, usually a key and a display value. Two items with the same key are considered equals.
* {@link KeyValueItem} where the value is a {@link String}. Two items with the same key are considered equals.
*
* @author Andrea Vacondio
* @param <K>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region;

import org.pdfsam.ui.support.Style;

Expand All @@ -44,7 +44,7 @@ public RadioButtonDrivenTextFieldsPane(ToggleGroup group) {
getStyleClass().addAll(Style.GRID.css());
}

public void addRow(RadioButton radio, TextField field) {
public void addRow(RadioButton radio, Region field) {
requireNotNull(radio, "Cannot add a null radio");
requireNotNull(field, "Cannot add a null field");
GridPane.setValignment(radio, VPos.BOTTOM);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the PDF Split And Merge source code
* Created on 03/giu/2014
* Created on 26/gen/2015
* Copyright 2013-2014 by Andrea Vacondio ([email protected]).
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -18,53 +18,65 @@
*/
package org.pdfsam.split;

import static org.pdfsam.support.RequireUtils.requireNotNull;
import static org.apache.commons.lang3.StringUtils.defaultString;

import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;

import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Tooltip;

import org.pdfsam.i18n.DefaultI18nContext;
import org.pdfsam.support.KeyStringValueItem;
import org.pdfsam.support.params.SinglePdfSourceMultipleOutputParametersBuilder;
import org.pdfsam.ui.workspace.RestorableView;
import org.sejda.model.parameter.SimpleSplitParameters;
import org.sejda.model.pdf.page.PredefinedSetOfPages;

/**
* A radio button associated to a Predefined set of pages
* A {@link RadioButton} showing a combo to select a {@link PredefinedSetOfPages} as split option
*
* @author Andrea Vacondio
*
*/
class PredefinedSetOfPagesRadioButton extends RadioButton implements SplitParametersBuilderCreator, RestorableView {
class SplitAfterPredefinedSetOfPagesRadioButton extends RadioButton implements SplitParametersBuilderCreator,
RestorableView {

private PredefinedSetOfPages pages;
private ComboBox<KeyStringValueItem<PredefinedSetOfPages>> combo;

public PredefinedSetOfPagesRadioButton(PredefinedSetOfPages pages, String text) {
super(text);
requireNotNull(pages, "Cannot create the radio button with a null predefined set of pages.");
this.pages = pages;
public SplitAfterPredefinedSetOfPagesRadioButton(ComboBox<KeyStringValueItem<PredefinedSetOfPages>> combo) {
super(DefaultI18nContext.getInstance().i18n("Split after"));
this.combo = combo;
combo.getSelectionModel().selectFirst();
setTooltip(new Tooltip(DefaultI18nContext.getInstance().i18n("Split the document after the given page numbers")));
}

public PredefinedSetOfPages getPages() {
return pages;
public SimpleSplitParametersBuilder getBuilder(Consumer<String> onError) {
KeyStringValueItem<PredefinedSetOfPages> selected = combo.getSelectionModel().getSelectedItem();
if (selected != null) {
return new SimpleSplitParametersBuilder(selected.getKey());
}
onError.accept(DefaultI18nContext.getInstance().i18n("No page selected"));
return null;
}

public void saveStateTo(Map<String, String> data) {
if (isSelected()) {
data.put(pages.toString(), Boolean.TRUE.toString());
data.put("splitAfterPredefined", Boolean.TRUE.toString());
}
KeyStringValueItem<PredefinedSetOfPages> selected = combo.getSelectionModel().getSelectedItem();
if (selected != null) {
data.put("splitAfterPredefined.combo", defaultString(selected.getKey().toString()));
}
}

public void restoreStateFrom(Map<String, String> data) {
Optional.ofNullable(data.get(pages.toString())).map(Boolean::valueOf).ifPresent(this::setSelected);
}

public SimpleSplitParametersBuilder getBuilder(Consumer<String> onError) {
SimpleSplitParametersBuilder builder = new SimpleSplitParametersBuilder();
builder.pages(pages);
return builder;
public void restoreStateFrom(Map<String, String> data) {
Optional.ofNullable(data.get("splitAfterPredefined")).map(Boolean::valueOf).ifPresent(this::setSelected);
Optional.ofNullable(data.get("splitAfterPredefined.combo")).map(PredefinedSetOfPages::valueOf)
.map(KeyStringValueItem::keyEmptyValue).ifPresent(this.combo.getSelectionModel()::select);
}

/**
Expand All @@ -78,7 +90,7 @@ static class SimpleSplitParametersBuilder extends

private PredefinedSetOfPages pages;

void pages(PredefinedSetOfPages pages) {
SimpleSplitParametersBuilder(PredefinedSetOfPages pages) {
this.pages = pages;
}

Expand All @@ -93,5 +105,4 @@ public SimpleSplitParameters build() {
return params;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import java.util.Map;
import java.util.function.Consumer;

import javafx.scene.control.ComboBox;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import org.pdfsam.i18n.DefaultI18nContext;
import org.pdfsam.support.KeyStringValueItem;
import org.pdfsam.support.params.SinglePdfSourceMultipleOutputParametersBuilder;
import org.pdfsam.ui.commons.RadioButtonDrivenTextFieldsPane;
import org.pdfsam.ui.commons.ValidableTextField;
Expand All @@ -43,41 +43,41 @@
*/
class SplitOptionsPane extends VBox implements SplitParametersBuilderCreator, RestorableView {

private PredefinedSetOfPagesRadioButton burst = new PredefinedSetOfPagesRadioButton(PredefinedSetOfPages.ALL_PAGES,
DefaultI18nContext.getInstance().i18n("Burst (Split into single pages)"));
private PredefinedSetOfPagesRadioButton even = new PredefinedSetOfPagesRadioButton(PredefinedSetOfPages.EVEN_PAGES,
DefaultI18nContext.getInstance().i18n("Split even pages"));
private PredefinedSetOfPagesRadioButton odd = new PredefinedSetOfPagesRadioButton(PredefinedSetOfPages.ODD_PAGES,
DefaultI18nContext.getInstance().i18n("Split odd pages"));

private ToggleGroup group = new ToggleGroup();
private SplitAfterPredefinedSetOfPagesRadioButton splitAfterPredefined;
private SplitAfterRadioButton splitAfter;
private SplitByEveryRadioButton splitByEvery;

SplitOptionsPane() {
super(Style.DEFAULT_SPACING);
ComboBox<KeyStringValueItem<PredefinedSetOfPages>> predefinedCombo = new ComboBox<>();
predefinedCombo.getItems().add(
KeyStringValueItem.keyValue(PredefinedSetOfPages.ALL_PAGES,
DefaultI18nContext.getInstance().i18n("Every page")));
predefinedCombo.getItems().add(
KeyStringValueItem.keyValue(PredefinedSetOfPages.EVEN_PAGES,
DefaultI18nContext.getInstance().i18n("Even pages")));
predefinedCombo.getItems().add(
KeyStringValueItem.keyValue(PredefinedSetOfPages.ODD_PAGES,
DefaultI18nContext.getInstance().i18n("Odd pages")));
splitAfterPredefined = new SplitAfterPredefinedSetOfPagesRadioButton(predefinedCombo);
ValidableTextField splitAfterField = new ValidableTextField();
splitAfter = new SplitAfterRadioButton(splitAfterField);
ValidableTextField splitByEveryField = new ValidableTextField();
splitByEvery = new SplitByEveryRadioButton(splitByEveryField);
RadioButtonDrivenTextFieldsPane grid = new RadioButtonDrivenTextFieldsPane(group);
burst.setToggleGroup(group);
burst.setTooltip(new Tooltip(DefaultI18nContext.getInstance().i18n("Explode the document into single pages")));
burst.setSelected(true);
even.setToggleGroup(group);
even.setTooltip(new Tooltip(DefaultI18nContext.getInstance().i18n("Split the document after every even page")));
odd.setToggleGroup(group);
odd.setTooltip(new Tooltip(DefaultI18nContext.getInstance().i18n("Split the document after every odd page")));

splitAfterPredefined.setToggleGroup(group);
splitAfter.setToggleGroup(group);
splitByEvery.setToggleGroup(group);

grid.addRow(splitAfterPredefined, predefinedCombo);
grid.addRow(splitAfter, splitAfterField);
grid.addRow(splitByEvery, splitByEveryField);
splitAfterPredefined.setSelected(true);

HBox simpleSplit = new HBox(20, burst, even, odd);
simpleSplit.getStyleClass().addAll(Style.VITEM.css());
getStyleClass().addAll(Style.CONTAINER.css());
getChildren().addAll(simpleSplit, grid);
getChildren().addAll(grid);
}

public SinglePdfSourceMultipleOutputParametersBuilder<? extends AbstractSplitByPageParameters> getBuilder(
Expand All @@ -86,17 +86,13 @@ public SinglePdfSourceMultipleOutputParametersBuilder<? extends AbstractSplitByP
}

public void saveStateTo(Map<String, String> data) {
burst.saveStateTo(data);
even.saveStateTo(data);
odd.saveStateTo(data);
splitAfterPredefined.saveStateTo(data);
splitAfter.saveStateTo(data);
splitByEvery.saveStateTo(data);
}

public void restoreStateFrom(Map<String, String> data) {
burst.restoreStateFrom(data);
even.restoreStateFrom(data);
odd.restoreStateFrom(data);
splitAfterPredefined.restoreStateFrom(data);
splitAfter.restoreStateFrom(data);
splitByEvery.restoreStateFrom(data);
}
Expand Down

This file was deleted.

Loading

0 comments on commit 08eebc8

Please sign in to comment.