2 * Copyright 2000-2007 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.ide
.ui
;
19 import com
.intellij
.ide
.IdeBundle
;
20 import com
.intellij
.openapi
.application
.ApplicationManager
;
21 import com
.intellij
.openapi
.application
.PathManager
;
22 import com
.intellij
.openapi
.components
.ExportableApplicationComponent
;
23 import com
.intellij
.openapi
.components
.PersistentStateComponent
;
24 import com
.intellij
.openapi
.components
.State
;
25 import com
.intellij
.openapi
.components
.Storage
;
26 import com
.intellij
.openapi
.util
.SystemInfo
;
27 import com
.intellij
.util
.xmlb
.Accessor
;
28 import com
.intellij
.util
.xmlb
.SerializationFilter
;
29 import com
.intellij
.util
.xmlb
.XmlSerializerUtil
;
30 import com
.intellij
.util
.xmlb
.annotations
.Property
;
31 import org
.jetbrains
.annotations
.NonNls
;
32 import org
.jetbrains
.annotations
.NotNull
;
35 import javax
.swing
.event
.EventListenerList
;
45 file
= "$APP_CONFIG$/ui.lnf.xml"
48 public class UISettings
implements PersistentStateComponent
<UISettings
>, ExportableApplicationComponent
{
49 private final EventListenerList myListenerList
;
51 @Property(filter
= FontFilter
.class)
53 public String FONT_FACE
;
54 @Property(filter
= FontFilter
.class)
57 public int RECENT_FILES_LIMIT
= 15;
58 public int EDITOR_TAB_LIMIT
= 10;
59 public boolean ANIMATE_WINDOWS
= true;
60 public int ANIMATION_SPEED
= 2000; // Pixels per second
61 public boolean SHOW_WINDOW_SHORTCUTS
= true;
62 public boolean HIDE_TOOL_STRIPES
= false;
63 public boolean SHOW_MEMORY_INDICATOR
= true;
64 public boolean SHOW_MAIN_TOOLBAR
= true;
65 public boolean SHOW_STATUS_BAR
= true;
66 public boolean SHOW_NAVIGATION_BAR
= true;
67 public boolean ALWAYS_SHOW_WINDOW_BUTTONS
= false;
68 public boolean CYCLE_SCROLLING
= true;
69 public boolean SCROLL_TAB_LAYOUT_IN_EDITOR
= false;
70 public boolean SHOW_CLOSE_BUTTON
= true;
71 public int EDITOR_TAB_PLACEMENT
= 1;
72 public boolean HIDE_KNOWN_EXTENSION_IN_TABS
= false;
73 public boolean SHOW_ICONS_IN_QUICK_NAVIGATION
= true;
74 public boolean CLOSE_NON_MODIFIED_FILES_FIRST
= false;
75 public boolean ACTIVATE_MRU_EDITOR_ON_CLOSE
= false;
76 public boolean ANTIALIASING_IN_EDITOR
= true;
77 public boolean MOVE_MOUSE_ON_DEFAULT_BUTTON
= false;
78 public boolean ENABLE_ALPHA_MODE
= false;
79 public int ALPHA_MODE_DELAY
= 1500;
80 public float ALPHA_MODE_RATIO
= 0.5f
;
81 public int MAX_CLIPBOARD_CONTENTS
= 5;
82 public boolean OVERRIDE_NONIDEA_LAF_FONTS
= false;
83 public boolean SHOW_ICONS_IN_MENUS
= true; // Only makes sense on MacOS
84 public boolean DISABLE_MNEMONICS
= SystemInfo
.isMac
; // IDEADEV-33409, should be disabled by default on MacOS
87 * Defines whether asterisk is shown on modified editor tab or not
89 public boolean MARK_MODIFIED_TABS_WITH_ASTERISK
= false;
94 public static final int TABS_NONE
= 0;
96 /** Invoked by reflection */
98 myListenerList
=new EventListenerList();
99 setSystemFontFaceAndSize();
102 public void addUISettingsListener(UISettingsListener listener
){
103 myListenerList
.add(UISettingsListener
.class,listener
);
107 * Notifies all registered listeners that UI settings has been changed.
109 public void fireUISettingsChanged(){
110 UISettingsListener
[] listeners
= myListenerList
.getListeners(UISettingsListener
.class);
111 for (UISettingsListener listener
: listeners
) {
112 listener
.uiSettingsChanged(this);
116 public static UISettings
getInstance() {
117 return ApplicationManager
.getApplication().getComponent(UISettings
.class);
120 public void removeUISettingsListener(UISettingsListener listener
){
121 myListenerList
.remove(UISettingsListener
.class,listener
);
124 private void setDefaultFontSettings(){
125 FONT_FACE
= "Dialog";
129 private static boolean isValidFont(final Font font
){
132 font
.canDisplay('a') &&
133 font
.canDisplay('z') &&
134 font
.canDisplay('A') &&
135 font
.canDisplay('Z') &&
136 font
.canDisplay('0') &&
137 font
.canDisplay('1');
139 catch (Exception e
) {
140 // JRE has problems working with the font. Just skip.
146 * Under Win32 it's possible to determine face and size of default fount.
148 private void setSystemFontFaceAndSize(){
149 if(FONT_FACE
== null || FONT_SIZE
<= 0){
150 if(SystemInfo
.isWindows
){
151 //noinspection HardCodedStringLiteral
152 Font font
=(Font
)Toolkit
.getDefaultToolkit().getDesktopProperty("win.messagebox.font");
154 FONT_FACE
= font
.getName();
155 FONT_SIZE
= font
.getSize();
157 setDefaultFontSettings();
159 }else{ // UNIXes go here
160 setDefaultFontSettings();
165 private static boolean hasDefaultFontSetting(final UISettings settings
) {
166 Font font
=(Font
)Toolkit
.getDefaultToolkit().getDesktopProperty("win.messagebox.font");
167 return SystemInfo
.isWindows
&& font
!= null && settings
.FONT_FACE
.equals(font
.getName()) && settings
.FONT_SIZE
== font
.getSize();
171 public UISettings
getState() {
175 public void loadState(UISettings object
) {
176 XmlSerializerUtil
.copyBean(object
, this);
178 // Check tab placement in editor
180 EDITOR_TAB_PLACEMENT
!= TABS_NONE
&&
181 EDITOR_TAB_PLACEMENT
!= SwingConstants
.TOP
&&
182 EDITOR_TAB_PLACEMENT
!= SwingConstants
.LEFT
&&
183 EDITOR_TAB_PLACEMENT
!= SwingConstants
.BOTTOM
&&
184 EDITOR_TAB_PLACEMENT
!= SwingConstants
.RIGHT
186 EDITOR_TAB_PLACEMENT
=SwingConstants
.TOP
;
188 // Check that alpha ration in in valid range
189 if(ALPHA_MODE_DELAY
<0){
190 ALPHA_MODE_DELAY
=1500;
192 if(ALPHA_MODE_RATIO
< 0.0f
||ALPHA_MODE_RATIO
>1.0f
){
193 ALPHA_MODE_RATIO
=0.5f
;
196 setSystemFontFaceAndSize();
197 // 1. Sometimes system font cannot display standard ASCI symbols. If so we have
198 // find any other suitable font withing "preferred" fonts first.
199 boolean fontIsValid
= isValidFont(new Font(FONT_FACE
, Font
.PLAIN
, FONT_SIZE
));
201 @NonNls final String
[] preferredFonts
= new String
[]{"dialog", "Arial", "Tahoma"};
202 for (String preferredFont
: preferredFonts
) {
203 if (isValidFont(new Font(preferredFont
, Font
.PLAIN
, FONT_SIZE
))) {
204 FONT_FACE
= preferredFont
;
210 // 2. If all preferred fonts are not valid in current environment
211 // we have to find first valid font (if any)
213 Font
[] fonts
= GraphicsEnvironment
.getLocalGraphicsEnvironment().getAllFonts();
214 for (Font font
: fonts
) {
215 if (isValidFont(font
)) {
216 FONT_FACE
= font
.getName();
223 if (MAX_CLIPBOARD_CONTENTS
<= 0) {
224 MAX_CLIPBOARD_CONTENTS
= 5;
228 fireUISettingsChanged();
231 public static class FontFilter
implements SerializationFilter
{
232 public boolean accepts(Accessor accessor
, Object bean
) {
233 UISettings settings
= (UISettings
)bean
;
235 return !hasDefaultFontSetting(settings
);
240 private static final boolean DONT_TOUCH_ALIASING
= "true".equalsIgnoreCase(System
.getProperty("idea.use.default.antialiasing.in.editor"));
242 public static void setupAntialiasing(final Graphics g
) {
243 if (DONT_TOUCH_ALIASING
) return;
245 Graphics2D g2d
=(Graphics2D
)g
;
246 UISettings uiSettings
=getInstance();
248 g2d
.setRenderingHint(RenderingHints
.KEY_ANTIALIASING
,RenderingHints
.VALUE_ANTIALIAS_OFF
);
249 if(uiSettings
.ANTIALIASING_IN_EDITOR
) {
250 Toolkit tk
= Toolkit
.getDefaultToolkit();
251 //noinspection HardCodedStringLiteral
252 Map map
= (Map
)tk
.getDesktopProperty("awt.font.desktophints");
254 final Object textAA
= map
.get(RenderingHints
.KEY_TEXT_ANTIALIASING
);
255 //This WILL become TRUE when Windows RDP is connected
256 if (RenderingHints
.VALUE_TEXT_ANTIALIAS_DEFAULT
.equals(textAA
)) {
257 g2d
.setRenderingHint(RenderingHints
.KEY_TEXT_ANTIALIASING
,RenderingHints
.VALUE_TEXT_ANTIALIAS_DEFAULT
);
260 g2d
.addRenderingHints(map
);
264 g2d
.setRenderingHint(RenderingHints
.KEY_TEXT_ANTIALIASING
,RenderingHints
.VALUE_TEXT_ANTIALIAS_ON
);
268 g2d
.setRenderingHint(RenderingHints
.KEY_TEXT_ANTIALIASING
,RenderingHints
.VALUE_TEXT_ANTIALIAS_OFF
);
273 public File
[] getExportFiles() {
274 return new File
[]{PathManager
.getOptionsFile("ui.lnf")};
278 public String
getPresentableName() {
279 return IdeBundle
.message("ui.settings");
284 public String
getComponentName() {
288 public void initComponent() {
292 public void disposeComponent() {