PIbd-21_MasenkinMS_LabWork05 #5

Closed
Factorino73 wants to merge 1 commits from LabWork05 into LabWork04
15 changed files with 771 additions and 7 deletions

View File

@ -85,12 +85,12 @@ public class BusCollectionForm extends JFrame {
return;
}
FrameAccordionBus frameAccordionBus = new FrameAccordionBus();
frameAccordionBus.setVisible(true);
FrameBusConfig frameBusConfig = new FrameBusConfig();
frameBusConfig.setVisible(true);
frameAccordionBus.accordionBusForm.buttonSelectBus.addActionListener(ev -> {
SelectedBus = frameAccordionBus.accordionBusForm.drawingBus;
frameAccordionBus.dispose();
frameBusConfig.busConfigForm.addButton.addActionListener(ev -> {
SelectedBus = frameBusConfig.busConfigForm._bus;
frameBusConfig.dispose();
if (SelectedBus != null) {
if (obj.plus(SelectedBus) > -2) {
Refresh();
@ -101,6 +101,8 @@ public class BusCollectionForm extends JFrame {
}
}
});
frameBusConfig.busConfigForm.cancelButton.addActionListener(ee -> frameBusConfig.dispose());
});
// Удаление объекта из набора

View File

@ -0,0 +1,300 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="AccordionBus.BusConfigForm">
<grid id="27dc6" binding="configPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="883" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="2f0df" binding="objectPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="etched"/>
<children>
<component id="20f52" class="javax.swing.JLabel" binding="bodyColorLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Осн. цвет"/>
</properties>
</component>
<component id="da4f5" class="javax.swing.JLabel" binding="additionalColorLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Доп. цвет"/>
</properties>
</component>
<component id="c025e" class="javax.swing.JLabel" binding="doorsTypeLabel">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Тип дверей"/>
</properties>
</component>
<grid id="31030" binding="pictureBoxPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="line"/>
<children/>
</grid>
</children>
</grid>
<component id="e7176" class="javax.swing.JButton" binding="addButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить"/>
</properties>
</component>
<component id="44b67" class="javax.swing.JButton" binding="cancelButton">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Отмена"/>
</properties>
</component>
<grid id="77ec7" binding="parametersPanel" layout-manager="GridLayoutManager" row-count="5" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="etched" title="Параметры"/>
<children>
<component id="ac4f6" class="javax.swing.JLabel" binding="speedSpinnerLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="a8b1d"/>
<text value="Скорость:"/>
</properties>
</component>
<component id="97f64" class="javax.swing.JLabel" binding="weightSpinnerLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="ba8dc"/>
<text value="Вес:"/>
</properties>
</component>
<component id="8413" class="javax.swing.JLabel" binding="doorsSpinnerLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="a9cd0"/>
<text value="Количество&#10; дверей:"/>
</properties>
</component>
<component id="a8b1d" class="javax.swing.JSpinner" binding="speedSpinner">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="ba8dc" class="javax.swing.JSpinner" binding="weightSpinner">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="a9cd0" class="javax.swing.JSpinner" binding="doorsSpinner">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="69782" class="javax.swing.JCheckBox" binding="additionalBodyCheckBox">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Дополнительный отсек"/>
</properties>
</component>
<component id="3f80a" class="javax.swing.JCheckBox" binding="additionalDoorCheckBox">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Дополнительная дверь"/>
</properties>
</component>
<grid id="39012" binding="colorPanel" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="2" row-span="3" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="etched" title="Цвета"/>
<children>
<grid id="38233" binding="redPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="50"/>
<preferred-size width="50" height="50"/>
<maximum-size width="50" height="50"/>
</grid>
</constraints>
<properties>
<background color="-65536"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="f7c8a" binding="greenPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="50"/>
<preferred-size width="50" height="50"/>
<maximum-size width="50" height="50"/>
</grid>
</constraints>
<properties>
<background color="-16711936"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="31ef7" binding="bluePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="50"/>
<preferred-size width="50" height="50"/>
<maximum-size width="50" height="50"/>
</grid>
</constraints>
<properties>
<background color="-16776961"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="1cd3a" binding="yellowPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="50"/>
<preferred-size width="50" height="50"/>
<maximum-size width="50" height="50"/>
</grid>
</constraints>
<properties>
<background color="-256"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="68a86" binding="whitePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="50"/>
<preferred-size width="50" height="50"/>
<maximum-size width="50" height="50"/>
</grid>
</constraints>
<properties>
<background color="-1"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="f31b6" binding="grayPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="50"/>
<preferred-size width="50" height="50"/>
<maximum-size width="50" height="50"/>
</grid>
</constraints>
<properties>
<background color="-8355712"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="95b8b" binding="blackPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="50"/>
<preferred-size width="50" height="50"/>
<maximum-size width="50" height="50"/>
</grid>
</constraints>
<properties>
<background color="-16777216"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="d2e96" binding="magentaPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="50"/>
<preferred-size width="50" height="50"/>
<maximum-size width="50" height="50"/>
</grid>
</constraints>
<properties>
<background color="-65281"/>
</properties>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<component id="dc93a" class="javax.swing.JLabel" binding="simpleObjectLabel">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<name value="simpleObjectLabel"/>
<text value="Простой"/>
</properties>
</component>
<component id="a3a8e" class="javax.swing.JLabel" binding="modifiedObjectLabel">
<constraints>
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<name value="modifiedObjectLabel"/>
<text value="Продвинутый"/>
</properties>
</component>
<grid id="1f954" binding="componentPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="2" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -0,0 +1,257 @@
package AccordionBus;
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.Console;
import java.io.IOException;
public class BusConfigForm {
// Переменная выбранный автобус
DrawingBus _bus = null;
// Переменная выбранный тип дверей
IDrawingDoors _doors = null;
// Компоненты DoorComponent
DoorComponent doorComponentTypeOne = new DoorComponent(new DrawingDoorsTypeOne());
DoorComponent doorComponentTypeTwo = new DoorComponent(new DrawingDoorsTypeTwo());
DoorComponent doorComponentTypeThree = new DoorComponent(new DrawingDoorsTypeThree());
private JPanel configPanel;
public JPanel getConfigPanel() {
return configPanel;
}
private JPanel objectPanel;
public JButton addButton;
public JButton cancelButton;
private JLabel bodyColorLabel;
private JLabel additionalColorLabel;
private JLabel doorsTypeLabel;
private JPanel pictureBoxPanel;
private JPanel parametersPanel;
private JLabel speedSpinnerLabel;
private JLabel weightSpinnerLabel;
private JLabel doorsSpinnerLabel;
private JSpinner speedSpinner;
private JSpinner weightSpinner;
private JSpinner doorsSpinner;
private JCheckBox additionalBodyCheckBox;
private JCheckBox additionalDoorCheckBox;
private JPanel colorPanel;
private JPanel redPanel;
private JPanel greenPanel;
private JPanel bluePanel;
private JPanel yellowPanel;
private JPanel whitePanel;
private JPanel grayPanel;
private JPanel blackPanel;
private JPanel magentaPanel;
private JLabel doorsTypeOneLabel = new JLabel("Дверь 1 типа");
private JLabel doorsTypeTwoLabel = new JLabel("Дверь 2 типа");
private JLabel doorsTypeThreeLabel = new JLabel("Дверь 3 типа");
private JLabel simpleObjectLabel;
private JLabel modifiedObjectLabel;
private JPanel componentPanel;
// Конструктор
public BusConfigForm() {
// Устанавливаем границы Label
simpleObjectLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
modifiedObjectLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
doorsTypeOneLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
doorsTypeTwoLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
doorsTypeThreeLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
bodyColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
additionalColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
doorsTypeLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
// Добавляем компоненты DoorComponent на форму
componentPanel.setLayout(new GridLayout());
componentPanel.add(doorComponentTypeOne);
componentPanel.add(doorComponentTypeTwo);
componentPanel.add(doorComponentTypeThree);
doorComponentTypeOne.setLayout(new GridLayout(1, 1));
doorComponentTypeTwo.setLayout(new GridLayout(1, 1));
doorComponentTypeThree.setLayout(new GridLayout(1, 1));
doorComponentTypeOne.add(doorsTypeOneLabel);
doorComponentTypeTwo.add(doorsTypeTwoLabel);
doorComponentTypeThree.add(doorsTypeThreeLabel);
// Устанавливаем допустимые значения Spinner
speedSpinner.setModel(new SpinnerNumberModel(100, 100, 1000, 1));
weightSpinner.setModel(new SpinnerNumberModel(100, 100, 1000, 1));
doorsSpinner.setModel(new SpinnerNumberModel(3, 3, 5, 1));
// Устанавливаем возможность перетаскивания Panel (цвета объекта)
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());
magentaPanel.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());
magentaPanel.addMouseListener(new PanelMouseAdapter());
// Устанавливаем возможность перетаскивания Label (типа объекта)
simpleObjectLabel.setTransferHandler(new LabelTransferHandler());
modifiedObjectLabel.setTransferHandler(new LabelTransferHandler());
simpleObjectLabel.addMouseListener(new LabelMouseAdapter());
modifiedObjectLabel.addMouseListener(new LabelMouseAdapter());
// Действия при приеме получаемой информации (получение типа объекта)
pictureBoxPanel.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)) {
return false;
}
try {
String data = (String)support.getTransferable().getTransferData(DataFlavor.stringFlavor);
switch (data) {
case "Простой":
_bus = new DrawingBus((int)speedSpinner.getValue(),
(int) weightSpinner.getValue(),
Color.WHITE,
900,
500);
_bus.drawingDoors.setNumDoors((int)doorsSpinner.getValue());
break;
case "Продвинутый":
_bus = new DrawingAccordionBus((int)speedSpinner.getValue(),
(int) weightSpinner.getValue(),
Color.WHITE,
Color.BLACK,
additionalBodyCheckBox.isSelected(),
additionalDoorCheckBox.isSelected(),
900,
500);
_bus.drawingDoors.setNumDoors((int)doorsSpinner.getValue());
break;
}
} catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
DrawBus();
return true;
}
});
// Действия при приеме получаемой информации (получение основного цвета объекта)
bodyColorLabel.setTransferHandler(new LabelTransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
if (_bus instanceof DrawingBus) {
try {
Color color = (Color)support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
bodyColorLabel.setBackground(color);
_bus.SetBodyColor(color);
}
catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
}
DrawBus();
return true;
}
});
// Действия при приеме получаемой информации (получение дополнительного цвета объекта)
additionalColorLabel.setTransferHandler(new LabelTransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
if (_bus instanceof DrawingAccordionBus) {
try {
Color color = (Color)support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
additionalColorLabel.setBackground(color);
((DrawingAccordionBus)_bus).SetAdditionalColor(color);
}
catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
}
DrawBus();
return true;
}
});
// Действия при приеме получаемой информации (получение типа дверей)
doorsTypeLabel.setTransferHandler(new TransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
return support.isDataFlavorSupported(IDrawingDoorsTransferable.IDrawingDoorsDataFlavor);
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
try {
IDrawingDoors drawingDoors = (IDrawingDoors)support.getTransferable().getTransferData(IDrawingDoorsTransferable.IDrawingDoorsDataFlavor);
drawingDoors.setNumDoors((int)doorsSpinner.getValue());
_bus.drawingDoors = drawingDoors;
}
catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
DrawBus();
return true;
}
});
}
// Отрисовать автобус
private void DrawBus () {
if (_bus == null) {
return;
}
Graphics g = pictureBoxPanel.getGraphics();
_bus.SetPosition((pictureBoxPanel.getWidth() - _bus.GetWidth()) / 2, (pictureBoxPanel.getHeight() - _bus.GetHeigth()) / 2);
pictureBoxPanel.paint(g);
_bus.DrawTransport(g);
}
}

