Home | History | Annotate | Download | only in flame
      1 package com.badlogic.gdx.tools.flame;
      2 
      3 import java.awt.GridBagConstraints;
      4 import java.awt.Insets;
      5 import java.awt.event.ActionEvent;
      6 import java.awt.event.ActionListener;
      7 import java.io.File;
      8 
      9 import javax.swing.DefaultComboBoxModel;
     10 import javax.swing.JButton;
     11 import javax.swing.JCheckBox;
     12 import javax.swing.JComboBox;
     13 import javax.swing.JLabel;
     14 
     15 import com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter;
     16 import com.badlogic.gdx.graphics.Texture;
     17 import com.badlogic.gdx.graphics.Texture.TextureFilter;
     18 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
     19 
     20 /** @author Inferno */
     21 public class TextureLoaderPanel extends EditorPanel {
     22 	public TextureLoaderPanel (FlameMain editor, String name, String description) {
     23 		super(editor, name, description);
     24 		setValue(null);
     25 	}
     26 
     27 	@Override
     28 	protected void initializeComponents () {
     29 		super.initializeComponents();
     30 		JButton atlasButton = new JButton("Open Atlas");
     31 		JButton textureButton = new JButton("Open Texture");
     32 		JButton defaultTextureButton = new JButton("Default Texture");
     33 		final JCheckBox genMipMaps = new JCheckBox("Generate MipMaps");
     34 		final JComboBox minFilterBox = new JComboBox(new DefaultComboBoxModel(TextureFilter.values()));
     35 		final JComboBox magFilterBox = new JComboBox(new DefaultComboBoxModel(TextureFilter.values()));
     36 
     37 		minFilterBox.setSelectedItem(editor.getTexture().getMinFilter());
     38 		magFilterBox.setSelectedItem(editor.getTexture().getMagFilter());
     39 
     40 		ActionListener filterListener = new ActionListener() {
     41 			public void actionPerformed (ActionEvent event) {
     42 				editor.getTexture().setFilter((TextureFilter)minFilterBox.getSelectedItem(), (TextureFilter)magFilterBox.getSelectedItem());
     43 			}
     44 		};
     45 
     46 		minFilterBox.addActionListener(filterListener);
     47 		magFilterBox.addActionListener(filterListener);
     48 
     49 		atlasButton.addActionListener(new ActionListener() {
     50 			@Override
     51 			public void actionPerformed (ActionEvent e) {
     52 				File file = editor.showFileLoadDialog();
     53 				if(file != null){
     54 					TextureAtlas atlas = editor.load(file.getAbsolutePath(), TextureAtlas.class, null,  null);
     55 					if(atlas != null){
     56 						editor.setAtlas(atlas);
     57 					}
     58 				}
     59 			}
     60 		});
     61 
     62 		textureButton.addActionListener(new ActionListener() {
     63 			@Override
     64 			public void actionPerformed (ActionEvent e) {
     65 				File file = editor.showFileLoadDialog();
     66 				if(file != null){
     67 					TextureParameter params = new TextureParameter();
     68 					params.genMipMaps = genMipMaps.isSelected();
     69 					params.minFilter = (TextureFilter)minFilterBox.getSelectedItem();
     70 					params.magFilter = (TextureFilter)magFilterBox.getSelectedItem();
     71 					Texture texture = editor.load(file.getAbsolutePath(), Texture.class, null, params);
     72 					if(texture != null){
     73 						editor.setTexture(texture);
     74 					}
     75 				}
     76 			}
     77 		});
     78 
     79 		defaultTextureButton.addActionListener(new ActionListener() {
     80 			@Override
     81 			public void actionPerformed (ActionEvent e) {
     82 				editor.setTexture(editor.assetManager.get(FlameMain.DEFAULT_BILLBOARD_PARTICLE, Texture.class));
     83 			}
     84 		});
     85 
     86 		contentPanel.add(new JLabel("Min. Filter"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
     87 			new Insets(6, 0, 0, 0), 0, 0));
     88 		contentPanel.add(minFilterBox, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
     89 			new Insets(6, 0, 0, 0), 0, 0));
     90 		contentPanel.add(new JLabel("Mag. Filter"), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
     91 			new Insets(6, 0, 0, 0), 0, 0));
     92 		contentPanel.add(magFilterBox, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
     93 			new Insets(6, 0, 0, 0), 0, 0));
     94 		contentPanel.add(genMipMaps, new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
     95 			new Insets(6, 0, 0, 0), 0, 0));
     96 		contentPanel.add(atlasButton, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
     97 			new Insets(6, 0, 0, 0), 0, 0));
     98 		contentPanel.add(textureButton, new GridBagConstraints(1, 3, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
     99 			new Insets(6, 0, 0, 0), 0, 0));
    100 		contentPanel.add(defaultTextureButton, new GridBagConstraints(2, 3, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    101 			new Insets(6, 0, 0, 0), 0, 0));
    102 
    103 	}
    104 }
    105