loZntC2f9y
AL_1

package mathhulk;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import java.awt.Desktop;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.graphics.Point;
import org.eclipse.wb.swt.SWTResourceManager;

import mathhulk.MathhulkAPI.Announcement;
import mathhulk.MathhulkAPI.User;

import swing2swt.layout.BorderLayout;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.custom.TableCursor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Slider;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.ExpandItem;

public class Dashboard {
	private MathhulkAPI api = null;
	User user = null;

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public Dashboard(MathhulkAPI api, User user) {
		this.api = api;
		this.user = user;
		open();
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		Shell shlMathhulkHelper = new Shell();
		shlMathhulkHelper.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
		shlMathhulkHelper.setModified(true);
		shlMathhulkHelper.setImage(SWTResourceManager.getImage(Dashboard.class, "/favicon.ico"));
		shlMathhulkHelper.setMinimumSize(new Point(300, 350));
		shlMathhulkHelper.setSize(300, 600);
		shlMathhulkHelper.setText("mathhulk Helper");
		shlMathhulkHelper.setLayout(new BorderLayout(0, 0));

		Menu menu = new Menu(shlMathhulkHelper, SWT.BAR);
		shlMathhulkHelper.setMenuBar(menu);

		MenuItem mntmAccount = new MenuItem(menu, SWT.CASCADE);
		mntmAccount.setText("Account");

		Menu menu_1 = new Menu(mntmAccount);
		mntmAccount.setMenu(menu_1);

		MenuItem mntmProfile = new MenuItem(menu_1, SWT.NONE);
		mntmProfile.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				try {
					openWebpage(
							new URL("https://www.theartex.net/system/profile.php?user=" + user.getUsername()).toURI());
				} catch (MalformedURLException | URISyntaxException e1) {
					e1.printStackTrace();
				}
			}
		});
		mntmProfile.setText("Manage Profile");

		MenuItem mntmLogout = new MenuItem(menu_1, SWT.NONE);
		mntmLogout.setText("Logout");

		MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
		mntmHelp.setText("Help");

		Menu menu_2 = new Menu(mntmHelp);
		mntmHelp.setMenu(menu_2);

		MenuItem mntmContact = new MenuItem(menu_2, SWT.NONE);
		mntmContact.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				try {
					openWebpage(new URL("https://www.theartex.net/contact").toURI());
				} catch (MalformedURLException | URISyntaxException e1) {
					e1.printStackTrace();
				}
			}
		});
		mntmContact.setText("Contact");

		Composite composite_1 = new Composite(shlMathhulkHelper, SWT.NONE);
		composite_1.setLayoutData(BorderLayout.NORTH);

		Label label = new Label(composite_1, SWT.NONE);
		label.setLocation(0, 0);
		label.setSize(40, 40);
		label.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
		label.setAlignment(SWT.CENTER);
		label.setImage(SWTResourceManager.getImage(Dashboard.class, "/logox40.png"));

		TabFolder tabFolder = new TabFolder(shlMathhulkHelper, SWT.NONE);
		tabFolder.setLayoutData(BorderLayout.CENTER);

		TabItem tbtmAnnouncements = new TabItem(tabFolder, SWT.NONE);
		tbtmAnnouncements.setText("Announcements");

		Composite composite = new Composite(tabFolder, SWT.NONE);
		tbtmAnnouncements.setControl(composite);
		composite.setLayout(new RowLayout(SWT.VERTICAL));

		ExpandBar expandBar = new ExpandBar(composite, SWT.NONE);
		expandBar.setLayoutData(new RowData(270, SWT.DEFAULT));

		for (Announcement anc : api.getAnnouncements()) {
			ExpandItem xpndtmDate = new ExpandItem(expandBar, SWT.NONE);
			xpndtmDate.setText(anc.getDate() + " - " + anc.getMessage().substring(0, 14) + "...");
			
			Composite compositeMessage = new Composite(expandBar, SWT.NONE);
			xpndtmDate.setControl(compositeMessage);
			xpndtmDate.setHeight(xpndtmDate.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
			compositeMessage.setLayout(new FillLayout(SWT.HORIZONTAL));

			Label lblMessage = new Label(compositeMessage, SWT.WRAP);
			lblMessage.setText(anc.getMessage());
		}

		shlMathhulkHelper.setMinimumSize(300, 350);
		shlMathhulkHelper.open();
		shlMathhulkHelper.layout();
		while (!shlMathhulkHelper.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	public static void openWebpage(URI uri) {
		Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
		if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
			try {
				desktop.browse(uri);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}