/*     */ package org.ui.editors.map;
/*     */ 
/*     */ import java.awt.*;
/*     */
/*     */
/*     */
/*     */ import java.awt.event.ActionEvent;
/*     */ import java.awt.event.KeyAdapter;
/*     */ import java.awt.event.KeyEvent;
/*     */ import java.awt.event.WindowAdapter;
/*     */ import java.awt.event.WindowEvent;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.util.Formatter;
/*     */ import javax.swing.Box;
/*     */ import javax.swing.JButton;
/*     */ import javax.swing.JFileChooser;
/*     */ import javax.swing.JFrame;
/*     */ import javax.swing.JLabel;
/*     */ import javax.swing.JOptionPane;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JScrollPane;
/*     */ import javax.swing.JTextPane;
/*     */ import org.ui.UICreator;
/*     */ import org.world.World;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class MapEditor
/*     */   extends JFrame
/*     */ {
/*     */   private static final long serialVersionUID = -6076124740248473039L;
/*     */   private volatile boolean closeRequest;
/*     */   private JPanel buttonPane;
/*     */   private JButton updateWorld;
/*     */   private JButton reset;
/*     */   private JButton load;
/*     */   private JButton save;
/*     */   private JButton info;
/*     */   private JLabel infoLabel;
/*     */   private JTextPane preview;
/*     */   private MapTextHighlighter highlighter;
/*     */   
/*     */   public MapEditor(World world) {
                setOpacity(1.0f);
                setBackground(Color.BLACK);

/*  64 */     createUIComponents();
/*     */     
/*  66 */     setupUIComponents(world);
/*     */     
/*  68 */     createListener(world);
/*     */ 
/*     */ 
/*     */     
/*  72 */     this.buttonPane.add(Box.createHorizontalStrut(12));
/*  73 */     this.buttonPane.add(this.updateWorld);
/*  74 */     this.buttonPane.add(this.reset);
/*  75 */     this.buttonPane.add(Box.createHorizontalStrut(6));
/*  76 */     this.buttonPane.add(this.load);
/*  77 */     this.buttonPane.add(this.save);
/*  78 */     this.buttonPane.add(Box.createHorizontalStrut(6));
/*  79 */     this.buttonPane.add(this.infoLabel);
/*  80 */     this.buttonPane.add(this.info);
/*     */ 
/*     */ 
/*     */ 
/*     */     
/*  85 */     Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     
/*  91 */     getContentPane().setLayout(new BorderLayout());
/*  92 */     getContentPane().add(new JScrollPane(this.preview), "Center");
/*  93 */     getContentPane().add(this.buttonPane, "South");
/*     */ 
/*     */     
/*  96 */     setTitle("RTX-GYTEBOT - Map Editor");
/*     */     
/*  98 */     setSize(size.width >> 1, size.height >> 1);
/*     */     
/* 100 */     setLocation(0, size.height >> 1);
/*     */     
/* 102 */     setVisible(true);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void createListener(World world) {
/* 112 */     this.preview.addKeyListener(new KeyAdapter()
/*     */         {
/*     */           public final void keyReleased(KeyEvent event)
/*     */           {
/* 116 */             MapEditor.this.highlighter.highlight();
/*     */           }
/*     */         });
/*     */ 
/*     */     
/* 121 */     this.reset.addActionListener(e -> {
/*     */           this.preview.setText(world.toString());
/*     */ 
/*     */           
/*     */           this.highlighter.highlight();
/*     */         });
/*     */     
/* 128 */     this.updateWorld.addActionListener(e -> world.setDataString(this.preview.getText()));
/*     */ 
/*     */     
/* 131 */     this.load.addActionListener(e -> {
/*     */           JFileChooser chooser = new JFileChooser();
/*     */ 
/*     */           
/*     */           chooser.setDialogType(0);
/*     */ 
/*     */           
/*     */           int value = chooser.showDialog(null, "Choose File");
/*     */           
/*     */           if (value == 0) {
/*     */             world.setWorld(chooser.getSelectedFile().getAbsolutePath());
/*     */           }
/*     */           
/*     */           this.preview.setText(world.toString());
/*     */           
/*     */           this.infoLabel.setText(String.format("Size: %d %d Coins: %d", new Object[] { Integer.valueOf(world.getWidth()), Integer.valueOf(world.getHeight()), Integer.valueOf(world.getCoinCount()) }));
/*     */           
/*     */           this.highlighter.highlight();
/*     */         });
/*     */     
/* 151 */     this.info.addActionListener(e -> {
/*     */         
/*     */         });
/* 154 */     this.save.addActionListener(e -> {
/*     */           JFileChooser chooser = new JFileChooser();
/*     */ 
/*     */           
/*     */           chooser.setDialogType(1);
/*     */ 
/*     */           
/*     */           int value = chooser.showDialog(null, "Choose File to save to");
/*     */ 
/*     */           
/*     */           if (value == 0) {
/*     */             try {
/*     */               Formatter formatter = new Formatter(chooser.getSelectedFile());
/*     */ 
/*     */               
/*     */               formatter.format("%s", new Object[] { world.toString() });
/*     */ 
/*     */               
/*     */               formatter.close();
/* 173 */             } catch (FileNotFoundException e1) {
/*     */               String errorMessage = String.format("Could not save current map to file: %s", new Object[] { chooser.getSelectedFile().toURI() });
/*     */               
/*     */               JOptionPane.showMessageDialog(null, errorMessage, "Error - saving map", 0);
/*     */               
/*     */               e1.printStackTrace();
/*     */             } 
/*     */           }
/*     */         });
/*     */     
/* 183 */     addWindowListener(new WindowAdapter()
/*     */         {
/*     */           public void windowClosing(WindowEvent event)
/*     */           {
/* 187 */             MapEditor.this.closeRequest = true;
/*     */           }
/*     */         });
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setupUIComponents(World world) {
/* 198 */     this.preview.setText(world.toString());
/*     */     
/* 200 */     this.highlighter.highlight();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void createUIComponents() {
/* 207 */     this.preview = new JTextPane();
/* 208 */     this.highlighter = new MapTextHighlighter(this.preview);
/*     */ 
/*     */     
/* 211 */     this.buttonPane = new JPanel(new FlowLayout(0, 4, 2));
/*     */ 
/*     */     
/* 214 */     this.updateWorld = UICreator.createIconifiedButton('g');
/* 215 */     this.reset = UICreator.createIconifiedButton('f');
/* 216 */     this.load = UICreator.createIconifiedButton('a');
/* 217 */     this.save = UICreator.createIconifiedButton('b');
/* 218 */     this.info = UICreator.createIconifiedButton('h');
/*     */     
/* 220 */     this.infoLabel = new JLabel();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public boolean getWindowCloseRequest() {
/* 227 */     return this.closeRequest;
/*     */   }
/*     */ }


/* Location:              /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/editors/map/MapEditor.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */