Skip to content
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

Юдин Павел #198

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ artifacts/
*.pidb
*.svclog
*.scc
*.png

# Chutzpah Test files
_Chutzpah*
Expand Down
33 changes: 33 additions & 0 deletions TagsCloud/App/Actions/CircleCloudAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using TagsCloud.CloudLayouter;
using TagsCloud.Infrastructure;
using TagsCloud.Infrastructure.UiActions;

namespace TagsCloud.App.Actions;

public class CircleCloudAction : IUiAction
{
private readonly IImageHolder imageHolder;
private readonly TagCloudPainter painter;
private readonly AppSettings settings;
private readonly Spiral spiral;

public CircleCloudAction(
AppSettings appSettings, IImageHolder imageHolder, TagCloudPainter painter, Spiral spiral)
{
settings = appSettings;
this.imageHolder = imageHolder;
this.painter = painter;
this.spiral = spiral;
}

public MenuCategory Category => MenuCategory.Types;
public string Name => "Круг";
public string Description => "";

public void Perform()
{
if (settings.File == null) throw new Exception("сначала загрузи файл");

painter.Paint(settings.File.FullName, spiral);
}
}
32 changes: 32 additions & 0 deletions TagsCloud/App/Actions/FlowerCloudAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using TagsCloud.CloudLayouter;
using TagsCloud.Infrastructure;
using TagsCloud.Infrastructure.UiActions;

namespace TagsCloud.App.Actions;

public class FlowerCloudAction : IUiAction
{
private readonly FlowerSpiral flowerSpiral;
private readonly IImageHolder imageHolder;
private readonly TagCloudPainter painter;
private readonly AppSettings settings;

public FlowerCloudAction(
IImageHolder imageHolder, TagCloudPainter painter, AppSettings settings, FlowerSpiral spiral)
{
flowerSpiral = spiral;
this.settings = settings;
this.imageHolder = imageHolder;
this.painter = painter;
}

public void Perform()
{
if (settings.File == null) throw new Exception("сначала загрузи файл");
painter.Paint(settings.File.FullName, flowerSpiral);
}

public MenuCategory Category => MenuCategory.Types;
public string Name => "Цветок";
public string Description => "";
}
28 changes: 28 additions & 0 deletions TagsCloud/App/Actions/ImageSettingsAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using TagsCloud.App.Settings;
using TagsCloud.Infrastructure;
using TagsCloud.Infrastructure.UiActions;

namespace TagsCloud.App.Actions;

public class ImageSettingsAction : IUiAction
{
private readonly IImageHolder imageHolder;
private readonly ImageSettings imageSettings;

public ImageSettingsAction(IImageHolder imageHolder,
ImageSettings imageSettings)
{
this.imageHolder = imageHolder;
this.imageSettings = imageSettings;
}

public MenuCategory Category => MenuCategory.Settings;
public string Name => "Изображение...";
public string Description => "Размеры изображения";

public void Perform()
{
SettingsForm.For(imageSettings).ShowDialog();
imageHolder.RecreateImage(imageSettings);
}
}
36 changes: 36 additions & 0 deletions TagsCloud/App/Actions/SaveFileAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Windows.Forms;
using TagsCloud.Infrastructure;
using TagsCloud.Infrastructure.UiActions;

namespace TagsCloud.App.Actions;

public class SaveFileAction : IUiAction
{
private readonly IImageHolder imageHolder;

public SaveFileAction(IImageHolder imageHolder)
{
this.imageHolder = imageHolder;
}

public MenuCategory Category => MenuCategory.File;
public string Name => "Сохранить";
public string Description => "Сохранить изображение в файл";

public void Perform()
{
var imagesDirectoryPath = Path.GetFullPath("..//..//..//images");
if (!Directory.Exists(imagesDirectoryPath)) Directory.CreateDirectory(imagesDirectoryPath);
var dialog = new SaveFileDialog
{
CheckFileExists = false,
InitialDirectory = Path.GetFullPath(imagesDirectoryPath),
DefaultExt = "png",
FileName = "image.png",
Filter = "Изображения (*.png)|*.png"
};
var res = dialog.ShowDialog();
if (res == DialogResult.OK)
imageHolder.SaveImage(dialog.FileName);
}
}
24 changes: 24 additions & 0 deletions TagsCloud/App/Actions/TagSettingsAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using TagsCloud.App.Settings;
using TagsCloud.Infrastructure;
using TagsCloud.Infrastructure.UiActions;

namespace TagsCloud.App.Actions;

