private void addPeriodButtons(JPanel centerPanel, final CustomPeriodPanel customPeriodPanel) { centerPanel.add(new JLabel(" " + getString("Choix_periode") + " : ")); for (final Period myPeriod : Period.values()) { final String linkLabel = myPeriod.getLinkLabel(); final MButton myPeriodButton = new MButton(linkLabel, ImageIconCache.getImageIcon(myPeriod.getIconName())); myPeriodButton.setToolTipText( getFormattedString("Choisir_periode", linkLabel) + " (Alt-" + linkLabel.charAt(0) + ')'); myPeriodButton.setMnemonic(linkLabel.charAt(0)); centerPanel.add(myPeriodButton); myPeriodButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { actionChangePeriod(myPeriod.getRange()); } }); } final String customPeriodLinkLabel = getString("personnalisee"); final MButton customPeriodButton = new MButton(customPeriodLinkLabel, ImageIconCache.getImageIcon("calendar.png")); customPeriodButton.setToolTipText( getFormattedString("Choisir_periode", customPeriodLinkLabel) + " (Alt-" + customPeriodLinkLabel.charAt(0) + ')'); customPeriodButton.setMnemonic(customPeriodLinkLabel.charAt(0)); centerPanel.add(customPeriodButton); customPeriodPanel.setVisible(false); customPeriodButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { customPeriodPanel.setVisible(!customPeriodPanel.isVisible()); if (customPeriodPanel.isVisible()) { customPeriodPanel.requestFocusInStartField(); } validate(); } }); }
private MButton createOnlineHelpButton() { final MButton onlineHelpButton = new MButton(getString("Aide_en_ligne"), ImageIconCache.getImageIcon("action_help.png")); onlineHelpButton.setToolTipText(getString("Afficher_aide_en_ligne") + " (F1)"); onlineHelpButton.setActionCommand("help"); onlineHelpButton .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke("F1"), "doHelp"); onlineHelpButton .getActionMap() .put( "doHelp", new AbstractAction() { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { onlineHelpButton.doClick(); } }); return onlineHelpButton; }
MainButtonsPanel( RemoteCollector remoteCollector, Range selectedRange, final URL monitoringUrl, boolean collectorServer) { super(remoteCollector, new BorderLayout()); this.collectorServer = collectorServer; setOpaque(true); setBackground(BACKGROUND); final JPanel centerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); centerPanel.setOpaque(false); add(centerPanel, BorderLayout.CENTER); final CustomPeriodPanel customPeriodPanel = new CustomPeriodPanel(remoteCollector, selectedRange); add(customPeriodPanel, BorderLayout.SOUTH); final MButton refreshButton = createRefreshButton(); final MButton pdfButton = createPdfButton(); // on ne peut pas instancier defaultSerializable ici car sinon, // les données ne seraient plus à jour après une actualisation, donc on passe la valeur spéciale // null final MButton xmlJsonButton = createXmlJsonButton(null); final MButton onlineHelpButton = createOnlineHelpButton(); final MButton monitoringButton = new MButton(getString("Monitoring"), MONITORING_ICON); monitoringButton.setToolTipText( getFormattedString("Monitoring_sur", remoteCollector.getApplication())); centerPanel.add(refreshButton); centerPanel.add(pdfButton); centerPanel.add(xmlJsonButton); centerPanel.add(onlineHelpButton); centerPanel.add(monitoringButton); addPeriodButtons(centerPanel, customPeriodPanel); refreshButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { actionRefresh(); } }); pdfButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { actionPdf(); } catch (final Exception ex) { showException(ex); } } }); monitoringButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().browse(new URI(monitoringUrl.toExternalForm())); } catch (final Exception ex) { showException(ex); } } }); onlineHelpButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop() .browse( new URI( monitoringUrl.toExternalForm() + "?resource=" + getString("help_url"))); } catch (final Exception ex) { showException(ex); } } }); }