Example usage for javax.swing ButtonGroup ButtonGroup

List of usage examples for javax.swing ButtonGroup ButtonGroup

Introduction

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

Prototype

public ButtonGroup() 

Source Link

Document

Creates a new ButtonGroup.

Usage

From source file:ca.phon.plugins.praat.export.TextGridExportWizard.java

private WizardStep setupExportOptionsStep() {
    final WizardStep retVal = new WizardStep();

    final DialogHeader header = new DialogHeader("Generate TextGrids", "Setup export options.");

    overwriteBox = new JCheckBox();
    overwriteBox.setText(OVERWRITE_MESSAGE);

    nameField = new JTextField();
    nameField.setEnabled(false);//from   www.  j a v a 2s.c  o m

    defaultNameButton = new JRadioButton(
            "Save as default TextGrid for session (__res/textgrids/.../default.TextGrid)");
    customNameButton = new JRadioButton("Save TextGrid with custom name");
    defaultNameButton.setSelected(true);

    defaultNameButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            boolean state = defaultNameButton.isSelected();
            if (state) {
                nameField.setEnabled(false);
            }
        }

    });

    customNameButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean state = customNameButton.isSelected();
            if (state) {
                nameField.setEnabled(true);
            }
        }
    });

    nameGroup = new ButtonGroup();
    nameGroup.add(defaultNameButton);
    nameGroup.add(customNameButton);

    final TextGridExporter exporter = new TextGridExporter();
    exportsTree = new ExportEntryCheckboxTree(session);
    exportsTree.setBorder(BorderFactory.createTitledBorder("Select tiers"));
    exportsTree.setChecked(exporter.getExports(getProject()));
    final JScrollPane exportsScroller = new JScrollPane(exportsTree);

    final JPanel topPanel = new JPanel();
    topPanel.setLayout(new VerticalLayout());
    topPanel.setBorder(BorderFactory.createTitledBorder("Options"));
    topPanel.add(defaultNameButton);
    topPanel.add(customNameButton);
    topPanel.add(nameField);
    topPanel.add(overwriteBox);

    final JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new BorderLayout());
    centerPanel.add(topPanel, BorderLayout.NORTH);
    centerPanel.add(exportsScroller, BorderLayout.CENTER);

    retVal.setLayout(new BorderLayout());
    retVal.add(header, BorderLayout.NORTH);
    retVal.add(centerPanel, BorderLayout.CENTER);

    return retVal;
}

From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java

/**
 * Setup the GUI./*from   w  w w  .j  a v a  2  s. co  m*/
 */
private void setupGUI() {
    JPanel mainPanel = new JPanel();
    this.setContentPane(mainPanel);

    // start layout
    mainPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 2, 5);
    JPanel radioPanel = new JPanel();
    radioPanel.setLayout(new BorderLayout());
    zoomRadiobutton = new JRadioButton(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.zoom.label"));
    zoomRadiobutton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.zoom.tip"));
    zoomRadiobutton.setSelected(true);
    radioPanel.add(zoomRadiobutton, BorderLayout.LINE_START);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.weightx = 1;
    selectionRadiobutton = new JRadioButton(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.selection.label"));
    selectionRadiobutton
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.selection.tip"));
    selectionRadiobutton.setHorizontalAlignment(SwingConstants.CENTER);
    radioPanel.add(selectionRadiobutton, BorderLayout.LINE_END);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 3;
    this.add(radioPanel, gbc);

    ButtonGroup group = new ButtonGroup();
    group.add(zoomRadiobutton);
    group.add(selectionRadiobutton);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1;
    gbc.gridwidth = 3;
    gbc.anchor = GridBagConstraints.CENTER;
    rangeAxisSelectionCombobox = new JComboBox();
    rangeAxisSelectionCombobox.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.range_axis_combobox.tip"));
    rangeAxisSelectionCombobox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateValueRange();
        }
    });
    this.add(rangeAxisSelectionCombobox, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 1;
    gbc.gridwidth = 3;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 2, 5);
    JLabel domainRangeLowerBoundLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_lower_bound.label"));
    this.add(domainRangeLowerBoundLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.insets = new Insets(2, 5, 2, 5);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    domainRangeLowerBoundField = new JTextField();
    domainRangeLowerBoundField.setText(String.valueOf(domainRangeLowerBound));
    domainRangeLowerBoundField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyDomainRangeLowerBoundInput(input);
        }
    });
    domainRangeLowerBoundField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_lower_bound.tip"));
    this.add(domainRangeLowerBoundField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.NONE;
    JLabel domainRangeUpperBoundLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_upper_bound.label"));
    this.add(domainRangeUpperBoundLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    domainRangeUpperBoundField = new JTextField();
    domainRangeUpperBoundField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_upper_bound.tip"));
    domainRangeUpperBoundField.setText(String.valueOf(domainRangeUpperBound));
    domainRangeUpperBoundField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyDomainRangeUpperBoundInput(input);
        }
    });
    this.add(domainRangeUpperBoundField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.NONE;
    JLabel valueRangeLowerBoundLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_lower_bound.label"));
    this.add(valueRangeLowerBoundLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    valueRangeLowerBoundField = new JTextField();
    valueRangeLowerBoundField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_lower_bound.tip"));
    valueRangeLowerBoundField.setText(String.valueOf(valueRangeLowerBound));
    valueRangeLowerBoundField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyValueRangeLowerBoundInput(input);
        }
    });
    this.add(valueRangeLowerBoundField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.NONE;
    JLabel valueRangeUpperBoundLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_upper_bound.label"));
    this.add(valueRangeUpperBoundLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    valueRangeUpperBoundField = new JTextField();
    valueRangeUpperBoundField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_upper_bound.tip"));
    valueRangeUpperBoundField.setText(String.valueOf(valueRangeUpperBound));
    valueRangeUpperBoundField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyValueRangeUpperBoundInput(input);
        }
    });
    this.add(valueRangeUpperBoundField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 6;
    gbc.gridwidth = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    this.add(new JSeparator(), gbc);

    gbc.gridx = 0;
    gbc.gridy = 7;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    JLabel colorMinValueLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_min_value.label"));
    this.add(colorMinValueLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 7;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    colorMinValueField = new JTextField();
    colorMinValueField
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_min_value.tip"));
    colorMinValueField.setText(String.valueOf(colorMinValue));
    colorMinValueField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyColorInput(input);
        }
    });
    colorMinValueField.setEnabled(false);
    this.add(colorMinValueField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 8;
    gbc.fill = GridBagConstraints.NONE;
    JLabel colorMaxValueLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_max_value.label"));
    this.add(colorMaxValueLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 8;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    colorMaxValueField = new JTextField();
    colorMaxValueField
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_max_value.tip"));
    colorMaxValueField.setText(String.valueOf(colorMaxValue));
    colorMaxValueField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyColorInput(input);
        }
    });
    colorMaxValueField.setEnabled(false);
    this.add(colorMaxValueField, gbc);

    gbc.gridx = 1;
    gbc.gridy = 9;
    gbc.fill = GridBagConstraints.NONE;
    restoreColorButton = new JButton(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.label"));
    restoreColorButton
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.tip"));
    restoreColorButton.setIcon(SwingTools.createIcon(
            "16/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.icon")));
    restoreColorButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            LinkAndBrushSelection linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.RESTORE_COLOR,
                    new LinkedList<Pair<Integer, Range>>(), new LinkedList<Pair<Integer, Range>>(), null, null,
                    engine.getPlotInstance());
            engine.getChartPanel().informLinkAndBrushSelectionListeners(linkAndBrushSelection);
            updateColorValues();
        }
    });
    restoreColorButton.setEnabled(false);
    this.add(restoreColorButton, gbc);

    gbc.gridx = 0;
    gbc.gridy = 10;
    gbc.gridwidth = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(2, 5, 5, 5);
    this.add(new JSeparator(), gbc);

    gbc.gridx = 0;
    gbc.gridy = 11;
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 5, 5);
    okButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.label"));
    okButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.tip"));
    okButton.setIcon(SwingTools
            .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.icon")));
    okButton.setMnemonic(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.mne").toCharArray()[0]);
    okButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // make sure fields have correct values
            boolean fieldsPassedChecks = checkFields();
            if (!fieldsPassedChecks) {
                return;
            }

            Object selectedItem = rangeAxisSelectionCombobox.getSelectedItem();
            if (selectedItem != null && selectedItem instanceof RangeAxisConfig) {
                RangeAxisConfig config = (RangeAxisConfig) selectedItem;
                boolean zoomOnLinkAndBrushSelection = engine.getChartPanel().getZoomOnLinkAndBrushSelection();
                Range domainRange = new Range(Double.parseDouble(domainRangeLowerBoundField.getText()),
                        Double.parseDouble(domainRangeUpperBoundField.getText()));
                Range valueRange = new Range(Double.parseDouble(valueRangeLowerBoundField.getText()),
                        Double.parseDouble(valueRangeUpperBoundField.getText()));
                LinkedList<Pair<Integer, Range>> domainRangeList = new LinkedList<Pair<Integer, Range>>();
                // only add domain zoom if != 0
                if (domainRange.getUpperBound() != 0) {
                    domainRangeList.add(new Pair<Integer, Range>(0, domainRange));
                }
                LinkedList<Pair<Integer, Range>> valueRangeList = new LinkedList<Pair<Integer, Range>>();
                // only add range zoom if at least one RangeAxisConfig exists
                if (engine.getPlotInstance().getMasterPlotConfiguration().getRangeAxisConfigs().size() > 0) {
                    if (valueRange.getUpperBound() != 0) {
                        // only add value zoom if != 0
                        valueRangeList.add(
                                new Pair<Integer, Range>(engine.getPlotInstance().getMasterPlotConfiguration()
                                        .getIndexOfRangeAxisConfigById(config.getId()), valueRange));
                    }
                }

                // zoom or select or color
                LinkAndBrushSelection linkAndBrushSelection = null;
                if (zoomRadiobutton.isSelected()) {
                    linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.ZOOM_IN, domainRangeList,
                            valueRangeList);
                    if (isColorChanged(Double.parseDouble(colorMinValueField.getText()),
                            Double.parseDouble(colorMaxValueField.getText()))) {
                        linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.COLOR_ZOOM,
                                domainRangeList, valueRangeList,
                                Double.parseDouble(colorMinValueField.getText()),
                                Double.parseDouble(colorMaxValueField.getText()), engine.getPlotInstance());
                    }
                } else if (selectionRadiobutton.isSelected()) {
                    linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.SELECTION, domainRangeList,
                            valueRangeList);
                    if (isColorChanged(Double.parseDouble(colorMinValueField.getText()),
                            Double.parseDouble(colorMaxValueField.getText()))) {
                        linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.COLOR_SELECTION,
                                domainRangeList, valueRangeList,
                                Double.parseDouble(colorMinValueField.getText()),
                                Double.parseDouble(colorMaxValueField.getText()), engine.getPlotInstance());
                    }
                }
                engine.getChartPanel().informLinkAndBrushSelectionListeners(linkAndBrushSelection);
                engine.getChartPanel().setZoomOnLinkAndBrushSelection(zoomOnLinkAndBrushSelection);
            } else {
                return;
            }

            ManageZoomDialog.this.dispose();
        }
    });
    okButton.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                okButton.doClick();
            }
        }
    });
    this.add(okButton, gbc);

    gbc.gridx = 2;
    gbc.gridy = 11;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.EAST;
    cancelButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.label"));
    cancelButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.tip"));
    cancelButton.setIcon(SwingTools
            .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.icon")));
    cancelButton.setMnemonic(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.mne").toCharArray()[0]);
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // cancel requested, close dialog
            ManageZoomDialog.this.dispose();
        }
    });
    this.add(cancelButton, gbc);

    // misc settings
    this.setMinimumSize(new Dimension(375, 360));
    // center dialog
    this.setLocationRelativeTo(null);
    this.setTitle(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.title.label"));
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setModal(true);

    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowActivated(WindowEvent e) {
            okButton.requestFocusInWindow();
        }
    });
}

From source file:edu.purdue.cc.bionet.ui.DistributionAnalysisDisplayPanel.java

/**
 * Creates a new DistributionAnalysisDisplayPanel.
 *//* ww w  .jav  a 2s  . c  om*/
public DistributionAnalysisDisplayPanel() {
    super(new BorderLayout());
    Language language = Settings.getLanguage();
    this.menuBar = new JMenuBar();
    this.curveFittingMenu = new JMenu(language.get("Curve Fitting"));
    this.curveFittingMenu.setMnemonic(KeyEvent.VK_C);
    this.groupsMenu = new JMenu(language.get("Groups"));
    this.groupsMenu.setMnemonic(KeyEvent.VK_G);
    this.viewMenu = new JMenu(language.get("View"));
    this.viewMenu.setMnemonic(KeyEvent.VK_V);
    this.removeSampleGroupsMenuItem = new JMenuItem(language.get("Reset Sample Groups"), KeyEvent.VK_R);
    this.chooseSampleGroupsMenuItem = new JMenuItem(language.get("Choose Sample Groups"), KeyEvent.VK_C);
    this.fitSelectorPanel = new JPanel(new GridLayout(4, 1));
    this.noFitButton = new JRadioButtonMenuItem(language.get("No Fit"));
    this.robustFitButton = new JRadioButtonMenuItem(language.get("Robust Linear Fit"));
    this.chiSquareFitButton = new JRadioButtonMenuItem(language.get("Chi Square Fit"));
    this.fitButtonGroup = new ButtonGroup();
    this.fitButtonGroup.add(this.noFitButton);
    this.fitButtonGroup.add(this.robustFitButton);
    this.fitButtonGroup.add(this.chiSquareFitButton);
    this.noFitButton.setSelected(true);
    this.hideOutliersViewMenuItem = new JMenuItem(language.get("Hide Current Outliers"));
    this.curveFittingMenu.add(this.noFitButton);
    this.curveFittingMenu.add(this.robustFitButton);
    this.curveFittingMenu.add(this.chiSquareFitButton);
    this.groupsMenu.add(this.removeSampleGroupsMenuItem);
    this.groupsMenu.add(this.chooseSampleGroupsMenuItem);
    this.viewMenu.add(this.hideOutliersViewMenuItem);
    this.chooseSampleGroupsMenuItem.addActionListener(this);
    this.removeSampleGroupsMenuItem.addActionListener(this);
    this.hideOutliersViewMenuItem.addActionListener(this);
    this.add(menuBar, BorderLayout.NORTH);
    this.menuBar.add(this.curveFittingMenu);
    this.menuBar.add(this.groupsMenu);
    this.menuBar.add(this.viewMenu);
}

