List of usage examples for javax.swing JTextPane JTextPane
public JTextPane(StyledDocument doc)
JTextPane
, with a specified document model. From source file:ExtendedParagraphExample.java
public static void main(String[] args) { try {// w w w . j a va 2 s.c o m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Extended Paragraph Example"); // Create the StyleContext, the document and the pane final StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); final JTextPane pane = new JTextPane(doc); pane.setEditorKit(new ExtendedStyledEditorKit()); try { // Add the text and apply the styles SwingUtilities.invokeAndWait(new Runnable() { public void run() { // Build the styles createDocumentStyles(sc); // Add the text addText(pane, sc, sc.getStyle(mainStyleName), content); } }); } catch (Exception e) { System.out.println("Exception when constructing document: " + e); System.exit(1); } f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true); }
From source file:com.rapidminer.gui.properties.RegexpPropertyDialog.java
public RegexpPropertyDialog(final Collection<String> items, String predefinedRegexp, String description) { super(ApplicationFrame.getApplicationFrame(), "parameter.regexp", ModalityType.APPLICATION_MODAL, new Object[] {}); this.items = items; this.supportsItems = items != null; this.infoText = "<html>" + I18N.getMessage(I18N.getGUIBundle(), getKey() + ".title") + ": <br/>" + description + "</html>"; Dimension size = new Dimension(420, 500); this.setMinimumSize(size); this.setPreferredSize(size); JPanel panel = new JPanel(createGridLayout(1, supportsItems ? 2 : 1)); // create regexp text field regexpTextField = new JTextField(predefinedRegexp); regexpTextField.setToolTipText(//from w w w . ja va 2 s . c om I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.tip")); regexpTextField.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { fireRegularExpressionUpdated(); } @Override public void keyTyped(KeyEvent e) { } }); regexpTextField.requestFocus(); // create replacement text field replacementTextField = new JTextField(); replacementTextField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.tip")); replacementTextField.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { fireRegularExpressionUpdated(); } @Override public void keyTyped(KeyEvent e) { } }); // create inline search documents inlineSearchDocument = new RegexpSearchStyledDocument(); inlineReplaceDocument = new RegexpReplaceStyledDocument(); // create search results list DefaultListCellRenderer resultCellRenderer = new DefaultListCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); setBackground(list.getBackground()); setForeground(list.getForeground()); setBorder(getNoFocusBorder()); return this; } private Border getNoFocusBorder() { Border border = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray); return border; } }; JList<RegExpResult> regexpFindingsList = new JList<RegExpResult>(resultsListModel); regexpFindingsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); regexpFindingsList.setLayoutOrientation(JList.VERTICAL); regexpFindingsList.setCellRenderer(resultCellRenderer); // regexp panel on left side of dialog JPanel regexpPanel = new JPanel(new GridBagLayout()); regexpPanel.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.border"))); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(4, 4, 4, 0); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.BOTH; regexpPanel.add(regexpTextField, c); // make shortcut button final Action nullAction = new DefaultAction(); PlainArrowDropDownButton autoWireDropDownButton = PlainArrowDropDownButton.makeDropDownButton(nullAction); for (String[] popupItem : (String[][]) ArrayUtils.addAll(regexpConstructs, regexpShortcuts)) { String shortcut = popupItem[0].length() > 14 ? popupItem[0].substring(0, 14) + "..." : popupItem[0]; autoWireDropDownButton .add(new InsertionAction("<html><table border=0 cellpadding=0 cellspacing=0><tr><td width=100>" + shortcut + "</td><td>" + popupItem[1] + "</td></tr></table></html>", popupItem[0])); } c.insets = new Insets(4, 0, 4, 0); c.gridx = 1; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; regexpPanel.add(autoWireDropDownButton.getDropDownArrowButton(), c); // make delete button c.insets = new Insets(4, 0, 4, 4); c.gridx = 2; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; JButton clearRegexpTextFieldButton = new JButton(SwingTools.createIcon("16/delete2.png")); clearRegexpTextFieldButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { regexpTextField.setText(""); fireRegularExpressionUpdated(); regexpTextField.requestFocusInWindow(); } }); regexpPanel.add(clearRegexpTextFieldButton, c); errorMessage = new JLabel(NO_ERROR_MESSAGE, NO_ERROR_ICON, SwingConstants.LEFT); errorMessage.setFocusable(false); c.insets = new Insets(4, 8, 4, 4); c.gridx = 0; c.gridy = 1; c.weightx = 0; c.weighty = 0; c.gridwidth = GridBagConstraints.REMAINDER; regexpPanel.add(errorMessage, c); // create replacement panel JPanel replacementPanel = new JPanel(new GridBagLayout()); replacementPanel.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.border"))); JPanel testerPanel = new JPanel(new GridBagLayout()); c.insets = new Insets(4, 4, 4, 0); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; replacementPanel.add(replacementTextField, c); // create inline search panel JPanel inlineSearchPanel = new JPanel(new GridBagLayout()); c.insets = new Insets(8, 4, 4, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; inlineSearchPanel.add( new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.search")), c); c.insets = new Insets(0, 0, 0, 0); c.gridx = 0; c.gridy = 1; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; inlineSearchPanel.add(new JScrollPane(new JTextPane(inlineSearchDocument)), c); c.insets = new Insets(8, 4, 4, 4); c.gridx = 0; c.gridy = 2; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; inlineSearchPanel.add( new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.replaced")), c); c.insets = new Insets(0, 0, 0, 0); c.gridx = 0; c.gridy = 3; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; JTextPane replaceTextPane = new JTextPane(inlineReplaceDocument); replaceTextPane.setEditable(false); inlineSearchPanel.add(new JScrollPane(replaceTextPane), c); // create regexp options panel ItemListener defaultOptionListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { fireRegexpOptionsChanged(); } }; cbCaseInsensitive = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive")); cbCaseInsensitive.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive.tip")); cbCaseInsensitive.addItemListener(defaultOptionListener); cbMultiline = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode")); cbMultiline.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode.tip")); cbMultiline.addItemListener(defaultOptionListener); cbDotall = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode")); cbDotall.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode.tip")); cbDotall.addItemListener(defaultOptionListener); cbUnicodeCase = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case")); cbUnicodeCase.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case.tip")); cbUnicodeCase.addItemListener(defaultOptionListener); JPanel regexpOptionsPanelWrapper = new JPanel(new BorderLayout()); JPanel regexpOptionsPanel = new JPanel(new GridBagLayout()); regexpOptionsPanelWrapper.add(regexpOptionsPanel, BorderLayout.NORTH); c.insets = new Insets(12, 4, 0, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; regexpOptionsPanel.add(cbMultiline, c); c.insets = new Insets(8, 4, 0, 4); c.gridy = 1; regexpOptionsPanel.add(cbCaseInsensitive, c); c.gridy = 2; regexpOptionsPanel.add(cbUnicodeCase, c); c.gridy = 3; regexpOptionsPanel.add(cbDotall, c); // create tabbed panel c.insets = new Insets(8, 4, 4, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; testExp = new JTabbedPane(); testExp.add( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.inline_search.title"), new JScrollPane(inlineSearchPanel)); testExp.add( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.result_list.title"), new JScrollPane(regexpFindingsList)); testExp.add( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.title"), regexpOptionsPanelWrapper); testerPanel.add(testExp, c); JPanel groupPanel = new JPanel(new GridBagLayout()); c.insets = new Insets(4, 4, 4, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; groupPanel.add(regexpPanel, c); c.insets = new Insets(4, 4, 4, 4); c.gridx = 0; c.gridy = 1; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; groupPanel.add(replacementPanel, c); c.insets = new Insets(4, 4, 4, 4); c.gridx = 0; c.gridy = 2; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; groupPanel.add(testerPanel, c); panel.add(groupPanel, 1, 0); if (supportsItems) { // item shortcuts list itemShortcutsList = new JList<String>(items.toArray(new String[items.size()])); itemShortcutsList.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.tip")); itemShortcutsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); itemShortcutsList.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { String text = regexpTextField.getText(); int cursorPosition = regexpTextField.getCaretPosition(); int index = itemShortcutsList.getSelectedIndex(); if (index > -1 && index < itemShortcutsList.getModel().getSize()) { String insertionString = itemShortcutsList.getModel().getElementAt(index).toString(); String newText = text.substring(0, cursorPosition) + insertionString + (cursorPosition < text.length() ? text.substring(cursorPosition) : ""); regexpTextField.setText(newText); regexpTextField.setCaretPosition(cursorPosition + insertionString.length()); regexpTextField.requestFocus(); fireRegularExpressionUpdated(); } } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); JScrollPane itemShortcutsPane = new JScrollPane(itemShortcutsList); itemShortcutsPane.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.border"))); // matched items list matchedItemsListModel = new DefaultListModel<String>(); JList<String> matchedItemsList = new JList<String>(matchedItemsListModel); matchedItemsList.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.tip")); // add custom cell renderer to disallow selections matchedItemsList.setCellRenderer(new DefaultListCellRenderer() { private static final long serialVersionUID = -5795848004756768378L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return super.getListCellRendererComponent(list, value, index, false, false); } }); JScrollPane matchedItemsPanel = new JScrollPane(matchedItemsList); matchedItemsPanel.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.border"))); // item panel on right side of dialog JPanel itemPanel = new JPanel(createGridLayout(1, 2)); itemPanel.add(itemShortcutsPane, 0, 0); itemPanel.add(matchedItemsPanel, 0, 1); panel.add(itemPanel, 0, 1); } okButton = makeOkButton("regexp_property_dialog_apply"); fireRegularExpressionUpdated(); layoutDefault(panel, supportsItems ? NORMAL : NARROW, okButton, makeCancelButton()); }
From source file:fll.subjective.SubjectiveFrame.java
/** * Make sure the data in the table is valid. This checks to make sure that for * all rows, all columns that contain numeric data are actually set, or none * of these columns are set in a row. This avoids the case of partial data. * This method is fail fast in that it will display a dialog box on the first * error it finds.//from w w w .j a v a2s . c om * * @return true if everything is ok */ @SuppressFBWarnings(value = "SIC_INNER_SHOULD_BE_STATIC_ANON", justification = "Static inner class to replace anonomous listener isn't worth the confusion of finding the class definition") private boolean validateData() { stopCellEditors(); final List<String> warnings = new LinkedList<String>(); for (final ScoreCategory subjectiveCategory : getChallengeDescription().getSubjectiveCategories()) { final String category = subjectiveCategory.getName(); final String categoryTitle = subjectiveCategory.getTitle(); final List<AbstractGoal> goals = subjectiveCategory.getGoals(); final List<Element> scoreElements = SubjectiveTableModel.getScoreElements(_scoreDocument, category); for (final Element scoreElement : scoreElements) { int numValues = 0; for (final AbstractGoal goal : goals) { final String goalName = goal.getName(); final Element subEle = SubjectiveUtils.getSubscoreElement(scoreElement, goalName); if (null != subEle) { final String value = subEle.getAttribute("value"); if (!value.isEmpty()) { numValues++; } } } if (numValues != goals.size() && numValues != 0) { warnings.add(categoryTitle + ": " + scoreElement.getAttribute("teamNumber") + " has too few scores (needs all or none): " + numValues); } } } if (!warnings.isEmpty()) { // join the warnings with carriage returns and display them final StyledDocument doc = new DefaultStyledDocument(); for (final String warning : warnings) { try { doc.insertString(doc.getLength(), warning + "\n", null); } catch (final BadLocationException ble) { throw new RuntimeException(ble); } } final JDialog dialog = new JDialog(this, "Warnings"); final Container cpane = dialog.getContentPane(); cpane.setLayout(new BorderLayout()); final JButton okButton = new JButton("Ok"); cpane.add(okButton, BorderLayout.SOUTH); okButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent ae) { dialog.setVisible(false); dialog.dispose(); } }); cpane.add(new JTextPane(doc), BorderLayout.CENTER); dialog.pack(); dialog.setVisible(true); return false; } else { return true; } }
From source file:src.gui.ItTabbedPane.java
public void openTab(Element diagram, String id, String title, String type, Element project, Element commonData, Element projectHeader, String language) { String diagramType = diagram.getName(); // Checks whether the diagram is already open String xpath = ""; if (language.equals("UML")) { if (diagramType.equals("objectDiagram")) { xpath = "openTab[@language='" + language + "' and @projectID='" + projectHeader.getAttributeValue("id") + "' and @diagramID='" + id + "' and type='" + diagramType + "' and problem='" + diagram.getParentElement().getParentElement().getAttributeValue("id") + "' and domain='" + diagram.getParentElement().getParentElement().getParentElement().getParentElement() .getAttributeValue("id") + "']"; } else if (diagramType.equals("repositoryDiagram")) { xpath = "openTab[@language='" + language + "' and @projectID='" + projectHeader.getAttributeValue("id") + "' and @diagramID='" + id + "' and type='" + diagramType + "' and domain='" + diagram.getParentElement().getParentElement().getAttributeValue("id") + "']"; } else {/*from www. j ava 2s. com*/ xpath = "openTab[@language='" + language + "' and @projectID='" + projectHeader.getAttributeValue("id") + "' and @diagramID='" + id + "' and type='" + diagramType + "']"; } } else if (language.equals("PDDL")) { if (diagramType.equals("domain")) { xpath = "openTab[@language='" + language + "' and @projectID='" + projectHeader.getAttributeValue("id") + "' and @diagramID='" + id + "' and type='" + diagramType + "']"; } else if (diagramType.equals("problem")) { xpath = "openTab[@language='" + language + "' and @projectID='" + projectHeader.getAttributeValue("id") + "' and @diagramID='" + id + "' and type='" + diagramType + "' and domain='" + diagram.getParentElement().getParentElement().getAttributeValue("id") + "']"; } } else if (language.equals("PetriNet")) { xpath = "openTab[@language='" + language + "' and @projectID='" + projectHeader.getAttributeValue("id") + "' and @diagramID='" + id + "' and type='" + diagramType + "']"; } else { xpath = "openTab[@language='" + language + "' and @projectID='" + projectHeader.getAttributeValue("id") + "' and @diagramID='" + id + "' and type='" + diagramType + "']"; } //Checks if it is already opened Element openingDiagram = null; try { XPath path = new JDOMXPath(xpath); openingDiagram = (Element) path.selectSingleNode(openTabs); } catch (JaxenException e2) { e2.printStackTrace(); } if (openingDiagram != null) { // select the tab if it is already open setSelectedIndex(openingDiagram.getParent().indexOf(openingDiagram)); } else { //New Tab Document newDoc = null; try { newDoc = XMLUtilities.readFromFile("resources/settings/commonData.xml"); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Element openTab = ((Element) newDoc.getRootElement().getChild("internalUse").getChild("openTab") .clone()); Icon icon = null; JRootPane panel = null; //Check Language Type if (language.equals("UML")) { // Open the tab if not if (type.equals("useCaseDiagram") || type.equals("classDiagram") || type.equals("stateMachineDiagram") || type.equals("repositoryDiagram") || type.equals("objectDiagram") || type.equals("activityDiagram")) { //tool bar ItToolBar toolBar = new ItToolBar(type, "UML"); toolBar.setName(title); //graph (jgraph) GraphModel model = new DefaultGraphModel(); GraphLayoutCache view = new GraphLayoutCache(model, new ItCellViewFactory()); ItGraph diagramGraph = new ItGraph(view, toolBar, propertiesPane, project, diagram, commonData, language); toolBar.setGraph(diagramGraph); diagramGraph.setVisible(false); JScrollPane graphScrollPane = new JScrollPane(diagramGraph); panel = new JRootPane(); panel.setLayout(new BorderLayout()); panel.add(toolBar, BorderLayout.NORTH); panel.add(graphScrollPane, BorderLayout.CENTER); diagramGraph.buildDiagram(); diagramGraph.setBackground(Color.WHITE); diagramGraph.setVisible(true); } else if (type.equals("timingDiagram")) { panel = new JRootPane(); panel.setLayout(new BorderLayout()); TimingDiagramPanel timingdiagrampanel = new TimingDiagramPanel(diagram, project); panel.add(timingdiagrampanel, BorderLayout.CENTER); //JScrollPane listScrollPane = new JScrollPane(timingdiagrampanel); //panel.add(listScrollPane, BorderLayout.CENTER); /* //1. get type and context String dtype = diagram.getChildText("type"); String context = diagram.getChildText("context"); //the frame and lifeline nodes Element frame = diagram.getChild("frame"); Element lifelines = frame.getChild("lifelines"); String durationStr = frame.getChildText("duration"); String lifelineName = ""; String yAxisName = ""; //condition lifeline if (dtype.equals("condition")){ //check if the context is a action if (context.equals("action")){ //get action/operator Element operatorRef = diagram.getChild("action"); Element operator = null; try { XPath path = new JDOMXPath("elements/classes/class[@id='"+operatorRef.getAttributeValue("class")+"']/operators/operator[@id='"+ operatorRef.getAttributeValue("id") +"']"); operator = (Element)path.selectSingleNode(project); } catch (JaxenException e2) { e2.printStackTrace(); } if (operator !=null){ System.out.println(operator.getChildText("name")); //check every lifeline for (Iterator<Element> it = lifelines.getChildren("lifeline").iterator(); it.hasNext();) { Element lifeline = it.next(); System.out.println("Life line id "+ lifeline.getAttributeValue("id")); //get the object (can be a parametr. literal, or object) Element objRef = lifeline.getChild("object"); Element attrRef = lifeline.getChild("attribute"); //get object class Element objClass = pddlScrollPanenull; try { XPath path = new JDOMXPath("elements/classes/class[@id='"+objRef.getAttributeValue("class")+"']"); objClass = (Element)path.selectSingleNode(project); } catch (JaxenException e2) { e2.printStackTrace(); } Element attribute = null; try { XPath path = new JDOMXPath("elements/classes/class[@id='"+attrRef .getAttributeValue("class")+"']/attributes/attribute[@id='"+ attrRef.getAttributeValue("id") +"']"); attribute = (Element)path.selectSingleNode(project); } catch (JaxenException e2) { e2.printStackTrace(); } yAxisName = attribute.getChildText("name"); //if (objClass!=null) Element object = null; //check what is this object (parameterof an action, object, literal) if (objRef.getAttributeValue("element").equals("parameter")){ //get parameter in the action try { XPath path = new JDOMXPath("parameters/parameter[@id='"+objRef.getAttributeValue("id")+"']"); object = (Element)path.selectSingleNode(operator); } catch (JaxenException e2) { e2.printStackTrace(); } String parameterStr = object.getChildText("name"); lifelineName = parameterStr + ":" + objClass.getChildText("name"); } // //Boolean attribute if (attribute.getChildText("type").equals("1")){ lifelineName += " - " + attribute.getChildText("name"); Element timeIntervals = lifeline.getChild("timeIntervals"); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Boolean"); int stepIndex = 0; for (Iterator<Element> it1 = timeIntervals.getChildren().iterator(); it1.hasNext();) { Element timeInterval = it1.next(); boolean insertPoint = true; Element durationConstratint = timeInterval.getChild("durationConstratint"); Element lowerbound = durationConstratint.getChild("lowerbound"); Element upperbound = durationConstratint.getChild("upperbound"); Element value = timeInterval.getChild("value"); //Add for both lower and upper bound //lower bound float lowerTimePoint = 0; try { lowerTimePoint = Float.parseFloat(lowerbound.getAttributeValue("value")); } catch (Exception e) { insertPoint = false; } System.out.println(" > point x= "+ Float.toString(lowerTimePoint)+ " , y= "+ lowerbound.getAttributeValue("value")); if (insertPoint){ series.add(lowerTimePoint, (value.getText().equals("false") ?0 :1)); } //upper bound float upperTimePoint = 0; try { upperTimePoint = Float.parseFloat(upperbound.getAttributeValue("value")); } catch (Exception e) { insertPoint = false; } System.out.println(" > point x= "+ Float.toString(upperTimePoint)+ " , y= "+ lowerbound.getAttributeValue("value")); if (insertPoint){ series.add(upperTimePoint, (value.getText().equals("false") ?0 :1)); } } dataset.addSeries(series); JFreeChart chart = ChartFactory.createXYStepChart(lifelineName, "time", "value", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot)chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); NumberAxis domainAxis = new NumberAxis("Time"); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setUpperBound(30.0); plot.setDomainAxis(domainAxis); String[] values = {"false", "true"}; //SymbolAxis rangeAxis = new SymbolAxis("Values", values); SymbolAxis rangeAxis = new SymbolAxis(yAxisName, values); plot.setRangeAxis(rangeAxis); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(chartPanel.getSize().width, 175)); panel.add(chartPanel, BorderLayout.CENTER); // XYSeries series = new XYSeries(lifelineName); // int stepIndex = 0; // // for (Iterator<Element> it1 = timeIntervals.getChildren().iterator(); it1.hasNext();) { // Element timeInterval = it1.next(); // // Element durationConstratint = timeInterval.getChild("durationConstratint"); // Element lowerbound = durationConstratint.getChild("lowerbound"); // Element upperbound = durationConstratint.getChild("upperbound"); // Element value = timeInterval.getChild("value"); // // // series.add(stepIndex++, (value.getText().equals("false") ?0 :1)); // // // } // // XYSeriesCollection dataset = new XYSeriesCollection(series); // JFreeChart chart = ChartFactory.createXYLineChart(lifelineName, "Steps", "Values", dataset, PlotOrientation.VERTICAL, false, true, false); // //JFreeChart chart = ChartFactory.createXYStepChart("test", "Values", "Steps", dataset, PlotOrientation.VERTICAL, false, true, false); // //JFreeChart chart = ChartFactory.createAreaChart("test", "x", "y", dataset, PlotOrientation.VERTICAL, false, true, false); // ChartPanel chartPanel = new ChartPanel(chart); // panel.add(chartPanel, BorderLayout.CENTER); //build graph true/false } } } } //if this is a possible sequence of action being modeled to a condition else if (context.equals("general")){ } } else if (dtype.equals("state")){ } */ /* panel = new JRootPane(); panel.setLayout(new BorderLayout()); panel.add(new Label("TIMING DIAGRAM"), BorderLayout.NORTH); String chartTitle = "Timing diagram"; XYSeries series = new XYSeries("Average Size"); series.add(20.0, 10.0); series.add(40.0, 20.0); series.add(70.0, 50.0); XYSeriesCollection dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "Steps", "Values", dataset, PlotOrientation.VERTICAL, false, true, false); //JFreeChart chart = ChartFactory.createXYStepChart("test", "Values", "Steps", dataset, PlotOrientation.VERTICAL, false, true, false); //JFreeChart chart = ChartFactory.createAreaChart("test", "x", "y", dataset, PlotOrientation.VERTICAL, false, true, false); ChartPanel chartPanel = new ChartPanel(chart); panel.add(chartPanel, BorderLayout.CENTER); */ } // Prepare Tab Icon icon = new ImageIcon("resources/images/" + diagram.getName() + ".png"); //Set Tab properties openTab.setAttribute("language", language); openTab.setAttribute("diagramID", id); openTab.setAttribute("projectID", projectHeader.getAttributeValue("id")); openTab.getChild("type").setText(type); if (type.equals("objectDiagram")) { //object diagrams problem openTab.getChild("problem") .setText(diagram.getParentElement().getParentElement().getAttributeValue("id")); // object diagrams problem planningProblems domain openTab.getChild("domain").setText(diagram.getParentElement().getParentElement() .getParentElement().getParentElement().getAttributeValue("id")); } else if (type.equals("repositoryDiagram")) { // repositoryDiagrams domain openTab.getChild("domain") .setText(diagram.getParentElement().getParentElement().getAttributeValue("id")); } } else if (language.equals("PDDL")) { ItToolBar toolBar = new ItToolBar(type, "PDDL"); toolBar.setName(title); ItHilightedDocument pddlDocument = new ItHilightedDocument(); pddlDocument.setHighlightStyle(ItHilightedDocument.PDDL_STYLE); JTextPane pddlTextPane = new JTextPane(pddlDocument); pddlTextPane.setFont(new Font("Courier", 0, 12)); toolBar.setTextPane(pddlTextPane); JScrollPane pddlScrollPane = new JScrollPane(pddlTextPane); panel = new JRootPane(); panel.setLayout(new BorderLayout()); panel.add(toolBar, BorderLayout.NORTH); panel.add(pddlScrollPane, BorderLayout.CENTER); icon = new ImageIcon("resources/images/" + diagram.getName() + ".png"); if (type.equals("domain")) { //PlanningDomains diagrams project Element projectDomain = diagram.getParentElement().getParentElement().getParentElement(); // TODO PDDL 3.0 was made default, but the user should be able to chose it Element xpddlDomain = ToXPDDL.XMLToXPDDLDomain(projectDomain, ToXPDDL.PDDL_3_0, null); String domainText = XPDDLToPDDL.parseXPDDLToPDDL(xpddlDomain, " "); pddlTextPane.setText(domainText); } else if (type.equals("problem")) { Element xpddlProblem = ToXPDDL.XMLToXPDDLProblem(diagram, ToXPDDL.PDDL_3_0); String problemText = XPDDLToPDDL.parseXPDDLToPDDL(xpddlProblem, " "); pddlTextPane.setText(problemText); } // Set Tab properties openTab.setAttribute("language", language); openTab.setAttribute("diagramID", id); openTab.setAttribute("projectID", projectHeader.getAttributeValue("id")); openTab.getChild("type").setText(type); if (type.equals("problem")) { // planningProblems domains openTab.getChild("domain") .setText(diagram.getParentElement().getParentElement().getAttributeValue("id")); } } else if (language.equals("PetriNet")) { // Open the tab if not ItToolBar toolBar = new ItToolBar(type, "PetriNet"); toolBar.setName(title); GraphModel model = new DefaultGraphModel(); GraphLayoutCache view = new GraphLayoutCache(model, new ItCellViewFactory()); ItGraph diagramGraph = new ItGraph(view, toolBar, propertiesPane, project, diagram, commonData, language); toolBar.setGraph(diagramGraph); diagramGraph.buildDiagram(); diagramGraph.setBackground(Color.WHITE); diagramGraph.setVisible(false); diagramGraph.setInfoPane(src.gui.ItSIMPLE.getInstance().getInfoEditorPane()); JScrollPane graphScrollPane = new JScrollPane(diagramGraph); panel = new JRootPane(); panel.setLayout(new BorderLayout()); panel.add(toolBar, BorderLayout.NORTH); panel.add(graphScrollPane, BorderLayout.CENTER); //panel.setContentPane(graphScrollPane); diagramGraph.buildDiagram(); diagramGraph.setVisible(true); // Prepare Tab Icon icon = new ImageIcon("resources/images/" + diagram.getName() + ".png"); //Set Tab properties openTab.setAttribute("language", language); openTab.setAttribute("diagramID", id); openTab.setAttribute("projectID", projectHeader.getAttributeValue("id")); openTab.getChild("type").setText(type); } if (icon != null && panel != null) { // add the tab openTabs.addContent(openTab); addTab(title, icon, panel); if (getTabCount() > 1) { setSelectedIndex(getTabCount() - 1); } } } }
From source file:src.gui.ItTabbedPane.java
public void openPDDLTab(Element diagram, String id, String title, Element project, Element projectHeader, File file) {/*from w ww .ja v a 2 s. c o m*/ String nodeType = diagram.getName(); // Checks whether the diagram is already open String xpath = "openTab[@language='PDDL' and @projectID='" + projectHeader.getAttributeValue("id") + "' and @diagramID='" + id + "' and type='" + nodeType + "']"; //Checks if it is already opened Element openingDiagram = null; try { XPath path = new JDOMXPath(xpath); openingDiagram = (Element) path.selectSingleNode(openTabs); } catch (JaxenException e2) { e2.printStackTrace(); } if (openingDiagram != null) { // select the tab if it is already open setSelectedIndex(openingDiagram.getParent().indexOf(openingDiagram)); } else { //New Tab Document newDoc = null; try { newDoc = XMLUtilities.readFromFile("resources/settings/commonData.xml"); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Element openTab = ((Element) newDoc.getRootElement().getChild("internalUse").getChild("openTab") .clone()); Icon icon = null; JRootPane panel = null; ItToolBar toolBar = new ItToolBar(diagram.getName(), "PDDL"); toolBar.setName(title); ItHilightedDocument pddlDocument = new ItHilightedDocument(); pddlDocument.setHighlightStyle(ItHilightedDocument.PDDL_STYLE); JTextPane pddlTextPane = new JTextPane(pddlDocument); pddlTextPane.setFont(new Font("Courier", 0, 12)); pddlDocument.setTextPane(pddlTextPane); pddlDocument.setData(diagram); pddlDocument.addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent de) { //throw new UnsupportedOperationException("Not supported yet."); //System.out.println("insert"); storechange(de); } public void removeUpdate(DocumentEvent de) { //throw new UnsupportedOperationException("Not supported yet."); //System.out.println("remove"); storechange(de); } public void changedUpdate(DocumentEvent de) { //throw new UnsupportedOperationException("Not supported yet."); //System.out.println("changed"); } public void storechange(DocumentEvent de) { //When a document is open it is also calling this method ItHilightedDocument document = (ItHilightedDocument) de.getDocument(); String text = document.getTextPane().getText(); Element diagram = document.getData(); Element content = diagram.getChild("content"); if (content != null) { content.setText(text); } else { content = new Element("content"); content.setText(text); diagram.addContent(content); } } }); //ROSI pddlDocument UndoManager undo = new UndoManager(); toolBar.setUndoManager(undo); pddlDocument.addUndoableEditListener(new MyUndoableEditListener(undo)); toolBar.setTextPane(pddlTextPane); JScrollPane pddlScrollPane = new JScrollPane(pddlTextPane); panel = new JRootPane(); panel.setLayout(new BorderLayout()); panel.add(toolBar, BorderLayout.NORTH); panel.add(pddlScrollPane, BorderLayout.CENTER); icon = new ImageIcon("resources/images/" + diagram.getName() + ".png"); String fileContentText = ""; fileContentText = getContentsAsString(file); pddlTextPane.setText(fileContentText); //Set Tab properties openTab.setAttribute("language", "PDDL"); openTab.setAttribute("diagramID", id); openTab.setAttribute("projectID", projectHeader.getAttributeValue("id")); openTab.getChild("type").setText(diagram.getName()); //if (diagram.getName().equals("pddlproblem")){ // // planningProblems domains // openTab.getChild("domain").setText(diagram.getParentElement().getParentElement().getAttributeValue("id")); //} if (icon != null && panel != null) { // add the tab openTabs.addContent(openTab); addTab(title, icon, panel); if (getTabCount() > 1) { setSelectedIndex(getTabCount() - 1); } } } }
From source file:src.gui.ItSIMPLE.java
/** * This method initializes domainPddlTextPane * * @return javax.swing.JTextPane/*from w w w . j a v a 2s . co m*/ */ public JTextPane getDomainPddlTextPane() { if (domainPddlTextPane == null) { ItHilightedDocument domainDocument = new ItHilightedDocument(); domainDocument.setHighlightStyle(ItHilightedDocument.PDDL_STYLE); domainPddlTextPane = new JTextPane(domainDocument); domainPddlTextPane.setFont(new Font("Courier", 0, 12)); domainPddlTextPane.setBackground(Color.WHITE); } return domainPddlTextPane; }
From source file:src.gui.ItSIMPLE.java
/** * This method initializes problemPddlTextPane * * @return javax.swing.JTextPane//from www . j av a2s . c o m */ private JTextPane getProblemPddlTextPane() { if (problemPddlTextPane == null) { ItHilightedDocument problemDocument = new ItHilightedDocument(); problemDocument.setHighlightStyle(ItHilightedDocument.PDDL_STYLE); problemPddlTextPane = new JTextPane(problemDocument); problemPddlTextPane.setFont(new Font("Courier", 0, 12)); problemPddlTextPane.setBackground(Color.WHITE); } return problemPddlTextPane; }
From source file:ome.formats.importer.gui.GuiCommonElements.java
/** * Add a text pane to the parent container * // w w w .ja v a 2 s.c om * @param container - parent container * @param text - text for new Text Pane * @param placement - TableLayout placement within the parent container * @param debug - turn on/off red debug borders * @return new JTextPane */ public static synchronized JTextPane addTextPane(Container container, String text, String placement, boolean debug) { StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT); try { document.insertString(document.getLength(), text, null); } catch (BadLocationException e) { log.error("BadLocationException inserting text to document."); } JTextPane textPane = new JTextPane(document); textPane.setOpaque(false); textPane.setEditable(false); textPane.setFocusable(false); container.add(textPane, placement); if (debug == true) textPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), textPane.getBorder())); return textPane; }
From source file:ome.formats.importer.gui.GuiCommonElements.java
/** * A version of addTextPane that lets you add a style and context * // w w w.ja v a 2 s . co m * @param container - parent container * @param text - text for new Text Pane * @param placement - TableLayout placement within the parent container * @param context - context for new text pane * @param style - style to apply to new text pane * @param debug - turn on/off red debug borders * @return new JTextPane */ public static synchronized JTextPane addTextPane(Container container, String text, String placement, StyleContext context, Style style, boolean debug) { StyledDocument document = new DefaultStyledDocument(context); try { document.insertString(document.getLength(), text, style); } catch (BadLocationException e) { log.error("BadLocationException inserting text to document."); } JTextPane textPane = new JTextPane(document); textPane.setOpaque(false); textPane.setEditable(false); textPane.setFocusable(false); container.add(textPane, placement); if (debug == true) textPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), textPane.getBorder())); return textPane; }
From source file:org.opendatakit.appengine.updater.UpdaterWindow.java
/** * Create the application./*from www . ja v a2s . c om*/ */ public UpdaterWindow(CommandLine cmd) { super(); AnnotationProcessor.process(this);// if not using AOP this.cmd = cmd; frame = new JFrame(); frame.setBounds(100, 100, isLinux() ? 720 : 680, 595); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); JLabel lblEmail = new JLabel(t(TranslatedStrings.EMAIL_LABEL)); txtEmail = new JTextField(); txtEmail.setFocusable(true); txtEmail.setEditable(true); txtEmail.setColumns(60); txtEmail.setMaximumSize(txtEmail.getPreferredSize()); if (cmd.hasOption(ArgumentNameConstants.EMAIL)) { txtEmail.setText(cmd.getOptionValue(ArgumentNameConstants.EMAIL)); } lblEmail.setLabelFor(txtEmail); JLabel lblToken = new JLabel(t(TranslatedStrings.TOKEN_GRANTING_LABEL)); txtToken = new JTextField(); txtToken.setColumns(60); txtToken.setMaximumSize(txtToken.getPreferredSize()); txtToken.setFocusable(false); txtToken.setEditable(false); if (cmd.hasOption(ArgumentNameConstants.TOKEN_GRANTING_CODE)) { txtToken.setText(cmd.getOptionValue(ArgumentNameConstants.TOKEN_GRANTING_CODE)); } lblToken.setLabelFor(txtToken); // set up listener for updating warning message txtEmail.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { updateUI(); } @Override public void removeUpdate(DocumentEvent e) { updateUI(); } @Override public void changedUpdate(DocumentEvent e) { updateUI(); } }); // set up listener for updating warning message txtToken.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { updateUI(); } @Override public void removeUpdate(DocumentEvent e) { updateUI(); } @Override public void changedUpdate(DocumentEvent e) { updateUI(); } }); if ((txtEmail.getText().length() > 0) && ((txtToken.getText().length() > 0) || perhapsHasToken())) { lblWarning = new JLabel(t(TranslatedStrings.WARNING_ERRANT_LABEL)); } else { lblWarning = new JLabel(t(TranslatedStrings.WARNING_REDIRECT_LABEL)); } JLabel outputArea = new JLabel(t(TranslatedStrings.OUTPUT_LBL)); editorArea = new JTextPane(new DefaultStyledDocument()); editorArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //Put the editor pane in a scroll pane. editorScrollPane = new JScrollPane(editorArea); editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(400, 300)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); outputArea.setLabelFor(editorScrollPane); // Create a container so that we can add a title around // the scroll pane. Can't add a title directly to the // scroll pane because its background would be white. // Lay out the label and scroll pane from top to bottom. JPanel listPane = new JPanel(); listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); listPane.add(outputArea); listPane.add(Box.createRigidArea(new Dimension(0, 5))); listPane.add(editorScrollPane); listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); btnDeleteToken = new JButton(t(TranslatedStrings.DELETE_TOKEN_LABEL)); btnDeleteToken.addActionListener(new DeleteTokenActionListener()); btnDeleteToken.setEnabled(perhapsHasToken()); btnChoose = new JButton(t(TranslatedStrings.GET_TOKEN_LABEL)); if ((txtEmail.getText().length() > 0) && (txtToken.getText().length() > 0) || perhapsHasToken()) { if (perhapsHasToken()) { btnChoose.setText(t(TranslatedStrings.VERIFY_TOKEN_LABEL)); } else { btnChoose.setText(t(TranslatedStrings.SET_TOKEN_LABEL)); } } else { btnChoose.setText(t(TranslatedStrings.GET_TOKEN_LABEL)); } btnChoose.addActionListener(new GetTokenActionListener()); btnChoose.setEnabled(txtEmail.getText().length() > 0); btnUpload = new JButton(t(TranslatedStrings.UPLOAD_LABEL)); btnUpload.addActionListener(new UploadActionListener()); btnUpload.setEnabled((txtEmail.getText().length() > 0) && perhapsHasToken()); btnRollback = new JButton(t(TranslatedStrings.ROLLBACK_LABEL)); btnRollback.addActionListener(new RollbackActionListener()); btnRollback.setEnabled((txtEmail.getText().length() > 0) && perhapsHasToken()); GroupLayout groupLayout = new GroupLayout(frame.getContentPane()); groupLayout .setHorizontalGroup( groupLayout.createSequentialGroup().addContainerGap() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblEmail) .addComponent(txtEmail).addComponent(lblToken).addComponent(txtToken) .addComponent(lblWarning).addComponent(listPane) .addGroup(groupLayout.createSequentialGroup().addComponent(btnDeleteToken) .addGap(3 * HorizontalSpacing).addComponent(btnChoose) .addGap(HorizontalSpacing).addComponent(btnUpload) .addGap(3 * HorizontalSpacing, 4 * HorizontalSpacing, Short.MAX_VALUE) .addComponent(btnRollback))) .addContainerGap()); groupLayout.setVerticalGroup(groupLayout.createSequentialGroup().addContainerGap().addComponent(lblEmail) .addPreferredGap(ComponentPlacement.RELATED).addComponent(txtEmail) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(lblToken) .addPreferredGap(ComponentPlacement.RELATED).addComponent(txtToken) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(lblWarning) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(listPane) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(btnDeleteToken) .addComponent(btnChoose).addComponent(btnUpload).addComponent(btnRollback)) .addContainerGap()); frame.getContentPane().setLayout(groupLayout); frame.addWindowListener(this); }