/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* SettingsDialog.java
*
* Created on Nov 4, 2008, 5:29:49 PM
*/
package owsproxyclient.settings;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import owsproxyclient.OWSClientGUI;
/**
*
* @author jeichar
*/
public class SettingsDialog extends javax.swing.JDialog {
private static final ResourceBundle translations = ResourceBundle.getBundle("owsproxyclient/translations");
private Result _result;
public int getActiveTabIndex() {
return jTabbedPane1.getSelectedIndex();
}
public List<Object> getState() {
ArrayList<Object> state = new ArrayList<Object>();
for (int i = 0; i < jTabbedPane1.getTabCount(); i++) {
SettingsPanel panel = (SettingsPanel) jTabbedPane1.getComponentAt(i);
state.add(panel.getState());
}
return state;
}
public void setMessage(String message) {
this.messages.setText(message);
}
public enum Result {
OK, CANCEL
}
/** Creates new form SettingsDialog */
public SettingsDialog(OWSClientGUI parent, boolean modal, List<Object> state) {
super(parent, modal);
initComponents();
for (int i = 0; i < jTabbedPane1.getTabCount(); i++) {
SettingsPanel panel = (SettingsPanel) jTabbedPane1.getComponentAt(i);
panel.init();
if( state!=null ){
panel.setState(state.get(i));
}
}
pack();
}
public Result getResult() {
return _result;
}
public void setActiveTab(int index){
jTabbedPane1.setSelectedIndex(index);
}
void updateButtons() {
boolean failure = false;
for (int i = 0; i < jTabbedPane1.getTabCount(); i++) {
SettingsPanel panel = (SettingsPanel) jTabbedPane1.getComponentAt(i);
final String msg = panel.getErrorMessage();
if (msg != null) {
jTabbedPane1.setTitleAt(i,"*"); // NOI18N
failure = true;
} else {
jTabbedPane1.setTitleAt(i, ""); // NOI18N
}
if (i == jTabbedPane1.getSelectedIndex()) {
if (msg == null) {
messages.setText("");
} else {
messages.setText(msg);
}
}
}
messages.updateUI();
okButton.setEnabled(!failure);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jTabbedPane1 = new javax.swing.JTabbedPane();
proxyPanel = new ProxySettingsPanel(this);
jPanel2 = new SecuritySettingsPanel(this);
cancelButton = new javax.swing.JButton();
okButton = new javax.swing.JButton();
messages = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
org.jdesktop.layout.GroupLayout proxyPanelLayout = new org.jdesktop.layout.GroupLayout(proxyPanel);
proxyPanel.setLayout(proxyPanelLayout);
proxyPanelLayout.setHorizontalGroup(
proxyPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 422, Short.MAX_VALUE)
);
proxyPanelLayout.setVerticalGroup(
proxyPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 234, Short.MAX_VALUE)
);
jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/owsproxyclient/proxy.png")), proxyPanel); // NOI18N
org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 422, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 234, Short.MAX_VALUE)
);
jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/owsproxyclient/kgpg.png")), jPanel2); // NOI18N
cancelButton.setText(translations.getString("Cancel")); // NOI18N
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
okButton.setText(translations.getString("OK")); // NOI18N
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
messages.setForeground(new java.awt.Color(255, 0, 3));
messages.setBorder(null);
messages.setOpaque(true);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.add(messages, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 118, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cancelButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 286, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(messages, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(cancelButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(okButton))
.addContainerGap())
);
layout.linkSize(new java.awt.Component[] {cancelButton, okButton}, org.jdesktop.layout.GroupLayout.VERTICAL);
pack();
}// </editor-fold>//GEN-END:initComponents
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
_result = Result.CANCEL;
setVisible(false);
}//GEN-LAST:event_cancelButtonActionPerformed
private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
_result = Result.CANCEL;
}//GEN-LAST:event_formWindowClosed
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
_result = Result.OK;
setVisible(false);
}//GEN-LAST:event_okButtonActionPerformed
public Object getState(int tabIndex) {
return ((SettingsPanel) jTabbedPane1.getComponentAt(tabIndex)).getState();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JPanel jPanel2;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JLabel messages;
private javax.swing.JButton okButton;
private javax.swing.JPanel proxyPanel;
// End of variables declaration//GEN-END:variables
}