Java Code Examples for javax.swing.SwingConstants#EAST

The following examples show how to use javax.swing.SwingConstants#EAST . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorPaneTesting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void run(Context context) throws Exception {
    Random random = context.container().random();
    int actionIndex = random.nextInt(4);
    boolean select = random.nextBoolean();
    int direction;
    switch (actionIndex) {
        case 0:
            direction = SwingConstants.WEST;
            break;
        case 1:
            direction = SwingConstants.EAST;
            break;
        case 2:
            direction = SwingConstants.NORTH;
            break;
        case 3:
            direction = SwingConstants.SOUTH;
            break;
        default:
            throw new IllegalStateException("Invalid actionIndex=" + actionIndex); // NOI18N
    }
    moveOrSelect(context, direction, select);
}
 
Example 2
Source File: WindowsLayoutStyle.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public int getPreferredGap(JComponent source, JComponent target, int type, int position, Container parent) {
	super.getPreferredGap(source, target, type, position, parent);

	if (type == INDENT) {
		if (position == SwingConstants.EAST || position == SwingConstants.WEST) {
			int gap = getButtonChildIndent(source, position);
			if (gap != 0) {
				return gap;
			}
			return 10;
		}
		type = RELATED;
	}
	if (type == UNRELATED) {
		return getCBRBPadding(source, target, position, dluToPixels(7, position));
	} else {
		boolean sourceLabel = (source.getUIClassID() == "LabelUI");
		boolean targetLabel = (target.getUIClassID() == "LabelUI");

		if (((sourceLabel && !targetLabel) || (targetLabel && !sourceLabel))
				&& (position == SwingConstants.EAST || position == SwingConstants.WEST)) {
			return getCBRBPadding(source, target, position, dluToPixels(3, position));
		}
		return getCBRBPadding(source, target, position, dluToPixels(4, position));
	}
}
 
Example 3
Source File: LayoutStyle.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
private boolean isRightAligned(AbstractButton button, int position) {
	if (position == SwingConstants.EAST) {
		boolean ltr = button.getComponentOrientation().isLeftToRight();
		int hAlign = button.getHorizontalAlignment();
		return ((ltr && (hAlign == SwingConstants.RIGHT || hAlign == SwingConstants.TRAILING))
				|| (!ltr && (hAlign == SwingConstants.LEADING)));
	}
	return false;
}
 
Example 4
Source File: CrossBorderLayout.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isBasis(int constraint) {
    if (constraint == SwingConstants.NORTH) return true;
    if (constraint == SwingConstants.WEST) return true;
    if (constraint == SwingConstants.SOUTH) return true;
    if (constraint == SwingConstants.EAST) return true;
    if (constraint == SwingConstants.CENTER) return true;
    return false;
}
 
Example 5
Source File: GroupLayout.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
private int getPadding(int axis) {
	int position;
	if (axis == HORIZONTAL) {
		position = SwingConstants.EAST;
	} else {
		position = SwingConstants.SOUTH;
	}
	return getLayoutStyle0().getPreferredGap(source, target, type, position, host);
}
 
Example 6
Source File: CrossBorderLayout.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public Component getLayoutComponent(int constraint) {
    if (constraint == SwingConstants.NORTH) return north;
    if (constraint == SwingConstants.WEST) return west;
    if (constraint == SwingConstants.SOUTH) return south;
    if (constraint == SwingConstants.EAST) return east;
    if (constraint == SwingConstants.CENTER) return center;
    throw new IllegalArgumentException("Illegal constraint: " + // NOI18N
            constraintName(constraint));
}
 
Example 7
Source File: ArrowIcon.java    From pumpernickel with MIT License 5 votes vote down vote up
private static String toString(int direction) {
	if (SwingConstants.NORTH == direction) {
		return "North";
	} else if (SwingConstants.SOUTH == direction) {
		return "South";
	} else if (SwingConstants.EAST == direction) {
		return "East";
	} else if (SwingConstants.WEST == direction) {
		return "West";
	}
	throw new IllegalArgumentException(
			"direction ("
					+ direction
					+ ") must be one of the SwingConstants: NORTH, SOUTH, EAST or WEST.");
}
 
Example 8
Source File: ViewUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static String toStringDirection(int direction) {
    switch (direction) {
        case SwingConstants.WEST: return "WEST";
        case SwingConstants.EAST: return "EAST";
        case SwingConstants.NORTH: return "NORTH";
        case SwingConstants.SOUTH: return "SOUTH";
        default: return "<INVALID-DIRECTION>";
    }
}
 
Example 9
Source File: ParagraphView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public int getNextVisualPositionFromChecked(int offset, Bias bias, Shape alloc,
        int direction, Bias[] biasRet)
{
    int retOffset;
    switch (direction) {
        case SwingConstants.EAST:
        case SwingConstants.WEST:
            retOffset = children.getNextVisualPositionX(this, offset, bias, alloc,
                    direction == SwingConstants.EAST, biasRet);
            break;
        case SwingConstants.NORTH:
        case SwingConstants.SOUTH:
            DocumentView docView = getDocumentView();
            if (docView != null) {
                retOffset = children.getNextVisualPositionY(this, offset, bias, alloc,
                        direction == SwingConstants.SOUTH, biasRet,
                        HighlightsViewUtils.getMagicX(docView, this, offset, bias, alloc));
            } else {
                retOffset = offset;
            }
            break;
        default:
            throw new IllegalArgumentException("Bad direction " + direction); // NOI18N
    }
    return retOffset;
}
 
Example 10
Source File: CrossBorderLayout.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static String constraintName(int constraint) {
    if (constraint == SwingConstants.NORTH) return "NORTH"; // NOI18N
    if (constraint == SwingConstants.WEST) return "WEST"; // NOI18N
    if (constraint == SwingConstants.SOUTH) return "SOUTH"; // NOI18N
    if (constraint == SwingConstants.EAST) return "EAST"; // NOI18N
    if (constraint == SwingConstants.NORTH_WEST) return "NORTH_WEST"; // NOI18N
    if (constraint == SwingConstants.NORTH_EAST) return "NORTH_EAST"; // NOI18N
    if (constraint == SwingConstants.SOUTH_WEST) return "SOUTH_WEST"; // NOI18N
    if (constraint == SwingConstants.SOUTH_EAST) return "SOUTH_EAST"; // NOI18N
    if (constraint == SwingConstants.CENTER) return "CENTER"; // NOI18N

    return "UNSUPPORTED_CONSTRAINT (value=" + constraint + ")"; // NOI18N
}
 
Example 11
Source File: CrossBorderLayout.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void checkSupported(int constraint) {
    if (constraint == SwingConstants.NORTH) return;
    if (constraint == SwingConstants.WEST) return;
    if (constraint == SwingConstants.SOUTH) return;
    if (constraint == SwingConstants.EAST) return;
    if (constraint == SwingConstants.NORTH_WEST) return;
    if (constraint == SwingConstants.NORTH_EAST) return;
    if (constraint == SwingConstants.SOUTH_WEST) return;
    if (constraint == SwingConstants.SOUTH_EAST) return;
    if (constraint == SwingConstants.CENTER) return;
    
    throw new IllegalArgumentException("Unsupported constraint: " + constraint); // NOI18N
}
 
Example 12
Source File: PopupButton.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
protected void displayPopup() {
    JPopupMenu menu = new JPopupMenu();
    populatePopup(menu);
    if (menu.getComponentCount() > 0) {
        Dimension size = menu.getPreferredSize();
        size.width = Math.max(size.width, getWidth());
        menu.setPreferredSize(size);
        
        int align = getPopupAlign();
        
        int x;
        switch (align) {
            case SwingConstants.EAST:
            case SwingConstants.NORTH_EAST:
            case SwingConstants.SOUTH_EAST:
                x = getWidth() - size.width;
                break;
            default:
                x = 0;
                break;
        }
        
        int y;
        switch (align) {
            case SwingConstants.NORTH:
            case SwingConstants.NORTH_EAST:
            case SwingConstants.NORTH_WEST:
                y = -size.height;
                break;
            default:
                y = getHeight();
                break;
        }
        
        menu.show(this, x, y);
    }
}
 
