📄 propertydialog.java
字号:
/**
* $Id:PropertyDialog.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 java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
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.JOptionPane;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.DefaultCellEditor;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import com.jfimagine.jfgraph.shape.base.AbstractShape;
import com.jfimagine.jfgraph.shape.base.Property;
import com.jfimagine.jfgraph.shape.base.ObjectList;
import com.jfimagine.jfdraw.gui.resource.CADResource;
import com.jfimagine.jfdraw.gui.GUIConst;
import com.jfimagine.jfdraw.gui.GUIUtils;
/**
* PropertyDialog class. A class used to get a new property list in gui by user.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class PropertyDialog extends JDialog
implements ActionListener {
private static PropertyDialog m_dialog;
private static JTable m_table;
private static MyTableModel m_tableModel;
private static boolean m_propertiesChanged =false;
private static AbstractShape m_shape;
private static ObjectList m_currentProperties;
private JButton confirmButton;
/**
* modify an object's properties
*
* @param modalFrame Determines which frame the dialog depends on; it should be
* a component in the dialog's controlling frame.
*
* @param aShape An abstract shape that to be modified properties.
* @return True if properties changed, false otherwise.
*/
public static boolean getNewProperties(Frame modalFrame,AbstractShape aShape) {
return getNewProperties(modalFrame,null,aShape);
}
/**
* modify an object's 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 aShape An abstract shape that to be modified properties.
* @return True if properties changed, false otherwise.
*/
public static boolean getNewProperties(Frame modalFrame,Component refComp,AbstractShape aShape) {
return showDialog(modalFrame,refComp,aShape);
}
/**
* 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,
AbstractShape aShape) {
Frame frame = JOptionPane.getFrameForComponent(frameComp);
m_dialog = new PropertyDialog(frame,
locationComp,
CADResource.getString("dialog.property"),
aShape);
m_dialog.setVisible(true);
return m_propertiesChanged;
}
private PropertyDialog(Frame frame,
Component locationComp,
String title,
AbstractShape aShape) {
super(frame, title, true);
//setResizable(false);
try{
m_shape =aShape;
m_currentProperties =(ObjectList)aShape.getPropertyList().clone();
}catch(Exception e){
}
Dimension buttonSize =new Dimension(120,25);
//Create and initialize the buttons.
JButton cancelButton = new JButton(CADResource.getString("button.cancel"));
cancelButton.setFont(GUIConst.FONT_BUTTON);
cancelButton.setActionCommand("Cancel");
cancelButton.addActionListener(this);
cancelButton.setPreferredSize(buttonSize);
confirmButton = new JButton(CADResource.getString("button.confirm"));
confirmButton.setFont(GUIConst.FONT_BUTTON);
confirmButton.setActionCommand("Confirm");
confirmButton.addActionListener(this);
confirmButton.setPreferredSize(buttonSize);
getRootPane().setDefaultButton(confirmButton);
JButton newButton = new JButton(CADResource.getString("button.new"));
newButton.setFont(GUIConst.FONT_BUTTON);
newButton.setActionCommand("New");
newButton.setPreferredSize(buttonSize);
newButton.addActionListener(this);
JButton removeButton = new JButton(CADResource.getString("button.remove"));
removeButton.setFont(GUIConst.FONT_BUTTON);
removeButton.setActionCommand("Remove");
removeButton.setPreferredSize(buttonSize);
removeButton.addActionListener(this);
//main part of the dialog
Dimension tableSize =new Dimension(400,200);
m_tableModel =new MyTableModel(m_currentProperties);
m_table = new JTable(m_tableModel);
m_table.setPreferredScrollableViewportSize(tableSize);
m_table.setPreferredSize(tableSize);
m_table.setRowHeight(20);
//Set up column sizes.
initColumnSizes(m_table);
//Fiddle with the type column's cell editors/renderers.
setTypeComboColumn(m_table, m_table.getColumnModel().getColumn(1));
int rowId=m_table.getRowCount()-1;
m_table.setRowSelectionInterval(rowId,rowId);
//Create the scroll pane and add the table to it.
JScrollPane sPane = new JScrollPane(m_table);
//sPane.setMinimumSize(tableSize);
//sPane.setPreferredSize(tableSize);
//sPane.setMaximumSize(tableSize);
sPane.setAlignmentX(LEFT_ALIGNMENT);
//Create a container so that we can add a title around
//the scroll pane. Can't add a title directly to the
//scroll pane because its background would be white.
//Lay out the aLabel and scroll pane from top to bottom.
JPanel propertyPane = new JPanel();
propertyPane.setLayout(new BoxLayout(propertyPane, BoxLayout.Y_AXIS));
JLabel aLabel = new JLabel(CADResource.getString("label.property.propertylist"));
aLabel.setFont(GUIConst.FONT_LABEL);
propertyPane.add(aLabel);
propertyPane.add(Box.createRigidArea(new Dimension(0,5)));
propertyPane.add(sPane);
propertyPane.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(0, 10, 10, 10));
buttonPane.add(Box.createRigidArea(new Dimension(20, 0)));
buttonPane.add(newButton);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(removeButton);
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(propertyPane, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.SOUTH);
pack();
setSize(new Dimension(400,300));
setResizable(false);
setLocationRelativeTo(locationComp);
}
private void stopEditing(){
//stupid two methods to stop editing below.
m_table.editCellAt(0,0);
m_table.editCellAt(0,1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -