List of usage examples for javax.swing ButtonGroup add
public void add(AbstractButton b)
From source file:org.f2o.absurdum.puck.gui.PuckFrame.java
/** * Instances and shows Puck's main frame. */// www. j av a 2 s .co m public PuckFrame() { super(); setLookAndFeel(PuckConfiguration.getInstance().getProperty("look")); /* LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels(); for ( int i = 0 ; i < lfs.length ; i++ ) { if ( lfs[i].getName().toLowerCase().contains("nimbus") ) { try { UIManager.setLookAndFeel(lfs[i].getClassName()); } catch (Exception e) //class not found, instantiation exception, etc. (shouldn't happen) { e.printStackTrace(); } } } */ setSize(PuckConfiguration.getInstance().getIntegerProperty("windowWidth"), PuckConfiguration.getInstance().getIntegerProperty("windowHeight")); setLocation(PuckConfiguration.getInstance().getIntegerProperty("windowLocationX"), PuckConfiguration.getInstance().getIntegerProperty("windowLocationY")); //setSize(600,600); if (PuckConfiguration.getInstance().getBooleanProperty("windowMaximized")) maximizeIfPossible(); //setTitle(Messages.getInstance().getMessage("frame.title")); refreshTitle(); left = new JPanel(); right = new JPanel(); JScrollPane rightScroll = new JScrollPane(right); rightScroll.getVerticalScrollBar().setUnitIncrement(16); //faster scrollbar (by default it was very slow, maybe because component inside is not text component!) split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, rightScroll) { //dynamic resizing of right panel /* public void setDividerLocation ( int pixels ) { if ( propPanel != null ) { double rightPartSize = getContentPane().getWidth() - pixels - 15; System.out.println("rps=" + rightPartSize); System.out.println("mnw=" + this.getMinimumSize().getWidth()); Dimension propPanSize = propPanel.getSize(); int propPanHeight = 0; if (propPanSize != null) propPanHeight = (int) propPanSize.getHeight(); //propPanel.revalidate(); System.out.println("h " + propPanHeight); //if ( rightPartSize >= propPanel.getMinimumSize().getWidth() ) propPanel.setPreferredSize(new Dimension((int)rightPartSize,propPanHeight)); //propPanel.setMinimumSize(new Dimension((int)rightPartSize,propPanHeight)); //propPanel.setMaximumSize(new Dimension((int)rightPartSize,propPanHeight)); //propPanel.setSize(new Dimension((int)rightPartSize,propPanHeight)); propPanel.revalidate(); } super.setDividerLocation(pixels); } */ }; split.setContinuousLayout(true); split.setResizeWeight(0.60); final int dividerLoc = PuckConfiguration.getInstance().getIntegerProperty("dividerLocation", 0); /* SwingUtilities.invokeLater(new Runnable(){ public void run() { */ /* } }); */ split.setOneTouchExpandable(true); getContentPane().add(split); System.out.println(Toolkit.getDefaultToolkit().getBestCursorSize(20, 20)); //it's 32x32. Will have to do it. //Image img = Toolkit.getDefaultToolkit().createImage( getClass().getResource("addCursor32.png") ); //Image img = Toolkit.getDefaultToolkit().createImage("addCursor32.png"); left.setLayout(new BorderLayout()); //right.setLayout(new BoxLayout(right,BoxLayout.LINE_AXIS)); if (PuckConfiguration.getInstance().getBooleanProperty("dynamicFormResizing")) right.setLayout(new BorderLayout()); else right.setLayout(new FlowLayout()); propPanel = new PropertiesPanel(); right.add(propPanel); graphPanel = new GraphEditingPanel(propPanel); graphPanel.setGrid(Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue()); graphPanel.setSnapToGrid( Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue()); propPanel.setGraphEditingPanel(graphPanel); tools = new PuckToolBar(graphPanel, propPanel, this); left.add(tools, BorderLayout.WEST); left.add(graphPanel, BorderLayout.CENTER); /* Action testAction = new AbstractAction() { public void actionPerformed ( ActionEvent evt ) { System.out.println("Puck!"); } } ; testAction.putValue(Action.NAME,"Print Puck"); tools.add(testAction); */ /* public void saveChanges ( ) { if ( editingFileName == null ) { //save as... code } else { File f = new File(editingFileName); try { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d)); Transformer t = TransformerFactory.newInstance().newTransformer(); Source s = new DOMSource(d); Result r = new StreamResult(f); t.transform(s,r); editingFileName = f.toString(); refreshTitle(); } catch ( Exception e ) { JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } } */ JMenuBar mainMenuBar = new JMenuBar(); JMenu fileMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file")); fileMenu.setMnemonic(KeyEvent.VK_F); saveMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.save")); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (editingFileName == null) JOptionPane.showMessageDialog(PuckFrame.this, "File has no name!", "Whoops!", JOptionPane.ERROR_MESSAGE); /* File f = new File(editingFileName); try { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d)); Transformer t = TransformerFactory.newInstance().newTransformer(); Source s = new DOMSource(d); Result r = new StreamResult(f); t.transform(s,r); editingFileName = f.toString(); refreshTitle(); } catch ( Exception e ) { JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } */ try { saveChangesInCurrentFile(); } catch (Exception e) { JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }); JMenu newMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.new")); JMenuItem newBlankMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.new.blank")); //newBlankMenuItem.setMnemonic(KeyEvent.VK_N); newBlankMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { GraphElementPanel.emptyQueue(); //stop deferred loads graphPanel.clear(); propPanel.clear(); JSyntaxBSHCodeFrame.closeAllInstances(); WorldPanel wp = new WorldPanel(graphPanel); WorldNode wn = new WorldNode(wp); graphPanel.setWorldNode(wn); propPanel.show(graphPanel.getWorldNode()); resetCurrentlyEditingFile(); refreshTitle(); //revalidate(); //only since java 1.7 //invalidate(); //validate(); split.revalidate(); //JComponents do have it before java 1.7 (not JFrame) } }); newMenu.add(newBlankMenuItem); JMenu templateMenus = new WorldTemplateMenuBuilder(this).getMenu(); if (templateMenus != null) { for (int i = 0; i < templateMenus.getItemCount(); i++) { if (i == 0) newMenu.add(new JSeparator()); newMenu.add(templateMenus.getItem(i)); } } JMenuItem saveAsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.saveas")); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { /* JFileChooser jfc = new JFileChooser("."); int opt = jfc.showSaveDialog(PuckFrame.this); if ( opt == JFileChooser.APPROVE_OPTION ) { File f = jfc.getSelectedFile(); try { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d)); Transformer t = TransformerFactory.newInstance().newTransformer(); Source s = new DOMSource(d); Result r = new StreamResult(f); t.transform(s,r); editingFileName = f.toString(); saveMenuItem.setEnabled(true); refreshTitle(); } catch ( Exception e ) { JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } */ try { saveAs(); saveMenuItem.setEnabled(true); } catch (Exception e) { JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } //saveAs(saveMenuItem); } }); JMenuItem openMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.open")); openMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { //graphPanel.setVisible(false); //propPanel.setVisible(false); JFileChooser jfc = new JFileChooser("."); jfc.setFileFilter(new FiltroFicheroMundo()); int opt = jfc.showOpenDialog(PuckFrame.this); if (opt == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); openFileOrShowError(f); } //graphPanel.setVisible(true); //propPanel.setVisible(true); } }); openRecentMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.recent")); JMenuItem exitMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.exit")); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { /* int opt = JOptionPane.showConfirmDialog(PuckFrame.this,Messages.getInstance().getMessage("exit.sure.text"),Messages.getInstance().getMessage("exit.sure.title"),JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); if ( opt == JOptionPane.YES_OPTION ) System.exit(0); */ userExit(); } }); JMenu exportMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.export")); JMenuItem exportAppletMenuItem = new JMenuItem( UIMessages.getInstance().getMessage("menu.file.export.applet")); exportAppletMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ExportAppletDialog dial = new ExportAppletDialog(PuckFrame.this); dial.setVisible(true); } }); exportMenu.add(exportAppletMenuItem); fileMenu.add(newMenu); fileMenu.add(openMenuItem); fileMenu.add(openRecentMenu); updateRecentMenu(); fileMenu.add(new JSeparator()); saveMenuItem.setEnabled(false); fileMenu.add(saveMenuItem); fileMenu.add(saveAsMenuItem); fileMenu.add(exportMenu); fileMenu.add(new JSeparator()); fileMenu.add(exitMenuItem); mainMenuBar.add(fileMenu); /** * Create an Edit menu to support cut/copy/paste. */ JMenu editMenu = new JMenu(UIMessages.getInstance().getMessage("menu.edit")); editMenu.setMnemonic(KeyEvent.VK_E); JMenuItem findMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.find.entity")); findMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showFindEntityDialog(); } }); editMenu.add(findMenuItem); editMenu.add(new JSeparator()); JMenuItem aMenuItem = new JMenuItem(new CutAction()); aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.cut")); aMenuItem.setMnemonic(KeyEvent.VK_T); editMenu.add(aMenuItem); aMenuItem = new JMenuItem(new CopyAction()); aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.copy")); aMenuItem.setMnemonic(KeyEvent.VK_C); editMenu.add(aMenuItem); aMenuItem = new JMenuItem(new PasteAction()); aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.paste")); aMenuItem.setMnemonic(KeyEvent.VK_P); editMenu.add(aMenuItem); mainMenuBar.add(editMenu); JMenu optionsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options")); JMenu gridMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.grid")); optionsMenu.add(gridMenu); final JCheckBoxMenuItem showGridItem = new JCheckBoxMenuItem( UIMessages.getInstance().getMessage("menu.options.grid.show")); showGridItem.setSelected( Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue()); gridMenu.add(showGridItem); showGridItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { graphPanel.setGrid(true); PuckConfiguration.getInstance().setProperty("showGrid", "true"); } else if (e.getStateChange() == ItemEvent.DESELECTED) { graphPanel.setGrid(false); PuckConfiguration.getInstance().setProperty("showGrid", "false"); } graphPanel.repaint(); } }); final JCheckBoxMenuItem snapToGridItem = new JCheckBoxMenuItem( UIMessages.getInstance().getMessage("menu.options.grid.snap")); snapToGridItem.setSelected( Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue()); gridMenu.add(snapToGridItem); snapToGridItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { graphPanel.setSnapToGrid(true); PuckConfiguration.getInstance().setProperty("snapToGrid", "true"); } else if (e.getStateChange() == ItemEvent.DESELECTED) { graphPanel.setSnapToGrid(false); PuckConfiguration.getInstance().setProperty("snapToGrid", "false"); } graphPanel.repaint(); } }); JMenuItem translationModeMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.translation")); ButtonGroup translationGroup = new ButtonGroup(); final JRadioButtonMenuItem holdMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.translation.hold")); final JRadioButtonMenuItem pushMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.translation.push")); pushMenuItem.setSelected("push".equals(PuckConfiguration.getInstance().getProperty("translateMode"))); if (!pushMenuItem.isSelected()) holdMenuItem.setSelected(true); translationGroup.add(holdMenuItem); translationGroup.add(pushMenuItem); holdMenuItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { if (holdMenuItem.isSelected()) PuckConfiguration.getInstance().setProperty("translateMode", "hold"); else PuckConfiguration.getInstance().setProperty("translateMode", "push"); } }); translationModeMenu.add(holdMenuItem); translationModeMenu.add(pushMenuItem); optionsMenu.add(translationModeMenu); JMenuItem toolSelectionModeMenu = new JMenu( UIMessages.getInstance().getMessage("menu.options.toolselection")); ButtonGroup toolSelectionGroup = new ButtonGroup(); final JRadioButtonMenuItem oneUseMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.toolselection.oneuse")); final JRadioButtonMenuItem multipleUseMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.toolselection.multipleuse")); multipleUseMenuItem.setSelected( "multipleUse".equalsIgnoreCase(PuckConfiguration.getInstance().getProperty("toolSelectionMode"))); if (!multipleUseMenuItem.isSelected()) oneUseMenuItem.setSelected(true); toolSelectionGroup.add(oneUseMenuItem); toolSelectionGroup.add(multipleUseMenuItem); oneUseMenuItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { if (oneUseMenuItem.isSelected()) PuckConfiguration.getInstance().setProperty("toolSelectionMode", "oneUse"); else PuckConfiguration.getInstance().setProperty("toolSelectionMode", "multipleUse"); } }); toolSelectionModeMenu.add(oneUseMenuItem); toolSelectionModeMenu.add(multipleUseMenuItem); optionsMenu.add(toolSelectionModeMenu); JMenuItem sizesMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.iconsizes")); sizesMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { IconSizesDialog dial = new IconSizesDialog(PuckFrame.this, true); dial.setVisible(true); } }); optionsMenu.add(sizesMenuItem); JMenuItem showHideMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.showhide")); showHideMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ShowHideDialog dial = new ShowHideDialog(PuckFrame.this, true); dial.setVisible(true); } }); optionsMenu.add(showHideMenuItem); JMenuItem mapColorsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.mapcolors")); mapColorsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MapColorsDialog dial = new MapColorsDialog(PuckFrame.this, true); dial.setVisible(true); } }); optionsMenu.add(mapColorsMenuItem); String skinList = PuckConfiguration.getInstance().getProperty("availableSkins"); if (skinList != null && skinList.trim().length() > 0) { JMenu skinsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.skins")); StringTokenizer st = new StringTokenizer(skinList, ", "); ButtonGroup skinButtons = new ButtonGroup(); while (st.hasMoreTokens()) { final String nextSkin = st.nextToken(); final JRadioButtonMenuItem skinMenuItem = new JRadioButtonMenuItem(nextSkin); skinMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setSkin(nextSkin); skinMenuItem.setSelected(true); } }); if (nextSkin.equals(PuckConfiguration.getInstance().getProperty("skin"))) skinMenuItem.setSelected(true); skinsMenu.add(skinMenuItem); skinButtons.add(skinMenuItem); } optionsMenu.add(skinsMenu); } JMenu lookFeelMenu = new JMenu(UIMessages.getInstance().getMessage("menu.looks")); ButtonGroup lookButtons = new ButtonGroup(); final JRadioButtonMenuItem defaultLookMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.looks.default")); if ("default".equals(PuckConfiguration.getInstance().getProperty("look"))) { defaultLookMenuItem.setSelected(true); } lookFeelMenu.add(defaultLookMenuItem); lookButtons.add(defaultLookMenuItem); defaultLookMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel("default"); defaultLookMenuItem.setSelected(true); } }); final JRadioButtonMenuItem systemLookMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.looks.system")); if ("system".equals(PuckConfiguration.getInstance().getProperty("look"))) { systemLookMenuItem.setSelected(true); } lookFeelMenu.add(systemLookMenuItem); lookButtons.add(systemLookMenuItem); systemLookMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel("system"); systemLookMenuItem.setSelected(true); } }); String additionalLookList = PuckConfiguration.getInstance().getProperty("additionalLooks"); if (additionalLookList != null && additionalLookList.trim().length() > 0) { StringTokenizer st = new StringTokenizer(additionalLookList, ", "); while (st.hasMoreTokens()) { final String nextLook = st.nextToken(); final JRadioButtonMenuItem lookMenuItem = new JRadioButtonMenuItem(nextLook); lookMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel(nextLook); lookMenuItem.setSelected(true); } }); if (nextLook.equals(PuckConfiguration.getInstance().getProperty("look"))) { lookMenuItem.setSelected(true); } lookFeelMenu.add(lookMenuItem); lookButtons.add(lookMenuItem); } } optionsMenu.add(lookFeelMenu); optionsMenu.add(new UILanguageSelectionMenu(this)); mainMenuBar.add(optionsMenu); JMenu toolsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.tools")); final JMenuItem verbListMenuItem = new JMenuItem( UIMessages.getInstance().getMessage("menu.tools.verblist")); verbListMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { WorldPanel wp = (WorldPanel) graphPanel.getWorldNode().getAssociatedPanel(); VerbListFrame vlf = VerbListFrame.getInstance(wp.getSelectedLanguageCode()); vlf.setVisible(true); } }); toolsMenu.add(verbListMenuItem); final JMenuItem validateMenuItem = new JMenuItem( UIMessages.getInstance().getMessage("menu.tools.validatebsh")); validateMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { BeanShellCodeValidator bscv = new BeanShellCodeValidator(graphPanel); if (!bscv.validate()) { BeanShellErrorsDialog bsed = new BeanShellErrorsDialog(PuckFrame.this, bscv.getErrorText()); bsed.setVisible(true); //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText()); } else { JOptionPane.showMessageDialog(PuckFrame.this, UIMessages.getInstance().getMessage("bsh.code.ok"), "OK!", JOptionPane.INFORMATION_MESSAGE); //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText()); } } }); toolsMenu.add(validateMenuItem); mainMenuBar.add(toolsMenu); JMenu helpMenu = new JMenu(UIMessages.getInstance().getMessage("menu.help")); //JHelpAction.startHelpWorker("help/PUCKHelp.hs"); //JHelpAction helpTocAction = JHelpAction.getShowHelpInstance(Messages.getInstance().getMessage("menu.help.toc")); //JHelpAction helpContextSensitiveAction = JHelpAction.getTrackInstance(Messages.getInstance().getMessage("menu.help.context")); //final JMenuItem helpTocMenuItem = new JMenuItem(helpTocAction); //final JMenuItem helpContextSensitiveMenuItem = new JMenuItem(helpContextSensitiveAction); //helpMenu.add(helpTocMenuItem); //helpMenu.add(helpContextSensitiveMenuItem); final JMenuItem helpMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.help.toc")); helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DocumentationLinkDialog dial = new DocumentationLinkDialog(PuckFrame.this, true); dial.setVisible(true); } }); helpMenu.add(helpMenuItem); mainMenuBar.add(helpMenu); MenuMnemonicOnTheFly.setMnemonics(mainMenuBar); this.setJMenuBar(mainMenuBar); //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { userExit(); } }); propPanel.show(graphPanel.getWorldNode()); setVisible(true); SwingUtilities.invokeLater(new Runnable() { public void run() { if (dividerLoc > 0) split.setDividerLocation(dividerLoc); else split.setDividerLocation(0.60); } }); }
From source file:org.geworkbench.components.lincs.LincsInterface.java
public LincsInterface() { final String lincsCwbFileName = this.getClass().getPackage().getName().replace(".", FilePathnameUtils.FILE_SEPARATOR) + FilePathnameUtils.FILE_SEPARATOR + "Lincs.cwb.xml"; setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); // temp do this, if data is there, then may be take out hideColumnList.add("P-value"); add(queryTypePanel);// w ww . ja v a 2 s .c o m add(queryConditionPanel1); add(queryConditionPanel2); add(queryCommandPanel); experimental.setSelected(true); ButtonGroup group = new ButtonGroup(); group.add(experimental); group.add(computational); queryTypePanel.add(new JLabel("Query Type")); queryTypePanel.add(experimental); queryTypePanel.add(computational); queryTypePanel.add(new JLabel(" ")); JLabel viewLicenseLabel = new JLabel("<html><font color=blue><u><b>View License</b></u></font></html>"); ; queryTypePanel.add(viewLicenseLabel); viewLicenseLabel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { viewLicense_actionPerformed(lincsCwbFileName); } }); String url = getLincsWsdlUrl(); // String url = // "http://localhost:8080/axis2/services/LincsService?wsdl"; lincs = new Lincs(url, null, null); queryConditionPanel1.setLayout(new GridLayout(2, 7)); final JLabel tissueTypeLabel = new JLabel("Tissue Type"); final JLabel cellLineLabel = new JLabel("Cell Line"); final JLabel drug1Label = new JLabel("Drug 1"); final JLabel drug2Label = new JLabel("Drug 2"); final JLabel assayTypeLabel = new JLabel("Assay Type"); final JLabel synergyMeasurementLabel = new JLabel("Synergy Measurement Type"); final JLabel similarityAlgorithmLabel = new JLabel("Similarity Algorithm"); final JLabel blankLabel = new JLabel(""); queryConditionPanel1.add(new JLabel("")); queryConditionPanel1.add(new JLabel("")); queryConditionPanel1.add(drug1Label); queryConditionPanel1.add(new JLabel("")); queryConditionPanel1.add(new JLabel("")); queryConditionPanel1.add(new JLabel("")); queryConditionPanel1.add(blankLabel); queryConditionPanel1.add(tissueTypeLabel); queryConditionPanel1.add(cellLineLabel); queryConditionPanel1.add(drug1Search); queryConditionPanel1.add(drug2Label); queryConditionPanel1.add(assayTypeLabel); queryConditionPanel1.add(synergyMeasurementLabel); queryConditionPanel1.add(new JLabel("")); queryConditionPanel2.setLayout(new GridLayout(1, 7)); List<String> tissueTypeList = null; List<String> drug1List = null; List<String> assayTypeList = null; List<String> synergyMeasuremetnTypeList = null; List<String> similarityAlgorithmList = null; try { tissueTypeList = addAll(lincs.getAllTissueNames()); drug1List = addAll(lincs.getCompound1NamesFromExperimental(null, null)); assayTypeList = addAll(lincs.getAllAssayTypeNames()); synergyMeasuremetnTypeList = addAll(lincs.getAllMeasurementTypeNames()); similarityAlgorithmList = addAll(lincs.getALLSimilarAlgorithmNames()); } catch (Exception ex) { log.error(ex.getMessage()); } tissueTypeBox = new JList(); final JScrollPane tissueTypeBoxPanel = buildJListPanel(tissueTypeList, tissueTypeBox); cellLineBox = new JList(); final JScrollPane cellLineBoxPanel = buildJListPanel(null, cellLineBox); cellLineBox.setEnabled(false); final JScrollPane drug1BoxPanel = buildFilterJListPanel(drug1List, drug1Box); drug2Box = new JList(); final JScrollPane drug2BoxPanel = buildJListPanel(null, drug2Box); drug2Box.setEnabled(false); assayTypeBox = new JList(); final JScrollPane assayTypeBoxPanel = buildJListPanel(assayTypeList, assayTypeBox); synergyMeasurementTypeBox = new JList(); final JScrollPane synergyMeasuremetnTypeBoxPanel = buildJListPanel(synergyMeasuremetnTypeList, synergyMeasurementTypeBox); similarityAlgorithmTypeBox = new JList(); final JScrollPane similarityAlgorithmTypeBoxPanel = buildJListPanel(similarityAlgorithmList, similarityAlgorithmTypeBox); onlyTitration = new JCheckBox("Only with titration"); queryConditionPanel2.add(tissueTypeBoxPanel); queryConditionPanel2.add(cellLineBoxPanel); queryConditionPanel2.add(drug1BoxPanel); queryConditionPanel2.add(drug2BoxPanel); queryConditionPanel2.add(assayTypeBoxPanel); queryConditionPanel2.add(synergyMeasuremetnTypeBoxPanel); queryConditionPanel2.add(onlyTitration); // dynamic dependency parts tissueTypeBox.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { List<String> selectedTissueList = getSelectedValues(tissueTypeBox); List<String> cellLineDataList = null; List<String> drug1DataList = null; try { cellLineDataList = addAll(lincs.getAllCellLineNamesForTissueTypes(selectedTissueList)); if (experimental.isSelected() == true) drug1DataList = addAll( lincs.getCompound1NamesFromExperimental(selectedTissueList, null)); else drug1DataList = addAll( lincs.getCompound1NamesFromComputational(selectedTissueList, null)); } catch (Exception ex) { log.error(ex.getMessage()); } if (tissueTypeBox.getSelectedValues() != null && tissueTypeBox.getSelectedValues().length > 0) cellLineBox.setModel(new LincsListModel(cellLineDataList)); else cellLineBox.setModel(new LincsListModel(null)); cellLineBox.setEnabled(true); cellLineBox.clearSelection(); drug1Box.removeAllItems(); for (int i = 0; i < drug1DataList.size(); i++) drug1Box.addItem(drug1DataList.get(i)); drug1Box.clearSelection(); drug2Box.clearSelection(); drug2Box.setModel(new LincsListModel(null)); drug2Box.setEnabled(false); cellLineBox.ensureIndexIsVisible(0); drug1Box.ensureIndexIsVisible(0); } } }); // dynamic dependency parts cellLineBox.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { List<String> selectedTissueList = getSelectedValues(tissueTypeBox); List<String> selectedCellLineList = getSelectedValues(cellLineBox); List<String> drug1DataList = null; try { if (experimental.isSelected() == true) drug1DataList = addAll(lincs.getCompound1NamesFromExperimental(selectedTissueList, selectedCellLineList)); else drug1DataList = addAll(lincs.getCompound1NamesFromComputational(selectedTissueList, selectedCellLineList)); } catch (Exception ex) { log.error(ex.getMessage()); } drug1Box.removeAllItems(); for (int i = 0; i < drug1DataList.size(); i++) drug1Box.addItem(drug1DataList.get(i)); drug1Box.ensureIndexIsVisible(0); drug1Box.clearSelection(); drug2Box.clearSelection(); drug2Box.setModel(new LincsListModel(null)); drug2Box.setEnabled(false); } } }); // dynamic dependency parts drug1Box.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { List<String> selectedTissueList = getSelectedValues(tissueTypeBox); List<String> selectedCellLineList = getSelectedValues(cellLineBox); List<String> selectedDrug1List = getSelectedValues(drug1Box); List<String> drug2DataList = null; try { if (experimental.isSelected() == true) drug2DataList = addAll(lincs.getCompound2NamesFromExperimental(selectedTissueList, selectedCellLineList, selectedDrug1List)); else drug2DataList = addAll(lincs.getCompound2NamesFromComputational(selectedTissueList, selectedCellLineList, selectedDrug1List)); } catch (Exception ex) { log.error(ex.getMessage()); } if (drug1Box.getSelectedValues() != null && drug1Box.getSelectedValues().length > 0) drug2Box.setModel(new LincsListModel(drug2DataList)); else drug2Box.setModel(new LincsListModel(null)); drug2Box.setEnabled(true); drug2Box.ensureIndexIsVisible(0); } } }); maxResult = new JCheckBox("Max results"); maxResultNumber = new JTextField("10", 10); searchButton = new JButton("Search"); resetButton = new JButton("Reset"); colorGradient = new JCheckBox("Color gradient for Score"); queryCommandPanel.add(maxResult); queryCommandPanel.add(maxResultNumber); queryCommandPanel.add(searchButton); queryCommandPanel.add(resetButton); queryCommandPanel.add(colorGradient); resultTable = new TableViewer(experimentalColumnNames, null, hideColumnList); add(resultTable); add(resultProcessingPanel); queryResultPanel.setLayout(new BorderLayout()); // queryResultPanel.add(new JScrollPane(resultTable), // BorderLayout.CENTER); plotOptions = new JComboBox(new String[] { HEATMAP, NETWORK }); JButton plotButton = new JButton("Plot"); final JCheckBox limitNetwork = new JCheckBox("Limit network to multiply-connected pairs"); limitNetwork.setEnabled(false); limitNetwork.setVisible(false); JButton exportButton = new JButton("Export"); exportButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { List<String> hideColumns = new ArrayList<String>(); hideColumns.add("Include"); TableViewer.export(resultTable.getTable(), hideColumns, resultTable); } }); resultProcessingPanel.add(new JLabel("Plot options:")); resultProcessingPanel.add(plotOptions); resultProcessingPanel.add(plotButton); resultProcessingPanel.add(limitNetwork); resultProcessingPanel.add(exportButton); plotOptions.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (plotOptions.getSelectedItem().toString().equals(HEATMAP)) { limitNetwork.setEnabled(false); } else if (plotOptions.getSelectedItem().toString().equals(NETWORK)) { limitNetwork.setEnabled(true); } } }); plotButton.addActionListener(plotListener); colorGradient.addActionListener(colorGradientListener); computational.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { queryConditionPanel1.remove(blankLabel); queryConditionPanel1.remove(assayTypeLabel); queryConditionPanel1.remove(synergyMeasurementLabel); queryConditionPanel2.remove(assayTypeBoxPanel); queryConditionPanel2.remove(synergyMeasuremetnTypeBoxPanel); queryConditionPanel1.add(similarityAlgorithmLabel, 10); queryConditionPanel2.add(similarityAlgorithmTypeBoxPanel, 4); queryConditionPanel1.updateUI(); queryConditionPanel2.updateUI(); onlyTitration.setEnabled(false); reset(); } }); experimental.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { queryConditionPanel1.remove(similarityAlgorithmLabel); queryConditionPanel2.remove(similarityAlgorithmTypeBoxPanel); queryConditionPanel1.add(blankLabel, 6); queryConditionPanel1.add(assayTypeLabel, 11); queryConditionPanel1.add(synergyMeasurementLabel, 12); queryConditionPanel2.add(assayTypeBoxPanel, 4); queryConditionPanel2.add(synergyMeasuremetnTypeBoxPanel, 5); queryConditionPanel1.updateUI(); queryConditionPanel2.updateUI(); onlyTitration.setEnabled(true); reset(); } }); searchButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int rowLimit = 0; List<String> tissueTypes = getSelectedValues(tissueTypeBox); List<String> cellLineNames = getSelectedValues(cellLineBox); List<String> drug1Names = getSelectedValues(drug1Box); List<String> drug2Names = getSelectedValues(drug2Box); if (maxResult.isSelected()) { try { rowLimit = new Integer(maxResultNumber.getText().trim()).intValue(); } catch (NumberFormatException nbe) { JOptionPane.showMessageDialog(null, "Please enter a number."); maxResultNumber.requestFocus(); return; } } if ((drug1Names == null || drug1Names.isEmpty()) && (drug2Names == null || drug2Names.isEmpty())) { JOptionPane.showMessageDialog(null, "Please select at least one drug constraint, multiple drugs can be selected."); return; } AbstractAnalysis selectedAnalysis = new LincsSearchAnalysis(); String dataSetName = null; if (experimental.isSelected()) { selectedAnalysis.setLabel("LINCS Experimental Query"); dataSetName = "LINCS Data"; } else { selectedAnalysis.setLabel("LINCS Computational Query"); dataSetName = "LINCS Data"; } final AnalysisInvokedEvent invokeEvent = new AnalysisInvokedEvent(selectedAnalysis, dataSetName); publishAnalysisInvokedEvent(invokeEvent); try { if (experimental.isSelected()) { List<String> assayTypes = getSelectedValues(assayTypeBox); List<String> measurementTypes = getSelectedValues(synergyMeasurementTypeBox); List<ExperimentalData> dataList = lincs.getExperimentalData(tissueTypes, cellLineNames, drug1Names, drug2Names, measurementTypes, assayTypes, onlyTitration.isSelected(), rowLimit); Object[][] objects = convertExperimentalData(dataList); updateResultTable(objects); } else { List<String> similarityAlgorithmTypes = getSelectedValues(similarityAlgorithmTypeBox); List<ComputationalData> dataList = lincs.getComputationalData(tissueTypes, cellLineNames, drug1Names, drug2Names, similarityAlgorithmTypes, rowLimit); Object[][] objects = convertComputationalData(dataList); updateResultTable(objects); } publishAnalysisCompleteEvent(new AnalysisCompleteEvent(invokeEvent)); } catch (Exception ex) { log.error(ex.getMessage()); publishAnalysisAbortEvent(new AnalysisAbortEvent(invokeEvent)); } if (resultTable.getData() == null || resultTable.getData().length == 0) { JOptionPane.showMessageDialog(null, "There is no row in the database for your query.", "Empty Set", JOptionPane.INFORMATION_MESSAGE); return; } freeVariables = getFreeVariables(); } }); resetButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { reset(); } }); }
From source file:org.intermine.install.swing.BuildProjectDialog.java
/** * Common initialisation: lays out the child components and wires up the necessary * event listeners.//ww w . ja v a2 s . c om */ 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
/** * Creates menu bar//ww w. ja v a2 s. c om * * @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 av a 2 s. c o m 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./* w w w . j av a 2 s.c o m*/ */ 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 ww w . j a v a 2s. com*/ */ 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 w w w . j a v a 2s . com*/ * 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);/*w w w . j a v a 2s .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;//www . j a va 2 s . c om 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; }