if (mode == SPLIT) {
if (firstSplitBorder == null) {
firstSplitBorder = createSplitBorder(c, name);
if (tabPane != null) { // there is alrady one tab pane
removeAll();
tabSplit = new JSplitPane(orientation, tabPane, firstSplitBorder);
elements.add(index, createElement(c, name, tabSplit,firstSplitBorder));
add(tabSplit);
} else { // we dont need a split yet
elements.add(index, createElement(c, name, firstSplitBorder,firstSplitBorder));
add(firstSplitBorder);
}
} else {
// there is split area, add this panel to it
Element p=getElement(firstSplitBorder.comp);
if (p.owner == p.border) {
// first split to be created
removeAll();
SplitBorder sb=createSplitBorder(c, name);
JSplitPane sp= new JSplitPane(orientation, p.border, sb);
p.owner = sp;
elements.add(index, createElement(c, name, sp,sb));
add(sp);
}
else{
JSplitPane prev=(JSplitPane)p.owner;
while(prev.getRightComponent() instanceof JSplitPane){
// go to latest split
prev=(JSplitPane)prev.getRightComponent();
}
SplitBorder right=(SplitBorder)prev.getRightComponent();
p=getElement(right.comp);
if(p.owner!=prev){ // cross check
throw new RuntimeException(
"SplitTabPane unexpected state : invalid owner "+p.comp+" "+p.owner);
}
SplitBorder sb=createSplitBorder(c, name);
JSplitPane split = new JSplitPane(orientation, right,
sb);
p.owner = split;
elements.add(index, createElement(c, name, split,sb));
prev.setRightComponent(split);
}
}
} else if(mode==TAB) {
if (tabPane == null) {
tabPane = new JTabbedPane(
orientation == JSplitPane.HORIZONTAL_SPLIT ? JTabbedPane.LEFT
: JTabbedPane.TOP);
tabPane.addMouseListener(this);
if (firstSplitBorder == null) {
// we dont need a split yet
removeAll();
add(tabPane);
} else {
removeAll();
Element e=getElement(firstSplitBorder.comp);
tabSplit = new JSplitPane(orientation, tabPane, e.owner);
if(e.owner == e.border){
e.owner=tabSplit;
}
add(tabSplit);
}