开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from Stefan/Java8Source
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
master
develop
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (2)
master
develop
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
master
develop
Java8Source
/
src
/
javax
/
swing
/
UIDefaults.java
Java8Source
/
src
/
javax
/
swing
/
UIDefaults.java
UIDefaults.java 47.63 KB
一键复制 编辑 原始数据 按行查看 历史
Stefan 提交于 2020年08月11日 23:17 +08:00 . 初始化
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package javax.swing;
import javax.swing.plaf.ComponentUI;
import javax.swing.border.*;
import javax.swing.event.SwingPropertyChangeSupport;
import java.lang.reflect.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.ResourceBundle;
import java.util.ResourceBundle.Control;
import java.util.Locale;
import java.util.Vector;
import java.util.MissingResourceException;
import java.awt.Font;
import java.awt.Color;
import java.awt.Insets;
import java.awt.Dimension;
import java.beans.PropertyChangeListener;
import java.security.AccessController;
import java.security.AccessControlContext;
import java.security.PrivilegedAction;
import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;
import sun.swing.SwingUtilities2;
import sun.util.CoreResourceBundleControl;
/**
* A table of defaults for Swing components. Applications can set/get
* default values via the <code>UIManager</code>.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans&trade;
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @see UIManager
* @author Hans Muller
*/
public class UIDefaults extends Hashtable<Object,Object>
{
private static final Object PENDING = new Object();
private SwingPropertyChangeSupport changeSupport;
private Vector<String> resourceBundles;
private Locale defaultLocale = Locale.getDefault();
/**
* Maps from a Locale to a cached Map of the ResourceBundle. This is done
* so as to avoid an exception being thrown when a value is asked for.
* Access to this should be done while holding a lock on the
* UIDefaults, eg synchronized(this).
*/
private Map<Locale, Map<String, Object>> resourceCache;
/**
* Creates an empty defaults table.
*/
public UIDefaults() {
this(700, .75f);
}
/**
* Creates an empty defaults table with the specified initial capacity and
* load factor.
*
* @param initialCapacity the initial capacity of the defaults table
* @param loadFactor the load factor of the defaults table
* @see java.util.Hashtable
* @since 1.6
*/
public UIDefaults(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
resourceCache = new HashMap<Locale, Map<String, Object>>();
}
/**
* Creates a defaults table initialized with the specified
* key/value pairs. For example:
* <pre>
Object[] uiDefaults = {
"Font", new Font("Dialog", Font.BOLD, 12),
"Color", Color.red,
"five", new Integer(5)
}
UIDefaults myDefaults = new UIDefaults(uiDefaults);
* </pre>
* @param keyValueList an array of objects containing the key/value
* pairs
*/
public UIDefaults(Object[] keyValueList) {
super(keyValueList.length / 2);
for(int i = 0; i < keyValueList.length; i += 2) {
super.put(keyValueList[i], keyValueList[i + 1]);
}
}
/**
* Returns the value for key. If the value is a
* <code>UIDefaults.LazyValue</code> then the real
* value is computed with <code>LazyValue.createValue()</code>,
* the table entry is replaced, and the real value is returned.
* If the value is an <code>UIDefaults.ActiveValue</code>
* the table entry is not replaced - the value is computed
* with <code>ActiveValue.createValue()</code> for each
* <code>get()</code> call.
*
* If the key is not found in the table then it is searched for in the list
* of resource bundles maintained by this object. The resource bundles are
* searched most recently added first using the locale returned by
* <code>getDefaultLocale</code>. <code>LazyValues</code> and
* <code>ActiveValues</code> are not supported in the resource bundles.
*
* @param key the desired key
* @return the value for <code>key</code>
* @see LazyValue
* @see ActiveValue
* @see java.util.Hashtable#get
* @see #getDefaultLocale
* @see #addResourceBundle
* @since 1.4
*/
public Object get(Object key) {
Object value = getFromHashtable( key );
return (value != null) ? value : getFromResourceBundle(key, null);
}
/**
* Looks up up the given key in our Hashtable and resolves LazyValues
* or ActiveValues.
*/
private Object getFromHashtable(final Object key) {
/* Quickly handle the common case, without grabbing
* a lock.
*/
Object value = super.get(key);
if ((value != PENDING) &&
!(value instanceof ActiveValue) &&
!(value instanceof LazyValue)) {
return value;
}
/* If the LazyValue for key is being constructed by another
* thread then wait and then return the new value, otherwise drop
* the lock and construct the ActiveValue or the LazyValue.
* We use the special value PENDING to mark LazyValues that
* are being constructed.
*/
synchronized(this) {
value = super.get(key);
if (value == PENDING) {
do {
try {
this.wait();
}
catch (InterruptedException e) {
}
value = super.get(key);
}
while(value == PENDING);
return value;
}
else if (value instanceof LazyValue) {
super.put(key, PENDING);
}
else if (!(value instanceof ActiveValue)) {
return value;
}
}
/* At this point we know that the value of key was
* a LazyValue or an ActiveValue.
*/
if (value instanceof LazyValue) {
try {
/* If an exception is thrown we'll just put the LazyValue
* back in the table.
*/
value = ((LazyValue)value).createValue(this);
}
finally {
synchronized(this) {
if (value == null) {
super.remove(key);
}
else {
super.put(key, value);
}
this.notifyAll();
}
}
}
else {
value = ((ActiveValue)value).createValue(this);
}
return value;
}
/**
* Returns the value for key associated with the given locale.
* If the value is a <code>UIDefaults.LazyValue</code> then the real
* value is computed with <code>LazyValue.createValue()</code>,
* the table entry is replaced, and the real value is returned.
* If the value is an <code>UIDefaults.ActiveValue</code>
* the table entry is not replaced - the value is computed
* with <code>ActiveValue.createValue()</code> for each
* <code>get()</code> call.
*
* If the key is not found in the table then it is searched for in the list
* of resource bundles maintained by this object. The resource bundles are
* searched most recently added first using the given locale.
* <code>LazyValues</code> and <code>ActiveValues</code> are not supported
* in the resource bundles.
*
* @param key the desired key
* @param l the desired <code>locale</code>
* @return the value for <code>key</code>
* @see LazyValue
* @see ActiveValue
* @see java.util.Hashtable#get
* @see #addResourceBundle
* @since 1.4
*/
public Object get(Object key, Locale l) {
Object value = getFromHashtable( key );
return (value != null) ? value : getFromResourceBundle(key, l);
}
/**
* Looks up given key in our resource bundles.
*/
private Object getFromResourceBundle(Object key, Locale l) {
if( resourceBundles == null ||
resourceBundles.isEmpty() ||
!(key instanceof String) ) {
return null;
}
// A null locale means use the default locale.
if( l == null ) {
if( defaultLocale == null )
return null;
else
l = defaultLocale;
}
synchronized(this) {
return getResourceCache(l).get(key);
}
}
/**
* Returns a Map of the known resources for the given locale.
*/
private Map<String, Object> getResourceCache(Locale l) {
Map<String, Object> values = resourceCache.get(l);
if (values == null) {
values = new TextAndMnemonicHashMap();
for (int i=resourceBundles.size()-1; i >= 0; i--) {
String bundleName = resourceBundles.get(i);
try {
Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
ResourceBundle b;
if (c != null) {
b = ResourceBundle.getBundle(bundleName, l, c);
} else {
b = ResourceBundle.getBundle(bundleName, l,
ClassLoader.getSystemClassLoader());
}
Enumeration keys = b.getKeys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
if (values.get(key) == null) {
Object value = b.getObject(key);
values.put(key, value);
}
}
} catch( MissingResourceException mre ) {
// Keep looking
}
}
resourceCache.put(l, values);
}
return values;
}
/**
* Sets the value of <code>key</code> to <code>value</code> for all locales.
* If <code>key</code> is a string and the new value isn't
* equal to the old one, fire a <code>PropertyChangeEvent</code>.
* If value is <code>null</code>, the key is removed from the table.
*
* @param key the unique <code>Object</code> who's value will be used
* to retrieve the data value associated with it
* @param value the new <code>Object</code> to store as data under
* that key
* @return the previous <code>Object</code> value, or <code>null</code>
* @see #putDefaults
* @see java.util.Hashtable#put
*/
public Object put(Object key, Object value) {
Object oldValue = (value == null) ? super.remove(key) : super.put(key, value);
if (key instanceof String) {
firePropertyChange((String)key, oldValue, value);
}
return oldValue;
}
/**
* Puts all of the key/value pairs in the database and
* unconditionally generates one <code>PropertyChangeEvent</code>.
* The events oldValue and newValue will be <code>null</code> and its
* <code>propertyName</code> will be "UIDefaults". The key/value pairs are
* added for all locales.
*
* @param keyValueList an array of key/value pairs
* @see #put
* @see java.util.Hashtable#put
*/
public void putDefaults(Object[] keyValueList) {
for(int i = 0, max = keyValueList.length; i < max; i += 2) {
Object value = keyValueList[i + 1];
if (value == null) {
super.remove(keyValueList[i]);
}
else {
super.put(keyValueList[i], value);
}
}
firePropertyChange("UIDefaults", null, null);
}
/**
* If the value of <code>key</code> is a <code>Font</code> return it,
* otherwise return <code>null</code>.
* @param key the desired key
* @return if the value for <code>key</code> is a <code>Font</code>,
* return the <code>Font</code> object; otherwise return
* <code>null</code>
*/
public Font getFont(Object key) {
Object value = get(key);
return (value instanceof Font) ? (Font)value : null;
}
/**
* If the value of <code>key</code> for the given <code>Locale</code>
* is a <code>Font</code> return it, otherwise return <code>null</code>.
* @param key the desired key
* @param l the desired locale
* @return if the value for <code>key</code> and <code>Locale</code>
* is a <code>Font</code>,
* return the <code>Font</code> object; otherwise return
* <code>null</code>
* @since 1.4
*/
public Font getFont(Object key, Locale l) {
Object value = get(key,l);
return (value instanceof Font) ? (Font)value : null;
}
/**
* If the value of <code>key</code> is a <code>Color</code> return it,
* otherwise return <code>null</code>.
* @param key the desired key
* @return if the value for <code>key</code> is a <code>Color</code>,
* return the <code>Color</code> object; otherwise return
* <code>null</code>
*/
public Color getColor(Object key) {
Object value = get(key);
return (value instanceof Color) ? (Color)value : null;
}
/**
* If the value of <code>key</code> for the given <code>Locale</code>
* is a <code>Color</code> return it, otherwise return <code>null</code>.
* @param key the desired key
* @param l the desired locale
* @return if the value for <code>key</code> and <code>Locale</code>
* is a <code>Color</code>,
* return the <code>Color</code> object; otherwise return
* <code>null</code>
* @since 1.4
*/
public Color getColor(Object key, Locale l) {
Object value = get(key,l);
return (value instanceof Color) ? (Color)value : null;
}
/**
* If the value of <code>key</code> is an <code>Icon</code> return it,
* otherwise return <code>null</code>.
* @param key the desired key
* @return if the value for <code>key</code> is an <code>Icon</code>,
* return the <code>Icon</code> object; otherwise return
* <code>null</code>
*/
public Icon getIcon(Object key) {
Object value = get(key);
return (value instanceof Icon) ? (Icon)value : null;
}
/**
* If the value of <code>key</code> for the given <code>Locale</code>
* is an <code>Icon</code> return it, otherwise return <code>null</code>.
* @param key the desired key
* @param l the desired locale
* @return if the value for <code>key</code> and <code>Locale</code>
* is an <code>Icon</code>,
* return the <code>Icon</code> object; otherwise return
* <code>null</code>
* @since 1.4
*/
public Icon getIcon(Object key, Locale l) {
Object value = get(key,l);
return (value instanceof Icon) ? (Icon)value : null;
}
/**
* If the value of <code>key</code> is a <code>Border</code> return it,
* otherwise return <code>null</code>.
* @param key the desired key
* @return if the value for <code>key</code> is a <code>Border</code>,
* return the <code>Border</code> object; otherwise return
* <code>null</code>
*/
public Border getBorder(Object key) {
Object value = get(key);
return (value instanceof Border) ? (Border)value : null;
}
/**
* If the value of <code>key</code> for the given <code>Locale</code>
* is a <code>Border</code> return it, otherwise return <code>null</code>.
* @param key the desired key
* @param l the desired locale
* @return if the value for <code>key</code> and <code>Locale</code>
* is a <code>Border</code>,
* return the <code>Border</code> object; otherwise return
* <code>null</code>
* @since 1.4
*/
public Border getBorder(Object key, Locale l) {
Object value = get(key,l);
return (value instanceof Border) ? (Border)value : null;
}
/**
* If the value of <code>key</code> is a <code>String</code> return it,
* otherwise return <code>null</code>.
* @param key the desired key
* @return if the value for <code>key</code> is a <code>String</code>,
* return the <code>String</code> object; otherwise return
* <code>null</code>
*/
public String getString(Object key) {
Object value = get(key);
return (value instanceof String) ? (String)value : null;
}
/**
* If the value of <code>key</code> for the given <code>Locale</code>
* is a <code>String</code> return it, otherwise return <code>null</code>.
* @param key the desired key
* @param l the desired <code>Locale</code>
* @return if the value for <code>key</code> for the given
* <code>Locale</code> is a <code>String</code>,
* return the <code>String</code> object; otherwise return
* <code>null</code>
* @since 1.4
*/
public String getString(Object key, Locale l) {
Object value = get(key,l);
return (value instanceof String) ? (String)value : null;
}
/**
* If the value of <code>key</code> is an <code>Integer</code> return its
* integer value, otherwise return 0.
* @param key the desired key
* @return if the value for <code>key</code> is an <code>Integer</code>,
* return its value, otherwise return 0
*/
public int getInt(Object key) {
Object value = get(key);
return (value instanceof Integer) ? ((Integer)value).intValue() : 0;
}
/**
* If the value of <code>key</code> for the given <code>Locale</code>
* is an <code>Integer</code> return its integer value, otherwise return 0.
* @param key the desired key
* @param l the desired locale
* @return if the value for <code>key</code> and <code>Locale</code>
* is an <code>Integer</code>,
* return its value, otherwise return 0
* @since 1.4
*/
public int getInt(Object key, Locale l) {
Object value = get(key,l);
return (value instanceof Integer) ? ((Integer)value).intValue() : 0;
}
/**
* If the value of <code>key</code> is boolean, return the
* boolean value, otherwise return false.
*
* @param key an <code>Object</code> specifying the key for the desired boolean value
* @return if the value of <code>key</code> is boolean, return the
* boolean value, otherwise return false.
* @since 1.4
*/
public boolean getBoolean(Object key) {
Object value = get(key);
return (value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
}
/**
* If the value of <code>key</code> for the given <code>Locale</code>
* is boolean, return the boolean value, otherwise return false.
*
* @param key an <code>Object</code> specifying the key for the desired boolean value
* @param l the desired locale
* @return if the value for <code>key</code> and <code>Locale</code>
* is boolean, return the
* boolean value, otherwise return false.
* @since 1.4
*/
public boolean getBoolean(Object key, Locale l) {
Object value = get(key,l);
return (value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
}
/**
* If the value of <code>key</code> is an <code>Insets</code> return it,
* otherwise return <code>null</code>.
* @param key the desired key
* @return if the value for <code>key</code> is an <code>Insets</code>,
* return the <code>Insets</code> object; otherwise return
* <code>null</code>
*/
public Insets getInsets(Object key) {
Object value = get(key);
return (value instanceof Insets) ? (Insets)value : null;
}
/**
* If the value of <code>key</code> for the given <code>Locale</code>
* is an <code>Insets</code> return it, otherwise return <code>null</code>.
* @param key the desired key
* @param l the desired locale
* @return if the value for <code>key</code> and <code>Locale</code>
* is an <code>Insets</code>,
* return the <code>Insets</code> object; otherwise return
* <code>null</code>
* @since 1.4
*/
public Insets getInsets(Object key, Locale l) {
Object value = get(key,l);
return (value instanceof Insets) ? (Insets)value : null;
}
/**
* If the value of <code>key</code> is a <code>Dimension</code> return it,
* otherwise return <code>null</code>.
* @param key the desired key
* @return if the value for <code>key</code> is a <code>Dimension</code>,
* return the <code>Dimension</code> object; otherwise return
* <code>null</code>
*/
public Dimension getDimension(Object key) {
Object value = get(key);
return (value instanceof Dimension) ? (Dimension)value : null;
}
/**
* If the value of <code>key</code> for the given <code>Locale</code>
* is a <code>Dimension</code> return it, otherwise return <code>null</code>.
* @param key the desired key
* @param l the desired locale
* @return if the value for <code>key</code> and <code>Locale</code>
* is a <code>Dimension</code>,
* return the <code>Dimension</code> object; otherwise return
* <code>null</code>
* @since 1.4
*/
public Dimension getDimension(Object key, Locale l) {
Object value = get(key,l);
return (value instanceof Dimension) ? (Dimension)value : null;
}
/**
* The value of <code>get(uidClassID)</code> must be the
* <code>String</code> name of a
* class that implements the corresponding <code>ComponentUI</code>
* class. If the class hasn't been loaded before, this method looks
* up the class with <code>uiClassLoader.loadClass()</code> if a non
* <code>null</code>
* class loader is provided, <code>classForName()</code> otherwise.
* <p>
* If a mapping for <code>uiClassID</code> exists or if the specified
* class can't be found, return <code>null</code>.
* <p>
* This method is used by <code>getUI</code>, it's usually
* not necessary to call it directly.
*
* @param uiClassID a string containing the class ID
* @param uiClassLoader the object which will load the class
* @return the value of <code>Class.forName(get(uidClassID))</code>
* @see #getUI
*/
public Class<? extends ComponentUI>
getUIClass(String uiClassID, ClassLoader uiClassLoader)
{
try {
String className = (String)get(uiClassID);
if (className != null) {
ReflectUtil.checkPackageAccess(className);
Class cls = (Class)get(className);
if (cls == null) {
if (uiClassLoader == null) {
cls = SwingUtilities.loadSystemClass(className);
}
else {
cls = uiClassLoader.loadClass(className);
}
if (cls != null) {
// Save lookup for future use, as forName is slow.
put(className, cls);
}
}
return cls;
}
}
catch (ClassNotFoundException e) {
return null;
}
catch (ClassCastException e) {
return null;
}
return null;
}
/**
* Returns the L&amp;F class that renders this component.
*
* @param uiClassID a string containing the class ID
* @return the Class object returned by
* <code>getUIClass(uiClassID, null)</code>
*/
public Class<? extends ComponentUI> getUIClass(String uiClassID) {
return getUIClass(uiClassID, null);
}
/**
* If <code>getUI()</code> fails for any reason,
* it calls this method before returning <code>null</code>.
* Subclasses may choose to do more or less here.
*
* @param msg message string to print
* @see #getUI
*/
protected void getUIError(String msg) {
System.err.println("UIDefaults.getUI() failed: " + msg);
try {
throw new Error();
}
catch (Throwable e) {
e.printStackTrace();
}
}
/**
* Creates an <code>ComponentUI</code> implementation for the
* specified component. In other words create the look
* and feel specific delegate object for <code>target</code>.
* This is done in two steps:
* <ul>
* <li> Look up the name of the <code>ComponentUI</code> implementation
* class under the value returned by <code>target.getUIClassID()</code>.
* <li> Use the implementation classes static <code>createUI()</code>
* method to construct a look and feel delegate.
* </ul>
* @param target the <code>JComponent</code> which needs a UI
* @return the <code>ComponentUI</code> object
*/
public ComponentUI getUI(JComponent target) {
Object cl = get("ClassLoader");
ClassLoader uiClassLoader =
(cl != null) ? (ClassLoader)cl : target.getClass().getClassLoader();
Class<? extends ComponentUI> uiClass = getUIClass(target.getUIClassID(), uiClassLoader);
Object uiObject = null;
if (uiClass == null) {
getUIError("no ComponentUI class for: " + target);
}
else {
try {
Method m = (Method)get(uiClass);
if (m == null) {
m = uiClass.getMethod("createUI", new Class[]{JComponent.class});
put(uiClass, m);
}
uiObject = MethodUtil.invoke(m, null, new Object[]{target});
}
catch (NoSuchMethodException e) {
getUIError("static createUI() method not found in " + uiClass);
}
catch (Exception e) {
getUIError("createUI() failed for " + target + " " + e);
}
}
return (ComponentUI)uiObject;
}
/**
* Adds a <code>PropertyChangeListener</code> to the listener list.
* The listener is registered for all properties.
* <p>
* A <code>PropertyChangeEvent</code> will get fired whenever a default
* is changed.
*
* @param listener the <code>PropertyChangeListener</code> to be added
* @see java.beans.PropertyChangeSupport
*/
public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
if (changeSupport == null) {
changeSupport = new SwingPropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(listener);
}
/**
* Removes a <code>PropertyChangeListener</code> from the listener list.
* This removes a <code>PropertyChangeListener</code> that was registered
* for all properties.
*
* @param listener the <code>PropertyChangeListener</code> to be removed
* @see java.beans.PropertyChangeSupport
*/
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
if (changeSupport != null) {
changeSupport.removePropertyChangeListener(listener);
}
}
/**
* Returns an array of all the <code>PropertyChangeListener</code>s added
* to this UIDefaults with addPropertyChangeListener().
*
* @return all of the <code>PropertyChangeListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
if (changeSupport == null) {
return new PropertyChangeListener[0];
}
return changeSupport.getPropertyChangeListeners();
}
/**
* Support for reporting bound property changes. If oldValue and
* newValue are not equal and the <code>PropertyChangeEvent</code>x
* listener list isn't empty, then fire a
* <code>PropertyChange</code> event to each listener.
*
* @param propertyName the programmatic name of the property
* that was changed
* @param oldValue the old value of the property
* @param newValue the new value of the property
* @see java.beans.PropertyChangeSupport
*/
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
if (changeSupport != null) {
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
}
/**
* Adds a resource bundle to the list of resource bundles that are
* searched for localized values. Resource bundles are searched in the
* reverse order they were added. In other words, the most recently added
* bundle is searched first.
*
* @param bundleName the base name of the resource bundle to be added
* @see java.util.ResourceBundle
* @see #removeResourceBundle
* @since 1.4
*/
public synchronized void addResourceBundle( String bundleName ) {
if( bundleName == null ) {
return;
}
if( resourceBundles == null ) {
resourceBundles = new Vector<String>(5);
}
if (!resourceBundles.contains(bundleName)) {
resourceBundles.add( bundleName );
resourceCache.clear();
}
}
/**
* Removes a resource bundle from the list of resource bundles that are
* searched for localized defaults.
*
* @param bundleName the base name of the resource bundle to be removed
* @see java.util.ResourceBundle
* @see #addResourceBundle
* @since 1.4
*/
public synchronized void removeResourceBundle( String bundleName ) {
if( resourceBundles != null ) {
resourceBundles.remove( bundleName );
}
resourceCache.clear();
}
/**
* Sets the default locale. The default locale is used in retrieving
* localized values via <code>get</code> methods that do not take a
* locale argument. As of release 1.4, Swing UI objects should retrieve
* localized values using the locale of their component rather than the
* default locale. The default locale exists to provide compatibility with
* pre 1.4 behaviour.
*
* @param l the new default locale
* @see #getDefaultLocale
* @see #get(Object)
* @see #get(Object,Locale)
* @since 1.4
*/
public void setDefaultLocale( Locale l ) {
defaultLocale = l;
}
/**
* Returns the default locale. The default locale is used in retrieving
* localized values via <code>get</code> methods that do not take a
* locale argument. As of release 1.4, Swing UI objects should retrieve
* localized values using the locale of their component rather than the
* default locale. The default locale exists to provide compatibility with
* pre 1.4 behaviour.
*
* @return the default locale
* @see #setDefaultLocale
* @see #get(Object)
* @see #get(Object,Locale)
* @since 1.4
*/
public Locale getDefaultLocale() {
return defaultLocale;
}
/**
* This class enables one to store an entry in the defaults
* table that isn't constructed until the first time it's
* looked up with one of the <code>getXXX(key)</code> methods.
* Lazy values are useful for defaults that are expensive
* to construct or are seldom retrieved. The first time
* a <code>LazyValue</code> is retrieved its "real value" is computed
* by calling <code>LazyValue.createValue()</code> and the real
* value is used to replace the <code>LazyValue</code> in the
* <code>UIDefaults</code>
* table. Subsequent lookups for the same key return
* the real value. Here's an example of a <code>LazyValue</code>
* that constructs a <code>Border</code>:
* <pre>
* Object borderLazyValue = new UIDefaults.LazyValue() {
* public Object createValue(UIDefaults table) {
* return new BorderFactory.createLoweredBevelBorder();
* }
* };
*
* uiDefaultsTable.put("MyBorder", borderLazyValue);
* </pre>
*
* @see UIDefaults#get
*/
public interface LazyValue {
/**
* Creates the actual value retrieved from the <code>UIDefaults</code>
* table. When an object that implements this interface is
* retrieved from the table, this method is used to create
* the real value, which is then stored in the table and
* returned to the calling method.
*
* @param table a <code>UIDefaults</code> table
* @return the created <code>Object</code>
*/
Object createValue(UIDefaults table);
}
/**
* This class enables one to store an entry in the defaults
* table that's constructed each time it's looked up with one of
* the <code>getXXX(key)</code> methods. Here's an example of
* an <code>ActiveValue</code> that constructs a
* <code>DefaultListCellRenderer</code>:
* <pre>
* Object cellRendererActiveValue = new UIDefaults.ActiveValue() {
* public Object createValue(UIDefaults table) {
* return new DefaultListCellRenderer();
* }
* };
*
* uiDefaultsTable.put("MyRenderer", cellRendererActiveValue);
* </pre>
*
* @see UIDefaults#get
*/
public interface ActiveValue {
/**
* Creates the value retrieved from the <code>UIDefaults</code> table.
* The object is created each time it is accessed.
*
* @param table a <code>UIDefaults</code> table
* @return the created <code>Object</code>
*/
Object createValue(UIDefaults table);
}
/**
* This class provides an implementation of <code>LazyValue</code>
* which can be
* used to delay loading of the Class for the instance to be created.
* It also avoids creation of an anonymous inner class for the
* <code>LazyValue</code>
* subclass. Both of these improve performance at the time that a
* a Look and Feel is loaded, at the cost of a slight performance
* reduction the first time <code>createValue</code> is called
* (since Reflection APIs are used).
* @since 1.3
*/
public static class ProxyLazyValue implements LazyValue {
private AccessControlContext acc;
private String className;
private String methodName;
private Object[] args;
/**
* Creates a <code>LazyValue</code> which will construct an instance
* when asked.
*
* @param c a <code>String</code> specifying the classname
* of the instance to be created on demand
*/
public ProxyLazyValue(String c) {
this(c, (String)null);
}
/**
* Creates a <code>LazyValue</code> which will construct an instance
* when asked.
*
* @param c a <code>String</code> specifying the classname of
* the class
* containing a static method to be called for
* instance creation
* @param m a <code>String</code> specifying the static
* method to be called on class c
*/
public ProxyLazyValue(String c, String m) {
this(c, m, null);
}
/**
* Creates a <code>LazyValue</code> which will construct an instance
* when asked.
*
* @param c a <code>String</code> specifying the classname
* of the instance to be created on demand
* @param o an array of <code>Objects</code> to be passed as
* paramaters to the constructor in class c
*/
public ProxyLazyValue(String c, Object[] o) {
this(c, null, o);
}
/**
* Creates a <code>LazyValue</code> which will construct an instance
* when asked.
*
* @param c a <code>String</code> specifying the classname
* of the class
* containing a static method to be called for
* instance creation.
* @param m a <code>String</code> specifying the static method
* to be called on class c
* @param o an array of <code>Objects</code> to be passed as
* paramaters to the static method in class c
*/
public ProxyLazyValue(String c, String m, Object[] o) {
acc = AccessController.getContext();
className = c;
methodName = m;
if (o != null) {
args = o.clone();
}
}
/**
* Creates the value retrieved from the <code>UIDefaults</code> table.
* The object is created each time it is accessed.
*
* @param table a <code>UIDefaults</code> table
* @return the created <code>Object</code>
*/
public Object createValue(final UIDefaults table) {
// In order to pick up the security policy in effect at the
// time of creation we use a doPrivileged with the
// AccessControlContext that was in place when this was created.
if (acc == null && System.getSecurityManager() != null) {
throw new SecurityException("null AccessControlContext");
}
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
try {
Class<?> c;
Object cl;
// See if we should use a separate ClassLoader
if (table == null || !((cl = table.get("ClassLoader"))
instanceof ClassLoader)) {
cl = Thread.currentThread().
getContextClassLoader();
if (cl == null) {
// Fallback to the system class loader.
cl = ClassLoader.getSystemClassLoader();
}
}
ReflectUtil.checkPackageAccess(className);
c = Class.forName(className, true, (ClassLoader)cl);
SwingUtilities2.checkAccess(c.getModifiers());
if (methodName != null) {
Class[] types = getClassArray(args);
Method m = c.getMethod(methodName, types);
return MethodUtil.invoke(m, c, args);
} else {
Class[] types = getClassArray(args);
Constructor constructor = c.getConstructor(types);
SwingUtilities2.checkAccess(constructor.getModifiers());
return constructor.newInstance(args);
}
} catch(Exception e) {
// Ideally we would throw an exception, unfortunately
// often times there are errors as an initial look and
// feel is loaded before one can be switched. Perhaps a
// flag should be added for debugging, so that if true
// the exception would be thrown.
}
return null;
}
}, acc);
}
/*
* Coerce the array of class types provided into one which
* looks the way the Reflection APIs expect. This is done
* by substituting primitive types for their Object counterparts,
* and superclasses for subclasses used to add the
* <code>UIResource</code> tag.
*/
private Class[] getClassArray(Object[] args) {
Class[] types = null;
if (args!=null) {
types = new Class[args.length];
for (int i = 0; i< args.length; i++) {
/* PENDING(ges): At present only the primitive types
used are handled correctly; this should eventually
handle all primitive types */
if (args[i] instanceof java.lang.Integer) {
types[i]=Integer.TYPE;
} else if (args[i] instanceof java.lang.Boolean) {
types[i]=Boolean.TYPE;
} else if (args[i] instanceof javax.swing.plaf.ColorUIResource) {
/* PENDING(ges) Currently the Reflection APIs do not
search superclasses of parameters supplied for
constructor/method lookup. Since we only have
one case where this is needed, we substitute
directly instead of adding a massive amount
of mechanism for this. Eventually this will
probably need to handle the general case as well.
*/
types[i]=java.awt.Color.class;
} else {
types[i]=args[i].getClass();
}
}
}
return types;
}
private String printArgs(Object[] array) {
String s = "{";
if (array !=null) {
for (int i = 0 ; i < array.length-1; i++) {
s = s.concat(array[i] + ",");
}
s = s.concat(array[array.length-1] + "}");
} else {
s = s.concat("}");
}
return s;
}
}
/**
* <code>LazyInputMap</code> will create a <code>InputMap</code>
* in its <code>createValue</code>
* method. The bindings are passed in in the constructor.
* The bindings are an array with
* the even number entries being string <code>KeyStrokes</code>
* (eg "alt SPACE") and
* the odd number entries being the value to use in the
* <code>InputMap</code> (and the key in the <code>ActionMap</code>).
* @since 1.3
*/
public static class LazyInputMap implements LazyValue {
/** Key bindings are registered under. */
private Object[] bindings;
public LazyInputMap(Object[] bindings) {
this.bindings = bindings;
}
/**
* Creates an <code>InputMap</code> with the bindings that are
* passed in.
*
* @param table a <code>UIDefaults</code> table
* @return the <code>InputMap</code>
*/
public Object createValue(UIDefaults table) {
if (bindings != null) {
InputMap km = LookAndFeel.makeInputMap(bindings);
return km;
}
return null;
}
}
/**
* <code>TextAndMnemonicHashMap</code> stores swing resource strings. Many of strings
* can have a mnemonic. For example:
* FileChooser.saveButton.textAndMnemonic=&Save
* For this case method get returns "Save" for the key "FileChooser.saveButtonText" and
* mnemonic "S" for the key "FileChooser.saveButtonMnemonic"
*
* There are several patterns for the text and mnemonic suffixes which are checked by the
* <code>TextAndMnemonicHashMap</code> class.
* Patterns which are converted to the xxx.textAndMnemonic key:
* (xxxNameText, xxxNameMnemonic)
* (xxxNameText, xxxMnemonic)
* (xxx.nameText, xxx.mnemonic)
* (xxxText, xxxMnemonic)
*
* These patterns can have a mnemonic index in format
* (xxxDisplayedMnemonicIndex)
*
* Pattern which is converted to the xxx.titleAndMnemonic key:
* (xxxTitle, xxxMnemonic)
*
*/
private static class TextAndMnemonicHashMap extends HashMap<String, Object> {
static final String AND_MNEMONIC = "AndMnemonic";
static final String TITLE_SUFFIX = ".titleAndMnemonic";
static final String TEXT_SUFFIX = ".textAndMnemonic";
@Override
public Object get(Object key) {
Object value = super.get(key);
if (value == null) {
boolean checkTitle = false;
String stringKey = key.toString();
String compositeKey = null;
if (stringKey.endsWith(AND_MNEMONIC)) {
return null;
}
if (stringKey.endsWith(".mnemonic")) {
compositeKey = composeKey(stringKey, 9, TEXT_SUFFIX);
} else if (stringKey.endsWith("NameMnemonic")) {
compositeKey = composeKey(stringKey, 12, TEXT_SUFFIX);
} else if (stringKey.endsWith("Mnemonic")) {
compositeKey = composeKey(stringKey, 8, TEXT_SUFFIX);
checkTitle = true;
}
if (compositeKey != null) {
value = super.get(compositeKey);
if (value == null && checkTitle) {
compositeKey = composeKey(stringKey, 8, TITLE_SUFFIX);
value = super.get(compositeKey);
}
return value == null ? null : getMnemonicFromProperty(value.toString());
}
if (stringKey.endsWith("NameText")) {
compositeKey = composeKey(stringKey, 8, TEXT_SUFFIX);
} else if (stringKey.endsWith(".nameText")) {
compositeKey = composeKey(stringKey, 9, TEXT_SUFFIX);
} else if (stringKey.endsWith("Text")) {
compositeKey = composeKey(stringKey, 4, TEXT_SUFFIX);
} else if (stringKey.endsWith("Title")) {
compositeKey = composeKey(stringKey, 5, TITLE_SUFFIX);
}
if (compositeKey != null) {
value = super.get(compositeKey);
return value == null ? null : getTextFromProperty(value.toString());
}
if (stringKey.endsWith("DisplayedMnemonicIndex")) {
compositeKey = composeKey(stringKey, 22, TEXT_SUFFIX);
value = super.get(compositeKey);
if (value == null) {
compositeKey = composeKey(stringKey, 22, TITLE_SUFFIX);
value = super.get(compositeKey);
}
return value == null ? null : getIndexFromProperty(value.toString());
}
}
return value;
}
String composeKey(String key, int reduce, String sufix) {
return key.substring(0, key.length() - reduce) + sufix;
}
String getTextFromProperty(String text) {
return text.replace("&", "");
}
String getMnemonicFromProperty(String text) {
int index = text.indexOf('&');
if (0 <= index && index < text.length() - 1) {
char c = text.charAt(index + 1);
return Integer.toString((int) Character.toUpperCase(c));
}
return null;
}
String getIndexFromProperty(String text) {
int index = text.indexOf('&');
return (index == -1) ? null : Integer.toString(index);
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/yxljava/Java8Source.git
git@gitee.com:yxljava/Java8Source.git
yxljava
Java8Source
Java8Source
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /