📄 previousconversationpanel.java.svn-base
字号:
/** * $Revision: $ * $Date: $ * * Copyright (C) 2007 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Lesser Public License (LGPL), * a copy of which is included in this distribution. */package org.jivesoftware.sparkplugin.ui.call;import org.jivesoftware.sparkplugin.callhistory.HistoryCall;import org.jivesoftware.sparkplugin.callhistory.TelephoneUtils;import org.jivesoftware.spark.plugin.phone.resource.PhoneRes;import net.java.sipmack.softphone.SoftPhoneManager;import org.jivesoftware.spark.component.TimeTrackingLabel;import org.jivesoftware.spark.component.VerticalFlowLayout;import org.jivesoftware.spark.util.ModelUtil;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Font;import java.text.SimpleDateFormat;import java.util.Collections;import java.util.Comparator;import java.util.Date;import java.util.List;import javax.swing.BorderFactory;import javax.swing.JLabel;import javax.swing.JPanel;/** * */public class PreviousConversationPanel extends JPanel { private final Color greenColor = new Color(91, 175, 41); private final JLabel currentCallLabel = new JLabel(); private final JPanel timePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0)); private final JLabel today = new JLabel(); private final JLabel statusLabel = new JLabel(); final JLabel previousLabel = new JLabel(PhoneRes.getIString("phone.previousconversations")+":"); private final JLabel oldConversation = new JLabel(); private final SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy, h:mm a"); private TimeTrackingLabel durationLabel; private Date startTime; public PreviousConversationPanel() { setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 5, 0, true, false)); setBackground(Color.white); setBorder(BorderFactory.createLineBorder(new Color(197, 213, 230))); // Set Default Color for Current Call Label currentCallLabel.setText(PhoneRes.getIString("phone.currentcall")+":"); currentCallLabel.setFont(new Font("Dialog", Font.BOLD, 13)); currentCallLabel.setForeground(greenColor); // Set default color for previous label. previousLabel.setForeground(new Color(64, 103, 162)); previousLabel.setFont(new Font("Dialog", Font.BOLD, 13)); statusLabel.setFont(new Font("Dialog", Font.BOLD, 12)); // Add Duration timer durationLabel = new TimeTrackingLabel(new Date(), this); durationLabel.setFont(new Font("Dialog", Font.BOLD, 12)); durationLabel.stopTimer(); // Build Time Panel timePanel.setOpaque(false); today.setForeground(Color.black); today.setFont(new Font("Dialog", Font.PLAIN, 12)); today.setText(formatter.format(new Date()) + " - "+PhoneRes.getIString("phone.time")+": "); timePanel.add(today); timePanel.add(durationLabel); oldConversation.setForeground(new Color(211, 0, 0)); oldConversation.setFont(new Font("Dialog", Font.BOLD, 12)); } /** * Builds the previous history list. * * @param phoneNumber the phone number to use for history checking. */ public void addPreviousConversations(String phoneNumber) { startTime = new Date(); currentCallLabel.setText(PhoneRes.getIString("phone.currentcall")+":"); currentCallLabel.setFont(new Font("Dialog", Font.BOLD, 13)); currentCallLabel.setForeground(greenColor); today.setText(formatter.format(new Date()) + " - "+PhoneRes.getIString("phone.time")+": "); // Add Current Call and Time Panel add(currentCallLabel); add(timePanel); add(statusLabel); statusLabel.setVisible(false); // Give some space. add(new JLabel()); add(previousLabel); add(oldConversation); int count = 0; final List<HistoryCall> calls = (List)SoftPhoneManager.getInstance().getLogManager().getCallHistory(); Collections.sort(calls, itemComparator); for (HistoryCall call : calls){ String number = TelephoneUtils.removeInvalidChars(call.getNumber()); if (number.equals(TelephoneUtils.removeInvalidChars(phoneNumber))) { count++; if (count > 4) { break; } final Date callDate = new Date(call.getTime()); final long duration = call.getCallLength(); StringBuilder builder = new StringBuilder(); builder.append(formatter.format(callDate)); builder.append(" "); builder.append("("); builder.append(ModelUtil.getTimeFromLong(duration*1000)); builder.append(")"); final JLabel callLabel = new JLabel(builder.toString()); callLabel.setForeground(Color.black); callLabel.setFont(new Font("Dialog", Font.PLAIN, 12)); add(callLabel); } } if (count == 0) { final JLabel label = new JLabel(PhoneRes.getIString("phone.noprevious")); label.setForeground(Color.gray); add(label); } durationLabel.resetTime(); durationLabel.startTimer(); invalidate(); validate(); repaint(); } public void callEnded() { durationLabel.stopTimer(); currentCallLabel.setForeground(Color.black); currentCallLabel.setText(PhoneRes.getIString("phone.callended")); today.setText(PhoneRes.getIString("phone.time")+": "); } public void transferring() { statusLabel.setText(PhoneRes.getIString("phone.transferring")); statusLabel.setVisible(true); } public void transfer(String user) { durationLabel.stopTimer(); statusLabel.setVisible(false); currentCallLabel.setForeground(Color.black); currentCallLabel.setText(PhoneRes.getIString("phone.callended")); today.setText(PhoneRes.getIString("phone.time")+": "); currentCallLabel.setText(PhoneRes.getIString("phone.transferto") + " " + user); Date now = new Date(); final SimpleDateFormat timeFormatter = new SimpleDateFormat("h:mm"); String end = timeFormatter.format(now); oldConversation.setText(formatter.format(startTime) + " - " + end + " (" + durationLabel.getText() + ")"); } final Comparator itemComparator = new Comparator() { public int compare(Object contactItemOne, Object contactItemTwo) { final HistoryCall time1 = (HistoryCall)contactItemOne; final HistoryCall time2 = (HistoryCall)contactItemTwo; if (time1.getTime() < time2.getTime()) { return 1; } else if (time1.getTime() > time2.getTime()) { return -1; } return 0; } };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -