Example usage for org.apache.commons.lang3 StringUtils abbreviate

List of usage examples for org.apache.commons.lang3 StringUtils abbreviate

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils abbreviate.

Prototype

public static String abbreviate(final String str, final int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:org.optaplanner.examples.rocktour.swingui.RockTourWorldPanel.java

public void resetPanel(RockTourSolution solution) {
    translator = new LatitudeLongitudeTranslator();
    RockBus bus = solution.getBus();/*from w  w w  .  j  av a  2  s . c  om*/
    translator.addCoordinates(bus.getStartLocation().getLatitude(), bus.getStartLocation().getLongitude());
    translator.addCoordinates(bus.getEndLocation().getLatitude(), bus.getEndLocation().getLongitude());
    for (RockShow show : solution.getShowList()) {
        translator.addCoordinates(show.getLocation().getLatitude(), show.getLocation().getLongitude());
    }

    Dimension size = getSize();
    double width = size.getWidth();
    double height = size.getHeight();
    translator.prepareFor(width, height);

    Graphics2D g = createCanvas(width, height);
    g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
    List<RockShow> showList = solution.getShowList();
    int maxAvailableDateSetSize = showList.stream().mapToInt(show -> show.getAvailableDateSet().size()).max()
            .orElse(-1);
    for (RockShow show : showList) {
        RockLocation location = show.getLocation();
        int x = translator.translateLongitudeToX(location.getLongitude());
        int y = translator.translateLatitudeToY(location.getLatitude());
        double percentage = (double) show.getAvailableDateSet().size() / maxAvailableDateSetSize;
        g.setColor(TangoColorFactory.buildPercentageColor(TangoColorFactory.PLUM_3, TangoColorFactory.PLUM_1,
                percentage));
        g.fillRect(x - 1, y - 1, 3, 3);
        if (location.getCityName() != null && showList.size() <= 500) {
            g.drawString(StringUtils.abbreviate(location.getCityName(), 20), x + 3, y - 3);
        }
        if (show.getDate() != null) {
            g.drawString(DAY_FORMATTER.format(show.getDate()), x + 3, y - 3 + LOCATION_NAME_TEXT_SIZE * 3 / 2);
        }
    }
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    RockLocation busStartLocation = bus.getStartLocation();
    int domicileX = translator.translateLongitudeToX(busStartLocation.getLongitude());
    int domicileY = translator.translateLatitudeToY(busStartLocation.getLatitude());
    g.fillRect(domicileX - 2, domicileY - 2, 5, 5);
    if (busStartLocation.getCityName() != null && showList.size() <= 500) {
        g.drawString(busStartLocation.getCityName(), domicileX + 3, domicileY - 3);
    }
    Set<RockShow> needsBackToDomicileLineSet = new HashSet<>(showList);
    for (RockShow trailingShow : showList) {
        if (trailingShow.getPreviousStandstill() instanceof RockShow) {
            needsBackToDomicileLineSet.remove(trailingShow.getPreviousStandstill());
        }
    }
    g.setColor(TangoColorFactory.CHOCOLATE_1);
    for (RockShow show : showList) {
        if (show.getPreviousStandstill() != null) {
            RockLocation previousLocation = show.getPreviousStandstill().getDepartureLocation();
            RockLocation location = show.getLocation();
            translator.drawRoute(g, previousLocation.getLongitude(), previousLocation.getLatitude(),
                    location.getLongitude(), location.getLatitude(), true, false);
            // Back to bus line
            if (needsBackToDomicileLineSet.contains(show)) {
                translator.drawRoute(g, location.getLongitude(), location.getLatitude(),
                        busStartLocation.getLongitude(), busStartLocation.getLatitude(), true, true);
            }
        }
    }
    g.setFont(g.getFont().deriveFont((float) TEXT_SIZE));
    // Legend
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    g.fillRect(5, (int) height - 17 - TEXT_SIZE, 5, 5);
    g.drawString("Bus start", 15, (int) height - 10 - TEXT_SIZE);
    g.setColor(TangoColorFactory.PLUM_2);
    g.fillRect(6, (int) height - 11, 3, 3);
    g.drawString("Show (darker means less available)", 15, (int) height - 5);
    repaint();
}

From source file:org.optaplanner.examples.tsp.swingui.TspWorldPanel.java

public void resetPanel(TravelingSalesmanTour travelingSalesmanTour) {
    translator = new LatitudeLongitudeTranslator();
    for (Location location : travelingSalesmanTour.getLocationList()) {
        translator.addCoordinates(location.getLatitude(), location.getLongitude());
    }//from  w w w  . ja va  2s  .  c  o m

    Dimension size = getSize();
    double width = size.getWidth();
    double height = size.getHeight();
    translator.prepareFor(width, height);

    Graphics2D g = createCanvas(width, height);
    String tourName = travelingSalesmanTour.getName();
    if (tourName.startsWith("europe")) {
        g.drawImage(europaBackground.getImage(), 0, 0, translator.getImageWidth(), translator.getImageHeight(),
                this);
    }
    g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
    g.setColor(TangoColorFactory.PLUM_2);
    List<Visit> visitList = travelingSalesmanTour.getVisitList();
    for (Visit visit : visitList) {
        Location location = visit.getLocation();
        int x = translator.translateLongitudeToX(location.getLongitude());
        int y = translator.translateLatitudeToY(location.getLatitude());
        g.fillRect(x - 1, y - 1, 3, 3);
        if (location.getName() != null && visitList.size() <= 500) {
            g.drawString(StringUtils.abbreviate(location.getName(), 20), x + 3, y - 3);
        }
    }
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    Domicile domicile = travelingSalesmanTour.getDomicile();
    Location domicileLocation = domicile.getLocation();
    int domicileX = translator.translateLongitudeToX(domicileLocation.getLongitude());
    int domicileY = translator.translateLatitudeToY(domicileLocation.getLatitude());
    g.fillRect(domicileX - 2, domicileY - 2, 5, 5);
    if (domicileLocation.getName() != null && visitList.size() <= 500) {
        g.drawString(domicileLocation.getName(), domicileX + 3, domicileY - 3);
    }
    Set<Visit> needsBackToDomicileLineSet = new HashSet<Visit>(visitList);
    for (Visit trailingVisit : visitList) {
        if (trailingVisit.getPreviousStandstill() instanceof Visit) {
            needsBackToDomicileLineSet.remove(trailingVisit.getPreviousStandstill());
        }
    }
    g.setColor(TangoColorFactory.CHOCOLATE_1);
    for (Visit visit : visitList) {
        if (visit.getPreviousStandstill() != null) {
            Location previousLocation = visit.getPreviousStandstill().getLocation();
            Location location = visit.getLocation();
            translator.drawRoute(g, previousLocation.getLongitude(), previousLocation.getLatitude(),
                    location.getLongitude(), location.getLatitude(), location instanceof AirLocation, false);
            // Back to domicile line
            if (needsBackToDomicileLineSet.contains(visit)) {
                translator.drawRoute(g, location.getLongitude(), location.getLatitude(),
                        domicileLocation.getLongitude(), domicileLocation.getLatitude(),
                        location instanceof AirLocation, true);
            }
        }
    }
    // Drag
    if (dragSourceStandstill != null) {
        g.setColor(TangoColorFactory.CHOCOLATE_2);
        Location sourceLocation = dragSourceStandstill.getLocation();
        Location targetLocation = dragTargetStandstill.getLocation();
        translator.drawRoute(g, sourceLocation.getLongitude(), sourceLocation.getLatitude(),
                targetLocation.getLongitude(), targetLocation.getLatitude(),
                sourceLocation instanceof AirLocation, dragTargetStandstill instanceof Domicile);
    }
    // Legend
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    g.fillRect(5, (int) height - 15 - TEXT_SIZE, 5, 5);
    g.drawString("Domicile", 15, (int) height - 10 - TEXT_SIZE);
    g.setColor(TangoColorFactory.PLUM_2);
    g.fillRect(6, (int) height - 9, 3, 3);
    g.drawString("Visit", 15, (int) height - 5);
    g.setColor(TangoColorFactory.ALUMINIUM_5);
    String locationsSizeString = travelingSalesmanTour.getLocationList().size() + " locations";
    g.drawString(locationsSizeString, ((int) width - g.getFontMetrics().stringWidth(locationsSizeString)) / 2,
            (int) height - 5);
    if (travelingSalesmanTour.getDistanceType() == DistanceType.AIR_DISTANCE) {
        String leftClickString = "Left click and drag between 2 locations to connect them.";
        g.drawString(leftClickString, (int) width - 5 - g.getFontMetrics().stringWidth(leftClickString),
                (int) height - 10 - TEXT_SIZE);
        String rightClickString = "Right click anywhere on the map to add a visit.";
        g.drawString(rightClickString, (int) width - 5 - g.getFontMetrics().stringWidth(rightClickString),
                (int) height - 5);
    }
    // Show soft score
    g.setColor(TangoColorFactory.ORANGE_3);
    SimpleLongScore score = travelingSalesmanTour.getScore();
    if (score != null) {
        String distanceString = travelingSalesmanTour.getDistanceString(NUMBER_FORMAT);
        g.setFont(g.getFont().deriveFont(Font.BOLD, (float) TEXT_SIZE * 2));
        g.drawString(distanceString, (int) width - g.getFontMetrics().stringWidth(distanceString) - 10,
                (int) height - 15 - 2 * TEXT_SIZE);
    }
    repaint();
}

From source file:org.ownchan.server.persistence.model.DbCloudLabel.java

@Override
public void setStatus(CloudLabelStatus status, String statusReason) {
    this.status = status;
    this.statusReason = StringUtils.abbreviate(statusReason, MAX_LENGTH_STATUS_REASON);
}

From source file:org.ownchan.server.persistence.model.DbContent.java

@Override
public void setStatus(ContentStatus status, String statusReason) {
    this.status = status;
    this.statusReason = StringUtils.abbreviate(statusReason, MAX_LENGTH_STATUS_REASON);
}

From source file:org.ownchan.server.persistence.model.DbContentAbuse.java

@Override
public void setStatus(ContentAbuseStatus status, String statusReason) {
    this.status = status;
    this.statusReason = StringUtils.abbreviate(statusReason, MAX_LENGTH_STATUS_REASON);
}

From source file:org.ownchan.server.persistence.model.DbPhysicalContent.java

@Override
public void setStatus(PhysicalContentStatus status, String statusReason) {
    this.status = status;
    this.statusReason = StringUtils.abbreviate(statusReason, MAX_LENGTH_STATUS_REASON);
}

From source file:org.ownchan.server.persistence.model.DbUser.java

@Override
public void setStatus(UserStatus status, String statusReason) {
    this.status = status;
    this.statusReason = StringUtils.abbreviate(statusReason, MAX_LENGTH_STATUS_REASON);
}

From source file:org.pesc.sdk.message.transcriptrequest.v1_4.TranscriptRequestValidator.java

/**
 * Create strict SourceDestinationType from relaxed SourceDestinationType.  Strict means that it will pass xsd validation.  Relaxed means that it doesn't need to pass xsd validation.
 * If relaxedOrganizationName is longer than 60 it will be abbreviated to 57 characters + '...'.  If relaxedOrganizationName is null or empty string strictOrganizationName will be null.
 * If relaxedCeeb is less than 6 characters it will be left padded.  If relaxedCeeb is more then 6 characters strictCeeb will be null.
 * @param relaxedSourceDestination/*  w  ww.  ja  v a 2 s .c o m*/
 * @return
 */
public static SourceDestinationType relaxedToStrictSourceDestination(
        SourceDestinationType relaxedSourceDestination) {
    SourceDestinationType strictSourceDestination = academicRecordObjectFactory.createSourceDestinationType();
    String organizationName = null;//1-60 characters
    String ceeb = null;//6 characters

    if (relaxedSourceDestination != null) {
        OrganizationType relaxedOrganization = relaxedSourceDestination.getOrganization();
        if (relaxedOrganization != null) {
            List<String> relaxedOrganizationNames = relaxedOrganization.getOrganizationNames();
            if (relaxedOrganizationNames.size() > 0) {
                String name = relaxedOrganizationNames.get(0);
                if (name != null && name.length() > 1) {
                    organizationName = StringUtils.abbreviate(name, 60);//limit to 60 characters
                }
            }
            String relaxedCeeb = relaxedOrganization.getCEEBACT();
            if (relaxedCeeb != null && relaxedCeeb.length() < 7) {
                ceeb = StringUtils.leftPad(relaxedCeeb, 6, '0');
            }
        }
    }
    OrganizationType organization = academicRecordObjectFactory.createOrganizationType();
    organization.getOrganizationNames().add(organizationName);
    organization.setCEEBACT(ceeb);
    strictSourceDestination.setOrganization(organization);
    return strictSourceDestination;
}

From source file:org.pesc.sdk.message.transcriptrequest.v1_4.TranscriptRequestValidator.java

/**
 * If relaxedRequestTrackingId is longer than 35 it will be abbreviated to 32 characters + '...'.
 * If relaxedRequestTrackingId is null or empty string strictRequestTrackingId will be null.
 * minLength 1//from  www .  j  ava 2s.co  m
 * maxLength 35
 * @param relaxedRequestTrackingId
 * @return
 */
public static String relaxedToStrictRequestTrackingId(String relaxedRequestTrackingId) {
    String strictRequestTrackingId = null;
    if (relaxedRequestTrackingId != null && relaxedRequestTrackingId.length() > 1) {
        strictRequestTrackingId = StringUtils.abbreviate(relaxedRequestTrackingId, 35);
    }
    return strictRequestTrackingId;
}

From source file:org.polymap.p4.P4Panel.java

public static String title(String type, String name) {
    return StringUtils.abbreviate(Joiner.on(": ").skipNulls().join(type, name), 32);
}