List of usage examples for java.awt.event WindowAdapter WindowAdapter
WindowAdapter
From source file:com.googlecode.gmail4j.util.LoginDialog.java
/** * Creates the required listeners/*w ww. j av a2 s .c o m*/ * * @param login Credentials object for filling the data */ private void createListeners(final Credentials login) { pass.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { setCredentials(login); dialog.setVisible(false); } } }); ok.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { setCredentials(login); dialog.setVisible(false); } }); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { log.warn("Login dialog closed, no username/password specified"); latch.countDown(); } }); }
From source file:FileTree3.java
public FileTree3() { super("Directories Tree [Tool Tips]"); setSize(400, 300);/*from w w w . j a v a 2 s . c o m*/ DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer")); DefaultMutableTreeNode node; File[] roots = File.listRoots(); for (int k = 0; k < roots.length; k++) { node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k]))); top.add(node); node.add(new DefaultMutableTreeNode(new Boolean(true))); } m_model = new DefaultTreeModel(top); // NEW m_tree = new JTree(m_model) { public String getToolTipText(MouseEvent ev) { if (ev == null) return null; TreePath path = m_tree.getPathForLocation(ev.getX(), ev.getY()); if (path != null) { FileNode fnode = getFileNode(getTreeNode(path)); if (fnode == null) return null; File f = fnode.getFile(); return (f == null ? null : f.getPath()); } return null; } }; ToolTipManager.sharedInstance().registerComponent(m_tree); m_tree.putClientProperty("JTree.lineStyle", "Angled"); TreeCellRenderer renderer = new IconCellRenderer(); m_tree.setCellRenderer(renderer); m_tree.addTreeExpansionListener(new DirExpansionListener()); m_tree.addTreeSelectionListener(new DirSelectionListener()); m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); m_tree.setShowsRootHandles(true); m_tree.setEditable(false); JScrollPane s = new JScrollPane(); s.getViewport().add(m_tree); getContentPane().add(s, BorderLayout.CENTER); m_display = new JTextField(); m_display.setEditable(false); getContentPane().add(m_display, BorderLayout.NORTH); m_popup = new JPopupMenu(); m_action = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (m_clickedPath == null) return; if (m_tree.isExpanded(m_clickedPath)) m_tree.collapsePath(m_clickedPath); else m_tree.expandPath(m_clickedPath); } }; m_popup.add(m_action); m_popup.addSeparator(); Action a1 = new AbstractAction("Delete") { public void actionPerformed(ActionEvent e) { m_tree.repaint(); JOptionPane.showMessageDialog(FileTree3.this, "Delete option is not implemented", "Info", JOptionPane.INFORMATION_MESSAGE); } }; m_popup.add(a1); Action a2 = new AbstractAction("Rename") { public void actionPerformed(ActionEvent e) { m_tree.repaint(); JOptionPane.showMessageDialog(FileTree3.this, "Rename option is not implemented", "Info", JOptionPane.INFORMATION_MESSAGE); } }; m_popup.add(a2); m_tree.add(m_popup); m_tree.addMouseListener(new PopupTrigger()); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:cl.uai.webcursos.emarking.desktop.OptionsDialog.java
/** * Create the dialog./*from w w w . ja v a 2 s .c o m*/ */ public OptionsDialog(Moodle _moodle) { addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { cancelled = true; } }); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setIconImage(Toolkit.getDefaultToolkit().getImage(OptionsDialog.class .getResource("/cl/uai/webcursos/emarking/desktop/resources/glyphicons_439_wrench.png"))); setTitle(EmarkingDesktop.lang.getString("emarkingoptions")); setModal(true); setBounds(100, 100, 707, 444); this.moodle = _moodle; this.moodle.loadProperties(); getContentPane().setLayout(new BorderLayout()); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { okButton = new JButton(EmarkingDesktop.lang.getString("ok")); okButton.setEnabled(false); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); if (!validator.isValid(moodleurl.getText())) { throw new Exception(EmarkingDesktop.lang.getString("invalidmoodleurl") + " " + moodleurl.getText()); } File f = new File(filename.getText()); if (!f.exists() || f.isDirectory() || (!f.getPath().endsWith(".pdf") && !f.getPath().endsWith(".zip"))) { throw new Exception(EmarkingDesktop.lang.getString("invalidpdffile") + " " + filename.getText()); } if (omrtemplate.getText().trim().length() > 0) { File omrf = new File(omrtemplate.getText()); if (!omrf.exists() || omrf.isDirectory() || (!omrf.getPath().endsWith(".xtmpl"))) { throw new Exception(EmarkingDesktop.lang.getString("invalidomrfile") + " " + omrtemplate.getText()); } } moodle.setLastfile(filename.getText()); moodle.getQrExtractor().setDoubleside(chckbxDoubleSide.isSelected()); moodle.setMaxthreads(Integer.parseInt(getMaxThreads().getSelectedItem().toString())); moodle.setResolution(Integer.parseInt(getResolution().getSelectedItem().toString())); moodle.setMaxzipsize(getMaxZipSize().getSelectedItem().toString()); moodle.setOMRTemplate(omrtemplate.getText()); moodle.setThreshold(Integer.parseInt(spinnerOMRthreshold.getValue().toString())); moodle.setDensity(Integer.parseInt(spinnerOMRdensity.getValue().toString())); moodle.setShapeSize(Integer.parseInt(spinnerOMRshapeSize.getValue().toString())); moodle.setAnonymousPercentage( Integer.parseInt(spinnerAnonymousPercentage.getValue().toString())); moodle.setAnonymousPercentageCustomPage( Integer.parseInt(spinnerAnonymousPercentageCustomPage.getValue().toString())); moodle.setFakeStudents(chckbxMarkersTraining.isSelected()); moodle.saveProperties(); cancelled = false; setVisible(false); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(panel, EmarkingDesktop.lang.getString("invaliddatainform")); } } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton(EmarkingDesktop.lang.getString("cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelled = true; setVisible(false); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); getContentPane().add(tabbedPane, BorderLayout.CENTER); panel = new JPanel(); tabbedPane.addTab(EmarkingDesktop.lang.getString("general"), null, panel, null); panel.setLayout(null); JPanel panel_2 = new JPanel(); panel_2.setBorder(new LineBorder(new Color(0, 0, 0), 1, true)); panel_2.setBounds(10, 11, 665, 131); panel.add(panel_2); panel_2.setLayout(null); JLabel lblPassword = new JLabel(EmarkingDesktop.lang.getString("password")); lblPassword.setBounds(10, 99, 109, 14); panel_2.add(lblPassword); lblPassword.setHorizontalAlignment(SwingConstants.RIGHT); password = new JPasswordField(); password.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { testConnection(); } }); password.setBounds(129, 96, 329, 20); panel_2.add(password); this.password.setText(this.moodle.getPassword()); btnTestConnection = new JButton(EmarkingDesktop.lang.getString("connect")); btnTestConnection.setEnabled(false); btnTestConnection.setBounds(468, 93, 172, 27); panel_2.add(btnTestConnection); username = new JTextField(); username.setBounds(129, 65, 329, 20); panel_2.add(username); username.setColumns(10); this.username.setText(this.moodle.getUsername()); moodleurl = new JTextField(); moodleurl.setBounds(129, 34, 329, 20); panel_2.add(moodleurl); moodleurl.setColumns(10); moodleurl.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { warn(); } @Override public void insertUpdate(DocumentEvent e) { warn(); } @Override public void changedUpdate(DocumentEvent e) { warn(); } private void warn() { UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); if (!validator.isValid(moodleurl.getText()) || !moodleurl.getText().endsWith("/")) { moodleurl.setForeground(Color.RED); btnTestConnection.setEnabled(false); } else { moodleurl.setForeground(Color.BLACK); btnTestConnection.setEnabled(true); } } }); // Initializing values from moodle configuration this.moodleurl.setText(this.moodle.getUrl()); JLabel lblMoodleUrl = new JLabel(EmarkingDesktop.lang.getString("moodleurl")); lblMoodleUrl.setBounds(10, 37, 109, 14); panel_2.add(lblMoodleUrl); lblMoodleUrl.setHorizontalAlignment(SwingConstants.RIGHT); JLabel lblUsername = new JLabel(EmarkingDesktop.lang.getString("username")); lblUsername.setBounds(10, 68, 109, 14); panel_2.add(lblUsername); lblUsername.setHorizontalAlignment(SwingConstants.RIGHT); JLabel lblMoodleSettings = new JLabel(EmarkingDesktop.lang.getString("moodlesettings")); lblMoodleSettings.setBounds(10, 11, 230, 14); panel_2.add(lblMoodleSettings); btnTestConnection.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { testConnection(); } }); JPanel panel_3 = new JPanel(); panel_3.setBorder(new LineBorder(new Color(0, 0, 0), 1, true)); panel_3.setBounds(10, 159, 666, 174); panel.add(panel_3); panel_3.setLayout(null); JLabel lblPdfFile = new JLabel(EmarkingDesktop.lang.getString("pdffile")); lblPdfFile.setBounds(0, 39, 119, 14); panel_3.add(lblPdfFile); lblPdfFile.setHorizontalAlignment(SwingConstants.RIGHT); JLabel lblScanned = new JLabel(EmarkingDesktop.lang.getString("scanned")); lblScanned.setBounds(0, 64, 119, 14); panel_3.add(lblScanned); lblScanned.setHorizontalAlignment(SwingConstants.RIGHT); chckbxDoubleSide = new JCheckBox(EmarkingDesktop.lang.getString("doubleside")); chckbxDoubleSide.setEnabled(false); chckbxDoubleSide.setBounds(125, 60, 333, 23); panel_3.add(chckbxDoubleSide); chckbxDoubleSide.setToolTipText(EmarkingDesktop.lang.getString("doublesidetooltip")); this.chckbxDoubleSide.setSelected(this.moodle.getQrExtractor().isDoubleside()); filename = new JTextField(); filename.setEnabled(false); filename.setBounds(129, 36, 329, 20); panel_3.add(filename); filename.setColumns(10); filename.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { warn(); } @Override public void insertUpdate(DocumentEvent e) { warn(); } @Override public void changedUpdate(DocumentEvent e) { warn(); } private void warn() { validateFileForProcessing(!btnTestConnection.isEnabled()); } }); this.filename.setText(this.moodle.getLastfile()); btnOpenPdfFile = new JButton(EmarkingDesktop.lang.getString("openfile")); btnOpenPdfFile.setEnabled(false); btnOpenPdfFile.setBounds(468, 33, 172, 27); panel_3.add(btnOpenPdfFile); JLabel lblPdfFileSettings = new JLabel(EmarkingDesktop.lang.getString("filesettings")); lblPdfFileSettings.setBounds(10, 11, 230, 14); panel_3.add(lblPdfFileSettings); JLabel lblOMRtemplate = new JLabel(EmarkingDesktop.lang.getString("omrfile")); lblOMRtemplate.setHorizontalAlignment(SwingConstants.RIGHT); lblOMRtemplate.setBounds(0, 142, 119, 14); panel_3.add(lblOMRtemplate); omrtemplate = new JTextField(); omrtemplate.setEnabled(false); omrtemplate.setText((String) null); omrtemplate.setColumns(10); omrtemplate.setBounds(129, 139, 329, 20); panel_3.add(omrtemplate); omrtemplate.setText(this.moodle.getOMRTemplate()); btnOpenOMRTemplate = new JButton(EmarkingDesktop.lang.getString("openomrfile")); btnOpenOMRTemplate.setEnabled(false); btnOpenOMRTemplate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(EmarkingDesktop.lang.getString("openfiletitle")); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileFilter(new FileFilter() { @Override public String getDescription() { return "*.xtmpl"; } @Override public boolean accept(File arg0) { if (arg0.getName().endsWith(".xtmpl") || arg0.isDirectory()) return true; return false; } }); int retval = chooser.showOpenDialog(panel); if (retval == JFileChooser.APPROVE_OPTION) { omrtemplate.setText(chooser.getSelectedFile().getAbsolutePath()); } else { return; } } }); btnOpenOMRTemplate.setBounds(468, 136, 172, 27); panel_3.add(btnOpenOMRTemplate); lblMarkersTraining = new JLabel((String) EmarkingDesktop.lang.getString("markerstraining")); lblMarkersTraining.setHorizontalAlignment(SwingConstants.RIGHT); lblMarkersTraining.setBounds(0, 89, 119, 14); panel_3.add(lblMarkersTraining); chckbxMarkersTraining = new JCheckBox(EmarkingDesktop.lang.getString("markerstrainingfakestudents")); chckbxMarkersTraining.setBounds(125, 87, 333, 23); panel_3.add(chckbxMarkersTraining); btnOpenPdfFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButton.setEnabled(false); JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(EmarkingDesktop.lang.getString("openfiletitle")); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileFilter(new FileFilter() { @Override public String getDescription() { return "*.pdf, *.zip"; } @Override public boolean accept(File arg0) { if (arg0.getName().endsWith(".zip") || arg0.getName().endsWith(".pdf") || arg0.isDirectory()) return true; return false; } }); int retval = chooser.showOpenDialog(panel); if (retval == JFileChooser.APPROVE_OPTION) { filename.setText(chooser.getSelectedFile().getAbsolutePath()); okButton.setEnabled(true); } else { return; } } }); JPanel panel_1 = new JPanel(); tabbedPane.addTab(EmarkingDesktop.lang.getString("advanced"), null, panel_1, null); panel_1.setLayout(null); JPanel panel_4 = new JPanel(); panel_4.setLayout(null); panel_4.setBorder(new LineBorder(new Color(0, 0, 0), 1, true)); panel_4.setBounds(10, 11, 665, 131); panel_1.add(panel_4); JLabel lblAdvancedOptions = new JLabel(EmarkingDesktop.lang.getString("advancedoptions")); lblAdvancedOptions.setBounds(10, 11, 233, 14); panel_4.add(lblAdvancedOptions); JLabel lblThreads = new JLabel(EmarkingDesktop.lang.getString("maxthreads")); lblThreads.setBounds(10, 38, 130, 14); panel_4.add(lblThreads); lblThreads.setHorizontalAlignment(SwingConstants.RIGHT); JLabel lblSomething = new JLabel(EmarkingDesktop.lang.getString("separatezipfiles")); lblSomething.setBounds(10, 73, 130, 14); panel_4.add(lblSomething); lblSomething.setHorizontalAlignment(SwingConstants.RIGHT); JLabel label = new JLabel(EmarkingDesktop.lang.getString("resolution")); label.setBounds(10, 105, 130, 14); panel_4.add(label); label.setHorizontalAlignment(SwingConstants.RIGHT); resolution = new JComboBox<Integer>(); resolution.setBounds(150, 99, 169, 27); panel_4.add(resolution); resolution.setModel(new DefaultComboBoxModel<Integer>(new Integer[] { 75, 100, 150, 300, 400, 500, 600 })); resolution.setSelectedIndex(2); this.resolution.setSelectedItem(this.moodle.getQrExtractor().getResolution()); maxZipSize = new JComboBox<String>(); maxZipSize.setBounds(150, 67, 169, 27); panel_4.add(maxZipSize); maxZipSize.setModel(new DefaultComboBoxModel<String>(new String[] { "<dynamic>", "2Mb", "4Mb", "8Mb", "16Mb", "32Mb", "64Mb", "128Mb", "256Mb", "512Mb", "1024Mb" })); maxZipSize.setSelectedIndex(6); this.maxZipSize.setSelectedItem(this.moodle.getMaxZipSizeString()); maxThreads = new JComboBox<Integer>(); maxThreads.setBounds(150, 32, 169, 27); panel_4.add(maxThreads); maxThreads.setModel(new DefaultComboBoxModel<Integer>(new Integer[] { 2, 4, 8, 16 })); maxThreads.setSelectedIndex(1); this.maxThreads.setSelectedItem(this.moodle.getQrExtractor().getMaxThreads()); JPanel panel_5 = new JPanel(); panel_5.setLayout(null); panel_5.setBorder(new LineBorder(new Color(0, 0, 0), 1, true)); panel_5.setBounds(10, 153, 665, 131); panel_1.add(panel_5); JLabel lblOMRoptions = new JLabel(EmarkingDesktop.lang.getString("omroptions")); lblOMRoptions.setBounds(10, 11, 233, 14); panel_5.add(lblOMRoptions); JLabel lblOMRthreshold = new JLabel(EmarkingDesktop.lang.getString("omrthreshold")); lblOMRthreshold.setHorizontalAlignment(SwingConstants.RIGHT); lblOMRthreshold.setBounds(10, 32, 130, 14); panel_5.add(lblOMRthreshold); JLabel lblShapeSize = new JLabel(EmarkingDesktop.lang.getString("omrshapesize")); lblShapeSize.setHorizontalAlignment(SwingConstants.RIGHT); lblShapeSize.setBounds(10, 99, 130, 14); panel_5.add(lblShapeSize); JLabel lblDensity = new JLabel(EmarkingDesktop.lang.getString("omrdensity")); lblDensity.setHorizontalAlignment(SwingConstants.RIGHT); lblDensity.setBounds(10, 70, 130, 14); panel_5.add(lblDensity); spinnerOMRthreshold = new JSpinner(); spinnerOMRthreshold.setBounds(150, 32, 169, 20); panel_5.add(spinnerOMRthreshold); spinnerOMRthreshold.setValue(this.moodle.getOMRthreshold()); spinnerOMRdensity = new JSpinner(); spinnerOMRdensity.setBounds(150, 67, 169, 20); panel_5.add(spinnerOMRdensity); spinnerOMRdensity.setValue(this.moodle.getOMRdensity()); spinnerOMRshapeSize = new JSpinner(); spinnerOMRshapeSize.setBounds(150, 99, 169, 20); panel_5.add(spinnerOMRshapeSize); spinnerOMRshapeSize.setValue(this.moodle.getOMRshapeSize()); JLabel lblAnonymousPercentage = new JLabel( "<html>" + EmarkingDesktop.lang.getString("anonymouspercentage") + "</html>"); lblAnonymousPercentage.setHorizontalAlignment(SwingConstants.RIGHT); lblAnonymousPercentage.setBounds(329, 32, 130, 27); panel_5.add(lblAnonymousPercentage); spinnerAnonymousPercentage = new JSpinner(); spinnerAnonymousPercentage.setBounds(469, 32, 169, 20); panel_5.add(spinnerAnonymousPercentage); spinnerAnonymousPercentage.setValue(this.moodle.getAnonymousPercentage()); JLabel lblAnonymousPercentageCustomPage = new JLabel( "<html>" + EmarkingDesktop.lang.getString("anonymouspercentagecustompage") + "</html>"); lblAnonymousPercentageCustomPage.setHorizontalAlignment(SwingConstants.RIGHT); lblAnonymousPercentageCustomPage.setBounds(329, 70, 130, 27); panel_5.add(lblAnonymousPercentageCustomPage); spinnerAnonymousPercentageCustomPage = new JSpinner(); spinnerAnonymousPercentageCustomPage.setBounds(469, 70, 169, 20); panel_5.add(spinnerAnonymousPercentageCustomPage); spinnerAnonymousPercentageCustomPage.setValue(this.moodle.getAnonymousPercentageCustomPage()); JLabel lblCustomPage = new JLabel( "<html>" + EmarkingDesktop.lang.getString("anonymouscustompage") + "</html>"); lblCustomPage.setHorizontalAlignment(SwingConstants.RIGHT); lblCustomPage.setBounds(329, 99, 130, 27); panel_5.add(lblCustomPage); spinnerCustomPage = new JSpinner(); spinnerCustomPage.setBounds(469, 99, 169, 20); panel_5.add(spinnerCustomPage); spinnerCustomPage.setValue(this.moodle.getAnonymousCustomPage()); }
From source file:com.mirth.connect.manager.ManagerDialog.java
public void setupDialog() { initComponents();/*ww w. ja v a2s . c om*/ initLayout(); heapSizeButton.setIcon(icon); databaseUrls.put("derby", "jdbc:derby:${dir.appdata}/mirthdb;create=true"); databaseUrls.put("postgres", "jdbc:postgresql://localhost:5432/mirthdb"); databaseUrls.put("mysql", "jdbc:mysql://localhost:3306/mirthdb"); databaseUrls.put("oracle", "jdbc:oracle:thin:@localhost:1521:DB"); databaseUrls.put("sqlserver", "jdbc:jtds:sqlserver://localhost:1433/mirthdb"); // Remove the service tab if it's not supported if (!serviceController.isShowServiceTab()) { tabPanel.removeTabAt(0); } pack(); setLocationRelativeTo(null); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { close(); } }); serverMemoryField.setDocument(new MirthFieldConstraints(0, false, false, true)); loadProperties(); }
From source file:org.apache.shiro.samples.spring.ui.WebStartView.java
public void afterPropertiesSet() throws Exception { ClassPathResource resource = new ClassPathResource("logo.png"); ImageIcon icon = new ImageIcon(resource.getURL()); JLabel logo = new JLabel(icon); valueField = new JTextField(20); updateValueLabel();// w w w . ja v a 2 s .c o m saveButton = new JButton("Save Value"); saveButton.addActionListener(this); refreshButton = new JButton("Refresh Value"); refreshButton.addActionListener(this); JPanel valuePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); valuePanel.add(valueField); valuePanel.add(saveButton); valuePanel.add(refreshButton); secureMethod1Button = new JButton("Method #1"); secureMethod1Button.addActionListener(this); secureMethod2Button = new JButton("Method #2"); secureMethod2Button.addActionListener(this); secureMethod3Button = new JButton("Method #3"); secureMethod3Button.addActionListener(this); JPanel methodPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); methodPanel.add(secureMethod1Button); methodPanel.add(secureMethod2Button); methodPanel.add(secureMethod3Button); frame = new JFrame("Apache Shiro Sample Application"); frame.setSize(500, 200); Container panel = frame.getContentPane(); panel.setLayout(new BorderLayout()); panel.add(logo, BorderLayout.NORTH); panel.add(valuePanel, BorderLayout.CENTER); panel.add(methodPanel, BorderLayout.SOUTH); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
From source file:ExpenseReport.java
public ExpenseReport() { super("Expense Report"); setSize(570, 200);/*from w w w . j a v a 2 s . co m*/ m_data = new ExpenseReportData(this); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); for (int k = 0; k < ExpenseReportData.m_columns.length; k++) { TableCellRenderer renderer; if (k == ExpenseReportData.COL_APPROVED) renderer = new CheckCellRenderer(); else { DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer(); textRenderer.setHorizontalAlignment(ExpenseReportData.m_columns[k].m_alignment); renderer = textRenderer; } TableCellEditor editor; if (k == ExpenseReportData.COL_CATEGORY) editor = new DefaultCellEditor(new JComboBox(ExpenseReportData.CATEGORIES)); else if (k == ExpenseReportData.COL_APPROVED) editor = new DefaultCellEditor(new JCheckBox()); else editor = new DefaultCellEditor(new JTextField()); TableColumn column = new TableColumn(k, ExpenseReportData.m_columns[k].m_width, renderer, editor); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(false); JScrollPane ps = new JScrollPane(); ps.setSize(550, 150); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); ImageIcon penny = new ImageIcon("penny.gif"); m_title = new JLabel("Total: $", penny, JButton.LEFT); m_title.setForeground(Color.black); m_title.setAlignmentY(0.5f); p.add(m_title); p.add(Box.createHorizontalGlue()); JButton bt = new JButton("Insert before"); bt.setMnemonic('b'); bt.setAlignmentY(0.5f); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row); m_table.tableChanged( new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Insert after"); bt.setMnemonic('a'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row + 1); m_table.tableChanged(new TableModelEvent(m_data, row + 1, row + 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Delete row"); bt.setMnemonic('d'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); if (m_data.delete(row)) { m_table.tableChanged(new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); calcTotal(); } } }; bt.addActionListener(lst); p.add(bt); getContentPane().add(p, BorderLayout.SOUTH); calcTotal(); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:Main.java
/** Construct the object including its GUI */ public Main() {/*from ww w.java 2 s .co m*/ super("More Choices"); // cp = getContentPane(); cp = this; cp.setLayout(new BorderLayout()); ButtonsPanel bp = new ButtonsPanel(); cp.add(BorderLayout.NORTH, bp); // Construct the more/less switcher less = new ActionListener() { public void actionPerformed(ActionEvent e) { cp.remove(moreOrLessPanel); pack(); moreOrLessButton.setText("More Choices"); moreOrLessButton.removeActionListener(less); moreOrLessButton.addActionListener(more); } }; more = new ActionListener() { public void actionPerformed(ActionEvent e) { cp.add(BorderLayout.SOUTH, moreOrLessPanel); pack(); moreOrLessButton.setText("Fewer Choices"); moreOrLessButton.removeActionListener(more); moreOrLessButton.addActionListener(less); } }; bp.add(moreOrLessButton = new JButton("More Choices")); // Initial state is to add more choices moreOrLessButton.addActionListener(more); moreOrLessPanel = new ChoicesPanel(); // Finally a frame closer addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); dispose(); System.exit(0); } }); pack(); }
From source file:ru.codemine.pos.ui.MainWindow.java
private void setupActionListeners() { addWindowListener(new WindowAdapter() { @Override//from w w w . j a va 2s . c om public void windowClosing(WindowEvent e) { if (WebOptionPane.showConfirmDialog(rootPane, " ?", " ?", WebOptionPane.YES_NO_OPTION, WebOptionPane.QUESTION_MESSAGE) == 0) { application.close(); } } }); }
From source file:DesktopManagerDemo.java
public DesktopManagerDemo() { setTitle("Animated DesktopManager"); m_count = m_tencount = 0;//from ww w .j av a 2 s. c o m JPanel innerListenerPanel = new JPanel(new GridLayout(15, 1)); JPanel listenerPanel = new JPanel(new BorderLayout()); m_dmEventCanvas = new DMEventCanvas(); m_lActivates = new JLabel("activateFrame"); m_lBegindrags = new JLabel("beginDraggingFrame"); m_lBeginresizes = new JLabel("beginResizingFrame"); m_lCloses = new JLabel("closeFrame"); m_lDeactivates = new JLabel("deactivateFrame"); m_lDeiconifies = new JLabel("deiconifyFrame"); m_lDrags = new JLabel("dragFrame"); m_lEnddrags = new JLabel("endDraggingFrame"); m_lEndresizes = new JLabel("endResizingFrame"); m_lIconifies = new JLabel("iconifyFrame"); m_lMaximizes = new JLabel("maximizeFrame"); m_lMinimizes = new JLabel("minimizeFrame"); m_lOpens = new JLabel("openFrame"); m_lResizes = new JLabel("resizeFrame"); m_lSetbounds = new JLabel("setBoundsForFrame"); innerListenerPanel.add(m_lActivates); innerListenerPanel.add(m_lBegindrags); innerListenerPanel.add(m_lBeginresizes); innerListenerPanel.add(m_lCloses); innerListenerPanel.add(m_lDeactivates); innerListenerPanel.add(m_lDeiconifies); innerListenerPanel.add(m_lDrags); innerListenerPanel.add(m_lEnddrags); innerListenerPanel.add(m_lEndresizes); innerListenerPanel.add(m_lIconifies); innerListenerPanel.add(m_lMaximizes); innerListenerPanel.add(m_lMinimizes); innerListenerPanel.add(m_lOpens); innerListenerPanel.add(m_lResizes); innerListenerPanel.add(m_lSetbounds); listenerPanel.add("Center", m_dmEventCanvas); listenerPanel.add("West", innerListenerPanel); listenerPanel.setOpaque(true); listenerPanel.setBackground(Color.white); m_myDesktopManager = new MyDesktopManager(); m_desktop = new JDesktopPane(); m_desktop.setDesktopManager(m_myDesktopManager); m_desktop.setBorder(new SoftBevelBorder(BevelBorder.LOWERED)); m_newFrame = new JButton("New Frame"); m_newFrame.addActionListener(this); m_infos = UIManager.getInstalledLookAndFeels(); String[] LAFNames = new String[m_infos.length]; for (int i = 0; i < m_infos.length; i++) { LAFNames[i] = m_infos[i].getName(); } m_UIBox = new JComboBox(LAFNames); m_UIBox.addActionListener(this); JPanel topPanel = new JPanel(true); topPanel.setLayout(new FlowLayout()); topPanel.setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED), new CompoundBorder(new EmptyBorder(2, 2, 2, 2), new SoftBevelBorder(BevelBorder.RAISED)))); getContentPane().setLayout(new BorderLayout()); getContentPane().add("North", topPanel); getContentPane().add("Center", m_desktop); getContentPane().add("South", listenerPanel); ((JPanel) getContentPane()).setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED), new CompoundBorder(new EmptyBorder(1, 1, 1, 1), new SoftBevelBorder(BevelBorder.RAISED)))); topPanel.add(m_newFrame); topPanel.add(new JLabel("Look & Feel:", SwingConstants.RIGHT)); topPanel.add(m_UIBox); setSize(645, 600); Dimension dim = getToolkit().getScreenSize(); setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2); setVisible(true); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(l); m_eventTimer = new Timer(1000, this); m_eventTimer.setRepeats(true); m_eventTimer.start(); }
From source file:omr.jai.RGBToBilevel.java
RGBToBilevel(final String fileName, boolean isErrorDiffusion) { // Load the file. PlanarImage src = JAI.create("fileload", fileName); // Load the ParameterBlock for the dithering operation // and set the operation name. ParameterBlock pb = new ParameterBlock(); pb.addSource(src);/*ww w . j a va 2 s . c om*/ String opName = null; if (isErrorDiffusion) { opName = "errordiffusion"; LookupTableJAI lut = new LookupTableJAI(new byte[][] { { (byte) 0x00, (byte) 0xff }, { (byte) 0x00, (byte) 0xff }, { (byte) 0x00, (byte) 0xff } }); pb.add(lut); pb.add(KernelJAI.ERROR_FILTER_FLOYD_STEINBERG); } else { opName = "ordereddither"; ColorCube cube = ColorCube.createColorCube(DataBuffer.TYPE_BYTE, 0, new int[] { 2, 2, 2 }); pb.add(cube); pb.add(KernelJAI.DITHER_MASK_443); } // Create a layout containing an IndexColorModel which maps // zero to zero and unity to 255; force SampleModel to be bilevel. ImageLayout layout = new ImageLayout(); byte[] map = new byte[] { (byte) 0x00, (byte) 0xff }; ColorModel cm = new IndexColorModel(1, 2, map, map, map); layout.setColorModel(cm); SampleModel sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, src.getWidth(), src.getHeight(), 1); layout.setSampleModel(sm); // Create a hint containing the layout. RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); // Dither the image. final PlanarImage dst = JAI.create(opName, pb, hints); // Exit on window closing. addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { JAI.create("filestore", dst, fileName + ".out", "PNG", null); System.exit(0); } }); // Display the result. //// ATTENTION A REMPLACER : add(new ScrollingImagePanel(dst, dst.getWidth(), dst.getHeight())); pack(); setVisible(true); }