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;
18  
19  import com.atlassian.theplugin.idea.ui.tree.AtlassianTree;
20  import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeModel;
21  
22  import javax.swing.tree.TreeCellRenderer;
23  import javax.swing.tree.TreePath;
24  import java.awt.event.ComponentAdapter;
25  import java.awt.event.ComponentEvent;
26  
27  /**
28   * Created by IntelliJ IDEA.
29   * User: lguminski
30   * Date: Jul 16, 2008
31   * Time: 10:39:31 PM
32   * To change this template use File | Settings | File Templates.
33   */
34  public class CommentTree extends AtlassianTree {
35  
36  	public CommentTree(AtlassianTreeModel model) {
37  		super(model);
38  		putClientProperty("JTree.lineStyle", "None");
39  		setShowsRootHandles(false);
40  		setRootVisible(false);
41  		setRowHeight(0);
42  	}
43  
44  	public CommentTree() {
45  		super();
46  	}
47  
48  	@Override
49  	protected void setExpandedState(final TreePath path, final boolean state) {
50  		if (state) {
51  			super.setExpandedState(path, state);
52  		}
53  	}
54  
55  	public void initializeUI() {
56  		registerUI();
57  		addComponentListener(new ComponentAdapter() {
58  			@Override
59  			public void componentResized(ComponentEvent e) {
60  				if (CommentTree.this.isVisible()) {
61  					registerUI();
62  				}
63  			}
64  		});
65  	}
66  
67  	private void registerUI() {
68  		CommentTree.this.setUI(new MyTreeUI());
69  	}
70  
71  	private class MyTreeUI extends BasicWideNodeTreeUI {
72  		@Override
73  		protected TreeCellRenderer createDefaultCellRenderer() {
74  			return DISPATCHING_RENDERER;
75  		}
76  	}
77  
78  
79  }