Search in sources :

Example 1 with ConfigurableEffect

use of com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect in project libgdx by libgdx.

the class Hiero method initializeEvents.

private void initializeEvents() {
    fontList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting())
                return;
            prefs.put("system.font", (String) fontList.getSelectedValue());
            updateFont();
        }
    });
    class FontUpdateListener implements ChangeListener, ActionListener {

        public void stateChanged(ChangeEvent evt) {
            updateFont();
        }

        public void actionPerformed(ActionEvent evt) {
            updateFont();
        }

        public void addSpinners(JSpinner[] spinners) {
            for (int i = 0; i < spinners.length; i++) {
                final JSpinner spinner = spinners[i];
                spinner.addChangeListener(this);
                ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().addKeyListener(new KeyAdapter() {

                    String lastText;

                    public void keyReleased(KeyEvent evt) {
                        JFormattedTextField textField = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
                        String text = textField.getText();
                        if (text.length() == 0)
                            return;
                        if (text.equals(lastText))
                            return;
                        lastText = text;
                        int caretPosition = textField.getCaretPosition();
                        try {
                            spinner.setValue(Integer.valueOf(text));
                        } catch (NumberFormatException ex) {
                        }
                        textField.setCaretPosition(caretPosition);
                    }
                });
            }
        }
    }
    FontUpdateListener listener = new FontUpdateListener();
    listener.addSpinners(new JSpinner[] { padTopSpinner, padRightSpinner, padBottomSpinner, padLeftSpinner, padAdvanceXSpinner, padAdvanceYSpinner });
    fontSizeSpinner.addChangeListener(listener);
    gammaSpinner.addChangeListener(listener);
    glyphPageWidthCombo.addActionListener(listener);
    glyphPageHeightCombo.addActionListener(listener);
    boldCheckBox.addActionListener(listener);
    italicCheckBox.addActionListener(listener);
    monoCheckBox.addActionListener(listener);
    resetCacheButton.addActionListener(listener);
    javaRadio.addActionListener(listener);
    nativeRadio.addActionListener(listener);
    freeTypeRadio.addActionListener(listener);
    sampleTextRadio.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            glyphCachePanel.setVisible(false);
        }
    });
    glyphCacheRadio.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            glyphCachePanel.setVisible(true);
        }
    });
    fontFileText.getDocument().addDocumentListener(new DocumentListener() {

        public void removeUpdate(DocumentEvent evt) {
            changed();
        }

        public void insertUpdate(DocumentEvent evt) {
            changed();
        }

        public void changedUpdate(DocumentEvent evt) {
            changed();
        }

        private void changed() {
            File file = new File(fontFileText.getText());
            if (fontList.isEnabled() && (!file.exists() || !file.isFile()))
                return;
            prefs.put("font.file", fontFileText.getText());
            updateFont();
        }
    });
    final ActionListener al = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            updateFontSelector();
            updateFont();
        }
    };
    systemFontRadio.addActionListener(al);
    fontFileRadio.addActionListener(al);
    browseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.ttf");
            dialog.setDirectory(prefs.get("dir.font", ""));
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.font", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
        }
    });
    backgroundColorLabel.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent evt) {
            java.awt.Color color = JColorChooser.showDialog(null, "Choose a background color", EffectUtil.fromString(prefs.get("background", "000000")));
            if (color == null)
                return;
            renderingBackgroundColor = new Color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1);
            backgroundColorLabel.setIcon(getColorIcon(color));
            prefs.put("background", EffectUtil.toString(color));
        }
    });
    effectsList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            ConfigurableEffect selectedEffect = (ConfigurableEffect) effectsList.getSelectedValue();
            boolean enabled = selectedEffect != null;
            for (Iterator iter = effectPanels.iterator(); iter.hasNext(); ) {
                ConfigurableEffect effect = ((EffectPanel) iter.next()).getEffect();
                if (effect == selectedEffect) {
                    enabled = false;
                    break;
                }
            }
            addEffectButton.setEnabled(enabled);
        }
    });
    effectsList.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2 && addEffectButton.isEnabled())
                addEffectButton.doClick();
        }
    });
    addEffectButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            new EffectPanel((ConfigurableEffect) effectsList.getSelectedValue());
        }
    });
    openMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.hiero");
            dialog.setDirectory(prefs.get("dir.open", ""));
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.open", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            lastOpenFilename = fileName;
            open(new File(dialog.getDirectory(), fileName));
        }
    });
    saveMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Save Hiero settings file", FileDialog.SAVE);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.hiero");
            dialog.setDirectory(prefs.get("dir.save", ""));
            if (lastSaveFilename.length() > 0) {
                dialog.setFile(lastSaveFilename);
            } else if (lastOpenFilename.length() > 0) {
                dialog.setFile(lastOpenFilename);
            }
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.save", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            if (!fileName.endsWith(".hiero"))
                fileName += ".hiero";
            lastSaveFilename = fileName;
            File file = new File(dialog.getDirectory(), fileName);
            try {
                save(file);
            } catch (IOException ex) {
                throw new RuntimeException("Error saving Hiero settings file: " + file.getAbsolutePath(), ex);
            }
        }
    });
    saveBMFontMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.fnt");
            dialog.setDirectory(prefs.get("dir.savebm", ""));
            if (lastSaveBMFilename.length() > 0) {
                dialog.setFile(lastSaveBMFilename);
            } else if (lastOpenFilename.length() > 0) {
                dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
            }
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.savebm", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            lastSaveBMFilename = fileName;
            saveBm(new File(dialog.getDirectory(), fileName));
        }
    });
    exitMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            dispose();
        }
    });
    sampleNeheButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            sampleTextPane.setText(NEHE_CHARS);
            resetCacheButton.doClick();
        }
    });
    sampleAsciiButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            StringBuilder buffer = new StringBuilder();
            buffer.append(NEHE_CHARS);
            buffer.append('\n');
            int count = 0;
            for (int i = 33; i <= 255; i++) {
                if (buffer.indexOf(Character.toString((char) i)) != -1)
                    continue;
                buffer.append((char) i);
                if (++count % 30 == 0)
                    buffer.append('\n');
            }
            sampleTextPane.setText(buffer.toString());
            resetCacheButton.doClick();
        }
    });
    sampleExtendedButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            sampleTextPane.setText(EXTENDED_CHARS);
            resetCacheButton.doClick();
        }
    });
}
Also used : DocumentListener(javax.swing.event.DocumentListener) StringBuilder(com.badlogic.gdx.utils.StringBuilder) ActionEvent(java.awt.event.ActionEvent) ConfigurableEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect) KeyAdapter(java.awt.event.KeyAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) KeyEvent(java.awt.event.KeyEvent) Iterator(java.util.Iterator) ChangeListener(javax.swing.event.ChangeListener) MouseEvent(java.awt.event.MouseEvent) Color(com.badlogic.gdx.graphics.Color) JFormattedTextField(javax.swing.JFormattedTextField) MouseAdapter(java.awt.event.MouseAdapter) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) JSpinner(javax.swing.JSpinner) File(java.io.File) FileDialog(java.awt.FileDialog)

Example 2 with ConfigurableEffect

use of com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect in project libgdx by libgdx.

the class Hiero method open.

void open(File file) {
    EffectPanel[] panels = (EffectPanel[]) effectPanels.toArray(new EffectPanel[effectPanels.size()]);
    for (int i = 0; i < panels.length; i++) panels[i].remove();
    HieroSettings settings = new HieroSettings(file.getAbsolutePath());
    fontList.setSelectedValue(settings.getFontName(), true);
    fontSizeSpinner.setValue(new Integer(settings.getFontSize()));
    boldCheckBox.setSelected(settings.isBold());
    italicCheckBox.setSelected(settings.isItalic());
    monoCheckBox.setSelected(settings.isMono());
    gammaSpinner.setValue(new Float(settings.getGamma()));
    padTopSpinner.setValue(new Integer(settings.getPaddingTop()));
    padRightSpinner.setValue(new Integer(settings.getPaddingRight()));
    padBottomSpinner.setValue(new Integer(settings.getPaddingBottom()));
    padLeftSpinner.setValue(new Integer(settings.getPaddingLeft()));
    padAdvanceXSpinner.setValue(new Integer(settings.getPaddingAdvanceX()));
    padAdvanceYSpinner.setValue(new Integer(settings.getPaddingAdvanceY()));
    glyphPageWidthCombo.setSelectedItem(new Integer(settings.getGlyphPageWidth()));
    glyphPageHeightCombo.setSelectedItem(new Integer(settings.getGlyphPageHeight()));
    if (settings.getRenderType() == RenderType.Native.ordinal())
        nativeRadio.setSelected(true);
    else if (settings.getRenderType() == RenderType.FreeType.ordinal())
        freeTypeRadio.setSelected(true);
    else if (settings.getRenderType() == RenderType.Java.ordinal())
        javaRadio.setSelected(true);
    String gt = settings.getGlyphText();
    if (gt.length() > 0) {
        sampleTextPane.setText(settings.getGlyphText());
    }
    final String font2 = settings.getFont2File();
    if (font2.length() > 0)
        fontFileText.setText(font2);
    else
        fontFileText.setText(prefs.get("font.file", ""));
    fontFileRadio.setSelected(settings.isFont2Active());
    systemFontRadio.setSelected(!settings.isFont2Active());
    for (Iterator iter = settings.getEffects().iterator(); iter.hasNext(); ) {
        ConfigurableEffect settingsEffect = (ConfigurableEffect) iter.next();
        for (int i = 0, n = effectsListModel.getSize(); i < n; i++) {
            ConfigurableEffect effect = (ConfigurableEffect) effectsListModel.getElementAt(i);
            if (effect.getClass() == settingsEffect.getClass()) {
                effect.setValues(settingsEffect.getValues());
                new EffectPanel(effect);
                break;
            }
        }
    }
    updateFont();
}
Also used : ConfigurableEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect) Iterator(java.util.Iterator)

