< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java

Print this page
rev 10947 : 8055723: Replace concat String to append in StringBuilder parameters


2213                         cols[counter] = counter;
2214                     }
2215                 } else {
2216                     cols = table.getSelectedColumns();
2217                 }
2218 
2219                 if (rows == null || cols == null || rows.length == 0 || cols.length == 0) {
2220                     return null;
2221                 }
2222 
2223                 StringBuilder plainStr = new StringBuilder();
2224                 StringBuilder htmlStr = new StringBuilder();
2225 
2226                 htmlStr.append("<html>\n<body>\n<table>\n");
2227 
2228                 for (int row = 0; row < rows.length; row++) {
2229                     htmlStr.append("<tr>\n");
2230                     for (int col = 0; col < cols.length; col++) {
2231                         Object obj = table.getValueAt(rows[row], cols[col]);
2232                         String val = ((obj == null) ? "" : obj.toString());
2233                         plainStr.append(val + "\t");
2234                         htmlStr.append("  <td>" + val + "</td>\n");
2235                     }
2236                     // we want a newline at the end of each line and not a tab
2237                     plainStr.deleteCharAt(plainStr.length() - 1).append("\n");
2238                     htmlStr.append("</tr>\n");
2239                 }
2240 
2241                 // remove the last newline
2242                 plainStr.deleteCharAt(plainStr.length() - 1);
2243                 htmlStr.append("</table>\n</body>\n</html>");
2244 
2245                 return new BasicTransferable(plainStr.toString(), htmlStr.toString());
2246             }
2247 
2248             return null;
2249         }
2250 
2251         public int getSourceActions(JComponent c) {
2252             return COPY;
2253         }
2254 
2255     }
2256 }  // End of Class BasicTableUI


2213                         cols[counter] = counter;
2214                     }
2215                 } else {
2216                     cols = table.getSelectedColumns();
2217                 }
2218 
2219                 if (rows == null || cols == null || rows.length == 0 || cols.length == 0) {
2220                     return null;
2221                 }
2222 
2223                 StringBuilder plainStr = new StringBuilder();
2224                 StringBuilder htmlStr = new StringBuilder();
2225 
2226                 htmlStr.append("<html>\n<body>\n<table>\n");
2227 
2228                 for (int row = 0; row < rows.length; row++) {
2229                     htmlStr.append("<tr>\n");
2230                     for (int col = 0; col < cols.length; col++) {
2231                         Object obj = table.getValueAt(rows[row], cols[col]);
2232                         String val = ((obj == null) ? "" : obj.toString());
2233                         plainStr.append(val).append('\t');
2234                         htmlStr.append("  <td>").append(val).append("</td>\n");
2235                     }
2236                     // we want a newline at the end of each line and not a tab
2237                     plainStr.deleteCharAt(plainStr.length() - 1).append('\n');
2238                     htmlStr.append("</tr>\n");
2239                 }
2240 
2241                 // remove the last newline
2242                 plainStr.deleteCharAt(plainStr.length() - 1);
2243                 htmlStr.append("</table>\n</body>\n</html>");
2244 
2245                 return new BasicTransferable(plainStr.toString(), htmlStr.toString());
2246             }
2247 
2248             return null;
2249         }
2250 
2251         public int getSourceActions(JComponent c) {
2252             return COPY;
2253         }
2254 
2255     }
2256 }  // End of Class BasicTableUI
< prev index next >