List of usage examples for java.awt.event WindowAdapter WindowAdapter
WindowAdapter
From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java
public MainController() { iliasProperties = readProperties();/* w w w.j a v a2 s . c o m*/ if (iliasProperties.getLookAndFeel() == null || iliasProperties.getLookAndFeel().trim().isEmpty()) { iliasProperties.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } try { UIManager.setLookAndFeel(iliasProperties.getLookAndFeel()); } catch (Exception e1) { e1.printStackTrace(); } fileObjectTableModel = new FileObjectTableModel(); mainFrame = new MainFrame(this, initMenuBar()); // initTableFiles(); handleFirstStart(); mainFrame.getFieldLogin().setText(iliasProperties.getUserName()); updateTitleCaption(); mainFrame.getCheckboxNotDownload().setSelected(!iliasProperties.isAllowDownload()); if (!mainFrame.getFieldLogin().getText().trim().isEmpty()) { mainFrame.getFieldPassword().requestFocus(); } syncService = new SyncService(this, this, new ObjectDoInterfaceX<Void, IliasProperties>() {//IliasProperties Callback @Override public IliasProperties doSomething(Void object) { iliasProperties.setUserName(mainFrame.getFieldLogin().getText()); iliasProperties.setAllowDownload(!mainFrame.getCheckboxNotDownload().isSelected()); saveProperties(iliasProperties); return iliasProperties; } }, new ObjectDoInterfaceX<Void, String>() {//Password Callback @Override public String doSomething(Void object) { return new String(mainFrame.getFieldPassword().getPassword()); } }, new ObjectDoInterfaceX<Throwable, Void>() { @Override public Void doSomething(Throwable e) { showError("Fehler bei der Dateisynchronisierung: " + e.getMessage(), e); return null; } }); mainFrame.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { minimizeToTray(); } @Override public void windowClosing(WindowEvent e) { try { syncService.logoutIfLoggedIn(); } catch (Exception ex) { System.exit(0); } } }); startOrStopAutoSync(); }
From source file:edu.ucsf.valelab.spotintensityanalysis.plot.PlotUtils.java
/** * Create a frame with a plot of the data given in XYSeries overwrite any * previously created frame with the same title * // ww w.j ava 2s . co m * @param title shown in the top of the plot * @param data array with data series to be plotted * @param xTitle Title of the X axis * @param yTitle Title of the Y axis * @param showShapes whether or not to draw shapes at the data points * @param annotation to be shown in plot * @return Frame that displays the data */ public Frame plotDataN(String title, XYSeries[] data, String xTitle, String yTitle, boolean[] showShapes, String annotation) { // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); // calculate min and max to scale the graph double minX, minY, maxX, maxY; minX = data[0].getMinX(); minY = data[0].getMinY(); maxX = data[0].getMaxX(); maxY = data[0].getMaxY(); for (XYSeries d : data) { dataset.addSeries(d); if (d.getMinX() < minX) { minX = d.getMinX(); } if (d.getMaxX() > maxX) { maxX = d.getMaxX(); } if (d.getMinY() < minY) { minY = d.getMinY(); } if (d.getMaxY() > maxY) { maxY = d.getMaxY(); } } JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); for (int i = 0; i < data.length; i++) { renderer.setSeriesFillPaint(i, Color.white); renderer.setSeriesLinesVisible(i, true); } renderer.setSeriesPaint(0, Color.blue); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); if (data.length > 1) { renderer.setSeriesPaint(1, Color.red); Shape square = new Rectangle2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(1, square, false); } if (data.length > 2) { renderer.setSeriesPaint(2, Color.darkGray); Shape rect = new Rectangle2D.Float(-2.0f, -1.0f, 4.0f, 2.0f); renderer.setSeriesShape(2, rect, false); } if (data.length > 3) { renderer.setSeriesPaint(3, Color.magenta); Shape rect = new Rectangle2D.Float(-1.0f, -2.0f, 2.0f, 4.0f); renderer.setSeriesShape(3, rect, false); } for (int i = 0; i < data.length; i++) { if (showShapes.length > i && !showShapes[i]) { renderer.setSeriesShapesVisible(i, false); } } // place annotation at 80 % of max X, maxY XYAnnotation an = new XYTextAnnotation(annotation, maxX - 0.2 * (maxX - minX), maxY); plot.addAnnotation(an); renderer.setUseFillPaint(true); if (graphFrame_ == null) graphFrame_ = new MyChartFrame(title, chart); else graphFrame_.getChartPanel().setChart(chart); graphFrame_.getChartPanel().setMouseWheelEnabled(true); graphFrame_.pack(); final MyChartFrame privateFrame = graphFrame_; graphFrame_.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { privateFrame.dispose(); } }); graphFrame_.setVisible(true); return graphFrame_; }
From source file:org.micromanager.saim.plot.PlotUtils.java
/** * Create a frame with a plot of the data given in XYSeries overwrite any * previously created frame with the same title * /*from w w w. j av a2s . c om*/ * @param title shown in the top of the plot * @param data array with data series to be plotted * @param xTitle Title of the X axis * @param yTitle Title of the Y axis * @param showShapes whether or not to draw shapes at the data points * @param annotation to be shown in plot * @return Frame that displays the data */ public Frame plotDataN(String title, XYSeries[] data, String xTitle, String yTitle, boolean[] showShapes, String annotation) { //Close existing frames Frame[] gfs = ChartFrame.getFrames(); for (Frame f : gfs) { if (f.getTitle().equals(title)) { f.dispose(); } } // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); // calculate min and max to scale the graph double minX, minY, maxX, maxY; minX = data[0].getMinX(); minY = data[0].getMinY(); maxX = data[0].getMaxX(); maxY = data[0].getMaxY(); for (XYSeries d : data) { dataset.addSeries(d); if (d.getMinX() < minX) { minX = d.getMinX(); } if (d.getMaxX() > maxX) { maxX = d.getMaxX(); } if (d.getMinY() < minY) { minY = d.getMinY(); } if (d.getMaxY() > maxY) { maxY = d.getMaxY(); } } JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); for (int i = 0; i < data.length; i++) { renderer.setSeriesFillPaint(i, Color.white); renderer.setSeriesLinesVisible(i, true); } renderer.setSeriesPaint(0, Color.blue); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); if (data.length > 1) { renderer.setSeriesPaint(1, Color.red); Shape square = new Rectangle2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(1, square, false); } if (data.length > 2) { renderer.setSeriesPaint(2, Color.darkGray); Shape rect = new Rectangle2D.Float(-2.0f, -1.0f, 4.0f, 2.0f); renderer.setSeriesShape(2, rect, false); } if (data.length > 3) { renderer.setSeriesPaint(3, Color.magenta); Shape rect = new Rectangle2D.Float(-1.0f, -2.0f, 2.0f, 4.0f); renderer.setSeriesShape(3, rect, false); } for (int i = 0; i < data.length; i++) { if (showShapes.length > i && !showShapes[i]) { renderer.setSeriesShapesVisible(i, false); } } // place annotation at 80 % of max X, maxY XYAnnotation an = new XYTextAnnotation(annotation, maxX - 0.2 * (maxX - minX), maxY); plot.addAnnotation(an); renderer.setUseFillPaint(true); final MyChartFrame graphFrame = new MyChartFrame(title, chart); graphFrame.getChartPanel().setMouseWheelEnabled(true); graphFrame.pack(); graphFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { graphFrame.dispose(); } }); graphFrame.setVisible(true); return graphFrame; }
From source file:edu.ucsf.valelab.saim.plot.PlotUtils.java
/** * Create a frame with a plot of the data given in XYSeries overwrite any * previously created frame with the same title * /* w w w .j av a 2 s.c o m*/ * @param title shown in the top of the plot * @param data array with data series to be plotted * @param xTitle Title of the X axis * @param yTitle Title of the Y axis * @param showShapes whether or not to draw shapes at the data points * @param annotation to be shown in plot * @return Frame that displays the data */ public Frame plotDataN(String title, XYSeries[] data, String xTitle, String yTitle, boolean[] showShapes, String annotation) { // Close existing frames // Frame[] gfs = ChartFrame.getFrames(); // for (Frame f : gfs) { //if (f.getTitle().equals(title)) { // f.dispose(); //} // } // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); // calculate min and max to scale the graph double minX, minY, maxX, maxY; minX = data[0].getMinX(); minY = data[0].getMinY(); maxX = data[0].getMaxX(); maxY = data[0].getMaxY(); for (XYSeries d : data) { dataset.addSeries(d); if (d.getMinX() < minX) { minX = d.getMinX(); } if (d.getMaxX() > maxX) { maxX = d.getMaxX(); } if (d.getMinY() < minY) { minY = d.getMinY(); } if (d.getMaxY() > maxY) { maxY = d.getMaxY(); } } JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); for (int i = 0; i < data.length; i++) { renderer.setSeriesFillPaint(i, Color.white); renderer.setSeriesLinesVisible(i, true); } renderer.setSeriesPaint(0, Color.blue); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); if (data.length > 1) { renderer.setSeriesPaint(1, Color.red); Shape square = new Rectangle2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(1, square, false); } if (data.length > 2) { renderer.setSeriesPaint(2, Color.darkGray); Shape rect = new Rectangle2D.Float(-2.0f, -1.0f, 4.0f, 2.0f); renderer.setSeriesShape(2, rect, false); } if (data.length > 3) { renderer.setSeriesPaint(3, Color.magenta); Shape rect = new Rectangle2D.Float(-1.0f, -2.0f, 2.0f, 4.0f); renderer.setSeriesShape(3, rect, false); } for (int i = 0; i < data.length; i++) { if (showShapes.length > i && !showShapes[i]) { renderer.setSeriesShapesVisible(i, false); } } // place annotation at 80 % of max X, maxY XYAnnotation an = new XYTextAnnotation(annotation, maxX - 0.2 * (maxX - minX), maxY); plot.addAnnotation(an); renderer.setUseFillPaint(true); final MyChartFrame graphFrame = new MyChartFrame(title, chart); graphFrame.getChartPanel().setMouseWheelEnabled(true); graphFrame.pack(); graphFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { graphFrame.dispose(); } }); graphFrame.setVisible(true); return graphFrame; }
From source file:com.raddle.tools.ClipboardTransferMain.java
public ClipboardTransferMain() { super();// w ww .j av a 2 s. co m initGUI(); //// ?? Properties p = new Properties(); File pf = new File(System.getProperty("user.home") + "/clip-trans/conf.properties"); if (pf.exists()) { try { p.load(new FileInputStream(pf)); serverAddrTxt.setText(StringUtils.defaultString(p.getProperty("server.addr"))); portTxt.setText(StringUtils.defaultString(p.getProperty("local.port"))); modifyClipChk.setSelected("true".equals(p.getProperty("allow.modify.local.clip"))); autoChk.setSelected("true".equals(p.getProperty("auto.modify.remote.clip"))); } catch (Exception e) { updateMessage(e.getMessage()); } } m.addListener(new ClipboardListener() { @Override public void contentChanged(Clipboard clipboard) { setRemoteClipboard(false); } }); m.setEnabled(autoChk.isSelected()); // try { pasteImage = ImageIO.read(ClipboardTransferMain.class.getResourceAsStream("/clipboard_paste.png")); grayImage = ImageIO.read(ClipboardTransferMain.class.getResourceAsStream("/clipboard_gray.png")); sendImage = ImageIO.read(ClipboardTransferMain.class.getResourceAsStream("/mail-send.png")); BufferedImage taskImage = ImageIO.read(ClipboardTransferMain.class.getResourceAsStream("/taskbar.png")); setIconImage(taskImage); SystemTray systemTray = SystemTray.getSystemTray(); trayIcon = new TrayIcon(grayImage, "??"); systemTray.add(trayIcon); //// trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) {// ??? if (ClipboardTransferMain.this.isVisible()) { ClipboardTransferMain.this.setState(ICONIFIED); } else { ClipboardTransferMain.this.setVisible(true); ClipboardTransferMain.this.setState(NORMAL); } } } }); ////// event this.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { ClipboardTransferMain.this.setVisible(false); super.windowIconified(e); } @Override public void windowClosing(WindowEvent e) { File pf = new File(System.getProperty("user.home") + "/clip-trans/conf.properties"); pf.getParentFile().mkdirs(); try { Properties op = new Properties(); op.setProperty("server.addr", serverAddrTxt.getText()); op.setProperty("local.port", portTxt.getText()); op.setProperty("allow.modify.local.clip", modifyClipChk.isSelected() + ""); op.setProperty("auto.modify.remote.clip", autoChk.isSelected() + ""); FileOutputStream os = new FileOutputStream(pf); op.store(os, "clip-trans"); os.flush(); os.close(); } catch (Exception e1) { } shutdown(); super.windowClosing(e); } }); } catch (Exception e) { updateMessage(e.getMessage()); } Thread thread = new Thread() { @Override public void run() { while (true) { try { String poll = iconQueue.take(); if ("send".equals(poll)) { trayIcon.setImage(grayImage); } else if ("paste".equals(poll)) { Thread.sleep(20); trayIcon.setImage(grayImage); } } catch (InterruptedException e1) { return; } } } }; thread.setDaemon(true); thread.start(); }
From source file:EditorPaneExample14.java
public static void main(String[] args) { try {// ww w. ja v a 2 s . c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new EditorPaneExample14(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(500, 400); f.setVisible(true); }
From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java
private WindowAdapter getWindowClosingListener() { return new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { /*//from w w w . jav a2 s . com * Run in a separate thread so the window closes, but the * process remains alive until we are finished handling the * windowClosing event. */ SwingUtilities.invokeLater(new Runnable() { public void run() { /* * In case the program was terminated abruptly, try to * stop the service as normal so that the post-execution * tasks are performed. */ if (cipherSolutionController.isServiceThreadActive()) { cipherSolutionController.stopServiceThread(SwingUserInterface.inDebugMode); /* * Keep waiting for the program to finish * post-execution tasks. */ try { while (cipherSolutionController.isServiceThreadActive()) { Thread.sleep(PROGRAM_EXIT_SLEEP_MILLIS); } } catch (InterruptedException e) { log.error( "Caught InterruptedException while waiting for service thread to complete after window close event. Unable to continue.", e); } } } }); } }; }
From source file:com.diversityarrays.dal.server.SqlDialog.java
SqlDialog(JFrame owner, SqlDalDatabase db) { super(owner, "SQL", ModalityType.MODELESS); setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.database = db; runner = new DefaultBackgroundRunner("SQL Command", this); setGlassPane(runner.getBlockingPane()); sqlCommands.setFont(GuiUtil.createMonospacedFont(12)); includeHeadingsInCopy.addItemListener(new ItemListener() { @Override//from www. j a v a 2s .c o m public void itemStateChanged(ItemEvent e) { boolean b = includeHeadingsInCopy.isSelected(); for (int n = tabbedPane.getTabCount(); --n >= 0;) { Component c = tabbedPane.getComponentAt(n); if (c instanceof SqlResultsPanel) { ((SqlResultsPanel) c).setIncludeHeadings(b); } } } }); tabbedPane.addContainerListener(new ContainerListener() { @Override public void componentRemoved(ContainerEvent e) { updateClosePanelAction(); } @Override public void componentAdded(ContainerEvent e) { updateClosePanelAction(); } }); updateClosePanelAction(); Box buttons = Box.createHorizontalBox(); buttons.add(Box.createHorizontalStrut(10)); buttons.add(new JButton(runAction)); buttons.add(Box.createHorizontalStrut(20)); buttons.add(new JButton(closePanelAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(includeHeadingsInCopy); buttons.add(Box.createHorizontalStrut(10)); buttons.add(new JButton(helpAction)); buttons.add(Box.createHorizontalStrut(10)); JPanel top = new JPanel(new BorderLayout()); top.add(BorderLayout.CENTER, new JScrollPane(sqlCommands)); top.add(BorderLayout.SOUTH, buttons); final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, tabbedPane); splitPane.setResizeWeight(0.25); setContentPane(splitPane); pack(); setSize(800, 600); addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { splitPane.setDividerLocation(0.25); removeWindowListener(this); } }); }
From source file:com.mgmtp.jfunk.core.ui.JFunkFrame.java
private void setUpGui() { buildMenuBar();/*from w ww .j a v a 2s . com*/ buildToolBar(); buildPopup(); buildTree(); BufferedImage image = null; try { image = ImageIO.read(getClass().getResource("/jFunk.png")); setIconImage(image); } catch (Exception e) { log.warn("Could not read icon image, standard icon will be used. Exception was: " + e.getMessage()); } setJMenuBar(menuBar); if (!readState()) { setSize(520, 600); setLocationRelativeTo(null); } final JScrollPane scrollPane = new JScrollPane(tree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); final Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(jPanelUtilities, BorderLayout.NORTH); contentPane.add(scrollPane, BorderLayout.CENTER); addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { exit(); } }); }
From source file:EditorPaneExample17.java
public static void main(String[] args) { try {//from w ww. j a va 2s . c o m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new EditorPaneExample17(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(500, 400); f.setVisible(true); }