1 | package com.framsticks.gui.controls; |
---|
2 | |
---|
3 | import javax.swing.JPanel; |
---|
4 | |
---|
5 | import com.framsticks.params.ParamFlags; |
---|
6 | import com.framsticks.params.Param; |
---|
7 | import com.framsticks.structure.Path; |
---|
8 | import com.framsticks.util.ExceptionHandler; |
---|
9 | import com.framsticks.util.FramsticksException; |
---|
10 | import com.framsticks.util.Misc; |
---|
11 | |
---|
12 | /** |
---|
13 | * Interface that each class that want to be component must implement. |
---|
14 | */ |
---|
15 | @SuppressWarnings("serial") |
---|
16 | public abstract class Control extends JPanel implements ExceptionHandler { |
---|
17 | |
---|
18 | public static final int LINE_HEIGHT = 36; |
---|
19 | |
---|
20 | // private static final Logger log = LogManager.getLogger(Control.class.getName()); |
---|
21 | |
---|
22 | protected final Param param; |
---|
23 | protected ControlOwner owner; |
---|
24 | |
---|
25 | protected abstract void updateEnabled(boolean enabled); |
---|
26 | |
---|
27 | private boolean userEnabled = true; |
---|
28 | |
---|
29 | public Control(Param param) { |
---|
30 | this.param = param; |
---|
31 | setName(param.getId()); |
---|
32 | } |
---|
33 | |
---|
34 | public Param getParam() { |
---|
35 | return param; |
---|
36 | } |
---|
37 | |
---|
38 | public void setOwner(ControlOwner owner) { |
---|
39 | this.owner = owner; |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * @return the userEnabled |
---|
44 | */ |
---|
45 | public final boolean isUserEnabled() { |
---|
46 | return userEnabled; |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * @param userEnabled the userEnabled to set |
---|
51 | */ |
---|
52 | public final void setUserEnabled(boolean userEnabled) { |
---|
53 | this.userEnabled = userEnabled; |
---|
54 | updateEnabled(!isReadonly()); |
---|
55 | } |
---|
56 | |
---|
57 | public final boolean isReadonly() { |
---|
58 | return !userEnabled || param.hasFlag(ParamFlags.READONLY) || param.hasFlag(ParamFlags.USERREADONLY); |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | @Override |
---|
63 | public String toString() { |
---|
64 | return param.toString(); |
---|
65 | } |
---|
66 | |
---|
67 | @Override |
---|
68 | public void handle(FramsticksException exception) { |
---|
69 | owner.handle(exception); |
---|
70 | } |
---|
71 | |
---|
72 | public Path getCurrentPath() { |
---|
73 | return owner.getCurrentPath(); |
---|
74 | } |
---|
75 | |
---|
76 | public Path assureCurrentPath() { |
---|
77 | return Misc.throwIfNull(owner.getCurrentPath()); |
---|
78 | } |
---|
79 | |
---|
80 | public void refreshState() { |
---|
81 | } |
---|
82 | } |
---|