Skip to content

Commit

Permalink
The content of the 'About' dialog can now be copied to the system cli…
Browse files Browse the repository at this point in the history
…pboard
  • Loading branch information
hbitteur committed May 24, 2024
1 parent 8b76b23 commit e16a1ca
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 22 deletions.
96 changes: 78 additions & 18 deletions app/src/main/java/org/audiveris/omr/ui/AboutAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@
import com.jgoodies.forms.layout.FormLayout;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.net.URI;
Expand Down Expand Up @@ -73,8 +77,8 @@ public class AboutAction
private static final Logger logger = LoggerFactory.getLogger(AboutAction.class);

// Resource injection
private static final ResourceMap resources = Application.getInstance().getContext()
.getResourceMap(AboutAction.class);
private static final ResourceMap resources =
Application.getInstance().getContext().getResourceMap(AboutAction.class);

//~ Instance fields ----------------------------------------------------------------------------

Expand All @@ -97,11 +101,36 @@ public void actionPerformed (ActionEvent e)
aboutBox = createAboutBox();
}

JOptionPane.showMessageDialog(
final Object[] options =
{ "OK", "Copy" };

final int choice = JOptionPane.showOptionDialog(
OMR.gui.getFrame(),
aboutBox,
resources.getString("AboutDialog.title"),
JOptionPane.INFORMATION_MESSAGE);
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
options,
options[0]);
System.out.println("choice: " + choice);

if (choice == 1) {
copyToClipBoard();
}
}

//-----------------//
// copyToClipBoard //
//-----------------//
private void copyToClipBoard ()
{
final String str = getContents();
final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
final StringSelection strSel = new StringSelection(str);
clip.setContents(strSel, strSel);
JOptionPane
.showMessageDialog(OMR.gui.getFrame(), resources.getString("AboutDialog.copied"));
}

//----------------//
Expand Down Expand Up @@ -201,21 +230,56 @@ private JPanel createAboutBox ()
((JLabel) Topic.javaVersion.comp).setText(System.getProperty("java.version"));

((JLabel) Topic.javaRuntime.comp).setText(
System.getProperty("java.runtime.name") + " (build " + System.getProperty(
"java.runtime.version") + ")");
System.getProperty("java.runtime.name") + " (build "
+ System.getProperty("java.runtime.version") + ")");

((JLabel) Topic.javaVm.comp).setText(
System.getProperty("java.vm.name") + " (build " + System.getProperty(
"java.vm.version") + ", " + System.getProperty("java.vm.info") + ")");
System.getProperty("java.vm.name") + " (build "
+ System.getProperty("java.vm.version") + ", "
+ System.getProperty("java.vm.info") + ")");

((JLabel) Topic.os.comp).setText(
System.getProperty("os.name") + " " + System.getProperty("os.version"));
((JLabel) Topic.os.comp)
.setText(System.getProperty("os.name") + " " + System.getProperty("os.version"));

((JLabel) Topic.osArch.comp).setText(System.getProperty("os.arch"));

return panel;
}

//-------------//
// getContents //
//-------------//
/**
* Build the textual content of the panel.
*
* @return the panel content as a single string with line breaks
*/
private String getContents ()
{
final StringBuilder sb = new StringBuilder();

for (Component comp : aboutBox.getComponents()) {
switch (comp) {
case JLabel label -> {
final String text = label.getText();
sb.append(text);
sb.append(text.endsWith(":") ? " " : WellKnowns.LINE_SEPARATOR);
}
case JEditorPane pane -> {
if (pane == Topic.home.comp) {
sb.append(resources.getString("Application.homepage"));
} else if (pane == Topic.project.comp) {
sb.append(resources.getString("Application.projectpage"));
}
sb.append(WellKnowns.LINE_SEPARATOR);
}
default -> {}
}
}

return sb.toString();
}

//~ Inner Classes ------------------------------------------------------------------------------

//-----------//
Expand All @@ -225,15 +289,11 @@ private static class Constants
extends ConstantSet
{

private final Constant.Integer titleFontSize = new Constant.Integer(
"Points",
14,
"Font size for title in about box");
private final Constant.Integer titleFontSize =
new Constant.Integer("Points", 14, "Font size for title in about box");

private final Constant.Integer urlFontSize = new Constant.Integer(
"Points",
10,
"Font size for URL in about box");
private final Constant.Integer urlFontSize =
new Constant.Integer("Points", 10, "Font size for URL in about box");
}

//------------//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# ----------------------

AboutDialog.title = About ${Application.name}
AboutDialog.copied = Content copied to clipboard!

aboutTitleLabel.text = ${Application.name}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,27 @@
# ----------------------

AboutDialog.title = A propos d'${Application.name}
homeLabel.text = Site Web:
AboutDialog.copied = Contenu copi\u00e9 dans le presse-papiers !

licenseLabel.text = Licence:
descriptionLabel.text = R\u00f4le :

ocrLabel.text = Moteur OCR:
ocrFolder.text = Donn\u00e9es OCR:
versionLabel.text = Version :

classesLabel.text = Conteneur:

homeLabel.text = Site Web :

projectLabel.text = Projet :

licenseLabel.text = Licence du logiciel :

ocrLabel.text = Moteur OCR :
ocrFolder.text = Donn\u00e9es OCR :

javaVendorLabel.text = Fournisseur Java :
javaVersionLabel.text = Version Java :
javaRuntimeLabel.text = Runtime java :
javaVmLabel.text = Machine virtuelle Java :

osLabel.text = Syst\u00e8me d'exploitation :
osArchLabel.text = Architecture :

0 comments on commit e16a1ca

Please sign in to comment.