Skip to content

Commit

Permalink
[Modernize Code] fixed several issues reported by sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl committed Dec 17, 2023
1 parent 7c2b866 commit 8cd23c7
Show file tree
Hide file tree
Showing 53 changed files with 1,443 additions and 1,087 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
*******************************************************************************/
package org.eclipse.draw2d.examples.swt;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.Polyline;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.Triangle;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
Expand All @@ -33,6 +23,17 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.Polyline;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.Triangle;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;

public class ShapeStylesExample {

static StyleAxis[] styleAxes = { new StyleAxis("Line Width", //$NON-NLS-1$
Expand All @@ -48,66 +49,62 @@ public void applyTo(Shape shape, int i) {
new StyleItem("SWT.LINE_DASH", SWT.LINE_DASH), new StyleItem("SWT.LINE_DASHDOT", SWT.LINE_DASHDOT), //$NON-NLS-1$ //$NON-NLS-2$
new StyleItem("SWT.LINE_DASHDOTDOT", SWT.LINE_DASHDOTDOT), //$NON-NLS-1$
new StyleItem("SWT.LINE_DOT", SWT.LINE_DOT), }) { //$NON-NLS-1$
@Override
public void applyTo(Shape shape, int i) {
shape.setLineStyle((int) elements[i].getValue());
}
},
@Override
public void applyTo(Shape shape, int i) {
shape.setLineStyle((int) elements[i].getValue());
}
},

new StyleAxis("Line Cap", new StyleItem[] { new StyleItem("SWT.CAP_FLAT", SWT.CAP_FLAT), //$NON-NLS-1$ //$NON-NLS-2$
new StyleItem("SWT.CAP_ROUND", SWT.CAP_ROUND), new StyleItem("SWT.CAP_SQUARE", SWT.CAP_SQUARE), }) { //$NON-NLS-1$ //$NON-NLS-2$
@Override
public void applyTo(Shape shape, int i) {
shape.setLineCap((int) elements[i].getValue());
}
},
@Override
public void applyTo(Shape shape, int i) {
shape.setLineCap((int) elements[i].getValue());
}
},

new StyleAxis("Line Miter Limit", //$NON-NLS-1$
new StyleItem[] { new StyleItem(0.0f), new StyleItem(0.5f), new StyleItem(1.0f),
new StyleItem(2.0f), new StyleItem(5.0f), new StyleItem(10.0f), new StyleItem(50.0f), }) {
@Override
public void applyTo(Shape shape, int i) {
shape.setLineMiterLimit(elements[i].getValue());
}
},
@Override
public void applyTo(Shape shape, int i) {
shape.setLineMiterLimit(elements[i].getValue());
}
},

new StyleAxis("Line Dash Offset", //$NON-NLS-1$
new StyleItem[] { new StyleItem(0.0f), new StyleItem(0.25f), new StyleItem(0.5f),
new StyleItem(1.0f), new StyleItem(2.0f), new StyleItem(2.5f), new StyleItem(5.0f),
new StyleItem(10.0f), }) {
@Override
public void applyTo(Shape shape, int i) {
shape.setLineDashOffset(elements[i].getValue());
}
},
@Override
public void applyTo(Shape shape, int i) {
shape.setLineDashOffset(elements[i].getValue());
}
},

new StyleAxis("Anti-Aliasing", new StyleItem[] { new StyleItem("SWT.ON", SWT.ON), //$NON-NLS-1$ //$NON-NLS-2$
new StyleItem("SWT.OFF", SWT.OFF), new StyleItem("SWT.DEFAULT", SWT.DEFAULT), }) { //$NON-NLS-1$ //$NON-NLS-2$
@Override
public void applyTo(Shape shape, int i) {
shape.setAntialias((int) elements[i].getValue());
}
},
@Override
public void applyTo(Shape shape, int i) {
shape.setAntialias((int) elements[i].getValue());
}
},

new StyleAxis("Alpha", new StyleItem[] { new StyleItem(0), new StyleItem(10), new StyleItem(50), //$NON-NLS-1$
new StyleItem(100), new StyleItem(150), new StyleItem(200), new StyleItem(255), }) {
@Override
public void applyTo(Shape shape, int i) {
shape.setAlpha((int) elements[i].getValue());
}
},
@Override
public void applyTo(Shape shape, int i) {
shape.setAlpha((int) elements[i].getValue());
}
},

