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

📄 attributedialog.java

📁 环境配置:系统装有jre运行环境。 使用说明: 1.双击drawer.jar文件
💻 JAVA
字号:
///////////////////////////////////////////////////////////
// Name: Drawer                                          //
// Author:Zhanghan                                       //
// Date:  2005-9-10                                      //
// Email: zhang_han04@ncic.ac.cn                         //
///////////////////////////////////////////////////////////

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.border.LineBorder;

//     This dialog pops up when you double-click.
public class AttributeDialog extends JDialog {

    private DrawingBoard board = null;
    private int strokeIndex = 0;
    private JButton bgButton = null;
    private JPanel colorPanel = null;
    private JButton fgButton = null;
    private JPanel mediumPanel1 = null;
    private JPanel mediumPanel3 = null;
    private JPanel sizePanel = null;
    private JComboBox weightCombo = null;
    public Position position = null;

    public static final Stroke STROKES[] = {
        new BasicStroke(1.0F), new BasicStroke(2.0F), new BasicStroke(5F), new BasicStroke(7.5F), new BasicStroke(10F)
    };

  public AttributeDialog(DrawingBoard board, int strokeIndex) {

    this.board = board;
    this.strokeIndex = strokeIndex;
    
    //center the dialog
    Dimension dialogSize = this.getPreferredSize();
    Dimension parentSize = board.getSize();
    Point loc = getLocation();
    this.setLocation( (parentSize.width - dialogSize.width) / 2 + loc.x,
                      (parentSize.height - dialogSize.height) / 2 + loc.y);

    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }



  private void jbInit() throws Exception {

    mediumPanel1 = new JPanel();
    colorPanel = new JPanel();
    fgButton = new JButton();
    bgButton = new JButton();
    sizePanel = new JPanel();
    mediumPanel3 = new JPanel();
    weightCombo = new JComboBox();
    
    this.setTitle("Attibute Settings");
    this.getContentPane().setLayout(new GridBagLayout());
    mediumPanel1.setLayout(new BoxLayout(mediumPanel1, 1));

    //Color Panel
    colorPanel.setLayout(new FlowLayout(1, 20, 10));
    colorPanel.setBorder(new TitledBorder("Color Settings"));
    fgButton.setBackground(board.getForeground());
    fgButton.setToolTipText("Change Drawing Color");
    fgButton.setBorder(new LineBorder(new Color(0, 0, 0)));
    fgButton.setPreferredSize(new Dimension(50, 50));
    fgButton.addActionListener(new ActionListener()
    {

      public void actionPerformed(ActionEvent actionevent)
      {
        fgButtonActionPerformed(actionevent);
      }

    });
    colorPanel.add(fgButton);
    bgButton.setBackground(board.getBackground());
    bgButton.setToolTipText("Change Board Background Color");
    bgButton.setBorder(new LineBorder(new Color(0, 0, 0)));
    bgButton.setPreferredSize(new Dimension(50, 50));
    bgButton.addActionListener(new ActionListener()
    {

      public void actionPerformed(ActionEvent actionevent)
      {
        bgButtonActionPerformed(actionevent);
      }

    });
    colorPanel.add(bgButton);
    mediumPanel1.add(colorPanel);

    //Size Panel
    sizePanel.setBorder(new TitledBorder("Size Setttings"));
    mediumPanel3.setLayout(new BorderLayout(0, 3));
    weightCombo.setFont(new Font("Dialog", 0, 10));
    weightCombo.setModel(new DefaultComboBoxModel(new String[] {
        "Stroke Weight 1.0px", "Stroke Weight 2.0px", "Stroke Weight 5.0px", "Stroke Weight 7.5px", "Stroke Weight 10.0px"
    }));
    weightCombo.setSelectedIndex(strokeIndex);
    weightCombo.addActionListener(new ActionListener()
    {

        public void actionPerformed(ActionEvent actionevent)
        {
            weightComboActionPerformed(actionevent);
        }

    });

    mediumPanel3.add(weightCombo, "North");
    sizePanel.add(mediumPanel3);
    mediumPanel1.add(sizePanel);
    GridBagConstraints gridbagconstraints = new GridBagConstraints();
    gridbagconstraints.anchor = 11;
    gridbagconstraints.weightx = 1.0D;
    gridbagconstraints.insets = new Insets(10, 5, 5, 5);

    //Position & Diameter Panel
    position = new Position(board);
    mediumPanel1.add(position);
    this.getContentPane().add(mediumPanel1, gridbagconstraints);

    position.setBorder(new TitledBorder("Position & Size Settings"));

    mediumPanel1.add(position);
    this.getContentPane().add(mediumPanel1, gridbagconstraints);

    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    this.setResizable(false);
    this.setModal(true);
    this.pack();
    this.setVisible(true);
  }

  private void fgButtonActionPerformed(ActionEvent actionevent)
  {
    Color color = JColorChooser.showDialog(this, "Change Drawing Color", board.getForeground());
    if(color != null)
    {
      board.setForeground(color);
      fgButton.setBackground(color);
    }
  }

  private void bgButtonActionPerformed(ActionEvent actionevent)
  {
    Color color = JColorChooser.showDialog(this, "Change Board Background Color", board.getBackground());
    if(color != null)
    {
      board.setBackground(color);
      bgButton.setBackground(color);
    }
  }


  private void weightComboActionPerformed(ActionEvent actionevent)
  {
    board.setStrokeIndex(weightCombo.getSelectedIndex());
    repaint();
  }
}

⌨️ 快捷键说明

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