1 package com.badlogic.gdx.tools.flame; 2 3 import java.awt.GridBagConstraints; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.ActionListener; 6 7 import javax.swing.JButton; 8 import javax.swing.JDialog; 9 import javax.swing.JOptionPane; 10 import javax.swing.JScrollPane; 11 12 import com.badlogic.gdx.graphics.g2d.TextureAtlas; 13 import com.badlogic.gdx.graphics.g2d.TextureRegion; 14 import com.badlogic.gdx.graphics.g3d.particles.influencers.RegionInfluencer; 15 import com.badlogic.gdx.utils.Array; 16 17 /** @author Inferno */ 18 public class RegionInfluencerPanel extends InfluencerPanel<RegionInfluencer> implements RegionPickerPanel.Listener { 19 JDialog regionSelectDialog; 20 RegionPickerPanel regionPickerPanel; 21 22 public RegionInfluencerPanel (FlameMain editor, String name, String desc, RegionInfluencer influencer) { 23 super(editor, influencer, name, desc); 24 setValue(influencer); 25 } 26 27 @Override 28 protected void initializeComponents () { 29 super.initializeComponents(); 30 31 JButton pickButton; 32 regionSelectDialog = new JDialog(editor, "Pick regions", true); 33 regionPickerPanel = new RegionPickerPanel(this); 34 JScrollPane scrollPane = new JScrollPane(); 35 scrollPane.setViewportView(regionPickerPanel); 36 regionSelectDialog.setContentPane(scrollPane); 37 regionSelectDialog.setDefaultCloseOperation( JDialog.HIDE_ON_CLOSE); 38 39 addContent(0, 0, pickButton = new JButton("Pick Regions"), false, GridBagConstraints.WEST, GridBagConstraints.NONE); 40 41 pickButton.addActionListener(new ActionListener() { 42 @Override 43 public void actionPerformed (ActionEvent arg0) { 44 if(editor.isUsingDefaultTexture()) { 45 JOptionPane.showMessageDialog(editor, "Load a Texture or an Atlas first."); 46 return; 47 } 48 49 TextureAtlas atlas = editor.getAtlas(); 50 if(atlas != null) 51 regionPickerPanel.setAtlas(atlas); 52 else 53 regionPickerPanel.setTexture(editor.getTexture()); 54 55 regionPickerPanel.revalidate(); 56 regionPickerPanel.repaint(); 57 regionSelectDialog.validate(); 58 regionSelectDialog.repaint(); 59 regionSelectDialog.pack(); 60 regionSelectDialog.setVisible(true); 61 } 62 }); 63 } 64 65 @Override 66 public void onRegionsSelected (Array<TextureRegion> regions) { 67 regionSelectDialog.setVisible(false); 68 if(regions.size == 0) return; 69 value.clear(); 70 value.add((TextureRegion[])regions.toArray(TextureRegion.class)); 71 editor.setTexture(regions.get(0).getTexture()); 72 editor.restart(); 73 } 74 75 } 76