-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Заколюкин Степан #208
Open
StepanZakolukin
wants to merge
14
commits into
kontur-courses:master
Choose a base branch
from
StepanZakolukin:dealing-with-exceptions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Заколюкин Степан #208
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d16e31e
Добавил все необходимые проекты с прошлой задачи
StepanZakolukin 22cbd2d
Перенес реализацию Result<T> из задания, выполненого на паре
StepanZakolukin 7c7e953
Избавился от исключений в реализации библиотеки TagCloud с помощью па…
StepanZakolukin ffb7108
Переписал блок настроек TagCloud и применил соответствующие изменения…
StepanZakolukin f88693e
Исправил ошибку. Добавил проекты не ссылками на существующие, а копиями
StepanZakolukin 682ae1e
Вытащил тесты на настройку шрифта в отдельный файл и добавил новые тесты
StepanZakolukin 608710a
Выделил тесты на настройку коэффициента сжатия облака в отдельный кла…
StepanZakolukin e7d8f4f
Добавил дополнительные тесты на настройку шрифта
StepanZakolukin 8b71def
Выделил тесты на натройку размера изоображения в отдельный файл
StepanZakolukin 0ecc242
Вынес логику генерации тестовых данных в отдельный класс
StepanZakolukin f84c3cf
Поменял абсолютные пути в файле проекта на относительные
StepanZakolukin d3ffbc9
Удалил лишние строки из файла тестового проекта
StepanZakolukin 325268c
Поменял абсолютный путь на относительный и удлил лишние строки в файл…
StepanZakolukin 62e6187
Влил состояние из другой ветки
StepanZakolukin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace ErrorHandling; | ||
|
||
public readonly struct ActionStatus(string error) | ||
{ | ||
public string Error { get; } = error; | ||
public bool IsSuccess => Error == null; | ||
|
||
public static ActionStatus Ok() | ||
{ | ||
return new ActionStatus(null); | ||
} | ||
|
||
public static ActionStatus Fail(string e) | ||
{ | ||
return new ActionStatus(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace TagCloudGUI.Controls; | ||
|
||
public class DropdownList : TagCloudTableLayoutPanel | ||
{ | ||
private readonly TagCloudLabel _heading; | ||
public event Action<object?, EventArgs>? TextHasBeenChanged; | ||
public string SelectedText { get; private set; } | ||
protected readonly TagCloudConfigurationForm ParentForm; | ||
public readonly ErrorInformation ErrorMessage = new(); | ||
|
||
public DropdownList(string heading, IEnumerable<string> list, TagCloudConfigurationForm parentForm) | ||
{ | ||
ParentForm = parentForm; | ||
_heading = new TagCloudLabel(heading); | ||
Margin = new Padding(0, 0, 0, 8); | ||
|
||
DropDownList.Items.AddRange(list.ToArray()); | ||
|
||
ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); | ||
RowStyles.Add(new RowStyle(SizeType.Absolute, 35)); | ||
RowStyles.Add(new RowStyle(SizeType.Absolute, 35)); | ||
RowStyles.Add(new RowStyle(SizeType.Absolute, 20)); | ||
|
||
Controls.Add(_heading, 0, 0); | ||
Controls.Add(DropDownList, 0, 1); | ||
Controls.Add(ErrorMessage, 0, 2); | ||
|
||
DropDownList.TextChanged += SelectionHasBeenChanged; | ||
} | ||
|
||
private void SelectionHasBeenChanged(object? sender, EventArgs args) | ||
{ | ||
SelectedText = DropDownList.Text; | ||
TextHasBeenChanged?.Invoke(sender, args); | ||
} | ||
|
||
protected ComboBox DropDownList { get; } = new() | ||
{ | ||
Dock = DockStyle.Fill, | ||
Margin = new Padding(0, 0, 0, 5), | ||
Padding = new Padding(0), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace TagCloudGUI.Controls; | ||
|
||
public sealed class ErrorInformation : Label | ||
{ | ||
public ErrorInformation() | ||
{ | ||
ForeColor = Color.Red; | ||
Dock = DockStyle.Fill; | ||
Margin = new Padding(0); | ||
Padding = new Padding(0); | ||
BorderStyle = BorderStyle.Fixed3D; | ||
Font = new Font(Font.FontFamily, 12, FontStyle.Bold, GraphicsUnit.Pixel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace TagCloudGUI.Controls; | ||
|
||
public sealed class TagCloudButton : Button | ||
{ | ||
public TagCloudButton() | ||
{ | ||
FlatStyle = FlatStyle.Flat; | ||
Padding = new Padding(0); | ||
Margin = new Padding(0); | ||
Height = 40; | ||
TextAlign = ContentAlignment.TopCenter; | ||
Font = new Font(Font.FontFamily, 20, FontStyle.Bold, GraphicsUnit.Pixel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace TagCloudGUI.Controls; | ||
|
||
public sealed class TagCloudLabel : Label | ||
{ | ||
public TagCloudLabel(string text) | ||
{ | ||
Text = text; | ||
Dock = DockStyle.Fill; | ||
Margin = new Padding(0, 0, 0, 5); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace TagCloudGUI.Controls; | ||
|
||
public class TagCloudTableLayoutPanel : TableLayoutPanel | ||
{ | ||
public TagCloudTableLayoutPanel() | ||
{ | ||
Dock = DockStyle.Fill; | ||
Margin = new Padding(0); | ||
Padding = new Padding(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace TagCloudGUI.Controls; | ||
|
||
public sealed class TagCloudTextBox : TextBox | ||
{ | ||
public TagCloudTextBox() | ||
{ | ||
Dock = DockStyle.Fill; | ||
TextAlign = HorizontalAlignment.Center; | ||
Margin = new Padding(0); | ||
Padding = new Padding(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace TagCloudGUI.Controls; | ||
|
||
public class TagCloudTreeView : TagCloudTableLayoutPanel | ||
{ | ||
private readonly TagCloudLabel _heading; | ||
|
||
protected readonly TreeView TreeView = new() | ||
{ | ||
Dock = DockStyle.Fill, | ||
Margin = new Padding(0), | ||
Padding = new Padding(0), | ||
BorderStyle = BorderStyle.None, | ||
CheckBoxes = true, | ||
ShowLines = false | ||
}; | ||
|
||
protected readonly TagCloudConfigurationForm ParentForm; | ||
|
||
public TagCloudTreeView(string heading, TagCloudConfigurationForm parentForm) | ||
{ | ||
Dock = DockStyle.Fill; | ||
ParentForm = parentForm; | ||
Margin = new Padding(0, 0, 0, 8); | ||
this._heading = new TagCloudLabel(heading); | ||
ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); | ||
RowStyles.Add(new RowStyle(SizeType.Absolute, 30)); | ||
RowStyles.Add(new RowStyle(SizeType.Absolute, 270)); | ||
|
||
Controls.Add(this._heading, 0, 0); | ||
Controls.Add(TreeView, 0, 1); | ||
} | ||
|
||
public IEnumerable<string> GetSelectedValues() | ||
{ | ||
for (var i = 0; i < TreeView.Nodes.Count; i++) | ||
if (TreeView.Nodes[i].Checked) | ||
yield return TreeView.Nodes[i].Text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using TagCloudGUI.Controls; | ||
|
||
namespace TagCloudGUI.Layout.FirstColumn; | ||
|
||
public class ColorSettings : DropdownList | ||
{ | ||
public ColorSettings(TagCloudConfigurationForm parentForm) : base( | ||
"Алгоритм расцветки слов:", | ||
parentForm.VisualizationProvider.Settings.ColoringAlgorithm.NamesOfColoringAlgorithms, | ||
parentForm) | ||
{ | ||
DropDownList.SelectedItem = parentForm.VisualizationProvider.Settings.ColoringAlgorithm.SelectedAlgorithm; | ||
TextHasBeenChanged += ColoringAlgorithmsIsSelected; | ||
parentForm.VisualizationProvider.Settings.ColoringAlgorithm.ValueChanged += (_, message) => | ||
{ | ||
ErrorMessage.Text = message; | ||
}; | ||
} | ||
|
||
private void ColoringAlgorithmsIsSelected(object? sender, EventArgs e) | ||
{ | ||
ParentForm.VisualizationProvider.Settings.ColoringAlgorithm.SelectedAlgorithm = SelectedText; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
TagCloud.GUI/Layout/FirstColumn/ConfiguringCloudCompressionRatio.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using TagCloud.ImageGeneration; | ||
using TagCloudGUI.Controls; | ||
|
||
namespace TagCloudGUI.Layout.FirstColumn; | ||
|
||
public class ConfiguringCloudCompressionRatio : TagCloudTableLayoutPanel | ||
{ | ||
private readonly TagCloudTextBox _coefficient = new(); | ||
|
||
private readonly TagCloudLabel _heading = new("Коэф. сжатия облака:") | ||
{ | ||
TextAlign = ContentAlignment.MiddleLeft | ||
}; | ||
|
||
private readonly ErrorInformation _errorMessage = new(); | ||
|
||
private readonly IVisualizationProvider _visualizationProvider; | ||
|
||
public ConfiguringCloudCompressionRatio(IVisualizationProvider visualizationProvider) | ||
{ | ||
_visualizationProvider = visualizationProvider; | ||
_coefficient.Text = $"{Math.Round(visualizationProvider.Settings.CompressionRatio.GetValueOrThrow(), 2)}"; | ||
_coefficient.TextChanged += CoefficientHasChanged; | ||
|
||
RowStyles.Add(new RowStyle(SizeType.Absolute, 35)); | ||
RowStyles.Add(new RowStyle(SizeType.Absolute, 20)); | ||
|
||
Controls.Add(CreateControlGrid(), 0, 0); | ||
Controls.Add(_errorMessage, 0, 1); | ||
|
||
visualizationProvider.Settings.CompressionRatio.ValueChanged += (_, message) => | ||
{ | ||
_errorMessage.Text = message; | ||
}; | ||
} | ||
|
||
private TagCloudTableLayoutPanel CreateControlGrid() | ||
{ | ||
var controlGrid = new TagCloudTableLayoutPanel | ||
{ | ||
Margin = new Padding(0, 0, 0, 5) | ||
}; | ||
|
||
controlGrid.RowStyles.Add(new RowStyle(SizeType.AutoSize)); | ||
controlGrid.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 260)); | ||
controlGrid.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 87)); | ||
controlGrid.Controls.Add(_heading, 0, 0); | ||
controlGrid.Controls.Add(_coefficient, 1, 0); | ||
|
||
return controlGrid; | ||
} | ||
|
||
private void CoefficientHasChanged(object? sender, EventArgs e) | ||
{ | ||
_visualizationProvider.Settings.CompressionRatio.Value = _coefficient.Text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using TagCloud.ImageGeneration; | ||
using TagCloudGUI.Controls; | ||
|
||
namespace TagCloudGUI.Layout.FirstColumn; | ||
|
||
public class FirstColumn : TagCloudTableLayoutPanel | ||
{ | ||
public FirstColumn(IVisualizationProvider visualizationProvider, TagCloudConfigurationForm parentForm) | ||
{ | ||
ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); | ||
RowStyles.Add(new RowStyle(SizeType.Absolute, 133)); | ||
for (var i = 0; i < 4; i++) | ||
RowStyles.Add(new RowStyle(SizeType.Absolute, 98)); | ||
RowStyles.Add(new RowStyle(SizeType.Absolute, 55)); | ||
RowStyles.Add(new RowStyle(SizeType.AutoSize)); | ||
|
||
Controls.Add(new ImageSizeSettings(visualizationProvider), 0, 0); | ||
Controls.Add(new FontSettings(visualizationProvider, parentForm), 0, 1); | ||
Controls.Add(new ColorSettings(parentForm), 0, 2); | ||
Controls.Add(new SettingUpLayoutAlgorithm(parentForm), 0, 3); | ||
Controls.Add(new SettingTextType(parentForm), 0, 4); | ||
Controls.Add(new ConfiguringCloudCompressionRatio(visualizationProvider), 0, 5); | ||
Controls.Add(new Panel { Dock = DockStyle.Fill }, 0, 6); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Drawing.Text; | ||
using TagCloud.ImageGeneration; | ||
using TagCloudGUI.Controls; | ||
|
||
namespace TagCloudGUI.Layout.FirstColumn; | ||
|
||
public sealed class FontSettings : DropdownList | ||
{ | ||
private static readonly IEnumerable<string> FontFamilies = new InstalledFontCollection().Families | ||
.Select(family => family.Name); | ||
|
||
private readonly IVisualizationProvider _visualizationProvider; | ||
|
||
public FontSettings(IVisualizationProvider visualizationProvider, TagCloudConfigurationForm parentForm) | ||
: base("Шрифт:", FontFamilies, parentForm) | ||
{ | ||
Dock = DockStyle.Fill; | ||
DropDownList.SelectedItem = visualizationProvider.Settings.FontFamily.Name; | ||
_visualizationProvider = visualizationProvider; | ||
TextHasBeenChanged += FontIsSelected; | ||
visualizationProvider.Settings.FontFamily.ValueChanged += (_, message) => | ||
{ | ||
ErrorMessage.Text = message; | ||
}; | ||
} | ||
|
||
private void FontIsSelected(object? sender, EventArgs args) | ||
{ | ||
_visualizationProvider.Settings.FontFamily.Name = SelectedText; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А можешь раскрыть, зачем тут
struct
? Ещё и readonly) И чем это лучше record?