i have a problem in using the infonode docking library. I have created the root window,dynamic view methods based on the example provided. Just modified it bit and just trying to use it. But I had gone through the documentations,user manuls provided by infonode. But coludnt find a way to add dynamic view to the rootwindow.
Here is an sampple code:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import javax.sound.sampled.ReverbType;
import javax.swing.*;
import net.infonode.docking.*;
import net.infonode.docking.drag.DockingWindowDragSource;
import net.infonode.docking.drag.DockingWindowDragger;
import net.infonode.docking.drag.DockingWindowDraggerProvider;
import net.infonode.docking.util.DockingUtil;
import net.infonode.docking.util.MixedViewHandler;
import net.infonode.docking.util.ViewMap;
public class DockTrial extends JFrame
{
JMenuBar menuBar;
JMenu fileMenu;
JMenuItem fMI;
int counter=0;
CustomRootWindow cRootWin;
private static final int ICON_SIZE = 8;
/**
* Contains the dynamic views that has been added to the root window
*/
private HashMap dynamicViews = new HashMap();
/**
* The one and only root window
*/
private RootWindow rootWindow;
/**
* Contains all the static views
*/
private ViewMap viewMap = new ViewMap();
/**
* An array of the static views
*/
private View[] views = new View[3];
/**
* A dynamically created view containing an id.
*/
private static class DynamicView extends View {
private int id;
/**
* Constructor.
*
* @param title the view title
* @param icon the view icon
* @param component the view component
* @param id the view id
*/
DynamicView(String title, Icon icon, Component component, int id) {
super(title, icon, component);
this.id = id;
}
/**
* Returns the view id.
*
* @return the view id
*/
public int getId() {
return id;
}
}
public DockTrial()
{
setSize(500,500);
setTitle("Docktrial");
setVisible(true);
setLayout(new BorderLayout());
add(menuBarr());
setJMenuBar(menuBar);
createComponents();
assignfunctions();
add(createToolBar(),BorderLayout.BEFORE_FIRST_LINE);
getContentPane().add(rootWindow, BorderLayout.CENTER);
}
public void createComponents()
{
// Create the views
for (int i = 0; i < views.length; i++) {
views[i] = new View("View " + i, VIEW_ICON, createViewComponent("View " + i));
viewMap.addView(i, views[i]);
}
// The mixed view map makes it easy to mix static and dynamic views inside the same root window
MixedViewHandler handler = new MixedViewHandler(viewMap, new ViewSerializer() {
public void writeView(View view, ObjectOutputStream out) throws IOException {
out.writeInt(((DynamicView) view).getId());
}
public View readView(ObjectInputStream in) throws IOException {
return getDynamicView(in.readInt());
}
});
rootWindow = DockingUtil.createRootWindow(viewMap, handler, true);
}
public void assignfunctions()
{
fMI.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
/* FloatingWindow fw = rootWindow.createFloatingWindow(new Point(50, 50),
new Dimension(300, 200),
getDynamicView(getDynamicViewId()));
// Show the window
fw.getTopLevelAncestor().setVisible(true);
fw.isDockable();*/
/*getDynamicView(getDynamicViewId()).dock();
rootWindow.revalidate();*/
}
});
}
/**
* Creates the frame tool bar.
*
* @return the frame tool bar
*/
private JToolBar createToolBar() {
JToolBar toolBar = new JToolBar();
JLabel label = new JLabel("Drag New View");
toolBar.add(label);
new DockingWindowDragSource(label, new DockingWindowDraggerProvider() {
public DockingWindowDragger getDragger(MouseEvent mouseEvent) {
return getDynamicView(getDynamicViewId()).startDrag(rootWindow);
}
});
return toolBar;
}
/**
* Returns a dynamic view with specified id, reusing an existing view if possible.
*
* @param id the dynamic view id
* @return the dynamic view
*/
private View getDynamicView(int id) {
View view = (View) dynamicViews.get(new Integer(id));
if (view == null)
view = new DynamicView("Dynamic View " + id, VIEW_ICON, createViewComponent("Dynamic View " + id), id);
return view;
}
/**
* Returns the next available dynamic view id.
*
* @return the next available dynamic view id
*/
private int getDynamicViewId() {
int id = 0;
while (dynamicViews.containsKey(new Integer(id)))
id++;
return id;
}
/**
* Returns a dynamic view with specified id, reusing an existing view if possible.
*
* @param id the dynamic view id
* @return the dynamic view
*/
private View getDynamicView(int id ,String t) {
View view = (View) dynamicViews.get(new Integer(id));
if (view == null)
view = new DynamicView("Dynamic View " + id + t, VIEW_ICON, createViewComponent("Dynamic View " + id), id);
return view;
}
/**
* Creates a view component containing the specified text.
*
* @param text the text
* @return the view component
*/
private static JComponent createViewComponent(String text) {
StringBuffer sb = new StringBuffer();
for (int j = 0; j < 100; j++)
sb.append(text + ". This is line " + j + "\n");
return new JScrollPane(new JTextArea(sb.toString()));
}
/**
* Custom view icon.
*/
private static final Icon VIEW_ICON = new Icon() {
public int getIconHeight() {
return ICON_SIZE;
}
public int getIconWidth() {
return ICON_SIZE;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
Color oldColor = g.getColor();
g.setColor(new Color(70, 70, 70));
g.fillRect(x, y, ICON_SIZE, ICON_SIZE);
g.setColor(new Color(100, 230, 100));
g.fillRect(x + 1, y + 1, ICON_SIZE - 2, ICON_SIZE - 2);
g.setColor(oldColor);
}
};
public JMenuBar menuBarr()
{
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
fMI = new JMenuItem("New Tab");
fileMenu.add(fMI);
menuBar.add(fileMenu);
return menuBar;
}
public static void main(String[] args)
{
new DockTrial();
}
}
I am evaluating this framework too. The answer is using DockingUtil.addwindow. Here is the sample.
public TestFrame() {
super("Test Dock");
rw = new RootWindow(null);
JMenu mu = new JMenu("File");
JMenuItem mi = new JMenuItem("Add Dock");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
View vw = new View("Dock", null, new JLabel("test"));
DockingUtil.addWindow(vw, rw);
}
});
JMenuBar mb = new JMenuBar();
mu.add(mi);
mb.add(mu);
this.setJMenuBar(mb);
this.setLayout(new BorderLayout());
this.add(rw);
}