<commit_before>// $Id: Draw.java,v 1.9 2005/01/28 14:16:43 belaban Exp $


package org.jgroups.demos;


import org.jgroups.*;
import org.jgroups.debug.Debugger;
import org.jgroups.util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.util.Random;




/**
 * Shared whiteboard, each new instance joins the same group. Each instance chooses a random color,
 * mouse moves are broadcast to all group members, which then apply them to their canvas<p>
 * @author <NAME>, Oct 17 2001
 */
public class Draw implements ActionListener, ChannelListener {
    private final ByteArrayOutputStream  out=new ByteArrayOutputStream();
    private final String                 groupname="DrawGroupDemo";
    private JChannel               channel=null;
    private int                    member_size=1;
    Debugger                       debugger=null;
    final boolean                        first=true;
    final boolean cummulative=true;
    private JFrame                 mainFrame=null;
    private JPanel                 sub_panel=null;
    private DrawPanel              panel=null;
    private JButton                clear_button, leave_button;
    private final Random                 random=new Random(System.currentTimeMillis());
    private final Font             default_font=new Font("Helvetica",Font.PLAIN,12);
    private final Color                  draw_color=selectColor();
    private final Color background_color=Color.white;
    boolean                        no_channel=false;





    public Draw(String props, boolean debug, boolean cummulative, boolean no_channel) throws Exception {
        this.no_channel=no_channel;
        if(no_channel)
            return;

        channel=new JChannel(props);
        if(debug) {
            debugger=new Debugger(channel, cummulative);
            debugger.start();
        }
        channel.setOpt(Channel.AUTO_RECONNECT, Boolean.TRUE);
        channel.setChannelListener(this);
    }






   public static void main(String[] args) {
       Draw             draw=null;
       String           props=null;
       boolean          debug=false;
       boolean          cummulative=false;
       boolean          no_channel=false;

        for(int i=0; i < args.length; i++) {
            if("-help".equals(args[i])) {
                help();
                return;
            }
            if("-debug".equals(args[i])) {
                debug=true;
                continue;
            }
            if("-cummulative".equals(args[i])) {
                cummulative=true;
                continue;
            }
            if("-props".equals(args[i])) {
                props=args[++i];
                continue;
            }
            if("-no_channel".equals(args[i])) {
                no_channel=true;
                continue;
            }
            help();
            return;
        }

        if(props == null) {
            props="UDP(mcast_addr=192.168.127.12;mcast_port=45566;ip_ttl=32;" +
                    "mcast_send_buf_size=64000;mcast_recv_buf_size=64000):" +
                    //"PIGGYBACK(max_wait_time=100;max_size=32000):" +
                    "PING(timeout=2000;num_initial_members=3):" +
                    "MERGE2(min_interval=5000;max_interval=10000):" +
                    "FD_SOCK:" +
                    "VERIFY_SUSPECT(timeout=1500):" +
                    "pbcast.NAKACK(max_xmit_size=8096;gc_lag=50;retransmit_timeout=600,1200,2400,4800):" +
                    "UNICAST(timeout=600,1200,2400,4800):" +
                    "pbcast.STABLE(desired_avg_gossip=20000):" +
                    "FRAG(frag_size=8096;down_thread=false;up_thread=false):" +
                    // "CAUSAL:" +
                    "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
                    "shun=false;print_local_addr=true)";
        }


        try {
            draw=new Draw(props, debug, cummulative, no_channel);
            draw.go();
        }
        catch(Throwable e) {
            e.printStackTrace();
            System.exit(0);
        }
    }


    static void help() {
        System.out.println("\nDraw [-help] [-debug] [-cummulative] [-no_channel] [-props <protocol stack definition>]");
        System.out.println("-debug: brings up a visual debugger");
        System.out.println("-no_channel: doesn't use JGroups at all, any drawing will be relected on the " +
                           "whiteboard directly");
        System.out.println("-props: argument can be an old-style protocol stack specification, or it can be " +
                           "a URL. In the latter case, the protocol specification will be read from the URL\n");
    }


    private Color selectColor() {
        int red=(Math.abs(random.nextInt()) % 255);
        int green=(Math.abs(random.nextInt()) % 255);
        int blue=(Math.abs(random.nextInt()) % 255);
        return new Color(red, green, blue);
    }



    public void go() throws Exception {
        if(!no_channel) {
            channel.connect(groupname);
        }
        mainFrame=new JFrame();
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        panel=new DrawPanel();
        panel.setBackground(background_color);
        sub_panel=new JPanel();
        mainFrame.getContentPane().add("Center", panel);
        clear_button=new JButton("Clear");
        clear_button.setFont(default_font);
        clear_button.addActionListener(this);
        leave_button=new JButton("Leave & Exit");
        leave_button.setFont(default_font);
        leave_button.addActionListener(this);
        sub_panel.add("South", clear_button);
        sub_panel.add("South", leave_button);
        mainFrame.getContentPane().add("South", sub_panel);
        mainFrame.setBackground(background_color);
        clear_button.setForeground(Color.blue);
        leave_button.setForeground(Color.blue);
        setTitle();
        mainFrame.pack();
        mainFrame.setLocation(15, 25);
        mainFrame.setBounds(new Rectangle(280, 280));
        mainFrame.setVisible(true);
        if(!no_channel)
            mainLoop();
    }




    void setTitle(String title) {
        String tmp="";
        if(no_channel) {
            mainFrame.setTitle(" Draw Demo ");
            return;
        }
        if(title != null) {
            mainFrame.setTitle(title);
        }
        else {
            if(channel.getLocalAddress() != null)
                tmp+=channel.getLocalAddress();
            tmp+=" (" + member_size + ") mbrs";
            mainFrame.setTitle(tmp);
        }
    }
<commit_msg>set size<commit_after>// $Id: Draw.java,v 1.10 2005/01/28 14:18:32 belaban Exp $


package org.jgroups.demos;


import org.jgroups.*;
import org.jgroups.debug.Debugger;
import org.jgroups.util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.util.Random;




/**
 * Shared whiteboard, each new instance joins the same group. Each instance chooses a random color,
 * mouse moves are broadcast to all group members, which then apply them to their canvas<p>
 * @author <NAME>, Oct 17 2001
 */
public class Draw implements ActionListener, ChannelListener {
    private final ByteArrayOutputStream  out=new ByteArrayOutputStream();
    private final String                 groupname="DrawGroupDemo";
    private JChannel               channel=null;
    private int                    member_size=1;
    Debugger                       debugger=null;
    final boolean                        first=true;
    final boolean cummulative=true;
    private JFrame                 mainFrame=null;
    private JPanel                 sub_panel=null;
    private DrawPanel              panel=null;
    private JButton                clear_button, leave_button;
    private final Random                 random=new Random(System.currentTimeMillis());
    private final Font             default_font=new Font("Helvetica",Font.PLAIN,12);
    private final Color                  draw_color=selectColor();
    private final Color background_color=Color.white;
    boolean                        no_channel=false;





    public Draw(String props, boolean debug, boolean cummulative, boolean no_channel) throws Exception {
        this.no_channel=no_channel;
        if(no_channel)
            return;

        channel=new JChannel(props);
        if(debug) {
            debugger=new Debugger(channel, cummulative);
            debugger.start();
        }
        channel.setOpt(Channel.AUTO_RECONNECT, Boolean.TRUE);
        channel.setChannelListener(this);
    }






