transitioned
This commit is contained in:
parent
1ce9de4971
commit
c8998395cc
10
Liner_Advanced/.idea/material_theme_project_new.xml
generated
Normal file
10
Liner_Advanced/.idea/material_theme_project_new.xml
generated
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MaterialThemeProjectNewConfig">
|
||||||
|
<option name="metadata">
|
||||||
|
<MTProjectMetadataState>
|
||||||
|
<option name="userId" value="7281a457:1950862827a:-7fff" />
|
||||||
|
</MTProjectMetadataState>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,31 @@
|
|||||||
|
package projectliner.Drawings;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
|
|
||||||
|
public class ColorTransferable implements Transferable {
|
||||||
|
public static DataFlavor colorFlavor = new DataFlavor(Color.class,
|
||||||
|
"A Color Object");
|
||||||
|
private Color color;
|
||||||
|
|
||||||
|
public ColorTransferable(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
return new DataFlavor[]{colorFlavor};
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
|
return flavor.equals(colorFlavor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||||
|
if (!isDataFlavorSupported(flavor)) {
|
||||||
|
throw new UnsupportedFlavorException(flavor);
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
}
|
@ -61,6 +61,9 @@ public class DrawingLiner extends DrawingBaseLiner {
|
|||||||
this.startPosY = this.startPosY - 20;
|
this.startPosY = this.startPosY - 20;
|
||||||
Color deckColor = linerEntity.getSecondaryColor();
|
Color deckColor = linerEntity.getSecondaryColor();
|
||||||
Color borderColor = Color.BLACK;
|
Color borderColor = Color.BLACK;
|
||||||
|
if (!linerEntity.hasExtraDeck()) {
|
||||||
|
this.deck.setNumericalValue(1);
|
||||||
|
}
|
||||||
this.deck.drawAdditionalElement(x, y, borderColor, deckColor, g);
|
this.deck.drawAdditionalElement(x, y, borderColor, deckColor, g);
|
||||||
if (linerEntity.hasPool()) {
|
if (linerEntity.hasPool()) {
|
||||||
g2d.setColor(Color.CYAN);
|
g2d.setColor(Color.CYAN);
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package projectliner.Drawings;
|
||||||
|
|
||||||
|
import projectliner.Drawings.DrawingBaseLiner;
|
||||||
|
|
||||||
|
public interface ILinerDelegate {
|
||||||
|
void setLiner(DrawingBaseLiner liner);
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package projectliner.Drawings;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
|
||||||
|
public class LabelTransferHandler extends TransferHandler {
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
JLabel label = (JLabel) c;
|
||||||
|
return new StringSelection(label.getText()); // Передаем текст метки
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
return COPY;
|
||||||
|
}
|
||||||
|
}
|
@ -28,5 +28,9 @@ public class BaseLinerEntity {
|
|||||||
public double getStep() {
|
public double getStep() {
|
||||||
return (double)this.speed / (this.weight / (double)100.0F);
|
return (double)this.speed / (this.weight / (double)100.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPrimaryColor(Color primaryColor) {
|
||||||
|
this.primaryColor = primaryColor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,4 +50,8 @@ public class LinerEntity extends BaseLinerEntity {
|
|||||||
public boolean hasPool() {
|
public boolean hasPool() {
|
||||||
return this.hasPool;
|
return this.hasPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSecondaryColor(Color secondaryColor) {
|
||||||
|
this.secondaryColor = secondaryColor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
448
Liner_Advanced/src/projectliner/FormLinerConfig.java
Normal file
448
Liner_Advanced/src/projectliner/FormLinerConfig.java
Normal file
@ -0,0 +1,448 @@
|
|||||||
|
package projectliner;
|
||||||
|
|
||||||
|
import projectliner.Drawings.DrawingBaseLiner;
|
||||||
|
import projectliner.Drawings.ColorTransferable;
|
||||||
|
import projectliner.Drawings.DrawingLiner;
|
||||||
|
import projectliner.Drawings.LabelTransferHandler;
|
||||||
|
import projectliner.Entities.LinerEntity;
|
||||||
|
import projectliner.Entities.LinerEntityType;
|
||||||
|
import projectliner.Drawings.ILinerDelegate;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.border.LineBorder;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.awt.dnd.*;
|
||||||
|
import java.awt.datatransfer.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public class FormLinerConfig extends JFrame {
|
||||||
|
private DrawingBaseLiner liner;
|
||||||
|
private ILinerDelegate linerDelegate;
|
||||||
|
private ColorTransferable colorTransferable;
|
||||||
|
|
||||||
|
private JButton buttonCancel;
|
||||||
|
private JButton buttonAdd;
|
||||||
|
private JPanel panelRed, panelGreen, panelBlue, panelYellow,
|
||||||
|
panelWhite, panelGray, panelBlack, panelPurple;
|
||||||
|
private JLabel labelPrimaryColor, labelSecondaryColor;
|
||||||
|
private JComboBox<String> comboBoxLinerType;
|
||||||
|
private JCheckBox checkBoxExtraDeck, checkBoxPool;
|
||||||
|
private JSpinner numericUpDownSpeed, numericUpDownWeight,
|
||||||
|
numericUpDownCapacity, numericUpDownMaxPassengers,
|
||||||
|
numericUpDownDeckNum;
|
||||||
|
private JLabel pictureBoxLiner;
|
||||||
|
|
||||||
|
public FormLinerConfig() {
|
||||||
|
initComponents();
|
||||||
|
buttonCancel.addActionListener(e -> dispose());
|
||||||
|
addMouseListenersToPanels();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLinerDelegate(ILinerDelegate linerDelegate) {
|
||||||
|
this.linerDelegate = linerDelegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawObject() {
|
||||||
|
BufferedImage bmp = new BufferedImage(pictureBoxLiner.getWidth(),
|
||||||
|
pictureBoxLiner.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
|
Graphics2D gr = bmp.createGraphics();
|
||||||
|
if (liner != null) {
|
||||||
|
if (liner instanceof DrawingLiner drawingLiner) {
|
||||||
|
drawingLiner.setPictureSize(pictureBoxLiner.getWidth(), pictureBoxLiner.getHeight());
|
||||||
|
drawingLiner.setPosition(15, 15);
|
||||||
|
drawingLiner.drawTransport(gr);
|
||||||
|
} else {
|
||||||
|
liner.setPictureSize(pictureBoxLiner.getWidth(), pictureBoxLiner.getHeight());
|
||||||
|
liner.setPosition(15, 15);
|
||||||
|
liner.drawTransport(gr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pictureBoxLiner.setIcon(new ImageIcon(bmp));
|
||||||
|
pictureBoxLiner.revalidate();
|
||||||
|
pictureBoxLiner.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMouseListenersToPanels() {
|
||||||
|
panelRed.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
panelMouseDown(panelRed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panelGreen.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
panelMouseDown(panelGreen);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panelBlue.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
panelMouseDown(panelBlue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panelYellow.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
panelMouseDown(panelYellow);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panelWhite.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
panelMouseDown(panelWhite);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panelGray.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
panelMouseDown(panelGray);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panelBlack.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
panelMouseDown(panelBlack);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panelPurple.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
panelMouseDown(panelPurple);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelObjectMouseDown(MouseEvent e) {
|
||||||
|
JLabel label = (JLabel) e.getSource();
|
||||||
|
TransferHandler handler = label.getTransferHandler();
|
||||||
|
if (handler != null) {
|
||||||
|
handler.exportAsDrag(label, e, TransferHandler.COPY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void panelObjectDragEnter(DropTargetDragEvent e) {
|
||||||
|
if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
|
||||||
|
e.acceptDrag(DnDConstants.ACTION_COPY);
|
||||||
|
} else {
|
||||||
|
e.rejectDrag();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void panelObjectDragDrop(DropTargetDropEvent e) {
|
||||||
|
try {
|
||||||
|
e.acceptDrop(DnDConstants.ACTION_COPY);
|
||||||
|
String data = (String) e.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||||
|
switch (data) {
|
||||||
|
case "Basic Object":
|
||||||
|
liner = new DrawingBaseLiner((int) numericUpDownSpeed.getValue(),
|
||||||
|
((Integer) numericUpDownWeight.getValue()).doubleValue() , Color.WHITE);
|
||||||
|
break;
|
||||||
|
case "Advanced Object":
|
||||||
|
liner = new DrawingLiner((int) numericUpDownSpeed.getValue(), ((Integer) numericUpDownWeight.getValue()).doubleValue(),
|
||||||
|
Color.WHITE, Color.BLACK, LinerEntityType.values()[comboBoxLinerType.getSelectedIndex()],
|
||||||
|
(int) numericUpDownCapacity.getValue(), (int) numericUpDownMaxPassengers.getValue(),
|
||||||
|
checkBoxExtraDeck.isSelected(), checkBoxPool.isSelected(), (int) numericUpDownDeckNum.getValue(), "Triangular Deck");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
drawObject();
|
||||||
|
e.dropComplete(true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
e.dropComplete(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void panelMouseDown(JPanel panel) {
|
||||||
|
Color color = panel.getBackground();
|
||||||
|
Transferable transferable = new ColorTransferable(color);
|
||||||
|
DragSource ds = new DragSource();
|
||||||
|
ds.createDefaultDragGestureRecognizer(panel, DnDConstants.ACTION_COPY, new DragGestureListener() {
|
||||||
|
public void dragGestureRecognized(DragGestureEvent dge) {
|
||||||
|
ds.startDrag(dge, DragSource.DefaultCopyDrop, transferable, new DragSourceAdapter() {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelColorDragEnter(DropTargetDragEvent e) {
|
||||||
|
if (e.isDataFlavorSupported(ColorTransferable.colorFlavor)) {
|
||||||
|
e.acceptDrag(DnDConstants.ACTION_COPY);
|
||||||
|
} else {
|
||||||
|
e.rejectDrag();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelColorDragDrop(DropTargetDropEvent e) {
|
||||||
|
try {
|
||||||
|
e.acceptDrop(DnDConstants.ACTION_COPY);
|
||||||
|
Color color = (Color) e.getTransferable().getTransferData(ColorTransferable.colorFlavor);
|
||||||
|
if (e.getDropTargetContext().getComponent() == labelPrimaryColor) {
|
||||||
|
liner.baseLiner.setPrimaryColor(color);
|
||||||
|
} else if (e.getDropTargetContext().getComponent() == labelSecondaryColor) {
|
||||||
|
if (liner instanceof DrawingLiner drawingLiner) {
|
||||||
|
if (drawingLiner.getBaseLiner() instanceof LinerEntity linerEntity) {
|
||||||
|
linerEntity.setSecondaryColor(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drawObject();
|
||||||
|
e.dropComplete(true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
e.dropComplete(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initComponents() {
|
||||||
|
setTitle("FormLinerConfig");
|
||||||
|
setSize(800, 300);
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
numericUpDownSpeed = new JSpinner(new SpinnerNumberModel(100,
|
||||||
|
0, 1000, 1));
|
||||||
|
numericUpDownSpeed.setMaximumSize(new Dimension(100, 20));
|
||||||
|
numericUpDownWeight = new JSpinner(new SpinnerNumberModel(100,
|
||||||
|
0, 1000, 1));
|
||||||
|
numericUpDownWeight.setMaximumSize(new Dimension(100, 20));
|
||||||
|
numericUpDownCapacity = new JSpinner(new SpinnerNumberModel(100,
|
||||||
|
0, 1000, 1));
|
||||||
|
numericUpDownCapacity.setMaximumSize(new Dimension(100, 20));
|
||||||
|
numericUpDownMaxPassengers = new JSpinner(new SpinnerNumberModel(100,
|
||||||
|
0, 1000, 1));
|
||||||
|
numericUpDownMaxPassengers.setMaximumSize(new Dimension(100, 20));
|
||||||
|
numericUpDownDeckNum = new JSpinner(new SpinnerNumberModel(1,
|
||||||
|
1, 3, 1));
|
||||||
|
numericUpDownDeckNum.setMaximumSize(new Dimension(100, 20));
|
||||||
|
|
||||||
|
comboBoxLinerType = new JComboBox<>(new String[]{"Passenger", "Cargo", "Military", "Mixed"});
|
||||||
|
comboBoxLinerType.setMaximumSize(new Dimension(100, 20));
|
||||||
|
checkBoxExtraDeck = new JCheckBox("Extra Deck feature");
|
||||||
|
checkBoxPool = new JCheckBox("Pool feature");
|
||||||
|
|
||||||
|
JPanel panelParameters = new JPanel();
|
||||||
|
panelParameters.setLayout(new BoxLayout(panelParameters, BoxLayout.Y_AXIS));
|
||||||
|
panelParameters.setMaximumSize(new Dimension(500, 260));
|
||||||
|
panelParameters.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||||
|
JLabel labelParameters = new JLabel("Parameters");
|
||||||
|
labelParameters.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
JPanel panelParametersLabels = new JPanel();
|
||||||
|
panelParametersLabels.setLayout(new BoxLayout(panelParametersLabels, BoxLayout.Y_AXIS));
|
||||||
|
panelParametersLabels.setMaximumSize(new Dimension(200, 200));
|
||||||
|
panelParametersLabels.add(new JLabel("Type of Liner"));
|
||||||
|
panelParametersLabels.add(Box.createVerticalStrut(10));
|
||||||
|
panelParametersLabels.add(new JLabel("Speed"));
|
||||||
|
panelParametersLabels.add(Box.createVerticalStrut(10));
|
||||||
|
panelParametersLabels.add(new JLabel("Weight"));
|
||||||
|
panelParametersLabels.add(Box.createVerticalStrut(10));
|
||||||
|
panelParametersLabels.add(new JLabel("Capacity"));
|
||||||
|
panelParametersLabels.add(Box.createVerticalStrut(10));
|
||||||
|
panelParametersLabels.add(new JLabel("Max Passengers"));
|
||||||
|
panelParametersLabels.add(Box.createVerticalStrut(10));
|
||||||
|
panelParametersLabels.add(new JLabel("Deck Number"));
|
||||||
|
|
||||||
|
JPanel panelParametersValues = new JPanel();
|
||||||
|
panelParametersValues.setLayout(new BoxLayout(panelParametersValues, BoxLayout.Y_AXIS));
|
||||||
|
panelParametersValues.setMaximumSize(new Dimension(200, 200));
|
||||||
|
panelParametersValues.add(comboBoxLinerType);
|
||||||
|
panelParametersValues.add(Box.createVerticalStrut(5));
|
||||||
|
panelParametersValues.add(numericUpDownSpeed);
|
||||||
|
panelParametersValues.add(Box.createVerticalStrut(5));
|
||||||
|
panelParametersValues.add(numericUpDownWeight);
|
||||||
|
panelParametersValues.add(Box.createVerticalStrut(5));
|
||||||
|
panelParametersValues.add(numericUpDownCapacity);
|
||||||
|
panelParametersValues.add(Box.createVerticalStrut(5));
|
||||||
|
panelParametersValues.add(numericUpDownMaxPassengers);
|
||||||
|
panelParametersValues.add(Box.createVerticalStrut(5));
|
||||||
|
panelParametersValues.add(numericUpDownDeckNum);
|
||||||
|
|
||||||
|
JPanel panelCheckBoxes = new JPanel();
|
||||||
|
panelCheckBoxes.setLayout(new BoxLayout(panelCheckBoxes, BoxLayout.X_AXIS));
|
||||||
|
panelCheckBoxes.setMaximumSize(new Dimension(300, 40));
|
||||||
|
panelCheckBoxes.add(checkBoxExtraDeck);
|
||||||
|
panelCheckBoxes.add(checkBoxPool);
|
||||||
|
|
||||||
|
JPanel panelAllParameters = new JPanel();
|
||||||
|
panelAllParameters.setLayout(new BoxLayout(panelAllParameters, BoxLayout.X_AXIS));
|
||||||
|
panelAllParameters.add(panelParametersLabels);
|
||||||
|
panelAllParameters.add(Box.createHorizontalStrut(10));
|
||||||
|
panelAllParameters.add(panelParametersValues);
|
||||||
|
|
||||||
|
panelParameters.add(labelParameters);
|
||||||
|
panelParameters.add(Box.createVerticalStrut(10));
|
||||||
|
panelParameters.add(panelAllParameters);
|
||||||
|
panelParameters.add(Box.createVerticalStrut(10));
|
||||||
|
panelParameters.add(panelCheckBoxes);
|
||||||
|
|
||||||
|
add(panelParameters, BorderLayout.WEST);
|
||||||
|
|
||||||
|
JPanel middlePanel = new JPanel();
|
||||||
|
middlePanel.setLayout(new BoxLayout(middlePanel, BoxLayout.Y_AXIS));
|
||||||
|
middlePanel.setMaximumSize(new Dimension(200, 200));
|
||||||
|
middlePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||||
|
JLabel labelColors = new JLabel("Colors");
|
||||||
|
labelColors.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
JPanel panelColorsUp = new JPanel();
|
||||||
|
panelColorsUp.setLayout(new BoxLayout(panelColorsUp, BoxLayout.X_AXIS));
|
||||||
|
JPanel panelColorsDown = new JPanel();
|
||||||
|
panelColorsDown.setLayout(new BoxLayout(panelColorsDown, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
|
panelRed = createColorPanel(Color.RED);
|
||||||
|
panelGreen = createColorPanel(Color.GREEN);
|
||||||
|
panelBlue = createColorPanel(Color.BLUE);
|
||||||
|
panelYellow = createColorPanel(Color.YELLOW);
|
||||||
|
panelWhite = createColorPanel(Color.WHITE);
|
||||||
|
panelGray = createColorPanel(Color.GRAY);
|
||||||
|
panelBlack = createColorPanel(Color.BLACK);
|
||||||
|
panelPurple = createColorPanel(Color.MAGENTA);
|
||||||
|
|
||||||
|
panelColorsUp.add(panelRed);
|
||||||
|
panelColorsUp.add(Box.createHorizontalStrut(10));
|
||||||
|
panelColorsUp.add(panelGreen);
|
||||||
|
panelColorsUp.add(Box.createHorizontalStrut(10));
|
||||||
|
panelColorsUp.add(panelBlue);
|
||||||
|
panelColorsUp.add(Box.createHorizontalStrut(10));
|
||||||
|
panelColorsUp.add(panelYellow);
|
||||||
|
panelColorsDown.add(panelWhite);
|
||||||
|
panelColorsDown.add(Box.createHorizontalStrut(10));
|
||||||
|
panelColorsDown.add(panelGray);
|
||||||
|
panelColorsDown.add(Box.createHorizontalStrut(10));
|
||||||
|
panelColorsDown.add(panelBlack);
|
||||||
|
panelColorsDown.add(Box.createHorizontalStrut(10));
|
||||||
|
panelColorsDown.add(panelPurple);
|
||||||
|
|
||||||
|
JLabel labelBasicObject = new JLabel("Basic Object");
|
||||||
|
labelBasicObject.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
labelBasicObject.setMaximumSize(new Dimension(200, 40));
|
||||||
|
labelBasicObject.setBorder(new LineBorder(Color.BLACK));
|
||||||
|
labelBasicObject.setTransferHandler(new LabelTransferHandler());
|
||||||
|
labelBasicObject.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
labelObjectMouseDown(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JLabel labelAdvancedObject = new JLabel("Advanced Object");
|
||||||
|
labelAdvancedObject.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
labelAdvancedObject.setMaximumSize(new Dimension(200, 40));
|
||||||
|
labelAdvancedObject.setBorder(new LineBorder(Color.BLACK));
|
||||||
|
labelAdvancedObject.setTransferHandler(new LabelTransferHandler());
|
||||||
|
labelAdvancedObject.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
labelObjectMouseDown(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JPanel objectEntities = new JPanel();
|
||||||
|
objectEntities.setLayout(new BoxLayout(objectEntities, BoxLayout.X_AXIS));
|
||||||
|
objectEntities.add(labelBasicObject);
|
||||||
|
objectEntities.add(Box.createHorizontalStrut(10));
|
||||||
|
objectEntities.add(labelAdvancedObject);
|
||||||
|
|
||||||
|
middlePanel.add(labelColors);
|
||||||
|
middlePanel.add(Box.createVerticalStrut(10));
|
||||||
|
middlePanel.add(panelColorsUp);
|
||||||
|
middlePanel.add(Box.createVerticalStrut(10));
|
||||||
|
middlePanel.add(panelColorsDown);
|
||||||
|
middlePanel.add(Box.createVerticalStrut(10));
|
||||||
|
middlePanel.add(objectEntities);
|
||||||
|
|
||||||
|
add(middlePanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel panelObject = new JPanel();
|
||||||
|
panelObject.setLayout(new BoxLayout(panelObject, BoxLayout.Y_AXIS));
|
||||||
|
panelObject.setMaximumSize(new Dimension(200, 300));
|
||||||
|
panelObject.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||||
|
|
||||||
|
labelPrimaryColor = new JLabel("Primary Color");
|
||||||
|
labelPrimaryColor.setMaximumSize(new Dimension(200, 40));
|
||||||
|
labelPrimaryColor.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
labelPrimaryColor.setBorder(new LineBorder(Color.BLACK));
|
||||||
|
labelPrimaryColor.setTransferHandler(new TransferHandler("background"));
|
||||||
|
|
||||||
|
labelSecondaryColor = new JLabel("Secondary Color");
|
||||||
|
labelSecondaryColor.setMaximumSize(new Dimension(200, 40));
|
||||||
|
labelSecondaryColor.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
labelSecondaryColor.setBorder(new LineBorder(Color.BLACK));
|
||||||
|
labelSecondaryColor.setTransferHandler(new TransferHandler("background"));
|
||||||
|
|
||||||
|
JPanel colorLabels = new JPanel();
|
||||||
|
colorLabels.setLayout(new BoxLayout(colorLabels, BoxLayout.X_AXIS));
|
||||||
|
colorLabels.add(labelPrimaryColor);
|
||||||
|
colorLabels.add(Box.createHorizontalStrut(10));
|
||||||
|
colorLabels.add(labelSecondaryColor);
|
||||||
|
|
||||||
|
pictureBoxLiner = new JLabel();
|
||||||
|
pictureBoxLiner.setMaximumSize(new Dimension(200, 150));
|
||||||
|
pictureBoxLiner.setPreferredSize(new Dimension(200, 150));
|
||||||
|
pictureBoxLiner.setMinimumSize(new Dimension(200, 150));
|
||||||
|
pictureBoxLiner.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
JPanel panelButtons = new JPanel();
|
||||||
|
panelButtons.setLayout(new BoxLayout(panelButtons, BoxLayout.X_AXIS));
|
||||||
|
buttonAdd = new JButton("Add");
|
||||||
|
buttonAdd.addActionListener(e -> buttonAddClick());
|
||||||
|
buttonCancel = new JButton("Cancel");
|
||||||
|
panelButtons.add(buttonAdd);
|
||||||
|
panelButtons.add(Box.createHorizontalStrut(10));
|
||||||
|
panelButtons.add(buttonCancel);
|
||||||
|
|
||||||
|
panelObject.add(colorLabels);
|
||||||
|
panelObject.add(Box.createVerticalStrut(10));
|
||||||
|
panelObject.add(pictureBoxLiner);
|
||||||
|
panelObject.add(Box.createVerticalStrut(10));
|
||||||
|
panelObject.add(panelButtons);
|
||||||
|
|
||||||
|
new DropTarget(panelObject, new DropTargetAdapter() {
|
||||||
|
public void dragEnter(DropTargetDragEvent e) {
|
||||||
|
panelObjectDragEnter(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dragOver(DropTargetDragEvent e) {
|
||||||
|
panelObjectDragEnter(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drop(DropTargetDropEvent e) {
|
||||||
|
panelObjectDragDrop(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
new DropTarget(labelPrimaryColor, new DropTargetAdapter() {
|
||||||
|
public void dragEnter(DropTargetDragEvent e) {
|
||||||
|
labelColorDragEnter(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dragOver(DropTargetDragEvent e) {
|
||||||
|
labelColorDragEnter(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drop(DropTargetDropEvent e) {
|
||||||
|
labelColorDragDrop(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
new DropTarget(labelSecondaryColor, new DropTargetAdapter() {
|
||||||
|
public void dragEnter(DropTargetDragEvent e) {
|
||||||
|
labelColorDragEnter(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dragOver(DropTargetDragEvent e) {
|
||||||
|
labelColorDragEnter(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drop(DropTargetDropEvent e) {
|
||||||
|
labelColorDragDrop(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
add(panelObject, BorderLayout.EAST);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel createColorPanel(Color color) {
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setBackground(color);
|
||||||
|
panel.setMaximumSize(new Dimension(50, 50));
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAddClick() {
|
||||||
|
if (liner != null && linerDelegate != null) {
|
||||||
|
linerDelegate.setLiner(liner);
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,6 @@ public class FormShipCollection extends JFrame {
|
|||||||
private AbstractCompany company = null;
|
private AbstractCompany company = null;
|
||||||
private JComboBox<String> comboBoxCompanySelector;
|
private JComboBox<String> comboBoxCompanySelector;
|
||||||
private JButton buttonAddLiner;
|
private JButton buttonAddLiner;
|
||||||
private JButton buttonAddShip;
|
|
||||||
private JButton buttonRemoveShip;
|
private JButton buttonRemoveShip;
|
||||||
private JButton buttonSubmitForTesting;
|
private JButton buttonSubmitForTesting;
|
||||||
private JButton buttonRefresh;
|
private JButton buttonRefresh;
|
||||||
@ -62,16 +61,7 @@ public class FormShipCollection extends JFrame {
|
|||||||
buttonAddLiner.addActionListener(new ActionListener() {
|
buttonAddLiner.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
createObject("DrawingBaseLiner");
|
addLiner();
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
buttonAddShip = new JButton("Add Ship");
|
|
||||||
buttonAddShip.setMaximumSize(new Dimension(Integer.MAX_VALUE, 36));
|
|
||||||
buttonAddShip.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
createObject("DrawingLiner");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -208,7 +198,6 @@ public class FormShipCollection extends JFrame {
|
|||||||
pictureBox.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
pictureBox.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
|
||||||
buttonAddLiner.setAlignmentX(Component.CENTER_ALIGNMENT);
|
buttonAddLiner.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
buttonAddShip.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
||||||
buttonCreateRandomShip.setAlignmentX(Component.CENTER_ALIGNMENT);
|
buttonCreateRandomShip.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
labelPosition.setAlignmentX(Component.CENTER_ALIGNMENT);
|
labelPosition.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
buttonRemoveShip.setAlignmentX(Component.CENTER_ALIGNMENT);
|
buttonRemoveShip.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
@ -223,8 +212,6 @@ public class FormShipCollection extends JFrame {
|
|||||||
controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
|
controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
|
||||||
controlPanel.add(buttonAddLiner);
|
controlPanel.add(buttonAddLiner);
|
||||||
controlPanel.add(Box.createVerticalStrut(10));
|
controlPanel.add(Box.createVerticalStrut(10));
|
||||||
controlPanel.add(buttonAddShip);
|
|
||||||
controlPanel.add(Box.createVerticalStrut(10));
|
|
||||||
controlPanel.add(buttonCreateRandomShip);
|
controlPanel.add(buttonCreateRandomShip);
|
||||||
controlPanel.add(Box.createVerticalStrut(10));
|
controlPanel.add(Box.createVerticalStrut(10));
|
||||||
controlPanel.add(buttonRemoveShip);
|
controlPanel.add(buttonRemoveShip);
|
||||||
@ -368,27 +355,17 @@ public class FormShipCollection extends JFrame {
|
|||||||
listBoxCollections.setModel(listModel);
|
listBoxCollections.setModel(listModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createObject(String type) {
|
private void addLiner() {
|
||||||
|
FormLinerConfig form = new FormLinerConfig();
|
||||||
|
form.setLinerDelegate(this::createObject);
|
||||||
|
form.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createObject(DrawingBaseLiner liner) {
|
||||||
if (company == null) {
|
if (company == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Random random = new Random();
|
if (AbstractCompany.add(company, liner)) {
|
||||||
DrawingBaseLiner drawingLiner;
|
|
||||||
switch (type) {
|
|
||||||
case "DrawingBaseLiner":
|
|
||||||
drawingLiner = new DrawingBaseLiner(random.nextInt(200) + 100,
|
|
||||||
random.nextInt(2000) + 1000, getColor(random));
|
|
||||||
break;
|
|
||||||
case "DrawingLiner":
|
|
||||||
drawingLiner = new DrawingLiner(random.nextInt(200) + 100, random.nextInt(2000) + 1000,
|
|
||||||
getColor(random), getColor(random),
|
|
||||||
LinerEntityType.CARGO, random.nextInt(9000) + 1000, random.nextInt(90) + 10,
|
|
||||||
random.nextBoolean(), random.nextBoolean(), 3, "Square Deck");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (AbstractCompany.add(company, drawingLiner)) {
|
|
||||||
JOptionPane.showMessageDialog(this, "Object was added");
|
JOptionPane.showMessageDialog(this, "Object was added");
|
||||||
pictureBox.setIcon(new ImageIcon(company.show()));
|
pictureBox.setIcon(new ImageIcon(company.show()));
|
||||||
} else {
|
} else {
|
||||||
@ -396,14 +373,6 @@ public class FormShipCollection extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color getColor(Random random) {
|
|
||||||
Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
|
||||||
JColorChooser colorChooser = new JColorChooser(color);
|
|
||||||
JDialog dialog = JColorChooser.createDialog(this, "Choose Color", true, colorChooser, null, null);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
return colorChooser.getColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeShip() {
|
private void removeShip() {
|
||||||
if (textFieldPosition.getText().isEmpty() || company == null) {
|
if (textFieldPosition.getText().isEmpty() || company == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -76,7 +76,3 @@ public class GenericLinerModelsCollection <T extends BaseLinerEntity,
|
|||||||
return formInfo.toString();
|
return formInfo.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//infoOfPlane.append("Истребитель:").append("\n");
|
|
||||||
// infoOfPlane.append("Скорость: ").append(plane.getStep()).append(",\n");
|
|
||||||
// infoOfPlane.append("Основной цвет: ").append(plane.getBodyColor()).append(",\n");
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user