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