📄 converters.java
字号:
} public Object decode(String value, Object format) throws ConversionException { try { int radix = (format == null? 10 : ((Integer)format).intValue()); return Long.valueOf(value, radix); } catch (Exception e) { throw new ConversionException(value, Long.class, e); } } } /** * Converter for java.lang.Short. * The <code>format</code> parameter may either be an Integer object * representing the radix or null. If <code>format</code> is null, * a default radix of 10 is used. */ static class ShortConverter implements Converter { public String encode(Object value, Object format) throws ConversionException { try { // Short doesn't have toString(short value, int radix) method int shortValue = ( (Short) value).intValue(); int radix = (format == null ? 10 : ( (Integer) format).intValue()); return Integer.toString(shortValue, radix); } catch (Exception e) { throw new ConversionException(value, Short.class, e); } } public Object decode(String value, Object format) throws ConversionException { try { int radix = (format == null ? 10 : ( (Integer) format).intValue()); return Short.valueOf(value, radix); } catch (Exception e) { throw new ConversionException(value, Short.class, e); } } } /** * Converter for java.lang.Float. * The <code>format</code> parameter is ignored. */ static class FloatConverter implements Converter { public String encode(Object value, Object format) throws ConversionException { try { Float floatValue = (Float) value; return floatValue.toString(); } catch (Exception e) { throw new ConversionException(value, Float.class, e); } } public Object decode(String value, Object format) throws ConversionException { try { return Float.valueOf(value); } catch (Exception e) { throw new ConversionException(value, Float.class, e); } } } /** * Converter for java.lang.Double. * The <code>format</code> parameter is ignored. */ static class DoubleConverter implements Converter { public String encode(Object value, Object format) throws ConversionException { try { Double doubleValue = (Double) value; return doubleValue.toString(); } catch (Exception e) { throw new ConversionException(value, Double.class, e); } } public Object decode(String value, Object format) throws ConversionException { try { return Double.valueOf(value); } catch (Exception e) { throw new ConversionException(value, Double.class, e); } } } /** * Converter for java.util.Date. * The <code>format</code> parameter must be either an instance of * <code>DateFormat</code> or <code>null</code>. If <code>null</code> is * specified, the converter will use the default <code>SimpleDateFormat</code> * object, whose format defaults to "EEE MMM dd hh:mm:ss z yyyy". * * @see java.text.DateFormat * @see java.text.SimpleDateFormat */ public static class DateConverter implements Converter { private DateFormat defaultInputFormat; private DateFormat defaultOutputFormat; public DateConverter() { defaultInputFormat = defaultOutputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy"); } public DateConverter(DateFormat defaultInputFormat, DateFormat defaultOutputFormat) { this.defaultInputFormat = defaultInputFormat; this.defaultOutputFormat = defaultOutputFormat; } public String encode(Object value, Object format) throws ConversionException { try { DateFormat dateFormat = format == null ? defaultOutputFormat : (DateFormat) format; return dateFormat.format((Date)value); } catch (Exception e) { throw new ConversionException(value, Date.class, e); } } public Object decode(String value, Object format) throws ConversionException { try { DateFormat dateFormat = format == null? defaultInputFormat : (DateFormat)format; return dateFormat.parse(value); } catch (Exception e) { throw new ConversionException(value, Date.class, e); } } } /** * Converter for org.jdesktop.swing.Link. * Currently the <code>format</code> parameter is ignored and the conversion * uses the HTML href tag format to encode and decode the values:<br> * <pre> <a href="%HREF%" target="%TARGET%">%DISPLAYSTRING%</a> * </pre> */// static class LinkConverter implements Converter {// /** @todo aim: quick hack, reimplement with sax parser instead! *///// private static final String URL_BEGIN = "<a href=\"";// private static final String URL_MARKER = "%u";// private static final String URL_END = "\"";// private static final String TARGET_BEGIN = " target=\"";// private static final String TARGET_MARKER = "%t";// private static final String TARGET_END = "\"";// private static final String DISPLAY_BEGIN = ">";// private static final String DISPLAY_MARKER = "%d";// private static final String DISPLAY_END = "</a>";//// private static final String TEMPLATE =// URL_BEGIN + URL_MARKER + URL_END +// TARGET_BEGIN + TARGET_MARKER + TARGET_END +// DISPLAY_BEGIN + DISPLAY_MARKER + DISPLAY_END;//// private static final String TEMPLATE2 =// URL_BEGIN + URL_MARKER + URL_END +// DISPLAY_BEGIN + DISPLAY_MARKER + DISPLAY_END;//// public String encode(Object value, Object format)// throws ConversionException {// try {// LinkModel link = (LinkModel) value;// String linkString;// String target = link.getTarget();// if (target != null) {// linkString = TEMPLATE.replaceFirst(URL_MARKER,// link.getURL().toExternalForm());// linkString = linkString.replaceFirst(TARGET_MARKER,// target);// }// else {// linkString = TEMPLATE2.replaceFirst(URL_MARKER,// link.getURL().toExternalForm());// }// linkString = linkString.replaceFirst(DISPLAY_MARKER,// link.getText());//// return linkString;// }// catch (Exception e) {// throw new ConversionException(value, LinkModel.class, e);// }// }//// public Object decode(String value, Object format)// throws ConversionException {// try {// String url = value.substring(URL_BEGIN.length(),// value.indexOf(URL_END, URL_BEGIN.length() + 1));// String target = null;// int targetIndex = value.indexOf(TARGET_BEGIN);// if (targetIndex != -1) {// target = value.substring(targetIndex + TARGET_BEGIN.length(),// value.indexOf(TARGET_END,// targetIndex + TARGET_BEGIN.length() + 1));// }// String display = value.substring(value.indexOf(DISPLAY_BEGIN) +// DISPLAY_BEGIN.length(),// value.indexOf(DISPLAY_END));////// return new LinkModel(display, target, new URL(url));// }// catch (Exception e) {// throw new ConversionException(value, LinkModel.class, e);// }// }// }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -