Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Automatic tile size in TileGrid

    Is it possible for tiles in TileGrid to have the size of their content or at least take up all the space in one dimesion?
    In the following example I would like the tiles to be completely visible in the horizontal direction, their height can stay fixed.
    Code:
    public class Application implements EntryPoint {
    	
    	private class MyTileGrid extends TileGrid {
    		
    		public MyTileGrid() {
    			setHeight100();		
    			setWidth(150);
    			setOverflow(Overflow.AUTO);
    			setShowEdges(true);
    			setPadding(10);
    			setCanAcceptDrop(true);
    			setCanDragReposition(false);
    			setCanDrag(false);
    			setCanDragResize(true);
    			setShowResizeBar(true);
    			setCanReorderTiles(true);
    			setCanDragTilesOut(true);			
    			setDragDataAction(DragDataAction.MOVE);						
    			setTileDragAppearance(DragAppearance.NONE);
    			setDragAppearance(DragAppearance.NONE);
    			
    			setTilesPerLine(1);		
    			setLayoutPolicy(TileLayoutPolicy.FIT);		
    			setExpandMargins(true);
    			setOrientation(Orientation.HORIZONTAL);
    			setDataSource(createDS());
    			setAutoFetchData(true);
    			
    		}
    		
    		@Override
    		protected String getTileHTML(Record rec) {		
    			String width = rec.getAttributeAsString("width");
    			String height = rec.getAttributeAsString("height");
    			String content = rec.getAttributeAsString("content");
    			
    			
    			StringBuilder html = new StringBuilder("<TABLE BORDER='1px black solid' CELLSPACING=0 CLASS=normal WIDTH='");
    			html.append(width);
    			html.append("' height=");
    			html.append(height);
    			html.append("' CELLPADDING=0 STYLE='table-layout:fixed; ");
    			html.append("overflow: hidden;'><tbody><tr><td style='white-space: nowrap;'>");
    			html.append(content);
    			
    			html.append("</td></tr></table>"); 
    					
    			return html.toString();	
    		}
    		
    	}
    
    	@Override
    	public void onModuleLoad() {
    		MyTileGrid grid = new MyTileGrid();
    		grid.draw();
    	}
    
    	private DataSource createDS() {
    		DataSource ds = new DataSource();
    		ds.setClientOnly(true);
    		
    		DataSourceField width = new DataSourceTextField("width");
    		DataSourceField height = new DataSourceTextField("height");
    		DataSourceField content = new DataSourceTextField("content");
    		ds.setFields(width, height, content);
    		
    		Record rec1 = new Record();
    		rec1.setAttribute("height", 100);
    		rec1.setAttribute("width", 100);
    		rec1.setAttribute("content", "100x100");
    		ds.addData(rec1);
    		Record rec2 = new Record();
    		rec2.setAttribute("height", 100);
    		rec2.setAttribute("width", 200);
    		rec2.setAttribute("content", "100x200");
    		ds.addData(rec2);
    		Record rec3 = new Record();
    		rec3.setAttribute("height", 200);
    		rec3.setAttribute("width", 100);
    		rec3.setAttribute("content", "200x100");
    		ds.addData(rec3);
    		
    		Record rec4 = new Record();
    		rec4.setAttribute("height", 100);
    		rec4.setAttribute("width", 300);
    		rec4.setAttribute("content", "100x300");
    		ds.addData(rec4);
    		
    		return ds;
    	}
    }
    Thanks
Working...
X