⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 font2dtest.java

📁 一个小公司要求给写的很简单的任务管理系统。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            if ( showFontInfoOpt ) {                fireUpdateFontInfo();                fontInfoDialog.show();            }            else              fontInfoDialog.hide();        }        catch ( Exception ex ) {            fireChangeStatus( "ERROR: Failed to Load Options File; See Stack Trace", true );            ex.printStackTrace();        }    }    /// Loads a previously saved image     private void loadComparisonPNG( String fileName ) {        try {	    BufferedImage image =		javax.imageio.ImageIO.read(new File(fileName));            JFrame f = new JFrame( "Comparison PNG" );            ImagePanel ip = new ImagePanel( image );            f.setResizable( false );            f.getContentPane().add( ip );            f.addWindowListener( new WindowAdapter() {                public void windowClosing( WindowEvent e ) {                    ( (JFrame) e.getSource() ).dispose();                }            });            f.pack();            f.show();        }        catch ( Exception ex ) {            fireChangeStatus( "ERROR: Failed to Load PNG File; See Stack Trace", true );            ex.printStackTrace();        }    }    /// Interface functions...    /// ActionListener interface function    /// Responds to JMenuItem, JTextField and JButton actions    public void actionPerformed( ActionEvent e ) {        Object source = e.getSource();        if ( source instanceof JMenuItem ) {            JMenuItem mi = (JMenuItem) source;            String itemName = mi.getText();            if ( itemName.equals( "Save Selected Options..." )) {                String fileName = promptFile( true, "options.txt" );                if ( fileName != null )                  writeCurrentOptions( fileName );            }            else if ( itemName.equals( "Load Options..." )) {                String fileName = promptFile( false, "options.txt" );                if ( fileName != null )                  loadOptions( fileName );            }            else if ( itemName.equals( "Save as PNG..." )) {                String fileName = promptFile( true, fontMenu.getSelectedItem() + ".png" );                if ( fileName != null )                  fp.doSavePNG( fileName );            }            else if ( itemName.equals( "Load PNG File to Compare..." )) {                String fileName = promptFile( false, null );                if ( fileName != null )                  loadComparisonPNG( fileName );            }            else if ( itemName.equals( "Page Setup..." ))              fp.doPageSetup();            else if ( itemName.equals( "Print..." ))              printDialog.show();            else if ( itemName.equals( "Close" ))              parent.dispose();            else if ( itemName.equals( "Exit" ))              System.exit(0);        }        else if ( source instanceof JTextField ) {            JTextField tf = (JTextField) source;            float sz = 12f;            try {                 sz = Float.parseFloat(sizeField.getText());                 if (sz < 1f || sz > 120f) {                      sz = 12f;                      sizeField.setText("12");                 }            } catch (Exception se) {                 sizeField.setText("12");            }            if ( tf == sizeField )              fp.setFontParams( fontMenu.getSelectedItem(),                                sz,                                styleMenu.getSelectedIndex(),                                transformMenu.getSelectedIndex() );        }        else if ( source instanceof JButton ) {            String itemName = ( (JButton) source ).getText();            /// Print dialog buttons...            if ( itemName.equals( "Print" )) {                for ( int i = 0; i < printModeCBs.length; i++ )                  if ( printModeCBs[i].isSelected() ) {                      printDialog.hide();                      fp.doPrint( i );                  }            }            else if ( itemName.equals( "Cancel" ))              printDialog.hide();            /// Update button from Usert Text JDialog...            else if ( itemName.equals( "Update" ))              fp.setTextToDraw( fp.USER_TEXT, null,                                parseUserText( userTextArea.getText() ), null );        }        else if ( source instanceof JComboBox ) {            JComboBox c = (JComboBox) source;                        /// RangeMenu handles actions by itself and then calls fireRangeChanged,            /// so it is not listed or handled here            if ( c == fontMenu || c == styleMenu || c == transformMenu ) {		float sz = 12f;		try {		    sz = Float.parseFloat(sizeField.getText());		    if (sz < 1f || sz > 120f) {			sz = 12f;			sizeField.setText("12");		    }		} catch (Exception se) {		    sizeField.setText("12");		}		fp.setFontParams(fontMenu.getSelectedItem(),				 sz,				 styleMenu.getSelectedIndex(),				 transformMenu.getSelectedIndex());	    } else if ( c == methodsMenu )              fp.setDrawMethod( methodsMenu.getSelectedIndex() );            else if ( c == textMenu ) {                if(canDisplayCheck) {                    fireRangeChanged();                }                int selected = textMenu.getSelectedIndex();                if ( selected == fp.RANGE_TEXT )                  fp.setTextToDraw( fp.RANGE_TEXT, rm.getSelectedRange(),                                    null, null );                else if ( selected == fp.USER_TEXT )                  fp.setTextToDraw( fp.USER_TEXT, null,                                    parseUserText( userTextArea.getText() ), null );                else if ( selected == fp.FILE_TEXT ) {                    String fileName = promptFile( false, null );                    if ( fileName != null ) {		      tFileName = fileName;		      readTextFile( fileName );		    } else {                        /// User cancelled selection; reset to previous choice                        c.setSelectedIndex( currentTextChoice );                        return;                    }                }                else if ( selected == fp.ALL_GLYPHS )                  fp.setTextToDraw( fp.ALL_GLYPHS, null, null, null );                updateGUI();                currentTextChoice = selected;            }            else if ( c == transformMenuG2 ) {            	fp.setTransformG2( transformMenuG2.getSelectedIndex() );            }	    else if (c == antiAliasMenu || c == fracMetricsMenu) {		if (c == antiAliasMenu) {		    boolean enabled = FontPanel.AAValues.			isLCDMode(antiAliasMenu.getSelectedItem());			contrastSlider.setEnabled(enabled);		}		fp.setRenderingHints(antiAliasMenu.getSelectedItem(),				     fracMetricsMenu.getSelectedItem(),				     contrastSlider.getValue());	    }        }    }    public void stateChanged(ChangeEvent e) {	 Object source = e.getSource();	 if (source instanceof JSlider) {	     fp.setRenderingHints(antiAliasMenu.getSelectedItem(),				  fracMetricsMenu.getSelectedItem(),				  contrastSlider.getValue());	     	 }    }    /// ItemListener interface function    /// Responds to JCheckBoxMenuItem, JComboBox and JCheckBox actions    public void itemStateChanged( ItemEvent e ) {        Object source = e.getSource();        if ( source instanceof JCheckBoxMenuItem ) {            JCheckBoxMenuItem cbmi = (JCheckBoxMenuItem) source;            if ( cbmi == displayGridCBMI )              fp.setGridDisplay( displayGridCBMI.getState() );            else if ( cbmi == force16ColsCBMI )              fp.setForce16Columns( force16ColsCBMI.getState() );            else if ( cbmi == showFontInfoCBMI ) {                if ( showFontInfoCBMI.getState() ) {                    fireUpdateFontInfo();                    fontInfoDialog.show();                }                else                  fontInfoDialog.hide();            }        }    }    private static void printUsage() {        String usage = "Usage: java -jar Font2DTest.jar [options]\n" +            "\nwhere options include:\n" +            "    -dcdc | -disablecandisplaycheck disable canDisplay check for font\n" +            "    -?    | -help                   print this help message\n" +            "\nExample :\n" +            "     To disable canDisplay check on font for ranges\n" +            "     java -jar Font2DTest.jar -dcdc";        System.out.println(usage);        System.exit(0);    }    /// Main function    public static void main(String argv[]) {                if(argv.length > 0) {            if(argv[0].equalsIgnoreCase("-disablecandisplaycheck") ||               argv[0].equalsIgnoreCase("-dcdc")) {                canDisplayCheck = false;            }            else {                printUsage();            }        }	UIManager.put("swing.boldMetal", Boolean.FALSE);        final JFrame f = new JFrame( "Font2DTest" );        final Font2DTest f2dt = new Font2DTest( f, false );        f.addWindowListener( new WindowAdapter() {            public void windowOpening( WindowEvent e ) { f2dt.repaint(); }            public void windowClosing( WindowEvent e ) { System.exit(0); }        });        f.getContentPane().add( f2dt );        f.pack();        f.show();    }    /// Inner class definitions...    /// Class to display just an image file    /// Used to show the comparison PNG image    private final class ImagePanel extends JPanel {        private final BufferedImage bi;                public ImagePanel( BufferedImage image ) {            bi = image;        }        public Dimension getPreferredSize() {            return new Dimension( bi.getWidth(), bi.getHeight() );        }        public void paintComponent( Graphics g ) {            g.drawImage( bi, 0, 0, this );        }    }    /// Classes made to avoid repetitive calls... (being lazy)    private final class ButtonV2 extends JButton {        public ButtonV2( String name, ActionListener al ) {            super( name );            this.addActionListener( al );        }    }    private final class ChoiceV2 extends JComboBox {                private BitSet bitSet = null;	public ChoiceV2() {;}        public ChoiceV2( ActionListener al ) {            super();            this.addActionListener( al );        }        public ChoiceV2( ActionListener al, boolean fontChoice) {            this(al);            if(fontChoice) {                //Register this component in ToolTipManager                setToolTipText("");                bitSet = new BitSet();                setRenderer(new ChoiceV2Renderer(this));            }        }                public String getToolTipText() {            int index = this.getSelectedIndex();            String fontName = (String) this.getSelectedItem();            if(fontName != null &&                (textMenu.getSelectedIndex() == fp.RANGE_TEXT)) {                if (getBit(index)) {                    return "Font \"" + fontName + "\" can display some characters in \"" +                         rm.getSelectedItem() + "\" range";                }                else {                    return "Font \"" + fontName + "\" cannot display any characters in \"" +                         rm.getSelectedItem() + "\" range";                }            }            return super.getToolTipText();        }        public void setBit(int bitIndex, boolean value) {            bitSet.set(bitIndex, value);        }        public boolean getBit(int bitIndex) {            return bitSet.get(bitIndex);        }    }     private final class ChoiceV2Renderer extends DefaultListCellRenderer {         private ImageIcon yesImage, blankImage;        private ChoiceV2 choice = null;        public ChoiceV2Renderer(ChoiceV2 choice) {            try {                yesImage = new ImageIcon(getClass().getResource("yes.gif"));                blankImage = new ImageIcon(getClass().getResource("blank.gif"));            }            catch(Exception exception) {                System.out.println("Exception : " + exception);            }            this.choice = choice;        }         public Component getListCellRendererComponent(JList list,                                                      Object value,                                                      int index,                                                      boolean isSelected,                                                      boolean cellHasFocus) {            if(textMenu.getSelectedIndex() == fp.RANGE_TEXT) {                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);                //For JComboBox if index is -1, its rendering the selected index.                if(index == -1) {                    index = choice.getSelectedIndex();                }                                if(choice.getBit(index)) {                    setIcon(yesImage);                }                else {                    setIcon(blankImage);                }            } else {                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);                setIcon(blankImage);            }            return this;        }    }    private final class LabelV2 extends JLabel {        public LabelV2( String name ) {            super( name );        }    }    private final class MenuItemV2 extends JMenuItem {        public MenuItemV2( String name, ActionListener al ) {            super( name );            this.addActionListener( al );        }    }    private final class CheckboxMenuItemV2 extends JCheckBoxMenuItem {        public CheckboxMenuItemV2( String name, boolean b, ItemListener il ) {            super( name, b );            this.addItemListener( il );        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -