From d781237090cd133ce520b03c1fa53f89fd3d74e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sat, 18 Nov 2023 22:32:49 +0400 Subject: [PATCH 1/5] done --- src/DoubleDeckerBus/ColorTransferable.java | 35 ++ .../DrawningObjects/DrawningBus.java | 21 +- .../DrawningDoubleDeckerBus.java | 4 + src/DoubleDeckerBus/FormBusCollection.java | 19 +- src/DoubleDeckerBus/FormBusConfig.java | 327 ++++++++++++++++++ src/DoubleDeckerBus/IDrawComponent.java | 37 ++ src/DoubleDeckerBus/LabelMouseAdapter.java | 12 + src/DoubleDeckerBus/LabelTransferHandler.java | 17 + src/DoubleDeckerBus/PanelMouseAdapter.java | 12 + src/DoubleDeckerBus/PanelTransferHandler.java | 16 + src/DoubleDeckerBus/iDrawTransferable.java | 36 ++ 11 files changed, 528 insertions(+), 8 deletions(-) create mode 100644 src/DoubleDeckerBus/ColorTransferable.java create mode 100644 src/DoubleDeckerBus/FormBusConfig.java create mode 100644 src/DoubleDeckerBus/IDrawComponent.java create mode 100644 src/DoubleDeckerBus/LabelMouseAdapter.java create mode 100644 src/DoubleDeckerBus/LabelTransferHandler.java create mode 100644 src/DoubleDeckerBus/PanelMouseAdapter.java create mode 100644 src/DoubleDeckerBus/PanelTransferHandler.java create mode 100644 src/DoubleDeckerBus/iDrawTransferable.java diff --git a/src/DoubleDeckerBus/ColorTransferable.java b/src/DoubleDeckerBus/ColorTransferable.java new file mode 100644 index 0000000..666f45e --- /dev/null +++ b/src/DoubleDeckerBus/ColorTransferable.java @@ -0,0 +1,35 @@ +package DoubleDeckerBus; + +import java.awt.*; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; + +public class ColorTransferable implements Transferable { + private Color color; + public 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); + } + } +} diff --git a/src/DoubleDeckerBus/DrawningObjects/DrawningBus.java b/src/DoubleDeckerBus/DrawningObjects/DrawningBus.java index be8d928..efaa3e7 100644 --- a/src/DoubleDeckerBus/DrawningObjects/DrawningBus.java +++ b/src/DoubleDeckerBus/DrawningObjects/DrawningBus.java @@ -14,8 +14,9 @@ public class DrawningBus { public int _pictureHeight; protected int _startPosX; protected int _startPosY; - protected int _busWidth = 110; - protected int _busHeight = 70; + public int _busWidth = 110; + public int _busHeight = 70; + public int _doorNumb; protected IDraw DrawningDoor; public EntityBus EntityBus() { @@ -69,6 +70,18 @@ public class DrawningBus { DrawningDoor.ChangeDoorsNumber(random.nextInt(2, 6)); } + public void ChangeIDraw(IDraw obj) { + DrawningDoor = obj; + obj.ChangeDoorsNumber(_doorNumb); + obj.ChangeX(_startPosX); + obj.ChangeY(_startPosY); + } + + public void ChangeDoorsNumb(int numb) { + _doorNumb = numb; + DrawningDoor.ChangeDoorsNumber(numb); + } + public void SetPosition(int x, int y){ if (EntityBus == null) { return; @@ -159,6 +172,10 @@ public class DrawningBus { DrawningDoor.ChangeY(_startPosY); } + public void ChangeColor(Color col){ + EntityBus.BodyColor = col; + } + public void DrawTransport(Graphics2D g2d) { if (EntityBus == null) { return; diff --git a/src/DoubleDeckerBus/DrawningObjects/DrawningDoubleDeckerBus.java b/src/DoubleDeckerBus/DrawningObjects/DrawningDoubleDeckerBus.java index da850a5..8d348ea 100644 --- a/src/DoubleDeckerBus/DrawningObjects/DrawningDoubleDeckerBus.java +++ b/src/DoubleDeckerBus/DrawningObjects/DrawningDoubleDeckerBus.java @@ -15,6 +15,10 @@ public class DrawningDoubleDeckerBus extends DrawningBus { } } + public void ChangeAddColor(Color col) { + ((EntityDoubleDeckerBus)EntityBus).AdditionalColor = col; + } + @Override public void DrawTransport(Graphics2D g2d) { diff --git a/src/DoubleDeckerBus/FormBusCollection.java b/src/DoubleDeckerBus/FormBusCollection.java index ede8d42..fa61436 100644 --- a/src/DoubleDeckerBus/FormBusCollection.java +++ b/src/DoubleDeckerBus/FormBusCollection.java @@ -124,22 +124,29 @@ public class FormBusCollection { return; } TheBusesGenericCollection _bus = _storage.Get(listBoxStorages.getSelectedValue()); - FormDoubleDeckerBus form = new FormDoubleDeckerBus(); - form.buttonSelect.addActionListener(new ActionListener() { + FormBusConfig form = new FormBusConfig(); + form.addButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (_bus.Insert(form.SelectedBus())) + if (_bus.Insert(form._bus)) { JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE); - form.SelectedBus()._pictureWidth = pictureBoxWidth; - form.SelectedBus()._pictureHeight = pictureBoxHeight; + form._bus._pictureWidth = pictureBoxWidth; + form._bus._pictureHeight = pictureBoxHeight; Draw(); } else { JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Информация", JOptionPane.INFORMATION_MESSAGE); } - form.BusFrame.dispose(); + form.frameConfig.dispose(); + Draw(); + } + }); + form.cancelButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + form.frameConfig.dispose(); Draw(); } }); diff --git a/src/DoubleDeckerBus/FormBusConfig.java b/src/DoubleDeckerBus/FormBusConfig.java new file mode 100644 index 0000000..3240c04 --- /dev/null +++ b/src/DoubleDeckerBus/FormBusConfig.java @@ -0,0 +1,327 @@ +package DoubleDeckerBus; + +import DoubleDeckerBus.DrawningObjects.*; + +import javax.swing.*; +import java.awt.*; +import java.awt.datatransfer.*; +import java.awt.event.*; +import java.io.IOException; + +public class FormBusConfig { + public JFrame frameConfig; + public JButton addButton; + public JButton cancelButton; + public DrawningBus _bus; + int _pictureBoxWidth = 218; + int _pictureBoxHeight = 190; + + public FormBusConfig(){ + frameConfig = new JFrame(); + addButton = new JButton("Добавить"); + cancelButton = new JButton("Отмена"); + addButton.setBounds(555,262,94,29); + cancelButton.setBounds(679,262,94,29); + Canvas canvas = new Canvas(); + canvas.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); + canvas.setBounds(555, 65, _pictureBoxWidth, _pictureBoxHeight); + JLabel iDrawLabel = new JLabel("Орнамент"); + JLabel colorLabel = new JLabel("Цвет"); + DrawningBus toGetSize = new DrawningBus(0,0, null, 0, 0); + IDrawComponent baseDoor = new IDrawComponent(new DrawningDoor(toGetSize._busWidth - toGetSize._busWidth / 10, + toGetSize._busHeight, + _pictureBoxWidth / 2 -toGetSize._busWidth / 2, + _pictureBoxHeight / 2 -toGetSize._busHeight / 2)); + IDrawComponent ovalDoor = new IDrawComponent(new DrawningDoorOval(toGetSize._busWidth - toGetSize._busWidth / 10, + toGetSize._busHeight, + _pictureBoxWidth / 2 -toGetSize._busWidth / 2, + _pictureBoxHeight / 2 -toGetSize._busHeight / 2)); + IDrawComponent triangleDoor = new IDrawComponent(new DrawningDoorTriangle(toGetSize._busWidth - toGetSize._busWidth / 10, + toGetSize._busHeight, + _pictureBoxWidth / 2 -toGetSize._busWidth / 2, + _pictureBoxHeight / 2 -toGetSize._busHeight / 2)); + baseDoor.setLayout(new GridLayout(1,1)); + ovalDoor.setLayout(new GridLayout(1,1)); + triangleDoor.setLayout(new GridLayout(1,1)); + iDrawLabel.setHorizontalAlignment(SwingConstants.CENTER); + iDrawLabel.setVerticalAlignment(SwingConstants.CENTER); + colorLabel.setHorizontalAlignment(SwingConstants.CENTER); + colorLabel.setVerticalAlignment(SwingConstants.CENTER); + JLabel baseLabel = new JLabel("Прямоугольные"); + JLabel ovalLabel = new JLabel("Овальные"); + JLabel triangleLabel = new JLabel("Треугольные"); + baseLabel.setHorizontalAlignment(SwingConstants.CENTER); + baseLabel.setVerticalAlignment(SwingConstants.CENTER); + ovalLabel.setHorizontalAlignment(SwingConstants.CENTER); + ovalLabel.setVerticalAlignment(SwingConstants.CENTER); + triangleLabel.setHorizontalAlignment(SwingConstants.CENTER); + triangleLabel.setVerticalAlignment(SwingConstants.CENTER); + + baseDoor.add(baseLabel); + ovalDoor.add(ovalLabel); + triangleDoor.add(triangleLabel); + baseDoor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); + ovalDoor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); + triangleDoor.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 checkSecondFloor = new JCheckBox("Наличие 2 этажа"); + JCheckBox checkLadder = new JCheckBox("Наличие лестницы"); + JCheckBox checkLineBetweenFloor = new JCheckBox("Наличие разделительной линии"); + checkSecondFloor.setBounds(6, 122, 159, 24); + checkLadder.setBounds(6, 152, 145, 24); + checkLineBetweenFloor.setBounds(6, 182, 131, 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); + baseDoor.setBounds(171,229, 120, 50); + ovalDoor.setBounds(297,229, 120, 50); + triangleDoor.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 doorNumbSpinnerModel = new SpinnerNumberModel(2, 2, 4, 1.0); + JSpinner wheelNumbSpinner = new JSpinner(doorNumbSpinnerModel); + 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(checkSecondFloor); + frameConfig.add(checkLadder); + frameConfig.add(checkLineBetweenFloor); + frameConfig.add(canvas); + frameConfig.add(addButton); + frameConfig.add(cancelButton); + frameConfig.add(wheelNumbSpinner); + frameConfig.setVisible(true); + frameConfig.add(colorPanel); + frameConfig.add(baseDoor); + frameConfig.add(ovalDoor); + frameConfig.add(triangleDoor); + colorPanel.setVisible(true); + baseDoor.setVisible(true); + ovalDoor.setVisible(true); + triangleDoor.setVisible(true); + + canvas.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 doorNumbObj = wheelNumbSpinner.getValue(); + Number doorNumb = (Number) doorNumbObj; + int doorsNumb = doorNumb.intValue(); + + String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); + switch (data) { + case "Простой": + _bus = new DrawningBus(speed, weight, Color.WHITE, _pictureBoxWidth, _pictureBoxHeight); + _bus.ChangeDoorsNumb(doorsNumb); + break; + case "Продвинутый": + _bus = new DrawningDoubleDeckerBus(speed, weight, Color.WHITE, Color.BLACK, + doorsNumb, _pictureBoxWidth, _pictureBoxHeight, + checkSecondFloor.isSelected(), checkLadder.isSelected(), checkLineBetweenFloor.isSelected()); + _bus.ChangeDoorsNumb(doorsNumb); + break; + } + _bus.SetPosition(_pictureBoxWidth / 2 -_bus._busWidth / 2, + _pictureBoxHeight / 2 -_bus._busHeight / 2); + + canvas.DrawningBus = _bus; + canvas.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 (_bus == null) + return false; + _bus.ChangeIDraw(obj); + canvas.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 (_bus == null) + return false; + _bus.ChangeColor(color); + canvas.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 (_bus == null || !(_bus instanceof DrawningDoubleDeckerBus)) + return false; + ((DrawningDoubleDeckerBus)_bus).ChangeAddColor(color); + canvas.repaint(); + return true; + } catch (UnsupportedFlavorException | IOException e) { + e.printStackTrace(); + } + } + return false; + } + } + ); + } +} \ No newline at end of file diff --git a/src/DoubleDeckerBus/IDrawComponent.java b/src/DoubleDeckerBus/IDrawComponent.java new file mode 100644 index 0000000..683072e --- /dev/null +++ b/src/DoubleDeckerBus/IDrawComponent.java @@ -0,0 +1,37 @@ +package DoubleDeckerBus; + +import DoubleDeckerBus.DrawningObjects.IDraw; + +import javax.swing.*; +import java.awt.datatransfer.Transferable; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public 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); + } + } + ); + } +} diff --git a/src/DoubleDeckerBus/LabelMouseAdapter.java b/src/DoubleDeckerBus/LabelMouseAdapter.java new file mode 100644 index 0000000..5d8c9c0 --- /dev/null +++ b/src/DoubleDeckerBus/LabelMouseAdapter.java @@ -0,0 +1,12 @@ +package DoubleDeckerBus; + +import javax.swing.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class LabelMouseAdapter extends MouseAdapter { + @Override + public void mousePressed(MouseEvent e) { + ((JLabel)e.getComponent()).getTransferHandler().exportAsDrag(((JLabel)e.getComponent()), e, TransferHandler.COPY); + } +} diff --git a/src/DoubleDeckerBus/LabelTransferHandler.java b/src/DoubleDeckerBus/LabelTransferHandler.java new file mode 100644 index 0000000..1decc9b --- /dev/null +++ b/src/DoubleDeckerBus/LabelTransferHandler.java @@ -0,0 +1,17 @@ +package DoubleDeckerBus; + +import javax.swing.*; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; + +public 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()); + } +} \ No newline at end of file diff --git a/src/DoubleDeckerBus/PanelMouseAdapter.java b/src/DoubleDeckerBus/PanelMouseAdapter.java new file mode 100644 index 0000000..858cc8e --- /dev/null +++ b/src/DoubleDeckerBus/PanelMouseAdapter.java @@ -0,0 +1,12 @@ +package DoubleDeckerBus; + +import javax.swing.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class PanelMouseAdapter extends MouseAdapter { + @Override + public void mousePressed(MouseEvent e) { + ((JPanel)e.getComponent()).getTransferHandler().exportAsDrag(((JPanel)e.getComponent()), e, TransferHandler.COPY); + } +} diff --git a/src/DoubleDeckerBus/PanelTransferHandler.java b/src/DoubleDeckerBus/PanelTransferHandler.java new file mode 100644 index 0000000..c2a103a --- /dev/null +++ b/src/DoubleDeckerBus/PanelTransferHandler.java @@ -0,0 +1,16 @@ +package DoubleDeckerBus; + +import javax.swing.*; +import java.awt.datatransfer.Transferable; + +public 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()); + } +} diff --git a/src/DoubleDeckerBus/iDrawTransferable.java b/src/DoubleDeckerBus/iDrawTransferable.java new file mode 100644 index 0000000..2208171 --- /dev/null +++ b/src/DoubleDeckerBus/iDrawTransferable.java @@ -0,0 +1,36 @@ +package DoubleDeckerBus; + +import DoubleDeckerBus.DrawningObjects.IDraw; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; + +public class iDrawTransferable implements Transferable { + private IDraw iDrawObject; + public 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); + } + } +} -- 2.25.1 From 3aa54de00ea8fa8e131bd4bf53c99f75f8c91e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sat, 18 Nov 2023 22:58:46 +0400 Subject: [PATCH 2/5] fix --- src/DoubleDeckerBus/FormBusConfig.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/DoubleDeckerBus/FormBusConfig.java b/src/DoubleDeckerBus/FormBusConfig.java index 3240c04..67383fd 100644 --- a/src/DoubleDeckerBus/FormBusConfig.java +++ b/src/DoubleDeckerBus/FormBusConfig.java @@ -25,7 +25,7 @@ public class FormBusConfig { Canvas canvas = new Canvas(); canvas.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); canvas.setBounds(555, 65, _pictureBoxWidth, _pictureBoxHeight); - JLabel iDrawLabel = new JLabel("Орнамент"); + JLabel iDrawLabel = new JLabel("Двери"); JLabel colorLabel = new JLabel("Цвет"); DrawningBus toGetSize = new DrawningBus(0,0, null, 0, 0); IDrawComponent baseDoor = new IDrawComponent(new DrawningDoor(toGetSize._busWidth - toGetSize._busWidth / 10, @@ -74,10 +74,10 @@ public class FormBusConfig { iDrawLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); JCheckBox checkSecondFloor = new JCheckBox("Наличие 2 этажа"); JCheckBox checkLadder = new JCheckBox("Наличие лестницы"); - JCheckBox checkLineBetweenFloor = new JCheckBox("Наличие разделительной линии"); + JCheckBox checkLineBetweenFloor = new JCheckBox("Наличие разделителя"); checkSecondFloor.setBounds(6, 122, 159, 24); checkLadder.setBounds(6, 152, 145, 24); - checkLineBetweenFloor.setBounds(6, 182, 131, 24); + checkLineBetweenFloor.setBounds(6, 182, 162, 24); JLabel simpleLabel = new JLabel("Простой"); JLabel advancedLabel = new JLabel("Продвинутый"); simpleLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); @@ -97,15 +97,15 @@ public class FormBusConfig { 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 doorNumbSpinnerModel = new SpinnerNumberModel(2, 2, 4, 1.0); - JSpinner wheelNumbSpinner = new JSpinner(doorNumbSpinnerModel); + SpinnerNumberModel doorNumbSpinnerModel = new SpinnerNumberModel(3, 3, 5, 1.0); + JSpinner doorNumbSpinner = new JSpinner(doorNumbSpinnerModel); 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); + doorNumbSpinner.setBounds(6, 220, 150, 27); JPanel redPanel = new JPanel(); JPanel greenPanel = new JPanel(); @@ -187,7 +187,7 @@ public class FormBusConfig { frameConfig.add(canvas); frameConfig.add(addButton); frameConfig.add(cancelButton); - frameConfig.add(wheelNumbSpinner); + frameConfig.add(doorNumbSpinner); frameConfig.setVisible(true); frameConfig.add(colorPanel); frameConfig.add(baseDoor); @@ -217,7 +217,7 @@ public class FormBusConfig { Number weightNumb = (Number) weightObj; int weight = weightNumb.intValue(); - Object doorNumbObj = wheelNumbSpinner.getValue(); + Object doorNumbObj = doorNumbSpinner.getValue(); Number doorNumb = (Number) doorNumbObj; int doorsNumb = doorNumb.intValue(); -- 2.25.1 From aa870dfeb3ca4115877d83036ccd54de49c64c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 26 Dec 2023 21:54:17 +0400 Subject: [PATCH 3/5] fix --- .../Generics/TheBusesGenericCollection.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/DoubleDeckerBus/Generics/TheBusesGenericCollection.java b/src/DoubleDeckerBus/Generics/TheBusesGenericCollection.java index 32f2b15..de2497c 100644 --- a/src/DoubleDeckerBus/Generics/TheBusesGenericCollection.java +++ b/src/DoubleDeckerBus/Generics/TheBusesGenericCollection.java @@ -66,12 +66,12 @@ public class TheBusesGenericCollection Date: Tue, 26 Dec 2023 22:22:46 +0400 Subject: [PATCH 4/5] fix --- src/DoubleDeckerBus/{ => DragDrop}/ColorTransferable.java | 2 +- src/DoubleDeckerBus/{ => DragDrop}/IDrawComponent.java | 4 ++-- src/DoubleDeckerBus/{ => DragDrop}/LabelMouseAdapter.java | 2 +- src/DoubleDeckerBus/{ => DragDrop}/LabelTransferHandler.java | 2 +- src/DoubleDeckerBus/{ => DragDrop}/PanelMouseAdapter.java | 2 +- src/DoubleDeckerBus/{ => DragDrop}/PanelTransferHandler.java | 2 +- src/DoubleDeckerBus/{ => DragDrop}/iDrawTransferable.java | 2 +- src/DoubleDeckerBus/FormBusConfig.java | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) rename src/DoubleDeckerBus/{ => DragDrop}/ColorTransferable.java (96%) rename src/DoubleDeckerBus/{ => DragDrop}/IDrawComponent.java (94%) rename src/DoubleDeckerBus/{ => DragDrop}/LabelMouseAdapter.java (90%) rename src/DoubleDeckerBus/{ => DragDrop}/LabelTransferHandler.java (92%) rename src/DoubleDeckerBus/{ => DragDrop}/PanelMouseAdapter.java (90%) rename src/DoubleDeckerBus/{ => DragDrop}/PanelTransferHandler.java (91%) rename src/DoubleDeckerBus/{ => DragDrop}/iDrawTransferable.java (96%) diff --git a/src/DoubleDeckerBus/ColorTransferable.java b/src/DoubleDeckerBus/DragDrop/ColorTransferable.java similarity index 96% rename from src/DoubleDeckerBus/ColorTransferable.java rename to src/DoubleDeckerBus/DragDrop/ColorTransferable.java index 666f45e..855d15f 100644 --- a/src/DoubleDeckerBus/ColorTransferable.java +++ b/src/DoubleDeckerBus/DragDrop/ColorTransferable.java @@ -1,4 +1,4 @@ -package DoubleDeckerBus; +package DoubleDeckerBus.DragDrop; import java.awt.*; import java.awt.datatransfer.DataFlavor; diff --git a/src/DoubleDeckerBus/IDrawComponent.java b/src/DoubleDeckerBus/DragDrop/IDrawComponent.java similarity index 94% rename from src/DoubleDeckerBus/IDrawComponent.java rename to src/DoubleDeckerBus/DragDrop/IDrawComponent.java index 683072e..dfeb338 100644 --- a/src/DoubleDeckerBus/IDrawComponent.java +++ b/src/DoubleDeckerBus/DragDrop/IDrawComponent.java @@ -1,4 +1,4 @@ -package DoubleDeckerBus; +package DoubleDeckerBus.DragDrop; import DoubleDeckerBus.DrawningObjects.IDraw; @@ -13,7 +13,7 @@ public class IDrawComponent extends JComponent { public IDrawComponent(IDraw obj){ this.obj = obj; this.addMouseListener( - new MouseAdapter(){ + new MouseAdapter(){ @Override public void mousePressed(MouseEvent e) { ((IDrawComponent)e.getComponent()).getTransferHandler().exportAsDrag(((IDrawComponent)e.getComponent()), e, TransferHandler.COPY); diff --git a/src/DoubleDeckerBus/LabelMouseAdapter.java b/src/DoubleDeckerBus/DragDrop/LabelMouseAdapter.java similarity index 90% rename from src/DoubleDeckerBus/LabelMouseAdapter.java rename to src/DoubleDeckerBus/DragDrop/LabelMouseAdapter.java index 5d8c9c0..d25cc2b 100644 --- a/src/DoubleDeckerBus/LabelMouseAdapter.java +++ b/src/DoubleDeckerBus/DragDrop/LabelMouseAdapter.java @@ -1,4 +1,4 @@ -package DoubleDeckerBus; +package DoubleDeckerBus.DragDrop; import javax.swing.*; import java.awt.event.MouseAdapter; diff --git a/src/DoubleDeckerBus/LabelTransferHandler.java b/src/DoubleDeckerBus/DragDrop/LabelTransferHandler.java similarity index 92% rename from src/DoubleDeckerBus/LabelTransferHandler.java rename to src/DoubleDeckerBus/DragDrop/LabelTransferHandler.java index 1decc9b..05bcd72 100644 --- a/src/DoubleDeckerBus/LabelTransferHandler.java +++ b/src/DoubleDeckerBus/DragDrop/LabelTransferHandler.java @@ -1,4 +1,4 @@ -package DoubleDeckerBus; +package DoubleDeckerBus.DragDrop; import javax.swing.*; import java.awt.datatransfer.StringSelection; diff --git a/src/DoubleDeckerBus/PanelMouseAdapter.java b/src/DoubleDeckerBus/DragDrop/PanelMouseAdapter.java similarity index 90% rename from src/DoubleDeckerBus/PanelMouseAdapter.java rename to src/DoubleDeckerBus/DragDrop/PanelMouseAdapter.java index 858cc8e..bd27560 100644 --- a/src/DoubleDeckerBus/PanelMouseAdapter.java +++ b/src/DoubleDeckerBus/DragDrop/PanelMouseAdapter.java @@ -1,4 +1,4 @@ -package DoubleDeckerBus; +package DoubleDeckerBus.DragDrop; import javax.swing.*; import java.awt.event.MouseAdapter; diff --git a/src/DoubleDeckerBus/PanelTransferHandler.java b/src/DoubleDeckerBus/DragDrop/PanelTransferHandler.java similarity index 91% rename from src/DoubleDeckerBus/PanelTransferHandler.java rename to src/DoubleDeckerBus/DragDrop/PanelTransferHandler.java index c2a103a..7d2b5ff 100644 --- a/src/DoubleDeckerBus/PanelTransferHandler.java +++ b/src/DoubleDeckerBus/DragDrop/PanelTransferHandler.java @@ -1,4 +1,4 @@ -package DoubleDeckerBus; +package DoubleDeckerBus.DragDrop; import javax.swing.*; import java.awt.datatransfer.Transferable; diff --git a/src/DoubleDeckerBus/iDrawTransferable.java b/src/DoubleDeckerBus/DragDrop/iDrawTransferable.java similarity index 96% rename from src/DoubleDeckerBus/iDrawTransferable.java rename to src/DoubleDeckerBus/DragDrop/iDrawTransferable.java index 2208171..ea3c475 100644 --- a/src/DoubleDeckerBus/iDrawTransferable.java +++ b/src/DoubleDeckerBus/DragDrop/iDrawTransferable.java @@ -1,4 +1,4 @@ -package DoubleDeckerBus; +package DoubleDeckerBus.DragDrop; import DoubleDeckerBus.DrawningObjects.IDraw; diff --git a/src/DoubleDeckerBus/FormBusConfig.java b/src/DoubleDeckerBus/FormBusConfig.java index 67383fd..4932c27 100644 --- a/src/DoubleDeckerBus/FormBusConfig.java +++ b/src/DoubleDeckerBus/FormBusConfig.java @@ -1,11 +1,11 @@ package DoubleDeckerBus; +import DoubleDeckerBus.DragDrop.*; import DoubleDeckerBus.DrawningObjects.*; import javax.swing.*; import java.awt.*; import java.awt.datatransfer.*; -import java.awt.event.*; import java.io.IOException; public class FormBusConfig { -- 2.25.1 From e078c849ab9544e0d487644f1c62551705916fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 27 Dec 2023 22:23:04 +0400 Subject: [PATCH 5/5] fix --- src/DoubleDeckerBus/DragDrop/IDrawComponent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DoubleDeckerBus/DragDrop/IDrawComponent.java b/src/DoubleDeckerBus/DragDrop/IDrawComponent.java index dfeb338..15360e9 100644 --- a/src/DoubleDeckerBus/DragDrop/IDrawComponent.java +++ b/src/DoubleDeckerBus/DragDrop/IDrawComponent.java @@ -34,4 +34,4 @@ public class IDrawComponent extends JComponent { } ); } -} +} \ No newline at end of file -- 2.25.1