Example 3 with ConfigurableEffect

use of com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect in project libgdx by libgdx.

the class HieroSettings method save.

/** Saves the settings to a file.
	 * @throws IOException if the file could not be saved. */
public void save(File file) throws IOException {
    PrintStream out = new PrintStream(file, "UTF-8");
    out.println("font.name=" + fontName);
    out.println("font.size=" + fontSize);
    out.println("font.bold=" + bold);
    out.println("font.italic=" + italic);
    out.println("font.gamma=" + gamma);
    out.println("font.mono=" + mono);
    out.println();
    out.println("font2.file=" + font2File);
    out.println("font2.use=" + font2Active);
    out.println();
    out.println("pad.top=" + paddingTop);
    out.println("pad.right=" + paddingRight);
    out.println("pad.bottom=" + paddingBottom);
    out.println("pad.left=" + paddingLeft);
    out.println("pad.advance.x=" + paddingAdvanceX);
    out.println("pad.advance.y=" + paddingAdvanceY);
    out.println();
    out.println("glyph.native.rendering=" + nativeRendering);
    out.println("glyph.page.width=" + glyphPageWidth);
    out.println("glyph.page.height=" + glyphPageHeight);
    out.println("glyph.text=" + glyphText);
    out.println();
    out.println(RENDER_TYPE + "=" + renderType);
    out.println();
    for (Iterator iter = effects.iterator(); iter.hasNext(); ) {
        ConfigurableEffect effect = (ConfigurableEffect) iter.next();
        out.println("effect.class=" + effect.getClass().getName());
        for (Iterator iter2 = effect.getValues().iterator(); iter2.hasNext(); ) {
            Value value = (Value) iter2.next();
            out.println("effect." + value.getName() + "=" + value.getString());
        }
        out.println();
    }
    out.close();
}
Also used : PrintStream(java.io.PrintStream) ConfigurableEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect) Iterator(java.util.Iterator) Value(com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect.Value)

Aggregations

ConfigurableEffect (com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect)3 Iterator (java.util.Iterator)3 Color (com.badlogic.gdx.graphics.Color)1 Value (com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect.Value)1 StringBuilder (com.badlogic.gdx.utils.StringBuilder)1 FileDialog (java.awt.FileDialog)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 JFormattedTextField (javax.swing.JFormattedTextField)1 JSpinner (javax.swing.JSpinner)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 DocumentEvent (javax.swing.event.DocumentEvent)1