/* * SerialUdpView.java * * Copyright (c) 2003-2004 Digi International * This program and the information contained in it is confidential and * proprietary to Digi International and may not be used, copied, or re- * produced without the prior written permission of Digi International. * */ package com.digi.config.ui; import com.digi.config.core.*; import com.digi.config.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; import javax.swing.border.*; import javax.swing.text.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.net.*; import java.text.*; /** * This class is a view panel that shows the serial UDP * settings for the ConnectMe device * * This view can be embedded in other panels as desired. */ public class SerialUdpView extends ConfigViewImpl { /** A KvpNode that holds just the fields used in this view */ KvpNode viewSettingTree; /** listens to the device for changes to kvpGroup */ DeviceChangeListener settingChangeListener; /** Panel that holds the view content */ GridContentPanel content; GridContentPanel serverContent; GridContentPanel clientContent; GridContentPanel sendToContent; GridContentPanel socketIdContent; GridContentPanel sopContent; GridContentPanel sopCustomContent; GridContentPanel satContent; GridContentPanel sabContent; int MAXDESTINATIONS = 64; // Data fields currently used in this view KvpField udpServerEnabledKvpField; KvpField udpServerPortKvpField; KvpField udpClientEnabledKvpField; KvpField udpSendToEnabledKvpField[] = new KvpField[MAXDESTINATIONS]; KvpField udpSendToAddressKvpField[] = new KvpField[MAXDESTINATIONS]; KvpField udpSendToPortKvpField[] = new KvpField[MAXDESTINATIONS]; KvpField udpSendToDescKvpField[] = new KvpField[MAXDESTINATIONS]; KvpField udpSocketIdEnabledKvpField; KvpField udpSocketIdKvpField; KvpField udpSopEnabledKvpField; KvpField udpSopPatternKvpField; KvpField udpSopStripPatternKvpField; KvpField udpSatEnabledKvpField; KvpField udpSatValueKvpField; KvpField udpSabEnabledKvpField; KvpField udpSabValueKvpField; // UI Controls for each field JCheckBox udpServerEnabled_UIC; JTextField udpServerPort_UIC; JCheckBox udpClientEnabled_UIC; JCheckBox udpSendToEnabled_UIC[] = new JCheckBox[MAXDESTINATIONS]; JTextField udpSendToAddress_UIC[] = new JTextField[MAXDESTINATIONS]; JTextField udpSendToPort_UIC[] = new JTextField[MAXDESTINATIONS]; JTextField udpSendToDesc_UIC[] = new JTextField[MAXDESTINATIONS]; JCheckBox udpSocketIdEnabled_UIC; JTextField udpSocketId_UIC; JCheckBox udpSopEnabled_UIC; JRadioButton udpSopCR_UIC; JRadioButton udpSopCRLF_UIC; JRadioButton udpSopCustom_UIC; JTextField udpSopCustomString_UIC; JCheckBox udpSopStripPattern_UIC; JCheckBox udpSatEnabled_UIC; JTextField udpSatValue_UIC; JCheckBox udpSabEnabled_UIC; JTextField udpSabValue_UIC; /** * Basic constructor. Sets up the tree view and the edit panel. */ public SerialUdpView() throws Exception { // create the KvpNode and the kvpGroup change listener viewSettingTree = new KvpNode(); settingChangeListener = new DeviceChangeListener() { public void deviceChanged(DeviceChangeEvent e) { SystemLog.debug("SerialUdpView was notified that device kvpGroup changed"); refreshViewKvpNode(); refreshViewControls(); } }; // Create the panel that will hold the view controls content = new GridContentPanel(this.getName(),1); // create a listener that will detect when a user edits the field values and update the appropriate view setting fields ControlChangeAdapter fieldListener = new ControlChangeAdapter() { public void changePerformed(Object source, ActionEvent ae, FocusEvent fe) { if (source==udpServerEnabled_UIC) udpServerEnabledKvpField.setStringValue(RciProtocol.toString(udpServerEnabled_UIC.isSelected())); else if (source==udpServerPort_UIC) udpServerPortKvpField.setStringValue(udpServerPort_UIC.getText()); else if (source==udpClientEnabled_UIC) udpClientEnabledKvpField.setStringValue(RciProtocol.toString(udpClientEnabled_UIC.isSelected())); else if (source==udpSocketIdEnabled_UIC) udpSocketIdEnabledKvpField.setStringValue(RciProtocol.toString(udpSocketIdEnabled_UIC.isSelected())); else if (source==udpSocketId_UIC) udpSocketIdKvpField.setStringValue(udpSocketId_UIC.getText()); else if (source==udpSopEnabled_UIC) udpSopEnabledKvpField.setStringValue(RciProtocol.toString(udpSopEnabled_UIC.isSelected())); else if (source==udpSopCR_UIC) { if (udpSopCR_UIC.isSelected()) udpSopPatternKvpField.setStringValue("CR"); } else if (source==udpSopCRLF_UIC) { if (udpSopCRLF_UIC.isSelected()) udpSopPatternKvpField.setStringValue("CR/LF"); } else if (source==udpSopCustom_UIC) { if (udpSopCustom_UIC.isSelected()) udpSopPatternKvpField.setStringValue(udpSopCustomString_UIC.getText()); } else if (source==udpSopCustomString_UIC) { if (udpSopCustom_UIC.isSelected()) udpSopPatternKvpField.setStringValue(udpSopCustomString_UIC.getText()); } else if (source==udpSopStripPattern_UIC) udpSopStripPatternKvpField.setStringValue(RciProtocol.toString(udpSopStripPattern_UIC.isSelected())); else if (source==udpSatEnabled_UIC) udpSatEnabledKvpField.setStringValue(RciProtocol.toString(udpSatEnabled_UIC.isSelected())); else if (source==udpSatValue_UIC) udpSatValueKvpField.setStringValue(udpSatValue_UIC.getText()); // else if (source==udpSabEnabled_UIC) // udpSabEnabledKvpField.setStringValue(RciProtocol.toString(udpSabEnabled_UIC.isSelected())); else if (source==udpSabValue_UIC) udpSabValueKvpField.setStringValue(udpSabValue_UIC.getText()); else { // Next, check to see if it was one of the destination list fields for (int i=0;i 40) errorList.add(new ValidationError("SerialUdpSocketIdError")); } // Verify String Mode if Enabled if (udpSopEnabled_UIC.isSelected()) { if (udpSopCR_UIC.isSelected() || udpSopCRLF_UIC.isSelected()) { // Nothing to Validate } else if (udpSopCustom_UIC.isSelected()) { if (udpSopCustomString_UIC.getText().length() == 0) errorList.add(new ValidationError("SerialUdpCustomStringError")); } else errorList.add(new ValidationError("SerialUdpSendOnPatternError")); } // Verify Send after Byte Mode if Enabled // if (udpSabEnabled_UIC.isSelected()) { if (!ValidationHelper.isValidRange(udpSabValue_UIC.getText(), 4, 4096)) errorList.add(new ValidationError("SerialUdpSendAfterByteError")); // } // Verify Send after Time Mode if Enabled if (udpSatEnabled_UIC.isSelected()) { if (!ValidationHelper.isValidRange(udpSatValue_UIC.getText(), 1, 65535)) errorList.add(new ValidationError("SerialUdpSendAfterTimeError")); } // Verify Destinations for (int i = 0; i < MAXDESTINATIONS; i++) { if (!ValidationHelper.isValidIPAddress(udpSendToAddress_UIC[i].getText())) errorList.add(new ValidationError("SerialUdpDestinationAddressError", new Serializable[]{ String.valueOf(i+1)})); if (!ValidationHelper.isValidNetworkPort(udpSendToPort_UIC[i].getText())) errorList.add(new ValidationError("SerialUdpDestinationPortError", new Serializable[]{ String.valueOf(i+1)})); if (udpSendToEnabled_UIC[i].isSelected()) { // Verify Valid if (InetAddress.getByName(udpSendToAddress_UIC[i].getText()).equals(InetAddress.getByName("0.0.0.0"))) errorList.add(new ValidationError("SerialUdpDestinationAddressError", new Serializable[]{ String.valueOf(i+1)})); if (Integer.parseInt(udpSendToPort_UIC[i].getText()) <= 0) errorList.add(new ValidationError("SerialUdpDestinationPortError", new Serializable[]{ String.valueOf(i+1)})); } } } } catch (Exception e) { System.out.println("Caught Exception in SerialUdpView::validationChanges()"); e.printStackTrace(); } } /** * This method instructs the view to place any changes the user has made within * the view into the provided clusters. Once the changes have been saved to * to the device, a subsequent call to commitChanges() will be made. */ public void getChanges(KvpNode settingCluster, KvpNode stateCluster) { // Merge the view changes into the provided cluster settingCluster.merge(viewSettingTree, false); } /** * Instructs the view to consider any user changes within the view as * saved to the device (ie committed). */ public void commitChanges() { // simply reset flags indicating user changes in the contols viewSettingTree.resetChanged(); } /** * Instructs the view to discard any changes the user has made within the * view and revert those fields to the original state. The view is also * free to refresh all its fields to the present cached state of the device at * this time. */ public void cancelChanges() { refreshViewKvpNode(); refreshViewControls(); } }