下面列出了javax.swing.SwingConstants#VERTICAL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private JSlider createSlider() {
slider = new JSlider(SwingConstants.VERTICAL, 0, 30, 0);
slider.addChangeListener(e -> {
if (!slider.getValueIsAdjusting()) {
model.changeTime(slider.getValue());
}
});
slider.setMajorTickSpacing(5);
slider.setMinorTickSpacing(1);
slider.createStandardLabels(10);
slider.setPaintTicks(true);
slider.setPaintLabels(true);
return slider;
}
@Override
public void paint(Graphics g, JComponent c) {
JSeparator separator = (JSeparator) c;
int w = separator.getWidth();
int h = separator.getHeight();
for (int a = 0; a < colors.length; a++) {
if (colors[a] != null) {
g.setColor(colors[a]);
if (separator.getOrientation() == SwingConstants.VERTICAL) {
g.drawLine(a, 0, a, h - 1);
} else {
g.drawLine(0, a, w - 1, a);
}
}
}
}
@Override
public int getScrollableBlockIncrement(Rectangle vis, int orientation, int direction) {
if (orientation == SwingConstants.VERTICAL) {
int height = measures.getCellHeight();
if (height < 1) {
measures.recompute();
height = measures.getCellHeight();
if (height < 1)
return 19 * vis.height / 20;
}
int lines = Math.max(1, (vis.height / height) - 1);
return lines * height;
} else {
return 19 * vis.width / 20;
}
}
/** Create a thumb that is centered at (0,0) for a horizontally oriented slider.
*
* @param sliderUI the slider UI this thumb relates to.
* @param x the x-coordinate where this thumb is centered.
* @param y the y-coordinate where this thumb is centered.
* @param width the width of the the thumb (assuming this is a horizontal slider)
* @param height the height of the the thumb (assuming this is a horizontal slider)
* @param leftEdge true if this is the left-most thumb
* @param rightEdge true if this is the right-most thumb.
* @return the shape of this thumb.
*/
public Shape getShape(MultiThumbSliderUI<?> sliderUI,float x,float y,int width,int height,boolean leftEdge,boolean rightEdge) {
// TODO: reinstate leftEdge and rightEdge once bug related to nudging
// adjacent thumbs is resolved.
GeneralPath path = new GeneralPath(getShape(width, height, false, false, !sliderUI.getThumbAntialiasing()));
if(sliderUI.slider.getOrientation()==SwingConstants.VERTICAL) {
path.transform(AffineTransform.getRotateInstance(-Math.PI/2));
}
path.transform( AffineTransform.getTranslateInstance(MathG.roundInt(x), MathG.roundInt(y)) );
return path;
}
public int getScrollableBlockIncrement(Rectangle visibleRect,
int orientation, int direction)
{
int result;
if (orientation == SwingConstants.VERTICAL)
result = visibleRect.height;
else
result = visibleRect.width;
result = (result / m_nodeFullSize) * m_nodeFullSize;
return result;
}
/**
* Specify the information needed to do unit scrolling.
*
* @param orientation specify the scrolling orientation. Must be either: SwingContants.HORIZONTAL
* or SwingContants.VERTICAL.
* @param info An IncrementInfo object containing information of how to calculate the scrollable
* amount.
*/
public void setScrollableUnitIncrement(int orientation, IncrementInfo info) {
switch (orientation) {
case SwingConstants.HORIZONTAL:
horizontalUnit = info;
break;
case SwingConstants.VERTICAL:
verticalUnit = info;
break;
default:
throw new IllegalArgumentException("Invalid orientation: " + orientation);
}
}
@Override
public int getScrollableUnitIncrement(Rectangle vis, int orientation, int direction) {
if (orientation == SwingConstants.VERTICAL) {
int ret = measures.getCellHeight();
if (ret < 1) {
measures.recompute();
ret = measures.getCellHeight();
if (ret < 1)
return 1;
}
return ret;
} else {
return Math.max(1, vis.width / 20);
}
}
public AstrosoftToolBar(Color mclr, AstrosoftActionManager actionMgr) {
buttons = new ArrayList<JButton>();
for(Command toolBarItem : Command.toolBarItems()){
buttons.add(new JButton(actionMgr.getAction(toolBarItem)));
}
for (JButton b:buttons){
add(b);
String cmd = b.getActionCommand();
if (cmd.equals(Command.PRINT) || cmd.equals(Command.SHADBALA_VIEW) || cmd.equals(Command.PANCHANG_VIEW)){
//addSeparator();
JSeparator separator = new JSeparator(SwingConstants.VERTICAL);
// FIXME size of separator
//separator.setPreferredSize(new Dimension(1,20));
/*separator.setSize(new Dimension(100,100));
separator.setMaximumSize(new Dimension(100,100));
separator.setMinimumSize(new Dimension(100,100));
separator.setVisible(true);
separator.setBounds(0,0,20,20);*/
add(separator);
}
b.setText("");
}
}
/**
* Returns <code>visibleRect.height</code> or <code>visibleRect.width</code>
* , depending on this spreadsheet's orientation.
*
* @return <code>visibleRect.height</code> or <code>visibleRect.width</code>
* per the orientation
* @see Scrollable#getScrollableBlockIncrement
*/
public int getScrollableBlockIncrement(Rectangle visibleRect,
int orientation, int direction) {
if (orientation == SwingConstants.VERTICAL) {
return visibleRect.height;
} else {
return visibleRect.width;
}
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return orientation == SwingConstants.VERTICAL ? visibleRect.height : visibleRect.width;
}
@Override
public Component getComponent(int width, int height) throws IOException {
// the main panel
final JPanel base = new JPanel();
base.setOpaque(false);
base.setPreferredSize(new Dimension(width, height));
base.setLayout(new GridBagLayout());
final ShapeModelDataset<FImage> dataset = AMToolsSampleDataset.load(ImageUtilities.FIMAGE_READER);
final PointListConnections connections = dataset.getConnections();
final List<PointList> pointData = dataset.getPointLists();
final PointDistributionModel pdm = new PointDistributionModel(pointData);
pdm.setNumComponents(10);
final JPanel sliderPanel = new JPanel();
sliderPanel.setOpaque(false);
sliderPanel.setLayout(new GridLayout(0, 1));
final JSlider[] sliders = new JSlider[10];
for (int i = 0; i < sliders.length; i++) {
sliders[i] = new JSlider(-100, 100, 0);
sliderPanel.add(sliders[i]);
}
stdev = pdm.getStandardDeviations(3);
final double[] currentValue = new double[10];
display = VideoDisplay.createVideoDisplay(new AnimatedVideo<FImage>(new FImage(600, 600)) {
@Override
protected void updateNextFrame(FImage frame) {
frame.fill(0f);
if (animate) {
System.arraycopy(a.nextValue(), 0, currentValue, 0, currentValue.length);
} else {
for (int i = 0; i < 10; i++) {
final double v = sliders[i].getValue() * stdev[i] / 100.0;
currentValue[i] = v;
}
}
final PointList newShape = pdm.generateNewShape(currentValue);
final PointList tfShape = newShape.transform(TransformUtilities.translateMatrix(300, 300).times(
TransformUtilities.scaleMatrix(150, 150)));
final List<Line2d> lines = connections.getLines(tfShape);
frame.drawLines(lines, 1, 1f);
for (final Point2d pt : tfShape) {
frame.drawPoint(pt, 1f, 5);
}
for (int i = 0; i < 10; i++) {
final int newVal = (int) (100.0 * currentValue[i] / stdev[i]);
sliders[i].setValue(newVal);
}
}
}, base);
final JPanel p = new JPanel();
p.setOpaque(false);
final JCheckBox cb = new JCheckBox();
cb.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (cb.isSelected()) {
a = makeAnimator(60, stdev, currentValue);
animate = true;
} else {
animate = false;
}
}
});
p.add(new JLabel("animate:"));
p.add(cb);
final JSeparator vh = new JSeparator(SwingConstants.HORIZONTAL);
sliderPanel.add(vh);
sliderPanel.add(p);
final JSeparator vs = new JSeparator(SwingConstants.VERTICAL);
base.add(vs);
base.add(sliderPanel);
return base;
}
public void paint( Graphics g, JComponent c )
{
boolean vertical = ((JSeparator)c).getOrientation() == SwingConstants.VERTICAL;
Dimension size = c.getSize();
//虚线样式
Stroke oldStroke = ((Graphics2D)g).getStroke();
Stroke sroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL, 0, new float[]{2, 2}, 0);//实线,空白
((Graphics2D)g).setStroke(sroke);//
Color temp = g.getColor();
UIDefaults table = UIManager.getLookAndFeelDefaults();
Color shadow = table.getColor("ToolBar.shadow");
Color highlight = table.getColor("ToolBar.highlight");
// TODO BUG_001:不知何故,垂直分隔条并不能像水平分隔条一样,拥有默认设置的new Dimension(6, 6)
// 而只有new Dimension(1, ...),而当它floating时却能正常表现(只能绘出hilight而不能绘出shadow)
//,有待深入研究,垂直的分隔条则不会有此种情况
if (vertical)
{
int x = (size.width / 2) - 1;
//* 当BUG_001存在时,暂时使用以下代码解决:把本该显示hilight的
//* 线条用shadow颜色绘制,最大可能保证ui的正常展现
// g.setColor(shadow);
// g.drawLine(x, 2, x, size.height - 2);
g.setColor(shadow);//highlight);
g.drawLine(x + 1, 2, x + 1, size.height - 2);
//* 当BUG_001不存在时,应该使用以下代码
// g.setColor(shadow);
// g.drawLine(x, 2, x, size.height - 2);
// g.setColor(highlight);
// g.drawLine(x + 1, 2, x + 1, size.height - 2);
}
else
{
int y = (size.height / 2) - 1;
g.setColor(shadow);
g.drawLine(2, y, size.width - 2, y);
g.setColor(highlight);
g.drawLine(2, y + 1, size.width - 2, y + 1);
}
g.setColor(temp);
//
((Graphics2D)g).setStroke(oldStroke);
}
public JComponent createVerticalSeparator() {
JSeparator x = new JSeparator(SwingConstants.VERTICAL);
x.setPreferredSize(DisplayUtils.getScaledDimension(20, 20));
return x;
}
public StatusBar()
{
super(new BorderLayout());
JPanel outerPanel = new JPanel(new BorderLayout());
add(outerPanel, BorderLayout.CENTER);
if (Platform.isMac())
{
// add some empty space so that status bar does not overlap the
// window resize widget on Mac OS X
Dimension dimension = new Dimension(20, 1);
Box.Filler filler =
new Box.Filler(dimension, dimension, dimension);
outerPanel.add(filler, BorderLayout.EAST);
}
JPanel panel = new JPanel(new BorderLayout());
//panel.setBorder(BorderFactory.createLineBorder(Color.gray));
outerPanel.add(panel, BorderLayout.CENTER);
m_iconBox = Box.createHorizontalBox();
panel.add(m_iconBox, BorderLayout.WEST);
m_toPlayLabel = new JLabel();
m_toPlayLabel.setMaximumSize(new Dimension(Short.MAX_VALUE,
Short.MAX_VALUE));
setToPlay(BLACK);
m_iconBox.add(m_toPlayLabel);
m_labelSetup
= new JLabel(GuiUtil.getIcon("gogui-setup-16x16",
i18n("LB_STATUS_SETUP")));
m_labelSetup.setVisible(false);
m_labelSetup.setToolTipText(i18n("TT_STATUS_SETUP"));
m_iconBox.add(m_labelSetup);
m_iconBox.add(GuiUtil.createSmallFiller());
m_text = new JLabel() {
/** Use tool tip if text is truncated. */
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
String text = super.getText();
if (text == null
|| g.getFontMetrics().stringWidth(text) < getWidth())
setToolTipText(null);
else
setToolTipText(text);
}
};
setPreferredLabelSize(m_text, 10);
panel.add(m_text, BorderLayout.CENTER);
Box moveTextBox = Box.createHorizontalBox();
panel.add(moveTextBox, BorderLayout.EAST);
m_moveText = new JLabel();
setPreferredLabelSize(m_moveText, 12);
m_moveText.setHorizontalAlignment(SwingConstants.LEFT);
m_moveTextSeparator = new JSeparator(SwingConstants.VERTICAL);
moveTextBox.add(m_moveTextSeparator);
moveTextBox.add(GuiUtil.createSmallFiller());
moveTextBox.add(m_moveText);
}
/** Reassign the orientation of this slider.
*
* @param i must be HORIZONTAL or VERTICAL
*/
public void setOrientation(int i) {
if(!(i==SwingConstants.HORIZONTAL || i==SwingConstants.VERTICAL))
throw new IllegalArgumentException("the orientation must be HORIZONTAL or VERTICAL");
putClientProperty(ORIENTATION_PROPERTY, i);
}
@Override
public int getScrollableBlockIncrement(final Rectangle visibleRect, final int orientation,
final int direction) {
return orientation == SwingConstants.VERTICAL ? visibleRect.height : visibleRect.width;
}
public void insertRows(int row, int rowCount) {
if (orientation == SwingConstants.VERTICAL) {
delegate.insertEntries(row, rowCount, defaultSize);
count += rowCount;
}
}
public int getGradientOrientation() {
Integer k = getProperty(KEY_GRADIENT_ORIENTATION);
if (k == null)
k = SwingConstants.VERTICAL;
return k;
}
@Override
public int getScrollableBlockIncrement(final Rectangle visibleRect, final int orientation,
final int direction) {
return orientation == SwingConstants.VERTICAL ? visibleRect.height : visibleRect.width;
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return orientation == SwingConstants.VERTICAL ? visibleRect.height : visibleRect.width;
}