1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.download;
|
---|
3 |
|
---|
4 | import java.awt.Component;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.preferences.AbstractProperty;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Defines the sizing policy used for download tabs.
|
---|
10 | * @author Michael Zangl
|
---|
11 | * @since 12705
|
---|
12 | */
|
---|
13 | public interface DownloadSourceSizingPolicy {
|
---|
14 | /**
|
---|
15 | * Gets the height of the download source panel.
|
---|
16 | * @return The height the component should have.
|
---|
17 | */
|
---|
18 | public int getComponentHeight();
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Check whether the user should be allowed to adjust the height of this download source panel
|
---|
22 | * @return <code>true</code> if the height should be adjustable
|
---|
23 | */
|
---|
24 | public boolean isHeightAdjustable();
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Stores the height
|
---|
28 | * @param height the height in pixel
|
---|
29 | */
|
---|
30 | public default void storeHeight(int height) {
|
---|
31 | throw new UnsupportedOperationException(
|
---|
32 | "Setting the height is not supported for " + this.getClass().getCanonicalName());
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * The download source has a fixed size provided by the component
|
---|
37 | * @author Michael Zangl
|
---|
38 | */
|
---|
39 | public class FixedDownloadSourceSizePolicy implements DownloadSourceSizingPolicy {
|
---|
40 | private final Component base;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Create a new fixed download source policy
|
---|
44 | * @param base The component of which the size should be taken.
|
---|
45 | */
|
---|
46 | public FixedDownloadSourceSizePolicy(Component base) {
|
---|
47 | this.base = base;
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public int getComponentHeight() {
|
---|
52 | return (int) base.getPreferredSize().getHeight();
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | public boolean isHeightAdjustable() {
|
---|
57 | return false;
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * The height of this component is given by a preference entry.
|
---|
63 | * <p>
|
---|
64 | * Mind that using a preferred component size is not possible in this case, since the preference entry needs to have a onstant default value.
|
---|
65 | */
|
---|
66 | public class AdjustableDownloadSizePolicy implements DownloadSourceSizingPolicy {
|
---|
67 |
|
---|
68 | private final AbstractProperty<Integer> preference;
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Create a new {@link AdjustableDownloadSizePolicy}
|
---|
72 | * @param preference The preference key to use
|
---|
73 | */
|
---|
74 | public AdjustableDownloadSizePolicy(AbstractProperty<Integer> preference) {
|
---|
75 | this.preference = preference;
|
---|
76 | }
|
---|
77 |
|
---|
78 | @Override
|
---|
79 | public int getComponentHeight() {
|
---|
80 | return Math.max(1, preference.get());
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | public boolean isHeightAdjustable() {
|
---|
85 | return true;
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public void storeHeight(int height) {
|
---|
90 | preference.put(height);
|
---|
91 | }
|
---|
92 |
|
---|
93 | }
|
---|
94 | }
|
---|