Coverage Report - us.paulevans.basicxslt.LoadConfigurationFrame
 
Classes in this File Line Coverage Branch Coverage Complexity
LoadConfigurationFrame
0%
0/53
0%
0/2
1.4
LoadConfigurationFrame$1
0%
0/3
N/A
1.4
 
 1  
 /*
 2  
         Copyright 2006 Paul Evans 
 3  
 
 4  
         Licensed under the Apache License, Version 2.0 (the "License"); 
 5  
         you may not use this file except in compliance with the License. 
 6  
         You may obtain a copy of the License at 
 7  
 
 8  
                 http://www.apache.org/licenses/LICENSE-2.0 
 9  
 
 10  
         Unless required by applicable law or agreed to in writing, software 
 11  
         distributed under the License is distributed on an "AS IS" BASIS, 
 12  
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 13  
         See the License for the specific language governing permissions and 
 14  
         limitations under the License.
 15  
  */
 16  
 package us.paulevans.basicxslt;
 17  
 
 18  
 import java.awt.BorderLayout;
 19  
 import java.awt.Color;
 20  
 import java.awt.Cursor;
 21  
 import java.awt.FlowLayout;
 22  
 import java.awt.Font;
 23  
 import java.awt.GridBagConstraints;
 24  
 import java.awt.GridBagLayout;
 25  
 import java.awt.event.ActionEvent;
 26  
 import java.awt.event.ActionListener;
 27  
 import java.awt.event.WindowAdapter;
 28  
 import java.awt.event.WindowEvent;
 29  
 
 30  
 import javax.swing.JButton;
 31  
 import javax.swing.JCheckBox;
 32  
 import javax.swing.JComboBox;
 33  
 import javax.swing.JFrame;
 34  
 import javax.swing.JLabel;
 35  
 import javax.swing.JPanel;
 36  
 import javax.swing.JScrollPane;
 37  
 import javax.swing.JSeparator;
 38  
 
 39  
 import net.blueslate.commons.gui.GUIUtils;
 40  
 
 41  
 /**
 42  
  * Defines the configuration frame.
 43  
  * @author pevans
 44  
  *
 45  
  */
 46  
 public class LoadConfigurationFrame extends JFrame implements ActionListener {                
 47  
         
 48  
         // frame width and height...
 49  
         private static final int FRAME_WIDTH = 485;
 50  
         private static final int FRAME_HEIGHT = 185;
 51  
         
 52  
         // get the i18n factory singleton instance...
 53  0
         private static final LabelStringFactory stringFactory = 
 54  
                 LabelStringFactory.getInstance();
 55  
 
 56  
         private JButton cancelBtn, okayBtn;
 57  
         private UserPreferences userPrefs;
 58  
         private BasicXSLTFrame parent;
 59  
         private JComboBox configurations;
 60  
         private JCheckBox makeDefault;
 61  
 
 62  
         /**
 63  
          * Constructor
 64  
          * @param aParent
 65  
          * @param aCurrentConfiguration
 66  
          * @param aAllConfigurations
 67  
          */
 68  
         public LoadConfigurationFrame(BasicXSLTFrame aParent, 
 69  0
                         String aCurrentConfiguration, String aAllConfigurations[]) {
 70  
                 
 71  
                 JPanel southPanel, mainPanel;
 72  
                 
 73  0
                 parent = aParent;
 74  0
                 userPrefs = Utils.getUserPrefs();
 75  0
                 addWindowListener(new WindowAdapter() {
 76  0
                         public void windowClosing(WindowEvent aEvt) {
 77  0
                                 dispose();
 78  0
                         }
 79  
                 });        
 80  0
                 mainPanel = new JPanel(new BorderLayout());
 81  0
                 mainPanel.add(buildMainPanel(aAllConfigurations), BorderLayout.CENTER);                
 82  0
                 southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
 83  0
                 southPanel.add(okayBtn = new JButton(stringFactory.getString(
 84  
                                 LabelStringFactory.OK_BUTTON)));
 85  0
                 southPanel.add(cancelBtn = new JButton(stringFactory.getString(
 86  
                                 LabelStringFactory.CANCEL_BUTTON)));
 87  0
                 okayBtn.addActionListener(this);
 88  0
                 cancelBtn.addActionListener(this);                
 89  0
                 getContentPane().setLayout(new BorderLayout());
 90  0
                 getContentPane().add(buildNorthPanel(), BorderLayout.NORTH);
 91  0
                 getContentPane().add(southPanel, BorderLayout.SOUTH);
 92  0
                 getContentPane().add(new JScrollPane(mainPanel), BorderLayout.CENTER);                
 93  0
                 setTitle(stringFactory.getString(
 94  
                                 LabelStringFactory.LOADCONFIG_FRAME_LOAD_CONFIGURATION));                
 95  0
                 setSize(FRAME_WIDTH, FRAME_HEIGHT);
 96  0
                 GUIUtils.center(this, aParent);
 97  0
                 setVisible(true);
 98  0
         }
 99  
         
 100  
         /**
 101  
          * Builds the north panel
 102  
          * @return
 103  
          */
 104  
         private JPanel buildNorthPanel() {
 105  
                 
 106  
                 GridBagLayout layout;
 107  
                 GridBagConstraints constraints;
 108  
                 JPanel panel;
 109  
                 int row, col;
 110  
                 JLabel headerLabel;
 111  
                 
 112  0
                 layout = new GridBagLayout();
 113  0
                 constraints = new GridBagConstraints();
 114  0
                 panel = new JPanel(layout);
 115  0
                 row = 0;
 116  0
                 col = 0;
 117  0
                 headerLabel = new JLabel(stringFactory.getString(
 118  
                                 LabelStringFactory.LOADCONFIG_FRAME_LOAD_CONFIGURATION));
 119  0
                 headerLabel.setFont(new Font("arial", Font.PLAIN, 18));
 120  0
                 GUIUtils.add(panel, headerLabel, layout, constraints, row++, col, 
 121  
                         1, 1, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH,
 122  
                         GUIUtils.MED_LARGE_INSETS);
 123  0
                 return panel;
 124  
         }    
 125  
         
 126  
         /**
 127  
          * Builds main panel
 128  
          * @param aAllConfigurations
 129  
          * @return
 130  
          */
 131  
         private JPanel buildMainPanel(String aAllConfigurations[]) {
 132  
                 
 133  
                 int row;
 134  
                 JLabel label;
 135  
                 GridBagLayout layout;
 136  
                 GridBagConstraints constraints;
 137  
                 JPanel main;                
 138  
                 
 139  0
                 layout = new GridBagLayout();
 140  0
                 constraints = new GridBagConstraints();
 141  0
                 main = new JPanel(layout);
 142  0
                 row = 0;        
 143  0
                 GUIUtils.add(main, new JLabel(stringFactory.getString(
 144  
                                 LabelStringFactory.LOADCONFIG_FRAME_LOAD_CONFIGURATION)),
 145  
                         layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, 
 146  
                         GridBagConstraints.NONE, GUIUtils.MED_INSETS);
 147  0
                 GUIUtils.add(main, label = new JLabel(userPrefs.getConfiguration()), 
 148  
                                 layout, constraints, row++, 1, 1, 1, GridBagConstraints.WEST, 
 149  
                                 GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
 150  0
                 label.setForeground(Color.BLUE);
 151  0
                 GUIUtils.add(main, new JSeparator(), layout, constraints, row++, 0, 1, 
 152  
                                 2, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, 
 153  
                                 GUIUtils.MED_INSETS);
 154  0
                 GUIUtils.add(main, new JLabel(stringFactory.getString(
 155  
                                 LabelStringFactory.LOADCONFIG_FRAME_CONFIGURATION)), layout, 
 156  
                                 constraints, row, 0, 1, 1, GridBagConstraints.EAST, 
 157  
                                 GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
 158  0
                 GUIUtils.add(main, configurations = new JComboBox(aAllConfigurations), 
 159  
                                 layout, constraints, row++, 1, 1, 1, GridBagConstraints.WEST, 
 160  
                                 GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
 161  0
                 GUIUtils.add(main, new JLabel(stringFactory.getString(
 162  
                                 LabelStringFactory.LOADCONFIG_FRAME_MAKE_DEFAULT)), layout, 
 163  
                                 constraints, row, 0, 1, 1, GridBagConstraints.EAST, 
 164  
                                 GridBagConstraints.NONE, GUIUtils.MED_INSETS);
 165  0
                 GUIUtils.add(main, makeDefault = new JCheckBox(), layout, constraints, 
 166  
                                 row++, 1, 1, 1, GridBagConstraints.WEST, 
 167  
                                 GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
 168  0
                 return main;
 169  
         }        
 170  
         
 171  
         /**
 172  
          * Event handler
 173  
          */
 174  
         public void actionPerformed(ActionEvent aEvent) {
 175  
                 
 176  
                 Object eventSource;
 177  
                 
 178  0
                 eventSource = aEvent.getSource();
 179  0
                 setCursor(new Cursor(Cursor.WAIT_CURSOR));
 180  0
                 if (eventSource == cancelBtn) {
 181  0
                         dispose();
 182  0
                 } else if (eventSource == okayBtn) {
 183  0
                         userPrefs.setConfiguration((String)configurations.getSelectedItem(), 
 184  
                                 makeDefault.isSelected());
 185  0
                         parent.refreshApplication();
 186  0
                         dispose();
 187  
                 }
 188  0
                 setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
 189  0
         }
 190  
 }
 191