use of com.servoy.j2db.ui.IButton in project servoy-client by Servoy.
the class ComponentFactory method createGraphicalComponent.
private static IComponent createGraphicalComponent(IApplication application, Form form, GraphicalComponent label, IScriptExecuter el, IDataProviderLookup dataProviderLookup) {
int style_halign = -1;
int style_valign = -1;
int textTransform = 0;
int mediaid = 0;
Pair<IStyleSheet, IStyleRule> styleInfo = getStyleForBasicComponent(application, label, form);
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
style_valign = ss.getVAlign(s);
style_halign = ss.getHAlign(s);
boolean parseMedia = true;
// anything else then then the css through the templategenerator is used. (See TemplateGenerator.createGraphicalComponentHTML)
if (application.getApplicationType() == IApplication.WEB_CLIENT) {
parseMedia = s.getValue(CSS.Attribute.BACKGROUND_REPEAT.toString()) == null && s.getValue(CSS.Attribute.BACKGROUND_POSITION.toString()) == null;
}
if (parseMedia) {
Object mediaUrl = s.getValue(CSS.Attribute.BACKGROUND_IMAGE.toString());
if (mediaUrl != null && mediaUrl.toString() != null) {
String mediaUrlString = mediaUrl.toString();
int start = mediaUrlString.indexOf(MediaURLStreamHandler.MEDIA_URL_DEF);
if (start != -1) {
String name = mediaUrlString.substring(start + MediaURLStreamHandler.MEDIA_URL_DEF.length());
if (name.endsWith("')") || name.endsWith("\")"))
name = name.substring(0, name.length() - 2);
if (name.endsWith(")"))
name = name.substring(0, name.length() - 1);
Media media = application.getFlattenedSolution().getMedia(name);
if (media != null) {
mediaid = media.getID();
}
}
}
}
String transform = s.getValue(CSS.Attribute.TEXT_TRANSFORM.toString());
if (transform != null) {
if ("uppercase".equals(transform)) {
textTransform = ILabel.UPPERCASE;
} else if ("lowercase".equals(transform)) {
textTransform = ILabel.LOWERCASE;
} else if ("capitalize".equals(transform)) {
textTransform = ILabel.CAPITALIZE;
}
}
}
}
ILabel l;
AbstractRuntimeLabel<? extends ILabel> scriptable;
IStylePropertyChangesRecorder jsChangeRecorder = application.getItemFactory().createChangesRecorder();
if (ComponentFactory.isButton(label)) {
IButton button;
if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
scriptable = new RuntimeScriptButton(jsChangeRecorder, application);
button = application.getItemFactory().createScriptButton((RuntimeScriptButton) scriptable, getWebID(form, label));
} else {
scriptable = new RuntimeDataButton(jsChangeRecorder, application);
button = application.getItemFactory().createDataButton((RuntimeDataButton) scriptable, getWebID(form, label));
IDataProvider dp = null;
try {
dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
((IDisplayData) button).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
((IDisplayTagText) button).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
((IDisplayData) button).setNeedEntireState(label.getDisplaysTags());
}
((AbstractRuntimeButton<IButton>) scriptable).setComponent(button, label);
button.setMediaOption(label.getMediaOptions());
if (label.getRolloverImageMediaID() > 0) {
try {
button.setRolloverIcon(label.getRolloverImageMediaID());
button.setRolloverEnabled(true);
} catch (Exception ex) {
Debug.error(ex);
}
}
l = button;
} else {
if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
scriptable = new RuntimeScriptLabel(jsChangeRecorder, application);
l = application.getItemFactory().createScriptLabel((RuntimeScriptLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
} else {
scriptable = new RuntimeDataLabel(jsChangeRecorder, application);
l = application.getItemFactory().createDataLabel((RuntimeDataLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
IDataProvider dp = null;
try {
dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
((IDisplayData) l).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
((IDisplayTagText) l).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
((IDisplayData) l).setNeedEntireState(label.getDisplaysTags());
}
((AbstractHTMLSubmitRuntimeLabel<ILabel>) scriptable).setComponent(l, label);
l.setMediaOption(label.getMediaOptions());
if (label.getRolloverImageMediaID() > 0) {
try {
l.setRolloverIcon(label.getRolloverImageMediaID());
} catch (Exception ex) {
Debug.error(ex);
}
}
}
String mnemonic = application.getI18NMessageIfPrefixed(label.getMnemonic());
if (mnemonic != null && mnemonic.length() > 0) {
l.setDisplayedMnemonic(mnemonic.charAt(0));
}
l.setTextTransform(textTransform);
if (el != null && (label.getOnActionMethodID() > 0 || label.getOnDoubleClickMethodID() > 0 || label.getOnRightClickMethodID() > 0)) {
l.addScriptExecuter(el);
if (label.getOnActionMethodID() > 0)
l.setActionCommand(Integer.toString(label.getOnActionMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onActionMethodID")));
if (label.getOnDoubleClickMethodID() > 0)
l.setDoubleClickCommand(Integer.toString(label.getOnDoubleClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onDoubleClickMethodID")));
if (label.getOnRightClickMethodID() > 0)
l.setRightClickCommand(Integer.toString(label.getOnRightClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onRightClickMethodID")));
}
if (label.getLabelFor() == null || (form.getView() != FormController.TABLE_VIEW && form.getView() != FormController.LOCKED_TABLE_VIEW)) {
int onRenderMethodID = label.getOnRenderMethodID();
AbstractBase onRenderPersist = label;
if (onRenderMethodID <= 0) {
onRenderMethodID = form.getOnRenderMethodID();
onRenderPersist = form;
}
if (onRenderMethodID > 0) {
RenderEventExecutor renderEventExecutor = scriptable.getRenderEventExecutor();
renderEventExecutor.setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(onRenderPersist.getFlattenedMethodArguments("onRenderMethodID")));
IForm rendererForm = application.getFormManager().getForm(form.getName());
IScriptExecuter rendererScriptExecuter = rendererForm instanceof FormController ? ((FormController) rendererForm).getScriptExecuter() : null;
renderEventExecutor.setRenderScriptExecuter(rendererScriptExecuter);
}
}
l.setRotation(label.getRotation());
l.setFocusPainted(label.getShowFocus());
l.setCursor(Cursor.getPredefinedCursor(label.getRolloverCursor()));
try {
int halign = label.getHorizontalAlignment();
if (halign != -1) {
l.setHorizontalAlignment(halign);
} else if (style_halign != -1) {
l.setHorizontalAlignment(style_halign);
}
} catch (RuntimeException e) {
// just ignore...Debug.error(e);
}
int valign = label.getVerticalAlignment();
if (valign != -1) {
l.setVerticalAlignment(valign);
} else if (style_valign != -1) {
l.setVerticalAlignment(style_valign);
}
try {
if (!label.getDisplaysTags()) {
l.setText(application.getI18NMessageIfPrefixed(label.getText()));
}
} catch (RuntimeException e1) {
// ignore
}
l.setToolTipText(application.getI18NMessageIfPrefixed(label.getToolTipText()));
if (label.getImageMediaID() > 0) {
try {
l.setMediaIcon(label.getImageMediaID());
} catch (Exception e) {
Debug.error(e);
}
} else if (mediaid > 0) {
try {
l.setMediaIcon(mediaid);
} catch (Exception e) {
Debug.error(e);
}
}
if (label.getDataProviderID() != null) {
scriptable.setComponentFormat(ComponentFormat.getComponentFormat(label.getFormat(), label.getDataProviderID(), dataProviderLookup, application));
}
applyBasicComponentProperties(application, l, label, styleInfo);
Border border = null;
Insets insets = null;
if (label.getBorderType() != null) {
border = ComponentFactoryHelper.createBorder(label.getBorderType());
}
if (label.getMargin() != null) {
insets = label.getMargin();
}
if (styleInfo != null && (border == null || insets == null)) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
if (border == null && ss.hasBorder(s)) {
border = ss.getBorder(s);
}
if (insets == null && ss.hasMargin(s)) {
insets = ss.getMargin(s);
}
}
}
if (border != null && insets != null) {
l.setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)));
} else if (border == null && insets != null && l instanceof IButton) {
((IButton) l).setMargin(insets);
} else // supports setMargin, then fake the margins through empty border. (issue 166391)
if (border == null && insets != null) {
l.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
}
if (l instanceof IAnchoredComponent) {
((IAnchoredComponent) l).setAnchors(label.getAnchors());
}
return l;
}
use of com.servoy.j2db.ui.IButton in project servoy-client by Servoy.
the class WebForm method getFormAnchorInfo.
@SuppressWarnings("unchecked")
public FormAnchorInfo getFormAnchorInfo() {
formAnchorInfo = new FormAnchorInfo(formController.getName(), formController.getForm().getSize(), formController.getForm().getUUID());
final Map<String, ISupportAnchors> elements = new HashMap<String, ISupportAnchors>();
Iterator<IPersist> e1 = formController.getForm().getAllObjects();
while (e1.hasNext()) {
IPersist obj = e1.next();
if (obj instanceof ISupportAnchors && obj instanceof ISupportBounds) {
elements.put(ComponentFactory.getWebID(formController.getForm(), obj), (ISupportAnchors) obj);
}
}
// In case we are in table view.
if (view instanceof WebCellBasedView) {
WebCellBasedView formPart = (WebCellBasedView) view;
formAnchorInfo.addPart(Part.getDisplayName(Part.BODY), formPart.getMarkupId(), 50);
formAnchorInfo.isTableView = true;
formAnchorInfo.bodyContainerId = formPart.getMarkupId();
}
// Find the id of the form navigator, if any.
visitChildren(Component.class, new IVisitor() {
public Object component(Component component) {
if (component instanceof WebDefaultRecordNavigator) {
formAnchorInfo.navigatorWebId = component.getMarkupId();
return IVisitor.CONTINUE_TRAVERSAL;
} else if (component instanceof WebTabPanel) {
return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
} else
return IVisitor.CONTINUE_TRAVERSAL;
}
});
visitChildren(WebDataRenderer.class, new IVisitor() {
public Object component(Component component) {
WebDataRenderer formPart = (WebDataRenderer) component;
final FormPartAnchorInfo part = formAnchorInfo.addPart(formPart.getFormPartName(), formPart.getMarkupId(), formPart.getSize().height);
if (Part.getDisplayName(Part.BODY).equals(formPart.getFormPartName())) {
Component parent = formPart.getParent();
formAnchorInfo.bodyContainerId = parent.getMarkupId();
}
formPart.visitChildren(ISupportWebBounds.class, new IVisitor() {
public Object component(Component comp) {
String id = comp.getId();
ISupportAnchors obj = elements.get(id);
if (obj != null) {
int anchors = obj.getAnchors();
if (((anchors > 0 && anchors != IAnchorConstants.DEFAULT)) || (comp instanceof WebTabPanel) || (comp instanceof IButton)) {
Rectangle r = ((ISupportWebBounds) comp).getWebBounds();
if (r != null) {
if (anchors == 0)
anchors = IAnchorConstants.DEFAULT;
int hAlign = -1;
int vAlign = -1;
if (obj instanceof ISupportTextSetup) {
ISupportTextSetup alignedObj = (ISupportTextSetup) obj;
hAlign = alignedObj.getHorizontalAlignment();
vAlign = alignedObj.getVerticalAlignment();
}
String imageDisplayURL = null;
boolean isRandomParamRemoved = false;
if (comp instanceof IImageDisplay) {
Object[] aImageDisplayURL = WebBaseButton.getImageDisplayURL((IImageDisplay) comp, false);
imageDisplayURL = (String) aImageDisplayURL[0];
isRandomParamRemoved = ((Boolean) aImageDisplayURL[1]).booleanValue();
}
part.addAnchoredElement(comp.getMarkupId(), anchors, r, hAlign, vAlign, comp.getClass(), imageDisplayURL, isRandomParamRemoved);
}
}
}
return IVisitor.CONTINUE_TRAVERSAL;
}
});
return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
});
return formAnchorInfo;
}
use of com.servoy.j2db.ui.IButton in project servoy-client by Servoy.
the class ComponentFactory method applyBasicComponentProperties.
public static void applyBasicComponentProperties(IApplication application, IComponent c, BaseComponent bc, Pair<IStyleSheet, IStyleRule> styleInfo) {
// flag for border set by style config
boolean isBorderStyle = false;
// by default it is not transparent
c.setOpaque(true);
// apply any style
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
if (s.hasAttribute(CSS.Attribute.COLOR.toString())) {
Color cfg = ss.getForeground(s);
if (cfg != null)
c.setForeground(cfg);
}
Object sbackground_color = s.getValue(CSS.Attribute.BACKGROUND_COLOR.toString());
if (sbackground_color != null) {
if (IStyleSheet.COLOR_TRANSPARENT.equals(sbackground_color.toString())) {
c.setOpaque(false);
} else {
Color cbg = ss.getBackground(s);
if (cbg != null)
c.setBackground(cbg);
}
}
// else c.setOpaque(false); // no background-color means transparent
if (ss.hasFont(s)) {
Font f = ss.getFont(s);
if (f != null)
c.setFont(f);
}
if (ss.hasBorder(s)) {
Border b = ss.getBorder(s);
if (b != null) {
c.setBorder(b);
isBorderStyle = true;
}
}
if (ss.hasMargin(s)) {
Insets i = ss.getMargin(s);
if (i != null && c instanceof IButton)
((IButton) c).setMargin(i);
}
}
}
// We intentionally leave the location setting to DataRenderers, since thats the context and might substract part heights from location!
java.awt.Dimension dim = bc.getSize();
if (dim != null)
c.setSize(bc.getSize());
javax.swing.border.Border border = ComponentFactoryHelper.createBorder(bc.getBorderType());
if ((c instanceof JCheckBox || /* DataCheckBox */
c instanceof JRadioButton) && (border != null || isBorderStyle)) {
((AbstractButton) c).setBorderPainted(true);
if (c instanceof JCheckBox) {
((JCheckBox) c).setBorderPaintedFlat(false);
}
}
if (border != null) {
if (border instanceof TitledBorder && Utils.isAppleMacOS()) {
// apple bug.. i have to set the font again (as new!!)
TitledBorder tb = (TitledBorder) border;
Font f = tb.getTitleFont();
if (f != null) {
tb.setTitleFont(new Font(f.getName(), f.getStyle(), f.getSize()));
}
c.setBorder(border);
} else {
c.setBorder(border);
}
}
// if (c instanceof IDelegate)
// {
// c = (JComponent)((IDelegate)c).getDelegate();
// }
String fontString = bc.getFontType();
if (fontString != null) {
Font f = PersistHelper.createFont(fontString);
if (f != null)
c.setFont(f);
}
java.awt.Color bg = bc.getBackground();
if (bg != null)
c.setBackground(bg);
java.awt.Color fg = bc.getForeground();
if (fg != null)
c.setForeground(fg);
String name = bc.getName();
if (name != null)
c.setName(name);
// only use component property value if it is "checked" to be transparent
if (bc.getTransparent())
c.setOpaque(false);
c.setComponentEnabled(bc.getEnabled());
c.setComponentVisible(bc.getVisible());
if (Utils.isSwingClient(application.getApplicationType())) {
// special code for smart client LAFs, like BizLaf
String delegateStyleClassNamePropertyKey = application.getSettings().getProperty("servoy.smartclient.componentStyleClassDelegatePropertyKey");
if (delegateStyleClassNamePropertyKey != null && c instanceof JComponent) {
if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeComponent) {
// special case since putClientProperty can delegate properties but cannot be overridden we relay on the scripting equivalent
((IRuntimeComponent) ((IScriptableProvider) c).getScriptObject()).putClientProperty(delegateStyleClassNamePropertyKey, bc.getStyleClass());
} else {
((JComponent) c).putClientProperty(delegateStyleClassNamePropertyKey, bc.getStyleClass());
}
}
}
}
Aggregations