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

📄 lineformatdialog.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 *    $Id:LineFormatDialog.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 com.jfimagine.jfgraph.shape.decorate.LineFormat;
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;


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

    private static final int  COMBOTYPE_STYLE       =1;
    private static final int  COMBOTYPE_WIDTH       =2;
    

    private static LineFormatDialog m_dialog;
    private static LineFormat m_lineFormat;

    private JComboBox lineStyleList;
    private JComboBox lineWidthList;
    private JButton colorPickerButton;  
    private Color m_lineColor;

    ImageIcon[] styleImages;
    public static String[] styleStrings = {   	"style_solid", "style_dot", 
                                		"style_dash", "style_dashdot", 
                                		"style_dashdotdot"};
                             
    ImageIcon[] widthImages;
    public static String[] widthStrings = {   	"width_0_", 
    						"width_1_", 
                                		"width_2_", 
                                		"width_3_", 
                                		"width_4_", 
                                		"width_5_", 
                                		"width_6_", 
                                		"width_7_", 
                                		"width_8_", 
                                		"width_9_", 
                                		"width_10_" };
                           
                           
    /**
     * Open an line format modifier window, to modify the line format.
     *
     * @param modalFrame  Determines which frame the dialog depends on; it should be
     * a component in the dialog's controlling frame. 
     *
     * @param lineFormat initial line format.
     * @return The line format.
     */
    public static LineFormat getNewLineFormat(Frame modalFrame,LineFormat lineFormat) {
    	return getNewLineFormat(modalFrame,null,lineFormat);
    }    

    /**
     * Open an line format modifier window, to modify the line 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 lineFormat initial line format.
     *
     * @return The line format.
     */
    public static LineFormat getNewLineFormat(Frame modalFrame,Component refComp,LineFormat lineFormat) {
    	return showDialog(modalFrame,refComp,lineFormat);
    }    


    /**
     * 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 LineFormat showDialog(Component frameComp,
                                    Component locationComp,
                                    LineFormat lineFormat) {
        Frame frame = JOptionPane.getFrameForComponent(frameComp);
        m_dialog = new LineFormatDialog(frame,
                                locationComp,
                                CADResource.getString("dialog.lineFormat"),
                                lineFormat);
        m_dialog.setVisible(true);
        return m_lineFormat;
    }


    private LineFormatDialog(Frame frame,
                       Component locationComp,
                       String title,
                       LineFormat lineFormat) {
        super(frame, title, true);
	setResizable(false);
        
        //initiate initial line format and this line format.
        if (lineFormat==null)
                lineFormat      =new LineFormat();
        m_lineFormat  =new LineFormat();

        //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);
        
        //main part of the dialog
        
        //two labels.
        JLabel  styleLabel	=new JLabel(CADResource.getString("label.line.dialog.lineStyle"));
        styleLabel.setFont(GUIConst.FONT_LABEL);
        styleLabel.setPreferredSize(new Dimension(120, 32));

        JLabel  widthLabel	=new JLabel(CADResource.getString("label.line.dialog.lineThickness"));
        widthLabel.setFont(GUIConst.FONT_LABEL);
        widthLabel.setPreferredSize(new Dimension(120, 32));

        JLabel  colorLabel	=new JLabel(CADResource.getString("label.line.dialog.lineColor"));
        colorLabel.setFont(GUIConst.FONT_LABEL);
        colorLabel.setPreferredSize(new Dimension(120, 32));

        JPanel  labelPanel	=new JPanel();
        labelPanel.setLayout(new BoxLayout(labelPanel,BoxLayout.Y_AXIS));
        labelPanel.add(styleLabel);
        labelPanel.add(Box.createRigidArea(new Dimension(0,30)));
        labelPanel.add(widthLabel);
        labelPanel.add(Box.createRigidArea(new Dimension(0,30)));
        labelPanel.add(colorLabel);
        labelPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

        //Load the style styleImages and create an array of indexes.

⌨️ 快捷键说明

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