file level inspection ui
[fedora-idea.git] / platform / platform-impl / src / com / intellij / openapi / fileEditor / impl / FileEditorInfoPane.java
blob759ad4fa40b0fb21cb599b574bcb833c6089c6e5
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.
17 package com.intellij.openapi.fileEditor.impl;
19 import javax.swing.*;
20 import java.awt.*;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.util.ArrayList;
25 /**
26 * @author max
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);
52 updateButtons();
54 });
56 myNextButton.addActionListener(new ActionListener() {
57 public void actionPerformed(ActionEvent e) {
58 layout.next(myCards);
59 updateButtons();
61 });
63 add(myButtonsPanel, BorderLayout.EAST);
64 myButtonsPanel.setVisible(false);
65 setVisible(false);
68 public void addInfo(JComponent component) {
69 myComponents.add(component);
70 myCards.add(component, String.valueOf(myCounter++));
71 updateButtons();
72 validate();
75 public void removeInfo(JComponent component) {
76 myComponents.remove(component);
77 myCards.remove(component);
78 updateButtons();
79 validate();
82 private int getCurrentCard() {
83 for (int i = 0; i < myComponents.size(); i++) {
84 if (myComponents.get(i).isVisible()) return i;
86 return -1;
89 private void updateButtons() {
90 int count = myComponents.size();
91 if (count > 0) {
92 setVisible(true);
93 if (count == 1) {
94 myButtonsPanel.setVisible(false);
96 else {
97 myButtonsPanel.setVisible(true);
98 int currentCard = getCurrentCard();
99 myNextButton.setEnabled(currentCard + 1 < count);
100 myPrevButton.setEnabled(currentCard - 1 >= 0);
103 else {
104 setVisible(false);