лаба 5

This commit is contained in:
Алексей Крюков 2023-12-25 12:23:06 +04:00
parent f05a18487e
commit a52763b47a

View File

@ -22,34 +22,30 @@ public class PictureBoxTracktorConfig extends JPanel {
return new StringSelection(((JLabel)c).getText());
}
}
private static class ColorTransferable implements Transferable {
private Color color;
private static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color");
public ColorTransferable(Color color) {
this.color = color;
}
private record ColorTransferable(Color color) implements Transferable {
private static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color");
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{colorDataFlavor};
}
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{colorDataFlavor};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return colorDataFlavor.equals(flavor);
}
@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);
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (isDataFlavorSupported(flavor)) {
return color;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
}
}
private class PanelTransferHandler extends TransferHandler {
private static class PanelTransferHandler extends TransferHandler {
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
@ -57,50 +53,45 @@ public class PictureBoxTracktorConfig extends JPanel {
@Override
protected Transferable createTransferable(JComponent c) {
return new ColorTransferable(((JPanel) c).getBackground());
return new ColorTransferable(c.getBackground());
}
}
private class LabelMouseAdapter extends MouseAdapter{
private static 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{
private static class PanelMouseAdapter extends MouseAdapter{
@Override
public void mousePressed(MouseEvent e) {
((JPanel)e.getComponent()).getTransferHandler().exportAsDrag(((JPanel)e.getComponent()), e, TransferHandler.COPY);
}
}
private class RollersTransferable implements Transferable {
private IDrawningRollers rollersDrawning;
private static final DataFlavor rollersDrawningDataFlavor = new DataFlavor(IDrawningRollers.class, "Roller Drawing");
public RollersTransferable(IDrawningRollers rollersDrawning) {
this.rollersDrawning = rollersDrawning;
}
private record RollersTransferable(IDrawningRollers rollersDrawning) implements Transferable {
private static final DataFlavor rollersDrawningDataFlavor = new DataFlavor(IDrawningRollers.class, "Roller Drawing");
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{rollersDrawningDataFlavor};
}
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{rollersDrawningDataFlavor};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(rollersDrawningDataFlavor);
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(rollersDrawningDataFlavor);
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (isDataFlavorSupported(flavor)) {
return rollersDrawning;
} else {
throw new UnsupportedFlavorException(flavor);
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (isDataFlavorSupported(flavor)) {
return rollersDrawning;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
}
}
private class RollerPanel extends JPanel{
private static class RollerPanel extends JPanel{
public IDrawningRollers rollersDrawning;
public RollerPanel(IDrawningRollers _rollersDrawning){
@ -123,7 +114,7 @@ public class PictureBoxTracktorConfig extends JPanel {
@Override
protected Transferable createTransferable(JComponent c) {
return new RollersTransferable(((RollerPanel)c).rollersDrawning);
return new RollersTransferable(((RollerPanel) c).rollersDrawning);
}
}
);
@ -149,7 +140,7 @@ public class PictureBoxTracktorConfig extends JPanel {
_tracktor.DrawTransport(g2d);
}
}
DrawningTracktor _tracktor = null;
DrawningTracktor _tracktor;
JButton buttonAdd, buttonCancel;
JLabel labelParameters, labelColors, labelSpeed, labelWeight, labelRollerAmount, labelSimpleObject, labelModifiedObject, labelBodyColor, labelBucketColor, labelSupportsColor, labelRollers, labelRollerPreview;
JCheckBox checkBoxBucket, checkBoxSupports;
@ -158,7 +149,7 @@ public class PictureBoxTracktorConfig extends JPanel {
JPanel panelRed, panelGreen, panelBlue, panelYellow, panelWhite, panelGray, panelBlack, panelMagenta;
TracktorPreview TracktorPreview;
public PictureBoxTracktorConfig() {
Random random = new Random();
new Random();
setLayout(null);
setBounds(0, 0, 800, 300);
buttonAdd = new JButton("Добавить");
@ -424,13 +415,13 @@ public class PictureBoxTracktorConfig extends JPanel {
labelRollers = new JLabel("Колеса");
labelRollers.setBounds(250, 150, 100, 20);
add(labelRollers);
RollerPanel RollerPanelDefault = new RollerPanel(new DrawningRollers((int)numericUpDownRollerAmount.getValue(),Color.RED));
RollerPanel RollerPanelDefault = new RollerPanel(new DrawningRollers((int) numericUpDownRollerAmount.getValue(), Color.RED));
RollerPanelDefault.setBounds(250, 180, 40, 40);
add(RollerPanelDefault);
RollerPanel RollerPanelCircles = new RollerPanel(new DrawningCrossRollers((int)numericUpDownRollerAmount.getValue(),Color.RED));
RollerPanel RollerPanelCircles = new RollerPanel(new DrawningCrossRollers((int) numericUpDownRollerAmount.getValue(), Color.RED));
RollerPanelCircles.setBounds(300, 180, 40, 40);
add(RollerPanelCircles);
RollerPanel RollerPanelStar = new RollerPanel(new DrawningSquaredRollers((int)numericUpDownRollerAmount.getValue(),Color.RED));
RollerPanel RollerPanelStar = new RollerPanel(new DrawningSquaredRollers((int) numericUpDownRollerAmount.getValue(), Color.RED));
RollerPanelStar.setBounds(350, 180, 40, 40);
add(RollerPanelStar);