Example usage for java.awt.event WindowAdapter WindowAdapter

List of usage examples for java.awt.event WindowAdapter WindowAdapter

Introduction

In this page you can find the example usage for java.awt.event WindowAdapter WindowAdapter.

Prototype

WindowAdapter

Source Link

Usage

From source file:EditorPaneExample20.java

public EditorPaneExample20() {
    super("JEditorPane Example 20");

    pane = new JEditorPane();
    pane.setEditable(true); // Editable
    getContentPane().add(new JScrollPane(pane), "Center");

    // Add a menu bar
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);// ww w  . jav a2s .  c  o  m

    // Populate it
    createMenuBar();

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);
    c.gridy = 3;
    panel.add(new JLabel(LOAD_TIME), c);

    c.gridy = 4;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    onlineLoad = new JCheckBox("Online Load");
    panel.add(onlineLoad, c);
    onlineLoad.setSelected(true);
    onlineLoad.setForeground(typeLabel.getForeground());

    c.gridy = 5;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    editableBox = new JCheckBox("Editable JEditorPane");
    panel.add(editableBox, c);
    editableBox.setSelected(true);
    editableBox.setForeground(typeLabel.getForeground());

    c.gridy = 6;
    c.weightx = 0.0;
    JButton saveButton = new JButton("Save");
    panel.add(saveButton, c);
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            EditorKit kit = pane.getEditorKit();
            try {
                if (kit instanceof RTFEditorKit) {
                    kit.write(System.out, pane.getDocument(), 0, pane.getDocument().getLength());
                    System.out.flush();
                } else {
                    if (writer == null) {
                        writer = new OutputStreamWriter(System.out);
                        pane.write(writer);
                        writer.flush();
                    }
                    kit.write(writer, pane.getDocument(), 0, pane.getDocument().getLength());
                    writer.flush();
                }
            } catch (Exception e) {
                System.out.println("Write failed");
            }
        }
    });

    c.gridx = 1;
    insertButton = new JButton("Insert HTML");
    panel.add(insertButton, c);
    insertButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (insertFrame == null) {
                insertFrame = new HTMLInsertFrame("HTML Insertion", pane);
                Point pt = EditorPaneExample20.this.getLocationOnScreen();
                Dimension d = EditorPaneExample20.this.getSize();
                insertFrame.setLocation(pt.x + d.width, pt.y);
                insertFrame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent evt) {
                        insertFrame.dispose();
                        insertFrame = null;
                        setInsertButtonState();
                    }
                });
                insertButton.setEnabled(false);
                insertFrame.setVisible(true);
            }
        }
    });
    insertButton.setEnabled(false);

    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;

    urlCombo = new JComboBox();
    panel.add(urlCombo, c);
    urlCombo.setEditable(true);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);
    timeLabel = new JLabel("");
    c.gridy = 3;
    panel.add(timeLabel, c);

    getContentPane().add(panel, "South");

    // Register a custom EditorKit for HTML
    ClassLoader loader = getClass().getClassLoader();
    if (loader != null) {
        // Java 2
        JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit",
                loader);
    } else {
        // JDK 1.1
        JEditorPane.registerEditorKitForContentType("text/html",
                "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit");
    }

    // Allocate the empty tree model
    DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty");
    emptyModel = new DefaultTreeModel(emptyRootNode);

    // Create and place the heading tree
    tree = new JTree(emptyModel);
    tree.setPreferredSize(new Dimension(200, 200));
    getContentPane().add(new JScrollPane(tree), "East");

    // Change page based on combo selection
    urlCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (populatingCombo == true) {
                return;
            }
            Object selection = urlCombo.getSelectedItem();
            loadNewPage(selection);
        }
    });

    // Change editability based on the checkbox
    editableBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pane.setEditable(editableBox.isSelected());
            pane.revalidate();
            pane.repaint();
        }
    });

    // Listen for page load to complete
    pane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("page")) {
                loadComplete();
                displayLoadTime();
                populateCombo(findLinks(pane.getDocument(), null));
                TreeNode node = buildHeadingTree(pane.getDocument());
                tree.setModel(new DefaultTreeModel(node));

                createMenuBar();
                enableMenuBar(true);
                getRootPane().revalidate();

                enableInput();
                loadingPage = false;
            }
        }
    });

    // Listener for tree selection
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getNewLeadSelectionPath();
            if (path != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object userObject = node.getUserObject();
                if (userObject instanceof Heading) {
                    Heading heading = (Heading) userObject;
                    try {
                        Rectangle textRect = pane.modelToView(heading.getOffset());
                        textRect.y += 3 * textRect.height;
                        pane.scrollRectToVisible(textRect);
                    } catch (BadLocationException e) {
                    }
                }
            }
        }
    });

    // Listener for hypertext events
    pane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            // Ignore hyperlink events if the frame is busy
            if (loadingPage == true) {
                return;
            }
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                JEditorPane sp = (JEditorPane) evt.getSource();
                if (evt instanceof HTMLFrameHyperlinkEvent) {
                    HTMLDocument doc = (HTMLDocument) sp.getDocument();
                    doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt);
                } else {
                    loadNewPage(evt.getURL());
                }
            } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                pane.setCursor(handCursor);
            } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
                pane.setCursor(defaultCursor);
            }
        }
    });
}

