}
// find existing column
for (int columnIndex = 0; columnIndex < columnIntervals.length; columnIndex++) {
boolean isFirst = columnIndex == 0;
boolean isLast = columnIndex == columnIntervals.length - 1;
Interval interval = columnIntervals[columnIndex];
Interval nextInterval = !isLast ? columnIntervals[columnIndex + 1] : null;
// before first
if (isFirst) {
boolean nearBegin = Math.abs(location.x - interval.begin()) < INSERT_COLUMN_SIZE;
if (nearBegin) {
m_target.m_column = 0;
m_target.m_columnInsert = true;
updateGridFeedback_column(new Interval(0, 0), interval);
// stop
break;
}
}
// gap or near to end of interval
if (!isLast) {
int gap = nextInterval.begin - interval.end();
boolean directGap = interval.end() <= location.x && location.x < nextInterval.begin;
boolean narrowGap = gap < 2 * INSERT_COLUMN_SIZE;
boolean nearEnd = Math.abs(location.x - interval.end()) < INSERT_COLUMN_SIZE;
boolean nearBegin = Math.abs(location.x - nextInterval.begin) < INSERT_COLUMN_SIZE;
if (directGap || narrowGap && (nearEnd || nearBegin)) {
m_target.m_column = columnIndex + 1;
m_target.m_columnInsert = true;
updateGridFeedback_column(interval, nextInterval);
// stop
break;
}
}
// prepare "append" parameters
if (isLast) {
boolean nearEnd = Math.abs(location.x - interval.end()) < INSERT_COLUMN_SIZE;
if (nearEnd) {
m_target.m_column = columnIndex + 1;
m_target.m_columnInsert = false;
updateGridFeedback_column(interval, new Interval(interval.end(), 0));
// stop
break;
}
}
// column
if (interval.contains(location.x)) {
m_target.m_column = columnIndex;
// feedback
m_target.m_feedbackBounds.x = interval.begin;
m_target.m_feedbackBounds.width = interval.length + 1;
// stop
break;
}
}
// find existing row
for (int rowIndex = 0; rowIndex < rowIntervals.length; rowIndex++) {
boolean isFirst = rowIndex == 0;
boolean isLast = rowIndex == rowIntervals.length - 1;
Interval interval = rowIntervals[rowIndex];
Interval nextInterval = !isLast ? rowIntervals[rowIndex + 1] : null;
// before first
if (isFirst) {
boolean nearBegin = Math.abs(location.y - interval.begin()) < INSERT_ROW_SIZE;
if (nearBegin) {
m_target.m_row = 0;
m_target.m_rowInsert = true;
updateGridFeedback_row(new Interval(0, 0), interval);
// stop
break;
}
}
// gap or near to end of interval
if (!isLast) {
int gap = nextInterval.begin - interval.end();
boolean directGap = interval.end() <= location.y && location.y < nextInterval.begin;
boolean narrowGap = gap < 2 * INSERT_ROW_SIZE;
boolean nearEnd = Math.abs(location.y - interval.end()) < INSERT_ROW_SIZE;
boolean nearBegin = Math.abs(location.y - nextInterval.begin) < INSERT_ROW_SIZE;
if (directGap || narrowGap && (nearEnd || nearBegin)) {
m_target.m_row = rowIndex + 1;
m_target.m_rowInsert = true;
updateGridFeedback_row(interval, nextInterval);
// stop
break;
}
}
// prepare "append" parameters
if (isLast) {
boolean nearEnd = Math.abs(location.y - interval.end()) < 2 * INSERT_ROW_SIZE;
if (nearEnd) {
m_target.m_row = rowIndex + 1;
m_target.m_rowInsert = false;
updateGridFeedback_row(interval, new Interval(interval.end(), 0));
// stop
break;
}
}
// row