001package arcade.gui.frame; 002 003import java.awt.BorderLayout; 004import java.awt.Color; 005import java.awt.Dimension; 006import java.util.HashMap; 007import java.util.Map; 008import javax.swing.BorderFactory; 009import javax.swing.JFrame; 010import javax.swing.JScrollPane; 011import javax.swing.border.Border; 012import arcade.gui.Arcade; 013import arcade.gui.panel.ArcadePanel; 014 015 016/** 017 * The top-level abstract class for frame creators 018 * 019 * @author Michael Deng 020 * 021 */ 022public abstract class AbstractFrameCreator { 023 024 private final String ARCADE_NAME = "Duke CS 308 Arcade"; 025 private final int FRAME_HEIGHT = 700; 026 private final int FRAME_WIDTH = 1130; 027 private final boolean FRAME_RESIZABLE = true; 028 029 private Arcade myArcade; 030 private ArcadePanel myContentPanel; 031 private Map<String, ArcadePanel> myPanels; 032 033 public AbstractFrameCreator (Arcade a) { 034 myArcade = a; 035 myPanels = new HashMap<String, ArcadePanel>(); 036 } 037 038 /** 039 * this method is the main method that will 040 * set up the jframe.. and get it read to add 041 * 042 * @return 043 */ 044 public ArcadeFrame createFrame () { 045 046 // layout the content panel 047 createContentPanel(); 048 049 // create the arcadeframe 050 ArcadeFrame myFrame = new ArcadeFrame(myArcade, ARCADE_NAME, myPanels); 051 052 // set size 053 // myFrame.setSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT)); 054 myFrame.setMinimumSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT)); 055 myFrame.setResizable(FRAME_RESIZABLE); 056 057 // add myContentPanel 058 myFrame.getContentPane().removeAll(); 059 myFrame.getContentPane().setLayout(new BorderLayout()); 060 myFrame.getContentPane().add(myContentPanel, BorderLayout.CENTER); 061 062 // set other things 063 myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 064 myFrame.setLocationRelativeTo(null); 065 066 myFrame.pack(); 067 myFrame.setVisible(true); 068 return myFrame; 069 070 } 071 072 /** 073 * Creates and populates the contentPanel 074 * The contentPanel is fit into the contentPane of the Frame 075 */ 076 protected void createContentPanel () { 077 myContentPanel = new ArcadePanel(myArcade, "contentpanel"); 078 myContentPanel.removeAll(); 079 // myContentPanel.setPreferredSize(new Dimension(FRAME_WIDTH, 080 // FRAME_HEIGHT)); 081 082 myContentPanel.setBackground(Color.BLACK); 083 084 setLayoutManager(); 085 addSubPanels(); 086 087 } 088 089 /** 090 * Must be implemented with assignment of layout manager 091 */ 092 abstract protected void setLayoutManager(); 093 094 /** 095 * Must be implemented with instructions to add each subpanel 096 */ 097 abstract protected void addSubPanels(); 098 099 100 101 102 /** 103 * Call this method on each base panel in the frame 104 * to prepare it for use in the arcade 105 */ 106 protected void setupPanel (String panelType, ArcadePanel panel) { 107 108 // create holder panel 109 ArcadePanel holder = new ArcadePanel(myArcade, panelType + "holder"); 110 holder.setLayout(new BorderLayout()); 111 holder.setBackground(Color.BLACK); 112 113 // add reference to holder panel to map 114 myPanels.put(panelType, holder); 115 116 // add holder panel to scrollpane 117 JScrollPane scrollPane = new JScrollPane(holder); 118 Border border = BorderFactory.createEmptyBorder(0, 0, 0, 0); 119 scrollPane.setBorder(border); 120 121 // holder.setAutoscrolls(true); 122 123 // add scrollpane to sizing panel 124 panel.setLayout(new BorderLayout()); 125 panel.add(scrollPane, BorderLayout.CENTER); 126 127 } 128 129 /** 130 * 131 * @return reference to the content panel 132 */ 133 protected ArcadePanel getContentPanel () { 134 return myContentPanel; 135 } 136 137 /** 138 * 139 * @return reference to the arcade 140 */ 141 protected Arcade getArcade () { 142 return myArcade; 143 } 144 145}