📄 undosetupdialog.java
字号:
/**
* $Id:UndoSetupDialog.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.JOptionPane;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
import com.jfimagine.jfdraw.gui.resource.CADResource;
import com.jfimagine.utils.commonutil.CommonUtil;
import com.jfimagine.jfdraw.gui.GUIConst;
/**
* UndoSetupDialog class. A class used to get a new undo depth in gui by user.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class UndoSetupDialog extends JDialog
implements ActionListener {
public static final int UNDODEPTH_MIN =1;
public static final int UNDODEPTH_MAX =50;
private static UndoSetupDialog m_dialog;
private static int m_undoDepth =20;
JTextField undoDepthText;
/**
* Open a window, to input/modify an undo depth.
*
* @param modalFrame Determines which frame the dialog depends on; it should be
* a component in the dialog's controlling frame.
*
* @param initialValue initial undo depth for modify
* @return A new undo depth.
*/
public static int getNewUndoDepth(Frame modalFrame,int initialValue) {
return getNewUndoDepth(modalFrame,null,initialValue);
}
/**
* Open a window, to input/modify a new undo depth.
*
* @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 initialValue initial undo depth for modify
* @return A new undo depth.
*/
public static int getNewUndoDepth(Frame modalFrame,Component refComp,int initialValue) {
return showDialog(modalFrame,refComp,initialValue);
}
/**
* 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.
*/
private static int showDialog(Component frameComp,
Component locationComp,
int initialValue) {
Frame frame = JOptionPane.getFrameForComponent(frameComp);
m_dialog = new UndoSetupDialog(frame,
locationComp,
CADResource.getString("dialog.undoSetup"),
initialValue);
m_dialog.setVisible(true);
return m_undoDepth;
}
private UndoSetupDialog(Frame frame,
Component locationComp,
String title,
int initialValue) {
super(frame, title, true);
setResizable(false);
//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);
if (initialValue<UNDODEPTH_MIN)
initialValue =UNDODEPTH_MIN;
else if (initialValue>UNDODEPTH_MAX)
initialValue =UNDODEPTH_MAX;
m_undoDepth =initialValue;
undoDepthText =new JTextField(CommonUtil.i2s(m_undoDepth));
undoDepthText.setFont(GUIConst.FONT_LABEL);
undoDepthText.setPreferredSize(new Dimension(50,20));
undoDepthText.setEditable(true);
//a top panel for placing undo label, undo text field.
JPanel undoPanel = new JPanel();
undoPanel.setLayout(new BoxLayout(undoPanel, BoxLayout.X_AXIS));
JLabel undoLabel = new JLabel(CADResource.getString("label.undo.undoDepth"));
undoLabel.setFont(GUIConst.FONT_LABEL);
undoPanel.add(undoLabel);
undoPanel.add(Box.createRigidArea(new Dimension(5,0)));
undoPanel.add(undoDepthText);
undoPanel.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.add(undoPanel, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.SOUTH);
pack();
setLocationRelativeTo(locationComp);
}
//Handle clicks on the Set and Cancel buttons.
public void actionPerformed(ActionEvent e) {
if ("Confirm".equals(e.getActionCommand())) {
int undoDepth =CommonUtil.s2i(undoDepthText.getText());
if (undoDepth==0)
undoDepth =1;
else if (undoDepth<UNDODEPTH_MIN)
undoDepth =UNDODEPTH_MIN;
else if (undoDepth>UNDODEPTH_MAX)
undoDepth =UNDODEPTH_MAX;
m_undoDepth =undoDepth;
}else{
//do nothing, don't change m_undoDepth
}
m_dialog.setVisible(false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -