@Override public String generateMaskedRow(String str) { if ((str == null || EMPTY_STRING.equals(str)) && keepNull) { return str; } else { CreditCardType cct_format = null; if (str == null || EMPTY_STRING.equals(str)) { cct_format = super.chooseCreditCardType(); return super.generateCreditCard(cct_format).toString(); } else { try { cct_format = super.getCreditCardType( Long.parseLong(str.replaceAll("\\s+", EMPTY_STRING))); // $NON-NLS-1$ } catch (NumberFormatException e) { cct_format = super.chooseCreditCardType(); return super.generateCreditCard(cct_format).toString(); } if (cct_format != null) { return super.generateCreditCardFormat(cct_format, str, keepFormat); } else { cct_format = super.chooseCreditCardType(); return super.generateCreditCard(cct_format).toString(); } } } }
@Override public String generateMaskedRow(String str) { StringBuilder sb = new StringBuilder(EMPTY_STRING); if ((str == null) || EMPTY_STRING.equals(str) && keepNull) { return str; } else { if (str != null && !EMPTY_STRING.equals(str) && !(" ").equals(str)) { // $NON-NLS-1$ String[] address = str.split(",| "); // $NON-NLS-1$ for (String tmp : address) { if (Arrays.asList(keys).contains(tmp)) { sb.append(tmp + " "); // $NON-NLS-1$ } else { for (int i = 0; i < tmp.length(); ++i) { if (Character.isDigit(tmp.charAt(i))) { sb.append(Character.forDigit(rnd.nextInt(9), 10)); } else { sb.append("X"); // $NON-NLS-1$ } } sb.append(" "); // $NON-NLS-1$ } } return sb.deleteCharAt(sb.length() - 1).toString(); } else { return EMPTY_STRING; } } }
/* * (non-Javadoc) * * @see * org.eclipse.nebula.widgets.gallery.AbstractGalleryItemRenderer#draw(org * .eclipse.swt.graphics.GC, org.eclipse.nebula.widgets.gallery.GalleryItem, * int, int, int, int, int) */ public void draw(GC gc, GalleryItem item, int index, int x, int y, int width, int height) { Image itemImage = item.getImage(); Color itemBackgroundColor = item.getBackground(); Color itemForegroundColor = item.getForeground(); int useableHeight = height; int imageWidth = 0; int imageHeight = 0; int xShift = 0; int yShift = 0; Point size = null; if (itemImage != null) { Rectangle itemImageBounds = itemImage.getBounds(); imageWidth = itemImageBounds.width; imageHeight = itemImageBounds.height; size = RendererHelper.getBestSize( imageWidth, imageHeight, useableHeight - 4 - this.dropShadowsSize, useableHeight - 4 - this.dropShadowsSize); xShift = ((useableHeight - size.x) >> 1) + 2; yShift = (useableHeight - size.y) >> 1; if (dropShadows) { Color c = null; for (int i = this.dropShadowsSize - 1; i >= 0; i--) { c = dropShadowsColors.get(i); gc.setForeground(c); gc.drawLine( x + useableHeight + i - xShift - 1, y + dropShadowsSize + yShift, x + useableHeight + i - xShift - 1, y + useableHeight + i - yShift); gc.drawLine( x + xShift + dropShadowsSize, y + useableHeight + i - yShift - 1, x + useableHeight + i - xShift, y - 1 + useableHeight + i - yShift); } } } // Draw selection background (rounded rectangles) if (selected || RendererHelper.isColorsEquals(itemBackgroundColor, gallery.getBackground())) { if (selected) { gc.setBackground(selectionBackgroundColor); gc.setForeground(selectionBackgroundColor); } else if (itemBackgroundColor != null) { gc.setBackground(itemBackgroundColor); } if (showRoundedSelectionCorners) gc.fillRoundRectangle(x, y, width, useableHeight, selectionRadius, selectionRadius); else gc.fillRectangle(x, y, width, useableHeight); } if (itemImage != null && size != null) { if (size.x > 0 && size.y > 0) { gc.drawImage( itemImage, 0, 0, imageWidth, imageHeight, x + xShift, y + yShift, size.x, size.y); drawAllOverlays(gc, item, x, y, size, xShift, yShift); } } if (item.getText() != null && !EMPTY_STRING.equals(item.getText()) && showLabels) { // Calculate font height (text and description) gc.setFont(textFont); String text = RendererHelper.createLabel(item.getText(), gc, width - useableHeight - 10); int textFontHeight = gc.getFontMetrics().getHeight(); String description = null; int descriptionFontHeight = 0; if (item.getText(1) != null && !EMPTY_STRING.equals(item.getText(1))) { gc.setFont(descriptionFont); description = RendererHelper.createLabel(item.getText(1), gc, width - useableHeight - 10); descriptionFontHeight = gc.getFontMetrics().getHeight(); } boolean displayText = false; boolean displayDescription = false; int remainingHeight = height - 2 - textFontHeight; if (remainingHeight > 0) displayText = true; remainingHeight -= descriptionFontHeight; if (remainingHeight > 0) displayDescription = true; // Background color gc.setBackground(selected ? selectionBackgroundColor : backgroundColor); // Draw text if (displayText) { int transY = (height - textFontHeight - 2); if (displayDescription) transY -= descriptionFontHeight; transY = transY >> 1; if (selected) { gc.setForeground(this.selectionForegroundColor); } else if (itemForegroundColor != null) { gc.setForeground(itemForegroundColor); } else { gc.setForeground(this.foregroundColor); } gc.setFont(textFont); gc.drawText(text, x + useableHeight + 5, y + transY, true); } // Draw description if (description != null && displayDescription) { gc.setForeground(this.descriptionColor); gc.setFont(descriptionFont); gc.drawText( description, x + useableHeight + 5, y + ((height - descriptionFontHeight - textFontHeight - 2) >> 1) + textFontHeight + 1, true); } } }