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