-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathAppearanceSettingsPage.java
185 lines (162 loc) · 6.48 KB
/
AppearanceSettingsPage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*-
* #%L
* BigDataViewer core classes with minimal dependencies.
* %%
* Copyright (C) 2012 - 2023 BigDataViewer developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package bdv.ui.appearance;
import bdv.ui.settings.ModificationListener;
import bdv.ui.settings.SettingsPage;
import bdv.util.Prefs;
import bdv.ui.appearance.StyleElements.ComboBoxEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.Box;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import net.miginfocom.swing.MigLayout;
import org.scijava.listeners.Listeners;
import static bdv.ui.appearance.StyleElements.booleanElement;
import static bdv.ui.appearance.StyleElements.cbentry;
import static bdv.ui.appearance.StyleElements.colorElement;
import static bdv.ui.appearance.StyleElements.comboBoxElement;
import static bdv.ui.appearance.StyleElements.linkedCheckBox;
import static bdv.ui.appearance.StyleElements.linkedColorButton;
import static bdv.ui.appearance.StyleElements.linkedComboBox;
import static bdv.ui.appearance.StyleElements.separator;
/**
* Preferences page for changing {@link Appearance}.
*/
public class AppearanceSettingsPage implements SettingsPage
{
private final String treePath;
private final AppearanceManager manager;
private final Listeners.List< ModificationListener > modificationListeners;
private final Appearance editedAppearance;
private final JPanel panel;
public AppearanceSettingsPage( final AppearanceManager manager )
{
this( "Appearance", manager );
}
public AppearanceSettingsPage( final String treePath, final AppearanceManager manager )
{
this.treePath = treePath;
this.manager = manager;
editedAppearance = new Appearance();
editedAppearance.set( manager.appearance() );
panel = new AppearancePanel( editedAppearance );
modificationListeners = new Listeners.SynchronizedList<>();
editedAppearance.updateListeners().add( () -> modificationListeners.list.forEach( l -> l.setModified() ) );
}
@Override
public String getTreePath()
{
return treePath;
}
@Override
public JPanel getJPanel()
{
return panel;
}
@Override
public Listeners< ModificationListener > modificationListeners()
{
return modificationListeners;
}
@Override
public void cancel()
{
editedAppearance.set( manager.appearance() );
}
@Override
public void apply()
{
manager.appearance().set( editedAppearance );
manager.save();
manager.toPrefs();
manager.updateLookAndFeel();
}
// --------------------------------------------------------------------
static class AppearancePanel extends JPanel
{
public AppearancePanel( final Appearance appearance )
{
super( new MigLayout( "fillx", "[r][l]", "" ) );
final List< ComboBoxEntry< LookAndFeelInfo > > lafs = new ArrayList<>();
lafs.add( cbentry( Appearance.DONT_MODIFY_LOOK_AND_FEEL, "don't set" ) );
for ( LookAndFeelInfo feel : UIManager.getInstalledLookAndFeels() )
lafs.add( cbentry( feel, feel.getName() ) );
final List< StyleElements.StyleElement > styleElements = Arrays.asList(
comboBoxElement( "look-and-feel", appearance::lookAndFeel, appearance::setLookAndFeel, lafs ),
separator(),
booleanElement( "show scalebar", appearance::showScaleBar, appearance::setShowScaleBar ),
booleanElement( "show scalebar in movies", appearance::showScaleBarInMovie, appearance::setShowScaleBarInMovie ),
colorElement( "scalebar foreground", appearance::scaleBarColor, appearance::setScaleBarColor ),
colorElement( "scalebar background", appearance::scaleBarBgColor, appearance::setScaleBarBgColor ),
booleanElement("show source info tool bar", appearance::showSourceInfoToolBar, appearance::setShowSourceInfoToolBar),
separator(),
booleanElement( "show minimap", appearance::showMultibox, appearance::setShowMultibox ),
booleanElement( "show source info", appearance::showTextOverlay, appearance::setShowTextOverlay ),
comboBoxElement( "source name position", appearance::sourceNameOverlayPosition, appearance::setSourceNameOverlayPosition, Prefs.OverlayPosition.values() )
);
final JColorChooser colorChooser = new JColorChooser();
styleElements.forEach( element -> element.accept(
new StyleElements.StyleElementVisitor()
{
@Override
public void visit( final StyleElements.Separator separator )
{
add( Box.createVerticalStrut( 10 ), "growx, span 2, wrap" );
}
@Override
public void visit( final StyleElements.ColorElement element )
{
add( new JLabel( element.getLabel() ), "r" );
add( linkedColorButton( element, colorChooser ), "l, wrap" );
}
@Override
public void visit( final StyleElements.BooleanElement element )
{
add( new JLabel( element.getLabel() ), "r" );
add( linkedCheckBox( element ), "l, wrap" );
}
@Override
public void visit( final StyleElements.ComboBoxElement< ? > element )
{
add( new JLabel( element.getLabel() ), "r" );
add( linkedComboBox( element ), "l, wrap" );
}
} ) );
appearance.updateListeners().add( () -> {
styleElements.forEach( StyleElements.StyleElement::update );
repaint();
} );
}
}
}