From 3c53069887ddf95b1fb3d046390f3d4e1556e38e Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Thu, 5 Nov 2009 19:51:28 +0000 Subject: [PATCH] Removes some UI repetition from the chat history window, uses one and the same spacing between the components for consistency and so that they become properly aligned. --- .../gui/main/chat/history/DatesPanel.java | 5 +- .../gui/main/chat/history/HistoryWindow.java | 86 +++++++++++-------- .../chat/history/HistoryWindowManager.java | 3 +- .../gui/main/chat/history/SearchPanel.java | 51 +++++------ 4 files changed, 72 insertions(+), 73 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/history/DatesPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/history/DatesPanel.java index 339764cdc..f191bb867 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/history/DatesPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/history/DatesPanel.java @@ -49,9 +49,7 @@ public DatesPanel(HistoryWindow historyWindow) this.historyWindow = historyWindow; this.setPreferredSize(new Dimension(100, 100)); - this.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createEmptyBorder(3, 3, 3, 0), - SIPCommBorders.getBoldRoundBorder())); + this.setBorder(SIPCommBorders.getBoldRoundBorder()); this.setOpaque(false); this.datesList.setModel(listModel); @@ -65,7 +63,6 @@ public DatesPanel(HistoryWindow historyWindow) this.setViewportView(listPanel); this.getVerticalScrollBar().setUnitIncrement(30); - } /** diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java b/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java index b61b6c8b8..9df82be12 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java @@ -48,20 +48,30 @@ public class HistoryWindow { private static final Logger logger = Logger.getLogger(HistoryWindow.class); + private static final String[] HISTORY_FILTER + = new String[] + { + MessageHistoryService.class.getName(), + FileHistoryService.class.getName() + }; + + /** + * The horizontal and vertical spacing between the UI components of this + * instance defined in one place for the purposes of consistency. Hopefully, + * one day it should be defined at a global application level to achieve + * consistency with the UI elsewhere. + */ + private static final int SPACING = 5; + private ChatConversationPanel chatConvPanel; - private TransparentPanel mainPanel - = new TransparentPanel(new BorderLayout(10, 10)); + private final JPanel mainPanel + = new TransparentPanel(new BorderLayout(SPACING, SPACING)); private JProgressBar progressBar; - private SearchPanel searchPanel; - private HistoryMenu historyMenu; - private TransparentPanel northPanel - = new TransparentPanel(new BorderLayout()); - private DatesPanel datesPanel; private Object historyContact; @@ -71,17 +81,14 @@ public class HistoryWindow private Hashtable dateHistoryTable = new Hashtable(); - private JLabel readyLabel = new JLabel( - GuiActivator.getResources().getI18NString("service.gui.READY")); + private final JLabel readyLabel + = new JLabel( + GuiActivator.getResources().getI18NString("service.gui.READY")); private String searchKeyword; private Vector datesVector = new Vector(); - private static final String[] historyFilter - = new String[]{ MessageHistoryService.class.getName(), - FileHistoryService.class.getName()}; - private Date ignoreProgressDate; private int lastProgress = 0; @@ -124,7 +131,6 @@ public HistoryWindow(Object historyContact) this.datesPanel = new DatesPanel(this); this.historyMenu = new HistoryMenu(this); - this.searchPanel = new SearchPanel(this); this.initPanels(); @@ -173,24 +179,22 @@ else if (historyContact instanceof ChatRoomWrapper) */ private void initPanels() { - this.northPanel.add(searchPanel, BorderLayout.CENTER); - - this.mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - - this.mainPanel.add(northPanel, BorderLayout.NORTH); + this.mainPanel + .setBorder( + BorderFactory + .createEmptyBorder(SPACING, SPACING, SPACING, SPACING)); + this.mainPanel.setPreferredSize(new Dimension(500, 400)); + this.mainPanel.add(new SearchPanel(this), BorderLayout.NORTH); this.mainPanel.add(chatConvPanel, BorderLayout.CENTER); - this.mainPanel.add(datesPanel, BorderLayout.WEST); - this.mainPanel.setPreferredSize(new Dimension(500, 400)); - this.getContentPane().add(mainPanel); } /** * Initializes the history with a list of all dates, for which a history - * with the given contact is availabled. + * with the given contact is available. */ private void initDates() { @@ -433,7 +437,7 @@ public void run() if (historyContact instanceof MetaContact) { msgList = history.findByEndDate( - historyFilter, + HISTORY_FILTER, (MetaContact) historyContact, new Date(System.currentTimeMillis())); } @@ -446,7 +450,7 @@ else if(historyContact instanceof ChatRoomWrapper) return; msgList = history.findByEndDate( - historyFilter, + HISTORY_FILTER, chatRoomWrapper.getChatRoom(), new Date(System.currentTimeMillis())); } @@ -551,7 +555,7 @@ public void run() if(historyContact instanceof MetaContact) { msgList = history.findByPeriod( - historyFilter, + HISTORY_FILTER, (MetaContact) historyContact, startDate, endDate); } @@ -564,7 +568,7 @@ else if (historyContact instanceof ChatRoomWrapper) return; msgList = history.findByPeriod( - historyFilter, + HISTORY_FILTER, chatRoomWrapper.getChatRoom(), startDate, endDate); } @@ -613,7 +617,7 @@ public void run() if (historyContact instanceof MetaContact) { msgList = history.findByKeyword( - historyFilter, + HISTORY_FILTER, (MetaContact) historyContact, keyword); } else if (historyContact instanceof ChatRoomWrapper) @@ -625,7 +629,7 @@ else if (historyContact instanceof ChatRoomWrapper) return; msgList = history.findByKeyword( - historyFilter, + HISTORY_FILTER, chatRoomWrapper.getChatRoom(), keyword); } @@ -752,11 +756,14 @@ private void initProgressBar(Date date) public void messageReceived(MessageReceivedEvent evt) { Contact sourceContact = evt.getSourceContact(); - - this.processMessage(sourceContact, evt.getTimestamp(), - Chat.INCOMING_MESSAGE, - evt.getSourceMessage().getContent(), - evt.getSourceMessage().getContentType()); + Message sourceMessage = evt.getSourceMessage(); + + this.processMessage( + sourceContact, + evt.getTimestamp(), + Chat.INCOMING_MESSAGE, + sourceMessage.getContent(), + sourceMessage.getContentType()); } /** @@ -766,11 +773,14 @@ public void messageReceived(MessageReceivedEvent evt) public void messageDelivered(MessageDeliveredEvent evt) { Contact destContact = evt.getDestinationContact(); + Message sourceMessage = evt.getSourceMessage(); - this.processMessage(destContact, evt.getTimestamp(), - Chat.OUTGOING_MESSAGE, - evt.getSourceMessage().getContent(), - evt.getSourceMessage().getContentType()); + this.processMessage( + destContact, + evt.getTimestamp(), + Chat.OUTGOING_MESSAGE, + sourceMessage.getContent(), + sourceMessage.getContentType()); } public void messageDeliveryFailed(MessageDeliveryFailedEvent evt) diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindowManager.java b/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindowManager.java index d7a0fb964..4b3104d95 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindowManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindowManager.java @@ -15,7 +15,8 @@ */ public class HistoryWindowManager { - private Hashtable contactHistory = new Hashtable(); + private final Map contactHistory + = new Hashtable(); /** * Checks if there's an open history window for the given history contact. diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/history/SearchPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/history/SearchPanel.java index 2d5ff2267..0936a2617 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/history/SearchPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/history/SearchPanel.java @@ -22,25 +22,14 @@ * or an hour, or searching by a keyword. * * @author Yana Stamcheva + * @author Lubomir Marinov */ public class SearchPanel extends TransparentPanel implements ActionListener, DocumentListener { - private static final String searchString - = GuiActivator.getResources().getI18NString("service.gui.SEARCH"); - - private JButton searchButton = new JButton( - searchString, - new ImageIcon(ImageLoader.getImage(ImageLoader.SEARCH_ICON))); - - private JLabel searchLabel = new JLabel(searchString + ": "); - private JTextField searchTextField = new JTextField(); - - private TransparentPanel textFieldPanel - = new TransparentPanel(new BorderLayout()); /* private JRadioButton todayMessagesRadio = new JRadioButton(Messages @@ -91,38 +80,40 @@ public class SearchPanel private JPanel checksPanel = new JPanel(new GridLayout(0, 1)); */ - private HistoryWindow historyWindow; + private final HistoryWindow historyWindow; // private JPanel extendedSearchPanel = new JPanel(new BorderLayout()); /** * Creates an instance of the SearchPanel. */ - public SearchPanel(HistoryWindow historyWindow) { - - super(new BorderLayout()); + public SearchPanel(HistoryWindow historyWindow) + { + super(new BorderLayout(5, 5)); this.historyWindow = historyWindow; - this.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder(searchString), - BorderFactory.createEmptyBorder(5, 5, 5, 5))); - - this.textFieldPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); - this.init(); } /** * Constructs the SearchPanel. */ - public void init() { - this.textFieldPanel.add(searchTextField); - + private void init() + { + String searchString + = GuiActivator.getResources().getI18NString("service.gui.SEARCH"); + JLabel searchLabel = new JLabel(searchString + ": "); + JButton searchButton + = new JButton( + searchString, + new ImageIcon( + ImageLoader.getImage(ImageLoader.SEARCH_ICON))); + this.searchTextField.getDocument().addDocumentListener(this); - + this.add(searchLabel, BorderLayout.WEST); - this.add(textFieldPanel, BorderLayout.CENTER); + this.add(searchTextField, BorderLayout.CENTER); /* this.detailsLabelsPanel.add(dateLabel); @@ -150,14 +141,14 @@ public void init() { this.dateCenteredPanel.add(datePanel); */ - this.searchButton.setName("search"); - this.searchButton.setMnemonic( + searchButton.setName("search"); + searchButton.setMnemonic( GuiActivator.getResources().getI18nMnemonic("service.gui.SEARCH")); // this.extendedSearchButton.setName("extendedSearch"); // this.extendedSearchOpenedButton.setName("extendedSearchOpened"); - this.searchButton.addActionListener(this); + searchButton.addActionListener(this); this.historyWindow.getRootPane().setDefaultButton(searchButton); // this.extendedSearchPanel.add(extendedSearchButton,