Issue#36 improved AboutDialog

This commit is contained in:
Didier Clermonté 2016-07-06 23:05:54 +02:00
parent f4aedd64cc
commit 8bf453577b
4 changed files with 79 additions and 28 deletions

View File

@ -21,19 +21,17 @@ package org.dclermonte.siba.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ResourceBundle;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
@ -52,7 +50,6 @@ import org.slf4j.LoggerFactory;
public class AboutDialog extends JDialog
{
private static final long serialVersionUID = 8868109575782482455L;
private static ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
public static final Logger logger = LoggerFactory.getLogger(AboutDialog.class);
/**
@ -62,6 +59,7 @@ public class AboutDialog extends JDialog
*/
public AboutDialog() throws IOException
{
setMinimumSize(new Dimension(600, 350));
setMaximumSize(new Dimension(600, 500));
setIconImage(Toolkit.getDefaultToolkit()
@ -73,10 +71,12 @@ public class AboutDialog extends JDialog
{
JPanel buttonPane = new JPanel();
buttonPane.setBackground(Color.GREEN);
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setFocusTraversalKeysEnabled(false);
okButton.setFocusPainted(false);
okButton.setBackground(new Color(0, 128, 0));
okButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
okButton.addActionListener(new ActionListener()
{
@ -87,10 +87,19 @@ public class AboutDialog extends JDialog
dispose();
}
});
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
{
Component horizontalGlue = Box.createHorizontalGlue();
buttonPane.add(horizontalGlue);
}
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
Component horizontalGlue = Box.createHorizontalGlue();
buttonPane.add(horizontalGlue);
}
}
JPanel panel = new JPanel();
panel.setBackground(Color.GREEN);
@ -101,23 +110,7 @@ public class AboutDialog extends JDialog
txtpnSimpleBackupDveloppeur.setBackground(Color.GREEN);
txtpnSimpleBackupDveloppeur.setFont(new Font("Dialog", Font.BOLD, 14));
txtpnSimpleBackupDveloppeur.setContentType("text/html");
String path = System.getProperty("user.dir");
String about = BUNDLE.getString("AboutDialog");
File aboutFile = new File(path + "/src/org/dclermonte/siba/gui/" + about);
FileReader in = new FileReader(aboutFile);
BufferedReader bufferedReader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();
String lines;
String line;
while ((line = bufferedReader.readLine()) != null)
{
stringBuilder.append(line);
}
lines = stringBuilder.toString();
txtpnSimpleBackupDveloppeur.setText(lines);
System.out.println("texte = " + lines);
// "Simple Backup\n\nDéveloppeur Christian Pierre Momon et Didier
// Clermonté\n\nLicence GNU Affero General Public License 2016");
txtpnSimpleBackupDveloppeur.setText(AboutDialogUtils.aboutDialog());
panel.add(txtpnSimpleBackupDveloppeur);
{
JLabel lblNewLabel = new JLabel("");
@ -125,12 +118,13 @@ public class AboutDialog extends JDialog
.setIcon(new ImageIcon(AboutDialog.class.getResource("/org/dclermonte/siba/gui/SibaLogo_256.png")));
panel.add(lblNewLabel, BorderLayout.WEST);
}
}
/**
* This method Launch the application.
*/
public static void main(final String string)
public static void view(final String string)
{
try
{

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
*
* This file is part of Siba.
*
* Siba is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.dclermonte.siba.gui;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ResourceBundle;
import org.apache.commons.io.FileUtils;
/**
*
* @author Didier Clermonté (dclermonte@april.org)
*
*/
public class AboutDialogUtils
{
private static ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
/**
*
* @return
* @throws IOException
*/
public static String aboutDialog() throws IOException
{
String result = null;
String about = BUNDLE.getString("AboutDialog");
File aboutFile = new File(AboutDialog.class.getResource("/org/dclermonte/siba/gui/" + about).getFile());
result = FileUtils.readFileToString(aboutFile, (Charset) null);
return result;
}
}

View File

@ -61,9 +61,9 @@ public class CheckPanel extends JPanel
private JTextField fileToCheckField;
/**
*
*
*/
public CheckPanel()
public CheckPanel() throws SibaException
{
setLayout(new BorderLayout(0, 0));

View File

@ -94,6 +94,10 @@ public class SibaGUI
{
message = "Java ran out of memory!\n\n";
}
else if (exception instanceof SibaException)
{
message = "SibaException" + exception.getMessage();
}
else
{
message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")";
@ -269,7 +273,7 @@ public class SibaGUI
@Override
public void actionPerformed(final ActionEvent e)
{
AboutDialog.main("");
AboutDialog.view("");
}
});
mnNewMenu.add(mntmNewMenuItem_2);