completed
This commit is contained in:
parent
c8998395cc
commit
3935381e31
@ -0,0 +1,22 @@
|
|||||||
|
package projectliner.Drawings;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.datatransfer.*;
|
||||||
|
|
||||||
|
public class AdditionalElementsTransferHandler extends TransferHandler {
|
||||||
|
private final IAdditionalElements additionalElements;
|
||||||
|
|
||||||
|
public AdditionalElementsTransferHandler(IAdditionalElements additionalElements) {
|
||||||
|
this.additionalElements = additionalElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
return new AdditionalElementsTransferable(additionalElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
return COPY;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package projectliner.Drawings;
|
||||||
|
|
||||||
|
import java.awt.datatransfer.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class AdditionalElementsTransferable implements Transferable {
|
||||||
|
public static final DataFlavor additionalElementsFlavor = new DataFlavor(IAdditionalElements.class, "IAdditionalElements");
|
||||||
|
private final IAdditionalElements additionalElements;
|
||||||
|
|
||||||
|
public AdditionalElementsTransferable(IAdditionalElements additionalElements) {
|
||||||
|
this.additionalElements = additionalElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
return new DataFlavor[]{additionalElementsFlavor};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
|
return flavor.equals(additionalElementsFlavor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||||
|
if (!isDataFlavorSupported(flavor)) {
|
||||||
|
throw new UnsupportedFlavorException(flavor);
|
||||||
|
}
|
||||||
|
return additionalElements;
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ public class DrawingBaseLiner {
|
|||||||
protected Integer startPosY;
|
protected Integer startPosY;
|
||||||
private int drawingLinerWidth;
|
private int drawingLinerWidth;
|
||||||
private int drawingLinerHeight;
|
private int drawingLinerHeight;
|
||||||
private IAdditionalElements deck;
|
protected IAdditionalElements deck;
|
||||||
|
|
||||||
private DrawingBaseLiner() {
|
private DrawingBaseLiner() {
|
||||||
this.drawingLinerWidth = 140;
|
this.drawingLinerWidth = 140;
|
||||||
@ -103,6 +103,11 @@ public class DrawingBaseLiner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDeck(IAdditionalElements deck, int deckNum) {
|
||||||
|
this.deck = deck;
|
||||||
|
this.deck.setNumericalValue(deckNum);
|
||||||
|
}
|
||||||
|
|
||||||
public void drawTransport(Graphics g) {
|
public void drawTransport(Graphics g) {
|
||||||
if (this.baseLiner != null && this.startPosX != null && this.startPosY != null) {
|
if (this.baseLiner != null && this.startPosX != null && this.startPosY != null) {
|
||||||
int x = this.startPosX;
|
int x = this.startPosX;
|
||||||
|
@ -12,7 +12,6 @@ import projectliner.Entities.LinerEntityType;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class DrawingLiner extends DrawingBaseLiner {
|
public class DrawingLiner extends DrawingBaseLiner {
|
||||||
private IAdditionalElements deck;
|
|
||||||
|
|
||||||
public DrawingLiner(int speed, double weight, Color primaryColor,
|
public DrawingLiner(int speed, double weight, Color primaryColor,
|
||||||
Color secondaryColor, LinerEntityType type, int capacity,
|
Color secondaryColor, LinerEntityType type, int capacity,
|
||||||
@ -46,7 +45,10 @@ public class DrawingLiner extends DrawingBaseLiner {
|
|||||||
case "Square Deck" -> this.deck = new SquareDeckDrawing();
|
case "Square Deck" -> this.deck = new SquareDeckDrawing();
|
||||||
default -> throw new IllegalArgumentException("Invalid deck form: " + form);
|
default -> throw new IllegalArgumentException("Invalid deck form: " + form);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeckNum(int deckNum) {
|
||||||
|
this.deck.setNumericalValue(deckNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawTransport(Graphics g) {
|
public void drawTransport(Graphics g) {
|
||||||
|
@ -29,6 +29,14 @@ public class BaseLinerEntity {
|
|||||||
return (double)this.speed / (this.weight / (double)100.0F);
|
return (double)this.speed / (this.weight / (double)100.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSpeed(int speed) {
|
||||||
|
this.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeight(double weight) {
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
public void setPrimaryColor(Color primaryColor) {
|
public void setPrimaryColor(Color primaryColor) {
|
||||||
this.primaryColor = primaryColor;
|
this.primaryColor = primaryColor;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,27 @@ public class LinerEntity extends BaseLinerEntity {
|
|||||||
return this.hasPool;
|
return this.hasPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCapacity(int capacity) {
|
||||||
|
this.capacity = capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxPassengers(int maxPassengers) {
|
||||||
|
this.maxPassengers = maxPassengers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtraDeck(boolean extraDeck) {
|
||||||
|
this.hasExtraDeck = extraDeck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPool(boolean pool) {
|
||||||
|
this.hasPool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
public void setSecondaryColor(Color secondaryColor) {
|
public void setSecondaryColor(Color secondaryColor) {
|
||||||
this.secondaryColor = secondaryColor;
|
this.secondaryColor = secondaryColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setType(LinerEntityType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
package projectliner;
|
package projectliner;
|
||||||
|
|
||||||
import projectliner.Drawings.DrawingBaseLiner;
|
import projectliner.Drawings.*;
|
||||||
import projectliner.Drawings.ColorTransferable;
|
|
||||||
import projectliner.Drawings.DrawingLiner;
|
|
||||||
import projectliner.Drawings.LabelTransferHandler;
|
|
||||||
import projectliner.Entities.LinerEntity;
|
import projectliner.Entities.LinerEntity;
|
||||||
import projectliner.Entities.LinerEntityType;
|
import projectliner.Entities.LinerEntityType;
|
||||||
import projectliner.Drawings.ILinerDelegate;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
@ -20,6 +16,7 @@ import java.awt.image.BufferedImage;
|
|||||||
public class FormLinerConfig extends JFrame {
|
public class FormLinerConfig extends JFrame {
|
||||||
private DrawingBaseLiner liner;
|
private DrawingBaseLiner liner;
|
||||||
private ILinerDelegate linerDelegate;
|
private ILinerDelegate linerDelegate;
|
||||||
|
private IAdditionalElements deck;
|
||||||
private ColorTransferable colorTransferable;
|
private ColorTransferable colorTransferable;
|
||||||
|
|
||||||
private JButton buttonCancel;
|
private JButton buttonCancel;
|
||||||
@ -116,7 +113,7 @@ public class FormLinerConfig extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void panelObjectDragEnter(DropTargetDragEvent e) {
|
private void panelObjectDragEnter(DropTargetDragEvent e) {
|
||||||
if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
|
if (e.isDataFlavorSupported(DataFlavor.stringFlavor) || e.isDataFlavorSupported(AdditionalElementsTransferable.additionalElementsFlavor)) {
|
||||||
e.acceptDrag(DnDConstants.ACTION_COPY);
|
e.acceptDrag(DnDConstants.ACTION_COPY);
|
||||||
} else {
|
} else {
|
||||||
e.rejectDrag();
|
e.rejectDrag();
|
||||||
@ -136,7 +133,7 @@ public class FormLinerConfig extends JFrame {
|
|||||||
liner = new DrawingLiner((int) numericUpDownSpeed.getValue(), ((Integer) numericUpDownWeight.getValue()).doubleValue(),
|
liner = new DrawingLiner((int) numericUpDownSpeed.getValue(), ((Integer) numericUpDownWeight.getValue()).doubleValue(),
|
||||||
Color.WHITE, Color.BLACK, LinerEntityType.values()[comboBoxLinerType.getSelectedIndex()],
|
Color.WHITE, Color.BLACK, LinerEntityType.values()[comboBoxLinerType.getSelectedIndex()],
|
||||||
(int) numericUpDownCapacity.getValue(), (int) numericUpDownMaxPassengers.getValue(),
|
(int) numericUpDownCapacity.getValue(), (int) numericUpDownMaxPassengers.getValue(),
|
||||||
checkBoxExtraDeck.isSelected(), checkBoxPool.isSelected(), (int) numericUpDownDeckNum.getValue(), "Triangular Deck");
|
checkBoxExtraDeck.isSelected(), checkBoxPool.isSelected(), (int) numericUpDownDeckNum.getValue(), "Square Deck");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
drawObject();
|
drawObject();
|
||||||
@ -147,6 +144,23 @@ public class FormLinerConfig extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void panelObjectDropAdditionalElements(DropTargetDropEvent e) {
|
||||||
|
try {
|
||||||
|
e.acceptDrop(DnDConstants.ACTION_COPY);
|
||||||
|
IAdditionalElements deck = (IAdditionalElements) e.getTransferable().getTransferData(AdditionalElementsTransferable.additionalElementsFlavor);
|
||||||
|
if (deck != null) {
|
||||||
|
liner.setDeck(deck, (int) numericUpDownDeckNum.getValue());
|
||||||
|
drawObject();
|
||||||
|
e.dropComplete(true);
|
||||||
|
} else {
|
||||||
|
e.dropComplete(false);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
e.dropComplete(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void panelMouseDown(JPanel panel) {
|
private void panelMouseDown(JPanel panel) {
|
||||||
Color color = panel.getBackground();
|
Color color = panel.getBackground();
|
||||||
Transferable transferable = new ColorTransferable(color);
|
Transferable transferable = new ColorTransferable(color);
|
||||||
@ -327,6 +341,47 @@ public class FormLinerConfig extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
JLabel labelSquareDeck = new JLabel("Square Deck");
|
||||||
|
labelSquareDeck.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
labelSquareDeck.setMaximumSize(new Dimension(200, 20));
|
||||||
|
labelSquareDeck.setBorder(new LineBorder(Color.BLACK));
|
||||||
|
labelSquareDeck.setTransferHandler(new AdditionalElementsTransferHandler(new SquareDeckDrawing()));
|
||||||
|
labelSquareDeck.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
labelObjectMouseDown(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JLabel labelCircularDeck = new JLabel("Circular Deck");
|
||||||
|
labelCircularDeck.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
labelCircularDeck.setMaximumSize(new Dimension(200, 20));
|
||||||
|
labelCircularDeck.setBorder(new LineBorder(Color.BLACK));
|
||||||
|
labelCircularDeck.setTransferHandler(new AdditionalElementsTransferHandler(new CircularDeckDrawing()));
|
||||||
|
labelCircularDeck.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
labelObjectMouseDown(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JLabel labelTriangularDeck = new JLabel("Triangular Deck");
|
||||||
|
labelTriangularDeck.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
labelTriangularDeck.setMaximumSize(new Dimension(200, 20));
|
||||||
|
labelTriangularDeck.setBorder(new LineBorder(Color.BLACK));
|
||||||
|
labelTriangularDeck.setTransferHandler(new AdditionalElementsTransferHandler(new TriangularDeckDrawing()));
|
||||||
|
labelTriangularDeck.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
labelObjectMouseDown(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JPanel additionalElements = new JPanel();
|
||||||
|
additionalElements.setLayout(new BoxLayout(additionalElements, BoxLayout.X_AXIS));
|
||||||
|
additionalElements.add(labelSquareDeck);
|
||||||
|
additionalElements.add(Box.createHorizontalStrut(10));
|
||||||
|
additionalElements.add(labelCircularDeck);
|
||||||
|
additionalElements.add(Box.createHorizontalStrut(10));
|
||||||
|
additionalElements.add(labelTriangularDeck);
|
||||||
|
|
||||||
JPanel objectEntities = new JPanel();
|
JPanel objectEntities = new JPanel();
|
||||||
objectEntities.setLayout(new BoxLayout(objectEntities, BoxLayout.X_AXIS));
|
objectEntities.setLayout(new BoxLayout(objectEntities, BoxLayout.X_AXIS));
|
||||||
objectEntities.add(labelBasicObject);
|
objectEntities.add(labelBasicObject);
|
||||||
@ -340,6 +395,8 @@ public class FormLinerConfig extends JFrame {
|
|||||||
middlePanel.add(panelColorsDown);
|
middlePanel.add(panelColorsDown);
|
||||||
middlePanel.add(Box.createVerticalStrut(10));
|
middlePanel.add(Box.createVerticalStrut(10));
|
||||||
middlePanel.add(objectEntities);
|
middlePanel.add(objectEntities);
|
||||||
|
middlePanel.add(Box.createVerticalStrut(10));
|
||||||
|
middlePanel.add(additionalElements);
|
||||||
|
|
||||||
add(middlePanel, BorderLayout.CENTER);
|
add(middlePanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
@ -397,7 +454,18 @@ public class FormLinerConfig extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drop(DropTargetDropEvent e) {
|
public void drop(DropTargetDropEvent e) {
|
||||||
panelObjectDragDrop(e);
|
try {
|
||||||
|
if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
|
||||||
|
panelObjectDragDrop(e);
|
||||||
|
} else if (e.isDataFlavorSupported(AdditionalElementsTransferable.additionalElementsFlavor)) {
|
||||||
|
panelObjectDropAdditionalElements(e);
|
||||||
|
} else {
|
||||||
|
e.rejectDrop();
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
e.dropComplete(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -429,9 +497,38 @@ public class FormLinerConfig extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
numericUpDownSpeed.addChangeListener(e -> updateLinerParameters());
|
||||||
|
numericUpDownWeight.addChangeListener(e -> updateLinerParameters());
|
||||||
|
numericUpDownCapacity.addChangeListener(e -> updateLinerParameters());
|
||||||
|
numericUpDownMaxPassengers.addChangeListener(e -> updateLinerParameters());
|
||||||
|
numericUpDownDeckNum.addChangeListener(e -> updateLinerParameters());
|
||||||
|
|
||||||
|
comboBoxLinerType.addItemListener(e -> updateLinerParameters());
|
||||||
|
|
||||||
|
checkBoxExtraDeck.addItemListener(e -> updateLinerParameters());
|
||||||
|
checkBoxPool.addItemListener(e -> updateLinerParameters());
|
||||||
|
|
||||||
add(panelObject, BorderLayout.EAST);
|
add(panelObject, BorderLayout.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateLinerParameters() {
|
||||||
|
if (liner != null) {
|
||||||
|
liner.baseLiner.setSpeed((int) numericUpDownSpeed.getValue());
|
||||||
|
liner.baseLiner.setWeight(((Integer) numericUpDownWeight.getValue()).doubleValue());
|
||||||
|
if (liner instanceof DrawingLiner drawingLiner) {
|
||||||
|
if (drawingLiner.getBaseLiner() instanceof LinerEntity linerEntity) {
|
||||||
|
linerEntity.setType(LinerEntityType.values()[comboBoxLinerType.getSelectedIndex()]);
|
||||||
|
linerEntity.setCapacity((int) numericUpDownCapacity.getValue());
|
||||||
|
linerEntity.setMaxPassengers((int) numericUpDownMaxPassengers.getValue());
|
||||||
|
linerEntity.setExtraDeck(checkBoxExtraDeck.isSelected());
|
||||||
|
linerEntity.setPool(checkBoxPool.isSelected());
|
||||||
|
}
|
||||||
|
drawingLiner.setDeckNum((int) numericUpDownDeckNum.getValue());
|
||||||
|
}
|
||||||
|
drawObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private JPanel createColorPanel(Color color) {
|
private JPanel createColorPanel(Color color) {
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setBackground(color);
|
panel.setBackground(color);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user