📄 orgchartpanel.java
字号:
{
info.put(FONTSIZE, new Integer(curFont.getSize()));
}
}
/**
* Creates the contents of a cell containing the info related to the node.
*
* @param node Subject node.
*
* @return The generated panel.
*/
private JPanel createNameAndPhotoLabel(final DefaultMutableTreeNode node)
{
_logger.debug("createNameAndPhotoLabel");
Hashtable info = (Hashtable) node.getUserObject();
boolean isPhoto = (info.get(PHOTO) != null);
JPanel res = new JPanel(new BorderLayout(0, 0));
res.setOpaque(false);
JPanel centerPanel = new JPanel();
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.BOTH;
c.gridy = 0;
c.gridy = 0;
c.gridx = 0;
c.weighty = 0.0;
c.weightx = 1.0;
GridBagLayout gridbag = new GridBagLayout();
centerPanel.setLayout(gridbag);
Integer alevel = (Integer) info.get(LEVEL);
if ((crits != null) && (levelAttribs != null) &&
(alevel.intValue() > crits.length))
{
alevel = new Integer(levelAttribs.size() - 1);
}
List alist = null;
if (levelAttribs != null)
{
alist = (List) levelAttribs.get(alevel);
}
_logger.debug("name " + info.get(NAME) + " level " + alevel);
Iterator iter;
if (alist != null)
{
iter = alist.iterator();
}
else
{
iter = attribs.iterator();
}
while (iter.hasNext())
{
String attyp = (String) iter.next();
if (!attyp.equals(PHOTO))
{
String atVal = null;
if (attyp.equals("displayname"))
{
atVal = (String) info.get(NAME);
}
else
{
atVal = (String) info.get(attyp);
}
if (atVal != null)
{
JLabel label = new JLabel(atVal);
label.setBackground(Color.blue);
setFont(label, titleFont, getMaxWidth(), info, isPhoto);
label.setForeground(textColor);
label.setHorizontalAlignment(JLabel.CENTER);
addAttrib(centerPanel, gridbag, c, label);
}
}
}
centerPanel.setOpaque(false);
// PHOTO
try
{
byte[] photo = (byte[]) info.get(PHOTO);
//DW/2615/BeginPatch
ImageIcon image = null;
if (photo != null)
{
//ImageIcon image = new ImageIcon(photo);
image = new ImageIcon(photo);
}
else if (defaultPhoto != null)
{
image = new ImageIcon(defaultPhoto);
}
if (image != null)
{
//DW/2615/EndPatch
Image im = image.getImage();
Image newIm = im.getScaledInstance(-1, PHOTO_SZ, Image.SCALE_FAST);
image = new ImageIcon(newIm);
if (image != null)
{
JLabel photoLab = new JLabel(image);
photoLab.setBorder(new EmptyBorder(0, 0, 0, 2));
res.add(photoLab, BorderLayout.WEST);
}
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
res.add(centerPanel, BorderLayout.CENTER);
return res;
}
/**
* Creates a cell related to a node.
*
* @param node Subject node.
*
* @return The created panel.
*/
private JPanel createPP(final DefaultMutableTreeNode node)
{
_logger.debug("createPP");
int state = 0;
Hashtable info = (Hashtable) node.getUserObject();
XJButton p1 = new XJButton(node, this);
if (isRoot(node))
{
baseCell = p1;
}
p1.setLayout(new BorderLayout());
Color aColor = cellColor;
JPanel gars1 = createNameAndPhotoLabel(node);
p1.add(gars1);
p1.setBackground(aColor);
p1.setMargin(new Insets(0, 0, 0, 0));
JPanel pp1 = new JPanel();
pp1.setLayout(new BorderLayout());
pp1.add(p1, BorderLayout.CENTER);
int w = getMaxWidth();
Integer hlevel = (Integer) info.get(LEVEL);
if ((crits != null) && (levelAttribs != null) &&
(hlevel.intValue() > crits.length))
{
hlevel = new Integer(levelAttribs.size() - 1);
}
int h = getMaxHeight(hlevel);
p1.setMinimumSize(new Dimension(w, h));
p1.setPreferredSize(new Dimension(w, h));
pp1.setMaximumSize(new Dimension(w, h));
return pp1;
}
/**
* Creates a panel surrounding a cell and its children (horizontal
* or vertical kinds of orgchart, large mode).
*
* @param node The top cell of the panel.
* @param hasChild Children presence flag.
* @param type Kind of required OrgLine.
* @param horiza Should be the panel containing the cell and brothers
* for the first child, else null.
* @param horizb should be the panel containing the cell and brothers
* for the last child, else null.
*
* @return Created panel.
*/
private JPanel createVert(final DefaultMutableTreeNode node,
final boolean hasChild, final short type, final XJPanel horiza,
final XJPanel horizb)
{
_logger.debug("createVert");
JPanel vert11 = new JPanel();
if (getDirection() == HORIZONTAL)
{
vert11.setLayout(new BoxLayout(vert11, BoxLayout.Y_AXIS));
}
else
{
vert11.setLayout(new BoxLayout(vert11, BoxLayout.X_AXIS));
}
JPanel pp11 = createPP(node);
if (type != NONE)
{
if (getDirection() == HORIZONTAL)
{
pp11.add(new OrgLine(type, backGround), BorderLayout.NORTH);
}
else
{
vert11.add(new OrgLine(type, backGround));
}
}
vert11.add(pp11);
if (hasChild)
{
if (getNbChildExpanded(node) > 1)
{
vert11.add(new OrgLine(HORIZONTAL_LEFT, backGround));
}
else
{
vert11.add(new OrgLine(backGround));
}
}
else
{
if (getDirection() == HORIZONTAL)
{
vert11.add(Box.createVerticalGlue());
}
else
{
vert11.add(Box.createHorizontalGlue());
}
}
if (horiza != null)
{
horiza.setP1(pp11);
}
if (horizb != null)
{
horizb.setP2(pp11);
}
vert11.setBackground(backGround);
return vert11;
}
/**
* Recomputes the position of all lines in the horizontal panels.
*/
private void recalcule()
{
_logger.debug("recalcule");
for (int i = 0; i < horizList.size(); i++)
{
XJPanel horiz = (XJPanel) (horizList.get(i));
horiz.recalcule();
}
}
/**
* Gets number of children of a node.
*
* @param node Node.
*
* @return Number of children.
*/
public final int getNbChildExpanded(final DefaultMutableTreeNode node)
{
return node.getChildCount();
}
/**
* Tests whether node is root node.
*
* @param node Node.
*
* @return True if the node is the root node, else false.
*/
public final boolean isRoot(final DefaultMutableTreeNode node)
{
_logger.debug("isRoot");
return (node == getRoot());
}
/**
* Creates a panel containing all children of a cell (horizontal
* or vertical kinds of orgchart, large mode).
*
* @param node Father node.
*
* @return The created panel.
*/
private JPanel processChildren(final DefaultMutableTreeNode node)
{
_logger.debug("processChildren");
int nbChildren = getNbChildExpanded(node);
if (nbChildren == 1)
{
JPanel horizc = new JPanel();
if (getDirection() == HORIZONTAL)
{
horizc.setLayout(new BoxLayout(horizc, BoxLayout.X_AXIS));
}
else
{
horizc.setLayout(new BoxLayout(horizc, BoxLayout.Y_AXIS));
}
DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(0);
boolean hasChild = (getNbChildExpanded(child) == 0) ? false : true;
JPanel vertc = createVert(child, hasChild, NONE, null, null);
if (hasChild)
{
JPanel pchild = processChildren(child);
vertc.add(pchild);
}
horizc.add(vertc);
horizc.setBackground(backGround);
return horizc;
}
else
{
// assume != 0
XJPanel horizc = new XJPanel();
if (getDirection() == HORIZONTAL)
{
horizc.setLayout(new BoxLayout(horizc, BoxLayout.X_AXIS));
}
else
{
horizc.setLayout(new BoxLayout(horizc, BoxLayout.Y_AXIS));
}
DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(0);
boolean hasChild = (getNbChildExpanded(child) == 0) ? false : true;
JPanel vertc1 = createVert(child, hasChild, HORIZONTAL_LEFT,
horizc, null);
horizc.setV1(vertc1);
if (hasChild)
{
JPanel pchild = processChildren(child);
vertc1.add(pchild);
}
horizc.add(vertc1);
if (getDirection() == HORIZONTAL)
{
horizc.add(Box.createHorizontalStrut(SPACEV));
}
else
{
horizc.add(Box.createVerticalStrut(SPACEV));
}
horizc.setBackground(backGround);
for (int i = 1; i < (nbChildren - 1); i++)
{
DefaultMutableTreeNode childi = (DefaultMutableTreeNode) node.getChildAt(i);
hasChild = (getNbChildExpanded(childi) == 0) ? false : true;
JPanel vertci = createVert(childi, hasChild, HORIZONTAL_CENTER,
null, null);
if (hasChild)
{
JPanel pchild = processChildren(childi);
vertci.add(pchild);
}
horizc.add(vertci);
if (getDirection() == HORIZONTAL)
{
horizc.add(Box.createHorizontalStrut(SPACEV));
}
else
{
horizc.add(Box.createVerticalStrut(SPACEV));
}
}
DefaultMutableTreeNode childn = (DefaultMutableTreeNode) node.getChildAt(nbChildren -
1);
hasChild = (getNbChildExpanded(childn) == 0) ? false : true;
JPanel vertcn = createVert(childn, hasChild, HORIZONTAL_RIGHT,
null, horizc);
horizc.setV2(vertcn);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -