public edu.cmu.cs.dennisc.java.util.zip.DataSource[] getDataSources() { edu.cmu.cs.dennisc.java.util.zip.DataSource[] dataSources; try { final java.awt.image.BufferedImage thumbnailImage = createThumbnail(); if (thumbnailImage != null) { if ((thumbnailImage.getWidth() > 0) && (thumbnailImage.getHeight() > 0)) { // pass } else { throw new RuntimeException(); } } else { throw new NullPointerException(); } final byte[] data = edu.cmu.cs.dennisc.image.ImageUtilities.writeToByteArray( edu.cmu.cs.dennisc.image.ImageUtilities.PNG_CODEC_NAME, thumbnailImage); // <lg> java.util.List<edu.cmu.cs.dennisc.java.util.zip.DataSource> dataSourcesList = edu.cmu.cs.dennisc.java.util.Lists.newArrayList(); edu.cmu.cs.dennisc.java.util.zip.DataSource thumbnailData = new edu.cmu.cs.dennisc.java.util.zip.DataSource() { @Override public String getName() { return "thumbnail.png"; } @Override public void write(java.io.OutputStream os) throws java.io.IOException { os.write(data); } }; dataSourcesList.add(thumbnailData); edu.cmu.cs.dennisc.java.util.zip.DataSource originalTypeData = getOriginalProgramTypeDataSource(); if (originalTypeData != null) { dataSourcesList.add(originalTypeData); } edu.cmu.cs.dennisc.java.util.zip.DataSource originalVersionData = getOriginalVersionDataSource(); if (originalVersionData != null) { dataSourcesList.add(originalVersionData); } dataSources = edu.cmu.cs.dennisc.java.lang.ArrayUtilities.createArray( dataSourcesList, edu.cmu.cs.dennisc.java.util.zip.DataSource.class); // </lg> } catch (Throwable t) { dataSources = new edu.cmu.cs.dennisc.java.util.zip.DataSource[] {}; } return dataSources; }
@Override protected javax.swing.JLabel updateLabel(javax.swing.JLabel rv, Object value) { java.net.URI uri = (java.net.URI) value; String text; javax.swing.Icon icon; if (uri != null) { if (uri.isAbsolute()) { boolean isExtensionDesired; if ("file".equals(uri.getScheme())) { isExtensionDesired = true; } else { uri = org.alice.ide.uricontent.StarterProjectUtilities.toFileUriFromStarterUri(uri); isExtensionDesired = false; } java.io.File file = new java.io.File(uri); text = file.getName(); if (isExtensionDesired) { // pass } else { final String SUFFIX = ".a3p"; if (text.endsWith(SUFFIX)) { text = text.substring(0, text.length() - SUFFIX.length()); } } if (file.exists()) { // //todo: remove // String path = edu.cmu.cs.dennisc.java.io.FileUtilities.getCanonicalPathIfPossible( // file ); // if( path != null ) { // String snapshotPath = path.substring( 0, path.length() - 3 ) + "png"; // if( edu.cmu.cs.dennisc.java.io.FileUtilities.existsAndHasLengthGreaterThanZero( // snapshotPath ) ) { // icon = new javax.swing.ImageIcon( snapshotPath ); // } else { // icon = null; // } // } else { // icon = null; // } // // if( icon != null ) { // //pass // } else { try { java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(file); java.util.zip.ZipEntry zipEntry = zipFile.getEntry("thumbnail.png"); if (zipEntry != null) { java.io.InputStream is = zipFile.getInputStream(zipEntry); java.awt.Image image = edu.cmu.cs.dennisc.image.ImageUtilities.read( edu.cmu.cs.dennisc.image.ImageUtilities.PNG_CODEC_NAME, is); icon = new SnapshotIcon(image); } else { icon = SNAPSHOT_NOT_AVAILABLE_ICON; } zipFile.close(); } catch (Throwable t) { icon = SNAPSHOT_NOT_AVAILABLE_ICON; } // } } else { icon = FILE_DOES_NOT_EXIST_ICON; } } else { text = uri.toString(); icon = FILE_DOES_NOT_EXIST_ICON; } } else { text = null; icon = FILE_DOES_NOT_EXIST_ICON; } rv.setText(text); rv.setIcon(icon); return rv; }