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

📄 fillformatdialog.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

        //Create the style combo box.
        ComboBoxRenderer renderer2= new ComboBoxRenderer(COMBOTYPE_FILLLINESTYLE);
        renderer2.setPreferredSize(new Dimension(60, 32));
        fillLineStyleList = new JComboBox(fillLineStyleIntArray);
        fillLineStyleList.setRenderer(renderer2);
        fillLineStyleList.setSelectedIndex(fillFormat.getFillLineStyle());
        fillLineStyleList.setMaximumRowCount(5);


        //Create a color picker button.
        fillLineColorPickerButton  = new JButton("");
        fillLineColorPickerButton.setMargin(new java.awt.Insets(0,0,0,0));
        fillLineColorPickerButton.setPreferredSize(new Dimension(30,30));
        fillLineColorPickerButton.setActionCommand("ChangeLineColor");
        fillLineColorPickerButton.addActionListener(this);
        GUIUtils.setButtonBackground(fillLineColorPickerButton,fillFormat.getFillLineColor());
    	m_fillLineColor	=new Color(fillFormat.getFillLineColor().getRGB());


	//add fillLineColor picker button to a small panel.
        JPanel  fillLineColorPickerPanel	=new JPanel();
        fillLineColorPickerPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
        fillLineColorPickerPanel.add(fillLineColorPickerButton,BorderLayout.CENTER);


	/*******************************************************
	 *  add labels to a top label container.
	 ******************************************************/
        JPanel  topLabelPanel	=new JPanel();
        topLabelPanel.setLayout(new BoxLayout(topLabelPanel,BoxLayout.Y_AXIS));
        topLabelPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

        topLabelPanel.add(styleLabel);
        topLabelPanel.add(Box.createRigidArea(new Dimension(0,30)));
        topLabelPanel.add(colorLabel);
        topLabelPanel.add(Box.createRigidArea(new Dimension(0,30)));
        topLabelPanel.add(color2Label);


	/*******************************************************
	 * add combobox and color picker button to top container.
	 ******************************************************/
        JPanel  topComboPanel	=new JPanel();
        topComboPanel.setLayout(new BoxLayout(topComboPanel,BoxLayout.Y_AXIS));
        topComboPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        topComboPanel.add(Box.createRigidArea(new Dimension(0,15)));
        topComboPanel.add(fillStyleList);
        topComboPanel.add(Box.createRigidArea(new Dimension(0,15)));
        topComboPanel.add(colorPickerPanel);
        topComboPanel.add(Box.createRigidArea(new Dimension(0,15)));
        topComboPanel.add(color2PickerPanel);

	/*******************************************************
	 * add top labels and top comboboxes to a top panel container.
	 ******************************************************/
        JPanel topPanel = new JPanel();
        topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
        topPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
        topPanel.add(Box.createHorizontalGlue());
        topPanel.add(topLabelPanel);
        topPanel.add(Box.createRigidArea(new Dimension(10, 0)));
        topPanel.add(topComboPanel);

	/*******************************************************
	 *  add labels to a bottom label container.
	 ******************************************************/
        JPanel  bottomLabelPanel	=new JPanel();
        bottomLabelPanel.setLayout(new BoxLayout(bottomLabelPanel,BoxLayout.Y_AXIS));
        bottomLabelPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

        bottomLabelPanel.add(fillLineStyleLabel);
        bottomLabelPanel.add(Box.createRigidArea(new Dimension(0,30)));

        bottomLabelPanel.add(fillLineColorLabel);

	
	/*******************************************************
	 * add combobox and color picker button to a bottom container.
	 ******************************************************/
        JPanel  bottomComboPanel	=new JPanel();
        bottomComboPanel.setLayout(new BoxLayout(bottomComboPanel,BoxLayout.Y_AXIS));
        bottomComboPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        bottomComboPanel.add(Box.createRigidArea(new Dimension(0,15)));
        bottomComboPanel.add(fillLineStyleList);
        bottomComboPanel.add(Box.createRigidArea(new Dimension(0,15)));
        bottomComboPanel.add(fillLineColorPickerPanel);

	/*******************************************************
	 * add bottom labels and bottom comboboxes to a bottom panel container.
	 ******************************************************/
        JPanel bottomPanel = new JPanel();
        bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
        bottomPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
        bottomPanel.add(Box.createHorizontalGlue());
        bottomPanel.add(bottomLabelPanel);
        bottomPanel.add(Box.createRigidArea(new Dimension(10, 0)));
        bottomPanel.add(bottomComboPanel);


        //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(topPanel);
        contentPane.add(Box.createRigidArea(new Dimension(0,5))); 
	contentPane.add(new JSeparator(SwingConstants.HORIZONTAL));
        contentPane.add(Box.createRigidArea(new Dimension(0,5))); 
	contentPane.add(bottomPanel);
        contentPane.add(Box.createRigidArea(new Dimension(0,5)));
	contentPane.add(buttonPane);

        //contentPane.add(topPanel, BorderLayout.NORTH);
        //contentPane.add(bottomPanel, BorderLayout.CENTER);
        //contentPane.add(buttonPane, BorderLayout.SOUTH);

        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(
                                       FillFormatDialog.this,
                                       CADResource.getString("dialog.pickColor"),
                                       m_fillColor);
                if (newColor != null) {
                        GUIUtils.setButtonBackground(colorPickerButton,newColor);
                        m_fillColor	=newColor;
                }
                return;

         }else if ("ChangeColor2".equals(cmd)){

                Color newColor = JColorChooser.showDialog(
                                       FillFormatDialog.this,
                                       CADResource.getString("dialog.pickColor"),
                                       m_fillColor2);
                if (newColor != null) {
                        GUIUtils.setButtonBackground(color2PickerButton,newColor);
                        m_fillColor2	=newColor;
                }
                return;

         }else if ("ChangeLineColor".equals(cmd)){

                Color newColor = JColorChooser.showDialog(
                                       FillFormatDialog.this,
                                       CADResource.getString("dialog.pickColor"),
                                       m_fillLineColor);
                if (newColor != null) {
                        GUIUtils.setButtonBackground(fillLineColorPickerButton,newColor);
                        m_fillLineColor	=newColor;
                }
                return;
                
         }else if ("Confirm".equals(cmd) || "Default".equals(cmd)) {
                m_fillFormat.setFillStyle(fillStyleList.getSelectedIndex());
                m_fillFormat.setFillColor(m_fillColor);
                m_fillFormat.setFillColor2(m_fillColor2);
                m_fillFormat.setFillLineStyle(fillLineStyleList.getSelectedIndex());
                m_fillFormat.setFillLineColor(m_fillLineColor);

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

    class ComboBoxRenderer extends JLabel
                           implements ListCellRenderer {

       
        private int m_comboType =COMBOTYPE_FILLSTYLE;
        
        public ComboBoxRenderer(int comboType) {
                m_comboType     =comboType;
                setOpaque(true);
                setHorizontalAlignment(CENTER);
                setVerticalAlignment(CENTER);
        }

        /*
         * This method finds the image and text corresponding
         * to the selected value and returns the label, set up
         * to display the text and image.
         */
        public Component getListCellRendererComponent(
                                           JList list,
                                           Object value,
                                           int index,
                                           boolean isSelected,
                                           boolean cellHasFocus) {
            //Get the selected index. (The index param isn't
            //always valid, so just use the value.)
            int selectedIndex = ((Integer)value).intValue();

            if (isSelected) {
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
            } else {
                setBackground(list.getBackground());
                setForeground(list.getForeground());
            }

            //Set the icon and text.  If icon was null, say so.
            ImageIcon icon;
            String itemText;
                
            if (m_comboType==COMBOTYPE_FILLSTYLE){    
                icon            = styleImages[selectedIndex];
                itemText        = styleStrings[selectedIndex];
                setIcon(icon);
            
            }else {    
                icon            = fillLineStyleImages[selectedIndex];
                itemText        = fillLineStyleStrings[selectedIndex];
                setIcon(icon);
            }    
            

            
            if (icon == null) {
                setText(itemText);
                setFont(list.getFont());
            }

            return this;
        }

    }
    
        
}

⌨️ 快捷键说明

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