Server
. You add
myServer
to the existing types (
NE
,
MD
,
NMW
,
BTS
, and so on).
Server
graphic states
.
ServerBaseRenderer
that extends IltNEBaseRenderer and redefine its method getPreferredSize. This class will be
enhanced later on to draw the
Server
element base.
static class ServerBaseRenderer extends IltNEBaseRenderer { private static Dimension NormalSize = new Dimension(25,40); private static Dimension SmallSize = new Dimension(13,21); public Dimension getPreferredSize (boolean collapsed) { if (collapsed) return SmallSize; else return NormalSize; } }
NormalSize
and
SmallSize
define the normal dimension of the base and its dimension when it
is collapsed. Calling
getPreferredSize
returns the current size of the base.
// Some factors for drawing: private static final float _XGrid = 4.0f / 25.0f; private static final float _YGrid = 4.0f / 40.0f; private static final float _WGrid = 13.0f / 25.0f; private static final float _HGrid = 1.0f / 40.0f; private static final float _VStepGrid = 2.0f / 40.0f; private static final float _XButton = 19.0f / 25.0f; private static final float _YButton = 4.0f / 40.0f; private static final float _WButton = 2.0f / 25.0f; private static final float _HButton = 2.0f / 40.0f; private static final float _XDisk = 18.0f / 25.0f; private static final float _YDisk = 23.0f / 40.0f; private static final float _WDisk = 3.0f / 25.0f; private static final float _HDisk = 12.0f / 40.0f;
private static Color GridColor = IltrColor.NewColor("server grid color", IltrColor._90PctGrey); private static Color ButtonColor = IltrColor.NewColor("server button color", Color.blue); private Ilt2DPalette GridPalette; private Ilt2DPalette ButtonPalette; protected void initResources () { super.initResources(); GridPalette = Ilt2DPalette.NewSimple2DPalette(GridColor); ButtonPalette = Ilt2DPalette.NewSimple2DPalette(ButtonColor); }
draw
method of an IlvGraphic object. The method receives a
graphic to draw with, a transformer linked to the associated
view, and an IlvRect object that gives the size and
position of the base.
public void drawMain (Graphics g, IlvTransformer t, IlvRect rect) { // Get the corners of the base rectangle. int x1 = (int)rect.x; int y1 = (int)rect.y; int x2 = x1 + (int)rect.width-1; int y2 = y1 + (int)rect.height-1; // Get the state dependent parameters. IltDetailLevel detailLevel = getDetailLevel(); Ilt2DPalette palette = getPalette(); Ilt2DPalette brightPalette = getBrightPalette(); Ilt2DPalette darkPalette = getDarkPalette(); int borderThickness = getBorderThickness();
Server
graphic states
), and the standard palettes.
if (x1<=x2 && y1<=y2) { IltGraphicUtil.FillRect(g,t,x1,y1,x2,y2,palette); // Paint the border if (detailLevel.equals(IltDetailLevel.MaximumDetails)) { if (rect.width < 20 && borderThickness > 1) IltGraphicUtil.DrawReliefRect (g,t,x1,y1,x2,y2, brightPalette, darkPalette, borderThickness); else { IltGraphicUtil.DrawRect(g,t,x1,y1,x2,y2, darkPalette, borderThickness); }
// Paint the grid, button and disk. if (detailLevel.equals(IltDetailLevel.MaximumDetails) || detailLevel.equals(IltDetailLevel.FewDetails)){ // Grid, button and disk dimensions. final int gridWidth = Math.round(rect.width * _WGrid); final int gridHeight = Math.round(rect.height * _HGrid); final int buttonWidth = Math.round(rect.width * _WButton); final int buttonHeight = Math.round(rect.height * _HButton); final int diskWidth = Math.round(rect.width * _WDisk); final int diskHeight = Math.round(rect.height * _HDisk); // Grid rectangle corners. final int gx1 = x1 + Math.round(rect.width * _XGrid); int gy1 = y1 + Math.round(rect.height * _YGrid); final int gx2 = gx1 + gridWidth-1; int gy2 = gy1 + gridHeight-1; final int gvstep = Math.round(rect.height * _VStepGrid); // Button rectangle corners. final int bx1 = x1 + Math.round(rect.width * _XButton); final int by1 = y1 + Math.round(rect.height * _YButton); final int bx2 = bx1 + buttonWidth-1; final int by2 = by1 + buttonHeight-1; // Disk rectangle corners. final int dx1 = x1 + Math.round(rect.width * _XDisk); final int dy1 = y1 + Math.round(rect.height * _YDisk); final int dx2 = dx1 + diskWidth-1; final int dy2 = dy1 + diskHeight-1; // Grid and button colors. final Ilt2DPalette gridPalette = (detailLevel.equals(IltDetailLevel.FewDetails) ? darkPalette : GridPalette); final Ilt2DPalette buttonPalette = (detailLevel.equals(IltDetailLevel.FewDetails) ? darkPalette : ButtonPalette); // Paint the grid. if (gvstep > 1) { for (int i = 0; i < 7; i++) { IltGraphicUtil._FillRect(g,t, gx1,gy1,gx2,gy2, gridPalette); gy1 += gvstep; gy2 += gvstep; } } else if (gvstep == 1) { // Paint a grey rectangle instead of the grid. Color rectColor = palette.getForeground(); Color gridColor = gridPalette.getForeground(); Color greyColor = new Color((rectColor.getRed()+gridColor.getRed())/2, (rectColor.getGreen()+gridColor.getGreen())/2, (rectColor.getBlue()+gridColor.getBlue())/2); Ilt2DPalette greyPalette = Ilt2DPalette.NewSimple2DPalette(greyColor); IltGraphicUtil._FillRect(g,t, gx1,gy1,gx2,gy2+6*gvstep, greyPalette); } // Paint the button. IltGraphicUtil._FillRect(g,t, bx1,by1,bx2,by2, buttonPalette); // Paint the disk. if (detailLevel.equals(IltDetailLevel.FewDetails)) { IltGraphicUtil._FillRect(g,t, dx1,dy1,dx2,dy2, darkPalette); } else { IltGraphicUtil._FillRect(g,t, dx1,dy1,dx2,dy2, palette); IltGraphicUtil.DrawReliefRect(g,t, dx1,dy1,dx2,dy2, brightPalette,darkPalette, 1); }
protected void drawExtraBorders (Graphics g, IlvTransformer t, IlvRect rect) { { // Draw the alarm border, if needed according to the state. Color c = getAlarmBorderColor(); if (c != null) drawExtraBorder(g,t,rect,c,0,IltrThickness.AlarmBorderThickness); } { // Draw the selection border, if the object is currently selected. Color c = getSelectionBorderForeground(); if (c != null) drawExtraBorder(g,t,rect,c,IltrThickness.AlarmBorderThickness, IltrThickness.SelectionBorderThickness); } }
static IltNetworkElement.Type Server = new IltNetworkElement.Type("Server"); static { IltSettings.SetValue("NetworkElement.Type.Server.Renderer", new IltBaseRendererFactory() { public IltBaseRenderer createValue() { return new ServerBaseRenderer(); } } ); } IltDefaultDataSource dataSource = new IltDefaultDataSource(); IltNetworkElement ne = new IltNetworkElement ("NE", Server, new IltOSIObjectState()); ne.setAttributeValue(IltObject.PositionAttribute, new IlpPoint(100,100)); dataSource.addObject(ne); IlpNetwork network = new IlpNetwork(); network.setDataSource(dataSource);
setting."ilog.tgo.model.IltNetworkElement"{ types[0]: @+neType0; } Subobject#neType0 { class: 'ilog.tgo.model.IltNetworkElement.Type'; name: "Server"; }
public class MyNERendererFactory implements IltBaseRendererFactory { public IltBaseRenderer createValue() { return new ServerBaseRenderer(); } }
setting."ilog.tgo.model.IltNetworkElement.Type"[name="Server"] { renderer: @+neRendererFactory0; } Subobject#neRendererFactory0 { class: 'MyNERendererFactory'; }
ne.setType (Server);
ne.setAttributeValue (IltNetworkElement.TypeAttribute, Server);