if (roiDesc.length == ROI_DESC_LENGTH) {
RoiShape shape = null;
try {
shape = RoiShape.valueOf(roiDesc[1].trim().toUpperCase(Locale.US));
} catch (final IllegalArgumentException e) {
new ErrorDialog(null, "Can not create ROI", "Invalid ROI Shape not added " + Arrays.toString(roiDesc)
+ ".\n\nCorrect values are RECTANGLE, OVAL, POINT, TEXT or CROSS and NONE to supress it.",
false, null).setVisible(true);
}
if (shape != null) {
CometeColor color = null;
try {
final Field colorField = CometeColor.class.getDeclaredField(roiDesc[7].trim().toUpperCase());
color = (CometeColor) colorField.get(colorField);
} catch (final SecurityException e1) {
System.err.println("cant find color => SecurityException");
} catch (final NoSuchFieldException e1) {
System.err.println("color does'nt exist");
} catch (final IllegalArgumentException e) {
System.err.println("cant find color => IllegalArgumentException");
} catch (final IllegalAccessException e) {
System.err.println("cant find color => IllegalAccessException");
}
if (color != null) {
try {
roi = new CometeRoi(roiDesc[0].trim(), shape, Integer.parseInt(roiDesc[2].trim()),
Integer.parseInt(roiDesc[3].trim()), Integer.parseInt(roiDesc[4].trim()),
Integer.parseInt(roiDesc[5].trim()), Integer.parseInt(roiDesc[6].trim()), color);
} catch (final NumberFormatException e) {
// TODO change to logger
System.err.println("invalid size or position: " + e.getMessage());
}
} else {
new ErrorDialog(
null,
"Can not create ROI",
"Invalid ROI Color not added "
+ Arrays.toString(roiDesc)
+ ".\n\nCorrects colors are WHITE, BLACK, RED, GREEN, BLUE, YELLOW, ORANGE, CYAN, MAGENTA, PURPLE, PINK, GRAY, DARK_GRAY or LIGHT_GRAY.",
false, null).setVisible(true);
}
}
} else {
new ErrorDialog(null, "Can not create ROI",
"Invalid ROI not added, the correct value must be RoiName,shape, LineSize, X, Y, Width, Height, Color.\n\nRoi : "
+ Arrays.toString(roiDesc), false, null).setVisible(true);
}
return roi;