1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Map Mirroring Tool

Discussion in 'Community Dev Corner' started by Aphelion, Nov 25, 2013.

Mods: Downburst, Mazey
  1. Aphelion

    Aphelion Wunderkind Donator
    1. Aphelion's Roleplay

    Messages:
    180
    Map Mirroring Tool
    A simple tool for mirroring King Arthur's Gold maps.

    Requires JAVA.

    [​IMG]

    Download

    Input:
    [​IMG]

    Output (no merge):
    [​IMG]

    Output (with merging):
    [​IMG]

    MapTool.java
    PHP:
    package aphelion3371;

    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.geom.AffineTransform;
    import java.awt.image.AffineTransformOp;
    import java.awt.image.BufferedImage;

    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;

    import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;

    /**
    * A simple tool for mirroring King Arthur's Gold maps.
    *
    * @author Aphelion3371
    */
    public class MapTool {

        public static 
    void main(String args[]) throws Exception {
            
    JFrame.setDefaultLookAndFeelDecorated(true);
            
    JDialog.setDefaultLookAndFeelDecorated(true);
            
    SwingUtilities.invokeAndWait(new Runnable() {
                public 
    void run() {
                    try {
                        
    UIManager.setLookAndFeel(new SubstanceGraphiteLookAndFeel());
                    
                        
    // Create GUI.
                        
    new GUI();
                    } catch(
    Exception e) {
                        
    e.printStackTrace();
                    }
                }
            });
        }

        
    /**
        * Mirrors the image.
        *
        * @param original The image to mirror.
        * @return The mirrored image.
        */
        
    public static BufferedImage mirror(final BufferedImage original) {
            
    AffineTransform tx AffineTransform.getScaleInstance(-11);
            
    tx.translate(-original.getWidth(null), 0);
            
    AffineTransformOp op = new AffineTransformOp(txAffineTransformOp.TYPE_NEAREST_NEIGHBOR);
            return 
    op.filter(originalnull);
        }

        
    /**
        * Merges the original with the mirrored image.
        *
        * @param original The original image.
        * @param mirrored The mirrored image.
        * @return An image combining the original and mirrored.
        */
        
    public static BufferedImage merge(final BufferedImage original, final BufferedImage mirrored) {
            
    BufferedImage full =
                      new 
    BufferedImage(original.getWidth() * 2original.getHeight(),
                                        
    BufferedImage.TYPE_INT_ARGB);
        
            
    Graphics g full.createGraphics();
            
    g.drawImage(original00null);
            
    g.drawImage(mirroredoriginal.getWidth(), 0null);
            return 
    full;
        }

        
    /**
        * Displays a message dialog.
        *
        * @param title The title of the dialog.
        * @param message The message to be contained in the dialog.
        * @param messageCode The message code.
        */
        
    public static void showMessageDialog(final String title, final String message, final int messageCode) {
            
    JFrame frame = new JFrame();
            
    frame.setSize(new Dimension(200150));
            
    frame.setResizable(false);
            
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        
            
    JOptionPane.showMessageDialog(framemessagetitlemessageCode);
        }

    }
    GUI.java
    PHP:
    package aphelion3371;

    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.io.File;

    import javax.imageio.ImageIO;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;

    /**
    * @author Aphelion3371
    */
    @SuppressWarnings("serial")
    public class 
    GUI extends JFrame {

        private 
    JPanel contentPane;
        private 
    JButton selectFileButton;
        private 
    JCheckBox mergeCheckBox;

        public 
    GUI() {
            
    setTitle("MapTool by Aphelion3371");
            
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
            
    Dimension size = new Dimension(27080);
            
    setSize(size);
            
    setPreferredSize(size);
        
            
    setResizable(false);
        
            
    contentPane = new JPanel();
            
    contentPane.setLayout(null);
            
    setContentPane(contentPane);

            final 
    JFileChooser fc = new JFileChooser();
            
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        
            
    selectFileButton = new JButton("Select image");
            
    selectFileButton.setBounds(5510030);
            
    selectFileButton.addActionListener(new ActionListener() {

                @
    Override
                
    public void actionPerformed(ActionEvent arg0) {
                    if(
    fc.showOpenDialog(GUI.this) == JFileChooser.APPROVE_OPTION) {
                        
    File file fc.getSelectedFile();
                        if(
    file.getName().endsWith(".png")) {
                            
    boolean merge mergeCheckBox.isSelected();
                            try {
                                
    BufferedImage in ImageIO.read(file);
                                
    BufferedImage out merge MapTool.merge(inMapTool.mirror(in)) : MapTool.mirror(in);
                            
                                
    fc.setSelectedFile(new File(file.getName().replace(".png""") + "-" + (merge "full" "mirrored") + ".png"));
                                if(
    fc.showSaveDialog(GUI.this) == JFileChooser.APPROVE_OPTION) {
                                    
    File destination fc.getSelectedFile();
                                
                                    
    ImageIO.write(out"png"destination);
                                    
    MapTool.showMessageDialog("Image saved""Image saved to: " destination.getAbsolutePath(), JOptionPane.INFORMATION_MESSAGE);
                                }
                            } catch(
    Exception e) {
                                
    e.printStackTrace();
                            
                                
    MapTool.showMessageDialog("Error processing image"" - failed to process image."JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            
    MapTool.showMessageDialog("Invalid format""Image must be in PNG format."JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            
            });
            
    contentPane.add(selectFileButton);
        
            
    mergeCheckBox = new JCheckBox("Merge images");
            
    mergeCheckBox.setBounds(115510030);
            
    mergeCheckBox.setToolTipText("Select this to have the original and mirrored image merged.");
            
    contentPane.add(mergeCheckBox);
        
            
    setLocationRelativeTo(null);
            
    setVisible(true);
            
    pack();
        }

    }
     
    Last edited: Jul 10, 2014
    BlueLuigi likes this.
  2. Klokinator

    Klokinator Such Beta
    1. Aphelion's Roleplay

    Messages:
    1,443
    Next: Make a full map editor. No but seriously, this is at least somewhat helpful :D
     
  3. Mazey

    Mazey Haxor Global Moderator Forum Moderator Staff Alumni Donator Official Server Admin

    Messages:
    1,914
    This isn't really helpful IMO, you just mirror it with GIMP's built-in tool or just Layer > Flip vertically Horizontally in paint.NET. That'd be faster too.
     
    Last edited: Nov 26, 2013
  4. Aphelion

    Aphelion Wunderkind Donator
    1. Aphelion's Roleplay

    Messages:
    180
    There is of course, the merging functionality.

    However, i do plan to create a full map editor.
     
    Last edited: Nov 27, 2013
  5. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Horizontally* you meant?

    Otherwise, would have been nice if you made vertical mirroring. Also can any mod modify the name to 'Map mirroring tool'? It's confusing
     
  6. Mazey

    Mazey Haxor Global Moderator Forum Moderator Staff Alumni Donator Official Server Admin

    Messages:
    1,914
    Copypaste
     
Mods: Downburst, Mazey