Example #1
0
  /**
   * Builds a blank display. Eventually I'll have to add loading from a map, though right now it
   * builds the map itself. I should separate that out.
   */
  public JComponent buildDisplay() {
    JPanel holder = new JPanel(new GridBagLayout());
    map = holder;

    // holder.setLayout(new GridLayout(mapHeight,mapWidth));
    // holder.setPreferredSize(new Dimension(mapWidth * TILE_SIZE * DISPLAY_SCALE,
    // 									mapHeight * TILE_SIZE * DISPLAY_SCALE));
    // holder.setMaximumSize(new Dimension(mapWidth * TILE_SIZE * DISPLAY_SCALE,
    //  									mapHeight * TILE_SIZE * DISPLAY_SCALE));
    // backEnd = emptyMap(mapWidth, mapHeight);

    GridBagConstraints gbc = new GridBagConstraints();

    // for(int i = 0; i < mapHeight; i++){
    // 	List<Tile> tList = new ArrayList<Tile>();
    // 	gbc.gridy = i;
    // 	for(int j = 0; j < mapWidth; j++){
    // 		gbc.gridx = j;
    // 		Tile t = new Tile(currTileImg, "Test", 0, 0, mov,"none",true, "0_0");
    // 		tList.add(t);
    // 		//t.setMargin(new Insets(0,0,0,0));
    // 		t.setMaximumSize(new Dimension(TILE_SIZE*DISPLAY_SCALE,TILE_SIZE*DISPLAY_SCALE));
    // 		t.setPreferredSize(new Dimension(TILE_SIZE*DISPLAY_SCALE, TILE_SIZE*DISPLAY_SCALE));
    // 		//tile.setPreferredSize(new Dimension(TILE_SIZE*DISPLAY_SCALE, TILE_SIZE*DISPLAY_SCALE));
    // 		t.addMouseListener(new MapButtonListener());
    // 		holder.add(t,gbc);

    // 	}
    // 	backEnd.addRow(tList);
    // }

    for (int i = 0; i < mapHeight; i++) {
      gbc.gridy = i;
      for (int j = 0; j < mapWidth; j++) {
        gbc.gridx = j;
        holder.add(backEnd.getTile(j, i), gbc);
      }
    }
    // gbc.gridy = 0;
    // gbc.gridx = mapWidth;
    // gbc.gridheight = GridBagConstraints.REMAINDER;
    // gbc.weightx = 1;
    // gbc.weighty = 1;
    // gbc.fill = GridBagConstraints.BOTH;
    // holder.add(new JPanel(), gbc);
    // gbc.gridx = 0;
    // gbc.gridy = mapHeight;
    // gbc.gridheight = 1;
    // gbc.gridwidth = GridBagConstraints.REMAINDER;
    // holder.add(new JPanel(), gbc);
    // System.out.println(backEnd);

    // Container panel to prevent stretching
    JPanel outer = new JPanel();
    outer.add(holder);

    // BoxLayout ensures that maxSize is honored
    // JPanel displaySizeRegulator = new JPanel();
    // displaySizeRegulator.setLayout(new BoxLayout(displaySizeRegulator, BoxLayout.X_AXIS));

    JScrollPane displayScroll =
        new JScrollPane(
            outer,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    mapScroll = displayScroll;

    // displaySizeRegulator.add(displayScroll);
    // displayRefresher = displaySizeRegulator;
    return displayScroll;
  }