diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 245cfd2..24ef177 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/ArmoredVehicle/src/DrawingArmoredVehicle.java b/ArmoredVehicle/src/DrawingArmoredVehicle.java index 2450510..c0ec905 100644 --- a/ArmoredVehicle/src/DrawingArmoredVehicle.java +++ b/ArmoredVehicle/src/DrawingArmoredVehicle.java @@ -23,11 +23,11 @@ public class DrawingArmoredVehicle{ /// /// Ширина окна отрисовки /// - protected int _pictureWidth = 0; + protected int _pictureWidth = 100; /// /// Высота окна отрисовки /// - protected int _pictureHeight = 0; + protected int _pictureHeight = 100; /// /// Ширина отрисовки /// @@ -50,7 +50,7 @@ public class DrawingArmoredVehicle{ { Random r = new Random(); ArmoredVehicle = new ArmoredVehicleEntity(speed, weight, bodyColor); - int variant = r.nextInt(3); + int variant = 0; switch(variant) { case 0: @@ -78,9 +78,9 @@ public class DrawingArmoredVehicle{ public DrawingArmoredVehicle(ArmoredVehicleEntity machine, IDrawingRoller rollers) { ArmoredVehicle = machine; - roller = rollers; - + roller = rollers; } + /// /// Установка позиции /// diff --git a/ArmoredVehicle/src/FormArmoredVehicleConfig.form b/ArmoredVehicle/src/FormArmoredVehicleConfig.form index 7511c4b..8bbadec 100644 --- a/ArmoredVehicle/src/FormArmoredVehicleConfig.form +++ b/ArmoredVehicle/src/FormArmoredVehicleConfig.form @@ -60,7 +60,7 @@ - + @@ -78,7 +78,9 @@ - + + + @@ -119,13 +121,6 @@ - - - - - - - @@ -157,33 +152,29 @@ - - + - + + + + - - - - + + + + - - - - - - - + @@ -521,21 +512,19 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -544,17 +533,13 @@ - - - - - - - - - - + + + + + + @@ -590,7 +575,7 @@ - + @@ -601,6 +586,9 @@ + + + diff --git a/ArmoredVehicle/src/FormArmoredVehicleConfig.java b/ArmoredVehicle/src/FormArmoredVehicleConfig.java index 9fa8fef..abf16aa 100644 --- a/ArmoredVehicle/src/FormArmoredVehicleConfig.java +++ b/ArmoredVehicle/src/FormArmoredVehicleConfig.java @@ -1,8 +1,12 @@ import java.awt.Color; import java.awt.Cursor; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; import java.util.function.Consumer; import javax.swing.JComponent; import javax.swing.JLabel; @@ -21,6 +25,7 @@ public class FormArmoredVehicleConfig extends javax.swing.JFrame { DrawingArmoredVehicle _machine; Consumer EventAddMachine; public boolean DialogResult = false; + Image img; /** * Creates new form FormArmoredVehicleConfig */ @@ -47,7 +52,6 @@ public class FormArmoredVehicleConfig extends javax.swing.JFrame { panelDraw.addMouseListener(defCursor); LabelColor.addMouseListener(defCursor); LabelDopColor.addMouseListener(defCursor); - //labelSetRoller.addMouseListener(defCursor); PanelRed.addMouseListener(drag); PanelBlack.addMouseListener(drag); @@ -62,6 +66,7 @@ public class FormArmoredVehicleConfig extends javax.swing.JFrame { LabelModify.addMouseListener(drag); LabelFirstRoller.addMouseListener(drag); LabelSecondRoller.addMouseListener(drag); + LabelSimpleRollers.addMouseListener(drag); buttonAdd.addActionListener(e -> { EventAddMachine.accept(_machine); @@ -315,7 +320,9 @@ public void AddEvent(Consumer ev) { EventAddMachine = ev; .addGroup(panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelParamsLayout.createSequentialGroup() .addComponent(checkboxGun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(148, 148, 148) + .addGap(54, 54, 54) + .addComponent(LabelSimple, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(27, 27, 27) .addComponent(LabelModify, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(panelParamsLayout.createSequentialGroup() .addGroup(panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -344,11 +351,6 @@ public void AddEvent(Consumer ev) { EventAddMachine = ev; .addGap(18, 18, 18) .addComponent(LabelSimpleRollers))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelParamsLayout.createSequentialGroup() - .addGap(227, 227, 227) - .addComponent(LabelSimple, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(159, Short.MAX_VALUE))) ); panelParamsLayout.setVerticalGroup( panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -373,27 +375,23 @@ public void AddEvent(Consumer ev) { EventAddMachine = ev; .addContainerGap() .addComponent(panelColors, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(LabelFirstRoller) + .addGroup(panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(LabelSecondRoller) - .addComponent(LabelSimpleRollers)) + .addGroup(panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(LabelFirstRoller) + .addComponent(LabelSimpleRollers))) .addGap(12, 12, 12) .addGroup(panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelParamsLayout.createSequentialGroup() - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(checkboxTower, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(checkboxGun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(59, 59, 59)) + .addComponent(checkboxGun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(panelParamsLayout.createSequentialGroup() .addGap(20, 20, 20) - .addComponent(LabelModify, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addGroup(panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelParamsLayout.createSequentialGroup() - .addContainerGap(216, Short.MAX_VALUE) - .addComponent(LabelSimple, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(68, 68, 68))) + .addGroup(panelParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(LabelModify, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(LabelSimple, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(15, Short.MAX_VALUE)) ); LabelDopColor.setText("Доп. цвет"); @@ -410,43 +408,43 @@ public void AddEvent(Consumer ev) { EventAddMachine = ev; ); panelDrawLayout.setVerticalGroup( panelDrawLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 177, Short.MAX_VALUE) + .addGap(0, 160, Short.MAX_VALUE) ); javax.swing.GroupLayout panelObjectLayout = new javax.swing.GroupLayout(panelObject); panelObject.setLayout(panelObjectLayout); panelObjectLayout.setHorizontalGroup( panelObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelObjectLayout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(LabelDopColor, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(60, 60, 60)) .addGroup(panelObjectLayout.createSequentialGroup() - .addGap(20, 20, 20) - .addComponent(panelDraw, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addContainerGap()) - .addGroup(panelObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelObjectLayout.createSequentialGroup() - .addGap(42, 42, 42) - .addComponent(LabelColor, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(157, Short.MAX_VALUE))) + .addGap(32, 32, 32) + .addGroup(panelObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelObjectLayout.createSequentialGroup() + .addComponent(panelDraw, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelObjectLayout.createSequentialGroup() + .addComponent(LabelColor, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(LabelDopColor, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(41, 41, 41)))) ); panelObjectLayout.setVerticalGroup( panelObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelObjectLayout.createSequentialGroup() .addGap(15, 15, 15) - .addComponent(LabelDopColor, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelDraw, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(panelObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(LabelColor, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE) + .addComponent(LabelDopColor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE) + .addComponent(panelDraw, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) - .addGroup(panelObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelObjectLayout.createSequentialGroup() - .addGap(16, 16, 16) - .addComponent(LabelColor, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(196, Short.MAX_VALUE))) ); buttonAdd.setLabel("Добавить"); + buttonAdd.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + buttonAddMouseClicked(evt); + } + }); buttonCancel.setLabel("Отмена"); @@ -480,13 +478,18 @@ public void AddEvent(Consumer ev) { EventAddMachine = ev; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(buttonAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addComponent(panelParams, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(panelParams, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// //GEN-END:initComponents + private void buttonAddMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonAddMouseClicked + DialogResult = true; + dispose(); + }//GEN-LAST:event_buttonAddMouseClicked + public void Drop(JComponent droppedItem) { if (droppedItem == null) { @@ -494,54 +497,73 @@ public void AddEvent(Consumer ev) { EventAddMachine = ev; } Color color = Color.WHITE; Color dopColor = Color.BLACK; + int rollers = Integer.parseInt((String) ComboBoxCountRollers.getSelectedItem()); if (droppedItem instanceof JPanel panel) { if (_machine == null) return; - if (LabelColor.getMousePosition() != null) { - //_machine.SetColor(panel.getBackground()); + boolean p = LabelColor.getMousePosition() != null; + if (p) { color = panel.getBackground(); + if(_machine instanceof DrawingTank tank) + { + var obj = (TankEntity)_machine.ArmoredVehicle; + _machine = new DrawingTank(obj.Speed, obj.Weight, + color, obj.DopColor, obj.MachineGun, obj.Tower); + } + else _machine = new DrawingArmoredVehicle(_machine.ArmoredVehicle.Speed, _machine.ArmoredVehicle.Weight, color); } if (LabelDopColor.getMousePosition() != null && _machine instanceof DrawingTank tank) { - //tank.SetDopColor(panel.getBackground()); dopColor = panel.getBackground(); + var obj = (TankEntity)_machine.ArmoredVehicle; + _machine = new DrawingTank(obj.Speed, obj.Weight, + obj.BodyColor, dopColor, obj.MachineGun, obj.Tower); + } + } + if (droppedItem instanceof JLabel label && panelDraw.getMousePosition() != null) { int speed = (int)SpinnerSpeed.getValue(); int weight = (int)SpinnerWeight.getValue(); - int rollers = Integer.parseInt((String) ComboBoxCountRollers.getSelectedItem()); + boolean tower = checkboxTower.getState(); boolean gun = checkboxGun.getState(); - + Graphics g = panelDraw.getGraphics(); if (label == LabelSimple) { - //try { pictureBox.remove(_machine); } catch (Exception ex) { } _machine = new DrawingArmoredVehicle(speed, weight, color); } else if (label == LabelModify) { - //try { pictureBox.remove(_machine); } catch (Exception ex) { } - _machine = new DrawingTank(speed, weight, color, dopColor, tower, gun); + _machine = new DrawingTank(speed, weight, color, dopColor, gun, tower); } + _machine.Count = rollers; - if (_machine!=null) { - _machine.SetPosition(panelDraw.getWidth() - 200, panelDraw.getHeight() - 150, panelDraw.getWidth(), panelDraw.getHeight()); - // pictureBox.add(_machine, BorderLayout.CENTER); - revalidate(); - } - - } else if (droppedItem instanceof JLabel label /*&& labelSetRoller.getMousePosition() != null*/ && _machine!=null) { + } + if (droppedItem instanceof JLabel label && _machine!=null) { if (label == LabelSimpleRollers) { - _machine = new DrawingArmoredVehicle(_machine.ArmoredVehicle, new Roller(color)); - //_machine.SetRollers((int)rollerSpinner.getValue(), new Roller(color)); + _machine = new DrawingArmoredVehicle(_machine.ArmoredVehicle, new Roller(_machine.ArmoredVehicle.BodyColor)); } else if (label == LabelFirstRoller) { - //_machine.SetRollers((int)rollerSpinner.getValue(), new DrawingFirstRoller(color)); - _machine = new DrawingArmoredVehicle(_machine.ArmoredVehicle, new DrawingFirstRoller(color)); + _machine = new DrawingArmoredVehicle(_machine.ArmoredVehicle, new DrawingFirstRoller(_machine.ArmoredVehicle.BodyColor)); } else if (label == LabelSecondRoller) { - //_machine.SetRollers((int)rollerSpinner.getValue(), new DrawingSecondRoller(color)); - _machine = new DrawingArmoredVehicle(_machine.ArmoredVehicle, new DrawingSecondRoller(color)); + _machine = new DrawingArmoredVehicle(_machine.ArmoredVehicle, new DrawingSecondRoller(_machine.ArmoredVehicle.BodyColor)); } } + + if (_machine!=null) { + _machine.Count = rollers; + _machine.SetPosition(panelDraw.getWidth() - 200, panelDraw.getHeight() - 150, panelDraw.getWidth(), panelDraw.getHeight()); + // pictureBox.add(_machine, BorderLayout.CENTER); + Graphics g = panelDraw.getGraphics(); + g.drawImage(Pic(), 0, 0, this); + } } - + Image Pic() + { + BufferedImage img = new BufferedImage(panelDraw.getWidth(), panelDraw.getHeight(), BufferedImage.TYPE_INT_BGR); + Graphics2D gr = img.createGraphics(); + gr.setBackground(Color.yellow); + _machine.DrawTransport(gr); + return img; + } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox ComboBoxCountRollers; private javax.swing.JLabel LabelColor; diff --git a/ArmoredVehicle/src/FormMachineConfig.java b/ArmoredVehicle/src/FormMachineConfig.java index 5c9a04b..78d3e76 100644 --- a/ArmoredVehicle/src/FormMachineConfig.java +++ b/ArmoredVehicle/src/FormMachineConfig.java @@ -143,10 +143,10 @@ public class FormMachineConfig extends JFrame { int rollers = (int)rollerSpinner.getValue(); boolean tower = checkBoxTower.isSelected(); boolean gun = checkBoxGun.isSelected(); - if (label == labelSimpleObject) { //try { pictureBox.remove(_machine); } catch (Exception ex) { } _machine = new DrawingArmoredVehicle(speed, weight, color); + } else if (label == labelModifiedObject) { //try { pictureBox.remove(_machine); } catch (Exception ex) { } _machine = new DrawingTank(speed, weight, color, dopColor, tower, gun);