Skip to content

fix: visible string 'spacer' in about dialog when using Nimbus LAF #89

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

Merged
merged 1 commit into from
Mar 2, 2014
Merged
Changes from all 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
78 changes: 36 additions & 42 deletions src/main/java/com/tagtraum/perf/gcviewer/AboutDialog.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.tagtraum.perf.gcviewer;

import com.tagtraum.perf.gcviewer.util.BuildInfoReader;
import com.tagtraum.perf.gcviewer.util.LocalisationHelper;
import com.tagtraum.perf.gcviewer.util.UrlDisplayHelper;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
Expand All @@ -19,26 +22,17 @@
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;

import com.tagtraum.perf.gcviewer.util.BuildInfoReader;
import com.tagtraum.perf.gcviewer.util.LocalisationHelper;
import com.tagtraum.perf.gcviewer.util.UrlDisplayHelper;

/**
* About dialog showing version and contributors information.
*
*
* @author Hendrik Schreiber
* @author <a href="mailto:[email protected]">Joerg Wuethrich</a>
*/
public class AboutDialog extends ScreenCenteredDialog implements ActionListener {

private static final String GCVIEWER_HOMEPAGE = "https://github.com/chewiebug/gcviewer/wiki";

private static final String ACTION_OK = "ok";
private static final String ACTION_HOMEPAGE = "homepage";

private JButton homePageButton;
private JButton okButton;


private static final String[] CONTRIBUTORS = {
"Hans Bausewein",
"Peter Bilstein",
Expand Down Expand Up @@ -69,53 +63,52 @@ public AboutDialog(Frame f) {
JPanel versionPanel = new JPanel();
versionPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
versionPanel.setLayout(new GridBagLayout());

JLabel copyright = new JLabel("\u00A9" + " 2011-2013: Joerg Wuethrich", JLabel.CENTER);

JLabel contributorsLabel = new JLabel("contributors (alphabetically ordered):", JLabel.CENTER);
contributorsLabel.setForeground(Color.GRAY);
JLabel contributors = new JLabel(formatContributors(CONTRIBUTORS), JLabel.CENTER);
contributors.setPreferredSize(calculatePreferredSize(contributors, true, logoIcon.getIconWidth()));

JLabel version = new JLabel("<html><font color=\"gray\">version:</font> " + BuildInfoReader.getVersion() + "</html>", JLabel.CENTER);
JLabel buildDate = new JLabel("<html><font color=\"gray\">build date:</font> " + BuildInfoReader.getBuildDate() + "</html>", JLabel.CENTER);

JLabel spacer1 = new JLabel("spacer");
spacer1.setForeground(getBackground());
JLabel spacer2 = new JLabel("spacer");
spacer2.setForeground(getBackground());

GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.anchor = GridBagConstraints.NORTH;
gridBagConstraints.fill = GridBagConstraints.VERTICAL;
gridBagConstraints.gridx = 0;

Insets insetsGapOnTop = new java.awt.Insets(10, 0, 0, 0);
GridBagConstraints gridBagConstraintsGapOnTop = new GridBagConstraints();

versionPanel.add(copyright, gridBagConstraints);
gridBagConstraints.gridy = 1;
versionPanel.add(spacer1, gridBagConstraints);

gridBagConstraintsGapOnTop.gridy = 1;
gridBagConstraintsGapOnTop.insets = insetsGapOnTop;
versionPanel.add(contributorsLabel, gridBagConstraintsGapOnTop);

gridBagConstraints.gridy = 2;
versionPanel.add(contributorsLabel, gridBagConstraints);
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
versionPanel.add(contributors, gridBagConstraints);
gridBagConstraints.gridy = 4;
gridBagConstraints.fill = GridBagConstraints.VERTICAL;
versionPanel.add(spacer2, gridBagConstraints);
gridBagConstraints.gridy = 5;
versionPanel.add(version, gridBagConstraints);
gridBagConstraints.gridy = 6;

gridBagConstraintsGapOnTop.gridy = 3;
versionPanel.add(version, gridBagConstraintsGapOnTop);

gridBagConstraints.gridy = 4;
versionPanel.add(buildDate, gridBagConstraints);

Panel buttonPanel = new Panel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
if (UrlDisplayHelper.displayUrlIsSupported()) {
homePageButton = new JButton("Homepage");
JButton homePageButton = new JButton("Homepage");
homePageButton.setActionCommand(ACTION_HOMEPAGE);
homePageButton.addActionListener(this);
buttonPanel.add(homePageButton);
}

okButton = new JButton(LocalisationHelper.getString("button_ok"));
JButton okButton = new JButton(LocalisationHelper.getString("button_ok"));
okButton.setActionCommand(ACTION_OK);
okButton.addActionListener(this);
buttonPanel.add(okButton);
Expand All @@ -132,34 +125,35 @@ private String formatContributors(String[] contributors) {
for (String contributor : contributors) {
sb.append(contributor).append(" | ");
}

sb.delete(sb.length() - 3, sb.length());

sb.append("</center></html>");

return sb.toString();
}

/**
* Returns the preferred size to set a component at in order to render
* an html string. You can specify the size of one dimension.
*
*
* @see http://blog.nobel-joergensen.com/2009/01/18/changing-preferred-size-of-a-html-jlabel/
*/
private Dimension calculatePreferredSize(JLabel labelWithHtmlText, boolean width, int preferredSize) {

View view = (View) labelWithHtmlText.getClientProperty(BasicHTML.propertyKey);
view.setSize(width ? preferredSize : 0,

view.setSize(width ? preferredSize : 0,
width ? 0 : preferredSize);

float w = view.getPreferredSpan(View.X_AXIS);
float h = view.getPreferredSpan(View.Y_AXIS);

return new Dimension((int) Math.ceil(w),
(int) Math.ceil(h));
}

@Override
public void actionPerformed(ActionEvent e) {
if (ACTION_HOMEPAGE.equals(e.getActionCommand())) {
UrlDisplayHelper.displayUrl(this, GCVIEWER_HOMEPAGE);
Expand Down