ПИбд-23 Салин Олег Алексеевич Лабораторная работа №5 (усложненная) #6
11
.idea/PIbd-23-Salin-O.A.-Monorail-Hard.iml
generated
Normal file
11
.idea/PIbd-23-Salin-O.A.-Monorail-Hard.iml
generated
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -1,5 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" default="true">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/PIbd-23-Salin-O.A.-Monorail-Hard.iml" filepath="$PROJECT_DIR$/.idea/PIbd-23-Salin-O.A.-Monorail-Hard.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -6,6 +6,7 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawningLocomotive extends DrawningMonorail{
|
public class DrawningLocomotive extends DrawningMonorail{
|
||||||
|
|
||||||
public DrawningLocomotive(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int wheelNumb,
|
public DrawningLocomotive(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int wheelNumb,
|
||||||
int width, int height, boolean secondCabine, boolean magniteRail, Color additionalColor){
|
int width, int height, boolean secondCabine, boolean magniteRail, Color additionalColor){
|
||||||
super(speed, weight, bodyColor, wheelColor, tireColor, width, height);
|
super(speed, weight, bodyColor, wheelColor, tireColor, width, height);
|
||||||
@ -15,6 +16,10 @@ public class DrawningLocomotive extends DrawningMonorail{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeAddColor(Color col){
|
||||||
|
((EntityLocomotive)EntityMonorail).AdditionalColor = col;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void DrawMonorail(Graphics2D g2d){
|
public void DrawMonorail(Graphics2D g2d){
|
||||||
if (!(EntityMonorail instanceof EntityLocomotive))
|
if (!(EntityMonorail instanceof EntityLocomotive))
|
||||||
|
@ -17,8 +17,9 @@ public class DrawningMonorail {
|
|||||||
public int _pictureHeight;
|
public int _pictureHeight;
|
||||||
protected int _startPosX;
|
protected int _startPosX;
|
||||||
protected int _startPosY;
|
protected int _startPosY;
|
||||||
protected int _monorailWidth = 133;
|
public int _monorailWidth = 133;
|
||||||
protected int _monorailHeight = 50;
|
public int _wheelNumb;
|
||||||
|
public int _monorailHeight = 50;
|
||||||
protected IDraw DrawningWheels;
|
protected IDraw DrawningWheels;
|
||||||
|
|
||||||
protected int wheelSz;
|
protected int wheelSz;
|
||||||
@ -48,6 +49,17 @@ public class DrawningMonorail {
|
|||||||
DrawningWheels.ChangeWheelsNumb(rand.nextInt(1, 6));
|
DrawningWheels.ChangeWheelsNumb(rand.nextInt(1, 6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeIDraw(IDraw obj){
|
||||||
|
DrawningWheels = obj;
|
||||||
|
obj.ChangeWheelsNumb(_wheelNumb);
|
||||||
|
obj.ChangeWheelsNumb(_wheelNumb);
|
||||||
|
obj.ChangeX(_startPosX);
|
||||||
|
obj.ChangeY(_startPosY);
|
||||||
|
}
|
||||||
|
public void ChangeWheelsNumb(int numb){
|
||||||
|
_wheelNumb = numb;
|
||||||
|
DrawningWheels.ChangeWheelsNumb(numb);
|
||||||
|
}
|
||||||
protected DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor,
|
protected DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor,
|
||||||
int width, int height, int monorailWidth, int monorailHeight){
|
int width, int height, int monorailWidth, int monorailHeight){
|
||||||
if(width <= _monorailWidth || height <= _monorailHeight)
|
if(width <= _monorailWidth || height <= _monorailHeight)
|
||||||
@ -144,6 +156,10 @@ public class DrawningMonorail {
|
|||||||
DrawningWheels.ChangeY(_startPosY);
|
DrawningWheels.ChangeY(_startPosY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeColor(Color col){
|
||||||
|
EntityMonorail.BodyColor = col;
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawMonorail(Graphics2D g2d){
|
public void DrawMonorail(Graphics2D g2d){
|
||||||
if (EntityMonorail == null)
|
if (EntityMonorail == null)
|
||||||
return;
|
return;
|
||||||
|
@ -61,7 +61,7 @@ public class DrawningWheelsCart implements IDraw{
|
|||||||
CurY + Height / 10 * 7};
|
CurY + Height / 10 * 7};
|
||||||
g2d.setColor(Color.BLACK);
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.fillPolygon(xPointsArrFrontCart, yPointsArrFrontCart, xPointsArrFrontCart.length);
|
g2d.fillPolygon(xPointsArrFrontCart, yPointsArrFrontCart, xPointsArrFrontCart.length);
|
||||||
g2d.setColor(TireColor);
|
g2d.setColor(Color.WHITE);
|
||||||
g2d.drawLine(CurX + Width / 10 * 2, CurY + Height / 10 * 7,CurX + Width / 10 * 4, CurY + Height / 10 * 9);
|
g2d.drawLine(CurX + Width / 10 * 2, CurY + Height / 10 * 7,CurX + Width / 10 * 4, CurY + Height / 10 * 9);
|
||||||
g2d.drawLine(CurX + Width / 10 * 4, CurY + Height / 10 * 7,CurX + Width / 10 * 2, CurY + Height / 10 * 9);
|
g2d.drawLine(CurX + Width / 10 * 4, CurY + Height / 10 * 7,CurX + Width / 10 * 2, CurY + Height / 10 * 9);
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ public class DrawningWheelsCart implements IDraw{
|
|||||||
CurY + Height / 10 * 9, CurY + Height / 10 * 9};
|
CurY + Height / 10 * 9, CurY + Height / 10 * 9};
|
||||||
g2d.setColor(Color.BLACK);
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.fillPolygon(xPointsArrBackCart, yPointsArrBackCart, xPointsArrBackCart.length);
|
g2d.fillPolygon(xPointsArrBackCart, yPointsArrBackCart, xPointsArrBackCart.length);
|
||||||
g2d.setColor(TireColor);
|
g2d.setColor(Color.WHITE);
|
||||||
g2d.drawLine(CurX + Width / 10 * 6, CurY + Height / 10 * 7,CurX + Width / 10 * 9, CurY + Height / 10 * 9);
|
g2d.drawLine(CurX + Width / 10 * 6, CurY + Height / 10 * 7,CurX + Width / 10 * 9, CurY + Height / 10 * 9);
|
||||||
g2d.drawLine(CurX + Width / 10 * 9, CurY + Height / 10 * 7,CurX + Width / 10 * 6, CurY + Height / 10 * 9);
|
g2d.drawLine(CurX + Width / 10 * 9, CurY + Height / 10 * 7,CurX + Width / 10 * 6, CurY + Height / 10 * 9);
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package MonorailHard.Entities;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class EntityLocomotive extends EntityMonorail{
|
public class EntityLocomotive extends EntityMonorail{
|
||||||
private Color AdditionalColor;
|
public Color AdditionalColor;
|
||||||
private boolean SecondCabine;
|
private boolean SecondCabine;
|
||||||
private boolean MagniteRail;
|
private boolean MagniteRail;
|
||||||
public Color AdditionalColor(){return AdditionalColor;};
|
public Color AdditionalColor(){return AdditionalColor;};
|
||||||
|
@ -4,7 +4,7 @@ import java.awt.*;
|
|||||||
public class EntityMonorail {
|
public class EntityMonorail {
|
||||||
private int Speed;
|
private int Speed;
|
||||||
private double Weight, Step;
|
private double Weight, Step;
|
||||||
private Color BodyColor, WheelColor, TireColor;
|
public Color BodyColor, WheelColor, TireColor;
|
||||||
|
|
||||||
public int Speed(){
|
public int Speed(){
|
||||||
return Speed;
|
return Speed;
|
||||||
|
@ -122,22 +122,29 @@ public class FormMonorailCollection {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> _monorails = _storage.Get(listBoxStorages.getSelectedValue());
|
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> _monorails = _storage.Get(listBoxStorages.getSelectedValue());
|
||||||
FormMonorail form = new FormMonorail();
|
FormMonorailConfig form = new FormMonorailConfig();
|
||||||
form.buttonSelect.addActionListener(new ActionListener() {
|
form.addButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (_monorails.Insert(form.SelectedMonorail()))
|
if (_monorails.Insert(form._monorail))
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||||
form.SelectedMonorail()._pictureWidth = pictureBoxWidth;
|
form._monorail._pictureWidth = pictureBoxWidth;
|
||||||
form.SelectedMonorail()._pictureHeight = pictureBoxHeight;
|
form._monorail._pictureHeight = pictureBoxHeight;
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||||
}
|
}
|
||||||
form.MonorailFrame.dispose();
|
form.frameConfig.dispose();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
form.cancelButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
form.frameConfig.dispose();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
472
src/MonorailHard/FormMonorailConfig.java
Normal file
472
src/MonorailHard/FormMonorailConfig.java
Normal file
@ -0,0 +1,472 @@
|
|||||||
|
package MonorailHard;
|
||||||
|
|
||||||
|
import MonorailHard.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 java.util.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.Border;
|
||||||
|
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static java.lang.Integer.parseInt;
|
||||||
|
|
||||||
|
|
||||||
|
public class FormMonorailConfig {
|
||||||
|
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 DrawningMonorail _monorail;
|
||||||
|
int _pictureBoxWidth = 218;
|
||||||
|
int _pictureBoxHeight = 190;
|
||||||
|
|
||||||
|
public FormMonorailConfig(){
|
||||||
|
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("Цвет");
|
||||||
|
DrawningMonorail toGetSize = new DrawningMonorail(0,0, null, null, null, 0, 0);
|
||||||
|
IDrawComponent cartComp = new IDrawComponent(new DrawningWheelsCart(toGetSize._monorailWidth - toGetSize._monorailWidth / 10,
|
||||||
|
toGetSize._monorailHeight,
|
||||||
|
_pictureBoxWidth / 2 -toGetSize._monorailWidth / 2,
|
||||||
|
_pictureBoxHeight / 2 -toGetSize._monorailHeight / 2, Color.GRAY, Color.BLACK));
|
||||||
|
IDrawComponent ornComp = new IDrawComponent(new DrawningWheelsOrn(toGetSize._monorailWidth - toGetSize._monorailWidth / 10,
|
||||||
|
toGetSize._monorailHeight,
|
||||||
|
_pictureBoxWidth / 2 -toGetSize._monorailWidth / 2,
|
||||||
|
_pictureBoxHeight / 2 -toGetSize._monorailHeight / 2, Color.GRAY, Color.BLACK));
|
||||||
|
IDrawComponent baseComp = new IDrawComponent(new DrawningWheels(toGetSize._monorailWidth - toGetSize._monorailWidth / 10,
|
||||||
|
toGetSize._monorailHeight,
|
||||||
|
_pictureBoxWidth / 2 -toGetSize._monorailWidth / 2,
|
||||||
|
_pictureBoxHeight / 2 -toGetSize._monorailHeight / 2, Color.GRAY, Color.BLACK));
|
||||||
|
cartComp.setLayout(new GridLayout(1,1));
|
||||||
|
ornComp.setLayout(new GridLayout(1,1));
|
||||||
|
baseComp.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);
|
||||||
|
|
||||||
|
cartComp.add(cartLabel);
|
||||||
|
ornComp.add(ornLabel);
|
||||||
|
baseComp.add(baseLabel);
|
||||||
|
cartComp.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
ornComp.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
baseComp.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 checkSecondCabine = new JCheckBox("Наличие 2 кабины");
|
||||||
|
JCheckBox checkMagniteRail = new JCheckBox("Наличие магнитной рельсы");
|
||||||
|
checkSecondCabine.setBounds(6, 132, 159, 24);
|
||||||
|
checkMagniteRail.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);
|
||||||
|
cartComp.setBounds(171,229, 120, 50);
|
||||||
|
ornComp.setBounds(297,229, 120, 50);
|
||||||
|
baseComp.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 wheelNumbSpinnerModel = new SpinnerNumberModel(2, 2, 4, 1.0);
|
||||||
|
JSpinner wheelNumbSpinner = new JSpinner(wheelNumbSpinnerModel);
|
||||||
|
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);
|
||||||
|
wheelNumbSpinner.setBounds(6, 200, 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(weightSpinner);
|
||||||
|
frameConfig.add(simpleLabel);
|
||||||
|
frameConfig.add(advancedLabel);
|
||||||
|
frameConfig.add(checkSecondCabine);
|
||||||
|
frameConfig.add(checkMagniteRail);
|
||||||
|
frameConfig.add(canv);
|
||||||
|
frameConfig.add(addButton);
|
||||||
|
frameConfig.add(cancelButton);
|
||||||
|
frameConfig.add(wheelNumbSpinner);
|
||||||
|
|
||||||
|
frameConfig.setVisible(true);
|
||||||
|
frameConfig.add(colorPanel);
|
||||||
|
frameConfig.add(cartComp);
|
||||||
|
frameConfig.add(ornComp);
|
||||||
|
frameConfig.add(baseComp);
|
||||||
|
colorPanel.setVisible(true);
|
||||||
|
cartComp.setVisible(true);
|
||||||
|
ornComp.setVisible(true);
|
||||||
|
baseComp.setVisible(true);
|
||||||
|
|
||||||
|
canv.setTransferHandler(
|
||||||
|
new TransferHandler(){
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||||
|
return support.isDataFlavorSupported(DataFlavor.stringFlavor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferHandler.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 wheelNumbObj = wheelNumbSpinner.getValue();
|
||||||
|
Number wheelNumbNumb = (Number) wheelNumbObj;
|
||||||
|
int wheelNumb = wheelNumbNumb.intValue();
|
||||||
|
|
||||||
|
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||||
|
switch (data) {
|
||||||
|
case "Простой":
|
||||||
|
|
||||||
|
_monorail = new DrawningMonorail(speed, weight, Color.WHITE,
|
||||||
|
Color.GRAY, Color.BLACK, _pictureBoxWidth, _pictureBoxHeight);
|
||||||
|
_monorail.ChangeWheelsNumb(wheelNumb);
|
||||||
|
break;
|
||||||
|
case "Продвинутый":
|
||||||
|
_monorail = new DrawningLocomotive(speed, weight, Color.WHITE, Color.GRAY, Color.BLACK,
|
||||||
|
wheelNumb, _pictureBoxWidth, _pictureBoxHeight,
|
||||||
|
checkSecondCabine.isSelected(), checkMagniteRail.isSelected(), Color.GRAY);
|
||||||
|
_monorail.ChangeWheelsNumb(wheelNumb);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_monorail.SetPosition(_pictureBoxWidth / 2 -_monorail._monorailWidth / 2,
|
||||||
|
_pictureBoxHeight / 2 -_monorail._monorailHeight / 2);
|
||||||
|
|
||||||
|
canv.DrawningMonorail = _monorail;
|
||||||
|
canv.repaint();
|
||||||
|
return true;
|
||||||
|
} catch (UnsupportedFlavorException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
iDrawLabel.setTransferHandler(
|
||||||
|
new TransferHandler(){
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||||
|
return support.isDataFlavorSupported(iDrawTransferable.iDrawDataFlavor);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferHandler.TransferSupport support) {
|
||||||
|
if (canImport(support)) {
|
||||||
|
try {
|
||||||
|
IDraw obj = (IDraw) support.getTransferable().getTransferData(iDrawTransferable.iDrawDataFlavor);
|
||||||
|
if (_monorail == null)
|
||||||
|
return false;
|
||||||
|
_monorail.ChangeIDraw(obj);
|
||||||
|
canv.repaint();
|
||||||
|
return true;
|
||||||
|
} catch (UnsupportedFlavorException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
colorLabel.setTransferHandler(
|
||||||
|
new TransferHandler(){
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||||
|
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferHandler.TransferSupport support) {
|
||||||
|
if (canImport(support)) {
|
||||||
|
try {
|
||||||
|
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||||
|
if (_monorail == null)
|
||||||
|
return false;
|
||||||
|
_monorail.ChangeColor(color);
|
||||||
|
canv.repaint();
|
||||||
|
return true;
|
||||||
|
} catch (UnsupportedFlavorException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
addColorLabel.setTransferHandler(
|
||||||
|
new TransferHandler(){
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||||
|
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferHandler.TransferSupport support) {
|
||||||
|
if (canImport(support)) {
|
||||||
|
try {
|
||||||
|
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||||
|
if (_monorail == null || !(_monorail instanceof DrawningLocomotive))
|
||||||
|
return false;
|
||||||
|
((DrawningLocomotive)_monorail).ChangeAddColor(color);
|
||||||
|
canv.repaint();
|
||||||
|
return true;
|
||||||
|
} catch (UnsupportedFlavorException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user