| 1 | /* | 
| 2 |  * Copyright (c) 2005 The PseudoQ Project. | 
| 3 |  * | 
| 4 |  * This file is part of PseudoQ. | 
| 5 |  * | 
| 6 |  * PseudoQ is free software; you can redistribute it and/or modify | 
| 7 |  * it under the terms of the GNU Lesser General Public License as published by | 
| 8 |  * the Free Software Foundation; either version 2.1 of the License, or | 
| 9 |  * (at your option) any later version. | 
| 10 |  * | 
| 11 |  * PseudoQ is distributed in the hope that it will be useful, | 
| 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 14 |  * GNU Lesser General Public License for more details. | 
| 15 |  * | 
| 16 |  * You should have received a copy of the GNU Lesser General Public License | 
| 17 |  * along with PseudoQ; if not, write to the Free Software | 
| 18 |  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
| 19 |  */ | 
| 20 |   | 
| 21 | package net.sourceforge.pseudoq.gui; | 
| 22 |   | 
| 23 | import java.awt.CardLayout; | 
| 24 |   | 
| 25 | import net.sourceforge.pseudoq.model.PuzzleTypeEnum; | 
| 26 |   | 
| 27 | /** | 
| 28 |  * First page of the {@link NewPuzzleWizard}.  This would be an inner class, | 
| 29 |  * except Netbeans' GUI form designer cannot handle that. | 
| 30 |  * @author <a href="http://sourceforge.net/users/stevensa">Andrew Stevens</a> | 
| 31 |  */ | 
| 32 | public class NewPuzzleWizardStep1 extends org.pietschy.wizard.PanelWizardStep { | 
| 33 |     private NewPuzzleWizard.Model model; | 
| 34 |   | 
| 35 |     /** | 
| 36 |      * Creates new form NewPuzzleWizardStep1  | 
| 37 |      */ | 
| 38 |     public NewPuzzleWizardStep1() { | 
| 39 |         super("Select puzzle type", "Choose the size & style of puzzle"); | 
| 40 |         initComponents(); | 
| 41 |         updateDescription(); | 
| 42 |     } | 
| 43 |   | 
| 44 |     public void applyState() throws org.pietschy.wizard.InvalidStateException { | 
| 45 |         model.setPuzzleType((PuzzleTypeEnum) jComboBox1.getSelectedItem()); | 
| 46 |         super.applyState(); | 
| 47 |     } | 
| 48 |   | 
| 49 |     public void init(org.pietschy.wizard.WizardModel wizardModel) { | 
| 50 |         this.model = (NewPuzzleWizard.Model) wizardModel; | 
| 51 |         super.init(wizardModel); | 
| 52 |     } | 
| 53 |   | 
| 54 |     /** This method is called from within the constructor to | 
| 55 |      * initialize the form. | 
| 56 |      * WARNING: Do NOT modify this code. The content of this method is | 
| 57 |      * always regenerated by the Form Editor. | 
| 58 |      */ | 
| 59 |     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents | 
| 60 |     private void initComponents() { | 
| 61 |         java.awt.GridBagConstraints gridBagConstraints; | 
| 62 |   | 
| 63 |         jLabel1 = new javax.swing.JLabel(); | 
| 64 |         jComboBox1 = new javax.swing.JComboBox(); | 
| 65 |         jPanel1 = new javax.swing.JPanel(); | 
| 66 |   | 
| 67 |         setLayout(new java.awt.GridBagLayout()); | 
| 68 |   | 
| 69 |         setComplete(true); | 
| 70 |         jLabel1.setText("Puzzle type:"); | 
| 71 |         gridBagConstraints = new java.awt.GridBagConstraints(); | 
| 72 |         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; | 
| 73 |         add(jLabel1, gridBagConstraints); | 
| 74 |   | 
| 75 |         jComboBox1.setModel(new javax.swing.DefaultComboBoxModel( | 
| 76 |             PuzzleTypeEnum.values()) | 
| 77 |     ); | 
| 78 |     jComboBox1.setSelectedIndex(PuzzleTypeEnum.STANDARD.ordinal()); | 
| 79 |     jComboBox1.addActionListener(new java.awt.event.ActionListener() { | 
| 80 |         public void actionPerformed(java.awt.event.ActionEvent evt) { | 
| 81 |             jComboBox1ActionPerformed(evt); | 
| 82 |         } | 
| 83 |     }); | 
| 84 |   | 
| 85 |     gridBagConstraints = new java.awt.GridBagConstraints(); | 
| 86 |     gridBagConstraints.gridx = 0; | 
| 87 |     gridBagConstraints.gridy = 1; | 
| 88 |     gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; | 
| 89 |     gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; | 
| 90 |     add(jComboBox1, gridBagConstraints); | 
| 91 |   | 
| 92 |     jPanel1.setLayout(new java.awt.CardLayout()); | 
| 93 |   | 
| 94 |     jPanel1.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(10, 0, 0, 0))); | 
| 95 |     addDescriptionPanels(); | 
| 96 |     gridBagConstraints = new java.awt.GridBagConstraints(); | 
| 97 |     gridBagConstraints.gridx = 0; | 
| 98 |     gridBagConstraints.gridy = 2; | 
| 99 |     add(jPanel1, gridBagConstraints); | 
| 100 |   | 
| 101 |     } | 
| 102 |     // </editor-fold>//GEN-END:initComponents | 
| 103 |   | 
| 104 |     private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed | 
| 105 |         updateDescription(); | 
| 106 |     }//GEN-LAST:event_jComboBox1ActionPerformed | 
| 107 |   | 
| 108 |     private void addDescriptionPanels() { | 
| 109 |         for(PuzzleTypeEnum puzzleType : PuzzleTypeEnum.values()) { | 
| 110 |             javax.swing.JTextArea jTextArea = new javax.swing.JTextArea(); | 
| 111 |             jTextArea.setText(puzzleType.getDescription()); | 
| 112 |             jPanel1.add(jTextArea, "card" + puzzleType.ordinal()); | 
| 113 |         } | 
| 114 |     } | 
| 115 |   | 
| 116 |     private void updateDescription() { | 
| 117 |         CardLayout layout = (CardLayout) jPanel1.getLayout(); | 
| 118 |         layout.show(jPanel1, "card" + ((PuzzleTypeEnum) jComboBox1.getSelectedItem()).ordinal()); | 
| 119 |     } | 
| 120 |   | 
| 121 |     // Variables declaration - do not modify//GEN-BEGIN:variables | 
| 122 |     private javax.swing.JComboBox jComboBox1; | 
| 123 |     private javax.swing.JLabel jLabel1; | 
| 124 |     private javax.swing.JPanel jPanel1; | 
| 125 |     // End of variables declaration//GEN-END:variables | 
| 126 |   | 
| 127 | } |