Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

IDebugConsole.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.terminal.gwt.client;
  5. import com.google.gwt.user.client.DOM;
  6. import com.google.gwt.user.client.Element;
  7. import com.google.gwt.user.client.Event;
  8. import com.google.gwt.user.client.Window;
  9. import com.google.gwt.user.client.ui.FlowPanel;
  10. import com.google.gwt.user.client.ui.HTML;
  11. import com.google.gwt.user.client.ui.Label;
  12. import com.google.gwt.user.client.ui.Panel;
  13. import com.google.gwt.user.client.ui.ScrollPanel;
  14. import com.google.gwt.user.client.ui.Widget;
  15. import com.itmill.toolkit.terminal.gwt.client.ui.IWindow;
  16. public final class IDebugConsole extends IWindow implements Console {
  17. /**
  18. * Builds number. For example 0-custom_tag in 5.0.0-custom_tag.
  19. */
  20. public static final String VERSION;
  21. /* Initialize version numbers from string replaced by build-script. */
  22. static {
  23. if ("@VERSION@".equals("@" + "VERSION" + "@")) {
  24. VERSION = "5.9.9-INTERNAL-NONVERSIONED-DEBUG-BUILD";
  25. } else {
  26. VERSION = "@VERSION@";
  27. }
  28. }
  29. private final Panel panel;
  30. public IDebugConsole(ApplicationConnection client,
  31. ApplicationConfiguration cnf) {
  32. super();
  33. this.client = client;
  34. panel = new FlowPanel();
  35. final ScrollPanel p = new ScrollPanel();
  36. p.add(panel);
  37. setWidget(p);
  38. setCaption("Debug window");
  39. minimize();
  40. show();
  41. ;
  42. log("Toolkit application servlet version: " + cnf.getSerletVersion());
  43. log("Widget set is built on version: " + VERSION);
  44. log("Application version: " + cnf.getApplicationVersion());
  45. if (!cnf.getSerletVersion().equals(VERSION)) {
  46. error("Warning: your widget set seems to be built with different "
  47. + "version than the one used on server. Unexpected "
  48. + "behavior may occur.");
  49. }
  50. }
  51. private void minimize() {
  52. // TODO stack to bottom (create window manager of some sort)
  53. setPixelSize(60, 60);
  54. setPopupPosition(Window.getClientWidth() - 142, 0);
  55. }
  56. /*
  57. * (non-Javadoc)
  58. *
  59. * @see com.itmill.toolkit.terminal.gwt.client.Console#log(java.lang.String)
  60. */
  61. public void log(String msg) {
  62. panel.add(new HTML(msg));
  63. System.out.println(msg);
  64. }
  65. /*
  66. * (non-Javadoc)
  67. *
  68. * @see
  69. * com.itmill.toolkit.terminal.gwt.client.Console#error(java.lang.String)
  70. */
  71. public void error(String msg) {
  72. panel.add((new HTML(msg)));
  73. System.out.println(msg);
  74. }
  75. /*
  76. * (non-Javadoc)
  77. *
  78. * @see
  79. * com.itmill.toolkit.terminal.gwt.client.Console#printObject(java.lang.
  80. * Object)
  81. */
  82. public void printObject(Object msg) {
  83. panel.add((new Label(msg.toString())));
  84. }
  85. /*
  86. * (non-Javadoc)
  87. *
  88. * @see
  89. * com.itmill.toolkit.terminal.gwt.client.Console#dirUIDL(com.itmill.toolkit
  90. * .terminal.gwt.client.UIDL)
  91. */
  92. public void dirUIDL(UIDL u) {
  93. panel.add(u.print_r());
  94. }
  95. public void setSize(Event event, boolean updateVariables) {
  96. super.setSize(event, false);
  97. }
  98. public void onScroll(Widget widget, int scrollLeft, int scrollTop) {
  99. }
  100. public void setPopupPosition(int left, int top) {
  101. // Keep the popup within the browser's client area, so that they can't
  102. // get
  103. // 'lost' and become impossible to interact with. Note that we don't
  104. // attempt
  105. // to keep popups pegged to the bottom and right edges, as they will
  106. // then
  107. // cause scrollbars to appear, so the user can't lose them.
  108. if (left < 0) {
  109. left = 0;
  110. }
  111. if (top < 0) {
  112. top = 0;
  113. }
  114. // Set the popup's position manually, allowing setPopupPosition() to be
  115. // called before show() is called (so a popup can be positioned without
  116. // it
  117. // 'jumping' on the screen).
  118. Element elem = getElement();
  119. DOM.setStyleAttribute(elem, "left", left + "px");
  120. DOM.setStyleAttribute(elem, "top", top + "px");
  121. }
  122. }