Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
e4bc1f1bfa | |||
|
ccf821d1b3 | ||
|
4fee4eecd4 | ||
|
1aa0c3e971 | ||
|
bf3fe46f43 | ||
|
eb8da47163 | ||
|
04338dc298 | ||
|
cece533ed5 | ||
|
09b0b76e4d | ||
|
702e485daa | ||
|
2038303ee1 | ||
|
6d4b66fe00 | ||
|
ef8c9c6e6b | ||
|
3e27acda2c | ||
ae4cefd616 | |||
|
7072feff6d | ||
|
f6ba6fe601 | ||
|
f1f7561301 | ||
|
a27cb59ee0 | ||
7fb5ba8c39 | |||
|
fac7aba105 | ||
|
80f133e150 | ||
|
6b543de74e | ||
|
c913a06626 |
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
Main.java
|
3
.idea/uiDesigner.xml
generated
3
.idea/uiDesigner.xml
generated
@ -119,6 +119,9 @@
|
||||
<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>
|
||||
<item class="FormCatamaran" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
@ -3,6 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/Resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
BIN
ProjectCatamaran/Resources/30px_arrow_down.png
Normal file
BIN
ProjectCatamaran/Resources/30px_arrow_down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 244 B |
BIN
ProjectCatamaran/Resources/30px_arrow_left.png
Normal file
BIN
ProjectCatamaran/Resources/30px_arrow_left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 249 B |
BIN
ProjectCatamaran/Resources/30px_arrow_right.png
Normal file
BIN
ProjectCatamaran/Resources/30px_arrow_right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 254 B |
BIN
ProjectCatamaran/Resources/30px_arrow_up.png
Normal file
BIN
ProjectCatamaran/Resources/30px_arrow_up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 B |
@ -0,0 +1,60 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningBoat;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractCompany {
|
||||
protected final int _placeSizeWidth = 210;
|
||||
protected final int _placeSizeHeight = 120;
|
||||
protected final int _pictureWidth;
|
||||
protected final int _pictureHeight;
|
||||
protected ICollectionGenericObjects<DrawningBoat> _collection = null;
|
||||
public int getMaxCount() {
|
||||
return _pictureWidth * _pictureHeight / (_placeSizeWidth*_placeSizeHeight);
|
||||
}
|
||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection) {
|
||||
this._pictureWidth = picWidth;
|
||||
this._pictureHeight = picHeight;
|
||||
this._collection = collection;
|
||||
int maxCount = getMaxCount();
|
||||
_collection.setMaxCount(maxCount);
|
||||
}
|
||||
public static int add(AbstractCompany company ,DrawningBoat boat) {
|
||||
if (company._collection == null) {
|
||||
return -1;
|
||||
}
|
||||
return company._collection.insert(boat);
|
||||
}
|
||||
|
||||
public static DrawningBoat remove(AbstractCompany company, int position) {
|
||||
if (company._collection == null) {
|
||||
return null;
|
||||
}
|
||||
return company._collection.remove(position);
|
||||
}
|
||||
public DrawningBoat getRandomObject() {
|
||||
if (_collection == null) {
|
||||
return null;
|
||||
}
|
||||
Random rnd = new Random();
|
||||
return _collection.get(rnd.nextInt(0, _collection.getCount() + 1));
|
||||
}
|
||||
public void show(Graphics g) {
|
||||
drawBackground(g);
|
||||
setObjectsPosition();
|
||||
if (_collection == null) {
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < _collection.getCount(); i++) {
|
||||
if(_collection.get(i) != null) {
|
||||
_collection.get(i).drawBoat(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected abstract void drawBackground(Graphics g);
|
||||
protected abstract void setObjectsPosition();
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningBoat;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BoatSharingService extends AbstractCompany {
|
||||
private final List<Point> locCoord = new ArrayList<>();
|
||||
private int numRows, numCols;
|
||||
public BoatSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection) {
|
||||
super(picWidth, picHeight, collection);
|
||||
_collection.setMaxCount(30);
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void drawBackground(Graphics g) {
|
||||
Color backgroundColor = new Color(135, 206, 235);
|
||||
|
||||
g.setColor(backgroundColor);
|
||||
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
||||
|
||||
g.setColor(new Color(165, 42, 42)); // Brown
|
||||
int offsetX = 10, offsetY = -5;
|
||||
int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY;
|
||||
numRows = 0;
|
||||
while (y >= 0) {
|
||||
int numCols = 0;
|
||||
while (x + _placeSizeWidth <= _pictureWidth) {
|
||||
numCols++;
|
||||
g.drawLine(x, y, x + _placeSizeWidth / 2, y);
|
||||
g.drawLine(x, y, x, y + _placeSizeHeight + 4);
|
||||
locCoord.add(new Point(x, y));
|
||||
x += _placeSizeWidth + 2;
|
||||
}
|
||||
numRows++;
|
||||
x = 1 + offsetX;
|
||||
y -= _placeSizeHeight + 5 + offsetY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setObjectsPosition() {
|
||||
if (locCoord == null || _collection == null) {
|
||||
return;
|
||||
}
|
||||
int row = numRows - 1, col = numCols;
|
||||
for (int i=0;i< _collection.getCount(); i++, col--) {
|
||||
if (_collection.get(i) != null) {
|
||||
_collection.get(i).setPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.get(i).setPosition((int)locCoord.get(row*numCols - col).getX() + 5,
|
||||
(int)locCoord.get(row*numCols - col).getY() + 9);
|
||||
if (col == 1) {
|
||||
col = numCols + 1;
|
||||
row--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
public enum CollectionType {
|
||||
None(0),
|
||||
Massive(1),
|
||||
List(2);
|
||||
|
||||
final private int collectionTypeValue;
|
||||
|
||||
CollectionType(int value){
|
||||
collectionTypeValue = value;
|
||||
}
|
||||
public int getCollectionTypeValue() {
|
||||
return collectionTypeValue;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningBoat;
|
||||
import Drawnings.DrawningCatamaran;
|
||||
import Drawnings.IDrawPaddles;
|
||||
import Entities.EntityBoat;
|
||||
import Entities.EntityCatamaran;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class Constructor<T extends EntityBoat, U extends IDrawPaddles> {
|
||||
private ArrayList<T> entitiesList = new ArrayList<>();
|
||||
private ArrayList<U> paddlesList = new ArrayList<>();
|
||||
public void addBoat(T obj) {
|
||||
entitiesList.add(obj);
|
||||
}
|
||||
public void addBoat(U obj) {
|
||||
paddlesList.add(obj);
|
||||
}
|
||||
|
||||
public DrawningBoat getRandomBoat() {
|
||||
Random rnd = new Random();
|
||||
int entityIndex = rnd.nextInt(0, 3);
|
||||
int paddlesIndex = rnd.nextInt(0, 3);
|
||||
|
||||
T entity = entitiesList.get(entityIndex);
|
||||
U paddles = paddlesList.get(paddlesIndex);
|
||||
|
||||
return (entity instanceof EntityCatamaran) ?
|
||||
new DrawningCatamaran((EntityCatamaran) entity, paddles) :
|
||||
new DrawningBoat(entity, paddles);
|
||||
}
|
||||
|
||||
public String getEntityDescription(int index) {
|
||||
if (index < 0 || index >= entitiesList.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
T entity = entitiesList.get(index);
|
||||
String entityClassName = (entity instanceof EntityCatamaran) ? "EntityCatamaran" : "EntityBoat";
|
||||
|
||||
return String.format("<html><i><u>%s</u></i> = %s</html>", entityClassName, entity);
|
||||
}
|
||||
|
||||
public String getPaddlesDescription(int index) {
|
||||
if (index < 0 || index >= paddlesList.size()) {
|
||||
return null;
|
||||
}
|
||||
return paddlesList.get(index).toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningBoat;
|
||||
|
||||
public interface ICollectionGenericObjects<T extends DrawningBoat> {
|
||||
int getCount();
|
||||
|
||||
void setMaxCount(int count);
|
||||
|
||||
int insert(T obj);
|
||||
|
||||
int insert(T obj, int index);
|
||||
|
||||
T remove(int index);
|
||||
|
||||
T get(int index);
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningBoat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ListGenericCollection<T extends DrawningBoat> implements ICollectionGenericObjects<T> {
|
||||
private final ArrayList<T> _collection;
|
||||
public ListGenericCollection() {
|
||||
_collection = new ArrayList<>();
|
||||
}
|
||||
private int maxCount;
|
||||
public int count;
|
||||
@Override
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
@Override
|
||||
public void setMaxCount(int count) {
|
||||
maxCount = count;
|
||||
}
|
||||
@Override
|
||||
public int insert(T obj) {
|
||||
return insert(obj, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(T obj, int index) {
|
||||
if (index > maxCount || index < 0 || index > count){
|
||||
return -1;
|
||||
}
|
||||
if(index == count){
|
||||
_collection.add(obj);
|
||||
}
|
||||
else {
|
||||
_collection.add(index, obj);
|
||||
}
|
||||
count = _collection.size();
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int index) {
|
||||
if (index > maxCount || index < 0 || index >= count){
|
||||
return null;
|
||||
}
|
||||
count = _collection.size() - 1;
|
||||
return _collection.remove(index);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int index) {
|
||||
if (index >= count){
|
||||
return null;
|
||||
}
|
||||
return _collection.get(index);
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningBoat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MassiveGenericObjects<T extends DrawningBoat> implements ICollectionGenericObjects<T> {
|
||||
private ArrayList<T> _collection;
|
||||
public MassiveGenericObjects() {
|
||||
_collection = new ArrayList<>();
|
||||
|
||||
}
|
||||
int maxCount = 0;
|
||||
int realSize = 0;
|
||||
@Override
|
||||
public int getCount() {
|
||||
return _collection.size();
|
||||
}
|
||||
@Override
|
||||
public int insert(T obj) {
|
||||
return insert(obj, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(T obj, int position) {
|
||||
if (position > maxCount|| position < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = position; i < maxCount; i++) {
|
||||
if (_collection.get(i) == null) {
|
||||
_collection.set(i, obj);
|
||||
realSize++;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
for (int i = position; i > 0; i--) {
|
||||
if (_collection.get(i) == null) {
|
||||
_collection.set(i, obj);
|
||||
realSize++;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int position) {
|
||||
if (position < 0 || position >= maxCount) {
|
||||
return null;
|
||||
}
|
||||
if (_collection.get(position) != null) {
|
||||
T bf = _collection.get(position);
|
||||
_collection.set(position, null);
|
||||
--realSize;
|
||||
return bf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int position) {
|
||||
if (position >= 0 && position < _collection.size()) {
|
||||
return _collection.get(position);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxCount(int count) {
|
||||
if (count > 0) {
|
||||
if (!_collection.isEmpty()) {
|
||||
ArrayList<T> bfLoc = new ArrayList<>(count);
|
||||
bfLoc.addAll(0, _collection);
|
||||
_collection = bfLoc;
|
||||
for (int i = 0; i < count - maxCount; i++) {
|
||||
_collection.add(null);
|
||||
}
|
||||
} else {
|
||||
_collection = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
_collection.add(null);
|
||||
}
|
||||
|
||||
}
|
||||
maxCount = count;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningBoat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class StorageCollection<T extends DrawningBoat> {
|
||||
private final HashMap<String, ICollectionGenericObjects<T>> _storages;
|
||||
public final ArrayList<String> keys;
|
||||
|
||||
public StorageCollection() {
|
||||
_storages = new HashMap<>();
|
||||
keys = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addCollection(String name, CollectionType collectionType){
|
||||
if (_storages.containsKey(name) || name.isEmpty()){
|
||||
return;
|
||||
}
|
||||
switch (collectionType){
|
||||
case None:
|
||||
return;
|
||||
case Massive:
|
||||
_storages.put(name, new MassiveGenericObjects<>());
|
||||
keys.add(name);
|
||||
break;
|
||||
case List:
|
||||
_storages.put(name, new ListGenericCollection<>());
|
||||
keys.add(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void delCollection(String name){
|
||||
_storages.remove(name);
|
||||
keys.remove(name);
|
||||
}
|
||||
|
||||
public ICollectionGenericObjects<T> getCollection(String name){
|
||||
return _storages.get(name);
|
||||
}
|
||||
|
||||
public T getObjectFromChooseCollection(String name, int ind){
|
||||
return this.getCollection(name).get(ind);
|
||||
}
|
||||
|
||||
}
|
182
ProjectCatamaran/src/Drawnings/DrawningAbstractCompany.java
Normal file
182
ProjectCatamaran/src/Drawnings/DrawningAbstractCompany.java
Normal file
@ -0,0 +1,182 @@
|
||||
package Drawnings;
|
||||
|
||||
import CollectionGenericObjects.*;
|
||||
|
||||
import CollectionGenericObjects.MassiveGenericObjects;
|
||||
import Forms.FormCatamaran;
|
||||
import Forms.FormConstructor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.Random;
|
||||
import java.util.Stack;
|
||||
|
||||
public class DrawningAbstractCompany extends JComponent {
|
||||
private AbstractCompany _company = null;
|
||||
|
||||
private final StorageCollection<DrawningBoat> storageCollection = new StorageCollection<>();
|
||||
private Stack<DrawningBoat> rubbishBinStack = new Stack<>();
|
||||
public boolean collectionComboBox_SelectedIndexChanged(JFrame frame, JList<String> collectionList, JComboBox<String> obj, int width, int height) {
|
||||
switch (obj.getSelectedIndex()) {
|
||||
case 1:
|
||||
if (collectionList.getSelectedIndex() == -1) {
|
||||
JOptionPane.showMessageDialog(frame,
|
||||
"Коллекция не выбрана");
|
||||
return false;
|
||||
}
|
||||
_company = new BoatSharingService(width, height,storageCollection.getCollection(collectionList.getSelectedValue()));
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void createObject(int type, JFrame obj) {
|
||||
if (_company == null) {
|
||||
return;
|
||||
}
|
||||
DrawningBoat _drawningBoat;
|
||||
Random random = new Random();
|
||||
switch (type) {
|
||||
case 0:
|
||||
_drawningBoat = new DrawningBoat(random.nextInt(70 - 30) + 30, random.nextInt(500 - 100) + 100,
|
||||
getColorR(obj, random), random.nextInt(3));
|
||||
break;
|
||||
case 1:
|
||||
_drawningBoat = new DrawningCatamaran(random.nextInt(70 - 30) + 30, random.nextInt(500 - 100) + 100,
|
||||
getColorR(obj, random), random.nextInt(3),
|
||||
getColorR(obj, random),
|
||||
random.nextBoolean(), random.nextBoolean());
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (AbstractCompany.add(_company, _drawningBoat) != -1) {
|
||||
JOptionPane.showMessageDialog(obj, "Объект добавлен");
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(obj, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
Color getColorR(JFrame obj, Random rnd) {
|
||||
Color color = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256));
|
||||
if (obj == null) {
|
||||
return color;
|
||||
}
|
||||
JColorChooser colorChooser = new JColorChooser();
|
||||
colorChooser.setColor(color);
|
||||
return JColorChooser.showDialog(obj, "Выберите цвет", color);
|
||||
}
|
||||
|
||||
public boolean deleteButtonAction(int val, Frame obj) {
|
||||
if (_company == null) {
|
||||
return false;
|
||||
}
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
obj,
|
||||
"Удалить объект?",
|
||||
"Подтвердение",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
DrawningBoat deletableBoat = AbstractCompany.remove(_company, val);
|
||||
if (deletableBoat != null) {
|
||||
rubbishBinStack.add(deletableBoat);
|
||||
JOptionPane.showMessageDialog(obj, "Выполнено");
|
||||
return true;
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(obj, "Удаление не удалось");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void goToCheckButtonAction() {
|
||||
if (_company == null) {
|
||||
return;
|
||||
}
|
||||
DrawningBoat boat = null;
|
||||
int counter = 100;
|
||||
while (boat == null && counter > 0) {
|
||||
boat = _company.getRandomObject();
|
||||
--counter;
|
||||
}
|
||||
if (boat == null) {
|
||||
return;
|
||||
}
|
||||
createFormCatamaran(boat);
|
||||
|
||||
}
|
||||
|
||||
public boolean goToCheckFromRubbishBinAction() {
|
||||
if (rubbishBinStack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
DrawningBoat boat = rubbishBinStack.pop();
|
||||
createFormCatamaran(boat);
|
||||
return !rubbishBinStack.isEmpty();
|
||||
}
|
||||
|
||||
public void createFormCatamaran(DrawningBoat boat) {
|
||||
FormCatamaran formCatamaran = new FormCatamaran();
|
||||
formCatamaran.setDrawningBoat(boat);
|
||||
formCatamaran.OpenFrame();
|
||||
}
|
||||
|
||||
private DrawningBoat createObject;
|
||||
public void getObjFromConstructor(JFrame obj) {
|
||||
if (_company == null) {
|
||||
return;
|
||||
}
|
||||
FormConstructor formConstructor = new FormConstructor();
|
||||
formConstructor.OpenFrame();
|
||||
|
||||
formConstructor.getAddButton().addActionListener(e -> {
|
||||
createObject = formConstructor.getConstructor().getObj();
|
||||
if (AbstractCompany.add(_company, createObject) != -1) {
|
||||
JOptionPane.showMessageDialog(obj, "Выполнено");
|
||||
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(obj, "Добавление не удалось");
|
||||
}
|
||||
obj.repaint();
|
||||
formConstructor.getjFrameConstructor().dispatchEvent(new WindowEvent(formConstructor.getjFrameConstructor(), WindowEvent.WINDOW_CLOSING));
|
||||
});
|
||||
}
|
||||
|
||||
public StorageCollection<DrawningBoat> addCollectionButtonAction(JFrame jFrameCollectionBoats, JTextField textFieldSetCollectionName,
|
||||
JRadioButton massiveRadioButton, JRadioButton listRadioButton) {
|
||||
|
||||
if (textFieldSetCollectionName.getText().isEmpty() || (!massiveRadioButton.isSelected() && !listRadioButton.isSelected())) {
|
||||
JOptionPane.showMessageDialog(jFrameCollectionBoats, "Не все элементы заполнены", "ERROR", JOptionPane.ERROR_MESSAGE);
|
||||
return null;
|
||||
}
|
||||
CollectionType collectionType = CollectionType.None;
|
||||
if (massiveRadioButton.isSelected())
|
||||
collectionType = CollectionType.Massive;
|
||||
else if (listRadioButton.isSelected())
|
||||
collectionType = CollectionType.List;
|
||||
storageCollection.addCollection(textFieldSetCollectionName.getText(), collectionType);
|
||||
return storageCollection;
|
||||
}
|
||||
public StorageCollection<DrawningBoat> deleteCollectionButtonAction(JFrame jFrameCollectionLocomotive, JList<String> keysList) {
|
||||
if (keysList.getSelectedIndex() != -1) {
|
||||
int result = JOptionPane.showConfirmDialog( jFrameCollectionLocomotive, "Удалить объект?",
|
||||
"Подтверждение", JOptionPane.YES_NO_OPTION);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
storageCollection.delCollection(keysList.getSelectedValue());
|
||||
return storageCollection;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (_company == null) {
|
||||
return;
|
||||
}
|
||||
_company.show(g);
|
||||
}
|
||||
}
|
146
ProjectCatamaran/src/Drawnings/DrawningBoat.java
Normal file
146
ProjectCatamaran/src/Drawnings/DrawningBoat.java
Normal file
@ -0,0 +1,146 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.*;
|
||||
import MovementStrategy.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningBoat {
|
||||
public Entities.EntityBoat entityBoat;
|
||||
public EntityBoat getEntityBoat() {
|
||||
return entityBoat;
|
||||
}
|
||||
private Integer _pictureWidth;
|
||||
private Integer _pictureHeight;
|
||||
protected Integer _startPosX;
|
||||
protected Integer _startPosY;
|
||||
private int _drawingBoatWidth = 107;
|
||||
private int _drawingBoatHeight = 80;
|
||||
public Integer GetPosX(){return _startPosX;}
|
||||
public Integer GetPosY(){return _startPosY;}
|
||||
public int GetWidth(){return _drawingBoatWidth;}
|
||||
public int GetHeight(){return _drawingBoatHeight;}
|
||||
public IDrawPaddles drawPaddles;
|
||||
|
||||
public DrawningBoat(int speed, float weight, Color bodyColor, int paddlesType) {
|
||||
entityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||
_startPosY = null;
|
||||
_startPosX = null;
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
switch (paddlesType) {
|
||||
case 0:
|
||||
drawPaddles = new DrawningPaddles();
|
||||
break;
|
||||
case 1:
|
||||
drawPaddles = new DrawningOvalPaddles();
|
||||
break;
|
||||
case 2:
|
||||
drawPaddles = new DrawningRectanglePaddles();
|
||||
break;
|
||||
}
|
||||
Random random = new Random();
|
||||
int paddlesCount = random.nextInt(1,4);
|
||||
drawPaddles.setNumber(paddlesCount);
|
||||
|
||||
}
|
||||
|
||||
protected DrawningBoat(int speed, float weight, Color bodyColor, int paddlesType, int boatWidth, int boatHeight) {
|
||||
this(speed, weight, bodyColor, paddlesType);
|
||||
_drawingBoatHeight = boatHeight;
|
||||
_drawingBoatWidth = boatWidth;
|
||||
|
||||
}
|
||||
public DrawningBoat(EntityBoat _entityBoat, IDrawPaddles _drawPaddles) {
|
||||
entityBoat = _entityBoat;
|
||||
drawPaddles = _drawPaddles;
|
||||
}
|
||||
public void setPosition(int x, int y) {
|
||||
if (_pictureHeight == null || _pictureWidth == null)
|
||||
return;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if (_drawingBoatWidth + x > _pictureWidth || x < 0) {
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_drawingBoatHeight + y > _pictureHeight || y < 0) {
|
||||
_startPosY = 0;
|
||||
}
|
||||
}
|
||||
public boolean setPictureSize(int width, int height) {
|
||||
|
||||
if (_drawingBoatHeight > height || _drawingBoatWidth > width)
|
||||
return false;
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = width;
|
||||
|
||||
if (_startPosX != null && _startPosY != null)
|
||||
{
|
||||
if (_startPosX + _drawingBoatWidth > width)
|
||||
_startPosX = width - _drawingBoatWidth;
|
||||
if (_startPosY + _drawingBoatHeight > height)
|
||||
_startPosY = height - _drawingBoatHeight;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean moveTransport(MovementDirection direction) {
|
||||
if (entityBoat == null || _pictureWidth == null || _pictureHeight == null)
|
||||
return false;
|
||||
switch (direction) {
|
||||
case MovementDirection.Left:
|
||||
if (_startPosX - entityBoat.getStep() > 0)
|
||||
_startPosX -= (int) entityBoat.getStep();
|
||||
return true;
|
||||
case MovementDirection.Up:
|
||||
if (_startPosY - entityBoat.getStep() > 0)
|
||||
_startPosY -= (int) entityBoat.getStep();
|
||||
return true;
|
||||
case MovementDirection.Right:
|
||||
if (_startPosX + entityBoat.getStep() < _pictureWidth - _drawingBoatWidth)
|
||||
_startPosX += (int) entityBoat.getStep();
|
||||
return true;
|
||||
case MovementDirection.Down:
|
||||
if (_startPosY + entityBoat.getStep() < _pictureHeight - _drawingBoatHeight)
|
||||
_startPosY += (int) entityBoat.getStep();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void drawBoat(Graphics g) {
|
||||
if (entityBoat == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
Point[] boatBorders = new Point[]{
|
||||
new Point(_startPosX + 10, _startPosY + 20),
|
||||
new Point(_startPosX + 80, _startPosY + 20),
|
||||
new Point(_startPosX + 107, _startPosY + 40),
|
||||
new Point(_startPosX + 80, _startPosY + 55),
|
||||
new Point(_startPosX + 10, _startPosY + 55)
|
||||
};
|
||||
|
||||
Polygon catamaranPolygon = new Polygon();
|
||||
for (Point point : boatBorders)
|
||||
catamaranPolygon.addPoint(point.x, point.y);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.draw(catamaranPolygon);
|
||||
g2d.setColor(entityBoat.getBodyColor());
|
||||
g2d.fill(catamaranPolygon);
|
||||
|
||||
int ellipseX = _startPosX + 17;
|
||||
int ellipseY = _startPosY + 24;
|
||||
int ellipseWidth = 65;
|
||||
int ellipseHeight = 27;
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(ellipseX, ellipseY, ellipseWidth, ellipseHeight);
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.fillOval(ellipseX, ellipseY, ellipseWidth, ellipseHeight);
|
||||
|
||||
drawPaddles.drawPaddles(g2d, entityBoat.getBodyColor(), _startPosX, _startPosY);
|
||||
}
|
||||
}
|
73
ProjectCatamaran/src/Drawnings/DrawningCatamaran.java
Normal file
73
ProjectCatamaran/src/Drawnings/DrawningCatamaran.java
Normal file
@ -0,0 +1,73 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningCatamaran extends DrawningBoat {
|
||||
public DrawningCatamaran(int speed, float weight, Color bodyColor, int paddlesType, Color additionalColor, boolean sail, boolean floaters) {
|
||||
super(speed, weight, bodyColor, paddlesType, 110, 80);
|
||||
entityBoat = new EntityCatamaran(speed, weight, bodyColor, additionalColor, floaters, sail);
|
||||
}
|
||||
public DrawningCatamaran(EntityCatamaran entity, IDrawPaddles paddles) {
|
||||
super(entity, paddles);
|
||||
}
|
||||
private void drawFloater(int y0, Color additionalColor, Graphics2D g2d)
|
||||
{
|
||||
g2d.setColor(additionalColor);
|
||||
g2d.setStroke(new BasicStroke(2));
|
||||
Point[] floater = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 10, _startPosY + y0 + 6),
|
||||
new Point(_startPosX + 90, _startPosY + y0 + 6),
|
||||
new Point(_startPosX + 110, _startPosY + y0 + 3),
|
||||
new Point(_startPosX + 90, _startPosY + y0),
|
||||
new Point(_startPosX + 10, _startPosY + y0),
|
||||
|
||||
};
|
||||
Polygon floaterPolygon = new Polygon();
|
||||
for (Point point: floater) {
|
||||
floaterPolygon.addPoint(point.x, point.y);
|
||||
}
|
||||
g2d.fillPolygon(floaterPolygon);
|
||||
g2d.drawPolygon(floaterPolygon);
|
||||
}
|
||||
@Override
|
||||
public void drawBoat(Graphics g) {
|
||||
|
||||
if (entityBoat == null || !(entityBoat instanceof EntityCatamaran entityCatamaran) || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
super.drawBoat(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
if (entityCatamaran.getFloaters()) {
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawLine(_startPosX+20, _startPosY+20, _startPosX + 20, _startPosY+17);
|
||||
g2d.drawLine(_startPosX+80, _startPosY+20, _startPosX + 80, _startPosY+17);
|
||||
g2d.drawLine(_startPosX+20, _startPosY+55, _startPosX + 20, _startPosY+58);
|
||||
g2d.drawLine(_startPosX+80, _startPosY+55, _startPosX + 80, _startPosY+58);
|
||||
|
||||
drawFloater(11, entityCatamaran.getAdditionalColor(), g2d);
|
||||
drawFloater(58, entityCatamaran.getAdditionalColor(), g2d);
|
||||
}
|
||||
|
||||
if (entityCatamaran.getSail()) {
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.setStroke(new BasicStroke(1));
|
||||
Point[] sail = new Point[] {
|
||||
new Point(_startPosX + 50, _startPosY + 45),
|
||||
new Point(_startPosX + 35, _startPosY + 39),
|
||||
new Point(_startPosX + 35, _startPosY + 24),
|
||||
new Point(_startPosX + 50, _startPosY + 18),
|
||||
new Point(_startPosX + 50, _startPosY + 43),
|
||||
};
|
||||
Polygon sailPolygon = new Polygon();
|
||||
for(Point point: sail) {
|
||||
sailPolygon.addPoint(point.x, point.y);
|
||||
}
|
||||
g2d.drawPolygon(sailPolygon);
|
||||
g2d.setColor(entityCatamaran.getAdditionalColor());
|
||||
g2d.fillPolygon(sailPolygon);
|
||||
}
|
||||
}
|
||||
}
|
79
ProjectCatamaran/src/Drawnings/DrawningConstructor.java
Normal file
79
ProjectCatamaran/src/Drawnings/DrawningConstructor.java
Normal file
@ -0,0 +1,79 @@
|
||||
package Drawnings;
|
||||
|
||||
import CollectionGenericObjects.Constructor;
|
||||
import Entities.EntityBoat;
|
||||
import Entities.EntityCatamaran;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningConstructor extends JComponent {
|
||||
|
||||
Constructor<EntityBoat, IDrawPaddles> constructor = new Constructor<>();
|
||||
private DrawningBoat obj;
|
||||
public DrawningBoat getObj() {
|
||||
return obj;
|
||||
}
|
||||
public DrawningConstructor() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
EntityBoat _entityBoat = null;
|
||||
IDrawPaddles _drawPaddles = null;
|
||||
Random rnd = new Random();
|
||||
int paddlesType = rnd.nextInt(3);
|
||||
switch (paddlesType) {
|
||||
case 0:
|
||||
_drawPaddles = new DrawningPaddles();
|
||||
break;
|
||||
case 1:
|
||||
_drawPaddles = new DrawningOvalPaddles();
|
||||
break;
|
||||
case 2:
|
||||
_drawPaddles = new DrawningRectanglePaddles();
|
||||
break;
|
||||
}
|
||||
int paddlesCount = rnd.nextInt(1,4);
|
||||
_drawPaddles.setNumber(paddlesCount);
|
||||
|
||||
int typeBoat = rnd.nextInt(0,2);
|
||||
|
||||
switch (typeBoat) {
|
||||
case 0:
|
||||
_entityBoat = new EntityBoat(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100,
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
|
||||
break;
|
||||
case 1:
|
||||
_entityBoat = new EntityCatamaran(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100,
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean());
|
||||
break;
|
||||
}
|
||||
constructor.addBoat(_entityBoat);
|
||||
constructor.addBoat(_drawPaddles);
|
||||
}
|
||||
obj = constructor.getRandomBoat();
|
||||
|
||||
}
|
||||
public void reCreateObj() {
|
||||
obj = constructor.getRandomBoat();
|
||||
}
|
||||
|
||||
public String getEntityString(int index) {
|
||||
return constructor.getEntityDescription(index);
|
||||
}
|
||||
public String getPaddlesString(int index) {
|
||||
return constructor.getPaddlesDescription(index);
|
||||
}
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (obj != null) {
|
||||
obj.setPosition(10, 30);
|
||||
obj.setPictureSize(400, 300);
|
||||
obj.drawBoat(g);
|
||||
}
|
||||
super.repaint();
|
||||
|
||||
}
|
||||
}
|
71
ProjectCatamaran/src/Drawnings/DrawningFormCatamaran.java
Normal file
71
ProjectCatamaran/src/Drawnings/DrawningFormCatamaran.java
Normal file
@ -0,0 +1,71 @@
|
||||
package Drawnings;
|
||||
|
||||
import MovementStrategy.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningFormCatamaran extends JComponent {
|
||||
DrawningBoat drawningBoat;
|
||||
|
||||
private int _pictureHeight = -1;
|
||||
private int _pictureWidth = -1;
|
||||
private AbstractStrategy _strategy;
|
||||
public void setDrawningBoat(DrawningBoat drawningBoat) {
|
||||
this.drawningBoat = drawningBoat;
|
||||
}
|
||||
|
||||
public boolean setPictureSize(int width, int height) {
|
||||
if (drawningBoat.GetHeight() > height || drawningBoat.GetWidth() > width)
|
||||
return false;
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = width;
|
||||
return true;
|
||||
}
|
||||
public void buttonStrategyStep(JComboBox<String> comboBox) {
|
||||
if (drawningBoat == null)
|
||||
return;
|
||||
if (comboBox.isEnabled()) {
|
||||
switch (comboBox.getSelectedIndex()) {
|
||||
case 0:
|
||||
_strategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_strategy = new MoveToBorder();
|
||||
break;
|
||||
|
||||
default:
|
||||
_strategy = null;
|
||||
break;
|
||||
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableBoat(drawningBoat), _pictureWidth, _pictureHeight);
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
comboBox.setEnabled(false);
|
||||
_strategy.MakeStep();
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish) {
|
||||
comboBox.setEnabled(true);
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
}
|
||||
public void MoveButtonsAction(MovementDirection direction) {
|
||||
if (drawningBoat == null)
|
||||
return;
|
||||
drawningBoat.moveTransport(direction);
|
||||
}
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (drawningBoat == null) {
|
||||
return;
|
||||
}
|
||||
drawningBoat.drawBoat(g);
|
||||
}
|
||||
}
|
43
ProjectCatamaran/src/Drawnings/DrawningOvalPaddles.java
Normal file
43
ProjectCatamaran/src/Drawnings/DrawningOvalPaddles.java
Normal file
@ -0,0 +1,43 @@
|
||||
package Drawnings;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningOvalPaddles implements IDrawPaddles {
|
||||
private PaddlesCount _paddlesCount;
|
||||
|
||||
@Override
|
||||
public void setNumber(int paddlesCount) {
|
||||
for (PaddlesCount value : PaddlesCount.values()) {
|
||||
if (value.getEnumNumber() == paddlesCount) {
|
||||
_paddlesCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawPaddles(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
int distanceBetweenPaddles = 27;
|
||||
for (int i = 0; i < _paddlesCount.getEnumNumber(); i++) {
|
||||
int posX = (int)(_startX + i * distanceBetweenPaddles); // Позиция X для текущей пары весел
|
||||
drawPaddlePair(g2d, posX, (int)_startY + 5);
|
||||
}
|
||||
|
||||
}
|
||||
private void drawPaddlePair(Graphics2D g2d, int posX, int posY) {
|
||||
g2d.drawLine(posX + 20, posY + 15, posX + 9, posY - 3); // Рисуем левое весло
|
||||
g2d.drawLine(posX + 20, posY + 50, posX + 9, posY + 68); // Рисуем правое весло
|
||||
|
||||
// Добавляем овалы на концы весел
|
||||
int ovalSize = 10; // Размер овала
|
||||
int halfStrokeWidth = 2; // Половина толщины линии
|
||||
g2d.fillOval(posX + 9 - halfStrokeWidth - ovalSize / 2, posY + 68 - ovalSize / 2, ovalSize, ovalSize);
|
||||
g2d.fillOval(posX + 9 - halfStrokeWidth - ovalSize / 2, posY - 3 - ovalSize / 2, ovalSize, ovalSize);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = "";
|
||||
buffer += "Тип: овальные, Количество вёсел: " + _paddlesCount.getEnumNumber() * 2;
|
||||
return buffer;
|
||||
}
|
||||
}
|
37
ProjectCatamaran/src/Drawnings/DrawningPaddles.java
Normal file
37
ProjectCatamaran/src/Drawnings/DrawningPaddles.java
Normal file
@ -0,0 +1,37 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningPaddles implements IDrawPaddles {
|
||||
private PaddlesCount _paddlesCount;
|
||||
@Override
|
||||
public void setNumber(int paddlesCount) {
|
||||
for (PaddlesCount value : PaddlesCount.values()) {
|
||||
if (value.getEnumNumber() == paddlesCount) {
|
||||
_paddlesCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawPaddles(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
int distanceBetweenPaddles = 27;
|
||||
for (int i = 0; i < _paddlesCount.getEnumNumber(); i++) {
|
||||
int posX = (int)(_startX + i * distanceBetweenPaddles); // Позиция X для текущей пары весел
|
||||
drawPaddlePair(g2d, posX, (int)_startY + 5);
|
||||
|
||||
}
|
||||
}
|
||||
private void drawPaddlePair(Graphics2D g2d, int posX, int posY) {
|
||||
g2d.drawLine(posX + 20, posY + 15, posX + 9, posY - 3); // Рисуем левое весло
|
||||
g2d.drawLine(posX + 20, posY + 50, posX + 9, posY + 68); // Рисуем правое весло
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = "";
|
||||
buffer += "Тип: обычные, Количество вёсел: " + _paddlesCount.getEnumNumber() * 2;
|
||||
return buffer;
|
||||
}
|
||||
}
|
45
ProjectCatamaran/src/Drawnings/DrawningRectanglePaddles.java
Normal file
45
ProjectCatamaran/src/Drawnings/DrawningRectanglePaddles.java
Normal file
@ -0,0 +1,45 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningRectanglePaddles implements IDrawPaddles {
|
||||
private PaddlesCount _paddlesCount;
|
||||
|
||||
@Override
|
||||
public void setNumber(int paddlesCount) {
|
||||
for (PaddlesCount value : PaddlesCount.values()) {
|
||||
if (value.getEnumNumber() == paddlesCount) {
|
||||
_paddlesCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPaddles(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
int distanceBetweenPaddles = 27;
|
||||
for (int i = 0; i < _paddlesCount.getEnumNumber(); i++) {
|
||||
int posX = (int)(_startX + i * distanceBetweenPaddles); // Позиция X для текущей пары весел
|
||||
drawPaddlePair(g2d, posX, (int)_startY + 5);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPaddlePair(Graphics2D g2d, int posX, int posY) {
|
||||
g2d.drawLine(posX + 20, posY + 15, posX + 9, posY - 3); // Рисуем левое весло
|
||||
g2d.drawLine(posX + 20, posY + 50, posX + 9, posY + 68); // Рисуем правое весло
|
||||
|
||||
int rectangleSize = 8; // Размер прямоугольника
|
||||
int halfStrokeWidth = 2; // Половина толщины линии
|
||||
// Добавляем прямоугольники на концы весел
|
||||
g2d.fillRect(posX + 9 - halfStrokeWidth - rectangleSize / 2, posY + 68 - rectangleSize / 2, rectangleSize, rectangleSize);
|
||||
g2d.fillRect(posX + 9 - halfStrokeWidth - rectangleSize / 2, posY - 3 - rectangleSize / 2, rectangleSize, rectangleSize);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = "";
|
||||
buffer += "Тип: прямоугольники, Количество вёсел: " + _paddlesCount.getEnumNumber() * 2;
|
||||
return buffer;
|
||||
}
|
||||
}
|
8
ProjectCatamaran/src/Drawnings/IDrawPaddles.java
Normal file
8
ProjectCatamaran/src/Drawnings/IDrawPaddles.java
Normal file
@ -0,0 +1,8 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawPaddles {
|
||||
void setNumber(int x);
|
||||
void drawPaddles(Graphics2D graphics2D, Color color, int _startX, int _startY);
|
||||
}
|
14
ProjectCatamaran/src/Drawnings/PaddlesCount.java
Normal file
14
ProjectCatamaran/src/Drawnings/PaddlesCount.java
Normal file
@ -0,0 +1,14 @@
|
||||
package Drawnings;
|
||||
|
||||
public enum PaddlesCount {
|
||||
One(1),
|
||||
Two(2),
|
||||
Three(3);
|
||||
final private int EnumNumber;
|
||||
PaddlesCount(int enumNumber) {
|
||||
EnumNumber = enumNumber;
|
||||
}
|
||||
public int getEnumNumber() {
|
||||
return EnumNumber;
|
||||
}
|
||||
}
|
38
ProjectCatamaran/src/Entities/EntityBoat.java
Normal file
38
ProjectCatamaran/src/Entities/EntityBoat.java
Normal file
@ -0,0 +1,38 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityBoat {
|
||||
private int Speed;
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
private double Weight;
|
||||
public double getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
private Color BodyColor;
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
private double Step;
|
||||
public double getStep() {
|
||||
return Speed*100/Weight;
|
||||
}
|
||||
|
||||
public EntityBoat(int speed, double weight, Color bodyColor) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = "";
|
||||
buffer += "Скорость: " + this.Speed;
|
||||
buffer += ", Вес: " + this.Weight;
|
||||
buffer += String.format(", Основной цвет : RGB{%d, %d, %d}",
|
||||
this.BodyColor.getRed(), this.BodyColor.getGreen(), this.BodyColor.getBlue());
|
||||
return buffer;
|
||||
}
|
||||
}
|
33
ProjectCatamaran/src/Entities/EntityCatamaran.java
Normal file
33
ProjectCatamaran/src/Entities/EntityCatamaran.java
Normal file
@ -0,0 +1,33 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityCatamaran extends EntityBoat {
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
private boolean Sail;
|
||||
public boolean getSail() {
|
||||
return Sail;
|
||||
}
|
||||
private boolean Floaters;
|
||||
public boolean getFloaters() {
|
||||
return Floaters;
|
||||
}
|
||||
public EntityCatamaran(int speed, double weight, Color bodyColor ,Color additionalColor, boolean sail, boolean floaters) {
|
||||
super(speed, weight, bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
Sail = sail;
|
||||
Floaters = floaters;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = super.toString();
|
||||
buffer += String.format(", Дополнительный цвет : RGB{%d, %d, %d}",
|
||||
this.AdditionalColor.getRed(), this.AdditionalColor.getGreen(), this.AdditionalColor.getBlue());
|
||||
buffer += ", Парус: " + this.Sail;
|
||||
buffer += ", Поплавки: " + this.Floaters;
|
||||
return buffer;
|
||||
}
|
||||
}
|
293
ProjectCatamaran/src/Forms/FormBoatCollection.java
Normal file
293
ProjectCatamaran/src/Forms/FormBoatCollection.java
Normal file
@ -0,0 +1,293 @@
|
||||
package Forms;
|
||||
|
||||
import CollectionGenericObjects.CollectionType;
|
||||
import CollectionGenericObjects.StorageCollection;
|
||||
import Drawnings.DrawningAbstractCompany;
|
||||
import Drawnings.DrawningBoat;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.NumberFormatter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class FormBoatCollection extends JFrame {
|
||||
final private JFrame jFrameCollectionBoats = new JFrame();
|
||||
final private DrawningAbstractCompany _company = new DrawningAbstractCompany();
|
||||
final private JButton refreshButton = new JButton("Обновить");
|
||||
final private JPanel refreshPanel = new JPanel();
|
||||
final private String[] listOfComboBox = {
|
||||
|
||||
"",
|
||||
"Хранилище"
|
||||
};
|
||||
final private JComboBox<String> comboBoxSelectorCompany = new JComboBox<>(listOfComboBox);
|
||||
final private JPanel comboBoxPanel = new JPanel();
|
||||
final private JPanel toolsPanel = new JPanel();
|
||||
final private JLabel toolsNameLabel = new JLabel("Инструменты");
|
||||
final private JPanel labelPanel = new JPanel();
|
||||
final private JButton buttonAddBoat = new JButton("Добавить лодку");
|
||||
final private JButton buttonAddCatamaran = new JButton("Добавить катамаран");
|
||||
final private JPanel addBoatPanel = new JPanel();
|
||||
final private JPanel addCatamaranPanel = new JPanel();
|
||||
final private JButton buttonRemove = new JButton("Удалить лолку");
|
||||
final private JPanel removePanel = new JPanel();
|
||||
final private JButton goToCheckButton = new JButton("Отправит на тесты");
|
||||
final private JPanel goToCheckPanel = new JPanel();
|
||||
final private JPanel addFromConstructorPanel = new JPanel();
|
||||
final private JButton addFromConstructorButton = new JButton("Добавить из констркутора");
|
||||
|
||||
final JRadioButton massiveRadioButton = new JRadioButton("Массив");
|
||||
final JRadioButton listRadioButton = new JRadioButton("Лист");
|
||||
final JPanel radioButtonsPanel = new JPanel();
|
||||
|
||||
final JButton addCollectionButton = new JButton("Добавить коллекцию");
|
||||
final JPanel addCollectionPanel = new JPanel();
|
||||
|
||||
|
||||
final JButton createCompanyButton = new JButton("Создать компанию");
|
||||
final JPanel createCompanyPanel = new JPanel();
|
||||
|
||||
|
||||
final JButton deleteCollectionButton = new JButton("Удалить коллекцию");
|
||||
final JPanel deleteCollectionPanel = new JPanel();
|
||||
|
||||
DefaultListModel<String> listModel = new DefaultListModel<>();
|
||||
JList<String> collectionsList = new JList<>(listModel);
|
||||
final JPanel collectionsListPanel = new JPanel();
|
||||
|
||||
final JTextField setCollectionName = new JTextField();
|
||||
final JLabel setCollectionNameLabel = new JLabel("Название коллекции:");
|
||||
final JPanel setCollectionNamePanel = new JPanel();
|
||||
|
||||
final private ArrayList<Component> listOfDownPanel = new ArrayList<>();
|
||||
|
||||
final private JButton goGoToCheckFromRubbishBinButton = new JButton("<html><center>Отправить на тест<br> объект из мусорки</html>");
|
||||
final private JPanel goGoToCheckFromRubbishBinPanel = new JPanel();
|
||||
|
||||
public void OpenFrame() {
|
||||
|
||||
jFrameCollectionBoats.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||
Dimension dimension = tolls.getScreenSize();
|
||||
jFrameCollectionBoats.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||
1200, 665);
|
||||
jFrameCollectionBoats.setTitle("Коллекция лодок");
|
||||
|
||||
toolsPanel.setBackground(Color.BLACK);
|
||||
labelPanel.setSize(new Dimension(100, 20));
|
||||
labelPanel.add(toolsNameLabel);
|
||||
|
||||
comboBoxPanel.setLayout(new BorderLayout());
|
||||
comboBoxPanel.setSize(new Dimension(170, 25));
|
||||
comboBoxPanel.add(comboBoxSelectorCompany, BorderLayout.CENTER);
|
||||
|
||||
addBoatPanel.setLayout(new BorderLayout());
|
||||
addBoatPanel.setSize(170, 25);
|
||||
addBoatPanel.add(buttonAddBoat, BorderLayout.CENTER);
|
||||
|
||||
addCatamaranPanel.setLayout(new BorderLayout());
|
||||
addCatamaranPanel.setSize(170, 25);
|
||||
addCatamaranPanel.add(buttonAddCatamaran, BorderLayout.CENTER);
|
||||
|
||||
removePanel.setLayout(new BorderLayout());
|
||||
removePanel.setSize(170, 25);
|
||||
removePanel.add(buttonRemove, BorderLayout.CENTER);
|
||||
|
||||
goToCheckPanel.setLayout(new BorderLayout());
|
||||
goToCheckPanel.setSize(170, 25);
|
||||
goToCheckPanel.add(goToCheckButton, BorderLayout.CENTER);
|
||||
|
||||
refreshPanel.setLayout(new BorderLayout());
|
||||
refreshPanel.setSize(170, 25);
|
||||
refreshPanel.add(refreshButton, BorderLayout.CENTER);
|
||||
|
||||
addFromConstructorPanel.setLayout(new BorderLayout());
|
||||
addFromConstructorPanel.setSize(170, 25);
|
||||
addFromConstructorPanel.add(addFromConstructorButton, BorderLayout.CENTER);
|
||||
|
||||
setCollectionNamePanel.setLayout(new BorderLayout());
|
||||
setCollectionNamePanel.setSize(170, 45);
|
||||
setCollectionNamePanel.add(setCollectionNameLabel, BorderLayout.NORTH);
|
||||
setCollectionNamePanel.add(setCollectionName, BorderLayout.SOUTH);
|
||||
|
||||
radioButtonsPanel.setLayout(new BorderLayout());
|
||||
radioButtonsPanel.setSize(170, 25);
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(massiveRadioButton);
|
||||
group.add(listRadioButton);
|
||||
radioButtonsPanel.add(massiveRadioButton, BorderLayout.WEST);
|
||||
radioButtonsPanel.add(listRadioButton, BorderLayout.EAST);
|
||||
|
||||
addCollectionPanel.setLayout(new BorderLayout());
|
||||
addCollectionPanel.setSize(170, 30);
|
||||
addCollectionPanel.add(addCollectionButton, BorderLayout.CENTER);
|
||||
|
||||
collectionsListPanel.setLayout(new BorderLayout());
|
||||
collectionsListPanel.setSize(170, 100);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(collectionsList);
|
||||
collectionsListPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
deleteCollectionPanel.setLayout(new BorderLayout());
|
||||
deleteCollectionPanel.setSize(170, 30);
|
||||
deleteCollectionPanel.add(deleteCollectionButton, BorderLayout.CENTER);
|
||||
|
||||
createCompanyPanel.setLayout(new BorderLayout());
|
||||
createCompanyPanel.setSize(170, 30);
|
||||
createCompanyPanel.add(createCompanyButton, BorderLayout.CENTER);
|
||||
|
||||
goGoToCheckFromRubbishBinPanel.setLayout(new BorderLayout());
|
||||
goGoToCheckFromRubbishBinPanel.setSize(170, 50);
|
||||
goGoToCheckFromRubbishBinPanel.add(goGoToCheckFromRubbishBinButton, BorderLayout.CENTER);
|
||||
|
||||
NumberFormat format = NumberFormat.getInstance();
|
||||
NumberFormatter formatter = new NumberFormatter(format);
|
||||
formatter.setValueClass(Integer.class);
|
||||
formatter.setMinimum(0);
|
||||
formatter.setMaximum(100);
|
||||
formatter.setAllowsInvalid(true);
|
||||
formatter.setCommitsOnValidEdit(true);
|
||||
|
||||
JTextField textBoxPosition = new JFormattedTextField(formatter);
|
||||
JPanel textBoxPanel = new JPanel();
|
||||
textBoxPanel.setLayout(new BorderLayout());
|
||||
textBoxPanel.setSize(170, 25);
|
||||
textBoxPanel.add(textBoxPosition, BorderLayout.CENTER);
|
||||
|
||||
jFrameCollectionBoats.add(toolsPanel);
|
||||
jFrameCollectionBoats.add(labelPanel);
|
||||
jFrameCollectionBoats.add(setCollectionNamePanel);
|
||||
jFrameCollectionBoats.add(radioButtonsPanel);
|
||||
jFrameCollectionBoats.add(addCollectionPanel);
|
||||
jFrameCollectionBoats.add(collectionsListPanel);
|
||||
jFrameCollectionBoats.add(deleteCollectionPanel);
|
||||
jFrameCollectionBoats.add(comboBoxPanel);
|
||||
jFrameCollectionBoats.add(createCompanyPanel);
|
||||
jFrameCollectionBoats.add(addBoatPanel);
|
||||
jFrameCollectionBoats.add(addCatamaranPanel);
|
||||
jFrameCollectionBoats.add(textBoxPanel);
|
||||
jFrameCollectionBoats.add(removePanel);
|
||||
jFrameCollectionBoats.add(goToCheckPanel);
|
||||
jFrameCollectionBoats.add(refreshPanel);
|
||||
jFrameCollectionBoats.add(addFromConstructorPanel);
|
||||
jFrameCollectionBoats.add(goGoToCheckFromRubbishBinPanel);
|
||||
jFrameCollectionBoats.add(_company);
|
||||
|
||||
listOfDownPanel.add(buttonAddBoat);
|
||||
listOfDownPanel.add(buttonAddCatamaran);
|
||||
listOfDownPanel.add(addFromConstructorButton);
|
||||
listOfDownPanel.add(textBoxPosition);
|
||||
listOfDownPanel.add(buttonRemove);
|
||||
listOfDownPanel.add(goToCheckButton);
|
||||
listOfDownPanel.add(goGoToCheckFromRubbishBinButton);
|
||||
listOfDownPanel.add(refreshButton);
|
||||
|
||||
setEnableComponentsOfList(listOfDownPanel, false);
|
||||
jFrameCollectionBoats.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent componentEvent) {
|
||||
|
||||
labelPanel.setLocation(jFrameCollectionBoats.getWidth() - 210, 0);
|
||||
toolsPanel.setLocation(jFrameCollectionBoats.getWidth() - 233, 0);
|
||||
setCollectionNamePanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 30);
|
||||
radioButtonsPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 78);
|
||||
addCollectionPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 103);
|
||||
collectionsListPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 137);
|
||||
deleteCollectionPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 227);
|
||||
comboBoxPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 400);
|
||||
createCompanyPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 370);
|
||||
goToCheckPanel.setLocation(jFrameCollectionBoats.getWidth() - 200,
|
||||
jFrameCollectionBoats.getHeight() - 320);
|
||||
goGoToCheckFromRubbishBinPanel.setLocation(jFrameCollectionBoats.getWidth() - 200,
|
||||
jFrameCollectionBoats.getHeight() - 295);
|
||||
addBoatPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 241);
|
||||
addCatamaranPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 214);
|
||||
addFromConstructorPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 187);
|
||||
textBoxPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 146);
|
||||
removePanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 119);
|
||||
|
||||
refreshPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 67);
|
||||
toolsPanel.setSize(new Dimension(10, jFrameCollectionBoats.getHeight()));
|
||||
|
||||
jFrameCollectionBoats.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
buttonAddBoat.addActionListener(e -> {
|
||||
_company.createObject(0, jFrameCollectionBoats);
|
||||
jFrameCollectionBoats.repaint();
|
||||
});
|
||||
buttonAddCatamaran.addActionListener(e -> {
|
||||
_company.createObject(1, jFrameCollectionBoats);
|
||||
jFrameCollectionBoats.repaint();
|
||||
});
|
||||
|
||||
buttonRemove.addActionListener(e -> {
|
||||
int pos = -1;
|
||||
if (!textBoxPosition.getText().isEmpty()) {
|
||||
int inputPos = Integer.parseInt(textBoxPosition.getText());
|
||||
if (inputPos <= 99 && inputPos >= 0) {
|
||||
pos = inputPos;
|
||||
}
|
||||
}
|
||||
if (pos != -1) {
|
||||
if(_company.deleteButtonAction(pos, jFrameCollectionBoats)) {
|
||||
goGoToCheckFromRubbishBinButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
jFrameCollectionBoats.repaint();
|
||||
|
||||
});
|
||||
refreshButton.addActionListener(e -> {
|
||||
jFrameCollectionBoats.repaint();
|
||||
});
|
||||
goToCheckButton.addActionListener(e -> {
|
||||
_company.goToCheckButtonAction();
|
||||
jFrameCollectionBoats.repaint();
|
||||
});
|
||||
goGoToCheckFromRubbishBinButton.addActionListener(e -> {
|
||||
goGoToCheckFromRubbishBinButton.setEnabled(_company.goToCheckFromRubbishBinAction());
|
||||
jFrameCollectionBoats.repaint();
|
||||
});
|
||||
createCompanyButton.addActionListener(e -> {
|
||||
boolean res = _company.collectionComboBox_SelectedIndexChanged(jFrameCollectionBoats, collectionsList, comboBoxSelectorCompany,
|
||||
jFrameCollectionBoats.getWidth() - 233, jFrameCollectionBoats.getHeight());
|
||||
setEnableComponentsOfList(listOfDownPanel, res);
|
||||
jFrameCollectionBoats.repaint();
|
||||
});
|
||||
addFromConstructorButton.addActionListener(e -> {
|
||||
_company.getObjFromConstructor(jFrameCollectionBoats);
|
||||
});
|
||||
addCollectionButton.addActionListener(e -> {
|
||||
StorageCollection<DrawningBoat> result = _company.addCollectionButtonAction(jFrameCollectionBoats, setCollectionName,
|
||||
massiveRadioButton, listRadioButton);
|
||||
updateCollectionsList(result);
|
||||
});
|
||||
deleteCollectionButton.addActionListener(e -> {
|
||||
StorageCollection<DrawningBoat> result = _company.deleteCollectionButtonAction(jFrameCollectionBoats, collectionsList);
|
||||
updateCollectionsList(result);
|
||||
});
|
||||
|
||||
jFrameCollectionBoats.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
private void updateCollectionsList(StorageCollection<DrawningBoat> storageCollection) {
|
||||
if (storageCollection == null) {
|
||||
return;
|
||||
}
|
||||
listModel.clear();
|
||||
ArrayList<String> keys = storageCollection.keys;
|
||||
for (String key : keys) {
|
||||
listModel.addElement(key);
|
||||
}
|
||||
}
|
||||
private void setEnableComponentsOfList(ArrayList<Component> list, boolean type) {
|
||||
for(var i: list) {
|
||||
i.setEnabled(type);
|
||||
}
|
||||
}
|
||||
}
|
113
ProjectCatamaran/src/Forms/FormCatamaran.java
Normal file
113
ProjectCatamaran/src/Forms/FormCatamaran.java
Normal file
@ -0,0 +1,113 @@
|
||||
package Forms;
|
||||
|
||||
import Drawnings.*;
|
||||
import MovementStrategy.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
|
||||
public class FormCatamaran extends JFrame {
|
||||
final private JFrame JFrameCatamaran = new JFrame();
|
||||
final private JButton buttonRight = new JButton(new ImageIcon("ProjectCatamaran\\Resources\\30px_arrow_right.png"));
|
||||
final private JPanel RightPanel = new JPanel();
|
||||
final private JButton buttonDown = new JButton(new ImageIcon("ProjectCatamaran\\Resources\\30px_arrow_down.png"));
|
||||
final private JPanel DownPanel = new JPanel();
|
||||
final private JButton buttonLeft = new JButton(new ImageIcon("ProjectCatamaran\\Resources\\30px_arrow_left.png"));
|
||||
final private JPanel LeftPanel = new JPanel();
|
||||
final private JButton buttonUp = new JButton(new ImageIcon("ProjectCatamaran\\Resources\\30px_arrow_up.png"));
|
||||
|
||||
final private JPanel UpPanel = new JPanel();
|
||||
final private String [] itemsComboBox = {
|
||||
"К центру",
|
||||
"К краю"
|
||||
};
|
||||
final private JComboBox<String> comboBoxStrategy =new JComboBox<>(itemsComboBox);
|
||||
final private JButton buttonStrategyStep = new JButton("Шаг");
|
||||
final private JPanel StrategyPanel = new JPanel(new BorderLayout());
|
||||
|
||||
final private DrawningFormCatamaran form = new DrawningFormCatamaran();
|
||||
public void setDrawningBoat(DrawningBoat boat) {form.setDrawningBoat(boat);}
|
||||
public void OpenFrame() {
|
||||
JFrameCatamaran.setVisible(true);
|
||||
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||
Dimension dimension = tolls.getScreenSize();
|
||||
JFrameCatamaran.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||
970, 700);
|
||||
JFrameCatamaran.setTitle("Катамаран");
|
||||
|
||||
comboBoxStrategy.setPreferredSize(new Dimension(100, 35));
|
||||
buttonStrategyStep.setPreferredSize(new Dimension(100, 35));
|
||||
StrategyPanel.setSize(100, 70);
|
||||
StrategyPanel.add(comboBoxStrategy, BorderLayout.NORTH);
|
||||
StrategyPanel.add(buttonStrategyStep, BorderLayout.SOUTH);
|
||||
|
||||
|
||||
UpPanel.setSize(30, 30);
|
||||
buttonUp.setPreferredSize(new Dimension(30, 30));
|
||||
UpPanel.add(buttonUp, BorderLayout.CENTER);
|
||||
|
||||
DownPanel.setSize(30, 30);
|
||||
buttonDown.setPreferredSize(new Dimension(30, 30));
|
||||
DownPanel.add(buttonDown, BorderLayout.CENTER);
|
||||
|
||||
RightPanel.setSize(30, 30);
|
||||
buttonRight.setPreferredSize(new Dimension(30, 30));
|
||||
RightPanel.add(buttonRight, BorderLayout.CENTER);
|
||||
|
||||
LeftPanel.setSize(30, 30);
|
||||
buttonLeft.setPreferredSize(new Dimension(30, 30));
|
||||
LeftPanel.add(buttonLeft, BorderLayout.CENTER);
|
||||
|
||||
JFrameCatamaran.add(StrategyPanel);
|
||||
JFrameCatamaran.add(UpPanel);
|
||||
JFrameCatamaran.add(DownPanel);
|
||||
JFrameCatamaran.add(RightPanel);
|
||||
JFrameCatamaran.add(LeftPanel);
|
||||
JFrameCatamaran.add(form);
|
||||
|
||||
JFrameCatamaran.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
StrategyPanel.setLocation(JFrameCatamaran.getWidth() - 100, 0);
|
||||
UpPanel.setLocation(JFrameCatamaran.getWidth() - 80, JFrameCatamaran.getHeight()-100);
|
||||
DownPanel.setLocation(JFrameCatamaran.getWidth() - 80, JFrameCatamaran.getHeight()-70);
|
||||
RightPanel.setLocation(JFrameCatamaran.getWidth() - 45, JFrameCatamaran.getHeight()-70);
|
||||
LeftPanel.setLocation(JFrameCatamaran.getWidth() - 115, JFrameCatamaran.getHeight()-70);
|
||||
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
JFrameCatamaran.repaint();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Up);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
|
||||
buttonDown.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Down);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
buttonLeft.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Left);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
buttonRight.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Right);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
buttonStrategyStep.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.buttonStrategyStep(comboBoxStrategy);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
92
ProjectCatamaran/src/Forms/FormConstructor.java
Normal file
92
ProjectCatamaran/src/Forms/FormConstructor.java
Normal file
@ -0,0 +1,92 @@
|
||||
package Forms;
|
||||
|
||||
import Drawnings.DrawningConstructor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
public class FormConstructor extends JFrame {
|
||||
private JFrame jFrameConstructor = new JFrame();
|
||||
public JFrame getjFrameConstructor() {
|
||||
return jFrameConstructor;
|
||||
}
|
||||
private JButton addButton = new JButton("Добавить объект");
|
||||
public JButton getAddButton() {
|
||||
return addButton;
|
||||
}
|
||||
public JButton reCreateButton = new JButton("Пересоздать");
|
||||
private final DrawningConstructor constructor = new DrawningConstructor();
|
||||
public DrawningConstructor getConstructor() {
|
||||
return constructor;
|
||||
}
|
||||
JPanel entitiesInfoPanel = new JPanel();
|
||||
JLabel firstEntityLabel = new JLabel();
|
||||
JLabel secondEntityLabel = new JLabel();
|
||||
JLabel thirdEntityLabel = new JLabel();
|
||||
|
||||
JPanel paddlesInfoPanel = new JPanel();
|
||||
JLabel firstPaddlesLabel = new JLabel();
|
||||
JLabel secondPaddlesLabel = new JLabel();
|
||||
JLabel thirdPaddlesLabel = new JLabel();
|
||||
|
||||
public void OpenFrame() {
|
||||
|
||||
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||
Dimension dimension = tolls.getScreenSize();
|
||||
jFrameConstructor.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||
800, 300);
|
||||
jFrameConstructor.setLayout(new BorderLayout());
|
||||
|
||||
firstEntityLabel.setText(constructor.getEntityString(0));
|
||||
secondEntityLabel.setText(constructor.getEntityString(1));
|
||||
thirdEntityLabel.setText(constructor.getEntityString(2));
|
||||
|
||||
entitiesInfoPanel.setLayout(new BoxLayout(entitiesInfoPanel, BoxLayout.Y_AXIS));
|
||||
entitiesInfoPanel.setBorder(BorderFactory.createTitledBorder("Entities"));
|
||||
entitiesInfoPanel.setSize(500, 130);
|
||||
entitiesInfoPanel.setLocation(150, 10);
|
||||
entitiesInfoPanel.add(firstEntityLabel);
|
||||
entitiesInfoPanel.add(secondEntityLabel);
|
||||
entitiesInfoPanel.add(thirdEntityLabel);
|
||||
|
||||
firstPaddlesLabel.setText(constructor.getPaddlesString(0));
|
||||
secondPaddlesLabel.setText(constructor.getPaddlesString(1));
|
||||
thirdPaddlesLabel.setText(constructor.getPaddlesString(2));
|
||||
|
||||
|
||||
paddlesInfoPanel.setLayout(new BoxLayout(paddlesInfoPanel, BoxLayout.Y_AXIS));
|
||||
paddlesInfoPanel.setBorder(BorderFactory.createTitledBorder("Paddles"));
|
||||
paddlesInfoPanel.setSize(500, 130);
|
||||
paddlesInfoPanel.setLocation(150, 150);
|
||||
paddlesInfoPanel.add(firstPaddlesLabel);
|
||||
paddlesInfoPanel.add(secondPaddlesLabel);
|
||||
paddlesInfoPanel.add(thirdPaddlesLabel);
|
||||
|
||||
addButton.setBounds(0, jFrameConstructor.getHeight() - 105, 150, 50);
|
||||
reCreateButton.setBounds(0, jFrameConstructor.getHeight() - 135, 150, 30);
|
||||
|
||||
jFrameConstructor.add(paddlesInfoPanel);
|
||||
jFrameConstructor.add(entitiesInfoPanel);
|
||||
jFrameConstructor.add(addButton);
|
||||
jFrameConstructor.add(reCreateButton);
|
||||
jFrameConstructor.add(constructor);
|
||||
jFrameConstructor.revalidate();
|
||||
jFrameConstructor.repaint();
|
||||
|
||||
jFrameConstructor.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent componentEvent) {
|
||||
addButton.setLocation(0, jFrameConstructor.getSize().height - 105);
|
||||
reCreateButton.setLocation(0, jFrameConstructor.getSize().height - 135);
|
||||
}
|
||||
});
|
||||
reCreateButton.addActionListener(e -> {
|
||||
constructor.reCreateObj();
|
||||
jFrameConstructor.repaint();
|
||||
});
|
||||
|
||||
jFrameConstructor.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
import Forms.FormBoatCollection;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||
// to see how IntelliJ IDEA suggests fixing it.
|
||||
System.out.println("Hello and welcome!");
|
||||
FormBoatCollection formBoatCollection = new FormBoatCollection();
|
||||
formBoatCollection.OpenFrame();
|
||||
}
|
||||
}
|
69
ProjectCatamaran/src/MovementStrategy/AbstractStrategy.java
Normal file
69
ProjectCatamaran/src/MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,69 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject _moveableObject;
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
protected int FieldWidth;
|
||||
protected int FieldHeight;
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
protected boolean MoveLeft() { return MoveTo(MovementDirection.Left); }
|
||||
protected boolean MoveRight() { return MoveTo(MovementDirection.Right); }
|
||||
protected boolean MoveUp() { return MoveTo(MovementDirection.Up); }
|
||||
protected boolean MoveDown() { return MoveTo(MovementDirection.Down); }
|
||||
|
||||
protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
|
||||
|
||||
protected int GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return _moveableObject.GetStep();
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
protected abstract boolean IsTargetDestination();
|
||||
|
||||
private boolean MoveTo(MovementDirection directionType)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.TryMoveObject(directionType))
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters GetObjectPosition();
|
||||
int GetStep();
|
||||
boolean TryMoveObject(MovementDirection direction);
|
||||
void MoveObject(MovementDirection direction);
|
||||
}
|
46
ProjectCatamaran/src/MovementStrategy/MoveToBorder.java
Normal file
46
ProjectCatamaran/src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,46 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy {
|
||||
@Override
|
||||
protected boolean IsTargetDestination()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder() + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder() + GetStep() >= FieldHeight;
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.RightBorder() - FieldWidth;
|
||||
if (Math.abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.DownBorder() - FieldHeight;
|
||||
if (Math.abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
ProjectCatamaran/src/MovementStrategy/MoveToCenter.java
Normal file
48
ProjectCatamaran/src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,48 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy {
|
||||
@Override
|
||||
protected boolean IsTargetDestination()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return (objParams.ObjectMiddleHorizontal() - GetStep() <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical() - GetStep() <= 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
ProjectCatamaran/src/MovementStrategy/MoveableBoat.java
Normal file
23
ProjectCatamaran/src/MovementStrategy/MoveableBoat.java
Normal file
@ -0,0 +1,23 @@
|
||||
package MovementStrategy;
|
||||
import Drawnings.*;
|
||||
|
||||
public class MoveableBoat implements IMoveableObject {
|
||||
private DrawningBoat _boat = null;
|
||||
public MoveableBoat(DrawningBoat drawningBoat)
|
||||
{
|
||||
_boat = drawningBoat;
|
||||
}
|
||||
|
||||
public ObjectParameters GetObjectPosition()
|
||||
{
|
||||
if (_boat == null || _boat.getEntityBoat() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_boat.GetPosX(), _boat.GetPosY(), _boat.GetWidth(), _boat.GetHeight());
|
||||
}
|
||||
|
||||
public int GetStep() { return (int) _boat.getEntityBoat().getStep(); }
|
||||
public boolean TryMoveObject(MovementDirection direction) { return _boat.moveTransport(direction); }
|
||||
public void MoveObject(MovementDirection direction) { _boat.moveTransport(direction); }
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum MovementDirection {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right;
|
||||
}
|
24
ProjectCatamaran/src/MovementStrategy/ObjectParameters.java
Normal file
24
ProjectCatamaran/src/MovementStrategy/ObjectParameters.java
Normal file
@ -0,0 +1,24 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class ObjectParameters {
|
||||
private int _x;
|
||||
private int _y;
|
||||
private int _width;
|
||||
private 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum StrategyStatus {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user