Bläddra i källkod

- add style selection to FontCreator

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7130 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
nor..67 14 år sedan
förälder
incheckning
ed5c220665

+ 15 - 0
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontVisualPanel2.form

@@ -57,6 +57,21 @@
 
       <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
       <SubComponents>
+        <Component class="javax.swing.JComboBox" name="jComboBox1">
+          <Properties>
+            <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
+              <StringArray count="4">
+                <StringItem index="0" value="Item 1"/>
+                <StringItem index="1" value="Item 2"/>
+                <StringItem index="2" value="Item 3"/>
+                <StringItem index="3" value="Item 4"/>
+              </StringArray>
+            </Property>
+          </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jComboBox1ActionPerformed"/>
+          </Events>
+        </Component>
         <Component class="javax.swing.JLabel" name="jLabel1">
           <Properties>
             <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">

+ 28 - 1
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontVisualPanel2.java

@@ -4,6 +4,7 @@
  */
 package com.jme3.gde.angelfont;
 
+import java.awt.Font;
 import javax.swing.ImageIcon;
 import javax.swing.JPanel;
 
@@ -12,10 +13,15 @@ public final class AngelFontVisualPanel2 extends JPanel {
     String fontName = "";
     int fontSize = 16;
     int imageSize = 256;
+    int style = Font.PLAIN;
 
     /** Creates new form AngelFontVisualPanel2 */
     public AngelFontVisualPanel2() {
         initComponents();
+        jComboBox1.removeAllItems();
+        jComboBox1.addItem("PLAIN");
+        jComboBox1.addItem("ITALIC");
+        jComboBox1.addItem("BOLD");
     }
 
     @Override
@@ -29,7 +35,7 @@ public final class AngelFontVisualPanel2 extends JPanel {
     }
 
     private void updateFont() {
-        jLabel3.setIcon(new ImageIcon(FontCreator.buildFont(fontName, imageSize, fontSize, true).getImage()));
+        jLabel3.setIcon(new ImageIcon(FontCreator.buildFont(fontName, imageSize, fontSize, style, true).getImage()));
         jLabel3.repaint();
         jPanel1.repaint();
     }
@@ -45,6 +51,7 @@ public final class AngelFontVisualPanel2 extends JPanel {
         jPanel1 = new javax.swing.JPanel();
         jLabel3 = new javax.swing.JLabel();
         jToolBar1 = new javax.swing.JToolBar();
+        jComboBox1 = new javax.swing.JComboBox();
         jLabel1 = new javax.swing.JLabel();
         jSpinner1 = new javax.swing.JSpinner();
         jLabel2 = new javax.swing.JLabel();
@@ -59,6 +66,14 @@ public final class AngelFontVisualPanel2 extends JPanel {
         jToolBar1.setFloatable(false);
         jToolBar1.setRollover(true);
 
+        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
+        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                jComboBox1ActionPerformed(evt);
+            }
+        });
+        jToolBar1.add(jComboBox1);
+
         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jLabel1.text")); // NOI18N
         jToolBar1.add(jLabel1);
 
@@ -106,7 +121,19 @@ public final class AngelFontVisualPanel2 extends JPanel {
         imageSize = (Integer) jSpinner2.getValue();
         updateFont();
     }//GEN-LAST:event_updateImageSize
+
+    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
+        if ("PLAIN".equals(jComboBox1.getSelectedItem())) {
+            style = Font.PLAIN;
+        } else if ("BOLD".equals(jComboBox1.getSelectedItem())) {
+            style = Font.BOLD;
+        } else if ("ITALIC".equals(jComboBox1.getSelectedItem())) {
+            style = Font.ITALIC;
+        }
+        updateFont();
+    }//GEN-LAST:event_jComboBox1ActionPerformed
     // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JComboBox jComboBox1;
     private javax.swing.JLabel jLabel1;
     private javax.swing.JLabel jLabel2;
     private javax.swing.JLabel jLabel3;

+ 9 - 5
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontWizardIterator.java

@@ -12,8 +12,7 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.nio.ByteBuffer;
 import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map.Entry;
+import java.util.HashSet;
 import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.logging.Level;
@@ -75,13 +74,14 @@ public final class AngelFontWizardIterator implements WizardDescriptor.Instantia
         String name = (String) wizard.getProperty("font_name");
         int fontSize = (Integer) wizard.getProperty("font_size");
         int imageSize = (Integer) wizard.getProperty("image_size");
