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:org.intermine.install.swing.BuildProjectDialog.java

/**
 * Common initialisation: lays out the child components and wires up the necessary
 * event listeners.//from   w w  w  .jav  a  2 s.c  o m
 */
private void init() {

    setName("Build Project Dialog");
    setTitle(Messages.getMessage("build.project.title"));

    releaseNumberLabel.setLabelFor(releaseNumberTextField);
    destinationLabel.setLabelFor(destinationTextField);

    Container cp = getContentPane();

    GridBagConstraints cons = GridBagHelper.setup(cp);

    JLabel infoLabel = new JLabel(Messages.getMessage("build.project.info.message"));
    infoLabel.setFont(infoLabel.getFont().deriveFont(Font.PLAIN));
    cons.gridwidth = 2;
    cons.weightx = 1;
    cp.add(infoLabel, cons);

    JPanel startPolicyPanel = new JPanel();
    //        startPolicyPanel.setBorder(BorderFactory.createLoweredBevelBorder());
    GridBagConstraints startPolicyPanelCons = GridBagHelper.setup(startPolicyPanel);
    startPolicyPanelCons.gridwidth = GridBagConstraints.REMAINDER;
    startPolicyPanel.add(startPolicyLabel, startPolicyPanelCons);

    startPolicyPanelCons.gridy++;
    startPolicyPanelCons.gridwidth = 2;
    buildDbRadioButton.setFont(infoLabel.getFont().deriveFont(Font.PLAIN));
    startPolicyPanel.add(buildDbRadioButton, startPolicyPanelCons);

    startPolicyPanelCons.gridy++;
    restart1RadioButton.setFont(infoLabel.getFont().deriveFont(Font.PLAIN));
    startPolicyPanel.add(restart1RadioButton, startPolicyPanelCons);

    //        startPolicyPanelCons.gridy++;
    //        restart2RadioButton.setFont(infoLabel.getFont().deriveFont(Font.PLAIN));
    //        startPolicyPanel.add(restart2RadioButton, startPolicyPanelCons);
    //
    //        startPolicyPanelCons.gridy++;
    //        testRadioButton.setFont(infoLabel.getFont().deriveFont(Font.PLAIN));
    //        startPolicyPanel.add(testRadioButton, startPolicyPanelCons);

    cons.gridy++;
    cp.add(startPolicyPanel, cons);

    JPanel userDBPanel = new JPanel();
    //        userDBPanel.setBorder(BorderFactory.createLoweredBevelBorder());
    GridBagConstraints userDBCons = GridBagHelper.setup(userDBPanel);
    userDBPanel.setAlignmentY(LEFT_ALIGNMENT);
    //        cons.gridwidth = GridBagConstraints.REMAINDER;

    userDBPanel.add(userDBOptionsLabel, userDBCons);

    //        userDBCons.gridy++;
    //        nowriteUserDbRadio.setFont(infoLabel.getFont().deriveFont(Font.PLAIN));
    //        userDBPanel.add(nowriteUserDbRadio, userDBCons);
    //
    //        userDBCons.gridy++;
    //        writeUserDbRadio.setFont(infoLabel.getFont().deriveFont(Font.PLAIN));
    //        userDBPanel.add(writeUserDbRadio, userDBCons);
    //
    //        userDBCons.gridy++;
    //        overwriteUserDbRadio.setFont(infoLabel.getFont().deriveFont(Font.PLAIN));
    //        userDBPanel.add(overwriteUserDbRadio, userDBCons);
    //
    //        cons.gridy++;
    //        cp.add(userDBPanel, cons);

    cons.gridy++;
    cons.gridx = 0;
    cons.weightx = 0;
    cons.gridwidth = 1;
    cp.add(encodingLabel, cons);

    cons.gridx++;
    cons.weightx = 0.5;
    encodingDropdown = new JComboBox(encodings);
    cp.add(encodingDropdown, cons);
    //cp.add(encodingTextField, cons);

    //        cons.gridy++;
    //        cons.gridx = 0;
    //        cons.gridwidth = 3;
    //        cons.weightx = 1;
    //        cp.add(serverBackupCheckBox, cons);

    //        cons.gridy++;
    //        cons.gridx = 0;
    //        cons.weightx = 0;
    //        cons.gridwidth = 1;
    //        cp.add(destinationCheckBox, cons);

    //        cons.gridy++;
    //        cons.weightx = 0;
    //        cons.gridwidth = 1;
    //        cp.add(destinationLabel, cons);

    //        cons.gridx++;
    //        cons.weightx = 0.75;
    //        cons.gridwidth = 2;
    //        cp.add(destinationTextField, cons);

    cons.gridy++;
    cons.gridx = 0;
    cons.weightx = 0;
    cons.gridwidth = 1;
    cp.add(new JLabel(Messages.getMessage("build.project.dump.host")), cons);

    cons.gridx++;
    cons.weightx = 0.75;
    cons.gridwidth = 1;
    cp.add(hostTextField, cons);

    cons.gridy++;
    cons.gridx = 0;
    cons.weightx = 0;
    cons.gridwidth = 1;
    cp.add(new JLabel(Messages.getMessage("build.project.dump.prefix")), cons);

    cons.gridx++;
    cons.weightx = 0.75;
    cons.gridwidth = 1;
    cp.add(prefixTextField, cons);

    cons.gridy++;
    cons.gridx = 0;
    cp.add(releaseNumberCheckBox, cons);

    //        cons.gridy++;
    //        cons.weightx = 0;
    //        cons.gridwidth = 1;
    //        cp.add(releaseNumberLabel, cons);

    cons.gridx++;
    cons.weightx = 0.5;
    cp.add(releaseNumberTextField, cons);

    cons.gridy++;
    cons.gridwidth = GridBagConstraints.REMAINDER;
    cons.gridx = 0;
    cons.weightx = 1;
    cp.add(new ButtonPanel(buildAction, new CancelAction()), cons);

    // encodingTextField.setText("SQL_ASCII");
    //        releaseNumberLabel.setEnabled(false);
    releaseNumberTextField.setEnabled(false);
    //        destinationLabel.setEnabled(false);
    //        destinationTextField.setEnabled(false);

    /**
    * Create Button group for userdb radio buttons
    * @serial
    */
    ButtonGroup userDBButtonGroup = new ButtonGroup();
    userDBButtonGroup.add(writeUserDbRadio);
    userDBButtonGroup.add(overwriteUserDbRadio);
    userDBButtonGroup.add(nowriteUserDbRadio);

    ButtonGroup startPolicyGroup = new ButtonGroup();
    startPolicyGroup.add(restart1RadioButton);
    startPolicyGroup.add(restart2RadioButton);
    startPolicyGroup.add(buildDbRadioButton);
    startPolicyGroup.add(testRadioButton);

    releaseNumberCheckBox.addActionListener(
            new LinkedFieldListener(releaseNumberCheckBox, releaseNumberLabel, releaseNumberTextField));
    destinationCheckBox.addActionListener(
            new LinkedFieldListener(destinationCheckBox, destinationLabel, destinationTextField));

    DocumentListener requiredTextListener = new RequiredTextListener();
    releaseNumberTextField.getDocument().addDocumentListener(requiredTextListener);
    //        destinationTextField.getDocument().addDocumentListener(requiredTextListener);
    hostTextField.getDocument().addDocumentListener(requiredTextListener);
    prefixTextField.getDocument().addDocumentListener(requiredTextListener);

    hostTextField.setToolTipText(Messages.getMessage("build.project.dump.host.tooltip"));
    hostTextField.setText("localhost");

    pack();

    progressDialog = new SystemProcessProgressDialog(this);
    progressDialog.setModalityType(ModalityType.APPLICATION_MODAL);
    progressDialog.setTitle(Messages.getMessage("build.project.title"));
    progressDialog.setInformationLabel(Messages.getMessage("build.project.message"));
}

