use of com.android.tools.idea.uibuilder.mockup.colorextractor.ColorExtractor in project android by JetBrains.
the class SimpleViewCreator method extractColor.
/**
* Find the color in the provided image and return them in the provided callback.
* The callback is called in a separate Thread
*
* @param image The image to extract the color from
* @param callback The callback to get the result of the color extraction
*/
protected void extractColor(@NotNull BufferedImage image, @NotNull ColorExtractor.ColorExtractorCallback callback) {
final Rectangle realCropping = getMockup().getComputedCropping();
final Rectangle selectionBounds = getSelectionBounds();
final BufferedImage subimage = image.getSubimage(realCropping.x + selectionBounds.x, realCropping.y + selectionBounds.y, selectionBounds.width, selectionBounds.height);
ColorExtractor colorExtractor = new DBSCANColorExtractor(subimage, DBSCANColorExtractor.DEFAULT_EPS, DBSCANColorExtractor.getMinClusterSize(subimage));
colorExtractor.run(callback);
}
use of com.android.tools.idea.uibuilder.mockup.colorextractor.ColorExtractor in project android by JetBrains.
the class ColorExtractorTool method initColorsComponents.
private void initColorsComponents() {
myExtractButton.addActionListener(e -> {
if (myExtractedColors != null) {
myColors.removeAll();
}
if (!myIsExtractingColor) {
ColorExtractor colorExtractor = new DBSCANColorExtractor(myMockup);
myIsExtractingColor = true;
colorExtractor.run(new ColorExtractor.ColorExtractorCallback() {
@Override
public void result(Collection<ExtractedColor> rgbColors) {
myProgressBar.setValue(100);
myExportButton.setEnabled(true);
myIsExtractingColor = false;
myExtractedColors = rgbColors;
for (ExtractedColor color : rgbColors) {
ColorPanel colorPanel = new ColorPanel(color);
colorPanel.addHoveredListener(ColorExtractorTool.this);
JPanel component = colorPanel.getComponent();
component.setMaximumSize(component.getPreferredSize());
myColors.add(component, 0);
}
myColors.revalidate();
}
@Override
public void progress(int progress) {
myProgressBar.setValue(progress);
}
});
}
});
}
Aggregations