Back Home

The Customizer Framework

The Customizer Framework is a framework to customize Swing components with a GUI. Thus it can be used as a base for applications like layout editors. Currently you can move and resize components with the mouse, snap-to-grid feature is supported and many things more covered in this trail.

JCustomizer and JCustomizerPane

JCustomizer wraps a JComponent and allows customization of the following properties: To move and resize the JCustomizer with the mouse you have to add it to a JCustomizerPane.
Double-clicking on a JCustomizer will fire an ActionEvent. You can register an ActionListener to get notified about these events.

Here's a picture of an application that uses a single JCustomizer added to a JCustomizerPane:

A snapshot of the SimpleSingleCustomizerSample



Try this:
  1. using Java Web Start.
  2. Select the JCustomizer by clicking it. Then the handles appear. You can move and resize the component with the mouse. When you release the JCustomizer it snaps to the grid. If you resize the frame the grid adjusts to its size.

Below is the code from SimpleSingleCustomizerSample.java that creates and configures the JCustomizer and the JCustomizerPane.
            
  1. // create a pane that supports customizers and "snap-to-grid" feature  
  2. JCustomizerPane pane = new JCustomizerPane();  
  3. // create a CustomizerLayout  
  4. InfiniteTableLayout itl = new InfiniteTableLayout(5050, pane);  
  5. // set the layout  
  6. pane.setCustomizerLayout(itl);  
  7. // create a JCustomizer that wraps a component and listens to mouse events  
  8. JCustomizer simpleCustomizer = new JCustomizer(new JLabel("A Simple Component"));  
  9. // add it to the JCustomizerPane  
  10. pane.addCustomizer(simpleCustomizer, new AbsoluteTableConstraints(505015050, simpleCustomizer, itl));  
  11.       

Text Customizers

AbstractTextCustomizer is a base class to write customizers for components, which can display texts, with inline-editing support. The framework provides 3 implementations:



A snapshot of the TextCustomizersSample



Try this:
  1. using Java Web Start.
  2. Double-click a text editor to edit its text and resize the JHtmlCustomizer to see how the text wraps automatically!

Below is the code from TextCustomizersSample.java that creates and configures the text customizers.
            
  1.  // create a CustomizerLayout  
  2.  InfiniteTableLayout itl = new InfiniteTableLayout(customizerPane);  
  3.  // set the layout  
  4.  customizerPane.setCustomizerLayout(itl);  
  5.  // create a JLabelCustomizer, which supports inline editing of a text  
  6.  JLabelCustomizer labelCustomizer = new JLabelCustomizer("A Label Customizer - double click to edit!");  
  7.  // add it to the JCustomizerPane  
  8.  customizerPane.addCustomizer(labelCustomizer, new AbsoluteTableConstraints(5050,  27020, labelCustomizer, itl));  
  9.  // create a JButtonCustomizer to customize a button using the String constructor.  
  10.  JButtonCustomizer buttonCustomizer = new JButtonCustomizer("Double click to edit this button!");  
  11.  // add it to the JCustomizerPane  
  12.  customizerPane.addCustomizer(buttonCustomizer, new AbsoluteTableConstraints(300100,  21050, buttonCustomizer, itl));  
  13.  // create a JButtonCustomizer to customize a JCheckBox  
  14.  JButtonCustomizer checkBoxCustomizer = new JButtonCustomizer(new JCheckBox("Double click to edit this check box!"true));  
  15.  // set the background color to white  
  16.  checkBoxCustomizer.setBackground(Color.WHITE);  
  17.  // add it to the JCustomizerPane  
  18.  customizerPane.addCustomizer(checkBoxCustomizer, new AbsoluteTableConstraints(30160,  25020, checkBoxCustomizer, itl));  
  19.  // create a JButtonCustomizer to customize a JRadioButton  
  20.  JButtonCustomizer radioButtonCustomizer = new JButtonCustomizer(new JRadioButton("Double click to edit this radio button!"true));  
  21. // set the background color to white  
  22.  radioButtonCustomizer.setBackground(Color.WHITE);  
  23.  // add it to the JCustomizerPane  
  24.  customizerPane.addCustomizer(radioButtonCustomizer, new AbsoluteTableConstraints(300200,  27020, radioButtonCustomizer, itl));  
  25.  // create a JHtmlCustomizer, which supports inline editing of a text  
  26.  JHtmlCustomizer htmlCustomizer = new JHtmlCustomizer();  
  27.  // set some HTML text  
  28.  htmlCustomizer.setHtmlBody("<b>This is an <i>editable</i> HTML</b> text! Double click!<br> " +  
  29.          "<a href=\"http://www.softsmithy.org\">This is a link!</a><br>" +  
  30.          "<font color=\"#FF0000\">And this </font>" +  
  31.          "<font color=\"#00FF00\">is a </font>" +  
  32.          "<font color=\"#00FFFF\">colored text!</font><br><br>" +  
  33.          "This is a very long text that shows automatic line wrapping!");  
  34.  // add it to the JCustomizerPane  
  35.  customizerPane.addCustomizer(htmlCustomizer, new AbsoluteTableConstraints(150250,  270150, htmlCustomizer, itl));  
  36.        

Implementing your own text customizer can be quite easy. Have a look at the source code of JLabelCustomizer for an example. (The source code gets shipped with the library or can be retrieved from the Subversion repository of the SoftSmithy project).

Icon Customizers

The JXIconCustomizer allows visual scaling of icons. (See here for more information about the Extended Icon Framework.) JLine2DCustomizer is specialized JXIconCustomizer to customize a line.

Selection Manager

JCustomizerPropertyTable

Customizer Actions

CustomizerBar

Customize Appearance

Back Home