Example usage for javax.swing JFrame setExtendedState

List of usage examples for javax.swing JFrame setExtendedState

Introduction

In this page you can find the example usage for javax.swing JFrame setExtendedState.

Prototype

public void setExtendedState(int state) 

Source Link

Document

Sets the state of this frame.

Usage

From source file:edu.ku.brc.specify.Specify.java

/**
 * Bring up the PPApp demo by showing the frame (only applicable if coming up
 * as an application, not an applet);/*from w  w  w .  j a  va2s.com*/
 */
public void showApp() {
    JFrame f = getFrame();
    f.setTitle(getTitle());
    f.getContentPane().add(this, BorderLayout.CENTER);
    f.pack();

    f.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            doExit(true);
        }
    });

    UIHelper.centerWindow(f);
    Rectangle r = f.getBounds();
    int x = AppPreferences.getLocalPrefs().getInt("APP.X", r.x);
    int y = AppPreferences.getLocalPrefs().getInt("APP.Y", r.y);
    int w = AppPreferences.getLocalPrefs().getInt("APP.W", r.width);
    int h = AppPreferences.getLocalPrefs().getInt("APP.H", r.height);
    boolean isMacAndMaxed = UIHelper.isMacOS()
            && AppPreferences.getLocalPrefs().getBoolean("APP.MAXIMIZED", true);
    if (isMacAndMaxed) {
        f.setExtendedState(Frame.MAXIMIZED_BOTH);
    } else {
        UIHelper.positionAndFitToScreen(f, x, y, w, h);
    }
    f.setVisible(true);
}

From source file:au.org.ala.delta.intkey.Intkey.java

/**
 * Creates and shows the GUI. Called by the swing application framework
 *//*w w  w.  j a va 2s . c  om*/
