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.skin;
  27 
  28 import javafx.css.StyleConverter;
  29 import javafx.css.CssMetaData;
  30 import java.net.URL;
  31 import java.util.ArrayList;
  32 
  33 import java.util.Arrays;
  34 import java.util.Collection;
  35 import java.util.List;
  36 import javafx.beans.value.WritableValue;
  37 import javafx.geometry.Insets;
  38 import javafx.geometry.Pos;
  39 import javafx.scene.Cursor;
  40 import javafx.scene.Scene;
  41 import javafx.scene.control.*;
  42 import javafx.scene.effect.BlendMode;
  43 import javafx.scene.image.Image;
  44 import javafx.scene.image.ImageView;
  45 import javafx.scene.layout.VBox;
  46 import javafx.scene.paint.Color;
  47 import javafx.scene.text.Font;
  48 import javafx.scene.text.TextAlignment;
  49 import javafx.stage.Stage;
  50 import javax.swing.GroupLayout;
  51 
  52 import org.junit.runner.RunWith;
  53 import org.junit.runners.Parameterized;
  54 import org.junit.runners.Parameterized.Parameters;
  55 
  56 import org.junit.Before;
  57 import org.junit.Ignore;
  58 import org.junit.Test;
  59 import static org.junit.Assert.*;
  60 
  61 public class LabeledImplTestOther {
  62     
  63     
  64     @Test public void test_RT_21357() {
  65         
  66         final Labeled labeled = new Label("label");
  67         final LabeledImpl labeledImpl = new LabeledImpl(labeled);
  68         
  69         URL url = LabeledSkinBase.class.getResource("caspian/center-btn.png");
  70         Image img = new Image(url.toExternalForm());
  71         assertNotNull(img);
  72         
  73         ImageView iView = new ImageView(img);
  74         labeled.setGraphic(iView);  
  75         
  76         assertEquals(labeled.getGraphic(), labeledImpl.getGraphic());
  77         assertNotNull(labeled.getGraphic());
  78     }
  79 
  80     @Test public void test_RT_21617() {
  81         
  82         MenuButton mb = new MenuButton();
  83         mb.setText("SomeText"); 
  84         MenuButtonSkin mbs = new MenuButtonSkin(mb);
  85         mb.setSkin(mbs);
  86          
  87         mb.setTranslateX(100);mb.setTranslateY(100); 
  88         
  89         Scene scene = new Scene(mb, 300, 300); 
  90         scene.getStylesheets().add(LabeledImplTestOther.class.getResource("LabeledImplTest.css").toExternalForm());
  91         Stage stage = new Stage();
  92         stage.setScene(scene); 
  93         stage.show(); 
  94         
  95         
  96         LabeledImpl labeledImpl = (LabeledImpl)mb.lookup(".label");
  97         assertNotNull(labeledImpl);
  98         // LabeledImpl should not mirror the translateX/Y of the MenuButton
  99         assertEquals(100, mb.getTranslateX(), 0.00001);
 100         assertEquals(0, labeledImpl.getTranslateX(), 0.00001);
 101         assertEquals(100, mb.getTranslateY(), 0.00001);
 102         assertEquals(0, labeledImpl.getTranslateY(), 0.00001);
 103         // opacity set to 50% in LabeledImplTest.css
 104         assertEquals(1, mb.getOpacity(), 0.00001);
 105         assertEquals(.5, labeledImpl.getOpacity(), 0.00001);
 106     }
 107     
 108 }