List of usage examples for javax.swing JDialog JDialog
public JDialog(Window owner)
From source file:org.languagetool.gui.Main.java
private void tagTextAndDisplayResults() { JLanguageTool langTool = ltSupport.getLanguageTool(); // tag text//w w w . j a v a2 s. c o m List<String> sentences = langTool.sentenceTokenize(textArea.getText()); StringBuilder sb = new StringBuilder(); if (taggerShowsDisambigLog) { sb.append("<table>"); sb.append("<tr>"); sb.append("<td><b>"); sb.append(messages.getString("token")); sb.append("</b></td>"); sb.append("<td><b>"); sb.append(messages.getString("disambiguatorLog")); sb.append("</b></td>"); sb.append("</tr>"); boolean odd = true; try { for (String sent : sentences) { AnalyzedSentence analyzed = langTool.getAnalyzedSentence(sent); odd = appendTagsWithDisambigLog(sb, analyzed, odd); } } catch (Exception e) { sb.append(getStackTraceAsHtml(e)); } sb.append("</table>"); } else { try { for (String sent : sentences) { AnalyzedSentence analyzed = langTool.getAnalyzedSentence(sent); String analyzedString = StringTools.escapeHTML(analyzed.toString(",")) .replace("<S>", "<S><br>").replace("[", "<font color='" + TAG_COLOR + "'>[") .replace("]", "]</font><br>"); sb.append(analyzedString).append('\n'); } } catch (Exception e) { sb.append(getStackTraceAsHtml(e)); } } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (taggerDialog == null) { taggerDialog = new JDialog(frame); taggerDialog.setTitle(messages.getString("taggerWindowTitle")); taggerDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); taggerDialog.setResizable(true); taggerDialog.setSize(640, 480); taggerDialog.setLocationRelativeTo(frame); KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); ActionListener actionListener = actionEvent -> taggerDialog.setVisible(false); taggerDialog.getRootPane().registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); JPanel panel = new JPanel(new GridBagLayout()); taggerDialog.add(panel); taggerArea = new JTextPane(); taggerArea.setContentType("text/html"); taggerArea.setEditable(false); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridwidth = 2; c.gridy = 0; c.weightx = 1.0; c.weighty = 1.0; c.insets = new Insets(8, 8, 4, 8); c.fill = GridBagConstraints.BOTH; panel.add(new JScrollPane(taggerArea), c); c.gridwidth = 1; c.gridx = 0; c.gridy = 1; c.weightx = 0.0; c.weighty = 0.0; c.insets = new Insets(4, 8, 8, 8); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.EAST; JCheckBox showDisAmbig = new JCheckBox(messages.getString("ShowDisambiguatorLog")); showDisAmbig.setSelected(taggerShowsDisambigLog); showDisAmbig.addItemListener((ItemEvent e) -> { taggerShowsDisambigLog = e.getStateChange() == ItemEvent.SELECTED; ltSupport.getConfig().setTaggerShowsDisambigLog(taggerShowsDisambigLog); }); panel.add(showDisAmbig, c); c.gridx = 1; JButton closeButton = new JButton(messages.getString("guiCloseButton")); closeButton.addActionListener(actionListener); panel.add(closeButton, c); } // orientation each time should be set as language may is changed taggerDialog.applyComponentOrientation( ComponentOrientation.getOrientation(languageBox.getSelectedLanguage().getLocale())); taggerDialog.setVisible(true); taggerArea.setText(HTML_FONT_START + sb + HTML_FONT_END); } }); }
From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java
private void editMasterdataRelation(mxCell cell) { EntityFieldMetaDataVO voField = null; RelationAttributePanel panel = new RelationAttributePanel(RelationAttributePanel.TYPE_ENTITY); String sSource = ""; String sTarget = ""; EntityMetaDataVO voSourceModify = null; if (cell.getValue() != null && cell.getValue() instanceof EntityFieldMetaDataVO) { voField = (EntityFieldMetaDataVO) cell.getValue(); EntityMetaDataVO voSource = (EntityMetaDataVO) cell.getSource().getValue(); voSourceModify = voSource;/*from www.j av a 2s . com*/ EntityMetaDataVO voTarget = (EntityMetaDataVO) cell.getTarget().getValue(); sSource = voSource.getEntity(); sTarget = voTarget.getEntity(); EntityMetaDataVO voForeign = MetaDataClientProvider.getInstance().getEntity(voSource.getEntity()); EntityMetaDataVO voEntity = MetaDataClientProvider.getInstance().getEntity(voTarget.getEntity()); panel.setEntity(voEntity); panel.setEntitySource(voForeign); panel.setEntityFields( MetaDataDelegate.getInstance().getAllEntityFieldsByEntity(voForeign.getEntity()).values()); if (voField.getId() != null) { voField = MetaDataClientProvider.getInstance().getEntityField(voForeign.getEntity(), voField.getField()); List<TranslationVO> lstTranslation = new ArrayList<TranslationVO>(); for (LocaleInfo lInfo : LocaleDelegate.getInstance().getAllLocales(false)) { Map<String, String> mp = new HashMap<String, String>(); mp.put(TranslationVO.labelsField[0], LocaleDelegate.getInstance().getResourceByStringId(lInfo, voField.getLocaleResourceIdForLabel())); mp.put(TranslationVO.labelsField[1], LocaleDelegate.getInstance().getResourceByStringId(lInfo, voField.getLocaleResourceIdForDescription())); TranslationVO voTrans = new TranslationVO(lInfo.localeId, lInfo.title, lInfo.language, mp); lstTranslation.add(voTrans); } panel.setTranslation(lstTranslation); panel.setFieldValues(voField); } else { MyGraphModel model = (MyGraphModel) graphComponent.getGraph().getModel(); panel.setFieldValues(voField); panel.setTranslationAndMore(model.getTranslation().get(voField)); } } else if (cell.getValue() != null && cell.getValue() instanceof String) { EntityMetaDataVO voSource = (EntityMetaDataVO) cell.getSource().getValue(); EntityMetaDataVO voTarget = (EntityMetaDataVO) cell.getTarget().getValue(); sSource = voSource.getEntity(); sTarget = voTarget.getEntity(); EntityMetaDataVO voForeign = MetaDataClientProvider.getInstance().getEntity(voSource.getEntity()); EntityMetaDataVO voEntity = MetaDataClientProvider.getInstance().getEntity(voTarget.getEntity()); voSourceModify = voForeign; panel.setEntity(voEntity); panel.setEntitySource(voForeign); panel.setEntityFields( MetaDataDelegate.getInstance().getAllEntityFieldsByEntity(voSource.getEntity()).values()); } double cellsDialog[][] = { { 5, TableLayout.PREFERRED, 5 }, { 5, TableLayout.PREFERRED, 5 } }; JDialog dia = new JDialog(mf); dia.setLayout(new TableLayout(cellsDialog)); dia.setTitle("Verbindung von " + sSource + " zu " + sTarget + " bearbeiten"); dia.setLocationRelativeTo(EntityRelationshipModelEditPanel.this); dia.add(panel, "1,1"); dia.setModal(true); panel.setDialog(dia); dia.pack(); dia.setVisible(true); if (panel.getState() == 1) { EntityFieldMetaDataVO vo = panel.getField(); cell.setValue(vo); EntityRelationshipModelEditPanel.this.fireChangeListenEvent(); List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>(); EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO(); toField.setEntityFieldMeta(vo); toField.setTranslation(panel.getTranslation().getRows()); toList.add(toField); MetaDataDelegate.getInstance().modifyEntityMetaData(voSourceModify, toList); MyGraphModel model = (MyGraphModel) graphComponent.getGraph().getModel(); model.getTranslation().put(vo, panel.getTranslation().getRows()); getGraphComponent().refresh(); loadReferenz(); } else { if (cell.getValue() instanceof String) getGraphModel().remove(cell); } }
From source file:org.nuclos.client.relation.MyGraphModel.java
public JPopupMenu createRelationPopupMenu(final mxCell cell, boolean delete) { final JPopupMenu pop = new JPopupMenu(); JMenuItem i1 = new JMenuItem( getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.1", "Bezug zu Stammdaten")); i1.addActionListener(new ActionListener() { @Override/*w w w . j a v a2s. com*/ public void actionPerformed(ActionEvent e) { editPanel.setIsPopupShown(false); if (cell.getTarget() == null || cell.getSource() == null) { remove(cell); return; } Object cells[] = { cell }; mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDARROW, mxConstants.ARROW_OPEN); mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDSIZE, "12"); mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ELBOW, mxConstants.ELBOW_VERTICAL); mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, EDGESTYLE, ELBOWCONNECTOR); RelationAttributePanel panel = new RelationAttributePanel(RelationAttributePanel.TYPE_ENTITY); mxCell target = (mxCell) cell.getTarget(); mxCell source = (mxCell) cell.getSource(); panel.setEntity((EntityMetaDataVO) target.getValue()); panel.setEntitySource((EntityMetaDataVO) source.getValue()); EntityMetaDataVO voSource = (EntityMetaDataVO) source.getValue(); EntityMetaDataVO voTarget = (EntityMetaDataVO) target.getValue(); panel.setEntityFields( MetaDataDelegate.getInstance().getAllEntityFieldsByEntity(voSource.getEntity()).values()); double cellsDialog[][] = { { 5, TableLayout.PREFERRED, 5 }, { 5, TableLayout.PREFERRED, 5 } }; JDialog dia = new JDialog(mf); dia.setLayout(new TableLayout(cellsDialog)); dia.setTitle(getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.10", "Bezug zu Stammdaten bearbeiten")); dia.setLocationRelativeTo(editPanel); dia.add(panel, "1,1"); dia.setModal(true); panel.setDialog(dia); dia.pack(); dia.setVisible(true); if (panel.getState() == 1) { EntityFieldMetaDataVO vo = panel.getField(); cell.setValue(vo); mpTransation.put(vo, panel.getTranslation().getRows()); List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>(); EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO(); toField.setEntityFieldMeta(vo); toField.setTranslation(panel.getTranslation().getRows()); toList.add(toField); MetaDataDelegate.getInstance().modifyEntityMetaData(voSource, toList); editPanel.loadReferenz(); } else { remove(cell); } } }); final JMenuItem i2 = new JMenuItem(getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.3", "Bezug zu Vorg\u00e4ngen (Unterformularbezug)")); i2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editPanel.setIsPopupShown(false); if (cell.getTarget() == null || cell.getSource() == null) { remove(cell); return; } Object cells[] = { cell }; mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDARROW, mxConstants.ARROW_DIAMOND); mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDSIZE, "12"); mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ELBOW, mxConstants.ELBOW_VERTICAL); mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, EDGESTYLE, ELBOWCONNECTOR); mxCell target = (mxCell) cell.getTarget(); mxCell source = (mxCell) cell.getSource(); EntityMetaDataVO voSource = (EntityMetaDataVO) source.getValue(); EntityMetaDataVO voTarget = (EntityMetaDataVO) target.getValue(); String sFieldName = null; boolean blnNotSet = true; while (blnNotSet) { sFieldName = JOptionPane.showInputDialog(editPanel, getSpringLocaleDelegate().getMessage( "nuclos.entityrelation.editor.1", "Bitte geben Sie den Namen des Feldes an!")); if (sFieldName == null || sFieldName.length() < 1) { MyGraphModel.this.remove(cell); return; } else if (sFieldName != null) { blnNotSet = false; } } EntityFieldMetaDataVO vo = new EntityFieldMetaDataVO(); vo.setModifiable(true); vo.setLogBookTracking(false); vo.setReadonly(false); vo.setShowMnemonic(true); vo.setInsertable(true); vo.setSearchable(true); vo.setNullable(false); vo.setUnique(true); vo.setDataType("java.lang.String"); List<TranslationVO> lstTranslation = new ArrayList<TranslationVO>(); for (LocaleInfo voLocale : LocaleDelegate.getInstance().getAllLocales(false)) { String sLocaleLabel = voLocale.language; Integer iLocaleID = voLocale.localeId; String sCountry = voLocale.title; Map<String, String> map = new HashMap<String, String>(); TranslationVO translation = new TranslationVO(iLocaleID, sCountry, sLocaleLabel, map); for (String sLabel : labels) { translation.getLabels().put(sLabel, sFieldName); } lstTranslation.add(translation); } vo.setForeignEntity(voTarget.getEntity()); vo.setField(sFieldName); vo.setDbColumn("INTID_" + sFieldName); cell.setValue(vo); List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>(); EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO(); toField.setEntityFieldMeta(vo); toField.setTranslation(lstTranslation); toList.add(toField); MetaDataDelegate.getInstance().modifyEntityMetaData(voSource, toList); editPanel.loadReferenz(); } }); final JMenuItem i4 = new JMenuItem( getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.5", "Arbeitsschritt")); i4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editPanel.setIsPopupShown(false); if (cell.getTarget() == null || cell.getSource() == null) { remove(cell); return; } Object cells[] = { cell }; mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDARROW, mxConstants.ARROW_OVAL); mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDSIZE, "12"); mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ELBOW, mxConstants.ELBOW_VERTICAL); mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, EDGESTYLE, ELBOWCONNECTOR); try { mxCell cellSource = (mxCell) cell.getSource(); mxCell cellTarget = (mxCell) cell.getTarget(); EntityMetaDataVO sourceModule = (EntityMetaDataVO) cellSource.getValue(); EntityMetaDataVO targetModule = (EntityMetaDataVO) cellTarget.getValue(); String sSourceModule = sourceModule.getEntity(); String sTargetModule = targetModule.getEntity(); boolean blnFound = false; for (MasterDataVO voGeneration : MasterDataCache.getInstance() .get(NuclosEntity.GENERATION.getEntityName())) { String sSource = (String) voGeneration.getField("sourceModule"); String sTarget = (String) voGeneration.getField("targetModule"); if (org.apache.commons.lang.StringUtils.equals(sSource, sSourceModule) && org.apache.commons.lang.StringUtils.equals(sTarget, sTargetModule)) { GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory .getInstance().newMasterDataCollectController( NuclosEntity.GENERATION.getEntityName(), null, null); gcc.runViewSingleCollectableWithId(voGeneration.getId()); blnFound = true; break; } } if (!blnFound) { GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory .getInstance().newMasterDataCollectController( NuclosEntity.GENERATION.getEntityName(), null, null); Map<String, Object> mp = new HashMap<String, Object>(); mp.put("sourceModule", sSourceModule); mp.put("sourceModuleId", new Integer( MetaDataClientProvider.getInstance().getEntity(sSourceModule).getId().intValue())); mp.put("targetModule", sTargetModule); mp.put("targetModuleId", new Integer( MetaDataClientProvider.getInstance().getEntity(sTargetModule).getId().intValue())); MasterDataVO vo = new MasterDataVO(NuclosEntity.GENERATION.getEntityName(), null, null, null, null, null, null, mp); gcc.runWithNewCollectableWithSomeFields(vo); } } catch (NuclosBusinessException e1) { LOG.warn("actionPerformed: " + e1); } catch (CommonPermissionException e1) { LOG.warn("actionPerformed: " + e1); } catch (CommonFatalException e1) { LOG.warn("actionPerformed: " + e1); } catch (CommonBusinessException e1) { LOG.warn("actionPerformed: " + e1); } } }); JMenuItem i5 = new JMenuItem( getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.12", "Verbindung l\u00f6sen")); i5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel(); model.remove(cell); } }); pop.add(i1); pop.add(i2); //pop.add(i3); pop.add(i4); if (delete) { pop.addSeparator(); pop.add(i5); } return pop; }
From source file:org.openflexo.view.controller.FlexoInspectorController.java
public static void main(String[] args) { JFrame frame = new JFrame(); final JDialog dialog = new JDialog(frame); dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); JButton button = new JButton("Show dialog"); button.addActionListener(new ActionListener() { @Override//from w w w.ja v a 2 s . c o m public void actionPerformed(ActionEvent e) { dialog.setVisible(true); } }); JLabel label = new JLabel("coucou"); dialog.add(label); dialog.pack(); JPanel panel = new JPanel(new BorderLayout()); panel.add(button); panel.setPreferredSize(new Dimension(500, 400)); frame.add(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Creates a modal JDialog containing the specified JComponent * for the specified parent.//w ww.j av a2 s. c om * The newly created dialog is then centered on the screen and made visible. * * @param parent The parent component. * @param title The title of the dialog. * @param c The component to display. * @see #centerAndShow(Component) */ public static void makeForDialog(Component parent, String title, JComponent c) { if (c == null) return; JDialog dialog = null; if (parent instanceof Frame) dialog = new JDialog((Frame) parent); else if (parent instanceof Dialog) dialog = new JDialog((Dialog) parent); else if (dialog == null) dialog = new JDialog(); //no parent dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setModal(true); dialog.setTitle(title); dialog.setSize(DIALOG_WIDTH, DIALOG_HEIGHT); Container container = dialog.getContentPane(); container.setLayout(new BorderLayout(0, 0)); container.add(c, BorderLayout.CENTER); centerAndShow(dialog); }
From source file:org.pentaho.ui.xul.swing.tags.SwingDialog.java
private void createDialog() { if (getParent() instanceof XulDialog) { Object parentObj = ((SwingDialog) getParent()).getDialog(); dialog = new JDialog((Dialog) parentObj); centerComp = (Component) parentObj; } else if (getParent() instanceof XulWindow) { Object parentObj = getParent().getManagedObject(); dialog = new JDialog((Frame) parentObj); centerComp = (Component) parentObj; } else {//from w w w . j a v a 2 s . c o m Document doc = getDocument(); Element rootElement = doc.getRootElement(); XulWindow window = null; if (rootElement != this) { // dialog is root, no JFrame Parent window = (XulWindow) rootElement; } if (window != null) { frame = (JFrame) window.getManagedObject(); dialog = new JDialog(frame); centerComp = frame; } else { final Object context = domContainer.getOuterContext(); if (context instanceof JFrame) { frame = (JFrame) context; centerComp = (Component) context; dialog = new JDialog(frame); } else if (context instanceof JDialog) { dialog = new JDialog((JDialog) context); centerComp = (Component) context; } else if (context instanceof JComponent) { dialog = new JDialog(); centerComp = (Component) context; } else { dialog = new JDialog(); } } } dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setResizable(getResizable()); dialog.setLayout(new BorderLayout()); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setOpaque(true); int pad = (this.getPadding() > -1) ? getPadding() : 3; mainPanel.setBorder(BorderFactory.createEmptyBorder(pad, pad, pad, pad)); dialog.setTitle(title); dialog.setModal(isModal()); dialog.add(mainPanel, BorderLayout.CENTER); mainPanel.add(container, BorderLayout.CENTER); container.setOpaque(false); if (this.header != null) { JPanel headerPanel = new JPanel(new BorderLayout()); headerPanel.setBackground(Color.decode("#5F86C0")); headerPanel.setOpaque(true); JPanel headerPanelInner = new JPanel(new BorderLayout()); headerPanelInner.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); headerPanelInner.setOpaque(false); headerPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.decode("#8FB1E5"), Color.decode("#446CA9"))); JLabel title = new JLabel(this.header.getTitle()); title.setForeground(Color.white); headerPanelInner.add(title, BorderLayout.WEST); JLabel desc = new JLabel(this.header.getDescription()); desc.setForeground(Color.white); headerPanelInner.add(desc, BorderLayout.EAST); headerPanel.add(headerPanelInner, BorderLayout.CENTER); mainPanel.add(headerPanel, BorderLayout.NORTH); } populateButtonPanel(); mainPanel.add(buttonPanel, BorderLayout.SOUTH); dialog.setSize(new Dimension(getWidth(), getHeight())); dialog.setPreferredSize(new Dimension(getWidth(), getHeight())); dialog.setMinimumSize(new Dimension(getWidth(), getHeight())); if (this.getBgcolor() != null) { mainPanel.setBackground(Color.decode(this.getBgcolor())); } }
From source file:org.photovault.swingui.PhotoInfoDlg.java
/** Creates the UI components needed for this dialog. *///w ww . j av a 2 s. c om protected void createUI() { Container parentView = getParentController().getView(); Window wnd = SwingUtilities.getWindowAncestor(parentView); dialogWindow = new JDialog((Frame) wnd); editor = new PhotoInfoEditor(this); addView(editor); dialogWindow.getContentPane().add(editor, BorderLayout.NORTH); final PhotoInfoDlg staticThis = this; registerAction("save_close", new DataAccessAction("OK") { public void actionPerformed(ActionEvent actionEvent, org.hibernate.Session currentSession) { save(); dialogWindow.setVisible(false); } }); registerAction("discard_close", new DataAccessAction("Cancel") { public void actionPerformed(ActionEvent actionEvent, org.hibernate.Session currentSession) { discard(); dialogWindow.setVisible(false); } }); JButton okBtn = new JButton(this.getActionAdapter("save_close")); // okBtn.addActionListener( new ActionListener() { // public void actionPerformed( ActionEvent e ) { // try { // ChangePhotoInfoCommand cmd = ctrl.getChangeCommand(); // masterCtrl.getCommandHandler().executeCommand( cmd ); // photoChanged = true; // setVisible( false ); // } catch ( Exception ex ) { // JOptionPane.showMessageDialog( // staticThis, // "Error while saving changes: \n" + ex.getMessage(), // "Error saving changes", // JOptionPane.ERROR_MESSAGE, // null ); // log.warn( "problem while saving changes: " + ex.getMessage() ); // } // } // } ); JButton applyBtn = new JButton(getActionAdapter("save")); // applyBtn.addActionListener( new ActionListener() { // public void actionPerformed( ActionEvent e ) { // try { // ChangePhotoInfoCommand cmd = ctrl.getChangeCommand(); // masterCtrl.getCommandHandler().executeCommand( cmd ); // photoChanged = true; // } catch ( Exception ex ) { // JOptionPane.showMessageDialog( // staticThis, // "Error while saving changes: \n" + ex.getMessage(), // "Error saving changes", // JOptionPane.ERROR_MESSAGE, // null ); // log.warn( "problem while saving changes: " + ex.getMessage() ); // } // } // } ); JButton discardBtn = new JButton(getActionAdapter("discard")); // discardBtn.addActionListener( new ActionListener() { // public void actionPerformed( ActionEvent e ) { // ctrl.discard(); // } // } ); JButton closeBtn = new JButton(getActionAdapter("discard_close")); // closeBtn.addActionListener( new ActionListener() { // public void actionPerformed( ActionEvent e ) { // ctrl.discard(); // setVisible( false ); // } // } ); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(okBtn); buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(applyBtn); buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(discardBtn); buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(closeBtn); dialogWindow.getContentPane().add(buttonPane, BorderLayout.SOUTH); dialogWindow.getRootPane().setDefaultButton(applyBtn); dialogWindow.pack(); }
From source file:pl.otros.vfs.browser.demo.TestBrowser.java
public static void main(final String[] args) throws InterruptedException, InvocationTargetException, SecurityException, IOException { if (args.length > 1) throw new IllegalArgumentException( "SYNTAX: java... " + TestBrowser.class.getName() + " [initialPath]"); SwingUtilities.invokeAndWait(new Runnable() { @Override/*from w w w .j ava2s. co m*/ public void run() { tryLoadSubstanceLookAndFeel(); final JFrame f = new JFrame("OtrosVfsBrowser demo"); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); DataConfiguration dc = null; final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); File favoritesFile = new File("favorites.properties"); propertiesConfiguration.setFile(favoritesFile); if (favoritesFile.exists()) { try { propertiesConfiguration.load(); } catch (ConfigurationException e) { e.printStackTrace(); } } dc = new DataConfiguration(propertiesConfiguration); propertiesConfiguration.setAutoSave(true); final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null); comp.setSelectionMode(SelectionMode.FILES_ONLY); comp.setMultiSelectionEnabled(true); comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) { @Override public void actionPerformed(ActionEvent e) { FileObject[] selectedFiles = comp.getSelectedFiles(); System.out.println("Selected files count=" + selectedFiles.length); for (FileObject selectedFile : selectedFiles) { try { FileSize fileSize = new FileSize(selectedFile.getContent().getSize()); System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString()); byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l); JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes))); JDialog d = new JDialog(f); d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI()); d.getContentPane().add(sp); d.setSize(600, 400); d.setVisible(true); } catch (Exception e1) { LOGGER.error("Failed to read file", e1); JOptionPane.showMessageDialog(f, (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) { @Override public void actionPerformed(ActionEvent e) { f.dispose(); try { propertiesConfiguration.save(); } catch (ConfigurationException e1) { e1.printStackTrace(); } System.exit(0); } }); contentPane.add(comp); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); }
From source file:pl.otros.vfs.browser.JOtrosVfsBrowserDialog.java
protected JDialog createDialog(Component parent) throws HeadlessException { Frame toUse = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); final JDialog dialog = new JDialog(toUse); dialog.getContentPane().add(vfsBrowser); dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { cancelSelection();// ww w . ja v a2s . c om } }); vfsBrowser.setApproveAction(new AbstractAction(Messages.getMessage("general.openButtonText")) { @Override public void actionPerformed(ActionEvent actionEvent) { returnValue = ReturnValue.Approve; dialog.dispose(); } }); vfsBrowser.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) { @Override public void actionPerformed(ActionEvent actionEvent) { cancelSelection(); dialog.dispose(); } }); dialog.setModal(true); dialog.invalidate(); dialog.repaint(); return dialog; }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
@Override public void mouseClicked(MouseEvent event, final StateRenderer2D source) { if (event.getButton() == MouseEvent.BUTTON3) { final LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType(); JPopupMenu popup = new JPopupMenu(); for (String type : positions.keySet()) { JMenu menu = new JMenu(type + "s"); for (final AssetPosition p : positions.get(type)) { if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection) continue; Color c = cmap.getColor(1 - (p.getAge() / (7200000.0))); String htmlColor = String.format("#%02X%02X%02X", c.getRed(), c.getGreen(), c.getBlue()); menu.add("<html><b>" + p.getAssetName() + "</b> <font color=" + htmlColor + ">" + getAge(p) + "</font>").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { source.focusLocation(p.getLoc()); }/*w ww . ja v a2 s. c o m*/ }); } popup.add(menu); } popup.addSeparator(); popup.add("Settings").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PluginUtils.editPluginProperties(SituationAwareness.this, true); } }); popup.add("Fetch asset properties").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // for (AssetTrack track : assets.values()) { // track.setColor(new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255))); // } fetchAssetProperties(); } }); popup.add("Select location sources").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); for (ILocationProvider l : localizers) { JCheckBox check = new JCheckBox(l.getName()); check.setSelected(true); p.add(check); check.setSelected(updateMethodNames.contains(l.getName())); } int op = JOptionPane.showConfirmDialog(getConsole(), p, "Location update sources", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (op == JOptionPane.CANCEL_OPTION) return; Vector<String> methods = new Vector<String>(); for (int i = 0; i < p.getComponentCount(); i++) { if (p.getComponent(i) instanceof JCheckBox) { JCheckBox sel = (JCheckBox) p.getComponent(i); if (sel.isSelected()) methods.add(sel.getText()); } } updateMethods = StringUtils.join(methods, ", "); propertiesChanged(); } }); popup.add("Select hidden positions types").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); for (String type : positions.keySet()) { JCheckBox check = new JCheckBox(type); check.setSelected(true); p.add(check); check.setSelected(hiddenPosTypes.contains(type)); } int op = JOptionPane.showConfirmDialog(getConsole(), p, "Position types to be hidden", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (op == JOptionPane.CANCEL_OPTION) return; Vector<String> types = new Vector<String>(); for (int i = 0; i < p.getComponentCount(); i++) { if (p.getComponent(i) instanceof JCheckBox) { JCheckBox sel = (JCheckBox) p.getComponent(i); if (sel.isSelected()) types.add(sel.getText()); } } hiddenTypes = StringUtils.join(types, ", "); propertiesChanged(); } }); popup.addSeparator(); popup.add("Decision Support").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dialogDecisionSupport == null) { dialogDecisionSupport = new JDialog(getConsole()); dialogDecisionSupport.setModal(false); dialogDecisionSupport.setAlwaysOnTop(true); dialogDecisionSupport.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); } ArrayList<AssetPosition> tags = new ArrayList<AssetPosition>(); LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType(); Vector<AssetPosition> spots = positions.get("SPOT Tag"); Vector<AssetPosition> argos = positions.get("Argos Tag"); if (spots != null) tags.addAll(spots); if (argos != null) tags.addAll(argos); if (!assets.containsKey(getConsole().getMainSystem())) { GuiUtils.errorMessage(getConsole(), "Decision Support", "UUV asset position is unknown"); return; } supportTable.setAssets(assets.get(getConsole().getMainSystem()).getLatest(), tags); JXTable table = new JXTable(supportTable); dialogDecisionSupport.setContentPane(new JScrollPane(table)); dialogDecisionSupport.invalidate(); dialogDecisionSupport.validate(); dialogDecisionSupport.setSize(600, 300); dialogDecisionSupport.setTitle("Decision Support Table"); dialogDecisionSupport.setVisible(true); dialogDecisionSupport.toFront(); GuiUtils.centerOnScreen(dialogDecisionSupport); } }); popup.show(source, event.getX(), event.getY()); } super.mouseClicked(event, source); }