Refactor hard-coded colours into ThemeSupport
This commit is contained in:
parent
a8af9ad372
commit
6bb142bb8e
|
@ -1,33 +1,28 @@
|
|||
package net.filebot.ui;
|
||||
|
||||
import static javax.swing.BorderFactory.*;
|
||||
import static net.filebot.ui.ThemeSupport.*;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.LinearGradientPaint;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import net.filebot.util.ui.GradientStyle;
|
||||
import net.filebot.util.ui.notification.SeparatorBorder;
|
||||
import net.filebot.util.ui.notification.SeparatorBorder.Position;
|
||||
|
||||
public class HeaderPanel extends JComponent {
|
||||
|
||||
private JLabel titleLabel = new JLabel();
|
||||
|
||||
private float[] gradientFractions = { 0.0f, 0.5f, 1.0f };
|
||||
private Color[] gradientColors = { new Color(0xF6F6F6), new Color(0xF8F8F8), new Color(0xF3F3F3) };
|
||||
|
||||
public HeaderPanel() {
|
||||
setLayout(new BorderLayout());
|
||||
setBackground(Color.WHITE);
|
||||
setBackground(getPanelBackground());
|
||||
|
||||
JPanel centerPanel = new JPanel(new BorderLayout());
|
||||
centerPanel.setOpaque(false);
|
||||
|
@ -43,7 +38,7 @@ public class HeaderPanel extends JComponent {
|
|||
|
||||
add(centerPanel, BorderLayout.CENTER);
|
||||
|
||||
setBorder(new SeparatorBorder(1, new Color(0xB4B4B4), new Color(0xACACAC), GradientStyle.LEFT_TO_RIGHT, Position.BOTTOM));
|
||||
setBorder(getSeparatorBorder(Position.BOTTOM));
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
|
@ -57,10 +52,7 @@ public class HeaderPanel extends JComponent {
|
|||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
LinearGradientPaint paint = new LinearGradientPaint(0, 0, getWidth(), 0, gradientFractions, gradientColors);
|
||||
|
||||
g2d.setPaint(paint);
|
||||
g2d.setPaint(getPanelBackgroundGradient(0, 0, getWidth(), 0));
|
||||
g2d.fill(getBounds());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package net.filebot.ui;
|
||||
|
||||
import static com.bulenkov.iconloader.util.ColorUtil.*;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.LinearGradientPaint;
|
||||
|
||||
import net.filebot.util.ui.GradientStyle;
|
||||
import net.filebot.util.ui.notification.SeparatorBorder;
|
||||
import net.filebot.util.ui.notification.SeparatorBorder.Position;
|
||||
|
||||
public class ThemeSupport {
|
||||
|
||||
public static Color getPanelBackground() {
|
||||
return getColor(0xFFFFFF);
|
||||
}
|
||||
|
||||
public static LinearGradientPaint getPanelBackgroundGradient(int x, int y, int w, int h) {
|
||||
float[] gradientFractions = { 0.0f, 0.5f, 1.0f };
|
||||
Color[] gradientColors = { getColor(0xF6F6F6), getColor(0xF8F8F8), getColor(0xF3F3F3) };
|
||||
|
||||
return new LinearGradientPaint(x, y, w, h, gradientFractions, gradientColors);
|
||||
}
|
||||
|
||||
public static SeparatorBorder getSeparatorBorder(Position position) {
|
||||
return new SeparatorBorder(1, getColor(0xB4B4B4), getColor(0xACACAC), GradientStyle.LEFT_TO_RIGHT, position);
|
||||
}
|
||||
|
||||
public static Color getColor(int rgba) {
|
||||
if (dark) {
|
||||
return getDarkColor(new Color(rgba));
|
||||
}
|
||||
return new Color(rgba);
|
||||
}
|
||||
|
||||
public static Color getDarkColor(Color c) {
|
||||
return isDark(c) ? c : shift(c, 0.2);
|
||||
}
|
||||
|
||||
private static boolean dark = false;
|
||||
|
||||
}
|
Loading…
Reference in New Issue