Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTreeViewSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTreeViewSkin.java?rev=1887553&r1=1887552&r2=1887553&view=diff ============================================================================== --- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTreeViewSkin.java (original) +++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTreeViewSkin.java Fri Mar 12 21:04:51 2021 @@ -74,7 +74,7 @@ public class TerraTreeViewSkin extends C * * @param nodeInfo The object to visit */ - public void visit(NodeInfo nodeInfo); + void visit(NodeInfo nodeInfo); } /** @@ -98,16 +98,16 @@ public class TerraTreeViewSkin extends C * Creates a new visible node iterator that will iterate over a portion * of the visible nodes list (useful during painting). * - * @param start The start index, inclusive - * @param end The end index, inclusive + * @param startIndex The start index, inclusive + * @param endIndex The end index, inclusive */ - public VisibleNodeIterator(int start, int end) { - if (start < 0 || end >= visibleNodes.getLength()) { + public VisibleNodeIterator(final int startIndex, final int endIndex) { + if (startIndex < 0 || endIndex >= visibleNodes.getLength()) { throw new IndexOutOfBoundsException(); } - this.index = start; - this.end = end; + this.index = startIndex; + this.end = endIndex; } /** @@ -199,7 +199,7 @@ public class TerraTreeViewSkin extends C * cached here to provide further optimizations during painting and user * input. */ - protected static class NodeInfo { + private static class NodeInfo { // Core metadata final TreeView treeView; final BranchInfo parent; @@ -221,10 +221,11 @@ public class TerraTreeViewSkin extends C public static final byte CHECK_STATE_MASK = CHECK_STATE_CHECKED_MASK | CHECK_STATE_MIXED_MASK; - protected NodeInfo(TreeView treeView, BranchInfo parent, Object data) { - this.treeView = treeView; - this.parent = parent; - this.data = data; + public NodeInfo(final TreeView treeViewValue, final BranchInfo parentValue, + final Object dataValue) { + this.treeView = treeViewValue; + this.parent = parentValue; + this.data = dataValue; depth = (parent == null) ? 0 : parent.depth + 1; @@ -246,7 +247,7 @@ public class TerraTreeViewSkin extends C } @SuppressWarnings("unchecked") - private static NodeInfo newInstance(TreeView treeView, BranchInfo parent, Object data) { + public static NodeInfo newInstance(final TreeView treeView, final BranchInfo parent, final Object data) { NodeInfo nodeInfo = null; if (data instanceof List<?>) { @@ -279,7 +280,7 @@ public class TerraTreeViewSkin extends C return ((fields & HIGHLIGHTED_MASK) != 0); } - public void setHighlighted(boolean highlighted) { + public void setHighlighted(final boolean highlighted) { if (highlighted) { fields |= HIGHLIGHTED_MASK; } else { @@ -291,7 +292,7 @@ public class TerraTreeViewSkin extends C return ((fields & SELECTED_MASK) != 0); } - public void setSelected(boolean selected) { + public void setSelected(final boolean selected) { if (selected) { fields |= SELECTED_MASK; } else { @@ -303,7 +304,7 @@ public class TerraTreeViewSkin extends C return ((fields & DISABLED_MASK) != 0); } - public void setDisabled(boolean disabled) { + public void setDisabled(final boolean disabled) { if (disabled) { fields |= DISABLED_MASK; } else { @@ -315,7 +316,7 @@ public class TerraTreeViewSkin extends C return ((fields & CHECKMARK_DISABLED_MASK) != 0); } - public void setCheckmarkDisabled(boolean checkmarkDisabled) { + public void setCheckmarkDisabled(final boolean checkmarkDisabled) { if (checkmarkDisabled) { fields |= CHECKMARK_DISABLED_MASK; } else { @@ -345,7 +346,7 @@ public class TerraTreeViewSkin extends C return ((fields & CHECK_STATE_CHECKED_MASK) != 0); } - public void setCheckState(TreeView.NodeCheckState checkState) { + public void setCheckState(final TreeView.NodeCheckState checkState) { fields &= ~CHECK_STATE_MASK; switch (checkState) { @@ -362,7 +363,7 @@ public class TerraTreeViewSkin extends C } } - public void clearField(byte mask) { + public void clearField(final byte mask) { fields &= ~mask; } @@ -376,13 +377,13 @@ public class TerraTreeViewSkin extends C * An internal data structure that keeps track of skin-related metadata for * a tree branch. */ - protected static final class BranchInfo extends NodeInfo { + private static final class BranchInfo extends NodeInfo { // Core skin metadata private List<NodeInfo> children = null; public static final byte EXPANDED_MASK = 1 << 6; - private BranchInfo(TreeView treeView, BranchInfo parent, List<Object> data) { + public BranchInfo(final TreeView treeView, final BranchInfo parent, final List<Object> data) { super(treeView, parent, data); } @@ -414,7 +415,7 @@ public class TerraTreeViewSkin extends C return ((fields & EXPANDED_MASK) != 0); } - public void setExpanded(boolean expanded) { + public void setExpanded(final boolean expanded) { if (expanded) { fields |= EXPANDED_MASK; } else { @@ -466,34 +467,21 @@ public class TerraTreeViewSkin extends C } public TerraTreeViewSkin() { - Theme theme = currentTheme(); + } - font = theme.getFont(); - color = theme.getColor(1); - disabledColor = theme.getColor(7); - backgroundColor = theme.getColor(4); - selectionColor = theme.getColor(4); - selectionBackgroundColor = theme.getColor(14); - inactiveSelectionColor = theme.getColor(1); - inactiveSelectionBackgroundColor = theme.getColor(10); - highlightColor = theme.getColor(1); - highlightBackgroundColor = theme.getColor(10); - spacing = 6; - indent = 16; - showHighlight = true; - showBranchControls = true; - showEmptyBranchControls = true; - branchControlColor = theme.getColor(12); - branchControlSelectionColor = theme.getColor(4); - branchControlInactiveSelectionColor = theme.getColor(14); - gridColor = theme.getColor(11); - showGridLines = false; + /** @return the {@code TreeView} we are attached to. */ + public TreeView getTreeView() { + return (TreeView) getComponent(); } @Override - public void install(Component component) { + public void install(final Component component) { super.install(component); + font = getThemeFont(); + + setDefaultStyles(); + TreeView treeView = (TreeView) component; treeView.getTreeViewListeners().add(this); treeView.getTreeViewBranchListeners().add(this); @@ -505,8 +493,8 @@ public class TerraTreeViewSkin extends C } @Override - public int getPreferredWidth(int height) { - TreeView treeView = (TreeView) getComponent(); + public int getPreferredWidth(final int height) { + TreeView treeView = getTreeView(); TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer(); int preferredWidth = 0; @@ -537,7 +525,7 @@ public class TerraTreeViewSkin extends C } @Override - public int getPreferredHeight(int width) { + public int getPreferredHeight(final int width) { int nodeHeight = getNodeHeight(); int visibleNodeCount = visibleNodes.getLength(); @@ -551,11 +539,11 @@ public class TerraTreeViewSkin extends C } @Override - public int getBaseline(int width, int height) { + public int getBaseline(final int width, final int height) { int baseline = -1; if (visibleNodes.getLength() > 0) { - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer(); NodeInfo nodeInfo = visibleNodes.get(0); @@ -602,8 +590,8 @@ public class TerraTreeViewSkin extends C } @Override - public void paint(Graphics2D graphics) { - TreeView treeView = (TreeView) getComponent(); + public void paint(final Graphics2D graphics) { + TreeView treeView = getTreeView(); TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer(); int width = getWidth(); @@ -779,244 +767,235 @@ public class TerraTreeViewSkin extends C return font; } - public void setFont(Font font) { - Utils.checkNull(font, "font"); + public void setFont(final Font newFont) { + Utils.checkNull(newFont, "font"); - this.font = font; + this.font = newFont; invalidateComponent(); } - public final void setFont(String font) { - setFont(decodeFont(font)); + public final void setFont(final String fontString) { + setFont(decodeFont(fontString)); } - public final void setFont(Dictionary<String, ?> font) { - setFont(Theme.deriveFont(font)); + public final void setFont(final Dictionary<String, ?> fontDictionary) { + setFont(Theme.deriveFont(fontDictionary)); } public Color getColor() { return color; } - public void setColor(Color color) { - Utils.checkNull(color, "color"); + public void setColor(final Color colorValue) { + Utils.checkNull(colorValue, "color"); - this.color = color; + this.color = colorValue; repaintComponent(); } - public void setColor(String color) { - setColor(GraphicsUtilities.decodeColor(color, "color")); + public void setColor(final String colorString) { + setColor(GraphicsUtilities.decodeColor(colorString, "color")); } - public final void setColor(int color) { - Theme theme = currentTheme(); - setColor(theme.getColor(color)); + public final void setColor(final int colorIndex) { + setColor(getColor(colorIndex)); } public Color getDisabledColor() { return disabledColor; } - public void setDisabledColor(Color disabledColor) { - Utils.checkNull(disabledColor, "disabledColor"); + public void setDisabledColor(final Color disabledColorValue) { + Utils.checkNull(disabledColorValue, "disabledColor"); - this.disabledColor = disabledColor; + this.disabledColor = disabledColorValue; repaintComponent(); } - public void setDisabledColor(String disabledColor) { - setDisabledColor(GraphicsUtilities.decodeColor(disabledColor, "disabledColor")); + public void setDisabledColor(final String disabledColorString) { + setDisabledColor(GraphicsUtilities.decodeColor(disabledColorString, "disabledColor")); } - public final void setDisabledColor(int disabledColor) { - Theme theme = currentTheme(); - setDisabledColor(theme.getColor(disabledColor)); + public final void setDisabledColor(final int disabledColorIndex) { + setDisabledColor(getColor(disabledColorIndex)); } public Color getBackgroundColor() { return backgroundColor; } - public void setBackgroundColor(Color backgroundColor) { + public void setBackgroundColor(final Color backgroundColorValue) { // We allow a null background color here - this.backgroundColor = backgroundColor; + this.backgroundColor = backgroundColorValue; repaintComponent(); } - public void setBackgroundColor(String backgroundColor) { - setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColor, "backgroundColor")); + public void setBackgroundColor(final String backgroundColorString) { + setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColorString, "backgroundColor")); } - public final void setBackgroundColor(int backgroundColor) { - Theme theme = currentTheme(); - setBackgroundColor(theme.getColor(backgroundColor)); + public final void setBackgroundColor(final int backgroundColorIndex) { + setBackgroundColor(getColor(backgroundColorIndex)); } public Color getSelectionColor() { return selectionColor; } - public void setSelectionColor(Color selectionColor) { - Utils.checkNull(selectionColor, "selectionColor"); + public void setSelectionColor(final Color selectionColorValue) { + Utils.checkNull(selectionColorValue, "selectionColor"); - this.selectionColor = selectionColor; + this.selectionColor = selectionColorValue; repaintComponent(); } - public void setSelectionColor(String selectionColor) { - setSelectionColor(GraphicsUtilities.decodeColor(selectionColor, "selectionColor")); + public void setSelectionColor(final String selectionColorString) { + setSelectionColor(GraphicsUtilities.decodeColor(selectionColorString, "selectionColor")); } - public final void setSelectionColor(int selectionColor) { - Theme theme = currentTheme(); - setSelectionColor(theme.getColor(selectionColor)); + public final void setSelectionColor(final int selectionColorIndex) { + setSelectionColor(getColor(selectionColorIndex)); } public Color getSelectionBackgroundColor() { return selectionBackgroundColor; } - public void setSelectionBackgroundColor(Color selectionBackgroundColor) { - Utils.checkNull(selectionBackgroundColor, "selectionBackgroundColor"); + public void setSelectionBackgroundColor(final Color selectionBackgroundColorValue) { + Utils.checkNull(selectionBackgroundColorValue, "selectionBackgroundColor"); - this.selectionBackgroundColor = selectionBackgroundColor; + this.selectionBackgroundColor = selectionBackgroundColorValue; repaintComponent(); } - public void setSelectionBackgroundColor(String selectionBackgroundColor) { + public void setSelectionBackgroundColor(final String selectionBackgroundColorString) { setSelectionBackgroundColor( - GraphicsUtilities.decodeColor(selectionBackgroundColor, "selectionBackgroundColor")); + GraphicsUtilities.decodeColor(selectionBackgroundColorString, "selectionBackgroundColor")); } - public final void setSelectionBackgroundColor(int selectionBackgroundColor) { - Theme theme = currentTheme(); - setSelectionBackgroundColor(theme.getColor(selectionBackgroundColor)); + public final void setSelectionBackgroundColor(final int selectionBackgroundColorIndex) { + setSelectionBackgroundColor(getColor(selectionBackgroundColorIndex)); } public Color getInactiveSelectionColor() { return inactiveSelectionColor; } - public void setInactiveSelectionColor(Color inactiveSelectionColor) { - Utils.checkNull(inactiveSelectionColor, "inactiveSelectionColor"); + public void setInactiveSelectionColor(final Color inactiveSelectionColorValue) { + Utils.checkNull(inactiveSelectionColorValue, "inactiveSelectionColor"); - this.inactiveSelectionColor = inactiveSelectionColor; + this.inactiveSelectionColor = inactiveSelectionColorValue; repaintComponent(); } - public void setInactiveSelectionColor(String inactiveSelectionColor) { + public void setInactiveSelectionColor(final String inactiveSelectionColorString) { setInactiveSelectionColor( - GraphicsUtilities.decodeColor(inactiveSelectionColor, "inactiveSelectionColor")); + GraphicsUtilities.decodeColor(inactiveSelectionColorString, "inactiveSelectionColor")); } - public final void setInactiveSelectionColor(int inactiveSelectionColor) { - Theme theme = currentTheme(); - setInactiveSelectionColor(theme.getColor(inactiveSelectionColor)); + public final void setInactiveSelectionColor(final int inactiveSelectionColorIndex) { + setInactiveSelectionColor(getColor(inactiveSelectionColorIndex)); } public Color getInactiveSelectionBackgroundColor() { return inactiveSelectionBackgroundColor; } - public void setInactiveSelectionBackgroundColor(Color inactiveSelectionBackgroundColor) { - Utils.checkNull(inactiveSelectionBackgroundColor, "inactiveSelectionBackgroundColor"); + public void setInactiveSelectionBackgroundColor(final Color inactiveSelectionBackgroundColorValue) { + Utils.checkNull(inactiveSelectionBackgroundColorValue, "inactiveSelectionBackgroundColor"); - this.inactiveSelectionBackgroundColor = inactiveSelectionBackgroundColor; + this.inactiveSelectionBackgroundColor = inactiveSelectionBackgroundColorValue; repaintComponent(); } - public void setInactiveSelectionBackgroundColor(String inactiveSelectionBackgroundColor) { + public void setInactiveSelectionBackgroundColor(final String inactiveSelectionBackgroundString) { setInactiveSelectionBackgroundColor( - GraphicsUtilities.decodeColor(inactiveSelectionBackgroundColor, "inactiveSelectionBackgroundColor")); + GraphicsUtilities.decodeColor(inactiveSelectionBackgroundString, "inactiveSelectionBackgroundColor")); } - public final void setInactiveSelectionBackgroundColor(int inactiveSelectionBackgroundColor) { - Theme theme = currentTheme(); - setInactiveSelectionBackgroundColor(theme.getColor(inactiveSelectionBackgroundColor)); + public final void setInactiveSelectionBackgroundColor(final int inactiveSelectionBackgroundIndex) { + setInactiveSelectionBackgroundColor(getColor(inactiveSelectionBackgroundIndex)); } public Color getHighlightColor() { return highlightColor; } - public void setHighlightColor(Color highlightColor) { - Utils.checkNull(highlightColor, "highlightColor"); + public void setHighlightColor(final Color highlightColorValue) { + Utils.checkNull(highlightColorValue, "highlightColor"); - this.highlightColor = highlightColor; + this.highlightColor = highlightColorValue; repaintComponent(); } - public void setHighlightColor(String highlightColor) { - setHighlightColor(GraphicsUtilities.decodeColor(highlightColor, "highlightColor")); + public void setHighlightColor(final String highlightColorString) { + setHighlightColor(GraphicsUtilities.decodeColor(highlightColorString, "highlightColor")); } - public final void setHighlightColor(int highlightColor) { - Theme theme = currentTheme(); - setHighlightColor(theme.getColor(highlightColor)); + public final void setHighlightColor(final int highlightColorIndex) { + setHighlightColor(getColor(highlightColorIndex)); } public Color getHighlightBackgroundColor() { return highlightBackgroundColor; } - public void setHighlightBackgroundColor(Color highlightBackgroundColor) { - Utils.checkNull(highlightBackgroundColor, "highlightBackgroundColor"); + public void setHighlightBackgroundColor(final Color highlightBackgroundColorValue) { + Utils.checkNull(highlightBackgroundColorValue, "highlightBackgroundColor"); - this.highlightBackgroundColor = highlightBackgroundColor; + this.highlightBackgroundColor = highlightBackgroundColorValue; repaintComponent(); } - public void setHighlightBackgroundColor(String highlightBackgroundColor) { + public void setHighlightBackgroundColor(final String highlightBackgroundColorString) { setHighlightBackgroundColor( - GraphicsUtilities.decodeColor(highlightBackgroundColor, "highlightBackgroundColor")); + GraphicsUtilities.decodeColor(highlightBackgroundColorString, "highlightBackgroundColor")); } - public final void setHighlightBackgroundColor(int highlightBackgroundColor) { - Theme theme = currentTheme(); - setHighlightBackgroundColor(theme.getColor(highlightBackgroundColor)); + public final void setHighlightBackgroundColor(final int highlightBackgroundColorIndex) { + setHighlightBackgroundColor(getColor(highlightBackgroundColorIndex)); } public int getSpacing() { return spacing; } - public void setSpacing(int spacing) { - Utils.checkNonNegative(spacing, "spacing"); + public void setSpacing(final int spacingValue) { + Utils.checkNonNegative(spacingValue, "spacing"); - this.spacing = spacing; + this.spacing = spacingValue; invalidateComponent(); } - public void setSpacing(Number spacing) { - Utils.checkNull(spacing, "spacing"); + public void setSpacing(final Number spacingValue) { + Utils.checkNull(spacingValue, "spacing"); - setSpacing(spacing.intValue()); + setSpacing(spacingValue.intValue()); } public int getIndent() { return indent; } - public void setIndent(int indent) { - Utils.checkNonNegative(indent, "indent"); + public void setIndent(final int indentValue) { + Utils.checkNonNegative(indentValue, "indent"); - this.indent = indent; + this.indent = indentValue; invalidateComponent(); } - public void setIndent(Number indent) { - Utils.checkNull(indent, "indent"); + public void setIndent(final Number indentValue) { + Utils.checkNull(indentValue, "indent"); - setIndent(indent.intValue()); + setIndent(indentValue.intValue()); } public boolean getShowHighlight() { return showHighlight; } - public void setShowHighlight(boolean showHighlight) { - this.showHighlight = showHighlight; + public void setShowHighlight(final boolean showHighlightValue) { + this.showHighlight = showHighlightValue; repaintComponent(); } @@ -1024,8 +1003,8 @@ public class TerraTreeViewSkin extends C return showBranchControls; } - public void setShowBranchControls(boolean showBranchControls) { - this.showBranchControls = showBranchControls; + public void setShowBranchControls(final boolean showBranchControlsValue) { + this.showBranchControls = showBranchControlsValue; invalidateComponent(); } @@ -1033,8 +1012,8 @@ public class TerraTreeViewSkin extends C return showEmptyBranchControls; } - public void setShowEmptyBranchControls(boolean showEmptyBranchControls) { - this.showEmptyBranchControls = showEmptyBranchControls; + public void setShowEmptyBranchControls(final boolean showEmptyBranchControlsValue) { + this.showEmptyBranchControls = showEmptyBranchControlsValue; repaintComponent(); } @@ -1042,90 +1021,86 @@ public class TerraTreeViewSkin extends C return branchControlColor; } - public void setBranchControlColor(Color branchControlColor) { - Utils.checkNull(branchControlColor, "branchControlColor"); + public void setBranchControlColor(final Color branchControlColorValue) { + Utils.checkNull(branchControlColorValue, "branchControlColor"); - this.branchControlColor = branchControlColor; + this.branchControlColor = branchControlColorValue; repaintComponent(); } - public void setBranchControlColor(String branchControlColor) { - setBranchControlColor(GraphicsUtilities.decodeColor(branchControlColor, "branchControlColor")); + public void setBranchControlColor(final String branchControlColorString) { + setBranchControlColor(GraphicsUtilities.decodeColor(branchControlColorString, "branchControlColor")); } - public final void setBranchControlColor(int branchControlColor) { - Theme theme = currentTheme(); - setBranchControlColor(theme.getColor(branchControlColor)); + public final void setBranchControlColor(final int branchControlColorIndex) { + setBranchControlColor(getColor(branchControlColorIndex)); } public Color getBranchControlSelectionColor() { return branchControlSelectionColor; } - public void setBranchControlSelectionColor(Color branchControlSelectionColor) { - Utils.checkNull(branchControlSelectionColor, "branchControlSelectionColor"); + public void setBranchControlSelectionColor(final Color branchControlSelectionColorValue) { + Utils.checkNull(branchControlSelectionColorValue, "branchControlSelectionColor"); - this.branchControlSelectionColor = branchControlSelectionColor; + this.branchControlSelectionColor = branchControlSelectionColorValue; repaintComponent(); } - public void setBranchControlSelectionColor(String branchControlSelectionColor) { + public void setBranchControlSelectionColor(final String branchControlSelectionColorString) { setBranchControlSelectionColor( - GraphicsUtilities.decodeColor(branchControlSelectionColor, "branchControlSelectionColor")); + GraphicsUtilities.decodeColor(branchControlSelectionColorString, "branchControlSelectionColor")); } - public final void setBranchControlSelectionColor(int branchControlSelectionColor) { - Theme theme = currentTheme(); - setBranchControlSelectionColor(theme.getColor(branchControlSelectionColor)); + public final void setBranchControlSelectionColor(final int branchControlSelectionColorIndex) { + setBranchControlSelectionColor(getColor(branchControlSelectionColorIndex)); } public Color getBranchControlInactiveSelectionColor() { return branchControlInactiveSelectionColor; } - public void setBranchControlInactiveSelectionColor(Color branchControlInactiveSelectionColor) { - Utils.checkNull(branchControlInactiveSelectionColor, "branchControlInactiveSelectionColor"); + public void setBranchControlInactiveSelectionColor(final Color branchControlInactiveSelectionColorValue) { + Utils.checkNull(branchControlInactiveSelectionColorValue, "branchControlInactiveSelectionColor"); - this.branchControlInactiveSelectionColor = branchControlInactiveSelectionColor; + this.branchControlInactiveSelectionColor = branchControlInactiveSelectionColorValue; repaintComponent(); } - public void setBranchControlInactiveSelectionColor(String branchControlInactiveSelectionColor) { + public void setBranchControlInactiveSelectionColor(final String branchControlInactiveSelectionString) { setBranchControlInactiveSelectionColor( - GraphicsUtilities.decodeColor(branchControlInactiveSelectionColor, "branchControlInactiveSelectionColor")); + GraphicsUtilities.decodeColor(branchControlInactiveSelectionString, "branchControlInactiveSelectionColor")); } - public final void setBranchControlInactiveSelectionColor(int branchControlInactiveSelectionColor) { - Theme theme = currentTheme(); - setBranchControlInactiveSelectionColor(theme.getColor(branchControlInactiveSelectionColor)); + public final void setBranchControlInactiveSelectionColor(final int branchControlInactiveSelectionIndex) { + setBranchControlInactiveSelectionColor(getColor(branchControlInactiveSelectionIndex)); } public Color getGridColor() { return gridColor; } - public void setGridColor(Color gridColor) { - Utils.checkNull(gridColor, "gridColor"); + public void setGridColor(final Color gridColorValue) { + Utils.checkNull(gridColorValue, "gridColor"); - this.gridColor = gridColor; + this.gridColor = gridColorValue; repaintComponent(); } - public void setGridColor(String gridColor) { - setGridColor(GraphicsUtilities.decodeColor(gridColor, "gridColor")); + public void setGridColor(final String gridColorString) { + setGridColor(GraphicsUtilities.decodeColor(gridColorString, "gridColor")); } - public final void setGridColor(int gridColor) { - Theme theme = currentTheme(); - setGridColor(theme.getColor(gridColor)); + public final void setGridColor(final int gridColorIndex) { + setGridColor(getColor(gridColorIndex)); } public boolean getShowGridLines() { return showGridLines; } - public void setShowGridLines(boolean showGridLines) { - this.showGridLines = showGridLines; + public void setShowGridLines(final boolean showGridLinesValue) { + this.showGridLines = showGridLinesValue; repaintComponent(); } @@ -1133,7 +1108,7 @@ public class TerraTreeViewSkin extends C * @return The fixed node height of this skin. */ protected int getNodeHeight() { - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer(); nodeRenderer.render(null, null, -1, treeView, false, false, TreeView.NodeCheckState.UNCHECKED, false, false); @@ -1152,7 +1127,7 @@ public class TerraTreeViewSkin extends C * y-coordinate, or {@code null} if there is no node at that location. * @param y The current Y location. */ - protected final NodeInfo getNodeInfoAt(int y) { + protected final NodeInfo getNodeInfoAt(final int y) { NodeInfo nodeInfo = null; int nodeHeight = getNodeHeight(); @@ -1171,7 +1146,7 @@ public class TerraTreeViewSkin extends C * node info. * @param path The path to query. */ - protected final NodeInfo getNodeInfoAt(Path path) { + protected final NodeInfo getNodeInfoAt(final Path path) { assert (path != null) : "Path is null"; NodeInfo result = null; @@ -1199,11 +1174,20 @@ public class TerraTreeViewSkin extends C } /** - * @return The bounding box defined by the specified node, or {@code null} if + * @return The metadata for the branch node at the specified path. + * @param path The path to query. + * @see #getNodeInfoAt(Path) + */ + protected final BranchInfo getBranchInfoAt(final Path path) { + return (BranchInfo) getNodeInfoAt(path); + } + + /** + * @return The bounding box defined by the specified node, or <tt>null</tt> if * the node is not currently visible. * @param nodeInfo The node information to search for. */ - protected final Bounds getNodeBounds(NodeInfo nodeInfo) { + protected final Bounds getNodeBounds(final NodeInfo nodeInfo) { Bounds bounds = null; int index = visibleNodes.indexOf(nodeInfo); @@ -1224,7 +1208,7 @@ public class TerraTreeViewSkin extends C * * @param visitor The callback to execute on each node info object */ - protected final void accept(NodeInfoVisitor visitor) { + protected final void accept(final NodeInfoVisitor visitor) { Sequence<NodeInfo> nodes = new ArrayList<>(); nodes.add(rootBranchInfo); @@ -1250,8 +1234,9 @@ public class TerraTreeViewSkin extends C * Adds all children of the specified branch to the visible node list. Any * children nodes that are expanded [branches] will also have their children * made visible, and so on. Invalidates the component only if necessary. + * @param parentBranchInfo The parent branch to traverse. */ - private void addVisibleNodes(BranchInfo parentBranchInfo) { + private void addVisibleNodes(final BranchInfo parentBranchInfo) { int insertIndex = -1; if (parentBranchInfo == rootBranchInfo) { @@ -1303,7 +1288,7 @@ public class TerraTreeViewSkin extends C * @param parentBranchInfo The branch info of the parent node. * @param index The index of the child within its parent. */ - private void addVisibleNode(BranchInfo parentBranchInfo, int index) { + private void addVisibleNode(final BranchInfo parentBranchInfo, final int index) { parentBranchInfo.loadChildren(); assert (index >= 0) : "Index is too small"; @@ -1352,7 +1337,7 @@ public class TerraTreeViewSkin extends C * @param count The number of child nodes to remove, or <code>-1</code> to remove * all child nodes from the visible nodes sequence. */ - private void removeVisibleNodes(BranchInfo parentBranchInfo, int index, int count) { + private void removeVisibleNodes(final BranchInfo parentBranchInfo, final int index, final int count) { parentBranchInfo.loadChildren(); int childrenLength = parentBranchInfo.children.getLength(); @@ -1400,7 +1385,7 @@ public class TerraTreeViewSkin extends C * * @param nodeInfo The node to search for. */ - protected void repaintNode(NodeInfo nodeInfo) { + protected void repaintNode(final NodeInfo nodeInfo) { Bounds bounds = getNodeBounds(nodeInfo); if (bounds != null) { repaintComponent(bounds); @@ -1425,12 +1410,7 @@ public class TerraTreeViewSkin extends C * @param mask The bitmask specifying which field to clear. */ private void clearFields(final byte mask) { - accept(new NodeInfoVisitor() { - @Override - public void visit(NodeInfo nodeInfo) { - nodeInfo.clearField(mask); - } - }); + accept(nodeInfo -> nodeInfo.clearField(mask)); } /** @@ -1439,7 +1419,7 @@ public class TerraTreeViewSkin extends C * be called when the tree view is valid. */ private void scrollSelectionToVisible() { - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); Sequence<Path> selectedPaths = treeView.getSelectedPaths(); int n = selectedPaths.getLength(); @@ -1463,10 +1443,10 @@ public class TerraTreeViewSkin extends C } @Override - public boolean mouseMove(Component component, int x, int y) { + public boolean mouseMove(final Component component, final int x, final int y) { boolean consumed = super.mouseMove(component, x, y); - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); if (showHighlight && treeView.getSelectMode() != SelectMode.NONE) { NodeInfo previousHighlightedNode = highlightedNode; @@ -1489,7 +1469,7 @@ public class TerraTreeViewSkin extends C } @Override - public void mouseOut(Component component) { + public void mouseOut(final Component component) { super.mouseOut(component); clearHighlightedNode(); @@ -1497,11 +1477,12 @@ public class TerraTreeViewSkin extends C } @Override - public boolean mouseDown(Component component, Mouse.Button button, int x, int y) { + public boolean mouseDown(final Component component, final Mouse.Button button, + final int x, final int y) { boolean consumed = super.mouseDown(component, button, x, y); if (!consumed) { - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); NodeInfo nodeInfo = getNodeInfoAt(y); if (nodeInfo != null && !nodeInfo.isDisabled()) { @@ -1577,10 +1558,11 @@ public class TerraTreeViewSkin extends C } @Override - public boolean mouseUp(Component component, Mouse.Button button, int x, int y) { + public boolean mouseUp(final Component component, final Mouse.Button button, + final int x, final int y) { boolean consumed = super.mouseUp(component, button, x, y); - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); if (selectPath != null && !treeView.getFirstSelectedPath().equals(treeView.getLastSelectedPath())) { treeView.setSelectedPath(selectPath); @@ -1591,11 +1573,12 @@ public class TerraTreeViewSkin extends C } @Override - public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) { + public boolean mouseClick(final Component component, final Mouse.Button button, + final int x, final int y, final int count) { boolean consumed = super.mouseClick(component, button, x, y, count); if (!consumed) { - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); NodeInfo nodeInfo = getNodeInfoAt(y); if (nodeInfo != null && !nodeInfo.isDisabled()) { @@ -1635,8 +1618,8 @@ public class TerraTreeViewSkin extends C } @Override - public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount, - int wheelRotation, int x, int y) { + public boolean mouseWheel(final Component component, final Mouse.ScrollType scrollType, + final int scrollAmount, final int wheelRotation, final int x, final int y) { if (highlightedNode != null) { Bounds nodeBounds = getNodeBounds(highlightedNode); @@ -1644,8 +1627,7 @@ public class TerraTreeViewSkin extends C highlightedNode = null; if (nodeBounds != null) { - repaintComponent(nodeBounds.x, nodeBounds.y, nodeBounds.width, nodeBounds.height, - true); + repaintComponent(nodeBounds.x, nodeBounds.y, nodeBounds.width, nodeBounds.height, true); } } @@ -1668,10 +1650,10 @@ public class TerraTreeViewSkin extends C * </ul> */ @Override - public boolean keyPressed(Component component, int keyCode, KeyLocation keyLocation) { + public boolean keyPressed(final Component component, final int keyCode, final KeyLocation keyLocation) { boolean consumed = false; - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); SelectMode selectMode = treeView.getSelectMode(); switch (keyCode) { @@ -1791,10 +1773,10 @@ public class TerraTreeViewSkin extends C * is {@link SelectMode#SINGLE}. */ @Override - public boolean keyReleased(Component component, int keyCode, KeyLocation keyLocation) { + public boolean keyReleased(final Component component, final int keyCode, final KeyLocation keyLocation) { boolean consumed = false; - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); if (keyCode == KeyCode.SPACE) { if (treeView.getCheckmarksEnabled() @@ -1818,7 +1800,7 @@ public class TerraTreeViewSkin extends C @Override public boolean isFocusable() { - TreeView treeView = (TreeView) getComponent(); + TreeView treeView = getTreeView(); return (treeView.getSelectMode() != SelectMode.NONE); } @@ -1830,13 +1812,13 @@ public class TerraTreeViewSkin extends C // ComponentStateListener methods @Override - public void enabledChanged(Component component) { + public void enabledChanged(final Component component) { super.enabledChanged(component); repaintComponent(); } @Override - public void focusedChanged(Component component, Component obverseComponent) { + public void focusedChanged(final Component component, final Component obverseComponent) { super.focusedChanged(component, obverseComponent); repaintComponent(); } @@ -1844,7 +1826,7 @@ public class TerraTreeViewSkin extends C // TreeView.Skin methods @Override - public Path getNodeAt(int y) { + public Path getNodeAt(final int y) { Path path = null; NodeInfo nodeInfo = getNodeInfoAt(y); @@ -1857,7 +1839,7 @@ public class TerraTreeViewSkin extends C } @Override - public Bounds getNodeBounds(Path path) { + public Bounds getNodeBounds(final Path path) { Bounds nodeBounds = null; NodeInfo nodeInfo = getNodeInfoAt(path); @@ -1870,8 +1852,8 @@ public class TerraTreeViewSkin extends C } @Override - public int getNodeIndent(int depth) { - TreeView treeView = (TreeView) getComponent(); + public int getNodeIndent(final int depth) { + TreeView treeView = getTreeView(); int nodeIndent = (depth - 1) * (indent + spacing); @@ -1887,7 +1869,7 @@ public class TerraTreeViewSkin extends C } @Override - public int getRowIndex(Path path) { + public int getRowIndex(final Path path) { int rowIndex = -1; NodeInfo nodeInfo = getNodeInfoAt(path); @@ -1902,7 +1884,7 @@ public class TerraTreeViewSkin extends C // TreeViewListener methods @Override - public void treeDataChanged(TreeView treeView, List<?> previousTreeData) { + public void treeDataChanged(final TreeView treeView, final List<?> previousTreeData) { @SuppressWarnings("unchecked") List<Object> treeData = (List<Object>) treeView.getTreeData(); @@ -1919,26 +1901,27 @@ public class TerraTreeViewSkin extends C } @Override - public void nodeRendererChanged(TreeView treeView, TreeView.NodeRenderer previousNodeRenderer) { + public void nodeRendererChanged(final TreeView treeView, + final TreeView.NodeRenderer previousNodeRenderer) { invalidateComponent(); } @Override - public void selectModeChanged(TreeView treeView, SelectMode previousSelectMode) { + public void selectModeChanged(final TreeView treeView, final SelectMode previousSelectMode) { // The selection has implicitly been cleared clearFields(NodeInfo.SELECTED_MASK); repaintComponent(); } @Override - public void checkmarksEnabledChanged(TreeView treeView) { + public void checkmarksEnabledChanged(final TreeView treeView) { // The check state of all nodes has implicitly been cleared clearFields(NodeInfo.CHECK_STATE_MASK); invalidateComponent(); } @Override - public void showMixedCheckmarkStateChanged(TreeView treeView) { + public void showMixedCheckmarkStateChanged(final TreeView treeView) { if (treeView.getCheckmarksEnabled()) { // The check state of all *branch* nodes may have changed, so we // need to update the cached check state of all BranchNode @@ -1972,38 +1955,34 @@ public class TerraTreeViewSkin extends C } @Override - public void disabledNodeFilterChanged(TreeView treeView, Filter<?> previousDisabledNodeFilter) { + public void disabledNodeFilterChanged(final TreeView treeView, final Filter<?> previousDisabledNodeFilter) { @SuppressWarnings("unchecked") final Filter<Object> disabledNodeFilter = (Filter<Object>) treeView.getDisabledNodeFilter(); - accept(new NodeInfoVisitor() { - @Override - public void visit(NodeInfo nodeInfo) { - if (nodeInfo != rootBranchInfo) { - nodeInfo.setDisabled(disabledNodeFilter != null - && disabledNodeFilter.include(nodeInfo.data)); + accept(nodeInfo -> { + if (nodeInfo != rootBranchInfo) { + nodeInfo.setDisabled(disabledNodeFilter != null + && disabledNodeFilter.include(nodeInfo.data)); } } - }); + ); repaintComponent(); } @Override - public void disabledCheckmarkFilterChanged(TreeView treeView, - Filter<?> previousDisabledCheckmarkFilter) { + public void disabledCheckmarkFilterChanged(final TreeView treeView, + final Filter<?> previousDisabledCheckmarkFilter) { @SuppressWarnings("unchecked") final Filter<Object> disabledCheckmarkFilter = (Filter<Object>) treeView.getDisabledCheckmarkFilter(); - accept(new NodeInfoVisitor() { - @Override - public void visit(NodeInfo nodeInfo) { - if (nodeInfo != rootBranchInfo) { - nodeInfo.setCheckmarkDisabled(disabledCheckmarkFilter != null - && disabledCheckmarkFilter.include(nodeInfo.data)); + accept(nodeInfo -> { + if (nodeInfo != rootBranchInfo) { + nodeInfo.setCheckmarkDisabled(disabledCheckmarkFilter != null + && disabledCheckmarkFilter.include(nodeInfo.data)); } } - }); + ); repaintComponent(); } @@ -2011,8 +1990,8 @@ public class TerraTreeViewSkin extends C // TreeViewBranchListener methods @Override - public void branchExpanded(TreeView treeView, Path path) { - BranchInfo branchInfo = (BranchInfo) getNodeInfoAt(path); + public void branchExpanded(final TreeView treeView, final Path path) { + BranchInfo branchInfo = getBranchInfoAt(path); branchInfo.setExpanded(true); addVisibleNodes(branchInfo); @@ -2021,8 +2000,8 @@ public class TerraTreeViewSkin extends C } @Override - public void branchCollapsed(TreeView treeView, Path path) { - BranchInfo branchInfo = (BranchInfo) getNodeInfoAt(path); + public void branchCollapsed(final TreeView treeView, final Path path) { + BranchInfo branchInfo = getBranchInfoAt(path); branchInfo.setExpanded(false); removeVisibleNodes(branchInfo, 0, -1); @@ -2031,14 +2010,14 @@ public class TerraTreeViewSkin extends C } @Override - public Vote previewBranchExpandedChange(TreeView treeView, Path path) { + public Vote previewBranchExpandedChange(final TreeView treeView, final Path path) { // We currently have no reason to refuse to open / close the branch // although other listeners might have a reason return Vote.APPROVE; } @Override - public void branchExpandedChangeVetoed(TreeView treeView, Path path, Vote reason) { + public void branchExpandedChangeVetoed(final TreeView treeView, final Path path, final Vote reason) { // Nothing really to do -- our visual state doesn't change until/unless the // expand/collapse really happens } @@ -2047,8 +2026,8 @@ public class TerraTreeViewSkin extends C @Override @SuppressWarnings("unchecked") - public void nodeInserted(TreeView treeView, Path path, int index) { - BranchInfo branchInfo = (BranchInfo) getNodeInfoAt(path); + public void nodeInserted(final TreeView treeView, final Path path, final int index) { + BranchInfo branchInfo = getBranchInfoAt(path); List<Object> branchData = (List<Object>) branchInfo.data; // Update our internal branch info @@ -2068,8 +2047,8 @@ public class TerraTreeViewSkin extends C } @Override - public void nodesRemoved(TreeView treeView, Path path, int index, int count) { - BranchInfo branchInfo = (BranchInfo) getNodeInfoAt(path); + public void nodesRemoved(final TreeView treeView, final Path path, final int index, final int count) { + BranchInfo branchInfo = getBranchInfoAt(path); // Remove the nodes from the visible nodes list removeVisibleNodes(branchInfo, index, count); @@ -2094,8 +2073,8 @@ public class TerraTreeViewSkin extends C @Override @SuppressWarnings("unchecked") - public void nodeUpdated(TreeView treeView, Path path, int index) { - BranchInfo branchInfo = (BranchInfo) getNodeInfoAt(path); + public void nodeUpdated(final TreeView treeView, final Path path, final int index) { + BranchInfo branchInfo = getBranchInfoAt(path); List<Object> branchData = (List<Object>) branchInfo.data; branchInfo.loadChildren(); @@ -2127,8 +2106,8 @@ public class TerraTreeViewSkin extends C } @Override - public void nodesCleared(TreeView treeView, Path path) { - BranchInfo branchInfo = (BranchInfo) getNodeInfoAt(path); + public void nodesCleared(final TreeView treeView, final Path path) { + BranchInfo branchInfo = getBranchInfoAt(path); // Remove the node from the visible nodes list removeVisibleNodes(branchInfo, 0, -1); @@ -2140,8 +2119,8 @@ public class TerraTreeViewSkin extends C } @Override - public void nodesSorted(TreeView treeView, Path path) { - BranchInfo branchInfo = (BranchInfo) getNodeInfoAt(path); + public void nodesSorted(final TreeView treeView, final Path path) { + BranchInfo branchInfo = getBranchInfoAt(path); // Remove the child nodes from the visible nodes list removeVisibleNodes(branchInfo, 0, -1); @@ -2157,8 +2136,8 @@ public class TerraTreeViewSkin extends C // TreeViewNodeStateListener methods @Override - public void nodeCheckStateChanged(TreeView treeView, Path path, - TreeView.NodeCheckState previousCheckState) { + public void nodeCheckStateChanged(final TreeView treeView, final Path path, + final TreeView.NodeCheckState previousCheckState) { NodeInfo nodeInfo = getNodeInfoAt(path); nodeInfo.setCheckState(treeView.getNodeCheckState(path)); @@ -2169,7 +2148,7 @@ public class TerraTreeViewSkin extends C // TreeViewSelectionListener methods @Override - public void selectedPathAdded(TreeView treeView, Path path) { + public void selectedPathAdded(final TreeView treeView, final Path path) { // Update the node info NodeInfo nodeInfo = getNodeInfoAt(path); nodeInfo.setSelected(true); @@ -2192,14 +2171,14 @@ public class TerraTreeViewSkin extends C } @Override - public void selectedPathRemoved(TreeView treeView, Path path) { + public void selectedPathRemoved(final TreeView treeView, final Path path) { NodeInfo nodeInfo = getNodeInfoAt(path); nodeInfo.setSelected(false); repaintNode(nodeInfo); } @Override - public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) { + public void selectedPathsChanged(final TreeView treeView, final Sequence<Path> previousSelectedPaths) { if (previousSelectedPaths != null && previousSelectedPaths != treeView.getSelectedPaths()) { // Ensure that the selection is visible if (treeView.isValid()) {
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_theme_defaults.json URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_theme_defaults.json?rev=1887553&r1=1887552&r2=1887553&view=diff ============================================================================== --- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_theme_defaults.json (original) +++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_theme_defaults.json Fri Mar 12 21:04:51 2021 @@ -67,12 +67,14 @@ // selectionColor = Color.DARK_GRAY; // inactiveSelectionColor = Color.DARK_GRAY; // } + // These were taken from TextAreaSkin (after the preceding code): backgroundColor : 'null', inactiveColor : 'GRAY', margin : 4, wrapText : true, tabWidth : 4, + // But, the colors below were taken from TerraTextAreaSkin... color : 1, backgroundColor : 11, @@ -81,6 +83,57 @@ selectionBackgroundColor : 14, inactiveSelectionColor : 1, inactiveSelectionBackgroundColor : 9 + }, + + TerraTextPaneSkin : { + // TODO: Conflicts with TextPaneSkin, whose constructor says this: + // color = defaultForegroundColor(); + // selectionBackgroundColor = defaultForegroundColor(); + // inactiveSelectionBackgroundColor = defaultForegroundColor(); + // if (!themeIsDark()) { + // selectionColor = Color.LIGHT_GRAY; + // inactiveSelectionColor = Color.LIGHT_GRAY; + // } else { + // selectionColor = Color.DARK_GRAY; + // inactiveSelectionColor = Color.DARK_GRAY; + // } + // inactiveColor = Color.GRAY; + + // While these colors were taken from TerraTextPaneSkin... + color : 1, + backgroundColor : 11, + inactiveColor : 7, + selectionColor : 4, + selectionBackgroundColor : 14, + inactiveSelectionColor : 1, + inactiveSelectionBackgroundColor : 9 + }, + + TerraScrollPaneSkin : { + backgroundColor : 4 + }, + + TerraTreeViewSkin : { + // Taken from TerraTreeViewSkin constructor... + color : 1, + disabledColor : 7, + backgroundColor : 4, + selectionColor : 4, + selectionBackgroundColor : 14, + inactiveSelectionColor : 1, + inactiveSelectionBackgroundColor : 10, + highlightColor : 1, + highlightBackgroundColor : 10, + spacing : 6, + indent : 16, + showHighlight : true, + showBranchControls : true, + showEmptyBranchControls : true, + branchControlColor : 12, + branchControlSelectionColor : 4, + branchControlInactiveSelectionColor : 14, + gridColor : 11, + showGridLines : false } /* More to come ... */ Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java?rev=1887553&r1=1887552&r2=1887553&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java Fri Mar 12 21:04:51 2021 @@ -57,32 +57,55 @@ import org.apache.pivot.wtk.Tooltip; public abstract class ComponentSkin implements Skin, ComponentListener, ComponentStateListener, ComponentMouseListener, ComponentMouseButtonListener, ComponentMouseWheelListener, ComponentKeyListener, ComponentTooltipListener { - private Component component = null; + /** The component to which this skin is attached. */ + private Component installedComponent = null; + + /** This component's current full width (usually calculated during layout). */ private int width = 0; + /** This component's current full height (usually calculated during layout). */ private int height = 0; + /** The allowance in the X-direction for tooltip text before going off the left edge. */ + private static final int TOOLTIP_X_ALLOWANCE = 16; + @Override - public int getWidth() { + public final int getWidth() { return width; } @Override - public int getHeight() { + public final int getHeight() { return height; } @Override - public Dimensions getSize() { + public final Dimensions getSize() { return new Dimensions(width, height); } + /** + * Set the final size of the component after layout has finished. + * <p> All subclasses must call this superclass method in order to + * set the {@link #width} and {@link #height} values, but may need + * to do additional calculations before doing so. + * + * @param newWidth The new (final) width of the component after layout. + * @param newHeight The new (final) height of the component after layout. + */ @Override - public void setSize(int width, int height) { - this.width = width; - this.height = height; + public void setSize(final int newWidth, final int newHeight) { + this.width = newWidth; + this.height = newHeight; } + /** + * @return The preferred size (width and height) of this component. + * <p> Depending on the component this can be a static value or derived + * (as for a container) from its subcomponents, etc. + * <p> The default implementation simply calls {@link #getPreferredWidth} + * and {@link #getPreferredHeight}. + */ @Override public Dimensions getPreferredSize() { return new Dimensions(getPreferredWidth(-1), getPreferredHeight(-1)); @@ -93,29 +116,43 @@ public abstract class ComponentSkin impl return getBaseline(width, height); } + /** + * Should be implemented in every subclass. + * <p> The default implementation here simply returns -1 (no baseline). + */ @Override - public int getBaseline(int widthArgument, int heightArgument) { + public int getBaseline(final int trialWidth, final int trialHeight) { return -1; } + /** + * Must be implemented in every subclass in order to do component-specific + * operations at instantiation time, but every subclass must call this + * superclass method to setup the necessary listeners, etc. + */ @Override - public void install(Component componentArgument) { - assert (this.component == null) : "Skin is already installed on a component."; + public void install(final Component component) { + assert (this.installedComponent == null) + : "This " + getClass().getSimpleName() + " is already installed on a component."; - componentArgument.getComponentListeners().add(this); - componentArgument.getComponentStateListeners().add(this); - componentArgument.getComponentMouseListeners().add(this); - componentArgument.getComponentMouseButtonListeners().add(this); - componentArgument.getComponentMouseWheelListeners().add(this); - componentArgument.getComponentKeyListeners().add(this); - componentArgument.getComponentTooltipListeners().add(this); + component.getComponentListeners().add(this); + component.getComponentStateListeners().add(this); + component.getComponentMouseListeners().add(this); + component.getComponentMouseButtonListeners().add(this); + component.getComponentMouseWheelListeners().add(this); + component.getComponentKeyListeners().add(this); + component.getComponentTooltipListeners().add(this); - this.component = componentArgument; + this.installedComponent = component; } + /** + * @return The installed component for this skin instance, set by {@link #install} + * (which therefore must be called by every subclass). + */ @Override - public Component getComponent() { - return component; + public final Component getComponent() { + return installedComponent; } /** @@ -136,132 +173,132 @@ public abstract class ComponentSkin impl // Component events @Override - public void parentChanged(Component componentArgument, Container previousParent) { + public void parentChanged(final Component component, final Container previousParent) { // No-op } @Override - public void sizeChanged(Component componentArgument, int previousWidth, int previousHeight) { + public void sizeChanged(final Component component, final int previousWidth, final int previousHeight) { // No-op } @Override - public void preferredSizeChanged(Component componentArgument, int previousPreferredWidth, - int previousPreferredHeight) { + public void preferredSizeChanged(final Component component, final int previousPreferredWidth, + final int previousPreferredHeight) { // No-op } @Override - public void widthLimitsChanged(Component componentArgument, int previousMinimumWidth, - int previousMaximumWidth) { + public void widthLimitsChanged(final Component component, final int previousMinimumWidth, + final int previousMaximumWidth) { // No-op } @Override - public void heightLimitsChanged(Component componentArgument, int previousMinimumHeight, - int previousMaximumHeight) { + public void heightLimitsChanged(final Component component, final int previousMinimumHeight, + final int previousMaximumHeight) { // No-op } @Override - public void locationChanged(Component componentArgument, int previousX, int previousY) { + public void locationChanged(final Component component, final int previousX, final int previousY) { // No-op } @Override - public void visibleChanged(Component componentArgument) { + public void visibleChanged(final Component component) { // No-op } @Override - public void cursorChanged(Component componentArgument, Cursor previousCursor) { + public void cursorChanged(final Component component, final Cursor previousCursor) { // No-op } @Override - public void tooltipTextChanged(Component componentArgument, String previousTooltipText) { + public void tooltipTextChanged(final Component component, final String previousTooltipText) { // No-op } @Override - public void tooltipDelayChanged(Component componentArgument, int previousTooltipDelay) { + public void tooltipDelayChanged(final Component component, final int previousTooltipDelay) { // No-op } @Override - public void dragSourceChanged(Component componentArgument, DragSource previousDragSource) { + public void dragSourceChanged(final Component component, final DragSource previousDragSource) { // No-op } @Override - public void dropTargetChanged(Component componentArgument, DropTarget previousDropTarget) { + public void dropTargetChanged(final Component component, final DropTarget previousDropTarget) { // No-op } @Override - public void menuHandlerChanged(Component componentArgument, MenuHandler previousMenuHandler) { + public void menuHandlerChanged(final Component component, final MenuHandler previousMenuHandler) { // No-op } @Override - public void nameChanged(Component componentArgument, String previousName) { + public void nameChanged(final Component component, final String previousName) { // No-op } // Component state events @Override - public void enabledChanged(Component componentArgument) { + public void enabledChanged(final Component component) { // No-op } @Override - public void focusedChanged(Component componentArgument, Component obverseComponent) { + public void focusedChanged(final Component component, final Component obverseComponent) { // No-op } // Component mouse events @Override - public boolean mouseMove(Component componentArgument, int x, int y) { + public boolean mouseMove(final Component component, final int x, final int y) { return false; } @Override - public void mouseOver(Component componentArgument) { + public void mouseOver(final Component component) { // No-op } @Override - public void mouseOut(Component componentArgument) { + public void mouseOut(final Component component) { // No-op } // Component mouse button events @Override - public boolean mouseDown(Component componentArgument, Mouse.Button button, int x, int y) { + public boolean mouseDown(final Component component, final Mouse.Button button, final int x, final int y) { return false; } @Override - public boolean mouseUp(Component componentArgument, Mouse.Button button, int x, int y) { + public boolean mouseUp(final Component component, final Mouse.Button button, final int x, final int y) { return false; } @Override - public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, - int count) { + public boolean mouseClick(final Component component, final Mouse.Button button, final int x, final int y, + final int count) { return false; } // Component mouse wheel events @Override - public boolean mouseWheel(Component componentArgument, Mouse.ScrollType scrollType, - int scrollAmount, int wheelRotation, int x, int y) { + public boolean mouseWheel(final Component component, final Mouse.ScrollType scrollType, + final int scrollAmount, final int wheelRotation, final int x, final int y) { return false; } // Component key events @Override - public boolean keyTyped(Component componentArgument, char character) { + public boolean keyTyped(final Component component, final char character) { return false; } @@ -273,8 +310,8 @@ public abstract class ComponentSkin impl * </ul> */ @Override - public boolean keyPressed(Component componentArgument, int keyCode, - KeyLocation keyLocation) { + public boolean keyPressed(final Component component, final int keyCode, + final KeyLocation keyLocation) { boolean consumed = false; EnumSet<Modifier> otherModifiers = EnumSet.noneOf(Modifier.class); @@ -284,7 +321,7 @@ public abstract class ComponentSkin impl if (keyCode == KeyCode.TAB && !Keyboard.areAnyPressed(otherModifiers) && getComponent().isFocused()) { - FocusTraversalDirection direction = (Keyboard.isPressed(Modifier.SHIFT)) + FocusTraversalDirection direction = Keyboard.isPressed(Modifier.SHIFT) ? FocusTraversalDirection.BACKWARD : FocusTraversalDirection.FORWARD; @@ -304,13 +341,13 @@ public abstract class ComponentSkin impl } @Override - public boolean keyReleased(Component componentArgument, int keyCode, - KeyLocation keyLocation) { + public boolean keyReleased(final Component component, final int keyCode, + final KeyLocation keyLocation) { return false; } @Override - public void tooltipTriggered(Component componentArgument, int x, int y) { + public void tooltipTriggered(final Component component, final int x, final int y) { String tooltipText = component.getTooltipText(); if (tooltipText != null) { @@ -323,7 +360,7 @@ public abstract class ComponentSkin impl Point location = component.mapPointToAncestor(display, x, y); // Ensure that the tooltip stays on screen - int tooltipX = location.x + 16; + int tooltipX = location.x + TOOLTIP_X_ALLOWANCE; int tooltipY = location.y; int tooltipWidth = tooltip.getPreferredWidth(); @@ -334,7 +371,7 @@ public abstract class ComponentSkin impl if (tooltipY > tooltipHeight) { tooltipX = display.getWidth() - tooltipWidth; } else { - tooltipX = location.x - tooltipWidth - 16; + tooltipX = location.x - tooltipWidth - TOOLTIP_X_ALLOWANCE; } if (tooltipX < 0) { tooltipX = 0; @@ -358,41 +395,74 @@ public abstract class ComponentSkin impl } // Utility methods + /** + * Mark the component's entire size as invalid, to be repainted when + * the event queue is empty. + */ protected void invalidateComponent() { - if (component != null) { - component.invalidate(); - component.repaint(); + if (installedComponent != null) { + installedComponent.invalidate(); + installedComponent.repaint(); } } + /** + * Repaint the entire component when the event queue is empty. + */ protected void repaintComponent() { repaintComponent(false); } - protected void repaintComponent(boolean immediate) { - if (component != null) { - component.repaint(immediate); + /** + * Repaint the entire component with the option to do so immediately + * (vs. when the event queue is empty). + * @param immediate {@code true} to repaint the entire component now. + */ + protected void repaintComponent(final boolean immediate) { + if (installedComponent != null) { + installedComponent.repaint(immediate); } } - protected void repaintComponent(Bounds area) { + /** + * Repaint the given area of the component when the event queue is empty. + * @param area The bounding box of the area to be repainted. + */ + protected void repaintComponent(final Bounds area) { assert (area != null) : "area is null."; - if (component != null) { - component.repaint(area.x, area.y, area.width, area.height); + if (installedComponent != null) { + installedComponent.repaint(area.x, area.y, area.width, area.height); } } - protected void repaintComponent(int x, int y, int widthArgument, int heightArgument) { - if (component != null) { - component.repaint(x, y, widthArgument, heightArgument); + /** + * Repaint the area of the component specified by the given location and size + * when the event queue is empty. + * @param x The starting X-position to paint. + * @param y The starting Y-position to paint. + * @param areaWidth The width of the area to repaint. + * @param areaHeight The height of the area to repaint. + */ + protected void repaintComponent(final int x, final int y, final int areaWidth, final int areaHeight) { + if (installedComponent != null) { + installedComponent.repaint(x, y, areaWidth, areaHeight); } } - protected void repaintComponent(int x, int y, int widthArgument, int heightArgument, - boolean immediate) { - if (component != null) { - component.repaint(x, y, widthArgument, heightArgument, immediate); + /** + * Repaint the area of the component specified by the given location and size + * with the option to do so immediately or when the event queue is empty. + * @param x The starting X-position to paint. + * @param y The starting Y-position to paint. + * @param areaWidth The width of the area to repaint. + * @param areaHeight The height of the area to repaint. + * @param immediate {@code true} to repaint the given area now. + */ + protected void repaintComponent(final int x, final int y, final int areaWidth, final int areaHeight, + final boolean immediate) { + if (installedComponent != null) { + installedComponent.repaint(x, y, areaWidth, areaHeight, immediate); } } @@ -409,71 +479,101 @@ public abstract class ComponentSkin impl * or empty or the font specification cannot be decoded. * @see FontUtilities#decodeFont(String) */ - public static Font decodeFont(String value) { + public static final Font decodeFont(final String value) { return FontUtilities.decodeFont(value); } /** * Returns the current Theme. * - * @return the theme + * @return The currently loaded theme. */ - protected Theme currentTheme() { + public final Theme currentTheme() { return Theme.getTheme(); } /** - * Returns if the current Theme is dark. + * Returns whether the current Theme is dark. * * Usually this means that (if true) any * color will be transformed in the opposite way. * - * @return true if it is flat, false otherwise (default) + * @return {@code true} if it is dark, {@code false} otherwise (default) */ - protected boolean themeIsDark() { + public final boolean themeIsDark() { return currentTheme().isThemeDark(); } /** - * Returns if the current Theme is flat. + * Returns whether the current Theme is flat. * * Note that flat themes usually have no bevel, gradients, shadow effects, * and in some cases even no borders. * - * @return true if it is flat, false otherwise (default) + * @return {@code true} if it is flat, {@code false} otherwise (default) */ - protected boolean themeIsFlat() { + public final boolean themeIsFlat() { return currentTheme().isThemeFlat(); } /** - * Returns if the current Theme has transitions enabled. + * Returns whether the current Theme has transitions enabled. * - * @return true if transitions are enabled (default), false otherwise + * @return {@code true} if transitions are enabled + * (default), {@code false} otherwise */ - protected boolean themeHasTransitionEnabled() { + public final boolean themeHasTransitionEnabled() { return currentTheme().isTransitionEnabled(); } /** * Returns the Theme default background color. * - * @return White if the theme is not dark (default), or Black. + * @return {@link Color#WHITE} if the theme is not dark + * (default), or {@link Color#BLACK}. */ - protected Color defaultBackgroundColor() { + public final Color defaultBackgroundColor() { return currentTheme().getDefaultBackgroundColor(); } /** * Returns the Theme default foreground color. * - * @return Black if the theme is not dark (default), or White. + * @return {@link Color#BLACK} if the theme is not dark + * (default), or {@link Color#WHITE}. */ - protected Color defaultForegroundColor() { + public final Color defaultForegroundColor() { return currentTheme().getDefaultForegroundColor(); } /** + * Returns the current theme color indicated by the index value. + * + * @param index Index into the theme's color palette. + * @return The current theme color value. + */ + public final Color getColor(final int index) { + return currentTheme().getColor(index); + } + + /** + * Returns the current font setting for the theme. + * + * @return The default font for the theme. + */ + public final Font getThemeFont() { + return currentTheme().getFont(); + } + + /** + * Sets the default styles for this skin by calling + * {@link Theme#setDefaultStyles} with the current skin object. + */ + public final void setDefaultStyles() { + currentTheme().setDefaultStyles(this); + } + + /** * Returns the input method listener for this component. * <p> Should be overridden by any component's skin that wants * to handle Input Method events (such as {@code TextInput}). Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java?rev=1887553&r1=1887552&r2=1887553&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java Fri Mar 12 21:04:51 2021 @@ -32,7 +32,6 @@ import org.apache.pivot.wtk.FocusTravers import org.apache.pivot.wtk.FocusTraversalPolicy; import org.apache.pivot.wtk.GraphicsUtilities; import org.apache.pivot.wtk.Mouse; -import org.apache.pivot.wtk.Theme; /** * Abstract base class for container skins. @@ -44,14 +43,21 @@ public abstract class ContainerSkin exte * of components in the container's component sequence. */ public static class IndexFocusTraversalPolicy implements FocusTraversalPolicy { + /** Whether to wrap at the ends or not. */ private boolean wrap; + /** Create a new policy with default wrap behavior (that is, don't wrap). */ public IndexFocusTraversalPolicy() { this(false); } - public IndexFocusTraversalPolicy(final boolean wrap) { - this.wrap = wrap; + /** + * Create a new policy using the given wrap value. + * @param newWrap Whether or not the policy should wrap around the ends + * of the container. + */ + public IndexFocusTraversalPolicy(final boolean newWrap) { + this.wrap = newWrap; } @Override @@ -84,7 +90,6 @@ public abstract class ContainerSkin exte } } } - break; case BACKWARD: @@ -106,7 +111,6 @@ public abstract class ContainerSkin exte } } } - break; default: @@ -118,8 +122,10 @@ public abstract class ContainerSkin exte } } + /** The {@link Paint} value to use for our background. */ private Paint backgroundPaint = null; + /** The default behavior to use for focus traversal among the children of this container. */ private static final FocusTraversalPolicy DEFAULT_FOCUS_TRAVERSAL_POLICY = new IndexFocusTraversalPolicy(); @Override @@ -178,31 +184,31 @@ public abstract class ContainerSkin exte /** * Sets the object used to paint the background of the container. * - * @param backgroundPaint The new {@link Paint} object to paint the background. + * @param newBackgroundPaint The new {@link Paint} object to paint the background. */ - public void setBackgroundPaint(final Paint backgroundPaint) { - this.backgroundPaint = backgroundPaint; + public void setBackgroundPaint(final Paint newBackgroundPaint) { + this.backgroundPaint = newBackgroundPaint; repaintComponent(); } /** * Sets the object used to paint the background of the container. * - * @param backgroundPaint A string recognized by Pivot as a + * @param backgroundPaintString A string recognized by Pivot as a * {@linkplain GraphicsUtilities#decodePaint(String) Color or Paint value}. */ - public final void setBackgroundPaint(final String backgroundPaint) { - setBackgroundPaint(GraphicsUtilities.decodePaint(backgroundPaint)); + public final void setBackgroundPaint(final String backgroundPaintString) { + setBackgroundPaint(GraphicsUtilities.decodePaint(backgroundPaintString)); } /** * Sets the object used to paint the background of the container. * - * @param backgroundPaint A dictionary containing a + * @param backgroundPaintDictionary A dictionary containing a * {@linkplain GraphicsUtilities#decodePaint(Dictionary) Paint description}. */ - public final void setBackgroundPaint(final Dictionary<String, ?> backgroundPaint) { - setBackgroundPaint(GraphicsUtilities.decodePaint(backgroundPaint)); + public final void setBackgroundPaint(final Dictionary<String, ?> backgroundPaintDictionary) { + setBackgroundPaint(GraphicsUtilities.decodePaint(backgroundPaintDictionary)); } /** @@ -225,22 +231,21 @@ public abstract class ContainerSkin exte /** * Sets the background of the container to a solid color. * - * @param backgroundColor Any of the + * @param backgroundColorString Any of the * {@linkplain GraphicsUtilities#decodeColor color values recognized by * Pivot}. */ - public final void setBackgroundColor(final String backgroundColor) { - setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColor, "backgroundColor")); + public final void setBackgroundColor(final String backgroundColorString) { + setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColorString, "backgroundColor")); } /** * Sets the background of the container to one of the theme colors. * - * @param backgroundColor An index into the theme's color palette. + * @param backgroundColorIndex An index into the theme's color palette. */ - public final void setBackgroundColor(final int backgroundColor) { - Theme theme = currentTheme(); - setBackgroundColor(theme.getColor(backgroundColor)); + public final void setBackgroundColor(final int backgroundColorIndex) { + setBackgroundColor(getColor(backgroundColorIndex)); } // Container events Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java?rev=1887553&r1=1887552&r2=1887553&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java Fri Mar 12 21:04:51 2021 @@ -78,6 +78,8 @@ public class ScrollPaneSkin extends Cont public void install(final Component component) { super.install(component); + setDefaultStyles(); + ScrollPane scrollPane = (ScrollPane) component; scrollPane.getViewportListeners().add(this); scrollPane.getScrollPaneListeners().add(this);