Package hermes.browser.components

Source Code of hermes.browser.components.MessagePayloadPanel

/*
* Copyright 2003,2004 Colin Crist
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package hermes.browser.components;

import hermes.Hermes;
import hermes.browser.HermesBrowser;
import hermes.browser.MessageRenderer;

import java.awt.BorderLayout;

import javax.jms.Message;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import org.apache.log4j.Logger;

import com.jidesoft.swing.JideScrollPane;
import com.jidesoft.swing.JideTabbedPane;

/**
* A panel for displaying JMS messages
*
* @author colincrist@hermesjms.com last changed by: $Author: colincrist $
* @version $Id: MessagePayloadPanel.java,v 1.3 2004/07/30 17:25:13 colincrist
*          Exp $
*/
public class MessagePayloadPanel extends JPanel {
  /**
   *
   */
  private static final long serialVersionUID = -7962228996637817501L;
  private static final Logger log = Logger.getLogger(MessagePayloadPanel.class);
  private final JTabbedPane tabbedPane = new JideTabbedPane();

  private final String destinationName;
  private Message message;

  public MessagePayloadPanel(String destinationName) {
    super();
    this.destinationName = destinationName;

    init();
  }

  public MessagePayloadPanel(Hermes hermes, String destinationName, Message message) {
    super();
    this.destinationName = destinationName;

    init();

    setMessage(hermes, message);
  }

  public Message getMessage() {
    return message;
  }

  private void init() {
    tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
    setLayout(new BorderLayout());
    add(tabbedPane, BorderLayout.CENTER);
  }

  public void setMessage(Hermes hermes, Message m) {
    String selectedTitle = null;
    int selectedIndex = 0;

    if (tabbedPane.getSelectedIndex() > -1) {
      selectedTitle = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
    }

    tabbedPane.removeAll();

    for (MessageRenderer renderer : HermesBrowser.getRendererManager().getRenderers()) {
      if (renderer.isActive() && renderer.canRender(m)) {
        JideScrollPane scrollPane = new JideScrollPane();
        scrollPane.setViewportView(renderer.render(scrollPane, m));

        tabbedPane.add(renderer.getDisplayName(), scrollPane);

        if (renderer.getDisplayName().equals(selectedTitle)) {
          selectedIndex = tabbedPane.getTabCount() - 1;
          tabbedPane.setSelectedIndex(selectedIndex);
        }
      }
    }

    tabbedPane.setSelectedIndex(selectedIndex);
    this.message = m;
  }
}
TOP

Related Classes of hermes.browser.components.MessagePayloadPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.