lab3 v0.1
This commit is contained in:
parent
f33808a992
commit
ca79a77693
@ -12,7 +12,8 @@ import java.io.IOException;
|
||||
public class AircraftCarrierApplication extends Application {
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(AircraftCarrierApplication.class.getResource("/com/example/aircraftcarrier/AircraftCarrierView.fxml"));
|
||||
// FXMLLoader fxmlLoader = new FXMLLoader(AircraftCarrierApplication.class.getResource("/com/example/aircraftcarrier/AircraftCarrierView.fxml"));
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(AircraftCarrierApplication.class.getResource("/com/example/aircraftcarrier/ShipCollectionView.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
stage.setTitle("Hello!");
|
||||
stage.setScene(scene);
|
||||
|
@ -11,6 +11,7 @@ import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.control.TextField;
|
||||
@ -34,13 +35,13 @@ public class AircraftCarrierController implements Initializable {
|
||||
@FXML
|
||||
private Canvas canvas;
|
||||
@FXML
|
||||
private TextField inputCountBlocks;
|
||||
@FXML
|
||||
private ChoiceBox<String> choiceBoxStrategy;
|
||||
private String[] strategyText = new String[]{"к центру", "к углу"};
|
||||
@FXML
|
||||
private ChoiceBox<String> choiceBoxShape;
|
||||
private String[] shapeText = new String[]{"квадрат", "треугольник", "круг"};
|
||||
private final String[] strategyText = new String[]{"к центру", "к углу"};
|
||||
|
||||
public void setDrawing(DrawingSimpleAircraftCarrier drawingAircraftCarrier) {
|
||||
this.drawingAircraftCarrier = drawingAircraftCarrier;
|
||||
draw();
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void ButtonStrategy_Click() {
|
||||
@ -68,73 +69,9 @@ public class AircraftCarrierController implements Initializable {
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void ButtonCreateSimple_Click() {
|
||||
drawingAircraftCarrier = new DrawingSimpleAircraftCarrier(
|
||||
random.nextInt(100) + 100,
|
||||
random.nextInt(1000) + 1000,
|
||||
Color.rgb(
|
||||
random.nextInt(256),
|
||||
random.nextInt(256),
|
||||
random.nextInt(256)
|
||||
)
|
||||
);
|
||||
|
||||
drawingAircraftCarrier.setCanvasWidth((int) canvas.getWidth());
|
||||
drawingAircraftCarrier.setCanvasHeight((int) canvas.getHeight());
|
||||
if (
|
||||
drawingAircraftCarrier.setPosition(
|
||||
random.nextInt(50) + 10,
|
||||
random.nextInt(50) + 10
|
||||
)
|
||||
) {
|
||||
drawingAircraftCarrier.Draw(canvas.getGraphicsContext2D());
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void ButtonCreateAdvanced_Click() {
|
||||
|
||||
int inputCount;
|
||||
try {
|
||||
inputCount = Integer.parseInt(inputCountBlocks.getText());
|
||||
} catch (Exception ignore) {
|
||||
inputCount = 0;
|
||||
}
|
||||
|
||||
drawingAircraftCarrier = new DrawingAircraftCarrier(
|
||||
random.nextInt(100) + 100,
|
||||
random.nextInt(1000) + 1000,
|
||||
Color.rgb(
|
||||
random.nextInt(256),
|
||||
random.nextInt(256),
|
||||
random.nextInt(256)
|
||||
),
|
||||
Color.rgb(
|
||||
random.nextInt(256),
|
||||
random.nextInt(256),
|
||||
random.nextInt(256)
|
||||
),
|
||||
random.nextBoolean(),
|
||||
random.nextBoolean(),
|
||||
inputCount,
|
||||
choiceBoxShape.getValue()
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
drawingAircraftCarrier.setCanvasWidth((int) canvas.getWidth());
|
||||
drawingAircraftCarrier.setCanvasHeight((int) canvas.getHeight());
|
||||
if (
|
||||
drawingAircraftCarrier.setPosition(
|
||||
random.nextInt(50) + 10,
|
||||
random.nextInt(50) + 10
|
||||
)
|
||||
) {
|
||||
drawingAircraftCarrier.Draw(canvas.getGraphicsContext2D());
|
||||
}
|
||||
private void draw() {
|
||||
canvas.getGraphicsContext2D().clearRect(0,0,canvas.getWidth(),canvas.getHeight());
|
||||
drawingAircraftCarrier.Draw(canvas.getGraphicsContext2D());
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -165,15 +102,13 @@ public class AircraftCarrierController implements Initializable {
|
||||
if (directionType == DirectionType.Unknown) return;
|
||||
|
||||
drawingAircraftCarrier.Move(directionType);
|
||||
drawingAircraftCarrier.Draw(canvas.getGraphicsContext2D());
|
||||
draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
System.out.println("start");
|
||||
canvas.widthProperty().bind(Root.widthProperty());
|
||||
canvas.heightProperty().bind(Root.heightProperty());
|
||||
choiceBoxStrategy.getItems().addAll(strategyText);
|
||||
choiceBoxShape.getItems().addAll(shapeText);
|
||||
}
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
package com.example.aircraftcarrier.Logic.Aircraft;
|
||||
|
||||
import com.example.aircraftcarrier.Logic.Block.DrawingBlock;
|
||||
import com.example.aircraftcarrier.Logic.Block.DrawingBlockCircle;
|
||||
import com.example.aircraftcarrier.Logic.Block.DrawingBlockTriangle;
|
||||
import com.example.aircraftcarrier.Logic.Block.IDrawingBlock;
|
||||
import com.example.aircraftcarrier.Logic.Entity.EntityAircraftCarrier;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
@ -10,15 +7,16 @@ import javafx.scene.paint.Color;
|
||||
|
||||
public class DrawingAircraftCarrier extends DrawingSimpleAircraftCarrier {
|
||||
public IDrawingBlock drawingBlock;
|
||||
|
||||
public DrawingAircraftCarrier() {super();}
|
||||
|
||||
public DrawingAircraftCarrier(
|
||||
int speed,
|
||||
int weight,
|
||||
Color primaryColor,
|
||||
Color secondaryColor,
|
||||
boolean hasDeck,
|
||||
boolean hasСabin,
|
||||
int countBlock,
|
||||
String shape
|
||||
boolean hasСabin
|
||||
) {
|
||||
super();
|
||||
aircraftCarrier = new EntityAircraftCarrier(speed,
|
||||
@ -27,17 +25,10 @@ public class DrawingAircraftCarrier extends DrawingSimpleAircraftCarrier {
|
||||
secondaryColor,
|
||||
hasDeck,
|
||||
hasСabin);
|
||||
}
|
||||
|
||||
if (shape != null) {
|
||||
drawingBlock = switch (shape) {
|
||||
case "квадрат" -> new DrawingBlock(countBlock);
|
||||
case "треугольник" -> new DrawingBlockTriangle(countBlock);
|
||||
case "круг" -> new DrawingBlockCircle(countBlock);
|
||||
default -> null;
|
||||
};
|
||||
} else {
|
||||
drawingBlock = null;
|
||||
}
|
||||
public void setDrawingBlock(IDrawingBlock iDrawingBlock) {
|
||||
drawingBlock = iDrawingBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,8 +28,14 @@ public class DrawingSimpleAircraftCarrier {
|
||||
);
|
||||
}
|
||||
|
||||
public void setCanvasParam(int width, int height) {
|
||||
if (x+widthPicture > width && y+heightPicture > height) return;
|
||||
heightCanvas = height;
|
||||
widthCanvas = width;
|
||||
}
|
||||
|
||||
public void setCanvasWidth(int width) {
|
||||
if (x+widthPicture > width);
|
||||
if (x+widthPicture > width) return;
|
||||
widthCanvas = width;
|
||||
}
|
||||
|
||||
@ -62,13 +68,17 @@ public class DrawingSimpleAircraftCarrier {
|
||||
}
|
||||
|
||||
public void Draw(GraphicsContext gc) {
|
||||
gc.clearRect(0,0,widthCanvas,heightCanvas);
|
||||
gc.setStroke(aircraftCarrier.getPrimaryColor());
|
||||
gc.setLineWidth(5);
|
||||
|
||||
double[] X = new double[]{x,x+200,x+250,x+200,x};
|
||||
double[] Y = new double[]{y,y,y+50,y+100,y+100};
|
||||
gc.strokePolygon(X, Y,5);
|
||||
|
||||
gc.strokeOval(x+175,y+35,30,30);
|
||||
|
||||
gc.setStroke(Color.BLACK);
|
||||
gc.setLineWidth(1);
|
||||
}
|
||||
|
||||
public boolean Move(DirectionType direction) {
|
||||
|
@ -7,10 +7,6 @@ import javafx.scene.paint.Color;
|
||||
public class DrawingBlock implements IDrawingBlock {
|
||||
private BlockCount blockCount;
|
||||
|
||||
public DrawingBlock(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
}
|
||||
|
||||
public void setBlockCount(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
}
|
||||
|
@ -7,9 +7,7 @@ import javafx.scene.paint.Color;
|
||||
public class DrawingBlockCircle implements IDrawingBlock {
|
||||
private BlockCount blockCount;
|
||||
|
||||
public DrawingBlockCircle(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
}
|
||||
public DrawingBlockCircle() {}
|
||||
|
||||
public void setBlockCount(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
|
@ -7,9 +7,7 @@ import javafx.scene.paint.Color;
|
||||
public class DrawingBlockTriangle implements IDrawingBlock {
|
||||
private BlockCount blockCount;
|
||||
|
||||
public DrawingBlockTriangle(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
}
|
||||
public DrawingBlockTriangle() {}
|
||||
|
||||
public void setBlockCount(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
|
@ -0,0 +1,54 @@
|
||||
package com.example.aircraftcarrier.Logic.CollectionGenericObjects;
|
||||
|
||||
import com.example.aircraftcarrier.Logic.Aircraft.DrawingSimpleAircraftCarrier;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractCompany {
|
||||
|
||||
protected static final int _placeSizeWidth = 300;
|
||||
protected static final int _placeSizeHeight = 150;
|
||||
protected final int _pictureWidth;
|
||||
protected final int _pictureHeight;
|
||||
|
||||
protected ICollectionGenericObjects<DrawingSimpleAircraftCarrier> _collection;
|
||||
public AbstractCompany(int pictureWidth, int pictureHeight, ICollectionGenericObjects<DrawingSimpleAircraftCarrier> collection) {
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount(GetMaxCount());
|
||||
}
|
||||
|
||||
private int GetMaxCount() {
|
||||
return (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight);
|
||||
};
|
||||
|
||||
public static boolean add(AbstractCompany company, DrawingSimpleAircraftCarrier aircraftCarrier) {
|
||||
return company != null && company._collection != null && company._collection.Insert(aircraftCarrier);
|
||||
}
|
||||
|
||||
public static boolean remove(AbstractCompany company, int pos){
|
||||
return company != null && company._collection != null && company._collection.Remove(pos);
|
||||
}
|
||||
|
||||
public DrawingSimpleAircraftCarrier GetRandom() {
|
||||
Random random = new Random();
|
||||
return _collection == null ? null : _collection.Get(random.nextInt(GetMaxCount()));
|
||||
}
|
||||
|
||||
public void Show(GraphicsContext gc) {
|
||||
gc.clearRect(0, 0, _pictureWidth, _pictureHeight);
|
||||
DrawBackground(gc);
|
||||
SetObjectPosition();
|
||||
for (int i = 0; i < _collection.count(); i++)
|
||||
{
|
||||
DrawingSimpleAircraftCarrier obj = _collection.Get(i);
|
||||
if (obj == null) return;
|
||||
obj.Draw(gc);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void DrawBackground(GraphicsContext gc);
|
||||
protected abstract void SetObjectPosition();
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.example.aircraftcarrier.Logic.CollectionGenericObjects;
|
||||
|
||||
import com.example.aircraftcarrier.Logic.Aircraft.DrawingSimpleAircraftCarrier;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
public class DocksService extends AbstractCompany {
|
||||
|
||||
public DocksService(int pictureWidth, int pictureHeight, ICollectionGenericObjects<DrawingSimpleAircraftCarrier> collection) {
|
||||
super(pictureWidth, pictureHeight, collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBackground(GraphicsContext gc) {
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||
{
|
||||
double[] X = {
|
||||
i*_placeSizeWidth+250,
|
||||
i*_placeSizeWidth,
|
||||
i*_placeSizeWidth,
|
||||
i*_placeSizeWidth+250,
|
||||
};
|
||||
double[] Y = {
|
||||
j*_placeSizeHeight,
|
||||
j*_placeSizeHeight,
|
||||
j*_placeSizeHeight+_placeSizeHeight,
|
||||
j*_placeSizeHeight+_placeSizeHeight,
|
||||
};
|
||||
gc.setLineWidth(5);
|
||||
gc.strokePolyline(X,Y,4);
|
||||
gc.setLineWidth(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void SetObjectPosition() {
|
||||
int maxXPositionCount = _pictureWidth / _placeSizeWidth;
|
||||
int maxYPositionCount = _pictureHeight / _placeSizeHeight;
|
||||
int xpos = 0;
|
||||
int ypos = maxYPositionCount;
|
||||
|
||||
for (int i = 0; i < _collection.count(); i++) {
|
||||
DrawingSimpleAircraftCarrier obj = _collection.Get(i);
|
||||
if (obj == null) { continue; }
|
||||
System.out.println(i);
|
||||
obj.setCanvasParam(_pictureWidth,_pictureHeight);
|
||||
obj.setPosition(xpos * _placeSizeWidth + 10, (ypos-1) * _placeSizeHeight + 10);
|
||||
xpos++;
|
||||
if (xpos >= maxXPositionCount)
|
||||
{
|
||||
xpos = 0;
|
||||
ypos--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.example.aircraftcarrier.Logic.CollectionGenericObjects;
|
||||
|
||||
public interface ICollectionGenericObjects<T> {
|
||||
int count();
|
||||
void SetMaxCount(int count);
|
||||
boolean Insert(T obj);
|
||||
boolean Insert(T obj, int position);
|
||||
boolean Remove(int position);
|
||||
T Get(int position);
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.example.aircraftcarrier.Logic.CollectionGenericObjects;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
private T[] _collection;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public MassiveGenericObjects() {
|
||||
this._collection = (T[]) new Object[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count() {
|
||||
return _collection.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void SetMaxCount(int count) {
|
||||
if (count > 0) {
|
||||
_collection = (T[]) new Object[count];
|
||||
Arrays.fill(_collection,null);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean _checkRange(int pos) {
|
||||
return (pos >= 0 && pos < _collection.length);
|
||||
}
|
||||
|
||||
private boolean _checkAndInsert(T obj, int pos)
|
||||
{
|
||||
if (_collection[pos] == null)
|
||||
{
|
||||
_collection[pos] = obj;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean Insert(T obj) {
|
||||
for (int i = 0; i< _collection.length;i++){
|
||||
if (_checkAndInsert(obj,i)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean Insert(T obj, int position) {
|
||||
if (!_checkRange(position)) return false;
|
||||
if (_checkAndInsert(obj, position)) return true;
|
||||
for (int i = position + 1; i < _collection.length; i++)
|
||||
{
|
||||
if (_checkAndInsert(obj, i)) return true;
|
||||
}
|
||||
for (int i = 0; i < position; i++)
|
||||
{
|
||||
if (_checkAndInsert(obj, i)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean Remove(int position) {
|
||||
if (!_checkRange(position) || _collection[position] == null) return false;
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T Get(int position) {
|
||||
if (_checkRange(position)) return _collection[position];
|
||||
return null;
|
||||
}
|
||||
}
|
@ -10,12 +10,12 @@ public class EntityAircraftCarrier extends EntitySimpleAircraftCarrier {
|
||||
|
||||
public EntityAircraftCarrier(
|
||||
int speed,
|
||||
int weight,
|
||||
double weight,
|
||||
Color primaryColor,
|
||||
Color secondaryColor,
|
||||
boolean hasDeck,
|
||||
boolean hasСabin
|
||||
){
|
||||
) {
|
||||
super(speed,weight,primaryColor);
|
||||
this.SecondaryColor = secondaryColor;
|
||||
this.HasDeck = hasDeck;
|
||||
|
@ -0,0 +1,202 @@
|
||||
package com.example.aircraftcarrier;
|
||||
|
||||
import com.example.aircraftcarrier.Logic.Aircraft.DrawingAircraftCarrier;
|
||||
import com.example.aircraftcarrier.Logic.Aircraft.DrawingSimpleAircraftCarrier;
|
||||
import com.example.aircraftcarrier.Logic.Block.DrawingBlock;
|
||||
import com.example.aircraftcarrier.Logic.Block.IDrawingBlock;
|
||||
import com.example.aircraftcarrier.Logic.CollectionGenericObjects.AbstractCompany;
|
||||
import com.example.aircraftcarrier.Logic.CollectionGenericObjects.DocksService;
|
||||
import com.example.aircraftcarrier.Logic.CollectionGenericObjects.MassiveGenericObjects;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Random;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class ShipCollectionController implements Initializable {
|
||||
|
||||
private AbstractCompany _company;
|
||||
Random random = new Random();
|
||||
|
||||
@FXML
|
||||
private TextField IdField;
|
||||
@FXML
|
||||
private Canvas canvasCollection;
|
||||
@FXML
|
||||
private AnchorPane wrapperCanvas;
|
||||
@FXML
|
||||
private ComboBox<String> comboBoxStorage;
|
||||
private final String[] storageText = new String[]{"Хранилище"};
|
||||
@FXML
|
||||
private static ColorPicker asdd1;
|
||||
|
||||
@FXML
|
||||
protected void ComboBox_Choice() {
|
||||
System.out.println(comboBoxStorage.getValue());
|
||||
switch (comboBoxStorage.getValue())
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new DocksService(
|
||||
(int)canvasCollection.getWidth(),
|
||||
(int)canvasCollection.getHeight(),
|
||||
new MassiveGenericObjects<DrawingSimpleAircraftCarrier>()
|
||||
);
|
||||
break;
|
||||
}
|
||||
_company.Show(canvasCollection.getGraphicsContext2D());
|
||||
}
|
||||
|
||||
private static Color GetColor(Random random) {
|
||||
Color c = Color.rgb(random.nextInt(256),random.nextInt(256),random.nextInt(256));
|
||||
// //TODO: доделать
|
||||
// asdd1.setVisible(false);
|
||||
// asdd1.sho
|
||||
// ColorPicker colorPicker = new ColorPicker(c);
|
||||
// Button confirmButton = new Button("Установить");
|
||||
// confirmButton.setAlignment(Pos.CENTER_RIGHT);
|
||||
//
|
||||
// HBox buttonBox = new HBox(confirmButton);
|
||||
// buttonBox.setAlignment(Pos.TOP_RIGHT);
|
||||
// buttonBox.setPadding(new Insets(10, 10, 10, 10));
|
||||
// VBox root = new VBox(colorPicker, buttonBox);
|
||||
//
|
||||
//
|
||||
//
|
||||
// Stage colorStage = new Stage();
|
||||
// colorStage.setScene(new Scene(root));
|
||||
//
|
||||
// confirmButton.setOnAction(event -> colorStage.close());
|
||||
//
|
||||
// colorStage.showAndWait();
|
||||
return c;
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void ButtonCreateSimple_Click() {
|
||||
if (_company == null) return;
|
||||
DrawingSimpleAircraftCarrier drawingAircraftCarrier;
|
||||
drawingAircraftCarrier = new DrawingSimpleAircraftCarrier(
|
||||
random.nextInt(100) + 100,
|
||||
random.nextInt(1000) + 1000,
|
||||
GetColor(random)
|
||||
);
|
||||
|
||||
drawingAircraftCarrier.setCanvasWidth((int) canvasCollection.getWidth());
|
||||
drawingAircraftCarrier.setCanvasHeight((int) canvasCollection.getHeight());
|
||||
AbstractCompany.add(_company,drawingAircraftCarrier);
|
||||
_company.Show(canvasCollection.getGraphicsContext2D());
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void ButtonCreate_Click() {
|
||||
if (_company == null) return;
|
||||
DrawingAircraftCarrier drawingAircraftCarrier;
|
||||
drawingAircraftCarrier = new DrawingAircraftCarrier(
|
||||
random.nextInt(100) + 100,
|
||||
random.nextInt(1000) + 1000,
|
||||
GetColor(random),
|
||||
GetColor(random),
|
||||
random.nextBoolean(),
|
||||
random.nextBoolean()
|
||||
);
|
||||
|
||||
IDrawingBlock imo = new DrawingBlock();
|
||||
imo.setBlockCount(2);
|
||||
drawingAircraftCarrier.setDrawingBlock(imo);
|
||||
|
||||
drawingAircraftCarrier.setCanvasWidth((int) canvasCollection.getWidth());
|
||||
drawingAircraftCarrier.setCanvasHeight((int) canvasCollection.getHeight());
|
||||
|
||||
System.out.println( AbstractCompany.add(_company,drawingAircraftCarrier));
|
||||
_company.Show(canvasCollection.getGraphicsContext2D());
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void ButtonTest_Click() {
|
||||
if (_company == null) return;
|
||||
DrawingSimpleAircraftCarrier aircraft = null;
|
||||
int counter = 100;
|
||||
while (aircraft == null & counter > 0) {
|
||||
aircraft = _company.GetRandom();
|
||||
counter--;
|
||||
}
|
||||
|
||||
if (aircraft == null) return;
|
||||
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(
|
||||
AircraftCarrierApplication.class.getResource(
|
||||
"/com/example/aircraftcarrier/AircraftCarrierView.fxml"
|
||||
)
|
||||
);
|
||||
try {
|
||||
AnchorPane Pane = fxmlLoader.load();
|
||||
AircraftCarrierController controller = fxmlLoader.getController();
|
||||
controller.setDrawing(aircraft);
|
||||
Stage stage = new Stage();
|
||||
Scene scene = new Scene(Pane);
|
||||
stage.setScene(scene);
|
||||
stage.showAndWait();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void ButtonDeleteAircraft_Click() {
|
||||
if (IdField.getText().isEmpty() || _company == null) return;
|
||||
|
||||
Alert alert = new Alert(Alert.AlertType.NONE);
|
||||
alert.setTitle("Удаление");
|
||||
alert.setContentText("вы действительно хотите удалить " + IdField.getText());
|
||||
alert.getButtonTypes().setAll(ButtonType.YES,ButtonType.NO);
|
||||
alert.showAndWait();
|
||||
ButtonType res = alert.resultProperty().getValue();
|
||||
|
||||
if (res == ButtonType.NO || res == ButtonType.CLOSE) return;
|
||||
|
||||
int pos = Integer.parseInt(IdField.getText());
|
||||
if (AbstractCompany.remove(_company, pos)) {
|
||||
Alert correct = new Alert(Alert.AlertType.NONE);
|
||||
alert.setTitle("Успешно");
|
||||
correct.setContentText("объект был удален");
|
||||
correct.getButtonTypes().setAll(ButtonType.OK);
|
||||
correct.showAndWait();
|
||||
|
||||
_company.Show(canvasCollection.getGraphicsContext2D());
|
||||
}
|
||||
else {
|
||||
Alert incorrect = new Alert(Alert.AlertType.NONE);
|
||||
incorrect.setContentText("объект не удален");
|
||||
incorrect.getButtonTypes().setAll(ButtonType.OK);
|
||||
incorrect.showAndWait();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
comboBoxStorage.getItems().addAll(storageText);
|
||||
// canvasCollection.widthProperty().bind(wrapperCanvas.widthProperty());
|
||||
// canvasCollection.heightProperty().bind(wrapperCanvas.heightProperty());
|
||||
IdField.textProperty().addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
|
||||
if(newValue.matches("\\d{0,2}")) {
|
||||
IdField.setText(newValue);
|
||||
} else {
|
||||
IdField.setText(oldValue);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -4,18 +4,14 @@
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="Root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onKeyPressed="#MoveEvent" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.aircraftcarrier.AircraftCarrierController">
|
||||
<AnchorPane fx:id="Root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onKeyPressed="#MoveEvent" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.aircraftcarrier.AircraftCarrierController">
|
||||
<children>
|
||||
<Canvas fx:id="canvas" height="400.0" width="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<Button layoutX="14.0" layoutY="361.0" mnemonicParsing="false" onAction="#ButtonCreateSimple_Click" text="Создать простую" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" />
|
||||
<Button layoutX="130.0" layoutY="354.0" mnemonicParsing="false" onAction="#ButtonCreateAdvanced_Click" text="Создать сложную" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="135.0" />
|
||||
<Canvas fx:id="canvas" height="600.0" width="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<Button fx:id="up" layoutX="524.4" layoutY="324.4" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#MoveEvent" style="-fx-background-image: url("up-arrow.png"); -fx-background-size: stretch;" AnchorPane.bottomAnchor="50.0" AnchorPane.rightAnchor="50.0" />
|
||||
<Button fx:id="right" layoutX="554.4" layoutY="354.4" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#MoveEvent" style="-fx-background-image: url("right-arrow.png"); -fx-background-size: stretch;" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="20.0" />
|
||||
<Button fx:id="down" layoutX="524.4" layoutY="354.4" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#MoveEvent" style="-fx-background-image: url("down-arrow.png"); -fx-background-size: stretch;" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="50.0" />
|
||||
<Button fx:id="left" layoutX="494.4" layoutY="354.4" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#MoveEvent" style="-fx-background-image: url("left-arrow.png"); -fx-background-size: stretch;" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="80.0" />
|
||||
<TextField fx:id="inputCountBlocks" layoutX="446.0" layoutY="14.0" promptText="количество блоков" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="20.0" />
|
||||
<ChoiceBox fx:id="choiceBoxStrategy" layoutX="430.0" layoutY="46.0" prefHeight="26.0" prefWidth="110.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="50.0" />
|
||||
<Button layoutX="524.0" layoutY="83.0" mnemonicParsing="false" onAction="#ButtonStrategy_Click" text="шаг" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="80.0" />
|
||||
<ChoiceBox fx:id="choiceBoxShape" layoutX="469.0" layoutY="116.0" prefHeight="26.0" prefWidth="110.0" AnchorPane.rightAnchor="20.599999999999994" AnchorPane.topAnchor="110.0" />
|
||||
<ChoiceBox fx:id="choiceBoxStrategy" layoutX="469.0" layoutY="14.0" prefHeight="26.0" prefWidth="110.0" AnchorPane.rightAnchor="20.600000000000023" AnchorPane.topAnchor="14.0" />
|
||||
<Button layoutX="543.0" layoutY="44.0" mnemonicParsing="false" onAction="#ButtonStrategy_Click" text="шаг" AnchorPane.rightAnchor="20.200000000000045" AnchorPane.topAnchor="44.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.canvas.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<BorderPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.aircraftcarrier.ShipCollectionController">
|
||||
<right>
|
||||
<BorderPane prefHeight="400.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<center>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<Button layoutX="64.0" layoutY="38.0" mnemonicParsing="false" onAction="#ButtonCreateSimple_Click" text="Создать Авианосец" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="55.0" />
|
||||
<Button layoutX="64.0" layoutY="82.0" mnemonicParsing="false" onAction="#ButtonCreate_Click" text="Создать супер Авианосец" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="90.0" />
|
||||
<Button layoutX="64.0" layoutY="132.0" mnemonicParsing="false" onAction="#ButtonDeleteAircraft_Click" text="Удалить Авианосец" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="160.0" />
|
||||
<Button layoutX="64.0" layoutY="166.0" mnemonicParsing="false" onAction="#ButtonTest_Click" text="Тесты" AnchorPane.bottomAnchor="55.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" />
|
||||
<Button layoutX="64.0" layoutY="216.0" mnemonicParsing="false" text="Обновить" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" />
|
||||
<ComboBox fx:id="comboBoxStorage" layoutX="23.0" layoutY="14.0" onAction="#ComboBox_Choice" prefWidth="150.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0" />
|
||||
<TextField fx:id="IdField" layoutX="24.0" layoutY="108.0" promptText="номер" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="125.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</right>
|
||||
<center>
|
||||
<AnchorPane fx:id="wrapperCanvas" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<Canvas fx:id="canvasCollection" height="600.0" width="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</center>
|
||||
</BorderPane>
|
Loading…
x
Reference in New Issue
Block a user