You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

GUIFramework (GFW) is the basic module for developing Swing GUIs at SLAC.

Requirements TO-DO

Developer's Guide

Abstract

This guide describes in detail how to use GFW in a Swing application. In general, you create your own Swing components (either programmatically, or with a GUI builder) and add them to the appropriate GFW frame.

Overview

We recommend the following steps:

  1. #Check out GFW from CVS into Eclipse.
  2. #Read and run the example code.
  3. #Create custom components for the desired GFW frame
  4. #Write code that adds custom components to GFW.
  5. #Add event listeners to the appropriate widgets.
  6. #Test the application.
  7. #Optional features.

Check out GFW from CVS into Eclipse

GFW is located in $CVSROOT/physics/GUIFramework

Read and run the example code

An example can be found in the class

edu.stanford.slac.gfw.example.GfwExample

When running the example, please observe

  • the different GFW frames
  • the various areas in which the custom components end up
  • how the GUI behaves when it is resized

Create custom components for the desired GFW frame

For a quick development (e.g. GUI mock ups), we recommend the Netbeans GUI Builder.

Write code that adds custom components to GFW

  1. Instantiate the custom components.
  2. Create an appropriate GFW frame and an instance of BasicFrameController
    final BasicFrame myFrame = new BasicFrame("My Frame"); //'final', because it's used later in an anonymous class
    BasicFrameController bfc = new BasicFrameController(myFrame);
    
  3. Using the BasicFrameController instance, add custom components to various areas of the GFW frame, such as
    • Title Bar
      bfc.addToTitleBar(myComponent);
      
    • Tab 1
      bfc.addTopTab1(myComponent);
      
    • Tab 2
      bfc.addTopTab2(myComponent);
      
    • New Tab
      bfc.addTopTab(myComponent, "My Label");
      
    • Bottom ScrollPane
      bfc.addToBottomScrollPane(myComponent);
      
  4. Display the GFW frame
    SwingUtilities.invokeLater(new Runnable() {
    	public void run() {
    		myFrame.setVisible(true);
    	}
    });
    

Add event listeners to the appropriate widgets

Below we describe the recommended way, but nothing prevents you from using any other technique.

  • Extend BasicFrameListener by overriding the default behavior and/or adding your own methods, e.g.
    public class MyBasicFrameListener extends BasicFrameListener {
    
    	@Override
    	public void helpButtonPressed(ActionEvent e) {
    		System.out.println("Help me!!!!");
    	}
    	
    	public void myOwnComponentActivated(EventObject e){
    		System.out.println("My own component activated");
    	}
    }
    
  • Override registerAsDelegateForSwingListeners method of the BasicFrameController class, e.g.
    public class MyBasicFrameController extends BasicFrameController {
    	
    	protected void registerAsDelegateForSwingListeners(
    			final MyBasicFrameListener myBasicFrameListener) {
    		super.registerAsDelegateForSwingListeners(myBasicFrameListener);
    		Component myComponent = null;
    		//get your own component
    		myComponent.addComponentListener(new ComponentAdapter(){
    			public void componentActivated(EventObject e){
    				myBasicFrameListener.myOwnComponentActivated(e);
    			}	
    		});
    	}
    
    	public MyBasicFrameController(BasicFrame basicFrame) {
    		super(basicFrame);
    	}
    
    }
    
  • Add your BasicFrameListener to your BasicFrameController
    MyBasicFrameListener myBasicFrameListener = new MyBasicFrameListener();
    MyBasicFrameController myBasicFrameController = new MyBasicFrameController(myFrame);
    myBasicFrameController.addBasicFrameListener(myBasicFrameListener);
    

Test the application

Optional features

  • No labels