blob: 60cc1e70c993710c167cc2754590947d731a0560 (
plain)
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
|
package xlogo;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import xlogo.storage.workspace.Language;
import xlogo.storage.workspace.SyntaxHighlightConfig;
/**
* This singleton class shall eliminate the accesses to Logo.messages.getString(),
* provide a unique way to access current settings and to stay updated through change events.
* @since 10th June 2014 - not yet consistently used throughout the application
* @author Marko
*
*/
public class AppSettings
{
private static AppSettings instance;
public static AppSettings getInstance()
{
if (instance == null)
instance = new AppSettings();
return instance;
}
/* * * * * * *
* LANGUAGE
* * * * * * */
private Language language;
public Language getLanguage()
{
return language;
}
public void setLanguage(Language language)
{
if (language == this.language)
return;
this.language = language;
Logo.generateLanguage(language);
notifyLanguageChanged();
}
/**
* Translate the key into the current language.
* Shortcut for Logo.messages#getString()
* @param key
* @return
*/
public String translate(String key)
{
return Logo.messages.getString(key);
}
private ArrayList<ActionListener> languageChangeListeners = new ArrayList<ActionListener>();
public void addLanguageChangeListener(ActionListener listener)
{
languageChangeListeners.add(listener);
}
public void removeLanguageChangeListener(ActionListener listener)
{
languageChangeListeners.remove(listener);
}
private void notifyLanguageChanged()
{
ActionEvent event = new ActionEvent(this, 0, "languageChange");
for (ActionListener listener : languageChangeListeners)
listener.actionPerformed(event);
}
/* * * * * * *
* FONT
* * * * * * */
private Font font;
public Font getFont()
{
return font;
}
public void setFont(Font font)
{
this.font = font;
notifyFontChanged();
}
private ArrayList<ActionListener> fontChangeListeners = new ArrayList<ActionListener>();
public void addFontChangeListener(ActionListener listener)
{
fontChangeListeners.add(listener);
}
public void removeFontChangeListener(ActionListener listener)
{
fontChangeListeners.remove(listener);
}
private void notifyFontChanged()
{
ActionEvent event = new ActionEvent(this, 0, "fontChange");
for (ActionListener listener : fontChangeListeners)
listener.actionPerformed(event);
}
/* * * * * * *
* SYNTAX HIGHLIGHTING STYLE
* * * * * * */
private SyntaxHighlightConfig syntaxHighlightingStyles;
public SyntaxHighlightConfig getSyntaxHighlightStyles()
{
return syntaxHighlightingStyles;
}
public void setSyntaxHighlightingStyles(SyntaxHighlightConfig syntaxHighlighStyles)
{
this.syntaxHighlightingStyles = syntaxHighlighStyles;
notifySyntaxHighlightStyleChanged();
}
private ArrayList<ActionListener> syntaxHighlightStyleChangeListeners = new ArrayList<ActionListener>();
public void addSyntaxHighlightStyleChangeListener(ActionListener listener)
{
syntaxHighlightStyleChangeListeners.add(listener);
}
public void removeSyntaxHighlightStyleChangeListener(ActionListener listener)
{
syntaxHighlightStyleChangeListeners.remove(listener);
}
private void notifySyntaxHighlightStyleChanged()
{
ActionEvent event = new ActionEvent(this, 0, "fontChange");
for (ActionListener listener : syntaxHighlightStyleChangeListeners)
listener.actionPerformed(event);
}
}
|