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

📄 fillformatdialog.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 *    $Id:FillFormatDialog.java $
 *
 *    Copyright 2004 ~ 2005  JingFei International Cooperation LTD. All rights reserved. *
 */
package com.jfimagine.jfdraw.gui.dialog;
 

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.Color;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.BorderFactory;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.ImageIcon;
import javax.swing.ListCellRenderer;
import javax.swing.JList;
import javax.swing.JColorChooser;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

import com.jfimagine.jfgraph.shape.decorate.FillFormat;
import com.jfimagine.jfdraw.gui.ToolFactory;
import com.jfimagine.jfdraw.gui.resource.CADResource;
import com.jfimagine.jfdraw.gui.GUIConst;
import com.jfimagine.jfdraw.gui.GUIUtils;

import com.jfimagine.jfdraw.gui.GlobalSettings;


 /**
 * FillFormatDialog class.  A class used to get a new fill format in gui by user.
 *
 * @author     CookieMaker    
 *
 * @version $Revision: 1.00 $
 */  
public class FillFormatDialog extends JDialog
                        implements ActionListener {

    private static final int  COMBOTYPE_FILLSTYLE       =1;
    private static final int  COMBOTYPE_FILLLINESTYLE   =2;

    private static FillFormatDialog m_dialog;
    private static FillFormat m_fillFormat;

    private JComboBox fillStyleList;
    private JButton colorPickerButton;
    private JButton color2PickerButton;

    private JComboBox fillLineStyleList;
    private JButton   fillLineColorPickerButton;

    private Color m_fillColor;
    private Color m_fillColor2;
    private Color m_fillLineColor;

    ImageIcon[] styleImages;
    public static String[] styleStrings = {   	"none", "solid", 
    						"slash","slash_reverse", 
    						"line_vertical","line_horizontal",
                                		"grid", "grid_inclined",
                                		"gradient_leftright", 
                                		"gradient_rightleft", 
                                		"gradient_updown", 
                                		"gradient_downup", 
                                		"gradient_upleft_rightdown", 
                                		"gradient_upright_leftdown", 
                                		"gradient_downleft_rightup", 
                                		"gradient_downright_leftup" 
                            };


    ImageIcon[] fillLineStyleImages;
    public static String[] fillLineStyleStrings = {   	"style_solid", "style_dot", 
                                			"style_dash", "style_dashdot", 
                                			"style_dashdotdot"};
                             
                           
                           
    /**
     * Open an fill format modifier window, to modify the fill format.
     *
     * @param modalFrame  Determines which frame the dialog depends on; it should be
     * a component in the dialog's controlling frame. 
     *
     * @param fillFormat initial fill format.
     * @return The fill format.
     */
    public static FillFormat getNewFillFormat(Frame modalFrame,FillFormat fillFormat) {
    	return getNewFillFormat(modalFrame,null,fillFormat);
    }    

    /**
     * Open an fill format modifier window, to modify the fill format.
     *
     * @param modalFrame  Determines which frame the dialog depends on; it should be
     * a component in the dialog's controlling frame. 
     *
     * @param refComp  This should be null if you want the dialog
     * to come up with its left corner in the center of the screen;
     * otherwise, it should be the component on top of which the
     * dialog should appear.
     *
     * @param fillFormat initial fill format.
     *
     * @return The fill format.
     */
    public static FillFormat getNewFillFormat(Frame modalFrame,Component refComp,FillFormat fillFormat) {
    	return showDialog(modalFrame,refComp,fillFormat);
    }    


    /**
     * Set up and show the dialog.  The first Component argument
     * determines which frame the dialog depends on; it should be
     * a component in the dialog's controlling frame. The second
     * Component argument should be null if you want the dialog
     * to come up with its left corner in the center of the screen;
     * otherwise, it should be the component on top of which the
     * dialog should appear.
     */
    public static FillFormat showDialog(Component frameComp,
                                    Component locationComp,
                                    FillFormat fillFormat) {
        Frame frame = JOptionPane.getFrameForComponent(frameComp);
        m_dialog = new FillFormatDialog(frame,
                                locationComp,
                                CADResource.getString("dialog.fillFormat"),
                                fillFormat);
        m_dialog.setVisible(true);
        return m_fillFormat;
    }


    private FillFormatDialog(Frame frame,
                       Component locationComp,
                       String title,
                       FillFormat fillFormat) {
        super(frame, title, true);
	setResizable(false);
        
        //initiate initial fill format and this fill format.
        if (fillFormat==null)
                fillFormat      =new FillFormat();
        m_fillFormat  =new FillFormat();

         /****************************************
          * Create and initialize the buttons.
          ****************************************/
        JButton cancelButton = new JButton(CADResource.getString("button.cancel"));
        cancelButton.setFont(GUIConst.FONT_BUTTON);
        cancelButton.addActionListener(this);

        final JButton confirmButton = new JButton(CADResource.getString("button.confirm"));
        confirmButton.setFont(GUIConst.FONT_BUTTON);
        confirmButton.setActionCommand("Confirm");
        confirmButton.addActionListener(this);
        getRootPane().setDefaultButton(confirmButton);

        final JButton defaultButton = new JButton(CADResource.getString("button.defaultvalue"));
        defaultButton.setFont(GUIConst.FONT_BUTTON);
        defaultButton.setActionCommand("Default");
        defaultButton.addActionListener(this);


        /************************************************
         *   fill style and fill color labels and combos.
         ************************************************/
        JLabel  styleLabel	=new JLabel(CADResource.getString("label.fill.dialog.fillStyle"));
        styleLabel.setFont(GUIConst.FONT_LABEL);
        styleLabel.setPreferredSize(new Dimension(140, 32));

        JLabel  colorLabel	=new JLabel(CADResource.getString("label.fill.dialog.fillColor"));
        colorLabel.setFont(GUIConst.FONT_LABEL);
        colorLabel.setPreferredSize(new Dimension(140, 32));

        JLabel  color2Label	=new JLabel(CADResource.getString("label.fill.dialog.fillColor2"));
        color2Label.setFont(GUIConst.FONT_LABEL);
        color2Label.setPreferredSize(new Dimension(140, 32));

        Integer[] styleIntArray = new Integer[styleStrings.length];
        styleImages = new ImageIcon[styleStrings.length];
        for (int i = 0; i < styleStrings.length; i++) {
           		styleIntArray[i] = new Integer(i);
            		styleImages[i] = ToolFactory.createIcon("fill/"+styleStrings[i] + "32");
            		if (styleImages[i] != null) {
                		styleImages[i].setDescription(styleStrings[i]);
            		}
        }

        ComboBoxRenderer renderer1= new ComboBoxRenderer(COMBOTYPE_FILLSTYLE);
        renderer1.setPreferredSize(new Dimension(60, 32));
        fillStyleList = new JComboBox(styleIntArray);
        fillStyleList.setRenderer(renderer1);
        fillStyleList.setSelectedIndex(fillFormat.getFillStyle());
        fillStyleList.setMaximumRowCount(5);


        //Create a color picker button.
        colorPickerButton  = new JButton("");
        colorPickerButton.setMargin(new java.awt.Insets(0,0,0,0));
        colorPickerButton.setPreferredSize(new Dimension(30,30));
        colorPickerButton.setActionCommand("ChangeColor");
        colorPickerButton.addActionListener(this);
        GUIUtils.setButtonBackground(colorPickerButton,fillFormat.getFillColor());
    	m_fillColor	=new Color(fillFormat.getFillColor().getRGB());

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

        //Create a color2 picker button.
        color2PickerButton  = new JButton("");
        color2PickerButton.setMargin(new java.awt.Insets(0,0,0,0));
        color2PickerButton.setPreferredSize(new Dimension(30,30));
        color2PickerButton.setActionCommand("ChangeColor2");
        color2PickerButton.addActionListener(this);
        GUIUtils.setButtonBackground(color2PickerButton,fillFormat.getFillColor2());
    	m_fillColor2	=new Color(fillFormat.getFillColor2().getRGB());

	//add color2 picker button to a small panel.
        JPanel  color2PickerPanel	=new JPanel();
        color2PickerPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
        color2PickerPanel.add(color2PickerButton,BorderLayout.CENTER);


        /***********************************************************
         *   fill line style, fill line width and fill line color.
         ***********************************************************/
        JLabel  fillLineStyleLabel	=new JLabel(CADResource.getString("label.fill.dialog.fillLineStyle"));
        fillLineStyleLabel.setFont(GUIConst.FONT_LABEL);
        fillLineStyleLabel.setPreferredSize(new Dimension(140, 32));

        JLabel  fillLineColorLabel	=new JLabel(CADResource.getString("label.fill.dialog.fillLineColor"));
        fillLineColorLabel.setFont(GUIConst.FONT_LABEL);
        fillLineColorLabel.setPreferredSize(new Dimension(140, 32));


        //Load the style styleImages and create an array of indexes.
        Integer[] fillLineStyleIntArray = new Integer[fillLineStyleStrings.length];
        fillLineStyleImages = new ImageIcon[fillLineStyleStrings.length];
        for (int i = 0; i < fillLineStyleStrings.length; i++) {
           		fillLineStyleIntArray[i] = new Integer(i);
            		fillLineStyleImages[i] = ToolFactory.createIcon("line/"+fillLineStyleStrings[i] + "32");
            		if (fillLineStyleImages[i] != null) {
                		fillLineStyleImages[i].setDescription(fillLineStyleStrings[i]);
            		}
        }

⌨️ 快捷键说明

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