Overview

ls://dev.artenum.com/projects/ArtTk/overview

ArtTk is a Java/Swing based library offering an extensive toolkit for scientific and technical applications. ArtTk provides a set of widgets and functional modules like:
  • A set of helper classes allowing a dynamical definition of menu and toolbar from a simple XML-based descriptor, supporting text contents, tooltips, icons, action commands, etc…
  • A versatile and extensible multi-desktop component;
  • An extended Grid layout to simplify the development of advanced scientific applications;
  • A set of scientific and technical widgets like:
    • A dynamical memory footprint monitor;
    • Simple key-values based fields editors;
    • A versatile color gradient editor
ArtTk has been made as light as possible in order to provide an efficient and simple solution for scientific and technical applications. ArtTk is used in several open-source and commercial projects like:
  • SPIS
  • Keridwen
  • Cassandra
  • BMGTools
  • Color gradient examples

In the example above, the color gradient at the top is directly read from the XML file below:

<?xml version="1.0" encoding="UTF-8"?>
<Gradient startColor="#ff00ff" endColor="#ff0000" nbColors="50">
    <Color position="10" code="#0000ff" />
    <Color position="20" code="#00ffff" />
    <Color position="30" code="#00ff00" />
    <Color position="40" code="#ffff00" />
</Gradient>

GridBagPanel layout examples

A GridBagPanel is a JPanel that implements methods facilitating the use of Swing GridBagLayout.

A HBox is a panel containing horizontally aligned components :

GridBagPanel panel = new GridBagPanel.Builder("HBox").build(PanelType.HBOX);
panel.addComponent(label1);
panel.addComponent(button1);
panel.addComponent(button2);


A VBox is a panel containing vertically aligned components :

GridBagPanel panel = new GridBagPanel.Builder("VBox").build(PanelType.VBOX);
panel.addComponent(label1);
panel.addComponent(button1);
panel.addComponent(button2);


A Grid is a panel containing components placed in a grid.

There are several ways to create a grid. The basic grid displayed at the top of the figure below could be built either by explicitly defining the component positions on the grid:

GridBagPanel grid1 = new GridBagPanel.Builder("Grid 1").build(PanelType.GRID);

// First line grid1.position(0, 0).addComponent(label1); grid1.position(1, 0).addComponent(textField1); grid1.position(2, 0).addComponent(button1); // Second line grid1.position(0, 1).addComponent(label2); grid1.position(1, 1).addComponent(textField2); grid1.position(2, 1).addComponent(button2);

or by implicit construction (line by line):

GridBagPanel grid1 = new GridBagPanel.Builder("Grid 1").build(PanelType.GRID);

// First line grid1.addComponent(label1); grid1.addComponent(textField1); grid1.addComponent(button1).newLine();

// Second line grid1.addComponent(label2); grid1.addComponent(textField2); grid1.addComponent(button2);

Of course, you can mix HBox , VBox and Grid components to obtain complex layouts:

Logger example

Properties editor example

Multi-desktop example

The Java source file

