添加标点时去除首位空格
This commit is contained in:
@@ -443,7 +443,16 @@ public class ImageDotMarker extends JFrame {
|
||||
private void addNewPoint(Point imgPoint) {
|
||||
// 提示用户输入点名称
|
||||
String name = JOptionPane.showInputDialog(this, "请输入标记点名称:", "添加标记点", JOptionPane.PLAIN_MESSAGE);
|
||||
if (name == null || name.isEmpty()) return; // 用户取消
|
||||
if (name == null) return; // 用户取消
|
||||
|
||||
// 去除空格
|
||||
name = name.trim();
|
||||
|
||||
// 检查去除空格后是否为空
|
||||
if (name.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "标记点名称不能为空!", "输入错误", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
MarkPoint point = new MarkPoint(imgPoint.x, imgPoint.y, name);
|
||||
points.add(point);
|
||||
@@ -466,10 +475,21 @@ public class ImageDotMarker extends JFrame {
|
||||
|
||||
private void editPointName(MarkPoint point) {
|
||||
String newName = JOptionPane.showInputDialog(this, "修改标记点名称:", point.name);
|
||||
if (newName != null && !newName.equals(point.name)) {
|
||||
point.name = newName;
|
||||
updateImageDisplay();
|
||||
updatePointList();
|
||||
if (newName != null) {
|
||||
// 去除空格
|
||||
newName = newName.trim();
|
||||
|
||||
// 检查去除空格后是否为空
|
||||
if (newName.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "标记点名称不能为空!", "输入错误", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newName.equals(point.name)) {
|
||||
point.name = newName;
|
||||
updateImageDisplay();
|
||||
updatePointList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user