001: /*
002: *******************************************************************************
003: * Copyright (C) 1997-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007: package com.ibm.icu.dev.demo.impl;
008:
009: import java.awt.*;
010: import java.util.*;
011:
012: public class DemoUtility {
013: public static final Font titleFont = new Font("TimesRoman",
014: Font.BOLD, 18);
015: public static final Font labelFont = new Font("TimesRoman",
016: Font.BOLD, 14);
017: public static final Font choiceFont = new Font("Helvetica",
018: Font.BOLD, 12);
019: public static final Font editFont = new Font("Helvetica",
020: Font.PLAIN, 14);
021: public static final Font creditFont = new Font("Helvetica",
022: Font.PLAIN, 10);
023: public static final Font numberFont = new Font("sansserif",
024: Font.PLAIN, 14);
025:
026: public static final Color bgColor = Color.lightGray;
027: public static final Color choiceColor = Color.white;
028:
029: public static final String copyright1 = "Copyright (C) IBM Corp and others. 1997 - 2002 All Rights Reserved";
030:
031: /**
032: Provides easy way to use basic functions of GridBagLayout, without
033: the complications. After building a panel, and inserting all the
034: * subcomponents, call this to lay it out in the desired number of columns.
035: */
036: public static void fixGrid(Container cont, int columns) {
037: GridBagLayout gridbag = new GridBagLayout();
038: cont.setLayout(gridbag);
039:
040: GridBagConstraints c = new GridBagConstraints();
041: c.fill = GridBagConstraints.VERTICAL;
042: c.weightx = 1.0;
043: c.insets = new Insets(2, 2, 2, 2);
044:
045: Component[] components = cont.getComponents();
046: for (int i = 0; i < components.length; ++i) {
047: // not used int colNumber = i%columns;
048: c.gridwidth = 1; // default
049: if ((i % columns) == columns - 1)
050: c.gridwidth = GridBagConstraints.REMAINDER; // last in grid
051: if (components[i] instanceof Label) {
052: switch (((Label) components[i]).getAlignment()) {
053: case Label.CENTER:
054: c.anchor = GridBagConstraints.CENTER;
055: break;
056: case Label.LEFT:
057: c.anchor = GridBagConstraints.WEST;
058: break;
059: case Label.RIGHT:
060: c.anchor = GridBagConstraints.EAST;
061: break;
062: }
063: }
064: gridbag.setConstraints(components[i], c);
065: }
066:
067: }
068:
069: /**
070: Provides easy way to change the spacing around an object in a GridBagLayout.
071: Call AFTER fixGridBag, passing in the container, the component, and the
072: new insets.
073: */
074: public static void setInsets(Container cont, Component comp,
075: Insets insets) {
076: GridBagLayout gbl = (GridBagLayout) cont.getLayout();
077: GridBagConstraints g = gbl.getConstraints(comp);
078: g.insets = insets;
079: gbl.setConstraints(comp, g);
080: }
081:
082: public static Panel createSpacer() {
083: Panel spacer = new Panel();
084: spacer.setLayout(null);
085: spacer.setSize(1000, 1);
086: return spacer;
087: }
088:
089: // to avoid goofy updates and misplaced cursors
090: public static void setText(TextComponent area, String newText) {
091: String foo = area.getText();
092: if (foo.equals(newText))
093: return;
094: area.setText(newText);
095: }
096:
097: /**
098: * Compares two locals. Return value is negative
099: * if they're different, and more positive the more
100: * fields that match.
101: */
102:
103: public static int compareLocales(Locale l1, Locale l2) {
104: int result = -1;
105:
106: if (l1.getLanguage().equals(l2.getLanguage())) {
107: result += 1;
108:
109: if (l1.getCountry().equals(l2.getCountry())) {
110: result += 1;
111:
112: if (l1.getVariant().equals(l2.getVariant())) {
113: result += 1;
114: }
115: }
116: }
117:
118: return result;
119: }
120:
121: /**
122: * Get the G7 locale list for demos.
123: */
124: public static Locale[] getG7Locales() {
125: return localeList;
126: }
127:
128: private static Locale[] localeList = { new Locale("DA", "DK", ""),
129: new Locale("EN", "US", ""), new Locale("EN", "GB", ""),
130: new Locale("EN", "CA", ""), new Locale("FR", "FR", ""),
131: new Locale("FR", "CA", ""), new Locale("DE", "DE", ""),
132: new Locale("IT", "IT", ""),
133: //new Locale("JA", "JP", ""),
134: };
135: }
|