From source file:com.wet.wired.jsr.player.JPlayer.java

public void showWindow() {

    setTitle("TestingOwl Player");
    setIconImage(owl.getWelcomeIcon().getImage());
    getContentPane().removeAll();/*w w  w.j av  a 2s.c o m*/

    JPanel panel = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    panel.setLayout(gbl);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            closePlayer();
            System.exit(0);
        }
    });

    open = new JButton("Open Recording");
    open.setActionCommand("open");
    open.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(open, gbc);

    reset = new JButton("Reset");
    reset.setActionCommand("reset");
    reset.setEnabled(false);
    reset.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(reset, gbc);

    play = new JButton("Play");
    play.setActionCommand("play");
    play.setEnabled(false);
    play.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(play, gbc);

    fastForward = new JButton("Fast Forward");
    fastForward.setActionCommand("fastForward");
    fastForward.setEnabled(false);
    fastForward.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 3;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(fastForward, gbc);

    pause = new JButton("Pause");
    pause.setActionCommand("pause");
    pause.setEnabled(false);
    pause.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 4;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(pause, gbc);

    close = new JButton("Close File");
    close.setActionCommand("close");
    close.setEnabled(false);
    close.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 5;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(close, gbc);

    // slider
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 6;
    gbc.gridy = 0;
    gbc.weightx = 1;
    gbc.weighty = 1;
    panel.add(createSliderLayout(), gbc);

    soundLevel.setSize(30, (int) close.getSize().getHeight());
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 7;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(soundLevel, gbc);

    recorder = new JButton("to Recorder");
    recorder.setActionCommand("recorder");
    recorder.setEnabled(true);
    recorder.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 8;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(recorder, gbc);

    panel.doLayout();

    this.getContentPane().add(panel, BorderLayout.NORTH);

    panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));

    frameLabel = new JLabel("Frame: 0 Time: 0");
    frameLabel.setForeground(Color.black);
    text = new JLabel("No recording selected");
    text.setForeground(Color.black);

    panel.add(text);
    panel.add(frameLabel);

    this.getContentPane().add(panel, BorderLayout.SOUTH);

    this.setSize(700, this.getHeight());
    this.pack();
    this.setVisible(true);
}

From source file:ar.edu.uns.cs.vyglab.arq.rockar.gui.JFrameControlPanel.java

private void initGUI() {
    try {//from ww  w.j  a  va 2 s.c om
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setIconImage(new ImageIcon(getClass().getClassLoader()
                .getResource("ar/edu/uns/cs/vyglab/arq/rockar/resources/images/splash/purple-monkey32.png"))
                        .getImage());
        this.setTitle("Rock.AR v2.0");
        this.addComponentListener(new ComponentAdapter() {
            public void componentResized(ComponentEvent evt) {
                thisComponentResized(evt);
            }
        });
        this.addWindowListener(new WindowAdapter() {
            public void windowClosed(WindowEvent evt) {
                thisWindowClosed(evt);
            }
        });
        {
            jPanelSouth = new JPanel();
            BorderLayout jPanelSouthLayout = new BorderLayout();
            getContentPane().add(jPanelSouth, BorderLayout.SOUTH);
            jPanelSouth.setLayout(jPanelSouthLayout);
            {
                jLabelInformation = new JLabel();
                jPanelSouth.add(jLabelInformation, BorderLayout.CENTER);
                jLabelInformation.setText(DataCenter.langResource.getString("control_information_label"));
                jLabelInformation.setOpaque(true);
                jLabelInformation.setBackground(new java.awt.Color(241, 191, 101));
            }
        }
        {
            jPanelCenter = new JPanel();
            GridLayout jPanelCenterLayout = new GridLayout(1, 1);
            jPanelCenterLayout.setHgap(5);
            jPanelCenterLayout.setVgap(5);
            jPanelCenterLayout.setColumns(1);
            getContentPane().add(jPanelCenter, BorderLayout.CENTER);
            jPanelCenter.setLayout(jPanelCenterLayout);
            {
                jPanelWest = new JPanel();
                BorderLayout jPanelWestLayout = new BorderLayout();
                jPanelCenter.add(jPanelWest);
                jPanelWest.setLayout(jPanelWestLayout);
                jPanelWest.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));
                {
                    jToolBarMineralTable = new JToolBar();
                    jToolBarMineralTable.setLayout(new FlowLayout(FlowLayout.LEFT));
                    jPanelWest.add(jToolBarMineralTable, BorderLayout.NORTH);
                    jToolBarMineralTable.setFloatable(false);
                    jToolBarMineralTable.setFocusable(false);
                    {
                        jButtonNew = new JButton();
                        jToolBarMineralTable.add(jButtonNew);
                        jButtonNew.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
                                "ar/edu/uns/cs/vyglab/arq/rockar/resources/images/Actions-tab-new-icon.png")));
                        jButtonNew.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jButtonNewActionPerformed(evt);
                            }
                        });
                    }
                    {
                        jButtonOpen = new JButton();
                        jToolBarMineralTable.add(jButtonOpen);
                        jButtonOpen.setIcon(new ImageIcon(getClass().getClassLoader()
                                .getResource("ar/edu/uns/cs/vyglab/arq/rockar/resources/images/open.png")));
                        jButtonOpen.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jButtonOpenActionPerformed(evt);
                            }
                        });
                    }
                    {
                        jButtonSave = new JButton();
                        jToolBarMineralTable.add(jButtonSave);
                        jButtonSave.setIcon(new ImageIcon(getClass().getClassLoader()
                                .getResource("ar/edu/uns/cs/vyglab/arq/rockar/resources/images/save.png")));
                        jButtonSave.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jButtonSaveActionPerformed(evt);
                            }
                        });
                    }
                    {
                        jSeparator1 = new JSeparator();
                        jToolBarMineralTable.add(jSeparator1);
                        jSeparator1.setOrientation(SwingConstants.VERTICAL);
                        jSeparator1.setSize(5, 44);
                        jSeparator1.setPreferredSize(new java.awt.Dimension(5, 44));
                    }
                    {
                        jButtonAdd = new JButton();
                        jToolBarMineralTable.add(jButtonAdd);
                        jButtonAdd.setIcon(new ImageIcon(getClass().getClassLoader()
                                .getResource("ar/edu/uns/cs/vyglab/arq/rockar/resources/images/add.png")));
                        jButtonAdd.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jButtonAddActionPerformed(evt);
                            }
                        });
                    }
                    {
                        jButtonEdit = new JButton();
                        jToolBarMineralTable.add(jButtonEdit);
                        jButtonEdit.setIcon(new ImageIcon(getClass().getClassLoader()
                                .getResource("ar/edu/uns/cs/vyglab/arq/rockar/resources/images/modify.png")));
                        jButtonEdit.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jButtonEditActionPerformed(evt);
                            }
                        });
                    }
                    {
                        jButtonRemove = new JButton();
                        jToolBarMineralTable.add(jButtonRemove);
                        jButtonRemove.setIcon(new ImageIcon(getClass().getClassLoader()
                                .getResource("ar/edu/uns/cs/vyglab/arq/rockar/resources/images/remove.png")));
                        jButtonRemove.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jButtonRemoveActionPerformed(evt);
                            }
                        });
                    }
                }
                {
                    jLabelMineralTableInformation = new JLabel();
                    jPanelWest.add(jLabelMineralTableInformation, BorderLayout.SOUTH);
                    jLabelMineralTableInformation
                            .setText(DataCenter.langResource.getString("total_counted_table"));
                    jLabelMineralTableInformation.setHorizontalAlignment(SwingConstants.LEFT);
                    jLabelMineralTableInformation.setBackground(new java.awt.Color(255, 212, 133));
                    jLabelMineralTableInformation.setOpaque(true);
                }
                {
                    jScrollPaneMineralTable = new JScrollPane();
                    jPanelWest.add(jScrollPaneMineralTable, BorderLayout.CENTER);
                    {
                        jTableMineralsModel = new RockTableModel(
                                new String[] { DataCenter.langResource.getString("keyvalue_table"),
                                        DataCenter.langResource.getString("name_table"),
                                        DataCenter.langResource.getString("color_table"),
                                        DataCenter.langResource.getString("counted_table"),
                                        DataCenter.langResource.getString("area_table") },
                                0);
                        //                     jTableMineralsModel.addRow(new Object[] {
                        //                           0, "x?", Color.gray, 0,
                        //                           "0.00" });
                        jTableMinerals = new JReadOnlyTable();
                        jScrollPaneMineralTable.setViewportView(jTableMinerals);
                        jTableMinerals.setModel(jTableMineralsModel);
                        jTableMinerals.setDefaultRenderer(Color.class, new ColorRenderer(true));
                        TableCellRenderer centerRenderer = new CenterRenderer();
                        TableColumn column = jTableMinerals.getColumnModel().getColumn(0);
                        column.setCellRenderer(centerRenderer);
                        column = jTableMinerals.getColumnModel().getColumn(1);
                        column.setCellRenderer(centerRenderer);
                        column = jTableMinerals.getColumnModel().getColumn(3);
                        column.setCellRenderer(centerRenderer);
                        column = jTableMinerals.getColumnModel().getColumn(4);
                        column.setCellRenderer(centerRenderer);

                    }
                }
            }
            {
                jPanelEast = new JPanel();
                jPanelCenter.add(jPanelEast);
                GridLayout jPanelEastLayout = new GridLayout(2, 1);
                jPanelEastLayout.setHgap(5);
                jPanelEastLayout.setVgap(5);
                jPanelEastLayout.setColumns(1);
                jPanelEast.setLayout(jPanelEastLayout);
                {
                    jPanelTop = new JPanel();
                    BorderLayout jPanelTopLayout = new BorderLayout();
                    jPanelEast.add(jPanelTop);
                    jPanelTop.setLayout(jPanelTopLayout);
                    jPanelTop.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));
                    {
                        jToolBarStats = new JToolBar();
                        jPanelTop.add(jToolBarStats, BorderLayout.NORTH);
                        jToolBarStats.setFloatable(false);
                        jToolBarStats.setFocusable(false);
                        {
                            jButtonExportStats = new JButton();
                            jButtonExportStats.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent arg0) {
                                    saveChartAsImage();
                                }
                            });
                            //jToolBarStats.add(jButtonExportStats);
                            jButtonExportStats.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
                                    "ar/edu/uns/cs/vyglab/arq/rockar/resources/images/export-graph.png")));
                        }
                        {
                            jButtonExportExcel = new JButton();
                            //jToolBarStats.add(jButtonExportExcel);
                            //jToolBarMineralTable.add(jButtonExportExcel);
                            jButtonExportExcel.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
                                    "ar/edu/uns/cs/vyglab/arq/rockar/resources/images/excel-icon.png")));
                            jButtonExportExcel.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent arg0) {
                                    exportToExcel();
                                }
                            });
                        }
                        {
                            jButtonExportAll = new JButton();
                            //jToolBarStats.add(jButtonExportAll);
                            jButtonExportAll.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
                                    "ar/edu/uns/cs/vyglab/arq/rockar/resources/images/Mimetypes-application-vnd-ms-excel-icon.png")));
                        }
                    }
                    {

                    }
                }
                {
                    jPanelBottom = new JPanel();
                    BorderLayout jPanelBottomLayout = new BorderLayout();
                    jPanelEast.add(jPanelBottom);
                    jPanelBottom.setLayout(jPanelBottomLayout);
                    jPanelBottom.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));
                    {
                        jToolBarOverview = new JToolBar();
                        jPanelBottom.add(jToolBarOverview, BorderLayout.NORTH);
                        jToolBarOverview.setFloatable(false);
                        jToolBarOverview.setFocusable(false);
                        {
                            jButtonExportOverview = new JButton();
                            jToolBarOverview.add(jButtonExportOverview);
                            jButtonExportOverview.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
                                    "ar/edu/uns/cs/vyglab/arq/rockar/resources/images/export-graph.png")));
                            jButtonExportOverview.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent arg0) {
                                    exportOverview();
                                }
                            });
                        }
                    }
                    {
                        jPanelOverviewContent = new JPanel();
                        jPanelBottom.add(jPanelOverviewContent, BorderLayout.CENTER);
                        jPanelOverviewContent.setLayout(new GridBagLayout());
                        this.jLabelOverview = new JLabel();
                        jPanelOverviewContent.add(this.jLabelOverview);
                    }
                }
            }
        }
        pack();
        this.setSize(800, 600);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:com.itemanalysis.jmetrik.gui.Jmetrik.java

public Jmetrik() {
    super("jMetrik");
    setPreferredSize(new Dimension(1024, 650));
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    //properly close database if user closes window
    this.addWindowListener(new WindowAdapter() {
        @Override// w  w  w.j  a  va2 s  .  c o  m
        public void windowClosing(WindowEvent we) {
            if (workspace != null) {
                workspace.closeDatabase();
            }
            System.exit(0);
        }
    });

    //add statusbar
    statusBar = new StatusBar(1024, 30);
    statusBar.setBorder(new EmptyBorder(2, 2, 2, 2));
    getContentPane().add(statusBar, BorderLayout.SOUTH);

    //start logging
    startLog();

    //left-right splitpane
    JSplitPane splitPane1 = new JSplitPane();
    splitPane1.setDividerLocation(200);

    //setup workspace list
    workspaceList = new JList();
    workspaceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    workspaceList.setModel(new SortedListModel<DataTableName>());
    workspaceList.addKeyListener(new DeleteKeyListener());
    //        workspaceList.getInsets().set(5, 5, 5, 5);

    //add icon to list cell renderer
    String urlString = "/images/spreadsheet.png";
    URL url = this.getClass().getResource(urlString);
    final ImageIcon tableIcon = new ImageIcon(url, "Table");
    workspaceList.setCellRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected,
                    cellHasFocus);
            label.setIcon(tableIcon);
            return label;
        }
    });

    JScrollPane scrollPane1 = new JScrollPane(workspaceList);
    scrollPane1.setPreferredSize(new Dimension(200, 698));

    splitPane1.setLeftComponent(scrollPane1);

    //tabbed pane for top pane
    tabbedPane = new JTabbedPane();
    tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);

    //setup data table
    dataTable = new DataTable();
    dataTable.setRowHeight(18);

    //change size of table header and center text
    JTableHeader header = dataTable.getTableHeader();
    header.setDefaultRenderer(new TableHeaderCellRenderer());

    JScrollPane dataScrollPane = new JScrollPane(dataTable);
    tabbedPane.addTab("Data", dataScrollPane);

    //setup variable table
    variableTable = new DataTable();
    variableTable.setRowHeight(18);
    variableTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            if (e.getClickCount() == 2) {
                JTable target = (JTable) e.getSource();
                int row = target.getSelectedRow();
                int col = target.getSelectedColumn();
                if (col == 0) {
                    if (target.getModel() instanceof VariableModel) {
                        VariableModel vModel = (VariableModel) target.getModel();
                        String s = (String) vModel.getValueAt(row, col);

                        DatabaseName db = workspace.getDatabaseName();
                        DataTableName table = workspace.getCurrentDataTable();

                        RenameVariableDialog renameVariableDialog = new RenameVariableDialog(Jmetrik.this, db,
                                table, s);
                        renameVariableDialog.setVisible(true);

                        if (renameVariableDialog.canRun()) {
                            RenameVariableCommand command = renameVariableDialog.getCommand();
                            workspace.runProcess(command);
                        }

                    } //end instanceof

                } //end if col==0

            } //end if click count==2
        }//end mouse clicked
    });

    //change size of table header and center text
    JTableHeader variableHeader = variableTable.getTableHeader();
    variableHeader.setDefaultRenderer(new TableHeaderCellRenderer());
    variableHeader.setPreferredSize(new Dimension(30, 21));

    JScrollPane variableScrollPane = new JScrollPane(variableTable);
    tabbedPane.addTab("Variables", variableScrollPane);

    splitPane1.setRightComponent(tabbedPane);
    getContentPane().add(splitPane1, BorderLayout.CENTER);

    //add status bar listener - needed to display status message that are generated within this class
    this.addPropertyChangeListener(statusBar.getStatusListener());

    //add listener for displaying error messages - needed to display errors and exceptions
    this.addPropertyChangeListener(new ErrorOccurredPropertyChangeListener());

    //instantiate file utilities
    fileUtils = new JmetrikFileUtils();
    fileUtils.addPropertyChangeListener(statusBar.getStatusListener());

    //set import and export path to user's documents folder
    JFileChooser chooser = new JFileChooser();
    FileSystemView fw = chooser.getFileSystemView();
    importExportPath = fw.getDefaultDirectory().toString().replaceAll("\\\\", "/");

    //create and start a workspace
    startWorkspace();

    //create menu bar and tool bar
    this.setJMenuBar(createMenuBar());

    JToolBar toolBar = createToolBar();
    toolBar.setFloatable(false);
    toolBar.setRollover(true);
    getContentPane().add(toolBar, BorderLayout.PAGE_START);

    pack();

}

From source file:net.brtly.monkeyboard.gui.MasterControlPanel.java

private void initWindowListener(final JFrame frame) {
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {

        }//from   w ww  .java  2  s .  com

        public void windowClosing(WindowEvent e) {
            frame.dispose();
        }

        public void windowClosed(WindowEvent e) {
            for (Runnable onClose : _runOnClose) {
                onClose.run();
            }
        }
    });
}

From source file:de.codesourcery.eve.skills.ui.Main.java

public void startUp() throws Exception {
    this.configProvider.addChangeListener(this);

    frame = new MainFrame();

    frame.addWindowListener(new WindowAdapter() {
        @Override//  www. j a v  a 2s .  c o m
        public void windowClosing(WindowEvent e) {
            log.info("windowClosing(): Main frame closed.");
            frame.dispose();
            shutdown();
        }
    });

    frame.setVisible(true);

    calendarReminder.startWatchdogThread();
}

From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java

private void initGUI() {
    try {/*from  www .j a  va 2s.  c  o m*/
        BorderLayout thisLayout = new BorderLayout();
        this.getContentPane().setLayout(thisLayout);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("Track Profiler " + TrackProfilerAppContext.PROGRAM_VERSION); //$NON-NLS-1$//$NON-NLS-2$
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                rootWindowClosing(evt);
            }
        });
        this.getContentPane().add(getJPanel1(), BorderLayout.CENTER);
        this.getContentPane().add(getTopToolBar(), BorderLayout.NORTH);
        this.getContentPane().add(getJPanel2(), BorderLayout.EAST);
        this.setLocation(new java.awt.Point(100, 100));
        pack();
        this.setSize(794, 537);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.juwimm.cms.http.AuthenticationStreamSupportingHttpInvokerRequestExecutor.java

@Override
protected void executePostMethod(HttpInvokerClientConfiguration config, HttpClient httpClient,
        PostMethod postMethod) throws IOException {
    HttpClientWrapper.getInstance().setHostConfiguration(super.getHttpClient(),
            new URL(config.getServiceUrl()));
    try {/*from   www  .j ava  2 s.c  o m*/
        super.executePostMethod(config, httpClient, postMethod);
        //if call succeeds 
        isErrorMessageShown = false;
    } catch (IOException e) {
        if ((e instanceof SocketException && e.getMessage().equals("Connection reset"))
                || (e instanceof ConnectException && e.getMessage().equals("Connection refused"))) {
            if (!isErrorMessageShown) {
                isErrorMessageShown = true;
                JOptionPane errorOptionPane = new JOptionPane(
                        Constants.rb.getString("exception.connectionToServerLost"),
                        JOptionPane.INFORMATION_MESSAGE);
                JDialog errorDialogPane = errorOptionPane.createDialog(UIConstants.getMainFrame(),
                        rb.getString("dialog.title"));
                errorDialogPane.setModalityType(ModalityType.MODELESS);
                errorDialogPane.setVisible(true);
                errorDialogPane.setEnabled(true);
                errorDialogPane.addWindowListener(new WindowAdapter() {
                    public void windowDeactivated(WindowEvent e) {
                        if (((JDialog) e.getSource()).isVisible() == false) {
                            isErrorMessageShown = false;
                        }
                    }
                });

            }
            log.error("server is not reachable");
        } else {
            e.printStackTrace();
        }
    }
    System.out.println(postMethod.getResponseHeaders());
}

From source file:EditorPaneExample16.java

public static void main(String[] args) {
    try {/*from   ww  w.  j a  va2 s.  co  m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new EditorPaneExample16();

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setSize(500, 400);
    f.setVisible(true);
}

From source file:EditorPaneExample13.java

public static void main(String[] args) {
    try {//  www . j  av  a  2  s .  c o  m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new EditorPaneExample13();

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setSize(500, 400);
    f.setVisible(true);
}