| 1 | package be.nikiroo.fanfix_swing.gui.utils; |
| 2 | |
| 3 | import java.awt.Color; |
| 4 | import java.awt.Container; |
| 5 | import java.awt.Frame; |
| 6 | import java.awt.Window; |
| 7 | import java.awt.event.ActionListener; |
| 8 | |
| 9 | import javax.swing.JButton; |
| 10 | import javax.swing.JComponent; |
| 11 | import javax.swing.JDialog; |
| 12 | import javax.swing.JScrollPane; |
| 13 | import javax.swing.SwingWorker; |
| 14 | |
| 15 | import be.nikiroo.utils.Progress; |
| 16 | |
| 17 | public 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 | } |