1 19 20 package org.netbeans.modules.junit; 21 22 import java.awt.Dimension ; 23 import java.awt.LayoutManager ; 24 import javax.swing.JPanel ; 25 26 33 public class SizeRestrictedPanel extends JPanel { 34 35 36 private final boolean widthRestriction; 37 38 private final boolean heightRestriction; 39 40 43 public SizeRestrictedPanel() { 44 this(true, true); 45 } 46 47 53 public SizeRestrictedPanel(boolean widthRestriction, 54 boolean heightRestriction) { 55 super(); 56 this.widthRestriction = widthRestriction; 57 this.heightRestriction = heightRestriction; 58 } 59 60 66 public SizeRestrictedPanel(LayoutManager layoutMgr) { 67 this(layoutMgr, true, true); 68 } 69 70 78 public SizeRestrictedPanel(LayoutManager layoutMgr, 79 boolean widthRestriction, 80 boolean heightRestriction) { 81 super(layoutMgr); 82 this.widthRestriction = widthRestriction; 83 this.heightRestriction = heightRestriction; 84 } 85 86 95 public Dimension getMaximumSize() { 96 if (widthRestriction && heightRestriction) { return getPreferredSize(); 98 } 99 if (widthRestriction == heightRestriction) { return super.getMaximumSize(); 101 } 102 103 Dimension maximumSize = super.getMaximumSize(); 104 if (widthRestriction) { 105 maximumSize.width = getPreferredSize().width; 106 } else { 107 maximumSize.height = getPreferredSize().height; 108 } 109 return maximumSize; 110 } 111 112 } 113 | Popular Tags |