+        int style = (Integer) wizard.getProperty("font_style");
         Project project = (Project) wizard.getProperty("project");
         ProjectAssetManager pm = project.getLookup().lookup(ProjectAssetManager.class);
         if (pm == null) {
             Logger.getLogger(AngelFontWizardIterator.class.getName()).log(Level.WARNING, "No ProjectAssetManager found!");
             return Collections.EMPTY_SET;
         }
-        AngelFont font = FontCreator.buildFont(name, imageSize, fontSize);
+        AngelFont font = FontCreator.buildFont(name, imageSize, fontSize, style);
         BufferedImage fontImage = font.getImage();
         ByteBuffer scratch = ByteBuffer.allocateDirect(4 * fontImage.getWidth() * fontImage.getHeight());
         byte[] data = (byte[]) fontImage.getRaster().getDataElements(0, 0,
@@ -91,6 +91,7 @@ public final class AngelFontWizardIterator implements WizardDescriptor.Instantia
         scratch.rewind();
         name = name.replaceAll(" ", "");
         File outputFile;
+        FileObject object;
         try {
             if (pm.getAssetFolder().getFileObject("Interface") == null) {
                 pm.getAssetFolder().createFolder("Interface");
@@ -105,7 +106,7 @@ public final class AngelFontWizardIterator implements WizardDescriptor.Instantia
             // write png file
             ImageIO.write(fontImage, "PNG", outputFile);
 
-            FileObject object = pm.getAssetFolder().getFileObject("Interface/Fonts/" + name, "fnt");
+            object = pm.getAssetFolder().getFileObject("Interface/Fonts/" + name, "fnt");
             if (object == null) {
                 object = pm.getAssetFolder().getFileObject("Interface/Fonts").createData(name, "fnt");
             }
@@ -116,7 +117,10 @@ public final class AngelFontWizardIterator implements WizardDescriptor.Instantia
             Exceptions.printStackTrace(e);
             return Collections.EMPTY_SET;
         }
-        return Collections.singleton(FileUtil.toFileObject(outputFile));
+        Set<FileObject> set = new HashSet<FileObject>();
+        set.add(FileUtil.toFileObject(outputFile));
+        set.add(object);
+        return set;
     }
 
     public void initialize(WizardDescriptor wizard) {

+ 1 - 0
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontWizardPanel2.java

@@ -83,6 +83,7 @@ public class AngelFontWizardPanel2 implements WizardDescriptor.Panel {
     }
 
     public void storeSettings(Object settings) {
+        ((WizardDescriptor)settings).putProperty("font_style", component.style);
         ((WizardDescriptor)settings).putProperty("font_size", component.fontSize);
         ((WizardDescriptor)settings).putProperty("image_size", component.imageSize);
     }

+ 9 - 5
jme3-angelfont/src/com/jme3/gde/angelfont/FontCreator.java

@@ -25,24 +25,28 @@ public abstract class FontCreator {
     }
 
     public static AngelFont buildFont(String fontName) {
-        return buildFont(fontName, 512);
+        return buildFont(fontName, 256);
     }
 
     public static AngelFont buildFont(String fontName, int bitmapSize) {
-        return buildFont(fontName, bitmapSize, 16, false);
+        return buildFont(fontName, bitmapSize, 16);
     }
 
     public static AngelFont buildFont(String fontName, int bitmapSize, int fontSize) {
-        return buildFont(fontName, bitmapSize, fontSize, false);
+        return buildFont(fontName, bitmapSize, fontSize, Font.PLAIN);
     }
 
-    public static AngelFont buildFont(String fontName, int bitmapSize, int fontSize, boolean debug) {
+    public static AngelFont buildFont(String fontName, int bitmapSize, int fontSize, int style) {
+        return buildFont(fontName, bitmapSize, fontSize, Font.PLAIN, false);
+    }
+
+    public static AngelFont buildFont(String fontName, int bitmapSize, int fontSize, int style, boolean debug) {
         BufferedImage fontImage;
         Font font;
 
         String charLocs = "";
 
-        font = new Font(fontName, Font.BOLD, fontSize); // Font Name
+        font = new Font(fontName, style, fontSize); // Font Name
         // use BufferedImage.TYPE_4BYTE_ABGR to allow alpha blending
         fontImage = new BufferedImage(bitmapSize, bitmapSize,
                 BufferedImage.TYPE_4BYTE_ABGR);