public final class OverviewFrame extends JDialog {
private static class CenterRenderer extends JComponent {
//gelöscht
}
private class ItemInfoRenderer extends JComponent {
//gelöscht
}
private static class ItemProductionList extends VisualItemList<NonvisibleObject> {
//gelöscht
}
/**
* Eclipse generated id.
*/
private static final long serialVersionUID = 2997029981752628340L;
// Render components for the screen sections that will be painted by 'hand'
private CenterRenderer centercomponent = null;
private ItemInfoRenderer iteminfocomponent = null;
private ItemProductionList itemproductionlist = null;
private JTable productionlisttable = null;
private ProductionListTableModel pltm = null;
boolean isthreadstop = false;
Thread repaintThread = new Thread() {
@Override
public void run() {
while (!isthreadstop) {
repaintAll();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
};
/**
* Constructor
*
* @param owner
* The owning frame. Until this dialog is closed the owner frame cannot be 'activated'.
*/
public OverviewFrame(JFrame owner) {
super(owner, true);
initGui();
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {
closeFrame();
}
});
repaintThread.start();
}
/**
* Closes the frame
*/
public void closeFrame() {
isthreadstop = true;
// Wait for the thread to stop
try {
Thread.sleep(250);
} catch (final InterruptedException e) {
}
this.dispose();
};
/**
* Inits and shows the gui.
*/
public void initGui() {
this.setSize(EngineConstants.OVERVIEWFRAME_WIDTH, EngineConstants.OVERVIEWFRAME_HEIGHT);
this.setTitle(Messages.getString("OverviewFrame.OVERVIEW")); //$NON-NLS-1$
this.setResizable(false);
// Create the mainpanel with a borderlayout
final JPanel mainPanel = new JPanel();
this.getContentPane().add(mainPanel);
mainPanel.setLayout(new BorderLayout(0, 0));
// Create the eastpanel
final JPanel eastPanel = new JPanel();
eastPanel.setPreferredSize(new Dimension(EngineConstants.OVERVIEWFRAME_EAST_WIDTH,
EngineConstants.OVERVIEWFRAME_HEIGHT));
// eastPanel.setLayout();
mainPanel.add(eastPanel, BorderLayout.EAST);
// Create table/scrollpane for the itemproductionlist
// Init tablemodel for the production table and load the itemproductionlist
pltm = new ProductionListTableModel();
pltm.setList(MainLogic.getInstance().getHumanLogic().getItemConstructionList());
// Create a jtable (for the playerlist)
productionlisttable = new JTable(pltm);
productionlisttable.createDefaultColumnsFromModel();
productionlisttable.setShowGrid(false);
productionlisttable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
productionlisttable.getTableHeader().setReorderingAllowed(false);
// Create a scrollpane and add the table
final JScrollPane productionlisttableScrollPane1 = new JScrollPane();
productionlisttableScrollPane1.setPreferredSize(new Dimension(
EngineConstants.OVERVIEWFRAME_EAST_WIDTH - 10, (EngineConstants.OVERVIEWFRAME_HEIGHT / 2) - 30));
productionlisttableScrollPane1.setViewportView(productionlisttable);
eastPanel.add(productionlisttableScrollPane1);
// Add the southern section of the eastern panel (selection of an item + showing item stats
// + add the item to the constructionlist)
itemproductionlist = new ItemProductionList(MainLogic.getInstance().getHumanLogic()
.getBlueprintlist(), EngineConstants.OVERVIEWFRAME_EAST_WIDTH - 10,
(EngineConstants.OVERVIEWFRAME_HEIGHT / 2) - 50 - EngineConstants.OVERVIEWFRAME_INFOPANEL_HEIGHT,
-1, -1, EngineConstants.IMAGE_WIDTH_SMALL, EngineConstants.IMAGE_HEIGHT_SMALL);
eastPanel.add(itemproductionlist);
// Create the mouseadapter for the itemproductionlist
final MouseAdapter iplma = new MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent e) {
itemproductionlist.onMouseClick(new Point(e.getX(), e.getY()));
}
@Override
public void mousePressed(MouseEvent e) {
showPopup(e);
}
@Override
public void mouseReleased(MouseEvent e) {
showPopup(e);
}
private void showPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
// NOP
}
}
};
itemproductionlist.addMouseListener(iplma);
iteminfocomponent = new ItemInfoRenderer();
eastPanel.add(iteminfocomponent);
// Create the 'add' button for the east panel and add it.
final JButton addButton = new JButton(Messages.getString("ADD")); //$NON-NLS-1$
addButton.setPreferredSize(new Dimension(EngineConstants.OVERVIEWFRAME_EAST_WIDTH - 50, 20));
eastPanel.add(addButton);
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainLogic.getInstance().getHumanLogic().addNVOToBuildList(itemproductionlist.getSelObj());
validate();
repaint();
}
});
// Create the centercomponent and add it.
centercomponent = new CenterRenderer();
mainPanel.add(centercomponent, BorderLayout.CENTER);
// Fenster in die Bildschirmmitte verschieben
final Rectangle screenRect = this.getGraphicsConfiguration().getBounds();
final Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(
this.getGraphicsConfiguration());
// Sicherstellen das Fenstern nicht au�erhalb des bildes ist
final int centerWidth = screenRect.width < this.getSize().width ? screenRect.x : screenRect.x
+ screenRect.width / 2 - this.getSize().width / 2;
int centerHeight = screenRect.height < this.getSize().height ? screenRect.y : screenRect.y
+ screenRect.height / 2 - this.getSize().height / 2;
// Set position
centerHeight = centerHeight < screenInsets.top ? screenInsets.top : centerHeight;
this.setLocation(centerWidth, centerHeight);
this.setVisible(true);
}
/**
* Refreshes and repaints all the data.
*/
private void repaintAll() {
productionlisttable.revalidate();
this.validate();
this.repaint();
};