View File

@ -0,0 +1,37 @@
package AccordionBus;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
// Класс для реализации поддержки передачи данных типа Color
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);
}
}
}

View File

@ -0,0 +1,34 @@
package AccordionBus;
import javax.swing.*;
import java.awt.datatransfer.Transferable;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
// Класс для создания компонента DrawingDoors для формы
public class DoorComponent extends JComponent {
public IDrawingDoors DrawingDoors;
public DoorComponent(IDrawingDoors drawingDoors) {
DrawingDoors = drawingDoors;
this.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
((DoorComponent)e.getComponent()).getTransferHandler().exportAsDrag(((DoorComponent)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 IDrawingDoorsTransferable(((DoorComponent)c).DrawingDoors);
}
});
}
}

View File

@ -18,6 +18,13 @@ public class DrawingAccordionBus extends DrawingBus {
drawingDoors = door;
}
// Смена дополнительного цвета
public void SetAdditionalColor(Color additionalColor) {
if (EntityBus instanceof EntityAccordionBus) {
((EntityAccordionBus)EntityBus).SetAdditionalColor(additionalColor);
}
}
// Прорисовка объекта
public void DrawTransport(Graphics g) {
if (EntityBus == null) {

View File

@ -70,6 +70,11 @@ public class DrawingBus {
}
}
// Смена основного цвета
public void SetBodyColor(Color bodyColor) {
EntityBus.SetBodyColor(bodyColor);
}
// Конструктор
public DrawingBus(int speed, int weight, Color bodyColor, int width, int height) {
// Проверка на вместимость объекта в размеры картинки
@ -96,7 +101,6 @@ public class DrawingBus {
drawingDoors = new DrawingDoorsTypeOne();
break;
}
drawingDoors.setNumDoors(random.nextInt(3, 6));
}
// Конструктор
@ -127,7 +131,6 @@ public class DrawingBus {
drawingDoors = new DrawingDoorsTypeOne();
break;
}
drawingDoors.setNumDoors(random.nextInt(3, 6));
}
// Конструктор

View File

@ -11,6 +11,9 @@ public class EntityAccordionBus extends EntityBus {
public Color getAdditionalColor() {
return AdditionalColor;
}
public void SetAdditionalColor(Color additionalColor) {
AdditionalColor = additionalColor;
}
// Дополнительный отсек
private boolean AdditionalBody;

View File

@ -21,6 +21,9 @@ public class EntityBus {
public Color getBodyColor() {
return BodyColor;
}
public void SetBodyColor(Color bodyColor) {
BodyColor = bodyColor;
}
// Шаг перемещения автобуса
public double Step() { return (double)Speed * 100 / Weight; }

View File

@ -0,0 +1,21 @@
package AccordionBus;
import javax.swing.*;
import java.awt.*;
public class FrameBusConfig extends JFrame {
public BusConfigForm busConfigForm;
public FrameBusConfig() {
super();
setTitle("BusConfig");
setDefaultCloseOperation(EXIT_ON_CLOSE);
busConfigForm = new BusConfigForm();
setContentPane(busConfigForm.getConfigPanel());
setDefaultLookAndFeelDecorated(false);
setPreferredSize(new Dimension(900, 300));
setLocation(500, 500);
pack();
setVisible(true);
}
}

View File

@ -0,0 +1,36 @@
package AccordionBus;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
// Класс для реализации поддержки передачи данных типа IDrawingDoors
public class IDrawingDoorsTransferable implements Transferable {
private IDrawingDoors IDrawingDoorsObject;
public static final DataFlavor IDrawingDoorsDataFlavor = new DataFlavor(IDrawingDoors.class, "IDrawingDoors");
public IDrawingDoorsTransferable(IDrawingDoors IDrawingDoorsObject) {
this.IDrawingDoorsObject = IDrawingDoorsObject;
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] {IDrawingDoorsDataFlavor};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return IDrawingDoorsDataFlavor.equals(flavor);
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (isDataFlavorSupported(flavor)) {
return IDrawingDoorsObject;
}
else {
throw new UnsupportedFlavorException(flavor);
}
}
}

View File

@ -0,0 +1,13 @@
package AccordionBus;
import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
// Передаем информацию при нажатии на Label
public class LabelMouseAdapter extends MouseAdapter {
@Override
public void mousePressed(MouseEvent e) {
((JLabel)e.getComponent()).getTransferHandler().exportAsDrag(((JLabel)e.getComponent()), e, TransferHandler.COPY);
}
}

View File

@ -0,0 +1,18 @@
package AccordionBus;
import javax.swing.*;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
// Класс для реализации поддержки передачи данных в Label
public class LabelTransferHandler extends TransferHandler {
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
public Transferable createTransferable(JComponent c) {
return new StringSelection(((JLabel)c).getText());
}
}

View File

@ -0,0 +1,13 @@
package AccordionBus;
import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
// Передаем информацию при нажатии на Panel
public class PanelMouseAdapter extends MouseAdapter {
@Override
public void mousePressed(MouseEvent e) {
((JPanel)e.getComponent()).getTransferHandler().exportAsDrag(((JPanel)e.getComponent()), e, TransferHandler.COPY);
}
}

View File

@ -0,0 +1,17 @@
package AccordionBus;
import javax.swing.*;
import java.awt.datatransfer.Transferable;
// Класс для реализации поддержки передачи данных в Panel
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());
}
}