Skip to content

Commit

Permalink
Removed warnings from draw2d examples
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl committed Apr 5, 2024
1 parent 0f520ca commit d72b8c4
Show file tree
Hide file tree
Showing 17 changed files with 477 additions and 394 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,17 @@ public void mousePressed(MouseEvent event) {

protected Shape createShape() {
Shape shape = null;
if (shapeCount == 0) {
shape = new Ellipse();
} else if (shapeCount == 1) {
shape = new RectangleFigure();
} else if (shapeCount == 2) {
shape = new RoundedRectangle();
} else if (shapeCount == 3) {
shape = new RectangleFigure();
} else if (shapeCount == 4) {
shape = new Ellipse();
} else if (shapeCount == 5) {
shape = new Triangle();
} else if (shapeCount == 6) {
shape = new RoundedRectangle();
} else if (shapeCount == 7) {
shape = new Triangle();
} else {
shape = new RoundedRectangle();
}
shape = switch (shapeCount) {
case 0 -> new Ellipse();
case 1 -> new RectangleFigure();
case 2 -> new RoundedRectangle();
case 3 -> new RectangleFigure();
case 4 -> new Ellipse();
case 5 -> new Triangle();
case 6 -> new RoundedRectangle();
case 7 -> new Triangle();
default -> new RoundedRectangle();
};

shape.setBackgroundColor(colors[colorCount]);
shape.setSize(70, 70);
Expand Down Expand Up @@ -320,7 +312,7 @@ public void widgetSelected(SelectionEvent e) {
@Override
public void widgetSelected(SelectionEvent e) {
gridLayout.verticalSpacing = getEventValue(e, "verticalSpacing").intValue(); //$NON-NLS-1$
;

updateView();
}
});
Expand Down Expand Up @@ -603,7 +595,8 @@ protected static int findAlignment(int align) {
protected static int findAlignment(String align) {
if (align.equals("BEGINNING")) { //$NON-NLS-1$
return SWT.BEGINNING;
} else if (align.equals("CENTER")) { //$NON-NLS-1$
}
if (align.equals("CENTER")) { //$NON-NLS-1$
return SWT.CENTER;
} else if (align.equals("END")) { //$NON-NLS-1$
return SWT.END;
Expand All @@ -614,7 +607,7 @@ protected static int findAlignment(String align) {
}

/**
* @see org.eclipse.draw2d.examples.AbstractExample#hookShell()
* @see org.eclipse.draw2d.examples.AbstractExample#hookShell(Shell)
*/
@Override
protected void hookShell(Shell shell) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected IFigure createContents() {
}

/**
* @see org.eclipse.draw2d.examples.AbstractExample#hookShell()
* @see org.eclipse.draw2d.examples.AbstractExample#hookShell(Shell)
*/
@Override
protected void hookShell(Shell shell) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static FigureCanvas createCanvas(Composite parent, int style, String tex
figure, or by the operating system.
Note that vertical scrolling may not be
as fast when the background from the
parent is inherited."""));
parent is inherited.""")); //$NON-NLS-1$
return canvas;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ static void refreshGrid() {
shell.pack();
}

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

public StyleAxis(String name, StyleItem[] elements) {
protected StyleAxis(String name, StyleItem[] elements) {
this.name = name;
this.elements = elements;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class CaretExample extends AbstractExample {

TextFlow caretOwner;
TextFlow content[];
TextFlow[] content;
Caret caret;
private Label offsetLabel;
private Label trailLabel;
Expand All @@ -50,7 +50,7 @@ protected IFigure createContents() {
protected void paintFigure(org.eclipse.draw2d.Graphics graphics) {
graphics.setBackgroundColor(new Color(null, 190, 220, 250));
graphics.fillRectangle(getBounds());
};
}
};

page.setBorder(new LineBorder(ColorConstants.darkGray, 10));
Expand All @@ -66,7 +66,7 @@ protected void paintFigure(org.eclipse.draw2d.Graphics graphics) {
</Japanese>.
<Hebrew>דפיםֱ מֱ- ישרֱֹאןץֱֹ\
</Hebrew>
<Arabic>نصً ثُ سٍَبُس</Arabic>""");
<Arabic>نصً ثُ سٍَبُس</Arabic>"""); //$NON-NLS-1$

text.setBorder(new TestBorder());
text.setFont(new Font(null, "Tahoma", 20, 0)); //$NON-NLS-1$
Expand All @@ -75,7 +75,7 @@ protected void paintFigure(org.eclipse.draw2d.Graphics graphics) {
page.addMouseMotionListener(new MouseMotionListener.Stub() {
@Override
public void mouseMoved(MouseEvent me) {
int trail[] = new int[1];
int[] trail = new int[1];
Point where = me.getLocation();
page.translateFromParent(where);
int offset = text.getOffset(where, trail, null);
Expand All @@ -85,15 +85,11 @@ public void mouseMoved(MouseEvent me) {
@Override
public void mouseExited(MouseEvent me) {

};
}
});
return page;
}

// protected int getShellStyle() {
// return super.getShellStyle() | SWT.RIGHT_TO_LEFT;
// }

@Override
protected void hookShell(Shell shell) {
getFigureCanvas().addKeyListener(new KeyAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@
*/
public abstract class MultiLineLabelExample {

private static MultiLineLabel label;

public static void main(String[] args) {
Display d = Display.getDefault();
Shell shell = new Shell(d);
shell.setLayout(new GridLayout());
label = new MultiLineLabel(shell);
MultiLineLabel label = new MultiLineLabel(shell);
Text text = new Text(shell, SWT.MULTI | SWT.WRAP | SWT.H_SCROLL | SWT.READ_ONLY);
label.setText("""
This is a oijeoi aeif jaoiewjf oaiew jfoaiew\
apijewpfk apoewkf paokwe pfokawpehfaowephf hawoiejf oaweijf paowkefp aoewkfpa\s\
pawkfe paoewkf paowekf pawokefoaiwjefo iajewoifja oewijf poerk pgaokew faewfpokew f\
f oaewkfp aewpofk apwejfoiuajweo foiwajef poawkefpawkje pfoakewpf aewpfkpaowke fpawf\
gfpowaegpawepmulti-line label.""");
gfpowaegpawepmulti-line label."""); //$NON-NLS-1$
text.setText(label.getText());

GridData data = new GridData(GridData.FILL_HORIZONTAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class TextFlowExample extends AbstractExample {

static protected IFigure createAlignmentParagraph() {
protected static IFigure createAlignmentParagraph() {
BlockFlow block = new BlockFlow();
block.setHorizontalAligment(PositionConstants.RIGHT);
block.add(new TextFlow(
Expand All @@ -45,10 +45,10 @@ static protected IFigure createAlignmentParagraph() {
return block;
}

static protected IFigure createBaselineParagraph() {
protected static IFigure createBaselineParagraph() {
BlockFlow block = new BlockFlow();

String message[] = { "Text fragments ", "with different ", "Font sizes will ", "have their ", "baseline ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
String[] message = { "Text fragments ", "with different ", "Font sizes will ", "have their ", "baseline ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"vertically ", "aligned ", "within ", "the current ", "line" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$

for (int i = 0; i < message.length; i++) {
Expand All @@ -61,7 +61,7 @@ static protected IFigure createBaselineParagraph() {
return block;
}

static protected IFigure createBlockParagraph() {
protected static IFigure createBlockParagraph() {
BlockFlow blockFlow = new BlockFlow();
blockFlow.setFont(COURIER);
TextFlow contents = new TextFlow();
Expand All @@ -74,12 +74,12 @@ static protected IFigure createBlockParagraph() {
public void foo() {
//TABs are not handled currently, only spaces.
System.out.println("foo")
}""");
}"""); //$NON-NLS-1$
blockFlow.add(contents);
return blockFlow;
}

static protected IFigure createNestedInlineParagraph() {
protected static IFigure createNestedInlineParagraph() {
BlockFlow blockFlow = new BlockFlow();
TextFlow text;
blockFlow.add(new TextFlow(
Expand All @@ -104,7 +104,7 @@ static protected IFigure createNestedInlineParagraph() {
return blockFlow;
}

static protected IFigure createParagraph() {
protected static IFigure createParagraph() {
BlockFlow blockFlow = new BlockFlow();
TextFlow contents = new TextFlow();
contents.setText("""
Expand All @@ -120,7 +120,7 @@ static protected IFigure createParagraph() {
return blockFlow;
}

static protected IFigure createTitle() {
protected static IFigure createTitle() {
BlockFlow blockFlow = new BlockFlow();
TextFlow contents = new TextFlow("Draw2D TextFlow Example"); //$NON-NLS-1$
contents.setFont(HEADING_1);
Expand Down Expand Up @@ -155,7 +155,6 @@ public static void main(String[] args) {
@Override
protected void setFigureCanvas(FigureCanvas canvas) {
super.setFigureCanvas(canvas);
// canvas.setVerticalScrollBarVisibility(canvas.ALWAYS);
canvas.getViewport().setContentsTracksWidth(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class TextFlowFactory {
static void addFontSizes(Figure parent, int min, int max) {
for (int i = min; i < max; i++) {
TextFlow tf = new TextFlow(Integer.toString(i) + " pt. Font "); //$NON-NLS-1$
// tf.setBackgroundColor(ColorConstants.lightGray);
// tf.setForegroundColor(ColorConstants.yellow);
tf.setFont(new org.eclipse.swt.graphics.Font(org.eclipse.swt.widgets.Display.getDefault(), "Helvetica", i, //$NON-NLS-1$
org.eclipse.swt.SWT.NORMAL));
parent.add(tf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@

public class TextFlowLargeExample {

static int KEYS_TYPED = 0;
static boolean PERFORMANCE = false;
static int keysTyped = 0;
static final boolean PERFORMANCE = false;
static FigureCanvas canvas;
static TextFlow target;
static FlowPage page;
static Font regularFont = new Font(Display.getDefault(), "Arial", 15, SWT.NORMAL), //$NON-NLS-1$
boldFont = new Font(Display.getDefault(), "Comic Sans MS", 16, SWT.BOLD); //$NON-NLS-1$
static Font regularFont = new Font(Display.getDefault(), "Arial", 15, SWT.NORMAL); //$NON-NLS-1$
static Font boldFont = new Font(Display.getDefault(), "Comic Sans MS", 16, SWT.BOLD); //$NON-NLS-1$

public static void main(String[] args) {
Display d = Display.getDefault();
Expand Down Expand Up @@ -78,19 +78,20 @@ public void keyPressed(KeyEvent e) {
}
}

static protected void addText(char c) {
protected static void addText(char c) {
if (((c <= 'Z') && (c >= 'A')) || ((c <= 'z') && (c >= 'a')) || (c == ' ')) {
if (target != null) {
target.setText(target.getText() + c);
if (PERFORMANCE && ((KEYS_TYPED % 10) == 0)) {
// System.out.println(KEYS_TYPED + " keys typed " + FlowPage.VALIDATIONS + " paints and layouts");
if (PERFORMANCE && ((keysTyped % 10) == 0)) {
// System.out.println(KEYS_TYPED + " keys typed " + FlowPage.VALIDATIONS + "
// paints and layouts");
}
KEYS_TYPED++;
keysTyped++;
}
}
}

static public void populatePage() {
public static void populatePage() {

target = new TextFlow("Normal text."); //$NON-NLS-1$
target.setToolTip(new Label("This is a Tooltip")); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
public class ThumbnailExample {

private static Figure contents;
private static Shell mainShell, overviewShell;
private static Shell mainShell;
private static Shell overviewShell;
private static Dimension offset = new Dimension();

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public void collapse() {
IFigure root = this;
Viewport port = null;
while (root.getParent() != null) {
if (root instanceof Viewport) {
port = ((Viewport) root);
if (root instanceof Viewport vp) {
port = vp;
}
root = root.getParent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.eclipse.draw2d.geometry.Transposer;

/**
* Performs a layout on a container containing {@link AbstractBranch} figures.
* This layout is similar to FlowLayout, except that the children are squeezed
* Performs a layout on a container containing {@link TreeBranch} figures. This
* layout is similar to FlowLayout, except that the children are squeezed
* together to overlap by comparing their left and right contours.
*
* @author hudsonr Created on Apr 18, 2003
Expand All @@ -45,12 +45,12 @@ protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHi
return result.getSize();
}

private static int[] calculateNewRightContour(int old[], int add[], int shift) {
private static int[] calculateNewRightContour(int[] old, int[] add, int shift) {
if (old == null) {
return add;
}
// if (shift < 0)
// shift = 0;
// if (shift < 0)
// shift = 0;
int[] result = new int[Math.max(old.length, add.length)];
System.arraycopy(add, 0, result, 0, add.length);
for (int i = add.length; i < result.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ public void validate() {
super.validate();
}

/**
* @return
*/
public boolean isCompressed() {
return compression;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
public class UMLClassFigure extends Figure {

/** Background color of UMLFigure */
public static Color classColor = new Color(null, 255, 255, 206);
public static final Color CLASS_COLOR = new Color(null, 255, 255, 206);

/** CompartmentFigures */
private CompartmentFigure attributeFigure = new CompartmentFigure();
private CompartmentFigure methodFigure = new CompartmentFigure();
private final CompartmentFigure attributeFigure = new CompartmentFigure();
private final CompartmentFigure methodFigure = new CompartmentFigure();

public UMLClassFigure(Label name) {
ToolbarLayout layout = new ToolbarLayout();
setLayoutManager(layout);
setBorder(new LineBorder(ColorConstants.black, 1));
setBackgroundColor(classColor);
setBackgroundColor(CLASS_COLOR);
setOpaque(true);

add(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
public class ZoomExample {

private static Figure contents;
// private static Shell overviewShell;

public static void main(String args[]) {
public static void main(String[] args) {
Display d = new Display();
final Shell shell = new Shell(d);
shell.setSize(800, 800);
Expand Down

0 comments on commit d72b8c4

Please sign in to comment.