1. ControlsFX
  2. ControlsFX
  3. ControlsFX

Commits

Samir Hadzic  committed 5abf68d

Adding the possibility to tell to the SpreadsheetCell that she has some comments.

  • Participants
  • Parent commits b868dc9
  • Branches default

Comments (0)

Files changed (4)

File src/main/java/impl/org/controlsfx/spreadsheet/CellView.java

View file
  • Ignore whitespace
         }
 
     }
+    @Override
+    protected javafx.scene.control.Skin<?> createDefaultSkin() {
+    	return new CellViewSkin(this);
+    };
 }

File src/main/java/impl/org/controlsfx/spreadsheet/CellViewSkin.java

View file
  • Ignore whitespace
+package impl.org.controlsfx.spreadsheet;
+
+import javafx.collections.ObservableList;
+import javafx.scene.control.TableCell;
+import javafx.scene.layout.Region;
+
+import org.controlsfx.control.spreadsheet.SpreadsheetCell;
+
+import com.sun.javafx.scene.control.skin.TableCellSkin;
+
+public class CellViewSkin extends TableCellSkin<ObservableList<SpreadsheetCell>, SpreadsheetCell>{
+
+	private Region commentTriangle = null;
+	
+	public CellViewSkin(
+			TableCell<ObservableList<SpreadsheetCell>, SpreadsheetCell> arg0) {
+		super(arg0);
+	}
+	
+	@Override
+	protected void layoutChildren(double x, final double y, final double w,
+            final double h) {
+		super.layoutChildren(x, y, w, h);
+		
+		if(getSkinnable().getItem() != null){
+			if( getSkinnable().getItem().isCommented()){
+				if(commentTriangle == null){
+					commentTriangle = new Region();
+				}
+				if(!getChildren().contains(commentTriangle)){
+					getChildren().add(commentTriangle);
+				}
+				commentTriangle.resize(6,6);
+				commentTriangle.getStyleClass().add("comment");
+				commentTriangle.relocate(getSkinnable().getWidth()-6, snappedTopInset()-1);
+			}else if(commentTriangle != null){
+				getChildren().remove(commentTriangle);
+				commentTriangle = null;
+			}
+		}
+	}
+}

File src/main/java/org/controlsfx/control/spreadsheet/SpreadsheetCell.java

View file
  • Ignore whitespace
 	 * http://www.oracle.com/technetwork/articles/java/javaserial-1536170.html
 	 */
 	private transient ObservableList<String> styleClass;
+
 	
 	
-
 	/***************************************************************************
 	 * 
 	 * Constructor
 	 * Properties
 	 * 
 	 ***************************************************************************/
-
+	
 	// --- item
 	private transient ObjectProperty<Object> item = new SimpleObjectProperty<Object>(this, "item") {
 		@Override protected void invalidated() {
         return editable;
     }
 
+    // --- comment
+ 	private transient BooleanProperty commented = new SimpleBooleanProperty(this, "commented", false);
+ 	
+ 	/**
+      * Return if this cell can be edited or not.
+      * 
+      * @return true if this cell is editable.
+      */
+     public final boolean isCommented() {
+         return commented == null ? true : commented.get();
+     }
+
+     /**
+      * Change the commented state of this cell.
+      * 
+      * @param flag
+      */
+     public final void setCommented(boolean flag) {
+    	 commentedProperty().set(flag);
+     }
+
+     /**
+      * The {@link BooleanProperty} linked with the commented state.
+      * 
+      * @return The {@link BooleanProperty} linked with the commented state.
+      */
+     public final BooleanProperty commentedProperty() {
+         return commented;
+     }
 	
 	
+	
+
 	/***************************************************************************
 	 * 
 	 * Public Methods

File src/main/resources/org/controlsfx/control/spreadsheet/spreadsheet.css

View file
  • Ignore whitespace
 /* HORIZONTAL HEADER VISIBILITY */
 .column-header-background.invisible { visibility: hidden; -fx-padding: -1em; }
 
+.comment{
+	-fx-background-color: red;
+	-fx-shape : "M 0 0 L -1 0 L 0 1 z";
+}