cleanup
[fedora-idea.git] / platform / platform-api / src / com / intellij / ui / tabs / impl / JBTabsTest.java
blobddf1a0014e19a98f24563cc32786569298ad2459
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.ui.tabs.impl;
18 import com.intellij.openapi.Disposable;
19 import com.intellij.openapi.actionSystem.DefaultActionGroup;
20 import com.intellij.openapi.util.Disposer;
21 import com.intellij.openapi.util.IconLoader;
22 import com.intellij.ui.SimpleTextAttributes;
23 import com.intellij.ui.tabs.JBTabsPosition;
24 import com.intellij.ui.tabs.TabInfo;
25 import com.intellij.ui.tabs.TabsListener;
26 import com.intellij.ui.tabs.UiDecorator;
28 import javax.swing.*;
29 import javax.swing.border.EmptyBorder;
30 import javax.swing.border.LineBorder;
31 import javax.swing.text.html.HTMLEditorKit;
32 import java.awt.*;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.ItemEvent;
36 import java.awt.event.ItemListener;
38 public class JBTabsTest {
39 public static void main(String[] args) {
40 System.out.println("JBTabs.main");
42 IconLoader.activate();
44 final JFrame frame = new JFrame();
45 frame.getContentPane().setLayout(new BorderLayout(0, 0));
46 final int[] count = new int[1];
47 final JBTabsImpl tabs = new JBTabsImpl(null, null, null, Disposer.newDisposable());
48 tabs.setTestMode(true);
51 //final JPanel flow = new JPanel(new FlowLayout(FlowLayout.CENTER));
52 //frame.getContentPane().add(flow);
53 //flow.add(tabs.getComponent());
55 frame.getContentPane().add(tabs.getComponent(), BorderLayout.CENTER);
57 JPanel south = new JPanel(new FlowLayout());
58 south.setOpaque(true);
59 south.setBackground(Color.white);
62 final JComboBox pos = new JComboBox(new Object[]{JBTabsPosition.top, JBTabsPosition.left, JBTabsPosition.right, JBTabsPosition.bottom});
63 pos.setSelectedIndex(0);
64 south.add(pos);
65 pos.addActionListener(new ActionListener() {
66 public void actionPerformed(final ActionEvent e) {
67 final JBTabsPosition p = (JBTabsPosition)pos.getSelectedItem();
68 if (p != null) {
69 tabs.getPresentation().setTabsPosition(p);
72 });
74 final JCheckBox bb = new JCheckBox("Buffered", true);
75 bb.addItemListener(new ItemListener() {
76 public void itemStateChanged(final ItemEvent e) {
77 tabs.setUseBufferedPaint(bb.isSelected());
79 });
80 south.add(bb);
82 final JCheckBox f = new JCheckBox("Focused");
83 f.addItemListener(new ItemListener() {
84 public void itemStateChanged(final ItemEvent e) {
85 tabs.setFocused(f.isSelected());
87 });
88 south.add(f);
91 final JCheckBox v = new JCheckBox("Vertical");
92 v.addItemListener(new ItemListener() {
93 public void itemStateChanged(final ItemEvent e) {
94 tabs.setSideComponentVertical(v.isSelected());
96 });
97 south.add(v);
99 final JCheckBox row = new JCheckBox("Single row", true);
100 row.addItemListener(new ItemListener() {
101 public void itemStateChanged(final ItemEvent e) {
102 tabs.setSingleRow(row.isSelected());
105 south.add(row);
107 final JCheckBox ghosts = new JCheckBox("Ghosts always visible", false);
108 ghosts.addItemListener(new ItemListener() {
109 public void itemStateChanged(final ItemEvent e) {
110 tabs.setGhostsAlwaysVisible(ghosts.isSelected());
113 south.add(ghosts);
115 final JCheckBox stealth = new JCheckBox("Stealth tab", tabs.isStealthTabMode());
116 stealth.addItemListener(new ItemListener() {
117 public void itemStateChanged(final ItemEvent e) {
118 tabs.setStealthTabMode(stealth.isSelected());
121 south.add(stealth);
123 final JCheckBox hide = new JCheckBox("Hide tabs", tabs.isHideTabs());
124 hide.addItemListener(new ItemListener() {
125 public void itemStateChanged(final ItemEvent e) {
126 tabs.setHideTabs(hide.isSelected());
129 south.add(hide);
131 frame.getContentPane().add(south, BorderLayout.SOUTH);
133 tabs.addListener(new TabsListener.Adapter() {
134 public void selectionChanged(final TabInfo oldSelection, final TabInfo newSelection) {
135 System.out.println("TabsWithActions.selectionChanged old=" + oldSelection + " new=" + newSelection);
139 final JTree someTree = new JTree() {
140 public void addNotify() {
141 super.addNotify(); //To change body of overridden methods use File | Settings | File Templates.
142 System.out.println("JBTabs.addNotify");
145 public void removeNotify() {
146 System.out.println("JBTabs.removeNotify");
147 super.removeNotify(); //To change body of overridden methods use File | Settings | File Templates.
150 //someTree.setBorder(new LineBorder(Color.cyan));
151 tabs.addTab(new TabInfo(someTree)).setText("Tree1").setActions(new DefaultActionGroup(), null)
152 .setIcon(IconLoader.getIcon("/debugger/frame.png"));
154 final JTree component = new JTree();
155 final TabInfo toAnimate1 = new TabInfo(component);
156 //toAnimate1.setIcon(IconLoader.getIcon("/debugger/console.png"));
157 final JCheckBox attract1 = new JCheckBox("Attract 1");
158 attract1.addActionListener(new ActionListener() {
159 public void actionPerformed(final ActionEvent e) {
160 //toAnimate1.setText("Should be animated");
162 if (attract1.isSelected()) {
163 toAnimate1.fireAlert();
165 else {
166 toAnimate1.stopAlerting();
170 south.add(attract1);
172 final JCheckBox hide1 = new JCheckBox("Hide 1", toAnimate1.isHidden());
173 hide1.addActionListener(new ActionListener() {
174 public void actionPerformed(final ActionEvent e) {
175 toAnimate1.setHidden(!toAnimate1.isHidden());
178 south.add(hide1);
181 final JCheckBox block = new JCheckBox("Block", false);
182 block.addActionListener(new ActionListener() {
183 public void actionPerformed(final ActionEvent e) {
184 tabs.setPaintBlocked(!block.isSelected(), true);
187 south.add(block);
189 final JCheckBox fill = new JCheckBox("Tab fill in", true);
190 fill.addActionListener(new ActionListener() {
191 public void actionPerformed(final ActionEvent e) {
192 tabs.getPresentation().setActiveTabFillIn(fill.isSelected() ? Color.white : null);
195 south.add(fill);
198 final JButton refire = new JButton("Re-fire attraction");
199 refire.addActionListener(new ActionListener() {
200 public void actionPerformed(final ActionEvent e) {
201 toAnimate1.fireAlert();
205 south.add(refire);
210 final JEditorPane text = new JEditorPane();
211 text.setEditorKit(new HTMLEditorKit());
212 StringBuffer buffer = new StringBuffer();
213 for (int i = 0; i < 50; i ++) {
214 buffer.append("1234567890abcdefghijklmnopqrstv1234567890abcdefghijklmnopqrstv1234567890abcdefghijklmnopqrstv<br>");
216 text.setText(buffer.toString());
218 final JLabel tb = new JLabel("Side comp");
219 tb.setBorder(new LineBorder(Color.red));
220 tabs.addTab(new TabInfo(new JScrollPane(text)).setSideComponent(tb)).setText("Text text text");
221 tabs.addTab(toAnimate1).append("Tree2", new SimpleTextAttributes(SimpleTextAttributes.STYLE_WAVED, Color.black, Color.red));
222 tabs.addTab(new TabInfo(new JTable())).setText("Table 1").setActions(new DefaultActionGroup(), null);
223 tabs.addTab(new TabInfo(new JTable())).setText("Table 2").setActions(new DefaultActionGroup(), null);
224 tabs.addTab(new TabInfo(new JTable())).setText("Table 3").setActions(new DefaultActionGroup(), null);
225 tabs.addTab(new TabInfo(new JTable())).setText("Table 4").setActions(new DefaultActionGroup(), null);
226 tabs.addTab(new TabInfo(new JTable())).setText("Table 5").setActions(new DefaultActionGroup(), null);
227 tabs.addTab(new TabInfo(new JTable())).setText("Table 6").setActions(new DefaultActionGroup(), null);
228 tabs.addTab(new TabInfo(new JTable())).setText("Table 7").setActions(new DefaultActionGroup(), null);
229 tabs.addTab(new TabInfo(new JTable())).setText("Table 8").setActions(new DefaultActionGroup(), null);
230 tabs.addTab(new TabInfo(new JTable())).setText("Table 9").setActions(new DefaultActionGroup(), null);
232 //tabs.getComponent().setBorder(new EmptyBorder(5, 5, 5, 5));
233 tabs.setTabSidePaintBorder(5);
234 tabs.setPaintBorder(1, 1, 1, 1);
236 tabs.getPresentation().setActiveTabFillIn(Color.white);
237 tabs.setGhostsAlwaysVisible(true);
239 //tabs.setBorder(new LineBorder(Color.blue, 5));
240 tabs.setBorder(new EmptyBorder(30, 30, 30, 30));
242 tabs.setUiDecorator(new UiDecorator() {
243 public UiDecoration getDecoration() {
244 return new UiDecoration(null, new Insets(0, -1, 0, -1));
249 tabs.setStealthTabMode(true);
251 frame.setBounds(1400, 200, 1000, 800);
252 frame.show();