summaryrefslogtreecommitdiff
path: root/propertysheet/src/org/eclipse/wb/internal/core/nls/ui/LocaleUtils.java
blob: 699bba8c155403d500e639e85734b36b3582cbfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*******************************************************************************
 * Copyright (c) 2011 Google, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Google, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.wb.internal.core.nls.ui;

import org.eclipse.wb.internal.core.nls.model.LocaleInfo;

import org.eclipse.swt.graphics.Image;

import java.util.Arrays;
import java.util.Comparator;

/**
 * UI utils for {@link LocaleInfo}.
 * 
 * @author scheglov_ke
 * @coverage core.nls.ui
 */
public class LocaleUtils {
  ////////////////////////////////////////////////////////////////////////////
  //
  // Constructor
  //
  ////////////////////////////////////////////////////////////////////////////
  private LocaleUtils() {
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // Utils
  //
  ////////////////////////////////////////////////////////////////////////////
  /**
   * @return the flag image for given {@link LocaleInfo}.
   */
  public static Image getImage(LocaleInfo localeInfo) {
    if (localeInfo.isDefault()) {
      return FlagImagesRepository.getEmptyFlagImage();
    } else {
      return FlagImagesRepository.getFlagImage(localeInfo.getLocale());
    }
  }

  /**
   * Sorts given array of {@link LocaleInfo}'s by title.
   */
  public static void sortByTitle(LocaleInfo locales[]) {
    Arrays.sort(locales, new Comparator<LocaleInfo>() {
      public int compare(LocaleInfo locale_1, LocaleInfo locale_2) {
        return locale_1.getTitle().compareTo(locale_2.getTitle());
      }
    });
  }
}