Remove ui.primary package
This commit is contained in:
		@@ -1,63 +0,0 @@
 | 
				
			|||||||
package envoy.client.ui.primary;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.awt.Graphics;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.swing.JButton;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Project: <strong>envoy-client</strong><br>
 | 
					 | 
				
			||||||
 * File: <strong>PrimaryButton.javaEvent.java</strong><br>
 | 
					 | 
				
			||||||
 * Created: <strong>07.12.2019</strong><br>
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @author Kai S. K. Engelbart
 | 
					 | 
				
			||||||
 * @author Maximilian Käfer
 | 
					 | 
				
			||||||
 * @since Envoy Client v0.2-alpha
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class PrimaryButton extends JButton {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static final long serialVersionUID = 0L;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private int arcSize;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Creates a primary button
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param title the title of the button
 | 
					 | 
				
			||||||
	 * @since Envoy 0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public PrimaryButton(String title) { this(title, 6); }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Creates a primary button
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param title   the title of the button
 | 
					 | 
				
			||||||
	 * @param arcSize the size of the arc used to draw the round button edges
 | 
					 | 
				
			||||||
	 * @since Envoy 0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public PrimaryButton(String title, int arcSize) {
 | 
					 | 
				
			||||||
		super(title);
 | 
					 | 
				
			||||||
		setBorderPainted(false);
 | 
					 | 
				
			||||||
		setFocusPainted(false);
 | 
					 | 
				
			||||||
		setContentAreaFilled(false);
 | 
					 | 
				
			||||||
		this.arcSize = arcSize;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	protected void paintComponent(Graphics g) {
 | 
					 | 
				
			||||||
		g.setColor(getBackground());
 | 
					 | 
				
			||||||
		g.fillRoundRect(0, 0, getWidth(), getHeight(), arcSize, arcSize);
 | 
					 | 
				
			||||||
		super.paintComponent(g);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * @return the arcSize
 | 
					 | 
				
			||||||
	 * @since Envoy 0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public int getArcSize() { return arcSize; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * @param arcSize the arcSize to set
 | 
					 | 
				
			||||||
	 * @since Envoy 0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public void setArcSize(int arcSize) { this.arcSize = arcSize; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
package envoy.client.ui.primary;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.awt.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.swing.JButton;
 | 
					 | 
				
			||||||
import javax.swing.JComponent;
 | 
					 | 
				
			||||||
import javax.swing.JScrollBar;
 | 
					 | 
				
			||||||
import javax.swing.plaf.basic.BasicScrollBarUI;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import envoy.client.data.Settings;
 | 
					 | 
				
			||||||
import envoy.client.ui.Theme;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Project: <strong>envoy-client</strong><br>
 | 
					 | 
				
			||||||
 * File: <strong>PrimaryScrollBar.java</strong><br>
 | 
					 | 
				
			||||||
 * Created: <strong>14.12.2019</strong><br>
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @author Maximilian Käfer
 | 
					 | 
				
			||||||
 * @since Envoy Client v0.2-alpha
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class PrimaryScrollBar extends BasicScrollBarUI {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private final Dimension	d	= new Dimension();
 | 
					 | 
				
			||||||
	private final int		arcSize;
 | 
					 | 
				
			||||||
	private final Color		scrollBarColor;
 | 
					 | 
				
			||||||
	private final Color		hoverColor;
 | 
					 | 
				
			||||||
	private final Color		draggingColor;
 | 
					 | 
				
			||||||
	private final boolean	isVertical;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Initializes a {@link PrimaryScrollBar} with a color scheme.
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param arcSize        the size of the arc used to draw the round scroll bar
 | 
					 | 
				
			||||||
	 *                       edges
 | 
					 | 
				
			||||||
	 * @param scrollBarColor the default color
 | 
					 | 
				
			||||||
	 * @param hoverColor     the color while hovering
 | 
					 | 
				
			||||||
	 * @param draggingColor  the color while dragging
 | 
					 | 
				
			||||||
	 * @param isVertical     indicates whether this is a vertical
 | 
					 | 
				
			||||||
	 *                       {@link PrimaryScrollBar}
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public PrimaryScrollBar(int arcSize, Color scrollBarColor, Color hoverColor, Color draggingColor, boolean isVertical) {
 | 
					 | 
				
			||||||
		this.arcSize		= arcSize;
 | 
					 | 
				
			||||||
		this.scrollBarColor	= scrollBarColor;
 | 
					 | 
				
			||||||
		this.hoverColor		= hoverColor;
 | 
					 | 
				
			||||||
		this.draggingColor	= draggingColor;
 | 
					 | 
				
			||||||
		this.isVertical		= isVertical;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Initializes a {@link PrimaryScrollBar} using a color scheme specified in a
 | 
					 | 
				
			||||||
	 * {@link Theme}
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param theme      the {@link Theme} to be applied to this
 | 
					 | 
				
			||||||
	 *                   {@link PrimaryScrollBar}
 | 
					 | 
				
			||||||
	 * @param isVertical indicates whether this is a vertical
 | 
					 | 
				
			||||||
	 *                   {@link PrimaryScrollBar}
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public PrimaryScrollBar(Theme theme, boolean isVertical) {
 | 
					 | 
				
			||||||
		this(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50),
 | 
					 | 
				
			||||||
				new Color(theme.getInteractableBackgroundColor().getRGB() + 170), isVertical);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * {@inheritDoc}
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	protected JButton createDecreaseButton(int orientation) {
 | 
					 | 
				
			||||||
		JButton button = new JButton();
 | 
					 | 
				
			||||||
		button.setPreferredSize(d);
 | 
					 | 
				
			||||||
		return button;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * {@inheritDoc}
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	protected JButton createIncreaseButton(int orientation) {
 | 
					 | 
				
			||||||
		JButton button = new JButton();
 | 
					 | 
				
			||||||
		button.setPreferredSize(d);
 | 
					 | 
				
			||||||
		return button;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * {@inheritDoc}
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	protected void paintTrack(Graphics g, JComponent c, Rectangle r) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * {@inheritDoc}
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	protected void paintThumb(Graphics g, JComponent c, Rectangle r) {
 | 
					 | 
				
			||||||
		Graphics2D g2 = (Graphics2D) g.create();
 | 
					 | 
				
			||||||
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 | 
					 | 
				
			||||||
		Color		color;
 | 
					 | 
				
			||||||
		JScrollBar	sb	= (JScrollBar) c;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (!sb.isEnabled()) return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (isDragging) color = draggingColor;
 | 
					 | 
				
			||||||
		else if (isThumbRollover()) color = hoverColor;
 | 
					 | 
				
			||||||
		else color = scrollBarColor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		g2.setPaint(color);
 | 
					 | 
				
			||||||
		if (isVertical) {
 | 
					 | 
				
			||||||
			g2.fillRoundRect(r.x - 9, r.y, r.width, r.height, arcSize, arcSize);
 | 
					 | 
				
			||||||
			g2.setPaint(Settings.getInstance().getCurrentTheme().getCellColor());
 | 
					 | 
				
			||||||
			g2.drawRoundRect(r.x - 9, r.y, r.width, r.height, arcSize, arcSize);
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			g2.fillRoundRect(r.x, r.y + 9, r.width, r.height - 10, arcSize, arcSize);
 | 
					 | 
				
			||||||
			g2.setPaint(Settings.getInstance().getCurrentTheme().getCellColor());
 | 
					 | 
				
			||||||
			g2.drawRoundRect(r.x, r.y + 9, r.width, r.height - 10, arcSize, arcSize);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		g2.dispose();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * {@inheritDoc}
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	protected void setThumbBounds(int x, int y, int width, int height) {
 | 
					 | 
				
			||||||
		super.setThumbBounds(x, y, width, height);
 | 
					 | 
				
			||||||
		scrollbar.repaint();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,85 +0,0 @@
 | 
				
			|||||||
package envoy.client.ui.primary;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.swing.JScrollPane;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import envoy.client.ui.Theme;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Project: <strong>envoy-client</strong><br>
 | 
					 | 
				
			||||||
 * File: <strong>PrimaryScrollPane.java</strong><br>
 | 
					 | 
				
			||||||
 * Created: <strong>15 Dec 2019</strong><br>
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @author Kai S. K. Engelbart
 | 
					 | 
				
			||||||
 * @author Maximilian Käfer
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class PrimaryScrollPane extends JScrollPane {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static final long serialVersionUID = 0L;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private int		verticalScrollBarMaximum	= getVerticalScrollBar().getMaximum();
 | 
					 | 
				
			||||||
	private boolean	chatOpened					= false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Initializes a {@link JScrollPane} with the primary Envoy design scheme
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @since Envoy Client v0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public PrimaryScrollPane() { setBorder(null); }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Styles the vertical and horizontal scroll bars.
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param theme the color set used to color the component
 | 
					 | 
				
			||||||
	 * @since Envoy Client v0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public void applyTheme(Theme theme) {
 | 
					 | 
				
			||||||
		setForeground(theme.getBackgroundColor());
 | 
					 | 
				
			||||||
		setBackground(theme.getCellColor());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		getVerticalScrollBar().setBackground(theme.getCellColor());
 | 
					 | 
				
			||||||
		getVerticalScrollBar().setUI(new PrimaryScrollBar(theme, true));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		getHorizontalScrollBar().setBackground(theme.getCellColor());
 | 
					 | 
				
			||||||
		getHorizontalScrollBar().setUI(new PrimaryScrollBar(theme, false));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Implements <b>autoscroll functionality</b> for the vertical scroll bar. </br>
 | 
					 | 
				
			||||||
	 * </br>
 | 
					 | 
				
			||||||
	 * Functionality to automatically scroll down when user views </br>
 | 
					 | 
				
			||||||
	 * the bottom of the chat while there are new messages added. </br>
 | 
					 | 
				
			||||||
	 * </br>
 | 
					 | 
				
			||||||
	 * When chat is opened, the vertical scroll bar starts at the bottom. </br>
 | 
					 | 
				
			||||||
	 * </br>
 | 
					 | 
				
			||||||
	 * When rereading messages, the chat doesn't scroll down if new messages </br>
 | 
					 | 
				
			||||||
	 * are added. (Besides see first point)
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @since Envoy Client v0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public void autoscroll() {
 | 
					 | 
				
			||||||
		// Automatic scrolling to the bottom
 | 
					 | 
				
			||||||
		getVerticalScrollBar().addAdjustmentListener(e -> {
 | 
					 | 
				
			||||||
			if (verticalScrollBarMaximum == e.getAdjustable().getMaximum()) return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (chatOpened) {
 | 
					 | 
				
			||||||
				e.getAdjustable().setValue(e.getAdjustable().getMaximum());
 | 
					 | 
				
			||||||
				verticalScrollBarMaximum	= getVerticalScrollBar().getMaximum();
 | 
					 | 
				
			||||||
				chatOpened					= false;
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if (getVerticalScrollBar().getValue() + getVerticalScrollBar().getVisibleAmount() + 100 >= getVerticalScrollBar().getMaximum()) {
 | 
					 | 
				
			||||||
				e.getAdjustable().setValue(e.getAdjustable().getMaximum());
 | 
					 | 
				
			||||||
				verticalScrollBarMaximum = getVerticalScrollBar().getMaximum();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Indicates a chat being opened by the user to this {@link PrimaryScrollPane}
 | 
					 | 
				
			||||||
	 * triggering it to automatically scroll down.
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param chatOpened indicates the chat opening status
 | 
					 | 
				
			||||||
	 * @since Envoy Client v0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public void setChatOpened(boolean chatOpened) { this.chatOpened = chatOpened; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,70 +0,0 @@
 | 
				
			|||||||
package envoy.client.ui.primary;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.awt.Font;
 | 
					 | 
				
			||||||
import java.awt.Graphics;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.swing.JTextArea;
 | 
					 | 
				
			||||||
import javax.swing.border.EmptyBorder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Project: <strong>envoy-client</strong><br>
 | 
					 | 
				
			||||||
 * File: <strong>PrimaryTextArea.javaEvent.java</strong><br>
 | 
					 | 
				
			||||||
 * Created: <strong>07.12.2019</strong><br>
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @author Maximilian Käfer
 | 
					 | 
				
			||||||
 * @since Envoy Client v0.2-alpha
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class PrimaryTextArea extends JTextArea {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static final long	serialVersionUID = 0L;
 | 
					 | 
				
			||||||
	private int					arcSize;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Creates the text area
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param borderSpace the space between components
 | 
					 | 
				
			||||||
	 * @since Envoy 0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public PrimaryTextArea(int borderSpace) { this(6, borderSpace); }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Creates the text area
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param arcSize     is the diameter of the arc at the four corners.
 | 
					 | 
				
			||||||
	 * @param borderSpace is the insets of the border on all four sides.
 | 
					 | 
				
			||||||
	 * @since Envoy 0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public PrimaryTextArea(int arcSize, int borderSpace) {
 | 
					 | 
				
			||||||
		super();
 | 
					 | 
				
			||||||
		setWrapStyleWord(true);
 | 
					 | 
				
			||||||
		setLineWrap(true);
 | 
					 | 
				
			||||||
		setBorder(null);
 | 
					 | 
				
			||||||
		setFont(new Font("Arial", Font.PLAIN, 17));
 | 
					 | 
				
			||||||
		setBorder(new EmptyBorder(borderSpace, borderSpace, borderSpace, borderSpace));
 | 
					 | 
				
			||||||
		setOpaque(false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		this.arcSize = arcSize;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * {@inheritDoc}
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	protected void paintComponent(Graphics g) {
 | 
					 | 
				
			||||||
		g.setColor(getBackground());
 | 
					 | 
				
			||||||
		g.fillRoundRect(0, 0, getWidth(), getHeight(), arcSize, arcSize);
 | 
					 | 
				
			||||||
		super.paintComponent(g);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * @return the arcSize - the diameter of the arc at the four corners.
 | 
					 | 
				
			||||||
	 * @since Envoy 0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public int getArcSize() { return arcSize; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * @param arcSize the arcSize to set
 | 
					 | 
				
			||||||
	 * @since Envoy 0.2-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public void setArcSize(int arcSize) { this.arcSize = arcSize; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,61 +0,0 @@
 | 
				
			|||||||
package envoy.client.ui.primary;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.awt.Dimension;
 | 
					 | 
				
			||||||
import java.awt.Graphics;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.swing.JButton;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import envoy.client.data.Settings;
 | 
					 | 
				
			||||||
import envoy.client.data.SettingsItem;
 | 
					 | 
				
			||||||
import envoy.client.ui.Color;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * This component can be used to toggle between two options. This will change
 | 
					 | 
				
			||||||
 * the state of a {@code boolean} {@link SettingsItem}.<br>
 | 
					 | 
				
			||||||
 * <br>
 | 
					 | 
				
			||||||
 * Project: <strong>envoy-client</strong><br>
 | 
					 | 
				
			||||||
 * File: <strong>PrimaryToggleSwitch.java</strong><br>
 | 
					 | 
				
			||||||
 * Created: <strong>21 Dec 2019</strong><br>
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @author Maximilian Käfer
 | 
					 | 
				
			||||||
 * @author Kai S. K. Engelbart
 | 
					 | 
				
			||||||
 * @since Envoy Client v0.3-alpha
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class PrimaryToggleSwitch extends JButton {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private boolean state;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static final long serialVersionUID = 0L;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Initializes a {@link PrimaryToggleSwitch}.
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param settingsItem the {@link SettingsItem} that is controlled by this
 | 
					 | 
				
			||||||
	 *                     {@link PrimaryToggleSwitch}
 | 
					 | 
				
			||||||
	 * @since Envoy Client v0.3-alpha
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public PrimaryToggleSwitch(SettingsItem<Boolean> settingsItem) {
 | 
					 | 
				
			||||||
		setPreferredSize(new Dimension(50, 25));
 | 
					 | 
				
			||||||
		setMinimumSize(new Dimension(50, 25));
 | 
					 | 
				
			||||||
		setMaximumSize(new Dimension(50, 25));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		setBorderPainted(false);
 | 
					 | 
				
			||||||
		setFocusPainted(false);
 | 
					 | 
				
			||||||
		setContentAreaFilled(false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		state = settingsItem.get();
 | 
					 | 
				
			||||||
		addActionListener((evt) -> { state = !state; settingsItem.set(state); revalidate(); repaint(); });
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * {@inheritDoc}
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	public void paintComponent(Graphics g) {
 | 
					 | 
				
			||||||
		g.setColor(state ? Color.GREEN : Color.LIGHT_GRAY);
 | 
					 | 
				
			||||||
		g.fillRoundRect(0, 0, getWidth(), getHeight(), 25, 25);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		g.setColor(Settings.getInstance().getCurrentTheme().getInteractableBackgroundColor());
 | 
					 | 
				
			||||||
		g.fillRoundRect(state ? 25 : 0, 0, 25, 25, 25, 25);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,17 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
 * This package defines all "primary" components that were defined specifically
 | 
					 | 
				
			||||||
 * for the visual improvement of Envoy. However, they can still be used in
 | 
					 | 
				
			||||||
 * general for other projects.<br>
 | 
					 | 
				
			||||||
 * Primary elements are supposed to provide the main functionality of a UI
 | 
					 | 
				
			||||||
 * component.<br>
 | 
					 | 
				
			||||||
 * <br>
 | 
					 | 
				
			||||||
 * Project: <strong>envoy-client</strong><br>
 | 
					 | 
				
			||||||
 * File: <strong>package-info.java</strong><br>
 | 
					 | 
				
			||||||
 * Created: <strong>14 Mar 2020</strong><br>
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @author Leon Hofmeister
 | 
					 | 
				
			||||||
 * @author Kai S. K. Engelbart
 | 
					 | 
				
			||||||
 * @author Maximilian Käfer
 | 
					 | 
				
			||||||
 * @since Envoy Client v0.1-beta
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
package envoy.client.ui.primary;
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user