2 * Copyright 2000-2009 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.
19 import com
.intellij
.util
.ui
.UIUtil
;
20 import org
.jetbrains
.annotations
.NonNls
;
21 import org
.jetbrains
.annotations
.Nullable
;
22 import org
.jetbrains
.annotations
.PropertyKey
;
24 import java
.lang
.ref
.Reference
;
25 import java
.lang
.ref
.SoftReference
;
26 import java
.text
.MessageFormat
;
27 import java
.util
.MissingResourceException
;
28 import java
.util
.ResourceBundle
;
31 * Created by IntelliJ IDEA.
35 * To change this template use File | Settings | File Templates.
37 public class CommonBundle
{
38 @NonNls private static final String BUNDLE
= "messages.CommonBundle";
39 private static Reference
<ResourceBundle
> ourBundle
;
40 public static boolean assertKeyIsFound
= false;
42 private CommonBundle() {}
44 public static String
message(@PropertyKey(resourceBundle
= BUNDLE
) String key
, Object
... params
) {
45 return message(getCommonBundle(), key
, params
);
48 private static ResourceBundle
getCommonBundle() {
49 ResourceBundle bundle
= null;
50 if (ourBundle
!= null) bundle
= ourBundle
.get();
52 bundle
= ResourceBundle
.getBundle(BUNDLE
);
53 ourBundle
= new SoftReference
<ResourceBundle
>(bundle
);
58 public static String
messageOrDefault(@Nullable final ResourceBundle bundle
, final String key
, final @Nullable String defaultValue
, final Object
... params
) {
59 if (bundle
== null) return defaultValue
;
63 value
= bundle
.getString(key
);
65 catch (MissingResourceException e
) {
66 if (defaultValue
!= null) {
69 value
= "!" + key
+ "!";
70 if (assertKeyIsFound
) {
71 assert false: key
+ " is not found";
76 value
= UIUtil
.replaceMnemonicAmpersand(value
);
78 if (params
.length
> 0 && value
.indexOf('{')>=0) {
79 return MessageFormat
.format(value
, params
);
85 public static String
message(final ResourceBundle bundle
, final String key
, final Object
... params
) {
86 return messageOrDefault(bundle
, key
, null, params
);
89 public static String
getCancelButtonText() {
90 return message("button.cancel");
93 public static String
getBackgroundButtonText() {
94 return message("button.background");
97 public static String
getHelpButtonText() {
98 return message("button.help");
101 public static String
getErrorTitle() {
102 return message("title.error");
105 public static String
getWarningTitle() {
106 return message("title.warning");
109 public static String
getLoadingTreeNodeText() {
110 return CommonBundle
.message("tree.node.loading");
113 public static String
getOkButtonText(){
114 return message("button.ok");
117 public static String
getYesButtonText(){
118 return CommonBundle
.message("button.yes");
121 public static String
getNoButtonText(){
122 return CommonBundle
.message("button.no");
125 public static String
getContinueButtonText(){
126 return CommonBundle
.message("button.continue");
130 public static String
getYesForAllButtonText() {
131 return CommonBundle
.message("button.yes.for.all");
134 public static String
getCloseButtonText() {
135 return CommonBundle
.message("button.close");
138 public static String
getNoForAllButtonText() {
139 return CommonBundle
.message("button.no.for.all");
142 public static String
getApplyButtonText() {
143 return CommonBundle
.message("button.apply");