1 /* 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. 3 * All rights reserved. Use is subject to license terms. 4 * 5 * This file is available and licensed under the following license: 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * - Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the distribution. 16 * - Neither the name of Oracle Corporation nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package com.oracle.javafx.scenebuilder.kit.util.control.effectpicker; 33 34 import javafx.scene.control.Menu; 35 import javafx.scene.control.RadioMenuItem; 36 import javafx.scene.control.SeparatorMenuItem; 37 import javafx.scene.control.ToggleGroup; 38 import javafx.scene.effect.Effect; 39 import javafx.scene.effect.Lighting; 40 41 /** 42 * Effect path item for the lighting effect. 43 */ 44 public class LightingPathItem extends EffectPathItem { 45 46 private final RadioMenuItem bumpMenuItem = new RadioMenuItem("BumpInput"); //NOI18N 47 private final RadioMenuItem contentMenuItem = new RadioMenuItem("ContentInput"); //NOI18N 48 private final ToggleGroup inputToggleGroup = new ToggleGroup(); 49 private EffectPathItem bumpInputPathItem; 50 private EffectPathItem contentInputPathItem; 51 52 public LightingPathItem(EffectPickerController epc, Effect effect, EffectPathItem hostPathItem) { 53 super(epc, effect, hostPathItem); 54 assert effect instanceof javafx.scene.effect.Lighting; 55 initialize(); 56 } 57 58 @Override 59 EffectPathItem getSelectedInputPathItem() { 60 if (bumpMenuItem.isSelected()) { 61 return bumpInputPathItem; 62 } else { 63 assert contentMenuItem.isSelected() == true; 64 return contentInputPathItem; 65 } 66 } 67 68 @Override 69 void setSelectedInputEffect(Effect input) { 70 if (bumpMenuItem.isSelected()) { 71 setBumpInput(input); 72 } else { 73 assert contentMenuItem.isSelected() == true; 74 setContentInput(input); 75 } 76 } 77 78 void setBumpInputPathItem(EffectPathItem epi) { 79 bumpInputPathItem = epi; 80 } 81 82 void setContentInputPathItem(EffectPathItem epi) { 83 contentInputPathItem = epi; 84 } 85 86 Effect getBumpInput() { 87 return ((Lighting) effect).getBumpInput(); 88 } 89 90 void setBumpInput(Effect input) { 91 ((Lighting) effect).setBumpInput(input); 92 } 93 94 Effect getContentInput() { 95 return ((Lighting) effect).getContentInput(); 96 } 97 98 void setContentInput(Effect input) { 99 ((Lighting) effect).setContentInput(input); 100 } 101 102 private void initialize() { 103 // Add Select Input Menu 104 final Menu inputMenu = new Menu("Select Input"); //NOI18N 105 bumpMenuItem.setToggleGroup(inputToggleGroup); 106 bumpMenuItem.setOnAction(event -> { 107 toggle_button.setText(getSimpleName() + " (BumpInput)"); //NOI18N 108 effectPickerController.updateUI(LightingPathItem.this); 109 }); 110 contentMenuItem.setToggleGroup(inputToggleGroup); 111 contentMenuItem.setOnAction(event -> { 112 toggle_button.setText(getSimpleName() + " (ContentInput)"); //NOI18N 113 effectPickerController.updateUI(LightingPathItem.this); 114 }); 115 116 inputMenu.getItems().addAll(bumpMenuItem, contentMenuItem); 117 menu_button.getItems().add(0, inputMenu); 118 menu_button.getItems().add(1, new SeparatorMenuItem()); 119 120 // BumpInput selected at init time 121 toggle_button.setText(getSimpleName() + " (BumpInput)"); //NOI18N 122 bumpMenuItem.setSelected(true); 123 contentMenuItem.setSelected(false); 124 } 125 }