5 lab for pull request
This commit is contained in:
parent
ac846959df
commit
27af9813f3
@ -10,7 +10,6 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.border.Border;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormLocomotiveConfig{
|
||||
|
||||
@ -108,7 +107,6 @@ public class FormLocomotiveConfig{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//для перетаскивания цвета
|
||||
private class PanelTransferHandler extends TransferHandler {
|
||||
@Override
|
||||
@ -156,15 +154,45 @@ public class FormLocomotiveConfig{
|
||||
labelModifiedObject.addMouseListener(new LabelMouseAdapter());
|
||||
labelModifiedObject.setBorder(br);
|
||||
|
||||
labelBlackWheels.setTransferHandler(new LabelTransferHandler());
|
||||
labelBlackWheels.setTransferHandler(new TransferHandler(){
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawingWheel());
|
||||
}
|
||||
});
|
||||
labelBlackWheels.addMouseListener(new LabelMouseAdapter());
|
||||
labelBlackWheels.setBorder(br);
|
||||
|
||||
labelEmptyWheels.setTransferHandler(new LabelTransferHandler());
|
||||
labelEmptyWheels.setTransferHandler(new TransferHandler(){
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawingEmptyWheels());
|
||||
}
|
||||
});
|
||||
labelEmptyWheels.addMouseListener(new LabelMouseAdapter());
|
||||
labelEmptyWheels.setBorder(br);
|
||||
|
||||
labelRainbowWheels.setTransferHandler((new LabelTransferHandler()));
|
||||
labelRainbowWheels.setTransferHandler( new TransferHandler(){
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawingWheelsBlueCrom());
|
||||
}
|
||||
});
|
||||
labelRainbowWheels.addMouseListener(new LabelMouseAdapter());
|
||||
labelRainbowWheels.setBorder(br);
|
||||
|
||||
@ -211,7 +239,6 @@ public class FormLocomotiveConfig{
|
||||
return true;
|
||||
}
|
||||
catch(UnsupportedFlavorException | IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -230,13 +257,12 @@ public class FormLocomotiveConfig{
|
||||
Border border = BorderFactory.createLineBorder(color);
|
||||
labelDopColor.setBorder(border);
|
||||
if(_loco == null) return false;
|
||||
if(!(_loco instanceof DrawingLocomotive))
|
||||
if(!(_loco instanceof DrawingElectricLocomotive))
|
||||
return false;
|
||||
((EntityElectricLocomotive)_loco.EntityLocomotive).SetAdditionalColor(color);
|
||||
return true;
|
||||
}
|
||||
catch(UnsupportedFlavorException | IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -244,12 +270,11 @@ public class FormLocomotiveConfig{
|
||||
}
|
||||
);
|
||||
|
||||
canvas = new Canvas();
|
||||
pictureBoxObject.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
return support.isDataFlavorSupported(DataFlavor.stringFlavor);
|
||||
return support.isDataFlavorSupported(DataFlavor.stringFlavor) || support.isDataFlavorSupported(WheelsTransferable.wheelsDrawingDataFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -281,31 +306,17 @@ public class FormLocomotiveConfig{
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
}
|
||||
try{
|
||||
int wheelsCount = (int)numericUpDownWheels.getValue();
|
||||
IDrawingWheels iDrawingWheels;
|
||||
String dataWheels = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||
switch (dataWheels){
|
||||
case "Черные колеса":
|
||||
iDrawingWheels = new DrawingWheel();
|
||||
iDrawingWheels.SetWheelsCount(wheelsCount);
|
||||
_loco._drawingWheels = iDrawingWheels;
|
||||
break;
|
||||
case "Пустые колеса":
|
||||
iDrawingWheels = new DrawingEmptyWheels();
|
||||
iDrawingWheels.SetWheelsCount(wheelsCount);
|
||||
_loco._drawingWheels = iDrawingWheels;
|
||||
break;
|
||||
case "Радужные колеса":
|
||||
iDrawingWheels = new DrawingWheelsBlueCrom();
|
||||
iDrawingWheels.SetWheelsCount(wheelsCount);
|
||||
_loco._drawingWheels = iDrawingWheels;
|
||||
break;
|
||||
IDrawingWheels drawingWheels = (IDrawingWheels) support.getTransferable().getTransferData(WheelsTransferable.wheelsDrawingDataFlavor);
|
||||
_loco._drawingWheels = drawingWheels;
|
||||
_loco.SetWheelsCount(wheelsCount);
|
||||
}catch(UnsupportedFlavorException | IOException e){
|
||||
}
|
||||
pictureBoxObject.repaint();
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -313,6 +324,34 @@ public class FormLocomotiveConfig{
|
||||
);
|
||||
}
|
||||
|
||||
private class WheelsTransferable implements Transferable {
|
||||
private IDrawingWheels drawingWheels;
|
||||
private static final DataFlavor wheelsDrawingDataFlavor = new DataFlavor(IDrawingWheels.class, "Wheels Drawing");
|
||||
|
||||
public WheelsTransferable(IDrawingWheels drawingWheels) {
|
||||
this.drawingWheels = drawingWheels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{wheelsDrawingDataFlavor};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return flavor.equals(wheelsDrawingDataFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return drawingWheels;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createUIComponents(){
|
||||
pictureBoxObject = new Canvas();
|
||||
pictureBoxObject.setBounds(new Rectangle(300, 300));
|
||||
|
Loading…
Reference in New Issue
Block a user