Methods Summary |
---|
void | _setTextFromModel()This resets the text on the text component we created to match
that of the AttributeSet for the Element we represent.
Document doc = getDocument();
try {
isSettingAttributes = true;
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readLock();
}
JTextComponent text = getTextComponent();
if (text != null) {
text.setText(getRepresentedText());
resetBorder();
Container host = getContainer();
if (host != null) {
preferenceChanged(this, true, true);
host.repaint();
}
}
}
finally {
isSettingAttributes = false;
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readUnlock();
}
}
|
void | _updateModelFromText()This copies the text from the text component we've created
to the Element's AttributeSet we represent.
Document doc = getDocument();
Object name = getElement().getAttributes().getAttribute
(StyleConstants.NameAttribute);
if ((name instanceof HTML.UnknownTag) &&
(doc instanceof StyledDocument)) {
SimpleAttributeSet sas = new SimpleAttributeSet();
JTextComponent textComponent = getTextComponent();
if (textComponent != null) {
String text = textComponent.getText();
isSettingAttributes = true;
try {
sas.addAttribute(StyleConstants.NameAttribute,
new HTML.UnknownTag(text));
((StyledDocument)doc).setCharacterAttributes
(getStartOffset(), getEndOffset() -
getStartOffset(), sas, false);
}
finally {
isSettingAttributes = false;
}
}
}
|
public void | changedUpdate(javax.swing.event.DocumentEvent e, java.awt.Shape a, javax.swing.text.ViewFactory f)
if (!isSettingAttributes) {
setTextFromModel();
}
|
public void | changedUpdate(javax.swing.event.DocumentEvent e)
updateModelFromText();
|
protected java.awt.Component | createComponent()
JTextField tf = new JTextField(getElement().getName());
Document doc = getDocument();
Font font;
if (doc instanceof StyledDocument) {
font = ((StyledDocument)doc).getFont(getAttributes());
tf.setFont(font);
}
else {
font = tf.getFont();
}
tf.getDocument().addDocumentListener(this);
updateYAlign(font);
// Create a panel to wrap the textfield so that the textfields
// laf border shows through.
JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(null);
if (isEndTag()) {
panel.setBorder(EndBorder);
}
else {
panel.setBorder(StartBorder);
}
panel.add(tf);
return panel;
|
public float | getAlignment(int axis)
if (axis == View.Y_AXIS) {
return yAlign;
}
return 0.5f;
|
public float | getMaximumSpan(int axis)
if (axis == View.X_AXIS && isVisible()) {
// Default to preferred.
return Math.max(30, super.getMaximumSpan(axis));
}
return super.getMaximumSpan(axis);
|
public float | getMinimumSpan(int axis)
if (axis == View.X_AXIS && isVisible()) {
// Default to preferred.
return Math.max(30, super.getPreferredSpan(axis));
}
return super.getMinimumSpan(axis);
|
public float | getPreferredSpan(int axis)
if (axis == View.X_AXIS && isVisible()) {
return Math.max(30, super.getPreferredSpan(axis));
}
return super.getPreferredSpan(axis);
|
java.lang.String | getRepresentedText()
String retValue = getElement().getName();
return (retValue == null) ? "" : retValue;
|
javax.swing.text.JTextComponent | getTextComponent()
Component comp = getComponent();
return (comp == null) ? null : (JTextComponent)((Container)comp).
getComponent(0);
|
public void | insertUpdate(javax.swing.event.DocumentEvent e)
updateModelFromText();
|
boolean | isEndTag()
AttributeSet as = getElement().getAttributes();
if (as != null) {
Object end = as.getAttribute(HTML.Attribute.ENDTAG);
if (end != null && (end instanceof String) &&
((String)end).equals("true")) {
return true;
}
}
return false;
|
public void | removeUpdate(javax.swing.event.DocumentEvent e)
updateModelFromText();
|
void | resetBorder()
Component comp = getComponent();
if (comp != null) {
if (isEndTag()) {
((JPanel)comp).setBorder(EndBorder);
}
else {
((JPanel)comp).setBorder(StartBorder);
}
}
|
void | setTextFromModel()This resets the text on the text component we created to match
that of the AttributeSet for the Element we represent.
If this is invoked on the event dispatching thread, this
directly invokes _setTextFromModel , otherwise
SwingUtilities.invokeLater is used to schedule execution
of _setTextFromModel .
if (SwingUtilities.isEventDispatchThread()) {
_setTextFromModel();
}
else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
_setTextFromModel();
}
});
}
|
void | updateModelFromText()This copies the text from the text component we've created
to the Element's AttributeSet we represent.
If this is invoked on the event dispatching thread, this
directly invokes _updateModelFromText , otherwise
SwingUtilities.invokeLater is used to schedule execution
of _updateModelFromText .
if (!isSettingAttributes) {
if (SwingUtilities.isEventDispatchThread()) {
_updateModelFromText();
}
else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
_updateModelFromText();
}
});
}
}
|
void | updateYAlign(java.awt.Font font)
Container c = getContainer();
FontMetrics fm = (c != null) ? c.getFontMetrics(font) :
Toolkit.getDefaultToolkit().getFontMetrics(font);
float h = fm.getHeight();
float d = fm.getDescent();
yAlign = (h - d) / h;
|