Coverage Report - us.paulevans.basicxslt.SaveAsConfigurationFrame
 
Classes in this File Line Coverage Branch Coverage Complexity
SaveAsConfigurationFrame
0%
0/57
0%
0/3
1.6
SaveAsConfigurationFrame$1
0%
0/3
N/A
1.6
 
 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.FlowLayout;
 21  
 import java.awt.Font;
 22  
 import java.awt.GridBagConstraints;
 23  
 import java.awt.GridBagLayout;
 24  
 import java.awt.event.ActionEvent;
 25  
 import java.awt.event.ActionListener;
 26  
 import java.awt.event.WindowAdapter;
 27  
 import java.awt.event.WindowEvent;
 28  
 
 29  
 import javax.swing.JButton;
 30  
 import javax.swing.JCheckBox;
 31  
 import javax.swing.JFrame;
 32  
 import javax.swing.JLabel;
 33  
 import javax.swing.JOptionPane;
 34  
 import javax.swing.JPanel;
 35  
 import javax.swing.JScrollPane;
 36  
 import javax.swing.JSeparator;
 37  
 import javax.swing.JTextField;
 38  
 
 39  
 import net.blueslate.commons.gui.GUIUtils;
 40  
 
 41  
 import org.apache.commons.lang.StringUtils;
 42  
 
 43  
 /**
 44  
  * Defines the save-as configuration frame.
 45  
  * @author pevans
 46  
  *
 47  
  */
 48  
 public class SaveAsConfigurationFrame extends JFrame 
 49  
         implements ActionListener {                
 50  
         
 51  
         // get the i18n factory singleton instance...
 52  0
         private static final LabelStringFactory stringFactory = 
 53  
                 LabelStringFactory.getInstance();
 54  
         
 55  
         // frame width and height values...
 56  
         private static final int FRAME_WIDTH = 470;
 57  
         private static final int FRAME_HEIGHT = 195;
 58  
 
 59  
         // instance members...
 60  
         private JButton cancelBtn, okayBtn;
 61  
         private UserPreferences userPrefs;
 62  
         private JTextField configurationName;
 63  
         private JCheckBox makeDefault;
 64  
         private BasicXSLTFrame parent;
 65  
 
 66  
         /**
 67  
          * Constructor
 68  
          * @param aParent
 69  
          * @param aCurrentConfiguration
 70  
          */
 71  
         public SaveAsConfigurationFrame(BasicXSLTFrame aParent, 
 72  0
                         String aCurrentConfiguration) {
 73  
                 
 74  
                 JPanel southPanel, mainPanel;
 75  
                 
 76  0
                 parent = aParent;
 77  0
                 userPrefs = Utils.getUserPrefs();
 78  0
                 addWindowListener(new WindowAdapter() {
 79  0
                         public void windowClosing(WindowEvent evt) {
 80  0
                                 dispose();
 81  0
                         }
 82  
                 });        
 83  0
                 mainPanel = new JPanel(new BorderLayout());
 84  0
                 mainPanel.add(buildMainPanel(), BorderLayout.CENTER);                
 85  0
                 southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
 86  0
                 southPanel.add(okayBtn = new JButton(stringFactory.getString(
 87  
                                 LabelStringFactory.OK_BUTTON)));
 88  0
                 southPanel.add(cancelBtn = new JButton(stringFactory.getString(
 89  
                                 LabelStringFactory.CANCEL_BUTTON)));
 90  0
                 okayBtn.addActionListener(this);
 91  0
                 cancelBtn.addActionListener(this);                
 92  0
                 getContentPane().setLayout(new BorderLayout());
 93  0
                 getContentPane().add(buildNorthPanel(), BorderLayout.NORTH);
 94  0
                 getContentPane().add(southPanel, BorderLayout.SOUTH);
 95  0
                 getContentPane().add(new JScrollPane(mainPanel), BorderLayout.CENTER);                
 96  0
                 setTitle(stringFactory.getString(
 97  
                                 LabelStringFactory.SAVEASCONFIG_FRAME_SAVE_CONFIGURATION_AS));                
 98  0
                 setSize(FRAME_WIDTH, FRAME_HEIGHT);
 99  0
                 GUIUtils.center(this, aParent);
 100  0
                 setVisible(true);
 101  0
                 configurationName.requestFocus();
 102  0
         }
 103  
         
 104  
         /**
 105  
          * Builds the north panel
 106  
          * @return
 107  
          */
 108  
         private JPanel buildNorthPanel() {
 109  
                 
 110  
                 GridBagLayout layout;
 111  
                 GridBagConstraints constraints;
 112  
                 JPanel panel;
 113  
                 int row, col;
 114  
                 
 115  0
                 layout = new GridBagLayout();
 116  0
                 constraints = new GridBagConstraints();
 117  0
                 panel = new JPanel(layout);
 118  0
                 row = 0;
 119  0
                 col = 0;
 120  0
                 JLabel headerLabel = new JLabel(stringFactory.getString(
 121  
                                 LabelStringFactory.SAVEASCONFIG_FRAME_SAVE_NEW_CONFIGURATION));
 122  0
                 headerLabel.setFont(new Font("arial", Font.PLAIN, 18));
 123  0
                 GUIUtils.add(panel, headerLabel, layout, constraints, row++, col, 
 124  
                         1, 1, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH,
 125  
                         GUIUtils.MED_LARGE_INSETS);
 126  0
                 return panel;
 127  
         }    
 128  
         
 129  
         /**
 130  
          * Builds the main panel
 131  
          * @return
 132  
          */
 133  
         private JPanel buildMainPanel() {
 134  
                 
 135  
                 int row;
 136  
                 GridBagLayout layout;
 137  
                 GridBagConstraints constraints;
 138  
                 JPanel main;
 139  
                 JLabel label;                
 140  
                 
 141  0
                 layout = new GridBagLayout();
 142  0
                 constraints = new GridBagConstraints();
 143  0
                 main = new JPanel(layout);
 144  0
                 row = 0;        
 145  0
                 GUIUtils.add(main, new JLabel(stringFactory.getString(
 146  
                                 LabelStringFactory.SAVEASCONFIG_FRAME_CURRENT_CONFIGURATION)),
 147  
                                 layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, 
 148  
                                 GridBagConstraints.NONE, GUIUtils.MED_INSETS);
 149  0
                 GUIUtils.add(main, label = new JLabel(userPrefs.getConfiguration()), 
 150  
                                 layout, constraints, row++, 1, 1, 1, GridBagConstraints.WEST, 
 151  
                                 GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
 152  0
                 label.setForeground(Color.BLUE);                
 153  0
                 GUIUtils.add(main, new JSeparator(), layout, constraints, row++, 0, 1, 
 154  
                                 2, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, 
 155  
                                 GUIUtils.MED_INSETS);
 156  0
                 GUIUtils.add(main, new JLabel(stringFactory.getString(
 157  
                                 LabelStringFactory.SAVEASCONFIG_FRAME_CONFIGURATION_NAME)),
 158  
                                 layout, constraints, row, 0, 1, 1, GridBagConstraints.NORTHEAST, 
 159  
                                 GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
 160  0
                 GUIUtils.add(main, new JScrollPane(configurationName = 
 161  
                                 new JTextField(20)), layout, constraints, row++, 1, 1, 1, 
 162  
                                 GridBagConstraints.WEST, GridBagConstraints.NONE, 
 163  
                                 GUIUtils.SMALL_INSETS);                
 164  0
                 GUIUtils.add(main, new JLabel(stringFactory.getString(
 165  
                                 LabelStringFactory.SAVEASCONFIG_FRAME_MAKE_DEFAULT)),
 166  
                                 layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, 
 167  
                                 GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
 168  0
                 GUIUtils.add(main, makeDefault = new JCheckBox(), layout, 
 169  
                                 constraints, row++, 1, 1, 1, GridBagConstraints.WEST, 
 170  
                                 GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
 171  0
                 return main;
 172  
         }        
 173  
         
 174  
         /**
 175  
          * Event handler
 176  
          */
 177  
         public void actionPerformed(ActionEvent aEvent) {
 178  
                 
 179  
                 Object eventSource;
 180  
                 String newConfigurationName;
 181  
                 
 182  0
                 eventSource = aEvent.getSource();
 183  0
                 if (eventSource == cancelBtn) {
 184  0
                         dispose();
 185  0
                 } else if (eventSource == okayBtn) {
 186  0
                         newConfigurationName = 
 187  
                                 StringUtils.strip(configurationName.getText());
 188  0
                         if (StringUtils.isNotBlank(newConfigurationName)) {
 189  0
                                 userPrefs.copyCurrentPreferences(newConfigurationName);
 190  0
                                 userPrefs.setConfiguration(newConfigurationName, 
 191  
                                         makeDefault.isSelected());
 192  0
                                 parent.refreshConfigurationLabel();                                
 193  0
                                 dispose();
 194  0
                         } else {
 195  0
                                 Utils.showDialog(this, stringFactory.getString(
 196  
                                                 LabelStringFactory.
 197  
                                                 SAVEASCONFIG_FRAME_CONFIG_STR_CANNOT_BE_EMPTY), 
 198  
                                                 stringFactory.getString(
 199  
                                                                 LabelStringFactory.SAVEASCONFIG_FRAME_ERROR), 
 200  
                                                                 JOptionPane.ERROR_MESSAGE);
 201  
                         }
 202  
                 }
 203  0
         }
 204  
 }
 205