KaAPI - K(C)ustomizable awt API

  • Specification
  • Architecture
  • The API
  • 
    
    

    Specification

    Objective

    To provide Customization and Extendibility for a Java application during _RUNTIME_ with the features provides by the Java language only. The API should not have any native method implementations and hence should be binary compatible on all Java platforms.

    Scope

    KaAPI is a framework, primarily for creating UI applications in Java using the java.awt package that could be customizable and extendable by the user of the application by adding/replacing new UI components and preserving the original semantics of the application.

    The framework also supports customization of any non-UI components. ( any Java class which is KaAPI enabled ,like sort algorithm )

    Features

    Application Features
    The following features are provided at the Application level, meaning to get these features an end-user needs to make changes only to the format file and not to the sources.
  • Component addition

    Any java class which implements the KUIComponent interface can be added to the KaAPI aware application.

  • Component deletion

    Any KUIComponent in a KaAPI aware application can be deleted. The side effect could be that the application might break if the deleted component is referenced by any other component. KUIComponents that are stand-alone can be deleted without breaking the application.

  • Component plugging

    Any KUIComponent can be replaced with any other KUIComponent with some limitations

  • Cosmetic customization

    KUIComponents can be placed at different locations and also its dimension, color etc can be modified.

    Programming Features

    The following features are provided for the programmers, who develop KaAPI enabled components.

  • Visibility

    A KUIComponent can be shown/hidden, and this can be dynamically changed from with-in another KUIComponent. This would be useful to create all the KUIComponents and show/hide them programatically.

  • Cloning

    A KUIComponent can clone an existing KUIComponent dynamically. Cloned objects have the same behavior, but can have different view.(ex:- a cloned button can have a different Label)

    Advantages

    Provides support for application enhancements and customization.

    The look-n-feel of the application can be customized depending on the user needs.

    Application prototypes can be generated faster by simply editing the format files and without changing sources. (next version would include a Visual format editor which would make prototyping even faster)

    Disadvantages

    Since all information about the KUI components is kept in a text file(.format), the semantics of the application could be changed by a bad programmer/user.

    Limitations

    Replacing a particular component (be it UI or non-UI) can only be done as follows :-

  • if a component A extends a class and the application only uses the public interface of the base class, then we could replace A with B which also extends the same base class as A.
  • if a component A publishes a 'java language interface' which it implements and the application only uses that 'interface', then a component B can implement that interface and be pluggable where A resides.

    Note :- With JDK 1.1 any KUIComponent class can be replaced with any other KUIComponent class provided all the public method's signature (method_name,arguments) of the former and the latter are the same


    Architecture

    KaAPI features are supported only for KaAPI enabled classes. 'KaAPI enabled' components or classes are any Java class which implements the KUIComponent interface.

    The Framework

    KaAPI package

    The KaAPI Components are packaged as 'KaAPI' package with the following public classes.
  • KFrame.class

    This is responsible for placing and creation of the KUI ( KaAPI UI ) components. The Application needs to create an Object of this class.

  • KFrameAgent.class

    This class is the interface between any KUI Component and its parent KFrame class.

  • KUICSyntaxChecker.class

    This is used to validate any format file.

  • KUIComponent.class

    The interface definition.

    All instances of KUI Component names are kept in a text file with .format extension. The format file should be passed to the KFrame() constructor.

    Sample code

    The following code fragment shows how to create a KFrame object and initialize the application

    
    package Apps ;
    
    import java.lang.* ;
    import java.io.* ;
    import java.awt.* ;
    import java.util.* ;
    
    import KaAPI.* ;
    
    /**
     * KaAPI Framework Demo
     *
     * @version 1.1 19 Oct 1996
     * @author  shiva
     **/
    
    public class KaAPIdemo
    {
        public    static    void    main( String[] args )
        {
            if ( args.length <= 0 ){
                System.out.println("Usage : KaAPIdemo <filename>") ;
                System.exit(0) ;
            }
    
            KFrame    wf = null ;
    
            try {
                wf = new KFrame( args[0] ) ;
            }
            catch( IOException e ){
                System.out.println(
                    args[0]+" is not found or the syntax is incorrect.") ;
                System.out.println(
                    "Run KUICc on the format file if exists") ;
                System.exit(0) ;
            }
    
            wf.setTitle("KaAPI Framework Demo") ;
            wf.setBackground(Color.lightGray) ;
            wf.showFrame() ;
        }
    }
    

    The following file is a java.awt.Button class that is KaAPI enabled

    
    package    KaAPI.widgets ;
    
    import java.io.* ;
    import java.awt.* ;
    
    import KaAPI.* ;
    
    /**
     * Button that is KaAPI framework aware
     *
     * @version 1.1 11 Aug 1996
     * @author  shiva
     **/
    
    public class KUICButton extends Button implements KUIComponent
    {
        private    int                _location ;
        private    int                _visibility ;
    
        protected String[]        ArgsKuic ;
        protected String[]        KuicLinks ;
        protected String          VarName ;
        protected KFrameAgent     FrameAgent ;
    
        public    KUICButton()
        {
            super(KFrame.AGENT.getArguments(0)) ;
        }
    
        public int    getUICLocation()
        {
            return _location ;
        }
    
        public int    getUICVisibility()
        {
            return _visibility ;
        }
    
        public boolean    setUICVisibility(int visFlag)
        {
            switch( visFlag ){
            case    KUIComponent.UIC_VISIBILITY_TOGGLE:
                if ( _visibility == KUIComponent.UIC_VISIBILITY_SHOW )
                    _visibility = KUIComponent.UIC_VISIBILITY_HIDE ;
                else
                if ( _visibility == KUIComponent.UIC_VISIBILITY_HIDE )
                    _visibility = KUIComponent.UIC_VISIBILITY_SHOW ;
                break ;
    
            case    KUIComponent.UIC_VISIBILITY_SHOW:
            case    KUIComponent.UIC_VISIBILITY_HIDE:
                    _visibility = visFlag ;
            }
    
            return true ;    /* change in visibility accepted */
    
        }
    
        public void    initUIC(String[] argsKaapi,String[] argsKuic,
                            String[] uicLinks,KFrameAgent frameAgent)
        {
            ArgsKuic      = argsKuic ;
            FrameAgent    = frameAgent ;
            VarName       = FrameAgent.getVariableName((KUIComponent)this);
            KuicLinks     = uicLinks ;
    
            _location     = frameAgent.getLocation(argsKaapi) ;
            _visibility   = frameAgent.getVisibility(argsKaapi) ;
        }
    
        public void    addUIC(KUIComponent kuic)
        {
        }
    }