gdx-studio
git clone https://git.pyrossh.dev/gdx-studio
An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop
src_libs/com/badlogic/gdx/tools/hiero/HieroPanel.java
| a62d533 | 1 | /******************************************************************************* |
| a62d533 | 2 | * Copyright 2011 See AUTHORS file. |
| a62d533 | 3 | * |
| a62d533 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| a62d533 | 5 | * you may not use this file except in compliance with the License. |
| a62d533 | 6 | * You may obtain a copy of the License at |
| a62d533 | 7 | * |
| a62d533 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| a62d533 | 9 | * |
| a62d533 | 10 | * Unless required by applicable law or agreed to in writing, software |
| a62d533 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| a62d533 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| a62d533 | 13 | * See the License for the specific language governing permissions and |
| a62d533 | 14 | * limitations under the License. |
| a62d533 | 15 | ******************************************************************************/ |
| a62d533 | 16 | |
| a62d533 | 17 | package com.badlogic.gdx.tools.hiero; |
| a62d533 | 18 | |
| a62d533 | 19 | import java.awt.BorderLayout; |
| a62d533 | 20 | import java.awt.Component; |
| a62d533 | 21 | import java.awt.Container; |
| a62d533 | 22 | import java.awt.Dimension; |
| a62d533 | 23 | import java.awt.EventQueue; |
| a62d533 | 24 | import java.awt.FileDialog; |
| a62d533 | 25 | import java.awt.FlowLayout; |
| a62d533 | 26 | import java.awt.Font; |
| a62d533 | 27 | import java.awt.Frame; |
| a62d533 | 28 | import java.awt.GraphicsEnvironment; |
| a62d533 | 29 | import java.awt.GridBagConstraints; |
| a62d533 | 30 | import java.awt.GridBagLayout; |
| a62d533 | 31 | import java.awt.Insets; |
| a62d533 | 32 | import java.awt.LayoutManager; |
| a62d533 | 33 | import java.awt.event.ActionEvent; |
| a62d533 | 34 | import java.awt.event.ActionListener; |
| a62d533 | 35 | import java.awt.event.KeyAdapter; |
| a62d533 | 36 | import java.awt.event.KeyEvent; |
| a62d533 | 37 | import java.awt.event.MouseAdapter; |
| a62d533 | 38 | import java.awt.event.MouseEvent; |
| a62d533 | 39 | import java.awt.image.BufferedImage; |
| a62d533 | 40 | import java.io.File; |
| a62d533 | 41 | import java.io.IOException; |
| a62d533 | 42 | import java.util.ArrayList; |
| a62d533 | 43 | import java.util.Iterator; |
| a62d533 | 44 | import java.util.List; |
| a62d533 | 45 | import java.util.prefs.Preferences; |
| a62d533 | 46 | |
| a62d533 | 47 | import javax.swing.BorderFactory; |
| a62d533 | 48 | import javax.swing.ButtonGroup; |
| a62d533 | 49 | import javax.swing.DefaultComboBoxModel; |
| a62d533 | 50 | import javax.swing.Icon; |
| a62d533 | 51 | import javax.swing.ImageIcon; |
| a62d533 | 52 | import javax.swing.JButton; |
| a62d533 | 53 | import javax.swing.JCheckBox; |
| a62d533 | 54 | import javax.swing.JColorChooser; |
| a62d533 | 55 | import javax.swing.JComboBox; |
| a62d533 | 56 | import javax.swing.JFormattedTextField; |
| a62d533 | 57 | import javax.swing.JLabel; |
| a62d533 | 58 | import javax.swing.JList; |
| a62d533 | 59 | import javax.swing.JMenu; |
| a62d533 | 60 | import javax.swing.JMenuBar; |
| a62d533 | 61 | import javax.swing.JMenuItem; |
| a62d533 | 62 | import javax.swing.JPanel; |
| a62d533 | 63 | import javax.swing.JRadioButton; |
| a62d533 | 64 | import javax.swing.JScrollPane; |
| a62d533 | 65 | import javax.swing.JSpinner; |
| a62d533 | 66 | import javax.swing.JTextField; |
| a62d533 | 67 | import javax.swing.JTextPane; |
| a62d533 | 68 | import javax.swing.JWindow; |
| a62d533 | 69 | import javax.swing.KeyStroke; |
| a62d533 | 70 | import javax.swing.ScrollPaneConstants; |
| a62d533 | 71 | import javax.swing.SpinnerNumberModel; |
| a62d533 | 72 | import javax.swing.border.EmptyBorder; |
| a62d533 | 73 | import javax.swing.event.ChangeEvent; |
| a62d533 | 74 | import javax.swing.event.ChangeListener; |
| a62d533 | 75 | import javax.swing.event.DocumentEvent; |
| a62d533 | 76 | import javax.swing.event.DocumentListener; |
| a62d533 | 77 | import javax.swing.event.ListSelectionEvent; |
| a62d533 | 78 | import javax.swing.event.ListSelectionListener; |
| a62d533 | 79 | |
| a62d533 | 80 | import org.lwjgl.opengl.GL11; |
| a62d533 | 81 | |
| a62d533 | 82 | import com.badlogic.gdx.ApplicationListener; |
| a62d533 | 83 | import com.badlogic.gdx.Gdx; |
| a62d533 | 84 | import com.badlogic.gdx.backends.lwjgl.LwjglAWTCanvas; |
| a62d533 | 85 | import com.badlogic.gdx.graphics.Color; |
| a62d533 | 86 | import com.badlogic.gdx.graphics.Texture; |
| a62d533 | 87 | import com.badlogic.gdx.graphics.g2d.BitmapFont; |
| a62d533 | 88 | import com.badlogic.gdx.tools.hiero.BMFontUtil; |
| a62d533 | 89 | import com.badlogic.gdx.tools.hiero.unicodefont.GlyphPage; |
| a62d533 | 90 | import com.badlogic.gdx.tools.hiero.unicodefont.HieroSettings; |
| a62d533 | 91 | import com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont; |
| a62d533 | 92 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.ColorEffect; |
| a62d533 | 93 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect; |
| a62d533 | 94 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect.Value; |
| a62d533 | 95 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.DistanceFieldEffect; |
| a62d533 | 96 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.EffectUtil; |
| a62d533 | 97 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.GradientEffect; |
| a62d533 | 98 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.OutlineEffect; |
| a62d533 | 99 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.OutlineWobbleEffect; |
| a62d533 | 100 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.OutlineZigzagEffect; |
| a62d533 | 101 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.ShadowEffect; |
| a62d533 | 102 | |
| a62d533 | 103 | import static org.lwjgl.opengl.GL11.*; |
| a62d533 | 104 | |
| a62d533 | 105 | /** A tool to visualize settings for {@link UnicodeFont} and to export BMFont files for use with {@link BitmapFont}.
|
| a62d533 | 106 | * @author Nathan Sweet */ |
| a62d533 | 107 | public class HieroPanel extends JPanel {
|
| a62d533 | 108 | static final String NEHE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" // |
| a62d533 | 109 | + "abcdefghijklmnopqrstuvwxyz\n1234567890\n" // |
| a62d533 | 110 | + "\"!`?'.,;:()[]{}<>|/@\\^$-%+=#_&~*\u007F";
|
| a62d533 | 111 | |
| a62d533 | 112 | public static volatile UnicodeFont newUnicodeFont; |
| a62d533 | 113 | public static UnicodeFont unicodeFont; |
| a62d533 | 114 | public static Color renderingBackgroundColor = Color.BLACK; |
| a62d533 | 115 | List effectPanels = new ArrayList(); |
| a62d533 | 116 | Preferences prefs; |
| a62d533 | 117 | ColorEffect colorEffect; |
| a62d533 | 118 | |
| a62d533 | 119 | JScrollPane appliedEffectsScroll; |
| a62d533 | 120 | JPanel appliedEffectsPanel; |
| a62d533 | 121 | JButton addEffectButton; |
| a62d533 | 122 | public static JTextPane sampleTextPane; |
| a62d533 | 123 | JSpinner padAdvanceXSpinner; |
| a62d533 | 124 | JList effectsList; |
| a62d533 | 125 | public static JPanel gamePanel; |
| a62d533 | 126 | JTextField fontFileText; |
| a62d533 | 127 | JRadioButton fontFileRadio; |
| a62d533 | 128 | JRadioButton systemFontRadio; |
| a62d533 | 129 | JSpinner padBottomSpinner; |
| a62d533 | 130 | JSpinner padLeftSpinner; |
| a62d533 | 131 | JSpinner padRightSpinner; |
| a62d533 | 132 | JSpinner padTopSpinner; |
| a62d533 | 133 | JList fontList; |
| a62d533 | 134 | JSpinner fontSizeSpinner; |
| a62d533 | 135 | DefaultComboBoxModel fontListModel; |
| a62d533 | 136 | JLabel backgroundColorLabel; |
| a62d533 | 137 | JButton browseButton; |
| a62d533 | 138 | JSpinner padAdvanceYSpinner; |
| a62d533 | 139 | JCheckBox italicCheckBox; |
| a62d533 | 140 | JCheckBox boldCheckBox; |
| a62d533 | 141 | JRadioButton javaRadio; |
| a62d533 | 142 | JRadioButton nativeRadio; |
| a62d533 | 143 | public static JLabel glyphsTotalLabel; |
| a62d533 | 144 | public static JLabel glyphPagesTotalLabel; |
| a62d533 | 145 | JComboBox glyphPageHeightCombo; |
| a62d533 | 146 | JComboBox glyphPageWidthCombo; |
| a62d533 | 147 | public static JComboBox glyphPageCombo; |
| a62d533 | 148 | JPanel glyphCachePanel; |
| a62d533 | 149 | JRadioButton glyphCacheRadio; |
| a62d533 | 150 | public static JRadioButton sampleTextRadio; |
| a62d533 | 151 | public static DefaultComboBoxModel glyphPageComboModel; |
| a62d533 | 152 | JButton resetCacheButton; |
| a62d533 | 153 | JButton sampleAsciiButton; |
| a62d533 | 154 | JButton sampleNeheButton; |
| a62d533 | 155 | DefaultComboBoxModel effectsListModel; |
| a62d533 | 156 | JMenuItem openMenuItem; |
| a62d533 | 157 | JMenuItem saveMenuItem; |
| a62d533 | 158 | JMenuItem exitMenuItem; |
| a62d533 | 159 | JMenuItem saveBMFontMenuItem; |
| a62d533 | 160 | public static File saveBmFontFile; |
| a62d533 | 161 | String lastSaveFilename = "", lastSaveBMFilename = "", lastOpenFilename = ""; |
| a62d533 | 162 | |
| a62d533 | 163 | //FontRenderer fontRenderer; |
| a62d533 | 164 | //LwjglAWTCanvas canvas; |
| a62d533 | 165 | |
| a62d533 | 166 | public HieroPanel() {
|
| a62d533 | 167 | super(new BorderLayout()); |
| a62d533 | 168 | initialize(); |
| a62d533 | 169 | //fontRenderer = new FontRenderer(); |
| a62d533 | 170 | //canvas = new LwjglAWTCanvas(fontRenderer, false); |
| a62d533 | 171 | //gamePanel.add(canvas.getCanvas()); |
| a62d533 | 172 | prefs = Preferences.userNodeForPackage(HieroPanel.class); |
| a62d533 | 173 | java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000"));
|
| a62d533 | 174 | backgroundColorLabel.setIcon(getColorIcon(backgroundColor)); |
| a62d533 | 175 | renderingBackgroundColor = new Color(backgroundColor.getRed() / 255f, backgroundColor.getGreen() / 255f, |
| a62d533 | 176 | backgroundColor.getBlue() / 255f, 1); |
| a62d533 | 177 | fontList.setSelectedValue(prefs.get("system.font", "Arial"), true);
|
| a62d533 | 178 | fontFileText.setText(prefs.get("font.file", ""));
|
| a62d533 | 179 | |
| a62d533 | 180 | java.awt.Color foregroundColor = EffectUtil.fromString(prefs.get("foreground", "ffffff"));
|
| a62d533 | 181 | colorEffect = new ColorEffect(); |
| a62d533 | 182 | colorEffect.setColor(foregroundColor); |
| a62d533 | 183 | effectsListModel.addElement(colorEffect); |
| a62d533 | 184 | effectsListModel.addElement(new GradientEffect()); |
| a62d533 | 185 | effectsListModel.addElement(new OutlineEffect()); |
| a62d533 | 186 | effectsListModel.addElement(new OutlineWobbleEffect()); |
| a62d533 | 187 | effectsListModel.addElement(new OutlineZigzagEffect()); |
| a62d533 | 188 | effectsListModel.addElement(new ShadowEffect()); |
| a62d533 | 189 | effectsListModel.addElement(new DistanceFieldEffect()); |
| a62d533 | 190 | new EffectPanel(colorEffect); |
| a62d533 | 191 | setVisible(true); |
| a62d533 | 192 | } |
| a62d533 | 193 | |
| a62d533 | 194 | void initialize () {
|
| a62d533 | 195 | initializeComponents(); |
| a62d533 | 196 | initializeMenus(); |
| a62d533 | 197 | initializeEvents(); |
| a62d533 | 198 | sampleNeheButton.doClick(); |
| a62d533 | 199 | } |
| a62d533 | 200 | |
| a62d533 | 201 | void updateFont () {
|
| a62d533 | 202 | updateFont(false); |
| a62d533 | 203 | } |
| a62d533 | 204 | |
| a62d533 | 205 | private void updateFont (boolean ignoreFileText) {
|
| a62d533 | 206 | UnicodeFont unicodeFont; |
| a62d533 | 207 | |
| a62d533 | 208 | int fontSize = ((Integer)fontSizeSpinner.getValue()).intValue(); |
| a62d533 | 209 | |
| a62d533 | 210 | File file = new File(fontFileText.getText()); |
| a62d533 | 211 | if (!ignoreFileText && file.exists() && file.isFile()) {
|
| a62d533 | 212 | // Load from file. |
| a62d533 | 213 | fontFileRadio.setSelected(true); |
| a62d533 | 214 | fontList.setEnabled(false); |
| a62d533 | 215 | systemFontRadio.setEnabled(false); |
| a62d533 | 216 | try {
|
| a62d533 | 217 | unicodeFont = new UnicodeFont(fontFileText.getText(), fontSize, boldCheckBox.isSelected(), |
| a62d533 | 218 | italicCheckBox.isSelected()); |
| a62d533 | 219 | } catch (Throwable ex) {
|
| a62d533 | 220 | ex.printStackTrace(); |
| a62d533 | 221 | updateFont(true); |
| a62d533 | 222 | return; |
| a62d533 | 223 | } |
| a62d533 | 224 | } else {
|
| a62d533 | 225 | // Load from java.awt.Font (kerning not available!). |
| a62d533 | 226 | fontList.setEnabled(true); |
| a62d533 | 227 | systemFontRadio.setEnabled(true); |
| a62d533 | 228 | systemFontRadio.setSelected(true); |
| a62d533 | 229 | unicodeFont = new UnicodeFont(Font.decode((String)fontList.getSelectedValue()), fontSize, boldCheckBox.isSelected(), |
| a62d533 | 230 | italicCheckBox.isSelected()); |
| a62d533 | 231 | } |
| a62d533 | 232 | unicodeFont.setPaddingTop(((Integer)padTopSpinner.getValue()).intValue()); |
| a62d533 | 233 | unicodeFont.setPaddingRight(((Integer)padRightSpinner.getValue()).intValue()); |
| a62d533 | 234 | unicodeFont.setPaddingBottom(((Integer)padBottomSpinner.getValue()).intValue()); |
| a62d533 | 235 | unicodeFont.setPaddingLeft(((Integer)padLeftSpinner.getValue()).intValue()); |
| a62d533 | 236 | unicodeFont.setPaddingAdvanceX(((Integer)padAdvanceXSpinner.getValue()).intValue()); |
| a62d533 | 237 | unicodeFont.setPaddingAdvanceY(((Integer)padAdvanceYSpinner.getValue()).intValue()); |
| a62d533 | 238 | unicodeFont.setGlyphPageWidth(((Integer)glyphPageWidthCombo.getSelectedItem()).intValue()); |
| a62d533 | 239 | unicodeFont.setGlyphPageHeight(((Integer)glyphPageHeightCombo.getSelectedItem()).intValue()); |
| a62d533 | 240 | unicodeFont.setNativeRendering(nativeRadio.isSelected()); |
| a62d533 | 241 | |
| a62d533 | 242 | for (Iterator iter = effectPanels.iterator(); iter.hasNext();) {
|
| a62d533 | 243 | EffectPanel panel = (EffectPanel)iter.next(); |
| a62d533 | 244 | unicodeFont.getEffects().add(panel.getEffect()); |
| a62d533 | 245 | } |
| a62d533 | 246 | |
| a62d533 | 247 | int size = sampleTextPane.getFont().getSize(); |
| a62d533 | 248 | if (size < 14) size = 14; |
| a62d533 | 249 | sampleTextPane.setFont(unicodeFont.getFont().deriveFont((float)size)); |
| a62d533 | 250 | |
| a62d533 | 251 | this.newUnicodeFont = unicodeFont; |
| a62d533 | 252 | } |
| a62d533 | 253 | |
| a62d533 | 254 | void save (File file) throws IOException {
|
| a62d533 | 255 | HieroSettings settings = new HieroSettings(); |
| a62d533 | 256 | settings.setFontName((String)fontList.getSelectedValue()); |
| a62d533 | 257 | settings.setFontSize(((Integer)fontSizeSpinner.getValue()).intValue()); |
| a62d533 | 258 | settings.setBold(boldCheckBox.isSelected()); |
| a62d533 | 259 | settings.setItalic(italicCheckBox.isSelected()); |
| a62d533 | 260 | settings.setPaddingTop(((Integer)padTopSpinner.getValue()).intValue()); |
| a62d533 | 261 | settings.setPaddingRight(((Integer)padRightSpinner.getValue()).intValue()); |
| a62d533 | 262 | settings.setPaddingBottom(((Integer)padBottomSpinner.getValue()).intValue()); |
| a62d533 | 263 | settings.setPaddingLeft(((Integer)padLeftSpinner.getValue()).intValue()); |
| a62d533 | 264 | settings.setPaddingAdvanceX(((Integer)padAdvanceXSpinner.getValue()).intValue()); |
| a62d533 | 265 | settings.setPaddingAdvanceY(((Integer)padAdvanceYSpinner.getValue()).intValue()); |
| a62d533 | 266 | settings.setGlyphPageWidth(((Integer)glyphPageWidthCombo.getSelectedItem()).intValue()); |
| a62d533 | 267 | settings.setGlyphPageHeight(((Integer)glyphPageHeightCombo.getSelectedItem()).intValue()); |
| a62d533 | 268 | settings.setGlyphText(sampleTextPane.getText()); |
| a62d533 | 269 | for (Iterator iter = effectPanels.iterator(); iter.hasNext();) {
|
| a62d533 | 270 | EffectPanel panel = (EffectPanel)iter.next(); |
| a62d533 | 271 | settings.getEffects().add(panel.getEffect()); |
| a62d533 | 272 | } |
| a62d533 | 273 | settings.save(file); |
| a62d533 | 274 | } |
| a62d533 | 275 | |
| a62d533 | 276 | void open (File file) {
|
| a62d533 | 277 | EffectPanel[] panels = (EffectPanel[])effectPanels.toArray(new EffectPanel[effectPanels.size()]); |
| a62d533 | 278 | for (int i = 0; i < panels.length; i++) |
| a62d533 | 279 | panels[i].remove(); |
| a62d533 | 280 | |
| a62d533 | 281 | HieroSettings settings = new HieroSettings(file.getAbsolutePath()); |
| a62d533 | 282 | fontList.setSelectedValue(settings.getFontName(), true); |
| a62d533 | 283 | fontSizeSpinner.setValue(new Integer(settings.getFontSize())); |
| a62d533 | 284 | boldCheckBox.setSelected(settings.isBold()); |
| a62d533 | 285 | italicCheckBox.setSelected(settings.isItalic()); |
| a62d533 | 286 | padTopSpinner.setValue(new Integer(settings.getPaddingTop())); |
| a62d533 | 287 | padRightSpinner.setValue(new Integer(settings.getPaddingRight())); |
| a62d533 | 288 | padBottomSpinner.setValue(new Integer(settings.getPaddingBottom())); |
| a62d533 | 289 | padLeftSpinner.setValue(new Integer(settings.getPaddingLeft())); |
| a62d533 | 290 | padAdvanceXSpinner.setValue(new Integer(settings.getPaddingAdvanceX())); |
| a62d533 | 291 | padAdvanceYSpinner.setValue(new Integer(settings.getPaddingAdvanceY())); |
| a62d533 | 292 | glyphPageWidthCombo.setSelectedItem(new Integer(settings.getGlyphPageWidth())); |
| a62d533 | 293 | glyphPageHeightCombo.setSelectedItem(new Integer(settings.getGlyphPageHeight())); |
| a62d533 | 294 | String gt = settings.getGlyphText(); |
| a62d533 | 295 | if (gt.length() > 0) {
|
| a62d533 | 296 | sampleTextPane.setText(settings.getGlyphText()); |
| a62d533 | 297 | } |
| a62d533 | 298 | |
| a62d533 | 299 | for (Iterator iter = settings.getEffects().iterator(); iter.hasNext();) {
|
| a62d533 | 300 | ConfigurableEffect settingsEffect = (ConfigurableEffect)iter.next(); |
| a62d533 | 301 | for (int i = 0, n = effectsListModel.getSize(); i < n; i++) {
|
| a62d533 | 302 | ConfigurableEffect effect = (ConfigurableEffect)effectsListModel.getElementAt(i); |
| a62d533 | 303 | if (effect.getClass() == settingsEffect.getClass()) {
|
| a62d533 | 304 | effect.setValues(settingsEffect.getValues()); |
| a62d533 | 305 | new EffectPanel(effect); |
| a62d533 | 306 | break; |
| a62d533 | 307 | } |
| a62d533 | 308 | } |
| a62d533 | 309 | } |
| a62d533 | 310 | |
| a62d533 | 311 | updateFont(); |
| a62d533 | 312 | } |
| a62d533 | 313 | |
| a62d533 | 314 | private void initializeEvents () {
|
| a62d533 | 315 | fontList.addListSelectionListener(new ListSelectionListener() {
|
| a62d533 | 316 | public void valueChanged (ListSelectionEvent evt) {
|
| a62d533 | 317 | if (evt.getValueIsAdjusting()) return; |
| a62d533 | 318 | prefs.put("system.font", (String)fontList.getSelectedValue());
|
| a62d533 | 319 | updateFont(); |
| a62d533 | 320 | } |
| a62d533 | 321 | }); |
| a62d533 | 322 | |
| a62d533 | 323 | class FontUpdateListener implements ChangeListener, ActionListener {
|
| a62d533 | 324 | public void stateChanged (ChangeEvent evt) {
|
| a62d533 | 325 | updateFont(); |
| a62d533 | 326 | } |
| a62d533 | 327 | |
| a62d533 | 328 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 329 | updateFont(); |
| a62d533 | 330 | } |
| a62d533 | 331 | |
| a62d533 | 332 | public void addSpinners (JSpinner[] spinners) {
|
| a62d533 | 333 | for (int i = 0; i < spinners.length; i++) {
|
| a62d533 | 334 | final JSpinner spinner = spinners[i]; |
| a62d533 | 335 | spinner.addChangeListener(this); |
| a62d533 | 336 | ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().addKeyListener(new KeyAdapter() {
|
| a62d533 | 337 | String lastText; |
| a62d533 | 338 | |
| a62d533 | 339 | public void keyReleased (KeyEvent evt) {
|
| a62d533 | 340 | JFormattedTextField textField = ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField(); |
| a62d533 | 341 | String text = textField.getText(); |
| a62d533 | 342 | if (text.length() == 0) return; |
| a62d533 | 343 | if (text.equals(lastText)) return; |
| a62d533 | 344 | lastText = text; |
| a62d533 | 345 | int caretPosition = textField.getCaretPosition(); |
| a62d533 | 346 | try {
|
| a62d533 | 347 | spinner.setValue(Integer.valueOf(text)); |
| a62d533 | 348 | textField.setCaretPosition(caretPosition); |
| a62d533 | 349 | } catch (Throwable ignored) {
|
| a62d533 | 350 | } |
| a62d533 | 351 | } |
| a62d533 | 352 | }); |
| a62d533 | 353 | } |
| a62d533 | 354 | } |
| a62d533 | 355 | } |
| a62d533 | 356 | FontUpdateListener listener = new FontUpdateListener(); |
| a62d533 | 357 | |
| a62d533 | 358 | listener.addSpinners(new JSpinner[] {padTopSpinner, padRightSpinner, padBottomSpinner, padLeftSpinner, padAdvanceXSpinner,
|
| a62d533 | 359 | padAdvanceYSpinner}); |
| a62d533 | 360 | fontSizeSpinner.addChangeListener(listener); |
| a62d533 | 361 | |
| a62d533 | 362 | glyphPageWidthCombo.addActionListener(listener); |
| a62d533 | 363 | glyphPageHeightCombo.addActionListener(listener); |
| a62d533 | 364 | boldCheckBox.addActionListener(listener); |
| a62d533 | 365 | italicCheckBox.addActionListener(listener); |
| a62d533 | 366 | resetCacheButton.addActionListener(listener); |
| a62d533 | 367 | javaRadio.addActionListener(listener); |
| a62d533 | 368 | nativeRadio.addActionListener(listener); |
| a62d533 | 369 | |
| a62d533 | 370 | sampleTextRadio.addActionListener(new ActionListener() {
|
| a62d533 | 371 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 372 | glyphCachePanel.setVisible(false); |
| a62d533 | 373 | } |
| a62d533 | 374 | }); |
| a62d533 | 375 | glyphCacheRadio.addActionListener(new ActionListener() {
|
| a62d533 | 376 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 377 | glyphCachePanel.setVisible(true); |
| a62d533 | 378 | } |
| a62d533 | 379 | }); |
| a62d533 | 380 | |
| a62d533 | 381 | fontFileText.getDocument().addDocumentListener(new DocumentListener() {
|
| a62d533 | 382 | public void removeUpdate (DocumentEvent evt) {
|
| a62d533 | 383 | changed(); |
| a62d533 | 384 | } |
| a62d533 | 385 | |
| a62d533 | 386 | public void insertUpdate (DocumentEvent evt) {
|
| a62d533 | 387 | changed(); |
| a62d533 | 388 | } |
| a62d533 | 389 | |
| a62d533 | 390 | public void changedUpdate (DocumentEvent evt) {
|
| a62d533 | 391 | changed(); |
| a62d533 | 392 | } |
| a62d533 | 393 | |
| a62d533 | 394 | private void changed () {
|
| a62d533 | 395 | File file = new File(fontFileText.getText()); |
| a62d533 | 396 | if (fontList.isEnabled() && (!file.exists() || !file.isFile())) return; |
| a62d533 | 397 | prefs.put("font.file", fontFileText.getText());
|
| a62d533 | 398 | updateFont(); |
| a62d533 | 399 | } |
| a62d533 | 400 | }); |
| a62d533 | 401 | |
| a62d533 | 402 | fontFileRadio.addActionListener(new ActionListener() {
|
| a62d533 | 403 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 404 | if (fontList.isEnabled()) systemFontRadio.setSelected(true); |
| a62d533 | 405 | } |
| a62d533 | 406 | }); |
| a62d533 | 407 | |
| a62d533 | 408 | browseButton.addActionListener(new ActionListener() {
|
| a62d533 | 409 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 410 | FileDialog dialog = new FileDialog((Frame)null, "Choose TrueType font file", FileDialog.LOAD); |
| a62d533 | 411 | dialog.setLocationRelativeTo(null); |
| a62d533 | 412 | dialog.setFile("*.ttf");
|
| a62d533 | 413 | dialog.setDirectory(prefs.get("dir.font", ""));
|
| a62d533 | 414 | dialog.setVisible(true); |
| a62d533 | 415 | if (dialog.getDirectory() != null) {
|
| a62d533 | 416 | prefs.put("dir.font", dialog.getDirectory());
|
| a62d533 | 417 | } |
| a62d533 | 418 | |
| a62d533 | 419 | String fileName = dialog.getFile(); |
| a62d533 | 420 | if (fileName == null) return; |
| a62d533 | 421 | fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath()); |
| a62d533 | 422 | } |
| a62d533 | 423 | }); |
| a62d533 | 424 | |
| a62d533 | 425 | backgroundColorLabel.addMouseListener(new MouseAdapter() {
|
| a62d533 | 426 | public void mouseClicked (MouseEvent evt) {
|
| a62d533 | 427 | java.awt.Color color = JColorChooser.showDialog(null, "Choose a background color", |
| a62d533 | 428 | EffectUtil.fromString(prefs.get("background", "000000")));
|
| a62d533 | 429 | if (color == null) return; |
| a62d533 | 430 | renderingBackgroundColor = new Color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1); |
| a62d533 | 431 | backgroundColorLabel.setIcon(getColorIcon(color)); |
| a62d533 | 432 | prefs.put("background", EffectUtil.toString(color));
|
| a62d533 | 433 | } |
| a62d533 | 434 | }); |
| a62d533 | 435 | |
| a62d533 | 436 | effectsList.addListSelectionListener(new ListSelectionListener() {
|
| a62d533 | 437 | public void valueChanged (ListSelectionEvent evt) {
|
| a62d533 | 438 | ConfigurableEffect selectedEffect = (ConfigurableEffect)effectsList.getSelectedValue(); |
| a62d533 | 439 | boolean enabled = selectedEffect != null; |
| a62d533 | 440 | for (Iterator iter = effectPanels.iterator(); iter.hasNext();) {
|
| a62d533 | 441 | ConfigurableEffect effect = ((EffectPanel)iter.next()).getEffect(); |
| a62d533 | 442 | if (effect == selectedEffect) {
|
| a62d533 | 443 | enabled = false; |
| a62d533 | 444 | break; |
| a62d533 | 445 | } |
| a62d533 | 446 | } |
| a62d533 | 447 | addEffectButton.setEnabled(enabled); |
| a62d533 | 448 | } |
| a62d533 | 449 | }); |
| a62d533 | 450 | |
| a62d533 | 451 | effectsList.addMouseListener(new MouseAdapter() {
|
| a62d533 | 452 | public void mouseClicked (MouseEvent evt) {
|
| a62d533 | 453 | if (evt.getClickCount() == 2 && addEffectButton.isEnabled()) addEffectButton.doClick(); |
| a62d533 | 454 | } |
| a62d533 | 455 | }); |
| a62d533 | 456 | |
| a62d533 | 457 | addEffectButton.addActionListener(new ActionListener() {
|
| a62d533 | 458 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 459 | new EffectPanel((ConfigurableEffect)effectsList.getSelectedValue()); |
| a62d533 | 460 | } |
| a62d533 | 461 | }); |
| a62d533 | 462 | |
| a62d533 | 463 | openMenuItem.addActionListener(new ActionListener() {
|
| a62d533 | 464 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 465 | FileDialog dialog = new FileDialog((Frame)null, "Open Hiero settings file", FileDialog.LOAD); |
| a62d533 | 466 | dialog.setLocationRelativeTo(null); |
| a62d533 | 467 | dialog.setFile("*.hiero");
|
| a62d533 | 468 | dialog.setDirectory(prefs.get("dir.open", ""));
|
| a62d533 | 469 | dialog.setVisible(true); |
| a62d533 | 470 | if (dialog.getDirectory() != null) {
|
| a62d533 | 471 | prefs.put("dir.open", dialog.getDirectory());
|
| a62d533 | 472 | } |
| a62d533 | 473 | |
| a62d533 | 474 | String fileName = dialog.getFile(); |
| a62d533 | 475 | if (fileName == null) return; |
| a62d533 | 476 | lastOpenFilename = fileName; |
| a62d533 | 477 | open(new File(dialog.getDirectory(), fileName)); |
| a62d533 | 478 | } |
| a62d533 | 479 | }); |
| a62d533 | 480 | |
| a62d533 | 481 | saveMenuItem.addActionListener(new ActionListener() {
|
| a62d533 | 482 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 483 | FileDialog dialog = new FileDialog((Frame)null, "Save Hiero settings file", FileDialog.SAVE); |
| a62d533 | 484 | dialog.setLocationRelativeTo(null); |
| a62d533 | 485 | dialog.setFile("*.hiero");
|
| a62d533 | 486 | dialog.setDirectory(prefs.get("dir.save", ""));
|
| a62d533 | 487 | |
| a62d533 | 488 | if (lastSaveFilename.length() > 0) {
|
| a62d533 | 489 | dialog.setFile(lastSaveFilename); |
| a62d533 | 490 | } else if (lastOpenFilename.length() > 0) {
|
| a62d533 | 491 | dialog.setFile(lastOpenFilename); |
| a62d533 | 492 | } |
| a62d533 | 493 | |
| a62d533 | 494 | dialog.setVisible(true); |
| a62d533 | 495 | |
| a62d533 | 496 | if (dialog.getDirectory() != null) {
|
| a62d533 | 497 | prefs.put("dir.save", dialog.getDirectory());
|
| a62d533 | 498 | } |
| a62d533 | 499 | |
| a62d533 | 500 | String fileName = dialog.getFile(); |
| a62d533 | 501 | if (fileName == null) return; |
| a62d533 | 502 | if (!fileName.endsWith(".hiero")) fileName += ".hiero";
|
| a62d533 | 503 | lastSaveFilename = fileName; |
| a62d533 | 504 | File file = new File(dialog.getDirectory(), fileName); |
| a62d533 | 505 | try {
|
| a62d533 | 506 | save(file); |
| a62d533 | 507 | } catch (IOException ex) {
|
| a62d533 | 508 | throw new RuntimeException("Error saving Hiero settings file: " + file.getAbsolutePath(), ex);
|
| a62d533 | 509 | } |
| a62d533 | 510 | } |
| a62d533 | 511 | }); |
| a62d533 | 512 | |
| a62d533 | 513 | saveBMFontMenuItem.addActionListener(new ActionListener() {
|
| a62d533 | 514 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 515 | FileDialog dialog = new FileDialog((Frame)null, "Save BMFont files", FileDialog.SAVE); |
| a62d533 | 516 | dialog.setLocationRelativeTo(null); |
| a62d533 | 517 | dialog.setFile("*.fnt");
|
| a62d533 | 518 | dialog.setDirectory(prefs.get("dir.savebm", ""));
|
| a62d533 | 519 | |
| a62d533 | 520 | if (lastSaveBMFilename.length() > 0) {
|
| a62d533 | 521 | dialog.setFile(lastSaveBMFilename); |
| a62d533 | 522 | } else if (lastOpenFilename.length() > 0) {
|
| a62d533 | 523 | dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
|
| a62d533 | 524 | } |
| a62d533 | 525 | |
| a62d533 | 526 | dialog.setVisible(true); |
| a62d533 | 527 | if (dialog.getDirectory() != null) {
|
| a62d533 | 528 | prefs.put("dir.savebm", dialog.getDirectory());
|
| a62d533 | 529 | } |
| a62d533 | 530 | |
| a62d533 | 531 | String fileName = dialog.getFile(); |
| a62d533 | 532 | if (fileName == null) return; |
| a62d533 | 533 | lastSaveBMFilename = fileName; |
| a62d533 | 534 | saveBmFontFile = new File(dialog.getDirectory(), fileName); |
| a62d533 | 535 | } |
| a62d533 | 536 | }); |
| a62d533 | 537 | |
| a62d533 | 538 | exitMenuItem.addActionListener(new ActionListener() {
|
| a62d533 | 539 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 540 | //dispose(); |
| a62d533 | 541 | } |
| a62d533 | 542 | }); |
| a62d533 | 543 | |
| a62d533 | 544 | sampleNeheButton.addActionListener(new ActionListener() {
|
| a62d533 | 545 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 546 | sampleTextPane.setText(NEHE); |
| a62d533 | 547 | } |
| a62d533 | 548 | }); |
| a62d533 | 549 | |
| a62d533 | 550 | sampleAsciiButton.addActionListener(new ActionListener() {
|
| a62d533 | 551 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 552 | StringBuilder buffer = new StringBuilder(); |
| a62d533 | 553 | buffer.append(NEHE); |
| a62d533 | 554 | buffer.append('\n');
|
| a62d533 | 555 | int count = 0; |
| a62d533 | 556 | for (int i = 33; i <= 255; i++) {
|
| a62d533 | 557 | if (buffer.indexOf(Character.toString((char)i)) != -1) continue; |
| a62d533 | 558 | buffer.append((char)i); |
| a62d533 | 559 | if (++count % 30 == 0) buffer.append('\n');
|
| a62d533 | 560 | } |
| a62d533 | 561 | sampleTextPane.setText(buffer.toString()); |
| a62d533 | 562 | } |
| a62d533 | 563 | }); |
| a62d533 | 564 | } |
| a62d533 | 565 | |
| a62d533 | 566 | private void initializeComponents () {
|
| a62d533 | 567 | setLayout(new GridBagLayout()); |
| a62d533 | 568 | JPanel leftSidePanel = new JPanel(); |
| a62d533 | 569 | leftSidePanel.setLayout(new GridBagLayout()); |
| a62d533 | 570 | add( |
| a62d533 | 571 | leftSidePanel, |
| a62d533 | 572 | new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), |
| a62d533 | 573 | 0, 0)); |
| a62d533 | 574 | {
|
| a62d533 | 575 | JPanel fontPanel = new JPanel(); |
| a62d533 | 576 | leftSidePanel.add(fontPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 577 | GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); |
| a62d533 | 578 | fontPanel.setLayout(new GridBagLayout()); |
| a62d533 | 579 | fontPanel.setBorder(BorderFactory.createTitledBorder("Font"));
|
| a62d533 | 580 | {
|
| a62d533 | 581 | fontSizeSpinner = new JSpinner(new SpinnerNumberModel(32, 0, 256, 1)); |
| a62d533 | 582 | fontPanel.add(fontSizeSpinner, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 583 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 584 | ((JSpinner.DefaultEditor)fontSizeSpinner.getEditor()).getTextField().setColumns(2); |
| a62d533 | 585 | } |
| a62d533 | 586 | {
|
| a62d533 | 587 | JScrollPane fontScroll = new JScrollPane(); |
| a62d533 | 588 | fontPanel.add(fontScroll, new GridBagConstraints(1, 1, 4, 1, 1.0, 1.0, GridBagConstraints.CENTER, |
| a62d533 | 589 | GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 590 | {
|
| a62d533 | 591 | fontListModel = new DefaultComboBoxModel(GraphicsEnvironment.getLocalGraphicsEnvironment() |
| a62d533 | 592 | .getAvailableFontFamilyNames()); |
| a62d533 | 593 | fontList = new JList(); |
| a62d533 | 594 | fontScroll.setViewportView(fontList); |
| a62d533 | 595 | fontList.setModel(fontListModel); |
| a62d533 | 596 | fontList.setVisibleRowCount(6); |
| a62d533 | 597 | fontList.setSelectedIndex(0); |
| a62d533 | 598 | fontScroll.setMinimumSize(new Dimension(220, fontList.getPreferredScrollableViewportSize().height)); |
| a62d533 | 599 | } |
| a62d533 | 600 | } |
| a62d533 | 601 | {
|
| a62d533 | 602 | systemFontRadio = new JRadioButton("System:", true);
|
| a62d533 | 603 | fontPanel.add(systemFontRadio, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, |
| a62d533 | 604 | GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0)); |
| a62d533 | 605 | systemFontRadio.setMargin(new Insets(0, 0, 0, 0)); |
| a62d533 | 606 | } |
| a62d533 | 607 | {
|
| a62d533 | 608 | fontFileRadio = new JRadioButton("File:");
|
| a62d533 | 609 | fontPanel.add(fontFileRadio, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, |
| a62d533 | 610 | GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 611 | fontFileRadio.setMargin(new Insets(0, 0, 0, 0)); |
| a62d533 | 612 | } |
| a62d533 | 613 | {
|
| a62d533 | 614 | fontFileText = new JTextField(); |
| a62d533 | 615 | fontPanel.add(fontFileText, new GridBagConstraints(1, 2, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 616 | GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0)); |
| a62d533 | 617 | } |
| a62d533 | 618 | {
|
| a62d533 | 619 | fontPanel.add(new JLabel("Size:"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
|
| a62d533 | 620 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 621 | } |
| a62d533 | 622 | {
|
| a62d533 | 623 | boldCheckBox = new JCheckBox("Bold");
|
| a62d533 | 624 | fontPanel.add(boldCheckBox, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 625 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 626 | } |
| a62d533 | 627 | {
|
| a62d533 | 628 | italicCheckBox = new JCheckBox("Italic");
|
| a62d533 | 629 | fontPanel.add(italicCheckBox, new GridBagConstraints(3, 3, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 630 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 631 | } |
| a62d533 | 632 | {
|
| a62d533 | 633 | browseButton = new JButton("...");
|
| a62d533 | 634 | fontPanel.add(browseButton, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 635 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 636 | browseButton.setMargin(new Insets(0, 0, 0, 0)); |
| a62d533 | 637 | } |
| a62d533 | 638 | {
|
| a62d533 | 639 | fontPanel.add(new JLabel("Rendering:"), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
|
| a62d533 | 640 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 641 | } |
| a62d533 | 642 | {
|
| a62d533 | 643 | javaRadio = new JRadioButton("Java");
|
| a62d533 | 644 | fontPanel.add(javaRadio, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 645 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 646 | javaRadio.setSelected(true); |
| a62d533 | 647 | } |
| a62d533 | 648 | {
|
| a62d533 | 649 | nativeRadio = new JRadioButton("Native");
|
| a62d533 | 650 | fontPanel.add(nativeRadio, new GridBagConstraints(2, 4, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 651 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 652 | } |
| a62d533 | 653 | ButtonGroup buttonGroup = new ButtonGroup(); |
| a62d533 | 654 | buttonGroup.add(systemFontRadio); |
| a62d533 | 655 | buttonGroup.add(fontFileRadio); |
| a62d533 | 656 | buttonGroup = new ButtonGroup(); |
| a62d533 | 657 | buttonGroup.add(javaRadio); |
| a62d533 | 658 | buttonGroup.add(nativeRadio); |
| a62d533 | 659 | } |
| a62d533 | 660 | {
|
| a62d533 | 661 | JPanel samplePanel = new JPanel(); |
| a62d533 | 662 | leftSidePanel.add(samplePanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 663 | GridBagConstraints.BOTH, new Insets(5, 0, 5, 5), 0, 0)); |
| a62d533 | 664 | samplePanel.setLayout(new GridBagLayout()); |
| a62d533 | 665 | samplePanel.setBorder(BorderFactory.createTitledBorder("Sample Text"));
|
| a62d533 | 666 | {
|
| a62d533 | 667 | JScrollPane textScroll = new JScrollPane(); |
| a62d533 | 668 | samplePanel.add(textScroll, new GridBagConstraints(0, 0, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, |
| a62d533 | 669 | GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 670 | {
|
| a62d533 | 671 | sampleTextPane = new JTextPane(); |
| a62d533 | 672 | textScroll.setViewportView(sampleTextPane); |
| a62d533 | 673 | } |
| a62d533 | 674 | } |
| a62d533 | 675 | {
|
| a62d533 | 676 | sampleNeheButton = new JButton(); |
| a62d533 | 677 | sampleNeheButton.setText("NEHE");
|
| a62d533 | 678 | samplePanel.add(sampleNeheButton, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 679 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 680 | } |
| a62d533 | 681 | {
|
| a62d533 | 682 | sampleAsciiButton = new JButton(); |
| a62d533 | 683 | sampleAsciiButton.setText("ASCII");
|
| a62d533 | 684 | samplePanel.add(sampleAsciiButton, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, |
| a62d533 | 685 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 686 | } |
| a62d533 | 687 | } |
| a62d533 | 688 | {
|
| a62d533 | 689 | JPanel renderingPanel = new JPanel(); |
| a62d533 | 690 | leftSidePanel.add(renderingPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, |
| a62d533 | 691 | GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 692 | renderingPanel.setBorder(BorderFactory.createTitledBorder("Rendering"));
|
| a62d533 | 693 | renderingPanel.setLayout(new GridBagLayout()); |
| a62d533 | 694 | {
|
| a62d533 | 695 | JPanel wrapperPanel = new JPanel(); |
| a62d533 | 696 | renderingPanel.add(wrapperPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, |
| a62d533 | 697 | GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 698 | wrapperPanel.setLayout(new BorderLayout()); |
| a62d533 | 699 | wrapperPanel.setBackground(java.awt.Color.white); |
| a62d533 | 700 | {
|
| a62d533 | 701 | gamePanel = new JPanel(); |
| a62d533 | 702 | wrapperPanel.add(gamePanel); |
| a62d533 | 703 | gamePanel.setLayout(new BorderLayout()); |
| a62d533 | 704 | gamePanel.setBackground(java.awt.Color.white); |
| a62d533 | 705 | } |
| a62d533 | 706 | } |
| a62d533 | 707 | {
|
| a62d533 | 708 | glyphCachePanel = new JPanel() {
|
| a62d533 | 709 | private int maxWidth; |
| a62d533 | 710 | |
| a62d533 | 711 | public Dimension getPreferredSize () {
|
| a62d533 | 712 | // Keep glyphCachePanel width from ever going down so the CanvasGameContainer doesn't change sizes and flicker. |
| a62d533 | 713 | Dimension size = super.getPreferredSize(); |
| a62d533 | 714 | maxWidth = Math.max(maxWidth, size.width); |
| a62d533 | 715 | size.width = maxWidth; |
| a62d533 | 716 | return size; |
| a62d533 | 717 | } |
| a62d533 | 718 | }; |
| a62d533 | 719 | glyphCachePanel.setVisible(false); |
| a62d533 | 720 | renderingPanel.add(glyphCachePanel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, |
| a62d533 | 721 | GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 722 | glyphCachePanel.setLayout(new GridBagLayout()); |
| a62d533 | 723 | {
|
| a62d533 | 724 | glyphCachePanel.add(new JLabel("Glyphs:"), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
|
| a62d533 | 725 | GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 726 | } |
| a62d533 | 727 | {
|
| a62d533 | 728 | glyphCachePanel.add(new JLabel("Pages:"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
|
| a62d533 | 729 | GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 730 | } |
| a62d533 | 731 | {
|
| a62d533 | 732 | glyphCachePanel.add(new JLabel("Page width:"), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
|
| a62d533 | 733 | GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 734 | } |
| a62d533 | 735 | {
|
| a62d533 | 736 | glyphCachePanel.add(new JLabel("Page height:"), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
|
| a62d533 | 737 | GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 738 | } |
| a62d533 | 739 | {
|
| a62d533 | 740 | glyphPageWidthCombo = new JComboBox(new DefaultComboBoxModel(new Integer[] {new Integer(32), new Integer(64),
|
| a62d533 | 741 | new Integer(128), new Integer(256), new Integer(512), new Integer(1024), new Integer(2048)})); |
| a62d533 | 742 | glyphCachePanel.add(glyphPageWidthCombo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 743 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 744 | glyphPageWidthCombo.setSelectedIndex(4); |
| a62d533 | 745 | } |
| a62d533 | 746 | {
|
| a62d533 | 747 | glyphPageHeightCombo = new JComboBox(new DefaultComboBoxModel(new Integer[] {new Integer(32), new Integer(64),
|
| a62d533 | 748 | new Integer(128), new Integer(256), new Integer(512), new Integer(1024), new Integer(2048)})); |
| a62d533 | 749 | glyphCachePanel.add(glyphPageHeightCombo, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 750 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 751 | glyphPageHeightCombo.setSelectedIndex(4); |
| a62d533 | 752 | } |
| a62d533 | 753 | {
|
| a62d533 | 754 | resetCacheButton = new JButton("Reset Cache");
|
| a62d533 | 755 | glyphCachePanel.add(resetCacheButton, new GridBagConstraints(0, 6, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 756 | GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 757 | } |
| a62d533 | 758 | {
|
| a62d533 | 759 | glyphPagesTotalLabel = new JLabel("1");
|
| a62d533 | 760 | glyphCachePanel.add(glyphPagesTotalLabel, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 761 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 762 | } |
| a62d533 | 763 | {
|
| a62d533 | 764 | glyphsTotalLabel = new JLabel("0");
|
| a62d533 | 765 | glyphCachePanel.add(glyphsTotalLabel, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 766 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 767 | } |
| a62d533 | 768 | {
|
| a62d533 | 769 | glyphPageComboModel = new DefaultComboBoxModel(); |
| a62d533 | 770 | glyphPageCombo = new JComboBox(); |
| a62d533 | 771 | glyphCachePanel.add(glyphPageCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 772 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 773 | glyphPageCombo.setModel(glyphPageComboModel); |
| a62d533 | 774 | } |
| a62d533 | 775 | {
|
| a62d533 | 776 | glyphCachePanel.add(new JLabel("View:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
|
| a62d533 | 777 | GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 778 | } |
| a62d533 | 779 | } |
| a62d533 | 780 | {
|
| a62d533 | 781 | JPanel radioButtonsPanel = new JPanel(); |
| a62d533 | 782 | renderingPanel.add(radioButtonsPanel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 783 | GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 784 | radioButtonsPanel.setLayout(new GridBagLayout()); |
| a62d533 | 785 | {
|
| a62d533 | 786 | sampleTextRadio = new JRadioButton("Sample text");
|
| a62d533 | 787 | radioButtonsPanel.add(sampleTextRadio, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 788 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 789 | sampleTextRadio.setSelected(true); |
| a62d533 | 790 | } |
| a62d533 | 791 | {
|
| a62d533 | 792 | glyphCacheRadio = new JRadioButton("Glyph cache");
|
| a62d533 | 793 | radioButtonsPanel.add(glyphCacheRadio, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 794 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 795 | } |
| a62d533 | 796 | {
|
| a62d533 | 797 | radioButtonsPanel.add(new JLabel("Background:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
|
| a62d533 | 798 | GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 799 | } |
| a62d533 | 800 | {
|
| a62d533 | 801 | backgroundColorLabel = new JLabel(); |
| a62d533 | 802 | radioButtonsPanel.add(backgroundColorLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 803 | GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 804 | } |
| a62d533 | 805 | ButtonGroup buttonGroup = new ButtonGroup(); |
| a62d533 | 806 | buttonGroup.add(glyphCacheRadio); |
| a62d533 | 807 | buttonGroup.add(sampleTextRadio); |
| a62d533 | 808 | } |
| a62d533 | 809 | } |
| a62d533 | 810 | JPanel rightSidePanel = new JPanel(); |
| a62d533 | 811 | rightSidePanel.setLayout(new GridBagLayout()); |
| a62d533 | 812 | add( |
| a62d533 | 813 | rightSidePanel, |
| a62d533 | 814 | new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), |
| a62d533 | 815 | 0, 0)); |
| a62d533 | 816 | {
|
| a62d533 | 817 | JPanel paddingPanel = new JPanel(); |
| a62d533 | 818 | paddingPanel.setLayout(new GridBagLayout()); |
| a62d533 | 819 | rightSidePanel.add(paddingPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 820 | GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); |
| a62d533 | 821 | paddingPanel.setBorder(BorderFactory.createTitledBorder("Padding"));
|
| a62d533 | 822 | {
|
| a62d533 | 823 | padTopSpinner = new JSpinner(); |
| a62d533 | 824 | paddingPanel.add(padTopSpinner, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 825 | GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 826 | ((JSpinner.DefaultEditor)padTopSpinner.getEditor()).getTextField().setColumns(2); |
| a62d533 | 827 | } |
| a62d533 | 828 | {
|
| a62d533 | 829 | padRightSpinner = new JSpinner(); |
| a62d533 | 830 | paddingPanel.add(padRightSpinner, new GridBagConstraints(2, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 831 | GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0)); |
| a62d533 | 832 | ((JSpinner.DefaultEditor)padRightSpinner.getEditor()).getTextField().setColumns(2); |
| a62d533 | 833 | } |
| a62d533 | 834 | {
|
| a62d533 | 835 | padLeftSpinner = new JSpinner(); |
| a62d533 | 836 | paddingPanel.add(padLeftSpinner, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, |
| a62d533 | 837 | GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0)); |
| a62d533 | 838 | ((JSpinner.DefaultEditor)padLeftSpinner.getEditor()).getTextField().setColumns(2); |
| a62d533 | 839 | } |
| a62d533 | 840 | {
|
| a62d533 | 841 | padBottomSpinner = new JSpinner(); |
| a62d533 | 842 | paddingPanel.add(padBottomSpinner, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 843 | GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 844 | ((JSpinner.DefaultEditor)padBottomSpinner.getEditor()).getTextField().setColumns(2); |
| a62d533 | 845 | } |
| a62d533 | 846 | {
|
| a62d533 | 847 | JPanel advancePanel = new JPanel(); |
| a62d533 | 848 | FlowLayout advancePanelLayout = new FlowLayout(); |
| a62d533 | 849 | advancePanel.setLayout(advancePanelLayout); |
| a62d533 | 850 | paddingPanel.add(advancePanel, new GridBagConstraints(0, 4, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 851 | GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 852 | {
|
| a62d533 | 853 | advancePanel.add(new JLabel("X:"));
|
| a62d533 | 854 | } |
| a62d533 | 855 | {
|
| a62d533 | 856 | padAdvanceXSpinner = new JSpinner(); |
| a62d533 | 857 | advancePanel.add(padAdvanceXSpinner); |
| a62d533 | 858 | ((JSpinner.DefaultEditor)padAdvanceXSpinner.getEditor()).getTextField().setColumns(2); |
| a62d533 | 859 | } |
| a62d533 | 860 | {
|
| a62d533 | 861 | advancePanel.add(new JLabel("Y:"));
|
| a62d533 | 862 | } |
| a62d533 | 863 | {
|
| a62d533 | 864 | padAdvanceYSpinner = new JSpinner(); |
| a62d533 | 865 | advancePanel.add(padAdvanceYSpinner); |
| a62d533 | 866 | ((JSpinner.DefaultEditor)padAdvanceYSpinner.getEditor()).getTextField().setColumns(2); |
| a62d533 | 867 | } |
| a62d533 | 868 | } |
| a62d533 | 869 | } |
| a62d533 | 870 | {
|
| a62d533 | 871 | JPanel effectsPanel = new JPanel(); |
| a62d533 | 872 | effectsPanel.setLayout(new GridBagLayout()); |
| a62d533 | 873 | rightSidePanel.add(effectsPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, |
| a62d533 | 874 | GridBagConstraints.BOTH, new Insets(5, 0, 5, 5), 0, 0)); |
| a62d533 | 875 | effectsPanel.setBorder(BorderFactory.createTitledBorder("Effects"));
|
| a62d533 | 876 | effectsPanel.setMinimumSize(new Dimension(210, 1)); |
| a62d533 | 877 | {
|
| a62d533 | 878 | JScrollPane effectsScroll = new JScrollPane(); |
| a62d533 | 879 | effectsPanel.add(effectsScroll, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, |
| a62d533 | 880 | GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5), 0, 0)); |
| a62d533 | 881 | {
|
| a62d533 | 882 | effectsListModel = new DefaultComboBoxModel(); |
| a62d533 | 883 | effectsList = new JList(); |
| a62d533 | 884 | effectsScroll.setViewportView(effectsList); |
| a62d533 | 885 | effectsList.setModel(effectsListModel); |
| a62d533 | 886 | effectsList.setVisibleRowCount(7); |
| a62d533 | 887 | effectsScroll.setMinimumSize(effectsList.getPreferredScrollableViewportSize()); |
| a62d533 | 888 | } |
| a62d533 | 889 | } |
| a62d533 | 890 | {
|
| a62d533 | 891 | addEffectButton = new JButton("Add");
|
| a62d533 | 892 | effectsPanel.add(addEffectButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, |
| a62d533 | 893 | GridBagConstraints.NONE, new Insets(0, 5, 6, 5), 0, 0)); |
| a62d533 | 894 | addEffectButton.setEnabled(false); |
| a62d533 | 895 | } |
| a62d533 | 896 | {
|
| a62d533 | 897 | appliedEffectsScroll = new JScrollPane(); |
| a62d533 | 898 | effectsPanel.add(appliedEffectsScroll, new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, |
| a62d533 | 899 | GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0)); |
| a62d533 | 900 | appliedEffectsScroll.setBorder(new EmptyBorder(0, 0, 0, 0)); |
| a62d533 | 901 | appliedEffectsScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); |
| a62d533 | 902 | {
|
| a62d533 | 903 | JPanel panel = new JPanel(); |
| a62d533 | 904 | panel.setLayout(new GridBagLayout()); |
| a62d533 | 905 | appliedEffectsScroll.setViewportView(panel); |
| a62d533 | 906 | {
|
| a62d533 | 907 | appliedEffectsPanel = new JPanel(); |
| a62d533 | 908 | appliedEffectsPanel.setLayout(new GridBagLayout()); |
| a62d533 | 909 | panel.add(appliedEffectsPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, |
| a62d533 | 910 | GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 911 | appliedEffectsPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, java.awt.Color.black)); |
| a62d533 | 912 | } |
| a62d533 | 913 | } |
| a62d533 | 914 | } |
| a62d533 | 915 | } |
| a62d533 | 916 | } |
| a62d533 | 917 | |
| a62d533 | 918 | private void initializeMenus () {
|
| a62d533 | 919 | {
|
| a62d533 | 920 | JMenuBar menuBar = new JMenuBar(); |
| a62d533 | 921 | //add(menuBar, BorderLayout.NORTH); |
| a62d533 | 922 | //setJMenuBar(menuBar); |
| a62d533 | 923 | {
|
| a62d533 | 924 | JMenu fileMenu = new JMenu(); |
| a62d533 | 925 | menuBar.add(fileMenu); |
| a62d533 | 926 | fileMenu.setText("File");
|
| a62d533 | 927 | fileMenu.setMnemonic(KeyEvent.VK_F); |
| a62d533 | 928 | {
|
| a62d533 | 929 | openMenuItem = new JMenuItem("Open Hiero settings file...");
|
| a62d533 | 930 | openMenuItem.setMnemonic(KeyEvent.VK_O); |
| a62d533 | 931 | openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
| a62d533 | 932 | fileMenu.add(openMenuItem); |
| a62d533 | 933 | } |
| a62d533 | 934 | {
|
| a62d533 | 935 | saveMenuItem = new JMenuItem("Save Hiero settings file...");
|
| a62d533 | 936 | saveMenuItem.setMnemonic(KeyEvent.VK_S); |
| a62d533 | 937 | saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
| a62d533 | 938 | fileMenu.add(saveMenuItem); |
| a62d533 | 939 | } |
| a62d533 | 940 | fileMenu.addSeparator(); |
| a62d533 | 941 | {
|
| a62d533 | 942 | saveBMFontMenuItem = new JMenuItem("Save BMFont files (text)...");
|
| a62d533 | 943 | saveBMFontMenuItem.setMnemonic(KeyEvent.VK_B); |
| a62d533 | 944 | saveBMFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); |
| a62d533 | 945 | fileMenu.add(saveBMFontMenuItem); |
| a62d533 | 946 | } |
| a62d533 | 947 | fileMenu.addSeparator(); |
| a62d533 | 948 | {
|
| a62d533 | 949 | exitMenuItem = new JMenuItem("Exit");
|
| a62d533 | 950 | exitMenuItem.setMnemonic(KeyEvent.VK_X); |
| a62d533 | 951 | fileMenu.add(exitMenuItem); |
| a62d533 | 952 | } |
| a62d533 | 953 | } |
| a62d533 | 954 | } |
| a62d533 | 955 | } |
| a62d533 | 956 | |
| a62d533 | 957 | static Icon getColorIcon (java.awt.Color color) {
|
| a62d533 | 958 | BufferedImage image = new BufferedImage(32, 16, BufferedImage.TYPE_INT_RGB); |
| a62d533 | 959 | java.awt.Graphics g = image.getGraphics(); |
| a62d533 | 960 | g.setColor(color); |
| a62d533 | 961 | g.fillRect(1, 1, 30, 14); |
| a62d533 | 962 | g.setColor(java.awt.Color.black); |
| a62d533 | 963 | g.drawRect(0, 0, 31, 15); |
| a62d533 | 964 | return new ImageIcon(image); |
| a62d533 | 965 | } |
| a62d533 | 966 | |
| a62d533 | 967 | private class EffectPanel extends JPanel {
|
| a62d533 | 968 | final java.awt.Color selectedColor = new java.awt.Color(0xb1d2e9); |
| a62d533 | 969 | |
| a62d533 | 970 | final ConfigurableEffect effect; |
| a62d533 | 971 | List values; |
| a62d533 | 972 | |
| a62d533 | 973 | JButton deleteButton; |
| a62d533 | 974 | private JPanel valuesPanel; |
| a62d533 | 975 | JLabel nameLabel; |
| a62d533 | 976 | |
| a62d533 | 977 | EffectPanel (final ConfigurableEffect effect) {
|
| a62d533 | 978 | this.effect = effect; |
| a62d533 | 979 | effectPanels.add(this); |
| a62d533 | 980 | effectsList.getListSelectionListeners()[0].valueChanged(null); |
| a62d533 | 981 | |
| a62d533 | 982 | setLayout(new GridBagLayout()); |
| a62d533 | 983 | setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, java.awt.Color.black)); |
| a62d533 | 984 | appliedEffectsPanel.add(this, new GridBagConstraints(0, -1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 985 | GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 986 | {
|
| a62d533 | 987 | JPanel titlePanel = new JPanel(); |
| a62d533 | 988 | titlePanel.setLayout(new LayoutManager() {
|
| a62d533 | 989 | public void removeLayoutComponent (Component comp) {
|
| a62d533 | 990 | } |
| a62d533 | 991 | |
| a62d533 | 992 | public Dimension preferredLayoutSize (Container parent) {
|
| a62d533 | 993 | return null; |
| a62d533 | 994 | } |
| a62d533 | 995 | |
| a62d533 | 996 | public Dimension minimumLayoutSize (Container parent) {
|
| a62d533 | 997 | return null; |
| a62d533 | 998 | } |
| a62d533 | 999 | |
| a62d533 | 1000 | public void layoutContainer (Container parent) {
|
| a62d533 | 1001 | Dimension buttonSize = deleteButton.getPreferredSize(); |
| a62d533 | 1002 | deleteButton.setBounds(getWidth() - buttonSize.width - 5, 0, buttonSize.width, buttonSize.height); |
| a62d533 | 1003 | |
| a62d533 | 1004 | Dimension labelSize = nameLabel.getPreferredSize(); |
| a62d533 | 1005 | nameLabel.setBounds(5, buttonSize.height / 2 - labelSize.height / 2, getWidth() - buttonSize.width - 5 - 5, |
| a62d533 | 1006 | labelSize.height); |
| a62d533 | 1007 | } |
| a62d533 | 1008 | |
| a62d533 | 1009 | public void addLayoutComponent (String name, Component comp) {
|
| a62d533 | 1010 | } |
| a62d533 | 1011 | }); |
| a62d533 | 1012 | {
|
| a62d533 | 1013 | deleteButton = new JButton(); |
| a62d533 | 1014 | titlePanel.add(deleteButton); |
| a62d533 | 1015 | deleteButton.setText("X");
|
| a62d533 | 1016 | deleteButton.setMargin(new Insets(0, 0, 0, 0)); |
| a62d533 | 1017 | Font font = deleteButton.getFont(); |
| a62d533 | 1018 | deleteButton.setFont(new Font(font.getName(), font.getStyle(), font.getSize() - 2)); |
| a62d533 | 1019 | } |
| a62d533 | 1020 | {
|
| a62d533 | 1021 | nameLabel = new JLabel(effect.toString()); |
| a62d533 | 1022 | titlePanel.add(nameLabel); |
| a62d533 | 1023 | Font font = nameLabel.getFont(); |
| a62d533 | 1024 | nameLabel.setFont(new Font(font.getName(), Font.BOLD, font.getSize())); |
| a62d533 | 1025 | } |
| a62d533 | 1026 | titlePanel.setPreferredSize(new Dimension(0, Math.max(nameLabel.getPreferredSize().height, |
| a62d533 | 1027 | deleteButton.getPreferredSize().height))); |
| a62d533 | 1028 | add(titlePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
| a62d533 | 1029 | new Insets(5, 0, 0, 5), 0, 0)); |
| a62d533 | 1030 | titlePanel.setOpaque(false); |
| a62d533 | 1031 | } |
| a62d533 | 1032 | {
|
| a62d533 | 1033 | valuesPanel = new JPanel(); |
| a62d533 | 1034 | valuesPanel.setOpaque(false); |
| a62d533 | 1035 | valuesPanel.setLayout(new GridBagLayout()); |
| a62d533 | 1036 | add(valuesPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 1037 | GridBagConstraints.HORIZONTAL, new Insets(0, 10, 5, 0), 0, 0)); |
| a62d533 | 1038 | } |
| a62d533 | 1039 | |
| a62d533 | 1040 | deleteButton.addActionListener(new ActionListener() {
|
| a62d533 | 1041 | public void actionPerformed (ActionEvent evt) {
|
| a62d533 | 1042 | remove(); |
| a62d533 | 1043 | updateFont(); |
| a62d533 | 1044 | } |
| a62d533 | 1045 | }); |
| a62d533 | 1046 | |
| a62d533 | 1047 | updateValues(); |
| a62d533 | 1048 | updateFont(); |
| a62d533 | 1049 | } |
| a62d533 | 1050 | |
| a62d533 | 1051 | public void remove () {
|
| a62d533 | 1052 | effectPanels.remove(this); |
| a62d533 | 1053 | appliedEffectsPanel.remove(EffectPanel.this); |
| a62d533 | 1054 | validate(); |
| a62d533 | 1055 | effectsList.getListSelectionListeners()[0].valueChanged(null); |
| a62d533 | 1056 | } |
| a62d533 | 1057 | |
| a62d533 | 1058 | public void updateValues () {
|
| a62d533 | 1059 | prefs.put("foreground", EffectUtil.toString(colorEffect.getColor()));
|
| a62d533 | 1060 | valuesPanel.removeAll(); |
| a62d533 | 1061 | values = effect.getValues(); |
| a62d533 | 1062 | for (Iterator iter = values.iterator(); iter.hasNext();) |
| a62d533 | 1063 | addValue((Value)iter.next()); |
| a62d533 | 1064 | } |
| a62d533 | 1065 | |
| a62d533 | 1066 | public void addValue (final Value value) {
|
| a62d533 | 1067 | JLabel valueNameLabel = new JLabel(value.getName() + ":"); |
| a62d533 | 1068 | valuesPanel.add(valueNameLabel, new GridBagConstraints(0, -1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, |
| a62d533 | 1069 | GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0)); |
| a62d533 | 1070 | |
| a62d533 | 1071 | final JLabel valueValueLabel = new JLabel(); |
| a62d533 | 1072 | valuesPanel.add(valueValueLabel, new GridBagConstraints(1, -1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 1073 | GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); |
| a62d533 | 1074 | valueValueLabel.setOpaque(true); |
| a62d533 | 1075 | if (value.getObject() instanceof java.awt.Color) |
| a62d533 | 1076 | valueValueLabel.setIcon(getColorIcon((java.awt.Color)value.getObject())); |
| a62d533 | 1077 | else |
| a62d533 | 1078 | valueValueLabel.setText(value.toString()); |
| a62d533 | 1079 | |
| a62d533 | 1080 | valueValueLabel.addMouseListener(new MouseAdapter() {
|
| a62d533 | 1081 | public void mouseEntered (MouseEvent evt) {
|
| a62d533 | 1082 | valueValueLabel.setBackground(selectedColor); |
| a62d533 | 1083 | } |
| a62d533 | 1084 | |
| a62d533 | 1085 | public void mouseExited (MouseEvent evt) {
|
| a62d533 | 1086 | valueValueLabel.setBackground(null); |
| a62d533 | 1087 | } |
| a62d533 | 1088 | |
| a62d533 | 1089 | public void mouseClicked (MouseEvent evt) {
|
| a62d533 | 1090 | Object oldObject = value.getObject(); |
| a62d533 | 1091 | value.showDialog(); |
| a62d533 | 1092 | if (!value.getObject().equals(oldObject)) {
|
| a62d533 | 1093 | effect.setValues(values); |
| a62d533 | 1094 | updateValues(); |
| a62d533 | 1095 | updateFont(); |
| a62d533 | 1096 | } |
| a62d533 | 1097 | } |
| a62d533 | 1098 | }); |
| a62d533 | 1099 | } |
| a62d533 | 1100 | |
| a62d533 | 1101 | public ConfigurableEffect getEffect () {
|
| a62d533 | 1102 | return effect; |
| a62d533 | 1103 | } |
| a62d533 | 1104 | |
| a62d533 | 1105 | public boolean equals (Object obj) {
|
| a62d533 | 1106 | if (this == obj) return true; |
| a62d533 | 1107 | if (obj == null) return false; |
| a62d533 | 1108 | if (getClass() != obj.getClass()) return false; |
| a62d533 | 1109 | final EffectPanel other = (EffectPanel)obj; |
| a62d533 | 1110 | if (effect == null) {
|
| a62d533 | 1111 | if (other.effect != null) return false; |
| a62d533 | 1112 | } else if (!effect.equals(other.effect)) return false; |
| a62d533 | 1113 | return true; |
| a62d533 | 1114 | } |
| a62d533 | 1115 | } |
| a62d533 | 1116 | |
| a62d533 | 1117 | public static class FontRenderer implements ApplicationListener {
|
| a62d533 | 1118 | private String sampleText; |
| a62d533 | 1119 | |
| a62d533 | 1120 | @Override |
| a62d533 | 1121 | public void create () {
|
| a62d533 | 1122 | glEnable(GL_SCISSOR_TEST); |
| a62d533 | 1123 | |
| a62d533 | 1124 | glEnable(GL_TEXTURE_2D); |
| a62d533 | 1125 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| a62d533 | 1126 | glEnableClientState(GL_VERTEX_ARRAY); |
| a62d533 | 1127 | |
| a62d533 | 1128 | glClearColor(0, 0, 0, 0); |
| a62d533 | 1129 | glClearDepth(1); |
| a62d533 | 1130 | |
| a62d533 | 1131 | glDisable(GL_LIGHTING); |
| a62d533 | 1132 | |
| a62d533 | 1133 | glEnable(GL_BLEND); |
| a62d533 | 1134 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| a62d533 | 1135 | } |
| a62d533 | 1136 | |
| a62d533 | 1137 | @Override |
| a62d533 | 1138 | public void resize (int width, int height) {
|
| a62d533 | 1139 | glViewport(0, 0, width, height); |
| a62d533 | 1140 | glScissor(0, 0, width, height); |
| a62d533 | 1141 | |
| a62d533 | 1142 | glMatrixMode(GL_PROJECTION); |
| a62d533 | 1143 | glLoadIdentity(); |
| a62d533 | 1144 | glOrtho(0, width, height, 0, 1, -1); |
| a62d533 | 1145 | glMatrixMode(GL_MODELVIEW); |
| a62d533 | 1146 | glLoadIdentity(); |
| a62d533 | 1147 | } |
| a62d533 | 1148 | |
| a62d533 | 1149 | @Override |
| a62d533 | 1150 | public void render () {
|
| a62d533 | 1151 | int viewWidth = Gdx.graphics.getWidth(); |
| a62d533 | 1152 | int viewHeight = Gdx.graphics.getHeight(); |
| a62d533 | 1153 | |
| a62d533 | 1154 | if (newUnicodeFont != null) {
|
| a62d533 | 1155 | if (unicodeFont != null) unicodeFont.destroy(); |
| a62d533 | 1156 | unicodeFont = newUnicodeFont; |
| a62d533 | 1157 | newUnicodeFont = null; |
| a62d533 | 1158 | } |
| a62d533 | 1159 | |
| a62d533 | 1160 | if (!unicodeFont.getEffects().isEmpty() && unicodeFont.loadGlyphs(25)) {
|
| a62d533 | 1161 | glyphPageComboModel.removeAllElements(); |
| a62d533 | 1162 | int pageCount = unicodeFont.getGlyphPages().size(); |
| a62d533 | 1163 | int glyphCount = 0; |
| a62d533 | 1164 | for (int i = 0; i < pageCount; i++) {
|
| a62d533 | 1165 | glyphPageComboModel.addElement("Page " + (i + 1));
|
| a62d533 | 1166 | glyphCount += ((GlyphPage)unicodeFont.getGlyphPages().get(i)).getGlyphs().size(); |
| a62d533 | 1167 | } |
| a62d533 | 1168 | glyphPagesTotalLabel.setText(String.valueOf(pageCount)); |
| a62d533 | 1169 | glyphsTotalLabel.setText(String.valueOf(glyphCount)); |
| a62d533 | 1170 | } |
| a62d533 | 1171 | |
| a62d533 | 1172 | if (saveBmFontFile != null) {
|
| a62d533 | 1173 | try {
|
| a62d533 | 1174 | BMFontUtil bmFont = new BMFontUtil(unicodeFont); |
| a62d533 | 1175 | bmFont.save(saveBmFontFile); |
| a62d533 | 1176 | } catch (Throwable ex) {
|
| a62d533 | 1177 | System.out.println("Error saving BMFont files: " + saveBmFontFile.getAbsolutePath());
|
| a62d533 | 1178 | ex.printStackTrace(); |
| a62d533 | 1179 | } finally {
|
| a62d533 | 1180 | saveBmFontFile = null; |
| a62d533 | 1181 | } |
| a62d533 | 1182 | } |
| a62d533 | 1183 | |
| a62d533 | 1184 | if (unicodeFont == null) return; |
| a62d533 | 1185 | |
| a62d533 | 1186 | try {
|
| a62d533 | 1187 | sampleText = sampleTextPane.getText(); |
| a62d533 | 1188 | } catch (Exception ex) {
|
| a62d533 | 1189 | } |
| a62d533 | 1190 | |
| a62d533 | 1191 | if (sampleTextRadio.isSelected()) {
|
| a62d533 | 1192 | GL11.glClearColor(renderingBackgroundColor.r, renderingBackgroundColor.g, renderingBackgroundColor.b, |
| a62d533 | 1193 | renderingBackgroundColor.a); |
| a62d533 | 1194 | GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); |
| a62d533 | 1195 | int offset = unicodeFont.getYOffset(sampleText); |
| a62d533 | 1196 | if (offset > 0) offset = 0; |
| a62d533 | 1197 | unicodeFont.drawString(0, -offset, sampleText, Color.WHITE, 0, sampleText.length()); |
| a62d533 | 1198 | } else {
|
| a62d533 | 1199 | GL11.glClearColor(1, 1, 1, 1); |
| a62d533 | 1200 | GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); |
| a62d533 | 1201 | unicodeFont.addGlyphs(sampleText); |
| a62d533 | 1202 | // GL11.glColor4f(renderingBackgroundColor.r, renderingBackgroundColor.g, renderingBackgroundColor.b, |
| a62d533 | 1203 | // renderingBackgroundColor.a); |
| a62d533 | 1204 | // fillRect(0, 0, unicodeFont.getGlyphPageWidth() + 2, unicodeFont.getGlyphPageHeight() + 2); |
| a62d533 | 1205 | int index = glyphPageCombo.getSelectedIndex(); |
| a62d533 | 1206 | List pages = unicodeFont.getGlyphPages(); |
| a62d533 | 1207 | if (index >= 0 && index < pages.size()) {
|
| a62d533 | 1208 | Texture texture = ((GlyphPage)pages.get(glyphPageCombo.getSelectedIndex())).getTexture(); |
| a62d533 | 1209 | |
| a62d533 | 1210 | glDisable(GL_TEXTURE_2D); |
| a62d533 | 1211 | glColor4f(renderingBackgroundColor.r, renderingBackgroundColor.g, renderingBackgroundColor.b, |
| a62d533 | 1212 | renderingBackgroundColor.a); |
| a62d533 | 1213 | glBegin(GL_QUADS); |
| a62d533 | 1214 | glVertex3f(0, 0, 0); |
| a62d533 | 1215 | glVertex3f(0, texture.getHeight(), 0); |
| a62d533 | 1216 | glVertex3f(texture.getWidth(), texture.getHeight(), 0); |
| a62d533 | 1217 | glVertex3f(texture.getWidth(), 0, 0); |
| a62d533 | 1218 | glEnd(); |
| a62d533 | 1219 | glEnable(GL_TEXTURE_2D); |
| a62d533 | 1220 | |
| a62d533 | 1221 | texture.bind(); |
| a62d533 | 1222 | glColor4f(1, 1, 1, 1); |
| a62d533 | 1223 | glBegin(GL_QUADS); |
| a62d533 | 1224 | glTexCoord2f(0, 0); |
| a62d533 | 1225 | glVertex3f(0, 0, 0); |
| a62d533 | 1226 | |
| a62d533 | 1227 | glTexCoord2f(0, 1); |
| a62d533 | 1228 | glVertex3f(0, texture.getHeight(), 0); |
| a62d533 | 1229 | |
| a62d533 | 1230 | glTexCoord2f(1, 1); |
| a62d533 | 1231 | glVertex3f(texture.getWidth(), texture.getHeight(), 0); |
| a62d533 | 1232 | |
| a62d533 | 1233 | glTexCoord2f(1, 0); |
| a62d533 | 1234 | glVertex3f(texture.getWidth(), 0, 0); |
| a62d533 | 1235 | glEnd(); |
| a62d533 | 1236 | } |
| a62d533 | 1237 | } |
| a62d533 | 1238 | } |
| a62d533 | 1239 | |
| a62d533 | 1240 | @Override |
| a62d533 | 1241 | public void pause () {
|
| a62d533 | 1242 | } |
| a62d533 | 1243 | |
| a62d533 | 1244 | @Override |
| a62d533 | 1245 | public void resume () {
|
| a62d533 | 1246 | } |
| a62d533 | 1247 | |
| a62d533 | 1248 | @Override |
| a62d533 | 1249 | public void dispose () {
|
| a62d533 | 1250 | } |
| a62d533 | 1251 | } |
| a62d533 | 1252 | } |