919 * Gets the preferred size for the editor component. If the component 920 * has been given a size prior to receiving this request, it will 921 * set the size of the view hierarchy to reflect the size of the component 922 * before requesting the preferred size of the view hierarchy. This 923 * allows formatted views to format to the current component size before 924 * answering the request. Other views don't care about currently formatted 925 * size and give the same answer either way. 926 * 927 * @param c the editor component 928 * @return the size 929 */ 930 public Dimension getPreferredSize(JComponent c) { 931 Document doc = editor.getDocument(); 932 Insets i = c.getInsets(); 933 Dimension d = c.getSize(); 934 935 if (doc instanceof AbstractDocument) { 936 ((AbstractDocument)doc).readLock(); 937 } 938 try { 939 if ((d.width > (i.left + i.right)) && (d.height > (i.top + i.bottom))) { 940 rootView.setSize(d.width - i.left - i.right, d.height - i.top - i.bottom); 941 } 942 else if (d.width == 0 && d.height == 0) { 943 // Probably haven't been layed out yet, force some sort of 944 // initial sizing. 945 rootView.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE); 946 } 947 d.width = (int) Math.min((long) rootView.getPreferredSpan(View.X_AXIS) + 948 (long) i.left + (long) i.right + caretMargin, Integer.MAX_VALUE); 949 d.height = (int) Math.min((long) rootView.getPreferredSpan(View.Y_AXIS) + 950 (long) i.top + (long) i.bottom, Integer.MAX_VALUE); 951 } finally { 952 if (doc instanceof AbstractDocument) { 953 ((AbstractDocument)doc).readUnlock(); 954 } 955 } 956 return d; 957 } 958 959 /** 960 * Gets the minimum size for the editor component. | 919 * Gets the preferred size for the editor component. If the component 920 * has been given a size prior to receiving this request, it will 921 * set the size of the view hierarchy to reflect the size of the component 922 * before requesting the preferred size of the view hierarchy. This 923 * allows formatted views to format to the current component size before 924 * answering the request. Other views don't care about currently formatted 925 * size and give the same answer either way. 926 * 927 * @param c the editor component 928 * @return the size 929 */ 930 public Dimension getPreferredSize(JComponent c) { 931 Document doc = editor.getDocument(); 932 Insets i = c.getInsets(); 933 Dimension d = c.getSize(); 934 935 if (doc instanceof AbstractDocument) { 936 ((AbstractDocument)doc).readLock(); 937 } 938 try { 939 if ((d.width > (i.left + i.right + caretMargin)) && (d.height > (i.top + i.bottom))) { 940 rootView.setSize(d.width - i.left - i.right - 941 caretMargin, d.height - i.top - i.bottom); 942 } 943 else if (d.width == 0 && d.height == 0) { 944 // Probably haven't been layed out yet, force some sort of 945 // initial sizing. 946 rootView.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE); 947 } 948 d.width = (int) Math.min((long) rootView.getPreferredSpan(View.X_AXIS) + 949 (long) i.left + (long) i.right + caretMargin, Integer.MAX_VALUE); 950 d.height = (int) Math.min((long) rootView.getPreferredSpan(View.Y_AXIS) + 951 (long) i.top + (long) i.bottom, Integer.MAX_VALUE); 952 } finally { 953 if (doc instanceof AbstractDocument) { 954 ((AbstractDocument)doc).readUnlock(); 955 } 956 } 957 return d; 958 } 959 960 /** 961 * Gets the minimum size for the editor component. |