| Method from javax.swing.text.html.HiddenTagView Detail: |
void _setTextFromModel() {
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();
}
}
}
This resets the text on the text component we created to match
that of the AttributeSet for the Element we represent. |
void _updateModelFromText() {
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;
}
}
}
}
This copies the text from the text component we've created
to the Element's AttributeSet we represent. |
public void changedUpdate(DocumentEvent e) {
updateModelFromText();
}
|
public void changedUpdate(DocumentEvent e,
Shape a,
ViewFactory f) {
if (!isSettingAttributes) {
setTextFromModel();
}
}
|
protected 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);
}
|
String getRepresentedText() {
String retValue = getElement().getName();
return (retValue == null) ? "" : retValue;
}
|
JTextComponent getTextComponent() {
Component comp = getComponent();
return (comp == null) ? null : (JTextComponent)((Container)comp).
getComponent(0);
}
|
public void insertUpdate(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(DocumentEvent e) {
updateModelFromText();
}
|
void resetBorder() {
Component comp = getComponent();
if (comp != null) {
if (isEndTag()) {
((JPanel)comp).setBorder(EndBorder);
}
else {
((JPanel)comp).setBorder(StartBorder);
}
}
}
|
void setTextFromModel() {
if (SwingUtilities.isEventDispatchThread()) {
_setTextFromModel();
}
else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
_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. |
void updateModelFromText() {
if (!isSettingAttributes) {
if (SwingUtilities.isEventDispatchThread()) {
_updateModelFromText();
}
else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
_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. |
void updateYAlign(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 > 0) ? (h - d) / h : 0;
}
|