GUIFramework (GFW) is the basic module for developing Swing GUIs at SLAC.
Current Version
0-0-1
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:
- #Check out GFW from CVS into Eclipse.
- #Read and run the example code.
- #Create custom components for the desired GFW frame
- #Customize GFW.
- #Add event listeners to the appropriate widgets.
- #Test the application.
- #Optional features.
- #Tips.
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.
Customize GFW
- Instantiate the custom components.
- Create an appropriate GFW frame, e.g.
final BasicFrame myFrame = new BasicFrame("My Frame"); //'final', because it's used later in an anonymous class
- Add custom components to various areas of the GFW frame, such as
- Title Bar
myFrame.addToTitleBar(myComponent);
- Tab 1
myFrame.addTopTab1(myComponent);
- Tab 2
myFrame.addTopTab2(myComponent);
- New Tab
myFrame.addTopTab(myComponent, "My Label");
- Bottom ScrollPane
myFrame.addToBottomScrollPane(myComponent);
- Title Bar
- Set application version
BasicFrame myFrame = ...; JLabel appVersionLabel = bf.getBasicPanel().getStatusPanel().getAppVersionLabel(); appVersionLabel.setText("my version"); //run in the GUI thread, of before displaying the frame
- #Add event listeners to the appropriate widgets
- 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 MyFrameListener extends BasicFrameListener { @Override public void helpButtonPressed(ActionEvent e) { System.out.println("Help me!!!!"); } public void myComponentActivated(EventObject e){ System.out.println("My component activated"); } }
- Override registerAsDelegateForSwingListeners method of the BasicFrameController class, e.g.
public class MyFrameController extends BasicFrameController { protected void registerAsDelegateForSwingListeners( final MyFrameListener myFrameListener) { super.registerAsDelegateForSwingListeners(myFrameListener); //don't forget this! Component myComponent = null; ... //get your own component myComponent.addComponentListener(new ComponentListener(){ public void componentActivated(EventObject e){ myFrameListener.myComponentActivated(e); } }); } public MyFrameController(BasicFrame myFrame) { super(myFrame); } }
- Add your BasicFrameListener to your BasicFrameController
BasicFrameListener myFrameListener = new MyFrameListener(); BasicFrameController myFrameController = new MyFrameController(myFrame); myFrameController.addBasicFrameListener(myFrameListener);
Test the application
Optional features
Info Text Pane
Located in the status panel, the info text pane can be used to display some info beyond messaging.
JTextPane infoTextPane = bf.getBasicPanel().getStatusPanel().getInfoTextPane(); infoTextPane.setText("my info"); //run in the GUI thread, of before displaying the frame
Progress Bar
Located in the status panel, the progress bar can be used to display some progress
JProgressBar progressBar = bf.getBasicPanel().getStatusPanel().getProgressBar(); //run all methods below in the GUI thread, of before displaying the frame progressBar.setMinimum(0); progressBar.setMaximum(10); progressBar.setValue(6);
or
JProgressBar progressBar = bf.getBasicPanel().getStatusPanel().getProgressBar(); progressBar.setIndeterminate(true); //run in the GUI thread, of before displaying the frame
SwingUtil
Tips
- When adding long text to the GUI that doesn't fit, update the frame, e.g.
BasicFrame myFrame = ...; myFrame.update();