import javax.swing.JLabel; //导入方法依赖的package包/类
/**
* The basic constructor.
*
* @param freeColClient The {@code FreeColClient} for the game.
*/
public CornerMapControls(final FreeColClient freeColClient) {
super(freeColClient, true);
compassRose = new JLabel(new ImageIcon(ResourceManager.getImage("image.skin.compass")));
compassRose.setFocusable(false);
compassRose.setSize(compassRose.getPreferredSize());
compassRose.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(MouseEvent e) {
Unit unit = getGUI().getActiveUnit();
if (unit == null) return;
int x = e.getX() - compassRose.getWidth()/2;
int y = e.getY() - compassRose.getHeight()/2;
double theta = Math.atan2(y, x) + Math.PI/2 + Math.PI/8;
if (theta < 0) {
theta += 2*Math.PI;
}
igc().moveUnit(unit, Direction.angleToDirection(theta));
}
});
miniMapPanel = new MiniMapPanel();
miniMapPanel.setFocusable(false);
/**
* In order to make the setLocation setup work, we need to set
* the layout to null first, then set the size of the minimap,
* and then its location.
*/
miniMapPanel.setLayout(null);
miniMap.setSize(MAP_WIDTH, MAP_HEIGHT);
// Add buttons:
miniMapPanel.add(miniMapToggleBorders);
miniMapPanel.add(miniMapToggleFogOfWarButton);
miniMapPanel.add(miniMapZoomInButton);
miniMapPanel.add(miniMapZoomOutButton);
miniMapPanel.add(miniMap);
String miniMapSkinKey = "image.skin.MiniMap";
if (ResourceManager.hasImageResource(miniMapSkinKey)) {
miniMapSkin = ResourceManager.getImage(miniMapSkinKey);
miniMapPanel.setBorder(null);
miniMapPanel.setSize(miniMapSkin.getWidth(null),
miniMapSkin.getHeight(null));
miniMapPanel.setOpaque(false);
// FIXME: LATER: The values below should be specified by a
// skin-configuration-file.
miniMap.setLocation(38, 75);
miniMapToggleBorders.setLocation(4,114);
miniMapToggleFogOfWarButton.setLocation(4, 144);
miniMapZoomInButton.setLocation(4, 174);
miniMapZoomOutButton.setLocation(264, 174);
} else {
miniMapSkin = null;
int width = miniMapZoomOutButton.getWidth()
+ miniMapZoomInButton.getWidth() + 4 * GAP;
miniMapPanel.setOpaque(true);
miniMap.setBorder(new BevelBorder(BevelBorder.RAISED));
miniMap.setLocation(width/2, GAP);
miniMapZoomInButton.setLocation(GAP,
MAP_HEIGHT + GAP - miniMapZoomInButton.getHeight());
miniMapZoomOutButton.setLocation(
miniMapZoomInButton.getWidth() + MAP_WIDTH + 3 * GAP,
MAP_HEIGHT + GAP - miniMapZoomOutButton.getHeight());
}
}