Example 13
Source File: PlafPaintUtils.java    From pumpernickel with MIT License 5 votes vote down vote up
private static void drawColors(Color[] colors, Graphics g, int x1, int y1,
		int x2, int y2, int direction) {
	for (int a = 0; a < colors.length; a++) {
		g.setColor(colors[colors.length - a - 1]);
		if (direction == SwingConstants.SOUTH) {
			g.drawLine(x1, y1 - a, x2, y2 - a);
		} else if (direction == SwingConstants.NORTH) {
			g.drawLine(x1, y1 + a, x2, y2 + a);
		} else if (direction == SwingConstants.EAST) {
			g.drawLine(x1 - a, y1, x2 - a, y2);
		} else if (direction == SwingConstants.WEST) {
			g.drawLine(x1 + a, y1, x2 + a, y2);
		}
	}
}
 
Example 14
Source File: PlafPaintUtils.java    From PyramidShader with GNU General Public License v3.0 5 votes vote down vote up
private static void drawColors(Color[] colors,Graphics g,int x1,int y1,int x2,int y2,int direction) {
	for(int a = 0; a<colors.length; a++) {
		g.setColor(colors[colors.length-a-1]);
		if(direction==SwingConstants.SOUTH) {
			g.drawLine(x1, y1-a, x2, y2-a);
		} else if(direction==SwingConstants.NORTH) {
			g.drawLine(x1, y1+a, x2, y2+a);
		} else if(direction==SwingConstants.EAST) {
			g.drawLine(x1-a, y1, x2-a, y2);
		} else if(direction==SwingConstants.WEST) {
			g.drawLine(x1+a, y1, x2+a, y2);
		}
	}
}
 
Example 15
Source File: XDMScrollBarUI.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private JButton createScrollButton(int orientation) {
	darkMode = scrollbar instanceof DarkScrollBar;

	if (darkMode) {
		return createZeroButton();
	}

	CustomButton btn = new CustomButton();
	btn.setBackground(darkMode ? trackColor2 : trackColor1);
	btn.setContentAreaFilled(false);
	btn.setHorizontalAlignment(JButton.CENTER);
	btn.setMargin(new Insets(0, 0, 0, 0));
	btn.setBorderPainted(false);
	if (orientation == SwingConstants.NORTH) {
		btn.setIcon(ImageResource.getIcon("up.png", 10, 10));
		btn.setPreferredSize(new Dimension(XDMUtils.getScaledInt(15), XDMUtils.getScaledInt(18)));
	}
	if (orientation == SwingConstants.SOUTH) {
		btn.setIcon(ImageResource.getIcon("down.png", 10, 10));
		btn.setPreferredSize(new Dimension(XDMUtils.getScaledInt(15), XDMUtils.getScaledInt(18)));
	}
	if (orientation == SwingConstants.EAST) {
		btn.setIcon(ImageResource.getIcon("right.png", 10, 10));
		btn.setPreferredSize(new Dimension(XDMUtils.getScaledInt(18), XDMUtils.getScaledInt(15)));
	}
	if (orientation == SwingConstants.WEST) {
		btn.setIcon(ImageResource.getIcon("left.png", 10, 10));
		btn.setPreferredSize(new Dimension(XDMUtils.getScaledInt(18), XDMUtils.getScaledInt(15)));
	}
	return btn;
}
 
Example 16
Source File: TriangleIcon.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Creates a new TriangleIcon.
 * 
 * @param direction
 *            one of the SwingConstant constants for NORTH, SOUTH, EAST or
 *            WEST. For example, if the direction is EAST this triangle will
 *            point to the right.
 * @param width
 *            the width of this icon
 * @param height
 *            the height of this icon
 * @param color
 *            the color to fill this icon with.
 */
