List of usage examples for javax.swing JButton addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:com.liveperson.infra.akka.actorx.ui.DisplayGraph.java
public static JPanel getGraphPanel() { final VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(new FRLayout(graph)); vv.setBackground(Color.white); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(vv.getPickedVertexState(), Color.blue, Color.yellow)); vv.getRenderContext().setVertexLabelTransformer(new Transformer<String, String>() { @Override/* www.j ava 2s. com*/ public String transform(String s) { return getClassName(s); } }); vv.setVertexToolTipTransformer(new Transformer<String, String>() { @Override public String transform(String s) { return getClassName(s); } }); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<String>(vv.getPickedEdgeState(), Color.black, Color.green)); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<String, String>()); vv.setEdgeToolTipTransformer(new Transformer<String, String>() { @Override public String transform(String edge) { StringBuffer buffer = new StringBuffer(); buffer.append("<html>"); int index = edge.indexOf(Main.DELIMITER); String fromActor = edge.substring(0, index); String toActor = edge.substring(index + Main.DELIMITER.length()); Map<String, Set<String>> connections = castConnectionList.get(fromActor); Set<String> messages = connections.get(toActor); for (String msg : messages) { buffer.append("<p>").append(getClassName(msg)); } buffer.append("</html>"); return buffer.toString(); } }); ToolTipManager.sharedInstance().setDismissDelay(60000); final DefaultModalGraphMouse<String, String> graphMouse = new DefaultModalGraphMouse<String, String>(); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(graphMouse); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Layout<String, String> layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { // if(layout instanceof IterativeContext) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); JPanel jp = new JPanel(); jp.setBackground(Color.WHITE); jp.setLayout(new BorderLayout()); jp.add(vv, BorderLayout.CENTER); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); JPanel control_panel = new JPanel(new GridLayout(2, 1)); JPanel topControls = new JPanel(); JPanel bottomControls = new JPanel(); control_panel.add(topControls); control_panel.add(bottomControls); jp.add(control_panel, BorderLayout.NORTH); topControls.add(jcb); bottomControls.add(plus); bottomControls.add(minus); bottomControls.add(reset); return jp; }
From source file:bigdata.explorer.nutch.grapview.ShowLayouts.java
private static JPanel getGraphPanel() throws IOException { g_array = (Graph<? extends Object, ? extends Object>[]) new Graph<?, ?>[graph_names.length]; Factory<Graph<Integer, Number>> graphFactory = new Factory<Graph<Integer, Number>>() { public Graph<Integer, Number> create() { return new SparseMultigraph<Integer, Number>(); }//ww w . j a v a 2s. c om }; Factory<Integer> vertexFactory = new Factory<Integer>() { int count; public Integer create() { return count++; } }; Factory<Number> edgeFactory = new Factory<Number>() { int count; public Number create() { return count++; } }; g_array[0] = TestGraphs.createTestGraph(false); g_array[1] = MixedRandomGraphGenerator.generateMixedRandomGraph(graphFactory, vertexFactory, edgeFactory, new HashMap<Number, Number>(), 20, true, new HashSet<Integer>()); g_array[2] = TestGraphs.getDemoGraph(); g_array[3] = TestGraphs.createDirectedAcyclicGraph(4, 4, 0.3); g_array[4] = TestGraphs.getOneComponentGraph(); g_array[5] = TestGraphs.createChainPlusIsolates(18, 5); g_array[6] = TestGraphs.createChainPlusIsolates(0, 20); g_array[7] = NutchGraphLoader.loadFullGraph("/home/kamir/ANALYSIS/Nutch/YellowMED_CORE"); Graph<? extends Object, ? extends Object> g = g_array[4]; // initial graph final VisualizationViewer<Integer, Number> vv = new VisualizationViewer<Integer, Number>(new FRLayout(g)); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow)); final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(graphMouse); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Layout<Integer, Number> layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { // if(layout instanceof IterativeContext) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener()); JPanel jp = new JPanel(); jp.setBackground(Color.WHITE); jp.setLayout(new BorderLayout()); jp.add(vv, BorderLayout.CENTER); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); JPanel control_panel = new JPanel(new GridLayout(2, 1)); JPanel topControls = new JPanel(); JPanel bottomControls = new JPanel(); control_panel.add(topControls); control_panel.add(bottomControls); jp.add(control_panel, BorderLayout.NORTH); final JComboBox graph_chooser = new JComboBox(graph_names); graph_chooser.addActionListener(new GraphChooser(jcb)); topControls.add(jcb); topControls.add(graph_chooser); bottomControls.add(plus); bottomControls.add(minus); bottomControls.add(modeBox); bottomControls.add(reset); return jp; }
From source file:edu.mbl.jif.datasetconvert.CheckboxTreeDimensions.java
public static void test() { JSONObject sumMD = SumMetadata.newSummaryMetadata("", "", new ImageAttributes(100, 100), new String[] { "Aniso", "Orient", "Sample0", "Sample1" }, 5, 10, 1, "source", "comment"); final CheckboxTreeDimensions tree = new CheckboxTreeDimensions(sumMD); QuickFrame f = new QuickFrame("Test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(300, 600);/*from w w w .ja v a2s . co m*/ Container jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); JScrollPane cbt = tree.getCheckboxTree(); cbt.setPreferredSize(new Dimension(200, 400)); jContentPane.add(cbt, BorderLayout.CENTER); JButton buttonTest = new JButton("test"); buttonTest.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tree.getSelectedIndices(); } }); jContentPane.add(buttonTest, BorderLayout.SOUTH); f.setContentPane(jContentPane); f.setTitle("CheckboxTree"); f.pack(); f.setVisible(true); }
From source file:AddingButtonWithActionListener.java
public static JButton getButton(final JOptionPane optionPane, String text, Icon icon) { final JButton button = new JButton(text, icon); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { // Return current text label, instead of argument to method optionPane.setValue(button.getText()); System.out.println(button.getText()); }// w w w . j a v a 2s. c om }; button.addActionListener(actionListener); return button; }
From source file:jatoo.proxy.dialog.ProxyDialog.java
/** * Shows the dialog relative to the specified owner. *///from w w w. j av a2 s . c om public static synchronized void show(Component owner) { JDialog dialogTmp; if (owner == null) { dialogTmp = new JDialog(); } else { dialogTmp = new JDialog(SwingUtilities.getWindowAncestor(owner)); } final JDialog dialog = dialogTmp; // // the panel final ProxyDialogPanel dialogPanel = PROXY_DIALOG_PANEL_FACTORY.createDialogPanel(); try { Proxy proxy = new Proxy(); proxy.load(); dialogPanel.setProxyEnabled(proxy.isEnabled()); dialogPanel.setHost(proxy.getHost()); dialogPanel.setPort(proxy.getPort()); dialogPanel.setProxyRequiringAuthentication(proxy.isRequiringAuthentication()); dialogPanel.setUsername(proxy.getUsername()); dialogPanel.setPassword(proxy.getPassword()); } catch (FileNotFoundException e) { // do nothing, maybe is the first time and the file is missing } catch (Exception e) { logger.error("Failed to load the properties.", e); } // // buttons JButton okButton = new JButton("Ok"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { if (dialogPanel.isProxyEnabled()) { if (dialogPanel.isProxyRequiringAuthentication()) { ProxyUtils.setProxy(dialogPanel.getHost(), dialogPanel.getPort(), dialogPanel.getUsername(), dialogPanel.getPassword()); } else { ProxyUtils.setProxy(dialogPanel.getHost(), dialogPanel.getPort()); } } else { ProxyUtils.removeProxy(); } dialog.dispose(); } catch (Exception e) { JOptionPane.showMessageDialog(dialog, "Failed to set the proxy:\n" + e.toString()); return; } try { Proxy proxy = new Proxy(); proxy.setEnabled(dialogPanel.isProxyEnabled()); proxy.setUsername(dialogPanel.getUsername()); proxy.setPassword(dialogPanel.getPassword()); proxy.setRequiringAuthentication(dialogPanel.isProxyRequiringAuthentication()); proxy.setHost(dialogPanel.getHost()); proxy.setPort(dialogPanel.getPort()); proxy.store(); } catch (Exception e) { logger.error("Failed to save the properties.", e); } } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); // // layout dialog dialogPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel buttonsGroup = new JPanel(new GridLayout(1, 2, 5, 5)); buttonsGroup.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); buttonsGroup.add(okButton); buttonsGroup.add(cancelButton); JPanel buttonsPanel = new JPanel(new BorderLayout()); buttonsPanel.add(buttonsGroup, BorderLayout.LINE_END); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(dialogPanel, BorderLayout.CENTER); contentPane.add(buttonsPanel, BorderLayout.PAGE_END); // // setup dialog dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setTitle("Proxy Settings"); dialog.setContentPane(contentPane); dialog.pack(); dialog.setLocationRelativeTo(dialog.getOwner()); dialog.setModal(true); // // and show dialog.setVisible(true); }
From source file:MainClass.java
public static JScrollPane createPagingScrollPaneForTable(JTable jt) { JScrollPane jsp = new JScrollPane(jt); TableModel tmodel = jt.getModel(); if (!(tmodel instanceof PagingModel)) { return jsp; }/*ww w. j ava 2 s . c o m*/ final PagingModel model = (PagingModel) tmodel; final JButton upButton = new JButton("UP"); upButton.setEnabled(false); final JButton downButton = new JButton("DOWN"); if (model.getPageCount() <= 1) { downButton.setEnabled(false); } upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageUp(); if (model.getPageOffset() == 0) { upButton.setEnabled(false); } downButton.setEnabled(true); } }); downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageDown(); if (model.getPageOffset() == (model.getPageCount() - 1)) { downButton.setEnabled(false); } upButton.setEnabled(true); } }); jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton); jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton); return jsp; }
From source file:ch.admin.hermes.etl.load.HermesETLApplication.java
/** * CommandLine parse und fehlende Argumente verlangen * @param args Args// w w w. j a v a 2 s . co m * @throws ParseException */ private static void parseCommandLine(String[] args) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // HACK um UTF-8 CharSet fuer alle Dateien zu setzen (http://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding) System.setProperty("file.encoding", "UTF-8"); Field charset = Charset.class.getDeclaredField("defaultCharset"); charset.setAccessible(true); charset.set(null, null); // commandline Options - FremdsystemSite, Username und Password Options options = new Options(); options.addOption("s", true, "Zielsystem - URL"); options.addOption("u", true, "Zielsystem - Username"); options.addOption("p", true, "Zielsystem - Password"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); site = cmd.getOptionValue("s"); user = cmd.getOptionValue("u"); passwd = cmd.getOptionValue("p"); // restliche Argumente pruefen - sonst usage ausgeben String[] others = cmd.getArgs(); if (others.length >= 1 && (others[0].endsWith(".js") || others[0].endsWith(".ftl"))) script = others[0]; if (others.length >= 2 && others[1].endsWith(".xml")) model = others[1]; // Dialog mit allen Werten zusammenstellen JComboBox<String> scenarios = new JComboBox<String>(crawler.getScenarios()); JTextField tsite = new JTextField(45); tsite.setText(site); JTextField tuser = new JTextField(16); tuser.setText(user); JPasswordField tpasswd = new JPasswordField(16); tpasswd.setText(passwd); final JTextField tscript = new JTextField(45); tscript.setText(script); final JTextField tmodel = new JTextField(45); tmodel.setText(model); JPanel myPanel = new JPanel(new GridLayout(6, 2)); myPanel.add(new JLabel("Szenario (von http://www.hermes.admin.ch):")); myPanel.add(scenarios); myPanel.add(new JLabel("XML Model:")); myPanel.add(tmodel); JPanel pmodel = new JPanel(); pmodel.add(tmodel); JButton bmodel = new JButton("..."); pmodel.add(bmodel); bmodel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model = getFile("Szenario XML Model", new String[] { "XML Model" }, new String[] { ".xml" }); if (model != null) tmodel.setText(model); } }); myPanel.add(pmodel); scenarios.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { try { Object o = e.getItem(); tmodel.setText(crawler.getModelURL(o.toString())); scenario = o.toString(); } catch (Exception e1) { } } }); // Script myPanel.add(new JLabel("Umwandlungs-Script:")); JPanel pscript = new JPanel(); pscript.add(tscript); JButton bscript = new JButton("..."); pscript.add(bscript); myPanel.add(pscript); bscript.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { script = getFile("JavaScript/Freemarker Umwandlungs-Script", new String[] { "JavaScript", "Freemarker" }, new String[] { ".js", ".ftl" }); if (script != null) tscript.setText(script); } }); // Zielsystem Angaben myPanel.add(new JLabel("Zielsystem URL:")); myPanel.add(tsite); myPanel.add(new JLabel("Zielsystem Benutzer:")); myPanel.add(tuser); myPanel.add(new JLabel("Zielsystem Password:")); myPanel.add(tpasswd); // Trick um Feld scenario und model zu setzen. if (scenarios.getItemCount() >= 8) scenarios.setSelectedIndex(8); // Dialog int result = JOptionPane.showConfirmDialog(null, myPanel, "HERMES 5 XML Model nach Fremdsystem/Format", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { site = tsite.getText(); user = tuser.getText(); passwd = new String(tpasswd.getPassword()); model = tmodel.getText(); script = tscript.getText(); } else System.exit(1); if (model == null || script == null || script.trim().length() == 0) usage(); if (script.endsWith(".js")) if (site == null || user == null || passwd == null || user.trim().length() == 0 || passwd.trim().length() == 0) usage(); }
From source file:org.datacleaner.widgets.result.AbstractCrosstabResultSwingRenderer.java
public static DCPanel createActionableValuePanel(Object value, Alignment alignment, ActionListener action, String iconImagePath) {/* ww w .ja va2s .c o m*/ final JLabel label = new JLabel(getLabelText(value)); final DCPanel panel = new DCPanel(); panel.add(label); panel.setLayout(new FlowLayout(alignment.getFlowLayoutAlignment(), 0, 0)); if (action != null && iconImagePath != null) { final JButton button = WidgetFactory.createSmallButton(iconImagePath); button.addActionListener(action); panel.add(Box.createHorizontalStrut(4)); panel.add(button); } return panel; }
From source file:org.drugis.mtc.gui.results.ResultsComponentFactory.java
/** * @param labelText Descriptive label for this memory usage entry * @param parent Parent for "save samples" dialog *//* w ww.ja v a 2 s . c o m*/ public static int buildMemoryUsage(final MTCModelWrapper<?> model, final String labelText, final PanelBuilder builder, final FormLayout layout, final int row, final JFrame parent) { final CellConstraints cc = new CellConstraints(); if (model.isSaved()) { LayoutUtil.addRow(layout); builder.add(new JLabel(labelText), cc.xy(1, row)); builder.add(new JLabel("N/A"), cc.xyw(3, row, 7)); return row + 2; } else { final MixedTreatmentComparison mtc = model.getModel(); final MCMCResultsMemoryUsageModel memoryModel = new MCMCResultsMemoryUsageModel(mtc.getResults()); final JLabel memory = BasicComponentFactory.createLabel(new ToStringValueModel(memoryModel)); final MCMCResultsAvailableModel resultsAvailableModel = new MCMCResultsAvailableModel(mtc.getResults()); final TaskTerminatedModel modelTerminated = new TaskTerminatedModel(mtc.getActivityTask()); final JButton clearButton = new JButton(MainWindow.IMAGELOADER.getIcon(FileNames.ICON_DELETE)); clearButton.setToolTipText("Clear results"); final BooleanAndModel modelFinishedAndResults = new BooleanAndModel( Arrays.<ValueModel>asList(modelTerminated, resultsAvailableModel)); Bindings.bind(clearButton, "enabled", modelFinishedAndResults); final JButton saveButton = new JButton(MainWindow.IMAGELOADER.getIcon(FileNames.ICON_SAVEFILE)); saveButton.setToolTipText("Save to R-file"); Bindings.bind(saveButton, "enabled", modelFinishedAndResults); saveButton.addActionListener(buildRButtonActionListener(mtc, parent)); clearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { mtc.getResults().clear(); // FIXME: change MCMC contract so clear fires a MCMCResultsClearedEvent memoryModel.resultsEvent(new MCMCResultsEvent(mtc.getResults())); resultsAvailableModel.resultsEvent(new MCMCResultsEvent(mtc.getResults())); } }); LayoutUtil.addRow(layout); builder.add(new JLabel(labelText), cc.xy(1, row)); builder.add(memory, cc.xy(3, row)); builder.add(clearButton, cc.xy(5, row)); builder.add(saveButton, cc.xy(7, row)); return row + 2; } }
From source file:com.sshtools.common.ui.SshToolsConnectionPanel.java
/** * * * @param parent/* www. j a va 2 s. c o m*/ * @param profile * @param optionalTabs * * @return */ public static SshToolsConnectionProfile showConnectionDialog(Component parent, SshToolsConnectionProfile profile, SshToolsConnectionTab[] optionalTabs) { // If no properties are provided, then use the default if (profile == null) { int port = DEFAULT_PORT; String port_S = Integer.toString(DEFAULT_PORT); port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S); try { port = Integer.parseInt(port_S); } catch (NumberFormatException e) { log.warn("Could not parse the port number from defaults file (property name" + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ")."); } profile = new SshToolsConnectionProfile(); profile.setHost(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_HOST, "")); profile.setPort(PreferencesStore.getInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, port)); profile.setUsername(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_USER, "")); } final SshToolsConnectionPanel conx = new SshToolsConnectionPanel(true); if (optionalTabs != null) { for (int i = 0; i < optionalTabs.length; i++) { conx.addTab(optionalTabs[i]); } } conx.setConnectionProfile(profile); JDialog d = null; Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent); if (w instanceof JDialog) { d = new JDialog((JDialog) w, "Connection Profile", true); } else if (w instanceof JFrame) { d = new JDialog((JFrame) w, "Connection Profile", true); } else { d = new JDialog((JFrame) null, "Connection Profile", true); } final JDialog dialog = d; class UserAction { boolean connect; } final UserAction userAction = new UserAction(); // Create the bottom button panel final JButton cancel = new JButton("Cancel"); cancel.setMnemonic('c'); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { userAction.connect = false; dialog.setVisible(false); } }); final JButton connect = new JButton("Connect"); connect.setMnemonic('t'); connect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (conx.validateTabs()) { userAction.connect = true; dialog.setVisible(false); } } }); dialog.getRootPane().setDefaultButton(connect); JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(6, 6, 0, 0); gbc.weighty = 1.0; UIUtil.jGridBagAdd(buttonPanel, connect, gbc, GridBagConstraints.RELATIVE); UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER); JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); southPanel.add(buttonPanel); // JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPanel.add(conx, BorderLayout.CENTER); mainPanel.add(southPanel, BorderLayout.SOUTH); // Show the dialog dialog.getContentPane().setLayout(new GridLayout(1, 1)); dialog.getContentPane().add(mainPanel); dialog.pack(); dialog.setResizable(false); UIUtil.positionComponent(SwingConstants.CENTER, dialog); //show the simple box and act on the answer. SshToolsSimpleConnectionPrompt stscp = SshToolsSimpleConnectionPrompt.getInstance(); StringBuffer sb = new StringBuffer(); userAction.connect = !stscp.getHostname(sb, profile.getHost()); boolean advanced = stscp.getAdvanced(); if (advanced) { userAction.connect = false; profile.setHost(sb.toString()); conx.hosttab.setConnectionProfile(profile); dialog.setVisible(true); } // Make sure we didn't cancel if (!userAction.connect) { return null; } conx.applyTabs(); if (!advanced) profile.setHost(sb.toString()); if (!advanced) { int port = DEFAULT_PORT; String port_S = Integer.toString(DEFAULT_PORT); port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S); try { port = Integer.parseInt(port_S); } catch (NumberFormatException e) { log.warn("Could not parse the port number from defaults file (property name" + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ")."); } profile.setPort(port); } if (!advanced) profile.setUsername(""); PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_HOST, profile.getHost()); // only save user inputed configuration if (advanced) { PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_USER, profile.getUsername()); PreferencesStore.putInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, profile.getPort()); } // Return the connection properties return profile; }