# fonts.py # Copyright (C) 2003 Frederic Laurent # # fonts.py is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # fonts.py is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with fonts.py; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from java.lang import * from java.awt import * from javax.swing import * testtext = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890" def windowClosingEvt(evt): System.exit(0) # class enable to change the font of each label contained in the list class FontRenderer(DefaultListCellRenderer): def getListCellRendererComponent(self, list_,value,index,isSelected,hasFocus): label = DefaultListCellRenderer.getListCellRendererComponent(self,list_,value,index,isSelected,hasFocus) label.setFont(Font(str(value), Font.PLAIN, 10)) label.setText("%s (%s): %s"%(str(value),label.getFont().getFamily(),testtext)) #label.setText("%s (%s : %s)"%(testtext,str(value),label.getFont().getFamily())) return label # create the main frame fr = JFrame("Fonts test", size=(400,400), windowClosing=windowClosingEvt) # create the font list ge = GraphicsEnvironment.getLocalGraphicsEnvironment() fontlist = map(lambda x:x.getFontName() , ge.getAllFonts()) j = JList(fontlist, cellRenderer = FontRenderer() ) #add the list to the frame and show it fr.getContentPane().add(JScrollPane(j)) fr.visible=1