List of usage examples for javax.swing JDialog JDialog
public JDialog(Window owner, String title)
From source file:org.apache.tika.gui.TikaGUI.java
private void textDialog(String title, URL resource) { try {//ww w . j a v a 2 s. co m JDialog dialog = new JDialog(this, title); JEditorPane editor = new JEditorPane(resource); editor.setContentType("text/html"); editor.setEditable(false); editor.setBackground(Color.WHITE); editor.setPreferredSize(new Dimension(400, 250)); editor.addHyperlinkListener(this); dialog.add(editor); dialog.pack(); dialog.setVisible(true); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.apache.tika.gui.TikaGUI.java
public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == EventType.ACTIVATED) { try {//from w ww . ja v a 2s . c o m URL url = e.getURL(); try (InputStream stream = url.openStream()) { JEditorPane editor = new JEditorPane("text/plain", IOUtils.toString(stream, UTF_8)); editor.setEditable(false); editor.setBackground(Color.WHITE); editor.setCaretPosition(0); editor.setPreferredSize(new Dimension(600, 400)); String name = url.toString(); name = name.substring(name.lastIndexOf('/') + 1); JDialog dialog = new JDialog(this, "Apache Tika: " + name); dialog.add(new JScrollPane(editor)); dialog.pack(); dialog.setVisible(true); } } catch (IOException exception) { exception.printStackTrace(); } } }
From source file:org.apache.uima.tools.docanalyzer.DBAnnotationViewerDialog.java
public void launchThatViewer(String xmi_id, TypeSystem typeSystem, final String[] aTypesToDisplay, boolean javaViewerRBisSelected, boolean javaViewerUCRBisSelected, boolean xmlRBisSelected, File styleMapFile, File viewerDirectory) { try {// w w w . j av a 2 s. c o m InputStream xmiDocument = this.xmiDAO.getXMI(xmi_id); // create a new CAS CAS cas = CasCreationUtils.createCas(Collections.EMPTY_LIST, typeSystem, UIMAFramework.getDefaultPerformanceTuningProperties()); if (this.med1.isUmcompress()) { //Descomprime el XMI System.out.println("con compresin"); //Create the decompressor and give it the data to compress Inflater decompressor = new Inflater(); byte[] documentDataByteArray = IOUtils.toByteArray(xmiDocument); decompressor.setInput(documentDataByteArray); //Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(documentDataByteArray.length); //Decompress the data byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } bos.close(); //Get the decompressed data byte[] decompressedData = bos.toByteArray(); XmiCasDeserializer.deserialize(new ByteArrayInputStream(decompressedData), cas, true); } else { System.out.println("sin compresin"); XmlCasDeserializer.deserialize(xmiDocument, cas, true); } //get the specified view cas = cas.getView(this.defaultCasViewName); //launch appropriate viewer if (javaViewerRBisSelected || javaViewerUCRBisSelected) { // JMP // record preference for next time med1.setViewType(javaViewerRBisSelected ? "Java Viewer" : "JV User Colors"); //create tree viewer component CasAnnotationViewer viewer = new CasAnnotationViewer(); viewer.setDisplayedTypes(aTypesToDisplay); if (javaViewerUCRBisSelected) getColorsForTypesFromFile(viewer, styleMapFile); else viewer.setHiddenTypes(new String[] { "uima.cpm.FileLocation" }); // launch viewer in a new dialog viewer.setCAS(cas); JDialog dialog = new JDialog(DBAnnotationViewerDialog.this, "Annotation Results for " + xmi_id + " in " + inputDirPath); // JMP dialog.getContentPane().add(viewer); dialog.setSize(850, 630); dialog.pack(); dialog.show(); } else { CAS defaultView = cas.getView(CAS.NAME_DEFAULT_SOFA); if (defaultView.getDocumentText() == null) { displayError( "The HTML and XML Viewers can only view the default text document, which was not found in this CAS."); return; } // generate inline XML File inlineXmlFile = new File(viewerDirectory, "inline.xml"); String xmlAnnotations = new CasToInlineXml().generateXML(defaultView); FileOutputStream outStream = new FileOutputStream(inlineXmlFile); outStream.write(xmlAnnotations.getBytes("UTF-8")); outStream.close(); if (xmlRBisSelected) // JMP passed in { // record preference for next time med1.setViewType("XML"); BrowserUtil.openUrlInDefaultBrowser(inlineXmlFile.getAbsolutePath()); } else // HTML view { med1.setViewType("HTML"); // generate HTML view // first process style map if not done already if (!processedStyleMap) { if (!styleMapFile.exists()) { annotationViewGenerator.autoGenerateStyleMapFile( promptForAE().getAnalysisEngineMetaData(), styleMapFile); } annotationViewGenerator.processStyleMap(styleMapFile); processedStyleMap = true; } annotationViewGenerator.processDocument(inlineXmlFile); File genFile = new File(viewerDirectory, "index.html"); // open in browser BrowserUtil.openUrlInDefaultBrowser(genFile.getAbsolutePath()); } } // end LTV here } catch (Exception ex) { displayError(ex); } }
From source file:org.barcelonamedia.uima.tools.docanalyzer.DBAnnotationViewerDialog.java
public void launchThatViewer(String xmi_id, TypeSystem typeSystem, final String[] aTypesToDisplay, boolean javaViewerRBisSelected, boolean javaViewerUCRBisSelected, boolean xmlRBisSelected, File styleMapFile, File viewerDirectory) { try {/* w ww. j a va2s.c om*/ InputStream xmiDocument = this.xmiDAO.getXMI(xmi_id); // create a new CAS CAS cas = CasCreationUtils.createCas(Collections.EMPTY_LIST, typeSystem, UIMAFramework.getDefaultPerformanceTuningProperties()); if (this.med1.isUmcompress()) { //Descomprime el XMI //Create the decompressor and give it the data to compress Inflater decompressor = new Inflater(); byte[] documentDataByteArray = IOUtils.toByteArray(xmiDocument); decompressor.setInput(documentDataByteArray); //Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(documentDataByteArray.length); //Decompress the data byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } bos.close(); //Get the decompressed data byte[] decompressedData = bos.toByteArray(); XmiCasDeserializer.deserialize(new ByteArrayInputStream(decompressedData), cas, true); } else { XmlCasDeserializer.deserialize(xmiDocument, cas, true); } //get the specified view cas = cas.getView(this.defaultCasViewName); //launch appropriate viewer if (javaViewerRBisSelected || javaViewerUCRBisSelected) { // JMP // record preference for next time med1.setViewType(javaViewerRBisSelected ? "Java Viewer" : "JV User Colors"); //create tree viewer component CasAnnotationViewer viewer = new CasAnnotationViewer(); viewer.setDisplayedTypes(aTypesToDisplay); if (javaViewerUCRBisSelected) getColorsForTypesFromFile(viewer, styleMapFile); else viewer.setHiddenTypes(new String[] { "uima.cpm.FileLocation" }); // launch viewer in a new dialog viewer.setCAS(cas); JDialog dialog = new JDialog(DBAnnotationViewerDialog.this, "Annotation Results for " + xmi_id + " in " + inputDirPath); // JMP dialog.getContentPane().add(viewer); dialog.setSize(850, 630); dialog.pack(); dialog.show(); } else { CAS defaultView = cas.getView(CAS.NAME_DEFAULT_SOFA); if (defaultView.getDocumentText() == null) { displayError( "The HTML and XML Viewers can only view the default text document, which was not found in this CAS."); return; } // generate inline XML File inlineXmlFile = new File(viewerDirectory, "inline.xml"); String xmlAnnotations = new CasToInlineXml().generateXML(defaultView); FileOutputStream outStream = new FileOutputStream(inlineXmlFile); outStream.write(xmlAnnotations.getBytes("UTF-8")); outStream.close(); if (xmlRBisSelected) // JMP passed in { // record preference for next time med1.setViewType("XML"); BrowserUtil.openUrlInDefaultBrowser(inlineXmlFile.getAbsolutePath()); } else // HTML view { med1.setViewType("HTML"); // generate HTML view // first process style map if not done already if (!processedStyleMap) { if (!styleMapFile.exists()) { annotationViewGenerator.autoGenerateStyleMapFile( promptForAE().getAnalysisEngineMetaData(), styleMapFile); } annotationViewGenerator.processStyleMap(styleMapFile); processedStyleMap = true; } annotationViewGenerator.processDocument(inlineXmlFile); File genFile = new File(viewerDirectory, "index.html"); // open in browser BrowserUtil.openUrlInDefaultBrowser(genFile.getAbsolutePath()); } } // end LTV here } catch (Exception ex) { displayError(ex); } }
From source file:org.drools.mas.SimpleClient.java
private void openFactEditorPanelForEdition(Object fact) { int pad = 100; if (this.factEditorPanel == null) { this.factEditorPanel = new FactEditorPanel(); this.factEditorPanel.setBounds(0, 0, this.getWidth() - pad, this.getHeight() - pad); factEditorPanelDialog = new JDialog(this, "Fact Editor"); factEditorPanelDialog.setSize(this.factEditorPanel.getWidth(), this.factEditorPanel.getHeight()); factEditorPanelDialog.setLocationRelativeTo(null); factEditorPanelDialog.add(this.factEditorPanel); EventDispatcher.getInstance().registerEventListener(new EventListener<NewFactCreatedEvent>() { public void onEvent(NewFactCreatedEvent event) { SimpleClient.this.factTableModel.addFact(event.getFact()); SimpleClient.this.factTableModel.fireTableDataChanged(); factEditorPanelDialog.setVisible(false); }/* w w w .j av a 2 s . c o m*/ }); EventDispatcher.getInstance().registerEventListener(new EventListener<FactModifiedEvent>() { public void onEvent(FactModifiedEvent event) { SimpleClient.this.factTableModel.replaceFact(event.getOriginalFact(), event.getNewFact()); SimpleClient.this.factTableModel.fireTableDataChanged(); factEditorPanelDialog.setVisible(false); } }); EventDispatcher.getInstance().registerEventListener(new EventListener<FactEditorPanelCloseEvent>() { public void onEvent(FactEditorPanelCloseEvent event) { factEditorPanelDialog.setVisible(false); } }); } factEditorPanel.reset(); if (fact != null) { factEditorPanel.editObject(fact); } factEditorPanelDialog.setVisible(true); }
From source file:org.freeplane.core.ui.components.OptionalDontShowMeAgainDialog.java
private OptionalDontShowMeAgainDialog show() { final String property = getProperty(); if (StringUtils.equals(property, "true")) { mResult = JOptionPane.OK_OPTION; return this; }/* w ww . j a v a2s .c om*/ if (mMessageType == BOTH_OK_AND_CANCEL_OPTIONS_ARE_STORED && StringUtils.equals(property, "false")) { mResult = JOptionPane.CANCEL_OPTION; return this; } mDialog = null; mDialog = new JDialog(mParent, TextUtils.getText(mTitleId)); mDialog.setModal(true); mDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); final AbstractAction cancelAction = new AbstractAction() { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent pE) { close(JOptionPane.CANCEL_OPTION); } }; final AbstractAction okAction = new AbstractAction() { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent pE) { close(JOptionPane.OK_OPTION); } }; UITools.addEscapeActionToDialog(mDialog, cancelAction); mDialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent pE) { close(JOptionPane.CANCEL_OPTION); } }); mDialog.getContentPane().setLayout(new GridBagLayout()); mDialog.getContentPane().add(new JLabel(TextUtils.getText(mMessageId)), new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); final ImageIcon questionMark; if (mMessageType == ONLY_OK_SELECTION_IS_SHOWN) { questionMark = new ImageIcon( ResourceController.getResourceController().getResource("/images/icons/messagebox_warning.png")); } else { questionMark = new ImageIcon( ResourceController.getResourceController().getResource("/images/icons/help.png")); } mDialog.getContentPane().add(new JLabel(questionMark), new GridBagConstraints(0, 0, 1, 2, 1.0, 2.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); String boxString; if (mMessageType != OptionalDontShowMeAgainDialog.BOTH_OK_AND_CANCEL_OPTIONS_ARE_STORED) { boxString = "OptionalDontShowMeAgainDialog.dontShowAgain"; } else { boxString = "OptionalDontShowMeAgainDialog.rememberMyDescision"; } mDontShowAgainBox = new JCheckBox(TextUtils.getRawText(boxString)); MenuBuilder.setLabelAndMnemonic(mDontShowAgainBox, null); mDialog.getContentPane().add(mDontShowAgainBox, new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); final String okText; if (mMessageType == ONLY_OK_SELECTION_IS_SHOWN) { okText = TextUtils.getRawText("ok"); } else { okText = TextUtils.getRawText("OptionalDontShowMeAgainDialog.ok"); } final JButton okButton = new JButton(okText); MenuBuilder.setLabelAndMnemonic(okButton, null); okButton.addActionListener(okAction); mDialog.getContentPane().add(okButton, new GridBagConstraints(2, 3, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); if (mMessageType != ONLY_OK_SELECTION_IS_SHOWN) { final JButton cancelButton = new JButton(TextUtils.getRawText("OptionalDontShowMeAgainDialog.cancel")); MenuBuilder.setLabelAndMnemonic(cancelButton, null); cancelButton.addActionListener(cancelAction); mDialog.getContentPane().add(cancelButton, new GridBagConstraints(3, 3, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); } mDialog.getRootPane().setDefaultButton(okButton); mDialog.pack(); if (mNode != null) { UITools.setDialogLocationRelativeTo(mDialog, mNode); } else { mDialog.setLocationRelativeTo(null); } mDialog.setVisible(true); return this; }
From source file:org.freeplane.view.swing.features.time.mindmapmode.nodelist.NodeList.java
public void startup() { if (dialog != null) { dialog.toFront();/*from w w w. ja v a 2 s. c o m*/ return; } NodeList.COLUMN_MODIFIED = TextUtils.getText(PLUGINS_TIME_LIST_XML_MODIFIED); NodeList.COLUMN_CREATED = TextUtils.getText(PLUGINS_TIME_LIST_XML_CREATED); NodeList.COLUMN_ICONS = TextUtils.getText(PLUGINS_TIME_LIST_XML_ICONS); NodeList.COLUMN_TEXT = TextUtils.getText(PLUGINS_TIME_LIST_XML_TEXT); NodeList.COLUMN_DETAILS = TextUtils.getText(PLUGINS_TIME_LIST_XML_DETAILS); NodeList.COLUMN_DATE = TextUtils.getText(PLUGINS_TIME_LIST_XML_DATE); NodeList.COLUMN_NOTES = TextUtils.getText(PLUGINS_TIME_LIST_XML_NOTES); dialog = new JDialog(Controller.getCurrentController().getViewController().getFrame(), modal /* modal */); String windowTitle; if (showAllNodes) { windowTitle = PLUGINS_TIME_MANAGEMENT_XML_WINDOW_TITLE_ALL_NODES; } else { windowTitle = PLUGINS_TIME_MANAGEMENT_XML_WINDOW_TITLE; } dialog.setTitle(TextUtils.getText(windowTitle)); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); final WindowAdapter windowListener = new WindowAdapter() { @Override public void windowGainedFocus(WindowEvent e) { mFilterTextSearchField.getEditor().selectAll(); } @Override public void windowClosing(final WindowEvent event) { disposeDialog(); } }; dialog.addWindowListener(windowListener); dialog.addWindowFocusListener(windowListener); UITools.addEscapeActionToDialog(dialog, new AbstractAction() { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { disposeDialog(); } }); final Container contentPane = dialog.getContentPane(); final GridBagLayout gbl = new GridBagLayout(); contentPane.setLayout(gbl); final GridBagConstraints layoutConstraints = new GridBagConstraints(); layoutConstraints.gridx = 0; layoutConstraints.gridy = 0; layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1; layoutConstraints.weightx = 0.0; layoutConstraints.weighty = 0.0; layoutConstraints.anchor = GridBagConstraints.WEST; layoutConstraints.fill = GridBagConstraints.HORIZONTAL; contentPane.add(new JLabel(TextUtils.getText(PLUGINS_TIME_MANAGEMENT_XML_FIND)), layoutConstraints); layoutConstraints.gridwidth = 1; layoutConstraints.gridx++; contentPane.add(Box.createHorizontalStrut(40), layoutConstraints); layoutConstraints.gridx++; contentPane.add(new JLabel(TextUtils.getText("filter_match_case")), layoutConstraints); layoutConstraints.gridx++; contentPane.add(matchCase, layoutConstraints); layoutConstraints.gridx++; contentPane.add(Box.createHorizontalStrut(40), layoutConstraints); layoutConstraints.gridx++; contentPane.add(new JLabel(TextUtils.getText("regular_expressions")), layoutConstraints); layoutConstraints.gridx++; contentPane.add(useRegexInFind, layoutConstraints); layoutConstraints.gridx = 0; layoutConstraints.weightx = 1.0; layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; layoutConstraints.gridy++; contentPane.add(/* new JScrollPane */(mFilterTextSearchField), layoutConstraints); layoutConstraints.gridy++; layoutConstraints.weightx = 0.0; layoutConstraints.gridwidth = 1; contentPane.add(new JLabel(TextUtils.getText(PLUGINS_TIME_MANAGEMENT_XML_REPLACE)), layoutConstraints); layoutConstraints.gridx = 5; contentPane.add(new JLabel(TextUtils.getText("regular_expressions")), layoutConstraints); layoutConstraints.gridx++; contentPane.add(useRegexInReplace, layoutConstraints); layoutConstraints.gridx = 0; layoutConstraints.weightx = 1.0; layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; layoutConstraints.gridy++; contentPane.add(/* new JScrollPane */(mFilterTextReplaceField), layoutConstraints); dateRenderer = new DateRenderer(); textRenderer = new TextRenderer(); iconsRenderer = new IconsRenderer(); tableView = new FlatNodeTable(); tableView.addKeyListener(new FlatNodeTableKeyListener()); tableView.addMouseListener(new FlatNodeTableMouseAdapter()); tableView.getTableHeader().setReorderingAllowed(false); tableModel = updateModel(); mFlatNodeTableFilterModel = new FlatNodeTableFilterModel(tableModel, new int[] { NodeList.NODE_TEXT_COLUMN, NodeList.NODE_DETAILS_COLUMN, NodeList.NODE_NOTES_COLUMN }); sorter = new TableSorter(mFlatNodeTableFilterModel); tableView.setModel(sorter); sorter.setTableHeader(tableView.getTableHeader()); sorter.setColumnComparator(Date.class, TableSorter.COMPARABLE_COMPARATOR); sorter.setColumnComparator(NodeModel.class, TableSorter.LEXICAL_COMPARATOR); sorter.setColumnComparator(IconsHolder.class, TableSorter.COMPARABLE_COMPARATOR); sorter.setSortingStatus(NodeList.DATE_COLUMN, TableSorter.ASCENDING); final JScrollPane pane = new JScrollPane(tableView); UITools.setScrollbarIncrement(pane); layoutConstraints.gridy++; GridBagConstraints tableConstraints = (GridBagConstraints) layoutConstraints.clone(); tableConstraints.weightx = 1; tableConstraints.weighty = 10; tableConstraints.fill = GridBagConstraints.BOTH; contentPane.add(pane, tableConstraints); mTreeLabel = new JLabel(); layoutConstraints.gridy++; GridBagConstraints treeConstraints = (GridBagConstraints) layoutConstraints.clone(); treeConstraints.fill = GridBagConstraints.BOTH; @SuppressWarnings("serial") JScrollPane scrollPane = new JScrollPane(mTreeLabel) { @Override public boolean isValidateRoot() { return false; } }; contentPane.add(scrollPane, treeConstraints); final AbstractAction exportAction = new AbstractAction( TextUtils.getText("plugins/TimeManagement.xml_Export")) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { exportSelectedRowsAndClose(); } }; final JButton exportButton = new JButton(exportAction); final AbstractAction replaceAllAction = new AbstractAction( TextUtils.getText("plugins/TimeManagement.xml_Replace_All")) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { replace(new HolderAccessor(false)); } }; final JButton replaceAllButton = new JButton(replaceAllAction); final AbstractAction replaceSelectedAction = new AbstractAction( TextUtils.getText("plugins/TimeManagement.xml_Replace_Selected")) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { replace(new HolderAccessor(true)); } }; final JButton replaceSelectedButton = new JButton(replaceSelectedAction); final AbstractAction gotoAction = new AbstractAction(TextUtils.getText("plugins/TimeManagement.xml_Goto")) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { selectSelectedRows(); } }; final JButton gotoButton = new JButton(gotoAction); final AbstractAction disposeAction = new AbstractAction( TextUtils.getText(PLUGINS_TIME_MANAGEMENT_XML_CLOSE)) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { disposeDialog(); } }; final JButton cancelButton = new JButton(disposeAction); /* Initial State */ gotoAction.setEnabled(false); exportAction.setEnabled(false); replaceSelectedAction.setEnabled(false); final Box bar = Box.createHorizontalBox(); bar.add(Box.createHorizontalGlue()); bar.add(cancelButton); bar.add(exportButton); bar.add(replaceAllButton); bar.add(replaceSelectedButton); bar.add(gotoButton); bar.add(Box.createHorizontalGlue()); layoutConstraints.gridy++; contentPane.add(/* new JScrollPane */(bar), layoutConstraints); final JMenuBar menuBar = new JMenuBar(); final JMenu menu = new JMenu(TextUtils.getText("plugins/TimeManagement.xml_menu_actions")); final AbstractAction[] actionList = new AbstractAction[] { gotoAction, replaceSelectedAction, replaceAllAction, exportAction, disposeAction }; for (int i = 0; i < actionList.length; i++) { final AbstractAction action = actionList[i]; final JMenuItem item = menu.add(action); item.setIcon(new BlindIcon(UIBuilder.ICON_SIZE)); } menuBar.add(menu); dialog.setJMenuBar(menuBar); final ListSelectionModel rowSM = tableView.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } final ListSelectionModel lsm = (ListSelectionModel) e.getSource(); final boolean enable = !(lsm.isSelectionEmpty()); replaceSelectedAction.setEnabled(enable); gotoAction.setEnabled(enable); exportAction.setEnabled(enable); } }); rowSM.addListSelectionListener(new ListSelectionListener() { String getNodeText(final NodeModel node) { return TextController.getController().getShortText(node) + ((node.isRoot()) ? "" : (" <- " + getNodeText(node.getParentNode()))); } public void valueChanged(final ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } final ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { mTreeLabel.setText(""); return; } final int selectedRow = lsm.getLeadSelectionIndex(); final NodeModel mindMapNode = getMindMapNode(selectedRow); mTreeLabel.setText(getNodeText(mindMapNode)); } }); final String marshalled = ResourceController.getResourceController() .getProperty(NodeList.WINDOW_PREFERENCE_STORAGE_PROPERTY); final WindowConfigurationStorage result = TimeWindowConfigurationStorage.decorateDialog(marshalled, dialog); final WindowConfigurationStorage storage = result; if (storage != null) { tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); int column = 0; for (final TimeWindowColumnSetting setting : ((TimeWindowConfigurationStorage) storage) .getListTimeWindowColumnSettingList()) { tableView.getColumnModel().getColumn(column).setPreferredWidth(setting.getColumnWidth()); sorter.setSortingStatus(column, setting.getColumnSorting()); column++; } } mFlatNodeTableFilterModel.setFilter((String) mFilterTextSearchField.getSelectedItem(), matchCase.isSelected(), useRegexInFind.isSelected()); dialog.setVisible(true); }
From source file:org.freeplane.view.swing.features.time.mindmapmode.NodeList.java
public void startup() { if (dialog != null) { dialog.toFront();/*from w w w.ja v a2 s . c o m*/ return; } NodeList.COLUMN_MODIFIED = TextUtils.getText(PLUGINS_TIME_LIST_XML_MODIFIED); NodeList.COLUMN_CREATED = TextUtils.getText(PLUGINS_TIME_LIST_XML_CREATED); NodeList.COLUMN_ICONS = TextUtils.getText(PLUGINS_TIME_LIST_XML_ICONS); NodeList.COLUMN_TEXT = TextUtils.getText(PLUGINS_TIME_LIST_XML_TEXT); NodeList.COLUMN_DATE = TextUtils.getText(PLUGINS_TIME_LIST_XML_DATE); NodeList.COLUMN_NOTES = TextUtils.getText(PLUGINS_TIME_LIST_XML_NOTES); dialog = new JDialog(Controller.getCurrentController().getViewController().getFrame(), modal /* modal */); String windowTitle; if (showAllNodes) { windowTitle = PLUGINS_TIME_MANAGEMENT_XML_WINDOW_TITLE_ALL_NODES; } else { windowTitle = PLUGINS_TIME_MANAGEMENT_XML_WINDOW_TITLE; } dialog.setTitle(TextUtils.getText(windowTitle)); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); final WindowAdapter windowListener = new WindowAdapter() { @Override public void windowGainedFocus(WindowEvent e) { mFilterTextSearchField.getEditor().selectAll(); } @Override public void windowClosing(final WindowEvent event) { disposeDialog(); } }; dialog.addWindowListener(windowListener); dialog.addWindowFocusListener(windowListener); UITools.addEscapeActionToDialog(dialog, new AbstractAction() { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { disposeDialog(); } }); final Container contentPane = dialog.getContentPane(); final GridBagLayout gbl = new GridBagLayout(); contentPane.setLayout(gbl); final GridBagConstraints layoutConstraints = new GridBagConstraints(); layoutConstraints.gridx = 0; layoutConstraints.gridy = 0; layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1; layoutConstraints.weightx = 0.0; layoutConstraints.weighty = 0.0; layoutConstraints.anchor = GridBagConstraints.WEST; layoutConstraints.fill = GridBagConstraints.HORIZONTAL; contentPane.add(new JLabel(TextUtils.getText(PLUGINS_TIME_MANAGEMENT_XML_FIND)), layoutConstraints); layoutConstraints.gridwidth = 1; layoutConstraints.gridx++; contentPane.add(Box.createHorizontalStrut(40), layoutConstraints); layoutConstraints.gridx++; contentPane.add(new JLabel(TextUtils.getText("filter_match_case")), layoutConstraints); layoutConstraints.gridx++; contentPane.add(matchCase, layoutConstraints); layoutConstraints.gridx++; contentPane.add(Box.createHorizontalStrut(40), layoutConstraints); layoutConstraints.gridx++; contentPane.add(new JLabel(TextUtils.getText("regular_expressions")), layoutConstraints); layoutConstraints.gridx++; contentPane.add(useRegexInFind, layoutConstraints); layoutConstraints.gridx = 0; layoutConstraints.weightx = 1.0; layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; layoutConstraints.gridy++; contentPane.add(/* new JScrollPane */(mFilterTextSearchField), layoutConstraints); layoutConstraints.gridy++; layoutConstraints.weightx = 0.0; layoutConstraints.gridwidth = 1; contentPane.add(new JLabel(TextUtils.getText(PLUGINS_TIME_MANAGEMENT_XML_REPLACE)), layoutConstraints); layoutConstraints.gridx = 5; contentPane.add(new JLabel(TextUtils.getText("regular_expressions")), layoutConstraints); layoutConstraints.gridx++; contentPane.add(useRegexInReplace, layoutConstraints); layoutConstraints.gridx = 0; layoutConstraints.weightx = 1.0; layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; layoutConstraints.gridy++; contentPane.add(/* new JScrollPane */(mFilterTextReplaceField), layoutConstraints); dateRenderer = new DateRenderer(); nodeRenderer = new NodeRenderer(); notesRenderer = new NotesRenderer(); iconsRenderer = new IconsRenderer(); timeTable = new FlatNodeTable(); timeTable.addKeyListener(new FlatNodeTableKeyListener()); timeTable.addMouseListener(new FlatNodeTableMouseAdapter()); timeTable.getTableHeader().setReorderingAllowed(false); timeTableModel = updateModel(); mFlatNodeTableFilterModel = new FlatNodeTableFilterModel(timeTableModel, NodeList.NODE_TEXT_COLUMN); sorter = new TableSorter(mFlatNodeTableFilterModel); timeTable.setModel(sorter); sorter.setTableHeader(timeTable.getTableHeader()); sorter.setColumnComparator(Date.class, TableSorter.COMPARABLE_COMPARATOR); sorter.setColumnComparator(NodeModel.class, TableSorter.LEXICAL_COMPARATOR); sorter.setColumnComparator(IconsHolder.class, TableSorter.COMPARABLE_COMPARATOR); sorter.setSortingStatus(NodeList.DATE_COLUMN, TableSorter.ASCENDING); final JScrollPane pane = new JScrollPane(timeTable); UITools.setScrollbarIncrement(pane); layoutConstraints.gridy++; GridBagConstraints tableConstraints = (GridBagConstraints) layoutConstraints.clone(); tableConstraints.weightx = 1; tableConstraints.weighty = 10; tableConstraints.fill = GridBagConstraints.BOTH; contentPane.add(pane, tableConstraints); mTreeLabel = new JLabel(); layoutConstraints.gridy++; GridBagConstraints treeConstraints = (GridBagConstraints) layoutConstraints.clone(); treeConstraints.fill = GridBagConstraints.BOTH; @SuppressWarnings("serial") JScrollPane scrollPane = new JScrollPane(mTreeLabel) { @Override public boolean isValidateRoot() { return false; } }; contentPane.add(scrollPane, treeConstraints); final AbstractAction exportAction = new AbstractAction( TextUtils.getText("plugins/TimeManagement.xml_Export")) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { exportSelectedRowsAndClose(); } }; final JButton exportButton = new JButton(exportAction); final AbstractAction replaceAllAction = new AbstractAction( TextUtils.getText("plugins/TimeManagement.xml_Replace_All")) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { replace(new ReplaceAllInfo()); } }; final JButton replaceAllButton = new JButton(replaceAllAction); final AbstractAction replaceSelectedAction = new AbstractAction( TextUtils.getText("plugins/TimeManagement.xml_Replace_Selected")) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { replace(new ReplaceSelectedInfo()); } }; final JButton replaceSelectedButton = new JButton(replaceSelectedAction); final AbstractAction gotoAction = new AbstractAction(TextUtils.getText("plugins/TimeManagement.xml_Goto")) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { selectSelectedRows(); } }; final JButton gotoButton = new JButton(gotoAction); final AbstractAction disposeAction = new AbstractAction( TextUtils.getText(PLUGINS_TIME_MANAGEMENT_XML_CLOSE)) { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent arg0) { disposeDialog(); } }; final JButton cancelButton = new JButton(disposeAction); /* Initial State */ gotoAction.setEnabled(false); exportAction.setEnabled(false); replaceSelectedAction.setEnabled(false); final Box bar = Box.createHorizontalBox(); bar.add(Box.createHorizontalGlue()); bar.add(cancelButton); bar.add(exportButton); bar.add(replaceAllButton); bar.add(replaceSelectedButton); bar.add(gotoButton); bar.add(Box.createHorizontalGlue()); layoutConstraints.gridy++; contentPane.add(/* new JScrollPane */(bar), layoutConstraints); final JMenuBar menuBar = new JMenuBar(); final JMenu menu = new JMenu(TextUtils.getText("plugins/TimeManagement.xml_menu_actions")); final AbstractAction[] actionList = new AbstractAction[] { gotoAction, replaceSelectedAction, replaceAllAction, exportAction, disposeAction }; for (int i = 0; i < actionList.length; i++) { final AbstractAction action = actionList[i]; final JMenuItem item = menu.add(action); item.setIcon(new BlindIcon(UIBuilder.ICON_SIZE)); } menuBar.add(menu); dialog.setJMenuBar(menuBar); final ListSelectionModel rowSM = timeTable.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } final ListSelectionModel lsm = (ListSelectionModel) e.getSource(); final boolean enable = !(lsm.isSelectionEmpty()); replaceSelectedAction.setEnabled(enable); gotoAction.setEnabled(enable); exportAction.setEnabled(enable); } }); rowSM.addListSelectionListener(new ListSelectionListener() { String getNodeText(final NodeModel node) { return TextController.getController().getShortText(node) + ((node.isRoot()) ? "" : (" <- " + getNodeText(node.getParentNode()))); } public void valueChanged(final ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } final ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { mTreeLabel.setText(""); return; } final int selectedRow = lsm.getLeadSelectionIndex(); final NodeModel mindMapNode = getMindMapNode(selectedRow); mTreeLabel.setText(getNodeText(mindMapNode)); } }); final String marshalled = ResourceController.getResourceController() .getProperty(NodeList.WINDOW_PREFERENCE_STORAGE_PROPERTY); final WindowConfigurationStorage result = TimeWindowConfigurationStorage.decorateDialog(marshalled, dialog); final WindowConfigurationStorage storage = result; if (storage != null) { timeTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); int column = 0; for (final TimeWindowColumnSetting setting : ((TimeWindowConfigurationStorage) storage) .getListTimeWindowColumnSettingList()) { timeTable.getColumnModel().getColumn(column).setPreferredWidth(setting.getColumnWidth()); sorter.setSortingStatus(column, setting.getColumnSorting()); column++; } } mFlatNodeTableFilterModel.setFilter((String) mFilterTextSearchField.getSelectedItem(), matchCase.isSelected(), useRegexInFind.isSelected()); dialog.setVisible(true); }
From source file:org.gofleet.module.routing.RoutingMap.java
private void newPlan(LatLon from) { JDialog d = new JDialog(basicWindow.getFrame(), "Generating New Plan"); try {/*from w w w . j a v a2 s.c o m*/ JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new RoutingFilter()); fc.setAcceptAllFileFilterUsed(true); int returnVal = fc.showOpenDialog(basicWindow.getFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); log.debug("Opening: " + file.getName()); JProgressBar progressBar = new JProgressBar(0, getNumberLines(file) * 2); progressBar.setValue(0); progressBar.setPreferredSize(new Dimension(150, 50)); progressBar.setStringPainted(true); d.add(progressBar); d.pack(); d.setVisible(true); TSPPlan[] param = processFile(file, progressBar); Map<String, String> values = getValues(from); double[] origin = new double[2]; origin[0] = new Double(values.get("origin_x")); origin[1] = new Double(values.get("origin_y")); TSPPlan[] res = calculateRouteOnWS(new Integer(values.get("maxDistance")), new Integer(values.get("maxTime")), origin, new Integer(values.get("startTime")), param, new Integer(values.get("timeSpentOnStop"))); progressBar.setValue(progressBar.getMaximum() - res.length); processTSPPlan(res, progressBar); } else { log.trace("Open command cancelled by user."); } } catch (Throwable t) { log.error("Error computing new plan", t); JOptionPane.showMessageDialog(basicWindow.getFrame(), "<html><p>" + i18n.getString("Main.Error") + ":</p><p>" + t.toString() + "</p><html>", i18n.getString("Main.Error"), JOptionPane.ERROR_MESSAGE); } finally { d.setVisible(false); d.dispose(); } }
From source file:org.gofleet.module.routing.RoutingMap.java
private Map<String, String> getValues(LatLon from) { final Map<String, String> mapa = new HashMap<String, String>(); final JDialog frame = new JDialog(basicWindow.getFrame(), "Configuration"); JPanel panel = new JPanel(new GridLayout(0, 2)); int width = 10; final JTextField maxDistance = new JTextField(width); maxDistance.setText("10"); final JTextField maxTime = new JTextField(width); maxTime.setText("8"); final JTextField origin_x = new JTextField(width / 2); origin_x.setText((new Double(from.getX())).toString()); final JTextField origin_y = new JTextField(width / 2); origin_y.setText((new Double(from.getY())).toString()); final JTextField startTime = new JTextField(width); startTime.setText("7"); final JTextField timeSpentOnStop = new JTextField(width); timeSpentOnStop.setText("1"); JLabel lmaxDistance = new JLabel("Maximum Distance (km)"); lmaxDistance.setLabelFor(maxDistance); JLabel lmaxTime = new JLabel("Maximum Time (hours)"); lmaxTime.setLabelFor(maxTime);//w w w. jav a 2 s .co m JLabel lorigin = new JLabel("Point of Origin"); lorigin.setLabelFor(origin_x); JLabel lstartTime = new JLabel("Start Time of Plan (0-24)"); lstartTime.setLabelFor(startTime); JLabel ltimeSpentOnStop = new JLabel("Time Spent on Stop (hours)"); ltimeSpentOnStop.setLabelFor(timeSpentOnStop); JButton close = new JButton("OK"); close.addActionListener(new AbstractAction() { private static final long serialVersionUID = -8912729211256933464L; @Override public void actionPerformed(ActionEvent arg0) { try { mapa.put("maxDistance", maxDistance.getText()); mapa.put("maxTime", maxTime.getText()); mapa.put("origin_x", origin_x.getText()); mapa.put("origin_y", origin_y.getText()); mapa.put("startTime", startTime.getText()); mapa.put("timeSpentOnStop", timeSpentOnStop.getText()); frame.dispose(); } catch (Throwable t) { log.error("Error configuring New Route Plan" + t); JOptionPane.showMessageDialog(RoutingMap.this, "Some values are wrong. Check them again."); } } }); panel.add(lmaxDistance); panel.add(maxDistance); panel.add(lmaxTime); panel.add(maxTime); panel.add(lorigin); JPanel panel_origin = new JPanel(); panel_origin.add(origin_x); panel_origin.add(origin_y); panel.add(panel_origin); panel.add(lstartTime); panel.add(startTime); panel.add(ltimeSpentOnStop); panel.add(timeSpentOnStop); panel.add(close); frame.add(panel, BorderLayout.CENTER); frame.pack(); frame.setModalityType(ModalityType.APPLICATION_MODAL); frame.setVisible(true); return mapa; }