List of usage examples for javax.swing JFrame setExtendedState
public void setExtendedState(int state)
From source file:app.SimpleLifecycleAdvisor.java
/** * Called when the application has fully started. This is after the initial application window has been made * visible./*from ww w.j av a 2 s . com*/ */ public void onPostStartup() { if (logger.isInfoEnabled()) { logger.info("onPostStartup()"); } JFrame frame = this.getOpeningWindow().getControl(); //System.out.println(this.getOpeningWindow().getControl()); frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH); }
From source file:es.emergya.ui.gis.popups.RouteDialog.java
public void showRouteDialog(LatLon from, LatLon to, CustomMapView view) { JFrame f = getRouteDialog(from, to, view); f.setVisible(true);/*from ww w .j a v a 2 s . com*/ f.setExtendedState(JFrame.NORMAL); f.requestFocus(); }
From source file:tn.mariages.gui.Accueil.java
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened int h = Toolkit.getDefaultToolkit().getScreenSize().height; int w = Toolkit.getDefaultToolkit().getScreenSize().width; Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation(-27, -16); this.setSize(144, h + 16); this.setExtendedState(this.MAXIMIZED_VERT); System.out.println("H " + h); JFrame LogoFrame = new JFrame("Logo"); LogoFrame.setSize(w - 45, h + 16);//from w w w . j a va 2 s . co m LogoFrame.setExtendedState(this.MAXIMIZED_HORIZ); this.setAlwaysOnTop(true); //LogoFrame.setExtendedState(LogoFrame.MAXIMIZED_BOTH); LogoFrame.setLocation(65, -16); JPanel logoPanel = new JPanel(); LogoFrame.add(logoPanel); ImageIcon icon; try { icon = new ImageIcon(new URL("http://www.images.tn/upload/original/1394208853.png")); /// TO CHANGE icon = new ImageIcon(icon.getImage().getScaledInstance(400, 400, BufferedImage.SCALE_SMOOTH)); JLabel logoLabel = new JLabel(icon); logoPanel.add(logoLabel); logoLabel.setAlignmentX(CENTER_ALIGNMENT); logoLabel.setAlignmentY(400); } catch (MalformedURLException ex) { Logger.getLogger(ListeFeatProd.class.getName()).log(Level.SEVERE, null, ex); } LogoFrame.setVisible(true); // TODO add your handling code here: }
From source file:Main.java
void initUI() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); int i = 1;/*from ww w .j a v a 2 s. c o m*/ for (GraphicsDevice gd : ge.getScreenDevices()) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(createLabel(String.valueOf(i))); frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "exit"); frame.getRootPane().getActionMap().put("exit", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); frame.setLocation(gd.getDefaultConfiguration().getBounds().getLocation()); frame.setUndecorated(true); frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH); frame.setVisible(true); gd.setFullScreenWindow(frame); i++; } }
From source file:de.erdesignerng.util.ApplicationPreferences.java
/** * Set the current window state as stored by updateWindowDefinition. * * @param aAlias the alias of the window * @param aFrame the window//from ww w.j av a 2 s . com */ public void setWindowState(String aAlias, JFrame aFrame) { if (windowDefinitions.containsKey(WINDOWSTATEPREFIX + aAlias)) { try { aFrame.setExtendedState(Integer.parseInt(windowDefinitions.get(WINDOWSTATEPREFIX + aAlias))); setWindowLocation(aAlias, aFrame); setWindowSize(aAlias, aFrame); } catch (NumberFormatException e) { aFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); } } }
From source file:au.org.ala.delta.editor.DeltaEditor.java
@Override protected void startup() { _actionMap = getContext().getActionMap(this); JFrame frame = getMainFrame(); frame.setPreferredSize(new Dimension(800, 600)); frame.setIconImages(IconHelper.getBlueIconList()); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); addExitListener(new ExitListener() { @Override/*w ww .j a v a 2s. co m*/ public void willExit(EventObject event) { } @Override public boolean canExit(EventObject event) { boolean canClose = closeAll(); return canClose; } }); _helpController = new HelpController("help/delta_editor/DeltaEditor"); _dataSetRepository = new SlotFileRepository(); _statusBar = new StatusBar(); // Hiding the status bar as it doesn't really convey much useful information and takes up screen space. //getMainView().setStatusBar(_statusBar); getMainView().setMenuBar(buildMenus()); _helpController.enableHelpKey(frame); createDesktop(); show(_desktop); }
From source file:de.bfs.radon.omsimulation.gui.OMPanelData.java
/** * Initialises the interface of the data panel. */// ww w. j a v a2s . c om protected void initialize() { setLayout(null); lblExportChartTo = new JLabel("Export chart to ..."); lblExportChartTo.setBounds(436, 479, 144, 14); lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblExportChartTo.setVisible(false); add(lblExportChartTo); btnCsv = new JButton("CSV"); btnCsv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String csv; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("csv")) { csv = ""; } else { csv = ".csv"; } String csvPath = file.getAbsolutePath() + csv; OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem(); double[] selectedValues = selectedRoom.getValues(); File csvFile = new File(csvPath); try { FileWriter logWriter = new FileWriter(csvFile); BufferedWriter csvOutput = new BufferedWriter(logWriter); csvOutput.write("\"ID\";\"" + selectedRoom.getId() + "\""); csvOutput.newLine(); for (int i = 0; i < selectedValues.length; i++) { csvOutput.write("\"" + i + "\";\"" + (int) selectedValues[i] + "\""); csvOutput.newLine(); } JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success", JOptionPane.INFORMATION_MESSAGE); csvOutput.close(); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnCsv.setBounds(590, 475, 70, 23); btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnCsv.setVisible(false); add(btnCsv); btnPdf = new JButton("PDF"); btnPdf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String pdf; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("pdf")) { pdf = ""; } else { pdf = ".pdf"; } String pdfPath = file.getAbsolutePath() + pdf; OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); String title = building.getName(); OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem(); JFreeChart chart = OMCharts.createRoomChart(title, selectedRoom, false); int height = (int) PageSize.A4.getWidth(); int width = (int) PageSize.A4.getHeight(); try { OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title); JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnPdf.setBounds(670, 475, 70, 23); btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnPdf.setVisible(false); add(btnPdf); lblSelectProject = new JLabel("Select Project"); lblSelectProject.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectProject.setBounds(10, 65, 132, 14); add(lblSelectProject); lblSelectRoom = new JLabel("Select Room"); lblSelectRoom.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectRoom.setBounds(10, 94, 132, 14); add(lblSelectRoom); panelData = new JPanel(); panelData.setBounds(10, 118, 730, 347); add(panelData); btnRefresh = new JButton("Load"); btnRefresh.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("") && !txtOmbFile.getText().equals(" ")) { txtOmbFile.setBackground(Color.WHITE); String ombPath = txtOmbFile.getText(); String omb; String[] tmpFileName = ombPath.split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(ombPath + omb); setOmbFile(ombPath + omb); File ombFile = new File(ombPath + omb); if (ombFile.exists()) { txtOmbFile.setBackground(Color.WHITE); btnRefresh.setEnabled(false); comboBoxProjects.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); btnPdf.setVisible(false); btnCsv.setVisible(false); lblExportChartTo.setVisible(false); progressBar.setVisible(true); progressBar.setStringPainted(true); progressBar.setIndeterminate(true); refreshProjectsTask = new RefreshProjects(); refreshProjectsTask.execute(); } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!", "Error", JOptionPane.ERROR_MESSAGE); } } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning", JOptionPane.WARNING_MESSAGE); } } }); btnRefresh.setBounds(616, 61, 124, 23); add(btnRefresh); btnMaximize = new JButton("Fullscreen"); btnMaximize.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnMaximize.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (comboBoxRooms.isEnabled()) { if (comboBoxRooms.getSelectedItem() != null) { OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); String title = building.getName(); OMRoom room = (OMRoom) comboBoxRooms.getSelectedItem(); panelRoom = createRoomPanel(title, room, false, false); JFrame chartFrame = new JFrame(); JPanel chartPanel = createRoomPanel(title, room, false, true); chartFrame.getContentPane().add(chartPanel); chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight()); chartFrame.setTitle("OM Simulation Tool: " + title + ", Room " + room.getId()); chartFrame.setResizable(true); chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); chartFrame.setVisible(true); } } } }); btnMaximize.setBounds(10, 475, 124, 23); btnMaximize.setVisible(false); add(btnMaximize); comboBoxProjects = new JComboBox<OMBuilding>(); comboBoxProjects.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); comboBoxProjects.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { boolean b = false; Color c = null; if (comboBoxProjects.isEnabled()) { if (comboBoxProjects.getSelectedItem() != null) { b = true; c = Color.WHITE; OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); comboBoxRooms.removeAllItems(); for (int i = 0; i < building.getRooms().length; i++) { comboBoxRooms.addItem(building.getRooms()[i]); } for (int i = 0; i < building.getCellars().length; i++) { comboBoxRooms.addItem(building.getCellars()[i]); } for (int i = 0; i < building.getMiscs().length; i++) { comboBoxRooms.addItem(building.getMiscs()[i]); } } else { b = false; c = null; } } else { b = false; c = null; } lblSelectRoom.setEnabled(b); panelData.setEnabled(b); btnMaximize.setVisible(b); comboBoxRooms.setEnabled(b); panelData.setBackground(c); } }); comboBoxProjects.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { boolean b = false; Color c = null; if (comboBoxProjects.isEnabled()) { if (comboBoxProjects.getSelectedItem() != null) { b = true; c = Color.WHITE; OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); comboBoxRooms.removeAllItems(); for (int i = 0; i < building.getRooms().length; i++) { comboBoxRooms.addItem(building.getRooms()[i]); } for (int i = 0; i < building.getCellars().length; i++) { comboBoxRooms.addItem(building.getCellars()[i]); } for (int i = 0; i < building.getMiscs().length; i++) { comboBoxRooms.addItem(building.getMiscs()[i]); } } else { b = false; c = null; } } else { b = false; c = null; } lblSelectRoom.setEnabled(b); panelData.setEnabled(b); btnMaximize.setVisible(b); comboBoxRooms.setEnabled(b); panelData.setBackground(c); } }); comboBoxProjects.setBounds(152, 61, 454, 22); add(comboBoxProjects); comboBoxRooms = new JComboBox<OMRoom>(); comboBoxRooms.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); comboBoxRooms.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (comboBoxRooms.isEnabled()) { if (comboBoxRooms.getSelectedItem() != null) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); remove(panelData); comboBoxRooms.setEnabled(false); refreshChartsTask = new RefreshCharts(); refreshChartsTask.execute(); } } } }); comboBoxRooms.setBounds(152, 90, 454, 22); add(comboBoxRooms); progressBar = new JProgressBar(); progressBar.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); progressBar.setBounds(10, 475, 730, 23); progressBar.setVisible(false); add(progressBar); lblSelectRoom.setEnabled(false); panelData.setEnabled(false); comboBoxRooms.setEnabled(false); lblHelp = new JLabel( "Select an OMB-Object file to analyse its data. You can inspect radon concentration for each room."); lblHelp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblHelp.setForeground(Color.GRAY); lblHelp.setBounds(10, 10, 730, 14); add(lblHelp); txtOmbFile = new JTextField(); txtOmbFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); txtOmbFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { setOmbFile(txtOmbFile.getText()); } }); txtOmbFile.setBounds(152, 33, 454, 20); add(txtOmbFile); txtOmbFile.setColumns(10); btnBrowse = new JButton("Browse"); btnBrowse.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb")); fileDialog.showOpenDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String omb; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(file.getAbsolutePath() + omb); setOmbFile(file.getAbsolutePath() + omb); } } }); btnBrowse.setBounds(616, 32, 124, 23); add(btnBrowse); lblSelectOmbfile = new JLabel("Select OMB-File"); lblSelectOmbfile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectOmbfile.setBounds(10, 36, 132, 14); add(lblSelectOmbfile); }
From source file:org.sunzoft.sunstock.StockMain.java
protected void initGUI() { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1024, 600);// w ww .jav a2s .c om frame.setLocationRelativeTo(null); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // Container contentPane = frame.getContentPane(); contentPane.setLayout(new BorderLayout(0, 0)); JFreeChart chart = createChart(); // 6:chartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseZoomable(true); contentPane.add(chartPanel, BorderLayout.CENTER); JPanel pCtrl = new JPanel(); if (profits.size() > 0) { startInput.setText(profits.get(0).date); endInput.setText(profits.get(profits.size() - 1).date); } else { startInput.setText("20100101"); endInput.setText("20100101"); } pCtrl.add(new JLabel("")); pCtrl.add(startInput); pCtrl.add(new JLabel("")); pCtrl.add(endInput); JButton confirm = new JButton(""); confirm.addActionListener(StockMain.this); pCtrl.add(confirm); contentPane.add(pCtrl, BorderLayout.NORTH); JPanel pStatus = new JPanel(); statusLabel = new JLabel(getStatusText()); pStatus.add(statusLabel); contentPane.add(pStatus, BorderLayout.SOUTH); frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH); frame.setVisible(true); //dataSource.close(); } }); }
From source file:de.bfs.radon.omsimulation.gui.OMPanelTesting.java
/** * Initialises the interface of the results panel. *//*from w w w . ja v a 2 s. co m*/ protected void initialize() { setLayout(null); isSimulated = false; lblExportChartTo = new JLabel("Export chart to ..."); lblExportChartTo.setBounds(436, 479, 144, 14); lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblExportChartTo.setVisible(false); add(lblExportChartTo); btnCsv = new JButton("CSV"); btnCsv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String csv; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("csv")) { csv = ""; } else { csv = ".csv"; } String csvPath = file.getAbsolutePath() + csv; double[] selectedValues; OMRoom[] rooms = new OMRoom[7]; rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem(); rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem(); rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem(); rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem(); rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem(); rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem(); rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem(); int start = sliderStartTime.getValue(); final int day = 24; File csvFile = new File(csvPath); try { OMCampaign campaign; if (isResult) { campaign = getResultCampaign(); } else { campaign = new OMCampaign(start, rooms, 0); } FileWriter logWriter = new FileWriter(csvFile); BufferedWriter csvOutput = new BufferedWriter(logWriter); csvOutput.write("\"ID\";\"Room\";\"Radon\""); csvOutput.newLine(); selectedValues = campaign.getValueChain(); int x = 0; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[0].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[1].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[2].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[3].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[4].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[5].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[6].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success", JOptionPane.INFORMATION_MESSAGE); csvOutput.close(); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnCsv.setBounds(590, 475, 70, 23); btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnCsv.setVisible(false); add(btnCsv); btnPdf = new JButton("PDF"); btnPdf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String pdf; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("pdf")) { pdf = ""; } else { pdf = ".pdf"; } String pdfPath = file.getAbsolutePath() + pdf; OMRoom[] rooms = new OMRoom[7]; rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem(); rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem(); rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem(); rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem(); rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem(); rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem(); rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem(); int start = sliderStartTime.getValue(); OMCampaign campaign; try { if (isResult) { campaign = getResultCampaign(); } else { campaign = new OMCampaign(start, rooms, 0); } JFreeChart chart = OMCharts.createCampaignChart(campaign, false); String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId() + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId() + ", Start: " + start; int height = (int) PageSize.A4.getWidth(); int width = (int) PageSize.A4.getHeight(); try { OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title); JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to create chart!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnPdf.setBounds(670, 475, 70, 23); btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnPdf.setVisible(false); add(btnPdf); lblSelectProject = new JLabel("Select Project"); lblSelectProject.setBounds(10, 65, 132, 14); lblSelectProject.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(lblSelectProject); lblSelectRooms = new JLabel("Select Rooms"); lblSelectRooms.setBounds(10, 94, 132, 14); lblSelectRooms.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(lblSelectRooms); lblStartTime = new JLabel("Start Time"); lblStartTime.setBounds(10, 123, 132, 14); lblStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(lblStartTime); lblWarning = new JLabel("Select 6 rooms and 1 cellar!"); lblWarning.setForeground(Color.RED); lblWarning.setBounds(565, 123, 175, 14); lblWarning.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblWarning.setVisible(false); add(lblWarning); sliderStartTime = new JSlider(); sliderStartTime.setMaximum(0); sliderStartTime.setBounds(152, 119, 285, 24); sliderStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(sliderStartTime); spnrStartTime = new JSpinner(); spnrStartTime.setModel(new SpinnerNumberModel(0, 0, 0, 1)); spnrStartTime.setBounds(447, 120, 108, 22); spnrStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(spnrStartTime); btnRefresh = new JButton("Load"); btnRefresh.setBounds(616, 61, 124, 23); btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(btnRefresh); btnMaximize = new JButton("Fullscreen"); btnMaximize.setBounds(10, 475, 124, 23); btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(btnMaximize); panelCampaign = new JPanel(); panelCampaign.setBounds(10, 150, 730, 315); panelCampaign.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(panelCampaign); progressBar = new JProgressBar(); progressBar.setBounds(10, 475, 730, 23); progressBar.setFont(new Font("SansSerif", Font.PLAIN, 11)); progressBar.setVisible(false); add(progressBar); lblOpenOmbfile = new JLabel("Open OMB-File"); lblOpenOmbfile.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblOpenOmbfile.setBounds(10, 36, 132, 14); add(lblOpenOmbfile); lblHelp = new JLabel("Select an OMB-Object file to manually simulate virtual campaigns."); lblHelp.setForeground(Color.GRAY); lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblHelp.setBounds(10, 10, 730, 14); add(lblHelp); txtOmbFile = new JTextField(); txtOmbFile.setFont(new Font("SansSerif", Font.PLAIN, 11)); txtOmbFile.setColumns(10); txtOmbFile.setBounds(152, 33, 454, 20); add(txtOmbFile); btnBrowse = new JButton("Browse"); btnBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11)); btnBrowse.setBounds(616, 32, 124, 23); add(btnBrowse); comboBoxRoom1 = new JComboBox<OMRoom>(); comboBoxRoom1.setBounds(152, 90, 75, 22); comboBoxRoom1.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom1); comboBoxRoom2 = new JComboBox<OMRoom>(); comboBoxRoom2.setBounds(237, 90, 75, 22); comboBoxRoom2.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom2); comboBoxRoom3 = new JComboBox<OMRoom>(); comboBoxRoom3.setBounds(323, 90, 75, 22); comboBoxRoom3.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom3); comboBoxRoom4 = new JComboBox<OMRoom>(); comboBoxRoom4.setBounds(408, 90, 75, 22); comboBoxRoom4.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom4); comboBoxRoom5 = new JComboBox<OMRoom>(); comboBoxRoom5.setBounds(494, 90, 75, 22); comboBoxRoom5.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom5); comboBoxRoom6 = new JComboBox<OMRoom>(); comboBoxRoom6.setBounds(579, 90, 75, 22); comboBoxRoom6.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom6); comboBoxRoom7 = new JComboBox<OMRoom>(); comboBoxRoom7.setBounds(665, 90, 75, 22); comboBoxRoom7.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom7); comboBoxProjects = new JComboBox<OMBuilding>(); comboBoxProjects.setBounds(152, 61, 454, 22); comboBoxProjects.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxProjects); comboBoxRoom1.addActionListener(this); comboBoxRoom1.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom2.addActionListener(this); comboBoxRoom2.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom3.addActionListener(this); comboBoxRoom3.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom4.addActionListener(this); comboBoxRoom4.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom5.addActionListener(this); comboBoxRoom5.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom6.addActionListener(this); comboBoxRoom6.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom7.addActionListener(this); comboBoxRoom7.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); sliderStartTime.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (comboBoxProjects.isEnabled() || isResult) { if (comboBoxProjects.getSelectedItem() != null) { spnrStartTime.setValue((int) sliderStartTime.getValue()); updateChart(); } } } }); spnrStartTime.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (comboBoxProjects.isEnabled() || isResult) { if (comboBoxProjects.getSelectedItem() != null) { sliderStartTime.setValue((Integer) spnrStartTime.getValue()); updateChart(); } } } }); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("") && !txtOmbFile.getText().equals(" ")) { txtOmbFile.setBackground(Color.WHITE); String ombPath = txtOmbFile.getText(); String omb; String[] tmpFileName = ombPath.split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(ombPath + omb); setOmbFile(ombPath + omb); File ombFile = new File(ombPath + omb); if (ombFile.exists()) { txtOmbFile.setBackground(Color.WHITE); btnRefresh.setEnabled(false); comboBoxProjects.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); progressBar.setVisible(true); btnPdf.setVisible(false); btnCsv.setVisible(false); btnMaximize.setVisible(false); lblExportChartTo.setVisible(false); progressBar.setIndeterminate(true); progressBar.setStringPainted(true); refreshTask = new Refresh(); refreshTask.execute(); } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!", "Error", JOptionPane.ERROR_MESSAGE); } } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning", JOptionPane.WARNING_MESSAGE); } } }); btnMaximize.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { OMRoom[] rooms = new OMRoom[7]; rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem(); rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem(); rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem(); rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem(); rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem(); rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem(); rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem(); int start = sliderStartTime.getValue(); String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId() + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId() + ", Start: " + start; OMCampaign campaign; if (isResult) { campaign = getResultCampaign(); } else { campaign = new OMCampaign(start, rooms, 0); } JPanel campaignChart = createCampaignPanel(campaign, false, true); JFrame chartFrame = new JFrame(); chartFrame.getContentPane().add(campaignChart); chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight()); chartFrame.setTitle(title); chartFrame.setResizable(true); chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); chartFrame.setVisible(true); } catch (IOException ioe) { ioe.printStackTrace(); } } }); txtOmbFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { setOmbFile(txtOmbFile.getText()); } }); btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb")); fileDialog.showOpenDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String omb; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(file.getAbsolutePath() + omb); setOmbFile(file.getAbsolutePath() + omb); } } }); }
From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java
/** * System Tray Icon setup/*w ww .j a va2s . c om*/ * @param frame owner JFrame */ private void setupTrayIcon(final JFrame frame) { // Idle Icon idleIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_inactive.png")); // Active Icon activeIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_active.png")); frame.setIconImage(idleIcon); // If system tray is supported by OS if (SystemTray.isSupported()) { // Set Icon trayIcon = new TrayIcon(idleIcon, "Nebula Grid Cluster", createTrayPopup()); trayIcon.setImageAutoSize(true); trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (!frame.isVisible()) { frame.setVisible(true); } frame.setExtendedState(JFrame.NORMAL); frame.requestFocus(); frame.toFront(); } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException ae) { log.debug("[UI] Unable to Initialize Tray Icon"); return; } frame.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { // Hide (can be shown using tray icon) frame.setVisible(false); } }); } }