|
|
|
@ -10,17 +10,23 @@ import com.fr.design.hyperlink.ReportletHyperlinkPane;
|
|
|
|
|
import com.fr.design.hyperlink.WebHyperlinkPane; |
|
|
|
|
import com.fr.design.javascript.EmailPane; |
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
|
|
|
|
|
import com.fr.js.EmailJavaScript; |
|
|
|
|
import com.fr.js.ReportletHyperlink; |
|
|
|
|
import com.fr.js.WebHyperlink; |
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.JComponent; |
|
|
|
|
import javax.swing.JFrame; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.JTable; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
|
import javax.swing.plaf.TableUI; |
|
|
|
|
import javax.swing.table.TableCellRenderer; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
@ -35,11 +41,11 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void populateBean(List<UIMenuNameableCreator> values) { |
|
|
|
|
((UIMenuTableDataModel)dataModel).populateBean(values); |
|
|
|
|
((UIMenuTableDataModel) dataModel).populateBean(values); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public List<UIMenuNameableCreator> updateBean() { |
|
|
|
|
return ((UIMenuTableDataModel)dataModel).updateBean(); |
|
|
|
|
return ((UIMenuTableDataModel) dataModel).updateBean(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void editingEvent(int rowIndex, int mouseY) { |
|
|
|
@ -68,7 +74,7 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected Color getRenderBackground(int row) { |
|
|
|
|
if(selectedRowIndex == row ) { |
|
|
|
|
if (selectedRowIndex == row) { |
|
|
|
|
return UIConstants.SKY_BLUE; |
|
|
|
|
} else { |
|
|
|
|
return (rollOverRowIndex == row) ? UIConstants.LIGHT_BLUE : UIConstants.NORMAL_BACKGROUND; |
|
|
|
@ -76,15 +82,14 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @param value 该行列的值(字符串) |
|
|
|
|
* @param row |
|
|
|
|
* @param column |
|
|
|
|
* @return 列表中默认显示的东西,如果有很多内容,可以装载一个JPanel里再嵌进来 |
|
|
|
|
*/ |
|
|
|
|
protected JComponent getRenderCompoment(Object value, int row,int column) { |
|
|
|
|
protected JComponent getRenderCompoment(Object value, int row, int column) { |
|
|
|
|
UILabel text = new UILabel(); |
|
|
|
|
if(value != null) { |
|
|
|
|
if (value != null) { |
|
|
|
|
text.setText(value.toString()); |
|
|
|
|
} |
|
|
|
|
return text; |
|
|
|
@ -95,7 +100,7 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
* 在table底部增加一行内容 |
|
|
|
|
*/ |
|
|
|
|
public void addLine(UIMenuNameableCreator line) { |
|
|
|
|
((UIMenuTableDataModel)dataModel).addLine(line); |
|
|
|
|
((UIMenuTableDataModel) dataModel).addLine(line); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -103,15 +108,16 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
* @return 某一行的内容 |
|
|
|
|
*/ |
|
|
|
|
public UIMenuNameableCreator getLine(int rowIndex) { |
|
|
|
|
return ((UIMenuTableDataModel)dataModel).getLine(rowIndex); |
|
|
|
|
return ((UIMenuTableDataModel) dataModel).getLine(rowIndex); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除某行内容 |
|
|
|
|
* |
|
|
|
|
* @param rowIndex |
|
|
|
|
*/ |
|
|
|
|
public void removeLine(int rowIndex) { |
|
|
|
|
((UIMenuTableDataModel)dataModel).removeLine(rowIndex); |
|
|
|
|
((UIMenuTableDataModel) dataModel).removeLine(rowIndex); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -119,23 +125,24 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
*/ |
|
|
|
|
public void clearAll() { |
|
|
|
|
int rowCount = dataModel.getRowCount(); |
|
|
|
|
for(int i = 0; i < rowCount; i++) { |
|
|
|
|
for (int i = 0; i < rowCount; i++) { |
|
|
|
|
removeLine(i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 对某一行拖动时进行排序 |
|
|
|
|
* |
|
|
|
|
* @param rowIndex |
|
|
|
|
* @param positive 鼠标移动的距离 |
|
|
|
|
*/ |
|
|
|
|
public void dragSort(int rowIndex, boolean positive) { |
|
|
|
|
((UIMenuTableDataModel)dataModel).dragSort(rowIndex, positive); |
|
|
|
|
((UIMenuTableDataModel) dataModel).dragSort(rowIndex, positive); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean isCellEditable(int row, int column) { |
|
|
|
|
if(column == 0) { |
|
|
|
|
if (column == 0) { |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
return super.isCellEditable(row, column); |
|
|
|
@ -157,7 +164,16 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public TableCellRenderer getDefaultRenderer(Class<?> columnClass) { |
|
|
|
|
return super.getDefaultRenderer(UITable.class); |
|
|
|
|
// 处理null的情况用于创建时未指定数据结构的情况
|
|
|
|
|
if (columnClass == null) { |
|
|
|
|
return createDefaultRenderer(); |
|
|
|
|
} |
|
|
|
|
return super.getDefaultRenderer(columnClass); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private @NotNull TableCellRenderer createDefaultRenderer() { |
|
|
|
|
Object renderer = defaultRenderersByColumnClass.get(UITable.class); |
|
|
|
|
return renderer != null ? (TableCellRenderer) renderer : new UITableRender(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private class UITableRender implements TableCellRenderer { |
|
|
|
@ -165,11 +181,11 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
public Component getTableCellRendererComponent(JTable table, |
|
|
|
|
Object value, boolean isSelected, boolean hasFocus, int row, |
|
|
|
|
int column) { |
|
|
|
|
JPanel pane = new JPanel(new BorderLayout(4,0)); |
|
|
|
|
JPanel pane = new JPanel(new BorderLayout(4, 0)); |
|
|
|
|
Color back = getRenderBackground(row); |
|
|
|
|
pane.setBackground(back); |
|
|
|
|
|
|
|
|
|
if(draggingIndex == row) { |
|
|
|
|
if (draggingIndex == row) { |
|
|
|
|
return pane; |
|
|
|
|
} |
|
|
|
|
pane.add(getRenderCompoment(value, row, column), BorderLayout.CENTER); |
|
|
|
@ -191,7 +207,7 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
|
|
|
|
|
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
|
|
|
|
if (listeners[i] == ChangeListener.class) { |
|
|
|
|
((ChangeListener)listeners[i + 1]).stateChanged(new ChangeEvent(this)); |
|
|
|
|
((ChangeListener) listeners[i + 1]).stateChanged(new ChangeEvent(this)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -207,7 +223,7 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
public static void main(String... args) { |
|
|
|
|
JFrame jf = new JFrame("test"); |
|
|
|
|
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
|
JPanel content = (JPanel)jf.getContentPane(); |
|
|
|
|
JPanel content = (JPanel) jf.getContentPane(); |
|
|
|
|
content.setLayout(new BorderLayout()); |
|
|
|
|
List<UIMenuNameableCreator> data = new ArrayList<UIMenuNameableCreator>(); |
|
|
|
|
UIMenuNameableCreator reportlet = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Reportlet"), |
|
|
|
@ -217,7 +233,7 @@ public class UIMenuTable extends JTable {
|
|
|
|
|
new EmailJavaScript(), EmailPane.class); |
|
|
|
|
|
|
|
|
|
UIMenuNameableCreator web = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Web_Link"), |
|
|
|
|
new WebHyperlink(), WebHyperlinkPane.class ); |
|
|
|
|
new WebHyperlink(), WebHyperlinkPane.class); |
|
|
|
|
data.add(reportlet); |
|
|
|
|
data.add(email); |
|
|
|
|
data.add(web); |
|
|
|
|