Here you can find the source of formatPartialName(String name, int numberOfCharacters)
Parameter | Description |
---|---|
name | The name of handle. |
numberOfCharacters | The number of characters. |
public static String formatPartialName(String name, int numberOfCharacters)
//package com.java2s; /*/*from w w w . j a v a 2s. c o m*/ * org.openmicroscopy.shoola.util.ui.UIUtilities * *------------------------------------------------------------------------------ * Copyright (C) 2006-2015 University of Dundee. All rights reserved. * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * *------------------------------------------------------------------------------ */ public class Main { /** The default number of characters for the partial name.*/ public static final int DEFAULT_NUMBER_OF_CHARACTERS = 30; /** * The string displayed before an item name if the name has been * truncated. */ public static final String DOTS = "..."; /** * Displays the end of the name if the name is longer that the number * of specified characters. * * @param name The name of handle. * @param numberOfCharacters The number of characters. * @return See above. */ public static String formatPartialName(String name, int numberOfCharacters) { if (name == null) return null; int n = DOTS.length() + numberOfCharacters; int m = name.length(); if (m <= n) return name; StringBuffer buffer = new StringBuffer(); buffer.append(DOTS); buffer.append(name.substring(m - n, m)); return buffer.toString(); } /** * Displays the end of the name if the name is longer that the number * of specified characters. * * @param name The name of handle. * @return See above. */ public static String formatPartialName(String name) { return formatPartialName(name, DEFAULT_NUMBER_OF_CHARACTERS); } }