From source file:org.jab.docsearch.DocSearch.java

/**
 * Constructor/*  w w  w  .ja v  a  2s  .  co m*/
 */
public DocSearch() {
    super(I18n.getString("ds.windowtitle"));

    // get logger
    logger = Logger.getLogger(getClass().getName());

    //
    File testCDFi = new File(cdRomDefaultHome);
    Properties sys = new Properties(System.getProperties());
    if (testCDFi.exists()) {
        sys.setProperty("disableLuceneLocks", "true");
        logger.info("DocSearch() Disabling Lucene Locks for CDROM indexes");
    } else {
        sys.setProperty("disableLuceneLocks", "false");
    }

    //
    checkCDROMDir();
    defaultHndlr = getBrowserFile();
    loadSettings();

    //
    pPanel = new ProgressPanel("", 100L);
    pPanel.init();

    phrase = new JRadioButton(I18n.getString("label.phrase"));
    searchField = new JComboBox();
    searchIn = new JComboBox(searchOptsLabels);
    JLabel searchTypeLabel = new JLabel(I18n.getString("label.search_type"));
    JLabel searchInLabel = new JLabel(I18n.getString("label.search_in"));
    keywords = new JRadioButton(I18n.getString("label.keyword"));
    //
    searchLabel = new JLabel(I18n.getString("label.search_for"));
    searchButton = new JButton(I18n.getString("button.search"));
    searchButton.setActionCommand("ac_search");
    searchButton.setMnemonic(KeyEvent.VK_A);
    // TODO alt text to resource
    htmlTag = "<img src=\"" + fEnv.getIconURL(FileType.HTML.getIcon())
            + "\" border=\"0\" alt=\"Web Page Document\">";
    wordTag = "<img src=\"" + fEnv.getIconURL(FileType.MS_WORD.getIcon())
            + "\" border=\"0\" alt=\"MS Word Document\">";
    excelTag = "<img src=\"" + fEnv.getIconURL(FileType.MS_EXCEL.getIcon())
            + "\" border=\"0\" alt=\"MS Excel Document\">";
    pdfTag = "<img src=\"" + fEnv.getIconURL(FileType.PDF.getIcon()) + "\" border=\"0\" alt=\"PDF Document\">";
    textTag = "<img src=\"" + fEnv.getIconURL(FileType.TEXT.getIcon())
            + "\" border=\"0\" alt=\"Text Document\">";
    rtfTag = "<img src=\"" + fEnv.getIconURL(FileType.RTF.getIcon()) + "\" border=\"0\" alt=\"RTF Document\">";
    ooImpressTag = "<img src=\"" + fEnv.getIconURL(FileType.OO_IMPRESS.getIcon())
            + "\" border=\"0\" alt=\"OpenOffice Impress Document\">";
    ooWriterTag = "<img src=\"" + fEnv.getIconURL(FileType.OO_WRITER.getIcon())
            + "\" border=\"0\" alt=\"OpenOffice Writer Document\">";
    ooCalcTag = "<img src=\"" + fEnv.getIconURL(FileType.OO_CALC.getIcon())
            + "\" border=\"0\" alt=\"OpenOffice Calc Document\">";
    ooDrawTag = "<img src=\"" + fEnv.getIconURL(FileType.OO_DRAW.getIcon())
            + "\" border=\"0\" alt=\"OpenOffice Draw Document\">";
    openDocumentTextTag = "<img src=\"" + fEnv.getIconURL(FileType.OPENDOCUMENT_TEXT.getIcon())
            + "\" border=\"0\" alt=\"OpenDocument Text Document\">";
    //
    idx = new Index(this);
    colors = new String[2];
    colors[0] = "ffeffa";
    colors[1] = "fdffda";
    if (env.isWebStart()) {
        startPageString = getClass().getResource("/" + FileEnvironment.FILENAME_START_PAGE_WS).toString();
        helpPageString = getClass().getResource("/" + FileEnvironment.FILENAME_HELP_PAGE_WS).toString();
        if (startPageString != null) {
            logger.debug("DocSearch() Start Page is: " + startPageString);
            hasStartPage = true;
        } else {
            logger.error("DocSearch() Start Page NOT FOUND where expected: " + startPageString);
        }
    } else {
        startPageString = FileUtils.addFolder(fEnv.getStartDirectory(), FileEnvironment.FILENAME_START_PAGE);
        helpPageString = FileUtils.addFolder(fEnv.getStartDirectory(), FileEnvironment.FILENAME_HELP_PAGE);
        File startPageFile = new File(startPageString);
        if (startPageFile.exists()) {
            logger.debug("DocSearch() Start Page is: " + startPageString);
            hasStartPage = true;
        } else {
            logger.error("DocSearch() Start Page NOT FOUND where expected: " + startPageString);
        }
    }

    defaultSaveFolder = FileUtils.addFolder(fEnv.getWorkingDirectory(), "saved_searches");
    searchField.setEditable(true);
    searchField.addItem("");

    bg = new ButtonGroup();
    bg.add(phrase);
    bg.add(keywords);
    keywords.setSelected(true);

    keywords.setToolTipText(I18n.getString("tooltip.keyword"));
    phrase.setToolTipText(I18n.getString("tooltip.phrase"));

    int iconInt = 2;
    searchField.setPreferredSize(new Dimension(370, 22));

    // application icon
    Image iconImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/ds.gif"));
    this.setIconImage(iconImage);

    // menu bar
    JMenuBar menuBar = createMenuBar();
    // add menu to frame
    setJMenuBar(menuBar);

    // tool bar
    JToolBar toolbar = createToolBar();

    editorPane = new JEditorPane("text/html", lastSearch);
    editorPane.setEditable(false);
    editorPane.addHyperlinkListener(new Hyperactive());
    if (hasStartPage) {
        try {
            editorPane.setContentType("text/html");
            if (setPage("home")) {
                logger.info("DocSearch() loaded start page: " + startPageString);
            }
        } catch (Exception e) {
            editorPane.setText(lastSearch);
        }
    } else {
        logger.warn("DocSearch() no start page loaded");
    }

    scrollPane = new JScrollPane(editorPane);
    scrollPane.setPreferredSize(new Dimension(1024, 720));
    scrollPane.setMinimumSize(new Dimension(900, 670));
    scrollPane.setMaximumSize(new Dimension(1980, 1980));

    // create panels
    // add printing stuff
    vista = new JComponentVista(editorPane, new PageFormat());

    JPanel topPanel = new JPanel();
    topPanel.add(searchLabel);
    topPanel.add(searchField);
    topPanel.add(searchButton);

    JPanel bottomPanel = new JPanel();
    bottomPanel.add(searchTypeLabel);
    bottomPanel.add(keywords);
    bottomPanel.add(phrase);
    bottomPanel.add(searchInLabel);
    bottomPanel.add(searchIn);

    // GUI items for advanced searching
    useDate = new JCheckBox(I18n.getString("label.use_date_property"));
    fromField = new JTextField(11);
    JLabel fromLabel = new JLabel(I18n.getString("label.from"));
    JLabel toLabel = new JLabel(I18n.getString("label.to"));
    toField = new JTextField(11);
    cbl = new CheckBoxListener();
    authorPanel = new JPanel();
    useAuthor = new JCheckBox(I18n.getString("label.use_auth_property"));
    authorField = new JTextField(31);
    JLabel authorLabel = new JLabel(I18n.getString("label.author"));
    authorPanel.add(useAuthor);
    authorPanel.add(authorLabel);
    authorPanel.add(authorField);

    // combine stuff
    JPanel datePanel = new JPanel();
    datePanel.add(useDate);
    datePanel.add(fromLabel);
    datePanel.add(fromField);
    datePanel.add(toLabel);
    datePanel.add(toField);

    JPanel metaPanel = new JPanel();
    metaPanel.setLayout(new BorderLayout());
    metaPanel.setBorder(new TitledBorder(I18n.getString("label.date_and_author")));
    metaPanel.add(datePanel, BorderLayout.NORTH);
    metaPanel.add(authorPanel, BorderLayout.SOUTH);

    useDate.addActionListener(cbl);
    useAuthor.addActionListener(cbl);

    fromField.setText(DateTimeUtils.getLastYear());
    toField.setText(DateTimeUtils.getToday());
    authorField.setText(System.getProperty("user.name"));

    JPanel[] panels = new JPanel[numPanels];
    for (int i = 0; i < numPanels; i++) {
        panels[i] = new JPanel();
    }

    // add giu to panels
    panels[0].setLayout(new BorderLayout());
    panels[0].add(topPanel, BorderLayout.NORTH);
    panels[0].add(bottomPanel, BorderLayout.SOUTH);
    panels[0].setBorder(new TitledBorder(I18n.getString("label.search_critera")));
    searchButton.addActionListener(this);

    JPanel fileTypePanel = new JPanel();
    useType = new JCheckBox(I18n.getString("label.use_filetype_property"));
    useType.addActionListener(cbl);
    fileType = new JComboBox(fileTypesToFindLabel);
    JLabel fileTypeLabel = new JLabel(I18n.getString("label.find_only_these_filetypes"));
    fileTypePanel.add(useType);
    fileTypePanel.add(fileTypeLabel);
    fileTypePanel.add(fileType);

    JPanel sizePanel = new JPanel();
    useSize = new JCheckBox(I18n.getString("label.use_filesize_property"));
    useSize.addActionListener(cbl);
    // TODO l18n kbytes
    JLabel sizeFromLabel = new JLabel(I18n.getString("label.from") + " KByte");
    JLabel sizeToLabel = new JLabel(I18n.getString("label.to") + " KByte");
    sizeFromField = new JTextField(10);
    sizeFromField.setText("0");
    sizeToField = new JTextField(10);
    sizeToField.setText("100");
    sizePanel.add(useSize);
    sizePanel.add(sizeFromLabel);
    sizePanel.add(sizeFromField);
    sizePanel.add(sizeToLabel);
    sizePanel.add(sizeToField);

    JPanel sizeAndTypePanel = new JPanel();
    sizeAndTypePanel.setLayout(new BorderLayout());
    sizeAndTypePanel.setBorder(new TitledBorder(I18n.getString("label.filetype_and_size")));
    sizeAndTypePanel.add(fileTypePanel, BorderLayout.NORTH);
    sizeAndTypePanel.add(sizePanel, BorderLayout.SOUTH);

    // set up the tabbed pane
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab(I18n.getString("label.general"), null, panels[0],
            I18n.getString("tooltip.general_search_criteria"));
    tabbedPane.addTab(I18n.getString("label.date_and_author"), null, metaPanel,
            I18n.getString("tooltip.date_auth_options"));
    tabbedPane.addTab(I18n.getString("label.filetype_and_size"), null, sizeAndTypePanel,
            I18n.getString("tooltip.filetype_and_size_options"));

    // gridbag
    getContentPane().setLayout(new GridLayout(1, numPanels + iconInt + 1));
    GridBagLayout gridbaglayout = new GridBagLayout();
    GridBagConstraints gridbagconstraints = new GridBagConstraints();
    getContentPane().setLayout(gridbaglayout);

    gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
    gridbagconstraints.insets = new Insets(1, 1, 1, 1);
    gridbagconstraints.gridx = 0;
    gridbagconstraints.gridy = 0;
    gridbagconstraints.gridwidth = 1;
    gridbagconstraints.gridheight = 1;
    gridbagconstraints.weightx = 1.0D;
    gridbagconstraints.weighty = 0.0D;
    gridbaglayout.setConstraints(toolbar, gridbagconstraints);
    getContentPane().add(toolbar);

    int start = 1;
    for (int i = 0; i < numPanels; i++) {
        if (i == 0) {
            gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
            gridbagconstraints.insets = new Insets(1, 1, 1, 1);
            gridbagconstraints.gridx = 0;
            gridbagconstraints.gridy = i + start;
            gridbagconstraints.gridwidth = 1;
            gridbagconstraints.gridheight = 1;
            gridbagconstraints.weightx = 1.0D;
            gridbagconstraints.weighty = 0.0D;
            gridbaglayout.setConstraints(tabbedPane, gridbagconstraints);
            getContentPane().add(tabbedPane);
        } else {
            gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
            gridbagconstraints.insets = new Insets(1, 1, 1, 1);
            gridbagconstraints.gridx = 0;
            gridbagconstraints.gridy = i + start;
            gridbagconstraints.gridwidth = 1;
            gridbagconstraints.gridheight = 1;
            gridbagconstraints.weightx = 1.0D;
            gridbagconstraints.weighty = 0.0D;
            gridbaglayout.setConstraints(panels[i], gridbagconstraints);
            getContentPane().add(panels[i]);
        }
    }

    // now add the results area
    gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
    gridbagconstraints.insets = new Insets(1, 1, 1, 1);
    gridbagconstraints.gridx = 0;
    gridbagconstraints.gridy = iconInt;
    gridbagconstraints.gridwidth = 1;
    gridbagconstraints.gridheight = 1;
    gridbagconstraints.weightx = 1.0D;
    gridbagconstraints.weighty = 1.0D;
    gridbaglayout.setConstraints(scrollPane, gridbagconstraints);
    getContentPane().add(scrollPane);
    JPanel statusP = new JPanel();
    statusP.setLayout(new BorderLayout());
    statusP.add(dirLabel, BorderLayout.WEST);
    statusP.add(pPanel, BorderLayout.EAST);

    // now add the status label
    gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
    gridbagconstraints.insets = new Insets(1, 1, 1, 1);
    gridbagconstraints.gridx = 0;
    gridbagconstraints.gridy = numPanels + iconInt;
    gridbagconstraints.gridwidth = 1;
    gridbagconstraints.gridheight = 1;
    gridbagconstraints.weightx = 1.0D;
    gridbagconstraints.weighty = 0.0D;
    gridbaglayout.setConstraints(statusP, gridbagconstraints);
    getContentPane().add(statusP);

    //
    File testArchDir = new File(fEnv.getArchiveDirectory());
    if (!testArchDir.exists()) {
        boolean madeDir = testArchDir.mkdir();
        if (!madeDir) {
            logger.warn("DocSearch() Error creating directory: " + fEnv.getArchiveDirectory());
        } else {
            logger.info("DocSearch() Directory created: " + fEnv.getArchiveDirectory());
        }
    }
    loadIndexes();

    // DocTypeHandler
    String handlersFiName;
    if (!isCDSearchTool) {
        handlersFiName = FileUtils.addFolder(fEnv.getWorkingDirectory(), DocTypeHandlerUtils.HANDLER_FILE);
    } else {
        handlersFiName = FileUtils.addFolder(cdRomDefaultHome, DocTypeHandlerUtils.HANDLER_FILE);
    }
    DocTypeHandlerUtils dthUtils = new DocTypeHandlerUtils();
    if (!FileUtils.fileExists(handlersFiName)) {
        logger.warn("DocSearch() Handlers file not found at: " + handlersFiName);
        handlerList = dthUtils.getInitialHandler(env);
    } else {
        handlerList = dthUtils.loadHandler(handlersFiName);
    }
}

