Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
d18b952541 | |||
20775f7f26 | |||
a81842346b | |||
c958114545 | |||
9c4cdb512f | |||
27af9813f3 | |||
ac846959df | |||
2e31988a1b | |||
00465b2d74 | |||
11104b9690 | |||
89c0ed3e48 | |||
cf649f759e | |||
c222fcb356 | |||
d9410fa68b | |||
cd64afbf92 | |||
2c212498fc | |||
8f3478b2b5 | |||
0c640c6769 | |||
d168f11ea6 | |||
bbc0734544 | |||
93d391fad3 | |||
3989c62269 | |||
00af902200 | |||
84307044fe | |||
e268bb35cb | |||
8fc5034d74 | |||
25a6ddb3bf | |||
e36d02dd75 | |||
dc5fb84108 | |||
34f72ac391 | |||
a6a16dcb11 | |||
f69fe262f8 | |||
2895044e8b | |||
37a3d7d8d2 | |||
4284b48c00 | |||
93622be5ba | |||
31d82d2a95 | |||
e89ef66010 | |||
ba8bcf5f78 | |||
69b251691f | |||
f940bf3dbc | |||
e8bd8ec31e | |||
fd41290d8e | |||
ae1e360bad | |||
7c710b06a2 | |||
58061ba1d9 |
79
.gitignore
vendored
79
.gitignore
vendored
@ -1,3 +1,82 @@
|
||||
# ---> JetBrains
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
11
.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml
generated
Normal file
11
.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml
generated
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
11
.idea/java.iml
generated
Normal file
11
.idea/java.iml
generated
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/java.iml" filepath="$PROJECT_DIR$/.idea/java.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
84
ProjectElectricLocomotive/AbstractStrategy.java
Normal file
84
ProjectElectricLocomotive/AbstractStrategy.java
Normal file
@ -0,0 +1,84 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject _moveableObject;
|
||||
private Status _state = Status.NotInit;
|
||||
protected int FieldWidth;
|
||||
protected int FieldHeight;
|
||||
public Status GetStatus() { return _state; }
|
||||
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
protected boolean MoveLeft(){
|
||||
return MoveTo(DyrectionType.Left);
|
||||
}
|
||||
|
||||
protected boolean MoveRight(){
|
||||
return MoveTo(DyrectionType.Right);
|
||||
}
|
||||
|
||||
protected boolean MoveUp(){
|
||||
return MoveTo(DyrectionType.Up);
|
||||
}
|
||||
|
||||
protected boolean MoveDown(){
|
||||
return MoveTo(DyrectionType.Down);
|
||||
}
|
||||
|
||||
/// Параметры объекта
|
||||
protected ObjectParameters GetObjectParameters(){
|
||||
if(_moveableObject == null) return null;
|
||||
return _moveableObject.GetObjectPosition();
|
||||
}
|
||||
|
||||
protected int GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(_moveableObject == null) return -1;
|
||||
return _moveableObject.GetStep();
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
protected abstract boolean IsTargetDestinaion();
|
||||
|
||||
private boolean MoveTo(DyrectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.CheckCanMove(directionType) == false) return false;
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
65
ProjectElectricLocomotive/DopClassParameters.java
Normal file
65
ProjectElectricLocomotive/DopClassParameters.java
Normal file
@ -0,0 +1,65 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class DopClassParameters<T extends EntityLocomotive, U extends IDrawingWheels> {
|
||||
public T[] _entityLocomotive;
|
||||
public U[] _idrawningWheels;
|
||||
|
||||
int _locomotivesCount;
|
||||
int _idrawningWheelsCount;
|
||||
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
|
||||
public DopClassParameters(int count, int width, int height) {
|
||||
_entityLocomotive = (T[]) new EntityLocomotive[count];
|
||||
_idrawningWheels = (U[]) new IDrawingWheels[count];
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_locomotivesCount = 0;
|
||||
_idrawningWheelsCount = 0;
|
||||
}
|
||||
|
||||
public void Add(T entityLocoObj) {
|
||||
if (_locomotivesCount < _entityLocomotive.length) {
|
||||
_entityLocomotive[_locomotivesCount] = entityLocoObj;
|
||||
_locomotivesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(U idrawingWheels) {
|
||||
if (_idrawningWheelsCount < _idrawningWheels.length) {
|
||||
_idrawningWheels[_idrawningWheelsCount] = idrawingWheels;
|
||||
_idrawningWheelsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public DrawingLocomotive RandomLocomotive(int pictureWidth, int pictureHeight) {
|
||||
Random rnd = new Random();
|
||||
if (_entityLocomotive == null || _idrawningWheels == null) {
|
||||
return null;
|
||||
}
|
||||
T entityLocomotive = _entityLocomotive[rnd.nextInt(_locomotivesCount)];
|
||||
U idrawingWheels = _idrawningWheels[rnd.nextInt(_idrawningWheelsCount)];
|
||||
|
||||
DrawingLocomotive drawLocomotive;
|
||||
if (entityLocomotive instanceof EntityElectricLocomotive) {
|
||||
drawLocomotive = new DrawingElectricLocomotive(
|
||||
(EntityElectricLocomotive) entityLocomotive,
|
||||
idrawingWheels,
|
||||
pictureWidth,
|
||||
pictureHeight
|
||||
);
|
||||
} else {
|
||||
drawLocomotive = new DrawingLocomotive(
|
||||
entityLocomotive,
|
||||
idrawingWheels,
|
||||
pictureWidth,
|
||||
pictureHeight
|
||||
);
|
||||
}
|
||||
return drawLocomotive;
|
||||
}
|
||||
}
|
44
ProjectElectricLocomotive/DrawingElectricLocomotive.java
Normal file
44
ProjectElectricLocomotive/DrawingElectricLocomotive.java
Normal file
@ -0,0 +1,44 @@
|
||||
package ProjectElectricLocomotive;
|
||||
import java.awt.*;
|
||||
public class DrawingElectricLocomotive extends DrawingLocomotive {
|
||||
|
||||
public DrawingElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean horns, boolean seifBatteries, int width, int height)
|
||||
{
|
||||
super(speed, weight, bodyColor, width, height, 150, 50);
|
||||
if (EntityLocomotive != null)
|
||||
{
|
||||
EntityLocomotive = new EntityElectricLocomotive(speed, width, bodyColor, additionalColor, horns, seifBatteries);
|
||||
}
|
||||
}
|
||||
|
||||
public DrawingElectricLocomotive(EntityElectricLocomotive entityElectricLocomotive, IDrawingWheels iDrawingWheels,
|
||||
int width, int height)
|
||||
{
|
||||
super(entityElectricLocomotive,iDrawingWheels, width, height, 150, 50);
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityLocomotive instanceof EntityElectricLocomotive electricLocomotive) ///////// WARNING INSTANCEOF
|
||||
{
|
||||
Color addColor = electricLocomotive.AdditionalColor;
|
||||
|
||||
if (electricLocomotive.Horns) {
|
||||
//horns
|
||||
g.setColor(addColor);
|
||||
g.fillRect(_startPosX + 30, _startPosY + 15, 20, 5);
|
||||
g.drawLine(_startPosX + 40, _startPosY + 15, _startPosX + 50, _startPosY + 10);
|
||||
g.drawLine(_startPosX + 50, _startPosY + 10, _startPosX + 45, _startPosY);
|
||||
g.drawLine(_startPosX + 45, _startPosY + 15, _startPosX + 50, _startPosY + 10);
|
||||
g.drawLine(_startPosX + 50, _startPosY + 10, _startPosX + 40, _startPosY);
|
||||
}
|
||||
|
||||
if (electricLocomotive.SeifBatteries) {
|
||||
g.setColor(addColor);
|
||||
g.fillRect(_startPosX + 80, _startPosY + 30, 5, 10);
|
||||
}
|
||||
super.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
28
ProjectElectricLocomotive/DrawingEmptyWheels.java
Normal file
28
ProjectElectricLocomotive/DrawingEmptyWheels.java
Normal file
@ -0,0 +1,28 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingEmptyWheels implements IDrawingWheels{
|
||||
private WheelsCount _wheelsCount;
|
||||
@Override
|
||||
public void SetWheelsCount(int wheelsCount) {
|
||||
for (WheelsCount val : WheelsCount.values()) {
|
||||
if (val.count == wheelsCount) {
|
||||
_wheelsCount = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._wheelsCount = WheelsCount.Three;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WheelsCount GetWheelsCount() {
|
||||
return _wheelsCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(x, y, w, h);
|
||||
}
|
||||
}
|
224
ProjectElectricLocomotive/DrawingLocomotive.java
Normal file
224
ProjectElectricLocomotive/DrawingLocomotive.java
Normal file
@ -0,0 +1,224 @@
|
||||
package ProjectElectricLocomotive;
|
||||
import java.awt.*;
|
||||
import java.security.cert.PolicyNode;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingLocomotive {
|
||||
public EntityLocomotive EntityLocomotive;
|
||||
protected IDrawingWheels _drawingWheels;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
public int _startPosX;
|
||||
public int _startPosY;
|
||||
private int _locoWidth = 150;
|
||||
private int _locoHeight = 50;
|
||||
|
||||
public int GetPosX(){
|
||||
return _startPosX;
|
||||
}
|
||||
public int GetPosY(){
|
||||
return _startPosY;
|
||||
}
|
||||
public int GetWidth(){
|
||||
return _locoWidth;
|
||||
}
|
||||
public int GetHeight(){
|
||||
return _locoHeight;
|
||||
}
|
||||
|
||||
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if (width < _locoWidth || height < _locoHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||
|
||||
Random rnd = new Random();
|
||||
int WhatWheels = rnd.nextInt(0, 3);
|
||||
|
||||
if(WhatWheels == 0) _drawingWheels = new DrawingWheel();
|
||||
if(WhatWheels == 1) _drawingWheels = new DrawingEmptyWheels();
|
||||
if(WhatWheels == 2) _drawingWheels = new DrawingWheelsBlueCrom();
|
||||
}
|
||||
|
||||
protected DrawingLocomotive(int speed, double weight, Color bodyColor, int width,
|
||||
int height, int locoWidth, int locoHeight)
|
||||
{
|
||||
this(speed,weight, bodyColor, width, height);
|
||||
if (width < _locoWidth || height < _locoHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_locoWidth = locoWidth;
|
||||
_locoHeight = locoHeight;
|
||||
}
|
||||
|
||||
protected DrawingLocomotive(EntityLocomotive entityLocomotive, IDrawingWheels iDrawingWheels,
|
||||
int width, int height){
|
||||
EntityLocomotive = entityLocomotive;
|
||||
_drawingWheels = iDrawingWheels;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
|
||||
protected DrawingLocomotive(EntityLocomotive entityLocomotive, IDrawingWheels iDrawingWheels,
|
||||
int width, int height, int locoWidth, int locoHeight){
|
||||
this(entityLocomotive, iDrawingWheels, width, height);
|
||||
_locoWidth = locoWidth;
|
||||
_locoHeight = locoHeight;
|
||||
}
|
||||
|
||||
public void SetWheelsCount(int wheelsCount){
|
||||
_drawingWheels.SetWheelsCount(wheelsCount);
|
||||
}
|
||||
|
||||
//Установка позиции
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x + _locoWidth > _pictureWidth)
|
||||
{
|
||||
x = _pictureWidth - _locoWidth;
|
||||
}
|
||||
if (y < 0 || y + _locoHeight > _pictureHeight)
|
||||
{
|
||||
y = _pictureHeight - _locoHeight;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public void MoveTransport(DyrectionType direction) {
|
||||
if (EntityLocomotive == null) {
|
||||
return;
|
||||
}
|
||||
switch (direction) {
|
||||
case Left:
|
||||
if (_startPosX - EntityLocomotive.Step() > 0) {
|
||||
_startPosX -= (int) EntityLocomotive.Step();
|
||||
}
|
||||
break;
|
||||
case Up:
|
||||
if (_startPosY - EntityLocomotive.Step() > 0) {
|
||||
_startPosY -= (int) EntityLocomotive.Step();
|
||||
}
|
||||
break;
|
||||
case Right:
|
||||
if (_startPosX + EntityLocomotive.Step() + _locoWidth < _pictureWidth) {
|
||||
_startPosX += (int) EntityLocomotive.Step();
|
||||
}
|
||||
break;
|
||||
case Down:
|
||||
if (_startPosY + EntityLocomotive.Step() + _locoHeight < _pictureHeight) {
|
||||
_startPosY += (int) EntityLocomotive.Step();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
{
|
||||
if (EntityLocomotive == null) return;
|
||||
}
|
||||
|
||||
Color colorBlack = Color.BLACK;
|
||||
Color windows = Color.BLUE;
|
||||
Color bodyColor = EntityLocomotive.BodyColor;
|
||||
|
||||
//локомотив
|
||||
g.setColor(bodyColor);
|
||||
Polygon locoP = new Polygon();
|
||||
locoP.addPoint(_startPosX, _startPosY + 40);
|
||||
locoP.addPoint(_startPosX, _startPosY + 30);
|
||||
locoP.addPoint(_startPosX + 20, _startPosY + 20);
|
||||
locoP.addPoint(_startPosX + 70, _startPosY + 20);
|
||||
locoP.addPoint(_startPosX +80, _startPosY + 30);
|
||||
locoP.addPoint(_startPosX +80, _startPosY + 40);
|
||||
locoP.addPoint(_startPosX +75, _startPosY + 45);
|
||||
locoP.addPoint(_startPosX +5, _startPosY + 45);
|
||||
locoP.addPoint(_startPosX, _startPosY + 40);
|
||||
g.fillPolygon(locoP);
|
||||
|
||||
g.setColor(colorBlack);
|
||||
g.drawPolygon(locoP);
|
||||
|
||||
//окошки
|
||||
Polygon window = new Polygon();
|
||||
window.addPoint(_startPosX + 10, _startPosY + 30);
|
||||
window.addPoint(_startPosX +15, _startPosY + 25);
|
||||
window.addPoint(_startPosX + 20, _startPosY + 25);
|
||||
window.addPoint(_startPosX + 20, _startPosY + 30);
|
||||
window.addPoint(_startPosX +10, _startPosY + 30);
|
||||
g.setColor(windows);
|
||||
g.fillPolygon(window);
|
||||
g.fillRect(_startPosX + 25, _startPosY + 25, 10, 5);
|
||||
g.setColor(Color.black);
|
||||
g.drawPolygon(window);
|
||||
g.drawRect(_startPosX + 25, _startPosY + 25, 10, 5);
|
||||
|
||||
//обязательные колеса
|
||||
//loco
|
||||
g.fillOval(_startPosX + 10, _startPosY + 45, 9, 9);
|
||||
g.fillOval(_startPosX + 25, _startPosY + 45, 9, 9);
|
||||
g.fillOval(_startPosX + 50, _startPosY + 45, 9, 9);
|
||||
g.fillOval(_startPosX + 65, _startPosY + 45, 9, 9);
|
||||
|
||||
//telejka
|
||||
Polygon telega = new Polygon();
|
||||
|
||||
telega.addPoint(_startPosX + 90, _startPosY + 25);
|
||||
telega.addPoint(_startPosX + 95, _startPosY + 20);
|
||||
telega.addPoint(_startPosX + 145, _startPosY + 20);
|
||||
telega.addPoint(_startPosX + 150, _startPosY + 25);
|
||||
telega.addPoint(_startPosX + 150, _startPosY + 45);
|
||||
telega.addPoint(_startPosX + 90, _startPosY + 45);
|
||||
telega.addPoint(_startPosX + 90, _startPosY + 25);
|
||||
|
||||
g.setColor(bodyColor);
|
||||
g.fillPolygon(telega);
|
||||
g.setColor(colorBlack);
|
||||
g.drawPolygon(telega);
|
||||
|
||||
//телега окна
|
||||
g.setColor(colorBlack);
|
||||
g.drawLine(_startPosX + 80, _startPosY + 40, _startPosX + 90, _startPosY + 40);
|
||||
g.setColor(windows); g.fillRect(_startPosX + 95, _startPosY + 30, 10, 5);
|
||||
g.fillRect(_startPosX + 115, _startPosY + 30, 10, 5);
|
||||
g.fillRect(_startPosX + 135, _startPosY + 30, 10, 5);
|
||||
|
||||
_drawingWheels.DrawWheels(g, colorBlack, _startPosX, _startPosY, 9,9);
|
||||
}
|
||||
|
||||
public boolean CanMove(DyrectionType direction)
|
||||
{
|
||||
if (EntityLocomotive == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch(direction) {
|
||||
//влево
|
||||
case Left:
|
||||
if (_startPosX - EntityLocomotive.Step() > 0) return true;
|
||||
break;
|
||||
case Up:
|
||||
if (_startPosY - EntityLocomotive.Step() > 0) return true;
|
||||
break;
|
||||
case Right:
|
||||
if (_startPosX + EntityLocomotive.Step() < _pictureWidth) return true;
|
||||
break;
|
||||
case Down:
|
||||
if (_startPosY + EntityLocomotive.Step() < _pictureHeight) return true;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public IMoveableObject GetMoveableObject() {
|
||||
return new DrawingObjectLocomotive(this);
|
||||
}
|
||||
}
|
30
ProjectElectricLocomotive/DrawingObjectLocomotive.java
Normal file
30
ProjectElectricLocomotive/DrawingObjectLocomotive.java
Normal file
@ -0,0 +1,30 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
public class DrawingObjectLocomotive implements IMoveableObject {
|
||||
private DrawingLocomotive _drawningLocomotive = null;
|
||||
public DrawingObjectLocomotive(DrawingLocomotive drawningLocomotive)
|
||||
{
|
||||
_drawningLocomotive = drawningLocomotive;
|
||||
}
|
||||
public ObjectParameters GetObjectPosition()
|
||||
{
|
||||
if (_drawningLocomotive == null || _drawningLocomotive.EntityLocomotive == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningLocomotive.GetPosX(), _drawningLocomotive.GetPosY(),
|
||||
_drawningLocomotive.GetWidth(), _drawningLocomotive.GetHeight());
|
||||
}
|
||||
public int GetStep(){
|
||||
if(_drawningLocomotive == null) return -1;
|
||||
return (int)(_drawningLocomotive.EntityLocomotive.Step());
|
||||
}
|
||||
public boolean CheckCanMove(DyrectionType direction){
|
||||
if(_drawningLocomotive == null) return false;
|
||||
return _drawningLocomotive.CanMove(direction);
|
||||
}
|
||||
public void MoveObject(DyrectionType direction){
|
||||
if(_drawningLocomotive == null) return;
|
||||
_drawningLocomotive.MoveTransport(direction);
|
||||
}
|
||||
}
|
26
ProjectElectricLocomotive/DrawingWheel.java
Normal file
26
ProjectElectricLocomotive/DrawingWheel.java
Normal file
@ -0,0 +1,26 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingWheel implements IDrawingWheels {
|
||||
private WheelsCount _wheelsCount;
|
||||
public void SetWheelsCount(int wheelsCount) {
|
||||
for (WheelsCount val : WheelsCount.values()) {
|
||||
if (val.count == wheelsCount) {
|
||||
_wheelsCount = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._wheelsCount = WheelsCount.Three;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WheelsCount GetWheelsCount() {
|
||||
return _wheelsCount;
|
||||
}
|
||||
|
||||
public void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.fillOval(x, y, w, h);
|
||||
}
|
||||
}
|
35
ProjectElectricLocomotive/DrawingWheelsBlueCrom.java
Normal file
35
ProjectElectricLocomotive/DrawingWheelsBlueCrom.java
Normal file
@ -0,0 +1,35 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingWheelsBlueCrom implements IDrawingWheels{
|
||||
private WheelsCount _wheelsCount;
|
||||
@Override
|
||||
public void SetWheelsCount(int wheelsCount) {
|
||||
for (WheelsCount val : WheelsCount.values()) {
|
||||
if (val.count == wheelsCount) {
|
||||
_wheelsCount = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._wheelsCount = WheelsCount.Three;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WheelsCount GetWheelsCount() {
|
||||
return _wheelsCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
g2d.setColor(Color.BLUE);
|
||||
g2d.drawOval(x, y + 3, w + 2, h + 2);
|
||||
g2d.setColor(Color.RED);
|
||||
g2d.drawOval(x - 2, y - 2, w + 2, h + 2);
|
||||
g2d.setColor(Color.MAGENTA);
|
||||
g2d.drawOval(x + 3, y, w + 3, h + 3);
|
||||
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(x, y, w, h);
|
||||
}
|
||||
}
|
5
ProjectElectricLocomotive/DyrectionType.java
Normal file
5
ProjectElectricLocomotive/DyrectionType.java
Normal file
@ -0,0 +1,5 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
public enum DyrectionType {
|
||||
Up, Down, Left, Right;
|
||||
}
|
21
ProjectElectricLocomotive/EntityElectricLocomotive.java
Normal file
21
ProjectElectricLocomotive/EntityElectricLocomotive.java
Normal file
@ -0,0 +1,21 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityElectricLocomotive extends EntityLocomotive {
|
||||
public Color AdditionalColor;
|
||||
public boolean Horns;
|
||||
public boolean SeifBatteries;
|
||||
public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, boolean horns, boolean seifBatteries)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
Horns = horns;
|
||||
SeifBatteries = seifBatteries;
|
||||
}
|
||||
|
||||
public void SetAdditionalColor(Color color){
|
||||
AdditionalColor = color;
|
||||
}
|
||||
|
||||
}
|
27
ProjectElectricLocomotive/EntityLocomotive.java
Normal file
27
ProjectElectricLocomotive/EntityLocomotive.java
Normal file
@ -0,0 +1,27 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityLocomotive {
|
||||
public int Speed;
|
||||
public double Weight;
|
||||
public Color BodyColor;
|
||||
public EntityLocomotive(int speed, double weight, Color bodyColor) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
public double Step()
|
||||
{
|
||||
return (double) Speed * 100 / Weight;
|
||||
}
|
||||
public void Init(int speed, double weight, Color bodyColor/*, Color additionalColor, boolean horns, boolean seifbatteries*/) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
public void SetBodyColor(Color color){
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
89
ProjectElectricLocomotive/ExtentionDrawingLoco.java
Normal file
89
ProjectElectricLocomotive/ExtentionDrawingLoco.java
Normal file
@ -0,0 +1,89 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ExtentionDrawingLoco {
|
||||
public static DrawingLocomotive CreateDrawingLocomotive(String info, String separatorForObject, int width, int height)
|
||||
{
|
||||
String[] strs = info.split(separatorForObject);
|
||||
if (strs.length == 7) {
|
||||
DrawingLocomotive drawingLoco = new DrawingLocomotive(
|
||||
Integer.parseInt(strs[0]),
|
||||
Double.parseDouble(strs[1]),
|
||||
new Color(
|
||||
Integer.parseInt(strs[2]),
|
||||
Integer.parseInt(strs[3]),
|
||||
Integer.parseInt(strs[4])
|
||||
),
|
||||
width, height
|
||||
);
|
||||
if (Objects.equals(strs[5], "DrawingWheel")) {
|
||||
drawingLoco._drawingWheels = new DrawingWheel();
|
||||
} else if (Objects.equals(strs[5], "DrawingEmptyWheels")) {
|
||||
drawingLoco._drawingWheels = new DrawingEmptyWheels();
|
||||
} else if (Objects.equals(strs[5], "DrawingWheelsBlueCrom")) {
|
||||
drawingLoco._drawingWheels = new DrawingWheelsBlueCrom();
|
||||
}
|
||||
drawingLoco.SetWheelsCount(Integer.parseInt(strs[6]));
|
||||
return drawingLoco;
|
||||
}
|
||||
if (strs.length == 12) {
|
||||
DrawingLocomotive drawingLoco = new DrawingElectricLocomotive(
|
||||
Integer.parseInt(strs[0]),
|
||||
Double.parseDouble(strs[1]),
|
||||
new Color(
|
||||
Integer.parseInt(strs[2]),
|
||||
Integer.parseInt(strs[3]),
|
||||
Integer.parseInt(strs[4])
|
||||
),
|
||||
new Color(
|
||||
Integer.parseInt(strs[7]),
|
||||
Integer.parseInt(strs[8]),
|
||||
Integer.parseInt(strs[9])
|
||||
),
|
||||
Boolean.parseBoolean(strs[10]),
|
||||
Boolean.parseBoolean(strs[11]),
|
||||
width, height
|
||||
);
|
||||
if (Objects.equals(strs[5], "DrawingWheel")) {
|
||||
drawingLoco._drawingWheels = new DrawingWheel();
|
||||
} else if (Objects.equals(strs[5], "DrawingEmptyWheels")) {
|
||||
drawingLoco._drawingWheels = new DrawingEmptyWheels();
|
||||
} else if (Objects.equals(strs[5], "DrawingWheelsBlueCrom")) {
|
||||
drawingLoco._drawingWheels = new DrawingWheelsBlueCrom();
|
||||
}
|
||||
drawingLoco.SetWheelsCount(Integer.parseInt(strs[6]));
|
||||
return drawingLoco;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String GetDataForSave(DrawingLocomotive drawingLoco, String separatorForObject) {
|
||||
var loco = drawingLoco.EntityLocomotive;
|
||||
if (loco == null) {
|
||||
return "";
|
||||
}
|
||||
String str = loco.Speed +
|
||||
separatorForObject +
|
||||
loco.Weight +
|
||||
separatorForObject +
|
||||
loco.BodyColor.getRed() + separatorForObject +
|
||||
loco.BodyColor.getGreen() + separatorForObject +
|
||||
loco.BodyColor.getBlue() + separatorForObject +
|
||||
(drawingLoco._drawingWheels.GetWheelsCount() == null ? "null" : drawingLoco._drawingWheels.getClass()) + separatorForObject +
|
||||
(drawingLoco._drawingWheels.GetWheelsCount() == null ? "0" : drawingLoco._drawingWheels.GetWheelsCount().count);
|
||||
if (!(loco instanceof EntityElectricLocomotive electroLoco)) {
|
||||
return str;
|
||||
}
|
||||
return str +
|
||||
separatorForObject +
|
||||
electroLoco.AdditionalColor.getRed() + separatorForObject +
|
||||
electroLoco.AdditionalColor.getGreen() + separatorForObject +
|
||||
electroLoco.AdditionalColor.getBlue() + separatorForObject +
|
||||
electroLoco.Horns +
|
||||
separatorForObject +
|
||||
electroLoco.SeifBatteries;
|
||||
}
|
||||
|
||||
}
|
38
ProjectElectricLocomotive/FormDopClassParameters.form
Normal file
38
ProjectElectricLocomotive/FormDopClassParameters.form
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectElectricLocomotive.FormDopClassParameters">
|
||||
<grid id="27dc6" binding="pictureBoxGenerated" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="0">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="758" height="552"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<maximumSize width="600" height="400"/>
|
||||
<minimumSize width="600" height="400"/>
|
||||
<opaque value="true"/>
|
||||
<preferredSize width="600" height="400"/>
|
||||
<requestFocusEnabled value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="1ee3" class="javax.swing.JButton" binding="ButtonGenerationRandomLocomotive">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Генерировать локомотив"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="b7e9d">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="d0ce8">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
87
ProjectElectricLocomotive/FormDopClassParameters.java
Normal file
87
ProjectElectricLocomotive/FormDopClassParameters.java
Normal file
@ -0,0 +1,87 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormDopClassParameters {
|
||||
private JButton ButtonGenerationRandomLocomotive;
|
||||
private JPanel pictureBoxGenerated;
|
||||
Random rnd;
|
||||
DrawingLocomotive drawingLocomotive;
|
||||
DopClassParameters<EntityLocomotive, IDrawingWheels> _dopClassParameters;
|
||||
|
||||
public JPanel getPictureBoxGenerated() {
|
||||
return pictureBoxGenerated;
|
||||
}
|
||||
|
||||
public FormDopClassParameters() {
|
||||
pictureBoxGenerated.setPreferredSize(new Dimension(400, 300));
|
||||
_dopClassParameters = new DopClassParameters<>(
|
||||
10,
|
||||
pictureBoxGenerated.getWidth(),
|
||||
pictureBoxGenerated.getHeight()
|
||||
);
|
||||
|
||||
ButtonGenerationRandomLocomotive.addActionListener(e -> {
|
||||
AddEntityLocomotive();
|
||||
AddRandomWheels();
|
||||
|
||||
drawingLocomotive = _dopClassParameters.RandomLocomotive(
|
||||
pictureBoxGenerated.getWidth(),
|
||||
pictureBoxGenerated.getHeight()
|
||||
);
|
||||
drawingLocomotive.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100));
|
||||
Draw();
|
||||
});
|
||||
}
|
||||
|
||||
public void AddEntityLocomotive() {
|
||||
rnd = new Random();
|
||||
EntityLocomotive entityLocomotive;
|
||||
Color color = new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
||||
|
||||
if (rnd.nextBoolean()) {
|
||||
entityLocomotive = new EntityLocomotive(
|
||||
rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 3000),
|
||||
color
|
||||
);
|
||||
} else {
|
||||
entityLocomotive = new EntityElectricLocomotive(
|
||||
rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 3000),
|
||||
color,
|
||||
color,
|
||||
rnd.nextBoolean(),
|
||||
rnd.nextBoolean()
|
||||
);
|
||||
}
|
||||
_dopClassParameters.Add(entityLocomotive);
|
||||
}
|
||||
|
||||
public void AddRandomWheels() {
|
||||
rnd = new Random();
|
||||
IDrawingWheels iDrawingWheels;
|
||||
int wheelsChoice = rnd.nextInt(0, 3);
|
||||
if (wheelsChoice == 0) {
|
||||
iDrawingWheels = new DrawingWheel();
|
||||
} else if (wheelsChoice == 1) {
|
||||
iDrawingWheels = new DrawingEmptyWheels();
|
||||
} else {
|
||||
iDrawingWheels = new DrawingWheelsBlueCrom();
|
||||
}
|
||||
iDrawingWheels.SetWheelsCount(rnd.nextInt(2, 5));
|
||||
_dopClassParameters.Add(iDrawingWheels);
|
||||
}
|
||||
|
||||
public void Draw() {
|
||||
if (drawingLocomotive.EntityLocomotive == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = pictureBoxGenerated.getGraphics();
|
||||
pictureBoxGenerated.paint(g);
|
||||
drawingLocomotive.DrawTransport(g);
|
||||
}
|
||||
|
||||
}
|
134
ProjectElectricLocomotive/FormElectricLocomotive.form
Normal file
134
ProjectElectricLocomotive/FormElectricLocomotive.form
Normal file
@ -0,0 +1,134 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectElectricLocomotive.FormElectricLocomotive">
|
||||
<grid id="27dc6" binding="pictureBox" custom-create="true" layout-manager="GridLayoutManager" row-count="6" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="24" y="37" width="663" height="500"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<minimumSize width="650" height="400"/>
|
||||
<preferredSize width="650" height="400"/>
|
||||
</properties>
|
||||
<border type="none">
|
||||
<font/>
|
||||
</border>
|
||||
<children>
|
||||
<vspacer id="17764">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="6cb47" class="javax.swing.JButton" binding="buttonCreateElectricLocomotive">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать электролокомотив"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ca377" class="javax.swing.JButton" binding="buttonCreateLocomotive">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать локомотив"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="dac01" class="javax.swing.JComboBox" binding="comboBoxStrategy">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="MoveToCenter"/>
|
||||
<item value="MoveToRightCorner"/>
|
||||
</model>
|
||||
<toolTipText value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="42f28" class="javax.swing.JButton" binding="buttonStep">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Шаг"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="cc460" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="5" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="true"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<icon value="ProjectElectricLocomotive/img/arrowRight.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2fa92" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="true"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<icon value="ProjectElectricLocomotive/img/arrowDown.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bbbb" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="4" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<hideActionText value="false"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<icon value="ProjectElectricLocomotive/img/arrowUp.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
<clientProperties>
|
||||
<hideActionText class="java.lang.Boolean" value="false"/>
|
||||
</clientProperties>
|
||||
</component>
|
||||
<component id="326c5" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="false"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<icon value="ProjectElectricLocomotive/img/arrowLeft.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
<clientProperties>
|
||||
<hideActionText class="java.lang.Boolean" value="false"/>
|
||||
</clientProperties>
|
||||
</component>
|
||||
<component id="7aad1" class="javax.swing.JButton" binding="ButtonSelectLocomotive">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Выбрать локо"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
171
ProjectElectricLocomotive/FormElectricLocomotive.java
Normal file
171
ProjectElectricLocomotive/FormElectricLocomotive.java
Normal file
@ -0,0 +1,171 @@
|
||||
package ProjectElectricLocomotive;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormElectricLocomotive extends JDialog{
|
||||
public DrawingLocomotive _drawingLocomotive;
|
||||
AbstractStrategy _abstractStrategy;
|
||||
private JButton buttonCreateElectricLocomotive;
|
||||
public JComponent pictureBox;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
public JComboBox comboBoxStrategy;
|
||||
private JButton buttonStep;
|
||||
private JButton buttonCreateLocomotive;
|
||||
public JButton ButtonSelectLocomotive;
|
||||
public DrawingLocomotive SelectedLocomotive;
|
||||
public boolean IsSelect = false;
|
||||
|
||||
public JComponent getPictureBox()
|
||||
{
|
||||
return pictureBox;
|
||||
}
|
||||
|
||||
private class Canvas extends JPanel{
|
||||
public Canvas(){
|
||||
}
|
||||
public void paintComponent (Graphics g){
|
||||
if (_drawingLocomotive == null){
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
g2d.setColor(getBackground());
|
||||
g2d.fillRect(0, 0, getWidth(), getHeight());
|
||||
super.paintComponents(g);
|
||||
_drawingLocomotive.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
public FormElectricLocomotive()
|
||||
{
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
buttonCreateLocomotive.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
Color color = JColorChooser.showDialog(
|
||||
null,
|
||||
"Цвет",
|
||||
null
|
||||
);
|
||||
_drawingLocomotive = new DrawingLocomotive(
|
||||
rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 3000),
|
||||
color,
|
||||
pictureBox.getWidth(),
|
||||
pictureBox.getHeight()
|
||||
);
|
||||
|
||||
_drawingLocomotive.SetWheelsCount(rnd.nextInt(2, 5));
|
||||
_drawingLocomotive.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100));
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonCreateElectricLocomotive.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
Color color = JColorChooser.showDialog(null, "Цвет", null);
|
||||
Color addColor = JColorChooser.showDialog(null, "Цвет2", null);
|
||||
|
||||
_drawingLocomotive = new DrawingElectricLocomotive(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
color,
|
||||
addColor,
|
||||
random.nextBoolean(),
|
||||
random.nextBoolean(),
|
||||
pictureBox.getWidth(),
|
||||
pictureBox.getHeight()
|
||||
);
|
||||
|
||||
_drawingLocomotive.SetWheelsCount(random.nextInt(2, 5));
|
||||
_drawingLocomotive.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
Draw();
|
||||
});
|
||||
|
||||
ButtonSelectLocomotive.addActionListener(e->{
|
||||
SelectedLocomotive = _drawingLocomotive;
|
||||
IsSelect = true;
|
||||
});
|
||||
|
||||
buttonStep.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawingLocomotive == null) {
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
switch(comboBoxStrategy.getSelectedIndex())
|
||||
{
|
||||
case 0:
|
||||
_abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_abstractStrategy = new MoveToRigthCorner();
|
||||
break;
|
||||
default:
|
||||
_abstractStrategy = null;
|
||||
break;
|
||||
} ;
|
||||
if (_abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(
|
||||
new DrawingObjectLocomotive(_drawingLocomotive), pictureBox.getWidth(),
|
||||
pictureBox.getHeight()
|
||||
);
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (_abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish) {
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ActionListener buttonMoveClickedListener = e -> {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
|
||||
switch (buttonName) {
|
||||
case ("buttonUp") -> {
|
||||
_drawingLocomotive.MoveTransport(DyrectionType.Up);
|
||||
}
|
||||
case ("buttonDown") -> {
|
||||
_drawingLocomotive.MoveTransport(DyrectionType.Down);
|
||||
}
|
||||
case ("buttonLeft") -> {
|
||||
_drawingLocomotive.MoveTransport(DyrectionType.Left);
|
||||
}
|
||||
case ("buttonRight") -> {
|
||||
_drawingLocomotive.MoveTransport(DyrectionType.Right);
|
||||
}
|
||||
}
|
||||
Draw();
|
||||
};
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
}
|
||||
public void Draw() {
|
||||
pictureBox.repaint();
|
||||
}
|
||||
|
||||
private void createUIComponents(){
|
||||
pictureBox = new Canvas();
|
||||
pictureBox.setBounds(new Rectangle(400, 300));
|
||||
}
|
||||
}
|
135
ProjectElectricLocomotive/FormLocomotiveCollections.form
Normal file
135
ProjectElectricLocomotive/FormLocomotiveCollections.form
Normal file
@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectElectricLocomotive.FormLocomotiveCollections">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="634" height="464"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="c25f7" binding="pictureBoxCollections" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true">
|
||||
<minimum-size width="400" height="320"/>
|
||||
<preferred-size width="400" height="320"/>
|
||||
<maximum-size width="400" height="320"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="line"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="40d5" binding="Instruments" layout-manager="GridLayoutManager" row-count="10" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true">
|
||||
<minimum-size width="160" height="400"/>
|
||||
<preferred-size width="160" height="400"/>
|
||||
<maximum-size width="160" height="400"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
</properties>
|
||||
<border type="none">
|
||||
<font/>
|
||||
</border>
|
||||
<children>
|
||||
<vspacer id="1eee0">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="7" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="5039" class="javax.swing.JTextField" binding="textBoxStorageName">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="50eff" class="javax.swing.JButton" binding="ButtonAddObject">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Добавить набор"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5ef9c" class="javax.swing.JList" binding="listBoxStorage">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1b1c" class="javax.swing.JButton" binding="ButtonCreateRandomLoco">
|
||||
<constraints>
|
||||
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать рандомный локо "/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="138d" class="javax.swing.JButton" binding="ButtonAddLocomotive">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Добавить локо"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b21cb" class="javax.swing.JButton" binding="ButtonRefreshCollection">
|
||||
<constraints>
|
||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Обновить "/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1d01d" class="javax.swing.JButton" binding="ButtonRemoveLocomotive">
|
||||
<constraints>
|
||||
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Удалить локо"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="25553" class="javax.swing.JTextField" binding="textFieldNumber">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="-"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d1477" class="javax.swing.JButton" binding="ButtonRemoveObject">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Удалить набор"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="ab73" class="javax.swing.JButton" binding="Button_OpenFormRemovedLocomotives">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Открыть удаленный локо"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
274
ProjectElectricLocomotive/FormLocomotiveCollections.java
Normal file
274
ProjectElectricLocomotive/FormLocomotiveCollections.java
Normal file
@ -0,0 +1,274 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.util.Stack;
|
||||
|
||||
public class FormLocomotiveCollections {
|
||||
FormElectricLocomotive formElectricLocomotive;
|
||||
FormLocomotiveConfig formLocomotiveConfig;
|
||||
private JPanel MainPanel;
|
||||
private JPanel pictureBoxCollections;
|
||||
private JPanel Instruments;
|
||||
private JButton ButtonAddLocomotive;
|
||||
private JTextField textFieldNumber;
|
||||
private JButton ButtonRefreshCollection;
|
||||
private JButton ButtonRemoveLocomotive;
|
||||
private JButton ButtonCreateRandomLoco;
|
||||
private JTextField textBoxStorageName;
|
||||
private JButton ButtonAddObject;
|
||||
private JList listBoxStorage;
|
||||
private JButton ButtonRemoveObject;
|
||||
private JButton Button_OpenFormRemovedLocomotives;
|
||||
public DrawingLocomotive loco;
|
||||
final LocomotivesGenericStorage _storage;
|
||||
FrameElectricLocomotive _frameRemovedLocomotives;
|
||||
private Stack<DrawingLocomotive> _stackRemoveObjects;
|
||||
FrameDopClassParameters frameDopClassParameters;
|
||||
public JPanel getPictureBoxCollections() {
|
||||
return MainPanel;
|
||||
}
|
||||
|
||||
public FormLocomotiveCollections() {
|
||||
formElectricLocomotive = new FormElectricLocomotive();
|
||||
formLocomotiveConfig = new FormLocomotiveConfig();
|
||||
_storage = new LocomotivesGenericStorage(400,300);
|
||||
_stackRemoveObjects = new Stack<>();
|
||||
listBoxStorage.addListSelectionListener(this::listBoxObjectsSelectedIndexChanged);
|
||||
|
||||
ButtonAddObject.addActionListener(e ->
|
||||
{
|
||||
String NameStorage = textBoxStorageName.getText();
|
||||
if (NameStorage.equals("")) {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Где данные? Напиши хоть что-нибудь",
|
||||
"Ошибка",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(NameStorage);
|
||||
ReloadObjects();
|
||||
Refresh();
|
||||
});
|
||||
|
||||
ButtonRemoveObject.addActionListener(e ->
|
||||
{
|
||||
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(), "Коллекция удалена", "Удаление", JOptionPane.INFORMATION_MESSAGE);
|
||||
_storage.DelSet((String) listBoxStorage.getSelectedValue()); //ТУТ СТРИНГ ОБРАТИ ВНИМАНИЕ КАК-НИБУДЬ
|
||||
ReloadObjects();
|
||||
});
|
||||
|
||||
ButtonAddLocomotive.addActionListener(e -> {
|
||||
if (listBoxStorage.getSelectedIndex() == -1)
|
||||
return;
|
||||
var obj = _storage.get(listBoxStorage.getSelectedValue().toString()); // ТУТ ЕЩЕ РАЗ - ОБРАТИ ВНИМАНИЕ НА СТРИНГ
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
FrameLocomotiveConfig frameLocomotiveConfig = new FrameLocomotiveConfig();
|
||||
frameLocomotiveConfig.setVisible(true);
|
||||
frameLocomotiveConfig._formLocomotiveConfig.buttonOk.addActionListener(e2 ->{
|
||||
frameLocomotiveConfig.dispose();
|
||||
loco = frameLocomotiveConfig._formLocomotiveConfig._loco;
|
||||
if(loco != null){
|
||||
if (obj.AddOverload(loco)!= -1) {
|
||||
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Объект добавлен");
|
||||
Refresh();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frameLocomotiveConfig._formLocomotiveConfig.buttonClose.addActionListener(e3 -> {
|
||||
frameLocomotiveConfig.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
ButtonCreateRandomLoco.addActionListener(e -> {
|
||||
if (frameDopClassParameters != null) frameDopClassParameters.dispose();
|
||||
frameDopClassParameters = new FrameDopClassParameters();
|
||||
frameDopClassParameters.setVisible(true);
|
||||
});
|
||||
|
||||
ButtonRemoveLocomotive.addActionListener(e -> {
|
||||
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
var obj = _storage.get(listBoxStorage.getSelectedValue().toString());
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
int pos;
|
||||
try {
|
||||
pos = Integer.parseInt(textFieldNumber.getText());
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Неверное значение",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
Object[] options = {"Да", "Нет"};
|
||||
int n = JOptionPane.showOptionDialog(this.getPictureBoxCollections(),
|
||||
"Удалить объект?",
|
||||
"Все серьезно",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]
|
||||
);
|
||||
if (n == 1) {
|
||||
return;
|
||||
}
|
||||
DrawingLocomotive removedPlane = obj.SubOverload(pos);
|
||||
if (removedPlane != null) {
|
||||
_stackRemoveObjects.push(removedPlane);
|
||||
Refresh();
|
||||
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Объект удален",
|
||||
"Успех",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Не удалось удалить объект",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
ButtonRefreshCollection.addActionListener(e -> {
|
||||
Refresh();
|
||||
});
|
||||
|
||||
Button_OpenFormRemovedLocomotives.addActionListener(e -> {
|
||||
if(_stackRemoveObjects.empty()) {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Вы ничего не удалили, кажется...",
|
||||
"ой",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
_frameRemovedLocomotives = new FrameElectricLocomotive();
|
||||
_frameRemovedLocomotives._formElectricLocomotive._drawingLocomotive = _stackRemoveObjects.pop();
|
||||
_frameRemovedLocomotives.setVisible(true);
|
||||
_frameRemovedLocomotives._formElectricLocomotive.Draw();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public JMenuBar getMenuBar() {
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
JMenu fileMenu = new JMenu("Файл");
|
||||
JMenuItem openItem = new JMenuItem("Загрузить");
|
||||
openItem.addActionListener(
|
||||
e -> {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
fileChooser.setDialogTitle("Выберите файл для загрузки данных");
|
||||
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
if (_storage.LoadData(selectedFile.getAbsolutePath())) {
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
);
|
||||
JMenuItem saveItem = new JMenuItem("Сохранить");
|
||||
saveItem.addActionListener(
|
||||
e -> {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setDialogTitle("Выберите файл для сохранения данных");
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
if (_storage.SaveData(selectedFile.getAbsolutePath()))
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
else
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
);
|
||||
JMenuItem openItemSingle = new JMenuItem("Загрузить коллекцию");
|
||||
openItemSingle.addActionListener(
|
||||
e -> {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
fileChooser.setDialogTitle("Выберите файл для загрузки данных");
|
||||
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
if (_storage.LoadDataSingle(selectedFile.getAbsolutePath())) {
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
);
|
||||
JMenuItem saveItemSingle = new JMenuItem("Сохранить коллекцию");
|
||||
saveItemSingle.addActionListener(
|
||||
e -> {
|
||||
if (listBoxStorage.getSelectedValue() == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
fileChooser.setDialogTitle("Выберите файл для сохранения данных");
|
||||
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
if (_storage.SaveDataSingle(selectedFile.getAbsolutePath(), (String) listBoxStorage.getSelectedValue()))
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
else
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
);
|
||||
fileMenu.add(openItem);
|
||||
fileMenu.add(saveItem);
|
||||
fileMenu.add(openItemSingle);
|
||||
fileMenu.add(saveItemSingle);
|
||||
menuBar.add(fileMenu);
|
||||
return menuBar;
|
||||
}
|
||||
|
||||
private void ReloadObjects() {
|
||||
int index = listBoxStorage.getSelectedIndex();
|
||||
listBoxStorage.setListData(_storage.Keys().toArray());
|
||||
if (listBoxStorage.getModel().getSize() > 0 && (index == -1 || index >= listBoxStorage.getModel().getSize())) {
|
||||
listBoxStorage.setSelectedIndex(0);
|
||||
} else if (listBoxStorage.getModel().getSize() > 0 && index > -1 && index < listBoxStorage.getModel().getSize()) {
|
||||
listBoxStorage.setSelectedIndex(index);
|
||||
}
|
||||
listBoxStorage.invalidate();
|
||||
}
|
||||
|
||||
private void listBoxObjectsSelectedIndexChanged(ListSelectionEvent e) {
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Refresh() {
|
||||
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
var obj = _storage.get(listBoxStorage.getSelectedValue().toString());
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = pictureBoxCollections.getGraphics();
|
||||
pictureBoxCollections.paint(g);
|
||||
obj.ShowLocomotives(g);
|
||||
}
|
||||
}
|
342
ProjectElectricLocomotive/FormLocomotiveConfig.form
Normal file
342
ProjectElectricLocomotive/FormLocomotiveConfig.form
Normal file
@ -0,0 +1,342 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectElectricLocomotive.FormLocomotiveConfig">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="980" height="500"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<maximumSize width="900" height="500"/>
|
||||
<minimumSize width="900" height="500"/>
|
||||
<preferredSize width="900" height="500"/>
|
||||
<requestFocusEnabled value="true"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="4a7b" binding="groupBoxObjectParameters" layout-manager="GridLayoutManager" row-count="10" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="600" height="400"/>
|
||||
<preferred-size width="600" height="400"/>
|
||||
<maximum-size width="600" height="400"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6e44e" class="javax.swing.JCheckBox" binding="checkBoxSeifBatteries">
|
||||
<constraints>
|
||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Признак наличия батарей"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="b49a8" binding="groupBoxColors" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="6" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="210" height="200"/>
|
||||
<preferred-size width="210" height="200"/>
|
||||
<maximum-size width="210" height="200"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value=""/>
|
||||
<toolTipText value=""/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="b01e9" binding="violetPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-6471681"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="f87f2" binding="orangePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-14018"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="b9af1" binding="yellowPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-984665"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="31fc0" binding="ligthBluePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-7678209"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="15de0" binding="melissePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-12845126"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="dd90a" binding="bluePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-10459905"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="9944c" binding="redPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1222825"/>
|
||||
<foreground color="-4511466"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="6d24f" binding="ligthGreenPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-6094977"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="f8fb4" class="javax.swing.JLabel" binding="labelSpeed">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Скорость"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6d54a" class="javax.swing.JSpinner" binding="numericUpDownSpeed" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="3368a" class="javax.swing.JLabel" binding="labelWeight">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Вес"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="73fe9" class="javax.swing.JSpinner" binding="numericUpDownWeight" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="4c1bf" class="javax.swing.JLabel" binding="lableSimpleObject">
|
||||
<constraints>
|
||||
<grid row="6" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Простой"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="cc241" class="javax.swing.JLabel" binding="labelModifiedObject">
|
||||
<constraints>
|
||||
<grid row="6" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-2133636"/>
|
||||
<text value="Сложный"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2e2" class="javax.swing.JCheckBox" binding="checkBoxHorns">
|
||||
<constraints>
|
||||
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Признак наличия рогов"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f2170" class="javax.swing.JLabel" binding="labelCountWheels">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Количество колес"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f9057" class="javax.swing.JSpinner" binding="numericUpDownWheels" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="bddf7" class="javax.swing.JLabel" binding="labelBlackWheels">
|
||||
<constraints>
|
||||
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Черные колеса"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e6296" class="javax.swing.JLabel" binding="labelEmptyWheels">
|
||||
<constraints>
|
||||
<grid row="7" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Пустые колеса"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f3cc8" class="javax.swing.JLabel" binding="labelRainbowWheels">
|
||||
<constraints>
|
||||
<grid row="7" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Радужные колеса"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="8989b" class="javax.swing.JButton" binding="buttonOk">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Добавить"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1efca" class="javax.swing.JButton" binding="buttonClose">
|
||||
<constraints>
|
||||
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Отмена"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="11089" binding="pictureBoxObject" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="300" height="300"/>
|
||||
<preferred-size width="300" height="300"/>
|
||||
<maximum-size width="300" height="300"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="41a80" binding="panelBodyColor" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="60" height="30"/>
|
||||
<preferred-size width="60" height="30"/>
|
||||
<maximum-size width="60" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="9cd35" class="javax.swing.JLabel" binding="labelColor">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="b6d99" binding="panelAdditionalColor" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="60" height="30"/>
|
||||
<preferred-size width="60" height="30"/>
|
||||
<maximum-size width="60" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="a349b" class="javax.swing.JLabel" binding="labelDopColor">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Доп. Цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
369
ProjectElectricLocomotive/FormLocomotiveConfig.java
Normal file
369
ProjectElectricLocomotive/FormLocomotiveConfig.java
Normal file
@ -0,0 +1,369 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.border.Border;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FormLocomotiveConfig{
|
||||
|
||||
public DrawingLocomotive _loco;
|
||||
private JPanel MainPanel;
|
||||
private JPanel groupBoxObjectParameters;
|
||||
private JPanel groupBoxColors;
|
||||
private JSpinner numericUpDownSpeed;
|
||||
private JSpinner numericUpDownWeight;
|
||||
private JLabel labelSpeed;
|
||||
private JLabel labelWeight;
|
||||
private JCheckBox checkBoxHorns;
|
||||
private JCheckBox checkBoxSeifBatteries;
|
||||
public JLabel lableSimpleObject;
|
||||
private JLabel labelModifiedObject;
|
||||
public JButton buttonOk;
|
||||
public JButton buttonClose;
|
||||
private JLabel labelColor;
|
||||
private JLabel labelDopColor;
|
||||
public JComponent pictureBoxObject;
|
||||
private JPanel redPanel;
|
||||
private JPanel orangePanel;
|
||||
private JPanel yellowPanel;
|
||||
private JPanel ligthGreenPanel;
|
||||
private JPanel melissePanel;
|
||||
private JPanel ligthBluePanel;
|
||||
private JPanel bluePanel;
|
||||
private JPanel violetPanel;
|
||||
private JPanel panelBodyColor;
|
||||
private JPanel panelAdditionalColor;
|
||||
private JLabel labelBlackWheels;
|
||||
private JLabel labelCountWheels;
|
||||
private JSpinner numericUpDownWheels;
|
||||
private JLabel labelEmptyWheels;
|
||||
private JLabel labelRainbowWheels;
|
||||
public Canvas canvas;
|
||||
|
||||
public JPanel getPictureBoxObject(){
|
||||
return MainPanel;
|
||||
}
|
||||
|
||||
private class Canvas extends JComponent{
|
||||
public Canvas(){
|
||||
}
|
||||
public void paintComponent (Graphics g){
|
||||
if (_loco == null){
|
||||
return;
|
||||
}
|
||||
super.paintComponents (g) ;
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
_loco.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
// класс для перетаскивания информации из labe'лов
|
||||
private class LabelTransferHandler extends TransferHandler {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new StringSelection(((JLabel)c).getText());
|
||||
}
|
||||
}
|
||||
|
||||
//для перетаскивания цветов
|
||||
private class ColorTransferable implements Transferable {
|
||||
private Color color;
|
||||
private static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color");
|
||||
|
||||
public ColorTransferable(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{colorDataFlavor};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return colorDataFlavor.equals(flavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return color;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//для перетаскивания цвета
|
||||
private class PanelTransferHandler extends TransferHandler {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new ColorTransferable(((JPanel)c).getBackground());
|
||||
}
|
||||
}
|
||||
|
||||
//для обработки "схватывания" label'ов
|
||||
private class LabelMouseAdapter extends MouseAdapter {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JLabel)e.getComponent()).getTransferHandler().exportAsDrag(((JLabel)e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
}
|
||||
|
||||
//для обработки "схватывания" panel'ей
|
||||
private class PanelMouseAdapter extends MouseAdapter{
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JPanel)e.getComponent()).getTransferHandler().exportAsDrag(((JPanel)e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
}
|
||||
|
||||
public FormLocomotiveConfig()
|
||||
{
|
||||
Border br = BorderFactory.createLineBorder(Color.BLACK);
|
||||
|
||||
SpinnerModel numSpeed = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||
numericUpDownSpeed = new JSpinner(numSpeed);
|
||||
|
||||
SpinnerModel numWeight = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||
numericUpDownWeight = new JSpinner(numWeight);
|
||||
|
||||
lableSimpleObject.setTransferHandler(new LabelTransferHandler());
|
||||
lableSimpleObject.addMouseListener(new LabelMouseAdapter());
|
||||
lableSimpleObject.setBorder(br);
|
||||
|
||||
labelModifiedObject.setTransferHandler(new LabelTransferHandler());
|
||||
labelModifiedObject.addMouseListener(new LabelMouseAdapter());
|
||||
labelModifiedObject.setBorder(br);
|
||||
|
||||
labelBlackWheels.setTransferHandler(new TransferHandler(){
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawingWheel());
|
||||
}
|
||||
});
|
||||
labelBlackWheels.addMouseListener(new LabelMouseAdapter());
|
||||
labelBlackWheels.setBorder(br);
|
||||
|
||||
labelEmptyWheels.setTransferHandler(new TransferHandler(){
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawingEmptyWheels());
|
||||
}
|
||||
});
|
||||
labelEmptyWheels.addMouseListener(new LabelMouseAdapter());
|
||||
labelEmptyWheels.setBorder(br);
|
||||
|
||||
labelRainbowWheels.setTransferHandler( new TransferHandler(){
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawingWheelsBlueCrom());
|
||||
}
|
||||
});
|
||||
labelRainbowWheels.addMouseListener(new LabelMouseAdapter());
|
||||
labelRainbowWheels.setBorder(br);
|
||||
|
||||
redPanel.setTransferHandler(new PanelTransferHandler());
|
||||
redPanel.addMouseListener(new PanelMouseAdapter());
|
||||
|
||||
orangePanel.setTransferHandler(new PanelTransferHandler());
|
||||
orangePanel.addMouseListener(new PanelMouseAdapter());
|
||||
|
||||
yellowPanel.setTransferHandler(new PanelTransferHandler());
|
||||
yellowPanel.addMouseListener(new PanelMouseAdapter());
|
||||
|
||||
ligthGreenPanel.setTransferHandler(new PanelTransferHandler());
|
||||
ligthGreenPanel.addMouseListener(new PanelMouseAdapter());
|
||||
|
||||
melissePanel.setTransferHandler(new PanelTransferHandler());
|
||||
melissePanel.addMouseListener(new PanelMouseAdapter());
|
||||
|
||||
ligthBluePanel.setTransferHandler(new PanelTransferHandler());
|
||||
ligthBluePanel.addMouseListener(new PanelMouseAdapter());
|
||||
|
||||
bluePanel.setTransferHandler(new PanelTransferHandler());
|
||||
bluePanel.addMouseListener(new PanelMouseAdapter());
|
||||
|
||||
violetPanel.setTransferHandler(new PanelTransferHandler());
|
||||
violetPanel.addMouseListener(new PanelMouseAdapter());
|
||||
|
||||
labelColor.setBorder(br);
|
||||
labelColor.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support)
|
||||
{
|
||||
try{
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
if(_loco == null) return false;
|
||||
_loco.EntityLocomotive.SetBodyColor(color);
|
||||
|
||||
panelBodyColor.setBackground(color);
|
||||
|
||||
Border border = BorderFactory.createLineBorder(color);
|
||||
|
||||
labelColor.setBorder(border);
|
||||
return true;
|
||||
}
|
||||
catch(UnsupportedFlavorException | IOException e){
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
labelDopColor.setBorder(br);
|
||||
labelDopColor.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support)
|
||||
{
|
||||
try{
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
panelAdditionalColor.setBackground(color);
|
||||
Border border = BorderFactory.createLineBorder(color);
|
||||
labelDopColor.setBorder(border);
|
||||
if(_loco == null) return false;
|
||||
if(!(_loco instanceof DrawingElectricLocomotive))
|
||||
return false;
|
||||
((EntityElectricLocomotive)_loco.EntityLocomotive).SetAdditionalColor(color);
|
||||
return true;
|
||||
}
|
||||
catch(UnsupportedFlavorException | IOException e){
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
pictureBoxObject.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
return support.isDataFlavorSupported(DataFlavor.stringFlavor) || support.isDataFlavorSupported(WheelsTransferable.wheelsDrawingDataFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importData(TransferHandler.TransferSupport support) {
|
||||
if (canImport(support)) {
|
||||
try {
|
||||
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||
switch (data) {
|
||||
case "Простой":
|
||||
_loco = new DrawingLocomotive(
|
||||
(int)numericUpDownSpeed.getValue(),
|
||||
(int)numericUpDownWeight.getValue(),
|
||||
Color.WHITE,
|
||||
pictureBoxObject.getWidth(),
|
||||
pictureBoxObject.getHeight()
|
||||
);
|
||||
break;
|
||||
case "Сложный":
|
||||
_loco = new DrawingElectricLocomotive(
|
||||
(int)numericUpDownSpeed.getValue(),
|
||||
(int)numericUpDownWeight.getValue(),
|
||||
Color.WHITE,
|
||||
Color.BLACK,
|
||||
checkBoxHorns.isSelected(),
|
||||
checkBoxSeifBatteries.isSelected(),
|
||||
pictureBoxObject.getWidth(),
|
||||
pictureBoxObject.getHeight()
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
}
|
||||
try{
|
||||
int wheelsCount = (int)numericUpDownWheels.getValue();
|
||||
IDrawingWheels drawingWheels = (IDrawingWheels) support.getTransferable().getTransferData(WheelsTransferable.wheelsDrawingDataFlavor);
|
||||
_loco._drawingWheels = drawingWheels;
|
||||
_loco.SetWheelsCount(wheelsCount);
|
||||
}catch(UnsupportedFlavorException | IOException e){
|
||||
}
|
||||
pictureBoxObject.repaint();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private class WheelsTransferable implements Transferable {
|
||||
private IDrawingWheels drawingWheels;
|
||||
private static final DataFlavor wheelsDrawingDataFlavor = new DataFlavor(IDrawingWheels.class, "Wheels Drawing");
|
||||
|
||||
public WheelsTransferable(IDrawingWheels drawingWheels) {
|
||||
this.drawingWheels = drawingWheels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{wheelsDrawingDataFlavor};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return flavor.equals(wheelsDrawingDataFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return drawingWheels;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createUIComponents(){
|
||||
pictureBoxObject = new Canvas();
|
||||
pictureBoxObject.setBounds(new Rectangle(300, 300));
|
||||
|
||||
SpinnerModel numSpeed = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||
numericUpDownSpeed = new JSpinner(numSpeed);
|
||||
|
||||
SpinnerModel numWeight = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||
numericUpDownWeight = new JSpinner(numWeight);
|
||||
|
||||
SpinnerModel numWheels = new SpinnerNumberModel(2,2, 4, 1);
|
||||
numericUpDownWheels = new JSpinner(numWheels);
|
||||
}
|
||||
|
||||
}
|
19
ProjectElectricLocomotive/FrameDopClassParameters.java
Normal file
19
ProjectElectricLocomotive/FrameDopClassParameters.java
Normal file
@ -0,0 +1,19 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameDopClassParameters extends JFrame {
|
||||
public FormDopClassParameters _formDopClassParameters;
|
||||
|
||||
public FrameDopClassParameters(){
|
||||
super();
|
||||
setTitle("Рандомный локомотив");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
_formDopClassParameters = new FormDopClassParameters();
|
||||
setContentPane(_formDopClassParameters.getPictureBoxGenerated());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(500, 200);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
18
ProjectElectricLocomotive/FrameElectricLocomotive.java
Normal file
18
ProjectElectricLocomotive/FrameElectricLocomotive.java
Normal file
@ -0,0 +1,18 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameElectricLocomotive extends JFrame {
|
||||
public FormElectricLocomotive _formElectricLocomotive;
|
||||
public FrameElectricLocomotive() {
|
||||
super();
|
||||
setTitle("Электролокомотив");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
_formElectricLocomotive = new FormElectricLocomotive();
|
||||
setContentPane(_formElectricLocomotive.getPictureBox());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(500, 200);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
18
ProjectElectricLocomotive/FrameLocomotiveCollection.java
Normal file
18
ProjectElectricLocomotive/FrameLocomotiveCollection.java
Normal file
@ -0,0 +1,18 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameLocomotiveCollection extends JFrame {
|
||||
public FormLocomotiveCollections _formLocomotiveCollections;
|
||||
public FrameLocomotiveCollection(){
|
||||
super();
|
||||
setTitle("Коллекция");setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
_formLocomotiveCollections = new FormLocomotiveCollections();
|
||||
setContentPane(_formLocomotiveCollections.getPictureBoxCollections());
|
||||
this.setJMenuBar(_formLocomotiveCollections.getMenuBar());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(400, 50);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
23
ProjectElectricLocomotive/FrameLocomotiveConfig.java
Normal file
23
ProjectElectricLocomotive/FrameLocomotiveConfig.java
Normal file
@ -0,0 +1,23 @@
|
||||
package ProjectElectricLocomotive;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
public class FrameLocomotiveConfig extends JFrame{
|
||||
|
||||
|
||||
public FormLocomotiveConfig _formLocomotiveConfig;
|
||||
public FrameLocomotiveConfig() {
|
||||
|
||||
super();
|
||||
setTitle("Конфиг");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
_formLocomotiveConfig = new FormLocomotiveConfig();
|
||||
setContentPane(_formLocomotiveConfig.getPictureBoxObject());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(100, 200);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
}
|
38
ProjectElectricLocomotive/IDrawingWheels.java
Normal file
38
ProjectElectricLocomotive/IDrawingWheels.java
Normal file
@ -0,0 +1,38 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingWheels {
|
||||
void SetWheelsCount(int wheelsCount);
|
||||
|
||||
WheelsCount GetWheelsCount();
|
||||
|
||||
void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h);
|
||||
|
||||
default void DrawWheels(Graphics g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight){
|
||||
WheelsCount wheelsCount = GetWheelsCount();
|
||||
if(wheelsCount == null) return;
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
int wheelWidth = 9;
|
||||
int wheelHeight = 9;
|
||||
|
||||
if(wheelsCount.count <= wheelsCount.Two.count){
|
||||
DrawWheel(g2d, color, startPosX + 95, startPosY + 45, 9, 9);
|
||||
DrawWheel(g2d, color, startPosX + 140, startPosY + 45, 9, 9);
|
||||
}
|
||||
|
||||
if (wheelsCount.count == wheelsCount.Three.count) {
|
||||
DrawWheel(g2d, color, startPosX + 95, startPosY + 45, 9, 9);
|
||||
DrawWheel(g2d, color, startPosX + 140, startPosY + 45, 9, 9);
|
||||
|
||||
DrawWheel(g2d, color, startPosX + 105, startPosY + 45, wheelWidth, wheelHeight);
|
||||
}
|
||||
if (wheelsCount.count == wheelsCount.Four.count) {
|
||||
DrawWheel(g2d, color, startPosX + 95, startPosY + 45, 9, 9);
|
||||
DrawWheel(g2d, color, startPosX + 140, startPosY + 45, 9, 9);
|
||||
|
||||
DrawWheel(g2d, color, startPosX + 105, startPosY + 45, wheelWidth, wheelHeight);
|
||||
DrawWheel(g2d, color, startPosX + 130, startPosY + 45, wheelWidth, wheelHeight);
|
||||
}
|
||||
}
|
||||
}
|
9
ProjectElectricLocomotive/IMoveableObject.java
Normal file
9
ProjectElectricLocomotive/IMoveableObject.java
Normal file
@ -0,0 +1,9 @@
|
||||
package ProjectElectricLocomotive;
|
||||
import java.awt.*;
|
||||
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters GetObjectPosition();
|
||||
int GetStep();
|
||||
boolean CheckCanMove(DyrectionType direction);
|
||||
void MoveObject(DyrectionType direction);
|
||||
}
|
98
ProjectElectricLocomotive/LocomotiveGenericCollection.java
Normal file
98
ProjectElectricLocomotive/LocomotiveGenericCollection.java
Normal file
@ -0,0 +1,98 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class LocomotiveGenericCollection<T extends DrawingLocomotive,U extends IMoveableObject>
|
||||
{
|
||||
//ширина/высота окна
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
|
||||
//ширина/высота занимаемого места
|
||||
private final int _placeSizeWidth = 150;
|
||||
private final int _placeSizeHeight = 50;
|
||||
|
||||
/// Набор объектов
|
||||
private final SetGeneric<T> _collection;
|
||||
|
||||
public LocomotiveGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width*height);
|
||||
}
|
||||
|
||||
public Iterable<T> GetLocomotives(){
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
|
||||
/// Перегрузка оператора сложения
|
||||
//да емае, почему в яве все по-другому?...
|
||||
public int AddOverload(T obj){
|
||||
if(obj == null){
|
||||
return -1;
|
||||
}
|
||||
return _collection.Insert(obj);
|
||||
}
|
||||
|
||||
public T SubOverload(int pos)
|
||||
{
|
||||
T loco = _collection.Get(pos);
|
||||
if (loco != null)
|
||||
{
|
||||
_collection.Remove(pos);
|
||||
}
|
||||
return loco;
|
||||
}
|
||||
|
||||
// получение объекта imoveableObj
|
||||
public U GetU(int pos)
|
||||
{
|
||||
return (U)_collection.Get(pos).GetMoveableObject();
|
||||
}
|
||||
|
||||
/// Вывод всего набора объектов
|
||||
public void ShowLocomotives(Graphics gr)
|
||||
{
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
}
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Color blackColor = Color.BLACK;
|
||||
g.setColor(blackColor);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
//линия рамзетки места
|
||||
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int HeightObjCount = _pictureHeight / _placeSizeHeight;
|
||||
int i = 0;
|
||||
for (var obj : _collection.GetEnumerator())
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
obj.SetPosition(
|
||||
(int)(i / HeightObjCount * _placeSizeWidth),
|
||||
(HeightObjCount - 1) * _placeSizeHeight - (int)(i % HeightObjCount * _placeSizeHeight)
|
||||
);
|
||||
obj.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
_collection.clear();
|
||||
}
|
||||
}
|
192
ProjectElectricLocomotive/LocomotivesGenericStorage.java
Normal file
192
ProjectElectricLocomotive/LocomotivesGenericStorage.java
Normal file
@ -0,0 +1,192 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LocomotivesGenericStorage {
|
||||
|
||||
private static final String _separatorForKeyValue = "@";
|
||||
private static final String _separatorRecords = ";";
|
||||
private static final String _separatorForObject = ":";
|
||||
private static final String _separatorForObjectSingle = "::";
|
||||
private static final String _keyword = "PlanesStorage";
|
||||
private static final String _keywordSingle = "PlanesStorageSingle";
|
||||
|
||||
final HashMap<String, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> _locomotiveStorage;
|
||||
|
||||
public List<String> Keys() {
|
||||
return _locomotiveStorage.keySet().stream().toList();
|
||||
}
|
||||
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
|
||||
public LocomotivesGenericStorage(int pictureWidth, int pictureHeight) {
|
||||
_locomotiveStorage = new HashMap<>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddSet(String name) {
|
||||
if (!(_locomotiveStorage.containsKey(name))) {
|
||||
_locomotiveStorage.put(name, new LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
}
|
||||
|
||||
public void DelSet(String name) {
|
||||
if (_locomotiveStorage.keySet().contains(name)) {
|
||||
_locomotiveStorage.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> get(String ind) {
|
||||
if (_locomotiveStorage.keySet().contains(ind)) {
|
||||
return _locomotiveStorage.get(ind);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public DrawingObjectLocomotive get(String name, int ind) {
|
||||
if (_locomotiveStorage.keySet().contains(ind)) {
|
||||
return _locomotiveStorage.get(name).GetU(ind);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean SaveDataSingle(String filename, String key) {
|
||||
var file = new File(filename);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
StringBuilder data = new StringBuilder();
|
||||
data.append(key).append("\n");
|
||||
for (DrawingLocomotive elem : _locomotiveStorage.get(key).GetLocomotives())
|
||||
data.append(elem != null ? ExtentionDrawingLoco.GetDataForSave(elem, _separatorForObjectSingle) + "\n" : "");
|
||||
if (data.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
||||
writer.write(_keywordSingle + System.lineSeparator() + data);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean LoadDataSingle(String filename){
|
||||
if (!new File(filename).exists()) {
|
||||
return false;
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||
String s = reader.readLine();
|
||||
if (s == null || s.isEmpty())
|
||||
return false;
|
||||
if (!s.startsWith(_keywordSingle))
|
||||
return false;
|
||||
String key = reader.readLine();
|
||||
if (key == null || key.isEmpty())
|
||||
return false;
|
||||
LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> collection;
|
||||
if (_locomotiveStorage.containsKey(key)){
|
||||
collection = _locomotiveStorage.get(key);
|
||||
collection.clear();
|
||||
}
|
||||
else
|
||||
collection = new LocomotiveGenericCollection<>(_pictureWidth, _pictureHeight);
|
||||
List<String> plainsStrings = new ArrayList<>();
|
||||
s = reader.readLine();
|
||||
while (s != null && !s.isEmpty()){
|
||||
plainsStrings.add(s);
|
||||
s = reader.readLine();
|
||||
}
|
||||
Collections.reverse(plainsStrings);
|
||||
for (String elem : plainsStrings) {
|
||||
DrawingLocomotive plane = ExtentionDrawingLoco.CreateDrawingLocomotive(
|
||||
elem,
|
||||
_separatorForObjectSingle,
|
||||
_pictureWidth,
|
||||
_pictureHeight
|
||||
);
|
||||
if (plane == null || collection.AddOverload(plane) == -1)
|
||||
return false;
|
||||
}
|
||||
_locomotiveStorage.put(key, collection);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean SaveData(String filename) {
|
||||
var file = new File(filename);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
StringBuilder data = new StringBuilder();
|
||||
for (Map.Entry<String, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> record : _locomotiveStorage.entrySet()) {
|
||||
StringBuilder records = new StringBuilder();
|
||||
for (DrawingLocomotive elem : record.getValue().GetLocomotives()) {
|
||||
records.append(elem != null ? ExtentionDrawingLoco.GetDataForSave(elem, _separatorForObject) + _separatorRecords : "");
|
||||
}
|
||||
data.append(record.getKey()).append(_separatorForKeyValue).append(records).append("\n");
|
||||
}
|
||||
if (data.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
||||
writer.write(_keyword + System.lineSeparator() + data);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean LoadData(String filename) {
|
||||
var file = new File(filename);
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||
String s = reader.readLine();
|
||||
if (s == null || s.isEmpty())
|
||||
return false;
|
||||
|
||||
if (!s.startsWith(_keyword)) {
|
||||
return false;
|
||||
}
|
||||
_locomotiveStorage.clear();
|
||||
s = reader.readLine();
|
||||
while (s != null && !s.isEmpty()) {
|
||||
String[] record = s.split(_separatorForKeyValue);
|
||||
s = reader.readLine();
|
||||
if (record.length != 2) {
|
||||
continue;
|
||||
}
|
||||
LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> collection = new LocomotiveGenericCollection<>(_pictureWidth, _pictureHeight);
|
||||
String[] set = record[1].split(_separatorRecords);
|
||||
List<String> reversedSet = Arrays.asList(set);
|
||||
Collections.reverse(reversedSet);
|
||||
for (String elem : reversedSet) {
|
||||
DrawingLocomotive plane = ExtentionDrawingLoco.CreateDrawingLocomotive(
|
||||
elem,
|
||||
_separatorForObject,
|
||||
_pictureWidth, _pictureHeight
|
||||
);
|
||||
if (plane == null || collection.AddOverload(plane) == -1)
|
||||
return false;
|
||||
}
|
||||
_locomotiveStorage.put(record[0], collection);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
8
ProjectElectricLocomotive/Main.java
Normal file
8
ProjectElectricLocomotive/Main.java
Normal file
@ -0,0 +1,8 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
FrameLocomotiveCollection mainFrame = new FrameLocomotiveCollection();
|
||||
}
|
||||
}
|
45
ProjectElectricLocomotive/MoveToCenter.java
Normal file
45
ProjectElectricLocomotive/MoveToCenter.java
Normal file
@ -0,0 +1,45 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy{
|
||||
@Override
|
||||
protected boolean IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) return false;
|
||||
|
||||
return objParams.ObjectMiddleHorizontal() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal() + GetStep()
|
||||
>= FieldWidth / 2 && objParams.ObjectMiddleVertical() <= FieldHeight / 2 && objParams.ObjectMiddleVertical()
|
||||
+ GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) return;
|
||||
var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
||||
if (Math.abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
||||
if (Math.abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
ProjectElectricLocomotive/MoveToRigthCorner.java
Normal file
21
ProjectElectricLocomotive/MoveToRigthCorner.java
Normal file
@ -0,0 +1,21 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
public class MoveToRigthCorner extends AbstractStrategy {
|
||||
@Override
|
||||
protected boolean IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) return false;
|
||||
|
||||
return objParams.RightBorder() >= FieldWidth - GetStep() && objParams.DownBorder() >= FieldHeight - GetStep();
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) return;
|
||||
|
||||
if (objParams.RightBorder() < FieldWidth - GetStep()) MoveRight();
|
||||
if (objParams.DownBorder() < FieldHeight - GetStep()) MoveDown();
|
||||
}
|
||||
}
|
51
ProjectElectricLocomotive/ObjectParameters.java
Normal file
51
ProjectElectricLocomotive/ObjectParameters.java
Normal file
@ -0,0 +1,51 @@
|
||||
package ProjectElectricLocomotive;
|
||||
public class ObjectParameters {
|
||||
private final int _x;
|
||||
private final int _y;
|
||||
private final int _width;
|
||||
private final int _height;
|
||||
|
||||
/// Левая граница
|
||||
public int LeftBorder()
|
||||
{
|
||||
return _x;
|
||||
};
|
||||
|
||||
/// Верхняя граница
|
||||
public int TopBorder()
|
||||
{
|
||||
return _y;
|
||||
}
|
||||
|
||||
/// Правая граница
|
||||
public int RightBorder()
|
||||
{
|
||||
return _x + _width;
|
||||
}
|
||||
|
||||
/// Нижняя граница
|
||||
public int DownBorder()
|
||||
{
|
||||
return _y + _height;
|
||||
}
|
||||
|
||||
/// Середина объекта по горизонтали
|
||||
public int ObjectMiddleHorizontal()
|
||||
{
|
||||
return _x + _width / 2;
|
||||
}
|
||||
|
||||
/// Середина объекта по вертикали
|
||||
public int ObjectMiddleVertical()
|
||||
{
|
||||
return _y + _height / 2;
|
||||
}
|
||||
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
72
ProjectElectricLocomotive/SetGeneric.java
Normal file
72
ProjectElectricLocomotive/SetGeneric.java
Normal file
@ -0,0 +1,72 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SetGeneric<T extends DrawingLocomotive>{
|
||||
private ArrayList<T> _places;
|
||||
|
||||
public int Count()
|
||||
{
|
||||
return _places.size();
|
||||
}
|
||||
|
||||
public int maxCount;
|
||||
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
maxCount = count;
|
||||
_places = new ArrayList<>(count);
|
||||
}
|
||||
|
||||
public int Insert(T loco)
|
||||
{
|
||||
return Insert(loco, 0);
|
||||
}
|
||||
|
||||
public int Insert(T loco, int position)
|
||||
{
|
||||
if(position < 0 || position > maxCount)
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
_places.add(position, loco);
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= Count() || position < 0)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
T plane = _places.get(position);
|
||||
_places.set(position, null);
|
||||
return plane;
|
||||
}
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count()) return null;
|
||||
return _places.get(position);
|
||||
}
|
||||
|
||||
public void Set(int position, T loco) {
|
||||
// Проверка позиции
|
||||
// Проверка свободных мест в списке
|
||||
if (position < 0 || position >= maxCount || Count() == maxCount) {
|
||||
return;
|
||||
}
|
||||
// Вставка в список по позиции
|
||||
_places.set(position, loco);
|
||||
}
|
||||
|
||||
public ArrayList<T> GetEnumerator() {
|
||||
return _places;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
_places.clear();
|
||||
}
|
||||
}
|
7
ProjectElectricLocomotive/Status.java
Normal file
7
ProjectElectricLocomotive/Status.java
Normal file
@ -0,0 +1,7 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
public enum Status {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
9
ProjectElectricLocomotive/WheelsCount.java
Normal file
9
ProjectElectricLocomotive/WheelsCount.java
Normal file
@ -0,0 +1,9 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
public enum WheelsCount {
|
||||
Two(2), Three(3), Four(4);
|
||||
public final int count;
|
||||
WheelsCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
BIN
ProjectElectricLocomotive/img/arrowDown.jpg
Normal file
BIN
ProjectElectricLocomotive/img/arrowDown.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 702 B |
BIN
ProjectElectricLocomotive/img/arrowLeft.jpg
Normal file
BIN
ProjectElectricLocomotive/img/arrowLeft.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 706 B |
BIN
ProjectElectricLocomotive/img/arrowRight.jpg
Normal file
BIN
ProjectElectricLocomotive/img/arrowRight.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 702 B |
BIN
ProjectElectricLocomotive/img/arrowUp.jpg
Normal file
BIN
ProjectElectricLocomotive/img/arrowUp.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 706 B |
Loading…
x
Reference in New Issue
Block a user