f531af01596d76b63f02c13f6f8551ea55ecb0d3
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.
17 package com
.intellij
.openapi
.fileEditor
.impl
;
19 import com
.intellij
.ui
.IdeBorderFactory
;
23 import java
.awt
.event
.ActionEvent
;
24 import java
.awt
.event
.ActionListener
;
25 import java
.util
.ArrayList
;
30 public class FileEditorInfoPane
extends JPanel
{
31 private int myCounter
= 0;
32 private final JPanel myCards
;
33 private final JButton myPrevButton
;
34 private final JButton myNextButton
;
35 private final java
.util
.List
<JComponent
> myComponents
;
36 private final JPanel myButtonsPanel
;
38 public FileEditorInfoPane() {
39 super(new BorderLayout());
40 final CardLayout layout
= new CardLayout();
41 myCards
= new JPanel(layout
);
42 myComponents
= new ArrayList
<JComponent
>();
43 add(myCards
, BorderLayout
.CENTER
);
44 myPrevButton
= new JButton("<");
45 myNextButton
= new JButton(">");
47 myButtonsPanel
= new JPanel(new GridLayout(1, 2));
48 myButtonsPanel
.add(myPrevButton
);
49 myButtonsPanel
.add(myNextButton
);
51 myPrevButton
.addActionListener(new ActionListener() {
52 public void actionPerformed(ActionEvent e
) {
53 layout
.previous(myCards
);
58 myNextButton
.addActionListener(new ActionListener() {
59 public void actionPerformed(ActionEvent e
) {
64 setBorder(IdeBorderFactory
.createBorder());
66 add(myButtonsPanel
, BorderLayout
.EAST
);
67 myButtonsPanel
.setVisible(false);
71 public void addInfo(JComponent component
) {
72 myComponents
.add(component
);
73 myCards
.add(component
, String
.valueOf(myCounter
++));
78 public void removeInfo(JComponent component
) {
79 myComponents
.remove(component
);
80 myCards
.remove(component
);
85 private int getCurrentCard() {
86 for (int i
= 0; i
< myComponents
.size(); i
++) {
87 if (myComponents
.get(i
).isVisible()) return i
;
92 private void updateButtons() {
93 int count
= myComponents
.size();
97 myButtonsPanel
.setVisible(false);
100 myButtonsPanel
.setVisible(true);
101 int currentCard
= getCurrentCard();
102 myNextButton
.setEnabled(currentCard
+ 1 < count
);
103 myPrevButton
.setEnabled(currentCard
- 1 >= 0);