The IlvManager class inherits from the IlvGraphic class; as a consequence, a manager
and a grapher can be added to another manager or grapher just like
any other graphic object. To add a manager to a manager, you use
the addObject method of the
IlvManager
class.
Example: Adding a nested manager
The following code shows a simple nested
manager.
import ilog.views.*; import ilog.views.graphic.*; import javax.swing.*; import java.awt.*; public class SubManagerExample { public static void main(String[] args) { IlvGraphic obj; IlvManager toplevel = new IlvManager(); IlvManager subManager = new IlvManager(); obj = new IlvRectangle(new IlvRect(10,10,50,50), false, true); subManager.addObject(obj, false); obj = new IlvRectangle(new IlvRect(100,100,50,50), false, true); subManager.addObject(obj, false); toplevel.addObject(subManager, false); obj = new IlvRectangle(new IlvRect(10,200,50,50), false, true); toplevel.addObject(obj, false); final IlvManagerView view = new IlvManagerView(toplevel); view.setBackground(Color.blue); SwingUtilities.invokeLater( new Runnable() { public void run() { JFrame frame = new JFrame("Sub manager Example"); frame.getContentPane().add(view); frame.setSize(200,200); frame.setVisible(true); } }); }
This simple example creates two
IlvManager
objects, the top-level manager (variable
toplevel
) that will be displayed in the view and the submanager (variable
subManager
). The submanager is added to the top-level manager by the line:
toplevel.addObject(subManager, false);
Two rectangles are also added to the
submanager. Another rectangle is added at the top level.
The following figure shows the resulting
application.
![subgraph2.gif](../../JViews_Framework/usradvfwork/_media/subgraph2_default.gif)
Submanager example
The white area is the submanager
containing two rectangles.
Note
Adding a manager to a manager can be done
to an infinite level. The library will just make sure that you
do not create cycles in the hierarchy of nested managers.