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
;
23 import javax
.swing
.table
.TableCellRenderer
;
25 import java
.awt
.event
.MouseAdapter
;
26 import java
.awt
.event
.MouseEvent
;
27 import java
.util
.Collection
;
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() {
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
) {
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
).
74 showUnderneathOf(myMoreLabel
);
77 public void setTags(Collection
<String
> tags
) {
79 myMoreLabel
.setVisible(myTags
.size() > 1);
80 if (myTags
.size() > 0)
81 myTextLabel
.setText(myTags
.iterator().next());
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());
91 final Collection
<String
> tags
= (Collection
<String
>) value
;
96 public void setSelected(boolean isSelected
, JTable table
){
98 setBackground(table
.getSelectionBackground());
99 setForeground(table
.getSelectionForeground());
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
) {
111 label
.setBackground(table
.getSelectionBackground());
112 label
.setForeground(table
.getSelectionForeground());
114 label
.setBackground(table
.getBackground());
115 label
.setForeground(table
.getForeground());