@Override public void save() { try { PrintWriter writer = new PrintWriter(file, "UTF-8"); for (HSB each : data) { writer.println(each.serialize()); } writer.close(); } catch (Exception e) { e.printStackTrace(); } }
/** * Generates an image for frame-image. * * @param backgroundColor background color. * @return An image data for frame. */ public ImageData create(HSB backgroundColor) { ImageData source = CoreImages.getImageDescriptor(CoreImages.FRAME).getImageData(); List<RGB> newRGBs = new ArrayList<RGB>(); for (RGB each : source.palette.colors) { try { HSB copy = backgroundColor.getCopy(); HSB hsb = new HSB(each); copy.brightness = hsb.brightness; copy = copy.mixWith(backgroundColor, 0.6f); newRGBs.add(copy.toRGB()); } catch (Exception e) { e.printStackTrace(); } } source.palette.colors = newRGBs.toArray(new RGB[newRGBs.size()]); return source; }
/** * @param height The height of drag handle to generate. * @param backgroundColor background color to generate drag handle. * @param embossed if <code>true</code> generated embossed drag handle, otherwise generated * engraved one. * @return Drag handle {@link ImageData}. */ public ImageData create(int height, HSB backgroundColor, boolean embossed) { ImageData source = null; if (embossed) { source = SharedImages.getImageDescriptor(SharedImages.HANDLE_EMBOSSED).getImageData(); } else { source = SharedImages.getImageDescriptor(SharedImages.HANDLE).getImageData(); } ImageData result = new ImageData(source.width, height, source.depth, source.palette); int offset = (result.height - source.height) / 2; for (int x = 0; x < result.width; x++) { for (int y = 0; y < result.height; y++) { if (y >= offset && y < offset + source.height) { result.setPixel(x, y, source.getPixel(x, y - offset)); } else { result.setPixel(x, y, source.transparentPixel); } } } result.transparentPixel = source.transparentPixel; List<RGB> newRGBs = new ArrayList<RGB>(); for (RGB each : result.palette.colors) { try { HSB hsb = backgroundColor.getCopy(); hsb.brightness = new HSB(each).brightness; hsb = hsb.mixWith(backgroundColor, 0.7f); newRGBs.add(hsb.toRGB()); } catch (Exception e) { e.printStackTrace(); } } result.palette.colors = newRGBs.toArray(new RGB[newRGBs.size()]); return result; }
public UserHomePalette(String name) { String userDir = System.getProperty("user.home"); file = new File(userDir, name); if (file.exists()) { FileInputStream fis; try { fis = new FileInputStream(file); String content = StringUtil.read(fis, "UTF-8"); String[] segmemts = content.split("\\s*[\r\n]+\\s*"); for (String each : segmemts) { each = each.trim(); if (each.length() == 0) { continue; } data.add(HSB.deserialize(each)); } } catch (Exception e) { e.printStackTrace(); } } }