separatorbar.java
来自「经典的货郎担问题解决办法」· Java 代码 · 共 150 行
JAVA
150 行
//-----------------------------------------------------------------------------
// com.coyotegulch.ui
//
// A Package of Generic Tools for AWT-based User Interfaces
//
// SeparatorBar.java
// version 3.1.0
//
// Copyright 1996-2001 Scott Robert Ladd. All rights reserved.
//
// For more information about this program, contact:
//
// Scott Robert Ladd
// scott@coyotegulch.com
// http://www.coyotegulch.com
//
//-----------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
//
// Free Software Foundation, Inc.
// 59 Temple Place - Suite 330
// Boston, MA 02111-1307, USA.
//-----------------------------------------------------------------------------
package com.coyotegulch.ui;
import java.awt.*;
public class SeparatorBar
extends Canvas
{
// constants
public static final int VERTICAL = 0;
public static final int HORIZONTAL = 1;
// fields
private int m_orientation;
// constructors
public SeparatorBar()
{
m_orientation = VERTICAL;
}
public SeparatorBar
(
int orient
)
{
if (orient == HORIZONTAL)
m_orientation = HORIZONTAL;
else
m_orientation = VERTICAL;
}
// properties
public int getOrientation()
{
return m_orientation;
}
// methods
public void update
(
Graphics g
)
{
paint(g);
}
public void paint
(
Graphics g
)
{
Dimension dim = getSize();
// fill rectangle with background color
g.setColor(getBackground());
g.fillRect(0,0,dim.width - 1,dim.height - 1);
// draw lines
Color hilite = getBackground().brighter().brighter();
if (m_orientation == VERTICAL)
{
int x = dim.width / 2;
g.setColor(hilite);
g.drawLine(x,0,x,dim.height);
g.setColor(getBackground().darker());
g.drawLine(x + 1,0,x + 1,dim.height);
}
else // horizontal line
{
int y = dim.height / 2;
g.setColor(hilite);
g.drawLine(0,y,dim.width,y);
g.setColor(getBackground().darker());
g.drawLine(0,y + 1,dim.width,y + 1);
}
}
public Dimension getPreferredSize()
{
Container parent = getParent();
Dimension dim = parent.getSize();
Insets ins = parent.getInsets();
if (m_orientation == VERTICAL)
{
dim.width = 4;
dim.height -= (ins.top + ins.bottom + 8);
}
else
{
dim.width -= (ins.left + ins.right + 8);
dim.height = 4;
}
return dim;
}
public Dimension getMinimumSize()
{
return getPreferredSize();
}
public Dimension getMaximumSize()
{
return getPreferredSize();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?