Quellcode durchsuchen

support for multiple style names

svn changeset:2004/svn branch:trunk
tags/6.7.0.beta1
Matti Tahvonen vor 17 Jahren
Ursprung
Commit
58be97d056

+ 4
- 0
src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java Datei anzeigen

@@ -387,6 +387,10 @@ public class ApplicationConnection implements EntryPoint, FocusListener {
component.setVisible(visible);
if (!visible)
return true;
// add additional styles as css classes
if(uidl.hasAttribute("style"))
component.addStyleName(uidl.getStringAttribute("style"));

return false;
}

+ 6
- 6
src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java Datei anzeigen

@@ -32,7 +32,7 @@ public class ICustomLayout extends ComplexPanel implements Paintable, Layout {
private HashMap widgetToCaptionWrapper = new HashMap();

/** Currently rendered style */
String currentStyle;
String currentTemplate;

/** Unexecuted scripts loaded from the template */
private String scripts = "";
@@ -115,16 +115,16 @@ public class ICustomLayout extends ComplexPanel implements Paintable, Layout {
private void updateHTML(UIDL uidl, ApplicationConnection client) {

// Update only if style has changed
String newStyle = uidl.getStringAttribute("style");
if (currentStyle != null && currentStyle.equals(newStyle))
String newTemplate = uidl.getStringAttribute("template");
if (currentTemplate != null && currentTemplate.equals(newTemplate))
return;

// Get the HTML-template from client
String template = client.getResource("layout/" + newStyle + ".html");
String template = client.getResource("layout/" + newTemplate + ".html");
if (template == null) {
template = "Layout file layout/" + newStyle + ".html is missing.";
template = "Layout file layout/" + newTemplate + ".html is missing.";
} else {
currentStyle = newStyle;
currentTemplate = newTemplate;
}

// Connect body of the template to DOM

+ 1
- 1
src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java Datei anzeigen

@@ -469,7 +469,7 @@ public class JsonPaintTarget implements PaintTarget {

tag.addAttribute("\"" + name + "\": \"" + escapeJSON(value) + "\"");

if (customLayoutArgumentsOpen && "style".equals(name))
if (customLayoutArgumentsOpen && "template".equals(name))
getPreCachedResources().add("layout/" + value + ".html");
if(name.equals("locale"))

+ 31
- 7
src/com/itmill/toolkit/ui/AbstractComponent.java Datei anzeigen

@@ -33,7 +33,9 @@ import com.itmill.toolkit.event.EventRouter;
import com.itmill.toolkit.event.MethodEventSource;
import com.itmill.toolkit.terminal.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
@@ -55,11 +57,11 @@ import java.lang.reflect.Method;
public abstract class AbstractComponent implements Component, MethodEventSource {

/* Private members ************************************************* */
/**
* Look-and-feel style of the component.
* Style names.
*/
private String style;
private ArrayList styles;

/**
* Caption text.
@@ -159,7 +161,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* default documentation from implemented interface.
*/
public String getStyle() {
return this.style;
String s = "";
if(styles != null) {
for(Iterator it = styles.iterator();it.hasNext();)
s += " " + (String) it.next();
}
return s;
}

/*
@@ -167,10 +174,27 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* default documentation from implemented interface.
*/
public void setStyle(String style) {
this.style = style;
if(this.styles == null) {
styles = new ArrayList();
}
styles.clear();
styles.add(style);
requestRepaint();
}

public void addStyleName(String style) {
if(this.styles == null) {
styles = new ArrayList();
}
if(! styles.contains(style))
this.styles.add(style);
requestRepaint();
}
public void removeStyleName(String style) {
styles.remove(style);
}
/*
* Get's the component's caption. Don't add a JavaDoc comment here, we use
* the default documentation from implemented interface.
@@ -516,7 +540,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
public final void paint(PaintTarget target) throws PaintException {

if (!target.startTag(this, this.getTag())) {
if (getStyle() != null && getStyle().length() > 0)
if (styles != null && styles.size() > 0)
target.addAttribute("style", getStyle());
if (isReadOnly())
target.addAttribute("readonly", true);

+ 24
- 4
src/com/itmill/toolkit/ui/Component.java Datei anzeigen

@@ -51,21 +51,41 @@ import java.util.Locale;
public interface Component extends Paintable, VariableOwner {

/**
* Gets the look-and-feel style of the component.
*
* Gets style for component. Multiple styles are joined with spaces.
*
* @return the component's styleValue of property style.
*/
public String getStyle();

/**
* Sets the look-and-feel style of the component. This method will trigger a
* Sets and replaces all previous style names of the component. This method will trigger a
* {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
*
* @param style
* the new style of the component.
*/
public void setStyle(String style);

/**
* Adds style name to component. Handeling additional style names is terminal spesicif,
* but in web browser enviroment they will most likely become CSS classes as given on server side.
*
* This method will trigger a
* {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
*
* @param style
* the new style to be added to the component
*/
public void addStyleName(String style);
/**
* Removes given style name from component.
*
* @param style
* the style to be removed
*/
public void removeStyleName(String style);
/**
* <p>
* Tests if the component is enabled or not. All the variable change events

+ 17
- 0
src/com/itmill/toolkit/ui/CustomComponent.java Datei anzeigen

@@ -519,4 +519,21 @@ public class CustomComponent implements Component {
this.componentType = componentType;
}

/**
* Custom component does not implement custom styles by default.
*
* @see com.itmill.toolkit.ui.Component#getStyle()
*/
public void addStyleName(String style) {
}

/**
* Custom component does not implement custom styles by default.
*
* @see com.itmill.toolkit.ui.Component#getStyle()
*/
public void removeStyleName(String style) {
}

}

+ 6
- 3
src/com/itmill/toolkit/ui/CustomLayout.java Datei anzeigen

@@ -67,12 +67,14 @@ public class CustomLayout extends AbstractComponentContainer implements Layout {
* Custom layout slots containing the components.
*/
private HashMap slots = new HashMap();
private String templateName;

/**
* Constructor for custom layout with given style.
* Constructor for custom layout with given template name.
*/
public CustomLayout(String style) {
setStyle(style);
public CustomLayout(String template) {
templateName = template;
}

/**
@@ -172,6 +174,7 @@ public class CustomLayout extends AbstractComponentContainer implements Layout {
*/
public void paintContent(PaintTarget target) throws PaintException {

target.addAttribute("template", templateName);
// Adds all items in all the locations
for (Iterator i = slots.keySet().iterator(); i.hasNext();) {


Laden…
Abbrechen
Speichern