List of usage examples for javax.swing JTextPane setFont
@BeanProperty(preferred = true, visualUpdate = true, description = "The font for the component.") public void setFont(Font font)
From source file:Main.java
public static void main(String[] args) throws Exception { int SIZE = 14; String FONT = "Dialog"; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane tp = new JTextPane(); tp.setFont(new Font(FONT, Font.PLAIN, SIZE)); tp.setPreferredSize(new Dimension(400, 300)); StyledDocument doc = tp.getStyledDocument(); Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style boldStyle = doc.addStyle("bold", defaultStyle); StyleConstants.setBold(boldStyle, true); String boldText = "this is bold test"; String plainText = "this is plain."; doc.insertString(doc.getLength(), boldText, boldStyle); doc.insertString(doc.getLength(), plainText, defaultStyle); JPanel panel = new JPanel(); panel.add(tp);/*from ww w . ja va 2 s. co m*/ JComboBox<String> zoomCombo = new JComboBox<String>( new String[] { "0.75", "1.00", "1.50", "1.75", "2.00" }); zoomCombo.addActionListener(e -> { String s = (String) zoomCombo.getSelectedItem(); double scale = new Double(s).doubleValue(); int size = (int) (SIZE * scale); tp.setFont(new Font(FONT, Font.PLAIN, size)); }); zoomCombo.setSelectedItem("1.00"); JPanel optionsPanel = new JPanel(); optionsPanel.add(zoomCombo); panel.setBackground(Color.WHITE); frame.add(panel, BorderLayout.CENTER); frame.add(optionsPanel, BorderLayout.NORTH); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String HTMLTEXT = "<html><head><style>.foot{color:red} .head{color:black}</style></head>" + "<span style='font-family:consolas'>java2s.com</span><br/>" + "<span style='font-family:tahoma'>java2s.com</span>"; JTextPane textPane1 = new JTextPane(); textPane1.setContentType("text/html"); textPane1.setFont(new Font("courier new", Font.PLAIN, 32)); textPane1.setDocument(new HTMLDocument() { @Override// w w w. ja va2 s .c o m public Font getFont(AttributeSet attr) { StyleContext styles = (StyleContext) getAttributeContext(); Font f = styles.getFont(attr); String ff = f.getFamily(); System.out.println(ff); return textPane1.getFont(); } }); textPane1.setText(HTMLTEXT); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(textPane1)); f.setSize(320, 240); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:StylesExample5.java
public static void main(String[] args) { try {/*from w ww . j av a 2 s . co m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Styles Example 5"); // Create the StyleContext, the document and the pane StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); final JTextPane pane = new JTextPane(doc); // Create and add the style final Style heading2Style = sc.addStyle("Heading2", null); heading2Style.addAttribute(StyleConstants.Foreground, Color.red); heading2Style.addAttribute(StyleConstants.FontSize, new Integer(16)); heading2Style.addAttribute(StyleConstants.FontFamily, "serif"); heading2Style.addAttribute(StyleConstants.Bold, new Boolean(true)); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { try { // Add the text to the document doc.insertString(0, text, null); // Finally, apply the style to the heading doc.setParagraphAttributes(0, 1, heading2Style, false); // Set the foreground and font pane.setForeground(Color.blue); pane.setFont(new Font("serif", Font.PLAIN, 12)); } catch (BadLocationException e) { } } }); } 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:Main.java
/** * Creates a new <code>JTextPane</code> object with the given properties. * * @param text The text which will appear in the text pane * @param backgroundColor The background color * @return A <code>JTextPane</code> object *///from w w w . j a v a 2 s . c o m public static JTextPane createJTextPane(String text, Color backgroundColor) { JTextPane jTextPane = new JTextPane(); jTextPane.setBorder(null); jTextPane.setEditable(false); jTextPane.setBackground(backgroundColor); jTextPane.setFont(new Font("Times New Roman", Font.PLAIN, 14)); if (text != null) { jTextPane.setText(text); } jTextPane.setVerifyInputWhenFocusTarget(false); jTextPane.setAutoscrolls(false); return jTextPane; }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(new BorderLayout()); setContentPane(panel);//from w w w. jav a 2 s .co m JTextPane textA = new JTextPane(); textA.setName("text"); textA.setContentType("text/html"); DefaultCaret caret = (DefaultCaret) textA.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); JScrollPane filler = new JScrollPane(textA, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JTextPane textB = new JTextPane(); textB.setName("text" + "_T"); textB.setFont(textA.getFont()); DefaultCaret caret_T = (DefaultCaret) textB.getCaret(); caret_T.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); JScrollPane filler_T = new JScrollPane(textB, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); panel.add(filler, BorderLayout.NORTH); panel.add(filler_T, BorderLayout.CENTER); pack(); }
From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java
public JTextPane createJTextPane(String text) { JTextPane jtp = new JTextPane(); jtp.setText(text);/*from w w w. j av a 2 s . c o m*/ SimpleAttributeSet underline = new SimpleAttributeSet(); StyleConstants.setUnderline(underline, true); jtp.getStyledDocument().setCharacterAttributes(0, text.length(), underline, true); jtp.setEditable(false); jtp.setOpaque(false); jtp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10)); jtp.setBorder(BorderFactory.createEmptyBorder()); jtp.setForeground(Color.blue); jtp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); return jtp; }
From source file:com.awesomecoding.minetestlauncher.Main.java
private void initialize() { fileGetter = new FileGetter(userhome + "\\minetest\\temp\\"); latest = fileGetter.getContents("http://socialmelder.com/minetest/latest.txt", true); currentVersion = latest.split("\n")[0]; changelog = fileGetter.getContents("http://socialmelder.com/minetest/changelog.html", false); try {//from w w w . j av a 2 s. c o m UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } frmMinetestLauncherV = new JFrame(); frmMinetestLauncherV.setResizable(false); frmMinetestLauncherV.setIconImage(Toolkit.getDefaultToolkit() .getImage(Main.class.getResource("/com/awesomecoding/minetestlauncher/icon.png"))); frmMinetestLauncherV.setTitle("Minetest Launcher (Version 0.1)"); frmMinetestLauncherV.setBounds(100, 100, 720, 480); frmMinetestLauncherV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SpringLayout springLayout = new SpringLayout(); frmMinetestLauncherV.getContentPane().setLayout(springLayout); final JProgressBar progressBar = new JProgressBar(); springLayout.putConstraint(SpringLayout.WEST, progressBar, 10, SpringLayout.WEST, frmMinetestLauncherV.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, progressBar, -10, SpringLayout.SOUTH, frmMinetestLauncherV.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, progressBar, -130, SpringLayout.EAST, frmMinetestLauncherV.getContentPane()); frmMinetestLauncherV.getContentPane().add(progressBar); final JButton btnDownloadPlay = new JButton("Play!"); springLayout.putConstraint(SpringLayout.WEST, btnDownloadPlay, 6, SpringLayout.EAST, progressBar); springLayout.putConstraint(SpringLayout.SOUTH, btnDownloadPlay, 0, SpringLayout.SOUTH, progressBar); springLayout.putConstraint(SpringLayout.EAST, btnDownloadPlay, -10, SpringLayout.EAST, frmMinetestLauncherV.getContentPane()); frmMinetestLauncherV.getContentPane().add(btnDownloadPlay); final JLabel label = new JLabel("Ready to play!"); springLayout.putConstraint(SpringLayout.WEST, label, 10, SpringLayout.WEST, frmMinetestLauncherV.getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, btnDownloadPlay, 0, SpringLayout.NORTH, label); springLayout.putConstraint(SpringLayout.SOUTH, label, -37, SpringLayout.SOUTH, frmMinetestLauncherV.getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, progressBar, 6, SpringLayout.SOUTH, label); frmMinetestLauncherV.getContentPane().add(label); JTextPane txtpnNewFeatures = new JTextPane(); txtpnNewFeatures.setBackground(SystemColor.window); springLayout.putConstraint(SpringLayout.NORTH, txtpnNewFeatures, 10, SpringLayout.NORTH, frmMinetestLauncherV.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, txtpnNewFeatures, 10, SpringLayout.WEST, frmMinetestLauncherV.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, txtpnNewFeatures, -10, SpringLayout.NORTH, btnDownloadPlay); springLayout.putConstraint(SpringLayout.EAST, txtpnNewFeatures, 0, SpringLayout.EAST, btnDownloadPlay); txtpnNewFeatures.setEditable(false); txtpnNewFeatures.setContentType("text/html"); txtpnNewFeatures.setText(changelog); txtpnNewFeatures.setFont(new Font("Tahoma", Font.PLAIN, 12)); frmMinetestLauncherV.getContentPane().add(txtpnNewFeatures); File file = new File(userhome + "\\minetest\\version.txt"); if (!file.exists()) newVersion = true; else { String version = fileGetter.getLocalContents(file, false); if (!version.equals(currentVersion)) newVersion = true; } if (newVersion) { label.setText("New Version Available! (" + currentVersion + ")"); btnDownloadPlay.setText("Download & Play"); btnDownloadPlay.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { Thread t = new Thread() { public void run() { File file = new File(userhome + "\\minetest\\version.txt"); String version = fileGetter.getLocalContents(file, false); try { FileUtils.deleteDirectory(new File(userhome + "\\minetest\\minetest-" + version)); } catch (Exception e) { e.printStackTrace(); } fileGetter.download(latest.split("\n")[1], userhome + "\\minetest\\temp\\", "minetest.zip", label, progressBar, btnDownloadPlay, currentVersion); try { label.setText("Cleaning up..."); btnDownloadPlay.setText("Cleaning up..."); FileUtils.deleteDirectory(new File(userhome + "\\minetest\\temp")); } catch (IOException e) { e.printStackTrace(); } System.exit(0); } }; t.start(); } }); } else { btnDownloadPlay.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { try { label.setText("Launching..."); btnDownloadPlay.setEnabled(false); btnDownloadPlay.setText("Launching..."); File file = new File(userhome + "\\minetest\\version.txt"); String version = fileGetter.getLocalContents(file, false); Runtime.getRuntime() .exec(userhome + "\\minetest\\minetest-" + version + "\\bin\\minetest.exe"); System.exit(0); } catch (IOException e) { e.printStackTrace(); } } }); progressBar.setValue(100); } }
From source file:src.gui.ItTabbedPane.java
public void openPDDLTab(Element diagram, String id, String title, Element project, Element projectHeader, File file) {/*from w w w .jav a 2s. 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.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 w w w. j a v a 2 s.c o m*/ 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:edu.ku.brc.specify.tasks.SystemSetupTask.java
/** * /*from w w w .j a v a 2 s .com*/ */ private void synonymCleanup() { JTextPane tp = new JTextPane(); JScrollPane js = new JScrollPane(); js.getViewport().add(tp); String text = ""; try { String template = "synonym_cleanup_%s.html"; String fileName = String.format(template, Locale.getDefault().getLanguage()); File file = XMLHelper.getConfigDir(fileName); if (!file.exists()) { fileName = String.format(template, "en"); file = XMLHelper.getConfigDir(fileName); } text = FileUtils.readFileToString(file); } catch (Exception ex) { ex.printStackTrace(); } JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); p.add(js, BorderLayout.CENTER); tp.setContentType("text/html"); tp.setText(text); tp.setCaretPosition(0); tp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 18)); CustomDialog dlg = new CustomDialog((Frame) getTopWindow(), getI18nRS("SYN_CLEANUP"), true, CustomDialog.OKCANCELAPPLY, p); dlg.setOkLabel(getI18nRS("SYN_CLEANUP")); dlg.setCancelLabel(getI18nRS("Report")); dlg.setApplyLabel(getResourceString("CANCEL")); dlg.setCloseOnApplyClk(true); dlg.createUI(); dlg.setSize(600, 450); UIHelper.centerAndShow(dlg); if (dlg.getBtnPressed() == CustomDialog.OK_BTN || dlg.getBtnPressed() == CustomDialog.CANCEL_BTN) { boolean doCleanup = dlg.getBtnPressed() == CustomDialog.OK_BTN; SynonymCleanup synonymCleanup = new SynonymCleanup(doCleanup); synonymCleanup.execute(); // start the background task } }