/** * Gets a special kind of Phrase that changes some characters into corresponding symbols. * * @param leading * @param string * @param font * @return a newly constructed Phrase */ public static final Phrase getInstance(int leading, String string, Font font) { Phrase p = new Phrase(true); p.setLeading(leading); p.font = font; if (font.getFamily() != Font.SYMBOL && font.getFamily() != Font.ZAPFDINGBATS && font.getBaseFont() == null) { int index; while ((index = SpecialSymbol.index(string)) > -1) { if (index > 0) { String firstPart = string.substring(0, index); ((ArrayList) p).add(new Chunk(firstPart, font)); string = string.substring(index); } Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor()); StringBuffer buf = new StringBuffer(); buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0))); string = string.substring(1); while (SpecialSymbol.index(string) == 0) { buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0))); string = string.substring(1); } ((ArrayList) p).add(new Chunk(buf.toString(), symbol)); } } if (string != null && string.length() != 0) { ((ArrayList) p).add(new Chunk(string, font)); } return p; }
@NotNull public static String getHtmlWithFonts(@NotNull String input, int style, @NotNull Font baseFont) { int start = baseFont.canDisplayUpTo(input); if (start == -1) return input; Font font = null; StringBuilder result = new StringBuilder(); for (int i = start; i < input.length(); i++) { char c = input.charAt(i); if (baseFont.canDisplay(c)) { if (font != null) result.append("</font>"); result.append(c); font = null; } else if (font != null && font.canDisplay(c)) { result.append(c); } else { if (font != null) result.append("</font>"); font = getFontAbleToDisplay(c, baseFont.getSize(), style, baseFont.getFamily()); if (font != baseFont) result.append("<font face=\"").append(font.getFamily()).append("\">"); result.append(c); } } if (font != null) result.append("</font>"); return result.toString(); }
// {{{ 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 void setSelectedFont(Font font) { selectedFont = font; family = font.getFamily(); style = font.getStyle(); size = font.getSize(); preview.setFont(font); }
private static File findFileForFont(Font font, final boolean matchStyle) { final String normalizedFamilyName = font.getFamily().toLowerCase(Locale.getDefault()).replace(" ", ""); final int fontStyle = font.getStyle(); File[] files = new File(System.getProperty("user.home"), "Library/Fonts") .listFiles( new FilenameFilter() { @Override public boolean accept(File file, String name) { String normalizedName = name.toLowerCase(Locale.getDefault()); return normalizedName.startsWith(normalizedFamilyName) && (normalizedName.endsWith(".otf") || normalizedName.endsWith(".ttf")) && (!matchStyle || fontStyle == ComplementaryFontsRegistry.getFontStyle(name)); } }); if (files == null || files.length == 0) return null; // to make sure results are predictable we return first file in alphabetical order return Collections.min( Arrays.asList(files), new Comparator<File>() { @Override public int compare(File file1, File file2) { return file1.getName().compareTo(file2.getName()); } }); }
private static void fillStyledFontMap() { Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); for (Font font : allFonts) { String name = font.getName(); Integer style = null; if (!SystemInfo.isAppleJvm) { style = FONT_NAME_TO_STYLE.get( name); // workaround with explicit fontName->style mapping doesn't work on Apple JVM } if (style == null) { if (!Patches.JDK_MAC_FONT_STYLE_BUG) continue; style = getFontStyle(name); } if (style != Font.PLAIN) { String familyName = font.getFamily(); Pair<String, Integer>[] entry = ourStyledFontMap.get(familyName); if (entry == null) { //noinspection unchecked entry = new Pair[4]; for (int i = 1; i < 4; i++) { entry[i] = Pair.create(familyName, i); } ourStyledFontMap.put(familyName, entry); } entry[style] = Pair.create(name, Font.PLAIN); } } }
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)); } }
@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); }
/** Returns the specified font, but with the style's bold, underline and italic flags applied. */ public Font getStyledFont(Font font) { if (font == null) throw new NullPointerException("font param must not" + " be null"); if (font.equals(lastFont)) return lastStyledFont; lastFont = font; lastStyledFont = new Font( font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize()); if (underlined) { Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>(); attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); lastStyledFont = lastStyledFont.deriveFont(attr); } return lastStyledFont; }
@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())); }
/** Returns the font metrics for the styled font. */ public FontMetrics getFontMetrics(Font font, JComponent comp) { if (font == null) throw new NullPointerException("font param must not" + " be null"); if (font.equals(lastFont) && fontMetrics != null) return fontMetrics; lastFont = font; lastStyledFont = new Font( font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize()); if (underlined) { Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>(); attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); lastStyledFont = lastStyledFont.deriveFont(attr); } // fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(lastStyledFont); fontMetrics = comp.getFontMetrics(lastStyledFont); return fontMetrics; }
@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; }
public String toString() { return font != null ? font.getFamily() + getStyleName(font.getStyle()) + font.getSize() : ""; }
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); } }
/** * Sets the font of the specified attribute. * * @param attr attribute to apply this font to * @param f the font to use */ public static void setAttributeFont(MutableAttributeSet attr, Font f) { StyleConstants.setBold(attr, f.isBold()); StyleConstants.setItalic(attr, f.isItalic()); StyleConstants.setFontFamily(attr, f.getFamily()); StyleConstants.setFontSize(attr, f.getSize()); }
/** * Execute applet events. Here is the state transition diagram * * <pre>{@literal * Note: (XXX) is the action * APPLET_XXX is the state * (applet code loaded) --> APPLET_LOAD -- (applet init called)--> APPLET_INIT -- * (applet start called) --> APPLET_START -- (applet stop called) --> APPLET_STOP -- * (applet destroyed called) --> APPLET_DESTROY --> (applet gets disposed) --> * APPLET_DISPOSE --> ... * }</pre> * * In the legacy lifecycle model. The applet gets loaded, inited and started. So it stays in the * APPLET_START state unless the applet goes away(refresh page or leave the page). So the applet * stop method called and the applet enters APPLET_STOP state. Then if the applet is revisited, it * will call applet start method and enter the APPLET_START state and stay there. * * <p>In the modern lifecycle model. When the applet first time visited, it is same as legacy * lifecycle model. However, when the applet page goes away. It calls applet stop method and * enters APPLET_STOP state and then applet destroyed method gets called and enters APPLET_DESTROY * state. * * <p>This code is also called by AppletViewer. In AppletViewer "Restart" menu, the applet is jump * from APPLET_STOP to APPLET_DESTROY and to APPLET_INIT . * * <p>Also, the applet can jump from APPLET_INIT state to APPLET_DESTROY (in Netscape/Mozilla * case). Same as APPLET_LOAD to APPLET_DISPOSE since all of this are triggered by browser. */ @Override public void run() { Thread curThread = Thread.currentThread(); if (curThread == loaderThread) { // if we are in the loader thread, cause // loading to occur. We may exit this with // status being APPLET_DISPOSE, APPLET_ERROR, // or APPLET_LOAD runLoader(); return; } boolean disposed = false; while (!disposed && !curThread.isInterrupted()) { AppletEvent evt; try { evt = getNextEvent(); } catch (InterruptedException e) { showAppletStatus("bail"); return; } // showAppletStatus("EVENT = " + evt.getID()); try { switch (evt.getID()) { case APPLET_LOAD: if (!okToLoad()) { break; } // This complexity allows loading of applets to be // interruptable. The actual thread loading runs // in a separate thread, so it can be interrupted // without harming the applet thread. // So that we don't have to worry about // concurrency issues, the main applet thread waits // until the loader thread terminates. // (one way or another). if (loaderThread == null) { setLoaderThread(new Thread(null, this, "AppletLoader", 0, false)); loaderThread.start(); // we get to go to sleep while this runs loaderThread.join(); setLoaderThread(null); } else { // REMIND: issue an error -- this case should never // occur. } break; case APPLET_INIT: // AppletViewer "Restart" will jump from destroy method to // init, that is why we need to check status w/ APPLET_DESTROY if (status != APPLET_LOAD && status != APPLET_DESTROY) { showAppletStatus("notloaded"); break; } applet.resize(defaultAppletSize); if (PerformanceLogger.loggingEnabled()) { PerformanceLogger.setTime("Applet Init"); PerformanceLogger.outputLog(); } applet.init(); // Need the default(fallback) font to be created in this AppContext Font f = getFont(); if (f == null || "dialog".equals(f.getFamily().toLowerCase(Locale.ENGLISH)) && f.getSize() == 12 && f.getStyle() == Font.PLAIN) { setFont(new Font(Font.DIALOG, Font.PLAIN, 12)); } // Validate the applet in event dispatch thread // to avoid deadlock. try { final AppletPanel p = this; Runnable r = new Runnable() { @Override public void run() { p.validate(); } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } status = APPLET_INIT; showAppletStatus("inited"); break; case APPLET_START: { if (status != APPLET_INIT && status != APPLET_STOP) { showAppletStatus("notinited"); break; } applet.resize(currentAppletSize); applet.start(); // Validate and show the applet in event dispatch thread // to avoid deadlock. try { final AppletPanel p = this; final Applet a = applet; Runnable r = new Runnable() { @Override public void run() { p.validate(); a.setVisible(true); // Fix for BugTraq ID 4041703. // Set the default focus for an applet. if (hasInitialFocus()) { setDefaultFocus(); } } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } status = APPLET_START; showAppletStatus("started"); break; } case APPLET_STOP: if (status != APPLET_START) { showAppletStatus("notstarted"); break; } status = APPLET_STOP; // Hide the applet in event dispatch thread // to avoid deadlock. try { final Applet a = applet; Runnable r = new Runnable() { @Override public void run() { a.setVisible(false); } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } // During Applet.stop(), any AccessControlException on an involved Class remains in // the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is // reused, the same exception will occur during class loading. Set the // AppletClassLoader's // exceptionStatusSet flag to allow recognition of what had happened // when reusing AppletClassLoader object. try { applet.stop(); } catch (java.security.AccessControlException e) { setExceptionStatus(e); // rethrow exception to be handled as it normally would be. throw e; } showAppletStatus("stopped"); break; case APPLET_DESTROY: if (status != APPLET_STOP && status != APPLET_INIT) { showAppletStatus("notstopped"); break; } status = APPLET_DESTROY; // During Applet.destroy(), any AccessControlException on an involved Class remains in // the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is // reused, the same exception will occur during class loading. Set the // AppletClassLoader's // exceptionStatusSet flag to allow recognition of what had happened // when reusing AppletClassLoader object. try { applet.destroy(); } catch (java.security.AccessControlException e) { setExceptionStatus(e); // rethrow exception to be handled as it normally would be. throw e; } showAppletStatus("destroyed"); break; case APPLET_DISPOSE: if (status != APPLET_DESTROY && status != APPLET_LOAD) { showAppletStatus("notdestroyed"); break; } status = APPLET_DISPOSE; try { final Applet a = applet; Runnable r = new Runnable() { @Override public void run() { remove(a); } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } applet = null; showAppletStatus("disposed"); disposed = true; break; case APPLET_QUIT: return; } } catch (Exception e) { status = APPLET_ERROR; if (e.getMessage() != null) { showAppletStatus("exception2", e.getClass().getName(), e.getMessage()); } else { showAppletStatus("exception", e.getClass().getName()); } showAppletException(e); } catch (ThreadDeath e) { showAppletStatus("death"); return; } catch (Error e) { status = APPLET_ERROR; if (e.getMessage() != null) { showAppletStatus("error2", e.getClass().getName(), e.getMessage()); } else { showAppletStatus("error", e.getClass().getName()); } showAppletException(e); } clearLoadAbortRequest(); } }
/** * Updates the context according to the given element style. The properties that are not defined * in the style are left unchanged. * * @param style the style data */ public void update(NodeData style) { // setup the font String family = null; CSSProperty.FontFamily ff = style.getProperty("font-family"); if (ff == null) family = font.getFamily(); // use current else if (ff == FontFamily.list_values) { TermList fmlspec = style.getValue(TermList.class, "font-family"); if (fmlspec == null) family = font.getFamily(); else family = getFontName(fmlspec); } else { if (factory != null) family = factory .getConfig() .getDefaultFont(ff.getAWTValue()); // try to translate to physical font if (family == null) family = ff.getAWTValue(); // could not translate - use as is } double size; double psize = (parent == null) ? CSSUnits.medium_font : parent.getEm(); CSSProperty.FontSize fsize = style.getProperty("font-size"); if (fsize == null) size = em; else if (fsize == CSSProperty.FontSize.length || fsize == CSSProperty.FontSize.percentage) { TermLengthOrPercent lenspec = style.getValue(TermLengthOrPercent.class, "font-size"); if (lenspec != null) { em = psize; size = pxLength(lenspec, psize); // pixels are ok here (java is fixed to 72 dpi for font sizes) } else size = em; } else size = CSSUnits.convertFontSize(psize, fsize); fontSize = CSSUnits.points(size); if (rootContext != null) rem = rootContext.getEm(); else rem = em; // we don't have a root context? CSSProperty.FontWeight weight = style.getProperty("font-weight"); if (weight != null) fontWeight = weight; CSSProperty.FontStyle fstyle = style.getProperty("font-style"); if (fstyle != null) fontStyle = fstyle; int fs = Font.PLAIN; if (representsBold(fontWeight)) fs = Font.BOLD; if (fontStyle == CSSProperty.FontStyle.ITALIC || fontStyle == CSSProperty.FontStyle.OBLIQUE) fs = fs | Font.ITALIC; font = new Font(family, fs, (int) Math.round(size)); em = size; CSSProperty.FontVariant variant = style.getProperty("font-variant"); if (variant != null) fontVariant = variant; CSSProperty.TextDecoration decor = style.getProperty("text-decoration"); textDecoration.clear(); if (decor != null) { if (decor == TextDecoration.list_values) { TermList list = style.getValue(TermList.class, "text-decoration"); for (Term<?> t : list) { if (t.getValue() instanceof CSSProperty.TextDecoration) textDecoration.add((CSSProperty.TextDecoration) t.getValue()); } } else if (decor != TextDecoration.NONE) textDecoration.add(decor); } // color TermColor clr = style.getValue(TermColor.class, "color"); if (clr != null) color = clr.getValue(); }