public TriangleIcon(int direction, int width, int height, Color color) {
	this.direction = direction;
	this.width = width;
	this.height = height;
	this.color = color;

	if (direction == SwingConstants.EAST
			|| direction == SwingConstants.RIGHT) {
		triangle.moveTo(0, 0);
		triangle.lineTo(width, height / 2);
		triangle.lineTo(0, height);
	} else if (direction == SwingConstants.WEST
			|| direction == SwingConstants.LEFT) {
		triangle.moveTo(width, 0);
		triangle.lineTo(0, height / 2);
		triangle.lineTo(width, height);
	} else if (direction == SwingConstants.NORTH
			|| direction == SwingConstants.TOP) {
		triangle.moveTo(0, height);
		triangle.lineTo(width / 2, 0);
		triangle.lineTo(width, height);
	} else if (direction == SwingConstants.SOUTH
			|| direction == SwingConstants.BOTTOM) {
		triangle.moveTo(0, 0);
		triangle.lineTo(width / 2, height);
		triangle.lineTo(width, 0);
	} else {
		throw new IllegalArgumentException(
				"direction ("
						+ direction
						+ ") must be one of the SwingConstant constants: NORTH, SOUTH, EAST or WEST.");
	}
	triangle.closePath();
}
 
Example 17
Source File: FlatMonthUpIcon.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
public FlatMonthUpIcon() {
	super( SwingConstants.EAST );
}
 
Example 18
Source File: LayoutStyle.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the amount of space to use between two components. The return
 * value indicates the distance to place <code>component2</code> relative to
 * <code>component1</code>. For example, the following returns the amount of
 * space to place between <code>component2</code> and
 * <code>component1</code> when <code>component2</code> is placed vertically
 * above <code>component1</code>:
 * 
 * <pre>
 * int gap = getPreferredGap(component1, component2, LayoutStyle.RELATED, SwingConstants.NORTH, parent);
 * </pre>
 * 
 * The <code>type</code> parameter indicates the type of gap being
 * requested. It can be one of the following values:
 * <table>
 * <tr>
 * <td><code>RELATED</code>
 * <td>If the two components will be contained in the same parent and are
 * showing similar logically related items, use <code>RELATED</code>.
 * <tr>
 * <td><code>UNRELATED</code>
 * <td>If the two components will be contained in the same parent but show
 * logically unrelated items use <code>UNRELATED</code>.
 * <tr>
 * <td><code>INDENT</code>
 * <td>Used to obtain the preferred distance to indent a component relative
 * to another. For example, if you want to horizontally indent a JCheckBox
 * relative to a JLabel use <code>INDENT</code>. This is only useful for the
 * horizontal axis.
 * </table>
 * <p>
 * It's important to note that some look and feels may not distinguish
 * between <code>RELATED</code> and <code>UNRELATED</code>.
 * <p>
 * The return value is not intended to take into account the current size
 * and position of <code>component2</code> or <code>component1</code>. The
 * return value may take into consideration various properties of the
 * components. For example, the space may vary based on font size, or the
 * preferred size of the component.
 * 
 * @param component1
 *            the <code>JComponent</code> <code>component2</code> is being
 *            placed relative to
 * @param component2
 *            the <code>JComponent</code> being placed
 * @param type
 *            how the two components are being placed
 * @param position
 *            the position <code>component2</code> is being placed relative
 *            to <code>component1</code>; one of
 *            <code>SwingConstants.NORTH</code>,
 *            <code>SwingConstants.SOUTH</code>,
 *            <code>SwingConstants.EAST</code> or
 *            <code>SwingConstants.WEST</code>
 * @param parent
 *            the parent of <code>component2</code>; this may differ from
 *            the actual parent and may be null
 * @return the amount of space to place between the two components
 * @throws IllegalArgumentException
 *             if <code>position</code> is not one of
 *             <code>SwingConstants.NORTH</code>,
 *             <code>SwingConstants.SOUTH</code>,
 *             <code>SwingConstants.EAST</code> or
 *             <code>SwingConstants.WEST</code>; <code>type</code> not one
 *             of <code>INDENT</code>, <code>RELATED</code> or
 *             <code>UNRELATED</code>; or <code>component1</code> or
 *             <code>component2</code> is null
 */
