001 /* steelme theme manager for Java 002 * Copyright (C) 2000 - 2004 T.J. Willis 003 * 004 * This program is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU General Public License 006 * as published by the Free Software Foundation; either version 2 007 * of the License, or (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, write to the Free Software 016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. 017 * 018 * $Header: /cvsroot/steelme/steelme/src/net/sourceforge/steelme/FontChooserPanel.java,v 1.1.1.1 2004/05/10 14:28:11 tj_willis Exp $ 019 */ 020 package net.sourceforge.steelme; 021 022 import java.awt.*; 023 import java.awt.event.*; 024 import javax.swing.*; 025 026 /** 027 * A JPanel that lets the user select from installed fonts. 028 * 029 * @author <a href="mailto:tj_willis@users.sourceforge.net">T.J. Willis</a> 030 * @version 1.0 031 */ 032 public class FontChooserPanel extends JPanel implements ActionListener { 033 034 /** 035 * Creates new form FontChooser 036 * @param def a <code>Font</code> value 037 */ 038 public FontChooserPanel(Font def) { 039 initComponents(); 040 if(def!=null) 041 setThemeFont(def); 042 } 043 044 /** This method is called from within the constructor to 045 * initialize the form. 046 * WARNING: Do NOT modify this code. The content of this method is 047 * always regenerated by the Form Editor. 048 */ 049 private void initComponents() { 050 jLabel2 = new javax.swing.JLabel(); 051 jLabel3 = new javax.swing.JLabel(); 052 jComboBox1 = new javax.swing.JComboBox(); 053 jCheckBox1 = new javax.swing.JCheckBox(); 054 jCheckBox2 = new javax.swing.JCheckBox(); 055 jLabel5 = new javax.swing.JLabel(); 056 jList2 = new javax.swing.JComboBox(); //javax.swing.JList(); 057 058 setLayout(new java.awt.GridBagLayout()); 059 java.awt.GridBagConstraints gridBagConstraints1; 060 061 setBorder(new javax.swing.border.EtchedBorder()); 062 jLabel2.setText("Font:"); 063 gridBagConstraints1 = new java.awt.GridBagConstraints(); 064 gridBagConstraints1.gridy = 1; 065 add 066 (jLabel2, gridBagConstraints1); 067 068 jLabel3.setText("Size:"); 069 gridBagConstraints1 = new java.awt.GridBagConstraints(); 070 gridBagConstraints1.gridy = 2; 071 add 072 (jLabel3, gridBagConstraints1); 073 074 jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "8", "9","10","11","12","13","14","15", "16", "24", "36", "48", "72" 075 } 076 )); 077 gridBagConstraints1 = new java.awt.GridBagConstraints(); 078 gridBagConstraints1.gridy = 2; 079 gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; 080 add 081 (jComboBox1, gridBagConstraints1); 082 jComboBox1.addActionListener(this); 083 jComboBox1.setEditable(true); 084 085 jCheckBox1.setText("Bold"); 086 gridBagConstraints1 = new java.awt.GridBagConstraints(); 087 gridBagConstraints1.gridx = 1; 088 gridBagConstraints1.gridy = 3; 089 add 090 (jCheckBox1, gridBagConstraints1); 091 jCheckBox1.addActionListener(this); 092 093 jCheckBox2.setText("Italic"); 094 gridBagConstraints1 = new java.awt.GridBagConstraints(); 095 gridBagConstraints1.gridx = 2; 096 gridBagConstraints1.gridy = 3; 097 add 098 (jCheckBox2, gridBagConstraints1); 099 jCheckBox2.addActionListener(this); 100 101 jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); 102 jLabel5.setText("<HTML><CENTER>Now is the time<BR> for all good parties<BR> to come to the aid of their<BR> service.</CENTER></HTML>"); 103 jLabel5.setBorder(new javax.swing.border.TitledBorder(null, "Sample", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION)); 104 jLabel5.setAutoscrolls(true); 105 gridBagConstraints1 = new java.awt.GridBagConstraints(); 106 gridBagConstraints1.gridx = 3; 107 gridBagConstraints1.gridwidth = 2; 108 gridBagConstraints1.gridheight = 4; 109 jLabel5.setMinimumSize(new Dimension(150,150)); 110 jLabel5.setPreferredSize(new Dimension(150,150)); 111 add 112 (jLabel5, gridBagConstraints1); 113 114 115 String fontList[] = 116 GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); 117 118 for ( int i = 0; i < fontList.length; i++ ) 119 jList2.addItem( fontList[i] ); 120 //jList2.setListData(fontList); 121 jList2.setSelectedItem( "Dialog"); 122 jList2.addActionListener(this); 123 124 // jList2.setModel(new javax.swing.AbstractListModel() { 125 // String[] strings = { "Arial", "Helvetica" }; 126 // public int getSize() { return strings.length; } 127 // public Object getElementAt(int i) { return strings[i]; } 128 // }); 129 //jList2.setVisibleRowCount(1); 130 gridBagConstraints1 = new java.awt.GridBagConstraints(); 131 gridBagConstraints1.gridx = 1; 132 gridBagConstraints1.gridy = 1; 133 add 134 (jList2, gridBagConstraints1); 135 136 } 137 138 /** 139 * Called when user selects a font. Sets the preview font to selected. 140 * 141 * @param e an <code>ActionEvent</code> value 142 */ 143 public void actionPerformed(ActionEvent e) { 144 Font f = getSelectedFont(); 145 jLabel5.setFont(f); 146 //getContentPane().pack(); 147 } 148 149 /** 150 * Describe <code>setThemeFont</code> method here. 151 * 152 * @param f a <code>Font</code> value 153 */ 154 public void setThemeFont(Font f) { 155 int tsz, tst; 156 jList2.setSelectedItem(f.getName()); 157 jComboBox1.setSelectedItem(new Integer(f.getSize())); 158 tst = Font.PLAIN; 159 if(f.isBold()) 160 jCheckBox1.setSelected(true); 161 if(f.isItalic()) 162 jCheckBox2.setSelected(true); 163 164 } 165 166 /** 167 * Describe <code>getSelectedFont</code> method here. 168 * 169 * @return a <code>Font</code> value 170 */ 171 public Font getSelectedFont() { 172 int style = Font.PLAIN; 173 if ( jCheckBox1.isSelected()) 174 style += Font.BOLD; 175 if( jCheckBox2.isSelected()) 176 style += Font.ITALIC; 177 String fontName = jList2.getSelectedItem().toString(); 178 String fontSizeS = jComboBox1.getSelectedItem().toString(); 179 int fontSize = Integer.parseInt(fontSizeS); 180 return new Font(fontName,style,fontSize); 181 } 182 183 // Variables declaration - do not modify 184 private javax.swing.JLabel jLabel2; 185 private javax.swing.JLabel jLabel3; 186 private javax.swing.JComboBox jComboBox1; 187 private javax.swing.JCheckBox jCheckBox1; 188 private javax.swing.JCheckBox jCheckBox2; 189 private javax.swing.JLabel jLabel5; 190 private javax.swing.JComboBox jList2; 191 // End of variables declaration 192 193 }