use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.
the class DefaultCCPStrategy method cutOrCopy.
/**
* Do the actual copy or cut operation.
*
* @param table table
* @param cut if set to true cells we be emptied
*/
protected void cutOrCopy(JaretTable table, boolean cut) {
IJaretTableSelection selection = table.getSelectionModel().getSelection();
Clipboard cb = getClipboard();
if (!selection.isEmpty()) {
Set<IJaretTableCell> cells = selection.getAllSelectedCells(table.getTableModel());
int minx = -1;
int maxx = -1;
int miny = -1;
int maxy = -1;
// line is the outer map
Map<Integer, Map<Integer, IJaretTableCell>> cellMap = new HashMap<Integer, Map<Integer, IJaretTableCell>>();
for (IJaretTableCell cell : cells) {
Point p = table.getCellDisplayIdx(cell);
Map<Integer, IJaretTableCell> lineMap = cellMap.get(p.y);
if (lineMap == null) {
lineMap = new HashMap<Integer, IJaretTableCell>();
cellMap.put(p.y, lineMap);
}
if (miny == -1 || p.y < miny) {
miny = p.y;
}
if (maxy == -1 || p.y > maxy) {
maxy = p.y;
}
lineMap.put(p.x, cell);
if (minx == -1 || p.x < minx) {
minx = p.x;
}
if (maxx == -1 || p.x > maxx) {
maxx = p.x;
}
}
StringBuilder buf = new StringBuilder();
if (_includeHeadersInCopy) {
for (int x = minx; x <= maxx; x++) {
String headerLabel = table.getColumn(x).getHeaderLabel();
buf.append(headerLabel);
buf.append(COPY_DELIMITER);
}
buf.append("\n");
}
for (int y = miny; y <= maxy; y++) {
Map<Integer, IJaretTableCell> lineMap = cellMap.get(y);
// empty lines are ommitted
if (lineMap != null) {
for (int x = minx; x <= maxx; x++) {
IJaretTableCell cell = lineMap.get(x);
String value = null;
if (cell != null) {
Object val = cell.getColumn().getValue(cell.getRow());
value = val != null ? val.toString() : null;
if (cut) {
emptyCell(cell);
}
}
if (value != null) {
buf.append(value);
}
buf.append(COPY_DELIMITER);
}
buf.append("\n");
}
}
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { buf.toString() }, new Transfer[] { textTransfer });
}
}
use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.
the class DefaultCellStyleProvider method propertyChange.
/**
* {@inheritDoc} Listens to all styles and fires style changed for every location a style is used in.
*/
public void propertyChange(PropertyChangeEvent event) {
ICellStyle style = (ICellStyle) event.getSource();
List<IJaretTableCell> locs = getStyleLocations(style);
for (IJaretTableCell loc : locs) {
fireCellStyleChanged(loc.getRow(), loc.getColumn(), (ICellStyle) style);
}
}
use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.
the class JaretTable method getSelectedRectangle.
/**
* Retrieve the index rectangle of selected cells.
*
* @return rectangel made from the indizes of the selected cells if a rectangular area is selected (all cells)
*/
private Rectangle getSelectedRectangle() {
IJaretTableSelection selection = getSelectionModel().getSelection();
if (!selection.isEmpty() && _selectedIdxRectangle == null) {
Set<IJaretTableCell> cells = selection.getAllSelectedCells(getTableModel());
int minx = -1;
int maxx = -1;
int miny = -1;
int maxy = -1;
// line is the outer map
Map<Integer, Map<Integer, IJaretTableCell>> cellMap = new HashMap<Integer, Map<Integer, IJaretTableCell>>();
for (IJaretTableCell cell : cells) {
Point p = getCellDisplayIdx(cell);
Map<Integer, IJaretTableCell> lineMap = cellMap.get(p.y);
if (lineMap == null) {
lineMap = new HashMap<Integer, IJaretTableCell>();
cellMap.put(p.y, lineMap);
}
if (miny == -1 || p.y < miny) {
miny = p.y;
}
if (maxy == -1 || p.y > maxy) {
maxy = p.y;
}
lineMap.put(p.x, cell);
if (minx == -1 || p.x < minx) {
minx = p.x;
}
if (maxx == -1 || p.x > maxx) {
maxx = p.x;
}
}
// check if all cells are selected
boolean everythingSelected = true;
for (int y = miny; y <= maxy && everythingSelected; y++) {
Map<Integer, IJaretTableCell> lineMap = cellMap.get(y);
if (lineMap != null) {
for (int x = minx; x <= maxx; x++) {
IJaretTableCell cell = lineMap.get(x);
if (cell == null) {
everythingSelected = false;
break;
}
}
} else {
everythingSelected = false;
break;
}
}
if (everythingSelected) {
_selectedIdxRectangle = new Rectangle(minx, miny, maxx - minx + 1, maxy - miny + 1);
} else {
_selectedIdxRectangle = null;
}
}
return _selectedIdxRectangle;
}
use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.
the class JaretTable method selectRight.
/**
* Enlarge selection to the right.
*/
private void selectRight() {
IJaretTableCell cell = getFocussedCell();
if (_lastSelectType == SelectType.CELL && cell != null) {
int cx = getColumnIdx(cell.getColumn());
int cy = getRowIdx(cell.getRow());
if (_lastKeySelect == null) {
_lastKeySelect = new Point(-1, -1);
}
if (_firstKeySelect == null) {
_firstKeySelect = new Point(cx, cy);
_selectionModel.clearSelection();
}
focusRight();
cell = getFocussedCell();
cx = getColumnIdx(cell.getColumn());
cy = getRowIdx(cell.getRow());
ensureSelectionContainsRegion(_firstKeySelect.x, _firstKeySelect.y, cx, cy, _lastKeySelect.x, _lastKeySelect.y);
_lastSelectType = SelectType.CELL;
_lastKeySelect = new Point(cx, cy);
} else if (_lastSelectType == SelectType.COLUMN && (_lastColSelectIdx != -1 || _lastKeyColSelectIdx != -1)) {
if (_firstKeyColSelectIdx == -1) {
_firstKeyColSelectIdx = _lastColSelectIdx;
}
int colIdx = _lastKeyColSelectIdx != -1 ? _lastKeyColSelectIdx + 1 : _firstKeyColSelectIdx + 1;
if (colIdx > _cols.size() - 1) {
colIdx = _cols.size() - 1;
}
ensureSelectionContainsColRegion(_firstKeyColSelectIdx, colIdx, _lastKeyColSelectIdx);
_lastKeyColSelectIdx = colIdx;
}
}
use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.
the class JaretTable method handleFill.
/**
* Handle the end of a fill drag.
*
*/
private void handleFill() {
if (_fillDragStrategy != null) {
if (_horizontalFillDrag) {
// horizontal base rect
for (int i = _firstFillDragSelect.x; i < _firstFillDragSelect.x + _firstFillDragSelect.width; i++) {
IJaretTableCell firstCell = getCellForIdx(i, _firstFillDragSelect.y);
List<IJaretTableCell> cells = getSelectedCellsVertical(i);
cells.remove(firstCell);
_fillDragStrategy.doFill(this, firstCell, cells);
}
} else {
// vertical base rect
for (int i = _firstFillDragSelect.y; i < _firstFillDragSelect.y + _firstFillDragSelect.height; i++) {
IJaretTableCell firstCell = getCellForIdx(_firstFillDragSelect.x, i);
List<IJaretTableCell> cells = getSelectedCellsHorizontal(i);
cells.remove(firstCell);
_fillDragStrategy.doFill(this, firstCell, cells);
}
}
}
}
Aggregations