@Override
protected void startup() {
    final JFrame mainFrame = getMainFrame();
    _defaultGlassPane = mainFrame.getGlassPane();
    mainFrame.setTitle("Intkey");
    mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    mainFrame.setIconImages(IconHelper.getRedIconList());

    _helpController = new HelpController(HELPSET_PATH);

    _taxonformatter = new ItemFormatter(false, CommentStrippingMode.STRIP_ALL, AngleBracketHandlingMode.REMOVE,
            true, false, true);
    _context = new IntkeyContext(new IntkeyUIInterceptor(this), new DirectivePopulatorInterceptor(this));

    _advancedModeOnlyDynamicButtons = new ArrayList<JButton>();
    _normalModeOnlyDynamicButtons = new ArrayList<JButton>();
    _activeOnlyWhenCharactersUsedButtons = new ArrayList<JButton>();
    _dynamicButtonsFullHelp = new HashMap<JButton, String>();

    ActionMap actionMap = getContext().getActionMap();

    _rootPanel = new JPanel();
    _rootPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    _rootPanel.setBackground(SystemColor.control);
    _rootPanel.setLayout(new BorderLayout(0, 0));

    _globalOptionBar = new JPanel();
    _globalOptionBar.setBorder(new EmptyBorder(0, 5, 0, 5));
    _rootPanel.add(_globalOptionBar, BorderLayout.NORTH);
    _globalOptionBar.setLayout(new BorderLayout(0, 0));

    _pnlDynamicButtons = new JPanel();
    FlowLayout flowLayout_1 = (FlowLayout) _pnlDynamicButtons.getLayout();
    flowLayout_1.setVgap(0);
    flowLayout_1.setHgap(0);
    _globalOptionBar.add(_pnlDynamicButtons, BorderLayout.WEST);

    _btnContextHelp = new JButton();
    _btnContextHelp.setMinimumSize(new Dimension(30, 30));
    _btnContextHelp.setMaximumSize(new Dimension(30, 30));
    _btnContextHelp.setAction(actionMap.get("btnContextHelp"));
    _btnContextHelp.setPreferredSize(new Dimension(30, 30));
    _btnContextHelp.setMargin(new Insets(2, 5, 2, 5));
    _btnContextHelp.addActionListener(actionMap.get("btnContextHelp"));
    _globalOptionBar.add(_btnContextHelp, BorderLayout.EAST);

    _rootSplitPane = new JSplitPane();
    _rootSplitPane.setDividerSize(3);
    _rootSplitPane.setResizeWeight(0.5);
    _rootSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    _rootSplitPane.setContinuousLayout(true);
    _rootPanel.add(_rootSplitPane);

    _innerSplitPaneLeft = new JSplitPane();
    _innerSplitPaneLeft.setMinimumSize(new Dimension(25, 25));
    _innerSplitPaneLeft.setAlignmentX(Component.CENTER_ALIGNMENT);
    _innerSplitPaneLeft.setDividerSize(3);
    _innerSplitPaneLeft.setResizeWeight(0.5);

    _innerSplitPaneLeft.setContinuousLayout(true);
    _innerSplitPaneLeft.setOrientation(JSplitPane.VERTICAL_SPLIT);
    _rootSplitPane.setLeftComponent(_innerSplitPaneLeft);

    _pnlAvailableCharacters = new JPanel();
    _innerSplitPaneLeft.setLeftComponent(_pnlAvailableCharacters);
    _pnlAvailableCharacters.setLayout(new BorderLayout(0, 0));

    _sclPaneAvailableCharacters = new JScrollPane();
    _pnlAvailableCharacters.add(_sclPaneAvailableCharacters, BorderLayout.CENTER);

    _listAvailableCharacters = new JList();
    // _listAvailableCharacters.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _listAvailableCharacters.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    _listAvailableCharacters.setCellRenderer(_availableCharactersListCellRenderer);
    _listAvailableCharacters.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                int selectedIndex = _listAvailableCharacters.getSelectedIndex();
                if (selectedIndex >= 0) {
                    try {
                        Character ch = (Character) _availableCharacterListModel.getElementAt(selectedIndex);
                        executeDirective(new UseDirective(), Integer.toString(ch.getCharacterId()));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    });

    _sclPaneAvailableCharacters.setViewportView(_listAvailableCharacters);

    _pnlAvailableCharactersHeader = new JPanel();
    _pnlAvailableCharacters.add(_pnlAvailableCharactersHeader, BorderLayout.NORTH);
    _pnlAvailableCharactersHeader.setLayout(new BorderLayout(0, 0));

    _lblNumAvailableCharacters = new JLabel();
    _lblNumAvailableCharacters.setBorder(new EmptyBorder(0, 5, 0, 0));
    _lblNumAvailableCharacters.setFont(new Font("Tahoma", Font.PLAIN, 15));
    _lblNumAvailableCharacters.setText(MessageFormat.format(availableCharactersCaption, 0));
    _pnlAvailableCharactersHeader.add(_lblNumAvailableCharacters, BorderLayout.WEST);

    _pnlAvailableCharactersButtons = new JPanel();
    FlowLayout flowLayout = (FlowLayout) _pnlAvailableCharactersButtons.getLayout();
    flowLayout.setVgap(2);
    flowLayout.setHgap(2);
    _pnlAvailableCharactersHeader.add(_pnlAvailableCharactersButtons, BorderLayout.EAST);

    // All toolbar buttons should be disabled until a dataset is loaded.
    _btnRestart = new JButton();
    _btnRestart.setAction(actionMap.get("btnRestart"));
    _btnRestart.setPreferredSize(new Dimension(30, 30));
    _btnRestart.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnRestart);

    _btnBestOrder = new JButton();
    _btnBestOrder.setAction(actionMap.get("btnBestOrder"));
    _btnBestOrder.setPreferredSize(new Dimension(30, 30));
    _btnBestOrder.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnBestOrder);

    _btnSeparate = new JButton();
    _btnSeparate.setAction(actionMap.get("btnSeparate"));
    _btnSeparate.setVisible(_advancedMode);
    _btnSeparate.setPreferredSize(new Dimension(30, 30));
    _btnSeparate.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnSeparate);

    _btnNaturalOrder = new JButton();
    _btnNaturalOrder.setAction(actionMap.get("btnNaturalOrder"));
    _btnNaturalOrder.setPreferredSize(new Dimension(30, 30));
    _btnNaturalOrder.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnNaturalOrder);

    _btnDiffSpecimenTaxa = new JButton();
    _btnDiffSpecimenTaxa.setAction(actionMap.get("btnDiffSpecimenTaxa"));
    _btnDiffSpecimenTaxa.setEnabled(false);
    _btnDiffSpecimenTaxa.setPreferredSize(new Dimension(30, 30));
    _pnlAvailableCharactersButtons.add(_btnDiffSpecimenTaxa);

    _btnSetTolerance = new JButton();
    _btnSetTolerance.setAction(actionMap.get("btnSetTolerance"));
    _btnSetTolerance.setPreferredSize(new Dimension(30, 30));
    _btnSetTolerance.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnSetTolerance);

    _btnSetMatch = new JButton();
    _btnSetMatch.setAction(actionMap.get("btnSetMatch"));
    _btnSetMatch.setVisible(_advancedMode);
    _btnSetMatch.setPreferredSize(new Dimension(30, 30));
    _btnSetMatch.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnSetMatch);

    _btnSubsetCharacters = new JButton();
    _btnSubsetCharacters.setAction(actionMap.get("btnSubsetCharacters"));
    _btnSubsetCharacters.setPreferredSize(new Dimension(30, 30));
    _btnSubsetCharacters.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnSubsetCharacters);

    _btnFindCharacter = new JButton();
    _btnFindCharacter.setAction(actionMap.get("btnFindCharacter"));
    _btnFindCharacter.setPreferredSize(new Dimension(30, 30));
    _btnFindCharacter.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnFindCharacter);

    _pnlAvailableCharactersButtons.setEnabled(false);

    _pnlUsedCharacters = new JPanel();
    _innerSplitPaneLeft.setRightComponent(_pnlUsedCharacters);
    _pnlUsedCharacters.setLayout(new BorderLayout(0, 0));

    _sclPnUsedCharacters = new JScrollPane();
    _pnlUsedCharacters.add(_sclPnUsedCharacters, BorderLayout.CENTER);

    _listUsedCharacters = new JList();
    _listUsedCharacters.setCellRenderer(_usedCharactersListCellRenderer);
    _listUsedCharacters.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _listUsedCharacters.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                int selectedIndex = _listUsedCharacters.getSelectedIndex();
                if (selectedIndex >= 0) {
                    try {
                        Attribute attr = (Attribute) _usedCharacterListModel.getElementAt(selectedIndex);

                        if (_context.charactersFixed() && _context.getFixedCharactersList()
                                .contains(attr.getCharacter().getCharacterId())) {
                            return;
                        }

                        executeDirective(new ChangeDirective(),
                                Integer.toString(attr.getCharacter().getCharacterId()));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    });

    _sclPnUsedCharacters.setViewportView(_listUsedCharacters);

    _pnlUsedCharactersHeader = new JPanel();
    _pnlUsedCharacters.add(_pnlUsedCharactersHeader, BorderLayout.NORTH);
    _pnlUsedCharactersHeader.setLayout(new BorderLayout(0, 0));

    _lblNumUsedCharacters = new JLabel();
    _lblNumUsedCharacters.setBorder(new EmptyBorder(7, 5, 7, 0));
    _lblNumUsedCharacters.setFont(new Font("Tahoma", Font.PLAIN, 15));
    _lblNumUsedCharacters.setText(MessageFormat.format(usedCharactersCaption, 0));
    _pnlUsedCharactersHeader.add(_lblNumUsedCharacters, BorderLayout.WEST);

    _innerSplitPaneRight = new JSplitPane();
    _innerSplitPaneRight.setMinimumSize(new Dimension(25, 25));
    _innerSplitPaneRight.setDividerSize(3);
    _innerSplitPaneRight.setResizeWeight(0.5);
    _innerSplitPaneRight.setContinuousLayout(true);
    _innerSplitPaneRight.setOrientation(JSplitPane.VERTICAL_SPLIT);
    _rootSplitPane.setRightComponent(_innerSplitPaneRight);

    _pnlRemainingTaxa = new JPanel();
    _innerSplitPaneRight.setLeftComponent(_pnlRemainingTaxa);
    _pnlRemainingTaxa.setLayout(new BorderLayout(0, 0));

    _sclPnRemainingTaxa = new JScrollPane();
    _pnlRemainingTaxa.add(_sclPnRemainingTaxa, BorderLayout.CENTER);

    _listRemainingTaxa = new JList();

    _listRemainingTaxa.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                displayInfoForSelectedTaxa();
            }
        }
    });

    _sclPnRemainingTaxa.setViewportView(_listRemainingTaxa);

    _pnlRemainingTaxaHeader = new JPanel();
    _pnlRemainingTaxa.add(_pnlRemainingTaxaHeader, BorderLayout.NORTH);
    _pnlRemainingTaxaHeader.setLayout(new BorderLayout(0, 0));

    _lblNumRemainingTaxa = new JLabel();
    _lblNumRemainingTaxa.setBorder(new EmptyBorder(0, 5, 0, 0));
    _lblNumRemainingTaxa.setFont(new Font("Tahoma", Font.PLAIN, 15));
    _lblNumRemainingTaxa.setText(MessageFormat.format(remainingTaxaCaption, 0));
    _pnlRemainingTaxaHeader.add(_lblNumRemainingTaxa, BorderLayout.WEST);

    _pnlRemainingTaxaButtons = new JPanel();
    FlowLayout fl_pnlRemainingTaxaButtons = (FlowLayout) _pnlRemainingTaxaButtons.getLayout();
    fl_pnlRemainingTaxaButtons.setVgap(2);
    fl_pnlRemainingTaxaButtons.setHgap(2);
    _pnlRemainingTaxaHeader.add(_pnlRemainingTaxaButtons, BorderLayout.EAST);

    // All toolbar buttons should be disabled until a dataset is loaded.
    _btnTaxonInfo = new JButton();
    _btnTaxonInfo.setAction(actionMap.get("btnTaxonInfo"));
    _btnTaxonInfo.setPreferredSize(new Dimension(30, 30));
    _btnTaxonInfo.setEnabled(false);
    _pnlRemainingTaxaButtons.add(_btnTaxonInfo);

    _btnDiffTaxa = new JButton();
    _btnDiffTaxa.setAction(actionMap.get("btnDiffTaxa"));
    _btnDiffTaxa.setPreferredSize(new Dimension(30, 30));
    _btnDiffTaxa.setEnabled(false);
    _pnlRemainingTaxaButtons.add(_btnDiffTaxa);

    _btnSubsetTaxa = new JButton();
    _btnSubsetTaxa.setAction(actionMap.get("btnSubsetTaxa"));
    _btnSubsetTaxa.setPreferredSize(new Dimension(30, 30));
    _btnSubsetTaxa.setEnabled(false);
    _pnlRemainingTaxaButtons.add(_btnSubsetTaxa);

    _btnFindTaxon = new JButton();
    _btnFindTaxon.setAction(actionMap.get("btnFindTaxon"));
    _btnFindTaxon.setPreferredSize(new Dimension(30, 30));
    _btnFindTaxon.setEnabled(false);
    _pnlRemainingTaxaButtons.add(_btnFindTaxon);

    _pnlEliminatedTaxa = new JPanel();
    _innerSplitPaneRight.setRightComponent(_pnlEliminatedTaxa);
    _pnlEliminatedTaxa.setLayout(new BorderLayout(0, 0));

    _sclPnEliminatedTaxa = new JScrollPane();
    _pnlEliminatedTaxa.add(_sclPnEliminatedTaxa, BorderLayout.CENTER);

    _listEliminatedTaxa = new JList();

    _listEliminatedTaxa.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                displayInfoForSelectedTaxa();
            }
        }
    });

    _sclPnEliminatedTaxa.setViewportView(_listEliminatedTaxa);

    _pnlEliminatedTaxaHeader = new JPanel();
    _pnlEliminatedTaxa.add(_pnlEliminatedTaxaHeader, BorderLayout.NORTH);
    _pnlEliminatedTaxaHeader.setLayout(new BorderLayout(0, 0));

    _lblEliminatedTaxa = new JLabel();
    _lblEliminatedTaxa.setBorder(new EmptyBorder(7, 5, 7, 0));
    _lblEliminatedTaxa.setFont(new Font("Tahoma", Font.PLAIN, 15));
    _lblEliminatedTaxa.setText(MessageFormat.format(eliminatedTaxaCaption, 0));
    _pnlEliminatedTaxaHeader.add(_lblEliminatedTaxa, BorderLayout.WEST);

    JMenuBar menuBar = buildMenus(_advancedMode);
    getMainView().setMenuBar(menuBar);

    _txtFldCmdBar = new JTextField();
    _txtFldCmdBar.setCaretColor(Color.WHITE);
    _txtFldCmdBar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            String cmdStr = _txtFldCmdBar.getText();

            cmdStr = cmdStr.trim();
            if (_cmdMenus.containsKey(cmdStr)) {
                JMenu cmdMenu = _cmdMenus.get(cmdStr);
                cmdMenu.doClick();
            } else {
                _context.parseAndExecuteDirective(cmdStr);
            }
            _txtFldCmdBar.setText(null);
        }
    });

    _txtFldCmdBar.setFont(new Font("Courier New", Font.BOLD, 13));
    _txtFldCmdBar.setForeground(SystemColor.text);
    _txtFldCmdBar.setBackground(Color.BLACK);
    _txtFldCmdBar.setOpaque(true);
    _txtFldCmdBar.setVisible(_advancedMode);
    _rootPanel.add(_txtFldCmdBar, BorderLayout.SOUTH);
    _txtFldCmdBar.setColumns(10);

    _logDialog = new RtfReportDisplayDialog(getMainFrame(), new SimpleRtfEditorKit(null), null, logDialogTitle);

    // Set context-sensitive help keys for toolbar buttons
    _helpController.setHelpKeyForComponent(_btnRestart, HELP_ID_CHARACTERS_TOOLBAR_RESTART);
    _helpController.setHelpKeyForComponent(_btnBestOrder, HELP_ID_CHARACTERS_TOOLBAR_BEST);
    _helpController.setHelpKeyForComponent(_btnSeparate, HELP_ID_CHARACTERS_TOOLBAR_SEPARATE);
    _helpController.setHelpKeyForComponent(_btnNaturalOrder, HELP_ID_CHARACTERS_TOOLBAR_NATURAL);
    _helpController.setHelpKeyForComponent(_btnDiffSpecimenTaxa,
            HELP_ID_CHARACTERS_TOOLBAR_DIFF_SPECIMEN_REMAINING);
    _helpController.setHelpKeyForComponent(_btnSetTolerance, HELP_ID_CHARACTERS_TOOLBAR_TOLERANCE);
    _helpController.setHelpKeyForComponent(_btnSetMatch, HELP_ID_CHARACTERS_TOOLBAR_SET_MATCH);
    _helpController.setHelpKeyForComponent(_btnSubsetCharacters, HELP_ID_CHARACTERS_TOOLBAR_SUBSET_CHARACTERS);
    _helpController.setHelpKeyForComponent(_btnFindCharacter, HELP_ID_CHARACTERS_TOOLBAR_FIND_CHARACTERS);

    _helpController.setHelpKeyForComponent(_btnTaxonInfo, HELP_ID_TAXA_TOOLBAR_INFO);
    _helpController.setHelpKeyForComponent(_btnDiffTaxa, HELP_ID_TAXA_TOOLBAR_DIFF_TAXA);
    _helpController.setHelpKeyForComponent(_btnSubsetTaxa, HELP_ID_TAXA_TOOLBAR_SUBSET_TAXA);
    _helpController.setHelpKeyForComponent(_btnFindTaxon, HELP_ID_TAXA_TOOLBAR_FIND_TAXA);

    // This mouse listener on the default glasspane is to assist with
    // context senstive help. It intercepts the mouse events,
    // determines what component was being clicked on, then takes the
    // appropriate action to provide help for the component
    _defaultGlassPane.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            // Determine what point has been clicked on
            Point glassPanePoint = e.getPoint();
            Point containerPoint = SwingUtilities.convertPoint(getMainFrame().getGlassPane(), glassPanePoint,
                    getMainFrame().getContentPane());
            Component component = SwingUtilities.getDeepestComponentAt(getMainFrame().getContentPane(),
                    containerPoint.x, containerPoint.y);

            // Get the java help ID for this component. If none has been
            // defined, this will be null
            String helpID = _helpController.getHelpKeyForComponent(component);

            // change the cursor back to the normal one and take down the
            // classpane
            mainFrame.setCursor(Cursor.getDefaultCursor());
            mainFrame.getGlassPane().setVisible(false);

            // If a help ID was found, display the related help page in the
            // help viewer
            if (_helpController.getHelpKeyForComponent(component) != null) {
                _helpController.helpAction().actionPerformed(new ActionEvent(component, 0, null));
                _helpController.displayHelpTopic(mainFrame, helpID);
            } else {
                // If a dynamically-defined toolbar button was clicked, show
                // the help for this button in the ToolbarHelpDialog.
                if (component instanceof JButton) {
                    JButton button = (JButton) component;
                    if (_dynamicButtonsFullHelp.containsKey(button)) {
                        String fullHelpText = _dynamicButtonsFullHelp.get(button);
                        if (fullHelpText == null) {
                            fullHelpText = noHelpAvailableCaption;
                        }
                        RTFBuilder builder = new RTFBuilder();
                        builder.startDocument();
                        builder.appendText(fullHelpText);
                        builder.endDocument();
                        ToolbarHelpDialog dlg = new ToolbarHelpDialog(mainFrame, builder.toString(),
                                button.getIcon());
                        show(dlg);
                    }
                }
            }
        }
    });

    show(_rootPanel);
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelResults.java

/**
 * Initialises the interface of the results panel.
 *///from w w w.  ja  va 2  s .  c  o  m
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);

    btnMaximize = new JButton("Fullscreen");
    btnMaximize.setBounds(10, 475, 124, 23);
    btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnMaximize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    JFrame chartFrame = new JFrame();
                    OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                    String title = simulation.toString();
                    DescriptiveStatistics statistics = null;
                    OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    OMRoomType roomType = null;
                    switch (statisticsType) {
                    case RoomArithmeticMeans:
                        title = "R_AM, " + title;
                        statistics = simulation.getRoomAmDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomGeometricMeans:
                        title = "R_GM, " + title;
                        statistics = simulation.getRoomGmDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomMedianQ50:
                        title = "R_MED, " + title;
                        statistics = simulation.getRoomMedDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomMaxima:
                        title = "R_MAX, " + title;
                        statistics = simulation.getRoomMaxDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case CellarArithmeticMeans:
                        title = "C_AM, " + title;
                        statistics = simulation.getCellarAmDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarGeometricMeans:
                        title = "C_GM, " + title;
                        statistics = simulation.getCellarGmDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarMedianQ50:
                        title = "C_MED, " + title;
                        statistics = simulation.getCellarMedDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarMaxima:
                        title = "C_MAX, " + title;
                        statistics = simulation.getCellarMaxDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    default:
                        title = "R_AM, " + title;
                        statistics = simulation.getRoomAmDescriptiveStats();
                        roomType = OMRoomType.Misc;
                        break;
                    }
                    JPanel chartPanel = createDistributionPanel(title, statistics, roomType, false, true, 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);
                    chartFrame.setResizable(true);
                    chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                    chartFrame.setVisible(true);
                }
            }
        }
    });
    add(btnMaximize);

    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;
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                OMCampaign[] campaigns = simulation.getCampaigns();
                File csvFile = new File(csvPath);
                try {
                    FileWriter logWriter = new FileWriter(csvFile);
                    BufferedWriter csvOutput = new BufferedWriter(logWriter);
                    OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    String head = "";
                    switch (statisticsType) {
                    case RoomArithmeticMeans:
                        head = "R_AM";
                        break;
                    case RoomGeometricMeans:
                        head = "R_GM";
                        break;
                    case RoomMedianQ50:
                        head = "R_MED";
                        break;
                    case RoomMaxima:
                        head = "R_MAX";
                        break;
                    case CellarArithmeticMeans:
                        head = "C_AM";
                        break;
                    case CellarGeometricMeans:
                        head = "C_GM";
                        break;
                    case CellarMedianQ50:
                        head = "C_MED";
                        break;
                    case CellarMaxima:
                        head = "C_MAX";
                        break;
                    default:
                        head = "R_AM";
                        break;
                    }
                    csvOutput.write("\"ID\";\"CAMPAIGN\";\"START\";\"" + head + "\"");
                    csvOutput.newLine();
                    int value = 0;
                    for (int i = 0; i < campaigns.length; i++) {
                        switch (statisticsType) {
                        case RoomArithmeticMeans:
                            value = (int) campaigns[i].getRoomAverage();
                            break;
                        case RoomGeometricMeans:
                            value = (int) campaigns[i].getRoomLogAverage();
                            break;
                        case RoomMedianQ50:
                            value = (int) campaigns[i].getRoomMedian();
                            break;
                        case RoomMaxima:
                            value = (int) campaigns[i].getRoomMaximum();
                            break;
                        case CellarArithmeticMeans:
                            value = (int) campaigns[i].getCellarAverage();
                            break;
                        case CellarGeometricMeans:
                            value = (int) campaigns[i].getCellarLogAverage();
                            break;
                        case CellarMedianQ50:
                            value = (int) campaigns[i].getCellarMedian();
                            break;
                        case CellarMaxima:
                            value = (int) campaigns[i].getCellarMaximum();
                            break;
                        default:
                            value = (int) campaigns[i].getRoomAverage();
                            break;
                        }
                        csvOutput.write("\"" + i + "\";\"" + campaigns[i].getVariation() + "\";\""
                                + campaigns[i].getStart() + "\";\"" + value + "\"");
                        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;
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                String title = simulation.toString();
                DescriptiveStatistics statistics = null;
                OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                OMRoomType roomType = null;
                switch (statisticsType) {
                case RoomArithmeticMeans:
                    title = "R_AM, " + title;
                    statistics = simulation.getRoomAmDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomGeometricMeans:
                    title = "R_GM, " + title;
                    statistics = simulation.getRoomGmDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomMedianQ50:
                    title = "R_MED, " + title;
                    statistics = simulation.getRoomMedDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomMaxima:
                    title = "R_MAX, " + title;
                    statistics = simulation.getRoomMaxDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case CellarArithmeticMeans:
                    title = "C_AM, " + title;
                    statistics = simulation.getCellarAmDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarGeometricMeans:
                    title = "C_GM, " + title;
                    statistics = simulation.getCellarGmDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarMedianQ50:
                    title = "C_MED, " + title;
                    statistics = simulation.getCellarMedDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarMaxima:
                    title = "C_MAX, " + title;
                    statistics = simulation.getCellarMaxDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                default:
                    title = "R_AM, " + title;
                    statistics = simulation.getRoomAmDescriptiveStats();
                    roomType = OMRoomType.Misc;
                    break;
                }
                JFreeChart chart = OMCharts.createDistributionChart(title, statistics, roomType, 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);

    lblSelectSimulation = new JLabel("Select Simulation");
    lblSelectSimulation.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblSelectSimulation.setBounds(10, 65, 132, 14);
    add(lblSelectSimulation);

    lblSelectStatistics = new JLabel("Select Statistics");
    lblSelectStatistics.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblSelectStatistics.setBounds(10, 94, 132, 14);
    add(lblSelectStatistics);

    comboBoxSimulations = new JComboBox<OMSimulation>();
    comboBoxSimulations.setFont(new Font("SansSerif", Font.PLAIN, 11));
    comboBoxSimulations.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent arg0) {
            boolean b = false;
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    b = true;
                    comboBoxStatistics.removeAllItems();
                    comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values()));
                } else {
                    b = false;
                    comboBoxStatistics.removeAllItems();
                }
            } else {
                b = false;
                comboBoxStatistics.removeAllItems();
            }
            progressBar.setEnabled(b);
            btnPdf.setVisible(b);
            btnCsv.setVisible(b);
            btnMaximize.setVisible(b);
            lblExportChartTo.setVisible(b);
            comboBoxStatistics.setEnabled(b);
            lblSelectStatistics.setEnabled(b);
        }
    });
    comboBoxSimulations.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            boolean b = false;
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    b = true;
                    comboBoxStatistics.removeAllItems();
                    comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values()));
                    comboBoxStatistics.setSelectedIndex(0);
                } else {
                    b = false;
                    comboBoxStatistics.removeAllItems();
                }
            } else {
                b = false;
                comboBoxStatistics.removeAllItems();
            }
            progressBar.setEnabled(b);
            btnPdf.setVisible(b);
            btnCsv.setVisible(b);
            btnMaximize.setVisible(b);
            lblExportChartTo.setVisible(b);
            comboBoxStatistics.setEnabled(b);
            lblSelectStatistics.setEnabled(b);
        }
    });
    comboBoxSimulations.setBounds(152, 61, 454, 22);
    add(comboBoxSimulations);

    btnRefresh = new JButton("Load");
    btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (txtOmsFile.getText() != null && !txtOmsFile.getText().equals("")
                    && !txtOmsFile.getText().equals(" ")) {
                txtOmsFile.setBackground(Color.WHITE);
                String omsPath = txtOmsFile.getText();
                String oms;
                String[] tmpFileName = omsPath.split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("oms")) {
                    oms = "";
                } else {
                    oms = ".oms";
                }
                txtOmsFile.setText(omsPath + oms);
                setOmsFile(omsPath + oms);
                File omsFile = new File(omsPath + oms);
                if (omsFile.exists()) {
                    txtOmsFile.setBackground(Color.WHITE);
                    btnRefresh.setEnabled(false);
                    comboBoxSimulations.setEnabled(false);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    progressBar.setStringPainted(true);
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                    btnPdf.setVisible(false);
                    btnCsv.setVisible(false);
                    btnMaximize.setVisible(false);
                    lblExportChartTo.setVisible(false);
                    refreshSimulationsTask = new RefreshSimulations();
                    refreshSimulationsTask.execute();
                } else {
                    txtOmsFile.setBackground(new Color(255, 222, 222, 128));
                    JOptionPane.showMessageDialog(null, "OMS-file not found, please check the file path!",
                            "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                txtOmsFile.setBackground(new Color(255, 222, 222, 128));
                JOptionPane.showMessageDialog(null, "Please select an OMS-file!", "Warning",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    });

    comboBoxStatistics = new JComboBox<OMStatistics>();
    comboBoxStatistics.setFont(new Font("SansSerif", Font.PLAIN, 11));
    comboBoxStatistics.setBounds(152, 90, 454, 22);
    comboBoxStatistics.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            updateDistribution();
        }
    });
    add(comboBoxStatistics);

    btnRefresh.setBounds(616, 61, 124, 23);
    add(btnRefresh);

    panelDistribution = new JPanel();
    panelDistribution.setBounds(10, 118, 730, 347);
    add(panelDistribution);

    progressBar = new JProgressBar();
    progressBar.setFont(new Font("SansSerif", Font.PLAIN, 11));
    progressBar.setBounds(10, 475, 730, 23);
    add(progressBar);

    progressBar.setEnabled(false);
    comboBoxStatistics.setEnabled(false);
    lblSelectStatistics.setEnabled(false);
    btnPdf.setVisible(false);
    btnCsv.setVisible(false);
    btnMaximize.setVisible(false);
    lblExportChartTo.setVisible(false);

    lblHelp = new JLabel("Select an OMS-Simulation file to analyse the simulation results and "
            + "display the distribution chart.");
    lblHelp.setForeground(Color.GRAY);
    lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblHelp.setBounds(10, 10, 730, 14);
    add(lblHelp);

    lblSelectOms = new JLabel("Open OMS-File");
    lblSelectOms.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblSelectOms.setBounds(10, 36, 132, 14);
    add(lblSelectOms);

    txtOmsFile = new JTextField();
    txtOmsFile.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            setOmsFile(txtOmsFile.getText());
        }
    });
    txtOmsFile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    txtOmsFile.setColumns(10);
    txtOmsFile.setBounds(152, 33, 454, 20);
    add(txtOmsFile);

    buttonBrowse = new JButton("Browse");
    buttonBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.oms", "oms"));
            fileDialog.showOpenDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String oms;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("oms")) {
                    oms = "";
                } else {
                    oms = ".oms";
                }
                txtOmsFile.setText(file.getAbsolutePath() + oms);
                setOmsFile(file.getAbsolutePath() + oms);
            }
        }
    });
    buttonBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11));
    buttonBrowse.setBounds(616, 32, 124, 23);
    add(buttonBrowse);
    progressBar.setVisible(false);
}

From source file:com.jamfsoftware.jss.healthcheck.ui.HealthReport.java

/**
 * Creates a new Health Report JPanel window from the Health Check JSON string.
 * Will throw errors if the JSON is not formatted correctly.
 *//*from w w w.  ja v a2 s .c o  m*/
public HealthReport(final String JSON) throws Exception {
    LOGGER.debug("[DEBUG] - JSON String (Copy entire below line)");
    LOGGER.debug(JSON.replace("\n", ""));
    LOGGER.debug("Attempting to parse Health Report JSON");

    JsonElement report = new JsonParser().parse(JSON);
    JsonObject healthcheck = ((JsonObject) report).get("healthcheck").getAsJsonObject();
    Boolean show_system_info = true;
    JsonObject system = null;
    //Check if the check JSON contains system information and show/hide panels accordingly later.
    system = ((JsonObject) report).get("system").getAsJsonObject();

    final JsonObject data = ((JsonObject) report).get("checkdata").getAsJsonObject();

    this.JSSURL = extractData(healthcheck, "jss_url");

    if (extractData(system, "iscloudjss").contains("true")) {
        show_system_info = false;
        isCloudJSS = true;
    }

    PanelIconGenerator iconGen = new PanelIconGenerator();
    PanelGenerator panelGen = new PanelGenerator();

    //Top Level Frame
    final JFrame frame = new JFrame("JSS Health Check Report");

    //Top Level Content
    JPanel outer = new JPanel(new BorderLayout());

    //Two Blank Panels for the Sides
    JPanel blankLeft = new JPanel();
    blankLeft.add(new JLabel("        "));
    JPanel blankRight = new JPanel();
    blankRight.add(new JLabel("        "));
    blankLeft.setMinimumSize(new Dimension(100, 100));
    blankRight.setMinimumSize(new Dimension(100, 100));
    //Header
    JPanel header = new JPanel();
    header.add(new JLabel("Total Computers: " + extractData(healthcheck, "totalcomputers")));
    header.add(new JLabel("Total Mobile Devices: " + extractData(healthcheck, "totalmobile")));
    header.add(new JLabel("Total Users: " + extractData(healthcheck, "totalusers")));
    int total_devices = Integer.parseInt(extractData(healthcheck, "totalcomputers"))
            + Integer.parseInt(extractData(healthcheck, "totalmobile"));
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
    Date dateobj = new Date();
    header.add(new JLabel("JSS Health Check Report Performed On " + df.format(dateobj)));
    //Foooter
    JPanel footer = new JPanel();
    JButton view_report_json = new JButton("View Report JSON");
    footer.add(view_report_json);
    JButton view_activation_code = new JButton("View Activation Code");
    footer.add(view_activation_code);
    JButton test_again = new JButton("Run Test Again");
    footer.add(test_again);
    JButton view_text_report = new JButton("View Text Report");
    footer.add(view_text_report);
    JButton about_and_terms = new JButton("About and Terms");
    footer.add(about_and_terms);
    //Middle Content, set the background white and give it a border
    JPanel content = new JPanel(new GridLayout(2, 3));
    content.setBackground(Color.WHITE);
    content.setBorder(BorderFactory.createLineBorder(Color.BLACK));

    //Setup Outer Placement
    outer.add(header, BorderLayout.NORTH);
    outer.add(footer, BorderLayout.SOUTH);
    outer.add(blankLeft, BorderLayout.WEST);
    outer.add(blankRight, BorderLayout.EAST);
    outer.add(content, BorderLayout.CENTER);

    //Don't show system info if it is hosted.
    JPanel system_info = null;
    JPanel database_health = null;
    if (show_system_info) {
        //Read all of the System information variables from the JSON and perform number conversions.
        String[][] sys_info = { { "Operating System", extractData(system, "os") },
                { "Java Version", extractData(system, "javaversion") },
                { "Java Vendor", extractData(system, "javavendor") },
                { "Processor Cores", extractData(system, "proc_cores") },
                { "Is Clustered?", extractData(system, "clustering") },
                { "Web App Directory", extractData(system, "webapp_dir") },
                { "Free Memory",
                        Double.toString(
                                round((Double.parseDouble(extractData(system, "free_memory")) / 1000000000), 2))
                                + " GB" },
                { "Max Memory",
                        Double.toString(
                                round((Double.parseDouble(extractData(system, "max_memory")) / 1000000000), 2))
                                + " GB" },
                { "Memory currently in use", Double.toString(round(
                        (Double.parseDouble(extractData(system, "memory_currently_in_use")) / 1000000000), 2))
                        + " GB" },
                { "Total space",
                        Double.toString(
                                round((Double.parseDouble(extractData(system, "total_space")) / 1000000000), 2))
                                + " GB" },
                { "Free Space",
                        Double.toString(round(
                                (Double.parseDouble(extractData(system, "usable_space")) / 1000000000), 2))
                                + " GB" } };
        //Generate the system info panel.
        String systemInfoIcon = iconGen.getSystemInfoIconType(
                Integer.parseInt(extractData(healthcheck, "totalcomputers"))
                        + Integer.parseInt(extractData(healthcheck, "totalmobile")),
                extractData(system, "javaversion"), Double.parseDouble(extractData(system, "max_memory")));
        system_info = panelGen.generateContentPanelSystem("System Info", sys_info, "JSS Minimum Requirements",
                "http://www.jamfsoftware.com/resources/casper-suite-system-requirements/", systemInfoIcon);

        //Get all of the DB information.
        String[][] db_health = { { "Database Size", extractData(system, "database_size") + " MB" } };
        if (extractData(system, "database_size").equals("0")) {
            db_health[0][0] = "Unable to connect to database.";
        }

        String[][] large_sql_tables = extractArrayData(system, "largeSQLtables", "table_name", "table_size");
        String[][] db_health_for_display = ArrayUtils.addAll(db_health, large_sql_tables);
        //Generate the DB Health panel.
        String databaseIconType = iconGen.getDatabaseInfoIconType(total_devices,
                Double.parseDouble(extractData(system, "database_size")),
                extractArrayData(system, "largeSQLtables", "table_name", "table_size").length);
        database_health = panelGen.generateContentPanelSystem("Database Health", db_health_for_display,
                "Too Large SQL Tables", "https://google.com", databaseIconType);
        if (!databaseIconType.equals("green")) {
            this.showLargeDatabase = true;
        }
    }

    int password_strenth = 0;
    if (extractData(data, "password_strength", "uppercase?").contains("true")) {
        password_strenth++;
    }
    if (extractData(data, "password_strength", "lowercase?").contains("true")) {
        password_strenth++;
    }
    if (extractData(data, "password_strength", "number?").contains("true")) {
        password_strenth++;
    }
    if (extractData(data, "password_strength", "spec_chars?").contains("true")) {
        password_strenth++;
    }
    String password_strength_desc = "";
    if (password_strenth == 4) {
        password_strength_desc = "Excellent";
    } else if (password_strenth == 3 || password_strenth == 2) {
        password_strength_desc = "Good";
    } else if (password_strenth == 1) {
        this.strongerPassword = true;
        password_strength_desc = "Poor";
    } else {
        this.strongerPassword = true;
        password_strength_desc = "Needs Updating";
    }

    if (extractData(data, "loginlogouthooks", "is_configured").contains("false")) {
        this.loginInOutHooks = true;
    }

    try {
        if (Integer.parseInt(extractData(data, "device_row_counts", "computers").trim()) != Integer
                .parseInt(extractData(data, "device_row_counts", "computers_denormalized").trim())) {
            this.computerDeviceTableCountMismatch = true;
        }

        if (Integer.parseInt(extractData(data, "device_row_counts", "mobile_devices").trim()) != Integer
                .parseInt(extractData(data, "device_row_counts", "mobile_devices_denormalized").trim())) {
            this.mobileDeviceTableCountMismatch = true;
        }
    } catch (Exception e) {
        System.out.println("Unable to parse device row counts.");
    }

    if ((extractData(system, "mysql_version").contains("5.6.16")
            || extractData(system, "mysql_version").contains("5.6.20"))
            && (extractData(system, "os").contains("OS X") || extractData(system, "os").contains("Mac")
                    || extractData(system, "os").contains("OSX"))) {
        this.mysql_osx_version_bug = true;
    }

    //Get all of the information for the JSS ENV and generate the panel.
    String[][] env_info = {
            { "Checkin Frequency", extractData(data, "computercheckin", "frequency") + " Minutes" },
            { "Log Flushing", extractData(data, "logflushing", "log_flush_time") },
            { "Log In/Out Hooks", extractData(data, "loginlogouthooks", "is_configured") },
            { "Computer EA", extractData(data, "computerextensionattributes", "count") },
            { "Mobile Deivce EA", extractData(data, "mobiledeviceextensionattributes", "count") },
            { "Password Strength", password_strength_desc },
            { "SMTP Server", extractData(data, "smtpserver", "server") },
            { "Sender Email", extractData(data, "smtpserver", "sender_email") },
            { "GSX Connection", extractData(data, "gsxconnection", "status") } };
    String[][] vpp_accounts = extractArrayData(data, "vppaccounts", "name", "days_until_expire");
    String[][] ldap_servers = extractArrayData(data, "ldapservers", "name", "type", "address", "id");
    String envIconType = iconGen.getJSSEnvIconType(Integer.parseInt(extractData(healthcheck, "totalcomputers")),
            Integer.parseInt(extractData(data, "computercheckin", "frequency")),
            Integer.parseInt(extractData(data, "computerextensionattributes", "count")),
            Integer.parseInt(extractData(data, "mobiledeviceextensionattributes", "count")));
    JPanel env = panelGen.generateContentPanelEnv("JSS Environment", env_info, vpp_accounts, ldap_servers, "",
            "", envIconType);

    //Get all of the group information from the JSON, merge the arrays, and then generate the groups JPanel.
    String[][] groups_1 = ArrayUtils.addAll(
            extractArrayData(data, "computergroups", "name", "nested_groups_count", "criteria_count", "id"),
            extractArrayData(data, "mobiledevicegroups", "name", "nested_groups_count", "criteria_count",
                    "id"));
    String[][] groups_2 = ArrayUtils.addAll(groups_1,
            extractArrayData(data, "usergroups", "name", "nested_groups_count", "criteria_count", "id"));
    String groupIconType = iconGen.getGroupIconType("groups", countJSONObjectSize(data, "computergroups")
            + countJSONObjectSize(data, "mobiledevicegroups") + countJSONObjectSize(data, "usergroups"));
    JPanel groups = panelGen.generateContentPanelGroups("Groups", groups_2, "", "", groupIconType);
    if (groupIconType.equals("yellow") || groupIconType.equals("red")) {
        this.showGroupsHelp = true;
    }

    //Get all of the information for the printers, policies and scripts, then generate the panel.
    String[][] printers = extractArrayData(data, "printer_warnings", "model");
    String[][] policies = extractArrayData(data, "policies_with_issues", "name", "ongoing", "checkin_trigger");
    String[][] scripts = extractArrayData(data, "scripts_needing_update", "name");
    String[][] certs = { { "SSL Cert Issuer", extractData(data, "tomcat", "ssl_cert_issuer") },
            { "SLL Cert Expires", extractData(data, "tomcat", "cert_expires") },
            { "MDM Push Cert Expires", extractData(data, "push_cert_expirations", "mdm_push_cert") },
            { "Push Proxy Expires", extractData(data, "push_cert_expirations", "push_proxy") },
            { "Change Management Enabled?", extractData(data, "changemanagment", "isusinglogfile") },
            { "Log File Path:", extractData(data, "changemanagment", "logpath") } };
    String policiesScriptsIconType = iconGen.getPoliciesAndScriptsIconType(
            extractArrayData(data, "policies_with_issues", "name", "ongoing", "checkin_trigger").length,
            extractArrayData(data, "scripts_needing_update", "name").length);
    JPanel policies_scripts = panelGen.generateContentPanelPoliciesScripts(
            "Policies, Scripts, Certs and Change", policies, scripts, printers, certs, "", "",
            policiesScriptsIconType);
    if (extractArrayData(data, "policies_with_issues", "name", "ongoing", "checkin_trigger").length > 0) {
        this.showPolicies = true;
    }
    if (extractArrayData(data, "scripts_needing_update", "name").length > 0) {
        this.showScripts = true;
    }
    if (extractData(data, "changemanagment", "isusinglogfile").contains("false")) {
        this.showChange = true;
    }
    this.showCheckinFreq = iconGen.showCheckinFreq;
    this.showExtensionAttributes = iconGen.showCheckinFreq;
    this.showSystemRequirements = iconGen.showSystemRequirements;
    this.showScalability = iconGen.showScalability;
    //Update Panel Gen Variables
    updatePanelGenVariables(panelGen);

    //Generate the Help Section.
    content.add(panelGen.generateContentPanelHelp("Modifications to Consider", "", "", "blank"));
    //If contains system information, add those panels, otherwise just continue adding the rest of the panels.
    if (show_system_info) {
        content.add(system_info);
        content.add(database_health);
    }
    content.add(env);
    content.add(groups);
    content.add(policies_scripts);

    //View report action listner.
    //Opens a window with the health report JSON listed
    view_report_json.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPanel middlePanel = new JPanel();
            middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Health Report JSON"));
            // create the middle panel components
            JTextArea display = new JTextArea(16, 58);
            display.setEditable(false);
            //Make a new GSON object so the text can be Pretty Printed.
            Gson gson = new GsonBuilder().setPrettyPrinting().create();
            String pp_json = gson.toJson(JSON.trim());
            display.append(JSON);
            JScrollPane scroll = new JScrollPane(display);
            scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            //Add Textarea in to middle panel
            middlePanel.add(scroll);

            JFrame frame = new JFrame();
            frame.add(middlePanel);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    //Action listener for the Terms, About and Licence button.
    //Opens a new window with the AS IS License, 3rd Party Libs used and a small about section
    about_and_terms.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPanel middlePanel = new JPanel();
            middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "About, Licence and Terms"));
            // create the middle panel components
            JTextArea display = new JTextArea(16, 58);
            display.setEditable(false);
            display.append(StringConstants.ABOUT);
            display.append("\n\nThird Party Libraries Used:");
            display.append(
                    " Apache Commons Codec, Google JSON (gson), Java X JSON, JDOM, JSON-Simple, MySQL-connector");
            display.append(StringConstants.LICENSE);
            JScrollPane scroll = new JScrollPane(display);
            scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            //Add Textarea in to middle panel
            middlePanel.add(scroll);

            JFrame frame = new JFrame();
            frame.add(middlePanel);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    //Listener for a button click to open a window containing the activation code.
    view_activation_code.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(frame, extractData(data, "activationcode", "code") + "\nExpires: "
                    + extractData(data, "activationcode", "expires"));
        }
    });

    view_text_report.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPanel middlePanel = new JPanel();
            middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Text Health Report"));
            // create the middle panel components
            JTextArea display = new JTextArea(16, 58);
            display.setEditable(false);
            //Make a new GSON object so the text can be Pretty Printed.
            display.append(new HealthReportHeadless(JSON).getReportString());
            JScrollPane scroll = new JScrollPane(display);
            scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            //Add Textarea in to middle panel
            middlePanel.add(scroll);

            JFrame frame = new JFrame();
            frame.add(middlePanel);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    //Listener for the Test Again button. Opens a new UserPrompt object and keeps the Health Report open in the background.
    test_again.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                new UserPrompt();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }
    });

    frame.add(outer);
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setVisible(true);

    DetectVM vm_checker = new DetectVM();
    if (EnvironmentUtil.isMac()) {
        if (vm_checker.getIsVM()) {
            JOptionPane.showMessageDialog(new JFrame(),
                    "The tool has detected that it is running in a OSX Virtual Machine.\nThe opening of links is not supported on OSX VMs.\nPlease open the tool on a non-VM computer and run it again OR\nyou can also copy the JSON from the report to a non-VM OR view the text report.\nIf you are not running a VM, ignore this message.",
                    "VM Detected", JOptionPane.ERROR_MESSAGE);
        }
    }

}

