pcGenGUI.java

Index Score
pcgen.gui
PCGen

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
EXITSProcedure exits
LOGICAL_LINESNumber of statements
UNIQUE_OPERANDSNumber of unique operands
LOCLines of code
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
PROGRAM_VOCABHalstead program vocabulary
ELOCEffective lines of code
SIZESize of the file in bytes
LINESNumber of lines in the source file
EXEC_COMMENTSComments in executable code
LINE_COMMENTNumber of line comments
BLOCKSNumber of blocks
CYCLOMATICCyclomatic complexity
JAVA0034JAVA0034 Missing braces in if statement
JAVA0166JAVA0166 Generic exception caught
JAVA0144JAVA0144 Line exceeds maximum M characters
COMPARISONSNumber of comparison operators
JAVA0145JAVA0145 Tab character used in source file
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0076JAVA0076 Use of magic number
FUNCTIONSNumber of function declarations
JAVA0130JAVA0130 Non-static method does not use instance fields
RETURNSNumber of return points from functions
PROGRAM_VOLUMEHalstead program volume
WHITESPACENumber of whitespace lines
UNIQUE_OPERATORSNumber of unique operators
INTERFACE_COMPLEXITYInterface complexity
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0265JAVA0265 Use of Throwable.printStackTrace()
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0267JAVA0267 Use of System.err
LOOPSNumber of loops
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
/* * pcGenGUI.java * Copyright 2001 (C) Bryan McRoberts <merton_monk@yahoo.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Created on April 21, 2001, 2:15 PM */ package pcgen.gui; import gmgen.pluginmgr.PluginLoader; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URI; import java.util.List; import java.util.Map; import java.util.Observer; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JEditorPane; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.UIManager; import pcgen.cdom.base.Constants; import pcgen.core.Globals; import pcgen.core.PlayerCharacter; import pcgen.core.SettingsHandler; import pcgen.core.party.Party; import pcgen.core.utils.MessageType; import pcgen.core.utils.MessageWrapper; import pcgen.core.utils.ShowMessageConsoleObserver; import pcgen.core.utils.ShowMessageDelegate; import pcgen.gui.utils.DialogInputInterface; import pcgen.gui.utils.Hyperactive; import pcgen.gui.utils.IconUtilitities; import pcgen.gui.utils.NonGuiChooser; import pcgen.gui.utils.NonGuiChooserRadio; import pcgen.gui.utils.ShowMessageGuiObserver; import pcgen.gui.utils.SwingChooser; import pcgen.gui.utils.SwingChooserRadio; import pcgen.gui.utils.SwingChooserUserInput; import pcgen.gui.utils.Utility; import pcgen.io.ExportHandler; import pcgen.io.PCGFile; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.LstFileLoader; import pcgen.persistence.lst.SponsorLoader; import pcgen.util.InputFactory; import pcgen.util.Logging; import pcgen.util.chooser.ChooserFactory; /** * <code>pcGenGUI</code> is the Main-Class for the application. * It creates an unreferenced copy of itself, basically so that * the constructor code is run. * * @author Bryan McRoberts <merton_monk@users.sourceforge.net> * @version $Revision: 6206 $ */ public class pcGenGUI { private static SplashScreen splash; private static String templateName = ""; private static String inFileName = ""; private static String outFileName = ""; private static boolean partyMode = false; private static String[] startupArgs = { }; /** Instantiated popup frame {@link HPFrame}. */ private static HPFrame hpFrame = null; private PCGen_Frame1 frame; /** * Unknown. Doesn't appear to have a useful function. Kind of a * debug argument, this decides whether the main frame is * packed or validated. The value is only set to false, so * this means the choice is always validate. */ private boolean packFrame = false; /** * Initialises the application and loads the main * screen. It uses some system properties for parameters, and calls * {@link pcgen.persistence.PersistenceManager#initialize PersistenceManager.initialize} to load the * required campaign and configuration files. Finally the main * screen of the application is created, * {@link pcgen.gui.PCGen_Frame1 PCGen_Frame1}. * <p> * Some of the logic of the program initialisation should probably * be refactored into the core package. */ public pcGenGUI(Dimension d) { if (Globals.getUseGUI()) { macSpecificInit(); ChooserFactory.setInterfaceClassname(SwingChooser.class.getName()); ChooserFactory.setRadioInterfaceClassname(SwingChooserRadio.class .getName()); ChooserFactory.setUserInputInterfaceClassname(SwingChooserUserInput.class .getName()); InputFactory.setInterfaceClassname(DialogInputInterface.class .getName()); } else { ChooserFactory.setInterfaceClassname(NonGuiChooser.class.getName()); ChooserFactory.setRadioInterfaceClassname(NonGuiChooserRadio.class .getName()); ChooserFactory.setUserInputInterfaceClassname(NonGuiChooser.class .getName()); } // If we are not using the GUI then just load, export and exit if (!Globals.getUseGUI()) { runNonGui(); return; } // If we get here then we are running with a GUI frame = new PCGen_Frame1(); frame.setMainClass(this); // if on Mac then set the Frame so the Application menu will work // tmilam 21 Jan 2006 if (System.getProperty("os.name").equals("Mac OS X")) { try { Class[] cargs = new Class[]{PCGen_Frame1.class}; Object[] oargs = new Object[]{frame}; Class.forName("pcgen.gui.MacGUI").getDeclaredMethod("setPCGenFrame", cargs).invoke(null, oargs); } catch (ClassNotFoundException e) { // don't do anything, just default to standard Java style } catch (NoSuchMethodException e) { // don't do anything, just default to standard Java style } catch (IllegalAccessException e) { // don't do anything, just default to standard Java style } catch (java.lang.reflect.InvocationTargetException e) { // don't do anything, just default to standard Java style } } //Validate frames that have preset sizes //Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack(); } else { frame.validate(); } int x = -11; int y = -11; if (SettingsHandler.getLeftUpperCorner() != null) { x = (int) SettingsHandler.getLeftUpperCorner().getX(); y = (int) SettingsHandler.getLeftUpperCorner().getY(); } if ((x < -10) || (y < -10) || (d.height == 0) || (d.width == 0)) { frame.setSize(new Dimension(1020, 716)); Utility.centerFrame(frame, false); } else { frame.setLocation(x, y); frame.setSize(d); } //Read the maximized information from the options (1.4 ONLY!!!) int windowState = SettingsHandler.getWindowState(); if (windowState != Frame.NORMAL) { frame.setExtendedState(windowState); } UIFactory.initLookAndFeel(); frame.resetUI(); processStartupArgs(); hideSplashScreen(); // These can't be handled before the main frame exists SettingsHandler.readGUIOptionsProperties(); Utility.handleToolTipShownStateChange(); PCGen_Frame1.enableDisableMenuItems(); frame.setVisible(true); if (SettingsHandler.getShowTipOfTheDay()) { showTipOfTheDay(); } } /** * Test if we are running on Mac OS X, and if so do some Mac * specific intialization. */ private static void macSpecificInit() { // Fixes for Mac OS X look-and-feel menu problems. // sk4p 12 Dec 2002 // Moved into separate class // tmilam 21 Jan 2006 if (System.getProperty("os.name").equals("Mac OS X")) { try { Class.forName("pcgen.gui.MacGUI").getDeclaredMethod("initialize", (Class[])null).invoke((Object[]) null, (Object[])null); } catch (ClassNotFoundException e) { // don't do anything, just default to standard Java style System.out.println("This build of PCGen doesn't include Mac-enhanced features. Try the Mac build for a more Mac-like interface."); } catch (NoSuchMethodException e) { // don't do anything, just default to standard Java style } catch (IllegalAccessException e) { // don't do anything, just default to standard Java style } catch (java.lang.reflect.InvocationTargetException e) { // don't do anything, just default to standard Java style } } } /** * Run PCGen in non GUI mode. This means we just load the PC and export * it, then exit. */ private void runNonGui() { PlayerCharacter pc = runNonGuiLoad(new File(inFileName)); if (pc != null && (templateName != null) && (outFileName != null)) { runNonGuiExport(pc); } } /** * Perform the export part of a non-gui invocation. * This method will take the pre-loaded character(s) * and export them using the ouputsheet specified on the * command line. * @param pc */ private void runNonGuiExport(PlayerCharacter pc) { try { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFileName), "UTF-8")); final File template = new File(templateName); if (partyMode) { SettingsHandler.setSelectedPartyHTMLOutputSheet(template.getAbsolutePath()); (new ExportHandler(template)).write(Globals.getPCList(), bw); } else { SettingsHandler.setSelectedCharacterHTMLOutputSheet(template.getAbsolutePath(), pc); (new ExportHandler(template)).write(pc, bw); } bw.close(); } catch (Exception ex) { Logging.errorPrint("Exception in writing", ex); } Globals.executePostExportCommandStandard(outFileName); } /** * Load the character or characters specified in the file. * * @param file * The File object pointing to the file on disk that is to be * loaded. This can either be a '*.pcg' file for a single * character or a '*.pcp' for a party * @return True if the character or party loads sucessfully */ private PlayerCharacter runNonGuiLoad(File file) { Party party; if (partyMode) { party = Party.makePartyFromFile(file); } else { party = Party.makeSingleCharacterParty(file); } PlayerCharacter pc = party.load(null); if (pc == null) { //todo: i18n these messages ShowMessageDelegate.showMessageDialog(new MessageWrapper("Problems occurred while loading the file:" + file.getName(), "Error", MessageType.ERROR)); } return pc; } /** * Instantiates itself after setting look & feel, and * opening splash screen. Warning - this method should * avoid any calls which are internationalised, as this would * lock in the system default language before the user * options are loaded. * * @param args "-j" If first command line parameter is -j then the cross * platform look and feel is used. Otherwise the current * system is used (i.e. native L&F). This is a hidden * option :-) */ public static void main(String[] args) { templateName = System.getProperty("pcgen.templatefile"); inFileName = System.getProperty("pcgen.inputfile"); outFileName = System.getProperty("pcgen.outputfile"); startupArgs = args; if (inFileName != null) { partyMode = PCGFile.isPCGenPartyFile(new File(inFileName)); Globals.setUseGUI(false); } Observer messageObserver = null; if (Globals.getUseGUI()) { // need to set Mac GUI props before any other GUI stuff // tmilam 21 Jan 2006 macSpecificInit(); messageObserver = new ShowMessageGuiObserver(); } else { messageObserver = new ShowMessageConsoleObserver(); } ShowMessageDelegate.getInstance().addObserver(messageObserver); // // Ensure we are using the correct version of the run-time environment. // If not, inform the user, but still allow him to use the program // // Might want to be able to turn this message off at some point. // i.e. Don't show this again checkbox // try { final String sVersion = System.getProperty("java.version"); if (Double.valueOf(Globals.javaVersion.substring(0, 3)).doubleValue() < 1.5) { ShowMessageDelegate.showMessageDialog(new MessageWrapper( "PCGen requires Java 2 v1.5 or higher.\nYour version of java is currently " + sVersion + ".\n" + "To be able to run PCGen properly you will need:\n" + " * The Java 2 runtime environment available from\n" + " http://java.sun.com/javase/index.jsp\n\n" + "You'll need to pick the version of java appropriate for your\n" + "OS (the choices are Solaris/SPARC, Linux and Windows).", "PCGen", MessageType.INFORMATION)); } } catch (Exception e) { //Don't care? } try { if (Globals.getUseGUI()) // only set L&F if we're going to use a GUI { if ((args.length > 0) && args[0].equals("-j")) { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } else { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } } catch (Exception e) { //Hardly a fatal error, and quite unlikely at that... Logging.errorPrint("Couldn't set look and feel", e); } if (Globals.getUseGUI() && !(args.length > 0 && args[0].equals("--nosplash"))) { showSplashScreen(); } Dimension d = null; try { if (SettingsHandler.getFirstRun()) { if (Globals.getUseGUI()) { hideSplashScreen(); askFileLocation(); } } SettingsHandler.readOptionsProperties(); d = SettingsHandler.getOptionsFromProperties(null); } catch (Exception e) { e.printStackTrace(System.err); String message = e.getMessage(); if ((message == null) || (message.length() == 0)) { message = "Unknown error whilst reading options.ini"; } message += "\n\nIt MAY be possible to fix this problem by deleting your options.ini file."; ShowMessageDelegate.showMessageDialog(new MessageWrapper(message, "PCGen - Error processing Options.ini", MessageType.ERROR)); if (Globals.getUseGUI()) { hideSplashScreen(); } System.exit(0); } PluginLoader ploader = PluginLoader.inst(); ploader.startSystemPlugins(Constants.s_SYSTEM_TOKENS); SettingsHandler.initGameModes(); new pcGenGUI(d); } public static void showHpFrame(PlayerCharacter aPC) { initHpFrame(aPC); hpFrame.setPSize(); hpFrame.pack(); hpFrame.setVisible(true); } public static void showLicense() { String aString = " "; aString += readTextFromFile(SettingsHandler.getPcgenSystemDir() + File.separator + "opengaminglicense.10a.txt"); if (Globals.getSection15() != null) { aString += Globals.getSection15().toString(); } showLicense("OGL License 1.0a", aString); } public static void showMature(String text) { Logging.errorPrint("Warning: The following datasets contains mature themes. User discretion is advised."); Logging.errorPrint(text); final JFrame aFrame = new JFrame("Maturity Warning"); final JPanel jPanel1 = new JPanel(); final JPanel jPanel2 = new JPanel(); final JPanel jPanel3 = new JPanel(); final JLabel jLabel1 = new JLabel("Warning: The following datasets contains mature themes.", SwingConstants.CENTER); final JLabel jLabel2 = new JLabel("User discretion is advised.", SwingConstants.CENTER); final JCheckBox jCheckBox1 = new JCheckBox("Show on source load"); final JButton jClose = new JButton("Close"); jPanel1.setLayout(new BorderLayout()); jPanel1.add(jLabel1, BorderLayout.NORTH); jPanel1.add(jLabel2, BorderLayout.SOUTH); jPanel2.setLayout(new BorderLayout()); aFrame.getContentPane().add(jPanel1, BorderLayout.NORTH); aFrame.getContentPane().add(jPanel2, BorderLayout.CENTER); aFrame.getContentPane().add(jPanel3, BorderLayout.SOUTH); final JEditorPane a = new JEditorPane("text/html", text); a.setEditable(false); final JScrollPane aPane = new JScrollPane(); aPane.setViewportView(a); jPanel2.add(aPane, BorderLayout.CENTER); jPanel3.add(jCheckBox1); jPanel3.add(jClose); jCheckBox1.setSelected(SettingsHandler.showMature()); jClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aFrame.dispose(); } }); jCheckBox1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { SettingsHandler.setShowMature(jCheckBox1.isSelected()); } }); aFrame.setSize(new Dimension(456, 176)); Utility.centerFrame(aFrame, false); aFrame.setVisible(true); } public static void showLicense(String title, List<URI> fileList) { for (URI licenseFile : fileList) { try { StringBuilder dataBuffer = LstFileLoader.readFromURI(licenseFile); showLicense(title, dataBuffer.toString()); } catch (PersistenceLayerException e) { Logging.errorPrint("Could not read license at " + licenseFile, e); } } } public static void showLicense(String title, String text) { if (title == null) { title = "OGL License 1.0a"; } if (text == null) { text = "No license information found"; } final JFrame aFrame = new JFrame(title); final JButton jClose = new JButton("Close"); final JPanel jPanel = new JPanel(); final JCheckBox jCheckBox = new JCheckBox("Show on source load"); jPanel.add(jCheckBox); jCheckBox.setSelected(SettingsHandler.showLicense()); jCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { SettingsHandler.setShowLicense(jCheckBox.isSelected()); } }); jPanel.add(jClose); jClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aFrame.dispose(); } }); IconUtilitities.maybeSetIcon(aFrame, IconUtilitities.RESOURCE_APP_ICON); final JEditorPane a = new JEditorPane("text/html", text); a.setEditable(false); final JScrollPane aPane = new JScrollPane(); aPane.setViewportView(a); aFrame.getContentPane().setLayout(new BorderLayout()); aFrame.getContentPane().add(aPane, BorderLayout.CENTER); aFrame.getContentPane().add(jPanel, BorderLayout.SOUTH); aFrame.setSize(new Dimension(700, 500)); Utility.centerFrame(aFrame, false); aFrame.setVisible(true); } public static void showSponsors() { if (Globals.getSponsors().size() <= 1) { return; } String title = "PCGen's sponsors"; final JFrame aFrame = new JFrame(title); final JButton jClose = new JButton("Close"); final JPanel jPanel = new JPanel(); final JCheckBox jCheckBox = new JCheckBox("Show on source load"); jPanel.add(jCheckBox); jCheckBox.setSelected(SettingsHandler.showSponsors()); jCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { SettingsHandler.setShowSponsors(jCheckBox.isSelected()); } }); jPanel.add(jClose); jClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aFrame.dispose(); } }); IconUtilitities.maybeSetIcon(aFrame, IconUtilitities.RESOURCE_APP_ICON); StringBuffer sb = new StringBuffer(); sb.append("<html>"); sb.append("<img src='") .append(SponsorLoader.getConvertedSponsorPath(Globals.getSponsor("PCGEN").get("IMAGEBANNER"))) .append("'><br>"); String s = ""; if(Globals.getSponsors().size() > 2) { s = "s"; } sb.append("<H2><CENTER>Would like to thank our official sponsor") .append(s) .append(":</CENTER></h2>"); List<Map<String, String>> sponsors = Globals.getSponsors(); int size = 172; for(int i = 0; i < sponsors.size(); i++) { Map<String, String> sponsor = sponsors.get(i); if(sponsor.get("SPONSOR").equals("PCGEN")) { continue; } size += 70; sb.append("<img src='") .append(SponsorLoader.getConvertedSponsorPath(sponsor.get("IMAGEBANNER"))) .append("'><br>"); } sb.append("</html>"); final JEditorPane a = new JEditorPane("text/html", sb.toString()); a.setEditable(false); final JScrollPane aPane = new JScrollPane(); aPane.setViewportView(a); aFrame.getContentPane().setLayout(new BorderLayout()); aFrame.getContentPane().add(aPane, BorderLayout.CENTER); aFrame.getContentPane().add(jPanel, BorderLayout.SOUTH); aFrame.setSize(new Dimension(505, size)); Utility.centerFrame(aFrame, false); aFrame.setVisible(true); } public static void showMandatoryD20Info() { final ImageIcon imgIcon = IconUtilitities.getImageIcon("D20_logo_RGB.jpg"); if (imgIcon != null) { final JFrame aFrame = new JFrame("D20 Required Information"); IconUtilitities.maybeSetIcon(aFrame, IconUtilitities.RESOURCE_APP_ICON); final JPanel jPanel1 = new JPanel(); final JPanel jPanel2 = new JPanel(); final JPanel jPanel3 = new JPanel(); final JLabel jLabel1 = new JLabel(imgIcon); final JCheckBox jCheckBox1 = new JCheckBox("Show on source load"); final JButton jClose = new JButton("Close"); jPanel1.add(jLabel1); jPanel2.setLayout(new BorderLayout()); aFrame.getContentPane().add(jPanel1, BorderLayout.NORTH); aFrame.getContentPane().add(jPanel2, BorderLayout.CENTER); aFrame.getContentPane().add(jPanel3, BorderLayout.SOUTH); String d20License = readTextFromFile(SettingsHandler.getPcgenSystemDir() + File.separator + "D20System.htm"); final JEditorPane a = new JEditorPane("text/html", d20License); a.setEditable(false); a.addHyperlinkListener(new Hyperactive()); final JScrollPane aPane = new JScrollPane(); aPane.setViewportView(a); jPanel2.add(aPane, BorderLayout.CENTER); jPanel3.add(jCheckBox1); jPanel3.add(jClose); jCheckBox1.setSelected(SettingsHandler.showD20Info()); jClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aFrame.dispose(); } }); jCheckBox1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { SettingsHandler.setShowD20Info(jCheckBox1.isSelected()); } }); aFrame.setSize(new Dimension(456, 352)); Utility.centerFrame(aFrame, false); aFrame.setVisible(true); } } public static void showTipOfTheDay() { new TipOfTheDay().setVisible(true); } private static void askFileLocation() { final Object[] oOk = { "OK" }; final JLabel aLabel = new JLabel( "<html>Select a directory to store PCGen options in:<hr><b>PCGen Dir</b>: This is the directory that PCGen is installed into (default)<br><b>Home Dir</b>: This is your home directory<br><b>Select</b>: Select a directory to use <br>If you have an existing options.ini file, then select the directory containing that file<hr>"); final JPanel aPanel = new JPanel(); final JPanel bPanel = new JPanel(); final JPanel cPanel = new JPanel(new BorderLayout()); final JPanel allPanel = new JPanel(new BorderLayout()); ButtonGroup rGroup = new ButtonGroup(); JRadioButton rPButton = new JRadioButton("PCGen Dir", "pcgen" .equals(SettingsHandler.getFilePaths())); JRadioButton rUButton = new JRadioButton("Home Dir", "user" .equals(SettingsHandler.getFilePaths())); JRadioButton rSButton = new JRadioButton("Select a directory", !"pcgen" .equals(SettingsHandler.getFilePaths()) && !"user".equals(SettingsHandler.getFilePaths())); final JTextField textField = new JTextField(String.valueOf(SettingsHandler.getPcgenFilesDir())); textField.setEditable(false); textField.setMinimumSize(new Dimension(90, 25)); if ("user".equals(SettingsHandler.getFilePaths())) { textField.setText(System.getProperty("user.home") + File.separator + ".pcgen"); } final JButton dirButton = new JButton("..."); dirButton.setEnabled(false); rGroup.add(rPButton); rGroup.add(rUButton); rGroup.add(rSButton); aPanel.add(aLabel); bPanel.add(rPButton); bPanel.add(rUButton); cPanel.add(rSButton, BorderLayout.NORTH); rPButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { SettingsHandler.setFilePaths("pcgen"); textField.setText(System.getProperty("user.dir")); } }); rUButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { SettingsHandler.setFilePaths("user"); textField.setText(System.getProperty("user.home") + File.separator + ".pcgen"); } }); rSButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { SettingsHandler.setFilePaths("select"); dirButton.setEnabled(true); } }); dirButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File returnFile = SettingsHandler.getPcgenFilesDir(); JFileChooser fc; if (returnFile == null) { fc = new JFileChooser(); } else { fc = new JFileChooser(returnFile); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); final int rVal = fc.showOpenDialog(null); if (rVal == JFileChooser.APPROVE_OPTION) { returnFile = fc.getSelectedFile(); } textField.setText(String.valueOf(returnFile)); SettingsHandler.setPcgenFilesDir(returnFile); } }); cPanel.add(textField, BorderLayout.CENTER); cPanel.add(dirButton, BorderLayout.EAST); allPanel.setSize(new Dimension(400, 200)); allPanel.add(aPanel, BorderLayout.NORTH); allPanel.add(bPanel, BorderLayout.CENTER); allPanel.add(cPanel, BorderLayout.SOUTH); final Object[] message = new Object[1]; message[0] = allPanel; JOptionPane.showOptionDialog(null, message, "Directory for options.ini location", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, oOk, oOk[0]); } /** * Ensures that the splash screen is not visible. This should be * called before displaying any dialog boxes or windows at * startup. */ private static void hideSplashScreen() { if (splash != null) { splash.dispose(); splash = null; } } private static void initHpFrame(PlayerCharacter aPC) { if (hpFrame == null) { hpFrame = new HPFrame(); } hpFrame.setCharacter(aPC); } private boolean processStartupArgs() { boolean status = true; /* Load through the frame instead of this class so that the frame has a chance to update the menubars, etc. */ for (int i = 0; i < startupArgs.length; ++i) { final File file = new File(startupArgs[i]); if (PCGFile.isPCGenCharacterFile(file)) { if (frame.loadPCFromFile(file) == null) { Logging.errorPrint("No such PC file: " + startupArgs[i]); status = false; } } else if (PCGFile.isPCGenPartyFile(file)) { if (!frame.loadPartyFromFile(file)) { Logging.errorPrint("No such Party file: " + startupArgs[i]); status = false; } } } return status; } private static String readTextFromFile(String fileName) { String aString; final File aFile = new File(fileName); if (!aFile.exists()) { Logging.errorPrint("Could not find license at " + fileName); aString = "No license information found"; return aString; } try { BufferedReader theReader = new BufferedReader(new InputStreamReader(new FileInputStream(aFile), "UTF-8")); final int length = (int) aFile.length(); final char[] inputLine = new char[length]; theReader.read(inputLine, 0, length); theReader.close(); aString = new String(inputLine); } catch (IOException e) { Logging.errorPrint("Could not read license at " + fileName, e); aString = "No license information found"; } return aString; } private static void showSplashScreen() { splash = new SplashScreen(); } }

The table below shows all metrics for pcGenGUI.java.

MetricValueDescription
BLOCKS105.00Number of blocks
BLOCK_COMMENT23.00Number of block comment lines
COMMENTS122.00Comment lines
COMMENT_DENSITY 0.24Comment density
COMPARISONS55.00Number of comparison operators
CYCLOMATIC96.00Cyclomatic complexity
DECL_COMMENTS11.00Comments in declarations
DOC_COMMENT67.00Number of javadoc comment lines
ELOC515.00Effective lines of code
EXEC_COMMENTS21.00Comments in executable code
EXITS139.00Procedure exits
FUNCTIONS32.00Number of function declarations
HALSTEAD_DIFFICULTY73.04Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY65.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 1.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 6.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 1.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 8.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 2.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 0.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 4.00JAVA0144 Line exceeds maximum M characters
JAVA01451750.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 4.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 3.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 1.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 1.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 1.00JAVA0266 Use of System.out
JAVA0267 1.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 1.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES951.00Number of lines in the source file
LINE_COMMENT32.00Number of line comments
LOC712.00Lines of code
LOGICAL_LINES377.00Number of statements
LOOPS 2.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS1582.00Number of operands
OPERATORS2938.00Number of operators
PARAMS24.00Number of formal parameter declarations
PROGRAM_LENGTH4520.00Halstead program length
PROGRAM_VOCAB556.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS41.00Number of return points from functions
SIZE27955.00Size of the file in bytes
UNIQUE_OPERANDS509.00Number of unique operands
UNIQUE_OPERATORS47.00Number of unique operators
WHITESPACE117.00Number of whitespace lines