1. /*
  2. * @(#)MotifDesktopPaneUI.java 1.17 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.motif;
  8. import javax.swing.*;
  9. import java.awt.Rectangle;
  10. import java.awt.Dimension;
  11. import java.awt.Insets;
  12. import java.awt.Color;
  13. import java.awt.Graphics;
  14. import javax.swing.plaf.*;
  15. import java.io.Serializable;
  16. /**
  17. * <p>
  18. * <strong>Warning:</strong>
  19. * Serialized objects of this class will not be compatible with
  20. * future Swing releases. The current serialization support is appropriate
  21. * for short term storage or RMI between applications running the same
  22. * version of Swing. A future release of Swing will provide support for
  23. * long term persistence.
  24. *
  25. * @version 1.17 11/29/01
  26. * @author David Kloba
  27. */
  28. public class MotifDesktopPaneUI extends javax.swing.plaf.basic.BasicDesktopPaneUI
  29. {
  30. /// DesktopPaneUI methods
  31. public static ComponentUI createUI(JComponent d) {
  32. return new MotifDesktopPaneUI();
  33. }
  34. public MotifDesktopPaneUI() {
  35. }
  36. protected void installDesktopManager() {
  37. if(desktop.getDesktopManager() == null) {
  38. desktopManager = new MotifDesktopManager();
  39. desktop.setDesktopManager(desktopManager);
  40. }
  41. }
  42. public Insets getInsets(JComponent c) {return new Insets(0,0,0,0);}
  43. ////////////////////////////////////////////////////////////////////////////////////
  44. /// DragPane class
  45. ////////////////////////////////////////////////////////////////////////////////////
  46. private class DragPane extends JComponent {
  47. public void paint(Graphics g) {
  48. g.setColor(Color.darkGray);
  49. g.drawRect(0, 0, getWidth()-1, getHeight()-1);
  50. }
  51. };
  52. ////////////////////////////////////////////////////////////////////////////////////
  53. /// MotifDesktopManager class
  54. ////////////////////////////////////////////////////////////////////////////////////
  55. private class MotifDesktopManager extends DefaultDesktopManager implements Serializable {
  56. JComponent dragPane;
  57. boolean usingDragPane;
  58. // PENDING(klobad) this should be optimized
  59. public void setBoundsForFrame(JComponent f, int newX, int newY,
  60. int newWidth, int newHeight) {
  61. if(!usingDragPane) {
  62. boolean didResize;
  63. didResize = (f.getWidth() != newWidth || f.getHeight() != newHeight);
  64. Rectangle r = f.getBounds();
  65. f.setBounds(newX, newY, newWidth, newHeight);
  66. SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
  67. f.getParent().repaint(r.x, r.y, r.width, r.height);
  68. if(didResize) {
  69. f.validate();
  70. }
  71. } else {
  72. Rectangle r = dragPane.getBounds();
  73. dragPane.setBounds(newX, newY, newWidth, newHeight);
  74. SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
  75. dragPane.getParent().repaint(r.x, r.y, r.width, r.height);
  76. }
  77. }
  78. public void beginDraggingFrame(JComponent f) {
  79. usingDragPane = false;
  80. if(f.getParent() instanceof JLayeredPane) {
  81. if(dragPane == null)
  82. dragPane = new DragPane();
  83. JLayeredPane p = (JLayeredPane)f.getParent();
  84. p.setLayer(dragPane, Integer.MAX_VALUE);
  85. dragPane.setBounds(f.getX(), f.getY(), f.getWidth(), f.getHeight());
  86. p.add(dragPane);
  87. usingDragPane = true;
  88. }
  89. }
  90. public void dragFrame(JComponent f, int newX, int newY) {
  91. setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
  92. }
  93. public void endDraggingFrame(JComponent f) {
  94. if(usingDragPane) {
  95. JLayeredPane p = (JLayeredPane)f.getParent();
  96. p.remove(dragPane);
  97. usingDragPane = false;
  98. setBoundsForFrame(f, dragPane.getX(), dragPane.getY(),
  99. dragPane.getWidth(), dragPane.getHeight());
  100. }
  101. }
  102. public void beginResizingFrame(JComponent f, int direction) {
  103. usingDragPane = false;
  104. if(f.getParent() instanceof JLayeredPane) {
  105. if(dragPane == null)
  106. dragPane = new DragPane();
  107. JLayeredPane p = (JLayeredPane)f.getParent();
  108. p.setLayer(dragPane, Integer.MAX_VALUE);
  109. dragPane.setBounds(f.getX(), f.getY(),
  110. f.getWidth(), f.getHeight());
  111. p.add(dragPane);
  112. usingDragPane = true;
  113. }
  114. }
  115. public void resizeFrame(JComponent f, int newX, int newY,
  116. int newWidth, int newHeight) {
  117. setBoundsForFrame(f, newX, newY, newWidth, newHeight);
  118. }
  119. public void endResizingFrame(JComponent f) {
  120. if(usingDragPane) {
  121. JLayeredPane p = (JLayeredPane)f.getParent();
  122. p.remove(dragPane);
  123. usingDragPane = false;
  124. setBoundsForFrame(f, dragPane.getX(), dragPane.getY(),
  125. dragPane.getWidth(), dragPane.getHeight());
  126. }
  127. }
  128. }; /// END of MotifDesktopManager
  129. }