1 /* 2 * Copyright (c) 2012, 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; 27 28 import com.sun.javafx.scene.control.LabeledImpl; 29 import com.sun.javafx.scene.control.skin.Utils; 30 import javafx.scene.Scene; 31 import javafx.scene.control.Label; 32 import javafx.scene.control.Labeled; 33 import javafx.scene.control.MenuButton; 34 import javafx.scene.control.skin.MenuButtonSkin; 35 import javafx.scene.image.Image; 36 import javafx.scene.image.ImageView; 37 import javafx.stage.Stage; 38 import org.junit.Test; 39 40 import java.net.URL; 41 42 import static org.junit.Assert.assertEquals; 43 import static org.junit.Assert.assertNotNull; 44 45 public class LabeledImplTestOther { 46 47 48 @Test public void test_RT_21357() { 49 50 final Labeled labeled = new Label("label"); 51 final LabeledImpl labeledImpl = new LabeledImpl(labeled); 52 53 URL url = Utils.class.getResource("caspian/center-btn.png"); 54 Image img = new Image(url.toExternalForm()); 55 assertNotNull(img); 56 57 ImageView iView = new ImageView(img); 58 labeled.setGraphic(iView); 59 60 assertEquals(labeled.getGraphic(), labeledImpl.getGraphic()); 61 assertNotNull(labeled.getGraphic()); 62 } 63 64 @Test public void test_RT_21617() { 65 66 MenuButton mb = new MenuButton(); 67 mb.setText("SomeText"); 68 MenuButtonSkin mbs = new MenuButtonSkin(mb); 69 mb.setSkin(mbs); 70 71 mb.setTranslateX(100);mb.setTranslateY(100); 72 73 Scene scene = new Scene(mb, 300, 300); 74 scene.getStylesheets().add(LabeledImplTestOther.class.getResource("LabeledImplTest.css").toExternalForm()); 75 Stage stage = new Stage(); 76 stage.setScene(scene); 77 stage.show(); 78 79 80 LabeledImpl labeledImpl = (LabeledImpl)mb.lookup(".label"); 81 assertNotNull(labeledImpl); 82 // LabeledImpl should not mirror the translateX/Y of the MenuButton 83 assertEquals(100, mb.getTranslateX(), 0.00001); 84 assertEquals(0, labeledImpl.getTranslateX(), 0.00001); 85 assertEquals(100, mb.getTranslateY(), 0.00001); 86 assertEquals(0, labeledImpl.getTranslateY(), 0.00001); 87 // opacity set to 50% in LabeledImplTest.css 88 assertEquals(1, mb.getOpacity(), 0.00001); 89 assertEquals(.5, labeledImpl.getOpacity(), 0.00001); 90 } 91 92 }