1. /*
  2. * @(#)WindowsInternalFrameUI.java 1.21 03/01/31
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.windows;
  8. import java.awt.*;
  9. import java.beans.*;
  10. import javax.swing.*;
  11. import javax.swing.border.*;
  12. import javax.swing.plaf.basic.*;
  13. import javax.swing.plaf.ComponentUI;
  14. /**
  15. * Windows rendition of the component.
  16. * <p>
  17. * <strong>Warning:</strong>
  18. * Serialized objects of this class will not be compatible with
  19. * future Swing releases. The current serialization support is appropriate
  20. * for short term storage or RMI between applications running the same
  21. * version of Swing. A future release of Swing will provide support for
  22. * long term persistence.
  23. */
  24. public class WindowsInternalFrameUI extends BasicInternalFrameUI
  25. {
  26. XPStyle xp = XPStyle.getXP();
  27. public void installDefaults() {
  28. super.installDefaults();
  29. if (xp != null) {
  30. frame.setBorder(new XPBorder());
  31. } else {
  32. frame.setBorder(UIManager.getBorder("InternalFrame.border"));
  33. }
  34. }
  35. public void installUI(JComponent c) {
  36. super.installUI(c);
  37. c.setOpaque(xp == null);
  38. }
  39. public void uninstallDefaults() {
  40. frame.setBorder(null);
  41. super.uninstallDefaults();
  42. }
  43. public static ComponentUI createUI(JComponent b) {
  44. return new WindowsInternalFrameUI((JInternalFrame)b);
  45. }
  46. public WindowsInternalFrameUI(JInternalFrame w){
  47. super(w);
  48. }
  49. protected DesktopManager createDesktopManager(){
  50. return new WindowsDesktopManager();
  51. }
  52. protected JComponent createNorthPane(JInternalFrame w) {
  53. titlePane = new WindowsInternalFrameTitlePane(w);
  54. return titlePane;
  55. }
  56. protected LayoutManager createLayoutManager(){
  57. if (XPStyle.getXP() != null) {
  58. return new BasicInternalFrameUI.InternalFrameLayout() {
  59. public void layoutContainer(Container c) {
  60. Insets i = frame.getInsets();
  61. int cx, cy, cw, ch;
  62. cx = i.left;
  63. cy = 0;
  64. cw = frame.getWidth() - i.left - i.right;
  65. ch = frame.getHeight() - i.bottom;
  66. if (getNorthPane() != null) {
  67. Dimension size = getNorthPane().getPreferredSize();
  68. // Ignore insets when placing the title pane
  69. getNorthPane().setBounds(0, 0, frame.getWidth(), size.height);
  70. cy += size.height;
  71. ch -= size.height;
  72. }
  73. if (getSouthPane() != null) {
  74. Dimension size = getSouthPane().getPreferredSize();
  75. getSouthPane().setBounds(cx, frame.getHeight() - i.bottom - size.height,
  76. cw, size.height);
  77. ch -= size.height;
  78. }
  79. if (getWestPane() != null) {
  80. Dimension size = getWestPane().getPreferredSize();
  81. getWestPane().setBounds(cx, cy, size.width, ch);
  82. cw -= size.width;
  83. cx += size.width;
  84. }
  85. if (getEastPane() != null) {
  86. Dimension size = getEastPane().getPreferredSize();
  87. getEastPane().setBounds(cw - size.width, cy, size.width, ch);
  88. cw -= size.width;
  89. }
  90. if (frame.getRootPane() != null) {
  91. frame.getRootPane().setBounds(cx, cy, cw, ch);
  92. }
  93. }
  94. };
  95. } else {
  96. return super.createLayoutManager();
  97. }
  98. }
  99. private class XPBorder extends AbstractBorder {
  100. private XPStyle.Skin leftSkin = xp.getSkin("window.frameleft");
  101. private XPStyle.Skin rightSkin = xp.getSkin("window.frameright");
  102. private XPStyle.Skin bottomSkin = xp.getSkin("window.framebottom");
  103. /**
  104. * @param x the x position of the painted border
  105. * @param y the y position of the painted border
  106. * @param width the width of the painted border
  107. * @param height the height of the painted border
  108. */
  109. public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  110. boolean isSelected = ((JInternalFrame)c).isSelected();
  111. int topBorderHeight = (titlePane != null) ? titlePane.getSize().height : 0;
  112. bottomSkin.paintSkin(g, 0, height-bottomSkin.getHeight(),
  113. width, bottomSkin.getHeight(),
  114. isSelected ? 0 : 1);
  115. leftSkin.paintSkin(g, 0, topBorderHeight-1,
  116. leftSkin.getWidth(), height-topBorderHeight-bottomSkin.getHeight()+2,
  117. isSelected ? 0 : 1);
  118. rightSkin.paintSkin(g, width-rightSkin.getWidth(), topBorderHeight-1,
  119. rightSkin.getWidth(), height-topBorderHeight-bottomSkin.getHeight()+2,
  120. isSelected ? 0 : 1);
  121. }
  122. public Insets getBorderInsets(Component c) {
  123. return getBorderInsets(c, new Insets(0, 0, 0, 0));
  124. }
  125. public Insets getBorderInsets(Component c, Insets insets) {
  126. insets.top = 4;
  127. insets.left = leftSkin.getWidth();
  128. insets.right = rightSkin.getWidth();
  129. insets.bottom = bottomSkin.getHeight();
  130. return insets;
  131. }
  132. public boolean isBorderOpaque() {
  133. return true;
  134. }
  135. }
  136. }