public class TagSettingsAction : IUiAction
{
private readonly TagSettings tag;

public TagSettingsAction(TagSettings tag)
{
this.tag = tag;
}

public MenuCategory Category => MenuCategory.Settings;
public string Name => "Облако тегов...";
public string Description => "";

public void Perform()
{
SettingsForm.For(tag).ShowDialog();
}
}
32 changes: 32 additions & 0 deletions TagsCloud/App/Actions/UploadFileAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Windows.Forms;
using TagsCloud.Infrastructure;
using TagsCloud.Infrastructure.UiActions;

namespace TagsCloud.App.Actions;

public class UploadFileAction : IUiAction
{
private readonly AppSettings settings;

public UploadFileAction(AppSettings settings)
{
this.settings = settings;
}

public MenuCategory Category => MenuCategory.File;
public string Name => "Загрузить";
public string Description => "";

public void Perform()
{
var openFileDialog = new OpenFileDialog
{
Title = "Выберите файл",
Filter = "Текстовые файлы (*.txt)|*.txt|Документы (*.doc;*.docx)|*.doc;*.docx|Все файлы (*.*)|*.*",
FilterIndex = 1,
RestoreDirectory = true
};
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
settings.File = new FileInfo(openFileDialog.FileName);
}
}
24 changes: 24 additions & 0 deletions TagsCloud/App/Actions/WordAnalyzerSettingsAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using TagsCloud.App.Settings;
using TagsCloud.Infrastructure;
using TagsCloud.Infrastructure.UiActions;

namespace TagsCloud.App.Actions;

public class WordAnalyzerSettingsAction : IUiAction
{
private readonly WordAnalyzerSettings wordAnalyzerSettings;

public WordAnalyzerSettingsAction(WordAnalyzerSettings wordAnalyzerSettings)
{
this.wordAnalyzerSettings = wordAnalyzerSettings;
}

public MenuCategory Category => MenuCategory.Settings;
public string Name => "Анализатор...";
public string Description => "";

public void Perform()
{
SettingsForm.For(wordAnalyzerSettings).ShowDialog();
}
}
41 changes: 41 additions & 0 deletions TagsCloud/App/CloudForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions TagsCloud/App/CloudForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Drawing;
using System.Windows.Forms;
using TagsCloud.App.Settings;
using TagsCloud.Infrastructure;
using TagsCloud.Infrastructure.UiActions;

namespace TagsCloud;

public partial class CloudForm : Form
{
public CloudForm(IUiAction[] actions,
PictureBoxImageHolder pictureBox,
ImageSettings imageSettings)
{
InitializeComponent();
ClientSize = new Size(imageSettings.Width, imageSettings.Height);

var mainMenu = new MenuStrip();
mainMenu.Items.AddRange(actions.ToMenuItems());
Controls.Add(mainMenu);

pictureBox.RecreateImage(imageSettings);
pictureBox.Dock = DockStyle.Fill;
Controls.Add(pictureBox);
}

protected override void OnShown(EventArgs e)
{
base.OnShown(e);
Text = "TagCloud Painter";
}
}
6 changes: 6 additions & 0 deletions TagsCloud/App/Infrastructure/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TagsCloud.Infrastructure;

public class AppSettings
{
public FileInfo File { get; set; }
}
13 changes: 13 additions & 0 deletions TagsCloud/App/Infrastructure/IImageHolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Drawing;
using TagsCloud.App.Settings;

namespace TagsCloud.Infrastructure;

public interface IImageHolder
{
Size GetImageSize();
Graphics StartDrawing();
void UpdateUi();
void RecreateImage(ImageSettings settings);
void SaveImage(string fileName);
}
44 changes: 44 additions & 0 deletions TagsCloud/App/Infrastructure/PictureBoxImageHolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using TagsCloud.App.Settings;

namespace TagsCloud.Infrastructure;

public class PictureBoxImageHolder : PictureBox, IImageHolder
{
public Size GetImageSize()
{
FailIfNotInitialized();
return Image.Size;
}

public Graphics StartDrawing()
{
FailIfNotInitialized();
return Graphics.FromImage(Image);
}

public void UpdateUi()
{
Refresh();
Application.DoEvents();
}

public void RecreateImage(ImageSettings imageSettings)
{
Image = new Bitmap(imageSettings.Width, imageSettings.Height, PixelFormat.Format24bppRgb);
}

public void SaveImage(string fileName)
{
FailIfNotInitialized();
Image.Save(fileName);
}

private void FailIfNotInitialized()
{
if (Image == null)
throw new InvalidOperationException("Call PictureBoxImageHolder.RecreateImage before other method call!");
}
}
Loading