FIGURE 12-6 OrgChartTreeCellRenderer in Java

Generate QR Code ISO/IEC18004 in Java FIGURE 12-6 OrgChartTreeCellRenderer
FIGURE 12-6 OrgChartTreeCellRenderer
Make Denso QR Bar Code In Java
Using Barcode printer for Java Control to generate, create Quick Response Code image in Java applications.
Attributes as Pointers 397
Bar Code Creation In Java
Using Barcode encoder for Java Control to generate, create barcode image in Java applications.
nent that will either display just the name of the person to which the node corresponds, or a name and title inside a box:
Read Barcode In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
public class OrgChartTreeCellRenderer extends JPanel implements TreeCellRenderer { /** * Default constructor */ public OrgChartTreeCellRenderer() { // Icon, and under that a TreeCell setLayout( new BoxLayout(this,BoxLayoutX_AXIS) ); _icon = new JLabel() { public void setBackground( Color color ) { if( color instanceof ColorUIResource ) { color = null; } supersetBackground( color ); } }; add( _icon ); add( BoxcreateHorizontalStrut(4) ); add( _cell = new TreeCell() ); }
QR Printer In Visual C#
Using Barcode creator for .NET Control to generate, create Denso QR Bar Code image in VS .NET applications.
A TreeCellRenderer is required to provide only one public method getTreeCellRendererComponent to produce a component to display for a particular node In this case the code for the method is completely standard except for setting a tooltip for the node based on information in the user object of the node:
QR-Code Generator In VS .NET
Using Barcode generation for ASP.NET Control to generate, create QR Code image in ASP.NET applications.
/** * TreeCellRenderer interface implementation */ public Component getTreeCellRendererComponent( JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) { setEnabled( treeisEnabled() ); _cellsetValue( value ); _cellsetSelected( isSelected ); _cellsetFocus( hasFocus ); if ( leaf ) {
QR Code JIS X 0510 Creator In .NET Framework
Using Barcode creator for Visual Studio .NET Control to generate, create QR Code image in .NET applications.
398 Modeling Relationships
Quick Response Code Creation In Visual Basic .NET
Using Barcode creation for .NET Control to generate, create Denso QR Bar Code image in VS .NET applications.
_iconsetIcon(UIManagergetIcon("TreeleafIcon")); } else if ( expanded ) { _iconsetIcon(UIManagergetIcon("TreeopenIcon")); } else { _iconsetIcon(UIManagergetIcon("TreeclosedIcon")); } DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; Hashtable info = (Hashtable)nodegetUserObject(); setToolTipText( (String)infoget( "dn" ) ); return this; }
Draw Code 128C In Java
Using Barcode printer for Java Control to generate, create Code 128 Code Set C image in Java applications.
The renderer must also override JLabelgetPreferredSize, or the manager boxes will be truncated on the right:
Encoding Bar Code In Java
Using Barcode creator for Java Control to generate, create barcode image in Java applications.
/** * Calculate the size required as the sum of the icon and * the TreeCell * * @return the combined size of the icon and TreeCell */ public Dimension getPreferredSize() { Dimension iconD = _icongetPreferredSize(); Dimension cellD = _cellgetPreferredSize(); int height = Mathmax( iconDheight, cellDheight ); return new Dimension(iconDwidth + cellDwidth, height); }
Create Barcode In Java
Using Barcode maker for Java Control to generate, create bar code image in Java applications.
The TreeCell class (Figure 12-7) is responsible for rendering all text, as well as a box if the node corresponds to a manager:
Create Barcode In Java
Using Barcode maker for Java Control to generate, create bar code image in Java applications.
/** * Panel containing name and title */ class TreeCell extends JPanel { TreeCell() { setLayout( new BoxLayout( this, BoxLayoutY_AXIS ) ); setOpaque(true); }
EAN 128 Creation In Java
Using Barcode maker for Java Control to generate, create EAN 128 image in Java applications.
The main overridden method in TreeCell is setValue Information is pulled from the user object of the node to set the name and title The title is rendered in italics The member variable _lines keeps track of how many lines of text have been ren-
Monarch Creation In Java
Using Barcode maker for Java Control to generate, create Monarch image in Java applications.
Attributes as Pointers 399
Paint EAN 128 In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create GTIN - 128 image in ASP.NET applications.
TreeCell (from OrgChartTreeCellRenderer) _lines : int = 0 TreeCell() setBackground(color : Color) : void setPreferredSize(d : Dimension) : void getPreferredSize() : Dimension setValue(o : Object) : void setSelected(isSelected : boolean) : void setFocus(hasFocus : boolean) : void
Recognizing Code 128 In VS .NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET applications.
FIGURE 12-7 TreeCell
Data Matrix 2d Barcode Reader In .NET Framework
Using Barcode reader for .NET framework Control to read, scan read, scan image in VS .NET applications.
dered It is used to determine the size of the node and later to decide if a box is required around the text:
UPCA Creator In VS .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create UCC - 12 image in .NET framework applications.
/** * Set the text contents and fonts based on info in the * user object of the tree node * * @param o a tree node with a Hashtable as UserObject */ public void setValue(Object o) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)o; Hashtable info = (Hashtable)nodegetUserObject(); int maxWidth = 0; int height = 0; _lines = 0; removeAll(); JLabel label = new JLabel( (String)infoget( "name" ) ); add( label ); Dimension dim = labelgetPreferredSize(); height += dimheight; if (maxWidth < dimwidth) { maxWidth = dimwidth; } _lines++; // Check if this is a container node if ( nodegetChildCount() > 0 ) {
Bar Code Printer In Visual Studio .NET
Using Barcode generator for .NET framework Control to generate, create barcode image in .NET applications.
400 Modeling Relationships
Generating Bar Code In VB.NET
Using Barcode creator for Visual Studio .NET Control to generate, create barcode image in VS .NET applications.
label = new JLabel( (String)infoget( "title" ) ); add( label ); dim = labelgetPreferredSize(); height += dimheight; if (maxWidth < dimwidth) { maxWidth = dimwidth; } // Same font but italics for title Font font = labelgetFont(); font = new Font( fontgetName(), fontITALIC, fontgetSize() ); labelsetFont( font ); _lines++; } int margin = (_lines > 1) 2 : 0; setPreferredSize( new Dimension(maxWidth + 6 + 2*margin, height + 2*margin)); }
Generate Barcode In VS .NET
Using Barcode creator for ASP.NET Control to generate, create barcode image in ASP.NET applications.
TreeCellsetFocus is called by OrgChartTreeCellRenderergetTreeCellRendererComponent If the node corre-
sponds to a manager node (more than one line of text), it always applies a black border If not, it uses the standard border color if the node has focus and no border if it doesn t:
/** * Set the appropriate visuals for if the item has focus * or not * * @param hasFocus true if the item has * focus */ protected void setFocus( boolean hasFocus ) { int lineWidth = 1; // Put a black border around the cell if it contains // more than one line (ie, it contains a title) if ( _lines > 1 ) { setBorder(BorderFactorycreateLineBorder( Colorblack, lineWidth)); } else { if ( hasFocus ) { Color lineColor = UIManagergetColor(