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
.ide
.util
.newProjectWizard
;
18 import com
.intellij
.ui
.CheckboxTree
;
19 import com
.intellij
.ui
.CheckedTreeNode
;
20 import com
.intellij
.util
.ui
.tree
.TreeUtil
;
23 import javax
.swing
.tree
.TreePath
;
25 import java
.awt
.event
.MouseEvent
;
26 import java
.util
.List
;
31 public class FrameworksTree
extends CheckboxTree
{
32 private boolean myProcessingMouseEventOnCheckbox
;
34 public FrameworksTree(List
<List
<FrameworkSupportNode
>> groups
) {
35 super(new FrameworksTreeRenderer(), new FrameworksRootNode(groups
), new CheckPolicy(false, true, true, false));
36 setRootVisible(false);
37 setShowsRootHandles(false);
38 TreeUtil
.expandAll(this);
42 protected void processMouseEvent(MouseEvent e
) {
43 final TreePath path
= getPathForLocation(e
.getX(), e
.getY());
45 final Object node
= path
.getLastPathComponent();
46 if (node
instanceof FrameworkSupportNode
) {
47 final Rectangle checkboxBounds
= ((CheckboxTreeCellRendererBase
)getCellRenderer()).myCheckbox
.getBounds();
48 final Rectangle pathBounds
= getPathBounds(path
);
49 checkboxBounds
.setLocation(pathBounds
.getLocation());
50 if (checkboxBounds
.contains(e
.getPoint())) {
52 myProcessingMouseEventOnCheckbox
= true;
53 super.processMouseEvent(e
);
56 myProcessingMouseEventOnCheckbox
= false;
63 super.processMouseEvent(e
);
66 public boolean isProcessingMouseEventOnCheckbox() {
67 return myProcessingMouseEventOnCheckbox
;
70 private static class FrameworksTreeRenderer
extends CheckboxTreeCellRenderer
{
71 private FrameworksTreeRenderer() {
76 public void customizeRenderer(JTree tree
, Object value
, boolean selected
, boolean expanded
, boolean leaf
, int row
, boolean hasFocus
) {
77 if (value
instanceof FrameworkSupportNode
) {
78 final FrameworkSupportNode node
= (FrameworkSupportNode
)value
;
79 getTextRenderer().append(node
.getTitle());
80 getTextRenderer().setIcon(node
.getProvider().getIcon());
85 private static class FrameworksRootNode
extends CheckedTreeNode
{
86 public FrameworksRootNode(List
<List
<FrameworkSupportNode
>> groups
) {
88 for (List
<FrameworkSupportNode
> group
: groups
) {
89 for (FrameworkSupportNode node
: group
) {