/// <summary> /// Updates the result panel and its contents. /// </summary> public void updateSize() { //Resultlist if (content is ResultList) { ResultList temp = content as ResultList; temp.setSize(this.Width, this.Height); } //Info display else if (content is InfoDisplay) { InfoDisplay temp = content as InfoDisplay; temp.setSize(this.Width, this.Height); } //News reader else if (content is NewsReader) { NewsReader temp = content as NewsReader; temp.setSize(this.Width, this.Height); } //Integrated news list else if (content is IntegratedNewsList) { IntegratedNewsList temp = content as IntegratedNewsList; temp.setSize(this.Width, this.Height); } //Sets size of result panel content.Width = this.Width; content.Height = this.Height; }
JsonHandler js; //Json handler /// <summary> /// Displays information about a stock. /// </summary> /// <param name="type"></param> /// <param name="s"></param> /// <param name="m"></param> public InfoDisplay(String type, String s, String m) { //Set generic width of mercury buttons buttonWidth = 120; buttonHeight = 30; js = new JsonHandler(); chartPanel = new Panel(); //Initialize controller class c = new Controller(); symbol = s; market = m; //Check if type is a stock or market typeOfStock = type; if (typeOfStock == "stock") { stockList = js.getSingleStock(market, symbol, "month"); } //Type is market, create dummy stocks from market values else if (typeOfStock == "market") { //Markets can't be added to portfolio portfolioCompatible = false; //Empty stock list stockList = new List <Stock>(); List <Market> marketList = js.getSingleMarket(market, "month"); foreach (Market temp in marketList) { //Assign stock from current market value Stock tempStock = new Stock(); tempStock.Symbol = temp.MarketName; tempStock.Latest = temp.Latest; tempStock.OpenVal = temp.OpenVal; tempStock.Updated = temp.Updated; tempStock.Volume = "-"; stockList.Add(tempStock); } } stockList = checkStock(stockList); stockList = c.sortStockList(stockList, "Updated", false); Padding = new Padding(5, 3, 5, 3); this.BackColor = c.highlightWhite; //Get latest stock info Stock info = stockList.ElementAt(stockList.Count - 1); //Initialize panels chartTypePanel = new FlowLayoutPanel(); timeSpanPanel = new FlowLayoutPanel(); centerChartType = new FlowLayoutPanel(); centerTimeSpan = new FlowLayoutPanel(); timeSpanFiller = new Panel(); chartTypeFiller = new Panel(); stockInfoPanel = new FlowLayoutPanel(); //Create and add chart type buttons and listeners for charts //Candlestick candlestickButton = new MercuryButton("Candlestick", "candlestick"); candlestickButton.Click += new EventHandler(chooseChartType); candlestickButton.Width = buttonWidth; candlestickButton.Height = buttonHeight; //Line chart (Latest) lineChartButton = new MercuryButton("Latest", "line"); lineChartButton.Click += new EventHandler(chooseChartType); lineChartButton.Width = buttonWidth; lineChartButton.Height = buttonHeight; //Bar chart (Change) barChartButton = new MercuryButton("Change", "bar"); barChartButton.Click += new EventHandler(chooseChartType); barChartButton.Width = buttonWidth; barChartButton.Height = buttonHeight; //Add chart type buttons to panel chartTypePanel.Controls.Add(lineChartButton); chartTypePanel.Controls.Add(candlestickButton); chartTypePanel.Controls.Add(barChartButton); //Add button and event listener to control timespan value dayButton = new MercuryButton("Day", "day"); dayButton.Click += new EventHandler(chooseTimeSpan); dayButton.Width = buttonWidth; dayButton.Height = buttonHeight; weekButton = new MercuryButton("Week", "week"); weekButton.Click += new EventHandler(chooseTimeSpan); weekButton.Width = buttonWidth; weekButton.Height = buttonHeight; monthButton = new MercuryButton("Month", "month"); monthButton.Click += new EventHandler(chooseTimeSpan); monthButton.Width = buttonWidth; monthButton.Height = buttonHeight; //Add timespan buttons to panel timeSpanPanel.Controls.Add(monthButton); timeSpanPanel.Controls.Add(weekButton); timeSpanPanel.Controls.Add(dayButton); //Add stock control panel to display this.Controls.Add(stockInfoPanel); //Initialize labels containing stock info stockInfoLabel = new Label(); stockNameLabel = new Label(); stockInfoLabel.Height = 30; stockNameLabel.Height = 30; stockInfoLabel.Margin = new Padding(0, 1, 0, 1); stockNameLabel.Margin = new Padding(0, 1, 0, 1); stockInfoPanel.Padding = new Padding(0, 1, 0, 1); //Initialize stock name String stockName = ""; /* * If the info panel displays market info, set the name * of the market based on the symbol. */ switch (info.Symbol) { case "LSE": stockName = "London Stock Exchange"; break; case "OMX": stockName = "Stockholm Stock Exchange"; break; case "NYSE": stockName = "New York Stock Exchange"; break; default: stockName = info.Name; break; } //Initialize new tooltip ToolTip tt = new ToolTip(); /* * Set text of first label. * - Latest * - Opening value * - Change (percent) * - Volume */ stockInfoLabel.Text = "Latest: " + info.Latest + " | Opening: " + info.OpenVal + " | Change: " + info.Percent + " | Volume: " + info.Volume; //Add tooltip to stock info label tt.SetToolTip(stockInfoLabel, stockInfoLabel.Text); //Set label to name and symbol of stock stockNameLabel.Text = stockName + " | " + info.Symbol; //Set font of info labels stockInfoLabel.Font = c.mercuryFont; stockNameLabel.Font = new Font("Segoe UI", 12, FontStyle.Regular); //Add labels to panel stockInfoPanel.Controls.Add(stockNameLabel); stockInfoPanel.Controls.Add(stockInfoLabel); //Add button for adding stocks to portfolio MercuryButton portfolio = new MercuryButton("Add to portfolio", info.Symbol); portfolio.Width = 170; portfolio.Height = 30; //Disable portfolio if current type is market if (!portfolioCompatible) { portfolio.Enabled = false; portfolio.BackColor = Color.LightGray; } //Add listener to portfolio button portfolio.Click += new EventHandler(addStockToPortfolio); //Add portfolio button to panel stockInfoPanel.Controls.Add(portfolio); //Add panels to info display this.Controls.Add(chartPanel); this.Controls.Add(centerChartType); //Add chart type and filler centerChartType.Controls.Add(chartTypeFiller); centerChartType.Controls.Add(chartTypePanel); //Add panel that centers time span buttons this.Controls.Add(centerTimeSpan); //Add time span and filler panel centerTimeSpan.Controls.Add(timeSpanFiller); centerTimeSpan.Controls.Add(timeSpanPanel); //Set all chart buttons to unclicked resetchartButtons(); //Set all time span buttons to unclicked resetTimeSpanButtons(); //Initialize new chart initilizeChart(typeOfChart, timeSpan); //Set line chart button to clicked lineChartButton.BackColor = c.mercuryBlue; //Set month button to clicked monthButton.BackColor = c.mercuryBlue; //Initliaze new integrated news list news = new IntegratedNewsList(symbol, m); //Set background color of news list news.BackColor = c.highlightWhite; //Assign news panel to news list newsPanel = news; //Add news panel to info display this.Controls.Add(newsPanel); }