1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2008 - INRIA - Vincent Couvert
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 package org.scilab.modules.gui.utils;
17 
18 import javax.swing.SwingConstants;
19 
20 /**
21  * Alignment property values for Scilab Uicontrols
22  * @author Vincent COUVERT
23  */
24 public final class ScilabAlignment {
25 
26     /**
27      * Left horizontal alignment
28      */
29     public static final String LEFT = "left";
30 
31     /**
32      * Center horizontal alignment
33      */
34     public static final String CENTER = "center";
35 
36     /**
37      * Right horizontal alignment
38      */
39     public static final String RIGHT = "right";
40 
41     /**
42      * Top vertical alignment
43      */
44     public static final String TOP = "top";
45 
46     /**
47      * Middle vertical alignment
48      */
49     public static final String MIDDLE = "middle";
50 
51     /**
52      * Bottom vertical alignment
53      */
54     public static final String BOTTOM = "bottom";
55 
56     /**
57      * Constructor
58      */
ScilabAlignment()59     private ScilabAlignment() {
60         /* Should not be used */
61         throw new UnsupportedOperationException();
62     }
63 
64     /**
65      * Convert the Scilab string value for alignment to Swing value
66      * @param alignment the Scilab value for alignment
67      * @return the Swing value
68      */
toSwingAlignment(String alignment)69     public static int toSwingAlignment(String alignment) {
70         int returnValue = SwingConstants.CENTER;
71 
72         if (alignment.equals(LEFT)) {
73             returnValue = SwingConstants.LEFT;
74         } else if (alignment.equals(RIGHT)) {
75             returnValue = SwingConstants.RIGHT;
76         } else if (alignment.equals(TOP)) {
77             returnValue = SwingConstants.TOP;
78         } else if (alignment.equals(BOTTOM)) {
79             returnValue = SwingConstants.BOTTOM;
80         }
81 
82         return returnValue;
83     }
84 }
85