List of usage examples for javax.swing JDialog dispose
public void dispose()
From source file:net.rptools.maptool.client.functions.InputFunction.java
@Override public Object childEvaluate(Parser parser, String functionName, List<Object> parameters) throws EvaluationException, ParserException { // Extract the list of specifier strings from the parameters // "name | value | prompt | inputType | options" List<String> varStrings = new ArrayList<String>(); for (Object param : parameters) { String paramStr = (String) param; if (StringUtils.isEmpty(paramStr)) { continue; }/*w w w . j a v a2 s. c o m*/ // Multiple vars can be packed into a string, separated by "##" List<String> substrings = new ArrayList<String>(); StrListFunctions.parse(paramStr, substrings, "##"); for (String varString : substrings) { if (StringUtils.isEmpty(paramStr)) { continue; } varStrings.add(varString); } } // Create VarSpec objects from each variable's specifier string List<VarSpec> varSpecs = new ArrayList<VarSpec>(); for (String specifier : varStrings) { VarSpec vs; try { vs = new VarSpec(specifier); } catch (VarSpec.SpecifierException se) { throw new ParameterException(se.msg); } catch (InputType.OptionException oe) { throw new ParameterException(I18N.getText("macro.function.input.invalidOptionType", oe.key, oe.value, oe.type, specifier)); } varSpecs.add(vs); } // Check if any variables were defined if (varSpecs.isEmpty()) return BigDecimal.ONE; // No work to do, so treat it as a successful invocation. // UI step 1 - First, see if a token is in context. VariableResolver varRes = parser.getVariableResolver(); Token tokenInContext = null; if (varRes instanceof MapToolVariableResolver) { tokenInContext = ((MapToolVariableResolver) varRes).getTokenInContext(); } String dialogTitle = "Input Values"; if (tokenInContext != null) { String name = tokenInContext.getName(), gm_name = tokenInContext.getGMName(); boolean isGM = MapTool.getPlayer().isGM(); String extra = ""; if (isGM && gm_name != null && gm_name.compareTo("") != 0) extra = " for " + gm_name; else if (name != null && name.compareTo("") != 0) extra = " for " + name; dialogTitle = dialogTitle + extra; } // UI step 2 - build the panel with the input fields InputPanel ip = new InputPanel(varSpecs); // Calculate the height // TODO: remove this workaround int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int maxHeight = screenHeight * 3 / 4; Dimension ipPreferredDim = ip.getPreferredSize(); if (maxHeight < ipPreferredDim.height) { ip.modifyMaxHeightBy(maxHeight - ipPreferredDim.height); } // UI step 3 - show the dialog JOptionPane jop = new JOptionPane(ip, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dlg = jop.createDialog(MapTool.getFrame(), dialogTitle); // Set up callbacks needed for desired runtime behavior dlg.addComponentListener(new FixupComponentAdapter(ip)); dlg.setVisible(true); int dlgResult = JOptionPane.CLOSED_OPTION; try { dlgResult = (Integer) jop.getValue(); } catch (NullPointerException npe) { } dlg.dispose(); if (dlgResult == JOptionPane.CANCEL_OPTION || dlgResult == JOptionPane.CLOSED_OPTION) return BigDecimal.ZERO; // Finally, assign values from the dialog box to the variables for (ColumnPanel cp : ip.columnPanels) { List<VarSpec> panelVars = cp.varSpecs; List<JComponent> panelControls = cp.inputFields; int numPanelVars = panelVars.size(); StringBuilder allAssignments = new StringBuilder(); // holds all values assigned in this tab for (int varCount = 0; varCount < numPanelVars; varCount++) { VarSpec vs = panelVars.get(varCount); JComponent comp = panelControls.get(varCount); String newValue = null; switch (vs.inputType) { case TEXT: { newValue = ((JTextField) comp).getText(); break; } case LIST: { Integer index = ((JComboBox) comp).getSelectedIndex(); if (vs.optionValues.optionEquals("VALUE", "STRING")) { newValue = vs.valueList.get(index); } else { // default is "NUMBER" newValue = index.toString(); } break; } case CHECK: { Integer value = ((JCheckBox) comp).isSelected() ? 1 : 0; newValue = value.toString(); break; } case RADIO: { // This code assumes that the Box container returns components // in the same order that they were added. Component[] comps = ((Box) comp).getComponents(); int componentCount = 0; Integer index = 0; for (Component c : comps) { if (c instanceof JRadioButton) { JRadioButton radio = (JRadioButton) c; if (radio.isSelected()) index = componentCount; } componentCount++; } if (vs.optionValues.optionEquals("VALUE", "STRING")) { newValue = vs.valueList.get(index); } else { // default is "NUMBER" newValue = index.toString(); } break; } case LABEL: { newValue = null; // The variable name is ignored and not set. break; } case PROPS: { // Read out and assign all the subvariables. // The overall return value is a property string (as in StrPropFunctions.java) with all the new settings. Component[] comps = ((JPanel) comp).getComponents(); StringBuilder sb = new StringBuilder(); int setVars = 0; // "NONE", no assignments made if (vs.optionValues.optionEquals("SETVARS", "SUFFIXED")) setVars = 1; if (vs.optionValues.optionEquals("SETVARS", "UNSUFFIXED")) setVars = 2; if (vs.optionValues.optionEquals("SETVARS", "TRUE")) setVars = 2; // for backward compatibility for (int compCount = 0; compCount < comps.length; compCount += 2) { String key = ((JLabel) comps[compCount]).getText().split("\\:")[0]; // strip trailing colon String value = ((JTextField) comps[compCount + 1]).getText(); sb.append(key); sb.append("="); sb.append(value); sb.append(" ; "); switch (setVars) { case 0: // Do nothing break; case 1: parser.setVariable(key + "_", value); break; case 2: parser.setVariable(key, value); break; } } newValue = sb.toString(); break; } default: // should never happen newValue = null; break; } // Set the variable to the value we got from the dialog box. if (newValue != null) { parser.setVariable(vs.name, newValue.trim()); allAssignments.append(vs.name + "=" + newValue.trim() + " ## "); } } if (cp.tabVarSpec != null) { parser.setVariable(cp.tabVarSpec.name, allAssignments.toString()); } } return BigDecimal.ONE; // success // for debugging: //return debugOutput(varSpecs); }
From source file:net.sf.jabref.openoffice.StyleSelectDialog.java
private void displayDefaultStyle(boolean authoryear) { try {//from w w w.j a v a2 s. c o m // Read the contents of the default style file: URL defPath = authoryear ? JabRef.class.getResource(OpenOfficePanel.DEFAULT_AUTHORYEAR_STYLE_PATH) : JabRef.class.getResource(OpenOfficePanel.DEFAULT_NUMERICAL_STYLE_PATH); BufferedReader r = new BufferedReader(new InputStreamReader(defPath.openStream())); String line; StringBuilder sb = new StringBuilder(); while ((line = r.readLine()) != null) { sb.append(line); sb.append('\n'); } // Make a dialog box to display the contents: final JDialog dd = new JDialog(diag, Localization.lang("Default style"), true); JLabel header = new JLabel( "<html>" + Localization.lang("The panel below shows the definition of the default style.") //+"<br>" + Localization.lang( "If you want to use it as a template for a new style, you can copy the contents into a new .jstyle file") + "</html>"); header.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); dd.getContentPane().add(header, BorderLayout.NORTH); JTextArea ta = new JTextArea(sb.toString()); ta.setEditable(false); JScrollPane sp = new JScrollPane(ta); sp.setPreferredSize(new Dimension(700, 500)); dd.getContentPane().add(sp, BorderLayout.CENTER); JButton okButton = new JButton(Localization.lang("OK")); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addButton(okButton); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); dd.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { dd.dispose(); } }); dd.pack(); dd.setLocationRelativeTo(diag); dd.setVisible(true); } catch (IOException ex) { LOGGER.warn("Problem showing default style", ex); } }
From source file:com.ga.forms.DailyLogAddUI.java
private void checkInOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkInOutButtonActionPerformed DailyLogRecord log = new DailyLogRecord(); if (DailyLogAddUI.checkIn && !DailyLogAddUI.breakDone) { args = new HashMap(); DailyLogAddUI.breakDone = true;/*w w w . jav a2s. c o m*/ args.put("checked-in", Boolean.toString(DailyLogAddUI.checkIn)); args.put("had-break", Boolean.toString(DailyLogAddUI.breakDone)); args.put("checked-out", Boolean.toString(DailyLogAddUI.checkOut)); if (yesRdButton.isSelected() == true) { this.timeOnBreak = "00:30"; } else if (customRdButton.isSelected() == true) { this.timeOnBreak = customBreakTimeTextField.getText(); } else { this.timeOnBreak = "00:00"; } log.setDailyLogRecord(dateDisplayLbl.getText(), dayDisplayLbl.getText(), checkInTimeCombo.getSelectedItem().toString(), "", this.timeOnBreak, "", "", "", args); doc = (DBObject) JSON.parse(log.getDailyLogRecord().toString()); args.clear(); args.put("date", dateDisplayLbl.getText()); log.updateRecord(doc, args); } else if (DailyLogAddUI.checkIn && DailyLogAddUI.breakDone && !DailyLogAddUI.checkOut) { args = new HashMap(); DailyLogAddUI.checkOut = true; args.put("checked-in", Boolean.toString(DailyLogAddUI.checkIn)); args.put("had-break", Boolean.toString(DailyLogAddUI.breakDone)); args.put("checked-out", Boolean.toString(DailyLogAddUI.checkOut)); DailyLogDuration durationAgent = new DailyLogDuration(); durationAgent.calculateCurrentDuration(checkInTimeCombo.getSelectedItem().toString(), this.timeOnBreak, checkOutTimeCombo.getSelectedItem().toString()); this.duration = durationAgent.getCurrentDuration(); JFrame parent = new JFrame(); JOptionPane optionPane = new JOptionPane("Duration: " + this.duration + "\n\nDo you want to Check Out?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); JDialog msgDialog = optionPane.createDialog(parent, "DLM"); msgDialog.setVisible(true); if (optionPane.getValue().equals(0)) { int hours = Integer.parseInt(this.duration.split(":")[0]); int minutes = Integer.parseInt(this.duration.split(":")[1]); if (hours < 9) { durationAgent.calculateUnderTime(this.duration); this.underTime = durationAgent.getUnderTime(); this.overTime = "00:00"; } else if (hours >= 9 && minutes > 0 && minutes < 60) { this.underTime = "00:00"; durationAgent.calculateOverTime(this.duration); this.overTime = durationAgent.getOverTime(); } else { this.underTime = "00:00"; this.overTime = "00:00"; } log.setDailyLogRecord(dateDisplayLbl.getText(), dayDisplayLbl.getText(), checkInTimeCombo.getSelectedItem().toString(), checkOutTimeCombo.getSelectedItem().toString(), this.timeOnBreak, this.duration, this.underTime, this.overTime, args); doc = (DBObject) JSON.parse(log.getDailyLogRecord().toString()); args.clear(); args.put("date", dateDisplayLbl.getText()); log.updateRecord(doc, args); } else { msgDialog.dispose(); } } else { args = new HashMap(); DailyLogAddUI.checkIn = true; args.put("checked-in", Boolean.toString(DailyLogAddUI.checkIn)); args.put("had-break", Boolean.toString(DailyLogAddUI.breakDone)); args.put("checked-out", Boolean.toString(DailyLogAddUI.checkOut)); log.setDailyLogRecord(dateDisplayLbl.getText(), dayDisplayLbl.getText(), checkInTimeCombo.getSelectedItem().toString(), "", "", "", "", "", args); doc = (DBObject) JSON.parse(log.getDailyLogRecord().toString()); log.insertRecord(doc); } }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected void closeWindow(Window window, WindowOpenInfo openInfo) { if (!disableSavingScreenHistory) { screenHistorySupport.saveScreenHistory(window, openInfo.getOpenMode()); }/*w w w.j a va2 s. c o m*/ switch (openInfo.getOpenMode()) { case DIALOG: { JDialog dialog = (JDialog) openInfo.getData(); dialog.setVisible(false); dialog.dispose(); cleanupAfterModalDialogClosed(window); fireListeners(window, tabs.size() != 0); break; } case NEW_TAB: case NEW_WINDOW: { JComponent layout = (JComponent) openInfo.getData(); layout.remove(DesktopComponentsHelper.getComposition(window)); if (isMainWindowManager) { tabsPane.remove(layout); } WindowBreadCrumbs windowBreadCrumbs = tabs.get(layout); if (windowBreadCrumbs != null) { windowBreadCrumbs.clearListeners(); windowBreadCrumbs.removeWindow(); } tabs.remove(layout); stacks.remove(windowBreadCrumbs); fireListeners(window, tabs.size() != 0); if (!isMainWindowManager) { closeFrame(getFrame()); } break; } case THIS_TAB: { JComponent layout = (JComponent) openInfo.getData(); final WindowBreadCrumbs breadCrumbs = tabs.get(layout); if (breadCrumbs == null) throw new IllegalStateException("Unable to close screen: breadCrumbs not found"); breadCrumbs.removeWindow(); Window currentWindow = breadCrumbs.getCurrentWindow(); if (!stacks.get(breadCrumbs).empty()) { Map.Entry<Window, Integer> entry = stacks.get(breadCrumbs).pop(); putToWindowMap(entry.getKey(), entry.getValue()); } JComponent component = DesktopComponentsHelper.getComposition(currentWindow); Window currentWindowFrame = (Window) currentWindow.getFrame(); final java.awt.Component focusedCmp = windowOpenMode.get(currentWindowFrame).getFocusOwner(); if (focusedCmp != null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { focusedCmp.requestFocus(); } }); } layout.remove(DesktopComponentsHelper.getComposition(window)); if (App.getInstance().getConnection().isConnected()) { layout.add(component); if (isMainWindowManager) { // If user clicked on close button maybe selectedIndex != tabsPane.getSelectedIndex() // Refs #1117 int selectedIndex = 0; while ((selectedIndex < tabs.size()) && (tabsPane.getComponentAt(selectedIndex) != layout)) { selectedIndex++; } if (selectedIndex == tabs.size()) { selectedIndex = tabsPane.getSelectedIndex(); } setActiveWindowCaption(currentWindow.getCaption(), currentWindow.getDescription(), selectedIndex); } else { setTopLevelWindowCaption(currentWindow.getCaption()); component.revalidate(); component.repaint(); } } fireListeners(window, tabs.size() != 0); break; } default: throw new UnsupportedOperationException(); } }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
private JDialog createAddChildDialog() { final JDialog dlg = new JDialog(); dlg.setModal(true);/*w ww . jav a 2 s . c o m*/ // Content final JPanel content = new JPanel(); content.setLayout(new BorderLayout()); content.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // child name AlignmentGridPanel pathPanel = new AlignmentGridPanel(); final JTextField childNameText = new JTextField(); final RSyntaxTextArea childDataArea = new RSyntaxTextArea(); final JMenuBar bar = new JMenuBar(); final JMenu menu = new JMenu("Syntax Highlight"); bar.add(menu); setMenuItem(menu, childDataArea, SyntaxConstants.SYNTAX_STYLE_XML); setMenuItem(menu, childDataArea, SyntaxConstants.SYNTAX_STYLE_JAVA); setMenuItem(menu, childDataArea, SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE); pathPanel.addLine(new Component[] { new JLabel("Select:"), bar }); pathPanel.addLine(new Component[] { new JLabel("Name: "), childNameText }); pathPanel.addLine(new Component[] { new JLabel("Data: ") }); content.add(pathPanel, BorderLayout.NORTH); content.add(new RTextScrollPane(childDataArea), BorderLayout.CENTER); childDataArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE); // Buttons. final CButtonPane btnPanel = new CButtonPane(CButtonPane.TAIL); final JButton btnOk = new JButton("Ok"); btnOk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String name = childNameText.getText(); String data = childDataArea.getText(); if ((name == null || name.isEmpty()) || (data == null || data.isEmpty())) { JOptionPane.showMessageDialog(null, "Name or Data is empty", "Error", JOptionPane.ERROR_MESSAGE); return; } childName = name; childText = data; dlg.setVisible(false); dlg.dispose(); } }); final JButton btnCancel = new JButton("Cancel"); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { childName = ""; childText = ""; dlg.setVisible(false); dlg.dispose(); } }); btnPanel.add(btnCancel); btnPanel.add(btnOk); btnPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); Container con = dlg.getContentPane(); con.setLayout(new BorderLayout()); con.add(content, BorderLayout.CENTER); con.add(btnPanel, BorderLayout.SOUTH); return dlg; }
From source file:net.sf.jabref.gui.openoffice.OpenOfficePanel.java
private void showConnectDialog() { dialogOkPressed = false;/* w ww .ja v a2 s . c o m*/ final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true); final JTextField ooPath = new JTextField(30); JButton browseOOPath = new JButton(Localization.lang("Browse")); ooPath.setText(preferences.getOOPath()); browseOOPath.addActionListener(BrowseAction.buildForDir(ooPath)); final JTextField ooExec = new JTextField(30); JButton browseOOExec = new JButton(Localization.lang("Browse")); ooExec.setText(preferences.getExecutablePath()); browseOOExec.addActionListener(BrowseAction.buildForFile(ooExec)); final JTextField ooJars = new JTextField(30); JButton browseOOJars = new JButton(Localization.lang("Browse")); browseOOJars.addActionListener(BrowseAction.buildForDir(ooJars)); ooJars.setText(preferences.getJarsPath()); FormBuilder builder = FormBuilder.create() .layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "pref")); if (OS.WINDOWS || OS.OS_X) { builder.add(Localization.lang("Path to OpenOffice/LibreOffice directory")).xy(1, 1); builder.add(ooPath).xy(3, 1); builder.add(browseOOPath).xy(5, 1); } else { builder.add(Localization.lang("Path to OpenOffice/LibreOffice executable")).xy(1, 1); builder.add(ooExec).xy(3, 1); builder.add(browseOOExec).xy(5, 1); builder.appendColumns("4dlu, pref"); builder.add(Localization.lang("Path to OpenOffice/LibreOffice library dir")).xy(1, 3); builder.add(ooJars).xy(3, 3); builder.add(browseOOJars).xy(5, 3); } builder.padding("5dlu, 5dlu, 5dlu, 5dlu"); ButtonBarBuilder bb = new ButtonBarBuilder(); JButton ok = new JButton(Localization.lang("OK")); JButton cancel = new JButton(Localization.lang("Cancel")); ActionListener tfListener = e -> { preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText()); cDiag.dispose(); }; ooPath.addActionListener(tfListener); ooExec.addActionListener(tfListener); ooJars.addActionListener(tfListener); ok.addActionListener(e -> { preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText()); dialogOkPressed = true; cDiag.dispose(); }); cancel.addActionListener(e -> cDiag.dispose()); bb.addGlue(); bb.addRelatedGap(); bb.addButton(ok); bb.addButton(cancel); bb.addGlue(); bb.padding("5dlu, 5dlu, 5dlu, 5dlu"); cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER); cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); cDiag.pack(); cDiag.setLocationRelativeTo(frame); cDiag.setVisible(true); }
From source file:net.sf.jabref.openoffice.OpenOfficePanel.java
private void showConnectDialog() { dialogOkPressed = false;//w w w . j a v a 2 s . co m final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true); final JTextField ooPath = new JTextField(30); JButton browseOOPath = new JButton(Localization.lang("Browse")); ooPath.setText(Globals.prefs.get(JabRefPreferences.OO_PATH)); browseOOPath.addActionListener(BrowseAction.buildForDir(ooPath)); final JTextField ooExec = new JTextField(30); JButton browseOOExec = new JButton(Localization.lang("Browse")); ooExec.setText(Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH)); browseOOExec.addActionListener(BrowseAction.buildForFile(ooExec)); final JTextField ooJars = new JTextField(30); JButton browseOOJars = new JButton(Localization.lang("Browse")); browseOOJars.addActionListener(BrowseAction.buildForDir(ooJars)); ooJars.setText(Globals.prefs.get(JabRefPreferences.OO_JARS_PATH)); DefaultFormBuilder builder = new DefaultFormBuilder( new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "")); if (OS.WINDOWS || OS.OS_X) { builder.append(Localization.lang("Path to OpenOffice directory")); builder.append(ooPath); builder.append(browseOOPath); builder.nextLine(); } else { builder.append(Localization.lang("Path to OpenOffice executable")); builder.append(ooExec); builder.append(browseOOExec); builder.nextLine(); builder.append(Localization.lang("Path to OpenOffice library dir")); builder.append(ooJars); builder.append(browseOOJars); builder.nextLine(); } ButtonBarBuilder bb = new ButtonBarBuilder(); JButton ok = new JButton(Localization.lang("OK")); JButton cancel = new JButton(Localization.lang("Cancel")); ActionListener tfListener = (e -> { updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText()); cDiag.dispose(); }); ooPath.addActionListener(tfListener); ooExec.addActionListener(tfListener); ooJars.addActionListener(tfListener); ok.addActionListener(e -> { updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText()); dialogOkPressed = true; cDiag.dispose(); }); cancel.addActionListener(e -> cDiag.dispose()); bb.addGlue(); bb.addRelatedGap(); bb.addButton(ok); bb.addButton(cancel); bb.addGlue(); builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER); cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); cDiag.pack(); cDiag.setLocationRelativeTo(frame); cDiag.setVisible(true); }
From source file:es.emergya.ui.plugins.admin.AdminLayers.java
protected SummaryAction getSummaryAction(final CapaInformacion capaInformacion) { SummaryAction action = new SummaryAction(capaInformacion) { private static final long serialVersionUID = -3691171434904452485L; @Override//from w w w . j av a2 s . c o m protected JFrame getSummaryDialog() { if (capaInformacion != null) { d = getDialog(capaInformacion, null, "", null, "image/png"); return d; } else { JDialog primera = getJDialog(); primera.setResizable(false); primera.setVisible(true); primera.setAlwaysOnTop(true); } return null; } private JDialog getJDialog() { final JDialog dialog = new JDialog(); dialog.setTitle(i18n.getString("admin.capas.nueva.titleBar")); dialog.setIconImage(getBasicWindow().getIconImage()); dialog.setLayout(new BorderLayout()); JPanel centro = new JPanel(new FlowLayout()); centro.setOpaque(false); JLabel label = new JLabel(i18n.getString("admin.capas.nueva.url")); final JTextField url = new JTextField(50); final JLabel icono = new JLabel(LogicConstants.getIcon("48x48_transparente")); label.setLabelFor(url); centro.add(label); centro.add(url); centro.add(icono); dialog.add(centro, BorderLayout.CENTER); JPanel pie = new JPanel(new FlowLayout(FlowLayout.TRAILING)); pie.setOpaque(false); final JButton siguiente = new JButton(i18n.getString("admin.capas.nueva.boton.siguiente"), LogicConstants.getIcon("button_next")); JButton cancelar = new JButton(i18n.getString("admin.capas.nueva.boton.cancelar"), LogicConstants.getIcon("button_cancel")); final SiguienteActionListener siguienteActionListener = new SiguienteActionListener(url, dialog, icono, siguiente); url.addActionListener(siguienteActionListener); siguiente.addActionListener(siguienteActionListener); cancelar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); pie.add(siguiente); pie.add(cancelar); dialog.add(pie, BorderLayout.SOUTH); dialog.getContentPane().setBackground(Color.WHITE); dialog.pack(); dialog.setLocationRelativeTo(null); return dialog; } private JFrame getDialog(final CapaInformacion c, final Capa[] left_items, final String service, final Map<String, Boolean> transparentes, final String png) { if (left_items != null && left_items.length == 0) { JOptionPane.showMessageDialog(AdminLayers.this, i18n.getString("admin.capas.nueva.error.noCapasEnServicio")); } else { final String label_cabecera = i18n.getString("admin.capas.nueva.nombreCapa"); final String label_pie = i18n.getString("admin.capas.nueva.infoAdicional"); final String centered_label = i18n.getString("admin.capas.nueva.origenDatos"); final String left_label = i18n.getString("admin.capas.nueva.subcapasDisponibles"); final String right_label; if (left_items != null) { right_label = i18n.getString("admin.capas.nueva.capasSeleccionadas"); } else { right_label = i18n.getString("admin.capas.ficha.capasSeleccionadas"); } final String tituloVentana, cabecera; if (c.getNombre() == null) { tituloVentana = i18n.getString("admin.capas.nueva.titulo.nuevaCapa"); cabecera = i18n.getString("admin.capas.nueva.cabecera.nuevaCapa"); } else { tituloVentana = i18n.getString("admin.capas.nueva.titulo.ficha"); cabecera = i18n.getString("admin.capas.nueva.cabecera.ficha"); } final Capa[] right_items = c.getCapas().toArray(new Capa[0]); final AdminPanel.SaveOrUpdateAction<CapaInformacion> guardar = layers.new SaveOrUpdateAction<CapaInformacion>( c) { private static final long serialVersionUID = 7447770296943341404L; @Override public void actionPerformed(ActionEvent e) { if (isNew && CapaConsultas.alreadyExists(textfieldCabecera.getText())) { JOptionPane.showMessageDialog(super.frame, i18n.getString("admin.capas.nueva.error.nombreCapaYaExiste")); } else if (textfieldCabecera.getText().isEmpty()) { JOptionPane.showMessageDialog(super.frame, i18n.getString("admin.capas.nueva.error.nombreCapaEnBlanco")); } else if (((DefaultListModel) right.getModel()).size() == 0) { JOptionPane.showMessageDialog(super.frame, i18n.getString("admin.capas.nueva.error.noCapasSeleccionadas")); } else if (cambios) { int i = JOptionPane.showConfirmDialog(super.frame, i18n.getString("admin.capas.nueva.confirmar.guardar.titulo"), i18n.getString("admin.capas.nueva.confirmar.boton.guardar"), JOptionPane.YES_NO_CANCEL_OPTION); if (i == JOptionPane.YES_OPTION) { if (original == null) { original = new CapaInformacion(); } original.setInfoAdicional(textfieldPie.getText()); original.setNombre(textfieldCabecera.getText()); original.setHabilitada(habilitado.isSelected()); original.setOpcional(comboTipoCapa.getSelectedIndex() != 0); boolean transparente = true; HashSet<Capa> capas = new HashSet<Capa>(); List<Capa> capasEnOrdenSeleccionado = new ArrayList<Capa>(); int indice = 0; for (Object c : ((DefaultListModel) right.getModel()).toArray()) { if (c instanceof Capa) { transparente = transparente && (transparentes != null && transparentes.get(((Capa) c).getNombre()) != null && transparentes.get(((Capa) c).getNombre())); capas.add((Capa) c); capasEnOrdenSeleccionado.add((Capa) c); ((Capa) c).setCapaInformacion(original); ((Capa) c).setOrden(indice++); // ((Capa) // c).setNombre(c.toString()); } } original.setCapas(capas); if (original.getId() == null) { String url = nombre.getText(); if (url.indexOf("?") > -1) { if (!url.endsWith("?")) { url += "&"; } } else { url += "?"; } url += "VERSION=" + version + "&REQUEST=GetMap&FORMAT=" + png + "&SERVICE=" + service + "&WIDTH={2}&HEIGHT={3}&BBOX={1}&SRS={0}"; // if (transparente) url += "&TRANSPARENT=TRUE"; url += "&LAYERS="; String estilos = ""; final String coma = "%2C"; if (capasEnOrdenSeleccionado.size() > 0) { for (Capa c : capasEnOrdenSeleccionado) { url += c.getTitulo().replaceAll(" ", "+") + coma; estilos += c.getEstilo() + coma; } estilos = estilos.substring(0, estilos.length() - coma.length()); estilos = estilos.replaceAll(" ", "+"); url = url.substring(0, url.length() - coma.length()); } url += "&STYLES=" + estilos; original.setUrl_visible(original.getUrl()); original.setUrl(url); } CapaInformacionAdmin.saveOrUpdate(original); cambios = false; layers.setTableData(getAll(new CapaInformacion())); closeFrame(); } else if (i == JOptionPane.NO_OPTION) { closeFrame(); } } else { closeFrame(); } } }; JFrame segunda = generateUrlDialog(label_cabecera, label_pie, centered_label, tituloVentana, left_items, right_items, left_label, right_label, guardar, LogicConstants.getIcon("tittleficha_icon_capa"), cabecera, c.getHabilitada(), c.getOpcional(), c.getUrl_visible()); segunda.setResizable(false); if (c != null) { textfieldCabecera.setText(c.getNombre()); textfieldPie.setText(c.getInfoAdicional()); nombre.setText(c.getUrl_visible()); nombre.setEditable(false); if (c.getHabilitada() == null) { c.setHabilitada(false); } habilitado.setSelected(c.getHabilitada()); if (c.isOpcional() != null && c.isOpcional()) { comboTipoCapa.setSelectedIndex(1); } else { comboTipoCapa.setSelectedIndex(0); } } if (c.getId() == null) { habilitado.setSelected(true); comboTipoCapa.setSelectedIndex(1); } habilitado.setEnabled(true); if (c == null || c.getId() == null) { textfieldCabecera.setEditable(true); } else { textfieldCabecera.setEditable(false); } cambios = false; segunda.pack(); segunda.setLocationRelativeTo(null); segunda.setVisible(true); return segunda; } return null; } class SiguienteActionListener implements ActionListener { private final JTextField url; private final JDialog dialog; private final JLabel icono; private final JButton siguiente; public SiguienteActionListener(JTextField url, JDialog dialog, JLabel icono, JButton siguiente) { this.url = url; this.dialog = dialog; this.icono = icono; this.siguiente = siguiente; } @Override public void actionPerformed(ActionEvent e) { final CapaInformacion ci = new CapaInformacion(); ci.setUrl(url.getText()); ci.setCapas(new HashSet<Capa>()); SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { private List<Capa> res = new LinkedList<Capa>(); private String service = "WMS"; private String png = null; private Map<String, Boolean> transparentes = new HashMap<String, Boolean>(); private ArrayList<String> errorStack = new ArrayList<String>(); private Boolean goOn = true; @SuppressWarnings(value = "unchecked") @Override protected Object doInBackground() throws Exception { try { final String url2 = ci.getUrl(); WMSClient client = new WMSClient(url2); client.connect(new ICancellable() { @Override public boolean isCanceled() { return false; } @Override public Object getID() { return System.currentTimeMillis(); } }); version = client.getVersion(); for (final String s : client.getLayerNames()) { WMSLayer layer = client.getLayer(s); // this.service = // client.getServiceName(); final Vector allSrs = layer.getAllSrs(); boolean epsg = (allSrs != null) ? allSrs.contains("EPSG:4326") : false; final Vector formats = client.getFormats(); if (formats.contains("image/png")) { png = "image/png"; } else if (formats.contains("IMAGE/PNG")) { png = "IMAGE/PNG"; } else if (formats.contains("png")) { png = "png"; } else if (formats.contains("PNG")) { png = "PNG"; } boolean image = png != null; if (png == null) { png = "IMAGE/PNG"; } if (epsg && image) { boolean hasTransparency = layer.hasTransparency(); this.transparentes.put(s, hasTransparency); Capa capa = new Capa(); capa.setCapaInformacion(ci); if (layer.getStyles().size() > 0) { capa.setEstilo(((WMSStyle) layer.getStyles().get(0)).getName()); } capa.setNombre(layer.getTitle()); capa.setTitulo(s); res.add(capa); if (!hasTransparency) { errorStack.add(i18n.getString(Locale.ROOT, "admin.capas.nueva.error.capaNoTransparente", layer.getTitle())); } } else { String error = ""; // if (opaque) // error += "<li>Es opaca</li>"; if (!image) { error += i18n.getString("admin.capas.nueva.error.formatoPNG"); } if (!epsg) { error += i18n.getString("admin.capas.nueva.error.projeccion"); } final String cadena = i18n.getString(Locale.ROOT, "admin.capas.nueva.error.errorCapa", new Object[] { s, error }); errorStack.add(cadena); } } } catch (final Throwable t) { log.error("Error al parsear el WMS", t); goOn = false; icono.setIcon(LogicConstants.getIcon("48x48_transparente")); JOptionPane.showMessageDialog(dialog, i18n.getString("admin.capas.nueva.error.errorParseoWMS")); siguiente.setEnabled(true); } return null; } @Override protected void done() { super.done(); if (goOn) { dialog.dispose(); ci.setUrl_visible(ci.getUrl()); final JFrame frame = getDialog(ci, res.toArray(new Capa[0]), service, transparentes, png); if (!errorStack.isEmpty()) { String error = "<html>"; for (final String s : errorStack) { error += s + "<br/>"; } error += "</html>"; final String errorString = error; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JOptionPane.showMessageDialog(frame, errorString); } }); } } } }; sw.execute(); icono.setIcon(LogicConstants.getIcon("anim_conectando")); icono.repaint(); siguiente.setEnabled(false); } } }; return action; }
From source file:com.marginallyclever.makelangelo.MainGUI.java
public void chooseLanguage() { final JDialog driver = new JDialog(mainframe, "Language", true); driver.setLayout(new GridBagLayout()); final String[] choices = translator.getLanguageList(); final JComboBox<String> language_options = new JComboBox<String>(choices); final JButton save = new JButton(">>>"); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; c.gridwidth = 2;/*w ww .j a va 2 s .c o m*/ c.gridx = 0; c.gridy = 0; driver.add(language_options, c); c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.gridx = 2; c.gridy = 0; driver.add(save, c); ActionListener driveButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); // TODO prevent "close" icon. Must press save to continue! if (subject == save) { translator.currentLanguage = choices[language_options.getSelectedIndex()]; translator.saveConfig(); driver.dispose(); } } }; save.addActionListener(driveButtons); driver.pack(); driver.setVisible(true); }
From source file:com.paniclauncher.data.Settings.java
public void reloadLauncherData() { log("Updating Launcher Data"); final JDialog dialog = new JDialog(this.parent, ModalityType.APPLICATION_MODAL); dialog.setSize(300, 100);/*from w w w .ja v a2s . co m*/ dialog.setTitle("Updating Launcher"); dialog.setLocationRelativeTo(App.settings.getParent()); dialog.setLayout(new FlowLayout()); dialog.setResizable(false); dialog.add(new JLabel("Updating Launcher... Please Wait")); Thread updateThread = new Thread() { public void run() { checkForUpdatedFiles(); // Download all updated files reloadNewsPanel(); // Reload news panel loadPacks(); // Load the Packs available in the Launcher loadUsers(); // Load the Testers and Allowed Players for the packs reloadPacksPanel(); // Reload packs panel loadAddons(); // Load the Addons available in the Launcher loadInstances(); // Load the users installed Instances reloadInstancesPanel(); // Reload instances panel dialog.setVisible(false); // Remove the dialog dialog.dispose(); // Dispose the dialog }; }; updateThread.start(); dialog.setVisible(true); }