Created
October 12, 2019 02:33
-
-
Save pdglobal/2fae70828bcf1ffec8635e0eedbec012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package SIM.net.client.gui; | |
//By vallismortis from StackOverflow | |
//Many thanks! | |
import javax.swing.text.Element; | |
import javax.swing.text.LabelView; | |
import javax.swing.text.StyleConstants; | |
import javax.swing.text.View; | |
import javax.swing.text.ViewFactory; | |
import javax.swing.text.html.HTML; | |
import javax.swing.text.html.HTMLEditorKit; | |
public class WrappedHtmlEditorKit extends HTMLEditorKit | |
{ | |
private static final long serialVersionUID = 1L; | |
private ViewFactory viewFactory = null; | |
public WrappedHtmlEditorKit() | |
{ | |
super(); | |
this.viewFactory = new WrappedHtmlFactory(); | |
return; | |
} | |
@Override | |
public ViewFactory getViewFactory() | |
{ | |
return this.viewFactory; | |
} | |
private class WrappedHtmlFactory extends HTMLEditorKit.HTMLFactory | |
{ | |
@Override | |
public View create(Element elem) | |
{ | |
View v = super.create(elem); | |
if (v instanceof LabelView) | |
{ | |
Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute); | |
if ((o instanceof HTML.Tag) && (o == HTML.Tag.BR)) | |
{ | |
return v; | |
} | |
return new WrapLabelView(elem); | |
} | |
return v; | |
} | |
private class WrapLabelView extends LabelView | |
{ | |
public WrapLabelView(Element elem) | |
{ | |
super(elem); | |
return; | |
} | |
@Override | |
public float getMinimumSpan(int axis) | |
{ | |
switch (axis) | |
{ | |
case View.X_AXIS: | |
{ | |
return 0; | |
} | |
case View.Y_AXIS: | |
{ | |
return super.getMinimumSpan(axis); | |
} | |
default: | |
{ | |
throw new IllegalArgumentException("Invalid axis: " + axis); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment