Hi!
What should I insert in my class to know when user changed Label text? Can you help me?
Thanks!
public class Pool : GoBoxNode
{
//Variables
private int CellGridSize = 1;
private ResourceManager rm;
private Font mFont;
private Color mFontColor;
private Color mBackColor;
private Color mBorderColor;
private int mBorderThickness;
private ArrayList AppFontSizeList;
private int mKey = 0;
private int MinSizeW = 150;
private int MinSizeH = 100;
private GenerateProcess GenProcess;
public Pool(GenerateProcess Gen_Process)
{
GenProcess = Gen_Process;
rm = new ResourceManager("constants", this.GetType().Assembly);
this.LinkPointsSpread = true;
this.PortBorderMargin = new SizeF(1, 1);
this.Port.Brush = null;
this.Port.Pen = new Pen(mBorderColor, mBorderThickness);
this.Grid.Pen = new Pen(mBorderColor, mBorderThickness);
this.Resizable = true;
//Configure pool Label
ConfigurePoolLabel();
//Configure Pool Grid
ConfigurePoolGrid();
}
public int UniqueID
{
get { return this.mKey; }
set
{
this.mKey = value;
}
}
public override String Text
{
get
{
GoText lab = this.Label;
if (lab != null)
return lab.Text;
return null;
}
set
{
GoText lab = this.Label;
if (lab != null)
lab.Text = value;
}
}
public override RectangleF ComputeResize(RectangleF origRect, PointF newPoint, int handle, SizeF min, SizeF max, bool reshape)
{
RectangleF r = base.ComputeResize(origRect, newPoint, handle, min, max, reshape);
Pool pool = this as Pool;
foreach (GoObject obj in pool.GetEnumerator())
{
if (obj is Lane)
{
Lane lane = obj as Lane;
if (lane != null)
{
RectangleF rMin = new RectangleF();
bool any = false;
foreach (GoObject obj1 in lane.GetEnumerator())
{
if ((obj1 is ActivityProcessItem) || (obj1 is GatewayItem) || (obj1 is StartItem) || (obj1 is IntermediateItem) || (obj1 is EndItem) || (obj1 is AnnotationItem) || (obj1 is DataObjectItem))
{
if (!any)
{
rMin = obj1.Bounds;
any = true;
}
else
{
// add the object's bounding rect to this one
rMin = UnionRect(rMin, obj1.Bounds);
}
}
}
if (any)
{
r = UnionRect(r, rMin);
}
}
}
}
r.Width = Math.Max(1, (float)Math.Round(r.Width / CellGridSize)) * CellGridSize;
r.Height = Math.Max(1, (float)Math.Round(r.Height / CellGridSize)) * CellGridSize;
return r;
}
static RectangleF UnionRect(RectangleF a, RectangleF b)
{
float minx = Math.Min(a.X, b.X);
float miny = Math.Min(a.Y, b.Y);
float maxr = Math.Max(a.X + a.Width, b.X + b.Width);
float maxb = Math.Max(a.Y + a.Height, b.Y + b.Height);
return new RectangleF(minx, miny, maxr - minx, maxb - miny);
}
public override void DoResize(GoView view, RectangleF origRect, PointF newPoint, int whichHandle, GoInputState evttype, SizeF min, SizeF max)
{
base.DoResize(view, origRect, newPoint, whichHandle, evttype, new SizeF(MinSizeW, MinSizeH), max); // specify minimum resizing Size
}
protected override GoObject CreateBody()
{
AppFontSizeList = new ArrayList();
//Set default font in error case
mFont = new Font("Tahoma", 10);
mFontColor = Color.Black;
mBackColor = Color.White;
mBorderThickness = 2;
mBorderColor = Color.Black;
//Add Font Size into ArrayList
float FontSize = 7;
AppFontSizeList.Add(FontSize);
FontSize = 8;
AppFontSizeList.Add(FontSize);
FontSize = 9;
AppFontSizeList.Add(FontSize);
FontSize = 10;
AppFontSizeList.Add(FontSize);
//Create grid and Label
GoGroup boxgroup = new GoGroup();
boxgroup.Selectable = false;
boxgroup.Add(CreateLabel());
boxgroup.Add(CreateGrid());
return boxgroup;
}
//Create Grid
protected virtual GoGrid CreateGrid()
{
GoGrid grid = new GoGrid();
grid.Selectable = false;
grid.AutoRescales = true;
grid.Resizable = true;
grid.ResizesRealtime = true;
grid.Bounds = new RectangleF(0, 0, MinSizeW, MinSizeH);
grid.SnapDrag = GoViewSnapStyle.None;
grid.SnapResize = GoViewSnapStyle.None;
grid.CellSize = new SizeF(CellGridSize, CellGridSize);
grid.Style = GoViewGridStyle.None;
grid.Pen = new Pen(Color.Black, 2);
grid.BrushColor = mBackColor;
return grid;
}
private void ConfigurePoolLabel()
{
this.Label.Text = rm.GetString("PROCESS_DIAGRAM_POOL_ITEM_NAME");
if (GenProcess != null)
{
//Load Configuration into controls
if (GenProcess.AppIniFile != null)
{
//---------Set Background Color---------
DevExpress.XtraEditors.ColorEdit mBackColorEdit = new DevExpress.XtraEditors.ColorEdit();
mBackColorEdit.Text = GenProcess.AppIniFile.ReadString("ProcessDiagramDefaultConfig", "PDPoolBackgroundColor", "White");
if (mBackColorEdit.Text == "")
{
this.Label.BackgroundColor = mBackColor;
}
else
{
this.Label.BackgroundColor = mBackColorEdit.Color;
}
//---------Set Font Color---------
DevExpress.XtraEditors.ColorEdit mColorEdit = new DevExpress.XtraEditors.ColorEdit();
mColorEdit.Text = GenProcess.AppIniFile.ReadString("ProcessDiagramDefaultConfig", "PDPoolFontColor", "Black");
if (mColorEdit.Text == "")
{
this.Label.TextColor = mFontColor;
}
else
{
this.Label.TextColor = mColorEdit.Color;
}
//----------Set Font Size and Font Name--------------
int FontSizeIdx = GenProcess.AppIniFile.ReadInteger("ProcessDiagramDefaultConfig", "PDPoolFontSize", 3);
//Check if user changed ini file with a incorrect index
if (FontSizeIdx == -1)
{
FontSizeIdx = 3;
}
float mFontSize = (float)AppFontSizeList[FontSizeIdx];
//Set Font Name
DevExpress.XtraEditors.FontEdit mFontEdit = new DevExpress.XtraEditors.FontEdit();
mFontEdit.Text = GenProcess.AppIniFile.ReadString("ProcessDiagramDefaultConfig", "PDPoolFontName", "Tahoma");
Font testFont = new Font(mFontEdit.EditValue.ToString(), 10f);
if (testFont.Name != mFontEdit.EditValue.ToString())
{
this.Label.Font = mFont;
}
else
{
this.Label.Font = new Font(mFontEdit.Font.Name, mFontSize);
}
}
else
{
this.Label.Font = mFont;
this.Label.TextColor = mFontColor;
this.Label.BackgroundColor = mBackColor;
}
}
else
{
this.Label.Font = mFont;
this.Label.TextColor = mFontColor;
this.Label.BackgroundColor = mBackColor;
}
}
private void ConfigurePoolGrid()
{
//Configure item based on IniFile properties
if (GenProcess != null)
{
//Load Configuration into controls
if (GenProcess.AppIniFile != null)
{
//---------Set Border Color and border Thickness ---------
DevExpress.XtraEditors.ColorEdit mBorderColorEdit = new DevExpress.XtraEditors.ColorEdit();
mBorderColorEdit.Text = GenProcess.AppIniFile.ReadString("ProcessDiagramDefaultConfig", "PDPoolBorderColor", "Black");
int BorderThick = GenProcess.AppIniFile.ReadInteger("ProcessDiagramDefaultConfig", "PDPoolBorderThickness", 2);
if ((BorderThick == 0) || (BorderThick >= 11))
{
BorderThick = 2;
}
if (mBorderColorEdit.Text == "")
{
this.Port.Pen = new Pen(mBorderColor, BorderThick);
this.Grid.Pen = new Pen(mBorderColor, BorderThick);
}
else
{
this.Port.Pen = new Pen(mBorderColorEdit.Color, BorderThick);
this.Grid.Pen = new Pen(mBorderColorEdit.Color, BorderThick);
}
//---------Set Background Color---------
DevExpress.XtraEditors.ColorEdit mBackColorEdit = new DevExpress.XtraEditors.ColorEdit();
mBackColorEdit.Text = GenProcess.AppIniFile.ReadString("ProcessDiagramDefaultConfig", "PDPoolBackgroundColor", "White");
if (mBackColorEdit.Text == "")
{
this.Grid.BrushColor = Color.White;
}
else
{
this.Grid.BrushColor = mBackColorEdit.Color;
}
}
else
{
this.Grid.BrushColor = Color.White;
this.Port.Pen = new Pen(mBorderColor, mBorderThickness);
this.Grid.Pen = new Pen(mBorderColor, mBorderThickness);
}
}
else
{
this.Grid.BrushColor = Color.White;
this.Port.Pen = new Pen(mBorderColor, mBorderThickness);
this.Grid.Pen = new Pen(mBorderColor, mBorderThickness);
}
}
//Create label
protected virtual RotatedTextHolder CreateLabel()
{
RotatedTextHolder holder = new RotatedTextHolder();
//Label Left Side
RotatedText label = holder[0] as RotatedText;
label.Multiline = true;
label.Editable = true;
label.FontSize = 11;
label.TransparentBackground = false;
label.BackgroundColor = mBackColor;
label.Bordered = false;
label.AutoResizes = false;
label.StringTrimming = StringTrimming.EllipsisCharacter;
label.Alignment = Middle;
label.Angle = 270;
return holder;
}
//Get Label
public override GoText Label
{
get
{
RotatedTextHolder holder = this.TextHolder as RotatedTextHolder;
if (holder == null) return null;
foreach (GoObject o in holder)
{
if (o is RotatedText) return o as GoText;
}
return null;
}
}
//Get Label Holder
public virtual RotatedTextHolder TextHolder
{
get
{
GoGroup body = this.Body as GoGroup;
if (body == null) return null;
foreach (GoObject o in body)
{
if (o is RotatedTextHolder) return o as RotatedTextHolder;
}
return null;
}
}
//Get Grid
public virtual GoGrid Grid
{
get
{
GoGroup body = this.Body as GoGroup;
if (body == null) return null;
foreach (GoObject o in body)
{
if (o is GoGrid) return o as GoGrid;
}
return null;
}
}
//Object layout changed
public override void LayoutChildren(GoObject childchanged)
{
if (this.Count >= 2 && !Initializing)
{
GoGrid grid = this.Grid;
GoText label = this.Label;
if (grid != null && label != null)
{
label.Width = grid.Height;
PointF center = grid.GetSpotLocation(MiddleLeft) - new SizeF(label.Height / 2 + 1, 0);
label.Center = center;
}
//Adjust pool size after add and remove Lanes...
if (this.Count > 2)
{
//if ((childchanged is Lane)) //&& (childchanged.BeingRemoved)
//{
//Define new POol Heigh
RectangleF rectPool = this.Grid.Bounds;
Lane mLaneItem = (Lane)this[2];
rectPool.Height = (this.Count - 2) * mLaneItem.Grid.Height;
RectangleF newpollrect = new RectangleF(rectPool.X, rectPool.Y, rectPool.Width, rectPool.Height);
this.Grid.Bounds = newpollrect;
RectangleF rectLane = mLaneItem.Grid.Bounds;
for (int i = 2; i < this.Count; i++)
{
Lane LaneItem = (Lane)this<em>;
if (i == 2)
{
RectangleF newrect1 = new RectangleF(rectPool.X + this.Label.Height + 2, rectPool.Y, rectPool.Width - this.Label.Height, mLaneItem.Grid.Height);
LaneItem.Grid.Bounds = newrect1;
}
else
{
RectangleF newrect2 = new RectangleF(rectPool.X + this.Label.Height + 2, rectLane.Y + ((i - 2) * LaneItem.Grid.Height), rectPool.Width - this.Label.Height, mLaneItem.Grid.Height);
LaneItem.Grid.Bounds = newrect2;
}
}
//}
}
}
base.LayoutChildren(childchanged);
}
}