📄 orgline1.java
字号:
/*
* OPIAM Suite
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package opiam.admin.faare.service.services.views.orgchart;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JComponent;
/**
* This class implements an organization chart line, for tree and semalike
* orgcharts.
* It should be on top of each son cell of the organization chart
*/
public class OrgLine1 extends JComponent
{
/** Kind of line. */
private short position;
/** Background color. */
private Color backColor = null;
/** Line height. */
private int height = OrgChartPanel.SPACEV;
/** The corresponding cell is the last of the siblings or not. */
private boolean last = false;
/**
* Creates a new OrgLine1 object.
*
* @param abackColor Background color.
*/
public OrgLine1(final Color abackColor)
{
super();
this.position = OrgChartPanel.VERTICAL;
this.backColor = abackColor;
}
/**
* Creates a new OrgLine1 object.
*
* @param aposition Kind of line.
* @param abackColor Background color.
* @param aheight Line height.
*/
public OrgLine1(final short aposition, final Color abackColor,
final int aheight)
{
super();
this.position = aposition;
this.backColor = abackColor;
this.height = aheight;
}
/**
* Creates a new OrgLine1 object.
*
* @param aposition Kind of line.
* @param abackColor Background color.
* @param aheight Line height.
* @param alast Last cell flag.
*/
public OrgLine1(final short aposition, final Color abackColor,
final int aheight, final boolean alast)
{
super();
this.position = aposition;
this.backColor = abackColor;
this.height = aheight;
this.last = alast;
}
/**
* Gets minimum size of the component.
*
* @return The minimum size according to the line height.
*/
public final Dimension getMinimumSize()
{
return new Dimension(OrgChartPanel.SPACEH, height);
}
/**
* Gets preferred size of the component, which is the minimum size.
*
* @return The preferred size.
*/
public final Dimension getPreferredSize()
{
return getMinimumSize();
}
/**
* Gets maximum size of the component, which is the minimum size.
*
* @return The maximum size.
*/
public final Dimension getMaximumSize()
{
return getMinimumSize();
}
/**
* Draws the component.
*
* @param g Graphics on which to draw the component.
*/
public final void paint(final Graphics g)
{
int w = getSize().width;
int h = getSize().height;
// background color
if (backColor != null)
{
g.setColor(backColor);
g.fillRect(0, 0, w, h);
}
// lines
g.setColor(Color.black);
if (position == OrgChartPanel.VERTICAL)
{
g.drawLine(w / 2, 0, w / 2, h);
g.drawLine((w / 2) + 1, 0, (w / 2) + 1, h);
}
else if (position == OrgChartPanel.HORIZONTAL_LEFT)
{
g.drawLine(w / 2, 0, w / 2, h / 2);
g.drawLine(w / 2, h / 2, w, h / 2);
g.drawLine((w / 2) + 1, 0, (w / 2) + 1, h / 2);
g.drawLine(w / 2, (h / 2) + 1, w, (h / 2) + 1);
if (!last)
{
g.drawLine(w / 2, h / 2, w / 2, h);
g.drawLine((w / 2) + 1, h / 2, (w / 2) + 1, h);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -