1 package be
.nikiroo
.fanfix_swing
.gui
.utils
;
4 import java
.awt
.Component
;
6 import javax
.swing
.JButton
;
7 import javax
.swing
.JComponent
;
8 import javax
.swing
.JOptionPane
;
9 import javax
.swing
.JScrollPane
;
10 import javax
.swing
.JTree
;
11 import javax
.swing
.SwingUtilities
;
13 import be
.nikiroo
.fanfix
.Instance
;
15 public class UiHelper
{
16 static private Color buttonNormal
;
17 static private Color buttonPressed
;
19 static public void setButtonPressed(JButton button
, boolean pressed
) {
20 if (buttonNormal
== null) {
21 JButton defButton
= new JButton(" ");
22 buttonNormal
= defButton
.getBackground();
23 if (buttonNormal
.getBlue() >= 128) {
24 buttonPressed
= new Color( //
25 Math
.max(buttonNormal
.getRed() - 100, 0), //
26 Math
.max(buttonNormal
.getGreen() - 100, 0), //
27 Math
.max(buttonNormal
.getBlue() - 100, 0));
29 buttonPressed
= new Color( //
30 Math
.min(buttonNormal
.getRed() + 100, 255), //
31 Math
.min(buttonNormal
.getGreen() + 100, 255), //
32 Math
.min(buttonNormal
.getBlue() + 100, 255));
36 button
.setSelected(pressed
);
37 button
.setBackground(pressed ? buttonPressed
: buttonNormal
);
40 static public JComponent
scroll(JComponent pane
) {
41 JScrollPane scroll
= new JScrollPane(pane
);
42 scroll
.getVerticalScrollBar().setUnitIncrement(16);
43 scroll
.setHorizontalScrollBarPolicy(JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
48 * Display an error message and log the linked {@link Exception}.
50 * @param owner the owner of the error (to link the messagebox to it)
51 * @param message the message
52 * @param title the title of the error message
53 * @param e the exception to log if any
55 static public void error(final Component owner
, final String message
, final String title
, Exception e
) {
56 Instance
.getInstance().getTraceHandler().error(title
+ ": " + message
);
58 Instance
.getInstance().getTraceHandler().error(e
);
61 SwingUtilities
.invokeLater(new Runnable() {
64 JOptionPane
.showMessageDialog(owner
, message
, title
, JOptionPane
.ERROR_MESSAGE
);