mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-207914 Validation message doesn't fit explanation text
GitOrigin-RevId: 16b6f2c8b364ac97372a6ca66c06fb8d7237e5f1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
be778d6d9f
commit
0f9af1cf11
@@ -20,6 +20,7 @@ import com.intellij.util.ui.JBValue;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
@@ -242,8 +243,8 @@ public class ComponentValidator {
|
||||
JEditorPane tipComponent = new JEditorPane();
|
||||
View v = BasicHTML.createHTMLView(tipComponent, String.format("<html>%s</html>", info.message));
|
||||
String text = v.getPreferredSpan(View.X_AXIS) > MAX_WIDTH.get() ?
|
||||
String.format("<html><div width=%d>%s</div></html>", MAX_WIDTH.get(), info.message) :
|
||||
String.format("<html><div>%s</div></html>", info.message);
|
||||
String.format("<html><body><div width=%d>%s</div><body></html>", MAX_WIDTH.get(), trimMessage(info.message, tipComponent)) :
|
||||
String.format("<html><body><div>%s</div></body></html>", info.message);
|
||||
|
||||
tipComponent.setContentType("text/html");
|
||||
tipComponent.setEditable(false);
|
||||
@@ -281,6 +282,18 @@ public class ComponentValidator {
|
||||
setShowShadow(true);
|
||||
}
|
||||
|
||||
private static String trimMessage(String message, JComponent c) {
|
||||
String[] words = message.split("\\s+");
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for(String word : words) {
|
||||
word = SwingUtilities2.clipStringIfNecessary(c, c.getFontMetrics(c.getFont()), word, MAX_WIDTH.get());
|
||||
result.append(word).append(" ");
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static boolean withinComponent(@NotNull ValidationInfo info, @NotNull MouseEvent e) {
|
||||
if (info.component != null && info.component.isShowing()) {
|
||||
Rectangle screenBounds = new Rectangle(info.component.getLocationOnScreen(), info.component.getSize());
|
||||
|
||||
Reference in New Issue
Block a user