<commit_before>package com.joeylawrance.starterupper.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

import com.google.common.eventbus.Subscribe;
import com.joeylawrance.starterupper.model.Event;
import com.joeylawrance.starterupper.model.host.HostAction;
import com.joeylawrance.starterupper.model.host.HostPerformedAction;
import com.joeylawrance.starterupper.model.host.impl.Gravatar;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileNameExtensionFilter;

import java.io.File;

@SuppressWarnings("serial")
public class PicturePanel extends JPanel {
	final JButton sharePicture;
	final JButton takePicture;
	final JButton browsePicture;
	final JLabel status;

	final Gravatar model;
	CameraPanel camPanel;
	boolean take;

	public PicturePanel(final Gravatar model) {
		setLayout(new MigLayout("", "[640.00,grow]", "[480.00][grow][]"));
		this.model = model;
		setName("Profile picture");

		camPanel = new CameraPanel(model.getProfilePicture());
		add(camPanel, "cell 0 0,alignx center");

		JPanel panel = new JPanel();
		add(panel, "cell 0 1,alignx center,growy");
		panel.setLayout(new MigLayout("", "[][][]", "[]"));

		// takePicture is stateful: it switches between Take and Clear in the UI
		takePicture = new JButton();
		take = model.getProfilePicture().exists();
		takePicture.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if (take) {
					takePicture.setEnabled(false);
					camPanel.take();
					takePicture.setEnabled(true);
				} else {
					takePicture.setEnabled(false);
					camPanel.discard();
					takePicture.setEnabled(camPanel.canTakePicture());
				}
				updateState();
			}
		});

		panel.add(takePicture, "cell 0 0");

		sharePicture = new JButton("Share");
		sharePicture.setToolTipText("Share picture via Gravatar");
		sharePicture.setEnabled(false);
		sharePicture.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				takePicture.setEnabled(false);
				browsePicture.setEnabled(false);
				sharePicture.setEnabled(false);
				new SwingWorker<Void, Void>() {
					@Override
					protected Void doInBackground() throws Exception {
						status.setText("Uploading picture to Gravatar...");
						if (model.uploadPicture()) {
							status.setText("Uploaded picture to Gravatar.");							
						} else {
							status.setText("Unable to upload picture to Gravatar.");
						}
						take = camPanel.canTakePicture();
						takePicture.setEnabled(take);
						browsePicture.setEnabled(true);
						updateState();
						return null;
					}
				}.execute();
			}

		});
		panel.add(sharePicture, "cell 2 0");

		browsePicture = new JButton( "Browse..." );
		browsePicture.setToolTipText( "Browse for a picture on your computer" );
		browsePicture.setEnabled( true );

		browsePicture.addActionListener( new ActionListener() 
		{
			@Override
			public void actionPerformed( ActionEvent arg0 )
			{
				JFileChooser fileChooser = new JFileChooser();
				FileNameExtensionFilter filter = new FileNameExtensionFilter("All Image Files (*.jpg, *.png, *.bmp, *.gif)", "jpg", "png", "bmp", "gif");
				fileChooser.setFileFilter(filter);
				int returnValue = fileChooser.showOpenDialog( PicturePanel.this );
				File file = fileChooser.getSelectedFile();

				if( returnValue == JFileChooser.APPROVE_OPTION && filter.accept(file))
				{
					camPanel.setImage( file );
					take = true;
					takePicture.setEnabled(true);
					updateState();
				}
			}
		} );<commit_msg>Fix the disabled clear button after sharing Gravatar.<commit_after>package com.joeylawrance.starterupper.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

import com.google.common.eventbus.Subscribe;
import com.joeylawrance.starterupper.model.Event;
import com.joeylawrance.starterupper.model.host.HostAction;
import com.joeylawrance.starterupper.model.host.HostPerformedAction;
import com.joeylawrance.starterupper.model.host.impl.Gravatar;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileNameExtensionFilter;

import java.io.File;

@SuppressWarnings("serial")
public class PicturePanel extends JPanel {
	final JButton sharePicture;
	final JButton takePicture;
	final JButton browsePicture;
	final JLabel status;

	final Gravatar model;
	CameraPanel camPanel;
	boolean take;

	public PicturePanel(final Gravatar model) {
		setLayout(new MigLayout("", "[640.00,grow]", "[480.00][grow][]"));
		this.model = model;
		setName("Profile picture");

		camPanel = new CameraPanel(model.getProfilePicture());
		add(camPanel, "cell 0 0,alignx center");

		JPanel panel = new JPanel();
		add(panel, "cell 0 1,alignx center,growy");
		panel.setLayout(new MigLayout("", "[][][]", "[]"));

		// takePicture is stateful: it switches between Take and Clear in the UI
		takePicture = new JButton();
		take = model.getProfilePicture().exists();
		takePicture.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if (take) {
					takePicture.setEnabled(false);
					camPanel.take();
					takePicture.setEnabled(true);
				} else {
					takePicture.setEnabled(false);
					camPanel.discard();
					takePicture.setEnabled(camPanel.canTakePicture());
				}
				updateState();
			}
		});

		panel.add(takePicture, "cell 0 0");

		sharePicture = new JButton("Share");
		sharePicture.setToolTipText("Share picture via Gravatar");
		sharePicture.setEnabled(false);
		sharePicture.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				takePicture.setEnabled(false);
				browsePicture.setEnabled(false);
				sharePicture.setEnabled(false);
				new SwingWorker<Void, Void>() {
					@Override
					protected Void doInBackground() throws Exception {
						status.setText("Uploading picture to Gravatar...");
						if (model.uploadPicture()) {
							status.setText("Uploaded picture to Gravatar.");							
						} else {
							status.setText("Unable to upload picture to Gravatar.");
						}
						take = true;
						takePicture.setEnabled(take);
						browsePicture.setEnabled(true);
						updateState();
						return null;
					}
				}.execute();
			}

		});
		panel.add(sharePicture, "cell 2 0");

		browsePicture = new JButton( "Browse..." );
		browsePicture.setToolTipText( "Browse for a picture on your computer" );
		browsePicture.setEnabled( true );

		browsePicture.addActionListener( new ActionListener() 
		{
			@Override
			public void actionPerformed( ActionEvent arg0 )
			{
				JFileChooser fileChooser = new JFileChooser();
				FileNameExtensionFilter filter = new FileNameExtensionFilter("All Image Files (*.jpg, *.png, *.bmp, *.gif)", "jpg", "png", "bmp", "gif");
				fileChooser.setFileFilter(filter);
				int returnValue = fileChooser.showOpenDialog( PicturePanel.this );
				File file = fileChooser.getSelectedFile();

				if( returnValue == JFileChooser.APPROVE_OPTION && filter.accept(file))
				{
					camPanel.setImage( file );
					take = true;
					takePicture.setEnabled(take);
					updateState();
				}
			}
		} );
{'fraction_non_alphanumeric': 0.12253123740427246, 'fraction_numerical': 0.005642885933091495, 'mean_word_length': 4.169444444444444, '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': '678463', 'n_tokens_mistral': 2840, 'n_tokens_neox': 2243, 'n_words': 489}