📄 layersetupdialog.java
字号:
/**
* $Id:LayerSetupDialog.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 com.jfimagine.jfdraw.gui.resource.CADResource;
import com.jfimagine.utils.commonutil.CommonUtil;
import com.jfimagine.jfdraw.gui.GUIConst;
import com.jfimagine.jfgraph.shape.union.JFPage;
import com.jfimagine.jfgraph.shape.union.JFLayer;
/**
* LayerSetupDialog class. A class used to modify layers.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class LayerSetupDialog extends JDialog
implements ActionListener {
private static final String CMD_CONFIRM ="Confirm";
private static final String CMD_NEW ="New";
private static final String CMD_UPDATE ="Update";
private static final String CMD_REMOVE ="Remove";
private static final String CMD_MOVEUP ="MoveUp";
private static final String CMD_MOVEDOWN ="MoveDown";
private static LayerSetupDialog m_dialog;
private static JFPage m_page;
private static JCheckBoxList m_list;
private static boolean m_layerChanged=false;
/**
* Open a window, to input/modify layers properties.
*
* @param modalFrame Determines which frame the dialog depends on; it should be
* a component in the dialog's controlling frame.
*
* @param page A page to modify.
*/
public static boolean layerSetup(Frame modalFrame,JFPage page){
if (page==null)
return false;
else
return layerSetup(modalFrame,null,page);
}
/**
* Open a window, to input/modify layers properties.
*
* @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 page A page to modify.
*/
public static boolean layerSetup(Frame modalFrame,Component refComp,JFPage page) {
if (page==null)
return false;
else
return showDialog(modalFrame,refComp,page);
}
/**
* 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 boolean showDialog(Component frameComp,
Component locationComp,
JFPage page) {
Frame frame = JOptionPane.getFrameForComponent(frameComp);
m_dialog = new LayerSetupDialog(frame,
locationComp,
CADResource.getString("dialog.layerSetup"),
page);
m_dialog.setVisible(true);
return m_layerChanged;
}
private LayerSetupDialog(Frame frame,
Component locationComp,
String title,
JFPage page) {
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);
//
JButton confirmButton = new JButton(CADResource.getString("button.confirm"));
confirmButton.setFont(GUIConst.FONT_BUTTON);
confirmButton.setActionCommand(CMD_CONFIRM);
confirmButton.addActionListener(this);
getRootPane().setDefaultButton(confirmButton);
JLabel layerLabel =new JLabel(CADResource.getString("label.layerSetup.layers"));
layerLabel.setFont(GUIConst.FONT_LABEL);
layerLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
m_page =page;
m_list =new JCheckBoxList();
Dimension listSize =new Dimension(100,120);
m_list.setFont(GUIConst.FONT_LABEL);
m_list.setMinimumSize(listSize);
m_list.setPreferredSize(listSize);
m_list.setMaximumSize(new Dimension(Short.MAX_VALUE,
Short.MAX_VALUE));
m_list.setCheckItemList(m_page.getLayerItemList());
Dimension buttonSize =new Dimension(120,25);
JButton newButton = new JButton(CADResource.getString("label.layerSetup.new"));
newButton.setFont(GUIConst.FONT_BUTTON);
newButton.setMinimumSize(buttonSize);
newButton.setPreferredSize(buttonSize);
newButton.setMaximumSize(new Dimension(Short.MAX_VALUE,
Short.MAX_VALUE));
newButton.setAlignmentX(Component.LEFT_ALIGNMENT);
newButton.setActionCommand(CMD_NEW);
newButton.addActionListener(this);
JButton updateButton = new JButton(CADResource.getString("label.layerSetup.update"));
updateButton.setFont(GUIConst.FONT_BUTTON);
updateButton.setMinimumSize(buttonSize);
updateButton.setPreferredSize(buttonSize);
updateButton.setMaximumSize(new Dimension(Short.MAX_VALUE,
Short.MAX_VALUE));
updateButton.setAlignmentX(Component.LEFT_ALIGNMENT);
updateButton.setActionCommand(CMD_UPDATE);
updateButton.addActionListener(this);
JButton removeButton = new JButton(CADResource.getString("label.layerSetup.remove"));
removeButton.setFont(GUIConst.FONT_BUTTON);
removeButton.setMinimumSize(buttonSize);
removeButton.setPreferredSize(buttonSize);
removeButton.setMaximumSize(new Dimension(Short.MAX_VALUE,
Short.MAX_VALUE));
removeButton.setAlignmentX(Component.LEFT_ALIGNMENT);
removeButton.setActionCommand(CMD_REMOVE);
removeButton.addActionListener(this);
JButton moveUpButton = new JButton(CADResource.getString("label.layerSetup.moveUp"));
moveUpButton.setFont(GUIConst.FONT_BUTTON);
moveUpButton.setMinimumSize(buttonSize);
moveUpButton.setPreferredSize(buttonSize);
moveUpButton.setMaximumSize(new Dimension(Short.MAX_VALUE,
Short.MAX_VALUE));
moveUpButton.setAlignmentX(Component.LEFT_ALIGNMENT);
moveUpButton.setActionCommand(CMD_MOVEUP);
moveUpButton.addActionListener(this);
JButton moveDownButton = new JButton(CADResource.getString("label.layerSetup.moveDown"));
moveDownButton.setFont(GUIConst.FONT_BUTTON);
moveDownButton.setMinimumSize(buttonSize);
moveDownButton.setPreferredSize(buttonSize);
moveDownButton.setMaximumSize(new Dimension(Short.MAX_VALUE,
Short.MAX_VALUE));
moveDownButton.setAlignmentX(Component.LEFT_ALIGNMENT);
moveDownButton.setActionCommand(CMD_MOVEDOWN);
moveDownButton.addActionListener(this);
//a panel to place check box list.
JPanel listPanel = new JPanel();
listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.Y_AXIS));
listPanel.add(m_list);
listPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
//a panel to place control buttons.
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
controlPanel.add(newButton);
controlPanel.add(Box.createRigidArea(new Dimension(0,10)));
controlPanel.add(updateButton);
controlPanel.add(Box.createRigidArea(new Dimension(0,10)));
controlPanel.add(removeButton);
controlPanel.add(Box.createRigidArea(new Dimension(0,10)));
controlPanel.add(moveUpButton);
controlPanel.add(Box.createRigidArea(new Dimension(0,10)));
controlPanel.add(moveDownButton);
controlPanel.add(Box.createRigidArea(new Dimension(0,10)));
controlPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
//middle panel contains both list and control panel.
JPanel middlePanel = new JPanel();
middlePanel.setLayout(new BoxLayout(middlePanel, BoxLayout.X_AXIS));
middlePanel.add(listPanel);
middlePanel.add(Box.createRigidArea(new Dimension(10,0)));
middlePanel.add(controlPanel);
middlePanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
middlePanel.setAlignmentX(Component.CENTER_ALIGNMENT);
//Lay out the buttons from left to right.
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
buttonPanel.add(Box.createRigidArea(new Dimension(30, 0)));
buttonPanel.add(confirmButton);
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(cancelButton);
buttonPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
//main panel
JPanel mainPanel =new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
mainPanel.add(layerLabel);
mainPanel.add(Box.createRigidArea(new Dimension(0,1)));
mainPanel.add(middlePanel);
mainPanel.add(Box.createRigidArea(new Dimension(0,10)));
mainPanel.add(buttonPanel);
mainPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
//Put everything together, using the content pane's BorderLayout.
Container contentPane = getContentPane();
contentPane.add(mainPanel, BorderLayout.CENTER);
pack();
setLocationRelativeTo(locationComp);
}
//Handle clicks on the Set and Cancel buttons.
public void actionPerformed(ActionEvent e) {
String cmd =e.getActionCommand();
if (CMD_CONFIRM.equals(cmd)) {
//read items state from gui.
m_list.readItems();
if (m_list.getItemCount()==0){
JOptionPane.showMessageDialog(null, CADResource.getString("dialog.layerSetup.noItems"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE);
}else if (m_list.getFirstCheckedIndex()<0){
JOptionPane.showMessageDialog(null, CADResource.getString("dialog.layerSetup.noCheckedItems"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE);
}else{
//replace page's item list by checkBoxList's items.
m_page.setLayerItemList(m_list.getCheckItemList(),m_list.getRemovedCheckItemList());
m_layerChanged=true;
m_dialog.setVisible(false);
}
}else if (CMD_NEW.equals(cmd)){
m_list.addNewItem(com.jfimagine.jfdraw.gui.resource.CADResource.getString("label.layer.title"));
}else if (CMD_UPDATE.equals(cmd)){
m_list.modifySelected();
}else if (CMD_REMOVE.equals(cmd)){
if (m_list.getSelectedIndex()>=0){
int n = JOptionPane.showConfirmDialog(
LayerSetupDialog.this,
CADResource.getString("dialog.layerSetup.removeAlert"),
CADResource.getString("sys.warn"),
JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
m_list.removeSelected();
}
}
}else if (CMD_MOVEUP.equals(cmd)){
m_list.moveUp();
}else if (CMD_MOVEDOWN.equals(cmd)){
m_list.moveDown();
}else{
m_layerChanged=false;
m_dialog.setVisible(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -