Пример #1
0
		Image CreatePreviewImage(string s1,string s2)
		{
			int height = 80;
			int width = 530;
			int space = 2;
			int size = 30;
			int leftSpan = 15;
			int topSpan = 5;
			SquareLine squareLineLa;
			SquareLine squareLineLb;

			ArrayList squareArrayLa = new ArrayList();
			ArrayList squareArrayLb = new ArrayList();
			IGlyph glyph;
			for(int i=0;i<s1.Length;i++)
			{
				glyph = new Square(leftSpan + i*(size + space),topSpan,size,Color.DarkCyan,GlyphAppearance.Flat,s1[i].ToString());
				squareArrayLa.Add(glyph);
			}
			for(int i=0;i<s2.Length;i++)
			{
				glyph = new Square(leftSpan + i*(size + space),topSpan + size + 2,size,Color.DarkCyan,GlyphAppearance.Flat,s2[i].ToString());
				squareArrayLb.Add(glyph);
			}

			squareLineLa = new SquareLine(1,1,1,squareArrayLa);
			squareLineLb = new SquareLine(1,1,1,squareArrayLb);

			IIterator arrayIteratorLa = squareLineLa.CreateIterator();
			IIterator arrayIteratorLb = squareLineLb.CreateIterator();

			Bitmap bmp = new Bitmap(width,height);
			Graphics g = Graphics.FromImage(bmp);

			if(arrayIteratorLa != null)
			{
				for(IIterator iterator = arrayIteratorLa.First();!arrayIteratorLa.IsDone();iterator = arrayIteratorLa.Next())
				{
					iterator.CurrentItem.Draw(g);
				}
			}

			if(arrayIteratorLb != null)
			{
				for(IIterator iterator = arrayIteratorLb.First();!arrayIteratorLb.IsDone();iterator = arrayIteratorLb.Next())
				{
					iterator.CurrentItem.Draw(g);
				}
			}

			return bmp;

		}
Пример #2
0
		Image CreatePreviewImage(string s,string t,int pos)
		{
			int height = 80;
			int width = 530;
			int space = 2;
			int size = 30;
			int leftSpan = 15;
			int topSpan = 3;

			SquareLine squareLineS;
			SquareLine squareLineT;

			ArrayList squareArrayS = new ArrayList();
			ArrayList squareArrayT = new ArrayList();
			IGlyph glyph;
			for(int i=0;i<s.Length;i++)
			{
				glyph = new Square(leftSpan + i*(size + space),topSpan,size,SystemColors.InactiveBorder,GlyphAppearance.Popup,s[i].ToString());
				squareArrayS.Add(glyph);
			}
			int startX = ((IGlyph)squareArrayS[pos - 1]).Bounds.X;
			for(int i=0;i<t.Length;i++)
			{
				glyph = new Square(startX + i*(size + space),topSpan + size + 2,size,SystemColors.InactiveBorder,GlyphAppearance.Popup,t[i].ToString());
				squareArrayT.Add(glyph);
			}
			squareLineS = new SquareLine(0,0,1,squareArrayS);
			squareLineT = new SquareLine(0,0,1,squareArrayT);
			//最后初始化所有的迭代器
			IIterator arrayIteratorS = squareLineS.CreateIterator();
			IIterator arrayIteratorT = squareLineT.CreateIterator();

			Bitmap bmp = new Bitmap(width,height);
			Graphics g = Graphics.FromImage(bmp);

			for(IIterator iterator = arrayIteratorS.First();!arrayIteratorS.IsDone();iterator = arrayIteratorS.Next())
			{
				iterator.CurrentItem.Draw(g);
			}
			for(IIterator iterator = arrayIteratorT.First();!arrayIteratorT.IsDone();iterator = arrayIteratorT.Next())
			{
				iterator.CurrentItem.Draw(g);
			}

			return bmp;

		}
Пример #3
0
		Image CreatePreviewImage(string s,int pos,char c)
		{
			int height = 80;
			int width = 530;
			int space = 2;
			int size = 35;
			int leftSpan = 15;
			int topSpan = 40;
			ArrayList squareArray = new ArrayList();
			IGlyph glyph;
			for(int i=0;i<s.Length;i++)
			{
				glyph = new Square(leftSpan + i*(size + space),topSpan,size,Color.HotPink,GlyphAppearance.Flat,s[i].ToString());
				squareArray.Add(glyph);
			}
			SquareLine squareLine = new SquareLine(1,1,1,squareArray);

			Rectangle rec = new Rectangle(0,0,0,0);
			if(pos >= 1 && pos <= s.Length)
			{
				rec = ((IGlyph)squareArray[pos-1]).Bounds;
			}
			else if(pos == s.Length + 1)
			{
				Rectangle lastRectangle = ((IGlyph)squareArray[pos-2]).Bounds;
				rec = new Rectangle(lastRectangle.X + lastRectangle.Width + space,lastRectangle.Y - lastRectangle.Height,lastRectangle.Width,lastRectangle.Height);
			}
			Square insertSquare = new Square(rec.X,topSpan - size - 2,rec.Width,Color.Green,GlyphAppearance.Flat,c.ToString());

			//最后初始化所有的迭代器
			IIterator arrayIterator = squareLine.CreateIterator();
			IIterator nullIterator = insertSquare.CreateIterator();

			Bitmap bmp = new Bitmap(width,height);
			Graphics g = Graphics.FromImage(bmp);

			for(IIterator iterator = arrayIterator.First();!arrayIterator.IsDone();iterator = arrayIterator.Next())
			{
				iterator.CurrentItem.Draw(g);
			}
			nullIterator.CurrentItem.Draw(g);

			return bmp;

		}
Пример #4
0
		Image CreatePreviewImage(string r,char key)
		{
			int height = 80;
			int width = 530;
			int space = 2;
			int size = 29;
			int leftSpan = 5;
			int topSpan = 5;

			ArrayList squareArray = new ArrayList();
			IGlyph glyph;
			glyph = new Square(leftSpan,topSpan + size + 2,size,Color.HotPink,GlyphAppearance.Flat,"?");
			squareArray.Add(glyph);
			for(int i=0;i<r.Length;i++)
			{
				glyph = new Square(leftSpan + (i + 1)*(size + space),topSpan + size + 2,size,Color.Teal,GlyphAppearance.Flat,r[i].ToString());
				squareArray.Add(glyph);
			}
			squareLine = new SquareLine(0,0,1,squareArray);

			//最后初始化所有的迭代器
			IIterator arrayIterator = squareLine.CreateIterator();
			
			IIterator nullIterator = null;
			glyph = ((ArrayIterator)arrayIterator).GetGlyphByIndex((r.Length + 1) / 2);
			if(glyph != null)
			{
				nullIterator = new Square(glyph.Bounds.X,glyph.Bounds.Y - size - 2,size,Color.Red,GlyphAppearance.Flat,key.ToString()).CreateIterator();
			}

			Bitmap bmp = new Bitmap(width,height);
			Graphics g = Graphics.FromImage(bmp);

			for(IIterator iterator = arrayIterator.First();!arrayIterator.IsDone();iterator = arrayIterator.Next())
			{
				iterator.CurrentItem.Draw(g);
			}
			if(nullIterator != null)
			{
				nullIterator.CurrentItem.Draw(g);
			}

			return bmp;

		}
Пример #5
0
		Image CreatePreviewImage(string s,int pos)
		{
			int height = 80;
			int width = 530;
			int space = 2;
			int size = 35;
			int leftSpan = 15;
			int topSpan = 20;
			ArrayList squareArray = new ArrayList();
			IGlyph glyph;
			for(int i = 0;i < s.Length;i++)
			{
				if(pos - 1 != i)
				{
					glyph = new Square(leftSpan + i*(size + space),topSpan,size,Color.DarkCyan,GlyphAppearance.Flat,s[i].ToString());
				
				}
				else  //用红色表示要删除的元素
				{
					glyph = new Square(leftSpan + i*(size + space),topSpan,size,Color.Red,GlyphAppearance.Flat,s[i].ToString());				
				}
				squareArray.Add(glyph);
			}
			squareLine = new SquareLine(1,1,1,squareArray);

			IIterator arrayIterator = squareLine.CreateIterator();

			Bitmap bmp = new Bitmap(width,height);
			Graphics g = Graphics.FromImage(bmp);

			for(IIterator iterator = arrayIterator.First();!arrayIterator.IsDone();iterator = arrayIterator.Next())
			{
				iterator.CurrentItem.Draw(g);
			}

			return bmp;

		}
Пример #6
0
		public override void ExecuteAndUpdateCurrentLine()
		{
			switch (CurrentLine)
			{
				case 0:
					CurrentLine = 4;
					return;
				case 4:
					//判断IF语句是否成立,如果成立,CurrentLine = 5;不成立,CurrentLine = 8;
					if(status.I >=1 && status.I <= status.Length + 1)
					{
						CurrentLine = 8;
						return;
					}
					break;
				case 8:
					//判断for语句条件是否成立,如果成立,CurrentLine = 9;不成立,CurrentLine = 11;
					if(status.J < status.I -1)
					{
						CurrentLine = 11;
						return;
					}
					break;
				case 9:
					//移动一个图形元素.
					IGlyph tempGlyph = ((ArrayIterator)arrayIterator).GetGlyphByIndex(status.J);
					IGlyph tempGlyph1 = new Square(tempGlyph.Bounds.X + tempGlyph.Bounds.Width + squareSpace,tempGlyph.Bounds.Y,squareSize,status.图形背景色,status.图形外观,((Square)tempGlyph).Text);
					((ArrayIterator)arrayIterator).MoveGlyphHorizon(status.J,tempGlyph1,1);
					string c = status.L[status.J].ToString();
					status.CanEdit = true;
					status.L = status.L.Remove(status.J + 1,1);
					status.CanEdit = true;
					status.L = status.L.Insert(status.J,c);
					status.CanEdit = true;
					status.J--;
					CurrentLine = 8;

					return;
				case 11:
					//插入元素.
					((ArrayIterator)arrayIterator).MoveGlyphVertical(nullIterator.CurrentItem,nullIterator.CurrentItem.Bounds.Y + nullIterator.CurrentItem.Bounds.Height + 10);
					status.CanEdit = true;
					status.L = status.L.Remove(status.I - 1,1);
					status.CanEdit = true;
					status.L = status.L.Insert(status.I - 1,status.E.ToString());
					break;
				case 12:
					status.CanEdit = true;
					status.Length++;
					CurrentLine = 14;
					return;
				case 14:
					return;
			}
			CurrentLine++;

		}
Пример #7
0
		public override void InitGraph() 
		{
			SquareLine squareLine;
			Square insertSquare;
			ArrayList squareArray = new ArrayList();
			IGlyph glyph;
			for(int i=0;i<status.Length;i++)
			{
				glyph = new Square(40 + i*(squareSize + squareSpace),20 + squareSize + 10,squareSize,status.图形背景色,status.图形外观,status.L[i].ToString());
				squareArray.Add(glyph);
			}
			//最后再添加一个额外的元素,以保存插入元素后的数组的最后一个元素
			squareArray.Add(new Square(1,1,2,Color.Transparent,""));
			squareLine = new SquareLine(20,80,status.Length*(squareSize+20+10),squareArray);

			Rectangle rec = new Rectangle(0,0,0,0);
			if(status.I >= 1 && status.I <= status.Length)
			{
				rec = ((IGlyph)squareArray[status.I-1]).Bounds;
			}
			else if(status.I == status.Length + 1)
			{
				Rectangle lastRectangle = ((IGlyph)squareArray[status.I-2]).Bounds;
				rec = new Rectangle(lastRectangle.X + lastRectangle.Width + squareSpace,lastRectangle.Y - 10 - lastRectangle.Height,lastRectangle.Width,lastRectangle.Height);
			}
			insertSquare = new Square(rec.X,20,rec.Width,status.插入元素背景色,status.图形外观,status.E.ToString());

			//最后初始化所有的迭代器
			arrayIterator = squareLine.CreateIterator();
			nullIterator = insertSquare.CreateIterator();

		}
Пример #8
0
		public override void InitGraph() 
		{
			ArrayList squareArray = new ArrayList();
			IGlyph glyph;
			glyph = new Square(40,20 + squareSize + 10,squareSize,status.头元素颜色,status.图形外观,"?");
			squareArray.Add(glyph);
			for(int i=0;i<status.N;i++)
			{
				glyph = new Square(40 + (i + 1)*(squareSize + squareSpace),20 + squareSize + 10,squareSize,status.线性表颜色,status.图形外观,status.R[i].ToString());
				squareArray.Add(glyph);
			}
			squareLine = new SquareLine(20,80,(status.N + 1)*(squareSize+20+10),squareArray);

			arrayIterator = squareLine.CreateIterator();

			glyph = ((ArrayIterator)arrayIterator).GetGlyphByIndex((status.N + 1) / 2);
			if(glyph != null)
			{
				nullIterator = new Square(glyph.Bounds.X,glyph.Bounds.Y - squareSize - 10,squareSize,status.当前元素颜色,status.图形外观,status.Key.ToString()).CreateIterator();
			}

		}
Пример #9
0
		public override void InitGraph() 
		{
			SquareLine squareLineS;
			SquareLine squareLineT;

			ArrayList squareArrayS = new ArrayList();
			ArrayList squareArrayT = new ArrayList();
			IGlyph glyph;
			for(int i=0;i<status.SLength;i++)
			{
				glyph = new Square(40 + i*(squareSize + squareSpace),40 + 5,squareSize,status.串S元素颜色,status.图形外观,status.S[i].ToString());
				squareArrayS.Add(glyph);
			}
			int startX = ((IGlyph)squareArrayS[status.Pos - 1]).Bounds.X;
			for(int i=0;i<status.TLength;i++)
			{
				glyph = new Square(startX + i*(squareSize + squareSpace),40 + squareSize + 2 * 5,squareSize,status.串T元素颜色,status.图形外观,status.T[i].ToString());
				squareArrayT.Add(glyph);
			}
			squareLineS = new SquareLine(20,30,status.SLength*(squareSize+20+10),squareArrayS);
			squareLineT = new SquareLine(20,110,status.TLength*(squareSize+20+10),squareArrayT);
			//最后初始化所有的迭代器
			arrayIteratorS = squareLineS.CreateIterator();
			arrayIteratorT = squareLineT.CreateIterator();
		}
Пример #10
0
		public override void ExecuteAndUpdateCurrentLine()
		{
			IGlyph glyphI = null;
			IGlyph glyphJ = null;
			IGlyph insertingGlyph = null;

			switch (CurrentLine)
			{
				case 0:
					//i=j=k=0;
					status.CanEdit = true;
					status.I = 0;
					status.CanEdit = true;
					status.J = 0;
					status.CanEdit = true;
					status.K = 0;
					CurrentLine = 4;
					return;
				case 5:
					//判断while(i<La.length && j<Lb.length)是否成立,如果成立,CurrentLine = 6;不成立,CurrentLine = 12;
					if(status.I >=status.LaLength || status.J >= status.LbLength)
					{
						CurrentLine = 12;
						return;
					}
					CurrentLine = 7;
					return;
				case 7:
					//判断If(La.elem[i]<=Lb.elem[j])是否成立,如果成立,CurrentLine = 8;不成立,CurrentLine = 10;
					glyphI = ((ArrayIterator)arrayIteratorLa).GetGlyphByIndex(status.I);
					glyphJ = ((ArrayIterator)arrayIteratorLb).GetGlyphByIndex(status.J);					
					if(((Square)glyphI).Text[0] > ((Square)glyphJ).Text[0])
					{
						CurrentLine = 10;
						return;
					}
					break;
				case 8:
					//Lc.elem[k++]=La.elem[i++];
					glyphI = ((ArrayIterator)arrayIteratorLa).GetGlyphByIndex(status.I);
					currentGlyph = glyphI;
					((ArrayIterator)arrayIteratorLa).SetBackColor(status.I ,status.当前元素背景色,status.图形背景色,true);
					((ArrayIterator)arrayIteratorLb).SetBackColor(-1,status.图形背景色 ,status.图形背景色,true);
					insertingGlyph = new Square(40 + k*(squareSize + squareSpace),10 + 2 * squareSize + 3 * 5,squareSize,status.当前元素背景色,glyphI.Appearance,((Square)glyphI).Text);
					((ArrayIterator)arrayIteratorLc).InsertGlyph(insertingGlyph);
					status.CanEdit = true;
					status.Lc = status.Lc.Insert(status.Lc.Length,((Square)glyphI).Text);
					status.CanEdit = true;
					status.LcLength += 1;
					k += 1;
					status.CanEdit = true;
					status.I += 1;
					status.CanEdit = true;
					status.K += 1;
					CurrentLine = 5;
					return;
				case 10:
					//Lc.elem[k++]=Lb.elem[j++];
					glyphJ = ((ArrayIterator)arrayIteratorLb).GetGlyphByIndex(status.J);
					currentGlyph = glyphJ;
					((ArrayIterator)arrayIteratorLb).SetBackColor(status.J,status.当前元素背景色 ,status.图形背景色,true);
					((ArrayIterator)arrayIteratorLa).SetBackColor(-1,status.图形背景色 ,status.图形背景色,true);
					insertingGlyph = new Square(40 + k*(squareSize + squareSpace),10 + 2 * squareSize + 3 * 5,squareSize,status.当前元素背景色,glyphJ.Appearance,((Square)glyphJ).Text);
					((ArrayIterator)arrayIteratorLc).InsertGlyph(insertingGlyph);
					status.CanEdit = true;
					status.Lc = status.Lc.Insert(status.Lc.Length,((Square)glyphJ).Text);
					status.CanEdit = true;
					status.LcLength += 1;
					k += 1;
					status.CanEdit = true;
					status.J += 1;
					status.CanEdit = true;
					status.K += 1;
					CurrentLine = 5;
					return;
				case 12:
					//判断While(i<La.length)是否成立
					if(status.I >=status.LaLength)
					{
						CurrentLine = 14;
						return;
					}
					break;
				case 13:
					//Lc.elem[k++]=La.elem[i++];
					glyphI = ((ArrayIterator)arrayIteratorLa).GetGlyphByIndex(status.I);
					currentGlyph = glyphI;
					((ArrayIterator)arrayIteratorLa).SetBackColor(status.I,status.当前元素背景色 ,status.图形背景色,true);
					((ArrayIterator)arrayIteratorLb).SetBackColor(-1,status.图形背景色 ,status.图形背景色,true);
					insertingGlyph = new Square(40 + k*(squareSize + squareSpace),10 + 2 * squareSize + 3 * 5,squareSize,status.当前元素背景色,glyphI.Appearance,((Square)glyphI).Text);
					((ArrayIterator)arrayIteratorLc).InsertGlyph(insertingGlyph);
					status.CanEdit = true;
					status.Lc = status.Lc.Insert(status.Lc.Length,((Square)glyphI).Text);
					status.CanEdit = true;
					status.LcLength += 1;
					k += 1;
					status.CanEdit = true;
					status.I += 1;
					status.CanEdit = true;
					status.K += 1;
					CurrentLine = 12;
					return;
				case 14:
					//判断While(j<Lb.length)是否成立
					if(status.J >=status.LbLength)
					{
						CurrentLine = 16;
						return;
					}
					break;
				case 15:
					//Lc.elem[k++]=Lb.elem[j++];
					glyphJ = ((ArrayIterator)arrayIteratorLb).GetGlyphByIndex(status.J);
					currentGlyph = glyphJ;
					((ArrayIterator)arrayIteratorLb).SetBackColor(status.J ,status.当前元素背景色,status.图形背景色,true);
					((ArrayIterator)arrayIteratorLa).SetBackColor(-1,status.图形背景色 ,status.图形背景色,true);
					insertingGlyph = new Square(40 + k*(squareSize + squareSpace),10 + 2 * squareSize + 3 * 5,squareSize,status.当前元素背景色,glyphJ.Appearance,((Square)glyphJ).Text);
					((ArrayIterator)arrayIteratorLc).InsertGlyph(insertingGlyph);
					status.CanEdit = true;
					status.Lc = status.Lc.Insert(status.Lc.Length,((Square)glyphJ).Text);
					status.CanEdit = true;
					status.LcLength += 1;
					k += 1;
					status.CanEdit = true;
					status.J += 1;
					status.CanEdit = true;
					status.K += 1;
					CurrentLine = 14;
					return;
				case 16:
					//Lc.length=k;
					status.LcLength = status.K;
					break;
				case 17:
					return;
			}
			CurrentLine++;
		}
Пример #11
0
		public override void InitGraph() 
		{
			SquareLine squareLineLa;
			SquareLine squareLineLb;
			SquareLine squareLineLc;

			ArrayList squareArrayLa = new ArrayList();
			ArrayList squareArrayLb = new ArrayList();
			ArrayList squareArrayLc = new ArrayList();
			IGlyph glyph;
			for(int i=0;i<status.LaLength;i++)
			{
				glyph = new Square(40 + i*(squareSize + squareSpace),10 + 5,squareSize,status.图形背景色,status.图形外观,status.La[i].ToString());
				squareArrayLa.Add(glyph);
			}
			for(int i=0;i<status.LbLength;i++)
			{
				glyph = new Square(40 + i*(squareSize + squareSpace),10 + squareSize + 2 * 5,squareSize,status.图形背景色,status.图形外观,status.Lb[i].ToString());
				squareArrayLb.Add(glyph);
			}

			squareLineLa = new SquareLine(20,30,status.LaLength*(squareSize+20+10),squareArrayLa);
			squareLineLb = new SquareLine(20,110,status.LbLength*(squareSize+20+10),squareArrayLb);
			squareLineLc = new SquareLine(20,190,status.LaLength*(squareSize+20+10) + status.LbLength*(squareSize+20+10),squareArrayLc);
			//最后初始化所有的迭代器
			arrayIteratorLa = squareLineLa.CreateIterator();
			arrayIteratorLb = squareLineLb.CreateIterator();
			arrayIteratorLc = squareLineLc.CreateIterator();

		}
Пример #12
0
		public override void ExecuteAndUpdateCurrentLine()
		{
			switch (CurrentLine)
			{
				case 0:
					CurrentLine = 3;
					return;
				case 3:
					CurrentLine = 6;
					return;
				case 6:
					IGlyph glyph1 = ((ArrayIterator)arrayIterator).GetGlyphByIndex(status.I-1);
					status.CanEdit = true;
					status.E = ((Square)glyph1).Text;
					break;
				case 7:
					//判断for语句条件是否成立,如果成立,CurrentLine = 8;不成立,CurrentLine = 10;
					if(status.J > status.Length -1)
					{
						CurrentLine = 10;
						return;
					}
					break;
				case 8:
					//移动一个图形元素.
					movedGlyphs.Add(((ArrayIterator)arrayIterator).GetGlyphByIndex(status.J));
					IGlyph tempGlyph = ((ArrayIterator)arrayIterator).GetGlyphByIndex(status.J);
					IGlyph tempGlyph1 = new Square(tempGlyph.Bounds.X - tempGlyph.Bounds.Width - squareSpace,tempGlyph.Bounds.Y,squareSize,status.图形背景色,status.图形外观,((Square)tempGlyph).Text);
					((ArrayIterator)arrayIterator).MoveGlyphHorizon(status.J,tempGlyph1,0);
					string c = status.L[status.J].ToString();
					status.CanEdit = true;
					status.L = status.L.Remove(status.J - 1,1);
					status.CanEdit = true;
					status.L = status.L.Insert(status.J - 1,c);
					status.CanEdit = true;
					status.J++;
					CurrentLine = 7;
					return;
				case 10:
					//线性表长度减1
					status.CanEdit = true;
					status.Length--;
					status.CanEdit = true;
					status.L = status.L.Remove(status.Length,1);
					//删除最后一个结点
					((ArrayIterator)arrayIterator).DeleteGlyph(status.Length);
					break;
				case 11:
					return;
					
			}
			CurrentLine++;

		}
Пример #13
0
		public override void InitGraph() 
		{
			ArrayList squareArray = new ArrayList();
			IGlyph glyph;
			for(int i=0;i<status.Length;i++)
			{
				if(status.I-1 != i)
				{
					glyph = new Square(40 + i*(squareSize + squareSpace),40,squareSize,status.图形背景色,status.图形外观,status.L[i].ToString());
				
				}
				else  //用红色表示要删除的元素
				{
					glyph = new Square(40 + i*(squareSize + squareSpace),40,squareSize,status.删除元素背景色,status.图形外观,status.L[i].ToString());
				}
				squareArray.Add(glyph);
			}
			squareLine = new SquareLine(20,80,status.Length*(squareSize+20+10),squareArray);

			arrayIterator = squareLine.CreateIterator();

		}