update copyright
[fedora-idea.git] / plugins / cvs / cvs-plugin / src / com / intellij / cvsSupport2 / cvsoperations / cvsTagOrBranch / ui / TagsPanel.java
blob58e83d013a231eda09679a82c6b6dcc1646c4bd2
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.cvsSupport2.cvsoperations.cvsTagOrBranch.ui;
18 import com.intellij.openapi.diagnostic.Logger;
19 import com.intellij.openapi.ui.popup.PopupChooserBuilder;
20 import org.jetbrains.annotations.NonNls;
22 import javax.swing.*;
23 import javax.swing.table.TableCellRenderer;
24 import java.awt.*;
25 import java.awt.event.MouseAdapter;
26 import java.awt.event.MouseEvent;
27 import java.util.Collection;
29 /**
30 * author: lesya
33 public class TagsPanel extends JPanel implements TableCellRenderer{
35 private static final Logger LOG = Logger.getInstance("#com.intellij.cvsSupport2.cvsoperations.cvsTagOrBranch.ui.TagsPanel");
37 private final JLabel myTextLabel = new JLabel();
39 private final JLabel myMoreLabel = new JLabel(MORE_LABEL_TEXT){
40 private final Cursor myCursor = new Cursor(Cursor.HAND_CURSOR);
41 public Cursor getCursor() {
42 return myCursor;
46 private Collection<String> myTags;
47 private final JList myList = new JList();
48 @NonNls private static final String MORE_LABEL_TEXT = "<html><b>(...)</b></html>";
49 private final String myPopupTitle;
51 public TagsPanel(final String popupTitle) {
52 super(new BorderLayout());
53 add(myTextLabel, BorderLayout.CENTER);
54 add(myMoreLabel, BorderLayout.EAST);
56 myMoreLabel.addMouseListener(new MouseAdapter() {
57 public void mouseClicked(MouseEvent e) {
58 showTags();
60 });
61 myPopupTitle = popupTitle;
64 private void showTags() {
65 DefaultListModel model = new DefaultListModel();
66 myList.setModel(model);
67 for (final String myTag : myTags) {
68 model.addElement(myTag);
71 new PopupChooserBuilder(myList).
72 setTitle(myPopupTitle).
73 createPopup().
74 showUnderneathOf(myMoreLabel);
77 public void setTags(Collection<String> tags) {
78 myTags = tags;
79 myMoreLabel.setVisible(myTags.size() > 1);
80 if (myTags.size() > 0)
81 myTextLabel.setText(myTags.iterator().next());
82 revalidate();
85 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
86 setSelected(isSelected, table);
87 if (!(value instanceof Collection)) {
88 LOG.info("getTableCellRendererComponent: " + value == null ? null : value.toString());
89 return this;
91 final Collection<String> tags = (Collection<String>) value;
92 setTags(tags);
93 return this;
96 public void setSelected(boolean isSelected, JTable table){
97 if (isSelected) {
98 setBackground(table.getSelectionBackground());
99 setForeground(table.getSelectionForeground());
100 } else {
101 setBackground(table.getBackground());
102 setForeground(table.getForeground());
105 updateLabel(myTextLabel, isSelected, table);
106 updateLabel(myMoreLabel, isSelected, table);
109 private static void updateLabel(JLabel label, boolean isSelected, JTable table) {
110 if (isSelected) {
111 label.setBackground(table.getSelectionBackground());
112 label.setForeground(table.getSelectionForeground());
113 } else {
114 label.setBackground(table.getBackground());
115 label.setForeground(table.getForeground());