From 9f5a44a3549dc7853efb2083ce42eed0bc5c5cee Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Tue, 12 Apr 2011 22:35:05 +0000 Subject: [PATCH] =?UTF-8?q?A=20=20=20=20Winda/src/winda/animation=20A=20?= =?UTF-8?q?=20=20=20Winda/src/winda/animation/ElevatorAnimation.java=09Ele?= =?UTF-8?q?menty=20Animacji=20A=20=20=20=20Winda/src/winda/animation/Eleva?= =?UTF-8?q?torMovement.java=09Silnik=20Obs=C5=82uguj=C4=85cy=20Dane=20anim?= =?UTF-8?q?acji=20M=20=20=20=20Winda/src/winda/gui/WindaView.form=20M=20?= =?UTF-8?q?=20=20=20Winda/src/winda/gui/WindaView.java=09=09=09Pod=C5=82?= =?UTF-8?q?=C4=85czona=20animacja=20M=20=20=20=20Winda/src/winda/logic/Alg?= =?UTF-8?q?orytmGoraDol.java=09=09Co=C5=9Btam=20bo=20nie=20chcia=C5=82o=20?= =?UTF-8?q?si=C4=99=20kompilowa=C4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../winda/animation/ElevatorAnimation.java | 124 ++++++++++++++++++ .../src/winda/animation/ElevatorMovement.java | 107 +++++++++++++++ Winda/src/winda/gui/WindaView.form | 29 ++-- Winda/src/winda/gui/WindaView.java | 41 ++++-- Winda/src/winda/logic/AlgorytmGoraDol.java | 5 + 5 files changed, 283 insertions(+), 23 deletions(-) create mode 100644 Winda/src/winda/animation/ElevatorAnimation.java create mode 100644 Winda/src/winda/animation/ElevatorMovement.java diff --git a/Winda/src/winda/animation/ElevatorAnimation.java b/Winda/src/winda/animation/ElevatorAnimation.java new file mode 100644 index 0000000..d5983f7 --- /dev/null +++ b/Winda/src/winda/animation/ElevatorAnimation.java @@ -0,0 +1,124 @@ +package winda.animation; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import javax.swing.JApplet; + +/** + * + * @author Przemo + */ +public class ElevatorAnimation extends JApplet { + + private int x_dimension = 200; + private int y_dmension; + private int floor_count; + + private final int floor_size = 50; + private final int elevator_size_x = 40; + private final int elevator_size_y = 50; + + private Font elevator_font; + private Font floor_font; + + public int shift; + public int elevator_passangers; + public int[] floor_passangers; + + public ElevatorAnimation(int floor_count){ + this.floor_count = floor_count; + this.y_dmension = floor_size*this.floor_count; + this.elevator_font = new Font("Serif", Font.PLAIN, 30); + this.floor_font = new Font("Serif", Font.PLAIN, 16); + this.floor_passangers = new int[floor_count]; + } + + @Override + public Dimension getPreferredSize(){ + return new Dimension(this.x_dimension, this.y_dmension); + } + + @Override + public void paint(Graphics g){ + Graphics2D g2 = (Graphics2D) g; + + g2.drawImage(this.buffImage(), null, 0, 0); + } + + /* + * Buforowana klatka + */ + private BufferedImage buffImage(){ + BufferedImage buffi = new BufferedImage(this.x_dimension, this.y_dmension, BufferedImage.TYPE_BYTE_GRAY); + Graphics2D buffig = (Graphics2D) buffi.getGraphics(); + Rectangle r = new Rectangle(0,0,this.x_dimension,this.y_dmension); + + buffig.setBackground(Color.WHITE); + buffig.setColor(Color.BLACK); + buffig.clearRect(0, 0, this.x_dimension, this.y_dmension); + + this.drawElevatorShaft(buffig); + this.drawFloors(buffig); + this.drawPassangers(buffig); + this.drawElevator(buffig); + + return buffi; + } + + /* + * Rysowanie szybu windy + */ + private void drawElevatorShaft(Graphics2D g2){ + Line2D left = new Line2D.Double(45, 0, 45, this.y_dmension); + Line2D right = new Line2D.Double(95, 0, 95, this.y_dmension); + g2.draw(left); + g2.draw(right); + } + + /* + * Rysowanie Pięter z numerami + */ + private void drawFloors(Graphics2D g2){ + g2.setFont(this.floor_font); + for(int i=1;i<=this.floor_count;i++){ + int tmp = this.floor_count-i; + g2.draw(new Line2D.Double(0, this.floor_size*i, this.x_dimension, this.floor_size*i)); + g2.drawString(""+tmp, 100, (this.floor_size*i)-5); + } + } + + /* + * Rysowanie ilosci pasażerów na piętrach + */ + private void drawPassangers(Graphics2D g2){ + g2.setFont(elevator_font); + for(int i=1;i<=this.floor_count;i++){ + g2.drawString(""+this.floor_passangers[this.floor_count-i], 120 ,(this.floor_size*i)-15); + } + } + + /* + * Rysowanie windy + */ + private void drawElevator(Graphics2D g2){ + Rectangle2D winda = new Rectangle2D.Double(50, 00, this.elevator_size_x, this.elevator_size_y); + + g2.translate(0, this.shift); + g2.clearRect(50, 00, this.elevator_size_x, this.elevator_size_y); + g2.draw(winda); + + g2.setFont(this.elevator_font); + if(this.elevator_passangers < 10) + g2.drawString("0"+this.elevator_passangers, 55, 35); + else + g2.drawString(""+this.elevator_passangers, 55, 35); + } + +} diff --git a/Winda/src/winda/animation/ElevatorMovement.java b/Winda/src/winda/animation/ElevatorMovement.java new file mode 100644 index 0000000..b64d706 --- /dev/null +++ b/Winda/src/winda/animation/ElevatorMovement.java @@ -0,0 +1,107 @@ +package winda.animation; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Przemo + */ +public class ElevatorMovement { +// private final int FPS = 50; /* Frames Per Second */ +// private final int THREAD_WAIT_TIME = 1000/this.FPS; + + private ElevatorAnimation ea; + + private int floor_count; + private final int floor_size = 50; + private int time_for_floor; // Tymczasowo /* Miliseconds */ + private int actual_floor; + private double jump_time; + + public ElevatorMovement(int floor_count){ + this.floor_count = floor_count; + this.init(); + } + + public void goToFloor(int number){ + if(this.actual_floornumber) + this.goDown(number); + this.actual_floor = number; + } + + private void goUp(int number){ + while(this.ea.shift>(this.floor_size*(this.floor_count-(number+1)))){ + try { + this.ea.shift--; + this.ea.repaint(); + Thread.sleep((long) jump_time); + } catch (InterruptedException ex) { + Logger.getLogger(ElevatorMovement.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + private void goDown(int number) { + while(this.ea.shift<(this.floor_size*(this.floor_count-(number+1)))){ + try { + this.ea.shift++; + this.ea.repaint(); + Thread.sleep((long) jump_time); + } catch (InterruptedException ex) { + Logger.getLogger(ElevatorMovement.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + public ElevatorAnimation getElevatorAnimation(){ + return this.ea; + } + + public void setPassangersOnFloor(int floor, int number){ + this.ea.floor_passangers[floor]=number; + } + + public void setPassangersOnFloors(int []passangers){ + if(passangers.length == this.ea.floor_passangers.length) + this.ea.floor_passangers = passangers; + else + for(int i=0;i - + - + - + - + @@ -88,8 +88,9 @@ - - + + + @@ -108,13 +109,6 @@ - - - - - - - @@ -701,6 +695,13 @@ + + + + + + + @@ -818,6 +819,6 @@ - + diff --git a/Winda/src/winda/gui/WindaView.java b/Winda/src/winda/gui/WindaView.java index ce913da..1c990c8 100644 --- a/Winda/src/winda/gui/WindaView.java +++ b/Winda/src/winda/gui/WindaView.java @@ -17,12 +17,16 @@ import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; +import winda.animation.ElevatorAnimation; +import winda.animation.ElevatorMovement; import winda.logic.Winda; /** * The application's main frame. */ public class WindaView extends FrameView { + private ElevatorMovement em; + private ElevatorAnimation ea; Winda w = new Winda(); public WindaView(SingleFrameApplication app) { super(app); @@ -82,6 +86,24 @@ public class WindaView extends FrameView { } } }); + this.drawAnimation(); + } + + private void drawAnimation(){ + this.em = new ElevatorMovement(12); + this.ea = this.em.getElevatorAnimation(); + this.scrollPane1.add(ea); + } + + /** + * Not working yet :/ + * @param floor_count + */ + private void newAnimation(int floor_count){ + this.scrollPane1.remove(this.ea); + this.em.setFloorsCount(floor_count); + this.ea = this.em.getElevatorAnimation(); + this.scrollPane1.add(this.ea); } @Action @@ -104,7 +126,6 @@ public class WindaView extends FrameView { private void initComponents() { mainPanel = new javax.swing.JPanel(); - jScrollPane1 = new javax.swing.JScrollPane(); jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); @@ -148,6 +169,7 @@ public class WindaView extends FrameView { jLabel12 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jLabel13 = new javax.swing.JLabel(); + scrollPane1 = new java.awt.ScrollPane(); menuBar = new javax.swing.JMenuBar(); javax.swing.JMenu fileMenu = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); @@ -161,8 +183,6 @@ public class WindaView extends FrameView { mainPanel.setName("mainPanel"); // NOI18N - jScrollPane1.setName("jScrollPane1"); // NOI18N - org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(winda.gui.WindaApp.class).getContext().getResourceMap(WindaView.class); jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N jLabel1.setName("jLabel1"); // NOI18N @@ -546,6 +566,8 @@ public class WindaView extends FrameView { .addContainerGap(210, Short.MAX_VALUE)) ); + scrollPane1.setName("scrollPane1"); // NOI18N + javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( @@ -564,17 +586,17 @@ public class WindaView extends FrameView { .addComponent(jButton2))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(mainPanelLayout.createSequentialGroup() .addGap(10, 10, 10) .addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton4) .addGap(28, 28, 28) - .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)) + .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)) .addGroup(mainPanelLayout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(scrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 551, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(18, 18, 18) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -614,8 +636,9 @@ public class WindaView extends FrameView { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 433, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) + .addGap(10, 10, 10) + .addComponent(scrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 431, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton3) @@ -784,7 +807,6 @@ public class WindaView extends FrameView { private javax.swing.JPanel jPanel5; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; - private javax.swing.JScrollPane jScrollPane1; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; private javax.swing.JSeparator jSeparator3; @@ -803,6 +825,7 @@ public class WindaView extends FrameView { private javax.swing.JTextField jTextField1; private javax.swing.JPanel mainPanel; private javax.swing.JMenuBar menuBar; + private java.awt.ScrollPane scrollPane1; // End of variables declaration//GEN-END:variables private final Timer messageTimer; diff --git a/Winda/src/winda/logic/AlgorytmGoraDol.java b/Winda/src/winda/logic/AlgorytmGoraDol.java index 60ad7c4..5ea965a 100644 --- a/Winda/src/winda/logic/AlgorytmGoraDol.java +++ b/Winda/src/winda/logic/AlgorytmGoraDol.java @@ -6,6 +6,7 @@ package winda.logic; import java.util.ArrayList; +import java.util.List; import sun.misc.Sort; /** @@ -87,4 +88,8 @@ public class AlgorytmGoraDol implements IAlgorytm { public void SetMaxPietro(int maxPietro) { this.setFloorCount(maxPietro); } + + public List Trasa(List pasazerowie) { + throw new UnsupportedOperationException("Not supported yet."); + } }