nice dotted border
[fedora-idea.git] / platform / util / src / com / intellij / CommonBundle.java
blobd52f6b91a1bf3812ff554402dbc4949b4904bee2
1 /*
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.
17 package com.intellij;
19 import com.intellij.util.ui.UIUtil;
20 import org.jetbrains.annotations.NonNls;
21 import org.jetbrains.annotations.NotNull;
22 import org.jetbrains.annotations.Nullable;
23 import org.jetbrains.annotations.PropertyKey;
25 import java.lang.ref.Reference;
26 import java.lang.ref.SoftReference;
27 import java.text.MessageFormat;
28 import java.util.MissingResourceException;
29 import java.util.ResourceBundle;
31 /**
32 * @author yole
34 public class CommonBundle {
35 @NonNls private static final String BUNDLE = "messages.CommonBundle";
36 private static Reference<ResourceBundle> ourBundle;
37 public static boolean assertKeyIsFound = false;
39 private CommonBundle() {}
41 public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {
42 return message(getCommonBundle(), key, params);
45 private static ResourceBundle getCommonBundle() {
46 ResourceBundle bundle = null;
47 if (ourBundle != null) bundle = ourBundle.get();
48 if (bundle == null) {
49 bundle = ResourceBundle.getBundle(BUNDLE);
50 ourBundle = new SoftReference<ResourceBundle>(bundle);
52 return bundle;
55 public static String messageOrDefault(@Nullable final ResourceBundle bundle, final String key, @Nullable final String defaultValue, final Object... params) {
56 if (bundle == null) return defaultValue;
58 String value;
59 try {
60 value = bundle.getString(key);
62 catch (MissingResourceException e) {
63 if (defaultValue != null) {
64 value = defaultValue;
65 } else {
66 value = "!" + key + "!";
67 if (assertKeyIsFound) {
68 assert false: key + " is not found in "+BUNDLE;
73 value = UIUtil.replaceMnemonicAmpersand(value);
75 if (params.length > 0 && value.indexOf('{')>=0) {
76 return MessageFormat.format(value, params);
79 return value;
82 public static String message(final ResourceBundle bundle, final String key, final Object... params) {
83 return messageOrDefault(bundle, key, null, params);
86 @NotNull
87 public static String getCancelButtonText() {
88 return message("button.cancel");
91 public static String getBackgroundButtonText() {
92 return message("button.background");
95 public static String getHelpButtonText() {
96 return message("button.help");
99 public static String getErrorTitle() {
100 return message("title.error");
103 public static String getWarningTitle() {
104 return message("title.warning");
107 public static String getLoadingTreeNodeText() {
108 return message("tree.node.loading");
111 public static String getOkButtonText(){
112 return message("button.ok");
115 public static String getYesButtonText(){
116 return message("button.yes");
119 public static String getNoButtonText(){
120 return message("button.no");
123 public static String getContinueButtonText(){
124 return message("button.continue");
128 public static String getYesForAllButtonText() {
129 return message("button.yes.for.all");
132 public static String getCloseButtonText() {
133 return message("button.close");
136 public static String getNoForAllButtonText() {
137 return message("button.no.for.all");
140 public static String getApplyButtonText() {
141 return message("button.apply");