Skip to content

Commit

Permalink
MessagePanel
Browse files Browse the repository at this point in the history
  • Loading branch information
GalKarp committed Sep 7, 2014
1 parent da081ae commit f3ea786
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 19 deletions.
25 changes: 21 additions & 4 deletions Java-Missle/src/missile/DestructedLanucher.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public void run() {
for (WarEventListener l : allListeners) {
l.RemoveCurrentElement(target.getLauncherId());
}
for (WarEventListener l : allListeners) {
l.RemovedLauncherFromUI(target.getLauncherId());
}
// for (WarEventListener l : allListeners) {
// l.RemovedLauncherFromUI(target.getLauncherId());
// }

} catch (InterruptedException e) {
}
Expand All @@ -75,7 +75,7 @@ public void run() {
@Override
public void destroyTarget() throws Exception {
Object arr[] = {this, target};
double rate = 2; //Math.random(); // generate random success
double rate = 0 ;//Math.random(); // generate random success

if (target.isRunning()) {
if (!target.isHidden()) {
Expand All @@ -90,18 +90,35 @@ public void destroyTarget() throws Exception {
logger.log(Level.INFO, print_log, arr);
}
else {
for (WarEventListener l : allListeners) {
l.AddMessageToGui("Destruction of launcher "
+ target.getLauncherId()
+ " was failed");
}
throw new Exception("Destruction of launcher "
+ target.getLauncherId()
+ " was failed");

}
}
else {

for (WarEventListener l : allListeners) {
l.AddMessageToGui("Destruction of launcher "
+ target.getLauncherId()
+ " was failed - Launcher is hidden!");
}
throw new Exception("Destruction of launcher "
+ target.getLauncherId()
+ " was failed - Launcher is hidden!");
}
}
else {
for (WarEventListener l : allListeners) {
l.AddMessageToGui("Destruction of launcher "
+ target.getLauncherId()
+ " was failed - Launcher is not running!");
}
throw new Exception("Destruction of launcher "
+ target.getLauncherId()
+ " was failed - Launcher is not running!");
Expand Down
19 changes: 16 additions & 3 deletions Java-Missle/src/missile/DestructedMissile.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public void run() {
for (WarEventListener l : allListeners) {
l.RemoveCurrentElement(target.getMissileId());
}
for (WarEventListener l : allListeners) {
l.DestroyMissileProgressBar(target.getMissileId() , "missile");
}
// for (WarEventListener l : allListeners) {
// l.DestroyMissileProgressBar(target.getMissileId() , "missile");
// }



Expand Down Expand Up @@ -81,15 +81,28 @@ public void destroyTarget() throws Exception {
synchronized (target) {
target.interrupt();
}
for (WarEventListener l : allListeners) {
l.DestroyMissileProgressBar(target.getMissileId() , "missile");
}
String print_log = "Missle " + target.getMissileId()
+ " was destroyed";
logger.log(Level.INFO, print_log, arr);
} else {
for (WarEventListener l : allListeners) {
l.AddMessageToGui("Destruction of missile "
+ target.getMissileId()
+ " was failed");
}
throw new Exception("Destruction of missile "
+ target.getMissileId()
+ " was failed");
}
} else {
for (WarEventListener l : allListeners) {
l.AddMessageToGui("Destruction of missile "
+ target.getMissileId()
+ " was failed - Missile is not running");
}
throw new Exception("Destruction of missile "
+ target.getMissileId()
+ " was failed - Missile is not running");
Expand Down
5 changes: 5 additions & 0 deletions Java-Missle/src/view/ControlPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public void addNewLauncherPopUpFrame() {
new LauncherPopUpFrame(allListeners);
}

public void addMessageToGui(String string) {
JOptionPane.showMessageDialog(null, string);

}




Expand Down
1 change: 1 addition & 0 deletions Java-Missle/src/view/LaunchersPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void addLauncherToPanel(final String id) {
LaunchersPanel.class.getResource(LAUNCHER_IMAGE_PATH)));
launcher.setVerticalTextPosition(SwingConstants.BOTTOM);
launcher.setHorizontalTextPosition(SwingConstants.CENTER);
launcher.setPreferredSize(new Dimension(100, 100));
panel.add(launcher);
launchersQueue.add(launcher);
repaint();
Expand Down
83 changes: 83 additions & 0 deletions Java-Missle/src/view/MessagePanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import war.controller.WarUIEventsListener;

import javax.swing.JTextPane;
import javax.swing.JLabel;

public class MessagePanel extends JPanel {

private JLabel label;
private List<WarUIEventsListener> allListeners;
private boolean fireMissileButtonPressed;
private boolean destroyLauncherButtonPressed;
private WarGui warGui;
private JPanel panel;

public MessagePanel(List<WarUIEventsListener> allListeners, WarGui warGui) {
// this.warGui = warGui;
// setPreferredSize(new Dimension(307, 100));
// setBorder(new LineBorder(new Color(0, 0, 0)));
// this.allListeners = allListeners;
// this.fireMissileButtonPressed = false;
// this.destroyLauncherButtonPressed = false;
// setLayout(new FlowLayout());
setLayout(new BorderLayout(0, 0));


panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setPreferredSize(new Dimension(305, 100));
scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
}
});
add(scrollPane, BorderLayout.CENTER);
}

public boolean isFireMissileButtonPressed() {
return fireMissileButtonPressed;
}

public void setFireMissileButtonPressed(boolean fireMissileButtonPressed) {
this.fireMissileButtonPressed = fireMissileButtonPressed;
}

public void addMessageToPanel(String id) {
label = new JLabel();
label.setText(id);
label.setToolTipText(id);
label.setBorder(new LineBorder(new Color(0, 0, 0)));
label.setVerticalTextPosition(SwingConstants.BOTTOM);
label.setHorizontalTextPosition(SwingConstants.CENTER);
label.setPreferredSize(new Dimension(300, 30));
panel.add(label);
repaint();
validate();


}

}
31 changes: 19 additions & 12 deletions Java-Missle/src/view/WarGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class WarGui extends JFrame implements AbstractWarView {
private ProgressPanel progressPanel;
private DestroyersPanel destroyersPanel;
private OrefPanel orefPanel;
private MessagePanel MessagePanel;

public WarGui() {
allListeners = new LinkedList<WarUIEventsListener>();
Expand All @@ -39,10 +40,15 @@ public WarGui() {
launchersPanel = new LaunchersPanel(allListeners,this);
progressPanel = new ProgressPanel(allListeners, this);
destroyersPanel = new DestroyersPanel(allListeners);
MessagePanel = new MessagePanel(allListeners, this);
orefPanel = new OrefPanel();
setBackground(Color.DARK_GRAY);

SpringLayout springLayout = new SpringLayout();
springLayout.putConstraint(SpringLayout.NORTH, ironDomesPanel, 6, SpringLayout.SOUTH, launchersPanel);
springLayout.putConstraint(SpringLayout.SOUTH, ironDomesPanel, -6, SpringLayout.NORTH, destroyersPanel);
springLayout.putConstraint(SpringLayout.NORTH, launchersPanel, 124,
SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, progressPanel, 56, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.SOUTH, progressPanel, -10, SpringLayout.SOUTH, getContentPane());

Expand Down Expand Up @@ -87,12 +93,6 @@ public WarGui() {
SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.SOUTH, destroyersPanel, -10,
SpringLayout.SOUTH, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, ironDomesPanel, 6,
SpringLayout.SOUTH, launchersPanel);
springLayout.putConstraint(SpringLayout.SOUTH, ironDomesPanel, -6,
SpringLayout.NORTH, destroyersPanel);
springLayout.putConstraint(SpringLayout.NORTH, launchersPanel, 10,
SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.SOUTH, launchersPanel, -410,
SpringLayout.SOUTH, getContentPane());

Expand All @@ -110,13 +110,12 @@ public WarGui() {

// Jlabel for the progressbar
JLabel lblEnemyMissileInterception = new JLabel();
springLayout.putConstraint(SpringLayout.WEST, lblEnemyMissileInterception, 324, SpringLayout.WEST, getContentPane());
springLayout.putConstraint(SpringLayout.SOUTH,
lblEnemyMissileInterception, 0, SpringLayout.NORTH,
progressPanel);
springLayout.putConstraint(SpringLayout.EAST, lblEnemyMissileInterception, -6, SpringLayout.WEST, orefPanel);
lblEnemyMissileInterception.setIcon(new ImageIcon(WarGui.class.getResource(PROGRESS_LABLE_IMAGE_PATH)));
springLayout.putConstraint(SpringLayout.EAST,
lblEnemyMissileInterception, 0, SpringLayout.EAST,
progressPanel);
springLayout.putConstraint(SpringLayout.NORTH,
lblEnemyMissileInterception, 10, SpringLayout.NORTH,
getContentPane());
Expand All @@ -125,11 +124,13 @@ public WarGui() {
.setHorizontalAlignment(SwingConstants.CENTER);
lblEnemyMissileInterception.setBackground(Color.WHITE);
lblEnemyMissileInterception.setForeground(Color.BLACK);
springLayout.putConstraint(SpringLayout.WEST,
lblEnemyMissileInterception, 6, SpringLayout.EAST,
launchersPanel);

getContentPane().add(lblEnemyMissileInterception);


springLayout.putConstraint(SpringLayout.WEST, MessagePanel, 0, SpringLayout.WEST, ironDomesPanel);
springLayout.putConstraint(SpringLayout.SOUTH, MessagePanel, -6, SpringLayout.NORTH, launchersPanel);
getContentPane().add(MessagePanel);
setSize(1180, 693);
setResizable(false);
setVisible(true);
Expand Down Expand Up @@ -234,4 +235,10 @@ public void RemoveCurrentElement(String destructorId) {

}

@Override
public void addMessageToGui(String string) {
MessagePanel.addMessageToPanel(string);

}

}
2 changes: 2 additions & 0 deletions Java-Missle/src/war/controller/AbstractWarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ void updateMissileProgress(int time, String missileId, String type,

void RemoveCurrentElement(String destructorId);

void addMessageToGui(String string);

}
8 changes: 8 additions & 0 deletions Java-Missle/src/war/controller/WarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ public void RemoveCurrentElement(String destructorId) {



@Override
public void AddMessageToGui(String string) {
warView.addMessageToGui(string);

}






Expand Down
2 changes: 2 additions & 0 deletions Java-Missle/src/war/controller/WarEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ void addedMissileToDestroy(String ironDome, String missileId,

void RemoveCurrentElement(String destructorId);

void AddMessageToGui(String string);

}

0 comments on commit f3ea786

Please sign in to comment.