annotate java/src/uk/ac/qmul/eecs/ccmi/checkboxtree/CheckBoxTreeCellRenderer.java @ 8:ea7885bd9bff tip

fixed bug : render solid line as dotted/dashed when moving the stylus from dotted/dashed to solid
author ccmi-guest
date Thu, 03 Jul 2014 16:12:20 +0100
parents 9e67171477bc
children
rev   line source
fiore@3 1 /*
fiore@3 2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
fiore@3 3
fiore@3 4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
fiore@3 5
fiore@3 6 This program is free software: you can redistribute it and/or modify
fiore@3 7 it under the terms of the GNU General Public License as published by
fiore@3 8 the Free Software Foundation, either version 3 of the License, or
fiore@3 9 (at your option) any later version.
fiore@3 10
fiore@3 11 This program is distributed in the hope that it will be useful,
fiore@3 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
fiore@3 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fiore@3 14 GNU General Public License for more details.
fiore@3 15
fiore@3 16 You should have received a copy of the GNU General Public License
fiore@3 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
fiore@3 18 */
fiore@3 19 package uk.ac.qmul.eecs.ccmi.checkboxtree;
fiore@3 20
fiore@3 21 import java.awt.Component;
fiore@3 22
fiore@3 23 import javax.swing.BorderFactory;
fiore@3 24 import javax.swing.JCheckBox;
fiore@3 25 import javax.swing.JTree;
fiore@3 26 import javax.swing.tree.DefaultTreeCellRenderer;
fiore@3 27
fiore@3 28
fiore@3 29 /**
fiore@3 30 * A tree cell renderer which renders {@code CheckBoxTreeNode} objects like a {@code JCheckBox}:
fiore@3 31 * thick box (showing whether the node is selected or not) followed by a label (same label it would
fiore@3 32 * appear with a default {@code DefaultTreeCellRenderer}.
fiore@3 33 *
fiore@3 34 */
fiore@3 35 @SuppressWarnings("serial")
fiore@3 36 public class CheckBoxTreeCellRenderer extends DefaultTreeCellRenderer {
fiore@3 37
fiore@3 38 public CheckBoxTreeCellRenderer(){
fiore@3 39 checkBox = new JCheckBox();
fiore@3 40 checkBox.setBorder(BorderFactory.createLineBorder(this.getBorderSelectionColor()));
fiore@3 41 }
fiore@3 42 /**
fiore@3 43 * Returns the {@code Component} that the renderer uses to draw the value
fiore@3 44 *
fiore@3 45 * @throws ClassCastException if {@code value} is not an instance of {@code CheckoxTreeNode}
fiore@3 46 * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(JTree, Object, boolean, boolean, boolean, int, boolean)
fiore@3 47 * @return the {@code Component} that the renderer uses to draw the value
fiore@3 48 */
fiore@3 49 @Override
fiore@3 50 public Component getTreeCellRendererComponent(JTree tree,
fiore@3 51 Object value,
fiore@3 52 boolean selected,
fiore@3 53 boolean expanded,
fiore@3 54 boolean leaf,
fiore@3 55 int row,
fiore@3 56 boolean hasFocus){
fiore@3 57
fiore@3 58 CheckBoxTreeNode treeNode = (CheckBoxTreeNode)value;
fiore@3 59 if(!treeNode.isSelectable())
fiore@3 60 return super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
fiore@3 61
fiore@3 62 checkBox.setSelected(treeNode.isSelected());
fiore@3 63 checkBox.setText(value.toString());
fiore@3 64 if(selected){
fiore@3 65 checkBox.setBackground(getBackgroundSelectionColor());
fiore@3 66 checkBox.setBorderPainted(true);
fiore@3 67 }else{
fiore@3 68 checkBox.setBackground(getBackgroundNonSelectionColor());
fiore@3 69 checkBox.setBorderPainted(false);
fiore@3 70 }
fiore@3 71 return checkBox;
fiore@3 72 }
fiore@3 73
fiore@3 74 private JCheckBox checkBox;
fiore@3 75 }