PageRenderTime 60ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/webswing-app-toolkit/src/main/java/org/webswing/toolkit/WebToolkit.java

https://bitbucket.org/manishgarg90/webswing
Java | 784 lines | 664 code | 106 blank | 14 comment | 46 complexity | 9f949adbfe050204b60d8bb203fa26d2 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. package org.webswing.toolkit;
  2. import java.applet.Applet;
  3. import java.awt.AWTException;
  4. import java.awt.Button;
  5. import java.awt.Checkbox;
  6. import java.awt.CheckboxMenuItem;
  7. import java.awt.Choice;
  8. import java.awt.Component;
  9. import java.awt.Cursor;
  10. import java.awt.Desktop;
  11. import java.awt.Dialog;
  12. import java.awt.FileDialog;
  13. import java.awt.Font;
  14. import java.awt.Frame;
  15. import java.awt.GraphicsConfiguration;
  16. import java.awt.GraphicsDevice;
  17. import java.awt.GraphicsEnvironment;
  18. import java.awt.HeadlessException;
  19. import java.awt.Image;
  20. import java.awt.JobAttributes;
  21. import java.awt.KeyboardFocusManager;
  22. import java.awt.Label;
  23. import java.awt.List;
  24. import java.awt.Menu;
  25. import java.awt.MenuBar;
  26. import java.awt.MenuItem;
  27. import java.awt.PageAttributes;
  28. import java.awt.Panel;
  29. import java.awt.Point;
  30. import java.awt.PopupMenu;
  31. import java.awt.PrintJob;
  32. import java.awt.RenderingHints;
  33. import java.awt.Robot;
  34. import java.awt.ScrollPane;
  35. import java.awt.Scrollbar;
  36. import java.awt.SystemTray;
  37. import java.awt.TextArea;
  38. import java.awt.TextField;
  39. import java.awt.TrayIcon;
  40. import java.awt.Window;
  41. import java.awt.Dialog.ModalityType;
  42. import java.awt.datatransfer.Clipboard;
  43. import java.awt.dnd.DragGestureEvent;
  44. import java.awt.dnd.DragGestureListener;
  45. import java.awt.dnd.DragGestureRecognizer;
  46. import java.awt.dnd.DragSource;
  47. import java.awt.dnd.InvalidDnDOperationException;
  48. import java.awt.dnd.MouseDragGestureRecognizer;
  49. import java.awt.dnd.peer.DragSourceContextPeer;
  50. import java.awt.event.WindowEvent;
  51. import java.awt.font.TextAttribute;
  52. import java.awt.im.InputMethodHighlight;
  53. import java.awt.im.spi.InputMethodDescriptor;
  54. import java.awt.image.ColorModel;
  55. import java.awt.peer.ButtonPeer;
  56. import java.awt.peer.CheckboxMenuItemPeer;
  57. import java.awt.peer.CheckboxPeer;
  58. import java.awt.peer.ChoicePeer;
  59. import java.awt.peer.DesktopPeer;
  60. import java.awt.peer.DialogPeer;
  61. import java.awt.peer.FileDialogPeer;
  62. import java.awt.peer.FontPeer;
  63. import java.awt.peer.FramePeer;
  64. import java.awt.peer.KeyboardFocusManagerPeer;
  65. import java.awt.peer.LabelPeer;
  66. import java.awt.peer.ListPeer;
  67. import java.awt.peer.MenuBarPeer;
  68. import java.awt.peer.MenuItemPeer;
  69. import java.awt.peer.MenuPeer;
  70. import java.awt.peer.MouseInfoPeer;
  71. import java.awt.peer.PanelPeer;
  72. import java.awt.peer.PopupMenuPeer;
  73. import java.awt.peer.RobotPeer;
  74. import java.awt.peer.ScrollPanePeer;
  75. import java.awt.peer.ScrollbarPeer;
  76. import java.awt.peer.SystemTrayPeer;
  77. import java.awt.peer.TextAreaPeer;
  78. import java.awt.peer.TextFieldPeer;
  79. import java.awt.peer.TrayIconPeer;
  80. import java.awt.peer.WindowPeer;
  81. import java.io.File;
  82. import java.io.FileInputStream;
  83. import java.io.IOException;
  84. import java.io.Serializable;
  85. import java.lang.reflect.Field;
  86. import java.lang.reflect.Method;
  87. import java.util.Hashtable;
  88. import java.util.Map;
  89. import java.util.Properties;
  90. import javax.swing.JPanel;
  91. import javax.swing.SwingUtilities;
  92. import org.webswing.Constants;
  93. import org.webswing.dispatch.WebEventDispatcher;
  94. import org.webswing.dispatch.WebPaintDispatcher;
  95. import org.webswing.model.Msg;
  96. import org.webswing.toolkit.api.WebswingMessagingApi;
  97. import org.webswing.toolkit.api.WebswingApi;
  98. import org.webswing.toolkit.api.WebswingApiProvider;
  99. import org.webswing.toolkit.extra.WindowManager;
  100. import org.webswing.toolkit.util.Logger;
  101. import org.webswing.toolkit.util.Util;
  102. import sun.awt.SunToolkit;
  103. import sun.awt.image.SurfaceManager;
  104. import sun.java2d.SurfaceData;
  105. import sun.print.PrintJob2D;
  106. @SuppressWarnings("restriction")
  107. public abstract class WebToolkit extends SunToolkit implements WebswingApiProvider {
  108. public static final Font defaultFont = new Font("Dialog", 0, 12);
  109. public static final String BACKGROUND_WINDOW_ID = "BG";
  110. private static Object TREELOCK = null;
  111. private WebEventDispatcher eventDispatcher;
  112. private WebPaintDispatcher paintDispatcher;
  113. private WebswingApiImpl api = new WebswingApiImpl();
  114. private WebswingMessagingApiImpl msgapi = new WebswingMessagingApiImpl();
  115. private WindowManager windowManager = WindowManager.getInstance();
  116. private ClassLoader swingClassLoader;
  117. public void init() {
  118. try {
  119. if (!System.getProperty("os.name", "").startsWith("Windows") && !System.getProperty("os.name", "").startsWith("Mac")) {
  120. Class<?> c = ClassLoader.getSystemClassLoader().loadClass("sun.awt.X11GraphicsEnvironment");
  121. Method initDisplayMethod = c.getDeclaredMethod("initDisplay", Boolean.TYPE);
  122. initDisplayMethod.setAccessible(true);
  123. initDisplayMethod.invoke(null, false);
  124. }
  125. } catch (Exception e) {
  126. Logger.error("Failed to init X11 display: ", e.getMessage());
  127. }
  128. installFonts();
  129. }
  130. private void installFonts() {
  131. try {
  132. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  133. Properties fontsProp=new Properties();
  134. String fontConfig=System.getProperty("sun.awt.fontconfig");
  135. if(fontConfig!=null) {
  136. fontsProp.load(new FileInputStream(new File(fontConfig)));
  137. for (String name : fontsProp.stringPropertyNames()) {
  138. if (name.startsWith("filename.")) {
  139. String file = fontsProp.getProperty(name);
  140. Font font = Font.createFont(Font.TRUETYPE_FONT, new File(file));
  141. ge.registerFont(font);
  142. }
  143. }
  144. }
  145. } catch (Exception e) {
  146. Logger.error("Failed to install fonts",e);
  147. }
  148. }
  149. public void startDispatchers() {
  150. eventDispatcher = new WebEventDispatcher();
  151. paintDispatcher = new WebPaintDispatcher();
  152. }
  153. public void initSize(final Integer desktopWidth, final Integer desktopHeight) {
  154. if (!SwingUtilities.isEventDispatchThread()) {
  155. SwingUtilities.invokeLater(new Runnable() {
  156. @Override
  157. public void run() {
  158. initSize(desktopWidth, desktopHeight);
  159. }
  160. });
  161. } else {
  162. int oldWidht = screenWidth;
  163. int oldHeight = screenHeight;
  164. screenWidth = desktopWidth;
  165. screenHeight = desktopHeight;
  166. displayChanged();
  167. resetGC();
  168. Util.resetWindowsGC(screenWidth, screenHeight);
  169. getPaintDispatcher().clientReadyToReceive();
  170. getPaintDispatcher().resetWindowsPosition(oldWidht, oldHeight);// in case windows moved out of screen by resizing screen.
  171. getPaintDispatcher().notifyWindowRepaintAll();
  172. }
  173. }
  174. protected WindowManager getWindowManager() {
  175. return windowManager;
  176. }
  177. public WebEventDispatcher getEventDispatcher() {
  178. return eventDispatcher;
  179. }
  180. public WebPaintDispatcher getPaintDispatcher() {
  181. return paintDispatcher;
  182. }
  183. // ////////////////////////////////////////////////////////////////////////////////////////////
  184. // /////////////////// Toolkit Implementation//////////////////////////////////////////////////
  185. private static WebMouseInfoPeer mPeer;
  186. public WebToolkit() {
  187. if (System.getProperty("java.version").startsWith("1.6") || System.getProperty("java.version").startsWith("1.7")) {
  188. try {
  189. Method m = SunToolkit.class.getDeclaredMethod("setDataTransfererClassName", String.class);
  190. m.setAccessible(true);
  191. m.invoke(null, "org.webswing.toolkit.WebDataTransfer");
  192. } catch (Exception e) {
  193. // do nothing
  194. }
  195. }
  196. }
  197. private static GraphicsConfiguration config;
  198. private Hashtable<String, FontPeer> cacheFontPeer;
  199. private WebClipboard clipboard;
  200. private Clipboard selectionClipboard;
  201. private boolean exiting = false;
  202. public static int screenWidth = Integer.parseInt(System.getProperty(Constants.SWING_SCREEN_WIDTH, Constants.SWING_SCREEN_WIDTH_MIN + ""));
  203. public static int screenHeight = Integer.parseInt(System.getProperty(Constants.SWING_SCREEN_HEIGHT, Constants.SWING_SCREEN_HEIGHT_MIN + ""));
  204. public static final Object targetToPeer(Object paramObject) {
  205. return SunToolkit.targetToPeer(paramObject);
  206. }
  207. public static final void targetDisposedPeer(Object paramObject1, Object paramObject2) {
  208. SunToolkit.targetDisposedPeer(paramObject1, paramObject2);
  209. }
  210. @Override
  211. protected void initializeDesktopProperties() {
  212. if (System.getProperty(Constants.SWING_START_SYS_PROP_ISOLATED_FS, "").equalsIgnoreCase("true")) {
  213. this.desktopProperties.put("Shell.shellFolderManager", "org.webswing.toolkit.extra.WebShellFolderManager");
  214. } else {
  215. if (System.getProperty("os.name", "").startsWith("Windows")) {
  216. this.desktopProperties.put("Shell.shellFolderManager", "sun.awt.shell.Win32ShellFolderManager2");
  217. }
  218. }
  219. this.desktopProperties.put("DnD.gestureMotionThreshold", 2);
  220. this.desktopProperties.put("DnD.Autoscroll.initialDelay", 100);
  221. this.desktopProperties.put("DnD.Autoscroll.interval", 100);
  222. this.desktopProperties.put("DnD.Autoscroll.cursorHysteresis", 10);
  223. this.desktopProperties.put("awt.dynamicLayoutSupported", true);
  224. this.desktopProperties.put("awt.file.showAttribCol", false);
  225. this.desktopProperties.put("awt.file.showHiddenFiles", false);
  226. this.desktopProperties.put("awt.mouse.numButtons", 5);
  227. this.desktopProperties.put("awt.multiClickInterval", 500);
  228. this.desktopProperties.put("awt.wheelMousePresent", true);
  229. this.desktopProperties.put("win.3d.backgroundColor", new java.awt.Color(240, 240, 240));
  230. this.desktopProperties.put("win.3d.darkShadowColor", new java.awt.Color(105, 105, 105));
  231. this.desktopProperties.put("win.3d.highlightColor", new java.awt.Color(255, 255, 255));
  232. this.desktopProperties.put("win.3d.lightColor", new java.awt.Color(227, 227, 227));
  233. this.desktopProperties.put("win.3d.shadowColor", new java.awt.Color(160, 160, 160));
  234. this.desktopProperties.put("win.ansiFixed.font", Font.decode("Monospaced 0 13"));
  235. this.desktopProperties.put("win.ansiFixed.font.height", 13);
  236. this.desktopProperties.put("win.ansiVar.font", Font.decode("Dialog 0 11"));
  237. this.desktopProperties.put("win.ansiVar.font.height", 11);
  238. this.desktopProperties.put("win.button.textColor", new java.awt.Color(0, 0, 0));
  239. this.desktopProperties.put("win.caret.width", 1);
  240. this.desktopProperties.put("win.defaultGUI.font", Font.decode("Dialog 0 11"));
  241. this.desktopProperties.put("win.defaultGUI.font.height", 11);
  242. this.desktopProperties.put("win.desktop.backgroundColor", new java.awt.Color(0, 0, 0));
  243. this.desktopProperties.put("win.deviceDefault.font", Font.decode("Dialog 1 13"));
  244. this.desktopProperties.put("win.deviceDefault.font.height", 13);
  245. this.desktopProperties.put("win.drag.height", 4);
  246. this.desktopProperties.put("win.drag.width", 4);
  247. this.desktopProperties.put("win.frame.activeBorderColor", new java.awt.Color(180, 180, 180));
  248. this.desktopProperties.put("win.frame.activeCaptionColor", new java.awt.Color(153, 180, 209));
  249. this.desktopProperties.put("win.frame.activeCaptionGradientColor", new java.awt.Color(185, 209, 234));
  250. this.desktopProperties.put("win.frame.backgroundColor", new java.awt.Color(255, 255, 255));
  251. this.desktopProperties.put("win.frame.captionButtonHeight", 22);
  252. this.desktopProperties.put("win.frame.captionButtonWidth", 36);
  253. this.desktopProperties.put("win.frame.captionFont", Font.decode("Dialog 0 12"));
  254. this.desktopProperties.put("win.frame.captionFont.height", 12);
  255. this.desktopProperties.put("win.frame.captionGradientsOn", true);
  256. this.desktopProperties.put("win.frame.captionHeight", 22);
  257. this.desktopProperties.put("win.frame.captionTextColor", new java.awt.Color(0, 0, 0));
  258. this.desktopProperties.put("win.frame.color", new java.awt.Color(100, 100, 100));
  259. this.desktopProperties.put("win.frame.fullWindowDragsOn", true);
  260. this.desktopProperties.put("win.frame.inactiveBorderColor", new java.awt.Color(244, 247, 252));
  261. this.desktopProperties.put("win.frame.inactiveCaptionColor", new java.awt.Color(191, 205, 219));
  262. this.desktopProperties.put("win.frame.inactiveCaptionGradientColor", new java.awt.Color(215, 228, 242));
  263. this.desktopProperties.put("win.frame.inactiveCaptionTextColor", new java.awt.Color(0, 0, 0));
  264. this.desktopProperties.put("win.frame.sizingBorderWidth", 5);
  265. this.desktopProperties.put("win.frame.smallCaptionButtonHeight", 22);
  266. this.desktopProperties.put("win.frame.smallCaptionButtonWidth", 22);
  267. this.desktopProperties.put("win.frame.smallCaptionFont", Font.decode("Dialog 0 12"));
  268. this.desktopProperties.put("win.frame.smallCaptionFont.height", 12);
  269. this.desktopProperties.put("win.frame.smallCaptionHeight", 22);
  270. this.desktopProperties.put("win.frame.textColor", new java.awt.Color(0, 0, 0));
  271. this.desktopProperties.put("win.highContrast.on", false);
  272. this.desktopProperties.put("win.icon.font", Font.decode("Dialog 0 12"));
  273. this.desktopProperties.put("win.icon.font.height", 12);
  274. this.desktopProperties.put("win.icon.hspacing", 75);
  275. this.desktopProperties.put("win.icon.titleWrappingOn", true);
  276. this.desktopProperties.put("win.icon.vspacing", 75);
  277. this.desktopProperties.put("win.item.highlightColor", new java.awt.Color(51, 153, 255));
  278. this.desktopProperties.put("win.item.highlightTextColor", new java.awt.Color(255, 255, 255));
  279. this.desktopProperties.put("win.item.hotTrackedColor", new java.awt.Color(0, 102, 204));
  280. this.desktopProperties.put("win.item.hotTrackingOn", true);
  281. this.desktopProperties.put("win.mdi.backgroundColor", new java.awt.Color(171, 171, 171));
  282. this.desktopProperties.put("win.menu.backgroundColor", new java.awt.Color(240, 240, 240));
  283. this.desktopProperties.put("win.menu.buttonWidth", 19);
  284. this.desktopProperties.put("win.menu.font", Font.decode("Dialog 0 12"));
  285. this.desktopProperties.put("win.menu.font.height", 12);
  286. this.desktopProperties.put("win.menu.height", 19);
  287. this.desktopProperties.put("win.menu.keyboardCuesOn", false);
  288. this.desktopProperties.put("win.menu.textColor", new java.awt.Color(0, 0, 0));
  289. this.desktopProperties.put("win.menubar.backgroundColor", new java.awt.Color(240, 240, 240));
  290. this.desktopProperties.put("win.messagebox.font", Font.decode("Dialog 0 12"));
  291. this.desktopProperties.put("win.messagebox.font.height", 12);
  292. this.desktopProperties.put("win.oemFixed.font", Font.decode("Dialog 0 12"));
  293. this.desktopProperties.put("win.oemFixed.font.height", 12);
  294. this.desktopProperties.put("win.properties.version", 3);
  295. this.desktopProperties.put("win.scrollbar.backgroundColor", new java.awt.Color(200, 200, 200));
  296. this.desktopProperties.put("win.scrollbar.height", 17);
  297. this.desktopProperties.put("win.scrollbar.width", 17);
  298. this.desktopProperties.put("win.status.font", Font.decode("Dialog 0 12"));
  299. this.desktopProperties.put("win.status.font.height", 12);
  300. this.desktopProperties.put("win.system.font", Font.decode("Dialog 1 13"));
  301. this.desktopProperties.put("win.system.font.height", 13);
  302. this.desktopProperties.put("win.systemFixed.font", Font.decode("Dialog 0 12"));
  303. this.desktopProperties.put("win.systemFixed.font.height", 12);
  304. this.desktopProperties.put("win.text.fontSmoothingContrast", 1200);
  305. this.desktopProperties.put("win.text.fontSmoothingOn", true);
  306. this.desktopProperties.put("win.text.fontSmoothingOrientation", 1);
  307. this.desktopProperties.put("win.text.fontSmoothingType", 2);
  308. this.desktopProperties.put("win.text.grayedTextColor", new java.awt.Color(109, 109, 109));
  309. this.desktopProperties.put("win.tooltip.backgroundColor", new java.awt.Color(255, 255, 225));
  310. this.desktopProperties.put("win.tooltip.font", Font.decode("Dialog 0 12"));
  311. this.desktopProperties.put("win.tooltip.font.height", 12);
  312. this.desktopProperties.put("win.tooltip.textColor", new java.awt.Color(0, 0, 0));
  313. this.desktopProperties.put("win.xpstyle.colorName", "NormalColor");
  314. this.desktopProperties.put("win.xpstyle.dllName", "C:\\WINDOWS\\resources\\themes\\Aero\\Aero.msstyles");
  315. this.desktopProperties.put("win.xpstyle.sizeName", "NormalSize");
  316. this.desktopProperties.put("win.xpstyle.themeActive", true);
  317. if (System.getProperty("os.name", "").startsWith("Windows")) {
  318. try {
  319. Field xpStyleEnabledField = sun.awt.windows.ThemeReader.class.getDeclaredField("xpStyleEnabled");
  320. xpStyleEnabledField.setAccessible(true);
  321. xpStyleEnabledField.setBoolean(null, true);
  322. } catch (Exception e) {
  323. Logger.debug("Failed to set xpStyleEnabled to true", e);
  324. }
  325. }
  326. }
  327. public boolean needUpdateWindow() {
  328. return true;
  329. }
  330. public boolean isTranslucencyCapable(GraphicsConfiguration paramGraphicsConfiguration) {
  331. return true;
  332. }
  333. public boolean isFrameStateSupported(int state) throws HeadlessException {
  334. return true;
  335. }
  336. public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager paramKeyboardFocusManager) throws HeadlessException {
  337. return new WebKeyboardFocusManagerPeer();
  338. }
  339. public FramePeer createFrame(Frame frame) throws HeadlessException {
  340. WebFramePeer localWFramePeer = new WebFramePeer(frame);
  341. targetCreatedPeer(frame, localWFramePeer);
  342. return localWFramePeer;
  343. }
  344. public DialogPeer createDialog(Dialog paramDialog) throws HeadlessException {
  345. WebDialogPeer localdialogPeer = new WebDialogPeer(paramDialog);
  346. targetCreatedPeer(paramDialog, localdialogPeer);
  347. return localdialogPeer;
  348. }
  349. public boolean isModalityTypeSupported(ModalityType mt) {
  350. return true;
  351. }
  352. public WindowPeer createWindow(Window paramWindow) throws HeadlessException {
  353. WebWindowPeer localwindowPeer = new WebWindowPeer(paramWindow);
  354. targetCreatedPeer(paramWindow, localwindowPeer);
  355. return localwindowPeer;
  356. }
  357. public PanelPeer createPanel(Panel panel) {
  358. if (panel instanceof Applet) {
  359. return super.createPanel(panel);
  360. }
  361. WebPanelPeer localpanelPeer = new WebPanelPeer(panel);
  362. targetCreatedPeer(panel, localpanelPeer);
  363. return localpanelPeer;
  364. }
  365. @Override
  366. protected synchronized MouseInfoPeer getMouseInfoPeer() {
  367. {
  368. if (mPeer == null) {
  369. mPeer = new WebMouseInfoPeer();
  370. }
  371. return mPeer;
  372. }
  373. }
  374. public FontPeer getFontPeer(String paramString, int paramInt) {
  375. FontPeer localObject = null;
  376. String str = paramString.toLowerCase();
  377. if (null != this.cacheFontPeer) {
  378. localObject = this.cacheFontPeer.get(str + paramInt);
  379. if (null != localObject) {
  380. return localObject;
  381. }
  382. }
  383. localObject = new WebFontPeer(paramString, paramInt);
  384. if (localObject != null) {
  385. if (null == this.cacheFontPeer) {
  386. this.cacheFontPeer = new Hashtable<String, FontPeer>(5, 0.9F);
  387. }
  388. if (null != this.cacheFontPeer) {
  389. this.cacheFontPeer.put(str + paramInt, localObject);
  390. }
  391. }
  392. return ((FontPeer) localObject);
  393. }
  394. public Clipboard getSystemClipboard() throws HeadlessException {
  395. return getWebswingClipboard();
  396. }
  397. public WebClipboard getWebswingClipboard() {
  398. synchronized (this) {
  399. if (this.clipboard == null) {
  400. this.clipboard = new WebClipboard("default", true);
  401. }
  402. }
  403. return this.clipboard;
  404. }
  405. public Clipboard getSystemSelection() throws HeadlessException {
  406. synchronized (this) {
  407. if (this.selectionClipboard == null) {
  408. this.selectionClipboard = new WebClipboard("selection", false);
  409. }
  410. }
  411. return this.selectionClipboard;
  412. }
  413. @Override
  414. protected Object lazilyLoadDesktopProperty(String name) {
  415. if ("awt.font.desktophints".equals(name)) {
  416. return SunToolkit.getDesktopFontHints();
  417. }
  418. return super.lazilyLoadDesktopProperty(name);
  419. }
  420. @Override
  421. protected RenderingHints getDesktopAAHints() {
  422. RenderingHints hints = new RenderingHints(null);
  423. hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  424. hints.put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 140);
  425. return hints;
  426. }
  427. public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent paramDragGestureEvent) throws InvalidDnDOperationException {
  428. return WebDragSourceContextPeer.createDragSourceContextPeer(paramDragGestureEvent);
  429. }
  430. @SuppressWarnings("unchecked")
  431. public <T extends DragGestureRecognizer> T createDragGestureRecognizer(Class<T> type, DragSource dragSource, Component component, int act, DragGestureListener listener) {
  432. if (MouseDragGestureRecognizer.class.equals(type)) {
  433. return (T) new WebMouseDragGestureRecognizer(dragSource, component, act, listener);
  434. }
  435. return null;
  436. }
  437. protected int getScreenWidth() {
  438. return screenWidth;
  439. }
  440. protected int getScreenHeight() {
  441. return screenHeight;
  442. }
  443. public int getScreenResolution() throws HeadlessException {
  444. return 72;
  445. }
  446. public ColorModel getColorModel() throws HeadlessException {
  447. if (config == null) {
  448. resetGC();
  449. }
  450. return config.getColorModel();
  451. }
  452. public void sync() {
  453. }
  454. public Map<TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight paramInputMethodHighlight) throws HeadlessException {
  455. return null;
  456. }
  457. public static void resetGC() {
  458. config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
  459. }
  460. public abstract void displayChanged();
  461. // EventQueue.invokeLater(new Runnable() {
  462. //
  463. // public void run() {
  464. // ((WebGraphicsEnvironment) GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
  465. // }
  466. // });
  467. // }
  468. public InputMethodDescriptor getInputMethodAdapterDescriptor() throws AWTException {
  469. return new WebInputMethodDescriptor();
  470. }
  471. protected boolean syncNativeQueue() {
  472. return true;
  473. }
  474. public void grab(Window paramWindow) {
  475. }
  476. public void ungrab(Window paramWindow) {
  477. }
  478. public ButtonPeer createButton(Button paramButton) throws HeadlessException {
  479. throw new UnsupportedOperationException();
  480. }
  481. public TextFieldPeer createTextField(TextField paramTextField) throws HeadlessException {
  482. throw new UnsupportedOperationException();
  483. }
  484. public ChoicePeer createChoice(Choice paramChoice) throws HeadlessException {
  485. throw new UnsupportedOperationException();
  486. }
  487. public LabelPeer createLabel(Label paramLabel) throws HeadlessException {
  488. throw new UnsupportedOperationException();
  489. }
  490. public ListPeer createList(List paramList) throws HeadlessException {
  491. throw new UnsupportedOperationException();
  492. }
  493. public CheckboxPeer createCheckbox(Checkbox paramCheckbox) throws HeadlessException {
  494. throw new UnsupportedOperationException();
  495. }
  496. public ScrollbarPeer createScrollbar(Scrollbar paramScrollbar) throws HeadlessException {
  497. throw new UnsupportedOperationException();
  498. }
  499. public ScrollPanePeer createScrollPane(ScrollPane paramScrollPane) throws HeadlessException {
  500. throw new UnsupportedOperationException();
  501. }
  502. public TextAreaPeer createTextArea(TextArea paramTextArea) throws HeadlessException {
  503. throw new UnsupportedOperationException();
  504. }
  505. public FileDialogPeer createFileDialog(FileDialog paramFileDialog) throws HeadlessException {
  506. return new WebFileDialogPeer(paramFileDialog);
  507. }
  508. public MenuBarPeer createMenuBar(MenuBar paramMenuBar) throws HeadlessException {
  509. throw new UnsupportedOperationException();
  510. }
  511. public MenuPeer createMenu(Menu paramMenu) throws HeadlessException {
  512. throw new UnsupportedOperationException();
  513. }
  514. public PopupMenuPeer createPopupMenu(PopupMenu paramPopupMenu) throws HeadlessException {
  515. throw new UnsupportedOperationException();
  516. }
  517. public MenuItemPeer createMenuItem(MenuItem paramMenuItem) throws HeadlessException {
  518. throw new UnsupportedOperationException();
  519. }
  520. public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem paramCheckboxMenuItem) throws HeadlessException {
  521. throw new UnsupportedOperationException();
  522. }
  523. public TrayIconPeer createTrayIcon(TrayIcon paramTrayIcon) throws HeadlessException, AWTException {
  524. throw new UnsupportedOperationException();
  525. }
  526. public SystemTrayPeer createSystemTray(SystemTray paramSystemTray) {
  527. return new WebSystemTrayPeer();
  528. }
  529. public boolean isTraySupported() {
  530. return false;
  531. }
  532. public RobotPeer createRobot(Robot robot, GraphicsDevice device) throws AWTException {
  533. return new WebRobotPeer(robot, device);
  534. }
  535. public boolean isDesktopSupported() {
  536. return true;
  537. }
  538. public boolean isWindowOpacityControlSupported() {
  539. return true;
  540. }
  541. public boolean isWindowShapingSupported() {
  542. return false;
  543. }
  544. public boolean isWindowTranslucencySupported() {
  545. return true;
  546. }
  547. protected DesktopPeer createDesktopPeer(Desktop paramDesktop) throws HeadlessException {
  548. return new WebDesktopPeer(paramDesktop);
  549. }
  550. public PrintJob getPrintJob(Frame frame, String jobtitle, JobAttributes jobAttributes, PageAttributes pageAttributes) {
  551. PrintJob2D localPrintJob2D = new PrintJob2D(frame, jobtitle, jobAttributes, pageAttributes);
  552. if (!localPrintJob2D.printDialog()) {
  553. localPrintJob2D = null;
  554. }
  555. return localPrintJob2D;
  556. }
  557. public PrintJob getPrintJob(Frame frame, String jobtitle, Properties paramProperties) {
  558. return getPrintJob(frame, jobtitle, null, null);
  559. }
  560. public void beep() {
  561. }
  562. @Override
  563. public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException {
  564. return false;
  565. }
  566. public GraphicsConfiguration getGraphicsConfig() {
  567. if (config == null) {
  568. resetGC();
  569. }
  570. return config;
  571. }
  572. public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
  573. return true;
  574. }
  575. // update system colors to win7 default theme (light)
  576. protected void loadSystemColors(int[] systemColors) throws HeadlessException {
  577. if (systemColors != null && systemColors.length == 26) {
  578. systemColors[0] = 0xff000000;
  579. systemColors[1] = 0xff99b4d1;
  580. systemColors[2] = 0xff000000;
  581. systemColors[3] = 0xffb4b4b4;
  582. systemColors[4] = 0xffbfcddb;
  583. systemColors[5] = 0xff434e54;
  584. systemColors[6] = 0xfff4f7fc;
  585. systemColors[7] = 0xffffffff;
  586. systemColors[8] = 0xff646464;
  587. systemColors[9] = 0xff000000;
  588. systemColors[10] = 0xfff0f0f0;
  589. systemColors[11] = 0xff000000;
  590. systemColors[12] = 0xffffffff;
  591. systemColors[13] = 0xff000000;
  592. systemColors[14] = 0xff3399ff;
  593. systemColors[15] = 0xffffffff;
  594. systemColors[16] = 0xff6d6d6d;
  595. systemColors[17] = 0xfff0f0f0;
  596. systemColors[18] = 0xff000000;
  597. systemColors[19] = 0xffe3e3e3;
  598. systemColors[20] = 0xffffffff;
  599. systemColors[21] = 0xffa0a0a0;
  600. systemColors[22] = 0xff696969;
  601. systemColors[23] = 0xffc8c8c8;
  602. systemColors[24] = 0xffffffe1;
  603. systemColors[25] = 0xff000000;
  604. }
  605. }
  606. abstract public boolean webConpoenentPeerUpdateGraphicsData();
  607. abstract public SurfaceData webComponentPeerReplaceSurfaceData(SurfaceManager mgr);
  608. public synchronized void exitSwing(final int i) {
  609. if (!exiting) {
  610. exiting = true;
  611. Thread shutdownThread = new Thread(new Runnable() {
  612. @Override
  613. public void run() {
  614. //tell server to kill this application after defined time
  615. try {
  616. getPaintDispatcher().notifyApplicationExiting();
  617. api.fireShutdownListeners();
  618. } catch (Exception e) {
  619. e.printStackTrace();
  620. System.exit(1);
  621. }
  622. }
  623. });
  624. shutdownThread.setName("Webswing shutdown thread");
  625. shutdownThread.setDaemon(true);
  626. shutdownThread.start();
  627. }
  628. }
  629. public void defaultShutdownProcedure() {
  630. //first send windows closing event to all windows
  631. for (Window w : Window.getWindows()) {
  632. w.dispatchEvent(new WindowEvent(w, WindowEvent.WINDOW_CLOSING));
  633. }
  634. SwingUtilities.invokeLater(new Runnable() {
  635. @Override
  636. public void run() {
  637. //make sure we close windows created by window close listeners executed above
  638. for (Window w : Window.getWindows()) {
  639. w.setVisible(false);
  640. w.dispose();
  641. }
  642. }
  643. });
  644. }
  645. public Object getTreeLock() {
  646. if (TREELOCK == null) {
  647. TREELOCK = new JPanel().getTreeLock();
  648. }
  649. return TREELOCK;
  650. }
  651. @Override
  652. public WebswingApi getApi() {
  653. return api;
  654. }
  655. @Override
  656. public WebswingMessagingApi getMessagingApi() {
  657. return msgapi;
  658. }
  659. public void processApiEvent(Msg event) {
  660. api.processEvent(event);
  661. }
  662. public boolean messageApiHasListenerForClass(String msgtype) {
  663. return msgapi.hasListenerForClass(msgtype);
  664. }
  665. public void messageApiProcessMessage(Serializable object) {
  666. msgapi.processMessage(object);
  667. }
  668. @Override
  669. public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) throws IndexOutOfBoundsException, HeadlessException {
  670. return new WebCursor(cursor, hotSpot, name);
  671. }
  672. public void setSwingClassLoader(ClassLoader swingClassLoader) {
  673. this.swingClassLoader = swingClassLoader;
  674. }
  675. public ClassLoader getSwingClassLoader() {
  676. return swingClassLoader;
  677. }
  678. }