Search in sources :

Example 6 with SpecialMatteBorder

use of com.servoy.j2db.util.gui.SpecialMatteBorder in project servoy-client by Servoy.

the class AbstractScriptLabel method setFocusPainted.

public void setFocusPainted(boolean showFocus) {
    if (showFocus) {
        final SpecialMatteBorder border = new SpecialMatteBorder(1, 1, 1, 1, Color.BLACK, Color.BLACK, Color.BLACK, Color.BLACK);
        border.setDashPattern(new float[] { 1 });
        addFocusListener(new FocusListener() {

            public void focusGained(FocusEvent e) {
                if (getBorder() == null)
                    setBorder(border);
            }

            public void focusLost(FocusEvent e) {
                if (getBorder() == border)
                    setBorder(null);
            }
        });
    }
}
Also used : SpecialMatteBorder(com.servoy.j2db.util.gui.SpecialMatteBorder) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 7 with SpecialMatteBorder

use of com.servoy.j2db.util.gui.SpecialMatteBorder in project servoy-client by Servoy.

the class CellAdapter method applyRowBorder.

private void applyRowBorder(JComponent component, JTable jtable, boolean isSelected, int row, boolean hasFocus) {
    Border styleBorder = getBorder(jtable, isSelected, row);
    boolean hasStyleBorder = false;
    if (styleBorder != null) {
        hasStyleBorder = true;
        if (component instanceof AbstractButton && !((AbstractButton) component).isBorderPainted()) {
            ((AbstractButton) component).setBorderPainted(true);
        }
    } else {
        styleBorder = noFocusBorder;
    }
    Border marginBorder = null;
    if (noFocusBorder instanceof EmptyBorder) {
        marginBorder = noFocusBorder;
    } else if (noFocusBorder instanceof CompoundBorder && ((CompoundBorder) noFocusBorder).getInsideBorder() instanceof EmptyBorder) {
        marginBorder = ((CompoundBorder) noFocusBorder).getInsideBorder();
    }
    Border adjustedBorder = null;
    if (!hasFocus) {
        if (hasStyleBorder && marginBorder != null) {
            styleBorder = new CompoundBorder(styleBorder, marginBorder);
        }
        adjustedBorder = styleBorder;
    } else {
        // $NON-NLS-1$
        adjustedBorder = UIManager.getBorder("Table.focusCellHighlightBorder");
        if (styleBorder != null) {
            if (hasStyleBorder) {
                if (marginBorder != null) {
                    adjustedBorder = new CompoundBorder(styleBorder, new CompoundBorder(adjustedBorder, marginBorder));
                } else {
                    adjustedBorder = new CompoundBorder(styleBorder, adjustedBorder);
                }
            } else if (styleBorder instanceof CompoundBorder) {
                Border insideBorder = ((CompoundBorder) styleBorder).getInsideBorder();
                Border outsideBorder = ((CompoundBorder) styleBorder).getOutsideBorder();
                if (outsideBorder instanceof SpecialMatteBorder)
                    adjustedBorder = new CompoundBorder(adjustedBorder, styleBorder);
                else
                    adjustedBorder = new CompoundBorder(adjustedBorder, insideBorder);
            } else if (styleBorder instanceof SpecialMatteBorder) {
                adjustedBorder = new CompoundBorder(adjustedBorder, styleBorder);
            } else {
                // keep the renderer content at the same position,
                // create a focus border with the same border insets
                Insets noFocusBorderInsets = styleBorder.getBorderInsets(component);
                Insets adjustedBorderInsets = adjustedBorder.getBorderInsets(component);
                EmptyBorder emptyInsideBorder = new EmptyBorder(Math.max(0, noFocusBorderInsets.top - adjustedBorderInsets.top), Math.max(0, noFocusBorderInsets.left - adjustedBorderInsets.left), Math.max(0, noFocusBorderInsets.bottom - adjustedBorderInsets.bottom), Math.max(0, noFocusBorderInsets.right - adjustedBorderInsets.right));
                adjustedBorder = new CompoundBorder(adjustedBorder, emptyInsideBorder);
            }
        }
    }
    component.setBorder(adjustedBorder);
}
Also used : AbstractButton(javax.swing.AbstractButton) Insets(java.awt.Insets) SpecialMatteBorder(com.servoy.j2db.util.gui.SpecialMatteBorder) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) Border(javax.swing.border.Border) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) SpecialMatteBorder(com.servoy.j2db.util.gui.SpecialMatteBorder)

Example 8 with SpecialMatteBorder

use of com.servoy.j2db.util.gui.SpecialMatteBorder in project servoy-client by Servoy.

the class JSSolutionModel method createSpecialMatteBorder.

/**
 * Create a special matte border string.
 *
 * @sample
 * var form = solutionModel.getForm("someForm");
 * // create a rectangle border (no rounded corners) and continous line
 * form.borderType = solutionModel.createSpecialMatteBorder(1,1,1,1,"#00ff00","#00ff00","#00ff00","#00ff00",0,null);
 * // create a border with rounded corners and dashed line (25 pixels drawn, then 25 pixels skipped)
 * // form.borderType = solutionModel.createSpecialMatteBorder(1,1,1,1,"#00ff00","#00ff00","#00ff00","#00ff00",10,new Array(25,25));
 *
 * @param top_width top width of matte border in pixels
 * @param right_width right width of matte border in pixels
 * @param bottom_width bottom width of matte border in pixels
 * @param left_width left width of matte border in pixels
 * @param top_color top border color
 * @param right_color right border color
 * @param bottom_color bottom border color
 * @param left_color left border color
 * @param rounding_radius width of the arc to round the corners
 * @param dash_pattern the dash pattern of border stroke
 */
@JSFunction
public String createSpecialMatteBorder(int top_width, int right_width, int bottom_width, int left_width, String top_color, String right_color, String bottom_color, String left_color, float rounding_radius, float[] dash_pattern) {
    SpecialMatteBorder border = new SpecialMatteBorder(top_width, left_width, bottom_width, right_width, PersistHelper.createColor(top_color), PersistHelper.createColor(right_color), PersistHelper.createColor(bottom_color), PersistHelper.createColor(left_color));
    border.setRoundingRadius(rounding_radius);
    if (dash_pattern != null)
        border.setDashPattern(dash_pattern);
    return ComponentFactoryHelper.createBorderString(border);
}
Also used : SpecialMatteBorder(com.servoy.j2db.util.gui.SpecialMatteBorder) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Aggregations

SpecialMatteBorder (com.servoy.j2db.util.gui.SpecialMatteBorder)8 RoundedBorder (com.servoy.j2db.util.gui.RoundedBorder)5 Insets (java.awt.Insets)5 Color (java.awt.Color)4 BevelBorder (javax.swing.border.BevelBorder)4 Border (javax.swing.border.Border)4 EmptyBorder (javax.swing.border.EmptyBorder)4 EtchedBorder (javax.swing.border.EtchedBorder)4 Font (java.awt.Font)3 StringTokenizer (java.util.StringTokenizer)3 CompoundBorder (javax.swing.border.CompoundBorder)3 LineBorder (javax.swing.border.LineBorder)3 MatteBorder (javax.swing.border.MatteBorder)3 TitledBorder (javax.swing.border.TitledBorder)3 JSONObject (org.json.JSONObject)2 CustomBevelBorder (com.servoy.j2db.util.gui.CustomBevelBorder)1 CustomEtchedBorder (com.servoy.j2db.util.gui.CustomEtchedBorder)1 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 HashMap (java.util.HashMap)1