34 * based upon css attributes. 35 * 36 * @author Timothy Prinzing 37 */ 38 public class InlineView extends LabelView { 39 40 /** 41 * Constructs a new view wrapped on an element. 42 * 43 * @param elem the element 44 */ 45 public InlineView(Element elem) { 46 super(elem); 47 StyleSheet sheet = getStyleSheet(); 48 attr = sheet.getViewAttributes(this); 49 } 50 51 /** 52 * Gives notification that something was inserted into 53 * the document in a location that this view is responsible for. 54 * If either parameter is <code>null</code>, behavior of this method is 55 * implementation dependent. 56 * 57 * @param e the change information from the associated document 58 * @param a the current allocation of the view 59 * @param f the factory to use to rebuild if the view has children 60 * @since 1.5 61 * @see View#insertUpdate 62 */ 63 public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) { 64 super.insertUpdate(e, a, f); 65 } 66 67 /** 68 * Gives notification that something was removed from the document 69 * in a location that this view is responsible for. 70 * If either parameter is <code>null</code>, behavior of this method is 71 * implementation dependent. 72 * 73 * @param e the change information from the associated document 74 * @param a the current allocation of the view 75 * @param f the factory to use to rebuild if the view has children 76 * @since 1.5 77 * @see View#removeUpdate 78 */ 79 public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) { 80 super.removeUpdate(e, a, f); 81 } 82 83 /** 84 * Gives notification from the document that attributes were changed 85 * in a location that this view is responsible for. 86 * 87 * @param e the change information from the associated document 88 * @param a the current allocation of the view 89 * @param f the factory to use to rebuild if the view has children 90 * @see View#changedUpdate 91 */ 92 public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) { 93 super.changedUpdate(e, a, f); 94 StyleSheet sheet = getStyleSheet(); 95 attr = sheet.getViewAttributes(this); 96 preferenceChanged(null, true, true); 97 } 98 99 /** 100 * Fetches the attributes to use when rendering. This is 101 * implemented to multiplex the attributes specified in the 102 * model with a StyleSheet. 103 */ 104 public AttributeSet getAttributes() { 105 return attr; 106 } 107 108 /** 109 * Determines how attractive a break opportunity in 110 * this view is. This can be used for determining which 111 * view is the most attractive to call <code>breakView</code> 112 * on in the process of formatting. A view that represents 113 * text that has whitespace in it might be more attractive 114 * than a view that has no whitespace, for example. The 115 * higher the weight, the more attractive the break. A 116 * value equal to or lower than <code>BadBreakWeight</code> 117 * should not be considered for a break. A value greater 118 * than or equal to <code>ForcedBreakWeight</code> should 119 * be broken. 120 * <p> 121 * This is implemented to provide the default behavior 122 * of returning <code>BadBreakWeight</code> unless the length 123 * is greater than the length of the view in which case the 124 * entire view represents the fragment. Unless a view has 125 * been written to support breaking behavior, it is not 126 * attractive to try and break the view. An example of 127 * a view that does support breaking is <code>LabelView</code>. 128 * An example of a view that uses break weight is 129 * <code>ParagraphView</code>. 130 * 131 * @param axis may be either View.X_AXIS or View.Y_AXIS 132 * @param pos the potential location of the start of the 133 * broken view >= 0. This may be useful for calculating tab 134 * positions. 135 * @param len specifies the relative length from <em>pos</em> 136 * where a potential break is desired >= 0. 137 * @return the weight, which should be a value between 138 * ForcedBreakWeight and BadBreakWeight. 139 * @see LabelView 140 * @see ParagraphView 141 * @see javax.swing.text.View#BadBreakWeight 142 * @see javax.swing.text.View#GoodBreakWeight 143 * @see javax.swing.text.View#ExcellentBreakWeight 144 * @see javax.swing.text.View#ForcedBreakWeight 145 */ 146 public int getBreakWeight(int axis, float pos, float len) { 147 if (nowrap) { 148 return BadBreakWeight; 149 } 150 return super.getBreakWeight(axis, pos, len); 151 } 152 153 /** 154 * Tries to break this view on the given axis. Refer to 155 * {@link javax.swing.text.View#breakView} for a complete 156 * description of this method. 157 * <p>Behavior of this method is unspecified in case <code>axis</code> 158 * is neither <code>View.X_AXIS</code> nor <code>View.Y_AXIS</code>, and 159 * in case <code>offset</code>, <code>pos</code>, or <code>len</code> 160 * is null. 161 * 162 * @param axis may be either <code>View.X_AXIS</code> or 163 * <code>View.Y_AXIS</code> 164 * @param offset the location in the document model 165 * that a broken fragment would occupy >= 0. This 166 * would be the starting offset of the fragment 167 * returned 168 * @param pos the position along the axis that the 169 * broken view would occupy >= 0. This may be useful for 170 * things like tab calculations 171 * @param len specifies the distance along the axis 172 * where a potential break is desired >= 0 173 * @return the fragment of the view that represents the 174 * given span. 175 * @since 1.5 176 * @see javax.swing.text.View#breakView 177 */ 178 public View breakView(int axis, int offset, float pos, float len) { 179 return super.breakView(axis, offset, pos, len); 180 } 181 182 183 /** | 34 * based upon css attributes. 35 * 36 * @author Timothy Prinzing 37 */ 38 public class InlineView extends LabelView { 39 40 /** 41 * Constructs a new view wrapped on an element. 42 * 43 * @param elem the element 44 */ 45 public InlineView(Element elem) { 46 super(elem); 47 StyleSheet sheet = getStyleSheet(); 48 attr = sheet.getViewAttributes(this); 49 } 50 51 /** 52 * Gives notification that something was inserted into 53 * the document in a location that this view is responsible for. 54 * If either parameter is {@code null}, behavior of this method is 55 * implementation dependent. 56 * 57 * @param e the change information from the associated document 58 * @param a the current allocation of the view 59 * @param f the factory to use to rebuild if the view has children 60 * @since 1.5 61 * @see View#insertUpdate 62 */ 63 public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) { 64 super.insertUpdate(e, a, f); 65 } 66 67 /** 68 * Gives notification that something was removed from the document 69 * in a location that this view is responsible for. 70 * If either parameter is {@code null}, behavior of this method is 71 * implementation dependent. 72 * 73 * @param e the change information from the associated document 74 * @param a the current allocation of the view 75 * @param f the factory to use to rebuild if the view has children 76 * @since 1.5 77 * @see View#removeUpdate 78 */ 79 public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) { 80 super.removeUpdate(e, a, f); 81 } 82 83 /** 84 * Gives notification from the document that attributes were changed 85 * in a location that this view is responsible for. 86 * 87 * @param e the change information from the associated document 88 * @param a the current allocation of the view 89 * @param f the factory to use to rebuild if the view has children 90 * @see View#changedUpdate 91 */ 92 public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) { 93 super.changedUpdate(e, a, f); 94 StyleSheet sheet = getStyleSheet(); 95 attr = sheet.getViewAttributes(this); 96 preferenceChanged(null, true, true); 97 } 98 99 /** 100 * Fetches the attributes to use when rendering. This is 101 * implemented to multiplex the attributes specified in the 102 * model with a StyleSheet. 103 */ 104 public AttributeSet getAttributes() { 105 return attr; 106 } 107 108 /** 109 * Determines how attractive a break opportunity in 110 * this view is. This can be used for determining which 111 * view is the most attractive to call {@code breakView} 112 * on in the process of formatting. A view that represents 113 * text that has whitespace in it might be more attractive 114 * than a view that has no whitespace, for example. The 115 * higher the weight, the more attractive the break. A 116 * value equal to or lower than {@code BadBreakWeight} 117 * should not be considered for a break. A value greater 118 * than or equal to {@code ForcedBreakWeight} should 119 * be broken. 120 * <p> 121 * This is implemented to provide the default behavior 122 * of returning {@code BadBreakWeight} unless the length 123 * is greater than the length of the view in which case the 124 * entire view represents the fragment. Unless a view has 125 * been written to support breaking behavior, it is not 126 * attractive to try and break the view. An example of 127 * a view that does support breaking is {@code LabelView}. 128 * An example of a view that uses break weight is 129 * {@code ParagraphView}. 130 * 131 * @param axis may be either View.X_AXIS or View.Y_AXIS 132 * @param pos the potential location of the start of the 133 * broken view >= 0. This may be useful for calculating tab 134 * positions. 135 * @param len specifies the relative length from <em>pos</em> 136 * where a potential break is desired >= 0. 137 * @return the weight, which should be a value between 138 * ForcedBreakWeight and BadBreakWeight. 139 * @see LabelView 140 * @see ParagraphView 141 * @see javax.swing.text.View#BadBreakWeight 142 * @see javax.swing.text.View#GoodBreakWeight 143 * @see javax.swing.text.View#ExcellentBreakWeight 144 * @see javax.swing.text.View#ForcedBreakWeight 145 */ 146 public int getBreakWeight(int axis, float pos, float len) { 147 if (nowrap) { 148 return BadBreakWeight; 149 } 150 return super.getBreakWeight(axis, pos, len); 151 } 152 153 /** 154 * Tries to break this view on the given axis. Refer to 155 * {@link javax.swing.text.View#breakView} for a complete 156 * description of this method. 157 * <p>Behavior of this method is unspecified in case {@code axis} 158 * is neither {@code View.X_AXIS} nor {@code View.Y_AXIS}, and 159 * in case {@code offset}, {@code pos}, or {@code len} 160 * is null. 161 * 162 * @param axis may be either {@code View.X_AXIS} or 163 * {@code View.Y_AXIS} 164 * @param offset the location in the document model 165 * that a broken fragment would occupy >= 0. This 166 * would be the starting offset of the fragment 167 * returned 168 * @param pos the position along the axis that the 169 * broken view would occupy >= 0. This may be useful for 170 * things like tab calculations 171 * @param len specifies the distance along the axis 172 * where a potential break is desired >= 0 173 * @return the fragment of the view that represents the 174 * given span. 175 * @since 1.5 176 * @see javax.swing.text.View#breakView 177 */ 178 public View breakView(int axis, int offset, float pos, float len) { 179 return super.breakView(axis, offset, pos, len); 180 } 181 182 183 /** |