public class SettingsWindow extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel plURL = null;
private JLabel lbURL = null;
private JLabel lbURLHost = null;
private JRadioButton rbURL = null;
private JRadioButton rbURLHost = null;
private JPanel plButtons = null;
private JButton btnOK = null;
private JButton btnCancel = null;
private JPanel plLanguage = null;
private JLabel lbLanguage = null;
private JComboBox cbLanguage = null;
private GUI guiFrame=null;
private JTextField tfURLName = null;
private boolean isFileExist = true;
/**
* This a constructor with the GUI
*/
public SettingsWindow(GUI guiFrame) {
super();
this.guiFrame = guiFrame;
initialize();
}
/**
* This is the default constructor
*/
public SettingsWindow(boolean isFileExist){
super();
this.isFileExist = isFileExist;
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(365, 150);
this.setContentPane(getJContentPane());
this.setTitle(Resource.getResource("SettingsWindow.Settings")); //$NON-NLS-1$
this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(Resource.getResource("SettingsWindow.TitleImageURL"))));
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
gridBagConstraints31.gridx = 0;
gridBagConstraints31.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints31.gridy = 0;
GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
gridBagConstraints21.gridx = 0;
gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints21.gridy = 2;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.gridx = 0;
gridBagConstraints2.gridy = 1;
jContentPane = new JPanel();
jContentPane.setLayout(new GridBagLayout());
jContentPane.setBackground(new Color(108,108,108));
jContentPane.add(getPlURL(), gridBagConstraints2);
jContentPane.add(getPlButtons(), gridBagConstraints21);
jContentPane.add(getPlLanguage(), gridBagConstraints31);
}
return jContentPane;
}
/**
* This method initializes plURL
*
* @return javax.swing.JPanel
*/
private JPanel getPlURL() {
if (plURL == null) {
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.fill = GridBagConstraints.VERTICAL;
gridBagConstraints4.gridy = 0;
gridBagConstraints4.weightx = 1.0;
gridBagConstraints4.insets = new Insets(0, 11, 0, 0);
gridBagConstraints4.gridx = 2;
GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
gridBagConstraints8.gridx = 1;
gridBagConstraints8.anchor = GridBagConstraints.SOUTH;
gridBagConstraints8.insets = new Insets(0, 0, 8, 0);
GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
gridBagConstraints6.gridx = 0;
gridBagConstraints6.insets = new Insets(0, 0, 0, 10);
gridBagConstraints6.gridy = 1;
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.gridx = 0;
gridBagConstraints5.insets = new Insets(0, 0, 5, 10);
gridBagConstraints5.anchor = GridBagConstraints.SOUTH;
gridBagConstraints5.ipadx = 0;
gridBagConstraints5.gridy = 0;
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.gridx = 1;
gridBagConstraints3.anchor = GridBagConstraints.WEST;
gridBagConstraints3.gridy = 1;
lbURLHost = new JLabel();
lbURLHost.setText(Resource.getResource("SettingsWindow.SetHost")); //$NON-NLS-1$
lbURLHost.setFont(new Font("Verdana",Font.PLAIN,12));
lbURLHost.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
lbURLHost.setForeground(Color.white);
lbURL = new JLabel();
lbURL.setText(Resource.getResource("SettingsWindow.URLInput")); //$NON-NLS-1$
lbURL.setFont(new Font("Verdana",Font.PLAIN,12));
lbURL.setForeground(Color.white);
plURL = new JPanel();
plURL.setLayout(new GridBagLayout());
plURL.setBackground(new Color(108,108,108));
plURL.add(lbURL, gridBagConstraints8);
plURL.add(lbURLHost, gridBagConstraints3);
plURL.add(getRbURL(), gridBagConstraints5);
plURL.add(getRbURLHost(), gridBagConstraints6);
plURL.add(getTfURLName(), gridBagConstraints4);
}
return plURL;
}
/**
* This method initializes rbURL
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getRbURL() {
if (rbURL == null) {
rbURL = new JRadioButton();
rbURL.setBackground(new Color(108,108,108));
rbURL.setSelected(true);
rbURL.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
rbURL.setSelected(true);
rbURLHost.setSelected(false);
}
});
}
return rbURL;
}
/**
* This method initializes rbURLHost
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getRbURLHost() {
if (rbURLHost == null) {
rbURLHost = new JRadioButton();
rbURLHost.setBackground(new Color(108,108,108));
rbURLHost.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
rbURLHost.setSelected(true);
rbURL.setSelected(false);
}
});
}
return rbURLHost;
}
/**
* This method initializes plButtons
*
* @return javax.swing.JPanel
*/
private JPanel getPlButtons() {
if (plButtons == null) {
lbLanguage = new JLabel();
lbLanguage.setText(Resource.getResource("SettingsWindow.LanguageChoice")); //$NON-NLS-1$
lbLanguage.setForeground(Color.white);
lbLanguage.setFont(new Font("Verdana",Font.PLAIN,12));
GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
gridBagConstraints10.anchor = GridBagConstraints.WEST;
gridBagConstraints10.insets = new Insets(7, 0, 0, 0);
GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
gridBagConstraints9.gridx = 1;
gridBagConstraints9.insets = new Insets(7, 40, 0, 0);
gridBagConstraints9.gridy = 0;
plButtons = new JPanel();
plButtons.setLayout(new GridBagLayout());
plButtons.setBackground(new Color(108,108,108));
plButtons.add(getBtnOK(), gridBagConstraints10);
plButtons.add(getBtnCancel(), gridBagConstraints9);
}
return plButtons;
}
/**
* This method initializes btnOK
*
* @return javax.swing.JButton
*/
private JButton getBtnOK() {
final JFrame frame = this;
if (btnOK == null) {
btnOK = new JButton();
btnOK.setPreferredSize(new Dimension(110, 20));
btnOK.setBackground(new Color(204,204,204));
btnOK.setText(Resource.getResource("SettingsWindow.OkBtn")); //$NON-NLS-1$
btnOK.setFont(new Font("Verdana",Font.BOLD,12));
btnOK.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent a){
String sel = (String)cbLanguage.getSelectedItem();
if (!isFileExist)
GUIConfig.createXML();
if (sel.compareTo(Resource.getResource("SettingsWindow.LanguageGerman"))==0){ //$NON-NLS-1$
GUIConfig.setLanguage(Locale.GERMANY.getLanguage());
GUIConfig.setCountry(Locale.GERMANY.getISO3Country());
}
if (sel.compareTo(Resource.getResource("SettingsWindow.LanguageEnglish"))==0){ //$NON-NLS-1$
GUIConfig.setLanguage(Locale.ENGLISH.getLanguage());
GUIConfig.setCountry(Locale.ENGLISH.getISO3Country());
}
else{
GUIConfig.setLanguage(Locale.getDefault().getLanguage());
GUIConfig.setCountry(Locale.getDefault().getISO3Country());
}
sel = tfURLName.getText();
if (rbURL.isSelected()){
if(sel.compareTo("")!=0){
GUIConfig.setURL(sel);
}
}
else
if(rbURLHost.isSelected()){
GUIConfig.setURL(Resource.getResource("SettingsWindow.HostURL")); //$NON-NLS-1$
}
String[] tmp = null;
if(guiFrame!=null){
guiFrame.dispose();
}
GUI.main(tmp);
frame.dispose();
}
});
}
return btnOK;
}
/**
* This method initializes btnCancel
*
* @return javax.swing.JButton
*/
private JButton getBtnCancel() {
final JFrame frame = this;
if (btnCancel == null) {
btnCancel = new JButton();
btnCancel.setPreferredSize(new Dimension(110, 20));
btnCancel.setBackground(new Color(204,204,204));
btnCancel.setText(Resource.getResource("SettingsWindow.CancelBtn")); //$NON-NLS-1$
btnCancel.setFont(new Font("Verdana",Font.BOLD,12));
btnCancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (guiFrame != null && guiFrame.isVisible()){
frame.dispose();
}
else{
if (guiFrame != null)
guiFrame.dispose();
frame.dispose();
}
}
});
}
return btnCancel;
}
/**
* This method initializes plLanguage
*
* @return javax.swing.JPanel
*/
private JPanel getPlLanguage() {
if (plLanguage == null) {
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
gridBagConstraints1.gridy = 0;
gridBagConstraints1.weightx = 1.0;
gridBagConstraints1.anchor = GridBagConstraints.EAST;
gridBagConstraints1.insets = new Insets(0, 0, 10, 0);
gridBagConstraints1.gridx = 1;
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = -1;
gridBagConstraints.insets = new Insets(0, 32, 10, 0);
gridBagConstraints.gridy = -1;
plLanguage = new JPanel();
plLanguage.setLayout(new GridBagLayout());
plLanguage.setBackground(new Color(108,108,108));
plLanguage.add(lbLanguage, gridBagConstraints);
plLanguage.add(getCbLanguage(), gridBagConstraints1);
}
return plLanguage;
}
/**
* This method initializes cbLanguage
*
* @return javax.swing.JComboBox
*/
private JComboBox getCbLanguage() {
String[] language = {Resource.getResource("SettingsWindow.LanguageGerman"),Resource.getResource("SettingsWindow.LanguageEnglish")}; //$NON-NLS-1$ //$NON-NLS-2$
if (cbLanguage == null) {
cbLanguage = new JComboBox(language);
cbLanguage.setPreferredSize(new Dimension(150, 25));
cbLanguage.setFont(new Font("Tahoma",Font.PLAIN,12));
cbLanguage.setBackground(Color.gray);
}
return cbLanguage;
}
@SuppressWarnings("unchecked") //$NON-NLS-1$
private boolean checkValid(String s1,String s2,String s3,String s4){
boolean noError=true;
return noError;
}
/**
* This method initializes tfURLName
*
* @return javax.swing.JTextField
*/
private JTextField getTfURLName() {
if (tfURLName == null) {
tfURLName = new JTextField();
tfURLName.setPreferredSize(new Dimension(150, 20));
tfURLName.setBackground(Color.lightGray);
}
return tfURLName;
}
} // @jve:decl-index=0:visual-constraint="10,10"