From b6841b55af37488af21594c4f1c8faf9ab7d0de6 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 11 Apr 2012 21:59:06 +0300 Subject: [PATCH] Removed deprecated an unneded setAlignment based on String (#8169) --- src/com/vaadin/ui/AbstractOrderedLayout.java | 18 +- src/com/vaadin/ui/AlignmentUtils.java | 151 ------------- src/com/vaadin/ui/GridLayout.java | 18 +- .../com/vaadin/tests/tickets/Ticket2279.java | 210 ------------------ 4 files changed, 2 insertions(+), 395 deletions(-) delete mode 100644 src/com/vaadin/ui/AlignmentUtils.java delete mode 100644 tests/testbench/com/vaadin/tests/tickets/Ticket2279.java diff --git a/src/com/vaadin/ui/AbstractOrderedLayout.java b/src/com/vaadin/ui/AbstractOrderedLayout.java index 9b21a00836..0f2f670331 100644 --- a/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -18,9 +18,9 @@ import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.Vaadin6Component; import com.vaadin.terminal.gwt.client.Connector; import com.vaadin.terminal.gwt.client.MouseEventDetails; +import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler; import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutServerRPC; import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutState; -import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler; @SuppressWarnings("serial") public abstract class AbstractOrderedLayout extends AbstractLayout implements @@ -347,22 +347,6 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements return (ratio == null) ? 0 : ratio.floatValue(); } - /** - * Sets the component alignment using a short hand string notation. - * - * @deprecated Replaced by - * {@link #setComponentAlignment(Component, Alignment)} - * - * @param component - * A child component in this layout - * @param alignment - * A short hand notation described in {@link AlignmentUtils} - */ - @Deprecated - public void setComponentAlignment(Component component, String alignment) { - AlignmentUtils.setComponentAlignment(this, component, alignment); - } - public void addListener(LayoutClickListener listener) { addListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, LayoutClickEvent.class, listener, diff --git a/src/com/vaadin/ui/AlignmentUtils.java b/src/com/vaadin/ui/AlignmentUtils.java deleted file mode 100644 index 029fc8c9b5..0000000000 --- a/src/com/vaadin/ui/AlignmentUtils.java +++ /dev/null @@ -1,151 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.ui; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -import com.vaadin.ui.Layout.AlignmentHandler; - -/** - * Helper class for setting alignments using a short notation. - * - * Supported notation is: - * - * t,top for top alignment - * - * m,middle for vertical center alignment - * - * b,bottom for bottom alignment - * - * l,left for left alignment - * - * c,center for horizontal center alignment - * - * r,right for right alignment - * - * @deprecated {@code AlignmentUtils} has been replaced by {@link Alignment}. - */ -@SuppressWarnings({ "serial" }) -@Deprecated -public class AlignmentUtils implements Serializable { - - private static int horizontalMask = AlignmentHandler.ALIGNMENT_LEFT - | AlignmentHandler.ALIGNMENT_HORIZONTAL_CENTER - | AlignmentHandler.ALIGNMENT_RIGHT; - - private static int verticalMask = AlignmentHandler.ALIGNMENT_TOP - | AlignmentHandler.ALIGNMENT_VERTICAL_CENTER - | AlignmentHandler.ALIGNMENT_BOTTOM; - - private static Map alignmentStrings = new HashMap(); - - private static void addMapping(int alignment, String... values) { - for (String s : values) { - alignmentStrings.put(s, alignment); - } - } - - static { - addMapping(AlignmentHandler.ALIGNMENT_TOP, "t", "top"); - addMapping(AlignmentHandler.ALIGNMENT_BOTTOM, "b", "bottom"); - addMapping(AlignmentHandler.ALIGNMENT_VERTICAL_CENTER, "m", "middle"); - - addMapping(AlignmentHandler.ALIGNMENT_LEFT, "l", "left"); - addMapping(AlignmentHandler.ALIGNMENT_RIGHT, "r", "right"); - addMapping(AlignmentHandler.ALIGNMENT_HORIZONTAL_CENTER, "c", "center"); - } - - /** - * Set the alignment for the component using short notation - * - * @param parent - * @param component - * @param alignment - * String containing one or two alignment strings. If short - * notation "r","t",etc is used valid strings include - * "r","rt","tr","t". If the longer notation is used the - * alignments should be separated by a space e.g. - * "right","right top","top right","top". It is valid to mix - * short and long notation but they must be separated by a space - * e.g. "r top". - * @throws IllegalArgumentException - */ - public static void setComponentAlignment(AlignmentHandler parent, - Component component, String alignment) - throws IllegalArgumentException { - if (alignment == null || alignment.length() == 0) { - throw new IllegalArgumentException( - "alignment for setComponentAlignment() cannot be null or empty"); - } - - Integer currentAlignment = parent.getComponentAlignment(component) - .getBitMask(); - - if (alignment.length() == 1) { - // Use short form "t","l",... - currentAlignment = parseAlignment(alignment.substring(0, 1), - currentAlignment); - } else if (alignment.length() == 2) { - // Use short form "tr","lb",... - currentAlignment = parseAlignment(alignment.substring(0, 1), - currentAlignment); - currentAlignment = parseAlignment(alignment.substring(1, 2), - currentAlignment); - } else { - // Alignments are separated by space - String[] strings = alignment.split(" "); - if (strings.length > 2) { - throw new IllegalArgumentException( - "alignment for setComponentAlignment() should not contain more than 2 alignments"); - } - for (String alignmentString : strings) { - currentAlignment = parseAlignment(alignmentString, - currentAlignment); - } - } - - int horizontalAlignment = currentAlignment & horizontalMask; - int verticalAlignment = currentAlignment & verticalMask; - parent.setComponentAlignment(component, new Alignment( - horizontalAlignment + verticalAlignment)); - } - - /** - * Parse alignmentString which contains one alignment (horizontal or - * vertical) and return and updated version of the passed alignment where - * the alignment in one direction has been changed. If the passed - * alignmentString is unknown an exception is thrown - * - * @param alignmentString - * @param alignment - * @return - * @throws IllegalArgumentException - */ - private static int parseAlignment(String alignmentString, int alignment) - throws IllegalArgumentException { - Integer parsed = alignmentStrings.get(alignmentString.toLowerCase()); - - if (parsed == null) { - throw new IllegalArgumentException( - "Could not parse alignment string '" + alignmentString - + "'"); - } - - if ((parsed & horizontalMask) != 0) { - // Get the vertical alignment from the current alignment - int vertical = (alignment & verticalMask); - // Add the parsed horizontal alignment - alignment = (vertical | parsed); - } else { - // Get the horizontal alignment from the current alignment - int horizontal = (alignment & horizontalMask); - // Add the parsed vertical alignment - alignment = (horizontal | parsed); - } - - return alignment; - } -} diff --git a/src/com/vaadin/ui/GridLayout.java b/src/com/vaadin/ui/GridLayout.java index 3166baf321..689cdcf28e 100644 --- a/src/com/vaadin/ui/GridLayout.java +++ b/src/com/vaadin/ui/GridLayout.java @@ -21,9 +21,9 @@ import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Vaadin6Component; import com.vaadin.terminal.gwt.client.Connector; import com.vaadin.terminal.gwt.client.MouseEventDetails; +import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler; import com.vaadin.terminal.gwt.client.ui.gridlayout.GridLayoutServerRPC; import com.vaadin.terminal.gwt.client.ui.gridlayout.GridLayoutState; -import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler; /** * A layout where the components are laid out on a grid using cell coordinates. @@ -1388,22 +1388,6 @@ public class GridLayout extends AbstractLayout implements return null; } - /** - * Sets the component alignment using a shorthand string notation. - * - * @deprecated Replaced by - * {@link #setComponentAlignment(Component, Alignment)} - * - * @param component - * A child component in this layout - * @param alignment - * A short hand notation described in {@link AlignmentUtils} - */ - @Deprecated - public void setComponentAlignment(Component component, String alignment) { - AlignmentUtils.setComponentAlignment(this, component, alignment); - } - public void addListener(LayoutClickListener listener) { addListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, LayoutClickEvent.class, listener, diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2279.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2279.java deleted file mode 100644 index 1e39cd0b8c..0000000000 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2279.java +++ /dev/null @@ -1,210 +0,0 @@ -package com.vaadin.tests.tickets; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import com.vaadin.Application; -import com.vaadin.terminal.gwt.client.ui.AlignmentInfo; -import com.vaadin.ui.AbstractOrderedLayout; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Label.ContentMode; -import com.vaadin.ui.Layout; -import com.vaadin.ui.Layout.AlignmentHandler; -import com.vaadin.ui.Root.LegacyWindow; -import com.vaadin.ui.VerticalLayout; - -// This tests the deprecated setComponentAlignment(Component,String) API -@SuppressWarnings("deprecation") -public class Ticket2279 extends Application.LegacyApplication { - - private Label label; - - private static Map expected = new HashMap(); - - private static Set longHorizontalAlignments = new HashSet(); - private static Set shortHorizontalAlignments = new HashSet(); - private static Set longVerticalAlignments = new HashSet(); - private static Set shortVerticalAlignments = new HashSet(); - - static { - expected.put("r", AlignmentInfo.Bits.ALIGNMENT_RIGHT); - expected.put("l", AlignmentInfo.Bits.ALIGNMENT_LEFT); - expected.put("c", AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER); - expected.put("t", AlignmentInfo.Bits.ALIGNMENT_TOP); - expected.put("b", AlignmentInfo.Bits.ALIGNMENT_BOTTOM); - expected.put("m", AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER); - - expected.put("right", AlignmentInfo.Bits.ALIGNMENT_RIGHT); - expected.put("left", AlignmentInfo.Bits.ALIGNMENT_LEFT); - expected.put("center", AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER); - expected.put("top", AlignmentInfo.Bits.ALIGNMENT_TOP); - expected.put("bottom", AlignmentInfo.Bits.ALIGNMENT_BOTTOM); - expected.put("middle", AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER); - - shortHorizontalAlignments.add("r"); - shortHorizontalAlignments.add("l"); - shortHorizontalAlignments.add("c"); - shortVerticalAlignments.add("t"); - shortVerticalAlignments.add("b"); - shortVerticalAlignments.add("m"); - - longHorizontalAlignments.add("right"); - longHorizontalAlignments.add("left"); - longHorizontalAlignments.add("center"); - longVerticalAlignments.add("top"); - longVerticalAlignments.add("bottom"); - longVerticalAlignments.add("middle"); - - } - - @Override - public void init() { - LegacyWindow w = new LegacyWindow(getClass().getSimpleName()); - setMainWindow(w); - setTheme("tests-tickets"); - AbstractOrderedLayout layout = (AbstractOrderedLayout) w.getContent(); - - createUI(layout); - } - - private void createUI(Layout layout) { - VerticalLayout vl = new VerticalLayout(); - vl.setWidth("500px"); - vl.setHeight("500px"); - vl.setStyleName("borders"); - label = new Label("Error messages follows:
", - ContentMode.XHTML); - vl.addComponent(label); - layout.addComponent(vl); - - testAlignments(vl); - - GridLayout gl = new GridLayout(1, 1); - gl.setWidth("500px"); - gl.setHeight("500px"); - gl.setStyleName("borders"); - label = new Label("Error messages follows:
", - ContentMode.XHTML); - gl.addComponent(label); - layout.addComponent(gl); - - testAlignments(gl); - - } - - private void testAlignments(AlignmentHandler layout) { - HashSet horizontals = new HashSet(); - horizontals.addAll(shortHorizontalAlignments); - horizontals.addAll(longHorizontalAlignments); - - for (String horiz : horizontals) { - // Test "l","r","left","right" etc - int expectedHoriz = expected.get(horiz); - checkAlignment(layout, horiz, AlignmentHandler.ALIGNMENT_TOP - | expectedHoriz); - - for (String vert : shortVerticalAlignments) { - int expectedVert = expected.get(vert); - - // Test "lt","rt" etc - if (horiz.length() == 1) { - checkAlignment(layout, horiz + vert, expectedHoriz - | expectedVert); - checkAlignment(layout, vert + horiz, expectedHoriz - | expectedVert); - } else { - boolean ok = false; - try { - checkAlignment(layout, horiz + vert, expectedHoriz - | expectedVert); - } catch (IllegalArgumentException e) { - // OK, "centert","rightb" etc are not valid - ok = true; - } - if (!ok) { - error("IllegalArgumentException was not thrown for " - + horiz + vert); - } - ok = false; - try { - checkAlignment(layout, vert + horiz, expectedHoriz - | expectedVert); - } catch (IllegalArgumentException e) { - // OK, "centert","rightb" etc are not valid - ok = true; - } - if (!ok) { - error("IllegalArgumentException was not thrown for " - + horiz + vert); - } - - } - - // Test "l t","r t" etc - checkAlignment(layout, horiz + " " + vert, expectedHoriz - | expectedVert); - checkAlignment(layout, vert + " " + horiz, expectedHoriz - | expectedVert); - } - - for (String vert : longVerticalAlignments) { - int expectedVert = expected.get(vert); - - // Test "right t","right b" etc - checkAlignment(layout, horiz + " " + vert, expectedHoriz - | expectedVert); - checkAlignment(layout, vert + " " + horiz, expectedHoriz - | expectedVert); - - // Three alignments should throw an exception - boolean ok = false; - try { - checkAlignment(layout, horiz + " " + vert + " " + horiz, - expectedHoriz | expectedVert); - } catch (IllegalArgumentException e) { - // OK, "centert","rightb" etc are not valid - ok = true; - } - if (!ok) { - error("IllegalArgumentException was not thrown for " - + horiz + " " + vert + " " + horiz); - } - } - } - - checkAlignment(layout, "left right", AlignmentHandler.ALIGNMENT_TOP - | AlignmentHandler.ALIGNMENT_RIGHT); - } - - private void checkAlignment(AlignmentHandler layout, - String alignmentString, int expected) { - layout.setComponentAlignment(label, AlignmentInfo.Bits.ALIGNMENT_TOP, - AlignmentInfo.Bits.ALIGNMENT_LEFT); - if (layout instanceof AbstractOrderedLayout) { - ((AbstractOrderedLayout) layout).setComponentAlignment(label, - alignmentString); - } else { - ((GridLayout) layout).setComponentAlignment(label, alignmentString); - } - - int actual = layout.getComponentAlignment(label).getBitMask(); - if (actual != expected) { - String error = "Error " + alignmentString - + " did not produce expected results"; - error(error); - } else { - String str = layout.getClass().getSimpleName() + "/" - + alignmentString + ": OK"; - System.out.println(str); - } - - } - - private void error(String error) { - label.setValue(label.getValue() + error + "
"); - System.out.println(error); - } -} -- 2.39.5