    rev 4839 : RT-2529: Locale specific runtime errors (Turkish)

       1 /*
       2  * Copyright (c) 2010, 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 javafx.scene;
      27
      28 import java.net.MalformedURLException;
      29 import java.net.URL;
      30 import java.util.Locale;
      31 import javafx.scene.image.Image;
      32 import com.sun.javafx.cursor.CursorFrame;
      33 import com.sun.javafx.cursor.CursorType;
      34 import com.sun.javafx.cursor.StandardCursorFrame;
      35
      36 /**
      37  * A class to encapsulate the bitmap representation of the mouse cursor.
      38  * @since JavaFX 2.0
      39  */
      40 public abstract class Cursor {
      41     /**
      42      * The default cursor type (gets set if no cursor is defined).
      43      */
      44     public static final Cursor DEFAULT =
      45             new StandardCursor("DEFAULT", CursorType.DEFAULT);
      46
      47     /**
      48      * The crosshair cursor type.
      49      */
      50     public static final Cursor CROSSHAIR =
      51             new StandardCursor("CROSSHAIR", CursorType.CROSSHAIR);
      52
      53     /**
      54      * The text cursor type.
      55      */
      56     public static final Cursor TEXT =
      57             new StandardCursor("TEXT", CursorType.TEXT);
      58
      59     /**
      60      * The wait cursor type.
      61      */
      62     public static final Cursor WAIT =
      63             new StandardCursor("WAIT", CursorType.WAIT);
      64
      65     /**
      66      * The south-west-resize cursor type.
      67      */
      68     public static final Cursor SW_RESIZE =
      69             new StandardCursor("SW_RESIZE", CursorType.SW_RESIZE);
      70
      71     /**
      72      * The south-east-resize cursor type.
      73      */
      74     public static final Cursor SE_RESIZE =
      75             new StandardCursor("SE_RESIZE", CursorType.SE_RESIZE);
      76
      77     /**
      78      * The north-west-resize cursor type.
      79      */
      80     public static final Cursor NW_RESIZE =
      81             new StandardCursor("NW_RESIZE", CursorType.NW_RESIZE);
      82
      83     /**
      84      * The north-east-resize cursor type.
      85      */
      86     public static final Cursor NE_RESIZE =
      87             new StandardCursor("NE_RESIZE", CursorType.NE_RESIZE);
      88
      89     /**
      90      * The north-resize cursor type.
      91      */
      92     public static final Cursor N_RESIZE =
      93             new StandardCursor("N_RESIZE", CursorType.N_RESIZE);
      94
      95     /**
      96      * The south-resize cursor type.
      97      */
      98     public static final Cursor S_RESIZE =
      99             new StandardCursor("S_RESIZE", CursorType.S_RESIZE);
     100
     101     /**
     102      * The west-resize cursor type.
     103      */
     104     public static final Cursor W_RESIZE =
     105             new StandardCursor("W_RESIZE", CursorType.W_RESIZE);
     106
     107     /**
     108      * The east-resize cursor type.
     109      */
     110     public static final Cursor E_RESIZE =
     111             new StandardCursor("E_RESIZE", CursorType.E_RESIZE);
     112
     113     /**
     114      * A cursor with a hand which is open
     115      */
     116     public static final Cursor OPEN_HAND =
     117             new StandardCursor("OPEN_HAND", CursorType.OPEN_HAND);
     118
     119     /**
     120      * A cursor with a hand that is closed, often used when
     121      * "grabbing", for example, when panning.
     122      */
     123     public static final Cursor CLOSED_HAND =
     124             new StandardCursor("CLOSED_HAND", CursorType.CLOSED_HAND);
     125
     126     /**
     127      * The hand cursor type, resembling a pointing hand, often
     128      * used to indicate that something can be clicked, such as
     129      * a hyperlink.
     130      */
     131     public static final Cursor HAND =
     132             new StandardCursor("HAND", CursorType.HAND);
     133
     134     /**
     135      * The move cursor type.
     136      */
     137     public static final Cursor MOVE =
     138             new StandardCursor("MOVE", CursorType.MOVE);
     139
     140     /**
     141      * The disappear cursor type. This is often used when dragging
     142      * something, such that when the user releases the mouse, the
     143      * item will disappear. On Mac, this is used when dragging items
     144      * off a toolbar or in other such situations.
     145      */
     146     public static final Cursor DISAPPEAR =
     147             new StandardCursor("DISAPPEAR", CursorType.DISAPPEAR);
     148
     149     /**
     150      * The horizontal cursor type.
     151      */
     152     public static final Cursor H_RESIZE =
     153             new StandardCursor("H_RESIZE", CursorType.H_RESIZE);
     154
     155     /**
     156      * The vertical cursor type.
     157      */
     158     public static final Cursor V_RESIZE =
     159             new StandardCursor("V_RESIZE", CursorType.V_RESIZE);
     160
     161     /**
     162      * The none cursor type. On platforms that don't support
     163      * custom cursors, this will be the same as {@code DEFAULT}.
     164      */
     165     public static final Cursor NONE =
     166             new StandardCursor("NONE", CursorType.NONE);
     167
     168     private String name = "CUSTOM";
     169
     170     Cursor() { }
     171     Cursor(String name) {
     172         this.name = name;
     173     }
     174
     175     abstract CursorFrame getCurrentFrame();
     176
     177     /**
     178      * Activates the cursor. Cursor should be activated to make sure
     179      * that the {@code impl_getCurrentFrame} returns up-to date values.
     180      */
     181     void activate() {
     182         // no activation necessary for standard cursors
     183     }
     184
     185     /**
     186      * Deactivates the cursor. Cursor should be deactivated, when no longer in
     187      * use to make it collectible by GC.
     188      */
     189     void deactivate() {
     190     }
     191
     192     /**
     193      * Returns a string representation for the cursor.
     194      * @return a string representation for the cursor.
     195      */
     196     @Override public String toString() {
     197         return name;
     198     }
     199
     200     // PENDING_DOC_REVIEW
     201     /**
     202      * Returns a cursor for the specified identifier. The identifier can be
     203      * either a name of some standard cursor or a valid URL string. If the
     204      * identifier names a standard cursor the corresponding cursor is returned.
     205      * In the case of a URL string, the method returns a new {@code ImageCursor}
     206      * created for that URL.
     207      *
     208      * @param identifier the cursor identifier
     209      * @return the cursor for the identifier
     210      * @throws IllegalArgumentException if the cursor identifier is not a
     211      *      valid URL string nor any standard cursor name
     212      */
     213     public static Cursor cursor(final String identifier) {
     214         if (identifier == null) {
     215             throw new NullPointerException(
     216                     "The cursor identifier must not be null");
     217         }
     218
     219         if (isUrl(identifier)) {
     220             return new ImageCursor(new Image(identifier));
     221         }
     222
     223         String uName = identifier.toUpperCase(Locale.ROOT);
     224         if (uName.equals(DEFAULT.name)) {
     225             return DEFAULT;
     226         } else if(uName.equals(CROSSHAIR.name)) {
     227             return CROSSHAIR;
     228         } else if (uName.equals(TEXT.name)) {
     229             return TEXT;
     230         } else if (uName.equals(WAIT.name)) {
     231             return WAIT;
     232         } else if (uName.equals(MOVE.name)) {
     233             return MOVE;
     234         } else if (uName.equals(SW_RESIZE.name)) {
     235             return SW_RESIZE;
     236         } else if (uName.equals(SE_RESIZE.name)) {
     237             return SE_RESIZE;
     238         } else if (uName.equals(NW_RESIZE.name)) {
     239             return NW_RESIZE;
     240         } else if (uName.equals(NE_RESIZE.name)) {
     241             return NE_RESIZE;
     242         } else if (uName.equals(N_RESIZE.name)) {
     243             return N_RESIZE;
     244         } else if (uName.equals(S_RESIZE.name)) {
     245             return S_RESIZE;
     246         } else if (uName.equals(W_RESIZE.name)) {
     247             return W_RESIZE;
     248         } else if (uName.equals(E_RESIZE.name)) {
     249             return E_RESIZE;
     250         } else if (uName.equals(OPEN_HAND.name)) {
     251             return OPEN_HAND;
     252         } else if (uName.equals(CLOSED_HAND.name)) {
     253             return CLOSED_HAND;
     254         } else if (uName.equals(HAND.name)) {
     255             return HAND;
     256         } else if (uName.equals(H_RESIZE.name)) {
     257             return H_RESIZE;
     258         } else if (uName.equals(V_RESIZE.name)) {
     259             return V_RESIZE;
     260         } else if (uName.equals(DISAPPEAR.name)) {
     261             return DISAPPEAR;
     262         } else if (uName.equals(NONE.name)) {
     263             return NONE;
     264         }
     265
     266         throw new IllegalArgumentException("Invalid cursor specification");
     267     }
     268
     269     private static boolean isUrl(final String identifier) {
     270         try {
     271             new URL(identifier);
     272         } catch (final MalformedURLException e) {
     273             return false;
     274         }
     275
     276         return true;
     277     }
     278
     279     private static final class StandardCursor extends Cursor {
     280         private final CursorFrame singleFrame;
     281
     282         public StandardCursor(final String name, final CursorType type) {
     283             super(name);
     284             singleFrame = new StandardCursorFrame(type);
     285         }
     286
     287         @Override
     288         CursorFrame getCurrentFrame() {
     289             return singleFrame;
     290         }
     291     }
     292 }
    --- EOF ---