1 package net.suberic.util.gui.propedit; 2 import java.awt.Component ; 3 import java.awt.Container ; 4 import javax.swing.*; 5 6 7 14 public class WizardPropertyEditor extends PropertyEditorPane { 15 WizardEditorPane wizard = null; 16 JButton backButton; 17 JButton nextButton; 18 19 20 24 public WizardPropertyEditor(PropertyEditorManager newManager, 25 SwingPropertyEditor newEditor, 26 Container newContainer, 27 boolean newCommit) { 28 manager = newManager; 29 container = newContainer; 30 editor = newEditor; 31 wizard = (WizardEditorPane) newEditor; 32 wizard.setWizardContainer(this); 33 doCommit = newCommit; 34 35 Component editorComponent = editor; 36 37 JPanel buttonPanel = createButtonPanel(); 38 39 pepLayout(editorComponent, buttonPanel); 40 41 wizard.loadContainerState(); 42 43 wizard.acceptDefaultFocus(); 44 45 } 46 47 50 public JPanel createButtonPanel() { 51 JPanel buttonPanel = new JPanel(); 52 53 SpringLayout buttonLayout = new SpringLayout(); 54 buttonPanel.setLayout(buttonLayout); 55 56 JButton helpButton = createButton("PropertyEditor.button.help", new AbstractAction() { 57 public void actionPerformed(java.awt.event.ActionEvent e) { 58 manager.getFactory().getHelpBroker().setCurrentID(editor.getHelpID()); 62 manager.getFactory().getHelpBroker().setDisplayed(true); 63 64 } 65 }); 66 67 buttonPanel.add(helpButton); 69 70 backButton = createButton("Wizard.button.back", new AbstractAction() { 71 public void actionPerformed(java.awt.event.ActionEvent e) { 72 wizard.back(); 73 } 74 }); 75 76 77 nextButton = createButton("Wizard.button.next", new AbstractAction() { 78 public void actionPerformed(java.awt.event.ActionEvent e) { 79 try { 80 wizard.next(); 81 } catch (PropertyValueVetoException pvve) { 82 manager.getFactory().showError(WizardPropertyEditor.this, pvve.getMessage()); 83 } 84 } 85 }); 86 87 JButton cancelButton = createButton("PropertyEditor.button.cancel", new AbstractAction() { 88 public void actionPerformed(java.awt.event.ActionEvent e) { 89 closeWizard(); 90 } 91 }); 92 93 buttonPanel.add(helpButton); 94 buttonPanel.add(cancelButton); 95 buttonPanel.add(backButton); 96 buttonPanel.add(nextButton); 97 98 Spring buttonWidth = Spring.constant(0); 99 buttonWidth = Spring.max(buttonWidth, buttonLayout.getConstraints(helpButton).getWidth()); 100 buttonWidth = Spring.max(buttonWidth, buttonLayout.getConstraints(cancelButton).getWidth()); 101 buttonWidth = Spring.max(buttonWidth, buttonLayout.getConstraints(backButton).getWidth()); 102 buttonWidth = Spring.max(buttonWidth, buttonLayout.getConstraints(nextButton).getWidth()); 103 104 buttonLayout.getConstraints(helpButton).setWidth(buttonWidth); 105 buttonLayout.getConstraints(cancelButton).setWidth(buttonWidth); 106 buttonLayout.getConstraints(backButton).setWidth(buttonWidth); 107 buttonLayout.getConstraints(nextButton).setWidth(buttonWidth); 108 109 buttonLayout.putConstraint(SpringLayout.WEST, helpButton, 5, SpringLayout.WEST, buttonPanel); 110 buttonLayout.putConstraint(SpringLayout.NORTH, helpButton, 5, SpringLayout.NORTH, buttonPanel); 111 buttonLayout.putConstraint(SpringLayout.SOUTH, buttonPanel, 5, SpringLayout.SOUTH, helpButton); 112 113 buttonLayout.putConstraint(SpringLayout.WEST, cancelButton, Spring.constant(5, 5, 32000), SpringLayout.EAST, helpButton); 114 buttonLayout.putConstraint(SpringLayout.NORTH, cancelButton, 5, SpringLayout.NORTH, buttonPanel); 115 116 buttonLayout.putConstraint(SpringLayout.WEST, backButton, 5, SpringLayout.EAST, cancelButton); 117 buttonLayout.putConstraint(SpringLayout.NORTH, backButton, 5, SpringLayout.NORTH, buttonPanel); 118 119 buttonLayout.putConstraint(SpringLayout.WEST, nextButton, 5, SpringLayout.EAST, backButton); 120 buttonLayout.putConstraint(SpringLayout.NORTH, nextButton, 5, SpringLayout.NORTH, buttonPanel); 121 buttonLayout.putConstraint(SpringLayout.EAST, buttonPanel, 5, SpringLayout.EAST, nextButton); 122 123 return buttonPanel; 124 } 125 126 129 public void setBeginningState(boolean beginningState) { 130 if (beginningState) { 131 backButton.setEnabled(false); 132 } else { 133 backButton.setEnabled(true); 134 } 135 } 136 137 140 public void setEndState(boolean endState) { 141 if (endState) { 142 if (! nextButton.getText().equals(manager.getProperty("Wizard.button.end.label", "Finish"))) { 143 nextButton.setText(manager.getProperty("Wizard.button.end.label", "Finish")); 144 String mnemonic = manager.getProperty("Wizard.button.end.keyBinding", ""); 145 if (mnemonic.length() > 0) { 146 nextButton.setMnemonic(mnemonic.charAt(0)); 147 } 148 } 149 } else { 150 if (! nextButton.getText().equals(manager.getProperty("Wizard.button.next", "Next"))) { 151 nextButton.setText(manager.getProperty("Wizard.button.next.label", "Finish")); 152 String mnemonic = manager.getProperty("Wizard.button.next.keyBinding", ""); 153 if (mnemonic.length() > 0) { 154 nextButton.setMnemonic(mnemonic.charAt(0)); 155 } 156 } 157 } 158 } 159 160 163 public void closeWizard() { 164 if (container instanceof JInternalFrame) { 165 try { 166 ((JInternalFrame)container).setClosed(true); 167 } catch (java.beans.PropertyVetoException pve) { 168 } 169 } else if (container instanceof JFrame) { 170 ((JFrame)container).dispose(); 171 } else if (container instanceof JDialog) { 172 ((JDialog)container).dispose(); 173 } 174 editor.remove(); 175 } 176 } 177 | Popular Tags |