1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.javafx.scene.control.skin; 27 28 import javafx.scene.control.DateCell; 29 import javafx.scene.text.Text; 30 31 import com.sun.javafx.scene.control.behavior.DateCellBehavior; 32 33 public class DateCellSkin extends CellSkinBase<DateCell, DateCellBehavior> { 34 35 public DateCellSkin(DateCell control) { 36 super(control, new DateCellBehavior(control)); 37 38 control.setMaxWidth(Double.MAX_VALUE); // make the cell grow to fill a GridPane's cell 39 } 40 41 @Override protected void updateChildren() { 42 super.updateChildren(); 43 44 Text secondaryText = (Text)getSkinnable().getProperties().get("DateCell.secondaryText"); 45 if (secondaryText != null) { 46 // LabeledSkinBase rebuilds the children list each time, so it's 47 // safe to add more here. 48 secondaryText.setManaged(false); 49 getChildren().add(secondaryText); 50 } 51 } 52 53 @Override protected void layoutChildren(final double x, final double y, 54 final double w, final double h) { 55 super.layoutChildren(x,y,w,h); 56 57 Text secondaryText = (Text)getSkinnable().getProperties().get("DateCell.secondaryText"); 58 if (secondaryText != null) { 59 // Place the secondary Text node at BOTTOM_RIGHT. 60 double textX = x + w - rightLabelPadding() - secondaryText.getLayoutBounds().getWidth(); 61 double textY = y + h - bottomLabelPadding() - secondaryText.getLayoutBounds().getHeight(); 62 secondaryText.relocate(snapPosition(textX), snapPosition(textY)); 63 } 64 } 65 66 private double cellSize() { 67 double cellSize = getCellSize(); 68 Text secondaryText = (Text)getSkinnable().getProperties().get("DateCell.secondaryText"); 69 if (secondaryText != null && cellSize == DEFAULT_CELL_SIZE) { 70 // Workaround for RT-31643. The cellSize property was not yet set from CSS. 71 cellSize = 36; 72 } 73 return cellSize; 74 } 75 76 @Override protected double computePrefWidth(double height, 77 double topInset, double rightInset, 78 double bottomInset, double leftInset) { 79 double pref = super.computePrefWidth(height, topInset, rightInset, bottomInset, leftInset); 80 return snapSize(Math.max(pref, cellSize())); 81 } 82 83 @Override protected double computePrefHeight(double width, 84 double topInset, double rightInset, 85 double bottomInset, double leftInset) { 86 double pref = super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset); 87 return snapSize(Math.max(pref, cellSize())); 88 } 89 }