package bluej.editor.moe;

import bluej.pkgmgr.Package;
import bluej.prefmgr.PrefMgr;
import bluej.prefmgr.PrefMgr.PrintSize;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.collections.FXCollections;
import javafx.geometry.Pos;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Window;
import bluej.Config;
import threadchecker.OnThread;
import threadchecker.Tag;


| A print dialog with options specific to the editor. | public class PrintDialog extends Dialog<PrintDialog.PrintChoices>{ @OnThread(Tag.Any) public static class PrintChoices { public final boolean printDiagram; public final boolean printReadme; public final boolean printSource; public final PrintSize printSize; public final boolean printLineNumbers; public final boolean printHighlighting; public PrintChoices(boolean printDiagram, boolean printReadme, boolean printSource, PrintSize printSize, boolean printLineNumbers, boolean printHighlighting) { this.printDiagram = printDiagram; this.printReadme = printReadme; this.printSource = printSource; this.printSize = printSize; this.printLineNumbers = printLineNumbers; this.printHighlighting = printHighlighting; } } private final BooleanExpression cannotPrint;
| Creates a new PrintDialog object. | | @param pkg The Package, if printing a whole package. | Null if printing a single class. | public PrintDialog(Window owner, Package pkg) { setTitle(Config.getString("editor.printDialog.title")); initOwner(owner); initModality(Modality.WINDOW_MODAL); getDialogPane().getButtonTypes().setAll(ButtonType.CANCEL, ButtonType.OK); ComboBox<PrintSize> comboSize = new ComboBox<>(FXCollections.observableArrayList(PrefMgr.PrintSize.values())); comboSize.getSelectionModel().select(PrefMgr.getPrintFontSize()); HBox sizeRow = new HBox(new Label(Config.getString("editor.printDialog.fontSize")), comboSize); sizeRow.setAlignment(Pos.BASELINE_LEFT); sizeRow.setSpacing(10.0); CheckBox checkLineNumbers = new CheckBox(Config.getString("editor.printDialog.printLineNumbers")); checkLineNumbers.setSelected(PrefMgr.getFlag(PrefMgr.PRINT_LINE_NUMBERS)); CheckBox checkHighlighting = new CheckBox(Config.getString("editor.printDialog.printHighlighting")); checkHighlighting.setSelected(PrefMgr.getFlag(PrefMgr.PRINT_SCOPE_HIGHLIGHTING)); VBox vBox = new VBox(sizeRow, checkLineNumbers, checkHighlighting); vBox.setSpacing(8); final CheckBox checkReadme; final CheckBox checkDiagram; final CheckBox checkSource; if (pkg != null) { checkSource = new CheckBox(Config.getString("pkgmgr.printDialog.printSource")); checkLineNumbers.disableProperty().bind(checkSource.selectedProperty().not()); checkHighlighting.disableProperty().bind(checkSource.selectedProperty().not()); checkSource.setSelected(PrefMgr.getFlag(PrefMgr.PACKAGE_PRINT_SOURCE)); vBox.getChildren().add(0, checkSource); checkDiagram = new CheckBox(Config.getString("pkgmgr.printDialog.printDiagram")); checkDiagram.setSelected(PrefMgr.getFlag(PrefMgr.PACKAGE_PRINT_DIAGRAM)); if (pkg.isUnnamedPackage()) { checkReadme = new CheckBox(Config.getString("pkgmgr.printDialog.printReadme")); checkReadme.setSelected(PrefMgr.getFlag(PrefMgr.PACKAGE_PRINT_README)); vBox.getChildren().add(0, checkReadme); cannotPrint = Bindings.createBooleanBinding( () -> !checkSource.isSelected() && !checkDiagram.isSelected() && !checkReadme.isSelected(), checkSource.selectedProperty(), checkDiagram.selectedProperty(), checkReadme.selectedProperty()); } else { checkReadme = null; cannotPrint = Bindings.createBooleanBinding( () -> !checkSource.isSelected() && !checkDiagram.isSelected(), checkSource.selectedProperty(), checkDiagram.selectedProperty()); } vBox.getChildren().add(0, checkDiagram); } else { checkReadme = null; checkDiagram = null; checkSource = null; cannotPrint = new ReadOnlyBooleanWrapper(false); } getDialogPane().lookupButton(ButtonType.OK).disableProperty().bind(cannotPrint); getDialogPane().setContent(vBox); setResultConverter(bt -> { if (bt == ButtonType.OK) { if (checkDiagram != null) PrefMgr.setFlag(PrefMgr.PACKAGE_PRINT_DIAGRAM, checkDiagram.isSelected()); if (checkReadme != null) PrefMgr.setFlag(PrefMgr.PACKAGE_PRINT_README, checkReadme.isSelected()); if (checkSource != null) PrefMgr.setFlag(PrefMgr.PACKAGE_PRINT_SOURCE, checkSource.isSelected()); PrefMgr.setFlag(PrefMgr.PRINT_LINE_NUMBERS, checkLineNumbers.isSelected()); PrefMgr.setFlag(PrefMgr.PRINT_SCOPE_HIGHLIGHTING, checkHighlighting.isSelected()); PrefMgr.setPrintFontSize(comboSize.getValue()); return new PrintChoices( checkDiagram == null ? false : checkDiagram.isSelected(), checkReadme == null ? false : checkReadme.isSelected(), checkSource == null ? false : checkSource.isSelected(), comboSize.getValue(), checkLineNumbers.isSelected(), checkHighlighting.isSelected()); } return null; }); } }
top, use, map, class PrintChoices

.   PrintChoices
.   PrintDialog




172 neLoCode + 4 LoComm