/*
* © 2008 3kraft
* $Id: PreferencesDialog.java,v 1.13 2010-12-03 18:10:03 illetsch Exp $
*/
package com.dreikraft.axbo.gui;
import com.dreikraft.events.ApplicationEventDispatcher;
import com.dreikraft.axbo.controller.PreferencesController;
import com.dreikraft.axbo.events.PrefsClose;
import javax.swing.DefaultComboBoxModel;
/**
* $Id: PreferencesDialog.java,v 1.13 2010-12-03 18:10:03 illetsch Exp $
*
* @author 3kraft - $Author: illetsch $
* @version $Revision: 1.13 $
*/
public class PreferencesDialog extends javax.swing.JDialog
{
private transient PreferencesController ctrl;
public PreferencesDialog(java.awt.Frame parent, boolean modal,
final PreferencesController ctrl)
{
super(parent, modal);
this.ctrl = ctrl;
setResizable(false);
initComponents();
}
/**
* Creates new form PreferencesDialog
*
* @param parent a parent frame
* @param modal is modal?
*/
public PreferencesDialog(java.awt.Frame parent, boolean modal)
{
this(parent, modal, null);
}
public void setController(PreferencesController ctrl)
{
this.ctrl = ctrl;
}
public void initComPortCB(final String[] items, final String sel)
{
comPortCB.setModel(new DefaultComboBoxModel<>(items));
comPortCB.setSelectedItem(sel);
}
public void initLanguageCB(final String[] items, final int sel)
{
languageCB.setModel(new DefaultComboBoxModel<>(items));
languageCB.setSelectedIndex(sel);
}
public void initChartTypeCB(final String[] items, final int sel)
{
chartTypeCB.setModel(new DefaultComboBoxModel<>(items));
chartTypeCB.setSelectedIndex(sel);
}
public String getComPortValue()
{
return (String)comPortCB.getSelectedItem();
}
public int getLanguageIndex()
{
return languageCB.getSelectedIndex();
}
public void setSelectedComPort(String comPortName)
{
comPortCB.setSelectedItem(comPortName);
}
public int getChartTypeIndex() {
return chartTypeCB.getSelectedIndex();
}
public String getSensor1Name()
{
return sensor1NameTextField.getText();
}
public void setSensor1Name(String name)
{
sensor1NameTextField.setText(name);
}
public String getSensor2Name()
{
return sensor2NameTextField.getText();
}
public void setSensor2Name(String name)
{
sensor2NameTextField.setText(name);
}
/** 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("rawtypes")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
preferencesPanel = new javax.swing.JPanel();
comPortLabel = new javax.swing.JLabel();
languageLabel = new javax.swing.JLabel();
languageCB = new javax.swing.JComboBox<String>();
saveButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
comPortCB = new javax.swing.JComboBox<String>();
sensor1NameLabel = new javax.swing.JLabel();
sensor2NameLabel = new javax.swing.JLabel();
sensor1NameTextField = new javax.swing.JTextField();
sensor2NameTextField = new javax.swing.JTextField();
restartLabel = new javax.swing.JLabel();
chartTypeLabel = new javax.swing.JLabel();
chartTypeCB = new javax.swing.JComboBox<String>();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("resources/default"); // NOI18N
setTitle(bundle.getString("preferences.frame.title")); // NOI18N
setAlwaysOnTop(true);
setModal(true);
setName("preferencesDialog"); // NOI18N
setResizable(false);
preferencesPanel.setFocusable(false);
preferencesPanel.setMaximumSize(null);
comPortLabel.setLabelFor(comPortCB);
comPortLabel.setText(bundle.getString("preferences.label.comPort")); // NOI18N
languageLabel.setLabelFor(languageCB);
languageLabel.setText(bundle.getString("preferences.label.language")); // NOI18N
saveButton.setText(bundle.getString("preferences.button.save")); // NOI18N
saveButton.putClientProperty("JButton.buttonType", "textured");
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
cancelButton.setText(bundle.getString("preferences.button.cancel")); // NOI18N
cancelButton.setMaximumSize(null);
cancelButton.setMinimumSize(null);
cancelButton.setPreferredSize(null);
cancelButton.putClientProperty("JButton.buttonType", "textured");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
comPortCB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comPortCBActionPerformed(evt);
}
});
sensor1NameLabel.setText(bundle.getString("label.sensor1Name")); // NOI18N
sensor2NameLabel.setText(bundle.getString("label.sensor2Name")); // NOI18N
restartLabel.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
restartLabel.setForeground(new java.awt.Color(255, 0, 0));
restartLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
restartLabel.setText(bundle.getString("preference.label.restart")); // NOI18N
chartTypeLabel.setText(bundle.getString("preferences.label.chartType")); // NOI18N
javax.swing.GroupLayout preferencesPanelLayout = new javax.swing.GroupLayout(preferencesPanel);
preferencesPanel.setLayout(preferencesPanelLayout);
preferencesPanelLayout.setHorizontalGroup(
preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(preferencesPanelLayout.createSequentialGroup()
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(preferencesPanelLayout.createSequentialGroup()
.addGap(13, 13, 13)
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(sensor2NameLabel)
.addComponent(sensor1NameLabel)
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(languageLabel)
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(chartTypeLabel)
.addComponent(comPortLabel))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, preferencesPanelLayout.createSequentialGroup()
.addComponent(languageCB, 0, 208, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(restartLabel))
.addComponent(comPortCB, 0, 290, Short.MAX_VALUE)
.addComponent(sensor1NameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
.addComponent(sensor2NameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
.addComponent(chartTypeCB, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, preferencesPanelLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(saveButton)))
.addContainerGap())
);
preferencesPanelLayout.setVerticalGroup(
preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(preferencesPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(preferencesPanelLayout.createSequentialGroup()
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(restartLabel)
.addComponent(languageCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(languageLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(comPortCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(comPortLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(chartTypeLabel)
.addComponent(chartTypeCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sensor1NameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sensor1NameLabel))
.addGap(32, 32, 32))
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sensor2NameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sensor2NameLabel)))
.addGroup(preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saveButton)
.addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
getContentPane().add(preferencesPanel, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cancelButtonActionPerformed
{//GEN-HEADEREND:event_cancelButtonActionPerformed
ApplicationEventDispatcher.getInstance().dispatchGUIEvent(new PrefsClose(
this, false));
}//GEN-LAST:event_cancelButtonActionPerformed
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_saveButtonActionPerformed
{//GEN-HEADEREND:event_saveButtonActionPerformed
ApplicationEventDispatcher.getInstance().dispatchGUIEvent(new PrefsClose(
this, true));
}//GEN-LAST:event_saveButtonActionPerformed
private void comPortCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comPortCBActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_comPortCBActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JComboBox<String> chartTypeCB;
private javax.swing.JLabel chartTypeLabel;
private javax.swing.JComboBox<String> comPortCB;
private javax.swing.JLabel comPortLabel;
private javax.swing.JComboBox<String> languageCB;
private javax.swing.JLabel languageLabel;
private javax.swing.JPanel preferencesPanel;
private javax.swing.JLabel restartLabel;
private javax.swing.JButton saveButton;
private javax.swing.JLabel sensor1NameLabel;
private javax.swing.JTextField sensor1NameTextField;
private javax.swing.JLabel sensor2NameLabel;
private javax.swing.JTextField sensor2NameTextField;
// End of variables declaration//GEN-END:variables
}