Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make two UI modifications in Welcoming window and Help-About dialog. #2752

Merged
merged 7 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added gapic/res/icons/add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/clipboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/recent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 113 additions & 1 deletion gapic/src/main/com/google/gapid/LoadingScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,23 @@
*/
package com.google.gapid;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gapid.util.GapidVersion.GAPID_VERSION;
import static com.google.gapid.util.GeoUtils.bottomLeft;
import static com.google.gapid.views.AboutDialog.showHelp;
import static com.google.gapid.views.TracerDialog.showOpenTraceDialog;
import static com.google.gapid.views.TracerDialog.showTracingDialog;
import static com.google.gapid.widgets.Widgets.createLabel;
import static com.google.gapid.widgets.Widgets.createLink;
import static com.google.gapid.widgets.Widgets.createMenuItem;
import static com.google.gapid.widgets.Widgets.scheduleIfNotDisposed;

import com.google.gapid.models.Analytics.View;
import com.google.gapid.models.Models;
import com.google.gapid.proto.service.Service.ClientAction;
import com.google.gapid.server.Client;
import com.google.gapid.util.Messages;
import com.google.gapid.util.OS;
import com.google.gapid.widgets.CenteringLayout;
import com.google.gapid.widgets.Theme;
import com.google.gapid.widgets.Widgets;
Expand All @@ -27,15 +41,30 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;

import java.io.File;

/**
* The loading screen is a minimal view shown while the UI is loading, looking for gapis, etc.
*/
public class LoadingScreen extends Composite {
private final Theme theme;
private final Label statusLabel;
private final Composite optionsContainer;
private Label recentIcon;
private Link recentLink;
private Label helpIcon;
private Link helpLink;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The labels and links can be final.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all these constructive opinions! Done all the others except this one. Because I initialize my recentLink outside of the constructor. (Cause that part of initialization is huge). Can I keep it or should I still use some tricks to turn it into final? (Like returning recentLink as a variable in the other initializing part)

private Models models;
private Client client;
private Widgets widgets;

public LoadingScreen(Composite parent, Theme theme) {
super(parent, SWT.NONE);
this.theme = theme;
setLayout(CenteringLayout.goldenRatio());

Composite container = Widgets.createComposite(this, new GridLayout(1, false));
Expand All @@ -46,12 +75,95 @@ public LoadingScreen(Composite parent, Theme theme) {
titleLabel.setFont(theme.bigBoldFont());
titleLabel.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false));

Label versionLabel = createLabel(container, "Version " + GAPID_VERSION.toFriendlyString());
versionLabel.setForeground(theme.welcomeVersionColor());
versionLabel.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false));

statusLabel = createLabel(container, "Starting up...");
statusLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false));
statusLabel.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false));

GridLayout gridLayout = new GridLayout(3, false);
gridLayout.horizontalSpacing = 15;
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved
optionsContainer = Widgets.createComposite(container, gridLayout);
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved
optionsContainer.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false));
this.createOptions();
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved
}

public void setText(String status) {
statusLabel.setText(status);
statusLabel.requestLayout();
}

/**
* Hide the messaging box and display the links after server set up.
*/
@SuppressWarnings("hiding")
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved
public void showOptions(Client client, Models models, Widgets widgets) {
this.client = client;
this.models = models;
this.widgets = widgets;

statusLabel.setVisible(false);
optionsContainer.setVisible(true);
if (models.settings.getRecent().length <= 0) {
removeRecentOption();
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* Initialize the links for layout settings. Hide them until server set up.
*/
private void createOptions() {
createLabel(optionsContainer, "", theme.add());
createLink(optionsContainer, "<a>Capture a new trace</a>", e -> {
showTracingDialog(checkNotNull(client), getShell(), checkNotNull(models), checkNotNull(widgets));
});
Label captureHint = createLabel(optionsContainer, (OS.isMac ? "\u2318" : "Ctrl") + " + T");
captureHint.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
captureHint.setForeground(theme.welcomeVersionColor());
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved

createLabel(optionsContainer, "", theme.open());
createLink(optionsContainer, "<a>Open an existing trace</a>", e -> {
showOpenTraceDialog(getShell(), checkNotNull(this.models));
});
Label openHint = createLabel(optionsContainer, (OS.isMac ? "\u2318" : "Ctrl") + " + O");
openHint.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
openHint.setForeground(theme.welcomeVersionColor());

recentIcon = createLabel(optionsContainer, "", theme.recent());
recentLink = createLink(optionsContainer, "<a>Open recent traces</a>", e -> {
Menu popup = new Menu(optionsContainer);
for (String file : checkNotNull(models).settings.recentFiles) {
createMenuItem(popup, file, 0, ev -> {
checkNotNull(models).analytics.postInteraction(View.Welcome, ClientAction.OpenRecent);
checkNotNull(models).capture.loadCapture(new File(file));
});
}
popup.addListener(SWT.Hide, ev -> scheduleIfNotDisposed(popup, popup::dispose));
popup.setLocation(optionsContainer.toDisplay(bottomLeft(((Link)e.widget).getBounds())));
popup.setVisible(true);
});
recentLink.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));

helpIcon = createLabel(optionsContainer, "", theme.help());
helpLink = createLink(optionsContainer, "<a>Help</a>", e -> showHelp(models.analytics));

optionsContainer.setVisible(false);
}

/**
* Remove the 'Open recent traces' option if there's no local trace opening history.
*/
private void removeRecentOption() {
// Replace the recent option with help option. (To avoid deleting widgets and unwanted layout changing.)
recentIcon.setImage(theme.help());
recentLink.setText("<a>Help</a>");
for (Listener l : recentLink.getListeners(SWT.Selection)) {
recentLink.removeListener(SWT.Selection, l);
}
recentLink.addListener(SWT.Selection, e -> showHelp(models.analytics));

helpIcon.setVisible(false);
helpLink.setVisible(false);
}
}
6 changes: 3 additions & 3 deletions gapic/src/main/com/google/gapid/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static com.google.gapid.util.GapidVersion.GAPID_VERSION;
import static com.google.gapid.views.ErrorDialog.showErrorDialog;
import static com.google.gapid.views.WelcomeDialog.showFirstTimeDialog;
import static com.google.gapid.views.WelcomeDialog.showWelcomeDialog;
import static com.google.gapid.widgets.Widgets.scheduleIfNotDisposed;

import com.google.common.base.Throwables;
Expand Down Expand Up @@ -147,8 +146,6 @@ private void uiStartup(Shell shell) {
Runnable onStart = () -> {
if (args.length == 1) {
models.capture.loadCapture(new File(args[0]));
} else if (!models.settings.skipWelcomeScreen) {
showWelcomeDialog(server.getClient(), window.getShell(), models, widgets);
}
};

Expand All @@ -158,6 +155,9 @@ private void uiStartup(Shell shell) {
} else {
shell.getDisplay().asyncExec(() -> showFirstTimeDialog(shell, models, widgets, onStart));
}

// Add the links on Loading Screen after the server set up.
window.updateLoadingScreen(server.getClient(), models, widgets);
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions gapic/src/main/com/google/gapid/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public void showLoadingMessage(String status) {
loadingScreen.setText(status);
}

public void updateLoadingScreen(Client client, Models models, Widgets widgets) {
this.loadingScreen.showOptions(client, models, widgets);
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved
}

public void initMainUi(Client client, Models models, Widgets widgets) {
Shell shell = getShell();

Expand Down
32 changes: 27 additions & 5 deletions gapic/src/main/com/google/gapid/views/AboutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.google.gapid.views;

import static com.google.gapid.util.GapidVersion.GAPID_VERSION;
import static com.google.gapid.widgets.Widgets.centered;
import static com.google.gapid.widgets.Widgets.createComposite;
import static com.google.gapid.widgets.Widgets.createLabel;
import static com.google.gapid.widgets.Widgets.createTextbox;
Expand All @@ -34,11 +33,17 @@

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

Expand All @@ -49,6 +54,7 @@
* Dialog showing some basic info about our application.
*/
public class AboutDialog {
protected static final Clipboard cb = new Clipboard(Display.getCurrent());
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved
private static final String HELP_URL = "https://google.github.io/gapid";
private static final Logger LOG = Logger.getLogger(AboutDialog.class.getName());

Expand Down Expand Up @@ -81,12 +87,28 @@ public String getTitle() {
protected Control createDialogArea(Composite parent) {
Composite area = (Composite)super.createDialogArea(parent);

Composite container = createComposite(area, centered(new RowLayout(SWT.VERTICAL)));
container.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.horizontalSpacing = 20;
gridLayout.verticalSpacing = 5;
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved
Composite container = createComposite(area, gridLayout);
container.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));

Label logo = createLabel(container, "", theme.dialogLogo());
logo.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false, 2, 1));

createLabel(container, "", theme.dialogLogo());
Text title = createForegroundLabel(container, Messages.WINDOW_TITLE);
title.setFont(theme.bigBoldFont());
title.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false, 2, 1));

