Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Modified HomePrint to contain array members
Modified HomePrint constructor for arrays
Modified get methods in HomePrint

Modified PageSetupPanel for checkbox components
Modified PageSetupPanel to create new checkbox components
Modified PageSetupPanel to add item listeners
Modified PageSetupPanel to update from HomePrint
Modified PageSetupPanel to update to HomePrint
Modified PageSetupPanel to add components graphically
  • Loading branch information
cks11003 committed Nov 18, 2015
1 parent cc2901a commit 742396c
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 29 deletions.
Binary file not shown.
Binary file modified SweetHome3D/classes/com/eteks/sweethome3d/model/HomePrint.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 33 additions & 8 deletions SweetHome3D/src/com/eteks/sweethome3d/model/HomePrint.java
Expand Up @@ -20,6 +20,7 @@
package com.eteks.sweethome3d.model;

import java.io.Serializable;
import java.util.List;

/**
* The print attributes for a home.
Expand All @@ -40,12 +41,14 @@ public class HomePrint implements Serializable {
private final float paperLeftMargin;
private final float paperBottomMargin;
private final float paperRightMargin;
private final boolean furniturePrinted;
private final boolean planPrinted;
//private final boolean furniturePrinted;
//private final boolean planPrinted;
private final boolean view3DPrinted;
private final Float planScale;
private final String headerFormat;
private final String footerFormat;
private final List<Boolean> furnitureList;
private final List<Boolean> planViewList;


/**
Expand All @@ -58,8 +61,8 @@ public class HomePrint implements Serializable {
float paperLeftMargin,
float paperBottomMargin,
float paperRightMargin,
boolean furniturePrinted,
boolean planPrinted,
List<Boolean> furnitureList,
List<Boolean> planViewList,
boolean view3DPrinted,
Float planScale,
String headerFormat,
Expand All @@ -71,8 +74,8 @@ public class HomePrint implements Serializable {
this.paperLeftMargin = paperLeftMargin;
this.paperBottomMargin = paperBottomMargin;
this.paperRightMargin = paperRightMargin;
this.furniturePrinted = furniturePrinted;
this.planPrinted = planPrinted;
this.furnitureList = furnitureList;
this.planViewList = planViewList;
this.view3DPrinted = view3DPrinted;
this.planScale = planScale;
this.headerFormat = headerFormat;
Expand Down Expand Up @@ -132,15 +135,37 @@ public class HomePrint implements Serializable {
* Returns whether home furniture should be printed or not.
*/
public boolean isFurniturePrinted() {
return this.furniturePrinted;
/* TODO: Remove this method and dependencies */
return true;
//return this.furniturePrinted;
}

/**
* Returns whether home plan should be printed or not.
*/
public boolean isPlanPrinted() {
return this.planPrinted;
/* TODO: Remove this method and dependencies */
return true;
//return this.planPrinted;
}

/**
* Gets the Boolean list determining which levels
* should have furniture lists printed.
*/
public List<Boolean> getFurnitureList() {
return this.furnitureList;
}

/**
* Gets the Boolean list determining which levels
* should have plan views printed.
*/
public List<Boolean> getPlanViewList() {
return this.planViewList;
}



/**
* Returns whether home 3D view should be printed or not.
Expand Down
Expand Up @@ -384,6 +384,17 @@ public class HomePrintableComponent extends JComponent implements Printable {
this.printablePages.add(page);
}
}
System.out.println("Test here");
view3D = this.controller.getHomeController3D().getView();
if (pageExists == NO_SUCH_PAGE
&& view3D != null
&& (homePrint == null || !homePrint.isView3DPrinted())) {
pageExists = ((Printable)view3D).print(g2D, pageFormat, page - this.planPageCount - this.furniturePageCount + 1);
if (pageExists == PAGE_EXISTS
&& !this.printablePages.contains(page)) {
this.printablePages.add(page);
}
}

// Print header and footer
if (pageExists == PAGE_EXISTS) {
Expand Down
112 changes: 92 additions & 20 deletions SweetHome3D/src/com/eteks/sweethome3d/swing/PageSetupPanel.java
Expand Up @@ -36,6 +36,8 @@ import java.awt.print.PrinterJob;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ActionMap;
import javax.swing.ButtonGroup;
Expand All @@ -58,6 +60,7 @@ import javax.swing.event.DocumentListener;

import com.eteks.sweethome3d.j3d.Component3DManager;
import com.eteks.sweethome3d.model.HomePrint;
import com.eteks.sweethome3d.model.Level;
import com.eteks.sweethome3d.model.UserPreferences;
import com.eteks.sweethome3d.swing.NullableSpinner.NullableSpinnerNumberModel;
import com.eteks.sweethome3d.tools.OperatingSystem;
Expand All @@ -75,7 +78,7 @@ public class PageSetupPanel extends JPanel implements DialogView {
private final PageSetupController controller;
private PageFormat pageFormat;
private JButton pageFormatButton;
private JCheckBox furniturePrintedCheckBox;
//private JCheckBox furniturePrintedCheckBox;
private JCheckBox planPrintedCheckBox;
private JRadioButton bestFitPlanScaleRadioButton;
private JRadioButton userPlanScaleRadioButton;
Expand All @@ -88,6 +91,8 @@ public class PageSetupPanel extends JPanel implements DialogView {
private JLabel variablesLabel;
private JToolBar variableButtonsToolBar;
private String dialogTitle;
private List<JCheckBox> furnitureBoxes;
private List<JCheckBox> planViewBoxes;

/**
* Creates a panel that displays page setup.
Expand Down Expand Up @@ -141,10 +146,19 @@ public class PageSetupPanel extends JPanel implements DialogView {
final PageSetupController controller) {
this.pageFormatButton = new JButton(SwingTools.getLocalizedLabelText(preferences,
PageSetupPanel.class, "pageFormatButton.text"));
this.furniturePrintedCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
PageSetupPanel.class, "furniturePrintedCheckBox.text"));
//this.furniturePrintedCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
// PageSetupPanel.class, "furniturePrintedCheckBox.text"));
this.planPrintedCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
PageSetupPanel.class, "planPrintedCheckBox.text"));
PageSetupPanel.class, "planPrintedCheckBox.text"));

// Create Lists for Furniture and PlanView Check Boxes
this.furnitureBoxes = new ArrayList<JCheckBox>();
this.planViewBoxes = new ArrayList<JCheckBox>();
for(Level curLvl : controller.getHomeLevels())
{
furnitureBoxes.add(new JCheckBox(curLvl.getName()));
planViewBoxes.add(new JCheckBox(curLvl.getName()));
}

// Create scale radio buttons and user's scale spinner
this.bestFitPlanScaleRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
Expand Down Expand Up @@ -215,8 +229,18 @@ public class PageSetupPanel extends JPanel implements DialogView {
updateController(controller);
}
};
this.furniturePrintedCheckBox.addItemListener(itemListener);
this.planPrintedCheckBox.addItemListener(itemListener);

for(JCheckBox chBx : this.furnitureBoxes)
{
chBx.addItemListener(itemListener);
}
for(JCheckBox chBx : this.planViewBoxes)
{
chBx.addItemListener(itemListener);
}

//this.furniturePrintedCheckBox.addItemListener(itemListener);
//this.planPrintedCheckBox.addItemListener(itemListener);
userPlanScaleSpinnerModel.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ev) {
updateController(controller);
Expand Down Expand Up @@ -301,8 +325,13 @@ public class PageSetupPanel extends JPanel implements DialogView {
final NullableSpinnerNumberModel userPlanScaleSpinnerModel =
(NullableSpinner.NullableSpinnerNumberModel)this.userPlanScaleSpinner.getModel();
if (homePrint != null) {
this.furniturePrintedCheckBox.setSelected(homePrint.isFurniturePrinted());
this.planPrintedCheckBox.setSelected(homePrint.isPlanPrinted());
//this.furniturePrintedCheckBox.setSelected(homePrint.isFurniturePrinted());
//this.planPrintedCheckBox.setSelected(homePrint.isPlanPrinted());
for(int i = 0; i<homePrint.getFurnitureList().size() && i<furnitureBoxes.size(); i++)
{
furnitureBoxes.get(i).setSelected(homePrint.getFurnitureList().get(i).booleanValue());
planViewBoxes.get(i).setSelected(homePrint.getPlanViewList().get(i).booleanValue());
}
this.bestFitPlanScaleRadioButton.setEnabled(homePrint.isPlanPrinted());
this.userPlanScaleRadioButton.setEnabled(homePrint.isPlanPrinted());
if (homePrint.getPlanScale() == null) {
Expand All @@ -321,8 +350,8 @@ public class PageSetupPanel extends JPanel implements DialogView {
String footerFormat = homePrint.getFooterFormat();
this.footerFormatTextField.setText(footerFormat != null ? footerFormat : "");
} else {
this.furniturePrintedCheckBox.setSelected(true);
this.planPrintedCheckBox.setSelected(true);
//this.furniturePrintedCheckBox.setSelected(true);
//this.planPrintedCheckBox.setSelected(true);
this.bestFitPlanScaleRadioButton.setEnabled(true);
this.bestFitPlanScaleRadioButton.setSelected(true);
this.userPlanScaleRadioButton.setEnabled(true);
Expand Down Expand Up @@ -355,12 +384,25 @@ public class PageSetupPanel extends JPanel implements DialogView {
break;
}
Paper paper = this.pageFormat.getPaper();
// Build the Boolean arrays from the check box lists:
List<Boolean> furnList = new ArrayList<Boolean>();
List<Boolean> planList = new ArrayList<Boolean>();
for(JCheckBox chBx : furnitureBoxes)
{
furnList.add(new Boolean(chBx.isSelected()));
}
for(JCheckBox chBx : planViewBoxes)
{
planList.add(new Boolean(chBx.isSelected()));
}


HomePrint homePrint = new HomePrint(paperOrientation, (float)paper.getWidth(), (float)paper.getHeight(),
(float)paper.getImageableY(), (float)paper.getImageableX(),
(float)(paper.getHeight() - paper.getImageableHeight() - paper.getImageableY()),
(float)(paper.getWidth() - paper.getImageableWidth() - paper.getImageableX()),
this.furniturePrintedCheckBox.isSelected(),
this.planPrintedCheckBox.isSelected(),
furnList,
planList,
this.view3DPrintedCheckBox.isSelected(),
this.userPlanScaleRadioButton.isSelected() && this.userPlanScaleSpinner.getValue() != null
? 1f / ((Number)this.userPlanScaleSpinner.getValue()).intValue()
Expand All @@ -377,10 +419,10 @@ public class PageSetupPanel extends JPanel implements DialogView {
if (!OperatingSystem.isMacOSX()) {
this.pageFormatButton.setMnemonic(KeyStroke.getKeyStroke(preferences.getLocalizedString(
PageSetupPanel.class, "pageFormatButton.mnemonic")).getKeyCode());
this.furniturePrintedCheckBox.setMnemonic(KeyStroke.getKeyStroke(preferences.getLocalizedString(
PageSetupPanel.class, "furniturePrintedCheckBox.mnemonic")).getKeyCode());
this.planPrintedCheckBox.setMnemonic(KeyStroke.getKeyStroke(preferences.getLocalizedString(
PageSetupPanel.class, "planPrintedCheckBox.mnemonic")).getKeyCode());
//this.furniturePrintedCheckBox.setMnemonic(KeyStroke.getKeyStroke(preferences.getLocalizedString(
// PageSetupPanel.class, "furniturePrintedCheckBox.mnemonic")).getKeyCode());
//this.planPrintedCheckBox.setMnemonic(KeyStroke.getKeyStroke(preferences.getLocalizedString(
// PageSetupPanel.class, "planPrintedCheckBox.mnemonic")).getKeyCode());
this.view3DPrintedCheckBox.setMnemonic(KeyStroke.getKeyStroke(preferences.getLocalizedString(
PageSetupPanel.class, "view3DPrintedCheckBox.mnemonic")).getKeyCode());
this.bestFitPlanScaleRadioButton.setMnemonic(KeyStroke.getKeyStroke(preferences.getLocalizedString(
Expand All @@ -405,18 +447,48 @@ public class PageSetupPanel extends JPanel implements DialogView {
: GridBagConstraints.LINE_START;
// First row
JPanel topPanel = new JPanel(new GridBagLayout());
JPanel checkListPanel = new JPanel(new GridBagLayout());
topPanel.add(this.pageFormatButton, new GridBagConstraints(
0, 0, 2, 1, 0, 0, GridBagConstraints.CENTER,
GridBagConstraints.NONE, new Insets(0, 0, 10, 0) , 0, 0));
Insets lastComponentInsets = new Insets(0, 0, 5, 0);

System.out.println("Hello, world.");
for(Level curLvl : controller.getHomeLevels())
{
System.out.println(curLvl.getName());
}
checkListPanel.add(new JLabel("Plan Views:"), new GridBagConstraints(
0,0,2,1,0,0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0,0,0,20),0,0));
checkListPanel.add(new JLabel("Furniture Tables:"), new GridBagConstraints(
2,0,2,1,0,0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0));
int i = 1;
for(JCheckBox chBx : this.planViewBoxes)
{
checkListPanel.add(chBx, new GridBagConstraints(
0,0+i,2,1,0,0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0));
i++;
}

i = 1;
for(JCheckBox chBx : this.furnitureBoxes)
{
checkListPanel.add(chBx, new GridBagConstraints(
2,0+i,2,1,0,0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0));
i++;
}

topPanel.add(checkListPanel, new GridBagConstraints(
0,1,2,1,0,0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0));
// Furniture component
topPanel.add(this.furniturePrintedCheckBox, new GridBagConstraints(
/*topPanel.add(this.furniturePrintedCheckBox, new GridBagConstraints(
0, 1, 2, 1, 0, 0, GridBagConstraints.LINE_START,
GridBagConstraints.NONE, lastComponentInsets , 0, 0));
GridBagConstraints.NONE, lastComponentInsets , 0, 0));*/
// Plan components
topPanel.add(this.planPrintedCheckBox, new GridBagConstraints(
//topPanel.add(this.planPrintedCheckBox, new GridBagConstraints(
topPanel.add(new JLabel("Plan View:"), new GridBagConstraints(
0, 2, 2, 1, 0, 0, GridBagConstraints.LINE_START,
GridBagConstraints.NONE, new Insets(0, 0, 2, 0), 0, 0));
GridBagConstraints.NONE, new Insets(10, 0, 2, 0), 0, 0));
topPanel.add(this.bestFitPlanScaleRadioButton, new GridBagConstraints(
0, 3, 2, 1, 0, 0, GridBagConstraints.LINE_START,
GridBagConstraints.NONE, new Insets(0, 20, 2, 0), 0, 0));
Expand Down
Expand Up @@ -21,6 +21,7 @@ package com.eteks.sweethome3d.viewcontroller;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.List;

import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
Expand All @@ -30,6 +31,7 @@ import javax.swing.undo.UndoableEditSupport;

import com.eteks.sweethome3d.model.Home;
import com.eteks.sweethome3d.model.HomePrint;
import com.eteks.sweethome3d.model.Level;
import com.eteks.sweethome3d.model.UserPreferences;

/**
Expand Down Expand Up @@ -84,7 +86,7 @@ public class PageSetupController implements Controller {
public void displayView(View parentView) {
getView().displayView(parentView);
}

/**
* Adds the property change <code>listener</code> in parameter to this controller.
*/
Expand Down Expand Up @@ -129,6 +131,27 @@ public class PageSetupController implements Controller {
this.undoSupport.postEdit(undoableEdit);
}

/**
* Returns a list of the levels in home
*/
public List<Level> getHomeLevels() {
return home.getLevels();
}

/**
* Returns the number of levels
*/
public int levelCount() {
return getHomeLevels().size();
}

/**
* Return the level at the specified index
*/
public Level getHomeLevel(int levelNumber) {
return getHomeLevels().get(levelNumber);
}

/**
* Undoable edit for home print modification. This class isn't anonymous to avoid
* being bound to controller and its view.
Expand Down

0 comments on commit 742396c

Please sign in to comment.