PIbd-23_Nasyrov_A_G_Lab5_hard #5
@ -8,16 +8,31 @@ import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class DrawningAirplane {
|
||||
protected EntityAirplane EntityAirplane;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
public int _pictureWidth;
|
||||
public int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
protected IDraw DrawningIlluminators;
|
||||
private int _airplaneWidth = 200;
|
||||
private int _airplaneHeight = 78;
|
||||
public int _airplaneWidth = 200;
|
||||
public int _airplaneHeight = 78;
|
||||
public int _illuminatorsNumb;
|
||||
public EntityAirplane EntityAirplane(){
|
||||
return EntityAirplane;
|
||||
}
|
||||
public void ChangeColor(Color col){
|
||||
EntityAirplane.BodyColor = col;
|
||||
}
|
||||
public void ChangeIDraw(IDraw obj){
|
||||
DrawningIlluminators = obj;
|
||||
obj.ChangeIlluminatorNumb(_illuminatorsNumb);
|
||||
//obj.ChangeIlluminatorNumb(_illuminatorsNumb);
|
||||
obj.ChangeX(_startPosX);
|
||||
obj.ChangeY(_startPosY);
|
||||
}
|
||||
public void ChangeIlluminatorNumb(int numb){
|
||||
_illuminatorsNumb = numb;
|
||||
DrawningIlluminators.ChangeIlluminatorNumb(numb);
|
||||
}
|
||||
public DrawningAirplane(int speed, double weight, Color bodyColor, int width, int height){
|
||||
if(width <= _airplaneWidth || height <= _airplaneHeight)
|
||||
return;
|
||||
|
@ -11,6 +11,10 @@ public class DrawningAirplaneWithRadar extends DrawningAirplane {
|
||||
EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, additionalColor, radar,dopBak);
|
||||
}
|
||||
}
|
||||
public void ChangeAddColor(Color col){
|
||||
((EntityAirplaneWithRadar)EntityAirplane).AdditionalColor = col;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawAirplane(Graphics2D g2d){
|
||||
if(!(EntityAirplane instanceof EntityAirplaneWithRadar)){
|
||||
|
@ -22,11 +22,11 @@ public class DrawningIlluminators implements IDraw{
|
||||
CurY = y;
|
||||
}
|
||||
public void ChangeIlluminatorNumb(int x){
|
||||
if(x <= 2)
|
||||
if(x <= 10)
|
||||
IlluminatorNumb = NumberType.Ten;
|
||||
if(x == 3)
|
||||
if(x == 20)
|
||||
IlluminatorNumb = NumberType.Twenty;
|
||||
if(x >= 4)
|
||||
if(x >= 30)
|
||||
IlluminatorNumb = NumberType.Thirty;
|
||||
}
|
||||
public NumberType IlluminatorNumb(){
|
||||
|
@ -21,11 +21,11 @@ public class DrawningIlluminatorsCirc implements IDraw {
|
||||
CurY = y;
|
||||
}
|
||||
public void ChangeIlluminatorNumb(int x){
|
||||
if(x <= 2)
|
||||
if(x <= 10)
|
||||
IlluminatorNumb = NumberType.Ten;
|
||||
if(x == 3)
|
||||
if(x == 20)
|
||||
IlluminatorNumb = NumberType.Twenty;
|
||||
if(x >= 4)
|
||||
if(x >= 30)
|
||||
IlluminatorNumb = NumberType.Thirty;
|
||||
}
|
||||
public NumberType IlluminatorNumb(){
|
||||
|
@ -17,11 +17,11 @@ public class DrawningIlluminatorsQuad implements IDraw {
|
||||
CurY = curY;
|
||||
}
|
||||
public void ChangeIlluminatorNumb(int x){
|
||||
if(x <= 2)
|
||||
if(x <= 10)
|
||||
IlluminatorNumb = NumberType.Ten;
|
||||
if(x == 3)
|
||||
if(x == 20)
|
||||
IlluminatorNumb = NumberType.Twenty;
|
||||
if(x >= 4)
|
||||
if(x >= 30)
|
||||
IlluminatorNumb = NumberType.Thirty;
|
||||
}
|
||||
public void ChangeX(int x){
|
||||
|
@ -3,7 +3,7 @@ import java.awt.*;
|
||||
public class EntityAirplane {
|
||||
private int Speed;
|
||||
private double Weight, Step;
|
||||
private Color BodyColor;
|
||||
public Color BodyColor;
|
||||
public int Speed(){
|
||||
return Speed;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package src.Entities;
|
||||
import java.awt.*;
|
||||
public class EntityAirplaneWithRadar extends EntityAirplane {
|
||||
private Color AdditionalColor;
|
||||
public Color AdditionalColor;
|
||||
private boolean Radar;
|
||||
private boolean DopBak;
|
||||
public Color AdditionalColor(){return AdditionalColor;}
|
||||
|
@ -20,25 +20,27 @@ public class FormAirplaneCollection {
|
||||
private int pictureBoxWidth = 630;
|
||||
private int pictureBoxHeight = 426;
|
||||
CollectionCanvas canv;
|
||||
void Draw(){
|
||||
if(canv == null)
|
||||
|
||||
void Draw() {
|
||||
if (canv == null)
|
||||
return;
|
||||
canv.repaint();
|
||||
}
|
||||
private void ReloadObjects(){
|
||||
|
||||
private void ReloadObjects() {
|
||||
int index = listBoxStorages.getSelectedIndex();
|
||||
listBoxModel.clear();
|
||||
List<String> keys = _storage.Keys();
|
||||
for(int i = 0; i < keys.size(); i++){
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
listBoxModel.addElement(keys.get(i));
|
||||
}
|
||||
if(listBoxModel.size() > 0 && (index == -1 || index >= listBoxModel.size()))
|
||||
if (listBoxModel.size() > 0 && (index == -1 || index >= listBoxModel.size()))
|
||||
listBoxStorages.setSelectedIndex(0);
|
||||
else if(listBoxModel.size() > 0)
|
||||
else if (listBoxModel.size() > 0)
|
||||
listBoxStorages.setSelectedIndex(index);
|
||||
}
|
||||
|
||||
public FormAirplaneCollection(){
|
||||
public FormAirplaneCollection() {
|
||||
AirplaneTrashCollection<DrawningAirplane> _trashCollection = new AirplaneTrashCollection<>();
|
||||
JButton callTrashButton = new JButton("Мусор");
|
||||
_storage = new AirplaneGenericStorage(pictureBoxWidth, pictureBoxHeight);
|
||||
@ -48,20 +50,20 @@ public class FormAirplaneCollection {
|
||||
JTextField storageName = new JTextField();
|
||||
JButton addStorageButton = new JButton("Добавить набор");
|
||||
listBoxModel = new DefaultListModel<>();
|
||||
listBoxStorages= new JList<>(listBoxModel);
|
||||
listBoxStorages = new JList<>(listBoxModel);
|
||||
scrollPane.setViewportView(listBoxStorages);
|
||||
JButton delStorageButton = new JButton("Удалить набор");
|
||||
//toolBox.setBounds(623,12, 227, 80);
|
||||
JFrame collectionFrame = new JFrame();
|
||||
collectionFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
collectionFrame.setSize(880,497);
|
||||
collectionFrame.setSize(880, 497);
|
||||
toolBox.setBounds(623, 12, 227, 426);
|
||||
canv.setBounds(12,12,pictureBoxWidth,pictureBoxHeight);
|
||||
canv.setBounds(12, 12, pictureBoxWidth, pictureBoxHeight);
|
||||
JButton addButton = new JButton("Добавить");
|
||||
JButton removeButton = new JButton("Удалить");
|
||||
JButton refreshButton = new JButton("Обновить");
|
||||
JTextField airplaneNumb = new JTextField();
|
||||
GridLayout lay = new GridLayout(9,1);
|
||||
GridLayout lay = new GridLayout(9, 1);
|
||||
toolBox.add(storageName);
|
||||
toolBox.add(addStorageButton);
|
||||
toolBox.add(scrollPane);
|
||||
@ -81,7 +83,7 @@ public class FormAirplaneCollection {
|
||||
addStorageButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(storageName.getText() == null)
|
||||
if (storageName.getText() == null)
|
||||
return;
|
||||
_storage.AddSet(storageName.getText());
|
||||
ReloadObjects();
|
||||
@ -91,7 +93,7 @@ public class FormAirplaneCollection {
|
||||
delStorageButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
_storage.DelSet(listBoxStorages.getSelectedValue());
|
||||
@ -102,7 +104,7 @@ public class FormAirplaneCollection {
|
||||
callTrashButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_trashCollection.GetSize() == 0)
|
||||
if (_trashCollection.GetSize() == 0)
|
||||
return;
|
||||
FormAirplaneWithRadar form = new FormAirplaneWithRadar();
|
||||
form.ChangeAirplane(_trashCollection.GetTop());
|
||||
@ -113,23 +115,31 @@ public class FormAirplaneCollection {
|
||||
addButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
FormAirplaneWithRadar form = new FormAirplaneWithRadar();
|
||||
form.buttonSelect.addActionListener(new ActionListener() {
|
||||
FormAirplaneConfig form = new FormAirplaneConfig();
|
||||
form.addButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_airplanes.Insert(form.SelectedAirplane()))
|
||||
{
|
||||
if (_airplanes.Insert(form._airplane)) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
form._airplane._pictureWidth = pictureBoxWidth;
|
||||
form._airplane._pictureHeight = pictureBoxHeight;
|
||||
Draw();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
|
||||
}
|
||||
form.AirplaneFrame.dispose();
|
||||
form.frameConfig.dispose();
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
form.cancelButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
form.frameConfig.dispose();
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
@ -138,19 +148,18 @@ public class FormAirplaneCollection {
|
||||
removeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
if(_airplanes == null) {
|
||||
if (_airplanes == null) {
|
||||
return;
|
||||
}
|
||||
String tmp = airplaneNumb.getText();
|
||||
int numb;
|
||||
try{
|
||||
try {
|
||||
numb = Integer.parseInt(tmp);
|
||||
}
|
||||
catch(Exception ex){
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Введите число", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
@ -166,11 +175,11 @@ public class FormAirplaneCollection {
|
||||
refreshButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
if(_airplanes == null) {
|
||||
if (_airplanes == null) {
|
||||
return;
|
||||
}
|
||||
_airplanes.ShowAirplanes();
|
||||
@ -178,21 +187,23 @@ public class FormAirplaneCollection {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class CollectionCanvas extends JComponent {
|
||||
public AirplaneGenericStorage _storage;
|
||||
public JList<String> listBoxStorages;
|
||||
public CollectionCanvas(){
|
||||
}
|
||||
@Override
|
||||
public void paintComponent (Graphics g){
|
||||
if (listBoxStorages == null || listBoxStorages.getSelectedIndex() == -1){
|
||||
return;
|
||||
class CollectionCanvas extends JComponent {
|
||||
public AirplaneGenericStorage _storage;
|
||||
public JList<String> listBoxStorages;
|
||||
|
||||
public CollectionCanvas() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
if (listBoxStorages == null || listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.drawImage(_storage.Get(listBoxStorages.getSelectedValue()).ShowAirplanes(), 0, 0, this);
|
||||
super.repaint();
|
||||
}
|
||||
super.paintComponents (g) ;
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
g2d.drawImage(_storage.Get(listBoxStorages.getSelectedValue()).ShowAirplanes(), 0, 0, this);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
452
src/FormAirplaneConfig.java
Normal file
452
src/FormAirplaneConfig.java
Normal file
@ -0,0 +1,452 @@
|
||||
package src;
|
||||
|
||||
import src.DrawningObjects.*;
|
||||
|
||||
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 java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.lang.Integer.parseInt;
|
||||
|
||||
public class FormAirplaneConfig {
|
||||
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 iDrawTransferable implements Transferable {
|
||||
private IDraw iDrawObject;
|
||||
private static final DataFlavor iDrawDataFlavor = new DataFlavor(IDraw.class, "IDraw");
|
||||
public iDrawTransferable(IDraw iDrawObject) {
|
||||
this.iDrawObject = iDrawObject;
|
||||
}
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{iDrawDataFlavor};
|
||||
}
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return iDrawDataFlavor.equals(flavor);
|
||||
}
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return iDrawObject;
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
private class IDrawComponent extends JComponent{
|
||||
public IDraw obj;
|
||||
|
||||
public IDrawComponent(IDraw obj){
|
||||
this.obj = obj;
|
||||
this.addMouseListener(
|
||||
new MouseAdapter(){
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((IDrawComponent)e.getComponent()).getTransferHandler().exportAsDrag(((IDrawComponent)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 iDrawTransferable(((IDrawComponent)c).obj);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public JFrame frameConfig;
|
||||
|
||||
public JButton addButton;
|
||||
public JButton cancelButton;
|
||||
public DrawningAirplane _airplane;
|
||||
int _pictureBoxWidth = 218;
|
||||
int _pictureBoxHeight = 190;
|
||||
|
||||
public FormAirplaneConfig(){
|
||||
frameConfig = new JFrame();
|
||||
addButton = new JButton("Добавить");
|
||||
cancelButton = new JButton("Отмена");
|
||||
addButton.setBounds(555,262,94,29);
|
||||
cancelButton.setBounds(679,262,94,29);
|
||||
Canvas canv = new Canvas();
|
||||
canv.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
canv.setBounds(555, 65, _pictureBoxWidth, _pictureBoxHeight);
|
||||
JLabel iDrawLabel = new JLabel("Форма");
|
||||
JLabel colorLabel = new JLabel("Цвет");
|
||||
DrawningAirplane toGetSize = new DrawningAirplane(0,0, null, 0, 0);
|
||||
IDrawComponent usualComp = new IDrawComponent(new DrawningIlluminators(toGetSize._airplaneWidth - toGetSize._airplaneWidth / 10,
|
||||
toGetSize._airplaneHeight,
|
||||
_pictureBoxWidth / 2 -toGetSize._airplaneWidth / 2,
|
||||
_pictureBoxHeight / 2 -toGetSize._airplaneHeight / 2));
|
||||
IDrawComponent circComp = new IDrawComponent(new DrawningIlluminatorsCirc(toGetSize._airplaneWidth - toGetSize._airplaneWidth / 10,
|
||||
toGetSize._airplaneHeight,
|
||||
_pictureBoxWidth / 2 -toGetSize._airplaneWidth / 2,
|
||||
_pictureBoxHeight / 2 -toGetSize._airplaneHeight / 2));
|
||||
IDrawComponent quadComp = new IDrawComponent(new DrawningIlluminatorsQuad(toGetSize._airplaneWidth - toGetSize._airplaneWidth / 10,
|
||||
toGetSize._airplaneHeight,
|
||||
_pictureBoxWidth / 2 -toGetSize._airplaneWidth / 2,
|
||||
_pictureBoxHeight / 2 -toGetSize._airplaneHeight / 2));
|
||||
usualComp.setLayout(new GridLayout(1,1));
|
||||
circComp.setLayout(new GridLayout(1,1));
|
||||
quadComp.setLayout(new GridLayout(1,1));
|
||||
iDrawLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
iDrawLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
colorLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
colorLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
JLabel cartLabel = new JLabel("Круглые");
|
||||
JLabel ornLabel = new JLabel("Прозрачные");
|
||||
JLabel baseLabel = new JLabel("Квадратные");
|
||||
cartLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
cartLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
ornLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
ornLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
baseLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
baseLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
||||
usualComp.add(cartLabel);
|
||||
circComp.add(ornLabel);
|
||||
quadComp.add(baseLabel);
|
||||
usualComp.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
circComp.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
quadComp.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
JLabel addColorLabel = new JLabel("Доп цвет");
|
||||
addColorLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
addColorLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
colorLabel.setBounds(555, 20, 70, 33);
|
||||
addColorLabel.setBounds(629, 20, 70, 33);
|
||||
iDrawLabel.setBounds(703, 20, 70, 33);
|
||||
colorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
addColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
iDrawLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
JCheckBox checkRadar = new JCheckBox("Радар");
|
||||
JCheckBox checkDopBak = new JCheckBox("Дополнительный бак");
|
||||
checkRadar.setBounds(6, 132, 159, 24);
|
||||
checkDopBak.setBounds(6, 162, 145, 24);
|
||||
JLabel simpleLabel = new JLabel("Простой");
|
||||
JLabel advancedLabel = new JLabel("Продвинутый");
|
||||
simpleLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
advancedLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
simpleLabel.setBounds(171,169, 120, 50);
|
||||
simpleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
simpleLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
advancedLabel.setBounds(297,169, 120, 50);
|
||||
advancedLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
advancedLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
usualComp.setBounds(171,229, 120, 50);
|
||||
circComp.setBounds(297,229, 120, 50);
|
||||
quadComp.setBounds(423,229, 120, 50);
|
||||
JLabel speedLabel = new JLabel ("Скорость");
|
||||
JLabel weightLabel = new JLabel ("Вес");
|
||||
JPanel colorPanel = new JPanel();
|
||||
colorPanel.setBounds(171, 23, 234,143);
|
||||
SpinnerNumberModel speedSpinnerModel = new SpinnerNumberModel(100.0, 100.0, 1000.0, 1.0);
|
||||
SpinnerNumberModel weightSpinnerModel = new SpinnerNumberModel(100.0, 100.0, 1000.0, 1.0);
|
||||
SpinnerNumberModel illuminatorNumbSpinnerModel = new SpinnerNumberModel(10, 10, 30, 10);
|
||||
JLabel illuminatorLabel = new JLabel ("Количество иллюминаторов");
|
||||
JSpinner illuminatorNumbSpinner = new JSpinner(illuminatorNumbSpinnerModel);
|
||||
JSpinner speedSpinner = new JSpinner(speedSpinnerModel);
|
||||
JSpinner weightSpinner = new JSpinner(weightSpinnerModel);
|
||||
speedSpinner.setBounds(6, 46, 150, 27);
|
||||
speedLabel.setBounds(6, 23, 73, 20);
|
||||
weightSpinner.setBounds(6, 99, 150, 27);
|
||||
weightLabel.setBounds(6, 76, 33, 20);
|
||||
illuminatorLabel.setBounds(6, 200, 150, 27);
|
||||
illuminatorNumbSpinner.setBounds(6, 230, 150, 27);
|
||||
|
||||
JPanel redPanel = new JPanel();
|
||||
JPanel greenPanel = new JPanel();
|
||||
JPanel bluePanel = new JPanel();
|
||||
JPanel yellowPanel = new JPanel();
|
||||
JPanel whitePanel = new JPanel();
|
||||
JPanel grayPanel = new JPanel();
|
||||
JPanel blackPanel = new JPanel();
|
||||
JPanel purplePanel = new JPanel();
|
||||
|
||||
redPanel.setTransferHandler(new PanelTransferHandler());
|
||||
greenPanel.setTransferHandler(new PanelTransferHandler());
|
||||
bluePanel.setTransferHandler(new PanelTransferHandler());
|
||||
yellowPanel.setTransferHandler(new PanelTransferHandler());
|
||||
whitePanel.setTransferHandler(new PanelTransferHandler());
|
||||
grayPanel.setTransferHandler(new PanelTransferHandler());
|
||||
blackPanel.setTransferHandler(new PanelTransferHandler());
|
||||
purplePanel.setTransferHandler(new PanelTransferHandler());
|
||||
|
||||
redPanel.addMouseListener(new PanelMouseAdapter());
|
||||
greenPanel.addMouseListener(new PanelMouseAdapter());
|
||||
bluePanel.addMouseListener(new PanelMouseAdapter());
|
||||
yellowPanel.addMouseListener(new PanelMouseAdapter());
|
||||
whitePanel.addMouseListener(new PanelMouseAdapter());
|
||||
grayPanel.addMouseListener(new PanelMouseAdapter());
|
||||
blackPanel.addMouseListener(new PanelMouseAdapter());
|
||||
purplePanel.addMouseListener(new PanelMouseAdapter());
|
||||
|
||||
redPanel.setName("Красный");
|
||||
greenPanel.setName("Зелёный");
|
||||
bluePanel.setName("Синий");
|
||||
yellowPanel.setName("Жёлтый");
|
||||
whitePanel.setName("Белый");
|
||||
grayPanel.setName("Серый");
|
||||
blackPanel.setName("Чёрный");
|
||||
purplePanel.setName("Фиолетовый");
|
||||
|
||||
|
||||
simpleLabel.setTransferHandler(new LabelTransferHandler());
|
||||
simpleLabel.addMouseListener(new LabelMouseAdapter());
|
||||
|
||||
advancedLabel.setTransferHandler(new LabelTransferHandler());
|
||||
advancedLabel.addMouseListener(new LabelMouseAdapter());
|
||||
|
||||
|
||||
|
||||
redPanel.setBackground(Color.RED);
|
||||
greenPanel.setBackground(Color.GREEN);
|
||||
bluePanel.setBackground(Color.BLUE);
|
||||
yellowPanel.setBackground(Color.YELLOW);
|
||||
whitePanel.setBackground(Color.WHITE);
|
||||
grayPanel.setBackground(Color.GRAY);
|
||||
blackPanel.setBackground(Color.BLACK);
|
||||
purplePanel.setBackground(Color.PINK);
|
||||
|
||||
colorPanel.setLayout(new GridLayout(2, 4));
|
||||
|
||||
colorPanel.add(redPanel);
|
||||
colorPanel.add(greenPanel);
|
||||
colorPanel.add(bluePanel);
|
||||
colorPanel.add(yellowPanel);
|
||||
colorPanel.add(whitePanel);
|
||||
colorPanel.add(grayPanel);
|
||||
colorPanel.add(blackPanel);
|
||||
colorPanel.add(purplePanel);
|
||||
|
||||
|
||||
frameConfig.add(colorLabel);
|
||||
frameConfig.add(addColorLabel);
|
||||
frameConfig.add(iDrawLabel);
|
||||
frameConfig.setLayout(null);
|
||||
frameConfig.setSize(818, 350);
|
||||
frameConfig.add(speedLabel);
|
||||
frameConfig.add(speedSpinner);
|
||||
frameConfig.add(weightLabel);
|
||||
frameConfig.add(illuminatorLabel);
|
||||
frameConfig.add(weightSpinner);
|
||||
frameConfig.add(simpleLabel);
|
||||
frameConfig.add(advancedLabel);
|
||||
frameConfig.add(checkRadar);
|
||||
frameConfig.add(checkDopBak);
|
||||
frameConfig.add(canv);
|
||||
frameConfig.add(addButton);
|
||||
frameConfig.add(cancelButton);
|
||||
frameConfig.add(illuminatorNumbSpinner);
|
||||
|
||||
frameConfig.setVisible(true);
|
||||
frameConfig.add(colorPanel);
|
||||
frameConfig.add(usualComp);
|
||||
frameConfig.add(circComp);
|
||||
frameConfig.add(quadComp);
|
||||
colorPanel.setVisible(true);
|
||||
usualComp.setVisible(true);
|
||||
circComp.setVisible(true);
|
||||
quadComp.setVisible(true);
|
||||
|
||||
canv.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferSupport support) {
|
||||
return support.isDataFlavorSupported(DataFlavor.stringFlavor);
|
||||
}
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
if (canImport(support)) {
|
||||
try {
|
||||
Object speedObj = speedSpinner.getValue();
|
||||
Number speedNumb = (Number) speedObj;
|
||||
int speed = speedNumb.intValue();
|
||||
|
||||
Object weightObj = weightSpinner.getValue();
|
||||
Number weightNumb = (Number) weightObj;
|
||||
int weight = weightNumb.intValue();
|
||||
|
||||
Object illuminatorNumbObj = illuminatorNumbSpinner.getValue();
|
||||
Number illuminatorNumbNumb = (Number) illuminatorNumbObj;
|
||||
int illuminatorNumb = illuminatorNumbNumb.intValue();
|
||||
|
||||
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||
switch (data) {
|
||||
case "Простой":
|
||||
_airplane = new DrawningAirplane(speed, weight, Color.WHITE, _pictureBoxWidth, _pictureBoxHeight);
|
||||
_airplane.ChangeIlluminatorNumb(illuminatorNumb);
|
||||
break;
|
||||
case "Продвинутый":
|
||||
_airplane = new DrawningAirplaneWithRadar(speed, weight, Color.WHITE, Color.GRAY, checkRadar.isSelected(), checkDopBak.isSelected(), _pictureBoxWidth, _pictureBoxHeight);
|
||||
_airplane.ChangeIlluminatorNumb(illuminatorNumb);
|
||||
break;
|
||||
}
|
||||
_airplane.SetPosition(_pictureBoxWidth / 2 - _airplane.GetWidth()/2, _pictureBoxHeight / 2 - _airplane.GetHeight()/2);
|
||||
canv.DrawningAirplane = _airplane;
|
||||
canv.repaint();
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
iDrawLabel.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferSupport support) {
|
||||
return support.isDataFlavorSupported(iDrawTransferable.iDrawDataFlavor);
|
||||
}
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
if (canImport(support)) {
|
||||
try {
|
||||
IDraw obj = (IDraw) support.getTransferable().getTransferData(iDrawTransferable.iDrawDataFlavor);
|
||||
if (_airplane == null)
|
||||
return false;
|
||||
_airplane.ChangeIDraw(obj);
|
||||
canv.repaint();
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
colorLabel.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 (_airplane == null)
|
||||
return false;
|
||||
_airplane.ChangeColor(color);
|
||||
canv.repaint();
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
addColorLabel.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 (_airplane == null || !(_airplane instanceof DrawningAirplaneWithRadar))
|
||||
return false;
|
||||
((DrawningAirplaneWithRadar)_airplane).ChangeAddColor(color);
|
||||
canv.repaint();
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user