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
;
21 import java
.awt
.event
.ActionEvent
;
22 import java
.awt
.event
.ActionListener
;
23 import java
.util
.ArrayList
;
28 public class FileEditorInfoPane
extends JPanel
{
29 private int myCounter
= 0;
30 private final JPanel myCards
;
31 private final JButton myPrevButton
;
32 private final JButton myNextButton
;
33 private final java
.util
.List
<JComponent
> myComponents
;
34 private final JPanel myButtonsPanel
;
36 public FileEditorInfoPane() {
37 super(new BorderLayout());
38 final CardLayout layout
= new CardLayout();
39 myCards
= new JPanel(layout
);
40 myComponents
= new ArrayList
<JComponent
>();
41 add(myCards
, BorderLayout
.CENTER
);
42 myPrevButton
= new JButton("<");
43 myNextButton
= new JButton(">");
45 myButtonsPanel
= new JPanel(new GridLayout(1, 2));
46 myButtonsPanel
.add(myPrevButton
);
47 myButtonsPanel
.add(myNextButton
);
49 myPrevButton
.addActionListener(new ActionListener() {
50 public void actionPerformed(ActionEvent e
) {
51 layout
.previous(myCards
);
56 myNextButton
.addActionListener(new ActionListener() {
57 public void actionPerformed(ActionEvent e
) {
63 add(myButtonsPanel
, BorderLayout
.EAST
);
64 myButtonsPanel
.setVisible(false);
68 public void addInfo(JComponent component
) {
69 myComponents
.add(component
);
70 myCards
.add(component
, String
.valueOf(myCounter
++));
75 public void removeInfo(JComponent component
) {
76 myComponents
.remove(component
);
77 myCards
.remove(component
);
82 private int getCurrentCard() {
83 for (int i
= 0; i
< myComponents
.size(); i
++) {
84 if (myComponents
.get(i
).isVisible()) return i
;
89 private void updateButtons() {
90 int count
= myComponents
.size();
94 myButtonsPanel
.setVisible(false);
97 myButtonsPanel
.setVisible(true);
98 int currentCard
= getCurrentCard();
99 myNextButton
.setEnabled(currentCard
+ 1 < count
);
100 myPrevButton
.setEnabled(currentCard
- 1 >= 0);