/// <summary> /// Validates data entered in the GUI. If any values are invalid (non-numbers in /// the X and Y fields, blank label field), the OK button is disabled and the field is highlighted in red. </summary> /// <returns> true if all the text is valid. False if not. </returns> private bool validateData() { string text = __textTextField.getText().Trim(); double x = -1; bool badX = false; double y = -1; bool badY = false; GRLimits limits = __parent.getDataLimits(); // make sure the X value is a double and that it is within the range // of the X values in the data limits try { x = (Convert.ToDouble(__xTextField.getText().Trim())); if (x < limits.getLeftX() || x > limits.getRightX()) { badX = true; } } catch (Exception) { badX = true; } // if the X value is not valid, set the textfield red to show this. // Otherwise, make sure the text has the proper background color. if (badX) { __xTextField.setBackground(Color.red); } else { __xTextField.setBackground(__textFieldBackground); } // make sure the Y value is a double and that it is within the range // of the Y values in the data limits try { y = (Convert.ToDouble(__yTextField.getText().Trim())); if (y < limits.getBottomY() || y > limits.getTopY()) { badY = true; } } catch (Exception) { badY = true; } // if the Y value is not valid, set the textfield red to show this. // Otherwise, make sure the text has the proper background color. if (badY) { __yTextField.setBackground(Color.red); } else { __yTextField.setBackground(__textFieldBackground); } // make sure that the text is not an empty string. If it is, make // its textfield red. Otherwise, the textfield will have the normal textfield color. bool badText = false; if (text.Trim().Equals("")) { badText = true; __textTextField.setBackground(Color.red); } else { __textTextField.setBackground(__textFieldBackground); } // make sure that the font size is an integer greater than 0. If not, // set its textfield to red. Otherwise the textfield will have a normal textfield color. bool badFontSize = false; int size = 0; try { size = (Convert.ToInt32(__fontSizeTextField.getText().Trim())); } catch (Exception) { badFontSize = true; } if (size <= 0) { badFontSize = true; } if (badFontSize) { __fontSizeTextField.setBackground(Color.red); } else { __fontSizeTextField.setBackground(__textFieldBackground); } if (!badText && !badX && !badY && !badFontSize) { // if all the data validated properly then mark whether the data are dirty or not. // OK is only active if the data are valid and something is dirty. bool dirty = false; PropList p = (PropList)__node.getAssociatedObject(); string temp = p.getValue("Text").Trim(); if (!temp.Equals(__textTextField.getText().Trim())) { dirty = true; } string val = p.getValue("Point").Trim(); temp = StringUtil.getToken(val, ",", 0, 0); if (!temp.Equals(__xTextField.getText().Trim())) { dirty = true; } temp = StringUtil.getToken(val, ",", 0, 1); if (!temp.Equals(__yTextField.getText().Trim())) { dirty = true; } temp = p.getValue("OriginalFontSize").Trim(); if (!temp.Equals(__fontSizeTextField.getText().Trim())) { dirty = true; } temp = p.getValue("FontName").Trim(); if (!temp.Equals(__fontNameComboBox.getSelected().Trim())) { dirty = true; } temp = p.getValue("FontStyle").Trim(); if (!temp.Equals(__fontStyleComboBox.getSelected().Trim())) { dirty = true; } temp = p.getValue("TextPosition").Trim(); if (!temp.Equals(__textPositionComboBox.getSelected().Trim())) { dirty = true; } __applyButton.setEnabled(dirty); __okButton.setEnabled(dirty); return(true); } else { // if the data aren't valid, the ok button is not enabled __applyButton.setEnabled(false); __okButton.setEnabled(false); return(false); } }