   public static void main(String[] args) {
       Draw             draw=null;
       String           props=null;
       boolean          debug=false;
       boolean          cummulative=false;
       boolean          no_channel=false;

        for(int i=0; i < args.length; i++) {
            if("-help".equals(args[i])) {
                help();
                return;
            }
            if("-debug".equals(args[i])) {
                debug=true;
                continue;
            }
            if("-cummulative".equals(args[i])) {
                cummulative=true;
                continue;
            }
            if("-props".equals(args[i])) {
                props=args[++i];
                continue;
            }
            if("-no_channel".equals(args[i])) {
                no_channel=true;
                continue;
            }
            help();
            return;
        }

        if(props == null) {
            props="UDP(mcast_addr=192.168.127.12;mcast_port=45566;ip_ttl=32;" +
                    "mcast_send_buf_size=64000;mcast_recv_buf_size=64000):" +
                    //"PIGGYBACK(max_wait_time=100;max_size=32000):" +
                    "PING(timeout=2000;num_initial_members=3):" +
                    "MERGE2(min_interval=5000;max_interval=10000):" +
                    "FD_SOCK:" +
                    "VERIFY_SUSPECT(timeout=1500):" +
                    "pbcast.NAKACK(max_xmit_size=8096;gc_lag=50;retransmit_timeout=600,1200,2400,4800):" +
                    "UNICAST(timeout=600,1200,2400,4800):" +
                    "pbcast.STABLE(desired_avg_gossip=20000):" +
                    "FRAG(frag_size=8096;down_thread=false;up_thread=false):" +
                    // "CAUSAL:" +
                    "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
                    "shun=false;print_local_addr=true)";
        }


        try {
            draw=new Draw(props, debug, cummulative, no_channel);
            draw.go();
        }
        catch(Throwable e) {
            e.printStackTrace();
            System.exit(0);
        }
    }


    static void help() {
        System.out.println("\nDraw [-help] [-debug] [-cummulative] [-no_channel] [-props <protocol stack definition>]");
        System.out.println("-debug: brings up a visual debugger");
        System.out.println("-no_channel: doesn't use JGroups at all, any drawing will be relected on the " +
                           "whiteboard directly");
        System.out.println("-props: argument can be an old-style protocol stack specification, or it can be " +
                           "a URL. In the latter case, the protocol specification will be read from the URL\n");
    }


    private Color selectColor() {
        int red=(Math.abs(random.nextInt()) % 255);
        int green=(Math.abs(random.nextInt()) % 255);
        int blue=(Math.abs(random.nextInt()) % 255);
        return new Color(red, green, blue);
    }



    public void go() throws Exception {
        if(!no_channel) {
            channel.connect(groupname);
        }
        mainFrame=new JFrame();
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        panel=new DrawPanel();
        panel.setBackground(background_color);
        sub_panel=new JPanel();
        mainFrame.getContentPane().add("Center", panel);
        clear_button=new JButton("Clear");
        clear_button.setFont(default_font);
        clear_button.addActionListener(this);
        leave_button=new JButton("Leave & Exit");
        leave_button.setFont(default_font);
        leave_button.addActionListener(this);
        sub_panel.add("South", clear_button);
        sub_panel.add("South", leave_button);
        mainFrame.getContentPane().add("South", sub_panel);
        mainFrame.setBackground(background_color);
        clear_button.setForeground(Color.blue);
        leave_button.setForeground(Color.blue);
        setTitle();
        mainFrame.pack();
        mainFrame.setLocation(15, 25);
        mainFrame.setBounds(new Rectangle(250, 250));
        mainFrame.setVisible(true);
        if(!no_channel)
            mainLoop();
    }




    void setTitle(String title) {
        String tmp="";
        if(no_channel) {
            mainFrame.setTitle(" Draw Demo ");
            return;
        }
        if(title != null) {
            mainFrame.setTitle(title);
        }
        else {
            if(channel.getLocalAddress() != null)
                tmp+=channel.getLocalAddress();
            tmp+=" (" + member_size + ")";
            mainFrame.setTitle(tmp);
        }
    }

{'fraction_non_alphanumeric': 0.11182084617118809, 'fraction_numerical': 0.02322086120087172, 'mean_word_length': 1.9101246446534004, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '498756', 'n_tokens_mistral': 3974, 'n_tokens_neox': 3648, 'n_words': 714}