<commit_before>/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 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.spark.ui;

import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.ReconnectionManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.SwingTimerTask;
import org.jivesoftware.spark.util.TaskEngine;

import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.text.html.HTMLEditorKit;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.TimerTask;

/**
 * RetryPanel is the UI/Function class to handle reconnection logic. This allows for a simple card layout to replace the current
 * roster when the connection has been lost.
 *
 * @author <NAME>
 */
public class RetryPanel extends JPanel implements ConnectionListener {
    private JEditorPane pane;
    private RolloverButton retryButton;
    private boolean closedOnError;

    /**
     * Construct the RetryPanel.
     */
    public RetryPanel() {
        setLayout(new GridBagLayout());

        // Init Components
        pane = new JEditorPane();
        pane.setBackground(Color.white);
        pane.setEditorKit(new HTMLEditorKit());
        pane.setEditable(false);

        retryButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.SMALL_CHECK));

        layoutComponents();

        retryButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                attemptReconnection();
            }
        });


        setBackground(Color.white);

        retryButton.setText("Reconnect");

        SparkManager.getConnection().addConnectionListener(this);
    }

    private void attemptReconnection() {
        retryButton.setText("Attempting...");
        retryButton.setEnabled(false);

        TimerTask task = new SwingTimerTask() {
            public void doRun() {
                reconnect();
            }
        };

        TaskEngine.getInstance().schedule(task, 100);
    }

    private void reconnect() {
        try {
            if (closedOnError) {
                ReconnectionManager.forced = true;
            }
            else {
                SparkManager.getMainWindow().logout(false);
            }
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }


    /**
     * Sets the reason the user was disconnected from the server.
     *
     * @param reason the reason the user was disconnected from the server.
     */
    public void setDisconnectReason(String reason) {<commit_msg>See SPARK-898.  This is a workaround to get Spark to compile with newer versions of Smack. A real fix still needs to go into place.<commit_after>/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 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.spark.ui;

import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.ReconnectionManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.SwingTimerTask;
import org.jivesoftware.spark.util.TaskEngine;

import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.text.html.HTMLEditorKit;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.TimerTask;

/**
 * RetryPanel is the UI/Function class to handle reconnection logic. This allows for a simple card layout to replace the current
 * roster when the connection has been lost.
 *
 * @author <NAME>
 */
public class RetryPanel extends JPanel implements ConnectionListener {
    private JEditorPane pane;
    private RolloverButton retryButton;
    private boolean closedOnError;

    /**
     * Construct the RetryPanel.
     */
    public RetryPanel() {
        setLayout(new GridBagLayout());

        // Init Components
        pane = new JEditorPane();
        pane.setBackground(Color.white);
        pane.setEditorKit(new HTMLEditorKit());
        pane.setEditable(false);

        retryButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.SMALL_CHECK));

        layoutComponents();

        retryButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                attemptReconnection();
            }
        });


        setBackground(Color.white);

        retryButton.setText("Reconnect");

        SparkManager.getConnection().addConnectionListener(this);
    }

    private void attemptReconnection() {
        retryButton.setText("Attempting...");
        retryButton.setEnabled(false);

        TimerTask task = new SwingTimerTask() {
            public void doRun() {
                reconnect();
            }
        };

        TaskEngine.getInstance().schedule(task, 100);
    }

    private void reconnect() {
        try {
            if (closedOnError) {
                //FIXME!!!!!   ReconnectionManager.forced = true;
            }
            else {
                SparkManager.getMainWindow().logout(false);
            }
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }


    /**
     * Sets the reason the user was disconnected from the server.
     *
     * @param reason the reason the user was disconnected from the server.
     */
    public void setDisconnectReason(String reason) {
{'fraction_non_alphanumeric': 0.0936951316839585, 'fraction_numerical': 0.002713487629688747, 'mean_word_length': 2.772426249247441, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4247397', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1711, 'n_words': 431}