// Create variables buttons tool bar
this.variablesLabel = new JLabel(preferences.getLocalizedString(
PageSetupPanel.class, "variablesLabel.text"));
this.variableButtonsToolBar = new JToolBar();
this.variableButtonsToolBar.setFloatable(false);
ActionMap actions = getActionMap();
this.variableButtonsToolBar.add(actions.get(HomePrintableComponent.Variable.PAGE_NUMBER));
this.variableButtonsToolBar.add(actions.get(HomePrintableComponent.Variable.PAGE_COUNT));
this.variableButtonsToolBar.add(actions.get(HomePrintableComponent.Variable.PLAN_SCALE));
this.variableButtonsToolBar.add(actions.get(HomePrintableComponent.Variable.DATE));
this.variableButtonsToolBar.add(actions.get(HomePrintableComponent.Variable.TIME));
this.variableButtonsToolBar.add(actions.get(HomePrintableComponent.Variable.HOME_PRESENTATION_NAME));
this.variableButtonsToolBar.add(actions.get(HomePrintableComponent.Variable.HOME_NAME));
for (int i = 0, n = this.variableButtonsToolBar.getComponentCount(); i < n; i++) {
JComponent component = (JComponent)this.variableButtonsToolBar.getComponentAtIndex(i);
// Remove focusable property on buttons
component.setFocusable(false);
}
updateComponents(controller.getPrint());
final PropertyChangeListener printChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
updateComponents(controller.getPrint());
}
};
this.pageFormatButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
// Show the page setup dialog
PrinterJob printerJob = PrinterJob.getPrinterJob();
pageFormat = printerJob.pageDialog(pageFormat);
updateController(controller);
}
});
ItemListener itemListener = new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
updateController(controller);
}
};
this.furniturePrintedCheckBox.addItemListener(itemListener);
this.planPrintedCheckBox.addItemListener(itemListener);
userPlanScaleSpinnerModel.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ev) {
updateController(controller);
}
});
this.bestFitPlanScaleRadioButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
updateController(controller);
}
});
this.userPlanScaleRadioButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
if (userPlanScaleRadioButton.isSelected()
&& userPlanScaleSpinnerModel.getValue() == null) {
userPlanScaleSpinnerModel.setValue(DEFAULT_SCALE);
} else {
updateController(controller);
}
}
});
this.view3DPrintedCheckBox.addItemListener(itemListener);
controller.addPropertyChangeListener(PageSetupController.Property.PRINT, printChangeListener);
DocumentListener documentListener = new DocumentListener() {
public void changedUpdate(DocumentEvent ev) {
controller.removePropertyChangeListener(PageSetupController.Property.PRINT, printChangeListener);
updateController(controller);
controller.addPropertyChangeListener(PageSetupController.Property.PRINT, printChangeListener);
}
public void insertUpdate(DocumentEvent ev) {
changedUpdate(ev);
}
public void removeUpdate(DocumentEvent ev) {
changedUpdate(ev);
}
};
this.headerFormatTextField.getDocument().addDocumentListener(documentListener);
FocusListener textFieldFocusListener = new FocusListener() {
public void focusGained(FocusEvent ev) {
ActionMap actionMap = getActionMap();
for (HomePrintableComponent.Variable field : HomePrintableComponent.Variable.values()) {
actionMap.get(field).setEnabled(true);
}
}
public void focusLost(FocusEvent ev) {
ActionMap actionMap = getActionMap();
for (HomePrintableComponent.Variable field : HomePrintableComponent.Variable.values()) {
actionMap.get(field).setEnabled(false);
}
}
};
this.headerFormatTextField.addFocusListener(textFieldFocusListener);
this.footerFormatTextField.getDocument().addDocumentListener(documentListener);