001: package org.enhydra.jawe.base.panel.panels;
002:
003: import java.awt.Component;
004: import java.util.List;
005:
006: import javax.swing.JTabbedPane;
007: import javax.swing.SwingConstants;
008:
009: import org.enhydra.jawe.base.panel.PanelContainer;
010: import org.enhydra.shark.xpdl.XMLCollection;
011: import org.enhydra.shark.xpdl.XMLElement;
012:
013: /**
014: * Creates a tabbed panel.
015: * @author Sasa Bojanic
016: */
017: public class XMLTabbedPanel extends XMLBasicPanel {
018: private JTabbedPane tabbed;
019:
020: public XMLTabbedPanel(PanelContainer pc, XMLElement myOwnerL,
021: List panels, String title, boolean showTitle) {
022: super (pc, myOwnerL, title, true, showTitle && title != null
023: && !title.equals(""), true);
024:
025: tabbed = new JTabbedPane(SwingConstants.TOP);
026: //tabbed.setLayout(new BoxLayout(this.tabbed,BoxLayout.Y_AXIS));
027: //tabbed.setLayout(new GridLayout(1,1));
028: tabbed.setAlignmentX(Component.LEFT_ALIGNMENT);
029: tabbed.setAlignmentY(Component.TOP_ALIGNMENT);
030:
031: for (int i = 0; i < panels.size(); i++) {
032: XMLPanel pnl = (XMLPanel) panels.get(i);
033: if (pnl == null)
034: continue;
035: if (pnl.getTitle() != null && !pnl.getTitle().equals("")) {
036: String t = pnl.getTitle();
037: if (pnl.getOwner() instanceof XMLCollection) {
038: t = pc.getSettings().getLanguageDependentString(
039: pnl.getOwner().toName() + "Key");
040: }
041: tabbed.addTab(t, pnl);
042: } else {
043: String t = pnl.getTitle();
044: if (pnl.getOwner() instanceof XMLCollection) {
045: t = pc.getSettings().getLanguageDependentString(
046: pnl.getOwner().toName() + "Key");
047: } else {
048: t = pc.getLabelGenerator().getLabel(pnl.getOwner());
049: }
050: tabbed.addTab(t, pnl);
051: }
052: }
053: if (tabbed.getTabCount() > 0) {
054: tabbed.setSelectedIndex(0); //Harald Meister
055: }
056: //tabbed.setPreferredSize(tabbed.getMinimumSize());
057: //elementPanel.setPreferredSize(elementPanel.getMinimumSize())
058: add(tabbed);
059: }
060:
061: public int getTabCount() {
062: return tabbed.getTabCount();
063: }
064:
065: public XMLPanel getTabbedPanel(int no) {
066: if (no >= tabbed.getTabCount()) {
067: return null;
068: }
069: return (XMLPanel) tabbed.getComponentAt(no);
070: }
071:
072: public int getActiveTab() {
073: return tabbed.getSelectedIndex();
074: }
075:
076: public XMLPanel getSelectedTabPanel() {
077: return (XMLPanel) tabbed.getComponentAt(getSelectedTab());
078: }
079:
080: public void setActiveTab(int tab) {
081: tabbed.setSelectedIndex(tab);
082: }
083:
084: public boolean validateEntry() {
085: boolean isOK = true;
086: for (int i = 0; i < tabbed.getComponentCount(); i++) {
087: Component c = tabbed.getComponent(i);
088: if (c instanceof XMLPanel) {
089: isOK = isOK && ((XMLPanel) c).validateEntry();
090: }
091: }
092: return isOK;
093: }
094:
095: public void setElements() {
096: if (!getOwner().isReadOnly()) {
097: for (int i = 0; i < tabbed.getComponentCount(); i++) {
098: Component c = tabbed.getComponent(i);
099: if (c instanceof XMLPanel) {
100: ((XMLPanel) c).setElements();
101: }
102: }
103: }
104: }
105:
106: public XMLPanel getPanelForElement(XMLElement el) {
107: for (int i = 0; i < tabbed.getComponentCount(); i++) {
108: Component c = tabbed.getComponent(i);
109: if (c instanceof XMLPanel) {
110: XMLPanel p = (XMLPanel) c;
111: if (p instanceof XMLGroupPanel) {
112: p = ((XMLGroupPanel) p).getPanelForElement(el);
113: if (p != null) {
114: return p;
115: }
116: } else if (p.getOwner() == el) {
117: return p;
118: }
119: }
120: }
121: return null;
122: }
123:
124: public int getSelectedTab() {
125: return tabbed.getSelectedIndex();
126: }
127:
128: public void setSelectedTab(int selIndex) {
129: tabbed.setSelectedIndex(selIndex);
130: }
131:
132: public void cleanup() {
133: for (int i = 0; i < tabbed.getComponentCount(); i++) {
134: Component c = tabbed.getComponent(i);
135: if (c instanceof XMLPanel) {
136: ((XMLPanel) c).cleanup();
137: }
138: }
139: }
140:
141: }
|