123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- /*
- * Copyright (c) 2006-2017 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
- * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
- package com.dmdirc.addons.ui_swing.components.statusbar;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Graphics;
-
- import javax.swing.border.EtchedBorder;
-
- /**
- * An {@link EtchedBorder} with one of it's sides missing.
- */
- class SidelessEtchedBorder extends EtchedBorder {
-
- /** A version number for this class. */
- private static final long serialVersionUID = 1;
- /** Side to not paint. */
- private final Side side;
-
- /**
- * Specifies which side to not include.
- */
- public enum Side {
-
- /** Top border. */
- TOP,
- /** Right hand border. */
- RIGHT,
- /** Bottom border. */
- BOTTOM,
- /** Left hand border. */
- LEFT,
- /* Draw all borders. */
- NONE,
-
- }
-
- /**
- * Creates a new sideless etched border.
- *
- * @param side Which side do you wish to leave out
- */
- public SidelessEtchedBorder(final Side side) {
- this.side = side;
- }
-
- /**
- * Creates a new sideless etched border.
- *
- * @param etchType What etch type to use
- * @param side Which side do you wish to leave out
- */
- public SidelessEtchedBorder(final int etchType, final Side side) {
- super(etchType);
- this.side = side;
- }
-
- /**
- * Creates a new sideless etched border.
- *
- * @param highlight Highlight colour to use
- * @param shadow Shadow colour to use
- * @param side Which side do you wish to leave out
- */
- public SidelessEtchedBorder(final Color highlight, final Color shadow,
- final Side side) {
- super(highlight, shadow);
- this.side = side;
- }
-
- /**
- * Creates a new sideless etched border.
- *
- * @param etchType What etch type to use
- * @param highlight Highlight colour to use
- * @param shadow Shadow colour to use
- * @param side Which side do you wish to leave out
- */
- public SidelessEtchedBorder(final int etchType, final Color highlight,
- final Color shadow, final Side side) {
- super(etchType, highlight, shadow);
- this.side = side;
- }
-
- @Override
- public void paintBorder(final Component c, final Graphics g, final int x,
- final int y, final int width, final int height) {
- g.translate(x, y);
- g.setColor(etchType == LOWERED ? getShadowColor(c) : getHighlightColor(c));
- if (!side.equals(Side.TOP)) {
- g.drawLine(0, 0, width - 1, 0);
- }
- if (!side.equals(Side.BOTTOM)) {
- g.drawLine(0, height - 2, width, height - 2);
- }
- if (!side.equals(Side.LEFT)) {
- g.drawLine(0, 0, 0, height - 2);
- }
- if (!side.equals(Side.RIGHT)) {
- g.drawLine(width - 2, 0, width - 2, height - 1);
- }
- g.setColor(Color.WHITE);
- if (!side.equals(Side.BOTTOM)) {
- g.drawLine(0, height - 1, width, height - 1);
- }
- if (!side.equals(Side.RIGHT)) {
- g.drawLine(width - 1, 0, width - 1, height - 1);
- }
- g.translate(-x, -y);
- }
-
- }
|