Search in sources :

Example 46 with ComponentEvent

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();
}
Also used : MalformedURLException(java.net.MalformedURLException) BufferedImage(java.awt.image.BufferedImage) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) BufferedImage(java.awt.image.BufferedImage) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 47 with ComponentEvent

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;
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) LineBorder(javax.swing.border.LineBorder) Color(java.awt.Color) DefaultTableModel(javax.swing.table.DefaultTableModel) DecimalFormat(java.text.DecimalFormat) JTableHeader(javax.swing.table.JTableHeader) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Format(java.text.Format) DecimalFormat(java.text.DecimalFormat) JTable(javax.swing.JTable) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 48 with ComponentEvent

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);
}
Also used : ComponentEvent(java.awt.event.ComponentEvent) Component(java.awt.Component) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 49 with ComponentEvent

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();
}
Also used : GridLayout(java.awt.GridLayout) MouseInsideListener(org.freeplane.core.ui.MouseInsideListener) JComponent(javax.swing.JComponent) ComponentEvent(java.awt.event.ComponentEvent) JComponent(javax.swing.JComponent) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) ComponentAdapter(java.awt.event.ComponentAdapter) JPopupMenu(javax.swing.JPopupMenu)

Example 50 with ComponentEvent

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();
            }
        }
    });
}
Also used : IMapViewManager(org.freeplane.features.ui.IMapViewManager) ViewController(org.freeplane.features.ui.ViewController) WindowEvent(java.awt.event.WindowEvent) WindowConfigurationStorage(org.freeplane.core.resources.WindowConfigurationStorage) WindowAdapter(java.awt.event.WindowAdapter) IUndoHandler(org.freeplane.core.undo.IUndoHandler) ComponentEvent(java.awt.event.ComponentEvent) MapModel(org.freeplane.features.map.MapModel) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ViewController(org.freeplane.features.ui.ViewController) JDialog(javax.swing.JDialog) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

ComponentEvent (java.awt.event.ComponentEvent)120 ComponentAdapter (java.awt.event.ComponentAdapter)97 Dimension (java.awt.Dimension)22 Component (java.awt.Component)18 ActionEvent (java.awt.event.ActionEvent)18 JPanel (javax.swing.JPanel)18 JScrollPane (javax.swing.JScrollPane)16 ComponentListener (java.awt.event.ComponentListener)15 MouseEvent (java.awt.event.MouseEvent)15 JButton (javax.swing.JButton)15 JLabel (javax.swing.JLabel)15 BorderLayout (java.awt.BorderLayout)12 Point (java.awt.Point)12 WindowAdapter (java.awt.event.WindowAdapter)12 WindowEvent (java.awt.event.WindowEvent)12 MouseAdapter (java.awt.event.MouseAdapter)11 ActionListener (java.awt.event.ActionListener)10 JTable (javax.swing.JTable)9 AbstractAction (javax.swing.AbstractAction)8 BoxLayout (javax.swing.BoxLayout)8