// {{{ parseHighlightStyle() SyntaxStyle parseHighlightStyle(String style) { Font f = (resultTree != null) ? resultTree.getFont() : UIManager.getFont("Tree.font"); SyntaxStyle s; try { s = SyntaxUtilities.parseStyle(style, f.getFamily(), f.getSize(), true, null); } catch (Exception e) { style = "color:#000000"; s = SyntaxUtilities.parseStyle(style, f.getFamily(), f.getSize(), true); } return s; } // }}}
public static void bumpUpFontSize(Component widget, int bumps) { if (!UserPreferences.readLocalePref() .equals("ko")) { // HACK!!! refector with variable localeSupportsBold Font f = widget.getFont(); widget.setFont(new Font(f.getFamily(), f.getStyle(), f.getSize() + bumps)); } }
public void setSelectedFont(Font font) { selectedFont = font; family = font.getFamily(); style = font.getStyle(); size = font.getSize(); preview.setFont(font); }
@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub Object source = e.getSource(); if (source == ok) { response = APPLY_OPTION; this.setVisible(false); } else if (source == cancel) { response = CANCEL_OPTION; this.setVisible(false); } else if (source == sizeCombo) { // get the number from the source JComboBox number = (JComboBox) source; String numberItem = (String) number.getSelectedItem(); Font temp = example.getFont(); // then set the font int newSize = Integer.parseInt(numberItem); example.setFont(new Font(temp.getFamily(), temp.getStyle(), newSize)); } else if (source == fontCombo) { JComboBox font = (JComboBox) source; String s = (String) font.getSelectedItem(); Font tmp = example.getFont(); example.setFont(new Font(s, tmp.getStyle(), tmp.getSize())); } else if (source == foreground) { Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground()); MenuBar.shapeLBG.setBackground(tmp); if (tmp != null) example.setForeground(tmp); } }
public static void makeEmphasized(Component widget) { // Set to bold amd add color Font font = widget.getFont(); if (!UserPreferences.readLocalePref() .equals("ko")) // HACK!!! refector with variable localeSupportsBold widget.setFont(new Font(font.getFamily(), Font.BOLD, font.getSize())); widget.setForeground(UIProperties.emphasisColor); }
/** @param args command line params */ public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); f = UIManager.getDefaults().getFont("TabbedPane.font"); f = new Font(f.getFamily(), Font.BOLD, f.getSize()); } catch (Exception x) { } new TestProgram().start(); }
private void _applyFontStyleForSelection(Font font) { StyledDocument doc = mTextEditor.getStyledDocument(); MutableAttributeSet attrs = mTextEditor.getInputAttributes(); StyleConstants.setFontFamily(attrs, font.getFamily()); StyleConstants.setFontSize(attrs, font.getSize()); StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0)); StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0)); StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0)); int start = mTextEditor.getSelectionStart(); int end = mTextEditor.getSelectionEnd(); doc.setCharacterAttributes(start, (end - start), attrs, false); }
@Override public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub Object source = e.getSource(); Font tmp = example.getFont(); int style = tmp.getStyle(); if (source == italic) if (italic.isSelected()) style = style | Font.ITALIC; // turn italic on else style = style & ~Font.ITALIC; // turn italic off else if (source == bold) if (bold.isSelected()) style = style | Font.BOLD; // turn bold on else style = style & ~Font.BOLD; // turn bold off example.setFont(new Font(tmp.getFamily(), style, tmp.getSize())); }
@Override public void scaleView() { // Slot sizes skillBoxSize = (int) (((double) getScreenWidth() / 15)); imgSize = (int) ((double) skillBoxSize * .40); levelUpBoxSize = (int) ((double) skillBoxSize * .60); plusIconSize = (int) ((double) skillBoxSize * .45); // Rect size skillRectWidth = skillCount * skillBoxSize; skillRectHeight = skillBoxSize; // Coordinates for skill box skillBoxStartX = (getScreenWidth() - skillRectWidth) / 2; skillBoxStartY = getScreenHeight() - skillRectHeight - 25; // Coordinates for level up boxes levelUpBoxLeftX = skillBoxStartX + (skillBoxSize - levelUpBoxSize) / 2; int skillBoxRight = skillBoxStartX + skillBoxSize; levelUpBoxLeftXDistanceGap = skillBoxRight + (skillBoxSize - levelUpBoxSize) / 2 - levelUpBoxLeftX; levelUpBoxRightX = levelUpBoxLeftX + ((skillCount - 1) * levelUpBoxLeftXDistanceGap) + levelUpBoxSize; levelUpBoxBottomY = skillBoxStartY; levelUpBoxTopY = levelUpBoxBottomY - levelUpBoxSize; // Font keyBindFontSize = getScreenWidth() / 100; skillLabelFontSize = keyBindFontSize; CDFontSize = getScreenWidth() / 50; skillLabelFont = new Font("Courier New", Font.PLAIN, skillLabelFontSize); // Setup keybind font keyBindFont = new Font("Courier New", Font.BOLD, keyBindFontSize); Map<TextAttribute, Object> attributes = new HashMap<>(); attributes.put(TextAttribute.FAMILY, keyBindFont.getFamily()); attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_EXTRABOLD); attributes.put(TextAttribute.SIZE, (int) (keyBindFont.getSize() * 1.5)); keyBindFont = Font.getFont(attributes); CDFont = new Font("Courier New", Font.PLAIN, CDFontSize); }
private TextLayout createAndCacheTextLayout( int fragmentIndex, Font basefont, FontRenderContext fontRenderContext) { String text = myFragments.get(fragmentIndex); AttributedString string = new AttributedString(text); int start = 0; int end = text.length(); AttributedCharacterIterator it = string.getIterator(new AttributedCharacterIterator.Attribute[0], start, end); Font currentFont = basefont; int currentIndex = start; for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) { Font font = basefont; if (!font.canDisplay(c)) { for (SuitableFontProvider provider : SuitableFontProvider.EP_NAME.getExtensions()) { font = provider.getFontAbleToDisplay( c, basefont.getSize(), basefont.getStyle(), basefont.getFamily()); if (font != null) break; } } int i = it.getIndex(); if (!Comparing.equal(currentFont, font)) { if (i > currentIndex) { string.addAttribute(TextAttribute.FONT, currentFont, currentIndex, i); } currentFont = font; currentIndex = i; } } if (currentIndex < end) { string.addAttribute(TextAttribute.FONT, currentFont, currentIndex, end); } TextLayout layout = new TextLayout(string.getIterator(), fontRenderContext); if (fragmentIndex >= myLayouts.size()) { myLayouts.addAll(Collections.nCopies(fragmentIndex - myLayouts.size() + 1, null)); } myLayouts.set(fragmentIndex, layout); myLayoutFont = getBaseFont(); return layout; }
private void init(Font font) { JPanel content = new JPanel(new BorderLayout()); content.setBorder(new EmptyBorder(12, 12, 12, 12)); setContentPane(content); JPanel listPanel = new JPanel(new GridLayout(1, 3, 6, 6)); String[] fonts; try { fonts = getFontList(); } catch (Exception e) { Log.log(Log.ERROR, this, "Broken Java implementation!"); Log.log(Log.ERROR, this, e); fonts = new String[] {"Broken Java implementation!"}; } JPanel familyPanel = createTextFieldAndListPanel( "font-selector.family", familyField = new JTextField(), familyList = new JList(fonts)); listPanel.add(familyPanel); String[] sizes = {"9", "10", "12", "14", "16", "18", "24"}; JPanel sizePanel = createTextFieldAndListPanel( "font-selector.size", sizeField = new JTextField(), sizeList = new JList(sizes)); listPanel.add(sizePanel); String[] styles = { jEdit.getProperty("font-selector.plain"), jEdit.getProperty("font-selector.bold"), jEdit.getProperty("font-selector.italic"), jEdit.getProperty("font-selector.bolditalic") }; JPanel stylePanel = createTextFieldAndListPanel( "font-selector.style", styleField = new JTextField(), styleList = new JList(styles)); styleField.setEditable(false); listPanel.add(stylePanel); familyList.setSelectedValue(font.getFamily(), true); familyField.setText(font.getFamily()); sizeList.setSelectedValue(String.valueOf(font.getSize()), true); sizeField.setText(String.valueOf(font.getSize())); styleList.setSelectedIndex(font.getStyle()); styleField.setText((String) styleList.getSelectedValue()); ListHandler listHandler = new ListHandler(); familyList.addListSelectionListener(listHandler); sizeList.addListSelectionListener(listHandler); styleList.addListSelectionListener(listHandler); content.add(BorderLayout.NORTH, listPanel); preview = new JLabel(jEdit.getProperty("font-selector.long-text")) { public void paintComponent(Graphics g) { if (fontSelector != null) fontSelector.setAntiAliasEnabled(g); super.paintComponent(g); } }; preview.setBorder(new TitledBorder(jEdit.getProperty("font-selector.preview"))); updatePreview(); Dimension prefSize = preview.getPreferredSize(); prefSize.height = 50; preview.setPreferredSize(prefSize); content.add(BorderLayout.CENTER, preview); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); buttons.setBorder(new EmptyBorder(12, 0, 0, 0)); buttons.add(Box.createGlue()); ok = new JButton(jEdit.getProperty("common.ok")); ok.addActionListener(new ActionHandler()); getRootPane().setDefaultButton(ok); buttons.add(ok); buttons.add(Box.createHorizontalStrut(6)); cancel = new JButton(jEdit.getProperty("common.cancel")); cancel.addActionListener(new ActionHandler()); buttons.add(cancel); buttons.add(Box.createGlue()); content.add(BorderLayout.SOUTH, buttons); pack(); setLocationRelativeTo(getParent()); setVisible(true); }
public EditorPaneHTMLHelp(String htmlFile) { if (GlobalValues.useSystemBrowserForHelp) { Desktop d = GlobalValues.desktop; try { // create a temp file GlobalValues.forHTMLHelptempFile = new File("tempHTMLHelpSynthetic.html"); FileWriter fw = new FileWriter(GlobalValues.forHTMLHelptempFile); java.util.List<String> list = readTextFromJar(htmlFile); Iterator<String> it = list.iterator(); while (it.hasNext()) { fw.write(it.next() + "\n"); } String canonicalPathOfFile = GlobalValues.forHTMLHelptempFile.getCanonicalPath(); URL urlFile = new URL("file://" + canonicalPathOfFile); URI uriOfFile = urlFile.toURI(); fw.close(); d.browse(uriOfFile); } catch (Exception e) { e.printStackTrace(); } } else { URL initialURL = getClass().getResource(htmlFile); font = GlobalValues.htmlfont; String title = "HTML Help"; setTitle(title); final Stack<String> urlStack = new Stack<String>(); final JEditorPane editorPane; editorPane = new JEditorPane(new HTMLEditorKit().getContentType(), " "); editorPane.setOpaque(false); editorPane.setBorder(null); editorPane.setEditable(false); JPanel magPanel = new JPanel(); magnificationFactor = GlobalValues.helpMagnificationFactor; magFactor = new JTextField(Double.toString(magnificationFactor)); JButton magButton = new JButton("Set Magnification: "); magButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { magnificationFactor = Double.parseDouble(magFactor.getText()); GlobalValues.helpMagnificationFactor = magnificationFactor; } }); magPanel.setLayout(new GridLayout(1, 2)); magPanel.add(magButton); magPanel.add(magFactor); final JTextField url = new JTextField(initialURL.toString()); // set up hyperlink listener editorPane.setEditable(false); try { // remember URL for back button urlStack.push(initialURL.toString()); // show URL in text field url.setText(initialURL.toString()); // add a CSS rule to force body tags to use the default label font // instead of the value in javax.swing.text.html.default.csss String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() * GlobalValues.helpMagnificationFactor + "pt; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); editorPane.setPage(initialURL); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } editorPane.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() * GlobalValues.helpMagnificationFactor + "pt; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); } }); editorPane.addHyperlinkListener( new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { // remember URL for back button urlStack.push(event.getURL().toString()); // show URL in text field url.setText(event.getURL().toString()); editorPane.setPage(event.getURL()); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } } } }); // set up checkbox for toggling edit mode final JCheckBox editable = new JCheckBox(); editable.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { editorPane.setEditable(editable.isSelected()); } }); // set up load button for loading URL ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { try { // remember URL for back button urlStack.push(url.getText()); editorPane.setPage(url.getText()); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }; JButton loadButton = new JButton("Load/Magnify"); loadButton.addActionListener(listener); url.addActionListener(listener); // set up back button and button action JButton backButton = new JButton("Back"); backButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (urlStack.size() <= 1) return; try { // get URL from back button urlStack.pop(); // show URL in text field String urlString = urlStack.peek(); url.setText(urlString); editorPane.setPage(urlString); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }); JPanel allPanel = new JPanel(new BorderLayout()); // put all control components in a panel JPanel ctrlPanel = new JPanel(new BorderLayout()); JPanel urlPanel = new JPanel(); urlPanel.add(new JLabel("URL")); urlPanel.add(url); JPanel buttonPanel = new JPanel(); buttonPanel.add(loadButton); buttonPanel.add(backButton); buttonPanel.add(new JLabel("Editable")); buttonPanel.add(magPanel); buttonPanel.add(editable); ctrlPanel.add(buttonPanel, BorderLayout.NORTH); ctrlPanel.add(urlPanel, BorderLayout.CENTER); allPanel.add(ctrlPanel, BorderLayout.NORTH); allPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER); add(allPanel); } }