track shaped components while dragging

This commit is contained in:
Branislav Stojkovic
2019-02-05 12:01:55 +01:00
parent 2735d7e343
commit ae3e698d9e
2 changed files with 24 additions and 18 deletions
@@ -46,15 +46,17 @@ public class Ellipse extends AbstractShape {
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
g2d.setComposite(oldComposite);
float alpha = this.alpha;
if (componentState == ComponentState.DRAGGING)
alpha = 0;
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
g2d.setComposite(oldComposite);
// Do not track any changes that follow because the whole oval has been
// tracked so far.
drawingObserver.stopTracking();
@@ -52,16 +52,20 @@ public class Rectangle extends AbstractShape {
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
int radius = (int) edgeRadius.convertToPixels();
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
g2d.setComposite(oldComposite);
float alpha = this.alpha;
if (componentState == ComponentState.DRAGGING)
alpha = 0;
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
g2d.setComposite(oldComposite);
// Do not track any changes that follow because the whole rect has been
// tracked so far.
drawingObserver.stopTracking();