47 |
import javax.swing.text.EditorKit; |
import javax.swing.text.EditorKit; |
48 |
import javax.swing.text.Element; |
import javax.swing.text.Element; |
49 |
import javax.swing.text.MutableAttributeSet; |
import javax.swing.text.MutableAttributeSet; |
50 |
|
import javax.swing.text.SimpleAttributeSet; |
51 |
import javax.swing.text.Style; |
import javax.swing.text.Style; |
52 |
|
import javax.swing.text.StyleConstants; |
53 |
import javax.swing.text.StyledDocument; |
import javax.swing.text.StyledDocument; |
54 |
import javax.swing.text.StyledEditorKit; |
import javax.swing.text.StyledEditorKit; |
55 |
|
|
194 |
*/ |
*/ |
195 |
public void insertComponent(Component component) |
public void insertComponent(Component component) |
196 |
{ |
{ |
197 |
// TODO: One space must be inserted here with attributes set to indicate |
SimpleAttributeSet atts = new SimpleAttributeSet(); |
198 |
// that the component must be displayed here. Have to figure out the |
atts.addAttribute(StyleConstants.ComponentAttribute, component); |
199 |
// attributes. |
atts.addAttribute(StyleConstants.NameAttribute, |
200 |
|
StyleConstants.ComponentElementName); |
201 |
|
try |
202 |
|
{ |
203 |
|
getDocument().insertString(getCaret().getDot(), " ", atts); |
204 |
|
} |
205 |
|
catch (BadLocationException ex) |
206 |
|
{ |
207 |
|
AssertionError err = new AssertionError("Unexpected bad location"); |
208 |
|
err.initCause(ex); |
209 |
|
throw err; |
210 |
|
} |
211 |
} |
} |
212 |
|
|
213 |
/** |
/** |
217 |
*/ |
*/ |
218 |
public void insertIcon(Icon icon) |
public void insertIcon(Icon icon) |
219 |
{ |
{ |
220 |
// TODO: One space must be inserted here with attributes set to indicate |
SimpleAttributeSet atts = new SimpleAttributeSet(); |
221 |
// that the icon must be displayed here. Have to figure out the |
atts.addAttribute(StyleConstants.IconAttribute, icon); |
222 |
// attributes. |
atts.addAttribute(StyleConstants.NameAttribute, |
223 |
|
StyleConstants.IconElementName); |
224 |
|
try |
225 |
|
{ |
226 |
|
getDocument().insertString(getCaret().getDot(), " ", atts); |
227 |
|
} |
228 |
|
catch (BadLocationException ex) |
229 |
|
{ |
230 |
|
AssertionError err = new AssertionError("Unexpected bad location"); |
231 |
|
err.initCause(ex); |
232 |
|
throw err; |
233 |
|
} |
234 |
} |
} |
235 |
|
|
236 |
/** |
/** |