diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/DetailsPart.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/DetailsPart.java index b18afa21c1f..06e7580d420 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/DetailsPart.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/DetailsPart.java @@ -41,18 +41,18 @@ */ public final class DetailsPart implements IFormPart, IPartSelectionListener { private IManagedForm managedForm; - private ScrolledPageBook pageBook; + private final ScrolledPageBook pageBook; private IFormPart masterPart; private IStructuredSelection currentSelection; - private Hashtable pages; + private final Hashtable pages; private IDetailsPageProvider pageProvider; private int pageLimit=Integer.MAX_VALUE; private static class PageBag { private static int counter; - private int ticket; + private final int ticket; private IDetailsPage page; - private boolean fixed; + private final boolean fixed; public PageBag(IDetailsPage page, boolean fixed) { this.page= page; @@ -127,8 +127,9 @@ public void setPageProvider(IDetailsPageProvider provider) { @Override public void commit(boolean onSave) { IDetailsPage page = getCurrentPage(); - if (page != null) + if (page != null) { page.commit(onSave); + } } /** * Returns the current page visible in the part. @@ -138,8 +139,9 @@ public IDetailsPage getCurrentPage() { Control control = pageBook.getCurrentPage(); if (control != null && !control.isDisposed()) { Object data = control.getData(); - if (data instanceof IDetailsPage) + if (data instanceof IDetailsPage) { return (IDetailsPage) data; + } } return null; } @@ -163,8 +165,9 @@ public void initialize(IManagedForm form) { @Override public boolean isDirty() { IDetailsPage page = getCurrentPage(); - if (page != null) + if (page != null) { return page.isDirty(); + } return false; } /** @@ -174,8 +177,9 @@ public boolean isDirty() { @Override public boolean isStale() { IDetailsPage page = getCurrentPage(); - if (page != null) + if (page != null) { return page.isStale(); + } return false; } @@ -185,8 +189,9 @@ public boolean isStale() { @Override public void refresh() { IDetailsPage page = getCurrentPage(); - if (page != null) + if (page != null) { page.refresh(); + } } /** * Sets the focus to the currently visible page. @@ -194,8 +199,9 @@ public void refresh() { @Override public void setFocus() { IDetailsPage page = getCurrentPage(); - if (page != null) + if (page != null) { page.setFocus(); + } } @Override @@ -208,19 +214,20 @@ public void selectionChanged(IFormPart part, ISelection selection) { this.masterPart = part; if (currentSelection != null) { } - if (selection instanceof IStructuredSelection) + if (selection instanceof IStructuredSelection) { currentSelection = (IStructuredSelection) selection; - else + } else { currentSelection = null; + } update(); } private void update() { Object key = null; if (currentSelection != null) { for (Object obj : currentSelection) { - if (key == null) + if (key == null) { key = getKey(obj); - else if (!getKey(obj).equals(key)) { + } else if (!getKey(obj).equals(key)) { key = null; break; } @@ -231,8 +238,9 @@ else if (!getKey(obj).equals(key)) { private Object getKey(Object object) { if (pageProvider!=null) { Object key = pageProvider.getPageKey(object); - if (key!=null) + if (key!=null) { return key; + } } return object.getClass(); } @@ -260,11 +268,13 @@ private void showPage(final Object key) { parent.setData(fpage); } //commit the current page - if (oldPage!=null && oldPage.isDirty()) + if (oldPage!=null && oldPage.isDirty()) { oldPage.commit(false); + } //refresh the new page - if (fpage.isStale()) + if (fpage.isStale()) { fpage.refresh(); + } fpage.selectionChanged(masterPart, currentSelection); pageBook.showPage(key); }); @@ -273,12 +283,15 @@ private void showPage(final Object key) { } // If we are switching from an old page to nothing, // don't loose data - if (oldPage!=null && oldPage.isDirty()) + if (oldPage!=null && oldPage.isDirty()) { oldPage.commit(false); + } pageBook.showEmptyPage(); } private void checkLimit() { - if (pages.size() <= getPageLimit()) return; + if (pages.size() <= getPageLimit()) { + return; + } // overflow int currentTicket = PageBag.getCurrentTicket(); int cutoffTicket = currentTicket - getPageLimit(); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/FormColors.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/FormColors.java index d47f6da6103..b66afcddd6c 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/FormColors.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/FormColors.java @@ -175,8 +175,9 @@ protected void initializeColorTable() { * keys to ensure they are available. */ public void initializeSectionToolBarColors() { - if (colorRegistry.containsKey(IFormColors.TB_BG)) + if (colorRegistry.containsKey(IFormColors.TB_BG)) { return; + } createTitleBarGradientColors(); createTitleBarOutlineColors(); createTwistieColors(); @@ -194,8 +195,9 @@ public void initializeSectionToolBarColors() { * @since 3.3 */ protected void initializeFormHeaderColors() { - if (colorRegistry.containsKey(IFormColors.H_BOTTOM_KEYLINE2)) + if (colorRegistry.containsKey(IFormColors.H_BOTTOM_KEYLINE2)) { return; + } createFormHeaderColors(); } @@ -226,8 +228,9 @@ public RGB getSystemColor(int code) { public Color createColor(String key, RGB rgb) { Color c = getResourceManager().createColor(rgb); Color prevC = colorRegistry.get(key); - if (prevC != null && !prevC.isDisposed()) + if (prevC != null && !prevC.isDisposed()) { getResourceManager().destroyColor(prevC.getRGB()); + } colorRegistry.put(key, c); return c; } @@ -282,15 +285,16 @@ public Color createColor(String key, int r, int g, int b) { * background color will be used. */ protected void updateBorderColor() { - if (isWhiteBackground()) + if (isWhiteBackground()) { border = getColor(IFormColors.BORDER); - else { + } else { border = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); Color bg = getImpliedBackground(); if (border.getRed() == bg.getRed() && border.getGreen() == bg.getGreen() - && border.getBlue() == bg.getBlue()) + && border.getBlue() == bg.getBlue()) { border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW); + } } } @@ -368,10 +372,11 @@ public boolean isWhiteBackground() { * @return color object if found, or null if not. */ public Color getColor(String key) { - if (key.startsWith(IFormColors.TB_PREFIX)) + if (key.startsWith(IFormColors.TB_PREFIX)) { initializeSectionToolBarColors(); - else if (key.startsWith(IFormColors.H_PREFIX)) + } else if (key.startsWith(IFormColors.H_PREFIX)) { initializeFormHeaderColors(); + } return colorRegistry.get(key); } @@ -379,8 +384,9 @@ else if (key.startsWith(IFormColors.H_PREFIX)) * Disposes all the colors in the registry. */ public void dispose() { - if (resources != null) + if (resources != null) { resources.dispose(); + } resources = null; colorRegistry = null; } @@ -436,12 +442,15 @@ public static RGB blend(RGB c1, RGB c2, int ratio) { * @since 3.1 */ public static boolean testAnyPrimaryColor(RGB rgb, int from, int to) { - if (testPrimaryColor(rgb.red, from, to)) + if (testPrimaryColor(rgb.red, from, to)) { return true; - if (testPrimaryColor(rgb.green, from, to)) + } + if (testPrimaryColor(rgb.green, from, to)) { return true; - if (testPrimaryColor(rgb.blue, from, to)) + } + if (testPrimaryColor(rgb.blue, from, to)) { return true; + } return false; } @@ -461,12 +470,15 @@ public static boolean testAnyPrimaryColor(RGB rgb, int from, int to) { */ public static boolean testTwoPrimaryColors(RGB rgb, int from, int to) { int total = 0; - if (testPrimaryColor(rgb.red, from, to)) + if (testPrimaryColor(rgb.red, from, to)) { total++; - if (testPrimaryColor(rgb.green, from, to)) + } + if (testPrimaryColor(rgb.green, from, to)) { total++; - if (testPrimaryColor(rgb.blue, from, to)) + } + if (testPrimaryColor(rgb.blue, from, to)) { total++; + } return total >= 2; } @@ -487,8 +499,9 @@ private static int blend(int v1, int v2, int ratio) { } private Color getImpliedBackground() { - if (getBackground() != null) + if (getBackground() != null) { return getBackground(); + } return getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); } @@ -641,8 +654,9 @@ private void createFormHeaderDNDColors() { } private LocalResourceManager getResourceManager() { - if (resources == null) + if (resources == null) { resources = new LocalResourceManager(JFaceResources.getResources()); + } return resources; } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/HyperlinkGroup.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/HyperlinkGroup.java index 0e3bc43643d..a19274acf9c 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/HyperlinkGroup.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/HyperlinkGroup.java @@ -34,10 +34,10 @@ */ public final class HyperlinkGroup extends HyperlinkSettings { - private ArrayList links = new ArrayList<>(); + private final ArrayList links = new ArrayList<>(); private Hyperlink lastActivated; private Hyperlink lastEntered; - private GroupListener listener; + private final GroupListener listener; private boolean isActiveBackgroundSet; private boolean isActiveForegroundSet; private boolean isBackgroundSet; @@ -69,22 +69,28 @@ private void onMouseEnter(Event e) { Hyperlink link = (Hyperlink) e.widget; previousBackground = link.getBackground(); previousForeground = link.getForeground(); - if (isActiveBackgroundSet) + if (isActiveBackgroundSet) { link.setBackground(getActiveBackground()); - if (isActiveForegroundSet) + } + if (isActiveForegroundSet) { link.setForeground(getActiveForeground()); - if (getHyperlinkUnderlineMode() == UNDERLINE_HOVER) + } + if (getHyperlinkUnderlineMode() == UNDERLINE_HOVER) { link.setUnderlined(true); + } link.setCursor(getHyperlinkCursor()); } private void onMouseExit(Event e) { Hyperlink link = (Hyperlink) e.widget; - if (isActiveBackgroundSet) + if (isActiveBackgroundSet) { link.setBackground(previousBackground); - if (isActiveForegroundSet) + } + if (isActiveForegroundSet) { link.setForeground(previousForeground); - if (getHyperlinkUnderlineMode() == UNDERLINE_HOVER) + } + if (getHyperlinkUnderlineMode() == UNDERLINE_HOVER) { link.setUnderlined(false); + } } @Override public void linkActivated(HyperlinkEvent e) { @@ -105,8 +111,9 @@ public void linkExited(HyperlinkEvent e) { } private void linkExited(Hyperlink link) { link.setCursor(null); - if (lastEntered == link) + if (lastEntered == link) { lastEntered = null; + } } } @@ -139,12 +146,15 @@ public Hyperlink getLastActivated() { */ public void add(Hyperlink link) { - if (isBackgroundSet) + if (isBackgroundSet) { link.setBackground(getBackground()); - if (isForegroundSet) + } + if (isForegroundSet) { link.setForeground(getForeground()); - if (getHyperlinkUnderlineMode() == UNDERLINE_ALWAYS) + } + if (getHyperlinkUnderlineMode() == UNDERLINE_ALWAYS) { link.setUnderlined(true); + } hook(link); } @@ -237,16 +247,19 @@ private void unhook(Hyperlink link) { link.removeHyperlinkListener(listener); link.removeListener(SWT.MouseEnter, listener); link.removeListener(SWT.MouseExit, listener); - if (lastActivated == link) + if (lastActivated == link) { lastActivated = null; - if (lastEntered == link) + } + if (lastEntered == link) { lastEntered = null; + } links.remove(link); } private void onMouseDown(Event e) { - if (e.button == 1) + if (e.button == 1) { return; + } lastActivated = (Hyperlink) e.widget; } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/HyperlinkSettings.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/HyperlinkSettings.java index 81c0ee45d92..c2f235be6d4 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/HyperlinkSettings.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/HyperlinkSettings.java @@ -74,8 +74,9 @@ public HyperlinkSettings(Display display) { public void initializeDefaultForegrounds(Display display) { Color fg = JFaceColors.getHyperlinkText(display); Color afg = JFaceColors.getActiveHyperlinkText(display); - if (fg == null) + if (fg == null) { fg = display.getSystemColor(SWT.COLOR_LINK_FOREGROUND); + } setForeground(fg); setActiveForeground(afg); } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/ManagedForm.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/ManagedForm.java index 9d7737b20bb..cef7b406e84 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/ManagedForm.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/ManagedForm.java @@ -41,9 +41,9 @@ public class ManagedForm implements IManagedForm { private Object input; - private ScrolledForm form; + private final ScrolledForm form; - private FormToolkit toolkit; + private final FormToolkit toolkit; private Object container; @@ -51,7 +51,7 @@ public class ManagedForm implements IManagedForm { private boolean initialized; - private Vector parts = new Vector<>(); + private final Vector parts = new Vector<>(); /** * Creates a managed form in the provided parent. Form toolkit and widget @@ -122,8 +122,9 @@ public void reflow(boolean changed) { public void fireSelectionChanged(IFormPart part, ISelection selection) { for (int i = 0; i < parts.size(); i++) { IFormPart cpart = parts.get(i); - if (part.equals(cpart)) + if (part.equals(cpart)) { continue; + } if (cpart instanceof IPartSelectionListener) { ((IPartSelectionListener) cpart).selectionChanged(part, selection); @@ -137,8 +138,9 @@ public void fireSelectionChanged(IFormPart part, ISelection selection) { */ @Override public void initialize() { - if (initialized) + if (initialized) { return; + } for (IFormPart part : parts) { part.initialize(this); } @@ -167,9 +169,9 @@ public void dispose() { public void refresh() { Thread t = Thread.currentThread(); Thread dt = toolkit.getColors().getDisplay().getThread(); - if (t.equals(dt)) + if (t.equals(dt)) { doRefresh(); - else { + } else { toolkit.getColors().getDisplay().asyncExec(this::doRefresh); } } @@ -182,15 +184,17 @@ private void doRefresh() { nrefreshed++; } } - if (nrefreshed > 0) + if (nrefreshed > 0) { form.reflow(true); + } } @Override public void commit(boolean onSave) { for (IFormPart part : parts) { - if (part.isDirty()) + if (part.isDirty()) { part.commit(onSave); + } } } @@ -201,8 +205,9 @@ public boolean setInput(Object input) { this.input = input; for (IFormPart part : parts) { boolean result = part.setFormInput(input); - if (result) + if (result) { pageResult = true; + } } return pageResult; } @@ -228,8 +233,9 @@ public void setFocus() { @Override public boolean isDirty() { for (IFormPart part : parts) { - if (part.isDirty()) + if (part.isDirty()) { return true; + } } return false; } @@ -237,8 +243,9 @@ public boolean isDirty() { @Override public boolean isStale() { for (IFormPart part : parts) { - if (part.isStale()) + if (part.isStale()) { return true; + } } return false; } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/MasterDetailsBlock.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/MasterDetailsBlock.java index 50e4c05379c..6ae7115cb0f 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/MasterDetailsBlock.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/MasterDetailsBlock.java @@ -114,10 +114,10 @@ private void hookSashListeners() { purgeSashes(); Control [] children = getChildren(); for (Control element : children) { - if (element instanceof Sash) { - Sash sash = (Sash)element; - if (sashes.contains(sash)) + if (element instanceof Sash sash) { + if (sashes.contains(sash)) { continue; + } sash.addListener(SWT.Paint, listener); sash.addListener(SWT.MouseEnter, listener); sash.addListener(SWT.MouseExit, listener); @@ -128,8 +128,9 @@ private void hookSashListeners() { private void purgeSashes() { for (Iterator iter=sashes.iterator(); iter.hasNext();) { Sash sash = iter.next(); - if (sash.isDisposed()) + if (sash.isDisposed()) { iter.remove(); + } } } } @@ -213,7 +214,9 @@ private void hookResizeListener() { Listener listener = ((MDSashForm)sashForm).listener; Control [] children = sashForm.getChildren(); for (Control element : children) { - if (element instanceof Sash) continue; + if (element instanceof Sash) { + continue; + } element.addListener(SWT.Resize, listener); } } @@ -266,13 +269,15 @@ private void onSashPaint(Event e) { gc.setForeground(colors.getColor(IFormColors.TB_BORDER)); Point size = sash.getSize(); if (vertical) { - if (hover!=null) + if (hover!=null) { gc.fillRectangle(0, 0, size.x, size.y); //else //gc.drawLine(1, 0, 1, size.y-1); - } else if (hover!=null) + } + } else if (hover!=null) { gc.fillRectangle(0, 0, size.x, size.y); //else //gc.drawLine(0, 1, size.x-1, 1); + } } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/SectionPart.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/SectionPart.java index 71daa333137..741c45d5c2f 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/SectionPart.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/SectionPart.java @@ -34,7 +34,7 @@ * @since 3.0 */ public class SectionPart extends AbstractFormPart { - private Section section; + private final Section section; /** * Creates a new section part based on the provided section. @@ -115,7 +115,8 @@ protected void expansionStateChanged(boolean expanded) { @Override public void setFocus() { Control client = section.getClient(); - if (client != null) + if (client != null) { client.setFocus(); + } } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/FormEditor.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/FormEditor.java index 91211baacdb..d0c5971781b 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/FormEditor.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/FormEditor.java @@ -90,8 +90,9 @@ public ISelection getSelection() { if (activeEditor != null) { ISelectionProvider selectionProvider = activeEditor.getSite() .getSelectionProvider(); - if (selectionProvider != null) + if (selectionProvider != null) { return selectionProvider.getSelection(); + } } if (globalSelection != null) { return globalSelection; @@ -106,8 +107,9 @@ public void setSelection(ISelection selection) { if (activeEditor != null) { ISelectionProvider selectionProvider = activeEditor.getSite() .getSelectionProvider(); - if (selectionProvider != null) + if (selectionProvider != null) { selectionProvider.setSelection(selection); + } } else { this.globalSelection = selection; fireSelectionChanged(new SelectionChangedEvent(this, @@ -265,13 +267,12 @@ public void addPage(int index, Control control) { public boolean isDirty() { if (pages != null) { for (Object page : pages) { - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage) page; - if (fpage.isDirty()) + if (page instanceof IFormPage fpage) { + if (fpage.isDirty()) { return true; + } - } else if (page instanceof IEditorPart) { - IEditorPart editor = (IEditorPart) page; + } else if (page instanceof IEditorPart editor) { if (editor.isDirty()) { return true; } @@ -292,11 +293,11 @@ public boolean isDirty() { protected void commitPages(boolean onSave) { if (pages != null) { for (Object page : pages) { - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage)page; + if (page instanceof IFormPage fpage) { IManagedForm mform = fpage.getManagedForm(); - if (mform != null && mform.isDirty()) + if (mform != null && mform.isDirty()) { mform.commit(onSave); + } } } } @@ -311,10 +312,11 @@ protected void commitPages(boolean onSave) { public int addPage(IEditorPart editor, IEditorInput input) throws PartInitException { int index = super.addPage(editor, input); - if (editor instanceof IFormPage) + if (editor instanceof IFormPage) { configurePage(index, (IFormPage) editor); - else + } else { registerPage(-1, editor); + } return index; } @@ -329,10 +331,11 @@ public int addPage(IEditorPart editor, IEditorInput input) public void addPage(int index, IEditorPart editor, IEditorInput input) throws PartInitException { super.addPage(index, editor, input); - if (editor instanceof IFormPage) + if (editor instanceof IFormPage) { configurePage(index, (IFormPage) editor); - else + } else { registerPage(index, editor); + } updatePageIndices(index+1); } @@ -365,10 +368,10 @@ public void removePage(int pageIndex) { if (pageIndex >= 0 && pageIndex < pages.size()) { Object page = pages.get(pageIndex); pages.remove(page); - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage) page; - if (!fpage.isEditor()) + if (page instanceof IFormPage fpage) { + if (!fpage.isEditor()) { fpage.dispose(); + } } updatePageIndices(pageIndex); } @@ -379,8 +382,7 @@ public void removePage(int pageIndex) { private void updatePageIndices(int start) { for (int i = start; i < pages.size(); i++) { Object page = pages.get(i); - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage) page; + if (page instanceof IFormPage fpage) { fpage.setIndex(i); } } @@ -401,12 +403,12 @@ public void editorDirtyStateChanged() { @Override public void dispose() { for (Object page : pages) { - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage) page; + if (page instanceof IFormPage fpage) { // don't dispose source pages because they will // be disposed as nested editors by the superclass - if (!fpage.isEditor()) + if (!fpage.isEditor()) { fpage.dispose(); + } } } pages = null; @@ -474,8 +476,7 @@ protected void pageChange(int newPageIndex) { } // Now is the absolute last moment to create the page control. Object page = pages.get(newPageIndex); - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage) page; + if (page instanceof IFormPage fpage) { if (fpage.getPartControl() == null) { fpage.createPartControl(getContainer()); setControl(newPageIndex, fpage.getPartControl()); @@ -487,16 +488,19 @@ protected void pageChange(int newPageIndex) { // Commit old page before activating the new one IFormPage oldFormPage = (IFormPage) pages.get(oldPageIndex); IManagedForm mform = oldFormPage.getManagedForm(); - if (mform != null) + if (mform != null) { mform.commit(false); + } } if (pages.size() > newPageIndex - && pages.get(newPageIndex) instanceof IFormPage) + && pages.get(newPageIndex) instanceof IFormPage) { ((IFormPage) pages.get(newPageIndex)).setActive(true); + } if (oldPageIndex != -1 && pages.size() > oldPageIndex && newPageIndex != oldPageIndex && - pages.get(oldPageIndex) instanceof IFormPage) + pages.get(oldPageIndex) instanceof IFormPage) { ((IFormPage) pages.get(oldPageIndex)).setActive(false); + } // Call super - this will cause pages to switch super.pageChange(newPageIndex); this.currentPage = newPageIndex; @@ -512,8 +516,7 @@ protected void pageChange(int newPageIndex) { public IFormPage setActivePage(String pageId) { for (int i = 0; i < pages.size(); i++) { Object page = pages.get(i); - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage) page; + if (page instanceof IFormPage fpage) { if (fpage.getId().equals(pageId)) { setActivePage(i); return fpage; @@ -532,10 +535,10 @@ public IFormPage setActivePage(String pageId) { */ public IFormPage findPage(String pageId) { for (Object page : pages) { - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage) page; - if (fpage.getId().equals(pageId)) + if (page instanceof IFormPage fpage) { + if (fpage.getId().equals(pageId)) { return fpage; + } } } return null; @@ -555,8 +558,9 @@ public IFormPage setActivePage(String pageId, Object pageInput) { IFormPage page = setActivePage(pageId); if (page != null) { IManagedForm mform = page.getManagedForm(); - if (mform != null) + if (mform != null) { mform.setInput(pageInput); + } } return page; } @@ -573,10 +577,10 @@ public IFormPage setActivePage(String pageId, Object pageInput) { */ public IFormPage selectReveal(Object pageInput) { for (Object page : pages) { - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage) page; - if (fpage.selectReveal(pageInput)) + if (page instanceof IFormPage fpage) { + if (fpage.selectReveal(pageInput)) { return fpage; + } } } return null; @@ -594,8 +598,9 @@ public IFormPage getActivePageInstance() { int index = getActivePage(); if (index != -1) { Object page = pages.get(index); - if (page instanceof IFormPage) + if (page instanceof IFormPage) { return (IFormPage) page; + } } return null; } @@ -612,8 +617,9 @@ protected void setActivePage(int pageIndex) { super.setActivePage(pageIndex); IFormPage activePage = (IFormPage) pages.get(pageIndex); activePage.setActive(true); - } else + } else { super.setActivePage(pageIndex); + } updateActionBarContributor(pageIndex); } @@ -653,15 +659,16 @@ public void close(final boolean save) { private void registerPage(int index, Object page) throws PartInitException { if (!pages.contains(page)) { - if (index == -1) + if (index == -1) { pages.add(page); - else + } else { pages.add(index, page); + } } - if (page instanceof IFormPage) { - IFormPage fpage = (IFormPage) page; - if (!fpage.isEditor()) + if (page instanceof IFormPage fpage) { + if (!fpage.isEditor()) { fpage.init(getEditorSite(), getEditorInput()); + } } } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/FormPage.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/FormPage.java index 5efb4b2efc2..429c7fa39b5 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/FormPage.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/FormPage.java @@ -40,7 +40,7 @@ public class FormPage extends EditorPart implements IFormPage { private FormEditor editor; private PageForm mform; private int index; - private String id; + private final String id; private static class PageForm extends ManagedForm { public PageForm(FormPage page, ScrolledForm form) { @@ -57,8 +57,9 @@ public void dirtyStateChanged() { } @Override public void staleStateChanged() { - if (getPage().isActive()) + if (getPage().isActive()) { refresh(); + } } } /** @@ -135,8 +136,9 @@ public void setActive(boolean active) { if (active) { // We are switching to this page - refresh it // if needed. - if (mform != null) + if (mform != null) { mform.refresh(); + } } } /** @@ -188,8 +190,9 @@ public Control getPartControl() { */ @Override public void dispose() { - if (mform != null) + if (mform != null) { mform.dispose(); + } } /** * Returns the unique identifier that can be used to reference this page. @@ -215,16 +218,18 @@ public Image getTitleImage() { */ @Override public void setFocus() { - if (mform != null) + if (mform != null) { mform.setFocus(); + } } /** * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor) */ @Override public void doSave(IProgressMonitor monitor) { - if (mform != null) + if (mform != null) { mform.commit(true); + } } /** * @see org.eclipse.ui.ISaveablePart#doSaveAs() @@ -291,8 +296,9 @@ public boolean isEditor() { */ @Override public boolean selectReveal(Object object) { - if (mform != null) + if (mform != null) { return mform.setInput(object); + } return false; } /** diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/SharedHeaderFormEditor.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/SharedHeaderFormEditor.java index 0fce7228a10..fe4e0675291 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/SharedHeaderFormEditor.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/editor/SharedHeaderFormEditor.java @@ -41,8 +41,9 @@ private static class HeaderForm extends ManagedForm { public HeaderForm(FormEditor editor, ScrolledForm form) { super(editor.getToolkit(), form); setContainer(editor); - if (editor.getEditorInput() != null) + if (editor.getEditorInput() != null) { setInput(editor.getEditorInput()); + } } private FormEditor getEditor() { @@ -120,14 +121,15 @@ protected void setActivePage(int pageIndex) { @Override public void setFocus() { installActivationListener(); - if (wasHeaderActive) + if (wasHeaderActive) { ((ManagedForm) getHeaderForm()).setFocus(); - else { + } else { int index= getActivePage(); - if (index == -1) + if (index == -1) { ((ManagedForm) getHeaderForm()).setFocus(); - else + } else { super.setFocus(); + } } } @@ -173,8 +175,9 @@ public boolean isDirty() { @Override protected void commitPages(boolean onSave) { - if (headerForm != null && headerForm.isDirty()) + if (headerForm != null && headerForm.isDirty()) { headerForm.commit(onSave); + } super.commitPages(onSave); } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/events/HyperlinkEvent.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/events/HyperlinkEvent.java index af3157469d0..6cd5962a95b 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/events/HyperlinkEvent.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/events/HyperlinkEvent.java @@ -21,8 +21,8 @@ */ public final class HyperlinkEvent extends TypedEvent { private static final long serialVersionUID = 6009335074727417445L; - private String label; - private int stateMask; + private final String label; + private final int stateMask; /** * Creates a new hyperlink * diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/AbstractHyperlink.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/AbstractHyperlink.java index 50bda1806d6..d3f70662f64 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/AbstractHyperlink.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/AbstractHyperlink.java @@ -138,8 +138,9 @@ public AbstractHyperlink(Composite parent, int style) { * the event listener to add */ public void addHyperlinkListener(IHyperlinkListener listener) { - if (listeners == null) + if (listeners == null) { listeners = new ListenerList<>(); + } listeners.add(listener); } @@ -150,8 +151,9 @@ public void addHyperlinkListener(IHyperlinkListener listener) { * the event listener to remove */ public void removeHyperlinkListener(IHyperlinkListener listener) { - if (listeners == null) + if (listeners == null) { return; + } listeners.remove(listener); } @@ -173,8 +175,9 @@ public boolean getSelection() { */ protected void handleEnter(Event e) { redraw(); - if (listeners == null) + if (listeners == null) { return; + } HyperlinkEvent he = new HyperlinkEvent(this, getHref(), getText(), e.stateMask); for (IHyperlinkListener listener : listeners) { @@ -190,8 +193,9 @@ protected void handleExit(Event e) { // disarm the link; won't activate on mouseup armed = false; redraw(); - if (listeners == null) + if (listeners == null) { return; + } HyperlinkEvent he = new HyperlinkEvent(this, getHref(), getText(), e.stateMask); for (IHyperlinkListener listener : listeners) { @@ -206,8 +210,9 @@ protected void handleExit(Event e) { protected void handleActivate(Event e) { // disarm link, back to normal state armed = false; - if (listeners == null) + if (listeners == null) { return; + } setCursor(FormsResources.getBusyCursor()); HyperlinkEvent he = new HyperlinkEvent(this, getHref(), getText(), e.stateMask); @@ -273,8 +278,9 @@ public String getText() { protected void paint(PaintEvent e) { GC gc = e.gc; Rectangle clientArea = getClientArea(); - if (clientArea.width == 0 || clientArea.height == 0) + if (clientArea.width == 0 || clientArea.height == 0) { return; + } paintHyperlink(gc); if (paintFocus && hasFocus) { Rectangle carea = getClientArea(); @@ -284,28 +290,34 @@ protected void paint(PaintEvent e) { } private void handleMouseDown(Event e) { - if (e.button != 1) + if (e.button != 1) { return; + } // armed and ready to activate on mouseup armed = true; } private void handleMouseUp(Event e) { - if (!armed || e.button != 1) + if (!armed || e.button != 1) { return; + } Point size = getSize(); // Filter out mouse up events outside // the link. This can happen when mouse is // clicked, dragged outside the link, then // released. - if (e.x < 0) + if (e.x < 0) { return; - if (e.y < 0) + } + if (e.y < 0) { return; - if (e.x >= size.x) + } + if (e.x >= size.x) { return; - if (e.y >= size.y) + } + if (e.y >= size.y) { return; + } handleActivate(e); } @@ -321,7 +333,8 @@ private void handleMouseMove(Event e) { public void setEnabled (boolean enabled) { boolean needsRedraw = enabled != getEnabled(); super.setEnabled(enabled); - if (needsRedraw) + if (needsRedraw) { redraw(); + } } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ColumnLayout.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ColumnLayout.java index e051cf29f5b..4519d845990 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ColumnLayout.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ColumnLayout.java @@ -75,7 +75,7 @@ public final class ColumnLayout extends Layout implements ILayoutExtension { */ public int rightMargin = 5; - private LayoutCache cache = new LayoutCache(); + private final LayoutCache cache = new LayoutCache(); private static final int MIN_SIZE = -2; @@ -185,8 +185,9 @@ private Point computeSize(Composite parent, int wHint, int hHint) { } colHeight = heights[ncol]; } - if (colHeight > 0) + if (colHeight > 0) { colHeight += verticalSpacing; + } colHeight += childHeight; } heights[ncol] = Math.max(heights[ncol],colHeight); @@ -279,8 +280,9 @@ protected void layout(Composite parent, boolean flushCache) { } colHeight = heights[ncol]; } - if (colHeight > 0) + if (colHeight > 0) { colHeight += verticalSpacing; + } switch (align) { diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ExpandableComposite.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ExpandableComposite.java index f2ca24a22bc..d32c0af8ac4 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ExpandableComposite.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ExpandableComposite.java @@ -224,7 +224,7 @@ public class ExpandableComposite extends Canvas { private Control client; - private ListenerList listeners = new ListenerList<>(); + private final ListenerList listeners = new ListenerList<>(); private Color titleBarForeground; @@ -232,15 +232,15 @@ private class ExpandableLayout extends Layout implements ILayoutExtension { private static final int MIN_WIDTH = -2; - private SizeCache toggleCache = new SizeCache(); + private final SizeCache toggleCache = new SizeCache(); - private SizeCache textClientCache = new SizeCache(); + private final SizeCache textClientCache = new SizeCache(); - private SizeCache textLabelCache = new SizeCache(); + private final SizeCache textLabelCache = new SizeCache(); - private SizeCache descriptionCache = new SizeCache(); + private final SizeCache descriptionCache = new SizeCache(); - private SizeCache clientCache = new SizeCache(); + private final SizeCache clientCache = new SizeCache(); private void initCache(boolean shouldFlush) { toggleCache.setControl(toggle); @@ -276,8 +276,9 @@ protected void layout(Composite parent, boolean changed) { Point toggleSize = toggleCache.computeSize(SWT.DEFAULT, SWT.DEFAULT); int width = clientArea.width - marginWidth - marginWidth - thmargin - thmargin; - if (toggleSize.x > 0) + if (toggleSize.x > 0) { width -= toggleSize.x + IGAP; + } // TODO: This code is common between computeSize and layout int gapBetweenTcAndLabel = (textClient != null && textLabel != null) ? IGAP : 0; @@ -343,9 +344,10 @@ protected void layout(Composite parent, boolean changed) { if (textLabel != null) { int ty = y; if (leftAlignment) { - if (size.y < tcsize.y) + if (size.y < tcsize.y) { ty = (tcsize.y - size.y) / 2 + marginHeight + tvmargin; + } } int gap = 0; @@ -360,13 +362,16 @@ protected void layout(Composite parent, boolean changed) { if (textClient != null) { int tcwidth = clientArea.width - marginWidth - marginWidth - thmargin - thmargin; - if (toggleSize.x > 0) + if (toggleSize.x > 0) { tcwidth -= toggleSize.x + IGAP; - if (size.x > 0) + } + if (size.x > 0) { tcwidth -= size.x + IGAP; + } tcwidth = Math.min(tcsize.x, tcwidth); - if (tcwidth < 0) + if (tcwidth < 0) { tcwidth = 0; + } int tcx; if ((expansionStyle & LEFT_TEXT_CLIENT_ALIGNMENT) != 0) { tcx = x + ((size.x > 0) ? size.x + IGAP : 0); @@ -377,8 +382,9 @@ protected void layout(Composite parent, boolean changed) { } y += height; - if (hasTitleBar()) + if (hasTitleBar()) { y += tvmargin; + } Control separatorControl = getSeparatorControl(); if (separatorControl != null) { y += VSPACE; @@ -479,14 +485,17 @@ protected Point computeSize(Composite parent, int wHint, int hHint, if ((expanded || (expansionStyle & COMPACT) == 0) && client != null) { int cwHint = wHint; int clientIndent = 0; - if ((expansionStyle & CLIENT_INDENT) != 0) + if ((expansionStyle & CLIENT_INDENT) != 0) { clientIndent = toggleWidthPlusGap; + } if (cwHint != SWT.DEFAULT && cwHint != MIN_WIDTH) { cwHint -= marginWidth + marginWidth + thmargin + thmargin; - if ((expansionStyle & CLIENT_INDENT) != 0) - if (tcsize.x > 0) + if ((expansionStyle & CLIENT_INDENT) != 0) { + if (tcsize.x > 0) { cwHint -= toggleWidthPlusGap; + } + } } Point dsize = null; Point csize; @@ -500,8 +509,9 @@ protected Point computeSize(Composite parent, int wHint, int hHint, int dwHint = cwHint; if (dwHint == SWT.DEFAULT || dwHint == MIN_WIDTH) { dwHint = csize.x; - if ((expansionStyle & CLIENT_INDENT) != 0) + if ((expansionStyle & CLIENT_INDENT) != 0) { dwHint -= toggleWidthPlusGap; + } } dsize = descriptionCache.computeSize(dwHint, SWT.DEFAULT); width = Math.max(width, dsize.x + clientIndent); @@ -572,8 +582,9 @@ public ExpandableComposite(Composite parent, int style) { public ExpandableComposite(Composite parent, int style, int expansionStyle) { super(parent, style); this.expansionStyle = expansionStyle; - if ((expansionStyle & TITLE_BAR) != 0) + if ((expansionStyle & TITLE_BAR) != 0) { setBackgroundMode(SWT.INHERIT_DEFAULT); + } super.setLayout(new ExpandableLayout()); if (hasTitleBar()) { this.addPaintListener(e -> { @@ -582,14 +593,16 @@ public ExpandableComposite(Composite parent, int style, int expansionStyle) { } }); } - if ((expansionStyle & TWISTIE) != 0) + if ((expansionStyle & TWISTIE) != 0) { toggle = new Twistie(this, SWT.NULL); - else if ((expansionStyle & TREE_NODE) != 0) + } else if ((expansionStyle & TREE_NODE) != 0) { toggle = new TreeNode(this, SWT.NULL); - else + } else { expanded = true; - if ((expansionStyle & EXPANDED) != 0) + } + if ((expansionStyle & EXPANDED) != 0) { expanded = true; + } if (toggle != null) { toggle.setExpanded(expanded); toggle.addHyperlinkListener(new HyperlinkAdapter() { @@ -599,12 +612,13 @@ public void linkActivated(HyperlinkEvent e) { } }); toggle.addPaintListener(e -> { - if (textLabel instanceof Label && !isFixedStyle()) + if (textLabel instanceof Label && !isFixedStyle()) { if (toggle.hover) { textLabel.setForeground(toggle.getHoverDecorationColor()); } else { textLabel.setForeground(getTitleBarForeground()); } + } }); toggle.addKeyListener(new KeyAdapter() { @Override @@ -653,8 +667,9 @@ public void linkActivated(HyperlinkEvent e) { Listener listener = e -> { switch (e.type) { case SWT.MouseDown: - if (toggle != null) + if (toggle != null) { toggle.setFocus(); + } break; case SWT.MouseUp: label.setCursor(FormsResources.getBusyCursor()); @@ -695,8 +710,9 @@ public void linkActivated(HyperlinkEvent e) { textLabel.addTraverseListener(e -> { if (e.detail == SWT.TRAVERSE_MNEMONIC) { // steal the mnemonic - if (!isVisible() || !isEnabled()) + if (!isVisible() || !isEnabled()) { return; + } if (FormUtil.mnemonicMatch(getText(), e.character)) { e.doit = false; if (!isFixedStyle()) { @@ -723,8 +739,9 @@ public boolean forceFocus() { @Override public void setMenu(Menu menu) { - if (textLabel != null) + if (textLabel != null) { textLabel.setMenu(menu); + } super.setMenu(menu); } @@ -743,10 +760,12 @@ public final void setLayout(Layout layout) { public void setBackground(Color bg) { super.setBackground(bg); if ((getExpansionStyle() & TITLE_BAR) == 0) { - if (textLabel != null) + if (textLabel != null) { textLabel.setBackground(bg); - if (toggle != null) + } + if (toggle != null) { toggle.setBackground(bg); + } } } @@ -756,10 +775,12 @@ public void setBackground(Color bg) { @Override public void setForeground(Color fg) { super.setForeground(fg); - if (textLabel != null) + if (textLabel != null) { textLabel.setForeground(fg); - if (toggle != null) + } + if (toggle != null) { toggle.setForeground(fg); + } } /** @@ -769,8 +790,9 @@ public void setForeground(Color fg) { * the color object */ public void setToggleColor(Color c) { - if (toggle != null) + if (toggle != null) { toggle.setDecorationColor(c); + } } /** @@ -781,8 +803,9 @@ public void setToggleColor(Color c) { * the active color object */ public void setActiveToggleColor(Color c) { - if (toggle != null) + if (toggle != null) { toggle.setHoverDecorationColor(c); + } } /** @@ -791,18 +814,22 @@ public void setActiveToggleColor(Color c) { @Override public void setFont(Font font) { super.setFont(font); - if (textLabel != null) + if (textLabel != null) { textLabel.setFont(font); - if (toggle != null) + } + if (toggle != null) { toggle.setFont(font); + } } @Override public void setEnabled(boolean enabled) { - if (textLabel != null) + if (textLabel != null) { textLabel.setEnabled(enabled); - if (toggle != null) + } + if (toggle != null) { toggle.setEnabled(enabled); + } super.setEnabled(enabled); } @@ -865,12 +892,13 @@ public void setToolTipText(String string) { * @see #setText(String) */ public String getText() { - if (textLabel instanceof Label) + if (textLabel instanceof Label) { return ((Label) textLabel).getText(); - else if (textLabel instanceof Hyperlink) + } else if (textLabel instanceof Hyperlink) { return ((Hyperlink) textLabel).getText(); - else + } else { return ""; //$NON-NLS-1$ + } } /** @@ -929,10 +957,12 @@ public void setExpanded(boolean expanded, boolean fireExpanding) { protected void internalSetExpanded(boolean expanded) { if (this.expanded != expanded) { this.expanded = expanded; - if (getDescriptionControl() != null) + if (getDescriptionControl() != null) { getDescriptionControl().setVisible(expanded); - if (client != null) + } + if (client != null) { client.setVisible(expanded); + } reflow(); } } @@ -1044,8 +1074,9 @@ public Control getTextClient() { * more. */ public void setTextClient(Control textClient) { - if (this.textClient != null) + if (this.textClient != null) { this.textClient.dispose(); + } this.textClient = textClient; } @@ -1063,8 +1094,9 @@ public void setTextClient(Control textClient) { * @since 3.3 */ public int getTextClientHeightDifference() { - if (textClient == null || textLabel == null) + if (textClient == null || textLabel == null) { return 0; + } int theight = textLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; int tcheight = textClient.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; return Math.max(tcheight - theight, 0); @@ -1090,8 +1122,9 @@ protected boolean hasTitleBar() { */ public void setTitleBarForeground(Color color) { titleBarForeground = color; - if (textLabel != null) + if (textLabel != null) { textLabel.setForeground(color); + } } /** @@ -1108,8 +1141,9 @@ public Color getTitleBarForeground() { private void toggleState() { boolean newState = !isExpanded(); internalSetExpanded(newState, true); - if (newState) + if (newState) { FormUtil.ensureVisible(this); + } } /** @@ -1134,14 +1168,16 @@ private void internalSetExpanded(boolean expanded, boolean fireExpanding) { private void fireExpanding(boolean state, boolean before) { int size = listeners.size(); - if (size == 0) + if (size == 0) { return; + } ExpansionEvent e = new ExpansionEvent(this, state); for (IExpansionListener listener : listeners) { - if (before) + if (before) { listener.expansionStateChanging(e); - else + } else { listener.expansionStateChanged(e); + } } } @@ -1165,16 +1201,18 @@ private ExpandableComposite getSibling(Control[] children, int index, int loc = down ? index + 1 : index - 1; while (loc >= 0 && loc < children.length) { Control c = children[loc]; - if (c instanceof ExpandableComposite && c.isVisible()) + if (c instanceof ExpandableComposite && c.isVisible()) { return (ExpandableComposite) c; + } loc = down ? loc + 1 : loc - 1; } return null; } private void programmaticToggleState() { - if (toggle != null) + if (toggle != null) { toggle.setExpanded(!toggle.isExpanded()); + } toggleState(); } @@ -1182,8 +1220,9 @@ private void paintTitleFocus(GC gc) { Point size = textLabel.getSize(); gc.setBackground(textLabel.getBackground()); gc.setForeground(textLabel.getForeground()); - if (toggle.isFocusControl()) + if (toggle.isFocusControl()) { gc.drawFocus(0, 0, size.x, size.y); + } } void reflow() { diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Form.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Form.java index 2a9bddf0700..645d9895e09 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Form.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Form.java @@ -96,13 +96,13 @@ * @noextend This class is not intended to be subclassed by clients. */ public class Form extends Composite { - private FormHeading head; + private final FormHeading head; - private Composite body; + private final Composite body; - private SizeCache bodyCache = new SizeCache(); + private final SizeCache bodyCache = new SizeCache(); - private SizeCache headCache = new SizeCache(); + private final SizeCache headCache = new SizeCache(); private FormText selectionText; @@ -134,10 +134,11 @@ public Point computeSize(Composite composite, int wHint, int hHint, boolean ignoreBody=getData(FormUtil.IGNORE_BODY)!=null; Point bsize; - if (ignoreBody) + if (ignoreBody) { bsize = new Point(0,0); - else + } else { bsize = bodyCache.computeSize(wHint, SWT.DEFAULT); + } width = Math.max(bsize.x, width); height += bsize.y; return new Point(width, height); @@ -814,8 +815,9 @@ void setSelectionText(FormText text) { * @since org.eclipse.ui.forms 3.4 */ public IMessageManager getMessageManager() { - if (messageManager == null) + if (messageManager == null) { messageManager = new MessageManager(this); + } return messageManager; } } \ No newline at end of file diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/FormText.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/FormText.java index 0e2bde803f5..d6bfb547cd1 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/FormText.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/FormText.java @@ -201,7 +201,7 @@ public class FormText extends Canvas { private ListenerList listeners; - private Hashtable resourceTable = new Hashtable<>(); + private final Hashtable resourceTable = new Hashtable<>(); private IHyperlinkSegment entered; @@ -238,11 +238,13 @@ public Point computeSize(Composite composite, int wHint, int hHint, boolean changed) { long start = 0; - if (DEBUG_TEXT) + if (DEBUG_TEXT) { start = System.currentTimeMillis(); + } int innerWidth = wHint; - if (innerWidth != SWT.DEFAULT) + if (innerWidth != SWT.DEFAULT) { innerWidth -= marginWidth * 2; + } Point textSize = computeTextSize(innerWidth); int textWidth = textSize.x + 2 * marginWidth; int textHeight = textSize.y + 2 * marginHeight; @@ -270,8 +272,9 @@ private Point computeTextSize(int wHint) { for (int i = 0; i < paragraphs.length; i++) { Paragraph p = paragraphs[i]; if (i > 0 && getParagraphsSeparated() - && p.getAddVerticalSpace()) + && p.getAddVerticalSpace()) { loc.y += getParagraphSpacing(lineHeight); + } loc.rowHeight = 0; loc.indent = p.getIndent(); loc.x = p.getIndent(); @@ -286,11 +289,13 @@ private Point computeTextSize(int wHint) { } else { pwidth = Math.max(pwidth, loc.width); } - if (segment instanceof IFocusSelectable) + if (segment instanceof IFocusSelectable) { selectableInTheLastRow = true; + } } - if (wHint == SWT.DEFAULT) + if (wHint == SWT.DEFAULT) { width = Math.max(width, pwidth); + } loc.y += loc.rowHeight; } else { // empty new line @@ -298,8 +303,9 @@ private Point computeTextSize(int wHint) { } } gc.dispose(); - if (selectableInTheLastRow) + if (selectableInTheLastRow) { loc.y += 1; + } return new Point(width, loc.y); } @@ -332,8 +338,9 @@ protected void layout(Composite composite, boolean flushCache) { IHyperlinkSegment selectedLink = getSelectedLink(); for (int i = 0; i < paragraphs.length; i++) { Paragraph p = paragraphs[i]; - if (i > 0 && paragraphsSeparated && p.getAddVerticalSpace()) + if (i > 0 && paragraphsSeparated && p.getAddVerticalSpace()) { loc.y += getParagraphSpacing(lineHeight); + } loc.indent = p.getIndent(); loc.resetCaret(); loc.rowHeight = 0; @@ -376,8 +383,9 @@ public FormText(Composite parent, int style) { } }); addListener(SWT.Traverse, e -> { - if (DEBUG_FOCUS) + if (DEBUG_FOCUS) { System.out.println("Traversal: " + e); //$NON-NLS-1$ + } switch (e.detail) { case SWT.TRAVERSE_PAGE_NEXT: case SWT.TRAVERSE_PAGE_PREVIOUS: @@ -390,12 +398,13 @@ public FormText(Composite parent, int style) { e.doit = true; return; } - if (e.detail == SWT.TRAVERSE_TAB_NEXT) + if (e.detail == SWT.TRAVERSE_TAB_NEXT) { e.doit = advance(true); - else if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) + } else if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) { e.doit = advance(false); - else if (e.detail != SWT.TRAVERSE_RETURN) + } else if (e.detail != SWT.TRAVERSE_RETURN) { e.doit = true; + } }); addFocusListener(new FocusListener() { @Override @@ -418,8 +427,9 @@ public void focusLost(FocusEvent e) { } if (hasFocus) { hasFocus = false; - if (!controlFocusTransfer) + if (!controlFocusTransfer) { handleFocusChange(); + } } } }); @@ -572,10 +582,11 @@ public void setImage(String key, Image image) { */ public void setColor(String key, Color color) { String fullKey = "c." + key; //$NON-NLS-1$ - if (color == null) + if (color == null) { resourceTable.remove(fullKey); - else + } else { resourceTable.put(fullKey, color); + } } /** @@ -594,10 +605,11 @@ public void setColor(String key, Color color) { */ public void setFont(String key, Font font) { String fullKey = "f." + key; //$NON-NLS-1$ - if (font == null) + if (font == null) { resourceTable.remove(fullKey); - else + } else { resourceTable.put(fullKey, font); + } model.clearCache(fullKey); } @@ -619,10 +631,11 @@ public void setFont(String key, Font font) { */ public void setControl(String key, Control control) { String fullKey = "o." + key; //$NON-NLS-1$ - if (control == null) + if (control == null) { resourceTable.remove(fullKey); - else + } else { resourceTable.put(fullKey, control); + } } /** @@ -662,10 +675,11 @@ public void setFont(Font font) { public void setText(String text, boolean parseTags, boolean expandURLs) { disposeResourceTable(false); entered = null; - if (parseTags) + if (parseTags) { model.parseTaggedText(text, expandURLs); - else + } else { model.parseRegularText(text, expandURLs); + } hookControlSegmentFocus(); layout(); redraw(); @@ -693,17 +707,20 @@ public void setContents(InputStream is, boolean expandURLs) { private void hookControlSegmentFocus() { Paragraph[] paragraphs = model.getParagraphs(); - if (paragraphs == null) + if (paragraphs == null) { return; + } Listener listener = e -> { switch (e.type) { case SWT.FocusIn: - if (!controlFocusTransfer) + if (!controlFocusTransfer) { syncControlSegmentFocus((Control) e.widget); + } break; case SWT.Traverse: - if (DEBUG_FOCUS) + if (DEBUG_FOCUS) { System.out.println("Control traversal: " + e); //$NON-NLS-1$ + } switch (e.detail) { case SWT.TRAVERSE_PAGE_NEXT: case SWT.TRAVERSE_PAGE_PREVIOUS: @@ -714,20 +731,21 @@ private void hookControlSegmentFocus() { } Control c = (Control) e.widget; ControlSegment segment = (ControlSegment) c.getData(CONTROL_KEY); - if (e.detail == SWT.TRAVERSE_TAB_NEXT) + if (e.detail == SWT.TRAVERSE_TAB_NEXT) { e.doit = advanceControl(c, segment, true); - else if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) + } else if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) { e.doit = advanceControl(c, segment, false); - if (!e.doit) + } + if (!e.doit) { e.detail = SWT.TRAVERSE_NONE; + } break; } }; for (Paragraph p : paragraphs) { ParagraphSegment[] segments = p.getSegments(); for (ParagraphSegment segment : segments) { - if (segment instanceof ControlSegment) { - ControlSegment cs = (ControlSegment) segment; + if (segment instanceof ControlSegment cs) { Control c = cs.getControl(resourceTable); if (c != null) { if (c.getData(CONTROL_KEY) == null) { @@ -742,8 +760,7 @@ else if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) } private void attachTraverseListener(Control c, Listener listener) { - if (c instanceof Composite) { - Composite parent = (Composite) c; + if (c instanceof Composite parent) { Control[] children = parent.getChildren(); for (Control element : children) { attachTraverseListener(element, listener); @@ -774,27 +791,32 @@ private void syncControlSegmentFocus(Control control) { while (control != null) { cs = (ControlSegment) control.getData(CONTROL_KEY); - if (cs != null) + if (cs != null) { break; + } control = control.getParent(); } - if (cs == null) + if (cs == null) { return; + } IFocusSelectable current = model.getSelectedSegment(); // If the model and the control match, all is well - if (current == cs) + if (current == cs) { return; + } IHyperlinkSegment oldLink = null; if (current != null && current instanceof IHyperlinkSegment) { oldLink = (IHyperlinkSegment) current; exitLink(oldLink, SWT.NULL); } - if (DEBUG_FOCUS) + if (DEBUG_FOCUS) { System.out.println("Sync control: " + cs + ", oldLink=" + oldLink); //$NON-NLS-1$ //$NON-NLS-2$ + } model.select(cs); - if (oldLink != null) + if (oldLink != null) { paintFocusTransfer(oldLink, null); // getAccessible().setFocus(model.getSelectedSegmentIndex()); + } } private boolean advanceControl(Control c, ControlSegment segment, @@ -813,8 +835,9 @@ private boolean advanceControl(Control c, ControlSegment segment, // nowhere to go return setFocusToNextSibling(this, next); } - if (setFocusToNextSibling(c, next)) + if (setFocusToNextSibling(c, next)) { return true; + } // still here - must go one level up segment = (ControlSegment) parent.getData(CONTROL_KEY); return advanceControl(parent, segment, next); @@ -830,14 +853,16 @@ private boolean setFocusToNextSibling(Control c, boolean next) { if (next) { for (int j = i + 1; j < children.length; j++) { Control nc = children[j]; - if (nc.setFocus()) + if (nc.setFocus()) { return false; + } } } else { for (int j = i - 1; j >= 0; j--) { Control pc = children[j]; - if (pc.setFocus()) + if (pc.setFocus()) { return false; + } } } } @@ -895,8 +920,9 @@ public void setMenu(Menu menu) { currentMenu.dispose(); super.setMenu(menu); } - } else + } else { super.setMenu(menu); + } } private void createMenu() { @@ -954,8 +980,9 @@ public void setHyperlinkSettings(HyperlinkSettings settings) { * the listener to add */ public void addHyperlinkListener(IHyperlinkListener listener) { - if (listeners == null) + if (listeners == null) { listeners = new ListenerList<>(); + } listeners.add(listener); } @@ -966,8 +993,9 @@ public void addHyperlinkListener(IHyperlinkListener listener) { * the listener to remove */ public void removeHyperlinkListener(IHyperlinkListener listener) { - if (listeners == null) + if (listeners == null) { return; + } listeners.remove(listener); } @@ -1035,8 +1063,9 @@ public void removeSelectionListener(SelectionListener listener) { public String getSelectionText() { checkWidget(); - if (selData != null) + if (selData != null) { return selData.getSelectionText(); + } return ""; //$NON-NLS-1$ } @@ -1059,8 +1088,9 @@ public boolean canCopy() { */ public void copy() { - if (!canCopy()) + if (!canCopy()) { return; + } Clipboard clipboard = new Clipboard(getDisplay()); Object[] o = new Object[] { getSelectionText() }; Transfer[] t = new Transfer[] { TextTransfer.getInstance() }; @@ -1098,8 +1128,9 @@ public String getSelectedLinkText() { private IHyperlinkSegment getSelectedLink() { IFocusSelectable segment = model.getSelectedSegment(); - if (segment != null && segment instanceof IHyperlinkSegment) + if (segment != null && segment instanceof IHyperlinkSegment) { return (IHyperlinkSegment) segment; + } return null; } @@ -1108,9 +1139,9 @@ private void initAccessible() { accessible.addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { - if (e.childID == ACC.CHILDID_SELF) + if (e.childID == ACC.CHILDID_SELF) { e.result = model.getAccessibleText(); - else { + } else { int linkCount = model.getHyperlinkCount(); if (e.childID >= 0 && e.childID < linkCount) { IHyperlinkSegment link = model.getHyperlink(e.childID); @@ -1134,10 +1165,11 @@ public void getHelp(AccessibleEvent e) { public void getChildAtPoint(AccessibleControlEvent e) { Point pt = toControl(new Point(e.x, e.y)); IHyperlinkSegment link = model.findHyperlinkAt(pt.x, pt.y); - if (link != null) + if (link != null) { e.childID = model.indexOf(link); - else + } else { e.childID = ACC.CHILDID_SELF; + } } @Override @@ -1256,17 +1288,19 @@ private void startSelection(MouseEvent e) { selData = new SelectionData(e); redraw(); Form form = FormUtil.getForm(this); - if (form != null) + if (form != null) { form.setSelectionText(this); + } } private void endSelection(MouseEvent e) { inSelection = false; if (selData != null) { - if (!selData.isEnclosed()) + if (!selData.isEnclosed()) { selData = null; - else + } else { computeSelection(); + } } notifySelectionChanged(); } @@ -1275,8 +1309,9 @@ private void computeSelection() { GC gc = new GC(this); Paragraph[] paragraphs = model.getParagraphs(); IHyperlinkSegment selectedLink = getSelectedLink(); - if (getDisplay().getFocusControl() != this) + if (getDisplay().getFocusControl() != this) { selectedLink = null; + } for (Paragraph p : paragraphs) { p.computeSelection(gc, resourceTable, selectedLink, selData); } @@ -1315,8 +1350,9 @@ private void handleDrag(MouseEvent e) { } private void handleMouseClick(MouseEvent e, boolean down) { - if (DEBUG_FOCUS) + if (DEBUG_FOCUS) { System.out.println("FormText: mouse click(" + down + ")"); //$NON-NLS-1$ //$NON-NLS-2$ + } if (down) { // select a hyperlink mouseFocus = true; @@ -1339,7 +1375,9 @@ private void handleMouseClick(MouseEvent e, boolean down) { } else { if (e.button == 1) { endSelection(e); - if (isDisposed()) return; + if (isDisposed()) { + return; + } IHyperlinkSegment segmentUnder = model .findHyperlinkAt(e.x, e.y); if (segmentUnder != null && armed == segmentUnder && selData == null) { @@ -1362,8 +1400,9 @@ private void updateTooltipText(ParagraphSegment segment) { String currentTooltipText = getToolTipText(); if ((currentTooltipText != null && tooltipText == null) - || (currentTooltipText == null && tooltipText != null)) + || (currentTooltipText == null && tooltipText != null)) { setToolTipText(tooltipText); + } } private void handleMouseMove(MouseEvent e) { @@ -1380,8 +1419,7 @@ private void handleMouseMove(MouseEvent e) { entered = null; } setCursor(null); - } else if (segmentUnder instanceof IHyperlinkSegment) { - IHyperlinkSegment linkUnder = (IHyperlinkSegment) segmentUnder; + } else if (segmentUnder instanceof IHyperlinkSegment linkUnder) { if (entered!=null && linkUnder!=entered) { // Special case: links are so close that there are 0 pixels between. // Must exit the link before entering the next one. @@ -1401,43 +1439,52 @@ private void handleMouseMove(MouseEvent e) { paintLinkHover(entered, false); entered = null; } - if (segmentUnder instanceof TextSegment) + if (segmentUnder instanceof TextSegment) { setCursor(model.getHyperlinkSettings().getTextCursor()); - else + } else { setCursor(null); + } } } private boolean advance(boolean next) { - if (DEBUG_FOCUS) + if (DEBUG_FOCUS) { System.out.println("Advance: next=" + next); //$NON-NLS-1$ + } IFocusSelectable current = model.getSelectedSegment(); - if (current != null && current instanceof IHyperlinkSegment) + if (current != null && current instanceof IHyperlinkSegment) { exitLink((IHyperlinkSegment) current, SWT.NULL); + } IFocusSelectable newSegment = null; boolean valid = false; // get the next segment that can accept focus. Links // can always accept focus but controls may not while (!valid) { - if (!model.traverseFocusSelectableObjects(next)) + if (!model.traverseFocusSelectableObjects(next)) { break; + } newSegment = model.getSelectedSegment(); - if (newSegment == null) + if (newSegment == null) { break; + } valid = setControlFocus(next, newSegment); } - IHyperlinkSegment newLink = newSegment instanceof IHyperlinkSegment ? (IHyperlinkSegment) newSegment + IHyperlinkSegment newLink = newSegment instanceof IHyperlinkSegment i ? i : null; - if (valid) + if (valid) { enterLink(newLink, SWT.NULL); - IHyperlinkSegment oldLink = current instanceof IHyperlinkSegment ? (IHyperlinkSegment) current + } + IHyperlinkSegment oldLink = current instanceof IHyperlinkSegment i ? i : null; - if (oldLink != null || newLink != null) + if (oldLink != null || newLink != null) { paintFocusTransfer(oldLink, newLink); - if (newLink != null) + } + if (newLink != null) { ensureVisible(newLink); - if (newLink != null) + } + if (newLink != null) { getAccessible().setFocus(model.getSelectedSegmentIndex()); + } return !valid; } @@ -1460,15 +1507,18 @@ private void handleFocusChange() { boolean valid = false; IFocusSelectable selectable = null; while (!valid) { - if (!model.traverseFocusSelectableObjects(advance)) + if (!model.traverseFocusSelectableObjects(advance)) { break; + } selectable = model.getSelectedSegment(); - if (selectable == null) + if (selectable == null) { break; + } valid = setControlFocus(advance, selectable); } - if (selectable != null) + if (selectable != null) { ensureVisible(selectable); + } if (selectable instanceof IHyperlinkSegment) { enterLink((IHyperlinkSegment) selectable, SWT.NULL); paintFocusTransfer(null, (IHyperlinkSegment) selectable); @@ -1478,13 +1528,15 @@ private void handleFocusChange() { paintFocusTransfer(getSelectedLink(), null); model.selectLink(null); } - if (!model.hasFocusSegments()) + if (!model.hasFocusSegments()) { redraw(); + } } private void enterLink(IHyperlinkSegment link, int stateMask) { - if (link == null || listeners == null) + if (link == null || listeners == null) { return; + } HyperlinkEvent he = new HyperlinkEvent(this, link.getHref(), link .getText(), stateMask); for (IHyperlinkListener listener : listeners) { @@ -1493,8 +1545,9 @@ private void enterLink(IHyperlinkSegment link, int stateMask) { } private void exitLink(IHyperlinkSegment link, int stateMask) { - if (link == null || listeners == null) + if (link == null || listeners == null) { return; + } HyperlinkEvent he = new HyperlinkEvent(this, link.getHref(), link .getText(), stateMask); for (IHyperlinkListener listener : listeners) { @@ -1507,8 +1560,9 @@ private void paintLinkHover(IHyperlinkSegment link, boolean hover) { HyperlinkSettings settings = getHyperlinkSettings(); Color newFg = hover ? settings.getActiveForeground() : settings .getForeground(); - if (newFg != null) + if (newFg != null) { gc.setForeground(newFg); + } gc.setBackground(getBackground()); gc.setFont(getFont()); boolean selected = (link == getSelectedLink()); @@ -1519,8 +1573,9 @@ private void paintLinkHover(IHyperlinkSegment link, boolean hover) { private void activateSelectedLink() { IHyperlinkSegment link = getSelectedLink(); - if (link != null) + if (link != null) { activateLink(link, SWT.NULL); + } } private void activateLink(IHyperlinkSegment link, int stateMask) { @@ -1542,8 +1597,9 @@ private void activateLink(IHyperlinkSegment link, int stateMask) { private void ensureBoldFontPresent(Font regularFont) { Font boldFont = (Font) resourceTable.get(FormTextModel.BOLD_FONT_ID); - if (boldFont != null) + if (boldFont != null) { return; + } boldFont = FormFonts.getInstance().getBoldFont(getDisplay(), regularFont); resourceTable.put(FormTextModel.BOLD_FONT_ID, boldFont); } @@ -1619,12 +1675,14 @@ private void ensureVisible(IFocusSelectable segment) { mouseFocus = false; return; } - if (segment == null) + if (segment == null) { return; + } Rectangle bounds = segment.getBounds(); ScrolledComposite scomp = FormUtil.getScrolledComposite(this); - if (scomp == null) + if (scomp == null) { return; + } Point origin = FormUtil.getControlLocation(scomp, this); origin.x += bounds.x; origin.y += bounds.y; @@ -1651,8 +1709,9 @@ public Point computeSize(int wHint, int hHint, boolean changed) { size = new Point(wHint, hHint); } Rectangle trim = computeTrim(0, 0, size.x, size.y); - if (DEBUG_TEXTSIZE) + if (DEBUG_TEXTSIZE) { System.out.println("FormText Computed size: "+trim); //$NON-NLS-1$ + } return new Point(trim.width, trim.height); } @@ -1670,8 +1729,7 @@ private void disposeResourceTable(boolean disposeBoldFont) { String key = enm.nextElement(); if (key.startsWith(ImageSegment.SEL_IMAGE_PREFIX)) { Object obj = resourceTable.get(key); - if (obj instanceof Image) { - Image image = (Image) obj; + if (obj instanceof Image image) { if (!image.isDisposed()) { image.dispose(); imagesToRemove.add(key); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/FormToolkit.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/FormToolkit.java index efaf0eec532..c5676b5877b 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/FormToolkit.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/FormToolkit.java @@ -120,30 +120,35 @@ public void paintControl(PaintEvent event) { Control c = element; boolean inactiveBorder = false; boolean textBorder = false; - if (!c.isVisible()) + if (!c.isVisible()) { continue; + } /* * if (c.getEnabled() == false && !(c instanceof CCombo)) * continue; */ - if (c instanceof Hyperlink) + if (c instanceof Hyperlink) { continue; + } Object flag = c.getData(KEY_DRAW_BORDER); if (flag != null) { - if (flag.equals(Boolean.FALSE)) + if (flag.equals(Boolean.FALSE)) { continue; - if (flag.equals(TREE_BORDER)) + } + if (flag.equals(TREE_BORDER)) { inactiveBorder = true; - else if (flag.equals(TEXT_BORDER)) + } else if (flag.equals(TEXT_BORDER)) { textBorder = true; + } } if (getBorderStyle() == SWT.BORDER) { if (!inactiveBorder && !textBorder) { continue; } if (c instanceof Text || c instanceof Table - || c instanceof Tree) + || c instanceof Tree) { continue; + } } if (!inactiveBorder && (c instanceof Text || c instanceof CCombo || textBorder)) { @@ -155,12 +160,13 @@ else if (flag.equals(TEXT_BORDER)) // gc.setForeground(getBorderStyle() == SWT.BORDER ? colors // .getBorderColor() : colors.getForeground()); gc.setForeground(colors.getBorderColor()); - if (c instanceof CCombo) + if (c instanceof CCombo) { gc.drawRectangle(b.x - 1, b.y - 1, b.width + 1, b.height + 1); - else + } else { gc.drawRectangle(b.x - 1, b.y - 2, b.width + 1, b.height + 3); + } } else if (inactiveBorder || c instanceof Table || c instanceof Tree) { Rectangle b = c.getBounds(); @@ -202,8 +208,9 @@ private static class KeyboardHandler extends KeyAdapter { public void keyPressed(KeyEvent e) { Widget w = e.widget; if (w instanceof Control) { - if (e.doit) + if (e.doit) { FormUtil.processKey(e.keyCode, (Control) w); + } } } } @@ -288,8 +295,9 @@ public FormToolkit(FormColors colors) { public Button createButton(Composite parent, String text, int style) { checkDisposed(); Button button = new Button(parent, style | SWT.FLAT | orientation); - if (text != null) + if (text != null) { button.setText(text); + } adapt(button, true, true); return button; } @@ -334,17 +342,20 @@ public Composite createCompositeSeparator(Composite parent) { checkDisposed(); final Composite composite = new Composite(parent, orientation); composite.addListener(SWT.Paint, e -> { - if (composite.isDisposed()) + if (composite.isDisposed()) { return; + } Rectangle bounds = composite.getBounds(); GC gc = e.gc; gc.setForeground(colors.getColor(IFormColors.SEPARATOR)); - if (colors.getBackground() != null) + if (colors.getBackground() != null) { gc.setBackground(colors.getBackground()); + } gc.fillGradientRectangle(0, 0, bounds.width, bounds.height, false); }); - if (parent instanceof Section) + if (parent instanceof Section) { ((Section) parent).setSeparatorControl(composite); + } return composite; } @@ -375,8 +386,9 @@ public Label createLabel(Composite parent, String text) { public Label createLabel(Composite parent, String text, int style) { checkDisposed(); Label label = new Label(parent, style | orientation); - if (text != null) + if (text != null) { label.setText(text); + } adapt(label, false, false); return label; } @@ -396,8 +408,9 @@ public Label createLabel(Composite parent, String text, int style) { public Hyperlink createHyperlink(Composite parent, String text, int style) { checkDisposed(); Hyperlink hyperlink = new Hyperlink(parent, style | orientation); - if (text != null) + if (text != null) { hyperlink.setText(text); + } hyperlink.addFocusListener(visibilityHandler); hyperlink.addKeyListener(keyboardHandler); hyperlinkGroup.add(hyperlink); @@ -475,26 +488,31 @@ public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) { if (colors.getForeground() != null) { control.setForeground(colors.getForeground()); } - if (control instanceof ExpandableComposite) { - ExpandableComposite ec = (ExpandableComposite) control; + if (control instanceof ExpandableComposite ec) { if (ec.toggle != null) { - if (trackFocus) + if (trackFocus) { ec.toggle.addFocusListener(visibilityHandler); - if (trackKeyboard) + } + if (trackKeyboard) { ec.toggle.addKeyListener(keyboardHandler); + } } if (ec.textLabel != null) { - if (trackFocus) + if (trackFocus) { ec.textLabel.addFocusListener(visibilityHandler); - if (trackKeyboard) + } + if (trackKeyboard) { ec.textLabel.addKeyListener(keyboardHandler); + } } return; } - if (trackFocus) + if (trackFocus) { control.addFocusListener(visibilityHandler); - if (trackKeyboard) + } + if (trackKeyboard) { control.addKeyListener(keyboardHandler); + } } /** @@ -516,8 +534,9 @@ public void mouseDown(MouseEvent e) { } } }); - if (composite.getParent() != null) + if (composite.getParent() != null) { composite.setMenu(composite.getParent().getMenu()); + } } /** @@ -649,8 +668,9 @@ public Text createText(Composite parent, String value) { public Text createText(Composite parent, String value, int style) { checkDisposed(); Text text = new Text(parent, borderStyle | style | orientation); - if (value != null) + if (value != null) { text.setText(value); + } text.setForeground(colors.getForeground()); text.setBackground(colors.getBackground()); text.addFocusListener(visibilityHandler); @@ -847,8 +867,9 @@ public void paintBordersFor(Composite parent) { checkDisposed(); // if (borderStyle == SWT.BORDER) // return; - if (borderPainter == null) + if (borderPainter == null) { borderPainter = new BorderPainter(); + } parent.addPaintListener(borderPainter); } @@ -922,8 +943,9 @@ public void setBorderStyle(int style) { */ public static void setControlVisible(Control c, boolean verticalOnly) { ScrolledComposite scomp = FormUtil.getScrolledComposite(c); - if (scomp == null) + if (scomp == null) { return; + } Point location = FormUtil.getControlLocation(scomp, c); scomp.setOrigin(location); } @@ -946,10 +968,12 @@ && compareVersion(osversion, 5, 1) >= 0) { // (6.0)) // Check for Windows Classic. If not used, set the style to BORDER RGB rgb = colors.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); - if (rgb.red != 212 || rgb.green != 208 || rgb.blue != 200) + if (rgb.red != 212 || rgb.green != 208 || rgb.blue != 200) { borderStyle = SWT.BORDER; - } else if (osname.startsWith("Mac")) //$NON-NLS-1$ + } + } else if (osname.startsWith("Mac")) { //$NON-NLS-1$ borderStyle = SWT.BORDER; + } } private int compareVersion(String version, int... numbers) { @@ -957,17 +981,21 @@ private int compareVersion(String version, int... numbers) { scanner.useDelimiter("\\."); //$NON-NLS-1$ for (int number : numbers) { - if (!scanner.hasNextInt()) + if (!scanner.hasNextInt()) { return -1; + } int result = Integer.compare(scanner.nextInt(), number); - if (result != 0) + if (result != 0) { return result; + } } - while (scanner.hasNextInt()) - if (scanner.nextInt() > 0) + while (scanner.hasNextInt()) { + if (scanner.nextInt() > 0) { return 1; + } + } } return 0; diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Hyperlink.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Hyperlink.java index 462a9519089..06b29c4b2b1 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Hyperlink.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Hyperlink.java @@ -74,8 +74,9 @@ protected void initAccessible() { @Override public void getName(AccessibleEvent e) { e.result = getText(); - if (e.result == null) + if (e.result == null) { getHelp(e); + } } @Override @@ -119,8 +120,9 @@ public void getDefaultAction (AccessibleControlEvent e) { @Override public void getState(AccessibleControlEvent e) { int state = ACC.STATE_NORMAL; - if (Hyperlink.this.getSelection()) + if (Hyperlink.this.getSelection()) { state = ACC.STATE_SELECTED | ACC.STATE_FOCUSED; + } e.detail = state; } }); @@ -158,14 +160,16 @@ public Point computeSize(int wHint, int hHint, boolean changed) { int innerWidth = wHint; if (innerWidth != SWT.DEFAULT) { innerWidth -= marginWidth * 2; - if (innerWidth < 0) + if (innerWidth < 0) { innerWidth = 0; + } } int innerHeight = hHint; if (innerHeight != SWT.DEFAULT) { innerHeight -= marginHeight * 2; - if (innerHeight < 0) + if (innerHeight < 0) { innerHeight = 0; + } } Point textSize = computeTextSize(innerWidth, innerHeight); int textWidth = textSize.x + 2 * marginWidth; @@ -209,10 +213,11 @@ public void setToolTipText (String string) { * the hyperlink text */ public void setText(String text) { - if (text != null) + if (text != null) { this.text = text; - else + } else { this.text = ""; //$NON-NLS-1$ + } redraw(); } @@ -274,14 +279,20 @@ protected void paintText(GC gc, Rectangle bounds) { } protected String shortenText(GC gc, String t, int width) { - if (t == null) return null; + if (t == null) { + return null; + } int w = gc.textExtent(ELLIPSIS).x; - if (width<=w) return t; + if (width<=w) { + return t; + } int l = t.length(); int max = l/2; int min = 0; int mid = (max+min)/2 - 1; - if (mid <= 0) return t; + if (mid <= 0) { + return t; + } while (min < mid && mid < max) { String s1 = t.substring(0, mid); String s2 = t.substring(l-mid, l); @@ -297,7 +308,9 @@ protected String shortenText(GC gc, String t, int width) { min = max; } } - if (mid == 0) return t; + if (mid == 0) { + return t; + } return t.substring(0, mid)+ELLIPSIS+t.substring(l-mid, l); } @@ -309,8 +322,9 @@ protected Point computeTextSize(int wHint, int hHint) { extent = FormUtil.computeWrapSize(gc, getText(), wHint); } else { extent = gc.textExtent(getText()); - if ((getStyle() & SWT.WRAP)==0 && wHint!=SWT.DEFAULT) + if ((getStyle() & SWT.WRAP)==0 && wHint!=SWT.DEFAULT) { extent.x = wHint; + } } gc.dispose(); return extent; diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ImageHyperlink.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ImageHyperlink.java index c0dacb4af85..f3929589a58 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ImageHyperlink.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ImageHyperlink.java @@ -79,8 +79,9 @@ public ImageHyperlink(Composite parent, int style) { super(parent, removeAlignment(style)); extractAlignment(style); addDisposeListener(e -> { - if (disabledImage != null) + if (disabledImage != null) { disabledImage.dispose(); + } }); } @@ -96,12 +97,14 @@ protected void paintHyperlink(GC gc, Rectangle bounds) { image = disabledImage; } else { - if ((state & ACTIVE) != 0) + if ((state & ACTIVE) != 0) { image = activeImage; - else if ((state & HOVER) != 0) + } else if ((state & HOVER) != 0) { image = hoverImage; - if (image == null) + } + if (image == null) { image = this.image; + } } Rectangle ibounds = image != null ? image.getBounds() : new Rectangle(0, 0, 0, 0); Point maxsize = computeMaxImageSize(); @@ -113,18 +116,21 @@ else if ((state & HOVER) != 0) if (horizontalAlignment == SWT.LEFT) { int x = bounds.x+marginWidth + maxsize.x / 2 - ibounds.width / 2; int textX = bounds.x + marginWidth + maxsize.x + spacing; - if (image != null) + if (image != null) { gc.drawImage(image, x, y); - if (getText() != null) + } + if (getText() != null) { drawText(gc, bounds, textX, textWidth); + } } else if (horizontalAlignment == SWT.RIGHT) { int x = bounds.x+marginWidth; if (getText() != null) { x += drawText(gc, bounds, x, textWidth); } x += maxsize.x / 2 - ibounds.width / 2 + spacing; - if (image != null) + if (image != null) { gc.drawImage(image, x, y); + } } } @@ -185,10 +191,12 @@ public Point computeSize(int wHint, int hHint, boolean changed) { width += 2 * marginWidth; height += 2 * marginHeight; - if (wHint != SWT.DEFAULT) + if (wHint != SWT.DEFAULT) { width = wHint; - if (hHint != SWT.DEFAULT) + } + if (hHint != SWT.DEFAULT) { height = hHint; + } return new Point(width + trim.width, height + trim.height); } @@ -211,8 +219,9 @@ protected void handleActivate(Event e) { redraw(); super.handleActivate(e); state &= ~ACTIVE; - if (!isDisposed()) + if (!isDisposed()) { redraw(); + } } /** @@ -335,8 +344,9 @@ private void extractAlignment(int style) { @Override public void setEnabled(boolean enabled) { - if (!enabled) + if (!enabled) { createDisabledImage(); + } super.setEnabled(enabled); if (enabled && disabledImage != null) { disabledImage.dispose(); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledForm.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledForm.java index 20e2f17eeec..fd1be197d1e 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledForm.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledForm.java @@ -50,7 +50,7 @@ * @noextend This class is not intended to be subclassed by clients. */ public class ScrolledForm extends SharedScrolledComposite { - private Form content; + private final Form content; private boolean customMenu; @@ -71,8 +71,9 @@ public ScrolledForm(Composite parent, int style) { super.setContent(content); content.setMenu(getMenu()); addDisposeListener(e -> { - if (!customMenu) + if (!customMenu) { setMenu(null); + } }); } @@ -85,8 +86,9 @@ public ScrolledForm(Composite parent, int style) { public void setMenu(Menu menu) { customMenu = true; super.setMenu(menu); - if (content != null) + if (content != null) { content.setMenu(menu); + } } /** diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledFormText.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledFormText.java index 7df09cad2bb..c38b6d75ee8 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledFormText.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledFormText.java @@ -72,8 +72,9 @@ public ScrolledFormText(Composite parent, boolean createFormText) { */ public ScrolledFormText(Composite parent, int style, boolean createFormText) { super(parent, style); - if (createFormText) + if (createFormText) { setFormText(new FormText(this, SWT.NULL)); + } } /** * Sets the form text to be managed by this scrolled form text. The @@ -88,8 +89,9 @@ public void setFormText(FormText formText) { this.content = formText; super.setContent(content); content.setMenu(getMenu()); - if (text != null) + if (text != null) { loadText(text); + } } /** * Sets the foreground color of the scrolled form text. @@ -100,8 +102,9 @@ public void setFormText(FormText formText) { @Override public void setForeground(Color fg) { super.setForeground(fg); - if (content != null) + if (content != null) { content.setForeground(fg); + } } /** * Sets the background color of the scrolled form text. @@ -112,8 +115,9 @@ public void setForeground(Color fg) { @Override public void setBackground(Color bg) { super.setBackground(bg); - if (content != null) + if (content != null) { content.setBackground(bg); + } } /** * The class sets the content widget. This method should not be called by @@ -162,8 +166,9 @@ public FormText getFormText() { private void loadText(String text) { if (content != null) { String markup = text; - if (!markup.startsWith("
")) //$NON-NLS-1$ + if (!markup.startsWith("")) { //$NON-NLS-1$ markup = "" + text + "
"; //$NON-NLS-1$//$NON-NLS-2$ + } content.setText(markup, true, false); } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledPageBook.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledPageBook.java index 271bdd1434c..86fef0b2a2c 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledPageBook.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledPageBook.java @@ -29,8 +29,8 @@ * @since 3.0 */ public class ScrolledPageBook extends SharedScrolledComposite { - private WrappedPageBook pageBook; - private Hashtable pages; + private final WrappedPageBook pageBook; + private final Hashtable pages; private Composite emptyPage; private Control currentPage; @@ -164,8 +164,9 @@ public void removePage(Object key, boolean showEmptyPage) { if (page != null) { pages.remove(key); page.dispose(); - if (showEmptyPage) + if (showEmptyPage) { showEmptyPage(); + } } } /** @@ -181,8 +182,9 @@ public void showPage(Object key) { pageBook.showPage(page); if (currentPage != null && currentPage != page) { // switching pages - force layout - if (page instanceof Composite) + if (page instanceof Composite) { ((Composite) page).layout(false); + } } currentPage = page; } else { @@ -208,8 +210,9 @@ public void showEmptyPage() { */ @Override public boolean setFocus() { - if (currentPage != null) + if (currentPage != null) { return currentPage.setFocus(); + } return super.setFocus(); } /** diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Section.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Section.java index e2aa62bf8c7..c9992824501 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Section.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Section.java @@ -111,8 +111,9 @@ private static int getBackgroundStyle(int estyle) { protected void internalSetExpanded(boolean expanded) { super.internalSetExpanded(expanded); if ((getExpansionStyle() & TITLE_BAR) != 0) { - if (!expanded) + if (!expanded) { super.setBackgroundImage(null); + } } reflow(); } @@ -133,8 +134,9 @@ protected void reflow() { * @param description new description text; not null */ public void setDescription(String description) { - if (descriptionControl instanceof Label) + if (descriptionControl instanceof Label) { ((Label) descriptionControl).setText(description); + } } /** @@ -144,8 +146,9 @@ public void setDescription(String description) { * not used to create the control. */ public String getDescription() { - if (descriptionControl instanceof Label) + if (descriptionControl instanceof Label) { return ((Label) descriptionControl).getText(); + } return null; } @@ -184,8 +187,9 @@ public Control getSeparatorControl() { public void setBackground(Color bg) { super.setBackground(bg); if (descriptionControl != null - && (getExpansionStyle() & DESCRIPTION) != 0) + && (getExpansionStyle() & DESCRIPTION) != 0) { descriptionControl.setBackground(bg); + } } /** @@ -197,8 +201,9 @@ public void setBackground(Color bg) { @Override public void setForeground(Color fg) { super.setForeground(fg); - if (descriptionControl != null) + if (descriptionControl != null) { descriptionControl.setForeground(fg); + } } /** @@ -275,8 +280,9 @@ public void setTitleBarGradientBackground(Color color) { * @return the title bar border color */ public Color getTitleBarBorderColor() { - if (titleColors == null) + if (titleColors == null) { return null; + } return titleColors.get(COLOR_BORDER); } @@ -287,10 +293,12 @@ public Color getTitleBarBorderColor() { * @return the title bar gradient background */ public Color getTitleBarGradientBackground() { - if (titleColors == null) + if (titleColors == null) { return null; - if ((getExpansionStyle() & SHORT_TITLE_BAR) != 0) + } + if ((getExpansionStyle() & SHORT_TITLE_BAR) != 0) { return getBackground(); + } return titleColors.get(COLOR_GBG); } @@ -300,16 +308,19 @@ public Color getTitleBarGradientBackground() { * @return the title bar background */ public Color getTitleBarBackground() { - if (titleColors == null) + if (titleColors == null) { return null; + } return titleColors.get(COLOR_BG); } private void putTitleBarColor(String key, Color color) { - if (color == null) + if (color == null) { return; - if (titleColors == null) + } + if (titleColors == null) { titleColors = new Hashtable<>(); + } titleColors.put(key, color); } @@ -336,13 +347,16 @@ protected void onPaint(PaintEvent e) { int theight = 5; Point tsize = null; Point tcsize = null; - if (toggle != null) + if (toggle != null) { tsize = toggle.getSize(); - if (getTextClient() != null) + } + if (getTextClient() != null) { tcsize = getTextClient().getSize(); + } Point size = textLabel == null ? new Point(0, 0) : textLabel.getSize(); - if (tsize != null) + if (tsize != null) { theight += Math.max(theight, tsize.y); + } gradientheight = theight; if (tcsize != null) { theight = Math.max(theight, tcsize.y); @@ -353,8 +367,9 @@ protected void onPaint(PaintEvent e) { gradientheight += tvmargin + tvmargin; // Background - if (getBackgroundImage() == null) + if (getBackgroundImage() == null) { updateHeaderImage(bg, bounds, gradientheight, theight); + } iGc.setBackground(getBackground()); iGc.fillRectangle(bounds.x, bounds.y, width, height); drawBackground(iGc, bounds.x, bounds.y, width, theight - 2); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/SharedScrolledComposite.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/SharedScrolledComposite.java index 447ed187782..a4a3527f668 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/SharedScrolledComposite.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/SharedScrolledComposite.java @@ -46,7 +46,7 @@ public abstract class SharedScrolledComposite extends ScrolledComposite { private boolean expandVertical = false; - private SizeCache contentCache = new SizeCache(); + private final SizeCache contentCache = new SizeCache(); private boolean reflowPending = false; @@ -79,8 +79,9 @@ public SharedScrolledComposite(Composite parent, int style) { @Override public void setForeground(Color fg) { super.setForeground(fg); - if (getContent() != null) + if (getContent() != null) { getContent().setForeground(fg); + } } /** @@ -92,8 +93,9 @@ public void setForeground(Color fg) { @Override public void setBackground(Color bg) { super.setBackground(bg); - if (getContent() != null) + if (getContent() != null) { getContent().setBackground(bg); + } } /** @@ -103,8 +105,9 @@ public void setBackground(Color bg) { @Override public void setFont(Font font) { super.setFont(font); - if (getContent() != null) + if (getContent() != null) { getContent().setFont(font); + } } /** @@ -127,10 +130,11 @@ public void setContent(Control content) { public boolean setFocus() { boolean result; FormUtil.setFocusScrollingEnabled(this, false); - if (getContent() != null) + if (getContent() != null) { result = getContent().setFocus(); - else + } else { result = super.setFocus(); + } FormUtil.setFocusScrollingEnabled(this, true); return result; } @@ -170,8 +174,9 @@ public void setExpandVertical(boolean expand) { public void reflow(boolean flushCache) { Composite c = (Composite) getContent(); Rectangle clientArea = getClientArea(); - if (c == null) + if (c == null) { return; + } if (clientArea.width == getSize().x) { ScrollBar bar = getVerticalBar(); if (bar != null) { @@ -202,10 +207,11 @@ public void reflow(boolean flushCache) { // reduce vertical scroll increment if necessary ScrollBar vbar = getVerticalBar(); if (vbar != null) { - if (getClientArea().height - 5 < V_SCROLL_INCREMENT) + if (getClientArea().height - 5 < V_SCROLL_INCREMENT) { getVerticalBar().setIncrement(getClientArea().height - 5); - else + } else { getVerticalBar().setIncrement(V_SCROLL_INCREMENT); + } } ignoreLayouts = false; @@ -230,11 +236,13 @@ private void scheduleReflow(final boolean flushCache) { reflowPending = true; getDisplay().asyncExec(() -> { reflowPending = false; - if (!isDisposed()) + if (!isDisposed()) { reflow(flushCache); + } }); - } else + } else { reflow(flushCache); + } } private void initializeScrollBars() { diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/SizeCache.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/SizeCache.java index 1bfac11fe15..a817ee6d2d6 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/SizeCache.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/SizeCache.java @@ -382,9 +382,8 @@ static boolean independentLengthAndWidth(Control control) { * dimension. */ private void computeHintOffset(Control control) { - if (control instanceof Scrollable) { + if (control instanceof Scrollable scrollable) { // For scrollables, subtract off the trim size - Scrollable scrollable = (Scrollable) control; Rectangle trim = scrollable.computeTrim(0, 0, 0, 0); widthAdjustment = trim.width; diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/TableWrapData.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/TableWrapData.java index e4142e1fc0c..29d652d30aa 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/TableWrapData.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/TableWrapData.java @@ -185,25 +185,31 @@ public TableWrapData(int align, int valign) { */ public TableWrapData(int align, int valign, int rowspan, int colspan) { if (align != LEFT && align != CENTER && align != RIGHT && align != FILL - && align != FILL_GRAB) + && align != FILL_GRAB) { SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, " \"align\""); //$NON-NLS-1$ + } if (valign != TOP && valign != MIDDLE && valign != BOTTOM - && valign != FILL && valign != FILL_GRAB) + && valign != FILL && valign != FILL_GRAB) { SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, " \"valign\""); //$NON-NLS-1$ - if (rowspan < 1) + } + if (rowspan < 1) { SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, " \"rowspan\""); //$NON-NLS-1$ - if (colspan < 1) + } + if (colspan < 1) { SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, " \"colspan\""); //$NON-NLS-1$ + } if (align == FILL_GRAB) { this.align = FILL; grabHorizontal = true; - } else + } else { this.align = align; + } if (valign == FILL_GRAB) { this.valign = FILL; grabVertical = true; - } else + } else { this.valign = valign; + } this.rowspan = rowspan; this.colspan = colspan; } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/TableWrapLayout.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/TableWrapLayout.java index b6fd0d9816f..4fabfee7dde 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/TableWrapLayout.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/TableWrapLayout.java @@ -108,7 +108,7 @@ public final class TableWrapLayout extends Layout implements ILayoutExtension { private int[] growingRows; - private LayoutCache cache = new LayoutCache(); + private final LayoutCache cache = new LayoutCache(); private class RowSpan { Control child; @@ -133,14 +133,16 @@ public void update(int currentRow, int rowHeight) { // is currentRow within this span? if (currentRow >= row && currentRow < row + td.rowspan) { totalHeight += rowHeight; - if (currentRow > row) + if (currentRow > row) { totalHeight += verticalSpacing; + } } } public int getRequiredHeightIncrease() { - if (totalHeight < height) + if (totalHeight < height) { return height - totalHeight; + } return 0; } } @@ -171,8 +173,9 @@ public int computeMinimumWidth(Composite parent, boolean changed) { grid = new ArrayList<>(); createGrid(parent); } - if (minColumnWidths == null) + if (minColumnWidths == null) { minColumnWidths = new int[numColumns]; + } for (int i = 0; i < numColumns; i++) { minColumnWidths[i] = 0; } @@ -204,8 +207,9 @@ public int computeMaximumWidth(Composite parent, boolean changed) { grid = new ArrayList<>(); createGrid(parent); } - if (maxColumnWidths == null) + if (maxColumnWidths == null) { maxColumnWidths = new int[numColumns]; + } for (int i = 0; i < numColumns; i++) { maxColumnWidths[i] = 0; } @@ -224,8 +228,9 @@ protected void layout(Composite parent, boolean changed) { cache.flush(); } - if (children.length == 0) + if (children.length == 0) { return; + } cache.setControls(children); @@ -253,8 +258,9 @@ protected void layout(Composite parent, boolean changed) { for (int i = 0; i < numColumns; i++) { columnWidths[i] = widestColumnWidth; } - } else + } else { columnWidths = minColumnWidths; + } } else if (parentWidth > maxWidth) { if (growingColumns.length == 0) { tableWidth = maxWidth; @@ -296,8 +302,9 @@ protected void layout(Composite parent, boolean changed) { placeControl(child, td, x, y, rowHeights, i); } x += columnWidths[j]; - if (j < numColumns - 1) + if (j < numColumns - 1) { x += horizontalSpacing; + } } y += rowHeight + verticalSpacing; } @@ -319,8 +326,9 @@ int[] computeRowHeights(Control[] children, int[] columnWidths, int cwidth = 0; for (int k = j; k < j + span; k++) { cwidth += columnWidths[k]; - if (k < j + span - 1) + if (k < j + span - 1) { cwidth += horizontalSpacing; + } } Point size = FormUtil.computeControlSize(cache.getCache(td.childIndex), cwidth - td.indent, td.maxWidth, td.maxHeight, isFillAligned(child)); @@ -333,16 +341,18 @@ int[] computeRowHeights(Control[] children, int[] columnWidths, RowSpan rowspan = rowspans.get(child); if (rowspan == null) { rowHeights[i] = Math.max(rowHeights[i], size.y); - } else + } else { rowspan.height = size.y; + } } updateRowSpans(i, rowHeights[i]); } for (Enumeration enm = rowspans.elements(); enm.hasMoreElements();) { RowSpan rowspan = enm.nextElement(); int increase = rowspan.getRequiredHeightIncrease(); - if (increase == 0) + if (increase == 0) { continue; + } TableWrapData td = (TableWrapData) rowspan.child.getLayoutData(); int ngrowing = 0; int[] affectedRows = new int[grid.size()]; @@ -367,11 +377,13 @@ int[] computeRowHeights(Control[] children, int[] columnWidths, } boolean isGrowingColumn(int col) { - if (growingColumns == null) + if (growingColumns == null) { return false; + } for (int growingColumn : growingColumns) { - if (col == growingColumn) + if (col == growingColumn) { return true; + } } return false; } @@ -411,8 +423,9 @@ void placeControl(Control control, TableWrapData td, int x, int y, if (rowspan != null) { slotHeight = 0; for (int i = row; i < row + td.rowspan; i++) { - if (i > row) + if (i > row) { slotHeight += verticalSpacing; + } slotHeight += rowHeights[i]; } } @@ -450,8 +463,9 @@ void createGrid(Composite composite) { rowspans = new Hashtable<>(); // children = composite.getChildren(); - if (children.length == 0) + if (children.length == 0) { return; + } // grid.add(createEmptyRow()); row = 0; @@ -549,8 +563,9 @@ private void updateGrowingColumns(ArrayList growingColumns, TableWrapData spec, int column) { int affectedColumn = column + spec.colspan - 1; for (Integer col : growingColumns) { - if (col.intValue() == affectedColumn) + if (col.intValue() == affectedColumn) { return; + } } growingColumns.add(Integer.valueOf(affectedColumn)); } @@ -559,16 +574,18 @@ private void updateGrowingRows(ArrayList growingRows, TableWrapData spe int row) { int affectedRow = row + spec.rowspan - 1; for (Integer irow : growingRows) { - if (irow.intValue() == affectedRow) + if (irow.intValue() == affectedRow) { return; + } } growingRows.add(Integer.valueOf(affectedRow)); } private TableWrapData[] createEmptyRow() { TableWrapData[] row = new TableWrapData[numColumns]; - for (int i = 0; i < numColumns; i++) + for (int i = 0; i < numColumns; i++) { row[i] = null; + } return row; } @@ -603,8 +620,9 @@ protected Point computeSize(Composite parent, int wHint, int hHint, int minWidth = internalGetMinimumWidth(parent, changed); int maxWidth = internalGetMaximumWidth(parent, changed); - if (wHint == SWT.DEFAULT) + if (wHint == SWT.DEFAULT) { parentWidth = maxWidth; + } int tableWidth = parentWidth; int[] columnWidths; @@ -615,8 +633,9 @@ protected Point computeSize(Composite parent, int wHint, int hHint, for (int i = 0; i < numColumns; i++) { columnWidths[i] = widestColumnWidth; } - } else + } else { columnWidths = minColumnWidths; + } } else if (parentWidth >= maxWidth) { if (makeColumnsEqualWidth) { columnWidths = new int[numColumns]; @@ -658,8 +677,9 @@ protected Point computeSize(Composite parent, int wHint, int hHint, int span = td.colspan; int cwidth = 0; for (int k = j; k < j + span; k++) { - if (k > j) + if (k > j) { cwidth += horizontalSpacing; + } cwidth += columnWidths[k]; } int cy = td.heightHint; @@ -679,19 +699,22 @@ protected Point computeSize(Composite parent, int wHint, int hHint, } } updateRowSpans(i, rowHeight); - if (i > 0) + if (i > 0) { innerHeight += verticalSpacing; + } innerHeight += rowHeight; } - if (!rowspans.isEmpty()) + if (!rowspans.isEmpty()) { innerHeight = compensateForRowSpans(innerHeight); + } int totalHeight = topMargin + innerHeight + bottomMargin; return new Point(tableWidth, totalHeight); } private void updateRowSpans(int row, int rowHeight) { - if (rowspans == null || rowspans.isEmpty()) + if (rowspans == null || rowspans.isEmpty()) { return; + } for (Enumeration enm = rowspans.elements(); enm.hasMoreElements();) { RowSpan rowspan = enm.nextElement(); rowspan.update(row, rowHeight); @@ -707,9 +730,10 @@ private int compensateForRowSpans(int totalHeight) { } int internalGetMinimumWidth(Composite parent, boolean changed) { - if (changed) + if (changed) { //calculateMinimumColumnWidths(parent, true); calculateColumnWidths(parent, minColumnWidths, false, true, makeColumnsEqualWidth); + } int minimumWidth = 0; widestColumnWidth = 0; if (makeColumnsEqualWidth) { @@ -719,12 +743,14 @@ int internalGetMinimumWidth(Composite parent, boolean changed) { } } for (int i = 0; i < numColumns; i++) { - if (i > 0) + if (i > 0) { minimumWidth += horizontalSpacing; - if (makeColumnsEqualWidth) + } + if (makeColumnsEqualWidth) { minimumWidth += widestColumnWidth; - else + } else { minimumWidth += minColumnWidths[i]; + } } // add margins minimumWidth += leftMargin + rightMargin; @@ -732,13 +758,15 @@ int internalGetMinimumWidth(Composite parent, boolean changed) { } int internalGetMaximumWidth(Composite parent, boolean changed) { - if (changed) + if (changed) { //calculateMaximumColumnWidths(parent, true); calculateColumnWidths(parent, maxColumnWidths, true, true, makeColumnsEqualWidth); + } int maximumWidth = 0; for (int i = 0; i < numColumns; i++) { - if (i > 0) + if (i > 0) { maximumWidth += horizontalSpacing; + } maximumWidth += maxColumnWidths[i]; } // add margins @@ -747,10 +775,12 @@ int internalGetMaximumWidth(Composite parent, boolean changed) { } void resetColumnWidths() { - if (minColumnWidths == null) + if (minColumnWidths == null) { minColumnWidths = new int[numColumns]; - if (maxColumnWidths == null) + } + if (maxColumnWidths == null) { maxColumnWidths = new int[numColumns]; + } for (int i = 0; i < numColumns; i++) { minColumnWidths[i] = 0; } @@ -780,8 +810,9 @@ void calculateColumnWidths(Composite parent, int [] columnWidths, boolean max, b SizeCache childCache = cache.getCache(td.childIndex); // !! int width = max?childCache.computeMaximumWidth():childCache.computeMinimumWidth(); - if (td.maxWidth!=SWT.DEFAULT) + if (td.maxWidth!=SWT.DEFAULT) { width = Math.min(width, td.maxWidth); + } width += td.indent; columnWidths[j] = Math.max(columnWidths[j], width); @@ -793,7 +824,9 @@ void calculateColumnWidths(Composite parent, int [] columnWidths, boolean max, b columnWidths[i] = widestColumnWidth; } } - if (!secondPassNeeded) return; + if (!secondPassNeeded) { + return; + } // Second pass for controls with multi-column horizontal span for (TableWrapData[] row : grid) { @@ -805,8 +838,9 @@ void calculateColumnWidths(Composite parent, int [] columnWidths, boolean max, b SizeCache childCache = cache.getCache(td.childIndex); int width = max?childCache.computeMaximumWidth():childCache.computeMinimumWidth(); - if (td.maxWidth!=SWT.DEFAULT) + if (td.maxWidth!=SWT.DEFAULT) { width = Math.min(width, td.maxWidth); + } width += td.indent; // check if the current width is enough to @@ -814,8 +848,9 @@ void calculateColumnWidths(Composite parent, int [] columnWidths, boolean max, b // the last column or to all the growing columns, if present int current = 0; for (int k = j; k < j + td.colspan; k++) { - if (k > j) + if (k > j) { current += horizontalSpacing; + } current += columnWidths[k]; } if (width <= current) { @@ -837,11 +872,13 @@ void calculateColumnWidths(Composite parent, int [] columnWidths, boolean max, b // distribute the delta to the growing // columns int percolumn = (width - current) / ndiv; - if ((width - current) % ndiv > 0) + if ((width - current) % ndiv > 0) { percolumn++; + } for (int k = j; k < j + td.colspan; k++) { - if (isGrowingColumn(k)) + if (isGrowingColumn(k)) { columnWidths[k] += percolumn; + } } } } @@ -852,22 +889,22 @@ void calculateColumnWidths(Composite parent, int [] columnWidths, boolean max, b boolean isFillAligned(Control control) { Object layoutData = control.getLayoutData(); - if (layoutData instanceof TableWrapData) { - TableWrapData tableWrapData = (TableWrapData) layoutData; - + if (layoutData instanceof TableWrapData tableWrapData) { if (tableWrapData.align == TableWrapData.FILL) { return true; } } if (control instanceof Composite - && ((Composite) control).getLayout() instanceof ILayoutExtension) + && ((Composite) control).getLayout() instanceof ILayoutExtension) { return true; + } return (control.getStyle() & SWT.WRAP) != 0; } private void initializeIfNeeded(Composite parent, boolean changed) { - if (changed) + if (changed) { initialLayout = true; + } if (initialLayout) { initializeLayoutData(parent); initialLayout = false; diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ToggleHyperlink.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ToggleHyperlink.java index a4017a351af..f1734d6e580 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ToggleHyperlink.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ToggleHyperlink.java @@ -148,10 +148,12 @@ public Color geHoverDecorationColor() { public Point computeSize(int wHint, int hHint, boolean changed) { int width = innerWidth + 2 * marginWidth; int height = innerHeight + 2 * marginHeight; - if (wHint != SWT.DEFAULT) + if (wHint != SWT.DEFAULT) { width = wHint; - if (hHint != SWT.DEFAULT) + } + if (hHint != SWT.DEFAULT) { height = hHint; + } Rectangle trim = computeTrim(0, 0, width, height); return new Point(trim.width, trim.height); @@ -210,14 +212,16 @@ public void getLocation(AccessibleControlEvent e) { } @Override public void getSelection (AccessibleControlEvent e) { - if (ToggleHyperlink.this.getSelection()) + if (ToggleHyperlink.this.getSelection()) { e.childID = ACC.CHILDID_SELF; + } } @Override public void getFocus (AccessibleControlEvent e) { - if (ToggleHyperlink.this.getSelection()) + if (ToggleHyperlink.this.getSelection()) { e.childID = ACC.CHILDID_SELF; + } } @Override public void getChildCount(AccessibleControlEvent e) { diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Twistie.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Twistie.java index 7bdf084b1db..e6a6d97ffa4 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Twistie.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Twistie.java @@ -64,23 +64,25 @@ protected void paintHyperlink(GC gc) { int as = gc.getAntialias(); gc.setAntialias(SWT.ON); Color bg; - if (!isEnabled()) + if (!isEnabled()) { bg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); - else if (hover && getHoverDecorationColor() != null) + } else if (hover && getHoverDecorationColor() != null) { bg = getHoverDecorationColor(); - else if (getDecorationColor() != null) + } else if (getDecorationColor() != null) { bg = getDecorationColor(); - else + } else { bg = getForeground(); + } gc.setBackground(bg); int[] data; Point size = getSize(); int x = (size.x - 9) / 2; int y = (size.y - 9) / 2; - if (isExpanded()) + if (isExpanded()) { data = translate(onPoints, x, y); - else + } else { data = translate(offPoints, x, y); + } gc.fillPolygon(data); gc.setBackground(getBackground()); gc.setAntialias(as); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/MessageManager.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/MessageManager.java index baecbf28092..7558a7fd30d 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/MessageManager.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/MessageManager.java @@ -46,12 +46,12 @@ public class MessageManager implements IMessageManager { private static final DefaultPrefixProvider DEFAULT_PREFIX_PROVIDER = new DefaultPrefixProvider(); - private ArrayList messages = new ArrayList<>(); + private final ArrayList messages = new ArrayList<>(); private ArrayList oldMessages; - private Hashtable decorators = new Hashtable<>(); + private final Hashtable decorators = new Hashtable<>(); private Hashtable oldDecorators; private boolean autoUpdate = true; - private Form form; + private final Form form; private IMessagePrefixProvider prefixProvider = DEFAULT_PREFIX_PROVIDER; private int decorationPosition = SWT.LEFT | SWT.BOTTOM; private static FieldDecoration standardError = FieldDecorationRegistry @@ -129,9 +129,9 @@ public String getPrefix() { @Override public boolean equals(Object obj) { - if (!(obj instanceof Message)) + if (!(obj instanceof Message msg)) { return false; - Message msg = (Message) obj; + } return (msg.getPrefix() == null ? getPrefix() == null : msg.getPrefix().equals(getPrefix())) && (msg.getControl() == null ? getControl() == null : msg.getControl().equals(getControl())) && (msg.getMessageType() == getMessageType()) && @@ -161,8 +161,9 @@ public String getPrefix(Control c) { ltext = ((CLabel) label).getText(); } if (ltext != null) { - if (!ltext.endsWith(":")) //$NON-NLS-1$ + if (!ltext.endsWith(":")) { //$NON-NLS-1$ return ltext + ": "; //$NON-NLS-1$ + } return ltext + " "; //$NON-NLS-1$ } } @@ -175,7 +176,7 @@ public String getPrefix(Control c) { class ControlDecorator { private ControlDecoration decoration; - private ArrayList controlMessages = new ArrayList<>(); + private final ArrayList controlMessages = new ArrayList<>(); private String prefix; ControlDecorator(Control control) { @@ -206,8 +207,9 @@ void updatePosition() { } String getPrefix() { - if (prefix == null) + if (prefix == null) { createPrefix(); + } return prefix; } @@ -217,9 +219,10 @@ private void createPrefix() { return; } prefix = prefixProvider.getPrefix(decoration.getControl()); - if (prefix == null) + if (prefix == null) { // make a prefix anyway prefix = ""; //$NON-NLS-1$ + } } void addAll(ArrayList target) { @@ -230,26 +233,30 @@ void addMessage(Object key, String text, Object data, int type) { Message message = MessageManager.this.addMessage(getPrefix(), key, text, data, type, controlMessages); message.control = decoration.getControl(); - if (isAutoUpdate()) + if (isAutoUpdate()) { update(); + } } boolean removeMessage(Object key) { Message message = findMessage(key, controlMessages); if (message != null) { controlMessages.remove(message); - if (isAutoUpdate()) + if (isAutoUpdate()) { update(); + } } return message != null; } boolean removeMessages() { - if (controlMessages.isEmpty()) + if (controlMessages.isEmpty()) { return false; + } controlMessages.clear(); - if (isAutoUpdate()) + if (isAutoUpdate()) { update(); + } return true; } @@ -261,12 +268,13 @@ public void update() { ArrayList peers = createPeers(controlMessages); int type = peers.get(0).getMessageType(); String description = createDetails(createPeers(peers), true); - if (type == IMessageProvider.ERROR) + if (type == IMessageProvider.ERROR) { decoration.setImage(standardError.getImage()); - else if (type == IMessageProvider.WARNING) + } else if (type == IMessageProvider.WARNING) { decoration.setImage(standardWarning.getImage()); - else if (type == IMessageProvider.INFORMATION) + } else if (type == IMessageProvider.INFORMATION) { decoration.setImage(standardInformation.getImage()); + } decoration.setDescriptionText(description); decoration.show(); } @@ -274,19 +282,22 @@ else if (type == IMessageProvider.INFORMATION) @Override public boolean equals(Object obj) { - if (!(obj instanceof ControlDecorator)) + if (!(obj instanceof ControlDecorator cd)) { return false; - ControlDecorator cd = (ControlDecorator) obj; - if (!cd.decoration.equals(decoration)) + } + if (!cd.decoration.equals(decoration)) { return false; + } return cd.getPrefix().equals(getPrefix()); } boolean hasSameMessages(ControlDecorator cd) { - if (cd.controlMessages.size() != controlMessages.size()) + if (cd.controlMessages.size() != controlMessages.size()) { return false; - if (!cd.controlMessages.containsAll(controlMessages)) + } + if (!cd.controlMessages.containsAll(controlMessages)) { return false; + } return true; } } @@ -317,8 +328,9 @@ public MessageManager(Form form) { @Override public void addMessage(Object key, String messageText, Object data, int type) { addMessage(null, key, messageText, data, type, messages); - if (isAutoUpdate()) + if (isAutoUpdate()) { updateForm(); + } } @Override @@ -331,8 +343,9 @@ public void addMessage(Object key, String messageText, Object data, decorators.put(control, dec); } dec.addMessage(key, messageText, data, type); - if (isAutoUpdate()) + if (isAutoUpdate()) { updateForm(); + } } @Override @@ -340,8 +353,9 @@ public void removeMessage(Object key) { Message message = findMessage(key, messages); if (message != null) { messages.remove(message); - if (isAutoUpdate()) + if (isAutoUpdate()) { updateForm(); + } } } @@ -349,19 +363,23 @@ public void removeMessage(Object key) { public void removeMessages() { if (!messages.isEmpty()) { messages.clear(); - if (isAutoUpdate()) + if (isAutoUpdate()) { updateForm(); + } } } @Override public void removeMessage(Object key, Control control) { ControlDecorator dec = decorators.get(control); - if (dec == null) + if (dec == null) { return; - if (dec.removeMessage(key)) - if (isAutoUpdate()) + } + if (dec.removeMessage(key)) { + if (isAutoUpdate()) { updateForm(); + } + } } @Override @@ -369,8 +387,9 @@ public void removeMessages(Control control) { ControlDecorator dec = decorators.get(control); if (dec != null) { if (dec.removeMessages()) { - if (isAutoUpdate()) + if (isAutoUpdate()) { updateForm(); + } } } } @@ -380,15 +399,17 @@ public void removeAllMessages() { boolean needsUpdate = false; for (Enumeration enm = decorators.elements(); enm.hasMoreElements();) { ControlDecorator control = enm.nextElement(); - if (control.removeMessages()) + if (control.removeMessages()) { needsUpdate = true; + } } if (!messages.isEmpty()) { messages.clear(); needsUpdate = true; } - if (needsUpdate && isAutoUpdate()) + if (needsUpdate && isAutoUpdate()) { updateForm(); + } } /* @@ -414,8 +435,9 @@ private Message addMessage(String prefix, Object key, String messageText, */ private Message findMessage(Object key, ArrayList list) { for (Message message : list) { - if (message.getKey().equals(key)) + if (message.getKey().equals(key)) { return message; + } } return null; } @@ -464,19 +486,21 @@ private void update(ArrayList mergedList) { } else { // show a summary message for the message // and list of errors for the details - if (peers.size() > 1) + if (peers.size() > 1) { messageText = NLS.bind( MULTIPLE_MESSAGE_SUMMARY_KEYS[maxType], new String[] { Integer.toString(peers.size()) }); - else + } else { messageText = SINGLE_MESSAGE_SUMMARY_KEYS[maxType]; + } form.setMessage(messageText, maxType, array); } } private static String getFullMessage(IMessage message) { - if (message.getPrefix() == null) + if (message.getPrefix() == null) { return message.getMessage(); + } return message.getPrefix() + message.getMessage(); } @@ -489,8 +513,9 @@ private ArrayList createPeers(ArrayList messages) { peers.clear(); maxType = message.type; } - if (message.type == maxType) + if (message.type == maxType) { peers.add(message); + } } return peers; } @@ -500,8 +525,9 @@ private String createDetails(ArrayList messages, boolean excludePrefix) PrintWriter out = new PrintWriter(sw); for (int i = 0; i < messages.size(); i++) { - if (i > 0) + if (i > 0) { out.println(); + } IMessage m = messages.get(i); out.print(excludePrefix ? m.getMessage() : getFullMessage(m)); } @@ -510,14 +536,16 @@ private String createDetails(ArrayList messages, boolean excludePrefix) } public static String createDetails(IMessage[] messages) { - if (messages == null || messages.length == 0) + if (messages == null || messages.length == 0) { return null; + } StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); for (int i = 0; i < messages.length; i++) { - if (i > 0) + if (i > 0) { out.println(); + } out.print(getFullMessage(messages[i])); } out.flush(); @@ -532,8 +560,9 @@ public String createSummary(IMessage[] messages) { private void pruneControlDecorators() { for (Iterator iter = decorators.values().iterator(); iter.hasNext();) { ControlDecorator dec = iter.next(); - if (dec.isDisposed()) + if (dec.isDisposed()) { iter.remove(); + } } } @@ -573,12 +602,14 @@ public void setAutoUpdate(boolean autoUpdate) { boolean needsCaching = this.autoUpdate && !autoUpdate; boolean needsUpdate = !this.autoUpdate && autoUpdate; this.autoUpdate = autoUpdate; - if (needsUpdate && isCacheChanged()) + if (needsUpdate && isCacheChanged()) { update(); + } if (needsCaching) { oldMessages = new ArrayList<>(); - for (Message message : messages) + for (Message message : messages) { oldMessages.add(new Message(message)); + } oldDecorators = new Hashtable<>(); for (Enumeration e = decorators.keys(); e.hasMoreElements();) { Object key = e.nextElement(); @@ -597,23 +628,28 @@ private boolean isCacheChanged() { } private boolean checkMessageCache() { - if (oldMessages == null) + if (oldMessages == null) { return false; - if (messages.size() != oldMessages.size()) + } + if (messages.size() != oldMessages.size()) { return true; - if (!oldMessages.containsAll(messages)) + } + if (!oldMessages.containsAll(messages)) { return true; + } return false; } private boolean checkDecoratorCache() { - if (oldDecorators == null) + if (oldDecorators == null) { return false; + } for (Entry next : decorators.entrySet()) { ControlDecorator cd = next.getValue(); ControlDecorator oldCd = oldDecorators.get(cd.decoration.getControl()); - if ((oldCd == null && cd.controlMessages.size() > 0) || (oldCd != null && !cd.hasSameMessages(oldCd))) + if ((oldCd == null && cd.controlMessages.size() > 0) || (oldCd != null && !cd.hasSameMessages(oldCd))) { return true; + } } return false; } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/dom/FormElement.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/dom/FormElement.java index 55d0695e393..2ec2c160550 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/dom/FormElement.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/dom/FormElement.java @@ -24,7 +24,7 @@ import org.eclipse.ui.forms.widgets.Form; public class FormElement extends CompositeElement { - private Map headerColors = new HashMap<>(); + private final Map headerColors = new HashMap<>(); private static final String[] headerColorKeys = { IFormColors.H_BOTTOM_KEYLINE1, IFormColors.H_BOTTOM_KEYLINE2, IFormColors.H_GRADIENT_END, IFormColors.H_GRADIENT_START, IFormColors.H_HOVER_FULL, IFormColors.H_HOVER_LIGHT, IFormColors.H_PREFIX }; diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/properties/css2/CSSPropertyFormHandler.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/properties/css2/CSSPropertyFormHandler.java index 16ddf15adb5..34e96e4b338 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/properties/css2/CSSPropertyFormHandler.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/properties/css2/CSSPropertyFormHandler.java @@ -57,11 +57,10 @@ public class CSSPropertyFormHandler extends AbstractCSSPropertySWTHandler { @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof Form)) { + if (!(control instanceof Form form)) { return; } - Form form = (Form) control; if (TEXT_BACKGROUND_COLOR.equals(property)) { if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { Color color = (Color) engine.convert(value, Color.class, form.getDisplay()); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/AggregateHyperlinkSegment.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/AggregateHyperlinkSegment.java index 9b6f2c18de6..07db261e024 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/AggregateHyperlinkSegment.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/AggregateHyperlinkSegment.java @@ -28,7 +28,7 @@ public class AggregateHyperlinkSegment extends ParagraphSegment implements IHyperlinkSegment { private String href; - private Vector segments = new Vector<>(); + private final Vector segments = new Vector<>(); public AggregateHyperlinkSegment() { } @@ -47,8 +47,9 @@ public boolean advanceLocator(GC gc, int wHint, Locator loc, boolean newLine = false; for (ParagraphSegment segment : segments) { if (segment.advanceLocator(gc, wHint, loc, objectTable, - computeHeightOnly)) + computeHeightOnly)) { newLine = true; + } } return newLine; } @@ -99,8 +100,9 @@ public void paintFocus(GC gc, Color bg, Color fg, boolean selected, @Override public Rectangle getBounds() { - if (segments.isEmpty()) + if (segments.isEmpty()) { return new Rectangle(Integer.MAX_VALUE, Integer.MAX_VALUE, 0, 0); + } IHyperlinkSegment segment0 = (IHyperlinkSegment) segments.get(0); Rectangle bounds = segment0.getBounds(); @@ -116,8 +118,9 @@ public Rectangle getBounds() { public boolean contains(int x, int y) { for (ParagraphSegment psegment : segments) { IHyperlinkSegment segment = (IHyperlinkSegment) psegment; - if (segment.contains(x, y)) + if (segment.contains(x, y)) { return true; + } } return false; } @@ -126,8 +129,9 @@ public boolean contains(int x, int y) { public boolean intersects(Rectangle rect) { for (ParagraphSegment psegment : segments) { IHyperlinkSegment segment = (IHyperlinkSegment) psegment; - if (segment.intersects(rect)) + if (segment.intersects(rect)) { return true; + } } return false; } @@ -157,8 +161,9 @@ public void clearCache(String fontId) { @Override public String getTooltipText() { - if (segments.size() > 0) + if (segments.size() > 0) { return segments.get(0).getTooltipText(); + } return super.getTooltipText(); } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BreakSegment.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BreakSegment.java index 89e997079a1..628f6c01f6a 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BreakSegment.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BreakSegment.java @@ -33,7 +33,9 @@ public boolean advanceLocator(GC gc, int wHint, Locator locator, FontMetrics fm = gc.getFontMetrics(); locator.rowHeight = fm.getHeight(); } - if (computeHeightOnly) locator.collectHeights(); + if (computeHeightOnly) { + locator.collectHeights(); + } locator.resetCaret(); locator.width = locator.x; locator.y += locator.rowHeight; diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BulletParagraph.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BulletParagraph.java index d9feb38b920..c6bf6c93796 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BulletParagraph.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BulletParagraph.java @@ -32,9 +32,9 @@ public class BulletParagraph extends Paragraph { private String text; - private int CIRCLE_DIAM = 5; + private final int CIRCLE_DIAM = 5; - private int SPACING = 10; + private final int SPACING = 10; private int indent = -1; @@ -52,8 +52,9 @@ public BulletParagraph(boolean addVerticalSpace) { @Override public int getIndent() { int ivalue = indent; - if (ivalue != -1) + if (ivalue != -1) { return ivalue; + } switch (style) { case CIRCLE: ivalue = CIRCLE_DIAM + SPACING; @@ -66,8 +67,9 @@ public int getIndent() { } public int getBulletIndent() { - if (bindent != -1) + if (bindent != -1) { return bindent; + } return 0; } @@ -137,8 +139,9 @@ private void layoutBullet(GC gc, Locator loc, int lineHeight, public void paintBullet(GC gc, Rectangle repaintRegion, Hashtable resourceTable) { - if (bbounds == null) + if (bbounds == null) { return; + } int x = bbounds.x; int y = bbounds.y; if (repaintRegion != null) { @@ -156,8 +159,9 @@ public void paintBullet(GC gc, Rectangle repaintRegion, gc.drawText(text, x, y); } else if (style == IMAGE && text != null) { Image image = (Image) resourceTable.get(text); - if (image != null) + if (image != null) { gc.drawImage(image, x, y); + } } } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BusyIndicator.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BusyIndicator.java index 41acc160492..75c5222f223 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BusyIndicator.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/BusyIndicator.java @@ -60,11 +60,17 @@ public BusyIndicator(Composite parent, int style) { timer = new Runnable() { @Override public void run () { - if (isDisposed()) return; + if (isDisposed()) { + return; + } redraw(); - if (!BusyIndicator.this.busy) return; + if (!BusyIndicator.this.busy) { + return; + } update(); - if (isDisposed()) return; + if (isDisposed()) { + return; + } imageIndex = (imageIndex + 1) % IMAGE_COUNT; dpy.timerExec(MILLISECONDS_OF_DELAY, this); } @@ -120,8 +126,9 @@ public boolean isBusy() { */ void onPaint(PaintEvent event) { Rectangle rect = getClientArea(); - if (rect.width == 0 || rect.height == 0) + if (rect.width == 0 || rect.height == 0) { return; + } Image activeImage; if (isBusy()) { @@ -146,7 +153,9 @@ void onPaint(PaintEvent event) { * boolean */ public synchronized void setBusy(boolean busy) { - if (this.busy == busy) return; + if (this.busy == busy) { + return; + } this.busy = busy; imageIndex = 0; dpy.asyncExec(timer); @@ -165,7 +174,9 @@ public void setImage(Image image) { private ImageDescriptor createImageDescriptor(String relativePath) { Bundle bundle = FrameworkUtil.getBundle(this.getClass()); URL url = FileLocator.find(bundle, IPath.fromOSString(relativePath),null); - if (url == null) return null; + if (url == null) { + return null; + } try { url = FileLocator.resolve(url); return ImageDescriptor.createFromURL(url); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ColumnLayoutUtils.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ColumnLayoutUtils.java index f28b6d3e73e..2eaa3eb0049 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ColumnLayoutUtils.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ColumnLayoutUtils.java @@ -51,8 +51,9 @@ private static int computeActualHeight(int ncolumns, Point[] sizes, int candidat column++; colHeight = 0; } - if (colHeight > 0) + if (colHeight > 0) { colHeight += verticalMargin; + } colHeight += childHeight; } return Math.max(colHeight, maxHeight); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ControlSegment.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ControlSegment.java index 17a46916d77..cd70c9813e6 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ControlSegment.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ControlSegment.java @@ -44,10 +44,10 @@ public void setHeight(int height) { public Control getControl(Hashtable resourceTable) { Object obj = resourceTable.get(getObjectId()); - if (obj instanceof Control) { - Control c = (Control)obj; - if (!c.isDisposed()) + if (obj instanceof Control c) { + if (!c.isDisposed()) { return c; + } } return null; } @@ -55,15 +55,19 @@ public Control getControl(Hashtable resourceTable) { @Override protected Point getObjectSize(Hashtable resourceTable, int widthHint) { Control control = getControl(resourceTable); - if (control==null) + if (control==null) { return new Point(0,0); + } Point size = control.computeSize(widthHint, SWT.DEFAULT); - if (widthHint!=SWT.DEFAULT && fill) + if (widthHint!=SWT.DEFAULT && fill) { size.x = Math.max(size.x, widthHint); - if (width != SWT.DEFAULT) + } + if (width != SWT.DEFAULT) { size.x = width; - if (height != SWT.DEFAULT) + } + if (height != SWT.DEFAULT) { size.y = height; + } return size; } @@ -72,8 +76,9 @@ public void layout(GC gc, int width, Locator loc, Hashtable reso boolean selected) { super.layout(gc, width, loc, resourceTable, selected); Control control = getControl(resourceTable); - if (control!=null) + if (control!=null) { control.setBounds(getBounds()); + } } @Override @@ -86,23 +91,25 @@ public boolean setFocus(Hashtable resourceTable, boolean next) { } private boolean setFocus(Control c, boolean direction) { - if (c instanceof Composite) { - Composite comp = (Composite)c; + if (c instanceof Composite comp) { Control [] tabList = comp.getTabList(); if (direction) { for (Control element : tabList) { - if (setFocus(element, direction)) + if (setFocus(element, direction)) { return true; + } } } else { for (int i=tabList.length-1; i>=0; i--) { - if (setFocus(tabList[i], direction)) + if (setFocus(tabList[i], direction)) { return true; + } } } - if (!(c instanceof Canvas)) + if (!(c instanceof Canvas)) { return false; + } } return c.setFocus(); } @@ -110,8 +117,9 @@ private boolean setFocus(Control c, boolean direction) { @Override public boolean isFocusSelectable(Hashtable resourceTable) { Control c = getControl(resourceTable); - if (c!=null) + if (c!=null) { return true; + } return false; } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormFonts.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormFonts.java index 26908361f52..7c6458c4850 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormFonts.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormFonts.java @@ -29,19 +29,20 @@ public class FormFonts { private static FormFonts instance; public static FormFonts getInstance() { - if (instance == null) + if (instance == null) { instance = new FormFonts(); + } return instance; } - private ResourceManagerManger manager = new ResourceManagerManger(); + private final ResourceManagerManger manager = new ResourceManagerManger(); private HashMap descriptors; private FormFonts() { } private static class BoldFontDescriptor extends FontDescriptor { - private FontData[] fFontData; + private final FontData[] fFontData; BoldFontDescriptor (Font font) { fFontData = font.getFontData(); @@ -52,8 +53,7 @@ private static class BoldFontDescriptor extends FontDescriptor { @Override public boolean equals(Object obj) { - if (obj instanceof BoldFontDescriptor) { - BoldFontDescriptor desc = (BoldFontDescriptor)obj; + if (obj instanceof BoldFontDescriptor desc) { return Arrays.equals(fFontData, desc.fFontData); } return false; @@ -102,12 +102,14 @@ public boolean markFinished(Font boldFont, Display display) { } private void checkHashMaps() { - if (descriptors == null) + if (descriptors == null) { descriptors = new HashMap<>(); + } } private void validateHashMaps() { - if (descriptors.isEmpty()) + if (descriptors.isEmpty()) { descriptors = null; + } } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.java index d23156b9bfe..526ba99469c 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.java @@ -87,13 +87,13 @@ public class FormHeading extends Canvas { private ToolBarManager toolBarManager; - private SizeCache toolbarCache = new SizeCache(); + private final SizeCache toolbarCache = new SizeCache(); - private SizeCache clientCache = new SizeCache(); + private final SizeCache clientCache = new SizeCache(); - private SizeCache messageCache = new SizeCache(); + private final SizeCache messageCache = new SizeCache(); - private SizeCache titleRegionCache = new SizeCache(); + private final SizeCache titleRegionCache = new SizeCache(); private TitleRegion titleRegion; @@ -113,11 +113,13 @@ public void createToolTip(Control control, boolean imageLabel) { public void update() { String details = getMessageType() == 0 ? null : MessageManager .createDetails(getChildrenMessages()); - if (messageRegion != null) + if (messageRegion != null) { messageRegion.updateToolTip(details); + } if (getMessageType() > 0 - && (details == null || details.isEmpty())) + && (details == null || details.isEmpty())) { details = getMessage(); + } titleRegion.updateToolTip(details); } } @@ -181,8 +183,9 @@ private Point layout(Composite composite, boolean move, int x, int y, int clientWidthHint = width; if (clientWidthHint != SWT.DEFAULT && clientWidthHint != MIN_WIDTH) { clientWidthHint -= HMARGIN * 2; - if (tbsize != null && getToolBarAlignment() == SWT.BOTTOM) + if (tbsize != null && getToolBarAlignment() == SWT.BOTTOM) { clientWidthHint -= tbsize.x + SPACING; + } } clsize = computeSize(clientCache, clientWidthHint); } @@ -192,11 +195,13 @@ private Point layout(Composite composite, boolean move, int x, int y, totalFlexWidth -= TITLE_HMARGIN * 2; // complete right margin if (hasToolBar() && getToolBarAlignment() == SWT.TOP - || hasMessageRegion()) + || hasMessageRegion()) { totalFlexWidth -= SPACING; + } // subtract tool bar - if (hasToolBar() && getToolBarAlignment() == SWT.TOP && tbsize != null) + if (hasToolBar() && getToolBarAlignment() == SWT.TOP && tbsize != null) { totalFlexWidth -= tbsize.x + SPACING; + } flexWidth = totalFlexWidth; if (hasMessageRegion()) { // remove message region spacing and divide by 2 @@ -254,49 +259,62 @@ private Point layout(Composite composite, boolean move, int x, int y, // compute sizes int width1 = 2 * TITLE_HMARGIN; width1 += tsize.x; - if (msize != null) + if (msize != null) { width1 += SPACING + msize.x; - if (tbsize != null && getToolBarAlignment() == SWT.TOP) + } + if (tbsize != null && getToolBarAlignment() == SWT.TOP) { width1 += SPACING + tbsize.x; + } if (msize != null - || (tbsize != null && getToolBarAlignment() == SWT.TOP)) + || (tbsize != null && getToolBarAlignment() == SWT.TOP)) { width1 += SPACING; + } size.x = width1; if (clsize != null) { int width2 = clsize.x; - if (tbsize != null && getToolBarAlignment() == SWT.BOTTOM) + if (tbsize != null && getToolBarAlignment() == SWT.BOTTOM) { width2 += SPACING + tbsize.x; + } width2 += 2 * HMARGIN; size.x = Math.max(width1, width2); } // height, first row size.y = tsize.y; - if (msize != null) + if (msize != null) { size.y = Math.max(msize.y, size.y); - if (tbsize != null && getToolBarAlignment() == SWT.TOP) + } + if (tbsize != null && getToolBarAlignment() == SWT.TOP) { size.y = Math.max(tbsize.y, size.y); - if (size.y > 0) + } + if (size.y > 0) { size.y += VMARGIN * 2; + } // add second row int height2 = 0; - if (tbsize != null && getToolBarAlignment() == SWT.BOTTOM) + if (tbsize != null && getToolBarAlignment() == SWT.BOTTOM) { height2 = tbsize.y; - if (clsize != null) + } + if (clsize != null) { height2 = Math.max(height2, clsize.y); - if (height2 > 0) + } + if (height2 > 0) { size.y += VSPACING + height2 + CLIENT_MARGIN; + } // add separator - if (size.y > 0 && isSeparatorVisible()) + if (size.y > 0 && isSeparatorVisible()) { size.y += SEPARATOR_HEIGHT; + } } else { // position controls int xloc = x; int yloc = y + VMARGIN; int row1Height = tsize.y; - if (hasMessageRegion() && msize != null) + if (hasMessageRegion() && msize != null) { row1Height = Math.max(row1Height, msize.y); - if (hasToolBar() && getToolBarAlignment() == SWT.TOP && tbsize != null) + } + if (hasToolBar() && getToolBarAlignment() == SWT.TOP && tbsize != null) { row1Height = Math.max(row1Height, tbsize.y); + } titleRegion.setBounds(xloc, // yloc + row1Height / 2 - tsize.y / 2, yloc, tsize.x, tsize.y); @@ -324,9 +342,10 @@ private Point layout(Composite composite, boolean move, int x, int y, msize.x, msize.y); xloc += msize.x; } - if (toolBarManager != null) + if (toolBarManager != null) { toolBarManager.getControl().setVisible( !toolBarManager.isEmpty()); + } if (tbsize != null && getToolBarAlignment() == SWT.TOP) { ToolBar tbar = toolBarManager.getControl(); tbar.setBounds(x + width - 1 - tbsize.x - HMARGIN, yloc @@ -403,16 +422,18 @@ public boolean isDisposed() { public boolean isEmpty() { Control c = getMessageControl(); - if (c == null) + if (c == null) { return true; + } return !c.getVisible(); } public int getFontHeight() { if (fontHeight == -1) { Control c = getMessageControl(); - if (c == null) + if (c == null) { return 0; + } GC gc = new GC(c.getDisplay()); gc.setFont(c.getFont()); fontHeight = gc.getFontMetrics().getHeight(); @@ -424,8 +445,9 @@ public int getFontHeight() { public int getFontBaselineHeight() { if (fontBaselineHeight == -1) { Control c = getMessageControl(); - if (c == null) + if (c == null) { return 0; + } GC gc = new GC(c.getDisplay()); gc.setFont(c.getFont()); FontMetrics fm = gc.getFontMetrics(); @@ -444,10 +466,12 @@ public void showMessage(String newMessage, int newType, this.messages = messages; if (newMessage == null) { // clearing of the message - if (oldControl != null && oldControl.getVisible()) + if (oldControl != null && oldControl.getVisible()) { oldControl.setVisible(false); - if (oldType != newType) + } + if (oldType != newType) { updateForeground(); + } return; } ensureControlExists(); @@ -457,14 +481,16 @@ public void showMessage(String newMessage, int newType, } else { messageLabel.setText(newMessage); } - if (oldType != newType) + if (oldType != newType) { updateForeground(); + } } public void updateToolTip(String toolTip) { Control control = getMessageControl(); - if (control != null) + if (control != null) { control.setToolTipText(toolTip); + } } public String getMessage() { @@ -480,8 +506,9 @@ public IMessage[] getChildrenMessages() { } public Control getMessageControl() { - if (needHyperlink() && messageHyperlink != null) + if (needHyperlink() && messageHyperlink != null) { return messageHyperlink; + } return messageLabel; } @@ -499,44 +526,53 @@ public Image getMessageImage() { } public void addMessageHyperlinkListener(IHyperlinkListener listener) { - if (listeners == null) + if (listeners == null) { listeners = new ListenerList<>(); + } listeners.add(listener); ensureControlExists(); - if (messageHyperlink != null) + if (messageHyperlink != null) { messageHyperlink.addHyperlinkListener(listener); - if (listeners.size() == 1) + } + if (listeners.size() == 1) { updateForeground(); + } } private void removeMessageHyperlinkListener(IHyperlinkListener listener) { if (listeners != null) { listeners.remove(listener); - if (messageHyperlink != null) + if (messageHyperlink != null) { messageHyperlink.removeHyperlinkListener(listener); - if (listeners.isEmpty()) + } + if (listeners.isEmpty()) { listeners = null; + } ensureControlExists(); - if (listeners == null && !isDisposed()) + if (listeners == null && !isDisposed()) { updateForeground(); + } } } private void ensureControlExists() { if (needHyperlink()) { - if (messageLabel != null) + if (messageLabel != null) { messageLabel.setVisible(false); + } if (messageHyperlink == null) { messageHyperlink = new Hyperlink(FormHeading.this, SWT.NULL); messageHyperlink.setUnderlined(true); messageHyperlink.setBackground(getBackground()); messageHyperlink.setText(message); messageHyperlink.setHref(messages); - for (IHyperlinkListener element : listeners) + for (IHyperlinkListener element : listeners) { messageHyperlink .addHyperlinkListener(element); - if (messageToolTipManager != null) + } + if (messageToolTipManager != null) { messageToolTipManager.createToolTip(messageHyperlink, false); + } } else if (!messageHyperlink.getVisible()) { messageHyperlink.setText(message); messageHyperlink.setHref(messages); @@ -544,14 +580,16 @@ private void ensureControlExists() { } } else { // need a label - if (messageHyperlink != null) + if (messageHyperlink != null) { messageHyperlink.setVisible(false); + } if (messageLabel == null) { messageLabel = new CLabel(FormHeading.this, SWT.NULL); messageLabel.setBackground(getBackground()); messageLabel.setText(message); - if (messageToolTipManager != null) + if (messageToolTipManager != null) { messageToolTipManager.createToolTip(messageLabel, false); + } } else if (!messageLabel.getVisible()) { messageLabel.setText(message); messageLabel.setVisible(true); @@ -566,10 +604,12 @@ private boolean needHyperlink() { } public void setBackground(Color bg) { - if (messageHyperlink != null) + if (messageHyperlink != null) { messageHyperlink.setBackground(bg); - if (messageLabel != null) + } + if (messageLabel != null) { messageLabel.setBackground(bg); + } } public void setForeground(Color fg) { @@ -616,8 +656,9 @@ public FormHeading(Composite parent, int style) { } }); addListener(SWT.Resize, e -> { - if (gradientInfo != null || (backgroundImage != null && !isBackgroundImageTiled())) + if (gradientInfo != null || (backgroundImage != null && !isBackgroundImageTiled())) { updateGradientImage(); + } }); addMouseMoveListener(this::updateTitleRegionHoverState); addMouseTrackListener(new MouseTrackListener() { @@ -685,10 +726,12 @@ public void setBackground(Color bg) { private void internalSetBackground(Color bg) { titleRegion.setBackground(bg); - if (messageRegion != null) + if (messageRegion != null) { messageRegion.setBackground(bg); - if (toolBarManager != null) + } + if (toolBarManager != null) { toolBarManager.getControl().setBackground(bg); + } putColor(COLOR_BASE_BG, bg); } @@ -699,8 +742,9 @@ private void internalSetBackground(Color bg) { public void setForeground(Color fg) { super.setForeground(fg); titleRegion.setForeground(fg); - if (messageRegion != null) + if (messageRegion != null) { messageRegion.setForeground(fg); + } } /** @@ -742,10 +786,11 @@ public void setFont(Font font) { */ public void setImage(Image image) { titleRegion.setImage(image); - if (messageRegion != null) + if (messageRegion != null) { titleRegion.updateImage(messageRegion.getMessageImage(), true); - else + } else { titleRegion.updateImage(null, true); + } } public void setTextBackground(Color[] gradientColors, int[] percents, @@ -770,12 +815,14 @@ public void setTextBackground(Color[] gradientColors, int[] percents, public void setHeadingBackgroundImage(Image image) { this.backgroundImage = image; - if (image != null) + if (image != null) { setBackground(null); + } if (isBackgroundImageTiled()) { setBackgroundImage(image); - } else + } else { updateGradientImage(); + } } public Image getHeadingBackgroundImage() { @@ -783,10 +830,11 @@ public Image getHeadingBackgroundImage() { } public void setBackgroundImageTiled(boolean tiled) { - if (tiled) + if (tiled) { flags |= BACKGROUND_IMAGE_TILED; - else + } else { flags &= ~BACKGROUND_IMAGE_TILED; + } setHeadingBackgroundImage(this.backgroundImage); } @@ -842,13 +890,15 @@ public IMenuManager getMenuManager() { * bar manager has not been created yet. */ public void updateToolBar() { - if (toolBarManager != null) + if (toolBarManager != null) { toolBarManager.update(false); + } } private void onPaint(GC gc) { - if (!isSeparatorVisible() && getBackgroundImage() == null) + if (!isSeparatorVisible() && getBackgroundImage() == null) { return; + } Rectangle carea = getClientArea(); if (carea.width == 0 || carea.height == 0) { return; @@ -857,9 +907,9 @@ private void onPaint(GC gc) { igc.setBackground(getBackground()); igc.fillRectangle(0, 0, width, height); if (getBackgroundImage() != null) { - if (gradientInfo != null) + if (gradientInfo != null) { drawBackground(igc, carea.x, carea.y, width, height); - else { + } else { Image bgImage = getBackgroundImage(); Rectangle ibounds = bgImage.getBounds(); drawBackground(igc, carea.x, carea.y, ibounds.width, ibounds.height); @@ -868,15 +918,17 @@ private void onPaint(GC gc) { if (isSeparatorVisible()) { // bg separator - if (hasColor(IFormColors.H_BOTTOM_KEYLINE1)) + if (hasColor(IFormColors.H_BOTTOM_KEYLINE1)) { igc.setForeground(getColor(IFormColors.H_BOTTOM_KEYLINE1)); - else + } else { igc.setForeground(getBackground()); + } igc.drawLine(carea.x, height - 2, carea.x + width - 1, height - 2); - if (hasColor(IFormColors.H_BOTTOM_KEYLINE2)) + if (hasColor(IFormColors.H_BOTTOM_KEYLINE2)) { igc.setForeground(getColor(IFormColors.H_BOTTOM_KEYLINE2)); - else + } else { igc.setForeground(getForeground()); + } igc.drawLine(carea.x, height - 1, carea.x + width - 1, height - 1); } }; @@ -892,10 +944,11 @@ private void updateTitleRegionHoverState(MouseEvent e) { titleRect.height += titleRect.y + 15; titleRect.x = 0; titleRect.y = 0; - if (titleRect.contains(e.x, e.y)) + if (titleRect.contains(e.x, e.y)) { titleRegion.setHoverState(TitleRegion.STATE_HOVER_LIGHT); - else + } else { titleRegion.setHoverState(TitleRegion.STATE_NORMAL); + } } private void updateGradientImage() { @@ -924,17 +977,19 @@ public boolean isSeparatorVisible() { } public void setSeparatorVisible(boolean addSeparator) { - if (addSeparator) + if (addSeparator) { flags |= SEPARATOR; - else + } else { flags &= ~SEPARATOR; + } } public void setToolBarAlignment(int alignment) { - if (alignment == SWT.BOTTOM) + if (alignment == SWT.BOTTOM) { flags |= BOTTOM_TOOLBAR; - else + } else { flags &= ~BOTTOM_TOOLBAR; + } } public int getToolBarAlignment() { @@ -947,8 +1002,9 @@ public void addMessageHyperlinkListener(IHyperlinkListener listener) { } public void removeMessageHyperlinkListener(IHyperlinkListener listener) { - if (messageRegion != null) + if (messageRegion != null) { messageRegion.removeMessageHyperlinkListener(listener); + } } public String getMessage() { @@ -966,22 +1022,26 @@ public IMessage[] getChildrenMessages() { private void ensureMessageRegionExists() { // ensure message region exists - if (messageRegion == null) + if (messageRegion == null) { messageRegion = new MessageRegion(); + } } public void showMessage(String newMessage, int type, IMessage[] messages) { if (messageRegion == null) { // check the trivial case - if (newMessage == null) + if (newMessage == null) { return; - } else if (messageRegion.isDisposed()) + } + } else if (messageRegion.isDisposed()) { return; + } ensureMessageRegionExists(); messageRegion.showMessage(newMessage, type, messages); titleRegion.updateImage(messageRegion.getMessageImage(), false); - if (messageToolTipManager != null) + if (messageToolTipManager != null) { messageToolTipManager.update(); + } layout(); redraw(); } @@ -1005,8 +1065,9 @@ public boolean isBusy() { */ public void setBusy(boolean busy) { - if (titleRegion.setBusy(busy)) + if (titleRegion.setBusy(busy)) { layout(); + } } public Control getHeadClient() { @@ -1014,17 +1075,19 @@ public Control getHeadClient() { } public void setHeadClient(Control headClient) { - if (headClient != null) + if (headClient != null) { Assert.isTrue(headClient.getParent() == this); + } this.headClient = headClient; layout(); } public void putColor(String key, Color color) { - if (color == null) + if (color == null) { colors.remove(key); - else + } else { colors.put(key, color); + } } public Color getColor(String key) { diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormImages.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormImages.java index b67e1f0d7bf..44d354d7f92 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormImages.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormImages.java @@ -36,12 +36,13 @@ public class FormImages { private static FormImages instance; public static FormImages getInstance() { - if (instance == null) + if (instance == null) { instance = new FormImages(); + } return instance; } - private ResourceManagerManger manager = new ResourceManagerManger(); + private final ResourceManagerManger manager = new ResourceManagerManger(); private Map descriptors; private FormImages() { @@ -62,8 +63,7 @@ private abstract static class AbstractImageDescriptor extends ImageDescriptor { @Override public boolean equals(Object obj) { - if (obj instanceof AbstractImageDescriptor) { - AbstractImageDescriptor id = (AbstractImageDescriptor)obj; + if (obj instanceof AbstractImageDescriptor id) { return fLength == id.fLength && Arrays.equals(fRGBs, id.fRGBs); } return false; @@ -72,15 +72,16 @@ public boolean equals(Object obj) { @Override public int hashCode() { int hash = 0; - for (RGB fRGB : fRGBs) + for (RGB fRGB : fRGBs) { hash = hash * 7 + fRGB.hashCode(); + } return hash * 7 + fLength; } } private class SimpleImageDescriptor extends AbstractImageDescriptor{ - private int fTheight; - private int fMarginHeight; + private final int fTheight; + private final int fMarginHeight; SimpleImageDescriptor (Color color1, Color color2, int realtheight, int theight, int marginHeight) { @@ -91,11 +92,11 @@ private class SimpleImageDescriptor extends AbstractImageDescriptor{ @Override public boolean equals(Object obj) { - if (obj instanceof SimpleImageDescriptor) { - SimpleImageDescriptor id = (SimpleImageDescriptor) obj; + if (obj instanceof SimpleImageDescriptor id) { if (super.equals(obj) && - id.fTheight == fTheight && id.fMarginHeight == fMarginHeight) + id.fTheight == fTheight && id.fMarginHeight == fMarginHeight) { return true; + } } return false; } @@ -147,8 +148,7 @@ public ComplexImageDescriptor(Color[] colors, int length, @Override public boolean equals(Object obj) { - if (obj instanceof ComplexImageDescriptor) { - ComplexImageDescriptor id = (ComplexImageDescriptor) obj; + if (obj instanceof ComplexImageDescriptor id) { if (super.equals(obj) && id.fVertical == fVertical && Arrays.equals(id.fPercents, fPercents)) { if (Objects.equals(fBgRGB, id.fBgRGB)) { @@ -157,10 +157,12 @@ public boolean equals(Object obj) { // if the only thing that isn't the same is the background color // still return true if it does not matter (percents add up to 100) int sum = 0; - for (int fPercent : fPercents) + for (int fPercent : fPercents) { sum += fPercent; - if (sum >= 100) + } + if (sum >= 100) { return true; + } } } return false; @@ -187,8 +189,9 @@ public Image createImage(boolean returnMissingImageOnError, Device device) { int height = fVertical ? fLength : 1; final ImageGcDrawer imageGcDrawer = (gc, iWidth, iHeight) -> { Color[] colors = new Color[fRGBs.length]; - for (int i = 0; i < colors.length; i++) + for (int i = 0; i < colors.length; i++) { colors[i] = new Color(device, fRGBs[i]); + } Color bg = fBgRGB == null ? null : new Color(device, fBgRGB); drawTextGradient(gc, iWidth, iHeight, colors, fPercents, fVertical, bg); }; @@ -201,20 +204,23 @@ private void drawTextGradient(GC gc, int width, int height, Color[] colors, int[] percents, boolean vertical, Color bg) { final Color oldBackground = gc.getBackground(); if (colors.length == 1) { - if (colors[0] != null) + if (colors[0] != null) { gc.setBackground(colors[0]); + } gc.fillRectangle(0, 0, width, height); } else { final Color oldForeground = gc.getForeground(); Color lastColor = colors[0]; - if (lastColor == null) + if (lastColor == null) { lastColor = oldBackground; + } int pos = 0; for (int i = 0; i < percents.length; ++i) { gc.setForeground(lastColor); lastColor = colors[i + 1]; - if (lastColor == null) + if (lastColor == null) { lastColor = oldBackground; + } gc.setBackground(lastColor); if (vertical) { int gradientHeight = percents[i] * height / 100; @@ -231,13 +237,15 @@ private void drawTextGradient(GC gc, int width, int height, Color[] colors, } } if (vertical && pos < height) { - if (bg != null) + if (bg != null) { gc.setBackground(bg); + } gc.fillRectangle(0, pos, width, height - pos); } if (!vertical && pos < width) { - if (bg != null) + if (bg != null) { gc.setBackground(bg); + } gc.fillRectangle(pos, 0, width - pos, height); } gc.setForeground(oldForeground); @@ -257,10 +265,10 @@ private class SimpleSectionImageDescriptor extends AbstractImageDescriptor { @Override public boolean equals(Object obj) { - if (obj instanceof SimpleSectionImageDescriptor) { - SimpleSectionImageDescriptor id = (SimpleSectionImageDescriptor) obj; - if (super.equals(obj) && id.fTheight == fTheight && id.fMarginHeight == fMarginHeight) + if (obj instanceof SimpleSectionImageDescriptor id) { + if (super.equals(obj) && id.fTheight == fTheight && id.fMarginHeight == fMarginHeight) { return true; + } } return false; } @@ -322,8 +330,9 @@ public Image createImage(boolean returnMissingImageOnError, Device device) { public Image getSectionGradientImage(Color color1, Color color2, int realtheight, int theight, int marginHeight, Display display) { - if (color1 == null || color1.isDisposed()) + if (color1 == null || color1.isDisposed()) { return null; + } AbstractImageDescriptor desc = new SimpleSectionGradientImageDescriptor(color1, color2, realtheight, theight, marginHeight); return getGradient(desc, display); @@ -331,21 +340,26 @@ public Image getSectionGradientImage(Color color1, Color color2, int realtheight public Image getGradient(Color color1, Color color2, int realtheight, int theight, int marginHeight, Display display) { - if (color1 == null || color1.isDisposed() || color2 == null || color2.isDisposed()) + if (color1 == null || color1.isDisposed() || color2 == null || color2.isDisposed()) { return null; + } AbstractImageDescriptor desc = new SimpleImageDescriptor(color1, color2, realtheight, theight, marginHeight); return getGradient(desc, display); } public Image getGradient(Color[] colors, int[] percents, int length, boolean vertical, Color bg, Display display) { - if (colors.length == 0) + if (colors.length == 0) { return null; - for (Color color : colors) - if (color == null || color.isDisposed()) + } + for (Color color : colors) { + if (color == null || color.isDisposed()) { return null; - if (bg != null && bg.isDisposed()) + } + } + if (bg != null && bg.isDisposed()) { return null; + } AbstractImageDescriptor desc = new ComplexImageDescriptor(colors, length, percents, vertical, bg); return getGradient(desc, display); } @@ -377,12 +391,14 @@ public synchronized boolean markFinished(Image image, Display display) { } private void checkHashMaps() { - if (descriptors == null) + if (descriptors == null) { descriptors = new HashMap<>(); + } } private void validateHashMaps() { - if (descriptors.isEmpty()) + if (descriptors.isEmpty()) { descriptors = null; + } } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormTextModel.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormTextModel.java index 70d2b2669c9..9a2b7ac8c81 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormTextModel.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormTextModel.java @@ -88,15 +88,17 @@ public FormTextModel() { * @see ITextModel#getParagraphs() */ public Paragraph[] getParagraphs() { - if (paragraphs == null) + if (paragraphs == null) { return new Paragraph[0]; + } return paragraphs .toArray(new Paragraph[paragraphs.size()]); } public String getAccessibleText() { - if (paragraphs == null) + if (paragraphs == null) { return ""; //$NON-NLS-1$ + } StringBuilder sbuf = new StringBuilder(); for (Paragraph paragraph : paragraphs) { String text = paragraph.getAccessibleText(); @@ -172,12 +174,14 @@ private void processSubnodes(Vector plist, NodeList children, boolean String tag = child.getNodeName().toLowerCase(); if (tag.equals("p")) { //$NON-NLS-1$ Paragraph p = processParagraph(child, expandURLs); - if (p != null) + if (p != null) { plist.add(p); + } } else if (tag.equals("li")) { //$NON-NLS-1$ Paragraph p = processListItem(child, expandURLs); - if (p != null) + if (p != null) { plist.add(p); + } } } } @@ -189,8 +193,9 @@ private Paragraph processParagraph(Node paragraph, boolean expandURLs) { Node addSpaceAtt = atts.getNamedItem("addVerticalSpace"); //$NON-NLS-1$ boolean addSpace = true; - if (addSpaceAtt == null) + if (addSpaceAtt == null) { addSpaceAtt = atts.getNamedItem("vspace"); //$NON-NLS-1$ + } if (addSpaceAtt != null) { String value = addSpaceAtt.getNodeValue(); @@ -232,8 +237,9 @@ private Paragraph processListItem(Node listItem, boolean expandURLs) { } if (valueAtt != null) { text = valueAtt.getNodeValue(); - if (style == BulletParagraph.IMAGE) + if (style == BulletParagraph.IMAGE) { text = "i." + text; //$NON-NLS-1$ + } } if (indentAtt != null) { String value = indentAtt.getNodeValue(); @@ -302,10 +308,12 @@ private void processSegments(Paragraph p, NodeList children, private boolean isIgnorableWhiteSpace(String text, boolean ignoreSpaces) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); - if (ignoreSpaces && c == ' ') + if (ignoreSpaces && c == ' ') { continue; - if (c == '\n' || c == '\r' || c == '\f') + } + if (c == '\n' || c == '\r' || c == '\f') { continue; + } return false; } return true; @@ -373,9 +381,9 @@ private void processObjectSegment(ObjectSegment segment, Node object, String pre } private void appendText(String value, StringBuilder buf, int[] spaceCounter) { - if (!whitespaceNormalized) + if (!whitespaceNormalized) { buf.append(value); - else { + } else { for (int j = 0; j < value.length(); j++) { char c = value.charAt(j); switch (c) { @@ -408,21 +416,25 @@ private String getNormalizedText(String text) { int[] spaceCounter = new int[1]; StringBuilder buf = new StringBuilder(); - if (text == null) + if (text == null) { return null; + } appendText(text, buf, spaceCounter); return buf.toString(); } private String getSingleNodeText(Node node) { String text = getNormalizedText(node.getNodeValue()); - if (!whitespaceNormalized) + if (!whitespaceNormalized) { return text; - if (text.length() > 0 && node.getPreviousSibling() == null && isIgnorableWhiteSpace(text.substring(0, 1), true)) + } + if (text.length() > 0 && node.getPreviousSibling() == null && isIgnorableWhiteSpace(text.substring(0, 1), true)) { return text.substring(1); + } if (text.length() > 1 && node.getNextSibling() == null - && isIgnorableWhiteSpace(text.substring(text.length() - 1), true)) + && isIgnorableWhiteSpace(text.substring(text.length() - 1), true)) { return text.substring(0, text.length() - 1); + } return text; } @@ -462,32 +474,34 @@ private ParagraphSegment processHyperlinkSegment(Node link, Node nowrap = atts.getNamedItem("nowrap"); //$NON-NLS-1$ if (nowrap != null) { String value = nowrap.getNodeValue(); - if (value != null && value.equalsIgnoreCase("true")) //$NON-NLS-1$ + if (value != null && value.equalsIgnoreCase("true")) { //$NON-NLS-1$ wrapAllowed = false; + } } Object status = checkChildren(link); - if (status instanceof Node) { - Node child = (Node)status; + if (status instanceof Node child) { ImageHyperlinkSegment segment = new ImageHyperlinkSegment(); segment.setHref(href); segment.setWordWrapAllowed(wrapAllowed); Node alt = child.getAttributes().getNamedItem("alt"); //$NON-NLS-1$ - if (alt!=null) + if (alt!=null) { segment.setTooltipText(alt.getNodeValue()); + } Node text = child.getAttributes().getNamedItem("text"); //$NON-NLS-1$ - if (text!=null) + if (text!=null) { segment.setText(text.getNodeValue()); + } processObjectSegment(segment, child, "i."); //$NON-NLS-1$ return segment; - } else if (status instanceof String) { - String text = (String) status; + } else if (status instanceof String text) { TextHyperlinkSegment segment = new TextHyperlinkSegment(text, settings, null); segment.setHref(href); segment.setFontId(boldFontId); Node alt = atts.getNamedItem("alt"); //$NON-NLS-1$ - if (alt!=null) + if (alt!=null) { segment.setTooltipText(alt.getNodeValue()); + } segment.setWordWrapAllowed(wrapAllowed); return segment; } else { @@ -501,8 +515,9 @@ private ParagraphSegment processHyperlinkSegment(Node link, TextHyperlinkSegment ts = new TextHyperlinkSegment( getNormalizedText(value), settings, null); Node alt = atts.getNamedItem("alt"); //$NON-NLS-1$ - if (alt!=null) + if (alt!=null) { ts.setTooltipText(alt.getNodeValue()); + } ts.setWordWrapAllowed(wrapAllowed); parent.add(ts); } else if (child.getNodeType() == Node.ELEMENT_NODE) { @@ -511,8 +526,9 @@ private ParagraphSegment processHyperlinkSegment(Node link, ImageHyperlinkSegment is = new ImageHyperlinkSegment(); processObjectSegment(is, child, "i."); //$NON-NLS-1$ Node alt = child.getAttributes().getNamedItem("alt"); //$NON-NLS-1$ - if (alt!=null) + if (alt!=null) { is.setTooltipText(alt.getNodeValue()); + } parent.add(is); is.setWordWrapAllowed(wrapAllowed); } @@ -530,18 +546,20 @@ private Object checkChildren(Node node) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); - if (child.getNodeType() == Node.TEXT_NODE) + if (child.getNodeType() == Node.TEXT_NODE) { text = true; - else if (child.getNodeType() == Node.ELEMENT_NODE + } else if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equalsIgnoreCase("img")) { //$NON-NLS-1$ imgNode = child; } } - if (text && imgNode == null) + if (text && imgNode == null) { return getNodeText(node); - else if (!text && imgNode != null) + } else if (!text && imgNode != null) { return imgNode; - else return null; + } else { + return null; + } } private void processTextSegment(Paragraph p, boolean expandURLs, @@ -555,8 +573,9 @@ private void processTextSegment(Paragraph p, boolean expandURLs, Node nowrap = atts.getNamedItem("nowrap"); //$NON-NLS-1$ if (nowrap != null) { String value = nowrap.getNodeValue(); - if (value != null && value.equalsIgnoreCase("true")) //$NON-NLS-1$ + if (value != null && value.equalsIgnoreCase("true")) { //$NON-NLS-1$ wrapAllowed = false; + } } String fontId = null; String colorId = null; @@ -573,8 +592,9 @@ private void processTextSegment(Paragraph p, boolean expandURLs, public void parseRegularText(String regularText, boolean convertURLs) { reset(); - if (regularText == null) + if (regularText == null) { return; + } regularText = getNormalizedText(regularText); @@ -605,8 +625,9 @@ public void parseRegularText(String regularText, boolean convertURLs) { public HyperlinkSettings getHyperlinkSettings() { // #132723 cannot have null settings - if (hyperlinkSettings==null) + if (hyperlinkSettings==null) { hyperlinkSettings = new HyperlinkSettings(SWTUtil.getStandardDisplay()); + } return hyperlinkSettings; } @@ -615,8 +636,9 @@ public void setHyperlinkSettings(HyperlinkSettings settings) { } private void reset() { - if (paragraphs == null) + if (paragraphs == null) { paragraphs = new Vector<>(); + } paragraphs.clear(); selectedSegmentIndex = -1; savedSelectedLinkIndex = -1; @@ -624,14 +646,16 @@ private void reset() { } IFocusSelectable[] getFocusSelectableSegments() { - if (selectableSegments != null || paragraphs == null) + if (selectableSegments != null || paragraphs == null) { return selectableSegments; + } Vector result = new Vector<>(); for (Paragraph paragraph : paragraphs) { ParagraphSegment[] segments = paragraph.getSegments(); for (ParagraphSegment segment : segments) { - if (segment instanceof IFocusSelectable) + if (segment instanceof IFocusSelectable) { result.add(segment); + } } } selectableSegments = result @@ -643,8 +667,9 @@ public IHyperlinkSegment getHyperlink(int index) { IFocusSelectable[] selectables = getFocusSelectableSegments(); if (selectables.length>index) { IFocusSelectable link = selectables[index]; - if (link instanceof IHyperlinkSegment) + if (link instanceof IHyperlinkSegment) { return (IHyperlinkSegment)link; + } } return null; } @@ -652,10 +677,10 @@ public IHyperlinkSegment getHyperlink(int index) { public IHyperlinkSegment findHyperlinkAt(int x, int y) { IFocusSelectable[] selectables = getFocusSelectableSegments(); for (IFocusSelectable segment : selectables) { - if (segment instanceof IHyperlinkSegment) { - IHyperlinkSegment link = (IHyperlinkSegment)segment; - if (link.contains(x, y)) + if (segment instanceof IHyperlinkSegment link) { + if (link.contains(x, y)) { return link; + } } } return null; @@ -669,10 +694,10 @@ public int indexOf(IHyperlinkSegment link) { IFocusSelectable[] selectables = getFocusSelectableSegments(); for (int i = 0; i < selectables.length; i++) { IFocusSelectable segment = selectables[i]; - if (segment instanceof IHyperlinkSegment) { - IHyperlinkSegment l = (IHyperlinkSegment)segment; - if (link==l) + if (segment instanceof IHyperlinkSegment l) { + if (link==l) { return i; + } } } return -1; @@ -681,8 +706,9 @@ public int indexOf(IHyperlinkSegment link) { public ParagraphSegment findSegmentAt(int x, int y) { for (Paragraph paragraph : paragraphs) { ParagraphSegment segment = paragraph.findSegmentAt(x, y); - if (segment != null) + if (segment != null) { return segment; + } } return null; } @@ -694,8 +720,9 @@ public void clearCache(String fontId) { } public IFocusSelectable getSelectedSegment() { - if (selectableSegments==null || selectedSegmentIndex == -1) + if (selectableSegments==null || selectedSegmentIndex == -1) { return null; + } return selectableSegments[selectedSegmentIndex]; } @@ -704,24 +731,28 @@ public int getSelectedSegmentIndex() { } public boolean linkExists(IHyperlinkSegment link) { - if (selectableSegments==null) + if (selectableSegments==null) { return false; + } for (IFocusSelectable selectableSegment : selectableSegments) { - if (selectableSegment==link) + if (selectableSegment==link) { return true; + } } return false; } public boolean traverseFocusSelectableObjects(boolean next) { IFocusSelectable[] selectables = getFocusSelectableSegments(); - if (selectables == null) + if (selectables == null) { return false; + } int size = selectables.length; if (next) { selectedSegmentIndex++; - } else + } else { selectedSegmentIndex--; + } if (selectedSegmentIndex < 0 || selectedSegmentIndex > size - 1) { selectedSegmentIndex = -1; @@ -731,8 +762,9 @@ public boolean traverseFocusSelectableObjects(boolean next) { public IFocusSelectable getNextFocusSegment(boolean next) { IFocusSelectable[] selectables = getFocusSelectableSegments(); - if (selectables == null) + if (selectables == null) { return null; + } int nextIndex = next?selectedSegmentIndex+1:selectedSegmentIndex-1; if (nextIndex < 0 || nextIndex > selectables.length - 1) { @@ -763,8 +795,9 @@ public void selectLink(IHyperlinkSegment link) { public void select(IFocusSelectable selectable) { IFocusSelectable[] selectables = getFocusSelectableSegments(); selectedSegmentIndex = -1; - if (selectables == null) + if (selectables == null) { return; + } for (int i = 0; i < selectables.length; i++) { if (selectables[i].equals(selectable)) { selectedSegmentIndex = i; @@ -775,8 +808,9 @@ public void select(IFocusSelectable selectable) { public boolean hasFocusSegments() { IFocusSelectable[] segments = getFocusSelectableSegments(); - if (segments.length > 0) + if (segments.length > 0) { return true; + } return false; } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormUtil.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormUtil.java index 17754b27e81..451080124e0 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormUtil.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormUtil.java @@ -195,8 +195,9 @@ public static Point computeWrapSize(GC gc, String text, int wHint) { * The recursive call proved to be the only thing that worked in all cases. Some attempts can be made * to estimate the height, but the algorithm needs to be run again to be sure. */ - if (maxWidth > wHint) + if (maxWidth > wHint) { return computeWrapSize(gc, text, maxWidth); + } return new Point(maxWidth, height); } @@ -264,16 +265,18 @@ public static void ensureVisible(Control c) { ScrolledComposite scomp = getScrolledComposite(c); if (scomp != null) { Object data = scomp.getData(FOCUS_SCROLLING); - if (data == null || !data.equals(Boolean.FALSE)) + if (data == null || !data.equals(Boolean.FALSE)) { FormUtil.ensureVisible(scomp, c); + } } } public static void ensureVisible(ScrolledComposite scomp, Control control) { // if the control is a FormText we do not need to scroll since it will // ensure visibility of its segments as necessary - if (control instanceof FormText) + if (control instanceof FormText) { return; + } Point controlSize = control.getSize(); Point controlOrigin = getControlLocation(scomp, control); ensureVisible(scomp, controlOrigin, controlSize); @@ -297,10 +300,11 @@ public static void ensureVisible(ScrolledComposite scomp, // horizontal left - make sure the left edge of // the control is showing if (controlOrigin.x < x) { - if (controlSize.x < area.width) + if (controlSize.x < area.width) { x = controlOrigin.x + controlSize.x - area.width; - else + } else { x = controlOrigin.x; + } } // vertical bottom if (controlSize.y < area.height @@ -311,10 +315,11 @@ public static void ensureVisible(ScrolledComposite scomp, // vertical top - make sure the top of // the control is showing if (controlOrigin.y < y) { - if (controlSize.y < area.height) + if (controlSize.y < area.height) { y = controlOrigin.y + controlSize.y - area.height; - else + } else { y = controlOrigin.y; + } } if (scompOrigin.x != x || scompOrigin.y != y) { @@ -366,8 +371,9 @@ public static Point getControlLocation(ScrolledComposite scomp, Control content = scomp.getContent(); Control currentControl = control; for (;;) { - if (currentControl == content) + if (currentControl == content) { break; + } Point location = currentControl.getLocation(); // if (location.x > 0) // x += location.x; @@ -427,16 +433,19 @@ public static void processKey(int keyCode, Control c) { } ScrolledComposite scomp = FormUtil.getScrolledComposite(c); if (scomp != null) { - if (c instanceof Combo) + if (c instanceof Combo) { return; + } switch (keyCode) { case SWT.ARROW_DOWN: - if (scomp.getData("novarrows") == null) //$NON-NLS-1$ + if (scomp.getData("novarrows") == null) { //$NON-NLS-1$ FormUtil.scrollVertical(scomp, false); + } break; case SWT.ARROW_UP: - if (scomp.getData("novarrows") == null) //$NON-NLS-1$ + if (scomp.getData("novarrows") == null) { //$NON-NLS-1$ FormUtil.scrollVertical(scomp, true); + } break; case SWT.ARROW_LEFT: FormUtil.scrollHorizontal(scomp, true); @@ -457,8 +466,9 @@ public static void processKey(int keyCode, Control c) { public static int getHeightHint(int hHint, Control c) { if (c instanceof Composite) { Layout layout = ((Composite) c).getLayout(); - if (layout instanceof ColumnLayout) + if (layout instanceof ColumnLayout) { return hHint; + } } return SWT.DEFAULT; } @@ -498,8 +508,9 @@ public static Image createAlphaMashImage(Device device, Image srcImage) { public static boolean mnemonicMatch(String text, char key) { char mnemonic = findMnemonic(text); - if (mnemonic == '\0') + if (mnemonic == '\0') { return false; + } return Character.toUpperCase(key) == Character.toUpperCase(mnemonic); } @@ -507,12 +518,15 @@ private static char findMnemonic(String string) { int index = 0; int length = string.length(); do { - while (index < length && string.charAt(index) != '&') + while (index < length && string.charAt(index) != '&') { index++; - if (++index >= length) + } + if (++index >= length) { return '\0'; - if (string.charAt(index) != '&') + } + if (string.charAt(index) != '&') { return string.charAt(index); + } index++; } while (index < length); return '\0'; @@ -521,19 +535,22 @@ private static char findMnemonic(String string) { public static void setFocusScrollingEnabled(Control c, boolean enabled) { ScrolledComposite scomp = null; - if (c instanceof ScrolledComposite) + if (c instanceof ScrolledComposite) { scomp = (ScrolledComposite)c; - else + } else { scomp = getScrolledComposite(c); - if (scomp!=null) + } + if (scomp!=null) { scomp.setData(FormUtil.FOCUS_SCROLLING, enabled?null:Boolean.FALSE); + } } public static void setAntialias(GC gc, int style) { if (!gc.getAdvanced()) { gc.setAdvanced(true); - if (!gc.getAdvanced()) + if (!gc.getAdvanced()) { return; + } } gc.setAntialias(style); } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ImageHyperlinkSegment.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ImageHyperlinkSegment.java index c212cd30f4d..570a7a00e06 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ImageHyperlinkSegment.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ImageHyperlinkSegment.java @@ -42,8 +42,9 @@ public String getHref() { public void paintFocus(GC gc, Color bg, Color fg, boolean selected, Rectangle repaintRegion) { Rectangle bounds = getBounds(); - if (bounds == null) + if (bounds == null) { return; + } if (selected) { gc.setBackground(bg); gc.setForeground(fg); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ImageSegment.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ImageSegment.java index 1eff39897a5..ada7ed5d3df 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ImageSegment.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ImageSegment.java @@ -32,13 +32,16 @@ public Image getImage(Hashtable objectTable) { } private Image getImage(String key, Hashtable objectTable) { - if (key == null) + if (key == null) { return null; + } Object obj = objectTable.get(key); - if (obj == null) + if (obj == null) { return null; - if (obj instanceof Image) + } + if (obj instanceof Image) { return (Image) obj; + } return null; } @@ -47,8 +50,9 @@ private Image getSelectedImage(Hashtable objectTable, SelectionD Image image = getImage(key, objectTable); if (image==null) { image = FormUtil.createAlphaMashImage(selData.display, getImage(objectTable)); - if (image!=null) + if (image!=null) { objectTable.put(key, image); + } } return image; } @@ -69,8 +73,9 @@ public void paint(GC gc, boolean hover, Hashtable resourceTable, Rectangle rect = image.getBounds(); iwidth = rect.width + (isSelectable()?2:0); iheight = rect.height + (isSelectable()?2:0); - } else + } else { return; + } Rectangle bounds = getBounds(); int ix = bounds.x+(isSelectable()?1:0); int iy = bounds.y+(isSelectable()?1:0); @@ -103,11 +108,12 @@ public void paint(GC gc, boolean hover, Hashtable resourceTable, gc.drawImage(selImage, sx, sy); gc.setBackground(savedBg); } - } - else + } else { drawClipImage(gc, image, ix, iy, repaintRegion); - } else + } + } else { drawClipImage(gc, image, ix, iy, repaintRegion); + } if (selected) { int fx = bounds.x; int fy = bounds.y; @@ -136,8 +142,9 @@ private void drawClipImage(GC gc, Image image, int ix, int iy, Rectangle repaint @Override protected Point getObjectSize(Hashtable resourceTable, int wHint) { Image image = getImage(resourceTable); - if (image==null) + if (image==null) { return new Point(0, 0); + } Rectangle ibounds = image.getBounds(); return new Point(ibounds.width, ibounds.height); } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/Locator.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/Locator.java index e19604f3147..961af410b0f 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/Locator.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/Locator.java @@ -53,8 +53,9 @@ public int getMiddle(int segmentHeight, boolean text) { int [] rdata = heights.get(rowCounter); int rheight = rdata[0]; int rleading = rdata[1]; - if (text) + if (text) { return y + rheight/2 - segmentHeight/2 - rleading; + } return y + rheight/2 - segmentHeight/2; } return y; @@ -64,8 +65,9 @@ public int getBaseline(int segmentHeight, boolean text) { int [] rdata = heights.get(rowCounter); int rheight = rdata[0]; int rleading = rdata[1]; - if (text) + if (text) { return y + rheight - segmentHeight - rleading; + } return y + rheight - segmentHeight; } return y; diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ObjectSegment.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ObjectSegment.java index b3e1b4e17e9..ab7f55ff960 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ObjectSegment.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ObjectSegment.java @@ -65,8 +65,9 @@ public boolean advanceLocator(GC gc, int wHint, Locator loc, } if (wHint != SWT.DEFAULT && !nowrap && loc.x + iwidth + loc.marginWidth > wHint) { // new line - if (computeHeightOnly) + if (computeHeightOnly) { loc.collectHeights(); + } loc.resetCaret(); loc.x += iwidth; loc.y += loc.rowHeight; @@ -84,14 +85,16 @@ public boolean advanceLocator(GC gc, int wHint, Locator loc, @Override public boolean contains(int x, int y) { - if (bounds==null) + if (bounds==null) { return false; + } return bounds.contains(x, y); } @Override public boolean intersects(Rectangle rect) { - if (bounds==null) + if (bounds==null) { return false; + } return bounds.intersects(rect); } @@ -129,8 +132,9 @@ public void layout(GC gc, int width, Locator loc, Hashtable reso if (size != null) { objWidth = size.x + (isSelectable()?2:0); objHeight = size.y + (isSelectable()?2:0); - } else + } else { return; + } loc.width = objWidth; if (!nowrap && loc.x + objWidth + loc.marginWidth > width) { @@ -141,10 +145,11 @@ public void layout(GC gc, int width, Locator loc, Hashtable reso int ix = loc.x; int iy = loc.y; - if (alignment==MIDDLE) + if (alignment==MIDDLE) { iy = loc.getMiddle(objHeight, false); - else if (alignment==BOTTOM) + } else if (alignment==BOTTOM) { iy = loc.getBaseline(objHeight, false); + } loc.x += objWidth; loc.rowHeight = Math.max(loc.rowHeight, objHeight); bounds = new Rectangle(ix, iy, objWidth, objHeight); diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/Paragraph.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/Paragraph.java index a1f96d180a4..406d293dbe2 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/Paragraph.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/Paragraph.java @@ -48,15 +48,17 @@ public boolean getAddVerticalSpace() { } public ParagraphSegment[] getSegments() { - if (segments == null) + if (segments == null) { return new ParagraphSegment[0]; + } return segments .toArray(new ParagraphSegment[segments.size()]); } public void addSegment(ParagraphSegment segment) { - if (segments == null) + if (segments == null) { segments = new Vector<>(); + } segments.add(segment); } @@ -67,14 +69,15 @@ public void parseRegularText(String text, boolean expandURLs, boolean wrapAllowe public void parseRegularText(String text, boolean expandURLs, boolean wrapAllowed, HyperlinkSettings settings, String fontId, String colorId) { - if (text.isEmpty()) + if (text.isEmpty()) { return; + } if (expandURLs) { int loc = findUrl(text,0); - if (loc == -1) + if (loc == -1) { addSegment(new TextSegment(text, fontId, colorId, wrapAllowed)); - else { + } else { int textLoc = 0; while (loc != -1) { addSegment(new TextSegment(text.substring(textLoc, loc), @@ -109,12 +112,15 @@ public void parseRegularText(String text, boolean expandURLs, boolean wrapAllowe private int findUrl(String text, int startIndex) { int[] locs = new int[PROTOCOLS.length]; - for (int i = 0; i < PROTOCOLS.length; i++) + for (int i = 0; i < PROTOCOLS.length; i++) { locs[i] = text.indexOf(PROTOCOLS[i], startIndex); + } Arrays.sort(locs); - for (int i = 0; i < PROTOCOLS.length; i++) - if (locs[i] != -1) + for (int i = 0; i < PROTOCOLS.length; i++) { + if (locs[i] != -1) { return locs[i]; + } + } return -1; } @@ -158,12 +164,14 @@ public void layout(GC gc, int width, Locator loc, int lineHeight, loc.x += 1; */ // compute heights - if (loc.heights == null) + if (loc.heights == null) { computeRowHeights(gc, width, loc, lineHeight, resourceTable); + } for (ParagraphSegment segment : segments) { boolean doSelect = false; - if (selectedLink instanceof ParagraphSegment sl && segment.equals(sl)) + if (selectedLink instanceof ParagraphSegment sl && segment.equals(sl)) { doSelect = true; + } segment.layout(gc, width, loc, resourceTable, doSelect); } loc.heights = null; @@ -179,11 +187,13 @@ public void paint(GC gc, Rectangle repaintRegion, ParagraphSegment[] segments = getSegments(); for (ParagraphSegment segment : segments) { - if (!segment.intersects(repaintRegion)) + if (!segment.intersects(repaintRegion)) { continue; + } boolean doSelect = false; - if (selectedLink instanceof ParagraphSegment sl && segment.equals(sl)) + if (selectedLink instanceof ParagraphSegment sl && segment.equals(sl)) { doSelect = true; + } segment.paint(gc, false, resourceTable, doSelect, selData, repaintRegion); } } @@ -218,8 +228,9 @@ public String getAccessibleText() { public ParagraphSegment findSegmentAt(int x, int y) { if (segments != null) { for (ParagraphSegment segment : segments) { - if (segment.contains(x, y)) + if (segment.contains(x, y)) { return segment; + } } } return null; diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/SWTUtil.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/SWTUtil.java index aebffcd6d30..c34c623de0f 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/SWTUtil.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/SWTUtil.java @@ -35,8 +35,9 @@ public class SWTUtil { public static Display getStandardDisplay() { Display display; display = Display.getCurrent(); - if (display == null) + if (display == null) { display = Display.getDefault(); + } return display; } @@ -47,18 +48,24 @@ public static Display getStandardDisplay() { * @return the shell for the given widget */ public static Shell getShell(Widget widget) { - if (widget instanceof Control) + if (widget instanceof Control) { return ((Control) widget).getShell(); - if (widget instanceof Caret) + } + if (widget instanceof Caret) { return ((Caret) widget).getParent().getShell(); - if (widget instanceof DragSource) + } + if (widget instanceof DragSource) { return ((DragSource) widget).getControl().getShell(); - if (widget instanceof DropTarget) + } + if (widget instanceof DropTarget) { return ((DropTarget) widget).getControl().getShell(); - if (widget instanceof Menu) + } + if (widget instanceof Menu) { return ((Menu) widget).getParent().getShell(); - if (widget instanceof ScrollBar) + } + if (widget instanceof ScrollBar) { return ((ScrollBar) widget).getParent().getShell(); + } return null; } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/SelectionData.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/SelectionData.java index 1f0670659ad..87c4bb52a33 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/SelectionData.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/SelectionData.java @@ -25,9 +25,9 @@ public class SelectionData { public Display display; public Color bg; public Color fg; - private Point start; - private Point stop; - private ArrayList segments; + private final Point start; + private final Point stop; + private final ArrayList segments; public SelectionData(MouseEvent e) { display = e.display; @@ -100,40 +100,46 @@ public boolean isEnclosed() { } public boolean isSelectedRow(Locator locator) { - if (!isEnclosed()) + if (!isEnclosed()) { return false; + } int rowHeight = locator.heights.get(locator.rowCounter)[0]; return isSelectedRow(locator.y, rowHeight); } public boolean isSelectedRow(int y, int rowHeight) { - if (!isEnclosed()) + if (!isEnclosed()) { return false; + } return (y + rowHeight >= getTopOffset() && y <= getBottomOffset()); } public boolean isFirstSelectionRow(Locator locator) { - if (!isEnclosed()) + if (!isEnclosed()) { return false; + } int rowHeight = locator.heights.get(locator.rowCounter)[0]; return (locator.y + rowHeight >= getTopOffset() && locator.y <= getTopOffset()); } public boolean isFirstSelectionRow(int y, int rowHeight) { - if (!isEnclosed()) + if (!isEnclosed()) { return false; + } return (y + rowHeight >= getTopOffset() && y <= getTopOffset()); } public boolean isLastSelectionRow(Locator locator) { - if (!isEnclosed()) + if (!isEnclosed()) { return false; + } int rowHeight = locator.heights.get(locator.rowCounter)[0]; return (locator.y + rowHeight >=getBottomOffset() && locator.y <= getBottomOffset()); } public boolean isLastSelectionRow(int y, int rowHeight) { - if (!isEnclosed()) + if (!isEnclosed()) { return false; + } return (y + rowHeight >=getBottomOffset() && y <= getBottomOffset()); } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TextHyperlinkSegment.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TextHyperlinkSegment.java index b4eec7a8003..4c782368dad 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TextHyperlinkSegment.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TextHyperlinkSegment.java @@ -32,7 +32,7 @@ public class TextHyperlinkSegment extends TextSegment implements //private static final String LINK_FG = "c.___link_fg"; - private HyperlinkSettings settings; + private final HyperlinkSettings settings; public TextHyperlinkSegment(String text, HyperlinkSettings settings, String fontId) { @@ -67,8 +67,9 @@ public void paint(GC gc, boolean hover, Hashtable resourceTable, underline = settings.getHyperlinkUnderlineMode() == HyperlinkSettings.UNDERLINE_ALWAYS; Color savedFg = gc.getForeground(); Color newFg = hover ? settings.getActiveForeground() : settings.getForeground(); - if (newFg!=null) + if (newFg!=null) { gc.setForeground(newFg); + } super.paint(gc, hover, resourceTable, selected, rolloverMode, selData, repaintRegion); gc.setForeground(savedFg); } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TextSegment.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TextSegment.java index 837714b84e8..101c3e49eae 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TextSegment.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TextSegment.java @@ -66,10 +66,12 @@ public boolean intersects(Rectangle region) { } public String getText() { - if (from == 0 && to == -1) + if (from == 0 && to == -1) { return TextSegment.this.getText(); - if (from > 0 && to == -1) + } + if (from > 0 && to == -1) { return TextSegment.this.getText().substring(from); + } return TextSegment.this.getText().substring(from, to); } } @@ -120,10 +122,12 @@ private String cleanup(String text) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (c == '\n' || c == '\r' || c == '\f') { - if (i > 0) + if (i > 0) { buf.append(' '); - } else + } + } else { buf.append(c); + } } return buf.toString(); } @@ -166,8 +170,9 @@ void setFontId(String fontId) { public boolean contains(int x, int y) { for (int i = 0; i < areaRectangles.size(); i++) { AreaRectangle ar = areaRectangles.get(i); - if (ar.contains(x, y)) + if (ar.contains(x, y)) { return true; + } if (i wHint) { // new line locator.resetCaret(); locator.y += locator.rowHeight; - if (computeHeightOnly) + if (computeHeightOnly) { locator.collectHeights(); + } locator.rowHeight = 0; locator.leading = 0; newLine = true; } int width = extent.x; - if (isSelectable()) + if (isSelectable()) { width += 1; + } locator.x += width; locator.width = locator.x; locator.rowHeight = Math.max(locator.rowHeight, extent.y); @@ -271,8 +283,9 @@ public boolean advanceLocator(GC gc, int wHint, Locator locator, TextFragment textFragment = textFragments[i]; int currentExtent = locator.x + lineExtent.x; - if (isSelectable()) + if (isSelectable()) { currentExtent += 1; + } // i != 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0) means: // only wrap on the first fragment if we are not at the start of a line @@ -281,8 +294,9 @@ public boolean advanceLocator(GC gc, int wHint, Locator locator, int lineWidth = currentExtent; locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); locator.leading = Math.max(locator.leading, fm.getLeading()); - if (computeHeightOnly) + if (computeHeightOnly) { locator.collectHeights(); + } locator.x = locator.indent; locator.y += locator.rowHeight; locator.rowHeight = 0; @@ -297,8 +311,9 @@ public boolean advanceLocator(GC gc, int wHint, Locator locator, width = Math.max (width, locator.x + lineExtent.x); } int lineWidth = lineExtent.x; - if (isSelectable()) + if (isSelectable()) { lineWidth += 1; + } locator.x += lineWidth; locator.width = width; locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); @@ -313,8 +328,9 @@ private void layoutWithoutWrapping(GC gc, int width, Locator locator, boolean selected, FontMetrics fm, int lineHeight, int descent) { Point extent = gc.textExtent(text); int ewidth = extent.x; - if (isSelectable()) + if (isSelectable()) { ewidth += 1; + } if (locator.x + ewidth > width-locator.marginWidth) { // new line locator.resetCaret(); @@ -345,8 +361,9 @@ protected int convertOffsetToStringIndex(GC gc, String s, int x, public void paintFocus(GC gc, Color bg, Color fg, boolean selected, Rectangle repaintRegion) { - if (areaRectangles == null) + if (areaRectangles == null) { return; + } for (AreaRectangle areaRectangle : areaRectangles) { Rectangle br = areaRectangle.rect; int bx = br.x; @@ -382,14 +399,16 @@ protected void paint(GC gc, boolean hover, Hashtable resourceTab if (fontId != null) { oldFont = gc.getFont(); Font newFont = (Font) resourceTable.get(fontId); - if (newFont != null) + if (newFont != null) { gc.setFont(newFont); + } } if (!hover && colorId != null) { oldColor = gc.getForeground(); Color newColor = (Color) resourceTable.get(colorId); - if (newColor != null) + if (newColor != null) { gc.setForeground(newColor); + } } Color oldBg = gc.getBackground(); @@ -441,8 +460,9 @@ public void computeSelection(GC gc, Hashtable resourceTable, Sel if (fontId != null) { oldFont = gc.getFont(); Font newFont = (Font) resourceTable.get(fontId); - if (newFont != null) + if (newFont != null) { gc.setFont(newFont); + } } for (AreaRectangle areaRectangle : areaRectangles) { @@ -569,8 +589,9 @@ private void paintStringSegment(GC gc, String s, int swidth, int x, int y, clipY -= repaintRegion.y; clipLineY -= repaintRegion.y; } - if (rolloverMode && !hover) + if (rolloverMode && !hover) { reverse = true; + } if (reverse) { drawUnderline(gc, swidth, clipX, clipLineY, hover, rolloverMode); drawText(gc, s, clipX, clipY); @@ -593,8 +614,9 @@ private void drawUnderline(GC gc, int swidth, int x, int y, boolean hover, gc.setForeground(gc.getBackground()); } gc.drawLine(x, y, x + swidth-1, y); - if (saved != null) + if (saved != null) { gc.setForeground(saved); + } } } @@ -608,8 +630,9 @@ public void layout(GC gc, int width, Locator locator, if (fontId != null) { oldFont = gc.getFont(); Font newFont = (Font) resourceTable.get(fontId); - if (newFont != null) + if (newFont != null) { gc.setFont(newFont); + } } FontMetrics fm = gc.getFontMetrics(); int lineHeight = fm.getHeight(); @@ -627,8 +650,9 @@ public void layout(GC gc, int width, Locator locator, for (int i = 0; i < textFragments.length; i++) { TextFragment fragment = textFragments[i]; int breakLoc = fragment.index; - if (breakLoc == 0) + if (breakLoc == 0) { continue; + } // (i != 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0)) means: // only wrap on the first fragment if we are not at the start of a line if ((i != 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0)) && locator.x + lineExtent.x + fragment.length > rightEdge) { @@ -645,8 +669,9 @@ public void layout(GC gc, int width, Locator locator, locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); locator.resetCaret(); - if (isSelectable()) + if (isSelectable()) { locator.x += 1; + } locator.y += locator.rowHeight; locator.rowCounter++; locator.rowHeight = 0; @@ -661,8 +686,9 @@ public void layout(GC gc, int width, Locator locator, //String lastLine = text.substring(lineStart, lastLoc); int ly = locator.getBaseline(lineHeight - fm.getLeading()); int lastWidth = lineExtent.x; - if (isSelectable()) + if (isSelectable()) { lastWidth += 1; + } Rectangle br = new Rectangle(isSelectable()?locator.x - 1:locator.x, ly, isSelectable()?lineExtent.x + 1:lineExtent.x, lineHeight - descent + 3); @@ -677,15 +703,17 @@ public void layout(GC gc, int width, Locator locator, } private void computeTextFragments(GC gc) { - if (textFragments != null) + if (textFragments != null) { return; + } ArrayList list = new ArrayList<>(); BreakIterator wb = BreakIterator.getLineInstance(); wb.setText(getText()); int cursor = 0; for (int loc = wb.first(); loc != BreakIterator.DONE; loc = wb.next()) { - if (loc == 0) + if (loc == 0) { continue; + } String word = text.substring(cursor, loc); Point extent = gc.textExtent(word); list.add(new TextFragment((short) loc, (short) extent.x)); @@ -697,9 +725,10 @@ private void computeTextFragments(GC gc) { @Override public void clearCache(String fontId) { - if (fontId==null && (this.fontId==null||this.fontId.equals(FormTextModel.BOLD_FONT_ID))) + if (fontId==null && (this.fontId==null||this.fontId.equals(FormTextModel.BOLD_FONT_ID))) { textFragments = null; - else if (fontId!=null && this.fontId!=null && fontId.equals(this.fontId)) + } else if (fontId!=null && this.fontId!=null && fontId.equals(this.fontId)) { textFragments = null; + } } } diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TitleRegion.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TitleRegion.java index b3aa9f19b63..7fc3d1317ed 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TitleRegion.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TitleRegion.java @@ -65,9 +65,9 @@ public class TitleRegion extends Canvas { private Image image; private BusyIndicator busyLabel; private Control currentTitleControl; - private Label titleLabel; - private StyledText titleText; - private SizeCache titleCache; + private final Label titleLabel; + private final StyledText titleText; + private final SizeCache titleCache; private int fontHeight = -1; private int fontBaselineHeight = -1; private MenuHyperlink menuHyperlink; @@ -97,10 +97,11 @@ public void mouseHover(MouseEvent e) { @Override public void mouseMove(MouseEvent e) { - if (e.button > 0) + if (e.button > 0) { setHoverState(STATE_NORMAL); - else + } else { setHoverState(STATE_HOVER_FULL); + } } } @@ -153,17 +154,21 @@ private Point layout(Composite composite, boolean move, int x, int y, if (menuManager != null) { menuHyperlink.setVisible(!menuManager.isEmpty() && currentTitleControl.getVisible()); - if (menuHyperlink.getVisible()) + if (menuHyperlink.getVisible()) { msize = menuHyperlink.computeSize(SWT.DEFAULT, SWT.DEFAULT); + } } - if (flushCache) + if (flushCache) { titleCache.flush(); + } titleCache.setControl(currentTitleControl); int twidth = iwidth == SWT.DEFAULT ? iwidth : iwidth - SPACING * 2; - if (bsize != null && twidth != SWT.DEFAULT) + if (bsize != null && twidth != SWT.DEFAULT) { twidth -= bsize.x + SPACING; - if (msize != null && twidth != SWT.DEFAULT) + } + if (msize != null && twidth != SWT.DEFAULT) { twidth -= msize.x + SPACING; + } if (currentTitleControl.getVisible()) { tsize = titleCache.computeSize(twidth, SWT.DEFAULT); if (twidth != SWT.DEFAULT) { @@ -176,8 +181,9 @@ private Point layout(Composite composite, boolean move, int x, int y, // System.out.println("twidth="+twidth+", // tsize.x="+tsize.x); //$NON-NLS-1$//$NON-NLS-2$ } - } else + } else { tsize = new Point(0, 0); + } Point size = new Point(width, height); if (!move) { // compute size @@ -191,10 +197,11 @@ private Point layout(Composite composite, boolean move, int x, int y, size.x += msize.x + SPACING; size.y = Math.max(size.y, msize.y); } - if (size.y > 0) + if (size.y > 0) { size.y += VMARGIN * 2; // System.out.println("Compute size: width="+width+", // size.x="+size.x); //$NON-NLS-1$ //$NON-NLS-2$ + } } else { // position controls int xloc = x + HMARGIN + SPACING; @@ -212,10 +219,12 @@ private Point layout(Composite composite, boolean move, int x, int y, if (Constants.OS_LINUX.equalsIgnoreCase(os)) { tw += 1; // See Bug 342610 } - if (bsize != null) + if (bsize != null) { tw -= bsize.x + SPACING; - if (msize != null) + } + if (msize != null) { tw -= msize.x + SPACING; + } currentTitleControl.setBounds(xloc, // yloc + height / 2 - tsize.y / 2, yloc, tw, tsize.y); @@ -276,8 +285,9 @@ private void hookHoverListeners() { } private void onPaint(PaintEvent e) { - if (hoverState == STATE_NORMAL) + if (hoverState == STATE_NORMAL) { return; + } GC gc = e.gc; Rectangle carea = getClientArea(); gc.setBackground(getHoverBackground()); @@ -289,33 +299,38 @@ private void onPaint(PaintEvent e) { } private Color getHoverBackground() { - if (hoverState == STATE_NORMAL) + if (hoverState == STATE_NORMAL) { return null; + } Color color = getColor(hoverState == STATE_HOVER_FULL ? IFormColors.H_HOVER_FULL : IFormColors.H_HOVER_LIGHT); - if (color == null) + if (color == null) { color = getDisplay() .getSystemColor( hoverState == STATE_HOVER_FULL ? SWT.COLOR_WIDGET_BACKGROUND : SWT.COLOR_WIDGET_LIGHT_SHADOW); + } return color; } public void setHoverState(int state) { - if (dragSource == null || this.hoverState == state) + if (dragSource == null || this.hoverState == state) { return; + } this.hoverState = state; Color color = getHoverBackground(); titleLabel.setBackground(color != null ? color : getColor(FormHeading.COLOR_BASE_BG)); titleText.setBackground(color != null ? color : getColor(FormHeading.COLOR_BASE_BG)); - if (busyLabel != null) + if (busyLabel != null) { busyLabel.setBackground(color != null ? color : getColor(FormHeading.COLOR_BASE_BG)); - if (menuHyperlink != null) + } + if (menuHyperlink != null) { menuHyperlink.setBackground(color != null ? color : getColor(FormHeading.COLOR_BASE_BG)); + } redraw(); } @@ -355,13 +370,15 @@ public void updateImage(Image newImage, boolean doLayout) { if (busyLabel != null) { busyLabel.setImage(theImage); } - if (doLayout) + if (doLayout) { layout(); + } } public void updateToolTip(String toolTip) { - if (busyLabel != null) + if (busyLabel != null) { busyLabel.setToolTipText(toolTip); + } } @Override @@ -369,10 +386,12 @@ public void setBackground(Color bg) { super.setBackground(bg); titleLabel.setBackground(bg); titleText.setBackground(bg); - if (busyLabel != null) + if (busyLabel != null) { busyLabel.setBackground(bg); - if (menuHyperlink != null) + } + if (menuHyperlink != null) { menuHyperlink.setBackground(bg); + } } @Override @@ -380,8 +399,9 @@ public void setForeground(Color fg) { super.setForeground(fg); titleLabel.setForeground(fg); titleText.setForeground(fg); - if (menuHyperlink != null) + if (menuHyperlink != null) { menuHyperlink.setForeground(fg); + } } public void setText(String text) { @@ -438,14 +458,17 @@ private void ensureBusyLabelExists() { HoverListener listener = new HoverListener(); busyLabel.addMouseTrackListener(listener); busyLabel.addMouseMoveListener(listener); - if (menuManager != null) + if (menuManager != null) { busyLabel.setMenu(menuManager.createContextMenu(this)); - if (dragSupport) + } + if (dragSupport) { addDragSupport(busyLabel, dragOperations, dragTransferTypes, dragListener); + } IMessageToolTipManager mng = ((FormHeading) getParent()) .getMessageToolTipManager(); - if (mng != null) + if (mng != null) { mng.createToolTip(busyLabel, true); + } } } @@ -457,8 +480,9 @@ private void createMenuHyperlink() { HoverListener listener = new HoverListener(); menuHyperlink.addMouseTrackListener(listener); menuHyperlink.addMouseMoveListener(listener); - if (dragSupport) + if (dragSupport) { addDragSupport(menuHyperlink, dragOperations, dragTransferTypes, dragListener); + } } /** @@ -469,12 +493,14 @@ private void createMenuHyperlink() { * the form's busy state */ public boolean setBusy(boolean busy) { - if (busy) + if (busy) { ensureBusyLabelExists(); - else if (busyLabel == null) + } else if (busyLabel == null) { return false; - if (busy == busyLabel.isBusy()) + } + if (busy == busyLabel.isBusy()) { return false; + } busyLabel.setBusy(busy); if (busyLabel.getImage() == null) { layout(); @@ -525,8 +551,9 @@ public IMenuManager getMenuManager() { setMenu(menu); titleLabel.setMenu(menu); titleText.setMenu(menu); - if (busyLabel != null) + if (busyLabel != null) { busyLabel.setMenu(menu); + } createMenuHyperlink(); } return menuManager; @@ -541,10 +568,12 @@ public void addDragSupport(int operations, Transfer[] transferTypes, dragSource = addDragSupport(titleLabel, operations, transferTypes, listener); addDragSupport(this, operations, transferTypes, listener); - if (busyLabel != null) + if (busyLabel != null) { addDragSupport(busyLabel, operations, transferTypes, listener); - if (menuHyperlink != null) + } + if (menuHyperlink != null) { addDragSupport(menuHyperlink, operations, transferTypes, listener); + } } private DragSource addDragSupport(Control control, int operations, diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/WrappedPageBook.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/WrappedPageBook.java index be22234ecb5..3d7d03fc00b 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/WrappedPageBook.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/WrappedPageBook.java @@ -31,8 +31,9 @@ class PageBookLayout extends Layout implements ILayoutExtension { @Override protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { - if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) + if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) { return new Point(wHint, hHint); + } Point result = null; if (currentPage != null) { result = currentPage.computeSize(wHint, hHint, flushCache); @@ -86,10 +87,12 @@ public WrappedPageBook(Composite parent, int style) { * the page to show */ public void showPage(Control page) { - if (page == currentPage) + if (page == currentPage) { return; - if (page.getParent() != this) + } + if (page.getParent() != this) { return; + } Control oldPage = currentPage; currentPage = page; // show new page @@ -100,8 +103,9 @@ public void showPage(Control page) { } // hide old *after* new page has been made visible in order to avoid // flashing - if (oldPage != null && !oldPage.isDisposed()) + if (oldPage != null && !oldPage.isDisposed()) { oldPage.setVisible(false); + } } @Override