Permalink
Browse files

Make sure that only one file with roi with same id can be loaded at a…

… time (see #6731)
  • Loading branch information...
1 parent a9aa24b commit ed4ea66646a66c2de6f705c17e6eb5cc033386e2 @jburel jburel committed Sep 13, 2011
@@ -479,7 +479,7 @@ public void loadROI()
if (f == null) return;
model.fireROILoading(f.getAbsolutePath());
fireStateChange();
- view.updateDrawingArea();
+ //view.updateDrawingArea();
}
/**
@@ -900,6 +900,8 @@ public void setUpdateROIComponent(Collection result)
UserNotifier un = reg.getUserNotifier();
try {
model.removeAllROI();
+ view.rebuildManagerTable();
+ view.updateDrawingArea();
} catch (NoSuchROIException e) {
reg.getLogger().error(this, "Cannot save the ROI "+e.getMessage());
un.notifyInfo("Save ROI", "Cannot save ROI " +
@@ -39,6 +39,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;
@@ -86,6 +87,7 @@
import org.openmicroscopy.shoola.util.roi.model.ShapeList;
import org.openmicroscopy.shoola.util.roi.model.util.Coord3D;
import org.openmicroscopy.shoola.util.roi.model.util.MeasurementUnits;
+import org.openmicroscopy.shoola.util.ui.MessageBox;
import org.openmicroscopy.shoola.util.ui.drawingtools.DrawingComponent;
import org.openmicroscopy.shoola.util.ui.drawingtools.canvas.DrawingCanvasView;
import pojos.ChannelData;
@@ -1102,6 +1104,7 @@ void saveROIToServer(boolean async)
ExperimenterData exp =
(ExperimenterData) MeasurementAgent.getUserDetails();
if (roiList.size() == 0) return;
+ roiComponent.reset();
if (async) {
currentSaver = new ROISaver(component, getImageID(),
exp.getId(), roiList);
@@ -146,6 +146,12 @@ public ROIComponent()
roiResult = new LinkedHashMap<Long, List<ROI>>();
}
+ /** Indicates to reset the identifier when loading from local file.*/
+ public void reset()
+ {
+ if (ioStrategy != null) ioStrategy.reset();
+ }
+
/**
* Removes the specified figure from the display.
*
@@ -308,7 +308,7 @@ private Coord3D getCurrentCoord()
*/
private void setCurrentROI(long ROIid)
{
- currentROI=ROIid;
+ currentROI = ROIid;
}
/**
@@ -334,31 +334,32 @@ private ROI createROI(IXMLElement roiElement, ROIComponent component)
throws NoSuchROIException, ParsingException, ROICreationException
{
if (!roiElement.hasAttribute(IOConstants.ROI_ID_ATTRIBUTE)) return null;
- long id=
- new Long(roiElement.getAttribute(IOConstants.ROI_ID_ATTRIBUTE,
- "-1"));
+ long id = Long.valueOf(
+ roiElement.getAttribute(IOConstants.ROI_ID_ATTRIBUTE, "-1"));
+ if (currentROI == id) return null;
setCurrentROI(id);
ROI newROI = component.createROI(id);
- ArrayList<IXMLElement> roiShapeList=
+ List<IXMLElement> roiShapeList =
roiElement.getChildrenNamed(IOConstants.ROISHAPE_TAG);
- ArrayList<IXMLElement> annotationElementList=
+ List<IXMLElement> annotationElementList =
roiElement.getChildrenNamed(IOConstants.ANNOTATION_TAG);
- ArrayList<IXMLElement> annotationList;
+ List<IXMLElement> annotationList;
for (IXMLElement annotationTagElement : annotationElementList)
{
- annotationList=annotationTagElement.getChildren();
+ annotationList = annotationTagElement.getChildren();
for (IXMLElement annotation : annotationList)
addAnnotation(annotation, newROI);
}
ROIShape shape, returnedShape;
for (IXMLElement roiShape : roiShapeList)
{
- shape=createROIShape(roiShape, newROI);
- shape.getFigure().setMeasurementUnits(component.getMeasurementUnits());
+ shape = createROIShape(roiShape, newROI);
+ shape.getFigure().setMeasurementUnits(
+ component.getMeasurementUnits());
component.addShape(newROI.getID(), shape.getCoord3D(), shape);
try
{
- returnedShape=
+ returnedShape =
component.getShape(newROI.getID(), shape.getCoord3D());
}
catch (NoSuchROIException e)
@@ -379,22 +380,20 @@ private ROI createROI(IXMLElement roiElement, ROIComponent component)
private ROIShape createROIShape(IXMLElement shapeElement, ROI newROI)
throws ParsingException
{
- int t=
- new Integer(shapeElement.getAttribute(IOConstants.T_ATTRIBUTE,
- "0"));
- int z=
- new Integer(shapeElement.getAttribute(IOConstants.Z_ATTRIBUTE,
- "0"));
- Coord3D coord=new Coord3D(z, t);
+ int t = Integer.valueOf(
+ shapeElement.getAttribute(IOConstants.T_ATTRIBUTE, "0"));
+ int z = Integer.valueOf(
+ shapeElement.getAttribute(IOConstants.Z_ATTRIBUTE, "0"));
+ Coord3D coord = new Coord3D(z, t);
setCurrentCoord(coord);
- IXMLElement figureElement=
+ IXMLElement figureElement =
shapeElement.getFirstChildNamed(IOConstants.SVG_TAG);
- ROIFigure fig=createFigure(figureElement);
- ROIShape shape=new ROIShape(newROI, coord, fig, fig.getBounds());
- ArrayList<IXMLElement> annotationElementList=
+ ROIFigure fig = createFigure(figureElement);
+ ROIShape shape = new ROIShape(newROI, coord, fig, fig.getBounds());
+ List<IXMLElement> annotationElementList =
shapeElement.getChildrenNamed(IOConstants.ANNOTATION_TAG);
- ArrayList<IXMLElement> annotationList;
+ List<IXMLElement> annotationList;
for (IXMLElement annotationTagElement : annotationElementList)
{
annotationList=annotationTagElement.getChildren();
@@ -426,118 +425,118 @@ private void addAnnotation(IXMLElement annotationElement, ROIShape shape)
*/
Object createAnnotationData(IXMLElement annotationElement)
{
- String dataType=
+ String dataType =
annotationElement.getAttribute(IOConstants.DATATYPE_ATTRIBUTE,
IOConstants.VALUE_NULL);
- if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_STRING))
+ if (IOConstants.ATTRIBUTE_DATATYPE_STRING.equals(dataType))
{
return annotationElement.getAttribute(IOConstants.VALUE_ATTRIBUTE,
IOConstants.VALUE_NULL);
}
- else if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_INTEGER))
+ else if (IOConstants.ATTRIBUTE_DATATYPE_INTEGER.equals(dataType))
{
- String value=
+ String value =
annotationElement.getAttribute(IOConstants.VALUE_ATTRIBUTE,
IOConstants.VALUE_NULL);
- if (value.equals(IOConstants.VALUE_NULL)) return 0;
+ if (IOConstants.VALUE_NULL.equals(value)) return 0;
return Integer.valueOf(value);
}
- else if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_BOOLEAN))
+ else if (IOConstants.ATTRIBUTE_DATATYPE_BOOLEAN.equals(dataType))
{
- String value=
+ String value =
annotationElement.getAttribute(IOConstants.VALUE_ATTRIBUTE,
IOConstants.VALUE_NULL);
- if (value.equals(IOConstants.VALUE_NULL)) return 0;
+ if (IOConstants.VALUE_NULL.equals(value)) return 0;
return Boolean.valueOf(value);
}
- else if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_LONG))
+ else if (IOConstants.ATTRIBUTE_DATATYPE_LONG.equals(dataType))
{
- String value=
+ String value =
annotationElement.getAttribute(IOConstants.VALUE_ATTRIBUTE,
IOConstants.VALUE_NULL);
- if (value.equals(IOConstants.VALUE_NULL)) return 0;
+ if (IOConstants.VALUE_NULL.equals(value)) return 0;
return Long.valueOf(value);
}
- else if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_FLOAT))
+ else if (IOConstants.ATTRIBUTE_DATATYPE_FLOAT.equals(dataType))
{
- String value=
+ String value =
annotationElement.getAttribute(IOConstants.VALUE_ATTRIBUTE,
IOConstants.VALUE_NULL);
- if (value.equals(IOConstants.VALUE_NULL)) return 0;
+ if (IOConstants.VALUE_NULL.equals(value)) return 0;
return Float.valueOf(value);
}
- else if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_DOUBLE))
+ else if (IOConstants.ATTRIBUTE_DATATYPE_DOUBLE.equals(dataType))
{
- String value=
+ String value =
annotationElement.getAttribute(IOConstants.VALUE_ATTRIBUTE,
IOConstants.VALUE_NULL);
- if (value.equals(IOConstants.VALUE_NULL)) return 0;
+ if (IOConstants.VALUE_NULL.equals(value)) return 0;
return Double.valueOf(value);
}
- else if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_POINT2D))
+ else if (IOConstants.ATTRIBUTE_DATATYPE_POINT2D.equals(dataType))
{
- String xValue=
+ String xValue =
annotationElement.getAttribute(IOConstants.X_ATTRIBUTE,
IOConstants.VALUE_NULL);
- String yValue=
+ String yValue =
annotationElement.getAttribute(IOConstants.Y_ATTRIBUTE,
IOConstants.VALUE_NULL);
- if (xValue.equals(IOConstants.VALUE_NULL)
- ||yValue.equals(IOConstants.VALUE_NULL))
+ if (IOConstants.VALUE_NULL.equals(xValue)
+ || IOConstants.VALUE_NULL.equals(yValue))
return new Point2D.Double(0, 0);
return new Point2D.Double(Double.valueOf(xValue),
Double.valueOf(yValue));
}
- else if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_RECTANGLE2D)
- ||dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_ELLIPSE2D))
+ else if (IOConstants.ATTRIBUTE_DATATYPE_RECTANGLE2D.equals(dataType)
+ || IOConstants.ATTRIBUTE_DATATYPE_ELLIPSE2D.equals(dataType))
{
- String xValue=
+ String xValue =
annotationElement.getAttribute(IOConstants.X_ATTRIBUTE,
IOConstants.VALUE_NULL);
- String yValue=
+ String yValue =
annotationElement.getAttribute(IOConstants.Y_ATTRIBUTE,
IOConstants.VALUE_NULL);
- String widthValue=
+ String widthValue =
annotationElement.getAttribute(IOConstants.WIDTH_ATTRIBUTE,
IOConstants.VALUE_NULL);
- String heightValue=
+ String heightValue =
annotationElement.getAttribute(
IOConstants.HEIGHT_ATTRIBUTE, IOConstants.VALUE_NULL);
- if (xValue.equals(IOConstants.VALUE_NULL)
- ||yValue.equals(IOConstants.VALUE_NULL)
- ||widthValue.equals(IOConstants.VALUE_NULL)
- ||heightValue.equals(IOConstants.VALUE_NULL))
+ if (IOConstants.VALUE_NULL.equals(yValue)
+ || IOConstants.VALUE_NULL.equals(xValue)
+ ||IOConstants.VALUE_NULL.equals(widthValue)
+ ||IOConstants.VALUE_NULL.equals(heightValue))
{
- if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_RECTANGLE2D))
+ if (IOConstants.ATTRIBUTE_DATATYPE_RECTANGLE2D.equals(dataType))
return new Rectangle2D.Double();
return new Ellipse2D.Double();
}
- if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_RECTANGLE2D))
+ if (IOConstants.ATTRIBUTE_DATATYPE_RECTANGLE2D.equals(dataType))
new Rectangle2D.Double(
new Double(xValue), new Double(yValue), new Double(widthValue),
new Double(heightValue));
- if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_ELLIPSE2D))
+ if (IOConstants.ATTRIBUTE_DATATYPE_ELLIPSE2D.equals(dataType))
return new Ellipse2D.Double(
- new Double(xValue), new Double(yValue), new Double(widthValue),
- new Double(heightValue));
+ Double.valueOf(xValue), Double.valueOf(yValue),
+ Double.valueOf(widthValue), Double.valueOf(heightValue));
}
- else if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_COORD3D))
+ else if (IOConstants.ATTRIBUTE_DATATYPE_COORD3D.equals(dataType))
{
- String zValue=
+ String zValue =
annotationElement.getAttribute(IOConstants.Z_ATTRIBUTE,
IOConstants.VALUE_NULL);
- String tValue=
+ String tValue =
annotationElement.getAttribute(IOConstants.T_ATTRIBUTE,
IOConstants.VALUE_NULL);
- if (zValue.equals(IOConstants.VALUE_NULL)
- ||tValue.equals(IOConstants.VALUE_NULL)) return new Coord3D(
- 0, 0);
- return new Coord3D(new Integer(zValue),new Integer(tValue));
+ if (IOConstants.VALUE_NULL.equals(zValue)
+ ||IOConstants.VALUE_NULL.equals(tValue))
+ return new Coord3D(0, 0);
+ return new Coord3D(Integer.valueOf(zValue), Integer.valueOf(tValue));
}
- else if (dataType.equals(IOConstants.ATTRIBUTE_DATATYPE_ARRAYLIST))
+ else if (IOConstants.ATTRIBUTE_DATATYPE_ARRAYLIST.equals(dataType))
{
- ArrayList list=new ArrayList();
- ArrayList<IXMLElement> arrayListElement=
+ List list = new ArrayList();
+ List<IXMLElement> arrayListElement =
annotationElement.getChildren();
for (IXMLElement dataElement : arrayListElement)
list.add(createAnnotationData(dataElement));
@@ -1072,11 +1071,11 @@ private void addMissingAttributes(ROIFigure figure)
}
}
-
+
/** Create instance. */
InputStrategy()
{
-
+ reset();
}
/**
@@ -1093,8 +1092,8 @@ private void addMissingAttributes(ROIFigure figure)
throws ParsingException, ROICreationException,
NoSuchROIException
{
- roiList=new ArrayList<ROI>();
- this.component=component;
+ roiList = new ArrayList<ROI>();
+ this.component = component;
IXMLParser parser;
try
{
@@ -1110,25 +1109,31 @@ private void addMissingAttributes(ROIFigure figure)
try
{
- IXMLReader reader=new StdXMLReader(in);
+ IXMLReader reader = new StdXMLReader(in);
parser.setReader(reader);
document=(IXMLElement) parser.parse();
}
catch (Exception ex)
{
- ParsingException e=new ParsingException(ex.getMessage());
+ ParsingException e = new ParsingException(ex.getMessage());
e.initCause(ex);
throw e;
}
- ArrayList<IXMLElement> roiElements=
+ List<IXMLElement> roiElements =
document.getChildrenNamed(IOConstants.ROI_TAG);
- int cnt=0;
for (IXMLElement roi : roiElements)
roiList.add(createROI(roi, component));
return roiList;
}
+
+ /** Indicates to reset the identifier when loading from local file.*/
+ void reset()
+ {
+ currentROI = -1;
+ currentCoord = null;
+ }
-}
+}
@@ -67,6 +67,12 @@ public XMLFileIOStrategy()
inputStrategy = new InputStrategy();
}
+ /** Indicates to reset the identifier when loading from local file.*/
+ public void reset()
+ {
+ inputStrategy.reset();
+ }
+
/**
* Converts the ROIs hosted in the passed input stream.
*
Oops, something went wrong.

0 comments on commit ed4ea66

Please sign in to comment.