> List of tutorials

Table of contents for this tutorial

Fat-Client-Development - JSBS_GUIServices, Services for GUI-elements

* For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

  • The owner of this web-site (www.javascout.biz) is not responsible for the content of web-sites linked within this document or other documents of www.javascout.biz.

  • If this document or other documents of this web-site (www.javascout.biz) infringes rights of third parties and your rights are infringed or you think that rights of others are infringed, please inform the author.
    An e-mail can be sent by clicking onto the 'hungry mailbox' in the upper right corner.

Last revision of this document:
2006-05-25

This is document contains the code for Class JSBS_GUIServices.
For easy 'cut and paste' ;-).

package js_base.frame;
 
import java.awt.*;
import javax.swing.*;
/**
 
*
 * @author
kurt@javascout.biz
 * @date 2006-05-03
 *
 * @description
 *  Class with static methods providing utilities around
 *  GUI-elements in general and
 *  the classes JSBS_StartFrame and JSBS_DetailFrame.
 *
 * @change-log
 * when         who               why
 * --------------------------------------------------------
 *
 */

public class JSBS_GUIServices {
/*
 * --------------------
 * Method to set the language dependant text to the GUI-elements of
 * classes derived from JSBS_StartFrame. */
    public static int
processLanguageDependantElements(JSBS_StartFrame parmfrmJSBS_StartFrame) {
/* Return-Code to pass the status, that was reported by called methods, back */
     int intStatusCode = 0;
/* local StatusCode for comparisons */
     int locintStatusCode = 0;
/* 
 * Call the method that sets the text into the TitleBar of the frame */
     locintStatusCode =
      parmfrmJSBS_StartFrame.structJSBS_XML_DisplayStrings.processJFrame(parmfrmJSBS_StartFrame);

/* Check if another Code than 0 (OK) was returned and keep it in that case */
     if (locintStatusCode > 0) intStatusCode = locintStatusCode ;
/* 
 * Get the 'ClassName' of the passed parameter - it is used in the next method-call */
     String locstrClassName = parmfrmJSBS_StartFrame.getClass().getName().trim();
/* 
 * Get the 'ContentPane' and call the method that inspects it recursive */
     Container locContainer = parmfrmJSBS_StartFrame.getContentPane();
  
   locintStatusCode =
       processLanguageDependantElements(
         locstrClassName, parmfrmJSBS_StartFrame, locContainer)
;

/* Check if another Code than 0 (OK) was returned and keep it in that case */
     if (locintStatusCode > 0) intStatusCode = locintStatusCode ;
/* 
 * Return the Status to the caller */
     
return intStatusCode;

  }
/*
 * --------------------
 * Method to set the language dependant text to the GUI-elements of
 * classes derived from JSBS_TaskFrame. */
    public static int processLanguageDependantElements(JSBS_TaskFrame parmfrmJSBS_TaskFrame) {
/* Return-Code to pass the status, that was reported by called methods, back */
     int intStatusCode = 0;
/* local StatusCode for comparisons */
     int locintStatusCode = 0;
/* Derive the StartFrame. */
     JSBS_StartFrame frmJSBS_StartFrame = parmfrmJSBS_TaskFrame.frmCC;
/* 
 * Call the method that sets the text into the TitleBar of the frame */
     locintStatusCode =
      frmJSBS_StartFrame.structJSBS_XML_DisplayStrings.processJFrame(parmfrmJSBS_TaskFrame);

/* Check if another Code than 0 (OK) was returned and keep it in that case */
     if (locintStatusCode > 0) intStatusCode = locintStatusCode ;
/* 
 * Get the 'ClassName' of the passed parameter - it is used in the next method-call */
     String locstrClassName = parmfrmJSBS_TaskFrame.getClass().getName().trim();
/* 
 * Get the 'ContentPane' and call the method that inspects it recursive */
     Container locContainer = parmfrmJSBS_TaskFrame.getContentPane();
  
   locintStatusCode =
       processLanguageDependantElements(
         locstrClassName, frmJSBS_StartFrame, locContainer)
;

/* Check if another Code than 0 (OK) was returned and keep it in that case */
     if (locintStatusCode > 0) intStatusCode = locintStatusCode ;
/* 
 * Return the Status to the caller */
     
return intStatusCode;

  }
/*
 * --------------------
 * Method to recursively search the hierarchic structure
 * of the GUI.
 * This is an internal method; methods to be called from other classes are
 * - processLanguageDependantElements(JSBS_StartFrame parmfrmJSBS_StartFrame) and
 * - processLanguageDependantElements(JSBS_TaskFrame parmfrmJSBS_TaskFrame)
*
/
    private static int processLanguageDependantElements(
                          String parmstrFrameClassName,
                          JSBS_StartFrame parmfrmJSBS_StartFrame,
                          Container parmContainer
) {
/* Return-Code to pass the status, that was reported by called methods, back */
      int intStatusCode = 0;
      int locintStatusCode = 0;
/* 
 * Check what type the 'Container' is of and call the suitable method */
     if (parmContainer instanceof JLabel) {
        JLabel locJLabel = (JLabel) parmContainer;
        locintStatusCode =
          parmfrmJSBS_StartFrame.structJSBS_XML_DisplayStrings.processJLabel(locJLabel,
                                                                              parmstrFrameClassName);
/* 
 * Check if another Code than 0 (OK) was returned and keep it in that case */
        if (locintStatusCode > 0) intStatusCode = locintStatusCode;
        return intStatusCode;
      }
/* */
     if (parmContainer instanceof JButton) {
        JButton locJButton = (JButton) parmContainer;
        locintStatusCode =
          parmfrmJSBS_StartFrame.structJSBS_XML_DisplayStrings.processJButton(locJButton,
                                                                              parmstrFrameClassName);
/* 
 * Check if another Code than 0 (OK) was returned and keep it in that case */
        if (locintStatusCode > 0) intStatusCode = locintStatusCode;
        return intStatusCode;
      }
/* */
     if (parmContainer instanceof JTextField) {
/* implement call to appropriate method later */
        return intStatusCode;
      }
/* 
 * Get child-elements and call this method recursively */
     Component comps[] = parmContainer.getComponents();
      for (int i = 0; i < comps.length; i++) {
        Component comp = comps[i];
        if (comp instanceof Container) {
          locintStatusCode =
                processLanguageDependantElements(parmstrFrameClassName,
                                                 parmfrmJSBS_StartFrame,
                                                 (Container) comp
);

/* 
 * Check if another Code than 0 (OK) was returned and keep it in that case */
          if (locintStatusCode > 0) intStatusCode = locintStatusCode ;
        }
      }
/* 
 * Return the Status to the caller */
     return intStatusCode;
  }
/*
 * --------------------
 * Method to get the text entered by a user out of a GUI-Element of class JtextField. */
    public static String getTextFromJTextField(JTextField parmJTextField) {
      String locstrReturnValue = parmJTextField.getText().trim();
      return locstrReturnValue;
    }
}