/** Creates the error area component. */ private void initErrorArea() { SimpleAttributeSet attribs = new SimpleAttributeSet(); StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT); StyleConstants.setFontFamily(attribs, errorPane.getFont().getFamily()); StyleConstants.setForeground(attribs, Color.RED); errorPane.setParagraphAttributes(attribs, true); errorPane.setPreferredSize(new Dimension(100, 50)); errorPane.setMinimumSize(new Dimension(100, 50)); errorPane.setOpaque(false); }
public void showItem() { if (!this.editorPanel.getViewer().isLanguageFunctionAvailable()) { return; } this.highlight = this.editorPanel .getEditor() .addHighlight(this.position, this.position + this.word.length(), null, true); final FindSynonymsActionHandler _this = this; QTextEditor editor = this.editorPanel.getEditor(); Rectangle r = null; try { r = editor.modelToView(this.position); } catch (Exception e) { // BadLocationException! Environment.logError("Location: " + this.position + " is not valid", e); UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms."); return; } int y = r.y; // Show a panel of all the items. final QPopup p = this.popup; p.setOpaque(false); Synonyms syns = null; try { syns = this.projectViewer.getSynonymProvider().getSynonyms(this.word); } catch (Exception e) { UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms."); Environment.logError("Unable to lookup synonyms for: " + word, e); return; } if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("ed"))) { // Trim off the ed and try again. try { syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 2)); } catch (Exception e) { UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms."); Environment.logError("Unable to lookup synonyms for: " + word, e); return; } } if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("s"))) { // Trim off the ed and try again. try { syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 1)); } catch (Exception e) { UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms."); Environment.logError("Unable to lookup synonyms for: " + word, e); return; } } StringBuilder sb = new StringBuilder(); if (syns.words.size() > 0) { sb.append("6px"); for (int i = 0; i < syns.words.size(); i++) { if (sb.length() > 0) { sb.append(", "); } sb.append("p, 3px, [p,90px], 5px"); } /* if (syns.words.size () > 0) { sb.append (",5px"); } */ } else { sb.append("6px, p, 6px"); } FormLayout summOnly = new FormLayout("3px, fill:380px:grow, 3px", sb.toString()); PanelBuilder pb = new PanelBuilder(summOnly); CellConstraints cc = new CellConstraints(); int ind = 2; Map<String, String> names = new HashMap(); names.put(Synonyms.ADJECTIVE + "", "Adjectives"); names.put(Synonyms.NOUN + "", "Nouns"); names.put(Synonyms.VERB + "", "Verbs"); names.put(Synonyms.ADVERB + "", "Adverbs"); names.put(Synonyms.OTHER + "", "Other"); if (syns.words.size() == 0) { JLabel l = new JLabel("No synonyms found."); l.setFont(l.getFont().deriveFont(Font.ITALIC)); pb.add(l, cc.xy(2, 2)); } // Determine what type of word we are looking for. for (Synonyms.Part i : syns.words) { JLabel l = new JLabel(names.get(i.type + "")); l.setFont(l.getFont().deriveFont(Font.ITALIC)); l.setFont(l.getFont().deriveFont((float) UIUtils.getEditorFontSize(10))); l.setBorder( new CompoundBorder( new MatteBorder(0, 0, 1, 0, Environment.getBorderColor()), new EmptyBorder(0, 0, 3, 0))); pb.add(l, cc.xy(2, ind)); ind += 2; HTMLEditorKit kit = new HTMLEditorKit(); HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument(); JTextPane t = new JTextPane(doc); t.setEditorKit(kit); t.setEditable(false); t.setOpaque(false); StringBuilder buf = new StringBuilder( "<style>a { text-decoration: none; } a:hover { text-decoration: underline; }</style><span style='color: #000000; font-size: " + ((int) UIUtils.getEditorFontSize(10) /*t.getFont ().getSize () + 2*/) + "pt; font-family: " + t.getFont().getFontName() + ";'>"); for (int x = 0; x < i.words.size(); x++) { String w = (String) i.words.get(x); buf.append("<a class='x' href='http://" + w + "'>" + w + "</a>"); if (x < (i.words.size() - 1)) { buf.append(", "); } } buf.append("</span>"); t.setText(buf.toString()); t.addHyperlinkListener( new HyperlinkAdapter() { public void hyperlinkUpdate(HyperlinkEvent ev) { if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { QTextEditor ed = _this.editorPanel.getEditor(); ed.replaceText( _this.position, _this.position + _this.word.length(), ev.getURL().getHost()); ed.removeHighlight(_this.highlight); _this.popup.setVisible(false); _this.projectViewer.fireProjectEvent( ProjectEvent.SYNONYM, ProjectEvent.REPLACE, ev.getURL().getHost()); } } }); // Annoying that we have to do this but it prevents the text from being too small. t.setSize(new Dimension(380, Short.MAX_VALUE)); JScrollPane sp = new JScrollPane(t); t.setCaretPosition(0); sp.setOpaque(false); sp.getVerticalScrollBar().setValue(0); /* sp.setPreferredSize (t.getPreferredSize ()); sp.setMaximumSize (new Dimension (380, 75)); */ sp.getViewport().setOpaque(false); sp.setOpaque(false); sp.setBorder(null); sp.getViewport().setBackground(Color.WHITE); sp.setAlignmentX(Component.LEFT_ALIGNMENT); pb.add(sp, cc.xy(2, ind)); ind += 2; } JPanel pan = pb.getPanel(); pan.setOpaque(true); pan.setBackground(Color.WHITE); this.popup.setContent(pan); // r.y -= this.editorPanel.getScrollPane ().getVerticalScrollBar ().getValue (); Point po = SwingUtilities.convertPoint(editor, r.x, r.y, this.editorPanel); r.x = po.x; r.y = po.y; // Subtract the insets of the editorPanel. Insets ins = this.editorPanel.getInsets(); r.x -= ins.left; r.y -= ins.top; this.editorPanel.showPopupAt(this.popup, r, "above", true); }
public ChatPane createChatPane(String userName) { JTextPane chatPane = new JTextPane(); chatPane.setEditable(false); Font font = chatPane.getFont(); float size = Main.pref.getInteger("geochat.fontsize", -1); if (size < 6) size += font.getSize2D(); chatPane.setFont(font.deriveFont(size)); // DefaultCaret caret = (DefaultCaret)chatPane.getCaret(); // does not work // caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); JScrollPane scrollPane = new JScrollPane( chatPane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); chatPane.addMouseListener(new GeoChatPopupAdapter(panel)); ChatPane entry = new ChatPane(); entry.pane = chatPane; entry.component = scrollPane; entry.notify = 0; entry.userName = userName; entry.isPublic = userName == null; chatPanes.put(userName == null ? PUBLIC_PANE : userName, entry); tabs.addTab(null, scrollPane); tabs.setTabComponentAt(tabs.getTabCount() - 1, new ChatTabTitleComponent(entry)); tabs.setSelectedComponent(scrollPane); return entry; }
public TextFilterWorker( File file, JProgressBar progress, JTextPane _textForOpen, JTextPane _textForClose, JButton _okButton, File outputFile) { _videoFile = file; _bar = progress; _openTextFont = _textForOpen.getFont(); _openTextColour = _textForOpen.getForeground(); _openText = _textForOpen.getText(); _closeTextFont = _textForClose.getFont(); _closeTextColour = _textForClose.getForeground(); _closeText = _textForClose.getText(); _button = _okButton; _outputFile = outputFile; }
/** Creates the text area. */ private void initTextArea() { textArea.setOpaque(false); textArea.setEditable(false); StyledDocument doc = textArea.getStyledDocument(); MutableAttributeSet standard = new SimpleAttributeSet(); StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER); StyleConstants.setFontFamily(standard, textArea.getFont().getFamily()); StyleConstants.setFontSize(standard, 12); doc.setParagraphAttributes(0, 0, standard, true); parentWindow.addSearchFieldListener(this); }
/** * Sets the reason of a call failure if one occurs. The renderer should display this reason to the * user. * * @param reason the reason to display */ public void setErrorReason(final String reason) { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater( new Runnable() { public void run() { setErrorReason(reason); } }); return; } if (errorMessageComponent == null) { errorMessageComponent = new JTextPane(); JTextPane textPane = (JTextPane) errorMessageComponent; textPane.setEditable(false); textPane.setOpaque(false); StyledDocument doc = textPane.getStyledDocument(); MutableAttributeSet standard = new SimpleAttributeSet(); StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER); StyleConstants.setFontFamily(standard, textPane.getFont().getFamily()); StyleConstants.setFontSize(standard, 12); doc.setParagraphAttributes(0, 0, standard, true); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 4; constraints.weightx = 1; constraints.weighty = 0; constraints.insets = new Insets(5, 0, 0, 0); add(errorMessageComponent, constraints); this.revalidate(); } errorMessageComponent.setText(reason); if (isVisible()) errorMessageComponent.repaint(); }
public ANOVAMatrixViewer(ANOVAMatrix matrix) { super(new BorderLayout()); JPanel infoPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // info string JTextPane infoText = new JTextPane(); infoText.setEditable(false); infoText.setBackground(infoPanel.getBackground()); infoText.setFont(infoText.getFont().deriveFont(Font.BOLD)); infoText.setText( "A dark background indicates that the probability for non-difference between the groups is less than " + Tools.formatNumber(matrix.getSignificanceLevel())); infoPanel.add(infoText); infoPanel.setBorder(BorderFactory.createEtchedBorder()); add(infoPanel, BorderLayout.NORTH); // table ANOVAMatrixViewerTable table = new ANOVAMatrixViewerTable(matrix); table.setBorder(BorderFactory.createEtchedBorder()); add(new ExtendedJScrollPane(table), BorderLayout.CENTER); }
/** * Lays out the widgets and positions the window in the middle of the screen. * * @param logo The Frame's background logo. * @param version The version of the software. * @param serverAvailable Pass <code>true</code> if the client needs to connect to a server, * <code>false</code> otherwise. */ private void buildGUI(Icon logo, String version, boolean serverAvailable) { JLabel splash = new JLabel(logo); layers = new JLayeredPane(); layers.add(splash, Integer.valueOf(0)); getContentPane().add(layers); int width = logo.getIconWidth(); int height = logo.getIconHeight(); layers.setBounds(0, 0, width, height); splash.setBounds(0, 0, width, height); int h = progressBar.getFontMetrics(progressBar.getFont()).getHeight(); int top = 120; int bottom = 100; currentTask.setBounds(TEXT_INDENT, top, width - 2 * TEXT_INDENT, h); top += 20; progressBar.setBounds(TEXT_INDENT, top, width - 2 * TEXT_INDENT, h); addToLayer(currentTask); addToLayer(progressBar); mainPanel = new JPanel(); mainPanel.setOpaque(false); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); Font f; versionInfo = UIUtilities.buildTextPane(version, FOOT_NOTE_COLOR); f = versionInfo.getFont(); versionInfo.setFont(f.deriveFont(VERSION_FONT_STYLE, f.getSize() - 4)); versionInfo.setOpaque(false); // Add login details. int y = height - bottom - 10; y = top + 2 * h; buildLogin(); displayComponents(serverAvailable); mainPanel.add(UIUtilities.buildComponentPanelCenter(versionInfo, 0, 0, false)); mainPanel.setBounds(0, y, width, height - top - bottom); addToLayer(mainPanel); }
/** * constructor * * @param controller is the parent object * @throws Exception */ public PseudoHYDC3View(PseudoHYDC3 controller) throws Exception { this.controller = controller; { String sFontName = "DFKai-SB2" /*"PMingLiU"*/; if (System.getProperty("hydc3.fontName") != null) { sFontName = System.getProperty("hydc3.fontName"); } UIManager.put( "TextPane.font", new Font( sFontName, UIManager.getFont("TextPane.font").getStyle(), UIManager.getFont("TextPane.font").getSize())); UIManager.put( "List.font", new Font( sFontName, UIManager.getFont("List.font").getStyle(), UIManager.getFont("List.font").getSize())); UIManager.put( "TextField.font", new Font( sFontName, UIManager.getFont("TextField.font").getStyle(), UIManager.getFont("TextField.font").getSize())); } frame = new JFrame("漢語大詞典もどき"); frame.setPreferredSize(new Dimension(800, 600)); { JMenuBar menuBar = new JMenuBar(); { JMenu menu = new JMenu("File"); { JMenuItem menuItem = new JMenuItem("Exit"); menuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { System.exit(0); } }); menu.add(menuItem); } menuBar.add(menu); } { JMenu menu = new JMenu("Help"); { JMenuItem menuItem = new JMenuItem("About..."); menuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog( frame, "漢語大詞典もどき version 0.1 by Beu", "about", JOptionPane.INFORMATION_MESSAGE); } }); menu.add(menuItem); } menuBar.add(menu); } frame.setJMenuBar(menuBar); JPanel rootPanel = new JPanel(new BorderLayout()); { JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); { JSplitPane splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT); { JTabbedPane tabbedPane = new JTabbedPane(); { JPanel panel = new JPanel(); BoxLayout layout = new BoxLayout(panel, BoxLayout.Y_AXIS); panel.setLayout(layout); { JPanel panel2 = new JPanel(); { inputTextField = new JTextField(8); Font font = inputTextField.getFont(); font = font.deriveFont(font.getSize2D() * 3); inputTextField.setFont(font); panel2.add(inputTextField); } panel.add(panel2); } { JPanel panel2 = new JPanel(); { JButton button = new JButton("字"); button.setActionCommand("searchWithCharacter"); button.addActionListener(controller); panel2.add(button); } { JButton button = new JButton("詞"); button.setActionCommand("searchWithWord"); button.addActionListener(controller); panel2.add(button); } { JButton button = new JButton("音"); button.setActionCommand("searchWithReading"); button.addActionListener(controller); panel2.add(button); } { JButton button = new JButton("碼"); button.setActionCommand("searchWithCode"); button.addActionListener(controller); panel2.add(button); } panel.add(panel2); } tabbedPane.addTab("輸入", panel); } { DefaultMutableTreeNode root = controller.getRadicalTree(); JTree tree = new JTree(root); Font font = tree.getFont(); font = font.deriveFont(font.getSize2D() * 1.5F); tree.setFont(font); tree.addTreeSelectionListener(controller); JScrollPane scrollPane = new JScrollPane( tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); tabbedPane.addTab("部首", scrollPane); } { JPanel panel = new JPanel(); BoxLayout layout = new BoxLayout(panel, BoxLayout.Y_AXIS); panel.setLayout(layout); { JPanel panel2 = new JPanel(); panel2.add(new JLabel("從")); { fromStrokesTextField = new JTextField("1", 2); Font font = fromStrokesTextField.getFont(); font = font.deriveFont(font.getSize2D() * 2); fromStrokesTextField.setFont(font); fromStrokesTextField.setHorizontalAlignment(JTextField.RIGHT); panel2.add(fromStrokesTextField); } panel2.add(new JLabel("到")); { toStrokesTextField = new JTextField("10", 2); Font font = toStrokesTextField.getFont(); font = font.deriveFont(font.getSize2D() * 2); toStrokesTextField.setFont(font); toStrokesTextField.setHorizontalAlignment(JTextField.RIGHT); panel2.add(toStrokesTextField); } panel.add(panel2); } { JPanel panel2 = new JPanel(); { JButton button = new JButton("査"); button.setActionCommand("searchWithStrokes"); button.addActionListener(controller); panel2.add(button); } panel.add(panel2); } tabbedPane.addTab("畫數", panel); } splitPane2.add(tabbedPane, JSplitPane.TOP); } { selectingList = new JList(); Font font = selectingList.getFont(); font = font.deriveFont(font.getSize2D() * 2); selectingList.setFont(font); selectingList.addMouseListener(controller); JScrollPane scrollPane = new JScrollPane( selectingList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setBorder(new TitledBorder("候補")); splitPane2.add(scrollPane, JSplitPane.BOTTOM); } splitPane.add(splitPane2, JSplitPane.LEFT); } { descriptionTextPane = new JTextPane(); Font font = descriptionTextPane.getFont(); font = font.deriveFont(font.getSize2D() * 1.5F); descriptionTextPane.setFont(font); descriptionTextPane.addMouseListener(controller); descriptionTextPane.addMouseMotionListener(controller); JScrollPane scrollPane = new JScrollPane( descriptionTextPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); splitPane.add(scrollPane, JSplitPane.RIGHT); } rootPanel.add(splitPane, BorderLayout.CENTER); } { JPanel panel = new JPanel(new BorderLayout()); { JLabel label = new JLabel("status"); panel.add(label, BorderLayout.WEST); } rootPanel.add(panel, BorderLayout.SOUTH); } frame.setContentPane(rootPanel); } frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
void setFontSize(float size) { Font font = textArea.getFont().deriveFont(size); textArea.setFont(font); }
/* * windowSetup(){...} * This is the window setup method. This window * is designed for admins to keep track of their * players and perform admin commands. */ public static void windowSetup() { scroller.setWheelScrollingEnabled(true); scroller.add(new JScrollBar()); scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Close the server then exit the program. frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { try { server.close(); System.exit(1); } catch (IOException ex) { System.exit(1); } } }); frame.setResizable(false); frame.setBounds(0, 0, 559, 291); frame.add(console, BorderLayout.SOUTH); frame.add(scroller, BorderLayout.CENTER); frame.setVisible(true); tPane.setEditable(false); tPane.setBackground(Color.BLACK); font = tPane.getFont(); tPane.setFont(font.deriveFont(Font.BOLD)); // Background color. console.setBackground(Color.BLACK); // Text color. console.setForeground(Color.WHITE); // All legal direction names. movable.add("NORTH"); movable.add("EAST"); movable.add("SOUTH"); movable.add("WEST"); movable.add("UP"); movable.add("DOWN"); // movable.add("NORT"); movable.add("EAS"); movable.add("SOUT"); movable.add("WES"); movable.add(""); movable.add("DOW"); // movable.add("NOR"); movable.add("EA"); movable.add("SOU"); movable.add("WE"); movable.add(""); movable.add("DO"); // movable.add("NO"); movable.add(""); movable.add("SO"); movable.add(""); movable.add(""); movable.add(""); // movable.add("N"); movable.add("E"); movable.add("S"); movable.add("W"); movable.add("U"); movable.add("D"); }