PIbd-21 Belianin N.N. LabWork05 Hard #6
@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
|
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -18,6 +18,9 @@ public class DrawingStarOrnament implements IOrnamentForm {
|
||||
case 4:
|
||||
wheels = CountWheels.Four;
|
||||
break;
|
||||
case 5:
|
||||
wheels = CountWheels.Five;
|
||||
break;
|
||||
default:
|
||||
wheels = CountWheels.Two;
|
||||
break;
|
||||
@ -27,7 +30,7 @@ public class DrawingStarOrnament implements IOrnamentForm {
|
||||
public void CaterpillarStar(Graphics g, int _startPosX, int _startPosY) {
|
||||
StarColor = Color.RED;
|
||||
g.setColor(StarColor);
|
||||
int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 12, _startPosX + 11, _startPosX + 15, _startPosX + 16};
|
||||
int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 13, _startPosX + 12, _startPosX + 15, _startPosX + 16};
|
||||
int yPontsStar[] = {_startPosY + 35, _startPosY + 38, _startPosY + 38, _startPosY + 42, _startPosY + 45, _startPosY + 42, _startPosY + 45, _startPosY + 41, _startPosY + 38, _startPosY + 38, _startPosY + 35};
|
||||
g.drawPolygon(xPontsStar, yPontsStar, xPontsStar.length);
|
||||
g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length);
|
||||
@ -38,6 +41,9 @@ public class DrawingStarOrnament implements IOrnamentForm {
|
||||
g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20);
|
||||
}
|
||||
public void Draw(Graphics g, int _startPosX, int _startPosY) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
|
||||
if (wheels == CountWheels.Two){
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
@ -18,6 +18,9 @@ public class DrawingSuspensionOrnament implements IOrnamentForm {
|
||||
case 4:
|
||||
wheels = CountWheels.Four;
|
||||
break;
|
||||
case 5:
|
||||
wheels = CountWheels.Five;
|
||||
break;
|
||||
default:
|
||||
wheels = CountWheels.Two;
|
||||
break;
|
||||
@ -29,19 +32,17 @@ public class DrawingSuspensionOrnament implements IOrnamentForm {
|
||||
g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20);
|
||||
}
|
||||
|
||||
public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) {
|
||||
SuspensionColor = Color.BLUE;
|
||||
g.setColor(SuspensionColor);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
}
|
||||
|
||||
public void Draw(Graphics g, int _startPosX, int _startPosY) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
|
||||
if (wheels == CountWheels.Two) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
SuspensionColor = Color.RED;
|
||||
g.setColor(SuspensionColor);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3);
|
||||
}
|
||||
|
||||
if (wheels == CountWheels.Three) {
|
||||
@ -49,22 +50,23 @@ public class DrawingSuspensionOrnament implements IOrnamentForm {
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3);
|
||||
}
|
||||
|
||||
if (wheels == CountWheels.Four) {
|
||||
if (wheels == CountWheels.Four || wheels == CountWheels.Five) {
|
||||
// Можно подкорректировать с 4ой и 5ой, чтобы с колёсами было чуть поточнее
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 25, _startPosY);
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 75, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 53, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ public class DrawingTank extends DrawingArmoVehicle {
|
||||
protected IOrnamentForm OrnamentsForm;
|
||||
private boolean OrnamentAdd;
|
||||
|
||||
// Конструктор (Инициализация характеристик)
|
||||
public DrawingTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height, boolean ornamentAdd) {
|
||||
super(speed, weight, bodyColor, _numWheel, width, height);
|
||||
ArmoVehicle = new EntityTank(speed, weight, bodyColor, _numWheel, additionalColor, bodyKit, caterpillar, tower);
|
||||
@ -13,11 +12,16 @@ public class DrawingTank extends DrawingArmoVehicle {
|
||||
this.OrnamentAdd = ornamentAdd;
|
||||
}
|
||||
|
||||
// Ещё один конструктор
|
||||
public DrawingTank(EntityTank tank, IOrnamentForm _wheelDrawing, int width, int height) {
|
||||
super(tank, _wheelDrawing, width, height);
|
||||
public DrawingTank(int speed, float weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height) {
|
||||
super(speed, weight, bodyColor, _numWheel, width, height);
|
||||
ArmoVehicle=new EntityTank(speed,weight,bodyColor,_numWheel, additionalColor,bodyKit,caterpillar, tower);
|
||||
}
|
||||
|
||||
public DrawingTank(EntityTank armoVehicle, IOrnamentForm _wheelDrawing, int width, int height) {
|
||||
super(armoVehicle, _wheelDrawing, width, height);
|
||||
if (height < _pictureHeight || width < _pictureWidth)
|
||||
return;
|
||||
ArmoVehicle = armoVehicle;
|
||||
}
|
||||
|
||||
// Установка позиции
|
||||
|
@ -18,6 +18,9 @@ public class DrawingWheelsCombination implements IOrnamentForm {
|
||||
case 4:
|
||||
wheels = CountWheels.Four;
|
||||
break;
|
||||
case 5:
|
||||
wheels = CountWheels.Five;
|
||||
break;
|
||||
default:
|
||||
wheels = CountWheels.Two;
|
||||
break;
|
||||
@ -33,24 +36,22 @@ public class DrawingWheelsCombination implements IOrnamentForm {
|
||||
g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length);
|
||||
}
|
||||
|
||||
public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) {
|
||||
CombinationColor = Color.BLUE;
|
||||
g.setColor(CombinationColor);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
}
|
||||
|
||||
public void DrawWheels(Graphics g, int _startPosX, int _startPosY){
|
||||
public void DrawWheels(Graphics g, int _startPosX, int _startPosY) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20);
|
||||
}
|
||||
|
||||
public void Draw(Graphics g, int _startPosX, int _startPosY) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
|
||||
if (wheels == CountWheels.Two){
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 105, _startPosY + 12);
|
||||
@ -61,9 +62,10 @@ public class DrawingWheelsCombination implements IOrnamentForm {
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 100, _startPosY + 50, 10, 3);
|
||||
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 55, _startPosY + 12);
|
||||
@ -76,10 +78,10 @@ public class DrawingWheelsCombination implements IOrnamentForm {
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 53, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 30, _startPosY + 12);
|
||||
@ -94,10 +96,10 @@ public class DrawingWheelsCombination implements IOrnamentForm {
|
||||
DrawWheels(g,_startPosX + 75, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 53, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3);
|
||||
g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 30, _startPosY + 12);
|
||||
|
@ -7,6 +7,7 @@ public class EntityArmoVehicle {
|
||||
return Weight;
|
||||
}
|
||||
public Color BodyColor;
|
||||
public void setBodyColor(Color color){ BodyColor = color; }
|
||||
public double Step;
|
||||
public int numWheel;
|
||||
|
||||
|
@ -2,6 +2,7 @@ import java.awt.*;
|
||||
|
||||
public class EntityTank extends EntityArmoVehicle {
|
||||
public Color AdditionalColor;
|
||||
public void setAdditionalColor(Color color) { AdditionalColor = color; }
|
||||
public boolean BodyKit;
|
||||
public boolean Caterpillar;
|
||||
public boolean Tower;
|
||||
@ -13,7 +14,4 @@ public class EntityTank extends EntityArmoVehicle {
|
||||
Caterpillar = caterpillar;
|
||||
Tower = tower;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -22,8 +22,8 @@ public class FormTankCollection {
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
if (obj.ShowTank() != null) {
|
||||
g.drawImage(obj.ShowTank(), 0, 0, this);
|
||||
if (obj.ShowTanks() != null) {
|
||||
g.drawImage(obj.ShowTanks(), 0, 0, this);
|
||||
}
|
||||
super.repaint();
|
||||
}
|
||||
@ -74,11 +74,11 @@ public class FormTankCollection {
|
||||
return;
|
||||
}
|
||||
|
||||
FormTank form = new FormTank();
|
||||
form.buttonSelectTank.addActionListener(
|
||||
FormTankConfig form = new FormTankConfig();
|
||||
form.buttonAdd.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (obj.Add(form._drawingVehicle) != -1) {
|
||||
if (obj != null && obj.Add(form._vehicle) != -1) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
Draw();
|
||||
} else {
|
||||
@ -152,14 +152,14 @@ public class FormTankCollection {
|
||||
JButton ButtonRefreshCollection = new JButton("Обновить коллекцию");
|
||||
ButtonRefreshCollection.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
JButton toFormTankGenerate = new JButton("Генерировать технику");
|
||||
toFormTankGenerate.addActionListener(
|
||||
JButton FormTankGenerate = new JButton("Генерация");
|
||||
FormTankGenerate.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FormTankGenerate formTankGenerate = new FormTankGenerate();
|
||||
@ -210,30 +210,33 @@ public class FormTankCollection {
|
||||
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Frame.setLayout(null);
|
||||
canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight);
|
||||
ButtonAddVehicle.setBounds(pictureBoxWidth - 10, 10, 170, 30);
|
||||
TextBoxNumber.setBounds(pictureBoxWidth - 10, 50, 170, 30);
|
||||
ButtonRemoveTank.setBounds(pictureBoxWidth - 10, 90, 170, 30);
|
||||
ButtonRefreshCollection.setBounds(pictureBoxWidth - 10, 130, 170, 30);
|
||||
toFormTankGenerate.setBounds(pictureBoxWidth - 10, 170, 170, 30);
|
||||
ButtonAddVehicle.setBounds(pictureBoxWidth, 0, 160, 20);
|
||||
TextBoxNumber.setBounds(pictureBoxWidth, 30, 160, 20);
|
||||
ButtonRemoveTank.setBounds(pictureBoxWidth, 60, 160, 20);
|
||||
ButtonRefreshCollection.setBounds(pictureBoxWidth, 90, 160, 20);
|
||||
FormTankGenerate.setBounds(pictureBoxWidth, 120, 160, 20);
|
||||
|
||||
buttonAddSet.setBounds(pictureBoxWidth - 10, 210, 170, 20);
|
||||
textBoxSetName.setBounds(pictureBoxWidth - 10, 240, 170, 20);
|
||||
jListStorage.setBounds(pictureBoxWidth - 10, 270, 170, 80);
|
||||
buttonRemoveSet.setBounds(pictureBoxWidth - 10, 360, 170, 20);
|
||||
buttonAddSet.setBounds(pictureBoxWidth, 150, 160, 20);
|
||||
textBoxSetName.setBounds(pictureBoxWidth, 180, 160, 20);
|
||||
jListStorage.setBounds(pictureBoxWidth, 210, 160, 80);
|
||||
buttonRemoveSet.setBounds(pictureBoxWidth, 300, 160, 20);
|
||||
|
||||
buttonGetRemoved.setBounds(pictureBoxWidth - 10, 390, 170, 20);
|
||||
buttonGetRemoved.setBounds(pictureBoxWidth, 330, 160, 20);
|
||||
|
||||
Frame.add(canv);
|
||||
Frame.add(ButtonAddVehicle);
|
||||
Frame.add(ButtonRemoveTank);
|
||||
Frame.add(ButtonRefreshCollection);
|
||||
Frame.add(TextBoxNumber);
|
||||
Frame.add(toFormTankGenerate);
|
||||
Frame.add(FormTankGenerate);
|
||||
|
||||
Frame.add(buttonAddSet);
|
||||
Frame.add(textBoxSetName);
|
||||
Frame.add(jListStorage);
|
||||
Frame.add(buttonRemoveSet);
|
||||
|
||||
Frame.add(buttonGetRemoved);
|
||||
|
||||
Frame.setVisible(true);
|
||||
}
|
||||
}
|
389
Tank/src/FormTankConfig.java
Normal file
389
Tank/src/FormTankConfig.java
Normal file
@ -0,0 +1,389 @@
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FormTankConfig {
|
||||
private class Canvas extends JComponent {
|
||||
public Canvas() { }
|
||||
|
||||
public void paintComponent (Graphics g) {
|
||||
if(_vehicle == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
_vehicle.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
//Класс для перетаскивания объекта на формочку
|
||||
private class LabelTransferHandler extends TransferHandler {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) { return TransferHandler.COPY; }
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable (JComponent c) { return new StringSelection(((JLabel)c).getText()); }
|
||||
}
|
||||
|
||||
// Класс для возможности передвижения цвета
|
||||
private class ColorTransferable implements Transferable {
|
||||
private Color color;
|
||||
private static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color");
|
||||
public ColorTransferable(Color color) { this.color = color; }
|
||||
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[]{ colorDataFlavor }; }
|
||||
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) { return colorDataFlavor.equals(flavor); }
|
||||
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||
if(isDataFlavorSupported(flavor)) {
|
||||
return color;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Для перетаскивания цвета к объекту
|
||||
private class PanelTransferHandler extends TransferHandler {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) { return TransferHandler.COPY; }
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new ColorTransferable(((JPanel)c).getBackground());
|
||||
}
|
||||
}
|
||||
|
||||
// Для обработки нажатий
|
||||
private class LabelMouseAdapter extends MouseAdapter {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JLabel)e.getComponent()).getTransferHandler().exportAsDrag(((JLabel)e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
}
|
||||
|
||||
private class PanelMouseAdapter extends MouseAdapter {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JPanel)e.getComponent()).getTransferHandler().exportAsDrag(((JPanel)e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
}
|
||||
|
||||
// Для передвижения wheels по формочке
|
||||
private class WheelTransferable implements Transferable {
|
||||
private IOrnamentForm wheelDrawing;
|
||||
private static final DataFlavor wheelDrawingDataFlavor = new DataFlavor(IOrnamentForm.class, "Wheel Drawing");
|
||||
public WheelTransferable(IOrnamentForm wheelDrawing) { this.wheelDrawing = wheelDrawing; }
|
||||
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) { return flavor.equals(wheelDrawingDataFlavor); }
|
||||
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { wheelDrawingDataFlavor }; }
|
||||
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||
if(isDataFlavorSupported(flavor)) {
|
||||
return wheelDrawing;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Для отрисовки wheels, которые можно брать и перетаскивать на объект
|
||||
private class ComponentWheel extends JComponent {
|
||||
public IOrnamentForm wheelDrawing;
|
||||
|
||||
// Конструктор
|
||||
public ComponentWheel(IOrnamentForm _wheelDrawing) {
|
||||
wheelDrawing = _wheelDrawing;
|
||||
this.addMouseListener(
|
||||
new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((ComponentWheel) e.getComponent()).getTransferHandler().exportAsDrag(((ComponentWheel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
});
|
||||
this.setTransferHandler(
|
||||
new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelTransferable(((ComponentWheel)c).wheelDrawing);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
wheelDrawing.Draw(g2d,-10, -42); //!!!!
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
final int WindowHeight = 700;
|
||||
final int WindowWidth = 1000;
|
||||
final int CanvasHeight = 600;
|
||||
final int CanvasWidth = 800;
|
||||
public DrawingArmoVehicle _vehicle = null;
|
||||
public JButton buttonAdd;
|
||||
public JFrame Frame;
|
||||
public Canvas canvas;
|
||||
|
||||
public FormTankConfig() {
|
||||
Border border = BorderFactory.createLineBorder(Color.GRAY);
|
||||
JLabel labelSpeed = new JLabel("Speed");
|
||||
JLabel labelWeight = new JLabel("Weight");
|
||||
JLabel labelWheelNum = new JLabel("Wheel");
|
||||
SpinnerModel spinnerModel = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||
JSpinner numericSpeed = new JSpinner(spinnerModel);
|
||||
SpinnerModel spinnerModel2 = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||
JSpinner numericWeight = new JSpinner(spinnerModel2);
|
||||
SpinnerModel spinnerModel3 = new SpinnerNumberModel(2, 2, 5, 1);
|
||||
JSpinner numericWheelNum = new JSpinner(spinnerModel3);
|
||||
JCheckBox checkBoxBodyKit = new JCheckBox("BodyKit");
|
||||
JCheckBox checkBoxCaterpillar = new JCheckBox("Caterpillar");
|
||||
JCheckBox checkBoxTower = new JCheckBox("Tower");
|
||||
JPanel[] colorPanels = {
|
||||
new JPanel(),new JPanel(),new JPanel(),new JPanel(),
|
||||
new JPanel(),new JPanel(),new JPanel(),new JPanel(),
|
||||
};
|
||||
colorPanels[0].setBackground(Color.BLACK);
|
||||
colorPanels[1].setBackground(Color.BLUE);
|
||||
colorPanels[2].setBackground(Color.GRAY);
|
||||
colorPanels[3].setBackground(Color.YELLOW);
|
||||
colorPanels[4].setBackground(Color.RED);
|
||||
colorPanels[5].setBackground(Color.GREEN);
|
||||
colorPanels[6].setBackground(Color.ORANGE);
|
||||
colorPanels[7].setBackground(Color.WHITE);
|
||||
for (var it : colorPanels){
|
||||
it.setTransferHandler(new PanelTransferHandler());
|
||||
it.addMouseListener(new PanelMouseAdapter());
|
||||
}
|
||||
|
||||
JLabel labelArmoVehicle = new JLabel("ArmoVehicle");
|
||||
labelArmoVehicle.setTransferHandler(new LabelTransferHandler());
|
||||
labelArmoVehicle.addMouseListener(new LabelMouseAdapter());
|
||||
labelArmoVehicle.setBorder(border);
|
||||
labelArmoVehicle.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
labelArmoVehicle.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
||||
JLabel labelTank = new JLabel("Tank");
|
||||
labelTank.setTransferHandler(new LabelTransferHandler());
|
||||
labelTank.addMouseListener(new LabelMouseAdapter());
|
||||
labelTank.setBorder(border);
|
||||
labelTank.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
labelTank.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
||||
JLabel labelColor = new JLabel("Color");
|
||||
labelColor.setBorder(border);
|
||||
labelColor.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
labelColor.setVerticalAlignment(SwingConstants.CENTER);
|
||||
labelColor.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferSupport support) {
|
||||
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
if (canImport(support)) {
|
||||
try {
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
if (_vehicle == null)
|
||||
return false;
|
||||
_vehicle.ArmoVehicle.setBodyColor(color);
|
||||
canvas.repaint();
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
JLabel labelAdditionalColor = new JLabel("Additional color");
|
||||
labelAdditionalColor.setBorder(border);
|
||||
labelAdditionalColor.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
labelAdditionalColor.setVerticalAlignment(SwingConstants.CENTER);
|
||||
labelAdditionalColor.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferSupport support) {
|
||||
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
if (canImport(support)) {
|
||||
try {
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
if (_vehicle == null)
|
||||
return false;
|
||||
if (!(_vehicle instanceof DrawingTank))
|
||||
return false;
|
||||
((EntityTank)_vehicle.ArmoVehicle).setAdditionalColor(color);
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
JLabel labelWheel = new JLabel("Wheel");
|
||||
labelWheel.setBorder(border);
|
||||
labelWheel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
labelWheel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
labelWheel.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferSupport support) {
|
||||
return support.isDataFlavorSupported(WheelTransferable.wheelDrawingDataFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
if (canImport(support)) {
|
||||
try {
|
||||
IOrnamentForm wheelDrawing = (IOrnamentForm) support.getTransferable().getTransferData(WheelTransferable.wheelDrawingDataFlavor);
|
||||
if (_vehicle == null)
|
||||
return false;
|
||||
wheelDrawing.setDigit(_vehicle.ArmoVehicle.numWheel);
|
||||
_vehicle.OrnamentsForm = wheelDrawing;
|
||||
canvas.repaint();
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
canvas = new Canvas();
|
||||
canvas.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferSupport support) {
|
||||
return support.isDataFlavorSupported(DataFlavor.stringFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
if (canImport(support)) {
|
||||
try {
|
||||
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||
switch (data) {
|
||||
case "ArmoVehicle":
|
||||
_vehicle = new DrawingArmoVehicle((int)numericSpeed.getValue(), (int)numericWeight.getValue(), Color.WHITE, (int)numericWheelNum.getValue(), CanvasWidth,CanvasHeight);
|
||||
break;
|
||||
case "Tank":
|
||||
_vehicle = new DrawingTank((int)numericSpeed.getValue(), (int)numericWeight.getValue(), Color.WHITE, (int)numericWheelNum.getValue(), Color.BLACK, checkBoxBodyKit.isSelected(), checkBoxCaterpillar.isSelected(), checkBoxTower.isSelected(), CanvasWidth, CanvasHeight);
|
||||
break;
|
||||
}
|
||||
canvas.repaint();
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
buttonAdd = new JButton("Add");
|
||||
JButton buttonCancel = new JButton("Cancel");
|
||||
|
||||
ComponentWheel componentSuspensionOrnament = new ComponentWheel(new DrawingSuspensionOrnament());
|
||||
ComponentWheel componentAsteriskOrnament = new ComponentWheel(new DrawingStarOrnament());
|
||||
ComponentWheel componentWheelCombination = new ComponentWheel(new DrawingWheelsCombination());
|
||||
|
||||
labelSpeed.setBounds(10,10,40,20);
|
||||
labelWeight.setBounds(10,40,40,20);
|
||||
labelWheelNum.setBounds(10,70,40,20);
|
||||
numericSpeed.setBounds(55,10,80,20);
|
||||
numericWeight.setBounds(55,40,80,20);
|
||||
numericWheelNum.setBounds(55,70,80,20);
|
||||
checkBoxBodyKit.setBounds(10,100,120,20);
|
||||
checkBoxCaterpillar.setBounds(10,130,120,20);
|
||||
checkBoxTower.setBounds(10,160,120,20);
|
||||
for (int i = 0; i < colorPanels.length; i+=2) {
|
||||
colorPanels[i].setBounds(10,200+i/2*60,50,50);
|
||||
colorPanels[i+1].setBounds(70,200+i/2*60,50,50);
|
||||
}
|
||||
componentSuspensionOrnament.setBounds(10,470,25,20); //!!!!!!!!!!!!!
|
||||
componentAsteriskOrnament.setBounds(50,470,20,20);
|
||||
componentWheelCombination.setBounds(90,470,25,20);
|
||||
labelArmoVehicle.setBounds(10,600 ,80,30);
|
||||
labelTank.setBounds(100,600 ,80,30);
|
||||
|
||||
labelColor.setBounds(WindowWidth-CanvasWidth, 10, CanvasWidth/3, 30);
|
||||
labelAdditionalColor.setBounds(WindowWidth-CanvasWidth + CanvasWidth/3, 10, CanvasWidth/3, 30);
|
||||
labelWheel.setBounds(WindowWidth-CanvasWidth + CanvasWidth*2/3, 10, CanvasWidth/3, 30);
|
||||
canvas.setBounds(WindowWidth-CanvasWidth, 50, CanvasWidth, CanvasHeight);
|
||||
buttonAdd.setBounds(WindowWidth-CanvasWidth, CanvasHeight+60, CanvasWidth/3, 30);
|
||||
buttonCancel.setBounds(WindowWidth-CanvasWidth + CanvasWidth*2/3, CanvasHeight+60, CanvasWidth/3, 30);
|
||||
|
||||
Frame = new JFrame();
|
||||
Frame.setSize (WindowWidth+20, WindowHeight+40);
|
||||
Frame.setLayout(null);
|
||||
Frame.add(labelSpeed);
|
||||
Frame.add(labelWeight);
|
||||
Frame.add(labelWheelNum);
|
||||
Frame.add(numericSpeed);
|
||||
Frame.add(numericWeight);
|
||||
Frame.add(numericWheelNum);
|
||||
Frame.add(checkBoxBodyKit);
|
||||
Frame.add(checkBoxCaterpillar);
|
||||
Frame.add(checkBoxTower);
|
||||
for (var it : colorPanels)
|
||||
Frame.add(it);
|
||||
Frame.add(labelArmoVehicle);
|
||||
Frame.add(labelTank);
|
||||
Frame.add(labelColor);
|
||||
Frame.add(labelAdditionalColor);
|
||||
Frame.add(labelWheel);
|
||||
Frame.add(canvas);
|
||||
Frame.add(buttonAdd);
|
||||
Frame.add(buttonCancel);
|
||||
Frame.add(componentSuspensionOrnament);
|
||||
Frame.add(componentAsteriskOrnament);
|
||||
Frame.add(componentWheelCombination);
|
||||
|
||||
Frame.setVisible(true);
|
||||
|
||||
buttonCancel.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Frame.dispose();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -41,9 +41,9 @@ public class FormTankGenerate extends JFrame {
|
||||
creatButton.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
_drawingTank = genericTankGenerate.GenerateTank(pictureBoxWidth,pictureBoxHeight);
|
||||
canv.repaint();
|
||||
}
|
||||
_drawingTank = genericTankGenerate.GenerateTank(pictureBoxWidth,pictureBoxHeight);
|
||||
canv.repaint();
|
||||
}
|
||||
}
|
||||
);
|
||||
creatButton.setBounds(pictureBoxWidth/2 - 40, pictureBoxHeight-20, 180, 20);
|
||||
|
@ -4,7 +4,7 @@ public class SetGeneric <T extends Object> {
|
||||
// Массив объектов, которые храним
|
||||
private final ArrayList<T> _places;
|
||||
// Количество объектов в массиве
|
||||
public int Count() { return _places.size(); }
|
||||
public int Count() { return _places.size(); }
|
||||
// Максимальное количество объектов в списке
|
||||
private final int _maxCount;
|
||||
|
||||
@ -44,7 +44,7 @@ public class SetGeneric <T extends Object> {
|
||||
if (position < 0 || position >= _places.size())
|
||||
return false;
|
||||
_places.remove(position);
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Получение объекта из набора по позиции
|
||||
|
@ -72,6 +72,8 @@ public class TanksGenericCollections<T extends DrawingArmoVehicle, U extends IMo
|
||||
int i = 0;
|
||||
for (T tank : _collection.GetTanks(100)) {
|
||||
if (tank != null) {
|
||||
tank._pictureHeight = _pictureHeight;
|
||||
tank._pictureWidth = _pictureWidth;
|
||||
tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||
if (tank instanceof DrawingTank)
|
||||
((DrawingTank) tank).DrawTransport((Graphics2D) g);
|
||||
|
Loading…
Reference in New Issue
Block a user