use of java.awt.event.WindowAdapter in project lwjgl by LWJGL.
the class DemoBox method initialize.
/**
* @return
*/
public boolean initialize() {
setTitle("LWJGL - Demo Box");
setSize(640, 480);
setLayout(new GridBagLayout());
// Setup selection panel
// =================================
selectionPanel = new Panel();
selectionPanel.setLayout(new BorderLayout());
selectionPanel.add(new Label("Demo", Label.CENTER), BorderLayout.NORTH);
Button fullScreen = new Button("Fullscreen");
fullScreen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
toggleFullscreen();
}
});
selectionPanel.add(fullScreen, BorderLayout.SOUTH);
final List demos = new List();
for (Enumeration e = selectableDemos.keys(); e.hasMoreElements(); ) {
demos.add(e.nextElement().toString());
}
selectionPanel.add(demos, BorderLayout.CENTER);
demos.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent event) {
demoSelected(event.getItemSelectable().getSelectedObjects()[0].toString());
}
});
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.weightx = 0.05;
gbc.weighty = 1.0;
add(selectionPanel, gbc);
// =================================
try {
demoCanvas = new DemoBoxGLCanvas(this);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.weightx = 0.95;
gbc.weighty = 1.0;
add(demoCanvas, gbc);
} catch (LWJGLException le) {
le.printStackTrace();
return false;
}
// ---------------------------------
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
demoCanvas.destroyCanvas();
dispose();
System.exit(0);
}
});
//demoSelected(demos.getSelectedItem());
return true;
}
use of java.awt.event.WindowAdapter in project pcgen by PCGen.
the class CharacterHPDialog method initComponents.
private void initComponents() {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JTable table = new JTable(tableModel) {
@Override
public TableCellEditor getCellEditor(int row, int column) {
if (column == 5) {
//TODO: the max roll should be calculated in a different manner
String hd = levels.getClassTaken(levels.getElementAt(row)).getHD();
int max = NumberUtils.toInt(hd);
return new IntegerEditor(1, max);
} else {
return super.getCellEditor(row, column);
}
}
};
table.setDefaultRenderer(JButton.class, new Renderer());
table.setDefaultEditor(JButton.class, new Editor());
table.setCellSelectionEnabled(false);
table.setRowHeight(new IntegerEditor(1, 10).getPreferredSize().height);
JTableHeader header = table.getTableHeader();
header.setReorderingAllowed(false);
JScrollPane scrollPane = new JScrollPane(table);
pane.add(scrollPane, BorderLayout.CENTER);
Box box = Box.createHorizontalBox();
box.add(new JLabel("Total Hp:"));
box.add(Box.createHorizontalStrut(3));
final ReferenceListener<Integer> hpListener = new ReferenceListener<Integer>() {
@Override
public void referenceChanged(ReferenceEvent<Integer> e) {
totalHp.setText(e.getNewReference().toString());
}
};
ReferenceFacade<Integer> hpRef = character.getTotalHPRef();
totalHp.setText(hpRef.get().toString());
hpRef.addReferenceListener(hpListener);
box.add(totalHp);
box.add(Box.createHorizontalStrut(5));
JButton button = new JButton("Reroll All");
button.setActionCommand("Reroll");
button.addActionListener(this);
box.add(button);
box.add(Box.createHorizontalGlue());
button = new JButton("Close");
button.setActionCommand("Close");
button.addActionListener(this);
box.add(button);
pane.add(box, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
//Make sure to remove the listeners so that the garbage collector can
//dispose of this dialog and prevent a memory leak
levels.removeHitPointListener(tableModel);
character.getTotalHPRef().removeReferenceListener(hpListener);
}
});
Utility.installEscapeCloseOperation(this);
}
use of java.awt.event.WindowAdapter in project pcgen by PCGen.
the class ChooserDialog method initComponents.
private void initComponents() {
setTitle(chooser.getName());
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
//detach listeners from the chooser
treeViewModel.setDelegate(null);
listModel.setListFacade(null);
chooser.getRemainingSelections().removeReferenceListener(ChooserDialog.this);
}
});
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JSplitPane split = new JSplitPane();
JPanel leftPane = new JPanel(new BorderLayout());
if (availTable != null) {
availTable.setAutoCreateRowSorter(true);
availTable.setTreeViewModel(treeViewModel);
availTable.getRowSorter().toggleSortOrder(0);
availTable.addActionListener(this);
leftPane.add(new JScrollPane(availTable), BorderLayout.CENTER);
} else {
availInput.addActionListener(this);
Dimension maxDim = new Dimension(Integer.MAX_VALUE, availInput.getPreferredSize().height);
availInput.setMaximumSize(maxDim);
JPanel availPanel = new JPanel();
availPanel.setLayout(new BoxLayout(availPanel, BoxLayout.PAGE_AXIS));
availPanel.add(Box.createRigidArea(new Dimension(10, 30)));
availPanel.add(Box.createVerticalGlue());
availPanel.add(new JLabel(LanguageBundle.getString("in_uichooser_value")));
availPanel.add(availInput);
availPanel.add(Box.createVerticalGlue());
leftPane.add(availPanel, BorderLayout.WEST);
}
JPanel buttonPane1 = new JPanel(new FlowLayout());
JButton addButton = new JButton(chooser.getAddButtonName());
addButton.setActionCommand("ADD");
addButton.addActionListener(this);
buttonPane1.add(addButton);
buttonPane1.add(new JLabel(Icons.Forward16.getImageIcon()));
leftPane.add(buttonPane1, BorderLayout.SOUTH);
split.setLeftComponent(leftPane);
JPanel rightPane = new JPanel(new BorderLayout());
JPanel labelPane = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
labelPane.add(new JLabel(chooser.getSelectionCountName()), new GridBagConstraints());
remainingLabel.setText(chooser.getRemainingSelections().get().toString());
labelPane.add(remainingLabel, gbc);
labelPane.add(new JLabel(chooser.getSelectedTableTitle()), gbc);
rightPane.add(labelPane, BorderLayout.NORTH);
list.setModel(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addActionListener(this);
rightPane.add(new JScrollPane(list), BorderLayout.CENTER);
JPanel buttonPane2 = new JPanel(new FlowLayout());
buttonPane2.add(new JLabel(Icons.Back16.getImageIcon()));
JButton removeButton = new JButton(chooser.getRemoveButtonName());
removeButton.setActionCommand("REMOVE");
removeButton.addActionListener(this);
buttonPane2.add(removeButton);
rightPane.add(buttonPane2, BorderLayout.SOUTH);
split.setRightComponent(rightPane);
if (chooser.isInfoAvailable()) {
JSplitPane infoSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
infoSplit.setTopComponent(split);
infoSplit.setBottomComponent(infoPane);
infoSplit.setResizeWeight(0.8);
pane.add(infoSplit, BorderLayout.CENTER);
if (availTable != null) {
availTable.getSelectionModel().addListSelectionListener(this);
}
} else {
pane.add(split, BorderLayout.CENTER);
}
JPanel bottomPane = new JPanel(new FlowLayout());
//$NON-NLS-1$
JButton button = new JButton(LanguageBundle.getString("in_ok"));
//$NON-NLS-1$
button.setMnemonic(LanguageBundle.getMnemonic("in_mn_ok"));
button.setActionCommand("OK");
button.addActionListener(this);
bottomPane.add(button);
//$NON-NLS-1$
button = new JButton(LanguageBundle.getString("in_cancel"));
//$NON-NLS-1$
button.setMnemonic(LanguageBundle.getMnemonic("in_mn_cancel"));
button.setActionCommand("CANCEL");
button.addActionListener(this);
bottomPane.add(button);
pane.add(bottomPane, BorderLayout.SOUTH);
}
use of java.awt.event.WindowAdapter in project pcgen by PCGen.
the class DIWarningDialog method initComponents.
/**
* Initialises the user interface.
*/
private void initComponents() {
setLayout(new GridBagLayout());
JLabel introLabel = new JLabel(introText);
GridBagConstraints gbc = new GridBagConstraints();
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10, 10, 5, 10);
add(introLabel, gbc);
JTextArea messageArea = new JTextArea();
messageArea.setName("errorMessageBox");
messageArea.setEditable(false);
messageArea.setTabSize(8);
messageArea.setText(fileText);
JScrollPane messageAreaContainer = new JScrollPane(messageArea);
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 1.0);
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(5, 10, 5, 10);
add(messageAreaContainer, gbc);
JLabel dummy = new JLabel(" ");
Utility.buildRelativeConstraints(gbc, 1, 1, 1.0, 0.0, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
add(dummy, gbc);
JButton yesButton = new JButton(LanguageBundle.getString("in_yes"));
yesButton.setActionCommand(ACTION_YES);
yesButton.addActionListener(this);
Utility.buildRelativeConstraints(gbc, 1, 1, 0.0, 0.0, GridBagConstraints.NONE, GridBagConstraints.EAST);
gbc.insets = new Insets(5, 5, 10, 5);
add(yesButton, gbc);
JButton noButton = new JButton(LanguageBundle.getString("in_no"));
noButton.setActionCommand(ACTION_NO);
noButton.addActionListener(this);
Utility.buildRelativeConstraints(gbc, 1, 1, 0.0, 0.0, GridBagConstraints.NONE, GridBagConstraints.EAST);
add(noButton, gbc);
JButton cancelButton = new JButton(LanguageBundle.getString("in_cancel"));
cancelButton.setActionCommand(ACTION_CANCEL);
cancelButton.addActionListener(this);
getRootPane().setDefaultButton(cancelButton);
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
gbc.insets = new Insets(5, 5, 10, 10);
add(cancelButton, gbc);
pack();
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
result = JOptionPane.CANCEL_OPTION;
setVisible(false);
}
});
}
use of java.awt.event.WindowAdapter in project pcgen by PCGen.
the class LanguageChooserDialog method initComponents.
private void initComponents() {
setTitle(chooser.getName());
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
//detach listeners from the chooser
treeViewModel.setDelegate(null);
listModel.setListFacade(null);
chooser.getRemainingSelections().removeReferenceListener(LanguageChooserDialog.this);
}
});
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JSplitPane split = new JSplitPane();
JPanel leftPane = new JPanel(new BorderLayout());
//leftPane.add(new JLabel("Available Languages"), BorderLayout.NORTH);
availTable.setAutoCreateRowSorter(true);
availTable.setTreeViewModel(treeViewModel);
availTable.getRowSorter().toggleSortOrder(0);
availTable.addActionListener(this);
leftPane.add(new JScrollPane(availTable), BorderLayout.CENTER);
JPanel buttonPane1 = new JPanel(new FlowLayout());
//$NON-NLS-1$
JButton addButton = new JButton(LanguageBundle.getString("in_sumLangAddLanguage"));
addButton.setActionCommand("ADD");
addButton.addActionListener(this);
buttonPane1.add(addButton);
buttonPane1.add(new JLabel(Icons.Forward16.getImageIcon()));
leftPane.add(buttonPane1, BorderLayout.SOUTH);
split.setLeftComponent(leftPane);
JPanel rightPane = new JPanel(new BorderLayout());
JPanel labelPane = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
//$NON-NLS-1$
labelPane.add(//$NON-NLS-1$
new JLabel(LanguageBundle.getString("in_sumLangRemain")), new GridBagConstraints());
remainingLabel.setText(chooser.getRemainingSelections().get().toString());
labelPane.add(remainingLabel, gbc);
//$NON-NLS-1$
labelPane.add(new JLabel(LanguageBundle.getString("in_sumSelectedLang")), gbc);
rightPane.add(labelPane, BorderLayout.NORTH);
list.setModel(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addActionListener(this);
rightPane.add(new JScrollPane(list), BorderLayout.CENTER);
JPanel buttonPane2 = new JPanel(new FlowLayout());
buttonPane2.add(new JLabel(Icons.Back16.getImageIcon()));
//$NON-NLS-1$
JButton removeButton = new JButton(LanguageBundle.getString("in_sumLangRemoveLanguage"));
removeButton.setActionCommand("REMOVE");
removeButton.addActionListener(this);
buttonPane2.add(removeButton);
rightPane.add(buttonPane2, BorderLayout.SOUTH);
split.setRightComponent(rightPane);
pane.add(split, BorderLayout.CENTER);
JPanel bottomPane = new JPanel(new FlowLayout());
//$NON-NLS-1$
JButton button = new JButton(LanguageBundle.getString("in_ok"));
//$NON-NLS-1$
button.setMnemonic(LanguageBundle.getMnemonic("in_mn_ok"));
button.setActionCommand("OK");
button.addActionListener(this);
bottomPane.add(button);
//$NON-NLS-1$
button = new JButton(LanguageBundle.getString("in_cancel"));
//$NON-NLS-1$
button.setMnemonic(LanguageBundle.getMnemonic("in_mn_cancel"));
button.setActionCommand("CANCEL");
button.addActionListener(this);
bottomPane.add(button);
pane.add(bottomPane, BorderLayout.SOUTH);
}
Aggregations