1. shemnon
  2. ControlsFX

Commits

Jonathan Giles  committed 903392d

More SpreadsheetView API cleanup.

  • Participants
  • Parent commits 7c4de61
  • Branches default

Comments (0)

Files changed (9)

File src/main/java/impl/org/controlsfx/skin/RowHeader.java

View file
  • Ignore whitespace
 import org.controlsfx.control.SpreadsheetView;
 import org.controlsfx.control.SpreadsheetView.SpreadsheetViewSelectionModel;
 
+import com.sun.javafx.scene.control.skin.VirtualScrollBar;
+
 
 /**
  * Display a rowHeader, the index of the lines displayed on screen.
 		RowHeader.this.setClip(clip);
 
 		// We desactivate and activate the rowheader upon request
-		spreadsheetView.rowHeaderProperty().addListener(new ChangeListener<Boolean>(){
+		spreadsheetView.showRowHeaderProperty().addListener(new ChangeListener<Boolean>(){
 			@Override
 			public void changed(ObservableValue<? extends Boolean> arg0,
 					Boolean arg1, Boolean arg2) {
 			}});
 
 		// When the Column header is showing or not, we need to update the position of the rowHeader
-		spreadsheetView.columnHeaderProperty().addListener(layout);
+		spreadsheetView.showColumnHeaderProperty().addListener(layout);
 
 		spreadsheetView.getFixedRows().addListener(layout);
 		//In case we resize the view in any manners
 			//We add prefHeight because we need to take the other header into account
 			// And also the fixedRows if any
 			double y = snappedTopInset() ;//+prefHeight*flow.getFixedRows().size();
-			if(spreadsheetView.columnHeaderProperty().get()){
+			if(spreadsheetView.showColumnHeaderProperty().get()){
 				y+=prefHeight;
 			}
 
 			//The Labels must be aligned with the rows
-			if(!spreadsheetView.isEmptyCells()){
+			if(!spreadsheetView.getGrid().getRows().isEmpty()){
 				y += spreadsheetViewSkin.getCell(0).getLocalToParentTransform().getTy();
 			}
 
 			Label label;
 			int i=0;
 			// We don't want to add Label if there are no rows associated with.
-			final int modelRowCount = spreadsheetView.getModelRowCount();
+			final int modelRowCount = spreadsheetView.getGrid().getRowCount();
 
 			// We iterate over the visibleRows
-			while(!spreadsheetView.isEmptyCells() && spreadsheetViewSkin.getCell(i) != null && i< modelRowCount){
+			while(!spreadsheetView.getGrid().getRows().isEmpty() && spreadsheetViewSkin.getCell(i) != null && i< modelRowCount){
 				label = getLabel(rowCount++);
 				label.setText(String.valueOf(spreadsheetViewSkin.getCell(i).getIndexVirtualFlow()+1));
 				label.resize(prefWidth,prefHeight);
 			}
 
 			// Then we iterate over the FixedRows if any
-			if(!spreadsheetView.getFixedRows().isEmpty() && !spreadsheetView.isEmptyCells()){
+			if(!spreadsheetView.getFixedRows().isEmpty() && !spreadsheetView.getGrid().getRows().isEmpty()){
 				for(i = 0;i<spreadsheetView.getFixedRows().size();++i){
 					label = getLabel(rowCount++);
 					label.setText(String.valueOf(i+1));
 					label.resize(prefWidth,prefHeight);
 
 					//If the columnHeader is here, we need to translate a bit
-					if(spreadsheetView.columnHeaderProperty().get()){
+					if(spreadsheetView.showColumnHeaderProperty().get()){
 						label.relocate(x, snappedTopInset()+prefHeight*(i+1));
 					}else{
 						label.relocate(x, snappedTopInset()+prefHeight*i);
 			}
 
 			//First one blank and on top (z-order) of the others
-			if(spreadsheetView.columnHeaderProperty().get()){
+			if(spreadsheetView.showColumnHeaderProperty().get()){
 				label = getLabel(rowCount++);
 				label.setText("");
 				label.resize(prefWidth,prefHeight);
 				label.getStyleClass().clear();
 			}
 
-			if(spreadsheetView.getHbar().isVisible()){
+			VirtualScrollBar hbar = SpreadsheetViewSkin.getSkin(spreadsheetView).getHBar();
+			if(hbar.isVisible()){
 				//Last one blank and on top (z-order) of the others
 				label = getLabel(rowCount++);
 				label.setText("");
-				label.resize(prefWidth,spreadsheetView.getHbar().getHeight());
-				label.relocate(snappedLeftInset(), getHeight()-spreadsheetView.getHbar().getHeight());
+				label.resize(prefWidth,hbar.getHeight());
+				label.relocate(snappedLeftInset(), getHeight()-hbar.getHeight());
 				label.getStyleClass().clear();
 			}
 			//Flush the rest of the children if any

File src/main/java/impl/org/controlsfx/skin/SpreadsheetCell.java

View file
  • Ignore whitespace
         	 */
         	if(row <= spv.getFixedRows().size()){
 	        	boolean flag = false;
-	        	for (int j = 0; j<spv.getRowCount();j++ ) {
+	        	for (int j = 0; j<SpreadsheetViewSkin.getSkin(spv).getCellsSize();j++ ) {
 	                    if(SpreadsheetViewSkin.getCell(spv, j) == getTableRow()){
 	                    	flag = true;
 	                    }
         final SpreadsheetView spv = getSpreadsheetView();
         final SpreadsheetRow row = SpreadsheetViewSkin.getCell(spv, spv.getFixedRows().size());
         
-        if (!spv.isEmptyCells() && row.getIndex() <= cell.getRow()) {
+        if (!spv.getGrid().getRows().isEmpty() && row.getIndex() <= cell.getRow()) {
         	final SpreadsheetRow rightRow = SpreadsheetViewSkin.getCell(spv, spv.getFixedRows().size()+cell.getRow() - row.getIndex());
             // We want to get the top of the spanned cell, so we need
             // to access the fixedRows.size plus the difference between where we want to go and the first visibleRow (header excluded)

File src/main/java/impl/org/controlsfx/skin/SpreadsheetHeaderRow.java

View file
  • Ignore whitespace
             @Override
             public void run() {
 
-                spreadsheetViewSkin.spreadsheetView.rowHeaderProperty().addListener(
+                spreadsheetViewSkin.spreadsheetView.showRowHeaderProperty().addListener(
                         rowHeaderListener);
                 selectionModel = spreadsheetViewSkin.spreadsheetView
                         .getSelectionModel();
                  *****************************************************************/
                 // We listen to the BooleanProperty linked with the CheckBox of
                 // the columnHeader
-                spreadsheetViewSkin.spreadsheetView.columnHeaderProperty()
+                spreadsheetViewSkin.spreadsheetView.showColumnHeaderProperty()
                         .addListener(new ChangeListener<Boolean>() {
                             @Override
                             public void changed(
          *****************************************************************/
         if (spreadsheetViewSkin != null
                 && spreadsheetViewSkin.spreadsheetView != null
-                && spreadsheetViewSkin.spreadsheetView.rowHeaderProperty().get()) {
+                && spreadsheetViewSkin.spreadsheetView.showRowHeaderProperty().get()) {
             padding += spreadsheetViewSkin.getRowHeaderWidth();
         }
 

File src/main/java/impl/org/controlsfx/skin/SpreadsheetNestedTableColumnHeader.java

View file
  • Ignore whitespace
      */
     public void layoutFixedColumns() {
     	final SpreadsheetView spreadsheetView = ((SpreadsheetViewSkin) getTableViewSkin()).spreadsheetView;
-        double hbarValue = spreadsheetView.getHbar().getValue();
+        double hbarValue = SpreadsheetViewSkin.getSkin(spreadsheetView).getHBar().getValue();
         
         final int labelHeight = (int) getChildren().get(0).prefHeight(-1);
         double fixedColumnWidth = 0;

File src/main/java/impl/org/controlsfx/skin/SpreadsheetRowSkin.java

View file
  • Ignore whitespace
              * FOR FIXED COLUMNS
              */
             double tableCellX = 0;
-            final double hbarValue = spreadsheetView.getHbar().getValue();
+            final double hbarValue = SpreadsheetViewSkin.getSkin(spreadsheetView).getHBar().getValue();
             // We translate that column by the Hbar Value if it's fixed
             if (spreadsheetView.getColumns().get(column).isFixed()) {
                 

File src/main/java/impl/org/controlsfx/skin/SpreadsheetViewSkin.java

View file
  • Ignore whitespace
 import com.sun.javafx.scene.control.skin.TableHeaderRow;
 import com.sun.javafx.scene.control.skin.TableViewSkin;
 import com.sun.javafx.scene.control.skin.VirtualFlow;
+import com.sun.javafx.scene.control.skin.VirtualScrollBar;
 
 // Despite the name, this skin is actually the skin of the TableView contained
 // within the SpreadsheetView. The skin for the SpreadsheetView itself currently
          *****************************************************************/
         spreadsheetView.getFixedRows().addListener(fixedRowsListener);
         spreadsheetView.getFixedColumns().addListener(fixedColumnsListener);
-        spreadsheetView.setHbar(getFlow().getHorizontalBar());
-        spreadsheetView.setVbar(getFlow().getVerticalBar());
+//        spreadsheetView.setHbar(getFlow().getHorizontalBar());
+//        spreadsheetView.setVbar(getFlow().getVerticalBar());
         /*****************************************************************
          * END MODIFIED BY NELLARMONIA
          *****************************************************************/
     @Override
     protected void layoutChildren(double x, double y, double w, final double h) {
         if (spreadsheetView == null) { return; }
-        if (spreadsheetView.rowHeaderProperty().get()) {
+        if (spreadsheetView.showRowHeaderProperty().get()) {
             x += rowHeaderWidth;
             w -= rowHeaderWidth;
         }
                 .getHeight() / 2;
         double tableHeaderRowHeight = 0;
 
-        if (spreadsheetView.columnHeaderProperty().get()) {
+        if (spreadsheetView.showColumnHeaderProperty().get()) {
             // position the table header
             tableHeaderRowHeight = getTableHeaderRow().prefHeight(-1);
             layoutInArea(getTableHeaderRow(), x, y, w, tableHeaderRowHeight,
             // FIXME try to hide the columnHeader
         }
 
-        if (spreadsheetView.rowHeaderProperty().get()) {
+        if (spreadsheetView.showRowHeaderProperty().get()) {
             layoutInArea(rowHeader, x - rowHeaderWidth, y
                     - tableHeaderRowHeight, w, h, baselineOffset, HPos.CENTER,
                     VPos.CENTER);
         return getFlow().getCells().size();
     }
     
+    public VirtualScrollBar getHBar() {
+        return getFlow().getHorizontalBar();
+    }
     
+    public VirtualScrollBar getVBar() {
+        return getFlow().getVerticalBar();
+    }
     
     
     
+    // hacky, but at least it lets us hide some API
+    public static final SpreadsheetViewSkin getSkin(SpreadsheetView spv) {
+        return (SpreadsheetViewSkin) spv.getSkin();
+    }
+    
     public static SpreadsheetRow getCell(SpreadsheetView spv, int index) {
         TableView<DataRow> tableView = (TableView<DataRow>) spv.getSkin().getNode();
         SpreadsheetViewSkin spvSkin = (SpreadsheetViewSkin) tableView.getSkin();

File src/main/java/org/controlsfx/control/SpreadsheetView.java

View file
  • Ignore whitespace
     private DataFormat fmt;
     private final ObservableList<Integer> fixedRows = FXCollections.observableArrayList();
     private final ObservableList<Integer> fixedColumns = FXCollections.observableArrayList();
-    private final BooleanProperty columnHeader = new SimpleBooleanProperty(true);
-    private final BooleanProperty rowHeader = new SimpleBooleanProperty(true);
 
     //Properties needed by the SpreadsheetView and managed by the skin (source is the VirtualFlow)
     private VirtualScrollBar hbar=null;
      *                                                                         *
      **************************************************************************/
 
-    // FIXME this shouldn't be here!
-    /**
-     * Not for public use.
-     * @return
-     */
-    public VirtualScrollBar getHbar() {
-        return hbar;
-    }
-
-    // FIXME this shouldn't be here!
-    /**
-     * Not for public use.
-     * @return
-     */
-    public void setHbar(VirtualScrollBar hbar) {
-        this.hbar = hbar;
-    }
-
-    // FIXME this shouldn't be here!
-    /**
-     * Not for public use.
-     * @return
-     */
-    public VirtualScrollBar getVbar() {
-        return vbar;
-    }
-
-    // FIXME this shouldn't be here!
-    /**
-     * Not for public use.
-     * @return
-     */
-    public void setVbar(VirtualScrollBar vbar) {
-        this.vbar = vbar;
-    }
-
-    // FIXME this shouldn't be here!
-    /**
-     * Not for public use.
-     * @return
-     */
-    public boolean isEmptyCells() {
-//        return cells.isEmpty();
-        return grid.getRows().isEmpty();
-    }
+//    // FIXME this shouldn't be here!
+//    /**
+//     * Not for public use.
+//     * @return
+//     */
+//    public VirtualScrollBar getHbar() {
+//        return hbar;
+//    }
+//
+//    // FIXME this shouldn't be here!
+//    /**
+//     * Not for public use.
+//     * @return
+//     */
+//    public void setHbar(VirtualScrollBar hbar) {
+//        this.hbar = hbar;
+//    }
+//
+//    // FIXME this shouldn't be here!
+//    /**
+//     * Not for public use.
+//     * @return
+//     */
+//    public VirtualScrollBar getVbar() {
+//        return vbar;
+//    }
+//
+//    // FIXME this shouldn't be here!
+//    /**
+//     * Not for public use.
+//     * @return
+//     */
+//    public void setVbar(VirtualScrollBar vbar) {
+//        this.vbar = vbar;
+//    }
+//
+//    // FIXME this shouldn't be here!
+//    /**
+//     * Not for public use.
+//     * @return
+//     */
+//    public boolean isEmptyCells() {
+////        return cells.isEmpty();
+//        return grid.getRows().isEmpty();
+//    }
 
     /**
      * Return a {@link TablePosition} of cell being currently edited.
     public ObservableList<SpreadsheetColumn> getColumns(){
 		return columns;
     }
-    /**
-     * Return the number of rows in the model.
-     * @return
-     */
-    public int getModelRowCount(){
-    	return grid.getRowCount();
-    }
+//    /**
+//     * Return the number of rows in the model.
+//     * @return
+//     */
+//    public int getModelRowCount(){
+//    	return grid.getRowCount();
+//    }
+//    
+// // FIXME this shouldn't be here!
+//    /**
+//     * Return the number of rows actually visible on screen.
+//     * @return
+//     */
+//    public final int getRowCount(){
+//        return grid.getRowCount();
+////        return cells.size();
+//    }
 
     /**
      * Return the model Grid used by the SpreadsheetView
     public final Grid getGrid(){
         return grid;
     }
+    
+    
+    private final BooleanProperty showColumnHeader = new SimpleBooleanProperty(true, "showColumnHeader");
+    
     /**
      * Activate and deactivate the Column Header
      * @param b
      */
-    public final void setColumnHeader(final boolean b){
+    public final void setShowColumnHeader(final boolean b){
         //TODO Need to do that again
         //flow.recreateCells(); // Because otherwise we have at the bottom
-        columnHeader.setValue(b);
+        showColumnHeader.setValue(b);
+    }
+    
+    public final boolean isShowColumnHeader() {
+        return showColumnHeader.get();
     }
 
     /**
      * BooleanProperty associated with the column Header.
      * @return
      */
-    public final BooleanProperty columnHeaderProperty() {
-        return columnHeader;
+    public final BooleanProperty showColumnHeaderProperty() {
+        return showColumnHeader;
     }
 
+    
+    private final BooleanProperty showRowHeader = new SimpleBooleanProperty(true, "showRowHeader");
+    
     /**
      * Activate and deactivate the Row Header
      * @param b
      */
-    public final void setRowHeader(final boolean b){
-        rowHeader.setValue(b);
+    public final void setShowRowHeader(final boolean b){
+        showRowHeader.setValue(b);
     }
+    
+    public final boolean isShowRowHeader() {
+        return showRowHeader.get();
+    }
+    
     /**
      * BooleanProperty associated with the row Header.
      * @return
      */
-    public final BooleanProperty rowHeaderProperty() {
-        return rowHeader;
+    public final BooleanProperty showRowHeaderProperty() {
+        return showRowHeader;
     }
 
     /**
         return tableView.getItems();
     }
     
-    // FIXME this shouldn't be here!
-    /**
-     * Return the number of rows actually visible on screen.
-     * @return
-     */
-    public final int getRowCount(){
-        return grid.getRowCount();
-//        return cells.size();
-    }
-    
-
     /**
      * Return the {@link SpreadsheetRow} at the specified index
      * @param index
             case ROW_INVISIBLE:
             default:
                 final DataCell<?> cellSpan = tableView.getItems().get(row).getCell(col);
-                if (!isEmptyCells() && getNonFixedRow(0).getIndex() <= cellSpan.getRow()) {
+                if (!grid.getRows().isEmpty() && getNonFixedRow(0).getIndex() <= cellSpan.getRow()) {
                     return new TablePosition<>(tableView, cellSpan.getRow(), tableView.getColumns().get(cellSpan.getColumn()));
 
                 } else { // If it's not, then it's the firstkey
          * Make the tableView move when selection operating outside bounds
          */
         private final Timeline timer = new Timeline(new KeyFrame(Duration.millis(100), new EventHandler<ActionEvent>() {
-            @Override
-            public void handle(ActionEvent event) {
+            @Override public void handle(ActionEvent event) {
+                SpreadsheetViewSkin skin = SpreadsheetViewSkin.getSkin(spreadsheetView);
+                
                 if (mouseEvent != null && !tableView.contains(mouseEvent.getX(), mouseEvent.getY())) {
                     if(mouseEvent.getSceneX() < tableView.getLayoutX()) {
-                        spreadsheetView.getHbar().decrement();
+                        skin.getHBar().decrement();
                     }else if(mouseEvent.getSceneX() > tableView.getLayoutX()+tableView.getWidth()){
-                        spreadsheetView.getHbar().increment();
+                        skin.getHBar().increment();
                     }
                     else if(mouseEvent.getSceneY() < tableView.getLayoutY()) {
-                        spreadsheetView.getVbar().decrement();
+                        skin.getVBar().decrement();
                     }else if(mouseEvent.getSceneY() > tableView.getLayoutY()+tableView.getHeight()) {
-                        spreadsheetView.getVbar().increment();
+                        skin.getVBar().increment();
                     }
                 }
             }
 
             //We try to make visible the rows that may be hiden by Fixed rows
             // We don't want to do any scroll behavior when dragging
-            if(!drag && !spreadsheetView.isEmptyCells() && spreadsheetView.getNonFixedRow(0).getIndex()> posFinal.getRow() && !spreadsheetView.getFixedRows().contains(posFinal.getRow())) {
+            if(!drag && !spreadsheetView.getGrid().getRows().isEmpty() && spreadsheetView.getNonFixedRow(0).getIndex()> posFinal.getRow() && !spreadsheetView.getFixedRows().contains(posFinal.getRow())) {
                 tableView.scrollTo(posFinal.getRow());
             }
 

File src/main/java/org/controlsfx/control/spreadsheet/view/SpreadsheetCellEditor.java

View file
  • Ignore whitespace
                 end();
             }
         };
-        spreadsheetView.getVbar().valueProperty().addListener(editorListener);
+        SpreadsheetViewSkin.getSkin(spreadsheetView).getVBar().valueProperty().addListener(editorListener);
     }
 
     /***************************************************************************
         editing = false;
         spreadsheetEditor.end();
 
-        spreadsheetView.getVbar().valueProperty()
-                .removeListener(editorListener);
+        SpreadsheetViewSkin.getSkin(spreadsheetView).getVBar().valueProperty().removeListener(editorListener);
         editorListener = null;
     }
 
         private SpreadsheetRow original;
         private boolean isMoved;
 
+        private int getCellCount() {
+            return SpreadsheetViewSkin.getSkin(spreadsheetView).getCellsSize();
+        }
         
         private boolean addCell(SpreadsheetCell<?> cell){
-            SpreadsheetRow temp = SpreadsheetViewSkin.getCell(spreadsheetView, spreadsheetView.getRowCount()-1-spreadsheetView.getFixedRows().size());
+            SpreadsheetRow temp = SpreadsheetViewSkin.getCell(spreadsheetView, getCellCount()-1-spreadsheetView.getFixedRows().size());
             if(temp != null){
                 temp.addCell(cell);
                 return true;
             }
             return false;
-
         }
         /***********************************************************************
          * * Public Methods * *
         public void startEdit() {
             // Case when RowSpan if larger and we're not on the last row
             if (modelCell != null && modelCell.getRowSpan() > 1
-                    && modelCell.getRow() != spreadsheetView.getRowCount() - 1) {
+                    && modelCell.getRow() != getCellCount() - 1) {
                 original = (SpreadsheetRow) viewCell.getTableRow();
 
                 final double temp = viewCell.getLocalToSceneTransform().getTy();

File src/samples/java/org/controlsfx/samples/SpreadsheetView/HelloSpreadsheetView.java

View file
  • Ignore whitespace
 			@Override
 			public void changed(ObservableValue<? extends Boolean> arg0,
 					Boolean arg1, Boolean arg2) {
-				spv.setRowHeader(arg2);
+				spv.setShowRowHeader(arg2);
 			}
 		});
 
 			@Override
 			public void changed(
 					ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2) {
-				spv.setColumnHeader(arg2);
+				spv.setShowColumnHeader(arg2);
 			}
 		});
 		//In order to change the span style more easily