From source file:org.ayound.js.debug.ui.DebugMainFrame.java

private void initAction() {
    actionOpen = new AbstractAction(Messages.getString("DebugMainFrame.Open")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser(); // 
            fileDialog.setFileFilter(new FileFilter() {

                @Override// w  w  w .  jav  a2s .  c om
                public boolean accept(File f) {
                    String fileName = f.getName().toLowerCase();
                    if (fileName.endsWith(".htm") //$NON-NLS-1$
                            || fileName.endsWith(".html") //$NON-NLS-1$
                            || fileName.endsWith(".js") || f.isDirectory()) { //$NON-NLS-1$
                        return true;
                    } else {
                        return false;
                    }

                }

                @Override
                public String getDescription() {
                    return ".htm,.html,.js"; //$NON-NLS-1$
                }
            });
            int result = fileDialog.showOpenDialog(DebugMainFrame.this);
            if (result == JFileChooser.APPROVE_OPTION) {
                openHtmlFile(fileDialog.getSelectedFile());
            }

        }
    };
    actionClose = new AbstractAction(Messages.getString("DebugMainFrame.Close")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            int index = mainPane.getSelectedIndex();
            if (index > -1) {
                mainPane.remove(index);
            }
        }
    };
    actionExit = new AbstractAction(Messages.getString("DebugMainFrame.Exit")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    ImageIcon startIcon = new ImageIcon(DebugMainFrame.class.getResource("icons/launch_run.gif")); //$NON-NLS-1$
    actionDebugStart = new AbstractAction(Messages.getString("DebugMainFrame.Start"), startIcon) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            startDebug();
        }
    };
    ImageIcon endIcon = new ImageIcon(DebugMainFrame.class.getResource("icons/terminate_co.gif")); //$NON-NLS-1$
    actionDebugEnd = new AbstractAction(Messages.getString("DebugMainFrame.End"), endIcon) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            endDebug();
        }
    };
    actionDebugEnd.setEnabled(false);
    actionHelp = new AbstractAction(Messages.getString("DebugMainFrame.Content")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            String locale = DebugMainFrame.this.getLocale().toString();
            String helpPath = "help/index_" + locale + ".html";
            File testFile = new File(new File(getBaseDir()), helpPath); //$NON-NLS-1$
            final String url = "file:///" + testFile.getAbsolutePath().replace('\\', '/'); //$NON-NLS-1$

            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    try {
                        // TODO Auto-generated method stub
                        JFrame someWindow = new JFrame();
                        JEditorPane htmlPane = new JEditorPane(url);
                        htmlPane.setEditable(false);
                        someWindow.setSize(800, 600);
                        someWindow.setExtendedState(JFrame.MAXIMIZED_BOTH);
                        someWindow.setVisible(true);
                        someWindow.add(new JScrollPane(htmlPane));
                    } catch (IOException ioe) {
                        System.err.println(Messages.getString("DebugMainFrame.ErrorDisplay") + url); //$NON-NLS-1$
                    }
                }
            });

        }
    };
    actionAbout = new AbstractAction(Messages.getString("DebugMainFrame.About")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(DebugMainFrame.this,
                    Messages.getString("DebugMainFrame.AboutContent"), //$NON-NLS-1$
                    Messages.getString("DebugMainFrame.ApplicationName"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
        }
    };
    actionLanguageChinese = new AbstractAction("Chinese") {

        public void actionPerformed(ActionEvent e) {
            DebugUIUtil.updateUI(Locale.SIMPLIFIED_CHINESE);
        }
    };
    actionLanguageEnglish = new AbstractAction("English") {

        public void actionPerformed(ActionEvent e) {
            DebugUIUtil.updateUI(Locale.ENGLISH);
        }
    };
}

From source file:org.fit.cssbox.scriptbox.demo.tester.JavaScriptTesterUIPresenter.java

public void showWindow() {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                JFrame window = tester.getWindow();
                window.setExtendedState(JFrame.MAXIMIZED_BOTH);
                window.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();//from w w w .ja va 2  s .  c  o  m
                JOptionPane.showMessageDialog(tester.getWindow(), "Unable to run application.",
                        "Internal error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
}

From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java

/**
 * Setup System Tray Icon./*from  w w  w .  j ava2s . co m*/
 * 
 * @param frame owner frame
 */
private void setupTrayIcon(final JFrame frame) {

    idleIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/node_inactive.png"));

    activeIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/node_active.png"));

    frame.setIconImage(idleIcon);

    // If system tray is supported by OS
    if (SystemTray.isSupported()) {
        trayIcon = new TrayIcon(idleIcon, "Nebula Grid Node", 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);
            }

        });
    }

}