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,7 +46,9 @@ public class Ellipse extends AbstractShape {
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels())); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
if (componentState != ComponentState.DRAGGING) { float alpha = this.alpha;
if (componentState == ComponentState.DRAGGING)
alpha = 0;
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
@@ -54,7 +56,7 @@ public class Ellipse extends AbstractShape {
g2d.setColor(color); g2d.setColor(color);
g2d.fillOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y); g2d.fillOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
}
// Do not track any changes that follow because the whole oval has been // Do not track any changes that follow because the whole oval has been
// tracked so far. // tracked so far.
drawingObserver.stopTracking(); drawingObserver.stopTracking();
@@ -52,7 +52,11 @@ public class Rectangle extends AbstractShape {
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels())); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
int radius = (int) edgeRadius.convertToPixels(); int radius = (int) edgeRadius.convertToPixels();
if (componentState != ComponentState.DRAGGING) {
float alpha = this.alpha;
if (componentState == ComponentState.DRAGGING)
alpha = 0;
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
@@ -61,7 +65,7 @@ public class Rectangle extends AbstractShape {
g2d.fillRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius, g2d.fillRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius); radius);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
}
// Do not track any changes that follow because the whole rect has been // Do not track any changes that follow because the whole rect has been
// tracked so far. // tracked so far.
drawingObserver.stopTracking(); drawingObserver.stopTracking();