From source file:org.jab.docsearch.DocSearch.java

/**
 * Creates menu bar//from  ww  w. j  av  a2  s .  c o  m
 *
 * @param menuBar  Menu bar
 */
private JMenuBar createMenuBar() {

    // menu bar
    JMenuBar menuBar = new JMenuBar();

    // ----- menu file

    // menu item print
    JMenuItem menuItemPrint = new JMenuItem(I18n.getString("menuitem.print"));
    menuItemPrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK));
    menuItemPrint.setActionCommand("ac_print");
    menuItemPrint.addActionListener(this);

    // scale X
    JRadioButtonMenuItem scaleXRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_width"));
    scaleXRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));
    scaleXRadioBut.addActionListener(new ScaleXListener());
    // scale Y
    JRadioButtonMenuItem scaleYRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_length"));
    scaleYRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK));
    scaleYRadioBut.addActionListener(new ScaleYListener());
    // scale fit
    JRadioButtonMenuItem scaleFitRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_to_fit"));
    scaleFitRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK));
    scaleFitRadioBut.addActionListener(new ScaleFitListener());
    // scale half
    JRadioButtonMenuItem scaleHalfRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_half"));
    scaleHalfRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK));
    scaleHalfRadioBut.addActionListener(new ScaleHalfListener());
    // scale double
    JRadioButtonMenuItem scale2RadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_2x"));
    scale2RadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
    scale2RadioBut.addActionListener(new Scale2Listener());
    // scale off
    JRadioButtonMenuItem scaleOffRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_off"), true);
    scaleOffRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));

    ButtonGroup scaleSetGroup = new ButtonGroup();
    scaleSetGroup.add(scale2RadioBut);
    scaleSetGroup.add(scaleFitRadioBut);
    scaleSetGroup.add(scaleHalfRadioBut);
    scaleSetGroup.add(scaleOffRadioBut);
    scaleSetGroup.add(scaleXRadioBut);
    scaleSetGroup.add(scaleYRadioBut);

    // build complete menu print preferences
    JMenu menuPrintPref = new JMenu(I18n.getString("menuitem.print_preferences"), true);
    menuPrintPref.add(scaleXRadioBut);
    menuPrintPref.add(scaleYRadioBut);
    menuPrintPref.add(scaleFitRadioBut);
    menuPrintPref.add(scaleHalfRadioBut);
    menuPrintPref.add(scale2RadioBut);
    menuPrintPref.addSeparator();
    menuPrintPref.add(scaleOffRadioBut);

    // menu item exit
    JMenuItem menuItemExit = new JMenuItem(I18n.getString("menuitem.exit"));
    menuItemExit.setActionCommand("ac_exit");
    menuItemExit.addActionListener(this);

    // build complete menu file
    JMenu menuFile = new JMenu(I18n.getString("menu.file"));
    menuFile.add(menuItemPrint);
    menuFile.add(menuPrintPref);
    menuFile.addSeparator();
    menuFile.add(menuItemExit);

    // add menu to menu bar
    menuBar.add(menuFile);

    // ----- menu index

    // menu item new
    JMenuItem menuItemNewIndex = new JMenuItem(I18n.getString("menuitem.new_index"));
    menuItemNewIndex.setActionCommand("ac_newindex");
    menuItemNewIndex.addActionListener(this);
    // menu item new spider
    JMenuItem menuItemNewSpiderIndex = new JMenuItem(I18n.getString("menuitem.new_spider_index"));
    menuItemNewSpiderIndex.setActionCommand("ac_newspiderindex");
    menuItemNewSpiderIndex.addActionListener(this);
    // menu item manage
    JMenuItem menuItemManageIndex = new JMenuItem(I18n.getString("menuitem.manage_indexes"));
    menuItemManageIndex.setActionCommand("ac_manageindex");
    menuItemManageIndex.addActionListener(this);
    // menu item rebuild
    JMenuItem menuItemRebuildIndex = new JMenuItem(I18n.getString("menuitem.rebuild_all_indexes"));
    menuItemRebuildIndex.setActionCommand("ac_rebuildindexes");
    menuItemRebuildIndex.addActionListener(this);
    // menu item import
    JMenuItem menuItemImportIndex = new JMenuItem(I18n.getString("menuitem.import_index"));
    menuItemImportIndex.setActionCommand("ac_importindex");
    menuItemImportIndex.addActionListener(this);

    // build complete menu index
    JMenu indexMenu = new JMenu(I18n.getString("menu.index"));
    indexMenu.add(menuItemNewIndex);
    indexMenu.add(menuItemNewSpiderIndex);
    indexMenu.add(menuItemManageIndex);
    indexMenu.add(menuItemRebuildIndex);
    indexMenu.addSeparator();
    indexMenu.add(menuItemImportIndex);

    // add menu to menu bar
    menuBar.add(indexMenu);

    // ----- menu bookmark

    // menu item add
    JMenuItem menuItemAddBookmark = new JMenuItem(I18n.getString("menuitem.add_bookmark"));
    menuItemAddBookmark.setActionCommand("ac_addbookmark");
    menuItemAddBookmark.addActionListener(this);
    // menu item delete all
    JMenuItem menuItemDeleteAll = new JMenuItem(I18n.getString("menuitem.delete_all_bookmarks"));
    menuItemDeleteAll.setActionCommand("ac_deleteallbookmarks");
    menuItemDeleteAll.addActionListener(this);

    // build complete menu index
    bookMarkMenu = new JMenu(I18n.getString("menu.bookmarks"));
    bookMarkMenu.add(menuItemAddBookmark);
    bookMarkMenu.add(menuItemDeleteAll);
    bookMarkMenu.addSeparator();

    // add menu to menu bar
    menuBar.add(bookMarkMenu);

    // ----- menu report

    // menu item metadata report
    JMenuItem menuItemMetadataReport = new JMenuItem(I18n.getString("menuitem.metadata_report"));
    menuItemMetadataReport.setActionCommand("ac_metadata_report");
    menuItemMetadataReport.addActionListener(this);
    // menu item servlet report
    JMenuItem menuItemServletReport = new JMenuItem(I18n.getString("menuitem.servlet_log_report"));
    menuItemServletReport.setActionCommand("ac_servlet_log_report");
    menuItemServletReport.addActionListener(this);

    // build complete menu report
    JMenu reportMenu = new JMenu(I18n.getString("menu.reports"));
    reportMenu.add(menuItemMetadataReport);
    reportMenu.add(menuItemServletReport);

    // add menu to menu bar
    menuBar.add(reportMenu);

    // ----- menu tools

    // menu item makr cd
    JMenuItem menuItemMakeCD = new JMenuItem(I18n.getString("menuitem.make_cd"));
    menuItemMakeCD.setActionCommand("ac_makecd");
    menuItemMakeCD.addActionListener(this);
    // menu item setting
    JMenuItem menuItemSetting = new JMenuItem(I18n.getString("menuitem.settings"));
    menuItemSetting.setActionCommand("ac_settings");
    menuItemSetting.addActionListener(this);

    // build complete menu report
    JMenu menuTool = new JMenu(I18n.getString("menu.tools"));
    menuTool.add(menuItemMakeCD);
    menuTool.addSeparator();
    menuTool.add(menuItemSetting);

    // add menu to menu bar
    menuBar.add(menuTool);

    // ----- menu help

    // menu item search tip
    JMenuItem menuItemSearchTip = new JMenuItem(I18n.getString("menuitem.search_tips"));
    menuItemSearchTip.setActionCommand("ac_search_tips");
    menuItemSearchTip.addActionListener(this);
    // menu item about
    JMenuItem menuItemAbout = new JMenuItem(I18n.getString("menuitem.about"));
    menuItemAbout.setActionCommand("ac_about");
    menuItemAbout.addActionListener(this);

    // build complete menu help
    JMenu menuHelp = new JMenu(I18n.getString("menu.help"));
    menuHelp.add(menuItemSearchTip);
    menuHelp.add(menuItemAbout);

    // add menu to menu bar
    menuBar.add(menuHelp);

    // finished
    return menuBar;
}

From source file:org.jcurl.demo.tactics.BroomPromptSwingBean.java

public BroomPromptSwingBean() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    final Box b = Box.createVerticalBox();
    {/*  w  w  w.  j a  va  2  s  .c om*/
        final JPanel tb = new JPanel();
        tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS));
        tb.setBorder(BorderFactory.createTitledBorder("Active"));
        tb.add(rock = new JComboBox(new Object[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
        rock.setPrototypeDisplayValue(8);
        rock.addItemListener(this);
        dark = new JRadioButton("dark");
        dark.addActionListener(this);
        light = new JRadioButton("light");
        light.addActionListener(this);
        final ButtonGroup bg = new ButtonGroup();
        bg.add(dark);
        bg.add(light);
        tb.add(dark);
        tb.add(light);
        b.add(tb);
    }
    {
        final JPanel tb = new JPanel();
        tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS));
        tb.setBorder(BorderFactory.createTitledBorder("Handle"));
        in = new JRadioButton("In Turn");
        in.addActionListener(this);
        out = new JRadioButton("Out Turn");
        out.addActionListener(this);
        final ButtonGroup bg = new ButtonGroup();
        bg.add(in);
        bg.add(out);
        tb.add(out);
        tb.add(in);
        tb.add(Box.createHorizontalGlue());
        b.add(tb);
    }
    {
        final JPanel tb = new JPanel();
        tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS));
        tb.setBorder(BorderFactory.createTitledBorder("Split Time"));

        if (UseJSpinnerBoundedRange) {
            split2 = new JSpinnerBoundedRange();
            split2.addFocusListener(this);
            split = null;
        } else {
            split2 = null;
            split = new JSpinner();
            // log.info(split.getEditor().getClass().getName());
            split.addFocusListener(this);
            final JSpinner.NumberEditor ed = (JSpinner.NumberEditor) split.getEditor();
            ed.addFocusListener(this);
            ed.getTextField().addFocusListener(this);
        }

        tb.add(split2);

        tb.add(dt = new JComboBox(new Object[] { "1/1000 sec", "1/100 sec", "1/10 sec", "sec" }));
        tb.add(Box.createHorizontalGlue());
        b.add(tb);
        dt.setEnabled(false);
    }
    {
        final JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
        p.setBorder(BorderFactory.createTitledBorder("Broom Position"));
        {
            x = new JSpinnerNumberUnit();
            x.setLabel("x: ");
            x.setBase(Unit.METER);
            x.setChoose(Unit.FOOT, Unit.INCH, Unit.CENTIMETER, Unit.METER);
            x.setModel(new SpinnerNumberModel(0.0, -IceSize.SIDE_2_CENTER, IceSize.SIDE_2_CENTER, 0.1));
            x.addChangeListener(this);
            x.addPropertyChangeListener(this);
            p.add(x);
        }
        {
            y = new JSpinnerNumberUnit();
            y.setLabel("y: ");
            y.setBase(Unit.METER);
            y.setChoose(Unit.FOOT, Unit.INCH, Unit.CENTIMETER, Unit.METER);
            y.setModel(new SpinnerNumberModel(0.0, -IceSize.BACK_2_TEE, IceSize.HOG_2_TEE, 0.1));
            y.addChangeListener(this);
            y.addPropertyChangeListener(this);
            p.add(y);
        }
        b.add(p);
    }
    this.add(b);
}

From source file:org.jets3t.apps.cockpit.gui.StartupDialog.java

/**
 * Initialises all GUI elements.//from ww  w.  j a v a  2  s .c om
 */
private void initGui() {
    this.setResizable(false);
    this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);

    cancelButton = new JButton("Don't log in");
    cancelButton.setActionCommand("Cancel");
    cancelButton.addActionListener(this);
    storeCredentialsButton = new JButton("Store Credentials");
    storeCredentialsButton.setActionCommand("StoreCredentials");
    storeCredentialsButton.addActionListener(this);
    okButton = new JButton("Log in");
    okButton.setActionCommand("LogIn");
    okButton.addActionListener(this);

    // Set default ENTER and ESCAPE buttons.
    this.getRootPane().setDefaultButton(okButton);
    this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"),
            "ESCAPE");
    this.getRootPane().getActionMap().put("ESCAPE", new AbstractAction() {
        private static final long serialVersionUID = -1742280851624947873L;

        public void actionPerformed(ActionEvent actionEvent) {
            setVisible(false);
        }
    });

    JPanel buttonsPanel = new JPanel(new GridBagLayout());
    buttonsPanel.add(cancelButton, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, insetsZero, 0, 0));
    buttonsPanel.add(storeCredentialsButton, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.EAST,
            GridBagConstraints.NONE, insetsZero, 0, 0));
    buttonsPanel.add(okButton, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.NONE, insetsZero, 0, 0));

    loginPassphrasePanel = new LoginPassphrasePanel(hyperlinkListener);
    loginLocalFolderPanel = new LoginLocalFolderPanel(ownerFrame, hyperlinkListener);
    loginCredentialsPanel = new LoginCredentialsPanel(false, hyperlinkListener);

    // Target storage service selection
    targetS3 = new JRadioButton("Amazon S3");
    targetS3.setSelected(true);
    targetGS = new JRadioButton("Google Storage");

    ButtonGroup targetButtonGroup = new ButtonGroup();
    targetButtonGroup.add(targetS3);
    targetButtonGroup.add(targetGS);

    JPanel targetServicePanel = new JPanel(new GridBagLayout());
    targetServicePanel.add(targetS3, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.EAST,
            GridBagConstraints.NONE, insetsZero, 0, 0));
    targetServicePanel.add(targetGS, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, insetsZero, 0, 0));

    // Tabbed Pane.
    tabbedPane = new JTabbedPane();
    tabbedPane.addChangeListener(this);
    tabbedPane.add(loginPassphrasePanel, "Online");
    tabbedPane.add(loginLocalFolderPanel, "Local Folder");
    tabbedPane.add(loginCredentialsPanel, "Direct Login");

    int row = 0;
    this.getContentPane().setLayout(new GridBagLayout());
    this.getContentPane().add(targetServicePanel, new GridBagConstraints(0, row++, 2, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    this.getContentPane().add(tabbedPane, new GridBagConstraints(0, row++, 2, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0));
    this.getContentPane().add(buttonsPanel, new GridBagConstraints(0, row++, 2, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

    this.pack();
    this.setSize(500, 430);
    this.setLocationRelativeTo(this.getOwner());
}

From source file:org.jets3t.apps.cockpitlite.ToggleAclDialog.java

/**
 * Initialises all GUI elements./*from  www.j  av a 2 s  . co m*/
 */
private void initGui() {
    // Initialise skins factory.
    skinsFactory = SkinsFactory.getInstance(applicationProperties);

    // Set Skinned Look and Feel.
    LookAndFeel lookAndFeel = skinsFactory.createSkinnedMetalTheme("SkinnedLookAndFeel");
    try {
        UIManager.setLookAndFeel(lookAndFeel);
    } catch (UnsupportedLookAndFeelException e) {
        log.error("Unable to set skinned LookAndFeel", e);
    }

    this.setResizable(false);
    this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);

    JHtmlLabel messageLabel = skinsFactory.createSkinnedJHtmlLabel("ToggleAclDialogMessage", hyperlinkListener);
    messageLabel.setText("File privacy setting:");
    messageLabel.setHorizontalAlignment(JLabel.CENTER);

    privateRadioButton = skinsFactory.createSkinnedJRadioButton("ToggleAclDialogPrivateRadioButton");
    privateRadioButton.setText("Private file");
    publicRadioButton = skinsFactory.createSkinnedJRadioButton("ToggleAclDialogPublicRadioButton");
    publicRadioButton.setText("Public file");
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(privateRadioButton);
    buttonGroup.add(publicRadioButton);

    publicRadioButton.setSelected(isPublicObject);
    privateRadioButton.setSelected(!isPublicObject);

    JButton okButton = skinsFactory.createSkinnedJButton("ToggleAclDialogOkButton");
    okButton.setName("OK");
    okButton.setText("OK");
    okButton.addActionListener(this);
    this.getRootPane().setDefaultButton(okButton);

    JPanel buttonsPanel = skinsFactory.createSkinnedJPanel("ToggleAclDialogButtonsPanel");
    buttonsPanel.setLayout(new GridBagLayout());
    buttonsPanel.add(privateRadioButton, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));
    buttonsPanel.add(publicRadioButton, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));
    buttonsPanel.add(okButton, new GridBagConstraints(0, 1, 2, 1, 1, 0, GridBagConstraints.CENTER,
            GridBagConstraints.NONE, insetsZero, 0, 0));

    int row = 0;
    this.getContentPane().setLayout(new GridBagLayout());
    this.getContentPane().add(messageLabel, new GridBagConstraints(0, row++, 1, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsDefault, 0, 0));
    this.getContentPane().add(buttonsPanel, new GridBagConstraints(0, row++, 1, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

    this.pack();
    this.setLocationRelativeTo(this.getOwner());
}

From source file:org.jets3t.gui.UserInputFields.java

/**
 * Builds a user input panel matching the fields specified in the uploader.properties file.
 *
 * @param fieldsPanel//from ww  w  .j a va  2  s  .c om
 * the panel component to add prompt and user input components to.
 * @param uploaderProperties
 * properties specific to the Uploader application that includes the field.* settings
 * necessary to build the User Inputs screen.
 *
 * @return
 * true if there is at least one valid user input field, false otherwise.
 */
public boolean buildFieldsPanel(JPanel fieldsPanel, Jets3tProperties uploaderProperties) {
    int fieldIndex = 0;

    for (int fieldNo = 0; fieldNo < 100; fieldNo++) {
        String fieldName = uploaderProperties.getStringProperty("field." + fieldNo + ".name", null);
        String fieldType = uploaderProperties.getStringProperty("field." + fieldNo + ".type", null);
        String fieldPrompt = uploaderProperties.getStringProperty("field." + fieldNo + ".prompt", null);
        String fieldOptions = uploaderProperties.getStringProperty("field." + fieldNo + ".options", null);
        String fieldDefault = uploaderProperties.getStringProperty("field." + fieldNo + ".default", null);

        if (fieldName == null) {
            log.debug("No field with index number " + fieldNo);
            continue;
        } else {
            if (fieldType == null || fieldPrompt == null) {
                log.warn("Field '" + fieldName + "' missing .type or .prompt properties");
                continue;
            }

            if ("message".equals(fieldType)) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
            } else if ("radio".equals(fieldType)) {
                if (fieldOptions == null) {
                    log.warn(
                            "Radio button field '" + fieldName + "' is missing the required .options property");
                    continue;
                }

                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                JPanel optionsPanel = skinsFactory.createSkinnedJPanel("OptionsPanel");
                optionsPanel.setLayout(new GridBagLayout());
                int columnOffset = 0;
                ButtonGroup buttonGroup = new ButtonGroup();
                StringTokenizer st = new StringTokenizer(fieldOptions, ",");
                while (st.hasMoreTokens()) {
                    String option = st.nextToken();
                    JRadioButton radioButton = skinsFactory.createSkinnedJRadioButton(fieldName);
                    radioButton.setText(option);
                    buttonGroup.add(radioButton);

                    if (fieldDefault != null && fieldDefault.equals(option)) {
                        // This option is the default one.
                        radioButton.setSelected(true);
                    } else if (buttonGroup.getButtonCount() == 1) {
                        // Make first button the default.
                        radioButton.setSelected(true);
                    }

                    optionsPanel.add(radioButton, new GridBagConstraints(columnOffset++, 0, 1, 1, 0, 0,
                            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
                }
                fieldsPanel.add(optionsPanel, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.NONE, insetsNone, 0, 0));

                userInputComponentsMap.put(fieldName, buttonGroup);
            } else if ("selection".equals(fieldType)) {
                if (fieldOptions == null) {
                    log.warn(
                            "Radio button field '" + fieldName + "' is missing the required .options property");
                    continue;
                }

                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                JComboBox comboBox = skinsFactory.createSkinnedJComboBox(fieldName);
                StringTokenizer st = new StringTokenizer(fieldOptions, ",");
                while (st.hasMoreTokens()) {
                    String option = st.nextToken();
                    comboBox.addItem(option);
                }

                if (fieldDefault != null) {
                    comboBox.setSelectedItem(fieldDefault);
                }

                fieldsPanel.add(comboBox, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, comboBox);
            } else if ("text".equals(fieldType)) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
                JTextField textField = skinsFactory.createSkinnedJTextField(fieldName);
                if (fieldDefault != null) {
                    textField.setText(fieldDefault);
                }

                fieldsPanel.add(textField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, textField);
            } else if ("password".equals(fieldType)) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
                JPasswordField passwordField = skinsFactory.createSkinnedJPasswordField(fieldName);
                if (fieldDefault != null) {
                    passwordField.setText(fieldDefault);
                }

                fieldsPanel.add(passwordField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, passwordField);
            } else if (fieldType.equals("textarea")) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 2, 1, 0, 0,
                        GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
                JTextArea textArea = skinsFactory.createSkinnedJTextArea(fieldName);
                textArea.setLineWrap(true);
                if (fieldDefault != null) {
                    textArea.setText(fieldDefault);
                }

                JScrollPane scrollPane = skinsFactory.createSkinnedJScrollPane(fieldName);
                scrollPane.setViewportView(textArea);
                fieldsPanel.add(scrollPane, new GridBagConstraints(0, fieldIndex++, 2, 1, 1, 1,
                        GridBagConstraints.WEST, GridBagConstraints.BOTH, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, textArea);
            } else {
                log.warn("Unrecognised .type setting for field '" + fieldName + "'");
            }
        }
    }

    return isUserInputFieldsAvailable();
}

From source file:org.languagetool.gui.ConfigurationDialog.java

private void createOfficeElements(GridBagConstraints cons, JPanel portPanel) {
    int numParaCheck = config.getNumParasToCheck();
    JRadioButton[] radioButtons = new JRadioButton[3];
    ButtonGroup numParaGroup = new ButtonGroup();
    radioButtons[0] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckOnlyParagraph")));
    radioButtons[0].setActionCommand("ParagraphCheck");

    radioButtons[1] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckFullText")));
    radioButtons[1].setActionCommand("FullTextCheck");

    radioButtons[2] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckNumParagraphs")));
    radioButtons[2].setActionCommand("NParagraphCheck");
    radioButtons[2].setSelected(true);/*from www.  j  a v  a  2 s  .  co m*/

    JTextField numParaField = new JTextField(Integer.toString(5), 2);
    numParaField.setEnabled(radioButtons[2].isSelected());
    numParaField.setMinimumSize(new Dimension(30, 25));

    for (int i = 0; i < 3; i++) {
        numParaGroup.add(radioButtons[i]);
    }

    if (numParaCheck == 0) {
        radioButtons[0].setSelected(true);
        numParaField.setEnabled(false);
    } else if (numParaCheck < 0) {
        radioButtons[1].setSelected(true);
        numParaField.setEnabled(false);
    } else {
        radioButtons[2].setSelected(true);
        numParaField.setText(Integer.toString(numParaCheck));
        numParaField.setEnabled(true);
    }

    radioButtons[0].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            numParaField.setEnabled(false);
            config.setNumParasToCheck(0);
        }
    });

    radioButtons[1].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            numParaField.setEnabled(false);
            config.setNumParasToCheck(-1);
        }
    });

    radioButtons[2].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int numParaCheck = Integer.parseInt(numParaField.getText());
            if (numParaCheck < 1)
                numParaCheck = 1;
            else if (numParaCheck > 99)
                numParaCheck = 99;
            config.setNumParasToCheck(numParaCheck);
            numParaField.setForeground(Color.BLACK);
            numParaField.setText(Integer.toString(numParaCheck));
            numParaField.setEnabled(true);
        }
    });

    numParaField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            try {
                int numParaCheck = Integer.parseInt(numParaField.getText());
                if (numParaCheck > 0 && numParaCheck < 99) {
                    numParaField.setForeground(Color.BLACK);
                    config.setNumParasToCheck(numParaCheck);
                } else {
                    numParaField.setForeground(Color.RED);
                }
            } catch (NumberFormatException ex) {
                numParaField.setForeground(Color.RED);
            }
        }
    });

    JLabel textChangedLabel = new JLabel(Tools.getLabel(messages.getString("guiTextChangeLabel")));
    cons.gridy++;
    portPanel.add(textChangedLabel, cons);

    cons.gridy++;
    cons.insets = new Insets(0, 30, 0, 0);
    for (int i = 0; i < 3; i++) {
        portPanel.add(radioButtons[i], cons);
        if (i < 2)
            cons.gridy++;
    }
    cons.gridx = 1;
    portPanel.add(numParaField, cons);

    JCheckBox noMultiResetbox = new JCheckBox(Tools.getLabel(messages.getString("guiNoMultiReset")));
    noMultiResetbox.setSelected(config.isNoMultiReset());
    noMultiResetbox.setEnabled(config.isResetCheck());
    noMultiResetbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setNoMultiReset(noMultiResetbox.isSelected());
        }
    });

    JCheckBox resetCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiDoResetCheck")));
    resetCheckbox.setSelected(config.isResetCheck());
    resetCheckbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setDoResetCheck(resetCheckbox.isSelected());
            noMultiResetbox.setEnabled(resetCheckbox.isSelected());
        }
    });
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    //    JLabel dummyLabel = new JLabel(" ");
    //    cons.gridy++;
    //    portPanel.add(dummyLabel, cons);
    cons.gridy++;
    portPanel.add(resetCheckbox, cons);

    cons.insets = new Insets(0, 30, 0, 0);
    cons.gridx = 0;
    cons.gridy++;
    portPanel.add(noMultiResetbox, cons);

    JCheckBox fullTextCheckAtFirstBox = new JCheckBox(
            Tools.getLabel(messages.getString("guiCheckFullTextAtFirst")));
    fullTextCheckAtFirstBox.setSelected(config.doFullCheckAtFirst());
    fullTextCheckAtFirstBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setFullCheckAtFirst(fullTextCheckAtFirstBox.isSelected());
        }
    });
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    //    cons.gridy++;
    //    JLabel dummyLabel2 = new JLabel(" ");
    //    portPanel.add(dummyLabel2, cons);
    cons.gridy++;
    portPanel.add(fullTextCheckAtFirstBox, cons);

    JCheckBox isMultiThreadBox = new JCheckBox(Tools.getLabel(messages.getString("guiIsMultiThread")));
    isMultiThreadBox.setSelected(config.isMultiThread());
    isMultiThreadBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setMultiThreadLO(isMultiThreadBox.isSelected());
        }
    });
    cons.gridy++;
    JLabel dummyLabel3 = new JLabel(" ");
    portPanel.add(dummyLabel3, cons);
    cons.gridy++;
    portPanel.add(isMultiThreadBox, cons);

}

From source file:org.languagetool.gui.ConfigurationDialog.java

@NotNull
private JPanel getMotherTonguePanel(GridBagConstraints cons) {
    JPanel motherTonguePanel = new JPanel();
    if (insideOffice) {
        motherTonguePanel.setLayout(new GridBagLayout());
        GridBagConstraints cons1 = new GridBagConstraints();
        cons1.insets = new Insets(0, 0, 0, 0);
        cons1.gridx = 0;// ww w.  j  a  va2s .co  m
        cons1.gridy = 0;
        cons1.anchor = GridBagConstraints.WEST;
        cons1.fill = GridBagConstraints.NONE;
        cons1.weightx = 0.0f;
        JRadioButton[] radioButtons = new JRadioButton[2];
        ButtonGroup numParaGroup = new ButtonGroup();
        radioButtons[0] = new JRadioButton(Tools.getLabel(messages.getString("guiUseDocumentLanguage")));
        radioButtons[0].setActionCommand("DocLang");
        radioButtons[0].setSelected(true);

        radioButtons[1] = new JRadioButton(Tools.getLabel(messages.getString("guiSetLanguageTo")));
        radioButtons[1].setActionCommand("SelectLang");

        JComboBox<String> motherTongueBox = new JComboBox<>(getPossibleMotherTongues());
        if (config.getMotherTongue() != null) {
            motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages));
        }
        motherTongueBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    Language motherTongue;
                    if (motherTongueBox.getSelectedItem() instanceof String) {
                        motherTongue = getLanguageForLocalizedName(
                                motherTongueBox.getSelectedItem().toString());
                    } else {
                        motherTongue = (Language) motherTongueBox.getSelectedItem();
                    }
                    config.setMotherTongue(motherTongue);
                    config.setUseDocLanguage(false);
                    radioButtons[1].setSelected(true);
                }
            }
        });

        for (int i = 0; i < 2; i++) {
            numParaGroup.add(radioButtons[i]);
        }

        if (config.getUseDocLanguage()) {
            radioButtons[0].setSelected(true);
        } else {
            radioButtons[1].setSelected(true);
        }

        radioButtons[0].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                config.setUseDocLanguage(true);
            }
        });

        radioButtons[1].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                config.setUseDocLanguage(false);
                Language motherTongue;
                if (motherTongueBox.getSelectedItem() instanceof String) {
                    motherTongue = getLanguageForLocalizedName(motherTongueBox.getSelectedItem().toString());
                } else {
                    motherTongue = (Language) motherTongueBox.getSelectedItem();
                }
                config.setMotherTongue(motherTongue);
            }
        });
        motherTonguePanel.add(radioButtons[0], cons1);
        cons1.gridy++;
        motherTonguePanel.add(radioButtons[1], cons1);
        cons1.gridx = 1;
        motherTonguePanel.add(motherTongueBox, cons1);
    } else {
        motherTonguePanel.add(new JLabel(messages.getString("guiMotherTongue")), cons);
        JComboBox<String> motherTongueBox = new JComboBox<>(getPossibleMotherTongues());
        if (config.getMotherTongue() != null) {
            motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages));
        }
        motherTongueBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    Language motherTongue;
                    if (motherTongueBox.getSelectedItem() instanceof String) {
                        motherTongue = getLanguageForLocalizedName(
                                motherTongueBox.getSelectedItem().toString());
                    } else {
                        motherTongue = (Language) motherTongueBox.getSelectedItem();
                    }
                    config.setMotherTongue(motherTongue);
                }
            }
        });
        motherTonguePanel.add(motherTongueBox, cons);
    }
    return motherTonguePanel;
}

From source file:org.languagetool.gui.Main.java

private JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(getLabel("guiMenuFile"));
    fileMenu.setMnemonic(getMnemonic("guiMenuFile"));
    JMenu editMenu = new JMenu(getLabel("guiMenuEdit"));
    editMenu.setMnemonic(getMnemonic("guiMenuEdit"));
    JMenu grammarMenu = new JMenu(getLabel("guiMenuGrammar"));
    grammarMenu.setMnemonic(getMnemonic("guiMenuGrammar"));
    JMenu helpMenu = new JMenu(getLabel("guiMenuHelp"));
    helpMenu.setMnemonic(getMnemonic("guiMenuHelp"));

    fileMenu.add(openAction);/* w  w  w  .  jav a 2s  .com*/
    fileMenu.add(saveAction);
    fileMenu.add(saveAsAction);
    recentFilesMenu = new JMenu(getLabel("guiMenuRecentFiles"));
    recentFilesMenu.setMnemonic(getMnemonic("guiMenuRecentFiles"));
    fileMenu.add(recentFilesMenu);
    updateRecentFilesMenu();
    fileMenu.addSeparator();
    fileMenu.add(new HideAction());
    fileMenu.addSeparator();
    fileMenu.add(new QuitAction());

    grammarMenu.add(checkAction);
    JCheckBoxMenuItem item = new JCheckBoxMenuItem(autoCheckAction);
    grammarMenu.add(item);
    JCheckBoxMenuItem showResult = new JCheckBoxMenuItem(showResultAction);
    grammarMenu.add(showResult);
    grammarMenu.add(new CheckClipboardAction());
    grammarMenu.add(new TagTextAction());
    grammarMenu.add(new AddRulesAction());
    grammarMenu.add(new OptionsAction());
    grammarMenu.add(new SelectFontAction());
    JMenu lafMenu = new JMenu(messages.getString("guiLookAndFeelMenu"));
    UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
    ButtonGroup buttonGroup = new ButtonGroup();
    for (UIManager.LookAndFeelInfo laf : lafInfo) {
        if (!"Nimbus".equals(laf.getName())) {
            continue;
        }
        addLookAndFeelMenuItem(lafMenu, laf, buttonGroup);
    }
    for (UIManager.LookAndFeelInfo laf : lafInfo) {
        if ("Nimbus".equals(laf.getName())) {
            continue;
        }
        addLookAndFeelMenuItem(lafMenu, laf, buttonGroup);
    }
    grammarMenu.add(lafMenu);

    helpMenu.add(new AboutAction());

    undoRedo.undoAction.putValue(Action.NAME, getLabel("guiMenuUndo"));
    undoRedo.undoAction.putValue(Action.MNEMONIC_KEY, getMnemonic("guiMenuUndo"));
    undoRedo.redoAction.putValue(Action.NAME, getLabel("guiMenuRedo"));
    undoRedo.redoAction.putValue(Action.MNEMONIC_KEY, getMnemonic("guiMenuRedo"));

    editMenu.add(undoRedo.undoAction);
    editMenu.add(undoRedo.redoAction);
    editMenu.addSeparator();

    Action cutAction = new DefaultEditorKit.CutAction();
    cutAction.putValue(Action.SMALL_ICON, getImageIcon("sc_cut.png"));
    cutAction.putValue(Action.LARGE_ICON_KEY, getImageIcon("lc_cut.png"));
    cutAction.putValue(Action.NAME, getLabel("guiMenuCut"));
    cutAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_T);
    editMenu.add(cutAction);

    Action copyAction = new DefaultEditorKit.CopyAction();
    copyAction.putValue(Action.SMALL_ICON, getImageIcon("sc_copy.png"));
    copyAction.putValue(Action.LARGE_ICON_KEY, getImageIcon("lc_copy.png"));
    copyAction.putValue(Action.NAME, getLabel("guiMenuCopy"));
    copyAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_C);
    editMenu.add(copyAction);

    Action pasteAction = new DefaultEditorKit.PasteAction();
    pasteAction.putValue(Action.SMALL_ICON, getImageIcon("sc_paste.png"));
    pasteAction.putValue(Action.LARGE_ICON_KEY, getImageIcon("lc_paste.png"));
    pasteAction.putValue(Action.NAME, getLabel("guiMenuPaste"));
    pasteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_P);
    editMenu.add(pasteAction);

    editMenu.addSeparator();

    editMenu.add(new SelectAllAction());

    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    menuBar.add(grammarMenu);
    menuBar.add(helpMenu);
    return menuBar;
}