]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/demos/src/com/ibm/icu/dev/demo/impl/DemoUtility.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / demos / src / com / ibm / icu / dev / demo / impl / DemoUtility.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 1997-2010, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.dev.demo.impl;
8
9 import java.awt.Color;
10 import java.awt.Component;
11 import java.awt.Container;
12 import java.awt.Font;
13 import java.awt.GridBagConstraints;
14 import java.awt.GridBagLayout;
15 import java.awt.Insets;
16 import java.awt.Label;
17 import java.awt.Panel;
18 import java.awt.TextComponent;
19 import java.util.Locale;
20
21 public class DemoUtility
22 {
23     public static final Font titleFont = new Font("TimesRoman",Font.BOLD,18);
24     public static final Font labelFont = new Font("TimesRoman",Font.BOLD,14);
25     public static final Font choiceFont = new Font("Helvetica",Font.BOLD,12);
26     public static final Font editFont = new Font("Helvetica",Font.PLAIN,14);
27     public static final Font creditFont = new Font("Helvetica",Font.PLAIN,10);
28     public static final Font numberFont = new Font("sansserif", Font.PLAIN, 14);
29
30     public static final Color bgColor = Color.lightGray;
31     public static final Color choiceColor = Color.white;
32
33     public static final String copyright1 =
34         "Copyright (C) IBM Corp and others. 1997 - 2002 All Rights Reserved";
35
36     /**
37     Provides easy way to use basic functions of GridBagLayout, without
38     the complications. After building a panel, and inserting all the
39     * subcomponents, call this to lay it out in the desired number of columns.
40     */
41     public static void fixGrid(Container cont, int columns) {
42         GridBagLayout gridbag = new GridBagLayout();
43         cont.setLayout(gridbag);
44
45         GridBagConstraints c = new GridBagConstraints();
46         c.fill = GridBagConstraints.VERTICAL;
47         c.weightx = 1.0;
48         c.insets = new Insets(2,2,2,2);
49
50         Component[] components = cont.getComponents();
51         for (int i = 0; i < components.length; ++i) {
52             // not used int colNumber = i%columns;
53             c.gridwidth = 1;    // default
54             if ((i%columns) == columns - 1)
55                 c.gridwidth = GridBagConstraints.REMAINDER;    // last in grid
56             if (components[i] instanceof Label) {
57                 switch (((Label)components[i]).getAlignment()) {
58                 case Label.CENTER: c.anchor = GridBagConstraints.CENTER; break;
59                 case Label.LEFT: c.anchor = GridBagConstraints.WEST; break;
60                 case Label.RIGHT: c.anchor = GridBagConstraints.EAST; break;
61                 }
62             }
63             gridbag.setConstraints(components[i], c);
64         }
65
66     }
67
68     /**
69     Provides easy way to change the spacing around an object in a GridBagLayout.
70     Call AFTER fixGridBag, passing in the container, the component, and the
71     new insets.
72     */
73     public static void setInsets(Container cont, Component comp, Insets insets) {
74         GridBagLayout gbl = (GridBagLayout)cont.getLayout();
75         GridBagConstraints g = gbl.getConstraints(comp);
76         g.insets = insets;
77         gbl.setConstraints(comp,g);
78     }
79
80     public static Panel createSpacer() {
81         Panel spacer = new Panel();
82         spacer.setLayout(null);
83         spacer.setSize(1000, 1);
84         return spacer;
85     }
86
87     // to avoid goofy updates and misplaced cursors
88     public static void setText(TextComponent area, String newText) {
89         String foo = area.getText();
90         if (foo.equals(newText)) return;
91         area.setText(newText);
92     }
93     
94     /**
95      * Compares two locals. Return value is negative
96      * if they're different, and more positive the more
97      * fields that match.
98      */
99      
100     public static int compareLocales(Locale l1, Locale l2)
101     {
102         int result = -1;
103         
104         if (l1.getLanguage().equals(l2.getLanguage())) {
105             result += 1;
106             
107             if (l1.getCountry().equals(l2.getCountry())) {
108                 result += 1;
109                 
110                 if (l1.getVariant().equals(l2.getVariant())) {
111                     result += 1;
112                 }
113             }
114         }
115         
116         return result;
117     }
118     
119     /**
120      * Get the G7 locale list for demos.
121      */
122     public static Locale[] getG7Locales() {
123         return localeList;
124     }
125     private static Locale[] localeList = {
126         new Locale("DA", "DK", ""),
127         new Locale("EN", "US", ""),
128         new Locale("EN", "GB", ""),
129         new Locale("EN", "CA", ""),
130         new Locale("FR", "FR", ""),
131         new Locale("FR", "CA", ""),
132         new Locale("DE", "DE", ""),
133         new Locale("IT", "IT", ""),
134     //new Locale("JA", "JP", ""),
135     };
136 }