1 30 31 package com.jgoodies.looks.demo; 32 33 import java.awt.BorderLayout ; 34 import java.awt.Dimension ; 35 36 import javax.swing.*; 37 import javax.swing.border.EmptyBorder ; 38 import javax.swing.tree.DefaultMutableTreeNode ; 39 import javax.swing.tree.DefaultTreeModel ; 40 import javax.swing.tree.TreeModel ; 41 42 import com.jgoodies.forms.factories.Borders; 43 import com.jgoodies.looks.Options; 44 import com.jgoodies.uif_lite.component.Factory; 45 import com.jgoodies.uif_lite.panel.SimpleInternalFrame; 46 47 54 final class TabTestTab { 55 56 59 JComponent build() { 60 JPanel panel = new JPanel(new BorderLayout ()); 61 panel.setBorder(Borders.DIALOG_BORDER); 62 panel.add(buildHorizontalSplit()); 63 return panel; 64 } 65 66 67 75 private JComponent buildHorizontalSplit() { 76 return Factory.createStrippedSplitPane( 77 JSplitPane.HORIZONTAL_SPLIT, 78 buildMainLeftPanel(), 79 buildMainRightPanel(), 80 0.2f); 81 } 82 83 84 88 private JComponent buildMainLeftPanel() { 89 JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.BOTTOM); 90 tabbedPane.putClientProperty(Options.EMBEDDED_TABS_KEY, Boolean.TRUE); 91 tabbedPane.addTab("Tree", Factory.createStrippedScrollPane(buildTree())); 92 tabbedPane.addTab("Help", Factory.createStrippedScrollPane(buildHelp())); 93 94 SimpleInternalFrame sif = new SimpleInternalFrame("Embedded Tabs"); 95 sif.setPreferredSize(new Dimension (150, 100)); 96 sif.add(tabbedPane); 97 return sif; 98 } 99 100 101 104 private JTree buildTree() { 105 JTree tree = new JTree(createSampleTreeModel()); 106 tree.putClientProperty(Options.TREE_LINE_STYLE_KEY, 107 Options.TREE_LINE_STYLE_NONE_VALUE); 108 tree.expandRow(3); 109 tree.expandRow(2); 110 tree.expandRow(1); 111 return tree; 112 } 113 114 115 private JComponent buildHelp() { 116 JTextArea area = new JTextArea("\n This tabbed pane uses\n embedded tabs."); 117 return area; 118 } 119 120 121 124 private JComponent buildMainRightPanel() { 125 JTabbedPane tabbedPane = new JTabbedPane(); 126 tabbedPane.putClientProperty(Options.NO_CONTENT_BORDER_KEY, Boolean.TRUE); 127 tabbedPane.addTab("Top", buildSplittedTabs(JTabbedPane.TOP)); 128 tabbedPane.addTab("Bottom", buildSplittedTabs(JTabbedPane.BOTTOM)); 129 tabbedPane.addTab("Left", buildSplittedTabs(JTabbedPane.LEFT)); 130 tabbedPane.addTab("Right", buildSplittedTabs(JTabbedPane.RIGHT)); 131 132 SimpleInternalFrame sif = new SimpleInternalFrame("Tabbed Pane without Content Border"); 133 sif.setPreferredSize(new Dimension (300, 100)); 134 sif.add(tabbedPane); 135 return sif; 136 } 137 138 139 150 private JComponent buildSplittedTabs(int tabPlacement) { 151 int orientation = (tabPlacement == JTabbedPane.TOP 152 || tabPlacement == JTabbedPane.BOTTOM) 153 ? JSplitPane.HORIZONTAL_SPLIT 154 : JSplitPane.VERTICAL_SPLIT; 155 JComponent split = Factory.createStrippedSplitPane( 156 orientation, 157 buildTabPanel(tabPlacement, JTabbedPane.WRAP_TAB_LAYOUT), 158 buildTabPanel(tabPlacement, JTabbedPane.SCROLL_TAB_LAYOUT), 159 0.5f); 160 JPanel panel = new JPanel(new BorderLayout ()); 161 panel.add(split, BorderLayout.CENTER); 162 panel.setBorder(new EmptyBorder (20, 20, 20, 20)); 163 return panel; 164 } 165 166 167 176 private JComponent buildTabPanel(int tabPlacement, int tabLayoutPolicy) { 177 JTabbedPane tabbedPane = new JTabbedPane(tabPlacement, tabLayoutPolicy); 178 String [] colors = { 179 "Black", "White", "Red", "Green", "Blue", "Yellow" }; 180 for (int i = 0; i < colors.length; i++) { 181 String color = colors[i]; 182 tabbedPane.addTab(color, new JPanel(null)); 183 } 184 return tabbedPane; 185 } 186 187 188 191 private TreeModel createSampleTreeModel() { 192 DefaultMutableTreeNode root = new DefaultMutableTreeNode ("Musicians"); 193 DefaultMutableTreeNode parent; 194 195 parent = new DefaultMutableTreeNode ("Drums"); 197 root.add(parent); 198 parent.add(new DefaultMutableTreeNode ("Elvin Jones")); 199 parent.add(new DefaultMutableTreeNode ("Jack DeJohnette")); 200 parent.add(new DefaultMutableTreeNode ("Rashied Ali")); 201 202 parent = new DefaultMutableTreeNode ("Piano"); 204 root.add(parent); 205 parent.add(new DefaultMutableTreeNode ("McCoy Tyner")); 206 parent.add(new DefaultMutableTreeNode ("Sun Ra")); 207 208 parent = new DefaultMutableTreeNode ("Saxophon"); 209 root.add(parent); 210 parent.add(new DefaultMutableTreeNode ("Albert Ayler")); 211 parent.add(new DefaultMutableTreeNode ("Archie Shepp")); 212 parent.add(new DefaultMutableTreeNode ("Charlie Parker")); 213 parent.add(new DefaultMutableTreeNode ("John Coltrane")); 214 parent.add(new DefaultMutableTreeNode ("Ornette Coleman")); 215 parent.add(new DefaultMutableTreeNode ("Pharoa Sanders")); 216 parent.add(new DefaultMutableTreeNode ("Sonny Rollins")); 217 218 return new DefaultTreeModel (root); 219 } 220 221 222 } | Popular Tags |