new StyleAxis("Enabled", new StyleItem[] { new StyleItem("true", 1), new StyleItem("false", 0), }) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@Override
public void applyTo(Shape shape, int i) {
int setting = (int) elements[i].getValue();
if (setting == 1) {
shape.setEnabled(true);
} else {
shape.setEnabled(false);
}
}
}, };
@Override
public void applyTo(Shape shape, int i) {
int setting = (int) elements[i].getValue();
shape.setEnabled(setting == 1);
}
}, };

static final String[] sampleShapeClasses = { Ellipse.class.getName(), RectangleFigure.class.getName(),
RoundedRectangle.class.getName(), Triangle.class.getName(), Polyline.class.getName() };
Expand Down Expand Up @@ -305,7 +302,7 @@ static void refreshGrid() {
}

static abstract class StyleAxis {
private String name;
private final String name;
protected StyleItem[] elements;

public StyleAxis(String name, StyleItem[] elements) {
Expand All @@ -329,8 +326,8 @@ public String getName() {
}

static class StyleItem {
private String name;
private float value;
private final String name;
private final float value;

public StyleItem(float value) {
this.name = Float.toString(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void moveAll() {
* @since 3.1
*/
@Before
protected void setUp() {
public void setUp() {
Figure contents = new Figure();
contents.addNotify();
contents.setBounds(new Rectangle(0, 0, 100, 100));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class BaseTestCase extends Assert {

protected static final Font TAHOMA = new Font(null, "Tahoma", 8, 0);//$NON-NLS-1$

public void assertEquals(Image expected, Image actual) {
public static void assertEquals(Image expected, Image actual) {
assertTrue("The given images did not match", //$NON-NLS-1$
Arrays.equals(expected.getImageData().data, actual.getImageData().data));
}
Expand All @@ -43,7 +43,7 @@ public void assertEquals(Image expected, Image actual) {
* <code>(width, height)</code>. Actual object <code>{@link Dimension}</code>.
* If they are not an AssertionFailedError is thrown.
*/
public void assertEquals(int width, int height, Dimension dimension) throws Exception {
public static void assertEquals(int width, int height, Dimension dimension) {
assertEquals(width, dimension.width);
assertEquals(height, dimension.height);
}
Expand All @@ -53,7 +53,7 @@ public void assertEquals(int width, int height, Dimension dimension) throws Exce
* Actual object <code>{@link Point}</code>. If they are not an
* AssertionFailedError is thrown.
*/
public void assertEquals(int x, int y, Point point) throws Exception {
public static void assertEquals(int x, int y, Point point) {
assertEquals(x, point.x);
assertEquals(y, point.y);
}
Expand All @@ -64,7 +64,7 @@ public void assertEquals(int x, int y, Point point) throws Exception {
* <code>{@link Insets}</code>. If they are not an AssertionFailedError is
* thrown.
*/
public void assertEquals(int top, int left, int bottom, int right, Insets insets) throws Exception {
public static void assertEquals(int top, int left, int bottom, int right, Insets insets) {
assertEquals(top, insets.top);
assertEquals(left, insets.left);
assertEquals(bottom, insets.bottom);
Expand All @@ -77,7 +77,7 @@ public void assertEquals(int top, int left, int bottom, int right, Insets insets
* <code>{@link Rectangle}</code>. If they are not an AssertionFailedError is
* thrown.
*/
public void assertEquals(int x, int y, int width, int height, Rectangle rectangle) throws Exception {
public static void assertEquals(int x, int y, int width, int height, Rectangle rectangle) {
assertEquals(x, rectangle.x);
assertEquals(y, rectangle.y);
assertEquals(width, rectangle.width);
Expand All @@ -89,7 +89,7 @@ public void assertEquals(int x, int y, int width, int height, Rectangle rectangl
* <code>(begin, length)</code>. Actual object <code>{@link Interval}</code>. If
* they are not an AssertionFailedError is thrown.
*/
public void assertEquals(int begin, int length, Interval interval) throws Exception {
public static void assertEquals(int begin, int length, Interval interval) {
assertEquals(begin, interval.begin());
assertEquals(length, interval.length());
}
Expand All @@ -98,7 +98,7 @@ public void assertEquals(int begin, int length, Interval interval) throws Except
* Waits given number of milliseconds and pumps the SWT event queue.<br>
* At least one events loop will be executed.
*/
protected void waitEventLoop(Shell shell, int timeMillis) {
protected static void waitEventLoop(Shell shell, int timeMillis) {
long start = System.currentTimeMillis();
do {
// One of the events might dispose the shell...
Expand Down
Loading

0 comments on commit 8cd23c7

Please sign in to comment.