Переделал на передачу объекта двигателей

This commit is contained in:
Никита Потапов 2023-12-05 12:43:26 +04:00
parent b8906c0325
commit b8c40931ed

View File

@ -58,13 +58,49 @@ public class FormPlaneConfig {
labelStormtrooper.setTransferHandler(new LabelTransferHandler());
labelStormtrooper.addMouseListener(new LabelMouseAdapter());
labelEllipseEngines.setTransferHandler(new LabelTransferHandler());
labelEllipseEngines.setTransferHandler(
new TransferHandler(){
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
protected Transferable createTransferable(JComponent c) {
return new EngineTransferable(new DrawingEnginesEllipse());
}
}
);
labelEllipseEngines.addMouseListener(new LabelMouseAdapter());
labelPyramidEngines.setTransferHandler(new LabelTransferHandler());
labelPyramidEngines.setTransferHandler(
new TransferHandler(){
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
protected Transferable createTransferable(JComponent c) {
return new EngineTransferable(new DrawingEnginesPyramid());
}
}
);
labelPyramidEngines.addMouseListener(new LabelMouseAdapter());
labelSimpleEngines.setTransferHandler(new LabelTransferHandler());
labelSimpleEngines.setTransferHandler(
new TransferHandler(){
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
protected Transferable createTransferable(JComponent c) {
return new EngineTransferable(new DrawingEnginesSimple());
}
}
);
labelSimpleEngines.addMouseListener(new LabelMouseAdapter());
JPanel[] colorPanels = {
@ -122,12 +158,11 @@ public class FormPlaneConfig {
}
);
Canvas canvas = new Canvas();
panelShow.setTransferHandler(
new TransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
return support.isDataFlavorSupported(DataFlavor.stringFlavor);
return support.isDataFlavorSupported(DataFlavor.stringFlavor) || support.isDataFlavorSupported(EngineTransferable.engineDrawingDataFlavor);
}
@Override
@ -161,30 +196,19 @@ public class FormPlaneConfig {
} else {
return false;
}
} catch (UnsupportedFlavorException | IOException e) {
}
String dataEngines = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
IDrawingEngines iDrawingEngines = null;
try {
IDrawingEngines drawingEngines = (IDrawingEngines) support.getTransferable().getTransferData(EngineTransferable.engineDrawingDataFlavor);
int enginesCount = (int) spinnerEnginesCount.getValue();
switch (dataEngines) {
case "Эллипс" -> {
iDrawingEngines = new DrawingEnginesEllipse();
}
case "Обычный" -> {
iDrawingEngines = new DrawingEnginesSimple();
}
case "Пирамид" -> {
iDrawingEngines = new DrawingEnginesPyramid();
}
}
if (iDrawingEngines != null) {
selectedPlane._drawingEngines = iDrawingEngines;
selectedPlane._drawingEngines = drawingEngines;
selectedPlane.SetEnginesCount(enginesCount);
}
catch (UnsupportedFlavorException | IOException e) {
}
panelShow.repaint();
return true;
} catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
}
return false;
}
@ -219,6 +243,34 @@ public class FormPlaneConfig {
}
}
private class EngineTransferable implements Transferable {
private IDrawingEngines drawingEngines;
private static final DataFlavor engineDrawingDataFlavor = new DataFlavor(IDrawingEngines.class, "Engine Drawing");
public EngineTransferable(IDrawingEngines drawingEngines) {
this.drawingEngines = drawingEngines;
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{engineDrawingDataFlavor};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(engineDrawingDataFlavor);
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (isDataFlavorSupported(flavor)) {
return drawingEngines;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
}
private class ColorTransferable implements Transferable {
private Color color;
private static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color");