Browse Source

REPORT-4308 单元格属性-样式,修改文本自定义样式无法实时生效

master
MoMeak 7 years ago
parent
commit
5abfa98b1a
  1. 125
      designer_base/src/com/fr/design/gui/icombobox/TextFontComboBox.java
  2. 15
      designer_base/src/com/fr/design/gui/style/FormatPane.java

125
designer_base/src/com/fr/design/gui/icombobox/TextFontComboBox.java

@ -0,0 +1,125 @@
package com.fr.design.gui.icombobox;
import com.fr.design.gui.icombobox.filter.Filter;
import com.fr.design.gui.icombobox.filter.StartsWithFilter;
import com.fr.design.gui.itextfield.UITextField;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
/**
* Created by MoMeak on 2017/9/5.
*/
public class TextFontComboBox<T> extends ExtendedComboBox{
private Filter filter;
public TextFontComboBox() {
this(new ArrayList<T>());
this.setEditable(true);
}
public TextFontComboBox(List<T> itemList) {
this(new StartsWithFilter(), itemList);
}
public TextFontComboBox(Filter filter, List<T> itemList) {
this.filter = filter;
setModel(new FilterableComboBoxModel(itemList));
setEditor(new TextFontComboBox.FilterComboBoxEditor());
setEditable(true);
}
public void setItemArray(T[] objectArray) {
List<T> itemList = new ArrayList<T>();
if(objectArray != null) {
for(int i = 0; i < objectArray.length; i++) {
itemList.add(objectArray[i]);
}
}
this.setItemList(itemList);
}
public void setItemList(List<T> itemList) {
((FilterableComboBoxModel)this.getModel()).setPrefix("");
((FilterableComboBoxModel)this.getModel()).setItemList(itemList);
}
class FilterComboBoxEditor implements ComboBoxEditor, DocumentListener {
private Object item;
public UITextField textField;
private volatile boolean filtering = false;
private volatile boolean setting = false;
public FilterComboBoxEditor() {
textField = new UITextField(15);
textField.getDocument().addDocumentListener(this);
}
public Component getEditorComponent() {
return textField;
}
public void setItem(Object item) {
if (filtering) {
return;
}
this.item = item;
this.setting = true;
String newText = (item == null) ? "" : item.toString();
textField.setText(newText);
this.setting = false;
}
public Object getItem() {
return this.item;
}
public void selectAll() {
textField.selectAll();
}
public void addActionListener(ActionListener l) {
textField.addActionListener(l);
}
public void removeActionListener(ActionListener l) {
textField.removeActionListener(l);
}
public void insertUpdate(DocumentEvent e) {
handleChange();
}
public void removeUpdate(DocumentEvent e) {
handleChange();
}
public void changedUpdate(DocumentEvent e) {
handleChange();
}
protected void handleChange() {
if (setting) {
return;
}
filtering = true;
((FilterableComboBoxModel) getModel()).setSelectedItem(textField.getText());
this.item = textField.getText();
setPopupVisible(true);
filtering = false;
}
}
}

15
designer_base/src/com/fr/design/gui/style/FormatPane.java

@ -9,8 +9,7 @@ import com.fr.data.core.FormatField.FormatContents;
import com.fr.design.border.UIRoundedBorder; import com.fr.design.border.UIRoundedBorder;
import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.LayoutConstants;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.*;
import com.fr.design.gui.icombobox.UIComboBoxRenderer;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
@ -22,6 +21,8 @@ import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.text.Format; import java.text.Format;
@ -51,7 +52,7 @@ public class FormatPane extends AbstractBasicStylePane {
private Format format; private Format format;
private UIComboBox typeComboBox; private UIComboBox typeComboBox;
private UIComboBox textField; private TextFontComboBox textField;
private UILabel sampleLabel; private UILabel sampleLabel;
private JPanel contentPane; private JPanel contentPane;
private JPanel txtCenterPane; private JPanel txtCenterPane;
@ -89,7 +90,8 @@ public class FormatPane extends AbstractBasicStylePane {
contentPane.add(sampleLabel, BorderLayout.NORTH); contentPane.add(sampleLabel, BorderLayout.NORTH);
txtCenterPane = new JPanel(new BorderLayout()); txtCenterPane = new JPanel(new BorderLayout());
textField = new UIComboBox(FormatField.getInstance().getFormatArray(getFormatContents())); textField = new TextFontComboBox();
// textField.setItemArray(FormatField.getInstance().getFormatArray(getFormatContents()));
textField.addItemListener(textFieldItemListener); textField.addItemListener(textFieldItemListener);
textField.setEditable(true); textField.setEditable(true);
txtCenterPane.add(textField, BorderLayout.NORTH); txtCenterPane.add(textField, BorderLayout.NORTH);
@ -322,9 +324,8 @@ public class FormatPane extends AbstractBasicStylePane {
cardLayout.show(centerPane, "hide"); cardLayout.show(centerPane, "hide");
} else { } else {
textField.removeAllItems(); textField.removeAllItems();
for (int i = 0; i < items.length; i++) { textField.setItemArray(items);
textField.addItem(items[i]); textField.setSelectedIndex(0);
}
centerPane.setPreferredSize(new Dimension(270, 65)); centerPane.setPreferredSize(new Dimension(270, 65));
cardLayout.show(centerPane, "show"); cardLayout.show(centerPane, "show");
} }

Loading…
Cancel
Save