PageRenderTime 45ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/jgraphpad-5.10.0.2/src/org/microplatform/gui/InternalFrame.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 221 lines | 82 code | 23 blank | 116 comment | 7 complexity | 7dd5d4baed579260e8a2513f1286aabd MD5 | raw file
  1. package org.microplatform.gui;
  2. /*
  3. * @(#)GPDocFrame.java 1.0 06.08.2003
  4. *
  5. * Copyright (C) 2003 sven_luzar
  6. *
  7. * 6/01/2006: I, Raphpael Valyi, changed back the header of this file to LGPL
  8. * because nobody changed the file significantly since the last
  9. * 3.0 version of GPGraphpad that was LGPL. By significantly, I mean:
  10. * - less than 3 instructions changes could honnestly have been done from an old fork,
  11. * - license or copyright changes in the header don't count
  12. * - automaticaly updating imports don't count,
  13. * - updating systematically 2 instructions to a library specification update don't count.
  14. *
  15. * This library is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU Lesser General Public
  17. * License as published by the Free Software Foundation; either
  18. * version 2.1 of the License, or (at your option) any later version.
  19. * This library is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22. * Lesser General Public License for more details.
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with this library; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  26. *
  27. */
  28. import java.awt.Container;
  29. import java.awt.Dimension;
  30. import java.awt.Rectangle;
  31. import java.awt.event.KeyEvent;
  32. import javax.swing.Action;
  33. import javax.swing.JButton;
  34. import javax.swing.JComponent;
  35. import javax.swing.JInternalFrame;
  36. import javax.swing.KeyStroke;
  37. import org.microplatform.loaders.LocaleChangeAdapter;
  38. /**
  39. * One Layer between the JInternalFrame
  40. * and our implementation.
  41. * Currently we add a load and store
  42. * management for the window position.
  43. * and a locale change listener support
  44. */
  45. public class InternalFrame extends JInternalFrame {
  46. /** Key description for the ESC key.
  47. *
  48. */
  49. protected KeyStroke escKeystroke =
  50. KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
  51. /** Calls the super constructor
  52. * and adds the instance to the position manager
  53. * and the locale change adapter
  54. *
  55. */
  56. public InternalFrame() {
  57. super();
  58. initInternalFrame();
  59. }
  60. /** Calls the super constructor
  61. * and adds the instance to the position manager
  62. * and the locale change adapter
  63. *
  64. * @param title
  65. */
  66. public InternalFrame(String title) {
  67. super(title);
  68. initInternalFrame();
  69. }
  70. /** Calls the super constructor
  71. * and adds the instance to the position manager
  72. * and the locale change adapter
  73. *
  74. * @param title
  75. * @param resizable
  76. */
  77. public InternalFrame(String title, boolean resizable) {
  78. super(title, resizable);
  79. initInternalFrame();
  80. }
  81. /** Calls the super constructor
  82. * and adds the instance to the position manager
  83. * and the locale change adapter
  84. *
  85. * @param title
  86. * @param resizable
  87. * @param closable
  88. */
  89. public InternalFrame(String title, boolean resizable, boolean closable) {
  90. super(title, resizable, closable);
  91. initInternalFrame();
  92. }
  93. /** Calls the super constructor
  94. * and adds the instance to the position manager
  95. * and the locale change adapter
  96. *
  97. * @param title
  98. * @param resizable
  99. * @param closable
  100. * @param maximizable
  101. */
  102. public InternalFrame(
  103. String title,
  104. boolean resizable,
  105. boolean closable,
  106. boolean maximizable) {
  107. super(title, resizable, closable, maximizable);
  108. initInternalFrame();
  109. }
  110. /** Calls the super constructor
  111. * and adds the instance to the position manager
  112. * and the locale change adapter
  113. *
  114. * @param title
  115. * @param resizable
  116. * @param closable
  117. * @param maximizable
  118. * @param iconifiable
  119. */
  120. public InternalFrame(
  121. String title,
  122. boolean resizable,
  123. boolean closable,
  124. boolean maximizable,
  125. boolean iconifiable) {
  126. super(title, resizable, closable, maximizable, iconifiable);
  127. initInternalFrame();
  128. }
  129. /**
  130. * Adds the instance to the position manager and to
  131. * the locale change adapter.
  132. * Registers the default esc action.
  133. *
  134. */
  135. private void initInternalFrame(){
  136. Dimension d;
  137. Container cont = this.getParent();
  138. if (cont == null
  139. || (cont.getSize().width == 0 && cont.getSize().height == 0)) {
  140. // use the dimension if no more information is available
  141. d = new Dimension(600, 400);
  142. } else {
  143. // will use the desktop pane size
  144. // if available
  145. d = cont.getSize();
  146. }
  147. int h = d.height;
  148. int w = d.width;
  149. int height = (int) (h * 0.66);
  150. int width = (int) (w * 0.66);
  151. int x = (int) ((double) (h - height) / 2);
  152. int y = (int) ((double) (w - width) / 2);
  153. Rectangle r = new Rectangle(x, y, width, height);
  154. setBounds(r);
  155. }
  156. /** makes an update for the locale
  157. * dependent values from the whole
  158. * container and calls
  159. * the super implementation
  160. *
  161. * @see java.awt.Component#validate()
  162. * @see java.awt.Container#validate()
  163. */
  164. public void validate() {
  165. LocaleChangeAdapter.updateContainer(this);
  166. super.validate();
  167. }
  168. /** Registers the specified
  169. * action for a esc action
  170. * of this frame.
  171. *
  172. * @param action the action
  173. *
  174. */
  175. public void registerEscAction(Action action) {
  176. this.getRootPane().registerKeyboardAction(
  177. action,
  178. escKeystroke,
  179. JComponent.WHEN_IN_FOCUSED_WINDOW);
  180. }
  181. /** Unregisters the esc action
  182. * of this frame.
  183. *
  184. */
  185. public void unregisterEscAction() {
  186. this.getRootPane().unregisterKeyboardAction(escKeystroke);
  187. }
  188. /** Registers the specified button
  189. * for the default button.
  190. *
  191. * @param button
  192. */
  193. public void setDefaultButton(JButton button){
  194. getRootPane().setDefaultButton(button);
  195. }
  196. }