View Javadoc

1   /**
2    * Copyright (C) 2008 Atlassian
3    * 
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
7    * 
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    * 
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.
15   */
16  
17  package com.atlassian.theplugin.idea.ui.tree.comment;
18  
19  import com.atlassian.theplugin.idea.ui.tree.AtlassianClickAction;
20  import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode;
21  import com.atlassian.theplugin.idea.crucible.ReviewData;
22  import com.intellij.ui.SimpleColoredComponent;
23  import com.intellij.ui.SimpleTextAttributes;
24  import com.jgoodies.forms.layout.CellConstraints;
25  import com.jgoodies.forms.layout.FormLayout;
26  
27  import javax.swing.*;
28  import javax.swing.tree.TreeCellRenderer;
29  import java.awt.*;
30  
31  /**
32   * Created by IntelliJ IDEA.
33   * User: lguminski
34   * Date: Jul 21, 2008
35   * Time: 3:57:40 PM
36   * To change this template use File | Settings | File Templates.
37   */
38  public class GeneralSectionNode extends AtlassianTreeNode {
39  	private static final String GENERAL_COMMENTS_SECTION = "General comments";
40  
41  	private static final TreeCellRenderer MY_RENDERER = new MyRenderer();
42  	private ReviewData review;
43  
44  	public GeneralSectionNode(ReviewData review, AtlassianClickAction action) {
45  		super(action);
46  		this.review = review;
47  	}
48  
49  	public GeneralSectionNode(GeneralSectionNode node) {
50  		super(node.getAtlassianClickAction());
51  		this.review = node.review;
52  	}
53  
54  	@Override
55      public TreeCellRenderer getTreeCellRenderer() {
56  		return MY_RENDERER;
57  	}
58  
59  	public ReviewData getReview() {
60  		return review;
61  	}
62  
63  	public AtlassianTreeNode getClone() {
64  		return new GeneralSectionNode(this);
65  	}
66  
67  	private static class MyRenderer implements TreeCellRenderer {
68  		public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded,
69                  boolean leaf, int row, boolean hasFocus) {
70  			GeneralSectionNode node = (GeneralSectionNode) value;
71  			JPanel panel = new JPanel(new FormLayout("4dlu, left:pref:grow, 4dlu", "4dlu, pref:grow, 4dlu"));
72  			SimpleColoredComponent component = new SimpleColoredComponent();
73  			component.append(GENERAL_COMMENTS_SECTION, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
74  			panel.add(component, new CellConstraints(2, 2));
75  
76  			panel.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder")
77  					: BorderFactory.createEmptyBorder(1, 1, 1, 1));
78  
79  			return panel;
80  		}
81  	}
82  }