List of usage examples for javax.swing ButtonGroup add
public void add(AbstractButton b)
From source file:ca.phon.app.session.editor.TranscriberSelectionDialog.java
/** Init display and listeners */ private void initDialog() { // setup layout // layout will be seperated into two sections, existing // and new transcripts FormLayout outerLayout = new FormLayout("3dlu, pref, right:pref:grow, 3dlu", "pref, 3dlu, top:pref:noGrow, 3dlu, pref, 3dlu, fill:pref:grow, 3dlu, pref"); this.getContentPane().setLayout(outerLayout); // create the 'new' panel first FormLayout newLayout = new FormLayout("left:pref:noGrow, 3dlu, fill:pref:grow", "bottom:pref:noGrow, 3dlu, bottom:pref:noGrow, 3dlu, bottom:pref:noGrow, 3dlu, bottom:pref:noGrow, 3dlu, bottom:pref:noGrow, fill:pref:grow"); JPanel newPanel = new JPanel(newLayout); this.newTranscriptButton = new JRadioButton(); this.newTranscriptButton.setText("New Transcriber"); this.newTranscriptButton.setSelected(true); this.newTranscriptButton.addActionListener(new ActionListener() { @Override/*w ww. j a va 2s. co m*/ public void actionPerformed(ActionEvent arg0) { realNameField.setEnabled(true); usernameField.setEnabled(true); passwordRequiredBox.setEnabled(true); if (passwordRequiredBox.isSelected()) { passwordField.setEnabled(true); checkField.setEnabled(true); } existingUserList.setEnabled(false); } }); this.existingTranscriptButton = new JRadioButton(); this.existingTranscriptButton.setText("Existing Transcriber"); this.existingTranscriptButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { realNameField.setEnabled(false); usernameField.setEnabled(false); passwordRequiredBox.setEnabled(false); passwordField.setEnabled(false); checkField.setEnabled(false); existingUserList.setEnabled(true); } }); ButtonGroup bg = new ButtonGroup(); bg.add(this.newTranscriptButton); bg.add(this.existingTranscriptButton); this.realNameField = new JTextField(); this.usernameField = new JTextField(); this.passwordRequiredBox = new JCheckBox(); this.passwordRequiredBox.setText("Use password"); this.passwordRequiredBox.setSelected(false); this.passwordRequiredBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { passwordField.setEnabled(passwordRequiredBox.isSelected()); checkField.setEnabled(passwordRequiredBox.isSelected()); } }); this.passwordField = new JPasswordField(); this.passwordField.setEnabled(false); this.checkField = new JPasswordField(); this.checkField.setEnabled(false); CellConstraints cc = new CellConstraints(); newPanel.add(new JLabel("Full Name:"), cc.xy(1, 1)); newPanel.add(this.realNameField, cc.xy(3, 1)); newPanel.add(new JLabel("Username:"), cc.xy(1, 3)); newPanel.add(this.usernameField, cc.xy(3, 3)); newPanel.add(this.passwordRequiredBox, cc.xyw(1, 5, 3)); newPanel.add(new JLabel("Password:"), cc.xy(1, 7)); newPanel.add(this.passwordField, cc.xy(3, 7)); newPanel.add(this.checkField, cc.xy(3, 9)); // create the 'existing' panel FormLayout existingLayout = new FormLayout( // just a list "fill:pref:grow", "fill:pref:grow"); JPanel existingPanel = new JPanel(existingLayout); List<String> existingUserData = new ArrayList<String>(); for (Transcriber t : session.getTranscribers()) existingUserData.add(t.getRealName() + " - " + t.getUsername()); this.existingUserList = new JList(existingUserData.toArray()); this.existingUserList.setEnabled(false); existingPanel.add(this.existingUserList, cc.xy(1, 1)); // create the button panel this.okButton = new JButton("OK"); this.okButton.setDefaultCapable(true); this.okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (checkDialog()) { okHandler(); } } }); getRootPane().setDefaultButton(okButton); this.cancelButton = new JButton("Cancel"); this.cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { cancelHandler(); } }); final JComponent bar = ButtonBarBuilder.buildOkCancelBar(okButton, cancelButton); this.getContentPane().add(bar, cc.xy(3, 9)); this.getContentPane().add(this.newTranscriptButton, cc.xy(2, 1)); this.getContentPane().add(newPanel, cc.xyw(2, 3, 2)); this.getContentPane().add(this.existingTranscriptButton, cc.xy(2, 5)); this.getContentPane().add(new JScrollPane(existingPanel), cc.xyw(2, 7, 2)); }
From source file:graphviewer.GraphCreate.java
/** * Create an instance of a directed graph *//*w w w .j a v a 2s . c o m*/ public GraphCreate() { super("SCCFinder"); this.graph = new DirectedSparseMultigraph<Integer, Integer>(); this.layout = new StaticLayout<Integer, Integer>(this.graph, new Dimension(600, 600)); final Transformer<Integer, Paint> redVertexPaint = new Transformer<Integer, Paint>() { public Paint transform(Integer i) { return Color.RED; } }; this.vv = new VisualizationViewer<Integer, Integer>(this.layout); this.vv.setBackground(Color.white); this.vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>()); this.vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); Container content = getContentPane(); content.add(this.vv); this.vv.getRenderContext().setVertexFillPaintTransformer(redVertexPaint); // add listeners to our visual component Factory<Integer> vertexFactory = new VertexFactory(); Factory<Integer> edgeFactory = new EdgeFactory(); this.graphMouse = new EditingModalGraphMouse<Integer, Integer>(this.vv.getRenderContext(), vertexFactory, edgeFactory); this.vv.setGraphMouse(this.graphMouse); this.vv.addKeyListener(new MyKeyListener()); final MouseListener[] mls = (MouseListener[]) (this.vv.getListeners(MouseListener.class)); final MouseListener wrapper = new MyWrapperMouseListener(mls[1]); this.graphMouse.setMode(ModalGraphMouse.Mode.EDITING); this.vv.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); this.controls = new JPanel(); final ScalingControl scaler = new CrossoverScalingControl(); // add some buttons this.plus = new JButton("+"); this.plus.setToolTipText("Press this button or use the mouse wheel to zoom out"); this.plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); setFocusable(false); } }); this.minus = new JButton("-"); this.minus.setToolTipText("Press this button or use the mouse wheel to zoom in"); this.minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); setFocusable(false); } }); this.edit = new JRadioButton("Editing"); this.edit.setToolTipText("You can just press 'e' to select this radiobutton"); this.edit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { graphMouse.setMode(ModalGraphMouse.Mode.EDITING); vv.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); setFocusable(false); } }); this.transform = new JRadioButton("Transforming"); this.transform.setToolTipText("You can just press 't' to select this radiobutton"); this.transform.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); vv.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); setFocusable(false); } }); this.pick = new JRadioButton("Picking"); this.pick.setToolTipText("You can just press 'p' to select this radiobutton"); this.pick.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setCursor(new Cursor(Cursor.HAND_CURSOR)); setFocusable(false); } }); GraphCreate.scc = new JButton("SCC"); GraphCreate.scc.setToolTipText("Strongly Connected Components algorithm"); GraphCreate.scc.setEnabled(false); GraphCreate.scc.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { createMathgraph(); GraphCreate.scc.setEnabled(false); edit.setEnabled(false); pick.setSelected(true); setFocusable(false); sccButtonPressed = true; graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setCursor(new Cursor(Cursor.HAND_CURSOR)); vv.removeMouseListener(mls[1]); vv.addMouseListener(wrapper); } }); GraphCreate.clear = new JButton("Clear"); GraphCreate.clear.setToolTipText("Clears our graph"); GraphCreate.clear.setEnabled(false); GraphCreate.clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for (int k = 0; k <= numberOfVertices; k++) { graph.removeVertex(k); } GraphCreate.scc.setEnabled(false); GraphCreate.clear.setEnabled(false); edit.setEnabled(true); edit.setSelected(true); setFocusable(false); graphMouse.setMode(ModalGraphMouse.Mode.EDITING); vv.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); vv.getRenderContext().setVertexFillPaintTransformer(redVertexPaint); if (sccButtonPressed) { vv.removeMouseListener(wrapper); vv.addMouseListener(mls[1]); } vv.repaint(); // calling garbage collector here Runtime r = Runtime.getRuntime(); r.gc(); GraphCreate.numberOfEdges = 0; GraphCreate.numberOfVertices = 0; sccButtonPressed = false; } }); ButtonGroup actions = new ButtonGroup(); actions.add(this.edit); actions.add(this.transform); actions.add(this.pick); this.edit.setSelected(true); this.controls.add(this.plus); this.controls.add(this.minus); this.controls.add(this.edit); this.controls.add(this.transform); this.controls.add(this.pick); this.controls.add(GraphCreate.scc); controls.add(GraphCreate.clear); this.help = new JButton("Help"); this.help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(vv, instructions); setFocusable(false); } }); this.controls.add(this.help); content.add(this.controls, BorderLayout.SOUTH); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.GlobalViewExperimentController.java
/** * Initialize plot options panel./*from w ww . j a va2 s . c o m*/ */ private void initPlotOptionsPanel() { // make new view plotOptionsPanel = new PlotOptionsPanel(); // add radiobuttons to a button group ButtonGroup scaleAxesButtonGroup = new ButtonGroup(); scaleAxesButtonGroup.add(plotOptionsPanel.getDoNotScaleAxesRadioButton()); scaleAxesButtonGroup.add(plotOptionsPanel.getScaleAxesRadioButton()); plotOptionsPanel.getDoNotScaleAxesRadioButton().setSelected(true); // another button group for the shifted/unshifted coordinates ButtonGroup shiftedCoordinatesButtonGroup = new ButtonGroup(); shiftedCoordinatesButtonGroup.add(plotOptionsPanel.getShiftedCoordinatesRadioButton()); shiftedCoordinatesButtonGroup.add(plotOptionsPanel.getUnshiftedCoordinatesRadioButton()); plotOptionsPanel.getUnshiftedCoordinatesRadioButton().setSelected(true); /** * Action listeners */ // do not scale axes plotOptionsPanel.getDoNotScaleAxesRadioButton().addActionListener((ActionEvent e) -> { int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem()); boolean useRawData = plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected(); resetPlotLogic(); generateDataForPlots(useRawData); // use the data to set the charts setChartsWithCollections(nCols); }); // scale axes to the experiment range plotOptionsPanel.getScaleAxesRadioButton().addActionListener((ActionEvent e) -> { boolean useRawData = plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected(); coordinatesChartPanels.stream().forEach((chartPanel) -> { trackCoordinatesController.scaleAxesToExperiment(chartPanel.getChart(), useRawData); }); }); // shift the all coordinates to the origin plotOptionsPanel.getShiftedCoordinatesRadioButton().addActionListener((ActionEvent e) -> { int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem()); resetPlotLogic(); generateDataForPlots(false); // use the data to set the charts setChartsWithCollections(nCols); }); // replot the unshifted coordinates plotOptionsPanel.getUnshiftedCoordinatesRadioButton().addActionListener((ActionEvent e) -> { int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem()); resetPlotLogic(); generateDataForPlots(true); // use the data to set the charts setChartsWithCollections(nCols); }); // replot with a different number of columns plotOptionsPanel.getnColsComboBox().addActionListener((ActionEvent e) -> { int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem()); boolean useRawData = plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected(); resetPlotLogic(); generateDataForPlots(useRawData); // use the data to set the charts setChartsWithCollections(nCols); }); plotOptionsPanel.getPlotSettingsPanel().add(plotSettingsMenuBar, BorderLayout.CENTER); // add view to parent component trackCoordinatesController.getTrackCoordinatesPanel().getOptionsExperimentParentPanel() .add(plotOptionsPanel, gridBagConstraints); }
From source file:TabbedPaneTest.java
public TabbedPaneFrame() { setTitle("TabbedPaneTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); tabbedPane = new JTabbedPane(); // we set the components to null and delay their loading until the tab is shown // for the first time ImageIcon icon = new ImageIcon("yellow-ball.gif"); tabbedPane.addTab("Mercury", icon, null); tabbedPane.addTab("Venus", icon, null); tabbedPane.addTab("Earth", icon, null); tabbedPane.addTab("Mars", icon, null); tabbedPane.addTab("Jupiter", icon, null); tabbedPane.addTab("Saturn", icon, null); tabbedPane.addTab("Uranus", icon, null); tabbedPane.addTab("Neptune", icon, null); tabbedPane.addTab("Pluto", null, null); final int plutoIndex = tabbedPane.indexOfTab("Pluto"); JPanel plutoPanel = new JPanel(); plutoPanel.add(new JLabel("Pluto", icon, SwingConstants.LEADING)); JToggleButton plutoCheckBox = new JCheckBox(); plutoCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tabbedPane.remove(plutoIndex); }// w w w .java2 s .co m }); plutoPanel.add(plutoCheckBox); tabbedPane.setTabComponentAt(plutoIndex, plutoPanel); add(tabbedPane, "Center"); tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { // check if this tab still has a null component if (tabbedPane.getSelectedComponent() == null) { // set the component to the image icon int n = tabbedPane.getSelectedIndex(); loadTab(n); } } }); loadTab(0); JPanel buttonPanel = new JPanel(); ButtonGroup buttonGroup = new ButtonGroup(); JRadioButton wrapButton = new JRadioButton("Wrap tabs"); wrapButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { tabbedPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT); } }); buttonPanel.add(wrapButton); buttonGroup.add(wrapButton); wrapButton.setSelected(true); JRadioButton scrollButton = new JRadioButton("Scroll tabs"); scrollButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); } }); buttonPanel.add(scrollButton); buttonGroup.add(scrollButton); add(buttonPanel, BorderLayout.SOUTH); }
From source file:de.fhg.iais.asc.ui.parts.TransformersPanel.java
private JPanel createSelectTransformersRadioGroup() { this.localTransformersRadioButton = LocalizedUI.createRadioButton("Transform.UseLocalScripts"); //$NON-NLS-1$ this.localTransformersRadioButton.setSelected(true); this.remoteTransformersRadioButton = LocalizedUI.createRadioButton("Transform.UseRemoteScripts"); //$NON-NLS-1$ // You've to remove this if the transformer scripts presenting server is enabled. this.remoteTransformersRadioButton.setEnabled(false); // Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(this.localTransformersRadioButton); group.add(this.remoteTransformersRadioButton); JPanel tranformersInnerPanel = new JPanel(new GridLayout(2, 1)); this.localTransformersRadioButton.addActionListener(new ActionListener() { @Override/*from ww w . j a v a 2 s. co m*/ public void actionPerformed(ActionEvent e) { if (TransformersPanel.this.localTransformersRadioButton.isSelected()) { TransformersPanel.this.myCortexModel.getConfig().put(AscConfiguration.TRANSFORMERS_URL, DEFAULT_TRANSFORMER_URL); } } }); this.remoteTransformersRadioButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (TransformersPanel.this.remoteTransformersRadioButton.isSelected()) { // get the frame the panel is embedded in Component currentComponent = TransformersPanel.this; while (currentComponent.getParent() != null && !(currentComponent instanceof JFrame)) { currentComponent = currentComponent.getParent(); } final JFrame parentFrame = currentComponent instanceof JFrame ? (JFrame) currentComponent : null; (new TransformationURLWindow(parentFrame, TransformersPanel.this.myCortexModel.getConfig())) .setVisible(true); if (TransformersPanel.this.myCortexModel.getConfig() .get(AscConfiguration.TRANSFORMERS_URL, DEFAULT_TRANSFORMER_URL) .equals(DEFAULT_TRANSFORMER_URL)) { TransformersPanel.this.remoteTransformersRadioButton.setSelected(false); TransformersPanel.this.localTransformersRadioButton.setSelected(true); } } } }); tranformersInnerPanel.add(this.localTransformersRadioButton); tranformersInnerPanel.add(this.remoteTransformersRadioButton); return tranformersInnerPanel; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.filtering.FilteringController.java
/** * Initialize the main view: the filtering panel (the two sub-views are kept * in two separate controllers)./*from ww w .j ava2 s .c o m*/ */ private void initFilteringPanel() { // make a new view filteringPanel = new FilteringPanel(); // make a new radio button group for the radio buttons ButtonGroup radioButtonGroup = new ButtonGroup(); radioButtonGroup.add(filteringPanel.getSingleCutOffRadioButton()); radioButtonGroup.add(filteringPanel.getMultipleCutOffRadioButton()); // select the first one as default filteringPanel.getMultipleCutOffRadioButton().setSelected(true); // set icon for question button Icon questionIcon = UIManager.getIcon("OptionPane.questionIcon"); ImageIcon scaledQuestionIcon = GuiUtils.getScaledIcon(questionIcon); filteringPanel.getQuestionButton().setIcon(scaledQuestionIcon); // action listeners // info button filteringPanel.getQuestionButton().addActionListener((ActionEvent e) -> { // pack and show info dialog GuiUtils.centerDialogOnFrame(singleCellPreProcessingController.getMainFrame(), filteringInfoDialog); filteringInfoDialog.setVisible(true); }); // which criterium for the filtering? filteringPanel.getMultipleCutOffRadioButton().addActionListener((ActionEvent e) -> { // need to reset the conditions list back to active singleCellPreProcessingController.getConditionsList().setEnabled(true); // set as the current condition the first one in the list singleCellPreProcessingController .setCurrentCondition(singleCellPreProcessingController.getPlateConditionList().get(0)); singleCellPreProcessingController.getAnalysisPlatePanel() .setCurrentCondition(singleCellPreProcessingController.getPlateConditionList().get(0)); singleCellPreProcessingController.getAnalysisPlatePanel().repaint(); // get the layout from the bottom panel and show the appropriate one CardLayout layout = (CardLayout) filteringPanel.getBottomPanel().getLayout(); layout.show(filteringPanel.getBottomPanel(), filteringPanel.getMultipleCutOffParentPanel().getName()); multipleCutOffFilteringController.plotRawKdeMultipleCutOff(getCurrentCondition()); setMedianDisplForCondition(getCurrentCondition()); setMedianDisplForExperiment(); }); filteringPanel.getSingleCutOffRadioButton().addActionListener((ActionEvent e) -> { // need to disable the conditions list singleCellPreProcessingController.getConditionsList().clearSelection(); singleCellPreProcessingController.getConditionsList().setEnabled(false); singleCellPreProcessingController.setCurrentCondition(null); singleCellPreProcessingController.getAnalysisPlatePanel().setCurrentCondition(null); singleCellPreProcessingController.getAnalysisPlatePanel().repaint(); // get the layout from the bottom panel and show the appropriate one CardLayout layout = (CardLayout) filteringPanel.getBottomPanel().getLayout(); layout.show(filteringPanel.getBottomPanel(), filteringPanel.getSingleCutOffParentPanel().getName()); singleCutOffFilteringController.plotRawKdeSingleCutOff(); setMedianDisplForExperiment(); singleCutOffFilteringController.showMedianDisplInList(); }); // add view to parent container singleCellPreProcessingController.getSingleCellAnalysisPanel().getFilteringParentPanel().add(filteringPanel, gridBagConstraints); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDRInputController.java
@Override protected void initDRInputPanel() { dRInputPanel = new DRInputPanel(); conditionsList = new ArrayList<>(); // control opaque property of bottom table dRInputPanel.getSlopesTableScrollPane().getViewport().setBackground(Color.white); slopesTable = dRInputPanel.getSlopesTable(); slopesTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); slopesTable.getTableHeader().setReorderingAllowed(false); slopesTable.setFillsViewportHeight(true); slopesTable.setModel(new NonEditableTableModel()); //create a ButtonGroup for the radioButtons used for analysis ButtonGroup experimentTypeRadioButtonGroup = new ButtonGroup(); //adding buttons to a ButtonGroup automatically deselect one when another one gets selected experimentTypeRadioButtonGroup.add(dRInputPanel.getStimulationRadioButton()); experimentTypeRadioButtonGroup.add(dRInputPanel.getInhibitionRadioButton()); //select as default first button (Stimulation) dRInputPanel.getStimulationRadioButton().setSelected(true); /*// w ww . j av a 2s. c om * Action listeners for buttons */ dRInputPanel.getAddConditionButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //add selected condition to analysis addToDRAnalysis(); } }); dRInputPanel.getRemoveConditionButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // remove condition from analysis removeFromDRAnalysis(); } }); /** * Choosing stimulation or inhibition type experiment defines standard * hillslope parameter */ dRInputPanel.getStimulationRadioButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doseResponseController.setStandardHillslope(1); } }); dRInputPanel.getInhibitionRadioButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doseResponseController.setStandardHillslope(-1); } }); }
From source file:net.sf.jabref.openoffice.AutoDetectPaths.java
private boolean autoDetectPaths() { if (OS.WINDOWS) { List<File> progFiles = findProgramFilesDir(); File sOffice = null;/*from w w w . ja va 2 s . c om*/ List<File> sofficeFiles = new ArrayList<>(); for (File dir : progFiles) { if (fileSearchCancelled) { return false; } sOffice = findFileDir(dir, "soffice.exe"); if (sOffice != null) { sofficeFiles.add(sOffice); } } if (sOffice == null) { JOptionPane.showMessageDialog(parent, Localization.lang( "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."), Localization.lang("Could not find OpenOffice/LibreOffice installation"), JOptionPane.INFORMATION_MESSAGE); JFileChooser jfc = new JFileChooser(new File("C:\\")); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } @Override public String getDescription() { return Localization.lang("Directories"); } }); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.showOpenDialog(parent); if (jfc.getSelectedFile() != null) { sOffice = jfc.getSelectedFile(); } } if (sOffice == null) { return false; } if (sofficeFiles.size() > 1) { // More than one file found DefaultListModel<File> mod = new DefaultListModel<>(); for (File tmpfile : sofficeFiles) { mod.addElement(tmpfile); } JList<File> fileList = new JList<>(mod); fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fileList.setSelectedIndex(0); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref")); b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1); b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3); b.add(fileList).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } else { sOffice = fileList.getSelectedValue(); } } else { sOffice = sofficeFiles.get(0); } return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe"); } else if (OS.OS_X) { File rootDir = new File("/Applications"); File[] files = rootDir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName()) || "LibreOffice.app".equals(file.getName()))) { rootDir = file; break; } } } File sOffice = findFileDir(rootDir, SOFFICE_BIN); if (fileSearchCancelled) { return false; } if (sOffice == null) { return false; } else { return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN); } } else { // Linux: String usrRoot = "/usr/lib"; File inUsr = findFileDir(new File(usrRoot), SOFFICE); if (fileSearchCancelled) { return false; } if (inUsr == null) { inUsr = findFileDir(new File("/usr/lib64"), SOFFICE); if (inUsr != null) { usrRoot = "/usr/lib64"; } } if (fileSearchCancelled) { return false; } File inOpt = findFileDir(new File("/opt"), SOFFICE); if (fileSearchCancelled) { return false; } if ((inUsr != null) && (inOpt == null)) { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } else if (inOpt != null) { if (inUsr == null) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { // Found both JRadioButton optRB = new JRadioButton(inOpt.getPath(), true); JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false); ButtonGroup bg = new ButtonGroup(); bg.add(optRB); bg.add(usrRB); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref ")); b.add(Localization.lang( "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:")) .xy(1, 1); b.add(optRB).xy(1, 3); b.add(usrRB).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } if (optRB.isSelected()) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } } } } return false; }
From source file:edu.ku.brc.specify.prefs.AttachmentPrefs.java
/** * //from w w w. ja va 2 s. c o m */ public AttachmentPrefs() { super(); createForm("Preferences", "Attachments"); PanelViewable pathPanel = form.getCompById("path_panel"); PanelViewable urlPanel = form.getCompById("url_panel"); isPublicDefChk = form.getCompById(ATTCH_PUB_DEF); pathBrwse = form.getCompById(ATTCH_PATH_ID); pathLbl = form.getLabelFor(ATTCH_PATH_ID); urlTxt = form.getCompById(ATTCH_URL_ID); urlLbl = form.getLabelFor(ATTCH_URL_ID); keyTxt = form.getCompById(ATTCH_KEY_ID); keyLbl = form.getLabelFor(ATTCH_KEY_ID); isInitialized = pathPanel != null && urlPanel != null && pathBrwse != null && pathLbl != null && urlTxt != null && urlLbl != null; if (!isInitialized) { UIRegistry.showError("The form is not setup correctly."); return; } isUsingGlobalAttchPrefs = globalPrefs.getBoolean(USE_GLOBAL_PREFS, false); canEditGlobalAttchPrefs = localPrefs.getBoolean(EDT_GLOBAL_PREFS, false); UIRegistry.loadAndPushResourceBundle("preferences"); pathRB = UIHelper.createRadioButton(UIRegistry.getResourceString("USE_ATTACH_PATH")); urlRB = UIHelper.createRadioButton(UIRegistry.getResourceString("USE_ATTACH_URL")); UIRegistry.popResourceBundle(); pathRB.setOpaque(false); urlRB.setOpaque(false); ButtonGroup group = new ButtonGroup(); group.add(pathRB); group.add(urlRB); CellConstraints cc = new CellConstraints(); if (pathPanel != null) pathPanel.add(pathRB, cc.xy(1, 1)); if (urlPanel != null) urlPanel.add(urlRB, cc.xy(1, 1)); JButton saveGGblPrefs = form.getCompById("SaveGGblPrefs"); JButton clearGGblPrefs = form.getCompById("ClearGGblPrefs"); if (saveGGblPrefs != null) { saveGGblPrefs.setVisible(isUsingGlobalAttchPrefs && canEditGlobalAttchPrefs); saveGGblPrefs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { oldAttachmentURL = (String) urlTxt.getText().trim(); oldAttachmentKey = (String) keyTxt.getText().trim(); globalPrefs.put(ATTACHMENT_PATH, oldAttachmentPath); globalPrefs.put(ATTACHMENT_URL, oldAttachmentURL); globalPrefs.put(ATTACHMENT_KEY, oldAttachmentKey); globalPrefs.putBoolean(ATTACHMENT_USE_PATH, pathRB.isSelected()); // Make sure local prefs is set for the type we are using. localPrefs.putBoolean(ATTACHMENT_USE_PATH, pathRB.isSelected()); //remotePrefs.putBoolean(ATTCH_PUB_DEF, isPublicDefChk.isSelected()); } }); } if (clearGGblPrefs != null) { clearGGblPrefs.setVisible(isUsingGlobalAttchPrefs && canEditGlobalAttchPrefs); clearGGblPrefs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { globalPrefs.remove(ATTACHMENT_PATH); globalPrefs.remove(ATTACHMENT_URL); globalPrefs.remove(ATTACHMENT_KEY); globalPrefs.remove(ATTACHMENT_USE_PATH); try { globalPrefs.flush(); } catch (BackingStoreException e) { e.printStackTrace(); } } }); } if (!isUsingGlobalAttchPrefs || canEditGlobalAttchPrefs) { ActionListener al = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleAttachmentsEnabledState(pathRB.isSelected()); } }; pathRB.addActionListener(al); urlRB.addActionListener(al); } else { pathBrwse.setEnabled(false); urlTxt.setEnabled(false); keyTxt.setEnabled(false); pathRB.setEnabled(false); urlRB.setEnabled(false); } setDataIntoUI(); }
From source file:edu.wpi.cs.wpisuitetng.modules.requirementsmanager.view.charts.StatView.java
/** * Builds the side panel with all the options for this StatViw * /*from w w w . j ava 2 s . c o m*/ * @return the formatted side panel */ public JPanel buildSidePanel() { final int VERTICAL_PADDING = 5; final int HORIZONTAL_PADDING = 5; final int FAR = 5; final SpringLayout sidePanelLayout = new SpringLayout(); final JPanel sidePanel = new JPanel(sidePanelLayout); final JLabel lblStatisticType = new JLabel("Statistic Type"); final String[] availableStatisticTypes = { "Status", "Assignees", "Iterations", "Velocity" }; // TODO: Add Estimates, Effort, Tasks charts for future use. comboBoxStatisticType = new JComboBox(availableStatisticTypes); comboBoxStatisticType.addActionListener(this); makePieRadio = new JRadioButton("Pie Chart"); makePieRadio.setMnemonic(KeyEvent.VK_P); makePieRadio.setActionCommand("Pie Chart"); makePieRadio.addActionListener(this); makeBarRadio = new JRadioButton("Bar Chart"); makeBarRadio.setMnemonic(KeyEvent.VK_B); makeBarRadio.setActionCommand("Bar Chart"); makeBarRadio.addActionListener(this); makeLineRadio = new JRadioButton("Line Chart"); makeLineRadio.setMnemonic(KeyEvent.VK_B); makeLineRadio.setActionCommand("Line Chart"); makeLineRadio.addActionListener(this); makeLineRadio.setEnabled(false); final ButtonGroup group = new ButtonGroup(); group.add(makePieRadio); group.add(makeBarRadio); group.add(makeLineRadio); updateSelectedItems(); final JPanel radioPanel = new JPanel(new GridLayout(3, 1)); radioPanel.add(makePieRadio); radioPanel.add(makeBarRadio); radioPanel.add(makeLineRadio); radioPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Chart Type")); sidePanel.add(lblStatisticType); sidePanel.add(comboBoxStatisticType); sidePanel.add(radioPanel); sidePanelLayout.putConstraint(SpringLayout.NORTH, lblStatisticType, VERTICAL_PADDING, SpringLayout.NORTH, sidePanel); sidePanelLayout.putConstraint(SpringLayout.WEST, lblStatisticType, HORIZONTAL_PADDING, SpringLayout.WEST, sidePanel); sidePanelLayout.putConstraint(SpringLayout.NORTH, comboBoxStatisticType, VERTICAL_PADDING, SpringLayout.SOUTH, lblStatisticType); sidePanelLayout.putConstraint(SpringLayout.WEST, comboBoxStatisticType, HORIZONTAL_PADDING, SpringLayout.WEST, sidePanel); sidePanelLayout.putConstraint(SpringLayout.NORTH, radioPanel, VERTICAL_PADDING + FAR, SpringLayout.SOUTH, comboBoxStatisticType); sidePanelLayout.putConstraint(SpringLayout.WEST, radioPanel, HORIZONTAL_PADDING, SpringLayout.WEST, sidePanel); return sidePanel; }