📄 rotatesetupdialog.java
字号:
/**
* $Id:RotateSetupDialog.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.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.JTextArea;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import com.jfimagine.jfdraw.gui.resource.CADResource;
import com.jfimagine.utils.commonutil.CommonUtil;
import com.jfimagine.jfdraw.gui.GUIConst;
import com.jfimagine.jfdraw.gui.GlobalSettings;
/**
* RotateSetupDialog is used to setup rotate parameters.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class RotateSetupDialog extends JDialog
implements ActionListener {
/** rotate in any angle */
public static final int ROTATE_ANYANYGLE =1;
/** rotate in fixed angle */
public static final int ROTATE_FIXEDANGLE =2;
private static RotateSetupDialog m_dialog;
private boolean m_configChanged =false;
private GlobalSettings m_settings;
JComboBox m_rotateTypeList;
JTextField m_rotateAngleText;
/**
* Open a window, to setup new rotate configuration.
*
* @param modalFrame Determines which frame the dialog depends on; it should be
* a component in the dialog's controlling frame.
*
* @return True if re-configged, false otherwise.
*/
public static boolean rotateSetup(Component c) {
Frame frame = JOptionPane.getFrameForComponent(c);
m_dialog = new RotateSetupDialog(frame,
CADResource.getString("rotate.setup.dialog.title"));
m_dialog.setVisible(true);
return m_dialog.m_configChanged;
}
private RotateSetupDialog(Frame frame,
String title) {
super(frame, title, true);
setResizable(false);
m_settings =GlobalSettings.getInstance();
//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);
//rotate type
JLabel rotateTypeLabel = new JLabel(CADResource.getString("rotate.setup.dialog.rotatetype"));
rotateTypeLabel.setFont(GUIConst.FONT_LABEL);
int rotateIndex =m_settings.getRotateType()-1;
if (rotateIndex<0)
rotateIndex =0;
else if (rotateIndex>1)
rotateIndex =1;
String[] rotateTypeItems =new String[2];
Dimension size =new Dimension(140,25);
rotateTypeItems[0] =CADResource.getString("rotate.setup.dialog.rotatetype.anyangle");
rotateTypeItems[1] =CADResource.getString("rotate.setup.dialog.rotatetype.fixedangle");
m_rotateTypeList =new JComboBox(rotateTypeItems);
m_rotateTypeList.setFont(GUIConst.FONT_LABEL);
m_rotateTypeList.setPreferredSize(size);
m_rotateTypeList.setMaximumSize(size);
m_rotateTypeList.setMinimumSize(size);
m_rotateTypeList.setEditable(false);
m_rotateTypeList.setSelectedIndex(rotateIndex);
//a top panel for placing rotateType label, rotateType list
JPanel rotateTypePanel = new JPanel();
rotateTypePanel.setLayout(new BoxLayout(rotateTypePanel, BoxLayout.X_AXIS));
rotateTypePanel.add(rotateTypeLabel);
rotateTypePanel.add(Box.createRigidArea(new Dimension(5,0)));
rotateTypePanel.add(m_rotateTypeList);
rotateTypePanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
//rotate angle
JLabel rotateAngleLabel = new JLabel(CADResource.getString("rotate.setup.dialog.rotatetype.fixedanglestep"));
rotateAngleLabel.setFont(GUIConst.FONT_LABEL);
m_rotateAngleText =new JTextField(5);
m_rotateAngleText.setText(""+m_settings.getRotateAngle());
size =new Dimension(50,25);
m_rotateAngleText.setPreferredSize(size);
JLabel degreeLabel = new JLabel(CADResource.getString("rotate.setup.dialog.rotatetype.fixedanglestep.degree"));
degreeLabel.setFont(GUIConst.FONT_LABEL);
//a panel for placing rotateAngle label, rotateAngle list
JPanel rotateAnglePanel = new JPanel();
rotateAnglePanel.setLayout(new BoxLayout(rotateAnglePanel, BoxLayout.X_AXIS));
rotateAnglePanel.add(rotateAngleLabel);
rotateAnglePanel.add(Box.createRigidArea(new Dimension(5,0)));
rotateAnglePanel.add(m_rotateAngleText);
rotateAnglePanel.add(Box.createRigidArea(new Dimension(5,0)));
rotateAnglePanel.add(degreeLabel);
rotateAnglePanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,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, 10, 10, 10));
buttonPane.add(Box.createRigidArea(new Dimension(30, 0)));
buttonPane.add(confirmButton);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(cancelButton);
//Put everything together, using the content pane's BorderLayout.
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane,BoxLayout.Y_AXIS));
contentPane.add(rotateTypePanel);
contentPane.add(rotateAnglePanel);
contentPane.add(buttonPane);
pack();
setLocationRelativeTo(null);
}
//Handle clicks on the Set and Cancel buttons.
public void actionPerformed(ActionEvent e) {
if ("Confirm".equals(e.getActionCommand())) {
int rotateType =m_rotateTypeList.getSelectedIndex()+1;
double rotateAngle =CommonUtil.s2f(m_rotateAngleText.getText());
if (rotateAngle<1)
rotateAngle =1;
else if (rotateAngle>359)
rotateAngle =359;
m_settings.setRotateType(rotateType);
m_settings.setRotateAngle(rotateAngle);
m_configChanged =true;
}else{
m_configChanged =false;
}
m_dialog.setVisible(false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -