Search in sources :

Example 41 with WindowAdapter

use of java.awt.event.WindowAdapter in project adempiere by adempiere.

the class VOnlyCurrentDays method jbInit.

/**
	 * 	Static Initializer
	 * 	@throws Exception
	 */
private void jbInit() throws Exception {
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    bShowAll.setText(Msg.getMsg(Env.getCtx(), "All"));
    bShowAll.addActionListener(this);
    bShowAll.setMargin(s_margin);
    bShowYear.setText(Msg.getMsg(Env.getCtx(), "Year"));
    bShowYear.addActionListener(this);
    bShowYear.setMargin(s_margin);
    bShowMonth.setText(Msg.getMsg(Env.getCtx(), "Month"));
    bShowMonth.addActionListener(this);
    bShowMonth.setMargin(s_margin);
    bShowWeek.setText(Msg.getMsg(Env.getCtx(), "Week"));
    bShowWeek.addActionListener(this);
    bShowWeek.setMargin(s_margin);
    bShowDay.setText(Msg.getMsg(Env.getCtx(), "Day"));
    bShowDay.addActionListener(this);
    bShowDay.setMargin(s_margin);
    bShowDay.setDefaultCapable(true);
    //
    mainPanel.add(bShowDay, null);
    mainPanel.add(bShowWeek, null);
    mainPanel.add(bShowMonth, null);
    mainPanel.add(bShowYear, null);
    mainPanel.add(bShowAll, null);
    //
    mainPanel.setToolTipText(Msg.getMsg(Env.getCtx(), "VOnlyCurrentDays", false));
    this.getContentPane().add(mainPanel, BorderLayout.CENTER);
    this.getRootPane().setDefaultButton(bShowDay);
    // 
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            m_isCancel = true;
        }
    });
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 42 with WindowAdapter

use of java.awt.event.WindowAdapter in project adempiere by adempiere.

the class Find method jbInit.

/**
	 *	Static Init.
	 *  <pre>
	 *  tabbedPane
	 *      simplePanel
	 *          scontentPanel
	 *          confirmPanelS
	 *      advancedPanel
	 *          toolBar
	 *          GC
	 *          confirmPanelA
	 *  southPanel
	 *      statusBar
	 *  </pre>
	 *  @throws Exception
	 */
private void jbInit() throws Exception {
    spaceE = Box.createHorizontalStrut(8);
    spaceN = Box.createVerticalStrut(8);
    spaceW = Box.createHorizontalStrut(8);
    spaceS = Box.createVerticalStrut(8);
    bIgnore.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/Ignore24.gif")));
    bIgnore.setMargin(new Insets(2, 2, 2, 2));
    bIgnore.setToolTipText(Msg.getMsg(Env.getCtx(), "Ignore"));
    bIgnore.addActionListener(this);
    fQueryName.setToolTipText(m_sToolTipText);
    fQueryName.setEditable(true);
    fQueryName.addActionListener(this);
    fQueryName.getEditor().getEditorComponent().addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent arg0) {
            // fQueryName received the focus - delete the tip text so the user can type without 
            // having to delete the tip.
            int index = fQueryName.getSelectedIndex();
            if (index < 0) {
                if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
                    fQueryName.setSelectedIndex(-1);
                    fQueryName.setSelectedItem("");
                }
            }
        }

        public void focusLost(FocusEvent arg0) {
            // fQueryName lost the focus. If the field is blank, replace the tip text.
            if (fQueryName.getSelectedItem() != null && fQueryName.getSelectedItem().equals("")) {
                fQueryName.setSelectedItem(m_sTipText);
            }
        }
    });
    bSave.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/Save24.gif")));
    bSave.setMargin(new Insets(2, 2, 2, 2));
    bSave.setToolTipText(Msg.getMsg(Env.getCtx(), "Save"));
    bSave.addActionListener(this);
    bNew.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/New24.gif")));
    bNew.setMargin(new Insets(2, 2, 2, 2));
    bNew.setToolTipText(Msg.getMsg(Env.getCtx(), "New"));
    bNew.addActionListener(this);
    bDelete.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/Delete24.gif")));
    bDelete.setMargin(new Insets(2, 2, 2, 2));
    bDelete.setToolTipText(Msg.getMsg(Env.getCtx(), "Delete"));
    bDelete.addActionListener(this);
    //
    southPanel.setLayout(southLayout);
    valueLabel.setLabelFor(valueField);
    valueLabel.setText(Msg.translate(Env.getCtx(), "Value"));
    nameLabel.setLabelFor(nameField);
    nameLabel.setText(Msg.translate(Env.getCtx(), "Name"));
    descriptionLabel.setLabelFor(descriptionField);
    descriptionLabel.setText(Msg.translate(Env.getCtx(), "Description"));
    valueField.setText("%");
    valueField.setColumns(FIELDLENGTH);
    nameField.setText("%");
    nameField.setColumns(FIELDLENGTH);
    descriptionField.setText("%");
    descriptionField.setColumns(FIELDLENGTH);
    scontentPanel.setToolTipText(Msg.getMsg(Env.getCtx(), "FindTip"));
    docNoLabel.setLabelFor(docNoField);
    docNoLabel.setText(Msg.translate(Env.getCtx(), "DocumentNo"));
    docNoField.setText("%");
    docNoField.setColumns(FIELDLENGTH);
    advancedScrollPane.setPreferredSize(new Dimension(540, 410));
    southPanel.add(statusBar, BorderLayout.SOUTH);
    this.getContentPane().add(southPanel, BorderLayout.SOUTH);
    //
    scontentPanel.setLayout(scontentLayout);
    simplePanel.setLayout(simpleLayout);
    simplePanel.add(confirmPanelS, BorderLayout.SOUTH);
    simplePanel.add(scontentPanel, BorderLayout.CENTER);
    scontentPanel.add(valueLabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 0, 5), 0, 0));
    scontentPanel.add(nameLabel, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 0, 5), 0, 0));
    scontentPanel.add(descriptionLabel, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 5, 5), 0, 0));
    scontentPanel.add(valueField, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0));
    scontentPanel.add(descriptionField, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
    scontentPanel.add(docNoLabel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 0, 5), 0, 0));
    scontentPanel.add(nameField, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0));
    scontentPanel.add(docNoField, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0));
    //
    scontentPanel.add(spaceE, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
    scontentPanel.add(spaceN, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
    scontentPanel.add(spaceW, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
    scontentPanel.add(spaceS, new GridBagConstraints(2, 15, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
    //
    //	tabbedPane.add(simplePanel, Msg.getMsg(Env.getCtx(),"Find"));
    tabbedPane.add(simplePanel, Msg.getMsg(Env.getCtx(), "Find"));
    //
    toolBar.add(bIgnore, null);
    toolBar.addSeparator();
    toolBar.add(bNew, null);
    toolBar.add(bDelete, null);
    toolBar.add(fQueryName, null);
    toolBar.add(bSave, null);
    advancedPanel.setLayout(advancedLayout);
    advancedPanel.add(toolBar, BorderLayout.NORTH);
    advancedPanel.add(confirmPanelA, BorderLayout.SOUTH);
    advancedPanel.add(advancedScrollPane, BorderLayout.CENTER);
    advancedScrollPane.getViewport().add(advancedTable, null);
    //	tabbedPane.add(advancedPanel, Msg.getMsg(Env.getCtx(),"Advanced"));
    tabbedPane.add(advancedPanel, Msg.getMsg(Env.getCtx(), "Advanced"));
    //
    this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
    //
    confirmPanelA.addActionListener(this);
    confirmPanelS.addActionListener(this);
    //
    JButton b = ConfirmPanel.createNewButton(true);
    confirmPanelS.addComponent(b);
    b.addActionListener(this);
    // teo_sarca, [ 1670847 ] Find dialog: closing and canceling need same functionality
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            cmd_cancel();
        }
    });
}
Also used : ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) WindowEvent(java.awt.event.WindowEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 43 with WindowAdapter

use of java.awt.event.WindowAdapter in project poi by apache.

the class POIBrowser method run.

protected void run(String[] args) {
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    /* Create the tree model with a root node. The latter is
         * invisible but it must be present because a tree model
         * always needs a root. */
    rootNode = new DefaultMutableTreeNode("POI Filesystems");
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    /* Create the tree UI element. */
    final JTree treeUI = new JTree(treeModel);
    getContentPane().add(new JScrollPane(treeUI));
    /* Add the POI filesystems to the tree. */
    int displayedFiles = 0;
    for (int i = 0; i < args.length; i++) {
        final String filename = args[i];
        try {
            FileInputStream fis = new FileInputStream(filename);
            POIFSReader r = new POIFSReader();
            r.registerListener(new TreeReaderListener(filename, rootNode));
            r.read(fis);
            fis.close();
            displayedFiles++;
        } catch (IOException ex) {
            System.err.println(filename + ": " + ex);
        } catch (Exception t) {
            System.err.println("Unexpected exception while reading \"" + filename + "\":");
            t.printStackTrace(System.err);
        }
    }
    /* Exit if there is no file to display (none specified or only
         * files with problems). */
    if (displayedFiles == 0) {
        System.out.println("No POI filesystem(s) to display.");
        System.exit(0);
    }
    /* Make the tree UI element visible. */
    treeUI.setRootVisible(true);
    treeUI.setShowsRootHandles(true);
    ExtendableTreeCellRenderer etcr = new ExtendableTreeCellRenderer();
    etcr.register(DocumentDescriptor.class, new DocumentDescriptorRenderer());
    etcr.register(PropertySetDescriptor.class, new PropertySetDescriptorRenderer());
    treeUI.setCellRenderer(etcr);
    setSize(600, 450);
    setTitle("POI Browser 0.09");
    setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) WindowAdapter(java.awt.event.WindowAdapter) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) JTree(javax.swing.JTree) WindowEvent(java.awt.event.WindowEvent) POIFSReader(org.apache.poi.poifs.eventfilesystem.POIFSReader)

Example 44 with WindowAdapter

use of java.awt.event.WindowAdapter in project joda-time by JodaOrg.

the class DateTimeBrowser method go.

// usage
/*
     * go This method reads the file, creates the table to display,
     * the window to display it in, and displays the window.
     * @param fileName the name of the file to read.
     * @param tryLines An estimate of the number of lines in
     * the file.
     */
private void go(String[] args) {
    mainArgs = args;
    // let user override if needed
    setDefaultTimeZone();
    // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    //
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    addMenus(menuBar);
    /*
         * Add a fast close listener
         */
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
            System.exit(0);
        }
    });
    //
    // Load current file, prime tables and JFrame.
    //
    currFile = new LoadedFile(mainArgs[0]);
    TableView tView = getDefaultTableView();
    resetDefaults(tView);
    //
    // Set max size at start, and display the window.
    //
    Dimension screenMax = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(screenMax);
    setVisible(true);
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) JMenuBar(javax.swing.JMenuBar)

Example 45 with WindowAdapter

use of java.awt.event.WindowAdapter in project jgnash by ccavanaugh.

the class DialogUtils method addBoundsListener.

/**
     * Listens to a JDialog to save and restore windows bounds automatically.
     * <p>
     * {@code setVisible(false)} and {@code dispose()} must not be used
     * to close the window.  Instead, dispatch a window closing event.
     * <PRE>
     * dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
     * </PRE>
     * and the dialog must be set to dispose on close
     * <PRE>
     * setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
     * </PRE>
     *
     * @param w        {@code Window} to listen to
     * @param prefNode String identifier to preference node to save and restore from
     * @param key      the key to save and restore from
     */
private static void addBoundsListener(final Window w, final String prefNode, final String key) {
    String bounds = Preferences.userRoot().node(prefNode).get(key, null);
    if (bounds != null) {
        if (w instanceof JDialog) {
            if (((JDialog) w).isResizable()) {
                w.setBounds(decodeRectangle(bounds));
            } else {
                w.setLocation(decodeRectangle(bounds).getLocation());
            }
        } else {
            w.setBounds(decodeRectangle(bounds));
        }
        Window owner = w.getOwner();
        if (owner != null) {
            w.setLocationRelativeTo(owner);
        }
    }
    /* listen for a window closing event and deal with it */
    w.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            // save position and size
            Preferences p = Preferences.userRoot().node(prefNode);
            p.put(key, encodeRectangle(w.getBounds()));
            // make GC easy
            w.removeWindowListener(this);
        }
    });
    if (w instanceof JDialog) {
        addEscapeListener((JDialog) w);
    }
}
Also used : Window(java.awt.Window) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Preferences(java.util.prefs.Preferences) JDialog(javax.swing.JDialog)

Aggregations

WindowAdapter (java.awt.event.WindowAdapter)143 WindowEvent (java.awt.event.WindowEvent)140 JPanel (javax.swing.JPanel)40 JButton (javax.swing.JButton)36 JFrame (javax.swing.JFrame)34 BorderLayout (java.awt.BorderLayout)32 Dimension (java.awt.Dimension)30 JLabel (javax.swing.JLabel)26 JScrollPane (javax.swing.JScrollPane)25 ActionEvent (java.awt.event.ActionEvent)22 ActionListener (java.awt.event.ActionListener)20 FlowLayout (java.awt.FlowLayout)18 GridBagConstraints (java.awt.GridBagConstraints)18 GridBagLayout (java.awt.GridBagLayout)18 Insets (java.awt.Insets)14 Frame (java.awt.Frame)13 Container (java.awt.Container)12 JTextArea (javax.swing.JTextArea)12 JDialog (javax.swing.JDialog)11 IOException (java.io.IOException)9