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

📄 fontformatdialog.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        transparencyList.setPreferredSize(new Dimension(80,32));
        transparencyList.setMaximumSize(new Dimension(80,32));
        transparencyList.setMinimumSize(new Dimension(80,32));
        
        JLabel  transparencyLabel	=new JLabel(CADResource.getString("label.font.dialog.transparency"));
        transparencyLabel.setFont(GUIConst.FONT_LABEL);
        transparencyLabel.setPreferredSize(new Dimension(140, 32));

        JLabel  percentLabel	=new JLabel("%");
        percentLabel.setFont(GUIConst.FONT_LABEL);
        percentLabel.setPreferredSize(new Dimension(20, 32));

	//add transparency combobox and the '%' char  to a small panel.
        JPanel  fontTransparencyPanel	=new JPanel();
        //fontTransparencyPanel.setLayout(new BoxLayout(fontTransparencyPanel,BoxLayout.X_AXIS));
        fontTransparencyPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
        fontTransparencyPanel.add(transparencyList,BorderLayout.CENTER);
        fontTransparencyPanel.add(percentLabel,BorderLayout.EAST);
        	

	useStrokeAndFillCheck	=new JCheckBox(CADResource.getString("label.font.dialog.useStrokeAndFill"));
	useStrokeAndFillCheck.setFont(GUIConst.FONT_LABEL);
	useStrokeAndFillCheck.setSelected(fontFormat.isUseStrokeAndFill());


 	GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    	String[] fontNameAry = env.getAvailableFontFamilyNames();

        fontNameList 	=new JComboBox(fontNameAry);
        fontNameList.setFont(GUIConst.FONT_DIALOG);
        fontNameList.setSelectedItem(fontFormat.getFontName());
        fontNameList.setMaximumRowCount(5);

	//Font style: "Normal", "Bold", "Italic", "Bold Italic"
        fontStyleList 	=new JComboBox(fontStyleAry);
        fontStyleList.setFont(GUIConst.FONT_LABEL);
        if (fontFormat.isBoldItalic())
        	fontStyleList.setSelectedIndex(3);
        else if  (fontFormat.isBold())
        	fontStyleList.setSelectedIndex(1);
        else  if (fontFormat.isItalic())
        	fontStyleList.setSelectedIndex(2);
        else
        	fontStyleList.setSelectedIndex(0);
        fontStyleList.setMaximumRowCount(5);


        fontSizeList 	=new JComboBox(fontSizeAry);
        fontSizeList.setFont(GUIConst.FONT_LABEL);
        fontSizeList.setSelectedItem(CommonUtil.i2s(fontFormat.getFont().getSize()));
        fontSizeList.setMaximumRowCount(5);

        //Create a color picker button.
        fontColorButton  = new JButton("");
        fontColorButton.setMargin(new java.awt.Insets(0,0,0,0));
        fontColorButton.setPreferredSize(new Dimension(30,30));
        fontColorButton.setActionCommand("ChangeColor");
        fontColorButton.addActionListener(this);
        GUIUtils.setButtonBackground(fontColorButton,fontFormat.getFontColor());
    	m_fontColor	=new Color(fontFormat.getFontColor().getRGB());

	//add color picker button to a small panel.
        JPanel  fontColorPanel	=new JPanel();
        fontColorPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
        fontColorPanel.add(fontColorButton,BorderLayout.CENTER);


	/*******************************************************
	 *  add labels and combobx to main container.
	 ******************************************************/
        JPanel  mainPanel	=new JPanel();
        mainPanel.setLayout(new BoxLayout(mainPanel,BoxLayout.Y_AXIS));
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        
        
        //font name
        JPanel namePanel	=new JPanel();
        namePanel.setLayout(new BoxLayout(namePanel,BoxLayout.X_AXIS));
        namePanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
	namePanel.add(nameLabel);
	namePanel.add(Box.createRigidArea(new Dimension(5,0)));
	namePanel.add(fontNameList);
	mainPanel.add(namePanel);
	mainPanel.add(Box.createRigidArea(new Dimension(0,15)));
	
	//font style:
        JPanel stylePanel	=new JPanel();
        stylePanel.setLayout(new BoxLayout(stylePanel,BoxLayout.X_AXIS));
        stylePanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
	stylePanel.add(styleLabel);
	stylePanel.add(Box.createRigidArea(new Dimension(5,0)));
	stylePanel.add(fontStyleList);
	mainPanel.add(stylePanel);
	mainPanel.add(Box.createRigidArea(new Dimension(0,15)));

	//font size:
        JPanel sizePanel	=new JPanel();
        sizePanel.setLayout(new BoxLayout(sizePanel,BoxLayout.X_AXIS));
        sizePanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
	sizePanel.add(sizeLabel);
	sizePanel.add(Box.createRigidArea(new Dimension(5,0)));
	sizePanel.add(fontSizeList);
	mainPanel.add(sizePanel);
	mainPanel.add(Box.createRigidArea(new Dimension(0,15)));
	

	//font color:
        JPanel colorPanel	=new JPanel();
        colorPanel.setLayout(new BoxLayout(colorPanel,BoxLayout.X_AXIS));
        colorPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
	colorPanel.add(colorLabel);
	colorPanel.add(Box.createRigidArea(new Dimension(5,0)));
	colorPanel.add(fontColorPanel);
	mainPanel.add(colorPanel);
	mainPanel.add(Box.createRigidArea(new Dimension(0,15)));

        JPanel transparencyPanel	=new JPanel();
        transparencyPanel.setLayout(new BoxLayout(transparencyPanel,BoxLayout.X_AXIS));
        transparencyPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
	transparencyPanel.add(transparencyLabel);
	transparencyPanel.add(Box.createRigidArea(new Dimension(5,0)));
	transparencyPanel.add(fontTransparencyPanel);
	mainPanel.add(transparencyPanel);
	mainPanel.add(Box.createRigidArea(new Dimension(0,15)));
	

	//font stroke and fill:
	JPanel strokePanel	=new JPanel();
        strokePanel.setLayout(new BoxLayout(strokePanel,BoxLayout.X_AXIS));
        strokePanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
        strokePanel.add(useStrokeAndFillCheck);
	colorPanel.add(Box.createRigidArea(new Dimension(5,0)));
        strokePanel.add(strokeLineButton);
	colorPanel.add(Box.createRigidArea(new Dimension(5,0)));
        strokePanel.add(fillStyleButton);
        mainPanel.add(strokePanel);
	mainPanel.add(Box.createRigidArea(new Dimension(0,10)));

	
        //Lay out the buttons from left to right.
        JPanel buttonPane = new JPanel();
        //buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
        buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
        buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
        //buttonPane.add(Box.createHorizontalGlue());
        buttonPane.add(Box.createRigidArea(new Dimension(15, 0)));
        buttonPane.add(defaultButton);
        buttonPane.add(Box.createRigidArea(new Dimension(15, 0)));
        buttonPane.add(confirmButton);
        buttonPane.add(Box.createRigidArea(new Dimension(15, 0)));
        buttonPane.add(cancelButton);

        //Put everything together
        Container contentPane = getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        //contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
	contentPane.add(mainPanel);
        contentPane.add(Box.createRigidArea(new Dimension(0,5)));
	contentPane.add(buttonPane);


        pack();
        setLocationRelativeTo(locationComp);
    }


    //Handle clicks on the Set and Cancel buttons.
    public void actionPerformed(ActionEvent e) {
    	 String cmd	=e.getActionCommand();
    	 
         if ("ChangeColor".equals(cmd)){

                Color newColor = JColorChooser.showDialog(
                                       FontFormatDialog.this,
                                       CADResource.getString("dialog.pickColor"),
                                       m_fontColor);
                if (newColor != null) {
                        GUIUtils.setButtonBackground(fontColorButton,newColor);
                        m_fontColor	=newColor;
                }
                return;
                
         }else if ("Confirm".equals(cmd) || "Default".equals(cmd)) {
                m_fontFormat.setFontName((String)fontNameList.getSelectedItem());
                m_fontFormat.setFontStyle(fontStyleList.getSelectedIndex());  
                int size	=CommonUtil.s2i((String)fontSizeList.getSelectedItem());
                m_fontFormat.setFontSize(size);
                m_fontFormat.setFontColor(m_fontColor);
                m_fontFormat.setTransparency(transparencyList.getSelectedIndex());
                m_fontFormat.setUseStrokeAndFill(useStrokeAndFillCheck.isSelected());

		if ("Default".equals(cmd)){
        		GlobalSettings settings	=GlobalSettings.getInstance();
        		settings.setFontFormat(m_fontFormat);
        		JOptionPane.showMessageDialog(null, CADResource.getString("message.defaultvalue.fontformat"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
        		
        		return;
        	}                
               
                m_dialog.setVisible(false);

	}else if ("StrokeLineSetup".equals(cmd)){
		LineFormat lineFormat=LineFormatDialog.showDialog(this,this,m_fontFormat.getLineFormat());
		if (lineFormat!=null){
			m_fontFormat.getLineFormat().setValue(lineFormat);
		}

	}else if ("FillStyleSetup".equals(cmd)){
		FillFormat fillFormat=FillFormatDialog.showDialog(this,this,m_fontFormat.getFillFormat());
		if (fillFormat!=null){
			m_fontFormat.getFillFormat().setValue(fillFormat);
		}

        }else{
           	m_fontFormat    =null;
                m_dialog.setVisible(false);
        }
    }
        
}

⌨️ 快捷键说明

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