Initial commit (missing a lot of things):
[nikiroo-utils.git] / src / be / nikiroo / fanfix_swing / gui / utils / UiHelper.java
CommitLineData
3cdf3fd8
NR
1package be.nikiroo.fanfix_swing.gui.utils;
2
3import java.awt.Color;
4import java.awt.Container;
5import java.awt.Frame;
6import java.awt.Window;
7import java.awt.event.ActionListener;
8
9import javax.swing.JButton;
10import javax.swing.JComponent;
11import javax.swing.JDialog;
12import javax.swing.JScrollPane;
13import javax.swing.SwingWorker;
14
15import be.nikiroo.utils.Progress;
16
17public class UiHelper {
18 static private Color buttonNormal;
19 static private Color buttonPressed;
20
21 static public void setButtonPressed(JButton button, boolean pressed) {
22 if (buttonNormal == null) {
23 JButton defButton = new JButton(" ");
24 buttonNormal = defButton.getBackground();
25 if (buttonNormal.getBlue() >= 128) {
26 buttonPressed = new Color( //
27 Math.max(buttonNormal.getRed() - 100, 0), //
28 Math.max(buttonNormal.getGreen() - 100, 0), //
29 Math.max(buttonNormal.getBlue() - 100, 0));
30 } else {
31 buttonPressed = new Color( //
32 Math.min(buttonNormal.getRed() + 100, 255), //
33 Math.min(buttonNormal.getGreen() + 100, 255), //
34 Math.min(buttonNormal.getBlue() + 100, 255));
35 }
36 }
37
38 button.setSelected(pressed);
39 button.setBackground(pressed ? buttonPressed : buttonNormal);
40 }
41
42 static public JComponent scroll(JComponent pane) {
43 JScrollPane scroll = new JScrollPane(pane);
44 scroll.getVerticalScrollBar().setUnitIncrement(16);
45 scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
46 return scroll;
47 }
48}