1 package com
.intellij
.ui
.tabs
.impl
;
3 import com
.intellij
.openapi
.Disposable
;
4 import com
.intellij
.openapi
.actionSystem
.DefaultActionGroup
;
5 import com
.intellij
.openapi
.util
.IconLoader
;
6 import com
.intellij
.ui
.SimpleTextAttributes
;
7 import com
.intellij
.ui
.tabs
.JBTabsPosition
;
8 import com
.intellij
.ui
.tabs
.TabInfo
;
9 import com
.intellij
.ui
.tabs
.TabsListener
;
10 import com
.intellij
.ui
.tabs
.UiDecorator
;
13 import javax
.swing
.border
.EmptyBorder
;
14 import javax
.swing
.border
.LineBorder
;
15 import javax
.swing
.text
.html
.HTMLEditorKit
;
17 import java
.awt
.event
.ActionEvent
;
18 import java
.awt
.event
.ActionListener
;
19 import java
.awt
.event
.ItemEvent
;
20 import java
.awt
.event
.ItemListener
;
22 public class JBTabsTest
{
23 public static void main(String
[] args
) {
24 System
.out
.println("JBTabs.main");
26 IconLoader
.activate();
28 final JFrame frame
= new JFrame();
29 frame
.getContentPane().setLayout(new BorderLayout(0, 0));
30 final int[] count
= new int[1];
31 final JBTabsImpl tabs
= new JBTabsImpl(null, null, null, new Disposable() {
32 public void dispose() {
35 tabs
.setTestMode(true);
38 //final JPanel flow = new JPanel(new FlowLayout(FlowLayout.CENTER));
39 //frame.getContentPane().add(flow);
40 //flow.add(tabs.getComponent());
42 frame
.getContentPane().add(tabs
.getComponent(), BorderLayout
.CENTER
);
44 JPanel south
= new JPanel(new FlowLayout());
45 south
.setOpaque(true);
46 south
.setBackground(Color
.white
);
49 final JComboBox pos
= new JComboBox(new Object
[]{JBTabsPosition
.top
, JBTabsPosition
.left
, JBTabsPosition
.right
, JBTabsPosition
.bottom
});
50 pos
.setSelectedIndex(0);
52 pos
.addActionListener(new ActionListener() {
53 public void actionPerformed(final ActionEvent e
) {
54 final JBTabsPosition p
= (JBTabsPosition
)pos
.getSelectedItem();
56 tabs
.getPresentation().setTabsPosition(p
);
61 final JCheckBox bb
= new JCheckBox("Buffered", true);
62 bb
.addItemListener(new ItemListener() {
63 public void itemStateChanged(final ItemEvent e
) {
64 tabs
.setUseBufferedPaint(bb
.isSelected());
69 final JCheckBox f
= new JCheckBox("Focused");
70 f
.addItemListener(new ItemListener() {
71 public void itemStateChanged(final ItemEvent e
) {
72 tabs
.setFocused(f
.isSelected());
78 final JCheckBox v
= new JCheckBox("Vertical");
79 v
.addItemListener(new ItemListener() {
80 public void itemStateChanged(final ItemEvent e
) {
81 tabs
.setSideComponentVertical(v
.isSelected());
86 final JCheckBox row
= new JCheckBox("Single row", true);
87 row
.addItemListener(new ItemListener() {
88 public void itemStateChanged(final ItemEvent e
) {
89 tabs
.setSingleRow(row
.isSelected());
94 final JCheckBox ghosts
= new JCheckBox("Ghosts always visible", false);
95 ghosts
.addItemListener(new ItemListener() {
96 public void itemStateChanged(final ItemEvent e
) {
97 tabs
.setGhostsAlwaysVisible(ghosts
.isSelected());
102 final JCheckBox stealth
= new JCheckBox("Stealth tab", tabs
.isStealthTabMode());
103 stealth
.addItemListener(new ItemListener() {
104 public void itemStateChanged(final ItemEvent e
) {
105 tabs
.setStealthTabMode(stealth
.isSelected());
110 final JCheckBox hide
= new JCheckBox("Hide tabs", tabs
.isHideTabs());
111 hide
.addItemListener(new ItemListener() {
112 public void itemStateChanged(final ItemEvent e
) {
113 tabs
.setHideTabs(hide
.isSelected());
118 frame
.getContentPane().add(south
, BorderLayout
.SOUTH
);
120 tabs
.addListener(new TabsListener
.Adapter() {
121 public void selectionChanged(final TabInfo oldSelection
, final TabInfo newSelection
) {
122 System
.out
.println("TabsWithActions.selectionChanged old=" + oldSelection
+ " new=" + newSelection
);
126 final JTree someTree
= new JTree() {
127 public void addNotify() {
128 super.addNotify(); //To change body of overridden methods use File | Settings | File Templates.
129 System
.out
.println("JBTabs.addNotify");
132 public void removeNotify() {
133 System
.out
.println("JBTabs.removeNotify");
134 super.removeNotify(); //To change body of overridden methods use File | Settings | File Templates.
137 //someTree.setBorder(new LineBorder(Color.cyan));
138 tabs
.addTab(new TabInfo(someTree
)).setText("Tree1").setActions(new DefaultActionGroup(), null)
139 .setIcon(IconLoader
.getIcon("/debugger/frame.png"));
141 final JTree component
= new JTree();
142 final TabInfo toAnimate1
= new TabInfo(component
);
143 //toAnimate1.setIcon(IconLoader.getIcon("/debugger/console.png"));
144 final JCheckBox attract1
= new JCheckBox("Attract 1");
145 attract1
.addActionListener(new ActionListener() {
146 public void actionPerformed(final ActionEvent e
) {
147 //toAnimate1.setText("Should be animated");
149 if (attract1
.isSelected()) {
150 toAnimate1
.fireAlert();
153 toAnimate1
.stopAlerting();
159 final JCheckBox hide1
= new JCheckBox("Hide 1", toAnimate1
.isHidden());
160 hide1
.addActionListener(new ActionListener() {
161 public void actionPerformed(final ActionEvent e
) {
162 toAnimate1
.setHidden(!toAnimate1
.isHidden());
168 final JCheckBox block
= new JCheckBox("Block", false);
169 block
.addActionListener(new ActionListener() {
170 public void actionPerformed(final ActionEvent e
) {
171 tabs
.setPaintBlocked(!block
.isSelected(), true);
176 final JCheckBox fill
= new JCheckBox("Tab fill in", true);
177 fill
.addActionListener(new ActionListener() {
178 public void actionPerformed(final ActionEvent e
) {
179 tabs
.getPresentation().setActiveTabFillIn(fill
.isSelected() ? Color
.white
: null);
185 final JButton refire
= new JButton("Re-fire attraction");
186 refire
.addActionListener(new ActionListener() {
187 public void actionPerformed(final ActionEvent e
) {
188 toAnimate1
.fireAlert();
197 final JEditorPane text
= new JEditorPane();
198 text
.setEditorKit(new HTMLEditorKit());
199 StringBuffer buffer
= new StringBuffer();
200 for (int i
= 0; i
< 50; i
++) {
201 buffer
.append("1234567890abcdefghijklmnopqrstv1234567890abcdefghijklmnopqrstv1234567890abcdefghijklmnopqrstv<br>");
203 text
.setText(buffer
.toString());
205 final JLabel tb
= new JLabel("Side comp");
206 tb
.setBorder(new LineBorder(Color
.red
));
207 tabs
.addTab(new TabInfo(new JScrollPane(text
)).setSideComponent(tb
)).setText("Text text text");
208 tabs
.addTab(toAnimate1
).append("Tree2", new SimpleTextAttributes(SimpleTextAttributes
.STYLE_WAVED
, Color
.black
, Color
.red
));
209 tabs
.addTab(new TabInfo(new JTable())).setText("Table 1").setActions(new DefaultActionGroup(), null);
210 tabs
.addTab(new TabInfo(new JTable())).setText("Table 2").setActions(new DefaultActionGroup(), null);
211 tabs
.addTab(new TabInfo(new JTable())).setText("Table 3").setActions(new DefaultActionGroup(), null);
212 tabs
.addTab(new TabInfo(new JTable())).setText("Table 4").setActions(new DefaultActionGroup(), null);
213 tabs
.addTab(new TabInfo(new JTable())).setText("Table 5").setActions(new DefaultActionGroup(), null);
214 tabs
.addTab(new TabInfo(new JTable())).setText("Table 6").setActions(new DefaultActionGroup(), null);
215 tabs
.addTab(new TabInfo(new JTable())).setText("Table 7").setActions(new DefaultActionGroup(), null);
216 tabs
.addTab(new TabInfo(new JTable())).setText("Table 8").setActions(new DefaultActionGroup(), null);
217 tabs
.addTab(new TabInfo(new JTable())).setText("Table 9").setActions(new DefaultActionGroup(), null);
219 //tabs.getComponent().setBorder(new EmptyBorder(5, 5, 5, 5));
220 tabs
.setTabSidePaintBorder(5);
221 tabs
.setPaintBorder(1, 1, 1, 1);
223 tabs
.getPresentation().setActiveTabFillIn(Color
.white
);
224 tabs
.setGhostsAlwaysVisible(true);
226 //tabs.setBorder(new LineBorder(Color.blue, 5));
227 tabs
.setBorder(new EmptyBorder(30, 30, 30, 30));
229 tabs
.setUiDecorator(new UiDecorator() {
230 public UiDecoration
getDecoration() {
231 return new UiDecoration(null, new Insets(0, -1, 0, -1));
236 tabs
.setStealthTabMode(true);
238 frame
.setBounds(1400, 200, 1000, 800);