Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
c13d67ae
Commit
c13d67ae
authored
6 years ago
by
Mikhail Sokolov
Browse files
Options
Download
Email Patches
Plain Diff
IDEA-209852 "New file dialog": Add validation error messages to the "Name" field
parent
69e2b23f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
platform/lang-impl/src/com/intellij/ide/actions/newclass/CreateWithTemplatesDialogPanel.java
+42
-21
.../ide/actions/newclass/CreateWithTemplatesDialogPanel.java
with
42 additions
and
21 deletions
+42
-21
platform/lang-impl/src/com/intellij/ide/actions/newclass/CreateWithTemplatesDialogPanel.java
+
42
-
21
View file @
c13d67ae
...
...
@@ -28,6 +28,8 @@ import java.awt.*;
import
java.awt.event.*
;
import
java.util.List
;
import
static
com
.
intellij
.
ide
.
ui
.
laf
.
darcula
.
DarculaUIUtil
.
Outline
;
public
class
CreateWithTemplatesDialogPanel
extends
JBPanel
implements
Disposable
{
private
final
JBTextField
myNameField
;
...
...
@@ -45,8 +47,6 @@ public class CreateWithTemplatesDialogPanel extends JBPanel implements Disposabl
myTemplatesList
=
createTemplatesList
(
templates
);
myErrorShowPoint
=
new
RelativePoint
(
myNameField
,
new
Point
(
0
,
myNameField
.
getHeight
()));
updateBorder
(
false
);
ScrollingUtil
.
installMoveUpAction
(
myTemplatesList
,
myNameField
);
ScrollingUtil
.
installMoveDownAction
(
myTemplatesList
,
myNameField
);
...
...
@@ -70,7 +70,7 @@ public class CreateWithTemplatesDialogPanel extends JBPanel implements Disposabl
}
public
void
setError
(
String
error
)
{
updateBorder
(
error
!=
null
);
myNameField
.
putClientProperty
(
"JComponent.outline"
,
error
!=
null
?
"error"
:
null
);
if
(
myErrorPopup
!=
null
&&
!
myErrorPopup
.
isDisposed
())
Disposer
.
dispose
(
myErrorPopup
);
if
(
error
==
null
)
return
;
...
...
@@ -80,8 +80,7 @@ public class CreateWithTemplatesDialogPanel extends JBPanel implements Disposabl
Dimension
hintSize
=
errorHint
.
getPreferredSize
();
Point
point
=
new
Point
(
0
,
insets
.
top
-
JBUI
.
scale
(
6
)
-
hintSize
.
height
);
myErrorShowPoint
=
new
RelativePoint
(
myNameField
,
point
);
});
popupBuilder
.
setCancelOnWindowDeactivation
(
false
)
}).
setCancelOnWindowDeactivation
(
false
)
.
setCancelOnClickOutside
(
true
);
myErrorPopup
=
popupBuilder
.
createPopup
();
...
...
@@ -97,22 +96,6 @@ public class CreateWithTemplatesDialogPanel extends JBPanel implements Disposabl
if
(
myErrorPopup
!=
null
&&
!
myErrorPopup
.
isDisposed
())
Disposer
.
dispose
(
myErrorPopup
);
}
private
void
updateBorder
(
boolean
error
)
{
JBColor
borderColor
=
JBColor
.
namedColor
(
"TextField.borderColor"
,
JBColor
.
namedColor
(
"Component.borderColor"
,
new
JBColor
(
0xbdbdbd
,
0x646464
))
);
Border
border
=
JBUI
.
Borders
.
customLine
(
borderColor
,
1
,
0
,
1
,
0
);
if
(
error
)
{
Color
errorColor
=
JBUI
.
CurrentTheme
.
Validator
.
errorBorderColor
();
Border
errorBorder
=
JBUI
.
Borders
.
customLine
(
errorColor
,
1
);
border
=
JBUI
.
Borders
.
merge
(
border
,
errorBorder
,
false
);
}
myNameField
.
setBorder
(
border
);
}
@NotNull
private
JBTextField
createNameField
()
{
JBTextField
res
=
new
JBTextField
();
...
...
@@ -125,6 +108,14 @@ public class CreateWithTemplatesDialogPanel extends JBPanel implements Disposabl
res
.
setPreferredSize
(
prefSize
);
res
.
setColumns
(
30
);
JBColor
borderColor
=
JBColor
.
namedColor
(
"TextField.borderColor"
,
JBColor
.
namedColor
(
"Component.borderColor"
,
new
JBColor
(
0xbdbdbd
,
0x646464
))
);
Border
border
=
JBUI
.
Borders
.
customLine
(
borderColor
,
1
,
0
,
1
,
0
);
Border
errorBorder
=
new
ErrorBorder
(
res
.
getBorder
());
res
.
setBorder
(
JBUI
.
Borders
.
merge
(
border
,
errorBorder
,
false
));
res
.
putClientProperty
(
"StatusVisibleFunction"
,
(
BooleanFunction
<
JBTextField
>)
field
->
field
.
getText
().
isEmpty
());
res
.
getEmptyText
().
setText
(
IdeBundle
.
message
(
"action.create.new.class.name.field"
));
res
.
addKeyListener
(
new
KeyAdapter
()
{
...
...
@@ -217,4 +208,34 @@ public class CreateWithTemplatesDialogPanel extends JBPanel implements Disposabl
}
};
private
static
class
ErrorBorder
implements
Border
{
private
final
Border
errorDelegateBorder
;
private
ErrorBorder
(
Border
delegate
)
{
errorDelegateBorder
=
delegate
;}
@Override
public
void
paintBorder
(
Component
c
,
Graphics
g
,
int
x
,
int
y
,
int
width
,
int
height
)
{
if
(
checkError
(
c
))
{
errorDelegateBorder
.
paintBorder
(
c
,
g
,
x
,
y
,
width
,
height
);
}
}
@Override
public
Insets
getBorderInsets
(
Component
c
)
{
return
checkError
(
c
)
?
errorDelegateBorder
.
getBorderInsets
(
c
)
:
JBUI
.
emptyInsets
();
}
@Override
public
boolean
isBorderOpaque
()
{
return
false
;
}
private
static
boolean
checkError
(
Component
c
)
{
Object
outlineObj
=
((
JComponent
)
c
).
getClientProperty
(
"JComponent.outline"
);
if
(
outlineObj
==
null
)
return
false
;
Outline
outline
=
outlineObj
instanceof
Outline
?
(
Outline
)
outlineObj
:
Outline
.
valueOf
(
outlineObj
.
toString
());
return
outline
==
Outline
.
error
||
outline
==
Outline
.
warning
;
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment