X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.spreadsheet.ui%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fui%2FSheetBorder.java;h=b74fb7f43d06b6ef453769cc1995564d8a53f36c;hb=refs%2Fchanges%2F38%2F238%2F2;hp=fe8ccf1bd0d9254368a50836a7ee32e5a9aeafd5;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetBorder.java b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetBorder.java index fe8ccf1bd..b74fb7f43 100644 --- a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetBorder.java +++ b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetBorder.java @@ -1,132 +1,132 @@ -package org.simantics.spreadsheet.ui; - -import java.awt.Graphics; -import java.awt.Insets; -import java.awt.Component; -import java.awt.Color; - -import javax.swing.Icon; -import javax.swing.border.EmptyBorder; - -import org.simantics.ui.colors.Colors; - -public class SheetBorder extends EmptyBorder -{ - private static final long serialVersionUID = 1L; - protected boolean bottomColor; - protected boolean rightColor; - - final Color NONE = Colors.awt(Colors.rgb(0.9,0.9,0.9)); - - - - /** - * Creates a matte border with the specified insets and color. - * @param top the top inset of the border - * @param left the left inset of the border - * @param bottom the bottom inset of the border - * @param right the right inset of the border - * @param matteColor the color rendered for the border - */ - public SheetBorder(int top, int left, int bottom, int right, boolean bottomColor, boolean rightColor) { - super(top, left, bottom, right); - this.bottomColor = bottomColor; - this.rightColor = rightColor; - } - - /** - * Paints the matte border. - */ - public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { - - Insets insets = getBorderInsets(c); - Color oldColor = g.getColor(); - g.translate(x, y); - - boolean same = bottomColor == rightColor; - - if(same) { - - g.setColor(bottomColor ? Color.BLACK : NONE); - g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom); - g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2); - - } else { - - // Not the same color - paint black on top - - if(bottomColor) { - // Black bottom - no right - g.setColor(NONE); - g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2); - g.setColor(Color.BLACK); - g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom); - } else { - // Black right - no bottom - g.setColor(NONE); - g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom); - g.setColor(Color.BLACK); - g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2); - } - - } - - g.translate(-x, -y); - g.setColor(oldColor); - - } - - /** - * Reinitialize the insets parameter with this Border's current Insets. - * @param c the component for which this border insets value applies - * @param insets the object to be reinitialized - * @since 1.3 - */ - public Insets getBorderInsets(Component c, Insets insets) { - return computeInsets(insets); - } - - /** - * Returns the insets of the border. - * @since 1.3 - */ - public Insets getBorderInsets() { - return computeInsets(new Insets(0,0,0,0)); - } - - /* should be protected once api changes area allowed */ - private Insets computeInsets(Insets insets) { - insets.left = left; - insets.top = top; - insets.right = right; - insets.bottom = bottom; - return insets; - } - - /** - * Returns the color used for tiling the border or null - * if a tile icon is being used. - * @since 1.3 - */ - public Color getMatteColor() { - return NONE; - } - - /** - * Returns the icon used for tiling the border or null - * if a solid color is being used. - * @since 1.3 - */ - public Icon getTileIcon() { - return null; - } - - /** - * Returns whether or not the border is opaque. - */ - public boolean isBorderOpaque() { - // If a tileIcon is set, then it may contain transparent bits - return true; - } - -} +package org.simantics.spreadsheet.ui; + +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Component; +import java.awt.Color; + +import javax.swing.Icon; +import javax.swing.border.EmptyBorder; + +import org.simantics.ui.colors.Colors; + +public class SheetBorder extends EmptyBorder +{ + private static final long serialVersionUID = 1L; + protected boolean bottomColor; + protected boolean rightColor; + + final Color NONE = Colors.awt(Colors.rgb(0.9,0.9,0.9)); + + + + /** + * Creates a matte border with the specified insets and color. + * @param top the top inset of the border + * @param left the left inset of the border + * @param bottom the bottom inset of the border + * @param right the right inset of the border + * @param matteColor the color rendered for the border + */ + public SheetBorder(int top, int left, int bottom, int right, boolean bottomColor, boolean rightColor) { + super(top, left, bottom, right); + this.bottomColor = bottomColor; + this.rightColor = rightColor; + } + + /** + * Paints the matte border. + */ + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + + Insets insets = getBorderInsets(c); + Color oldColor = g.getColor(); + g.translate(x, y); + + boolean same = bottomColor == rightColor; + + if(same) { + + g.setColor(bottomColor ? Color.BLACK : NONE); + g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom); + g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2); + + } else { + + // Not the same color - paint black on top + + if(bottomColor) { + // Black bottom - no right + g.setColor(NONE); + g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2); + g.setColor(Color.BLACK); + g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom); + } else { + // Black right - no bottom + g.setColor(NONE); + g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom); + g.setColor(Color.BLACK); + g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2); + } + + } + + g.translate(-x, -y); + g.setColor(oldColor); + + } + + /** + * Reinitialize the insets parameter with this Border's current Insets. + * @param c the component for which this border insets value applies + * @param insets the object to be reinitialized + * @since 1.3 + */ + public Insets getBorderInsets(Component c, Insets insets) { + return computeInsets(insets); + } + + /** + * Returns the insets of the border. + * @since 1.3 + */ + public Insets getBorderInsets() { + return computeInsets(new Insets(0,0,0,0)); + } + + /* should be protected once api changes area allowed */ + private Insets computeInsets(Insets insets) { + insets.left = left; + insets.top = top; + insets.right = right; + insets.bottom = bottom; + return insets; + } + + /** + * Returns the color used for tiling the border or null + * if a tile icon is being used. + * @since 1.3 + */ + public Color getMatteColor() { + return NONE; + } + + /** + * Returns the icon used for tiling the border or null + * if a solid color is being used. + * @since 1.3 + */ + public Icon getTileIcon() { + return null; + } + + /** + * Returns whether or not the border is opaque. + */ + public boolean isBorderOpaque() { + // If a tileIcon is set, then it may contain transparent bits + return true; + } + +}