use of java.awt.event.ComponentEvent in project narchy by automenta.
the class AwtGraphicsHandler method init.
@Override
public void init(final SideScrollMinicraft game) {
// canvas = new Canvas();
// create a frame to contain our game
container = new JFrame("Minicraft");
try {
ImageIcon ii = new ImageIcon(new URL("file:sprites/other/mouse.png"));
Image im = ii.getImage();
Toolkit tk = canvas.getToolkit();
myCursor = tk.createCustomCursor(im, new Point(0, 0), "MyCursor");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception e) {
System.out.println("myCursor creation failed " + e);
}
// get hold the content of the frame and set up the resolution of the game
panel = (JPanel) container.getContentPane();
panel.setPreferredSize(new Dimension(screenWidth, screenHeight));
panel.setLayout(null);
panel.setCursor(myCursor);
panel.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
Dimension d = e.getComponent().getSize();
canvas.setBounds(0, 0, d.width, d.height);
screenWidth = d.width;
screenHeight = d.height;
}
});
// setup our canvas size and put it into the content of the frame
canvas.setBounds(0, 0, screenWidth + 10, screenHeight + 10);
panel.add(canvas);
// Tell AWT not to bother repainting our canvas since we're
// going to do that our self in accelerated mode
canvas.setIgnoreRepaint(true);
// finally make the window visible
container.pack();
container.setResizable(true);
container.setVisible(true);
// add a listener to respond to the user closing the window. If they
// do we'd like to exit the game
// TODO: add this back in
container.addWindowListener(new MyWindowAdapter(game));
// request the focus so key events come to us
canvas.requestFocus();
// create the buffering strategy which will allow AWT
// to manage our accelerated graphics
// canvas.createBufferStrategy(2);
// strategy = canvas.getBufferStrategy();
buffer = new BufferedImage(canvas.getWidth(), canvas.getHeight(), BufferedImage.TYPE_INT_RGB);
g = (Graphics2D) buffer.getGraphics();
}
use of java.awt.event.ComponentEvent in project mafscaling by vimsh.
the class ClosedLoop method createAfrDataTable.
private JTable createAfrDataTable(JPanel panel, String tableName, int gridy) {
final JTable afrTable = new JTable() {
private static final long serialVersionUID = 6526901361175099297L;
public boolean isCellEditable(int row, int column) {
return false;
}
};
DefaultTableColumnModel afrModel = new DefaultTableColumnModel();
final TableColumn afrColumn = new TableColumn(0, 250);
afrColumn.setHeaderValue(tableName);
afrModel.addColumn(afrColumn);
JTableHeader lblAfrTableName = afrTable.getTableHeader();
lblAfrTableName.setColumnModel(afrModel);
lblAfrTableName.setReorderingAllowed(false);
DefaultTableCellRenderer headerRenderer = (DefaultTableCellRenderer) lblAfrTableName.getDefaultRenderer();
headerRenderer.setHorizontalAlignment(SwingConstants.LEFT);
GridBagConstraints gbc_lblAfrTableName = new GridBagConstraints();
gbc_lblAfrTableName.insets = new Insets((gridy == 0 ? 0 : 5), 0, 0, 0);
gbc_lblAfrTableName.anchor = GridBagConstraints.PAGE_START;
gbc_lblAfrTableName.fill = GridBagConstraints.HORIZONTAL;
gbc_lblAfrTableName.gridx = 0;
gbc_lblAfrTableName.gridy = gridy;
panel.add(lblAfrTableName, gbc_lblAfrTableName);
afrTable.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
afrColumn.setWidth(afrTable.getWidth());
}
});
afrTable.getTableHeader().setReorderingAllowed(false);
afrTable.setColumnSelectionAllowed(true);
afrTable.setCellSelectionEnabled(true);
afrTable.setBorder(new LineBorder(new Color(0, 0, 0)));
afrTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
afrTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
afrTable.setModel(new DefaultTableModel(AfrTableRowCount, AfrTableColumnCount));
Utils.initializeTable(afrTable, ColumnWidth);
if (tableName.equals(Afr1TableName)) {
Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") } };
NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class);
renderer.setFormats(formatMatrix);
} else if (tableName.equals(Afr2TableName)) {
Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") }, { new DecimalFormat("#"), new DecimalFormat("#") } };
NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class);
renderer.setFormats(formatMatrix);
}
GridBagConstraints gbc_afrTable = new GridBagConstraints();
gbc_afrTable.insets = new Insets(0, 0, 0, 0);
gbc_afrTable.anchor = GridBagConstraints.PAGE_START;
gbc_afrTable.gridx = 0;
gbc_afrTable.gridy = gridy + 1;
panel.add(afrTable, gbc_afrTable);
excelAdapter.addTable(afrTable, true, false);
return afrTable;
}
use of java.awt.event.ComponentEvent in project freeplane by freeplane.
the class AccelerateableAction method setNewAcceleratorOnNextClick.
static void setNewAcceleratorOnNextClick(KeyStroke accelerator) {
if (AccelerateableAction.isNewAcceleratorOnNextClickEnabled()) {
return;
}
acceleratorForNextClickedAction = accelerator;
String title = TextUtils.getText("SetAccelerator.dialogTitle");
String text = TextUtils.getText(SET_ACCELERATOR_ON_NEXT_CLICK_ACTION);
if (accelerator != null)
text = TextUtils.format("SetAccelerator.keystrokeDetected", toString(accelerator)) + "\n" + text;
final Component frame = Controller.getCurrentController().getViewController().getMenuComponent();
setAcceleratorOnNextClickActionDialog = UITools.createCancelDialog(frame, title, text);
getAcceleratorOnNextClickActionDialog().addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(final ComponentEvent e) {
setAcceleratorOnNextClickActionDialog = null;
acceleratorForNextClickedAction = null;
}
});
getAcceleratorOnNextClickActionDialog().setVisible(true);
}
use of java.awt.event.ComponentEvent in project freeplane by freeplane.
the class NodeTooltipManager method showTipWindow.
private void showTipWindow() {
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (insideComponent == null || !insideComponent.isShowing() || focusOwner == null)
return;
tip = insideComponent.createToolTip();
tip.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
final NodeTooltip component = (NodeTooltip) e.getComponent();
component.scrollUp();
component.removeComponentListener(this);
}
});
tip.setTipText(toolTipText);
final JComponent nearComponent = insideComponent;
focusOwnerRef = new WeakReference<Component>(focusOwner);
tipPopup = new JPopupMenu();
tipPopup.setLayout(new GridLayout(1, 1));
tipPopup.add(tip);
mouseInsideTooltipListener = new MouseInsideListener(tipPopup);
tipPopup.show(nearComponent, 0, nearComponent.getHeight());
focusOwner.requestFocusInWindow();
exitTimer.start();
}
use of java.awt.event.ComponentEvent in project freeplane by freeplane.
the class EditStylesAction method init.
private void init() {
this.mainController = Controller.getCurrentController();
if (dialog != null) {
Controller.setCurrentController((Controller) dialog.getRootPane().getClientProperty(Controller.class));
return;
}
dialog = new JDialog(UITools.getCurrentFrame());
final WindowConfigurationStorage windowConfigurationStorage = new WindowConfigurationStorage(getKey() + ".dialog");
windowConfigurationStorage.restoreDialogPositions(dialog);
dialog.setModal(true);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
getModeController().tryToCloseDialog();
}
});
Controller styleDialogController = SModeControllerFactory.getInstance().createController(dialog);
modeController = (SModeController) styleDialogController.getModeController();
final ViewController viewController = styleDialogController.getViewController();
viewController.init(styleDialogController);
dialog.addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(final ComponentEvent e) {
final WindowConfigurationStorage windowConfigurationStorage = new WindowConfigurationStorage(getKey() + ".dialog");
windowConfigurationStorage.storeDialogPositions(dialog);
final IMapViewManager mapViewManager = modeController.getController().getMapViewManager();
final MapModel map = mapViewManager.getModel();
final IUndoHandler undoHandler = (IUndoHandler) map.getExtension(IUndoHandler.class);
modeController.getMapController().closeWithoutSaving(map);
Controller.setCurrentController(mainController);
super.componentHidden(e);
mainController.getMapViewManager().changeToMapView(currentMapView);
currentMapView = null;
switch(modeController.getStatus()) {
case JOptionPane.OK_OPTION:
if (undoHandler.canUndo()) {
commit();
break;
}
// $FALL-THROUGH$
case JOptionPane.CANCEL_OPTION:
rollback();
}
}
});
}
Aggregations