From source file:BeanContainer.java

  protected JMenuBar createMenuBar() {
  JMenuBar menuBar = new JMenuBar();
    /*from www.j ava  2s  . c  om*/
  JMenu mFile = new JMenu("File");

  JMenuItem mItem = new JMenuItem("New...");
  ActionListener lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {  
      Thread newthread = new Thread() {
        public void run() {
          String result = (String)JOptionPane.showInputDialog(
            BeanContainer.this, 
            "Please enter class name to create a new bean", 
            "Input", JOptionPane.INFORMATION_MESSAGE, null, 
            null, m_className);
          repaint();
          if (result==null)
            return;
          try {
            m_className = result;
            Class cls = Class.forName(result);
            Object obj = cls.newInstance();
            if (obj instanceof Component) {
              m_activeBean = (Component)obj;
              m_activeBean.addFocusListener(
                BeanContainer.this);
              m_activeBean.requestFocus();
              getContentPane().add(m_activeBean);
            }
            validate();
          }
          catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(
              BeanContainer.this, "Error: "+ex.toString(),
              "Warning", JOptionPane.WARNING_MESSAGE);
          }
        }
      };
      newthread.start();
    }
  };
  mItem.addActionListener(lst);
  mFile.add(mItem);

  mItem = new JMenuItem("Load...");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {  
      Thread newthread = new Thread() {
        public void run() {
          m_chooser.setCurrentDirectory(m_currentDir);
          m_chooser.setDialogTitle(
            "Please select file with serialized bean");
          int result = m_chooser.showOpenDialog(
            BeanContainer.this);
          repaint();
          if (result != JFileChooser.APPROVE_OPTION)
            return;
          m_currentDir = m_chooser.getCurrentDirectory();
          File fChoosen = m_chooser.getSelectedFile();
          try {
            FileInputStream fStream = 
              new FileInputStream(fChoosen);
            ObjectInput  stream  =  
              new ObjectInputStream(fStream);
            Object obj = stream.readObject();
            if (obj instanceof Component) {
              m_activeBean = (Component)obj;
              m_activeBean.addFocusListener(
                BeanContainer.this);
              m_activeBean.requestFocus();
              getContentPane().add(m_activeBean);
            }
            stream.close();
            fStream.close();
            validate();
          }
          catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(
              BeanContainer.this, "Error: "+ex.toString(),
              "Warning", JOptionPane.WARNING_MESSAGE);
          }
          repaint();
        }
      };
      newthread.start();
    }
  };
  mItem.addActionListener(lst);
  mFile.add(mItem);

  mItem = new JMenuItem("Save...");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      Thread newthread = new Thread() {
        public void run() {
          if (m_activeBean == null)
            return;
          m_chooser.setDialogTitle(
            "Please choose file to serialize bean");
          m_chooser.setCurrentDirectory(m_currentDir);
          int result = m_chooser.showSaveDialog(
            BeanContainer.this);
          repaint();
          if (result != JFileChooser.APPROVE_OPTION)
            return;
          m_currentDir = m_chooser.getCurrentDirectory();
          File fChoosen = m_chooser.getSelectedFile();
          try {
            FileOutputStream fStream = 
              new FileOutputStream(fChoosen);
            ObjectOutput stream  =  
              new ObjectOutputStream(fStream);
            stream.writeObject(m_activeBean);
            stream.close();
            fStream.close();
          }
          catch (Exception ex) {
            ex.printStackTrace();
          JOptionPane.showMessageDialog(
            BeanContainer.this, "Error: "+ex.toString(),
            "Warning", JOptionPane.WARNING_MESSAGE);
          }
        }
      };
      newthread.start();
    }
  };
  mItem.addActionListener(lst);
  mFile.add(mItem);

  mFile.addSeparator();

  mItem = new JMenuItem("Exit");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      System.exit(0);
    }
  };
  mItem.addActionListener(lst);
  mFile.add(mItem);
  menuBar.add(mFile);
    
  JMenu mEdit = new JMenu("Edit");

  mItem = new JMenuItem("Delete");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      if (m_activeBean == null)
        return;
      Object obj = m_editors.get(m_activeBean);
      if (obj != null) {
        BeanEditor editor = (BeanEditor)obj;
        editor.dispose();
        m_editors.remove(m_activeBean);
      }
      getContentPane().remove(m_activeBean);
      m_activeBean = null;
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  mEdit.add(mItem);

  mItem = new JMenuItem("Properties...");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      if (m_activeBean == null)
        return;
      Object obj = m_editors.get(m_activeBean);
      if (obj != null) {
        BeanEditor editor = (BeanEditor)obj;
        editor.setVisible(true);
        editor.toFront();
      }
      else {
        BeanEditor editor = new BeanEditor(m_activeBean);
        m_editors.put(m_activeBean, editor);
      }
    }
  };
  mItem.addActionListener(lst);
  mEdit.add(mItem);
  menuBar.add(mEdit);

  JMenu mLayout = new JMenu("Layout");
  ButtonGroup group = new ButtonGroup();

  mItem = new JRadioButtonMenuItem("FlowLayout");
  mItem.setSelected(true);
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e){
      getContentPane().setLayout(new FlowLayout());
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);

  mItem = new JRadioButtonMenuItem("GridLayout");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e){
      int col = 3;
      int row = (int)Math.ceil(getContentPane().
        getComponentCount()/(double)col);
      getContentPane().setLayout(new GridLayout(row, col, 10, 10));
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);
    
  mItem = new JRadioButtonMenuItem("BoxLayout - X");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      getContentPane().setLayout(new BoxLayout(
        getContentPane(), BoxLayout.X_AXIS));
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);
    
  mItem = new JRadioButtonMenuItem("BoxLayout - Y");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      getContentPane().setLayout(new BoxLayout(
        getContentPane(), BoxLayout.Y_AXIS));
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);
    
  mItem = new JRadioButtonMenuItem("DialogLayout");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      getContentPane().setLayout(new DialogLayout());
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);

  menuBar.add(mLayout);

  return menuBar;
}

From source file:com.pos.spatobiz.app.view.karyawan.UbahKaryawan.java

/** This method is called from within the constructor to
 * initialize the form.//from w  w  w .  j  a  v  a 2s  .c  o  m
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    jeniskelamin = new ButtonGroup();
    labelKode = new WhiteLabel();
    labelNama = new WhiteLabel();
    labelTanggalLahir = new WhiteLabel();
    labelAlamat = new WhiteLabel();
    textKode = new TextBoxTransfer();
    textNama = new TextBoxTransfer();
    textTanggalLahir = new DateBox();
    textAlamat = new WhiteTextArea();
    errorKode = new RedLabel();
    errorNama = new RedLabel();
    errorTanggalLahir = new RedLabel();
    errorAlamat = new RedLabel();
    textTelepon = new TextBoxTransfer();
    labelTelepon = new WhiteLabel();
    labelEmail = new WhiteLabel();
    labelJenisKelamin = new WhiteLabel();
    labelPhoto = new WhiteLabel();
    textEmail = new TextBoxTransfer();
    radioPria = new JRadioButton();
    radioWanita = new JRadioButton();
    errorTelepon = new RedLabel();
    errorEmail = new RedLabel();
    imageChooser = new ImageChooser();
    buttonBatal = new Button();
    buttonUbah = new Button();
    buttonCari = new Button();

    setBackground(new Color(0, 0, 0));

    labelKode.setHorizontalAlignment(SwingConstants.RIGHT);
    labelKode.setText("Kode :");

    labelNama.setHorizontalAlignment(SwingConstants.RIGHT);
    labelNama.setText("Nama :");

    labelTanggalLahir.setHorizontalAlignment(SwingConstants.RIGHT);
    labelTanggalLahir.setText("Tanggal Lahir :");

    labelAlamat.setHorizontalAlignment(SwingConstants.RIGHT);
    labelAlamat.setText("Alamat :");

    textTanggalLahir.setFormatterFactory(
            new DefaultFormatterFactory(new DateFormatter(DateFormat.getDateInstance(DateFormat.LONG))));
    textTanggalLahir.setPreferredSize(new Dimension(120, 24));
    textTanggalLahir.setValue(new Date());

    errorKode.setText("error kode");

    errorNama.setText("error nama");

    errorTanggalLahir.setText("error tanggal lahir");

    errorAlamat.setText("error alamat");

    labelTelepon.setHorizontalAlignment(SwingConstants.RIGHT);
    labelTelepon.setText("Telepon :");

    labelEmail.setHorizontalAlignment(SwingConstants.RIGHT);
    labelEmail.setText("Email :");

    labelJenisKelamin.setHorizontalAlignment(SwingConstants.RIGHT);
    labelJenisKelamin.setText("Jenis Kelamin :");

    labelPhoto.setHorizontalAlignment(SwingConstants.RIGHT);
    labelPhoto.setText("Photo :");

    jeniskelamin.add(radioPria);
    radioPria.setFont(new Font("Tahoma", 1, 11));
    radioPria.setForeground(new Color(255, 255, 255));
    radioPria.setSelected(true);
    radioPria.setText("Pria");
    radioPria.setOpaque(false);

    jeniskelamin.add(radioWanita);
    radioWanita.setFont(new Font("Tahoma", 1, 11));
    radioWanita.setForeground(new Color(255, 255, 255));
    radioWanita.setText("Wanita");
    radioWanita.setOpaque(false);

    errorTelepon.setText("error telepon");

    errorEmail.setText("error email");

    buttonBatal.setMnemonic('B');
    buttonBatal.setText("Batal");

    buttonUbah.setMnemonic('U');
    buttonUbah.setText("Ubah");

    buttonCari.setText("Cari");

    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING,
                    layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(Alignment.TRAILING, false)
                                    .addComponent(labelPhoto, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelJenisKelamin, Alignment.LEADING,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelEmail, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createParallelGroup(Alignment.TRAILING, false)
                                    .addComponent(labelTelepon, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelTanggalLahir, Alignment.LEADING,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelAlamat, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelNama, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelKode, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addPreferredGap(ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(Alignment.TRAILING)
                                    .addComponent(textAlamat, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 403,
                                            Short.MAX_VALUE)
                                    .addComponent(textNama, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 403,
                                            Short.MAX_VALUE)
                                    .addComponent(textTanggalLahir, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            403, Short.MAX_VALUE)
                                    .addComponent(textTelepon, GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
                                    .addGroup(Alignment.LEADING,
                                            layout.createSequentialGroup().addComponent(radioPria)
                                                    .addPreferredGap(ComponentPlacement.UNRELATED)
                                                    .addComponent(radioWanita))
                                    .addComponent(imageChooser, Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                            253, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(textEmail, GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                            .addComponent(textKode, GroupLayout.DEFAULT_SIZE, 339,
                                                    Short.MAX_VALUE)
                                            .addPreferredGap(ComponentPlacement.UNRELATED)
                                            .addComponent(buttonCari, GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                            .addGap(4, 4, 4)
                            .addGroup(layout.createParallelGroup(Alignment.LEADING)
                                    .addComponent(errorKode, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorNama, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorTanggalLahir, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorAlamat, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorTelepon, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorEmail, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                    .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(buttonUbah, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(buttonBatal,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)))
            .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelKode, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textKode, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorKode, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonCari, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelNama, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textNama, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorNama, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelTanggalLahir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textTanggalLahir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorTanggalLahir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(labelAlamat, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textAlamat, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorAlamat, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(textTelepon, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTelepon, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorTelepon, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelEmail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textEmail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorEmail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelJenisKelamin, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(radioPria).addComponent(radioWanita))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(labelPhoto, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(imageChooser, GroupLayout.PREFERRED_SIZE, 189, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(buttonBatal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonUbah, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addContainerGap()));
}

From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java

private JMenu getjTypSortMenu() {
    JMenu typSortMenu = new JMenu("Typ Sortierung");

    JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren");
    inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder());
    inOrder.addActionListener(new ActionListener() {
        @Override//from  w  w  w  . java  2  s. com
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ConfigReader.getInstance().setTypeInOrder(inOrder.isSelected());
                //                    if (kabelTypAuswahlAAS != null) {
                //                        kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected());
                //                    }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    typSortMenu.add(inOrder);
    typSortMenu.addSeparator();

    ButtonGroup group = new ButtonGroup();
    for (AbstractTypeSort aTS : ConfigReader.getInstance().getAllTypSort()) {

        JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName());
        sw.setSelected(aTS.equals(ConfigReader.getInstance().getKabeltypSort()));
        group.add(sw);
        typSortMenu.add(sw);

        sw.addActionListener(aTS);
    }
    return typSortMenu;
}

From source file:net.sf.jabref.openoffice.AutoDetectPaths.java

private boolean autoDetectPaths() {

    if (OS.WINDOWS) {
        List<File> progFiles = findProgramFilesDir();
        File sOffice = null;/* ww w .  java  2  s .c o  m*/
        List<File> sofficeFiles = new ArrayList<>();
        for (File dir : progFiles) {
            if (fileSearchCancelled) {
                return false;
            }
            sOffice = findFileDir(dir, "soffice.exe");
            if (sOffice != null) {
                sofficeFiles.add(sOffice);
            }
        }
        if (sOffice == null) {
            JOptionPane.showMessageDialog(parent, Localization.lang(
                    "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."),
                    Localization.lang("Could not find OpenOffice/LibreOffice installation"),
                    JOptionPane.INFORMATION_MESSAGE);
            JFileChooser jfc = new JFileChooser(new File("C:\\"));
            jfc.setDialogType(JFileChooser.OPEN_DIALOG);
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

                @Override
                public boolean accept(File file) {
                    return file.isDirectory();
                }

                @Override
                public String getDescription() {
                    return Localization.lang("Directories");
                }
            });
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jfc.showOpenDialog(parent);
            if (jfc.getSelectedFile() != null) {
                sOffice = jfc.getSelectedFile();
            }
        }
        if (sOffice == null) {
            return false;
        }

        if (sofficeFiles.size() > 1) {
            // More than one file found
            DefaultListModel<File> mod = new DefaultListModel<>();
            for (File tmpfile : sofficeFiles) {
                mod.addElement(tmpfile);
            }
            JList<File> fileList = new JList<>(mod);
            fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            fileList.setSelectedIndex(0);
            FormBuilder b = FormBuilder.create()
                    .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref"));
            b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1);
            b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3);
            b.add(fileList).xy(1, 5);
            int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                    Localization.lang("Choose OpenOffice/LibreOffice executable"),
                    JOptionPane.OK_CANCEL_OPTION);
            if (answer == JOptionPane.CANCEL_OPTION) {
                return false;
            } else {
                sOffice = fileList.getSelectedValue();
            }

        } else {
            sOffice = sofficeFiles.get(0);
        }
        return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe");
    } else if (OS.OS_X) {
        File rootDir = new File("/Applications");
        File[] files = rootDir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName())
                        || "LibreOffice.app".equals(file.getName()))) {
                    rootDir = file;
                    break;
                }
            }
        }
        File sOffice = findFileDir(rootDir, SOFFICE_BIN);
        if (fileSearchCancelled) {
            return false;
        }
        if (sOffice == null) {
            return false;
        } else {
            return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN);
        }
    } else {
        // Linux:
        String usrRoot = "/usr/lib";
        File inUsr = findFileDir(new File(usrRoot), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if (inUsr == null) {
            inUsr = findFileDir(new File("/usr/lib64"), SOFFICE);
            if (inUsr != null) {
                usrRoot = "/usr/lib64";
            }
        }

        if (fileSearchCancelled) {
            return false;
        }
        File inOpt = findFileDir(new File("/opt"), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if ((inUsr != null) && (inOpt == null)) {
            return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
        } else if (inOpt != null) {
            if (inUsr == null) {
                return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
            } else { // Found both
                JRadioButton optRB = new JRadioButton(inOpt.getPath(), true);
                JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false);
                ButtonGroup bg = new ButtonGroup();
                bg.add(optRB);
                bg.add(usrRB);
                FormBuilder b = FormBuilder.create()
                        .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref "));
                b.add(Localization.lang(
                        "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:"))
                        .xy(1, 1);
                b.add(optRB).xy(1, 3);
                b.add(usrRB).xy(1, 5);
                int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                        Localization.lang("Choose OpenOffice/LibreOffice executable"),
                        JOptionPane.OK_CANCEL_OPTION);
                if (answer == JOptionPane.CANCEL_OPTION) {
                    return false;
                }
                if (optRB.isSelected()) {
                    return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
                } else {
                    return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
                }
            }
        }
    }
    return false;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.GlobalViewConditionController.java

/**
 * Initialize plot options panel./*from   w ww  .j  ava  2  s.  com*/
 */
private void initPlotOptionsPanel() {
    // make new view
    plotOptionsPanel = new PlotOptionsPanel();

    // add radiobuttons to a button group
    ButtonGroup scaleAxesButtonGroup = new ButtonGroup();
    scaleAxesButtonGroup.add(plotOptionsPanel.getDoNotScaleAxesRadioButton());
    scaleAxesButtonGroup.add(plotOptionsPanel.getScaleAxesRadioButton());
    plotOptionsPanel.getDoNotScaleAxesRadioButton().setSelected(true);
    // another button group for the shifted/unshifted coordinates
    ButtonGroup shiftedCoordinatesButtonGroup = new ButtonGroup();
    shiftedCoordinatesButtonGroup.add(plotOptionsPanel.getShiftedCoordinatesRadioButton());
    shiftedCoordinatesButtonGroup.add(plotOptionsPanel.getUnshiftedCoordinatesRadioButton());
    plotOptionsPanel.getUnshiftedCoordinatesRadioButton().setSelected(true);

    /**
     * Action listeners
     */
    // do not scale axes
    plotOptionsPanel.getDoNotScaleAxesRadioButton().addActionListener((ActionEvent e) -> {
        int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem());
        boolean useRawData = plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected();
        resetPlotLogic();
        generateTrackDataHolders(trackCoordinatesController.getCurrentCondition());
        generateDataForPlots(useRawData);
        // use the data to set the charts
        setChartsWithCollections(nCols);
    });

    // scale axes to the experiment range
    plotOptionsPanel.getScaleAxesRadioButton().addActionListener((ActionEvent e) -> {
        boolean useRawData = plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected();
        coordinatesChartPanels.stream().forEach((chartPanel) -> {
            trackCoordinatesController.scaleAxesToExperiment(chartPanel.getChart(), useRawData);
        });
    });

    // shift the all coordinates to the origin
    plotOptionsPanel.getShiftedCoordinatesRadioButton().addActionListener((ActionEvent e) -> {
        int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem());
        resetPlotLogic();
        generateTrackDataHolders(trackCoordinatesController.getCurrentCondition());
        generateDataForPlots(false);
        // use the data to set the charts
        setChartsWithCollections(nCols);
    });

    // replot the unshifted coordinates
    plotOptionsPanel.getUnshiftedCoordinatesRadioButton().addActionListener((ActionEvent e) -> {
        int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem());
        resetPlotLogic();
        generateTrackDataHolders(trackCoordinatesController.getCurrentCondition());
        generateDataForPlots(true);
        // use the data to set the charts
        setChartsWithCollections(nCols);
    });

    // replot with a different number of columns
    plotOptionsPanel.getnColsComboBox().addActionListener((ActionEvent e) -> {
        int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem());
        boolean useRawData = plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected();
        resetPlotLogic();
        generateTrackDataHolders(trackCoordinatesController.getCurrentCondition());
        generateDataForPlots(useRawData);
        // use the data to set the charts
        setChartsWithCollections(nCols);
    });

    plotOptionsPanel.getPlotSettingsPanel().add(plotSettingsMenuBar, BorderLayout.CENTER);

    // add view to parent component
    trackCoordinatesController.getTrackCoordinatesPanel().getOptionsConditionParentPanel().add(plotOptionsPanel,
            gridBagConstraints);
}

From source file:net.sf.firemox.Magic.java

/**
 * Creates new form Magic//from   www . j  av  a2  s  . c  o  m
 */
private Magic() {
    super();
    initComponents();

    // list all installed Look&Feel
    UIListener uiListener = new UIListener();
    UIManager.LookAndFeelInfo[] uimTMP = UIManager.getInstalledLookAndFeels();
    final List<Pair<String, String>> lfList = new ArrayList<Pair<String, String>>();
    for (LookAndFeelInfo lookAndFeel : uimTMP) {
        Pair<String, String> info = new Pair<String, String>(lookAndFeel.getName(), lookAndFeel.getClassName());
        if (!lfList.contains(info)) {
            lfList.add(info);
        }
    }

    // list all SkinLF themes
    final File[] themes = MToolKit.getFile("lib").listFiles(new FileFilter() {
        public boolean accept(File f) {
            return f != null && f.getName().endsWith(".zip");
        }
    });

    int maxIndex = Configuration.getConfiguration().getMaxIndex("themes.skinlf.caches.cache");
    List<Pair<String, String>> knownThemes = new ArrayList<Pair<String, String>>();
    for (int i = 0; i < maxIndex + 1; i++) {
        String file = Configuration.getConfiguration()
                .getString("themes.skinlf.caches.cache(" + i + ").[@file]");
        int index = ArrayUtils.indexOf(themes, MToolKit.getFile(file));
        if (index >= 0) {
            themes[index] = null;
            Pair<String, String> skin = new Pair<String, String>(
                    Configuration.getConfiguration().getString("themes.skinlf.caches.cache(" + i + ").[@name]"),
                    file);
            knownThemes.add(skin);
            lfList.add(skin);
        }
    }

    for (File theme : themes) {
        if (theme != null) {
            // a new theme --> will be cached
            try {
                final List<Node> properties = new XmlParser().parse(new ZipResourceLoader(theme.toURI().toURL())
                        .getResourceAsStream("skinlf-themepack.xml")).getNodes("property");
                PROPERTIES: for (int j = 0; j < properties.size(); j++) {
                    if ("skin.name".equals(properties.get(j).getAttribute("name"))) {
                        // skin name found
                        String relativePath = MToolKit.getRelativePath(theme.getCanonicalPath());
                        Pair<String, String> skin = new Pair<String, String>(
                                properties.get(j).getAttribute("value"), "zip:" + relativePath);
                        lfList.add(skin);
                        knownThemes.add(new Pair<String, String>(properties.get(j).getAttribute("value"),
                                relativePath));
                        break PROPERTIES;
                    }
                }
            } catch (Exception e) {
                Log.error("Error in " + theme, e);
            }
        }
    }

    Configuration.getConfiguration().clearProperty("themes.skinlf.caches");
    for (int index = 0; index < knownThemes.size(); index++) {
        Pair<String, String> skin = knownThemes.get(index);
        Configuration.getConfiguration().setProperty("themes.skinlf.caches.cache(" + index + ").[@name]",
                skin.key);
        Configuration.getConfiguration().setProperty("themes.skinlf.caches.cache(" + index + ").[@file]",
                skin.value);
    }

    // create look and feel menu items
    Collections.sort(lfList);
    lookAndFeels = new JRadioButtonMenuItem[lfList.size() + 1];
    ButtonGroup group5 = new ButtonGroup();
    for (int i = 0; i < lfList.size(); i++) {
        final String lfName = lfList.get(i).key;
        final String lfClassName = lfList.get(i).value;
        lookAndFeels[i] = new JRadioButtonMenuItem(lfName);
        if (lookAndFeelName.equalsIgnoreCase(lfClassName)) {
            // this the current l&f
            lookAndFeels[i].setSelected(true);
        }
        if (!SkinLF.isSkinLF(lfClassName)) {
            lookAndFeels[i].setEnabled(MToolKit.isAvailableLookAndFeel(lfClassName));
        }
        group5.add(lookAndFeels[i]);
        lookAndFeels[i].setActionCommand(lfClassName);
        themeMenu.add(lookAndFeels[i], i);
        lookAndFeels[i].addActionListener(uiListener);
    }
    lfList.clear();

    initialdelayMenu.addActionListener(this);
    dismissdelayMenu.addActionListener(this);

    ConnectionManager.enableConnectingTools(false);

    // read auto mana option
    MCommonVars.autoMana = Configuration.getBoolean("automana", true);
    autoManaMenu.setSelected(MCommonVars.autoMana);

    // Force to initialize the TBS settings
    MToolKit.tbsName = null;
    setMdb(Configuration.getString("lastTBS", IdConst.TBS_DEFAULT));

    // set the autoStack mode
    MCommonVars.autoStack = Configuration.getBoolean("autostack", false);
    autoPlayMenu.setSelected(MCommonVars.autoStack);

    // read maximum displayed colored mana in context
    PayMana.thresholdColored = Configuration.getInt("threshold-colored", 6);

    ZoneManager.updateLookAndFeel();

    // pack this frame
    pack();

    // Maximize this frame
    setExtendedState(Frame.MAXIMIZED_BOTH);

    if (batchMode != -1) {

        final String deckFile = Configuration.getString(Configuration.getString("decks.deck(0)"));
        try {
            Deck batchDeck = DeckReader.getDeck(this, deckFile);
            switch (batchMode) {
            case BATCH_SERVER:
                ConnectionManager.server = new Server(batchDeck, null);
                ConnectionManager.server.start();
                break;
            case BATCH_CLIENT:
                ConnectionManager.client = new Client(batchDeck, null);
                ConnectionManager.client.start();
                break;
            default:
            }
        } catch (Throwable e) {
            throw new RuntimeException("Error in batch mode : ", e);
        }
    }
}

From source file:com.mirth.connect.connectors.doc.DocumentWriter.java

private void initComponents() {
    setBackground(UIConstants.BACKGROUND_COLOR);

    outputLabel = new JLabel("Output:");
    ButtonGroup outputButtonGroup = new ButtonGroup();

    outputFileRadioButton = new MirthRadioButton("File");
    outputFileRadioButton.setBackground(getBackground());
    outputFileRadioButton.setToolTipText("Write the contents to a file.");
    outputFileRadioButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            updateFileEnabled(true);//from   w w w  .j  av a 2s  .co m
        }
    });
    outputButtonGroup.add(outputFileRadioButton);

    outputAttachmentRadioButton = new MirthRadioButton("Attachment");
    outputAttachmentRadioButton.setBackground(getBackground());
    outputAttachmentRadioButton.setToolTipText(
            "<html>Write the contents to an attachment. The destination's response message will contain the<br>attachment Id and can be used in subsequent connectors to include the attachment.</html>");
    outputAttachmentRadioButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            updateFileEnabled(false);
        }
    });
    outputButtonGroup.add(outputAttachmentRadioButton);

    outputBothRadioButton = new MirthRadioButton("Both");
    outputBothRadioButton.setBackground(getBackground());
    outputBothRadioButton.setToolTipText(
            "<html>Write the contents to a file and an attachment. The destination's response message will contain<br>the attachment Id and can be used in subsequent connectors to include the attachment.</html>");
    outputBothRadioButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            updateFileEnabled(true);
        }
    });
    outputButtonGroup.add(outputBothRadioButton);

    directoryLabel = new JLabel("Directory:");

    directoryField = new MirthTextField();
    directoryField.setToolTipText("The directory (folder) where the generated file should be written.");

    testConnectionButton = new JButton("Test Write");
    testConnectionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            testConnection();
        }
    });

    fileNameLabel = new JLabel("File Name:");
    fileNameField = new MirthTextField();
    fileNameField.setToolTipText("The file name to give to the generated file.");

    documentTypeLabel = new JLabel("Document Type:");
    ButtonGroup documentTypeButtonGroup = new ButtonGroup();

    documentTypePDFRadio = new MirthRadioButton("PDF");
    documentTypePDFRadio.setBackground(getBackground());
    documentTypePDFRadio.setToolTipText("The type of document to be created for each message.");
    documentTypePDFRadio.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            documentTypePDFRadioActionPerformed();
        }
    });
    documentTypeButtonGroup.add(documentTypePDFRadio);

    documentTypeRTFRadio = new MirthRadioButton("RTF");
    documentTypeRTFRadio.setBackground(getBackground());
    documentTypeRTFRadio.setToolTipText("The type of document to be created for each message.");
    documentTypeRTFRadio.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            documentTypeRTFRadioActionPerformed();
        }
    });
    documentTypeButtonGroup.add(documentTypeRTFRadio);

    encryptedLabel = new JLabel("Encrypted:");
    ButtonGroup encryptedButtonGroup = new ButtonGroup();

    encryptedYesRadio = new MirthRadioButton("Yes");
    encryptedYesRadio.setBackground(getBackground());
    encryptedYesRadio.setToolTipText(
            "If Document Type PDF is selected, generated documents can optionally be encrypted.");
    encryptedYesRadio.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            encryptedYesActionPerformed();
        }
    });
    encryptedButtonGroup.add(encryptedYesRadio);

    encryptedNoRadio = new MirthRadioButton("No");
    encryptedNoRadio.setBackground(getBackground());
    encryptedNoRadio.setToolTipText(
            "If Document Type PDF is selected, generated documents can optionally be encrypted.");
    encryptedNoRadio.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            encryptedNoActionPerformed();
        }
    });
    encryptedButtonGroup.add(encryptedNoRadio);

    passwordLabel = new JLabel("Password:");
    passwordField = new MirthPasswordField();
    passwordField.setToolTipText(
            "If Encrypted Yes is selected, enter the password to be used to later view the document here.");

    pageSizeLabel = new JLabel("Page Size:");
    pageSizeXLabel = new JLabel("");

    DocumentListener pageSizeDocumentListener = new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent evt) {
            updatePageSizeComboBox();
        }

        @Override
        public void insertUpdate(DocumentEvent evt) {
            updatePageSizeComboBox();
        }

        @Override
        public void changedUpdate(DocumentEvent evt) {
            updatePageSizeComboBox();
        }
    };

    pageSizeWidthField = new MirthTextField();
    pageSizeWidthField.getDocument().addDocumentListener(pageSizeDocumentListener);
    pageSizeWidthField.setToolTipText(
            "<html>The width of the page. The units for the width<br/>are determined by the drop-down menu to the right.<br/>When rendering PDFs, a minimum of 26mm is enforced.</html>");

    pageSizeHeightField = new MirthTextField();
    pageSizeHeightField.getDocument().addDocumentListener(pageSizeDocumentListener);
    pageSizeHeightField.setToolTipText(
            "<html>The height of the page. The units for the height<br/>are determined by the drop-down menu to the right.<br/>When rendering PDFs, a minimum of 26mm is enforced.</html>");

    pageSizeUnitComboBox = new MirthComboBox<Unit>();
    pageSizeUnitComboBox.setModel(new DefaultComboBoxModel<Unit>(Unit.values()));
    pageSizeUnitComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            updatePageSizeComboBox();
        }
    });
    pageSizeUnitComboBox.setToolTipText("The units to use for the page width and height.");

    pageSizeComboBox = new MirthComboBox<PageSize>();
    pageSizeComboBox.setModel(new DefaultComboBoxModel<PageSize>(
            ArrayUtils.subarray(PageSize.values(), 0, PageSize.values().length - 1)));
    pageSizeComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            pageSizeComboBoxActionPerformed();
        }
    });
    pageSizeComboBox.setToolTipText("Select a standard page size to use, or enter a custom page size.");

    templateLabel = new JLabel("HTML Template:");
    templateTextArea = new MirthRTextScrollPane(ContextType.DESTINATION_DISPATCHER, false,
            SyntaxConstants.SYNTAX_STYLE_HTML, false);
    templateTextArea.setBorder(BorderFactory.createEtchedBorder());
}