Skip to content

Commit

Permalink
Add dynamic lane count
Browse files Browse the repository at this point in the history
  • Loading branch information
felixb1515 committed Aug 26, 2024
1 parent 871e883 commit 2be50ac
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/main/java/de/usd/cstchef/view/RecipePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,33 @@ public void actionPerformed(ActionEvent arg0) {
// create active operations (middle) panel
LayoutPanel activeOperationsPanel = new LayoutPanel("Recipe");

// button to add lanes
JButton addLaneButton = new JButton("Plus");
activeOperationsPanel.addActionComponent(addLaneButton);
addLaneButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(operationSteps < 100) {
increaseLaneNumber(1);
}
}

});

// button to remove lanes
JButton removeLaneButton = new JButton("Minus");
activeOperationsPanel.addActionComponent(removeLaneButton);
removeLaneButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(operationSteps > 1) {
decreaseLaneNumber(1);
}
}

});

inactiveWarning = new JLabel(this.operation.toString() + " Operations currently inactive!");
inactiveWarning.setForeground(Color.RED);
Expand Down Expand Up @@ -328,6 +355,37 @@ public void actionPerformed(ActionEvent arg0) {
startAutoBakeTimer();
}

private void increaseLaneNumber(int number) {
this.operationSteps += number;

GridBagConstraints co = new GridBagConstraints();
co.gridheight = GridBagConstraints.REMAINDER;
co.weighty = 1;
co.fill = GridBagConstraints.VERTICAL;

for(int i = 0; i < number; i++) {
RecipeStepPanel opPanel = new RecipeStepPanel("Lane " + String.valueOf(operationSteps - (number - i) + 1), this);
operationLines.add(opPanel, co, operationSteps - (number - i));
operationLines.revalidate();
operationLines.repaint();

JPanel panel = opPanel.getOperationsPanel();
MoveOperationMouseAdapter moma = new MoveOperationMouseAdapter(opPanel, operationLines);
panel.addMouseListener(moma);
panel.addMouseMotionListener(moma);
}
}

private void decreaseLaneNumber(int number) {
int index = this.operationSteps;
this.operationSteps -= number;
for(int i = 0; i < number; i++) {
operationLines.remove(index - 1 - i);
operationLines.revalidate();
operationLines.repaint();
}
}

public void hideInactiveWarning(){
this.inactiveWarning.setVisible(false);
}
Expand Down Expand Up @@ -393,6 +451,10 @@ public void restoreState(String jsonState) throws IOException, ClassNotFoundExce
throw new IOException("wrong data format");
}

if(stepNodes.size() > operationSteps) {
increaseLaneNumber(stepNodes.size() - operationSteps);
}

for (int step = 0; step < stepNodes.size(); step++) {
JsonNode operationNodes = stepNodes.get(step);
if (!operationNodes.isArray()) {
Expand Down Expand Up @@ -687,6 +749,13 @@ private void saveFilterState() {
}

private void clear() {
if(this.operationSteps < 10) {
increaseLaneNumber(10 - this.operationSteps);
}
else if(this.operationSteps > 10) {
decreaseLaneNumber(this.operationSteps - 10);
}

for (int step = 0; step < this.operationSteps; step++) {
RecipeStepPanel stepPanel = (RecipeStepPanel) this.operationLines.getComponent(step);
int laneIndex = step + 1;
Expand Down

0 comments on commit 2be50ac

Please sign in to comment.