public class GeneralSample {
    public static void main(String[] args) throws Exception {
        // Frame initialisation

JPanel toolBar = new JPanel(); toolBar.setLayout(new BoxLayout(toolBar, BoxLayout.PAGE_AXIS)); JFrame f = new JFrame("Test loader"); f.getContentPane().setLayout(new BorderLayout()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(BorderLayout.NORTH, toolBar);

// Sample of GUILoader usage

GUILoader loader = new GUILoader(); loader.addActionListener(new PrintActionListener()); loader.load(GUILoader.class.getResource("/com/artenum/sample/Sample.xml").openStream());

// Add builded components in UI

f.setJMenuBar((JMenuBar) loader.getBuildedObject("menuBar")); JToolBar bar = (JToolBar) loader.getBuildedObject("toolBar1"); bar.setAlignmentX(JPanel.LEFT_ALIGNMENT); toolBar.add(bar); bar = ((JToolBar) loader.getBuildedObject("toolBar2")); bar.setAlignmentX(JPanel.LEFT_ALIGNMENT); toolBar.add(bar);

// Sample of desktop manager

DesktopManager desktopManager = new DesktopManager(); desktopManager.addDesktop("Bureau 1"); desktopManager.addDesktop("Bureau 2"); desktopManager.addDesktop("Bureau 3");

// Add internal frame in multi-desktop

JInternalFrame internalFrame = desktopManager.createMultiDesktopInternalFrame("Tutu", true, true, true, true); internalFrame.getContentPane().add(new JLabel("Hello tutu")); internalFrame.reshape(10, 10, 100, 100); internalFrame.setVisible(true); desktopManager.getCurrentDesktop().add(internalFrame);

internalFrame = desktopManager.createMultiDesktopInternalFrame("Tata", true, true, true, true); internalFrame.getContentPane().add(new JLabel("Hello tata")); internalFrame.reshape(110, 10, 100, 100); internalFrame.setVisible(true); desktopManager.getDesktop(1).add(internalFrame);

internalFrame = desktopManager.createMultiDesktopInternalFrame("Toto", true, true, true, true); internalFrame.getContentPane().add(new JLabel("Hello toto")); internalFrame.reshape(210, 10, 100, 100); internalFrame.setVisible(true); desktopManager.getDesktop("Bureau 3").add(internalFrame); f.getContentPane().add(BorderLayout.CENTER, desktopManager);

// Finish the frame initialisation

f.setSize(700, 500); f.setLocationRelativeTo(null); f.setVisible(true); } }

The Xml file

<?xml version="1.0" ?>
<GuiLoader>
	<MenuBar className="javax.swing.JMenuBar" resultKeyName="menuBar" >
		<Menu className="javax.swing.JMenu" txtContent="File">
			<Item className="javax.swing.JMenuItem" actionCommand="aa" txtContent="a"/>
			<Item className="javax.swing.JMenuItem" actionCommand="bb" txtContent="b"/>
			<Item className="javax.swing.JMenuItem" actionCommand="cc" txtContent="c"/>			
		</Menu>
		<Menu className="javax.swing.JMenu" txtContent="Edit">
			<Menu className="javax.swing.JMenu" txtContent="File">
				<Item className="javax.swing.JMenuItem" actionCommand="aa" txtContent="a"/>
				<Separation/>
				<Item className="javax.swing.JMenuItem" actionCommand="bb" txtContent="b"/>
				<Item className="javax.swing.JMenuItem" actionCommand="cc" txtContent="c"/>			
			</Menu>
		</Menu>			
		<Menu className="javax.swing.JMenu" txtContent="View"/>			
	</MenuBar>
	<ToolBar className="javax.swing.JToolBar" resultKeyName="toolBar1" >
		<Button className="javax.swing.JButton" actionCommand="add1 command" txtContent="a add1"/>
		<Button className="javax.swing.JButton" actionCommand="add2 command" txtContent="a add2"/>
		<Button className="javax.swing.JButton" actionCommand="add3 command" txtContent="a add3"/>				
	</ToolBar>
	<ToolBar className="javax.swing.JToolBar" resultKeyName="toolBar2" >
		<Button className="javax.swing.JButton" actionCommand="add1 command" txtContent="b add1"/>
		<Button className="javax.swing.JButton" actionCommand="add2 command" txtContent="b add2"/>
		<Button className="javax.swing.JButton" actionCommand="add3 command" txtContent="b add3"/>
		<Button className="javax.swing.JButton" actionCommand="FIXME" iconPath="/com/artenum/sample/conflict.gif" toolTip="Hello tooltip"/>
	</ToolBar>
</GuiLoader>


Last edited by Benoît Thiébault at Mar 5, 2010 7:53 AM - Edit content - View source


Decorated version - Feeds - LibreSource