Search in sources :

Example 1 with SpreadsheetCell

use of org.controlsfx.control.spreadsheet.SpreadsheetCell in project Gargoyle by callakrsos.

the class GargoyleSpreadSheetExam method start.

/* (non-Javadoc)
	 * @see javafx.application.Application#start(javafx.stage.Stage)
	 */
@Override
public void start(Stage primaryStage) throws Exception {
    GridBase gridBase = new GridBase(100, 100);
    List<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
    for (int row = 0; row < gridBase.getRowCount(); ++row) {
        ObservableList<SpreadsheetCell> currentRow = FXCollections.observableArrayList();
        for (int column = 0; column < gridBase.getColumnCount(); ++column) {
            SpreadsheetCell createCell = SpreadsheetCellType.STRING.createCell(row, column, 1, 1, "");
            currentRow.add(createCell);
        }
        rows.add(currentRow);
    }
    gridBase.setRows(rows);
    ExcelTemplateControl excelTemplateControl = new ExcelTemplateControl();
    primaryStage.setScene(new Scene(new GagoyleSpreadSheetView(gridBase)));
    primaryStage.show();
}
Also used : GridBase(org.controlsfx.control.spreadsheet.GridBase) SpreadsheetCell(org.controlsfx.control.spreadsheet.SpreadsheetCell) ExcelTemplateControl(com.kyj.fx.voeditor.visual.component.spreadsheets.ExcelTemplateControl) ObservableList(javafx.collections.ObservableList) GagoyleSpreadSheetView(com.kyj.fx.voeditor.visual.component.spreadsheets.GagoyleSpreadSheetView) Scene(javafx.scene.Scene)

Example 2 with SpreadsheetCell

use of org.controlsfx.control.spreadsheet.SpreadsheetCell in project Gargoyle by callakrsos.

the class GagoyleSpreadSheetView method createNewRow.

/**
	 * 새로운 Row를 생성한다.
	 *
	 * @param newRow
	 *            생성할 로우
	 * @return
	 */
private ObservableList<SpreadsheetCell> createNewRow() {
    Grid grid = ssv.getGrid();
    ObservableList<ObservableList<SpreadsheetCell>> rows = grid.getRows();
    int columnCount = grid.getColumnCount();
    int newRow = rows.size();
    ObservableList<SpreadsheetCell> newCells = FXCollections.observableArrayList(new ArrayList<>(columnCount));
    for (int newCol = 0; newCol < columnCount; newCol++) {
        newCells.add(SpreadsheetCellType.STRING.createCell(newRow, newCol, 1, 1, ""));
    }
    return newCells;
}
Also used : SpreadsheetCell(org.controlsfx.control.spreadsheet.SpreadsheetCell) ObservableList(javafx.collections.ObservableList) Grid(org.controlsfx.control.spreadsheet.Grid)

Example 3 with SpreadsheetCell

use of org.controlsfx.control.spreadsheet.SpreadsheetCell in project Gargoyle by callakrsos.

the class GagoyleSpreadSheetView method paste.

/**
	 * 붙여넣기
	 *
	 * @param pastString
	 */
public void paste(final String pastString, final int startRowIndex, final int startColumnIndex) {
    int row = startRowIndex;
    int column = startColumnIndex;
    int _column = column;
    String[] split = pastString.split("\n");
    Grid grid = ssv.getGrid();
    ObservableList<ObservableList<SpreadsheetCell>> rows = grid.getRows();
    for (String str : split) {
        String[] split2 = str.split("\t");
        _column = column;
        for (String str2 : split2) {
            SpreadsheetCell spreadsheetCell = null;
            if (rows.size() > row)
                spreadsheetCell = rows.get(row).get(_column);
            else /* 새로운 로우를 생성함. */
            {
                ObservableList<SpreadsheetCell> newCells = createNewRow();
                spreadsheetCell = newCells.get(_column);
                rows.add(newCells);
            }
            spreadsheetCell.setItem(str2);
            _column++;
        }
        row++;
    }
    ssv.setGrid(grid);
}
Also used : SpreadsheetCell(org.controlsfx.control.spreadsheet.SpreadsheetCell) ObservableList(javafx.collections.ObservableList) Grid(org.controlsfx.control.spreadsheet.Grid)

Example 4 with SpreadsheetCell

use of org.controlsfx.control.spreadsheet.SpreadsheetCell in project Gargoyle by callakrsos.

the class GagoyleSpreadSheetView method spreadSheetKeyPress.

