01ea1759370f — Quintillus 3 years ago
Refactor palette panel creation into its own method and JPanel.
1 files changed, 23 insertions(+), 10 deletions(-)

M src/main/java/jones/andrew/imageviewer/Main.java
M src/main/java/jones/andrew/imageviewer/Main.java +23 -10
@@ 51,6 51,7 @@ import java.awt.event.ActionEvent;
 import static java.awt.event.ActionEvent.SHIFT_MASK;
 import static java.awt.event.KeyEvent.VK_O;
 import static java.awt.event.KeyEvent.VK_Z;
+import javax.swing.JPanel;
 import javax.swing.JTextField;
 import javax.swing.KeyStroke;
 import javax.swing.filechooser.FileFilter;

          
@@ 338,20 339,12 @@ public class Main extends JFrame {
         getContentPane().setLayout(new GridBagLayout());
         getContentPane().add(pcxScroll, g);
         
+        JPanel palettePanel = createPalettePanel();
         
-        // BEGIN PALETTE
-        PalettePanel testPanel = new PalettePanel(Color.WHITE);
-        testPanel.setPreferredSize(new Dimension(32, 32));
-        testPanel.setMinimumSize(new Dimension(32, 32));
-        PalettePanel testPanel2 = new PalettePanel(Color.BLACK);
-        testPanel2.setPreferredSize(new Dimension(32, 32));
-        testPanel2.setMinimumSize(new Dimension(32, 32));
         g.gridy++;
         g.weighty = 0;
         g.fill = GridBagConstraints.NONE;
-        getContentPane().add(testPanel, g);
-        g.gridy++;
-        getContentPane().add(testPanel2, g);
+        getContentPane().add(palettePanel, g);
         // END PALETTE
         
         //pnlPCXViewer.setBackground(Color.WHITE);

          
@@ 380,6 373,26 @@ public class Main extends JFrame {
         setSize(new Dimension(640, 480));
         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }
+
+    private JPanel createPalettePanel() {
+        // BEGIN PALETTE
+        JPanel palettePanel = new JPanel();
+        GridBagConstraints paletteConstraints = new GridBagConstraints();
+        palettePanel.setLayout(new GridBagLayout());
+        paletteConstraints.fill = GridBagConstraints.NONE;
+        paletteConstraints.gridx = paletteConstraints.gridy = 0;
+        paletteConstraints.weightx = paletteConstraints.weighty = 0.1;
+        PalettePanel testPanel = new PalettePanel(Color.WHITE);
+        testPanel.setPreferredSize(new Dimension(32, 32));
+        testPanel.setMinimumSize(new Dimension(32, 32));
+        palettePanel.add(testPanel, paletteConstraints);
+        PalettePanel testPanel2 = new PalettePanel(Color.BLACK);
+        testPanel2.setPreferredSize(new Dimension(32, 32));
+        testPanel2.setMinimumSize(new Dimension(32, 32));
+        paletteConstraints.gridy++;
+        palettePanel.add(testPanel2, paletteConstraints);
+        return palettePanel;
+    }
     /**
      * @param args the command line arguments
      */