FontSelectionPanel.java

Index Score
org.xnap.gui.component
XNap 3

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
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
COMMENTSComment lines
SIZESize of the file in bytes
LINE_COMMENTNumber of line comments
RETURNSNumber of return points from functions
INTERFACE_COMPLEXITYInterface complexity
JAVA0113JAVA0113 Incorrect javadoc: no @author tag
JAVA0076JAVA0076 Use of magic number
FUNCTIONSNumber of function declarations
LINESNumber of lines in the source file
EXITSProcedure exits
JAVA0133JAVA0133 Non-synchronized method overrides synchronized method
JAVA0034JAVA0034 Missing braces in if statement
LOGICAL_LINESNumber of statements
PARAMSNumber of formal parameter declarations
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
ELOCEffective lines of code
OPERATORSNumber of operators
CYCLOMATICCyclomatic complexity
PROGRAM_LENGTHHalstead program length
JAVA0114JAVA0114 Incorrect javadoc: no @version tag
JAVA0128JAVA0128 Public constructor in non-public class
BLOCKSNumber of blocks
OPERANDSNumber of operands
JAVA0177JAVA0177 Variable declaration missing initializer
LOCLines of code
UNIQUE_OPERATORSNumber of unique operators
EXEC_COMMENTSComments in executable code
PROGRAM_VOLUMEHalstead program volume
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0173JAVA0173 Unused method parameter
JAVA0130JAVA0130 Non-static method does not use instance fields
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
WHITESPACENumber of whitespace lines
JAVA0145JAVA0145 Tab character used in source file
/* * XNap - A P2P framework and client. * * See the file AUTHORS for copyright information. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation. * * 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * This class has been adopted for the XNap project. */ // Copyright (C) 2000 Greg Merrill (greghmerrill@yahoo.com) // Distributed under the terms of the GNU General Public License (version 2) // For details on the GNU GPL, please visit http://www.gnu.org/copyleft/gpl.html // To find out more about this and other free software by Greg Merrill, // please visit http://gregmerrill.imagineis.com package org.xnap.gui.component; import java.awt.Canvas; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsEnvironment; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.font.FontRenderContext; import java.awt.font.GlyphVector; import java.awt.geom.Rectangle2D; import java.util.Observable; import java.util.Observer; import javax.swing.DefaultListCellRenderer; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.ListModel; import javax.swing.ListSelectionModel; import javax.swing.border.EmptyBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; /** A component which allows a user to select a font. Here is a code sample demonstrating its use: <a name="codeSample"> <p> <!-- prefix each pre line with '*' to avoid javadoc whitespace bug --> <pre> * import java.awt.*; * import java.awt.event.*; * import javax.swing.*; * * public class FontSelectionPanelDemo { * public static void main (String[] args) { * final JFrame frame = new JFrame(); * JPanel panel = new JPanel(new BorderLayout()); * final FontSelectionPanel fontSelectionPanel = new FontSelectionPanel( * new Font("Times New Roman", Font.BOLD+Font.ITALIC, 14) * ); * panel.add(fontSelectionPanel, BorderLayout.CENTER); * JButton button = new JButton("OK"); * button.addActionListener(new ActionListener () { * public void actionPerformed (ActionEvent e) { * try { * JOptionPane.showMessageDialog( * frame, * "Selected font is: " + fontSelectionPanel.getSelectedFont(), * "Selected Font", * JOptionPane.INFORMATION_MESSAGE * ); * } * catch (FontSelectionPanel.InvalidFontException ife) { * JOptionPane.showMessageDialog( * frame, * "You have not selected a valid font", * "Invalid Font", * JOptionPane.ERROR_MESSAGE * ); * } * } * }); * panel.add(button, BorderLayout.SOUTH); * frame.setContentPane(panel); * frame.addWindowListener(new WindowAdapter () { * public void windowClosing (WindowEvent e) { System.exit(0); } * }); * frame.pack(); * frame.show(); * } * } </pre> <p> <a name="versionHistory"> <h3>Version History:</h3> <dl> <dt><b>1.1</b> (August 19, 2000) <dd><tt>protected</tt> access to all major components now provided for the benefit of subclasses<br> Added methods {@link #setSelectedFont(java.awt.Font)}, {@link #setSelectedFontFamily(String)}, {@link #setSelectedFontStyle(int)}, {@link #setSelectedFontSize(int)}<br> GridBag fill strategy modified slightly to improve resizing behavior<br> Changed sample code to use BorderLayout<br> Added version history to javadocs <dt><b>1.0</b> (August 15, 2000) <dd>Initial release </dl> <p> Copyright (C) 2000 Greg Merrill ( <a href="mailto:greghmerrill@yahoo.com">greghmerrill@yahoo.com</a>). Distributed under the terms of the GNU General Public License (version 2). For details on the GNU GPL, please visit <a href="http://www.gnu.org/copyleft/gpl.html" >http://www.gnu.org/copyleft/gpl.html</a>. To find out more about this and other free software by Greg Merrill, please visit <a href="http://gregmerrill.imagineis.com" >http://gregmerrill.imagineis.com</a> @author <a href="mailto:greghmerrill@yahoo.com">Greg Merrill</a> @version 1.1 */ public class FontSelectionPanel extends JPanel { /** Like {@link #FontSelectionPanel(java.awt.Font)}, except an initialFont of <code>null</code> will be used. */ public FontSelectionPanel () { this(null); } /** Like {@link #FontSelectionPanel(java.awt.Font, String[], int[])}, except that a default list of styles (<code>{"Plain", "Bold", "Italic", "Bold Italic"}</code>) and font sizes (<code>{8, 9, 10, 12, 14}</code>) will be used. @param initialFont see {@link #FontSelectionPanel(java.awt.Font, String[], int[])} */ public FontSelectionPanel (Font initialFont) { this( initialFont, // Don't change the following two values without changing the javadocs new String [] {"Plain", "Bold", "Italic", "Bold Italic"}, new int [] {8, 9, 10, 12, 14} ); } /** Construct a new FontSelectionPanel whose family, style & size widget selections are set according to the supplied initial Font. Additionally, the style & size values available will be dictated by the values in styleDisplayNames and predefinedSizes, respectively. @param initialFont the newly constructed FontSelectionPanel's family, style, and size widgets will be set according to this value. This value may be null, in which case an initial font will be automatically created. This auto-created font will have a family, style, and size corresponding to the first avaiable value in the widget form family, style, and size respectively. @param styleDisplayNames must contain exactly four members. The members of this array represent the following styles, in order: Font.PLAIN, Font.BOLD, Font.ITALIC, and Font.BOLD+Font.ITALIC @param predefinedSizes must contain one or more predefined font sizes which will be available to the user as a convenience for populating the font size text field; all values must be greater than 0. */ public FontSelectionPanel ( Font initialFont, String[] styleDisplayNames, int[] predefinedSizes ) { super(new GridBagLayout()); this.setBorder(new EmptyBorder(12, 12, 11, 11)); GridBagConstraints gbc = new GridBagConstraints(); String[] availableFontFamilyNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); if (initialFont == null) { initialFont = new Font( availableFontFamilyNames[0], Font.PLAIN, predefinedSizes[0] );} // Font family fontFamilyList_ = new JList(availableFontFamilyNames); fontFamilyList_.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontFamilyList_.setVisibleRowCount(8); ListSelectionListener phraseCanvasUpdater = new ListSelectionListener () { public void valueChanged (ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { observable_.setChanged(); observable_.notifyObservers(); } } }; fontFamilyList_.addListSelectionListener(phraseCanvasUpdater); gbc.fill = GridBagConstraints.BOTH; gbc.gridheight = 2; this.add(new JScrollPane(fontFamilyList_), gbc); // Font style fontStyleList_ = new FontStyleList(styleDisplayNames); fontStyleList_.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontStyleList_.setVisibleRowCount(4); fontStyleList_.addListSelectionListener(phraseCanvasUpdater); gbc.gridx = 1; gbc.insets = new Insets(0, 10, 0, 0); // fontStyleList_ is put into a JScrollPane only because it puts a nice // border around it which is consistent with the border around // fontFamilyList_ this.add(new JScrollPane(fontStyleList_), gbc); // Font size fontSize_ = new JTextField(); fontSize_.setHorizontalAlignment(JTextField.RIGHT); fontSize_.setColumns(4); gbc.gridx = 2; gbc.gridheight = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(fontSize_, gbc); fontSizeList_ = new JList( validateAndConvertPredefinedSizes(predefinedSizes) ); fontSizeList_.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Will be able to see more than 1 row because gbc.fill set to BOTH fontSizeList_.setVisibleRowCount(1); fontSizeList_.setCellRenderer(new ListCellRenderer()); gbc.gridy = 1; gbc.insets = new Insets(10, 10, 0, 0); gbc.fill = GridBagConstraints.BOTH; this.add(new JScrollPane(fontSizeList_), gbc); // Phrase Canvas (displays current font selection) phraseCanvas_ = new PhraseCanvas( initialFont.getFamily(), initialFont, Color.black ); addObserver(new Observer () { public void update (Observable o, Object arg) { try { phraseCanvas_.setPhrase((String)fontFamilyList_.getSelectedValue()); phraseCanvas_.setFont(FontSelectionPanel.this.getSelectedFont()); } catch (InvalidFontException e) { phraseCanvas_.setPhrase(""); } phraseCanvas_.invalidate(); phraseCanvas_.repaint(); } }); phraseCanvas_.setSize( (int)this.getPreferredSize().getWidth(), 100 ); gbc.gridy = 2; gbc.gridx = 0; gbc.gridwidth = 3; gbc.insets = new Insets(10, 0, 0, 0); gbc.fill = GridBagConstraints.HORIZONTAL; // put into JScrollPane for formatting purposes (no scrolling ever occurs) this.add(new JScrollPane(phraseCanvas_), gbc); // Use FontSizeSynchronizer to ensure consistency between text field & // list for font size FontSizeSynchronizer fontSizeSynchronizer = new FontSizeSynchronizer(fontSizeList_, fontSize_); fontSizeList_.addListSelectionListener(fontSizeSynchronizer); fontSize_.getDocument().addDocumentListener(fontSizeSynchronizer); // Set initial widget values here at the end of the constructor to // ensure that all listeners have been added beforehand fontFamilyList_.setSelectedValue(initialFont.getFamily(), true); fontStyleList_.setSelectedStyle(initialFont.getStyle()); fontSize_.setText(String.valueOf(initialFont.getSize())); } /** JList for font family */ protected JList fontFamilyList_; /** FontStlyeList (subclass of JList) for font style */ protected FontStyleList fontStyleList_; /** JTextField for font size */ protected JTextField fontSize_; /** JList for font size */ protected JList fontSizeList_; /** PhraseCanvas in which font samples are displayed */ protected PhraseCanvas phraseCanvas_; /** @exception IllegalArgumentException thrown if <ul> <li>predefinedSizes does not contain one or more integer values <li>predefinedSizes contains any integers with a value of less than 1 </ul> */ private Integer[] validateAndConvertPredefinedSizes (int[] predefinedSizes) { if (predefinedSizes == null) { throw new IllegalArgumentException( "int[] predefinedSizes may not be null" );} if (predefinedSizes.length < 1) { throw new IllegalArgumentException( "int[] predefinedSizes must contain one or more values" );} Integer[] predefinedSizeIntegers = new Integer[predefinedSizes.length]; for (int i=0; i < predefinedSizes.length; i++) { if (predefinedSizes[i] < 1) { throw new IllegalArgumentException( "int[] predefinedSizes may not contain integers with value less than 1" );} predefinedSizeIntegers[i] = new Integer(predefinedSizes[i]); } return predefinedSizeIntegers; } /** Adds an Observer to this FontSelectionPanel; the supplied Observer will have its update() method called any time the Font currently specified in the FontSelectionPanel changes. (The <tt>arg</tt> supplied to the Observer will be <tt>null</tt>.) @param o observer to be added @see java.util.Observer */ public void addObserver (Observer o) { observable_.addObserver(o); } /** Removes an Observer from this FontSelectionPanel. @param o Observer to be removed @see java.util.Observer */ public void deleteObserver (Observer o) { observable_.deleteObserver(o); } /** Observable used for registering/notifying Observers */ protected PublicChangeObservable observable_ = new PublicChangeObservable(); /** Returns the currently selected font family @return currently selected font family @exception NoFontFamilySelectedException thrown if no font family is currently selected */ public String getSelectedFontFamily () throws NoFontFamilySelectedException { String fontFamily = (String)fontFamilyList_.getSelectedValue(); if (fontFamily == null) { throw new NoFontFamilySelectedException( "No font family is currently selected" );} return fontFamily; } /** Returns the currently selected font style. @return currently selected font style. This value will correspond to one of the font styles specified in {@link java.awt.Font} @exception NoFontStyleSelectedException thrown if no font style is currently selected */ public int getSelectedFontStyle () throws NoFontStyleSelectedException { return fontStyleList_.getSelectedStyle(); } /** Returns the currently selected font size. @return currently selected font size. @exception NoFontSizeSpecifiedException thrown if no font size is currently specified @exception InvalidFontSizeException thrown if the font size currently specified is invalid */ public int getSelectedFontSize () throws NoFontSizeSpecifiedException, InvalidFontSizeException { String fontSize = fontSize_.getText(); if ((fontSize == null) || (fontSize.equals(""))) { throw new NoFontSizeSpecifiedException("No font size specified"); } if (fontSize.length() > maxNumCharsInFontSize_) { throw new InvalidFontSizeException("Too many characters in font size"); } try { return Integer.parseInt(fontSize); } catch (NumberFormatException e) { throw new InvalidFontSizeException( "The number specified in the font size text field (" + fontSize_.getText() + ") is not a valid integer." );} } /** Returns the currently selected font. @return currently selected font. @exception InvalidFontException thrown if no valid font is currently specified; the actual class of the exception thrown may be {@link FontSelectionPanel.InvalidFontException}, {@link FontSelectionPanel.NoFontFamilySelectedException}, {@link FontSelectionPanel.NoFontStyleSelectedException}, {@link FontSelectionPanel.NoFontSizeSpecifiedException}, or {@link FontSelectionPanel.InvalidFontSizeException} */ public Font getSelectedFont () throws InvalidFontException { return new Font( getSelectedFontFamily(), getSelectedFontStyle(), getSelectedFontSize() ); } /** Changes the currently selected font by assigning all widget values to match the family/style/size values of the supplied font @param font font whose values should be used to set widgets @exception IllegalArgumentException thrown if the family or style of the font supplied are not available or invalid */ public void setSelectedFont (Font font) { setSelectedFontFamily(font.getFamily()); setSelectedFontStyle(font.getStyle()); setSelectedFontSize(font.getSize()); } /** Sets the currently selected font family. @param family family to which selection should change @exception IllegalArgumentException thrown if the supplied font family is not among the list of available font families */ public void setSelectedFontFamily (String family) { ListModel familyListModel = fontFamilyList_.getModel(); for (int i=0; i < familyListModel.getSize(); i++) { String s = familyListModel.getElementAt(i).toString(); if (s.equalsIgnoreCase(family)) { fontFamilyList_.setSelectedIndex(i); fontFamilyList_.ensureIndexIsVisible(i); return; } } throw new IllegalArgumentException( "The font family supplied, '" + family + "', is not in the list of availalbe " + "font families." ); } /** Sets the currently selected font style. @param style style to which selection should change @exception IllegalArgumentException thrown if the supplied font style is not one of Font.PLAIN, Font.BOLD, Font.ITALIC, or Font.BOLD+Font.ITALIC */ public void setSelectedFontStyle (int style) { fontStyleList_.setSelectedStyle(style); } /** Sets the currently selected font size. @param size size to which selection should change */ public void setSelectedFontSize (int size) { fontSize_.setText(String.valueOf(size)); } /** Maximum number of characters permissibile in a valid font size */ protected int maxNumCharsInFontSize_ = 3; /** This class synchronizes font size value between the list containing available font sizes & the text field in which font size is ultimately specified. */ protected class FontSizeSynchronizer implements DocumentListener, ListSelectionListener { /** @param list list containing predefined font sizes @param textField text field in which font size is specified */ public FontSizeSynchronizer (JList list, JTextField textField) { list_ = list; textField_ = textField; } /** @see javax.swing.event.ListSelectionListener */ public void valueChanged (ListSelectionEvent e) { if (updating_) { return; } updating_ = true; if (!e.getValueIsAdjusting()) { Object selectedValue = ((JList)e.getSource()).getSelectedValue(); if (selectedValue != null) { textField_.setText(selectedValue.toString()); } observable_.setChanged(); observable_.notifyObservers(); } updating_ = false; } /** @see javax.swing.event.DocumentListener */ public void changedUpdate (DocumentEvent e) { handle(e); } /** @see javax.swing.event.DocumentListener */ public void insertUpdate (DocumentEvent e) { handle(e); } /** @see javax.swing.event.DocumentListener */ public void removeUpdate (DocumentEvent e) { handle(e); } /** Handles all DocumentEvents */ protected void handle (DocumentEvent e) { if (updating_) { return; } updating_ = true; try { Integer currentFontSizeInteger = Integer.valueOf(textField_.getText()); boolean currentSizeWasInList = false; Object listMember; for (int i=0; i < list_.getModel().getSize(); i++) { listMember = list_.getModel().getElementAt(i); if (listMember.equals(currentFontSizeInteger)) { list_.setSelectedValue(currentFontSizeInteger, true); currentSizeWasInList = true; break; } } if (!currentSizeWasInList) { list_.clearSelection(); } } catch (NumberFormatException nfe) { list_.clearSelection(); } observable_.setChanged(); observable_.notifyObservers(); updating_ = false; } protected JList list_; protected JTextField textField_; protected boolean updating_; } // // Static inner classes // /** Represents a list of the four font styles: plain, bold, italic, and bold italic */ protected static class FontStyleList extends JList { /** Construct a new FontStyleList, using the supplied values for style display names @param styleDisplayNames must contain exactly four members. The members of this array represent the following styles, in order: Font.PLAIN, Font.BOLD, Font.ITALIC, and Font.BOLD+Font.ITALIC @exception IllegalArgumentException thrown if styleDisplayNames does not contain exactly four String values */ public FontStyleList (String[] styleDisplayNames) { super(validateStyleDisplayNames(styleDisplayNames)); } private static String[] validateStyleDisplayNames ( String[] styleDisplayNames ) { if (styleDisplayNames == null) { throw new IllegalArgumentException( "String[] styleDisplayNames may not be null" );} if (styleDisplayNames.length != 4) { throw new IllegalArgumentException( "String[] styleDisplayNames must have a length of 4" );} for (int i=0; i < styleDisplayNames.length; i++) { if (styleDisplayNames[i] == null) { throw new IllegalArgumentException( "No member of String[] styleDisplayNames may be null" );} } return styleDisplayNames; } /** @return currently selected font style @exception NoFontStyleSelectedException thrown if no font style is currently selected */ public int getSelectedStyle () throws NoFontStyleSelectedException { switch (this.getSelectedIndex()) { case 0: return Font.PLAIN; case 1: return Font.BOLD; case 2: return Font.ITALIC; case 3: return Font.BOLD+Font.ITALIC; default: throw new NoFontStyleSelectedException( "No font style is currently selected" ); } } /** Change the currently selected style in this FontStyleList @param style new selected style for this FontStyleList @exception IllegalArgumentException thrown if style is not one of Font.PLAIN, Font.BOLD, Font.ITALIC, or Font.BOLD+Font.ITALIC */ public void setSelectedStyle (int style) { switch (style) { case Font.PLAIN: this.setSelectedIndex(0); break; case Font.BOLD: this.setSelectedIndex(1); break; case Font.ITALIC: this.setSelectedIndex(2); break; case Font.BOLD+Font.ITALIC: this.setSelectedIndex(3); break; default: throw new IllegalArgumentException( "int style must come from java.awt.Font" ); } } } /** An implementation of {@link javax.swing.ListCellRenderer} which right justifies all cells. */ protected static class ListCellRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent ( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) { JLabel label = (JLabel)super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus ); label.setHorizontalAlignment(JLabel.RIGHT); return label; } } /** Subclass of {@link java.util.Observable} which allows <tt>public</tt> access to the setChanged() method. */ protected static class PublicChangeObservable extends Observable { /** @see java.util.Observable#setChanged() */ public void setChanged () { super.setChanged(); } } /** Component for displaying a "phrase" (a brief, one or two word String) using a particular font & a particular color. */ public static class PhraseCanvas extends Canvas { /** Constructs a new PhraseCanvas with the supplied phrase, font, and color. @param phrase phrase to be displayed in this PhraseCanvas @param font Font to use when rendering the phrase @param color Color to use when rendering the phrase */ public PhraseCanvas (String phrase, Font font, Color color) { phrase_ = phrase; font_ = font; color_ = color; } /** @see java.awt.Canvas#paint(java.awt.Graphics) */ public void paint (Graphics g) { // Workaround for bug in Font.createGlyphVector(), in review by // Sun with review id 108400. Font dummyFont = new Font( font_.getFamily(), font_.getStyle(), font_.getSize()+1 ); dummyFont.createGlyphVector( new FontRenderContext(null, antialiasOn_, false), phrase_ ); GlyphVector glyphVector = font_.createGlyphVector( new FontRenderContext(null, antialiasOn_, false), phrase_ ); // Use precedent set by applications like MS Word to place // glyph vector in the canvas: // 1. If the total width of the glyph vector is less than the // width of the canvas, the glyph vector will be horizontally centered // in the canvas; else the glyph vector will be left-aligned // 2. If the total height of the glyph vector is less than the height of // the canvas, the glyph vector will be vertically centered in the // canvas; else the glyph vector will be bottom-aligned Rectangle2D logicalBounds = glyphVector.getLogicalBounds(); double x; if (logicalBounds.getWidth() < this.getWidth()) { x = (this.getWidth()/2) - (logicalBounds.getWidth()/2); } else { x = 0; } double y; if (logicalBounds.getHeight() < this.getHeight()) { y = (this.getHeight()/2) + (logicalBounds.getHeight()/2); } else { y = this.getHeight(); } g.setColor(color_); Graphics2D g2d = (Graphics2D)g; g2d.drawGlyphVector(glyphVector, (float)x, (float)y); } /** Returns the phrase to be rendered by this PhraseCanvas. @return phrase to be rendered by this PhraseCanvas */ public String getPhrase () { return phrase_; } /** Sets the phrase to be rendered by this PhraseCanvas. @param phrase new phrase to be rendered by this PhraseCanvas; this new value will be rendered the next time {@link #paint(java.awt.Graphics)} is called */ public void setPhrase (String phrase) { phrase_ = phrase; } protected String phrase_; /** Returns the font to use when rendering the phrase. @return font to use when rendering the phrase */ public Font getFont () { return font_; } /** Sets the font to use when rendering the phrase. @param font new font to use when rendering the phrase; this new value will be used to render the phrase the next time {@link #paint(java.awt.Graphics)} is called */ public void setFont (Font font) { font_ = font; } protected Font font_; /** Returns the color to use when rendering the phrase. @return color to use when rendering the phrase */ public Color getColor () { return color_; } /** Sets the color to use when rendering the phrase. @param color new color to use when rendering the phrase; this new value will be used to render the phrase the next time {@link #paint(java.awt.Graphics)} is called */ public void setColor (Color color) { color_ = color; } protected Color color_; /** Returns true iff anti-aliasing is used when rendering the phrase. @return whether or not anti-aliasing is used when rendering the phrase */ public boolean isAntialiasOn () { return antialiasOn_; } /** Turn anti-aliasing on or off. @param antialiasOn whether or not to use anti-aliasing when rendering the phrase this new value will be used to render the phrase the next time {@link #paint(java.awt.Graphics)} is called */ public void setAntialiasOn (boolean antialiasOn) { antialiasOn_ = antialiasOn; } protected boolean antialiasOn_; } /** Indicates that an invalid font is currently specified */ public static class InvalidFontException extends Exception { public InvalidFontException (String msg) { super(msg); } } /** Indicates that no font family is currently selected */ public static class NoFontFamilySelectedException extends InvalidFontException { public NoFontFamilySelectedException (String msg) { super(msg); } } /** Indicates that no font style is currently selected */ public static class NoFontStyleSelectedException extends InvalidFontException { public NoFontStyleSelectedException (String msg) { super(msg); } } /** Indicates that no font size is currently specified */ public static class NoFontSizeSpecifiedException extends InvalidFontException { public NoFontSizeSpecifiedException (String msg) { super(msg); } } /** Indicates that an invalid font size is currently specified */ public static class InvalidFontSizeException extends InvalidFontException { public InvalidFontSizeException (String msg) { super(msg); } } }

The table below shows all metrics for FontSelectionPanel.java.

MetricValueDescription
BLOCKS75.00Number of blocks
BLOCK_COMMENT21.00Number of block comment lines
COMMENTS336.00Comment lines
COMMENT_DENSITY 1.02Comment density
COMPARISONS28.00Number of comparison operators
CYCLOMATIC81.00Cyclomatic complexity
DECL_COMMENTS60.00Comments in declarations
DOC_COMMENT283.00Number of javadoc comment lines
ELOC328.00Effective lines of code
EXEC_COMMENTS12.00Comments in executable code
EXITS69.00Procedure exits
FUNCTIONS43.00Number of function declarations
HALSTEAD_DIFFICULTY 0.56Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY108.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.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 0.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 non-protected 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 1.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 2.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA007615.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 2.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.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 2.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 1.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
JAVA011310.00JAVA0113 Incorrect javadoc: no @author tag
JAVA011410.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 5.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 2.00JAVA0128 Public constructor in non-public class
JAVA0130 1.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 1.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 0.00JAVA0144 Line exceeds maximum M characters
JAVA0145 6.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 0.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 1.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 9.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 0.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 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.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
JAVA0289 1.00null
LINES763.00Number of lines in the source file
LINE_COMMENT32.00Number of line comments
LOC382.00Lines of code
LOGICAL_LINES217.00Number of statements
LOOPS 4.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS863.00Number of operands
OPERATORS1694.00Number of operators
PARAMS42.00Number of formal parameter declarations
PROGRAM_LENGTH2557.00Halstead program length
PROGRAM_VOCAB340.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS66.00Number of return points from functions
SIZE28773.00Size of the file in bytes
UNIQUE_OPERANDS287.00Number of unique operands
UNIQUE_OPERATORS53.00Number of unique operators
WHITESPACE45.00Number of whitespace lines