Browse Source

REPORT-60472 气泡提示文字不应该可以修改

research/11.0
kuangshuai 3 years ago
parent
commit
c33e4fe1d9
  1. 28
      designer-base/src/main/java/com/fr/design/mainframe/guide/ui/bubble/BubbleWithClose.java

28
designer-base/src/main/java/com/fr/design/mainframe/guide/ui/bubble/BubbleWithClose.java

@ -2,12 +2,15 @@ package com.fr.design.mainframe.guide.ui.bubble;
import com.fr.base.GraphHelper; import com.fr.base.GraphHelper;
import com.fr.design.gui.frpane.UITextPane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.itextarea.UITextArea;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.JTextArea; import javax.swing.JTextPane;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Container; import java.awt.Container;
@ -35,10 +38,11 @@ public class BubbleWithClose extends Bubble {
private static final Color CONTENT_COLOR = new Color(51,51,52,128); private static final Color CONTENT_COLOR = new Color(51,51,52,128);
private static final Insets DEFAULT_INSET = new Insets(10, 15, 10, 15); private static final Insets DEFAULT_INSET = new Insets(10, 15, 10, 15);
private String title; private String title;
private String content; private String content;
private UITextArea titleTextArea; private UITextPane titleTextArea;
private UITextArea contentTextArea; private UITextPane contentTextArea;
private UIButton closeButton; private UIButton closeButton;
public BubbleWithClose(String title, String content) { public BubbleWithClose(String title, String content) {
@ -145,18 +149,24 @@ public class BubbleWithClose extends Bubble {
} }
} }
private UITextArea createTextArea(String str, Font font, Color foreground) { private UITextPane createTextArea(String str, Font font, Color foreground) {
UITextArea textArea= new UITextArea(str){ UITextPane textArea= new UITextPane(){
@Override @Override
public Insets getInsets() { public Insets getInsets() {
return new Insets(0, 0, 0, 0); return new Insets(0, 0, 0, 0);
} }
}; };
textArea.setEnabled(true); textArea.setText(str);
textArea.setEnabled(false);
textArea.setDisabledTextColor(foreground);
textArea.setBorder(null); textArea.setBorder(null);
textArea.setFont(font); textArea.setFont(font);
textArea.setOpaque(false); textArea.setOpaque(false);
textArea.setForeground(foreground); textArea.setForeground(foreground);
StyledDocument doc = textArea.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
return textArea; return textArea;
} }
@ -206,7 +216,7 @@ public class BubbleWithClose extends Bubble {
g2.fillRoundRect(bounds.x, bounds.y, bounds.width, HEADER_HEIGHT, 10, 10); g2.fillRoundRect(bounds.x, bounds.y, bounds.width, HEADER_HEIGHT, 10, 10);
} }
private int countLines(JTextArea textArea, int max_width) { private int countLines(JTextPane textArea, int max_width) {
AttributedString text = new AttributedString(textArea.getText()); AttributedString text = new AttributedString(textArea.getText());
text.addAttribute(TextAttribute.FONT, textArea.getFont()); text.addAttribute(TextAttribute.FONT, textArea.getFont());
FontRenderContext frc = textArea.getFontMetrics(textArea.getFont()) FontRenderContext frc = textArea.getFontMetrics(textArea.getFont())
@ -222,7 +232,7 @@ public class BubbleWithClose extends Bubble {
return lines; return lines;
} }
private Dimension calTextSize(JTextArea textArea, int maxWidth) { private Dimension calTextSize(JTextPane textArea, int maxWidth) {
if (textArea == null) { if (textArea == null) {
return new Dimension(0, 0); return new Dimension(0, 0);
} }

Loading…
Cancel
Save