下面列出了怎么用javafx.scene.control.Skin的API类实例代码及写法,或者点击链接到github查看源代码。
private void initialiseTreeViewReflection() {
// we can't use wrapped.getSkin() because it may be null.
// we don't care about the specific instance, we just want the class
@SuppressWarnings("PMD.UselessOverridingMethod")
Skin<?> dftSkin = new TreeView<Object>() {
@Override
protected Skin<?> createDefaultSkin() {
return super.createDefaultSkin();
}
}.createDefaultSkin();
Object flow = getVirtualFlow(dftSkin);
if (flow == null) {
return;
}
treeViewFirstVisibleMethod = MethodUtils.getMatchingMethod(flow.getClass(), "getFirstVisibleCell");
treeViewLastVisibleMethod = MethodUtils.getMatchingMethod(flow.getClass(), "getLastVisibleCell");
}
@Override
protected Skin<?> createDefaultSkin()
{
final SliderSkin skin = (SliderSkin) super.createDefaultSkin();
// SliderSkin is accessible, but the more interesting
// com.sun.javafx.scene.control.behavior.SliderBehavior
// is not.
// Work around this by locating 'track'...
for (Node node : skin.getChildren())
if (node.getStyleClass().contains("track"))
{
// Capture mouse clicks, use to inc/dec instead of jumping there
node.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> handleTrackClick(node, event));
// Disable mouse drag, which by default also jumps to mouse
node.setOnMouseDragged(null);
break;
}
return skin;
}
@Override protected Skin createDefaultSkin() {
switch(skinType) {
case YOTA2 : return new ClockSkin(Clock.this);
case LCD : return new LcdClockSkin(Clock.this);
case PEAR : return new PearClockSkin(Clock.this);
case PLAIN : return new PlainClockSkin(Clock.this);
case DB : return new DBClockSkin(Clock.this);
case FAT : return new FatClockSkin(Clock.this);
case ROUND_LCD : return new RoundLcdClockSkin(Clock.this);
case SLIM : return new SlimClockSkin(Clock.this);
case MINIMAL : return new MinimalClockSkin(Clock.this);
case DIGITAL : return new DigitalClockSkin(Clock.this);
case TEXT : return new TextClockSkin(Clock.this);
case DESIGN : return new DesignClockSkin(Clock.this);
case INDUSTRIAL: return new IndustrialClockSkin(Clock.this);
case TILE : return new TileClockSkin(Clock.this);
case DIGI : return new DigitalClockSkin(Clock.this);
case MORPHING : return new MorphingClockSkin(Clock.this);
case CLOCK :
default : return new ClockSkin(Clock.this);
}
}
public FGauge(final Gauge GAUGE, final GaugeDesign DESIGN, final GaugeBackground BACKGROUND) {
getStylesheets().add(getClass().getResource("framed-gauge.css").toExternalForm());
getStyleClass().setAll("framed-gauge");
gauge = GAUGE;
gaugeDesign = DESIGN;
gaugeBackground = BACKGROUND;
Skin skin = gauge.getSkin();
if (null == skin) {
throw new RuntimeException("Please use a valid Skin.");
}
init();
initGraphics();
registerListeners();
}
private Object getVirtualFlow(Skin<?> skin) {
try {
// On JRE 9 and 10, the field is declared in TreeViewSkin
// http://hg.openjdk.java.net/openjfx/9/rt/file/c734b008e3e8/modules/javafx.controls/src/main/java/javafx/scene/control/skin/TreeViewSkin.java#l85
// http://hg.openjdk.java.net/openjfx/10/rt/file/d14b61c6be12/modules/javafx.controls/src/main/java/javafx/scene/control/skin/TreeViewSkin.java#l85
// On JRE 8, the field is declared in the VirtualContainerBase superclass
// http://hg.openjdk.java.net/openjfx/8/master/rt/file/f89b7dc932af/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualContainerBase.java#l68
return FieldUtils.readField(skin, "flow", true);
} catch (IllegalAccessException ignored) {
} catch (RuntimeException re) {
if (!reflectionImpossibleWarning && "java.lang.reflect.InaccessibleObjectException".equals(re.getClass().getName())) {
// that exception was introduced for Jigsaw (JRE 9)
// so we can't refer to it without breaking compat with Java 8
// TODO find a way to report errors in the app directly, System.out is too shitty
System.out.println();
System.out.println("On JRE 9+, the following VM argument makes the controls smarter:");
System.out.println("--add-opens javafx.controls/javafx.scene.control.skin=ALL-UNNAMED");
System.out.println("Please consider adding it to your command-line or using the launch script bundled with PMD's binary distribution.");
reflectionImpossibleWarning = true;
} else {
throw re;
}
}
return null;
}
private void showAutocompletePopup(int insertionIndex, String input) {
CompletionResultSource suggestionMaker = mySuggestionProvider.get();
List<MenuItem> suggestions =
suggestionMaker.getSortedMatches(input, 5)
.map(result -> {
Label entryLabel = new Label();
entryLabel.setGraphic(result.getTextFlow());
entryLabel.setPrefHeight(5);
CustomMenuItem item = new CustomMenuItem(entryLabel, true);
item.setUserData(result);
item.setOnAction(e -> applySuggestion(insertionIndex, input, result.getStringMatch()));
return item;
})
.collect(Collectors.toList());
autoCompletePopup.getItems().setAll(suggestions);
myCodeArea.getCharacterBoundsOnScreen(insertionIndex, insertionIndex + input.length())
.ifPresent(bounds -> autoCompletePopup.show(myCodeArea, bounds.getMinX(), bounds.getMaxY()));
Skin<?> skin = autoCompletePopup.getSkin();
if (skin != null) {
Node fstItem = skin.getNode().lookup(".menu-item");
if (fstItem != null) {
fstItem.requestFocus();
}
}
}
public final void filterUI(){
GridPane gridLEFT = new GridPane();
// Labels
Label stopwordsLabel = new Label("Stop words removal");
UIUtils.setSize(stopwordsLabel, Main.columnWidthLEFT/2, 24);
Label resizingLabel = new Label("Resizing");
UIUtils.setSize(resizingLabel, Main.columnWidthLEFT/2, 24);
gridLEFT.add(stopwordsLabel,0,0);
gridLEFT.add(new Rectangle(0,3),0,1);
gridLEFT.add(resizingLabel,0,2);
// Values
stopwordLists = new StopwordSets();
stopwordListsCheckComboBox = new CheckComboBox<>(stopwordLists.availableSets);
stopwordListsCheckComboBox.setStyle("-fx-font-size: 12px;");
stopwordListsCheckComboBox.skinProperty().addListener(new ChangeListener<Skin>() {
@Override
public void changed(ObservableValue<? extends Skin> observable, Skin oldValue, Skin newValue) {
if(oldValue==null && newValue!=null){
CheckComboBoxSkin skin = (CheckComboBoxSkin)newValue;
ComboBox combo = (ComboBox)skin.getChildren().get(0);
combo.setPrefWidth(Main.columnWidthLEFT/2);
combo.setMaxWidth(Double.MAX_VALUE);
}
}
});
// stopwordListsCheckComboBox.setMaxWidth(Double.MAX_VALUE);
// UIUtils.setSize(stopwordListsCheckComboBox,Main.columnWidthLEFT/2, 24);
gridLEFT.add(stopwordListsCheckComboBox,1,0);
resizeSlider = new RangeSlider();
resizeSlider.setBlockIncrement(0.1);
UIUtils.setSize(resizeSlider,Main.columnWidthLEFT/2, 24);
resizeSlider.resize(Main.columnWidthLEFT/2, 24);
gridLEFT.add(resizeSlider,1,2);
HBox filterDatasetBOTH = new HBox(5);
filterDatasetBOTH.getChildren().addAll(gridLEFT,createFilterButton());
grid.add(filterDatasetBOTH,0,11);
}
private static <T> boolean listenToComboBoxSkin(final ComboBox<T> comboBox, final Cell<T> cell) {
Skin<?> skin = comboBox.getSkin();
if (skin != null && skin instanceof ComboBoxListViewSkin) {
ComboBoxListViewSkin cbSkin = (ComboBoxListViewSkin) skin;
Node popupContent = cbSkin.getPopupContent();
if (popupContent != null && popupContent instanceof ListView) {
popupContent.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> cell.commitEdit(comboBox.getValue()));
return true;
}
}
return false;
}
protected void fixHorizontalScrollbar()
{
Skin skin = tree.getSkin();
if(skin == null)
{
return;
}
for(Node n: skin.getNode().lookupAll(".scroll-bar"))
{
if(n instanceof ScrollBar)
{
ScrollBar b = (ScrollBar)n;
if(b.getOrientation() == Orientation.HORIZONTAL)
{
if(isAutoResizeMode())
{
b.setManaged(false);
b.setPrefHeight(0);
b.setPrefWidth(0);
}
else
{
b.setManaged(true);
b.setPrefHeight(USE_COMPUTED_SIZE);
b.setPrefWidth(USE_COMPUTED_SIZE);
}
}
}
}
}
/**
* {@inheritDoc}
*/
@Override
protected Skin<?> createDefaultSkin() {
return new TooltipSkin(this) {
{
Node node = getNode();
node.setEffect(null);
}
};
}
/**
* {@inheritDoc}
*/
@Override
public Skin<?> createDefaultSkin() {
S skin = createSkin();
// initialise the skin
skin.initialise();
// create and initialise the behavior of the skin (if it exists)
skin.createDefaultBehavior();
return skin;
}
@Override
protected Skin<?> createDefaultSkin() {
return new SelectableLabelSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
// TODO: extend default skin to use prompt text property
return super.createDefaultSkin();
}
@Override
protected Skin<?> createDefaultSkin() {
return new AutoTooltipCheckBoxSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
final Skin<?> buttonSkin = super.createDefaultSkin();
RippleEffect.attach(this, this::getChildren);
return buttonSkin;
}
@Override
protected Skin<?> createDefaultSkin() {
return new TableViewSkinX<T>(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new HiddenSidesPaneSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new SidesPaneSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new OnlyContextMenuSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new ListPopupSkin<>(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return createSkin(getSkinType());
}
private Skin<?> createSkin(SkinType skinType) {
return skinType.getFactory().apply(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new AutoTooltipLabelSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new CustomTileSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new CustomPageSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new CustomTabSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new CustomNavigationDrawerSkin(this);
}
@Override
protected final Skin<?> createDefaultSkin() {
return new WorkbenchSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new DialogSkin(this);
}
@Override
protected Skin<?> createDefaultSkin() {
return new PageSkin(this);
}