List of usage examples for java.awt.event WindowAdapter WindowAdapter
WindowAdapter
From source file:dbseer.gui.frame.DBSeerPlotPresetFrame.java
private void initializeGUI() throws Exception { chartPanels.clear();// w w w . jav a 2s.c o m this.setLayout(new MigLayout("fill")); int count = 0; ArrayList<DBSeerChart> charts = new ArrayList<DBSeerChart>(); for (String chartName : chartNames) { JFreeChart chart; if (chartName.equalsIgnoreCase("TransactionMix")) { chart = DBSeerChartFactory.createPieChart(chartName, dataset); } else { chart = DBSeerChartFactory.createXYLineChart(chartName, dataset); } double[] timestamp = new double[DBSeerChartFactory.timestamp.length]; for (int i = 0; i < DBSeerChartFactory.timestamp.length; ++i) { timestamp[i] = DBSeerChartFactory.timestamp[i]; } DBSeerChart newChart = new DBSeerChart(chartName, chart); charts.add(newChart); DBSeerSelectableChartPanel chartPanel = new DBSeerSelectableChartPanel(chart, dataset, chartName, timestamp); chartPanels.add(chartPanel); if (++count == numChartInRow) { this.add(chartPanel, "grow, wrap"); count = 0; } else { this.add(chartPanel, "grow"); } } // if live dataset, launch the chart refresher. if (dataset.isCurrent()) { final DBSeerChartRefreshWorker refresher = new DBSeerChartRefreshWorker(charts, dataset); this.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent windowEvent) { refresher.stop(); refresher.cancel(false); super.windowClosed(windowEvent); } }); refresher.execute(); } }
From source file:org.jfree.chart.demo.MeterChartDemo.java
/** * Displays a meter chart.// ww w.j a v a 2 s .com * * @param value the value. * @param shape the dial shape. */ void displayMeterChart(final double value, final DialShape shape) { final DefaultValueDataset data = new DefaultValueDataset(75.0); final MeterPlot plot = new MeterPlot(data); plot.setUnits("Degrees"); plot.setRange(new Range(20.0, 140.0)); // plot.setNormalRange(new Range(70.0, 100.0)); // plot.setWarningRange(new Range(100.0, 120.0)); // plot.setCriticalRange(new Range(120.0, 140.0)); plot.setDialShape(shape); plot.setNeedlePaint(Color.white); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 9)); // plot.setInsets(new Insets(5, 5, 5, 5)); final JFreeChart chart = new JFreeChart("Meter Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); // final MeterLegend legend = new MeterLegend("Sample Meter"); // chart.setLegend(legend); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final JFrame chartFrame = new ChartFrame("Meter Chart", chart); chartFrame.addWindowListener(new WindowAdapter() { /** * Invoked when a window is in the process of being closed. * The close operation can be overridden at this point. */ public void windowClosing(final WindowEvent e) { System.exit(0); } }); chartFrame.pack(); RefineryUtilities.positionFrameRandomly(chartFrame); chartFrame.setSize(250, 250); chartFrame.setVisible(true); }
From source file:br.univali.ps.ui.telas.TelaPrincipal.java
private void instalarObservadorJanela() { JFrame frame = Lancador.getJFrame(); if (frame == null) return;/*from www. ja v a2 s.c o m*/ frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { fecharAplicativo(); } @Override public void windowOpened(WindowEvent e) { Configuracoes configuracoes = Configuracoes.getInstancia(); if (configuracoes.isExibirDicasInterface()) { SwingUtilities.invokeLater(() -> { PortugolStudio.getInstancia().getTelaDicas().setVisible(true); }); } LOGGER.log(Level.INFO, "Janela principal aberta!"); } }); Lancador.getJFrame().addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { if (abrindo) { abrindo = false; // Por enquanto o Andr pediu para desativar esta verificao, ela s estar disponvel // no final do ano //verificarAtualizacaoCritica(); if (Configuracoes.getInstancia().isExibirTutorialUso()) { //TODO: criar e executar tutorial de uso antes de iniciar o Portugol dispararProcessosAbertura(); } else { dispararProcessosAbertura(); } } } }); }
From source file:de.bley.word.menu.GuiMenu.java
private void addListener() { button.addActionListener(new ActionListener() { @Override// ww w . j ava 2 s . c o m public void actionPerformed(ActionEvent e) { saveData(); refreshList(); } }); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (!textfield.getText().equals("") && !textfield.getText().equals(PropertieManager.getInstance() .getZuordnung().getReader().readFile(zuordnung.getPath().getFilepath()))) { int confirmed = JOptionPane.showConfirmDialog(null, "Daten speichern?", "Beenden", JOptionPane.YES_NO_OPTION); if (confirmed == JOptionPane.YES_OPTION) { saveData(); } } } }); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.standalone.StandaloneShutdownDialog.java
private void displayShutdownDialog() { String serverId = ServerDetector.getServerId(); log.info("Running in: " + (serverId != null ? serverId : "unknown server")); log.info("Console: " + ((System.console() != null) ? "available" : "not available")); log.info("Headless: " + (GraphicsEnvironment.isHeadless() ? "yes" : "no")); // Show this only when run from the standalone JAR via a double-click if (System.console() == null && !GraphicsEnvironment.isHeadless() && ServerDetector.isWinstone()) { log.info("If you are running WebAnno in a server environment, please use '-Djava.awt.headless=true'"); EventQueue.invokeLater(new Runnable() { @Override/*from ww w. j a v a 2s .c o m*/ public void run() { final JOptionPane optionPane = new JOptionPane(new JLabel( "<HTML>WebAnno is running now and can be accessed via <a href=\"http://localhost:8080\">http://localhost:8080</a>.<br>" + "WebAnno works best with the browsers Google Chrome or Safari.<br>" + "Use this dialog to shut WebAnno down.</HTML>"), JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_OPTION, null, new String[] { "Shutdown" }); final JDialog dialog = new JDialog((JFrame) null, "WebAnno", true); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { // Avoid closing window by other means than button } }); optionPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent aEvt) { if (dialog.isVisible() && (aEvt.getSource() == optionPane) && (aEvt.getPropertyName().equals(JOptionPane.VALUE_PROPERTY))) { System.exit(0); } } }); dialog.pack(); dialog.setVisible(true); } }); } else { log.info("Running in server environment or from command line: disabling interactive shutdown dialog."); } }
From source file:fr.irit.smac.amasfactory.service.execution.impl.TwoStepAgExecutionService.java
@Override public void displaySimpleGui() { JFrame frame = new JFrame() { {/*from w w w. ja v a 2 s . com*/ add(new SystemControllerPanel(systemStrategy, 500)); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { systemStrategy.shutdown(); } }); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }; frame.pack(); frame.setVisible(true); }
From source file:TradeMonitorGui.java
private XYPlot createChartFrame(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Average Stock Price over 1 minute", "Time", "Price in USD", dataset, true, true, false); XYPlot plot = chart.getXYPlot();/*w w w . j a v a 2s .co m*/ plot.setBackgroundPaint(new Color(245, 245, 245)); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); final JFrame frame = new JFrame(); frame.setBackground(Color.WHITE); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setTitle("Trade Monitor"); frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT); frame.setLayout(new BorderLayout()); frame.add(new ChartPanel(chart)); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { avgPrices.removeEntryListener(listenerId); } }); frame.setVisible(true); return plot; }
From source file:FileTree2.java
public FileTree2() { super("Directories Tree [Popup Menus]"); setSize(400, 300);/*from w w w . j av 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); m_tree = new JTree(m_model); 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); // NEW 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(FileTree2.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(FileTree2.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:InternalFrameListenerDemo.java
public InternalFrameListenerDemo() { setTitle("Animated InternalFrameListener"); m_count = m_tencount = 0;/*from w ww . j a va 2 s . c om*/ JPanel innerListenerPanel = new JPanel(new GridLayout(7, 1)); JPanel listenerPanel = new JPanel(new BorderLayout()); m_ifEventCanvas = new IFEventCanvas(); m_lOpened = new JLabel("internalFrameOpened"); m_lClosing = new JLabel("internalFrameClosing"); m_lClosed = new JLabel("internalFrameClosed"); m_lIconified = new JLabel("internalFrameIconified"); m_lDeiconified = new JLabel("internalFrameDeiconified"); m_lActivated = new JLabel("internalFrameActivated"); m_lDeactivated = new JLabel("internalFrameDeactivated"); innerListenerPanel.add(m_lOpened); innerListenerPanel.add(m_lClosing); innerListenerPanel.add(m_lClosed); innerListenerPanel.add(m_lIconified); innerListenerPanel.add(m_lDeiconified); innerListenerPanel.add(m_lActivated); innerListenerPanel.add(m_lDeactivated); listenerPanel.add("Center", m_ifEventCanvas); listenerPanel.add("West", innerListenerPanel); listenerPanel.setOpaque(true); listenerPanel.setBackground(Color.white); m_desktop = new JDesktopPane(); 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, 500); 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:AppletViewer.java
/** Construct the GUI for an Applet Viewer */ AppletViewer(String appName) {//from w ww. j a va2 s .co m super(); this.appName = appName; f = new JFrame("AppletViewer"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { f.setVisible(false); f.dispose(); System.exit(0); } }); Container cp = f.getContentPane(); cp.setLayout(new BorderLayout()); // Instantiate the AppletAdapter which gives us // AppletStub and AppletContext. if (aa == null) aa = new AppletAdapter(); // The AppletAdapter also gives us showStatus. // Therefore, must add() it very early on, since the Applet's // Constructor or its init() may use showStatus() cp.add(BorderLayout.SOUTH, aa); showStatus("Loading Applet " + appName); loadApplet(appName, WIDTH, HEIGHT); // sets ac and ai if (ai == null) return; // Now right away, tell the Applet how to find showStatus et al. ai.setStub(aa); // Connect the Applet to the Frame. cp.add(BorderLayout.CENTER, ai); Dimension d = ai.getSize(); d.height += aa.getSize().height; f.setSize(d); f.setVisible(true); // make the Frame and all in it appear showStatus("Applet " + appName + " loaded"); // Here we pretend to be a browser! ai.init(); ai.start(); }