public int getPreferredGap(JComponent component1, JComponent component2, int type, int position, Container parent) {
	if (position != SwingConstants.NORTH && position != SwingConstants.SOUTH && position != SwingConstants.WEST
			&& position != SwingConstants.EAST) {
		throw new IllegalArgumentException("Invalid position");
	}
	if (component1 == null || component2 == null) {
		throw new IllegalArgumentException("Components must be non-null");
	}
	if (type == RELATED) {
		return 6;
	} else if (type == UNRELATED) {
		return 12;
	} else if (type == INDENT) {
		if (position == SwingConstants.EAST || position == SwingConstants.WEST) {
			int gap = getButtonChildIndent(component1, position);
			if (gap != 0) {
				return gap;
			}
			return 6;
		}
		return 6;
	}
	throw new IllegalArgumentException("Invalid type");
}
 
Example 19
Source File: MSynthPainter.java    From swift-k with Apache License 2.0 4 votes vote down vote up
@Override
public void paintArrowButtonForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(SELECTED);
    switch (direction) {
        case SwingConstants.NORTH:
            g2.fillRoundRect(x, y, w, h + 4, 5, 5);
            g2.setColor(Color.BLACK);
            g2.fillRect(x, y + h, w, 4);
            break;
        case SwingConstants.SOUTH:
            g2.fillRoundRect(x, y - 4, w, h + 4, 5, 5);
            g2.setColor(Color.BLACK);
            g2.fillRect(x, y - 4, w, 4);
            break;
        case SwingConstants.WEST:
            g2.fillRoundRect(x, y, w + 4, h, 5, 5);
            g2.setColor(Color.BLACK);
            g2.fillRect(x + w, y, 4, h);
            break;
        case SwingConstants.EAST:
            g2.fillRoundRect(x - 4, y, w + 4, h, 5, 5);
            g2.setColor(Color.BLACK);
            g2.fillRect(x - 4, y, 4, h);
            break;
    }
    
    
    g2.setColor(ACCENT);
    Path2D p = new Path2D.Double();
    p.moveTo(4, 0);
    p.lineTo(8, 6);
    p.lineTo(0, 6);
    p.closePath();
    
    switch (direction) {
        case SwingConstants.NORTH:
            // no transform
            break;
        case SwingConstants.SOUTH:
            p.transform(AffineTransform.getRotateInstance(Math.PI, 4, 4));
            break;
        case SwingConstants.WEST:
            p.transform(AffineTransform.getRotateInstance(-Math.PI / 2, 4, 4));
            break;
        case SwingConstants.EAST:
            p.transform(AffineTransform.getRotateInstance(Math.PI / 2, 4, 4));
            break;
    }
    
    p.transform(AffineTransform.getTranslateInstance((w - 8) / 2.0, (h - 7) / 2.0));
    g2.fill(p);
}
 
Example 20
Source File: LayoutStyle.java    From RipplePower with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the amount of space to position a component inside its parent.
 * 
 * @param component
 *            the <code>Component</code> being positioned
 * @param position
 *            the position <code>component</code> is being placed relative
 *            to its parent; one of <code>SwingConstants.NORTH</code>,
 *            <code>SwingConstants.SOUTH</code>,
 *            <code>SwingConstants.EAST</code> or
 *            <code>SwingConstants.WEST</code>
 * @param parent
 *            the parent of <code>component</code>; this may differ from the
 *            actual parent and may be null
 * @return the amount of space to place between the component and specified
 *         edge
 * @throws IllegalArgumentException
 *             if <code>position</code> is not one of
 *             <code>SwingConstants.NORTH</code>,
 *             <code>SwingConstants.SOUTH</code>,
 *             <code>SwingConstants.EAST</code> or
 *             <code>SwingConstants.WEST</code>; or <code>component</code>
 *             is null
 */
public int getContainerGap(JComponent component, int position, Container parent) {
	if (position != SwingConstants.NORTH && position != SwingConstants.SOUTH && position != SwingConstants.WEST
			&& position != SwingConstants.EAST) {
		throw new IllegalArgumentException("Invalid position");
	}
	if (component == null) {
		throw new IllegalArgumentException("Component must be non-null");
	}
	return 12;
}