x < imageStartX + iw && y < imageStartY )
{
someDragged = true;
addingHorizontalStretch = true;
startX = x;
changedInterval = new NinePatchInterval ( ( x - imageStartX ) / zoom, false );
ninePatchIcon.addHorizontalStretch ( changedInterval );
repaintRequired = true;
}
else if ( addingHorizontalStretch && mouseEventType.equals ( MouseEventType.mouseDragged ) )
{
final int start = ( startX - imageStartX ) / zoom;
final int end = ( x - imageStartX ) / zoom;
changedInterval.setStart ( Math.max ( 0, Math.min ( start, end ) ) );
changedInterval.setEnd ( Math.min ( image.getWidth () - 1, Math.max ( start, end ) ) );
repaintRequired = true;
}
else if ( addingHorizontalStretch && mouseEventType.equals ( MouseEventType.mouseReleased ) )
{
someDragged = false;
addingHorizontalStretch = false;
verifyHorizontalStretchAreas ();
repaintRequired = true;
saveHistoryState ();
fireStateChanged ();
}
}
if ( addingVerticalStretch || !someDragged )
{
if ( mouseEventType.equals ( MouseEventType.mousePressed ) && y > imageStartY &&
y < imageStartY + ih && x < imageStartX )
{
someDragged = true;
addingVerticalStretch = true;
startY = y;
changedInterval = new NinePatchInterval ( ( y - imageStartY ) / zoom, false );
ninePatchIcon.addVerticalStretch ( changedInterval );
repaintRequired = true;
}
else if ( addingVerticalStretch && mouseEventType.equals ( MouseEventType.mouseDragged ) )
{
final int start = ( startY - imageStartY ) / zoom;
final int end = ( y - imageStartY ) / zoom;
changedInterval.setStart ( Math.max ( 0, Math.min ( start, end ) ) );
changedInterval.setEnd ( Math.min ( image.getHeight () - 1, Math.max ( start, end ) ) );
repaintRequired = true;
}
else if ( addingVerticalStretch && mouseEventType.equals ( MouseEventType.mouseReleased ) )
{
someDragged = false;
addingVerticalStretch = false;
verifyVerticalStretchAreas ();
repaintRequired = true;
saveHistoryState ();
fireStateChanged ();
}
}
}
// Removing stretch areas
if ( SwingUtilities.isRightMouseButton ( e ) )
{
if ( removingHorizontalStretch || !someDragged )
{
if ( mouseEventType.equals ( MouseEventType.mousePressed ) && x > imageStartX &&
x < imageStartX + iw && y < imageStartY )
{
someDragged = true;
removingHorizontalStretch = true;
startX = x;
removedInterval = new NinePatchInterval ( ( x - imageStartX ) / zoom, false );
finishHorizontalRemoval ();
repaintRequired = true;
}
else if ( removingHorizontalStretch && mouseEventType.equals ( MouseEventType.mouseDragged ) )
{
final int start = ( startX - imageStartX ) / zoom;
final int end = ( x - imageStartX ) / zoom;
removedInterval.setStart ( Math.max ( 0, Math.min ( start, end ) ) );
removedInterval.setEnd ( Math.min ( image.getWidth () - 1, Math.max ( start, end ) ) );
finishHorizontalRemoval ();
repaintRequired = true;
}
else if ( removingHorizontalStretch && mouseEventType.equals ( MouseEventType.mouseReleased ) )
{
someDragged = false;
removingHorizontalStretch = false;
repaintRequired = true;
saveHistoryState ();
fireStateChanged ();
}
}
if ( removingVerticalStretch || !someDragged )
{
if ( mouseEventType.equals ( MouseEventType.mousePressed ) && y > imageStartY &&
y < imageStartY + ih && x < imageStartX )
{
someDragged = true;
removingVerticalStretch = true;
startY = y;
removedInterval = new NinePatchInterval ( ( y - imageStartY ) / zoom, false );
finishVerticalRemoval ();
repaintRequired = true;
}
else if ( removingVerticalStretch && mouseEventType.equals ( MouseEventType.mouseDragged ) )
{