createLabel(container, "").setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true, 2, 1));
Button clipboard = com.google.gapid.widgets.Widgets.createButton(container, "", e -> {
stellama0208 marked this conversation as resolved.
Show resolved Hide resolved
String textData = "Version " + GAPID_VERSION;
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[]{textData}, new Transfer[]{textTransfer});
});
clipboard.setImage(theme.clipboard());
clipboard.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, true, true, 1, 3));

createForegroundLabel(container, "Version " + GAPID_VERSION);
createForegroundLabel(
container, "Server: " + Info.getServerName() + ", Version: " + Info.getServerVersion());
Expand Down
5 changes: 5 additions & 0 deletions gapic/src/main/com/google/gapid/widgets/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@
* {@link Color colors}, etc.).
*/
public interface Theme {
@Icon(file = "add.png") public Image add();
@Icon(file = "android.png", color = 0x335577) public Image androidLogo();
@Icon(file = "arrow.png") public Image arrow();
@Icon(file = "arrow_drop_down.png") public Image arrowDropDownLight();
@Icon(file = "arrow_drop_right.png") public Image arrowDropRightLight();
@Icon(file = "arrow_drop_down.png", color = 0xFFFFFF) public Image arrowDropDownDark();
@Icon(file = "arrow_drop_right.png", color = 0xFFFFFF) public Image arrowDropRightDark();
@Icon(file = "clipboard.png") public Image clipboard();
@Icon(file = "color_buffer0.png") public Image colorBuffer0();
@Icon(file = "color_buffer1.png") public Image colorBuffer1();
@Icon(file = "color_buffer2.png") public Image colorBuffer2();
Expand All @@ -72,16 +74,19 @@ public interface Theme {
@Icon(file = "flat.png") public Image flat();
@Icon(file = "flip_vertically.png") public Image flipVertically();
@Icon(file = "jump.png") public Image jump();
@Icon(file = "help.png") public Image help();
@Icon(file = "histogram.png") public Image toggleHistogram();
@Icon(file = "lit.png") public Image lit();
@Icon(file = "logo_128.png") public Image dialogLogo();
@Icon(file = "normals.png") public Image normals();
@Icon(file = "open.png") public Image open();
@Icon(file = "overdraw.png") public Image overdraw();
@Icon(file = "point_cloud.png") public Image pointCloud();
@Icon(file = "range_start.png") public Image rangeStartLight();
@Icon(file = "range_end.png") public Image rangeEndLight();
@Icon(file = "range_start.png", color = 0xFFFFFF) public Image rangeStartDark();
@Icon(file = "range_end.png", color = 0xFFFFFF) public Image rangeEndDark();
@Icon(file = "recent.png") public Image recent();
@Icon(file = "refresh.png") public Image refresh();
@Icon(file = "save.png") public Image save();
@Icon(file = "settings.png") public Image settings();
Expand Down