1 /*
   2  * Copyright (c) 2014, 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 package javafx.scene.control.test.nchart;
  26 
  27 import com.sun.javafx.scene.control.LabeledText;
  28 import java.util.ArrayList;
  29 import java.util.List;
  30 import javafx.geometry.Side;
  31 import javafx.scene.Node;
  32 import javafx.scene.chart.Axis;
  33 import javafx.scene.paint.Paint;
  34 import javafx.scene.shape.Path;
  35 import javafx.scene.text.Font;
  36 import javafx.scene.text.Text;
  37 import org.jemmy.action.GetAction;
  38 import org.jemmy.control.Wrap;
  39 import org.jemmy.fx.ByStyleClass;
  40 import org.jemmy.fx.Root;
  41 import org.jemmy.interfaces.Parent;
  42 import org.jemmy.lookup.Lookup;
  43 import org.jemmy.lookup.LookupCriteria;
  44 
  45 /**
  46  * @author Alexander Kirov
  47  *
  48  * This class is a part of experimental tests on Charts, which are aimed to
  49  * replace tests with huge amount of images, and which (probably) could fail at
  50  * any moment and for unknown reason. They could be fixed or disabled.
  51  */
  52 public class AxisDescriptionProvider {
  53 
  54     protected Parent<Node> controlAsParent;
  55     private Wrap<? extends Axis> axis;
  56     final String AXIS_MINOR_TICK_MARK_STYLE_CLASS = "axis-minor-tick-mark";
  57     final String AXIS_TICK_MARK_STYLE_CLASS = "axis-tick-mark";
  58     final String LABELED_TEXT_STYLE_CLASS = "text";
  59 
  60     public AxisDescriptionProvider(Wrap<? extends Axis> axis) {
  61         this.axis = axis;
  62         controlAsParent = axis.as(Parent.class, Node.class);
  63     }
  64 
  65     final public Wrap<? extends LabeledText> getTitleWrap() {
  66         return controlAsParent.lookup(LabeledText.class, new ByStyleClass(LABELED_TEXT_STYLE_CLASS)).wrap();
  67     }
  68 
  69     final public Wrap<? extends Path> getMinorTickMartPathWrap() {
  70         return controlAsParent.lookup(Path.class, new ByStyleClass(AXIS_MINOR_TICK_MARK_STYLE_CLASS)).wrap();
  71     }
  72 
  73     final public Wrap<? extends Path> getMajorTickMartPathWrap() {
  74         return controlAsParent.lookup(Path.class, new ByStyleClass(AXIS_TICK_MARK_STYLE_CLASS)).wrap();
  75     }
  76 
  77     final public List<Wrap<? extends Text>> getLegendLabels() {
  78         List<Wrap<? extends Text>> list = new ArrayList<Wrap<? extends Text>>();
  79         Lookup lookup = controlAsParent.lookup(Text.class, new LookupCriteria<Text>() {
  80             public boolean check(Text cntrl) {
  81                 return cntrl.getStyleClass().size() == 0;
  82             }
  83         });
  84 
  85         int size = lookup.size();
  86         for (int i = 0; i < size; i++) {
  87             list.add(lookup.wrap(i));
  88         }
  89 
  90         return list;
  91     }
  92 
  93     final public boolean isAnimated() {
  94         return new GetAction<Boolean>() {
  95             @Override
  96             public void run(Object... os) throws Exception {
  97                 setResult(axis.getControl().getAnimated());
  98             }
  99         }.dispatch(Root.ROOT.getEnvironment());
 100     }
 101 
 102     final public boolean isAutoRanging() {
 103         return new GetAction<Boolean>() {
 104             @Override
 105             public void run(Object... os) throws Exception {
 106                 setResult(axis.getControl().isAutoRanging());
 107             }
 108         }.dispatch(Root.ROOT.getEnvironment());
 109     }
 110 
 111     final public String getLabel() {
 112         return new GetAction<String>() {
 113             @Override
 114             public void run(Object... os) throws Exception {
 115                 setResult(axis.getControl().getLabel());
 116             }
 117         }.dispatch(Root.ROOT.getEnvironment());
 118     }
 119 
 120     final public Side getSide() {
 121         return new GetAction<Side>() {
 122             @Override
 123             public void run(Object... os) throws Exception {
 124                 setResult(axis.getControl().getSide());
 125             }
 126         }.dispatch(Root.ROOT.getEnvironment());
 127     }
 128 
 129     final public Paint getTickLabelFill() {
 130         return new GetAction<Paint>() {
 131             @Override
 132             public void run(Object... os) throws Exception {
 133                 setResult(axis.getControl().getTickLabelFill());
 134             }
 135         }.dispatch(Root.ROOT.getEnvironment());
 136     }
 137 
 138     final public Font getTickLabelFont() {
 139         return new GetAction<Font>() {
 140             @Override
 141             public void run(Object... os) throws Exception {
 142                 setResult(axis.getControl().getTickLabelFont());
 143             }
 144         }.dispatch(Root.ROOT.getEnvironment());
 145     }
 146 
 147     final public double getTickLabelGap() {
 148         return new GetAction<Double>() {
 149             @Override
 150             public void run(Object... os) throws Exception {
 151                 setResult(axis.getControl().getTickLabelGap());
 152             }
 153         }.dispatch(Root.ROOT.getEnvironment());
 154     }
 155 
 156     final public double getTickLabelRotation() {
 157         return new GetAction<Double>() {
 158             @Override
 159             public void run(Object... os) throws Exception {
 160                 setResult(axis.getControl().getTickLabelRotation());
 161             }
 162         }.dispatch(Root.ROOT.getEnvironment());
 163     }
 164 
 165     final public boolean isTickLabelsVisible() {
 166         return new GetAction<Boolean>() {
 167             @Override
 168             public void run(Object... os) throws Exception {
 169                 setResult(axis.getControl().isTickLabelsVisible());
 170             }
 171         }.dispatch(Root.ROOT.getEnvironment());
 172     }
 173 
 174     final public double getTickLength() {
 175         return new GetAction<Double>() {
 176             @Override
 177             public void run(Object... os) throws Exception {
 178                 setResult(axis.getControl().getTickLength());
 179             }
 180         }.dispatch(Root.ROOT.getEnvironment());
 181     }
 182 
 183     final public boolean isTickMarkVisible() {
 184         return new GetAction<Boolean>() {
 185             @Override
 186             public void run(Object... os) throws Exception {
 187                 setResult(axis.getControl().isTickMarkVisible());
 188             }
 189         }.dispatch(Root.ROOT.getEnvironment());
 190     }
 191 }