public void spreadSheetKeyPress(KeyEvent e) {
    if (e.isControlDown() && e.getCode() == KeyCode.C) {
        StringBuffer clipboardContent = new StringBuffer();
        ObservableList<TablePosition> selectedCells = ssv.getSelectionModel().getSelectedCells();
        int prevRow = -1;
        for (TablePosition<?, ?> pos : selectedCells) {
            int currentRow = pos.getRow();
            int currentColumn = pos.getColumn();
            if ((prevRow != -1 && prevRow != currentRow)) {
                clipboardContent.setLength(clipboardContent.length() - 1);
                LOGGER.debug(clipboardContent.toString());
                /*
					 * 라인세퍼레이터 사용하지말것. 이유는 클립보드에 들어가는 컨텐츠가 /r/n이되면서 엑셀에 붙여넣기시
					 * 잘못된 값이 입력됨. [ 금지 : SystemUtils.LINE_SEPARATOR = /r/n ]
					 */
                clipboardContent.append("\n");
            }
            prevRow = currentRow;
            SpreadsheetCell spreadsheetCell = ssv.getGrid().getRows().get(currentRow).get(currentColumn);
            clipboardContent.append(spreadsheetCell.getText()).append("\t");
        }
        clipboardContent.setLength(clipboardContent.length() - 1);
        LOGGER.debug(String.format("clipboard content : \n%s", clipboardContent.toString()));
        FxClipboardUtil.putString(clipboardContent.toString());
        // 상위 이벤트가 호출되서 클립보드가 없어지는것을 방지한다.
        e.consume();
    } else if (e.isControlDown() && e.getCode() == KeyCode.V) {
        int type = FxClipboardUtil.getCipboardContentTypes();
        switch(type) {
            case FxClipboardUtil.IMAGE:
                {
                    Image pastImage = FxClipboardUtil.pastImage();
                    ObservableList<TablePosition> selectedCells = ssv.getSelectionModel().getSelectedCells();
                    TablePosition tablePosition = selectedCells.get(0);
                    int row = tablePosition.getRow();
                    int column = tablePosition.getColumn();
                    SpreadsheetCell cell = new ImageCellType().createCell(row, column, 1, 1, pastImage);
                    ssv.getGrid().getRows().get(tablePosition.getRow()).set(tablePosition.getColumn(), cell);
                // this.getGrid().setCellValue(tablePosition.getRow(),
                // tablePosition.getColumn(), new ImageView(pastImage));
                }
                break;
            case FxClipboardUtil.FILE:
                List<File> pastFiles = FxClipboardUtil.pasteFiles();
                File file = pastFiles.get(0);
                if (file != null && file.exists()) {
                    try {
                        Image pastImage = new Image(file.toURI().toURL().openStream());
                        ObservableList<TablePosition> selectedCells = ssv.getSelectionModel().getSelectedCells();
                        TablePosition tablePosition = selectedCells.get(0);
                        int row = tablePosition.getRow();
                        int column = tablePosition.getColumn();
                        SpreadsheetCell cell = new ImageCellType().createCell(row, column, 1, 1, pastImage);
                        ssv.getGrid().getRows().get(tablePosition.getRow()).set(tablePosition.getColumn(), cell);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
                break;
            case FxClipboardUtil.URL:
                {
                    String pasteUrl = FxClipboardUtil.pasteUrl();
                    Image pastImage = new Image(pasteUrl);
                    ObservableList<TablePosition> selectedCells = ssv.getSelectionModel().getSelectedCells();
                    TablePosition tablePosition = selectedCells.get(0);
                    int row = tablePosition.getRow();
                    int column = tablePosition.getColumn();
                    SpreadsheetCell cell = new ImageCellType().createCell(row, column, 1, 1, pastImage);
                    ssv.getGrid().getRows().get(tablePosition.getRow()).set(tablePosition.getColumn(), cell);
                }
                break;
            case FxClipboardUtil.STRING:
                paste();
                break;
            default:
                paste();
                break;
        }
    }
    e.consume();
}
Also used : Image(javafx.scene.image.Image) SpreadsheetCell(org.controlsfx.control.spreadsheet.SpreadsheetCell) TablePosition(javafx.scene.control.TablePosition) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) File(java.io.File)

Example 5 with SpreadsheetCell

use of org.controlsfx.control.spreadsheet.SpreadsheetCell in project Gargoyle by callakrsos.

the class GagoyleSpreadSheetView method paste.

/**
	 * 특수문자에대한 문자열 paste에 대한 버그를 수정하기 위한 함수.
	 * @작성자 : KYJ
	 * @작성일 : 2016. 11. 23.
	 * @param items
	 * @param startRowIndex
	 * @param startColumnIndex
	 */
public void paste(List<Map<String, Object>> items, int startRowIndex, int startColumnIndex) {
    int row = startRowIndex;
    int column = startColumnIndex;
    int _column = column;
    //		String[] split = pastString.split("\n");
    Grid grid = ssv.getGrid();
    ObservableList<ObservableList<SpreadsheetCell>> rows = grid.getRows();
    for (Map<String, Object> str : items) {
        //			String[] split2 = str.split("\t");
        _column = column;
        Iterator<String> iterator = str.keySet().iterator();
        while (iterator.hasNext()) {
            String strCol = iterator.next();
            Object value = str.get(strCol);
            SpreadsheetCell spreadsheetCell = null;
            if (rows.size() > row) {
                ObservableList<SpreadsheetCell> observableList = rows.get(row);
                try {
                    spreadsheetCell = observableList.get(_column);
                } catch (IndexOutOfBoundsException e) {
                    e.printStackTrace();
                }
            } else /* 새로운 로우를 생성함. */
            {
                ObservableList<SpreadsheetCell> newCells = createNewRow();
                spreadsheetCell = newCells.get(_column);
            }
            if (value != null)
                value = value.toString();
            spreadsheetCell.setItem(value);
            _column++;
        }
        row++;
    }
}
Also used : SpreadsheetCell(org.controlsfx.control.spreadsheet.SpreadsheetCell) ObservableList(javafx.collections.ObservableList) Grid(org.controlsfx.control.spreadsheet.Grid)

Aggregations

ObservableList (javafx.collections.ObservableList)6 SpreadsheetCell (org.controlsfx.control.spreadsheet.SpreadsheetCell)6 Grid (org.controlsfx.control.spreadsheet.Grid)3 File (java.io.File)2 ExcelTemplateControl (com.kyj.fx.voeditor.visual.component.spreadsheets.ExcelTemplateControl)1 GagoyleSpreadSheetView (com.kyj.fx.voeditor.visual.component.spreadsheets.GagoyleSpreadSheetView)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Scene (javafx.scene.Scene)1 TablePosition (javafx.scene.control.TablePosition)1 Image (javafx.scene.image.Image)1 ExtensionFilter (javafx.stage.FileChooser.ExtensionFilter)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 GridBase (org.controlsfx.control.spreadsheet.GridBase)1