下面列出了javax.swing.JEditorPane#isEditable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void setEditable(boolean b) {
JEditorPane editor = getEditor();
if (editor.isEditable() == b) return;
editor.setEditable(b);
if (b) {
if (lastBgColor != null) editor.setBackground(lastBgColor);
if (lastCaret != null) editor.setCaret(lastCaret);
} else {
lastBgColor = editor.getBackground();
lastCaret = editor.getCaret();
editor.setBackground(disabledBgColor);
editor.setCaret(nullCaret);
}
}
public void setEditable(boolean b) {
JEditorPane editor = getEditor();
if (editor.isEditable() == b) return;
editor.setEditable(b);
if (b) {
if (lastBgColor != null) editor.setBackground(lastBgColor);
if (lastCaret != null) editor.setCaret(lastCaret);
} else {
lastBgColor = editor.getBackground();
lastCaret = editor.getCaret();
editor.setBackground(disabledBgColor);
editor.setCaret(nullCaret);
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
@Override
public void mouseClicked(MouseEvent e)
{
JEditorPane editor = (JEditorPane) e.getSource();
if (!editor.isEditable() && SwingUtilities.isLeftMouseButton(e))
{
Bias[] bias = new Bias[1];
Point pt = new Point(e.getX(), e.getY());
int pos = editor.getUI().viewToModel(editor, pt, bias);
if (bias[0] == Position.Bias.Backward && pos > 0) pos--;
//Point pt = new Point(e.getX(), e.getY());
//int pos = editor.viewToModel(pt);
// System.err.println("found position : " + pos);
if (pos >= 0)
{
Element el = ((SwingBoxDocument) editor.getDocument()).getCharacterElement(pos);
AttributeSet attr = el.getAttributes();
Anchor anchor = (Anchor) attr.getAttribute(Constants.ATTRIBUTE_ANCHOR_REFERENCE);
if (anchor != null && anchor.isActive())
createHyperLinkEvent(editor, el, anchor, EventType.ACTIVATED);
}
}
}
@Override
public void mouseClicked(MouseEvent e) {
JEditorPane editor = (JEditorPane) e.getSource();
if (editor.isEditable() && SwingUtilities.isLeftMouseButton(e) && e.getClickCount() >= 2) {
// make sure we do not start editing twice to avoid internal Java explosions
editor.setEditable(false);
super.mouseClicked(e);
editor.setEditable(true);
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
public void actionPerformed(ActionEvent e) {
JEditorPane target = getEditor(e);
if (target != null) {
if ((!target.isEditable()) || (!target.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
StyledEditorKit sek = getStyledEditorKit(target);
if (tempSet != null) {
tempSet.removeAttributes(tempSet);
}
else {
tempSet = new SimpleAttributeSet();
}
tempSet.addAttributes(sek.getInputAttributes());
target.replaceSelection("\n");
MutableAttributeSet ia = sek.getInputAttributes();
ia.removeAttributes(ia);
ia.addAttributes(tempSet);
tempSet.removeAttributes(tempSet);
}
else {
// See if we are in a JTextComponent.
JTextComponent text = getTextComponent(e);
if (text != null) {
if ((!text.isEditable()) || (!text.isEnabled())) {
UIManager.getLookAndFeel().provideErrorFeedback(target);
return;
}
text.replaceSelection("\n");
}
}
}
@Override
public void mouseMoved(MouseEvent e)
{
JEditorPane editor = (JEditorPane) e.getSource();
if (!editor.isEditable())
{
Bias[] bias = new Bias[1];
Point pt = new Point(e.getX(), e.getY());
int pos = editor.getUI().viewToModel(editor, pt, bias);
if (bias[0] == Position.Bias.Backward && pos > 0) pos--;
if (pos >= 0 && (editor.getDocument() instanceof StyledDocument))
{
Element elem = ((StyledDocument) editor.getDocument()).getCharacterElement(pos);
Object bb = elem.getAttributes().getAttribute(Constants.ATTRIBUTE_BOX_REFERENCE);
Anchor anchor = (Anchor) elem.getAttributes().getAttribute(Constants.ATTRIBUTE_ANCHOR_REFERENCE);
//System.out.println("Pos: " + pos);
//System.out.println("Elem: " + elem.getAttributes().getAttribute(Constants.ATTRIBUTE_BOX_REFERENCE));
//System.out.println("Anchor: " + anchor);
if (elem != prevElem)
{
prevElem = elem;
if (!anchor.isActive())
{
if (bb != null && bb instanceof TextBox)
setCursor(editor, textCursor);
else
setCursor(editor, defaultCursor);
}
}
if (anchor != prevAnchor)
{
if (prevAnchor == null)
{
if (anchor.isActive())
{
createHyperLinkEvent(editor, elem, anchor, EventType.ENTERED);
}
prevAnchor = anchor;
}
else if (!prevAnchor.equalProperties(anchor.getProperties()))
{
if (prevAnchor.isActive())
{
createHyperLinkEvent(editor, prevElem, prevAnchor, EventType.EXITED);
}
if (anchor.isActive())
{
createHyperLinkEvent(editor, elem, anchor, EventType.ENTERED);
}
prevAnchor = anchor;
}
}
}
else //nothing found
{
prevElem = null;
if (prevAnchor != null && prevAnchor.isActive())
{
createHyperLinkEvent(editor, prevElem, prevAnchor, EventType.EXITED);
prevAnchor = null;
}
setCursor(editor, defaultCursor);
}
}
}