List of usage examples for javax.swing JTextPane JTextPane
public JTextPane()
JTextPane
. From source file:com.mirth.connect.client.ui.dependencies.ChannelDependenciesWarningDialog.java
private void initComponents(final ChannelTask task, Set<ChannelDependency> dependencies, final Set<String> selectedChannelIds, Set<String> additionalChannelIds) throws ChannelDependencyException { additionalChannelIds.removeAll(selectedChannelIds); final OrderedChannels orderedChannels = ChannelDependencyUtil.getOrderedChannels(dependencies, new HashSet<String>(CollectionUtils.union(selectedChannelIds, additionalChannelIds))); final List<Set<String>> orderedChannelIds = orderedChannels.getOrderedIds(); if (task.isForwardOrder()) { Collections.reverse(orderedChannelIds); }/* ww w .j a va2 s . c om*/ descriptionLabel = new JLabel( "<html>There are additional channels in the dependency chain.<br/><b>Bolded</b> channels will be " + task.getFuturePassive() + " in the following order:</html>"); channelsPane = new JTextPane(); channelsPane.setContentType("text/html"); HTMLEditorKit editorKit = new HTMLEditorKit(); StyleSheet styleSheet = editorKit.getStyleSheet(); styleSheet.addRule("div {font-family:\"Tahoma\";font-size:11;text-align:top}"); channelsPane.setEditorKit(editorKit); channelsPane.setEditable(false); channelsPane.setBackground(getBackground()); setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds, false); descriptionScrollPane = new JScrollPane(channelsPane); includeCheckBox = new JCheckBox(WordUtils.capitalize(task.toString()) + " " + additionalChannelIds.size() + " additional channel" + (additionalChannelIds.size() == 1 ? "" : "s")); includeCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds, includeCheckBox.isSelected()); } }); okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { result = JOptionPane.OK_OPTION; dispose(); } }); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { result = JOptionPane.CANCEL_OPTION; dispose(); } }); }
From source file:TextComponentDemo.java
public TextComponentDemo() { super("TextComponentDemo"); // Create the text pane and configure it. textPane = new JTextPane(); textPane.setCaretPosition(0);// w ww. jav a 2 s . c om textPane.setMargin(new Insets(5, 5, 5, 5)); StyledDocument styledDoc = textPane.getStyledDocument(); if (styledDoc instanceof AbstractDocument) { doc = (AbstractDocument) styledDoc; //doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS)); } else { System.err.println("Text pane's document isn't an AbstractDocument!"); System.exit(-1); } JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(200, 200)); // Create the text area for the status log and configure it. changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); // Create a split pane for the change log and the text area. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); // Create the status area. JPanel statusPane = new JPanel(new GridLayout(1, 1)); CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status"); statusPane.add(caretListenerLabel); // Add the components. getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); // Set up the menu bar. createActionTable(textPane); JMenu editMenu = createEditMenu(); JMenu styleMenu = createStyleMenu(); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); // Add some key bindings. addBindings(); // Put the initial text into the text pane. initDocument(); // Start watching for undoable edits and caret changes. doc.addUndoableEditListener(new MyUndoableEditListener()); textPane.addCaretListener(caretListenerLabel); doc.addDocumentListener(new MyDocumentListener()); }
From source file:TextComponentDemo.java
public TextComponentDemo() { super("TextComponentDemo"); // Create the text pane and configure it. textPane = new JTextPane(); textPane.setCaretPosition(0);/*ww w.jav a 2s . c o m*/ textPane.setMargin(new Insets(5, 5, 5, 5)); StyledDocument styledDoc = textPane.getStyledDocument(); if (styledDoc instanceof AbstractDocument) { doc = (AbstractDocument) styledDoc; doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS)); } else { System.err.println("Text pane's document isn't an AbstractDocument!"); System.exit(-1); } JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(200, 200)); // Create the text area for the status log and configure it. changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); // Create a split pane for the change log and the text area. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); // Create the status area. JPanel statusPane = new JPanel(new GridLayout(1, 1)); CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status"); statusPane.add(caretListenerLabel); // Add the components. getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); // Set up the menu bar. actions = createActionTable(textPane); JMenu editMenu = createEditMenu(); JMenu styleMenu = createStyleMenu(); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); // Add some key bindings. addBindings(); // Put the initial text into the text pane. initDocument(); textPane.setCaretPosition(0); // Start watching for undoable edits and caret changes. doc.addUndoableEditListener(new MyUndoableEditListener()); textPane.addCaretListener(caretListenerLabel); doc.addDocumentListener(new MyDocumentListener()); }
From source file:org.freeinternals.javaclassviewer.ui.JSplitPaneClassFile.java
private void createAndShowGUI(JFrame top) { // Construct class file viewer final JTreeClassFile jTreeClassFile = new JTreeClassFile(this.classFile); jTreeClassFile.addTreeSelectionListener(new TreeSelectionListener() { @Override// www . j av a 2s . c o m public void valueChanged(final javax.swing.event.TreeSelectionEvent evt) { jTreeClassFileSelectionChanged(evt); } }); final JPanelForTree panel = new JPanelForTree(jTreeClassFile, top); final JTabbedPane tabbedPane = new JTabbedPane(); // Construct binary viewer this.binaryViewer = new JBinaryViewer(); this.binaryViewer.setData(this.classFile.getClassByteArray()); this.binaryViewerView = new JScrollPane(this.binaryViewer); this.binaryViewerView.getVerticalScrollBar().setValue(0); tabbedPane.add("Class File", this.binaryViewerView); // Construct opcode viewer this.opcode = new JTextPane(); this.opcode.setAlignmentX(Component.LEFT_ALIGNMENT); // this.opcode.setFont(new Font(Font.DIALOG_INPUT, Font.PLAIN, 14)); this.opcode.setEditable(false); this.opcode.setBorder(null); this.opcode.setContentType("text/html"); tabbedPane.add("Opcode", new JScrollPane(this.opcode)); // Class report this.report = new JTextPane(); this.report.setAlignmentX(Component.LEFT_ALIGNMENT); this.report.setEditable(false); this.report.setBorder(null); this.report.setContentType("text/html"); tabbedPane.add("Report", new JScrollPane(this.report)); this.setOrientation(JSplitPane.HORIZONTAL_SPLIT); this.setDividerSize(5); this.setDividerLocation(280); this.setLeftComponent(panel); this.setRightComponent(tabbedPane); this.binaryViewerView.getVerticalScrollBar().setValue(0); }
From source file:com.mindcognition.mindraider.ui.swing.concept.annotation.renderer.AbstractTextAnnotationRenderer.java
protected void init(AnnotationToHtmlTransformer editorToViewerTransfomer, KeyListener editorKeyListener, KeyListener viewerKeyListener, FocusListener editorFocusListener, FocusListener viewerFocusListener, MouseListener editorMouseListener, MouseListener viewerMouseListener, TextAnnotationToolbar toolbar) { this.editorToViewerTransfomer = editorToViewerTransfomer; this.toolbar = toolbar; setLayout(new BorderLayout()); JPanel editorViewerPanel = new JPanel(); editorViewerPanel.setLayout(new BoxLayout(editorViewerPanel, BoxLayout.Y_AXIS)); // editor/*from w ww .j ava 2s . c om*/ editor = new JTextArea(30, 100); configureEditor(editor); editor.addKeyListener(editorKeyListener); editor.addFocusListener(editorFocusListener); editor.addMouseListener(editorMouseListener); // TODO bundle editorScroll = encapsulateToScroll(editor, " Editor "); editorViewerPanel.add(editorScroll); editorScroll.setVisible(false); // view viewer = new JTextPane(); configureViewer(viewer); viewer.addKeyListener(viewerKeyListener); viewer.addFocusListener(viewerFocusListener); viewer.addMouseListener(viewerMouseListener); // TODO bundle viewerScroll = encapsulateToScroll(viewer, " Viewer "); editorViewerPanel.add(viewerScroll); add(editorViewerPanel, BorderLayout.CENTER); // toolbar if (toolbar != null) { add(toolbar, BorderLayout.SOUTH); } // let the container to redraw its content (hide/show) validate(); }
From source file:TextComponentDemo.java
public TextComponentDemo() { super("TextComponentDemo"); //Create the text pane and configure it. textPane = new JTextPane(); textPane.setCaretPosition(0);//from w ww .j a v a 2 s. c om textPane.setMargin(new Insets(5, 5, 5, 5)); StyledDocument styledDoc = textPane.getStyledDocument(); if (styledDoc instanceof AbstractDocument) { doc = (AbstractDocument) styledDoc; doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS)); } else { System.err.println("Text pane's document isn't an AbstractDocument!"); System.exit(-1); } JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(200, 200)); //Create the text area for the status log and configure it. changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); //Create a split pane for the change log and the text area. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); //Create the status area. JPanel statusPane = new JPanel(new GridLayout(1, 1)); CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status"); statusPane.add(caretListenerLabel); //Add the components. getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); //Set up the menu bar. createActionTable(textPane); JMenu editMenu = createEditMenu(); JMenu styleMenu = createStyleMenu(); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); //Add some key bindings. addBindings(); //Put the initial text into the text pane. initDocument(); //Start watching for undoable edits and caret changes. doc.addUndoableEditListener(new MyUndoableEditListener()); textPane.addCaretListener(caretListenerLabel); doc.addDocumentListener(new MyDocumentListener()); }
From source file:juicebox.windowui.QCDialog.java
public QCDialog(MainWindow mainWindow, HiC hic, String title) { super(mainWindow); Dataset dataset = hic.getDataset();/* w w w. j av a 2 s . c o m*/ String text = dataset.getStatistics(); String textDescription = null; String textStatistics = null; String graphs = dataset.getGraphs(); JTextPane description = null; JTabbedPane tabbedPane = new JTabbedPane(); HTMLEditorKit kit = new HTMLEditorKit(); StyleSheet styleSheet = kit.getStyleSheet(); styleSheet.addRule("table { border-collapse: collapse;}"); styleSheet.addRule("body {font-family: Sans-Serif; font-size: 12;}"); styleSheet.addRule("td { padding: 2px; }"); styleSheet.addRule( "th {border-bottom: 1px solid #000; text-align: left; background-color: #D8D8D8; font-weight: normal;}"); if (text != null) { int split = text.indexOf("</table>") + 8; textDescription = text.substring(0, split); textStatistics = text.substring(split); description = new JTextPane(); description.setEditable(false); description.setContentType("text/html"); description.setEditorKit(kit); description.setText(textDescription); tabbedPane.addTab("About Library", description); JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setContentType("text/html"); textPane.setEditorKit(kit); textPane.setText(textStatistics); JScrollPane pane = new JScrollPane(textPane); tabbedPane.addTab("Statistics", pane); } boolean success = true; if (graphs != null) { long[] A = new long[2000]; long sumA = 0; long[] mapq1 = new long[201]; long[] mapq2 = new long[201]; long[] mapq3 = new long[201]; long[] intraCount = new long[100]; final XYSeries intra = new XYSeries("Intra Count"); final XYSeries leftRead = new XYSeries("Left"); final XYSeries rightRead = new XYSeries("Right"); final XYSeries innerRead = new XYSeries("Inner"); final XYSeries outerRead = new XYSeries("Outer"); final XYSeries allMapq = new XYSeries("All MapQ"); final XYSeries intraMapq = new XYSeries("Intra MapQ"); final XYSeries interMapq = new XYSeries("Inter MapQ"); Scanner scanner = new Scanner(graphs); try { while (!scanner.next().equals("[")) ; for (int idx = 0; idx < 2000; idx++) { A[idx] = scanner.nextLong(); sumA += A[idx]; } while (!scanner.next().equals("[")) ; for (int idx = 0; idx < 201; idx++) { mapq1[idx] = scanner.nextInt(); mapq2[idx] = scanner.nextInt(); mapq3[idx] = scanner.nextInt(); } for (int idx = 199; idx >= 0; idx--) { mapq1[idx] = mapq1[idx] + mapq1[idx + 1]; mapq2[idx] = mapq2[idx] + mapq2[idx + 1]; mapq3[idx] = mapq3[idx] + mapq3[idx + 1]; allMapq.add(idx, mapq1[idx]); intraMapq.add(idx, mapq2[idx]); interMapq.add(idx, mapq3[idx]); } while (!scanner.next().equals("[")) ; for (int idx = 0; idx < 100; idx++) { int tmp = scanner.nextInt(); if (tmp != 0) innerRead.add(logXAxis[idx], tmp); intraCount[idx] = tmp; tmp = scanner.nextInt(); if (tmp != 0) outerRead.add(logXAxis[idx], tmp); intraCount[idx] += tmp; tmp = scanner.nextInt(); if (tmp != 0) rightRead.add(logXAxis[idx], tmp); intraCount[idx] += tmp; tmp = scanner.nextInt(); if (tmp != 0) leftRead.add(logXAxis[idx], tmp); intraCount[idx] += tmp; if (idx > 0) intraCount[idx] += intraCount[idx - 1]; if (intraCount[idx] != 0) intra.add(logXAxis[idx], intraCount[idx]); } } catch (NoSuchElementException exception) { JOptionPane.showMessageDialog(getParent(), "Graphing file improperly formatted", "Error", JOptionPane.ERROR_MESSAGE); success = false; } if (success) { final XYSeriesCollection readTypeCollection = new XYSeriesCollection(); readTypeCollection.addSeries(innerRead); readTypeCollection.addSeries(outerRead); readTypeCollection.addSeries(leftRead); readTypeCollection.addSeries(rightRead); final JFreeChart readTypeChart = ChartFactory.createXYLineChart("Types of reads vs distance", // chart title "Distance (log)", // domain axis label "Binned Reads (log)", // range axis label readTypeCollection, // data PlotOrientation.VERTICAL, true, // include legend true, false); final XYPlot readTypePlot = readTypeChart.getXYPlot(); readTypePlot.setDomainAxis(new LogarithmicAxis("Distance (log)")); readTypePlot.setRangeAxis(new LogarithmicAxis("Binned Reads (log)")); readTypePlot.setBackgroundPaint(Color.white); readTypePlot.setRangeGridlinePaint(Color.lightGray); readTypePlot.setDomainGridlinePaint(Color.lightGray); readTypeChart.setBackgroundPaint(Color.white); readTypePlot.setOutlinePaint(Color.black); final ChartPanel chartPanel = new ChartPanel(readTypeChart); final XYSeriesCollection reCollection = new XYSeriesCollection(); final XYSeries reDistance = new XYSeries("Distance"); for (int i = 0; i < A.length; i++) { if (A[i] != 0) reDistance.add(i, A[i] / (float) sumA); } reCollection.addSeries(reDistance); final JFreeChart reChart = ChartFactory.createXYLineChart( "Distance from closest restriction enzyme site", // chart title "Distance (bp)", // domain axis label "Fraction of Reads (log)", // range axis label reCollection, // data PlotOrientation.VERTICAL, true, // include legend true, false); final XYPlot rePlot = reChart.getXYPlot(); rePlot.setDomainAxis(new NumberAxis("Distance (bp)")); rePlot.setRangeAxis(new LogarithmicAxis("Fraction of Reads (log)")); rePlot.setBackgroundPaint(Color.white); rePlot.setRangeGridlinePaint(Color.lightGray); rePlot.setDomainGridlinePaint(Color.lightGray); reChart.setBackgroundPaint(Color.white); rePlot.setOutlinePaint(Color.black); final ChartPanel chartPanel2 = new ChartPanel(reChart); final XYSeriesCollection intraCollection = new XYSeriesCollection(); intraCollection.addSeries(intra); final JFreeChart intraChart = ChartFactory.createXYLineChart("Intra reads vs distance", // chart title "Distance (log)", // domain axis label "Cumulative Sum of Binned Reads (log)", // range axis label intraCollection, // data PlotOrientation.VERTICAL, true, // include legend true, false); final XYPlot intraPlot = intraChart.getXYPlot(); intraPlot.setDomainAxis(new LogarithmicAxis("Distance (log)")); intraPlot.setRangeAxis(new NumberAxis("Cumulative Sum of Binned Reads (log)")); intraPlot.setBackgroundPaint(Color.white); intraPlot.setRangeGridlinePaint(Color.lightGray); intraPlot.setDomainGridlinePaint(Color.lightGray); intraChart.setBackgroundPaint(Color.white); intraPlot.setOutlinePaint(Color.black); final ChartPanel chartPanel3 = new ChartPanel(intraChart); final XYSeriesCollection mapqCollection = new XYSeriesCollection(); mapqCollection.addSeries(allMapq); mapqCollection.addSeries(intraMapq); mapqCollection.addSeries(interMapq); final JFreeChart mapqChart = ChartFactory.createXYLineChart("MapQ Threshold Count", // chart title "MapQ threshold", // domain axis label "Count", // range axis label mapqCollection, // data PlotOrientation.VERTICAL, true, // include legend true, // include tooltips false); final XYPlot mapqPlot = mapqChart.getXYPlot(); mapqPlot.setBackgroundPaint(Color.white); mapqPlot.setRangeGridlinePaint(Color.lightGray); mapqPlot.setDomainGridlinePaint(Color.lightGray); mapqChart.setBackgroundPaint(Color.white); mapqPlot.setOutlinePaint(Color.black); final ChartPanel chartPanel4 = new ChartPanel(mapqChart); tabbedPane.addTab("Pair Type", chartPanel); tabbedPane.addTab("Restriction", chartPanel2); tabbedPane.addTab("Intra vs Distance", chartPanel3); tabbedPane.addTab("MapQ", chartPanel4); } } final ExpectedValueFunction df = hic.getDataset().getExpectedValues(hic.getZoom(), hic.getNormalizationType()); if (df != null) { double[] expected = df.getExpectedValues(); final XYSeriesCollection collection = new XYSeriesCollection(); final XYSeries expectedValues = new XYSeries("Expected"); for (int i = 0; i < expected.length; i++) { if (expected[i] > 0) expectedValues.add(i + 1, expected[i]); } collection.addSeries(expectedValues); String title1 = "Expected at " + hic.getZoom() + " norm " + hic.getNormalizationType(); final JFreeChart readTypeChart = ChartFactory.createXYLineChart(title1, // chart title "Distance between reads (log)", // domain axis label "Genome-wide expected (log)", // range axis label collection, // data PlotOrientation.VERTICAL, false, // include legend true, false); final XYPlot readTypePlot = readTypeChart.getXYPlot(); readTypePlot.setDomainAxis(new LogarithmicAxis("Distance between reads (log)")); readTypePlot.setRangeAxis(new LogarithmicAxis("Genome-wide expected (log)")); readTypePlot.setBackgroundPaint(Color.white); readTypePlot.setRangeGridlinePaint(Color.lightGray); readTypePlot.setDomainGridlinePaint(Color.lightGray); readTypeChart.setBackgroundPaint(Color.white); readTypePlot.setOutlinePaint(Color.black); final ChartPanel chartPanel5 = new ChartPanel(readTypeChart); tabbedPane.addTab("Expected", chartPanel5); } if (text == null && graphs == null) { JOptionPane.showMessageDialog(this, "Sorry, no metrics are available for this dataset", "Error", JOptionPane.ERROR_MESSAGE); setVisible(false); dispose(); } else { getContentPane().add(tabbedPane); pack(); setModal(false); setLocation(100, 100); setTitle(title); setVisible(true); } }
From source file:com.hp.alm.ali.idea.content.taskboard.BacklogItemPanel.java
public BacklogItemPanel(Project project, Entity item, TaskBoardFilter filter) { super(new BorderLayout()); this.project = project; this.item = item; this.filter = filter; entityLabelService = project.getComponent(EntityLabelService.class); entityService = project.getComponent(EntityService.class); activeItemService = project.getComponent(ActiveItemService.class); taskBoardConfiguration = project.getComponent(TaskBoardConfiguration.class); taskBoardFlow = project.getComponent(TaskBoardFlow.class); aliProjectConfiguration = project.getComponent(AliProjectConfiguration.class); header = new Header(); header.setBorder(new EmptyBorder(0, 5, 0, 5)); add(header, BorderLayout.NORTH); entityName = new JTextPane(); entityName.setBackground(getBackground()); entityName.setEditable(false);/*from w w w . jav a2s . c o m*/ add(entityName, BorderLayout.CENTER); content = new Content(); content.setBorder(new EmptyBorder(0, 5, 10, 5)); add(content, BorderLayout.SOUTH); tasks = new HashMap<Integer, TaskPanel>(); taskContainers = new HashMap<String, TaskContainerPanel>(); taskContainers.put(TaskPanel.TASK_NEW, new TaskContainerPanel(this, TaskPanel.TASK_NEW, item)); taskContainers.put(TaskPanel.TASK_IN_PROGRESS, new TaskContainerPanel(this, TaskPanel.TASK_IN_PROGRESS, item)); taskContainers.put(TaskPanel.TASK_COMPLETED, new TaskContainerPanel(this, TaskPanel.TASK_COMPLETED, item)); taskContent = new JPanel(new GridLayout(1, 3)); taskContent.add(getTaskContainer(TaskPanel.TASK_NEW)); taskContent.add(getTaskContainer(TaskPanel.TASK_IN_PROGRESS)); taskContent.add(getTaskContainer(TaskPanel.TASK_COMPLETED)); Color gridColor = UIManager.getDefaults().getColor("Table.gridColor"); taskContent.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 0, gridColor)); setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, gridColor)); // we don't use gap in grid layout to avoid trailing line (on the right) getTaskContainer(TaskPanel.TASK_IN_PROGRESS) .setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, gridColor)); getTaskContainer(TaskPanel.TASK_COMPLETED) .setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, gridColor)); simpleHighlight = new SimpleHighlight(entityName); setPreferredSize(DIMENSION); update(item); }
From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatSinglePanel.java
protected void buildUI() { CellConstraints cc = new CellConstraints(); JLabel currentFieldsLbl = createI18NLabel("DOF_DISPLAY_FORMAT"); formatEditor = new JTextPane(); // to make sure the component shrinks with the dialog formatEditor.setMinimumSize(new Dimension(200, 50)); formatEditor.setPreferredSize(new Dimension(350, 100)); formatEditor.getDocument().addDocumentListener(new DocumentAdaptor() { @Override/*from ww w . ja v a2 s . c om*/ public void changed(DocumentEvent e) { updateUIEnabled(); } }); PanelBuilder addFieldPB = new PanelBuilder(new FormLayout("p,2px,p,f:p:g,r:m", "p,2px,p")); sepText = createTextField(4); addFieldBtn = createButton(getResourceString("DOF_ADD_FIELD")); sepLbl = createI18NFormLabel("DOF_SEP_TXT"); addFieldPB.add(sepLbl, cc.xy(1, 1)); addFieldPB.add(sepText, cc.xy(3, 1)); addFieldPB.add(addFieldBtn, cc.xy(5, 1)); sepText.setDocument(new FilteredDoc()); addFieldBtn.setEnabled(false); sepLbl.setEnabled(false); sepText.setEnabled(false); // For when it is standalone if (AppPreferences.hasRemotePrefs()) { sepText.setText(AppPreferences.getRemote().get("DOF_SEP", ", ")); } else { sepText.setText(", "); } PanelBuilder pb = new PanelBuilder(new FormLayout("f:d:g", "10px," + // empty space on top of panel "p,f:p:g," + // Label & format text editor "2px,p," + // separator & add field "10px,p," + // separator & label "f:250px:g," // list box for available fields ), this); // layout components on main panel int y = 2; // leave first row blank pb.add(currentFieldsLbl, cc.xy(1, y)); y += 1; pb.add(UIHelper.createScrollPane(formatEditor), cc.xy(1, y)); y += 2; pb.add(addFieldPB.getPanel(), cc.xy(1, y)); y += 2; JLabel availableFieldsLbl = createI18NFormLabel("DOF_AVAILABLE_FIELDS", SwingConstants.LEFT); pb.add(availableFieldsLbl, cc.xy(1, y)); y += 1; // create field tree that will be re-used in all instances of single switch formatter editing panel availableFieldsComp = new AvailableFieldsComponent(tableInfo, dataObjFieldFormatMgrCache, uiFieldFormatterMgrCache); pb.add(UIHelper.createScrollPane(availableFieldsComp.getTree()), cc.xy(1, y)); y += 2; availableFieldsComp.getTree().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { boolean enable = availableFieldsComp.getTree().getSelectionCount() > 0; addFieldBtn.setEnabled(enable); sepText.setEnabled(enable); sepLbl.setEnabled(enable); } }); this.mainPanelBuilder = pb; fillWithObjFormatter(formatContainer.getSelectedFormatter()); addFormatTextListeners(); // must be called after list of available fields has been created addFieldListeners(); }
From source file:de.ailis.xadrian.components.ComplexEditor.java
/** * Constructor/*from w w w . jav a 2s. c o m*/ * * @param complex * The complex to edit * @param file * The file from which the complex was loaded. Null if it not * loaded from a file. */ public ComplexEditor(final Complex complex, final File file) { super(); setLayout(new BorderLayout()); this.complex = complex; this.file = file; // Create the text pane this.textPane = new JTextPane(); this.textPane.setEditable(false); this.textPane.setBorder(null); this.textPane.setContentType("text/html"); this.textPane.setDoubleBuffered(true); this.textPane.addHyperlinkListener(this); this.textPane.addCaretListener(this); // Create the popup menu for the text pane final JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new CopyAction(this)); popupMenu.add(new SelectAllAction(this)); popupMenu.addSeparator(); popupMenu.add(new AddFactoryAction(this)); popupMenu.add(new ChangeSectorAction(this.complex, this, "complex")); popupMenu.add(new ChangeSunsAction(this)); popupMenu.add(new ChangePricesAction(this)); popupMenu.add(new JCheckBoxMenuItem(new ToggleBaseComplexAction(this))); SwingUtils.setPopupMenu(this.textPane, popupMenu); final HTMLDocument document = (HTMLDocument) this.textPane.getDocument(); // Set the base URL of the text pane document.setBase(Main.class.getResource("templates/")); // Modify the body style so it matches the system font final Font font = UIManager.getFont("Label.font"); final String bodyRule = "body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt; }"; document.getStyleSheet().addRule(bodyRule); // Create the scroll pane final JScrollPane scrollPane = new JScrollPane(this.textPane); add(scrollPane); // Redraw the content redraw(); fireComplexState(); }