Ejemplo n.º 1
0
  /**
   * Implements CallListener.incomingCallReceived. When a call is received creates a call panel and
   * adds it to the main tabbed pane and plays the ring phone sound to the user.
   */
  public void incomingCallReceived(CallEvent event) {
    Call sourceCall = event.getSourceCall();

    CallPanel callPanel = new CallPanel(this, sourceCall, GuiCallParticipantRecord.INCOMING_CALL);

    mainFrame.addCallPanel(callPanel);

    if (mainFrame.getState() == JFrame.ICONIFIED) mainFrame.setState(JFrame.NORMAL);

    if (!mainFrame.isVisible()) mainFrame.setVisible(true);

    mainFrame.toFront();

    this.callButton.setEnabled(true);
    this.hangupButton.setEnabled(true);

    NotificationManager.fireNotification(
        NotificationManager.INCOMING_CALL,
        null,
        "Incoming call recived from: " + sourceCall.getCallParticipants().next());

    activeCalls.put(sourceCall, callPanel);

    this.setCallPanelVisible(true);
  }
Ejemplo n.º 2
0
  private void createBillFor(Customer customer) {
    List<CallEvent> customerEvents = new ArrayList<CallEvent>();
    for (CallEvent callEvent : callLog) {
      if (callEvent.getCaller().equals(customer.getPhoneNumber())) {
        customerEvents.add(callEvent);
      }
    }

    List<Call> calls = new ArrayList<Call>();

    CallEvent start = null;
    for (CallEvent event : customerEvents) {
      if (event instanceof CallStart) {
        start = event;
      }
      if (event instanceof CallEnd && start != null) {
        calls.add(new Call(start, event));
        start = null;
      }
    }

    BigDecimal totalBill = new BigDecimal(0);
    List<LineItem> items = new ArrayList<LineItem>();

    for (Call call : calls) {

      Tariff tariff = CentralTariffDatabase.getInstance().tarriffFor(customer);

      BigDecimal cost;

      DaytimePeakPeriod peakPeriod = new DaytimePeakPeriod();
      if (peakPeriod.offPeak(call.startTime())
          && peakPeriod.offPeak(call.endTime())
          && call.durationSeconds() < 12 * 60 * 60) {
        cost = new BigDecimal(call.durationSeconds()).multiply(tariff.offPeakRate());
      } else {
        cost = new BigDecimal(call.durationSeconds()).multiply(tariff.peakRate());
      }

      cost = cost.setScale(0, RoundingMode.HALF_UP);
      BigDecimal callCost = cost;
      totalBill = totalBill.add(callCost);
      items.add(new LineItem(call, callCost));
    }

    new BillGenerator().send(customer, items, MoneyFormatter.penceToPounds(totalBill));
  }
Ejemplo n.º 3
0
  /**
   * Implements CallListener.callEnded. Stops sounds that are playing at the moment if there're any.
   * Removes the call panel and disables the hangup button.
   */
  public void callEnded(CallEvent event) {
    Call sourceCall = event.getSourceCall();

    NotificationManager.stopSound(NotificationManager.BUSY_CALL);
    NotificationManager.stopSound(NotificationManager.INCOMING_CALL);
    NotificationManager.stopSound(NotificationManager.OUTGOING_CALL);

    if (activeCalls.get(sourceCall) != null) {
      CallPanel callPanel = (CallPanel) activeCalls.get(sourceCall);

      this.removeCallPanelWait(callPanel);
    }
  }