You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
6.2 KiB
169 lines
6.2 KiB
package com.fr.design.sort.common; |
|
|
|
import com.fr.base.svg.IconUtils; |
|
import com.fr.design.designer.TargetComponent; |
|
import com.fr.design.event.UIObserverListener; |
|
import com.fr.design.file.HistoryTemplateListCache; |
|
import com.fr.design.gui.ibutton.UIButton; |
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.design.mainframe.ElementCasePane; |
|
import com.fr.design.selection.SelectionEvent; |
|
import com.fr.design.selection.SelectionListener; |
|
import com.fr.grid.selection.CellSelection; |
|
import com.fr.grid.selection.Selection; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.stable.ColumnRow; |
|
import com.fr.stable.EssentialUtils; |
|
import com.fr.stable.StringUtils; |
|
|
|
import javax.swing.*; |
|
import java.awt.*; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
|
|
public class SortColumnRowPane extends JPanel { |
|
int paneWidth; |
|
int paneHeight; |
|
int jTextFieldWidth; |
|
JTextField colJTextField; |
|
JTextField rowJTextField; |
|
UIButton selectButton; |
|
private boolean isAlreadyAddListener = false; |
|
private CellSelection oldSelection; |
|
private SelectionListener gridSelectionChangeListener; |
|
UIObserverListener uiObserverListener; |
|
|
|
public SortColumnRowPane(int paneWidth, int paneHeight) { |
|
this.paneWidth = paneWidth; |
|
this.paneHeight = paneHeight; |
|
initComponents(); |
|
} |
|
|
|
private void initComponents() { |
|
initSize(); |
|
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
|
intUILabel(); |
|
initTextField(); |
|
initSelectButton(); |
|
this.setSize(new Dimension(paneWidth, paneHeight)); |
|
} |
|
|
|
void initSize() { |
|
jTextFieldWidth = (paneWidth - 40) / 2; |
|
} |
|
|
|
void intUILabel() { |
|
UILabel uiLabel = new UILabel(IconUtils.readIcon("/com/fr/design/images/buttonicon/propertiestab/cellelement_normal.png")); |
|
this.add(uiLabel); |
|
} |
|
|
|
public static boolean isAvailableColumnRow(ColumnRow columnRow) { |
|
return columnRow != null && columnRow.getRow() != -1 && columnRow.getColumn() != -1; |
|
} |
|
|
|
|
|
void initTextField() { |
|
colJTextField = new JTextField(); |
|
colJTextField.setEditable(false); |
|
rowJTextField = new JTextField(); |
|
rowJTextField.setEditable(false); |
|
colJTextField.setPreferredSize(new Dimension(jTextFieldWidth, paneHeight)); |
|
rowJTextField.setPreferredSize(new Dimension(jTextFieldWidth, paneHeight)); |
|
this.add(colJTextField); |
|
this.add(rowJTextField); |
|
} |
|
|
|
void initSelectButton() { |
|
selectButton = new UIButton(IconUtils.readIcon("/com/fr/design/images/buttonicon/select.png")); |
|
selectButton.addActionListener(new SelectActionListener(this)); |
|
this.add(selectButton); |
|
} |
|
|
|
public void populateBean(ColumnRow columnRow) { |
|
if (SortColumnRowPane.isAvailableColumnRow(columnRow)) { |
|
colJTextField.setText(EssentialUtils.convertIntToABC(columnRow.column + 1)); |
|
rowJTextField.setText(String.valueOf(columnRow.row + 1)); |
|
} else { |
|
colJTextField.setText(StringUtils.EMPTY); |
|
rowJTextField.setText(StringUtils.EMPTY); |
|
} |
|
refresh(); |
|
} |
|
|
|
public ColumnRow updateBean() { |
|
if (StringUtils.isNotBlank(colJTextField.getText()) && StringUtils.isNotBlank(rowJTextField.getText())) { |
|
return ColumnRow.valueOf(colJTextField.getText() + rowJTextField.getText()); |
|
} |
|
return null; |
|
} |
|
|
|
class SelectActionListener implements ActionListener { |
|
SortColumnRowPane columnRowPane; |
|
|
|
SelectActionListener(SortColumnRowPane columnRowPane) { |
|
this.columnRowPane = columnRowPane; |
|
} |
|
|
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
ElementCasePane elementCasePane = getCurrentElementCase(); |
|
if (elementCasePane == null || isAlreadyAddListener) { |
|
return; |
|
} |
|
oldSelection = (CellSelection) elementCasePane.getSelection(); |
|
elementCasePane.getGrid().setNotShowingTableSelectPane(false); |
|
elementCasePane.setEditable(false); |
|
elementCasePane.repaint(10); |
|
|
|
gridSelectionChangeListener = new SelectionListener() { |
|
@Override |
|
public void selectionChanged(SelectionEvent e) { |
|
Selection selection = elementCasePane.getSelection(); |
|
if (selection instanceof CellSelection) { |
|
CellSelection cellselection = (CellSelection) selection; |
|
ColumnRow cr = ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow()); |
|
elementCasePane.setOldSelecton(oldSelection); |
|
columnRowPane.populateBean(cr); |
|
if (columnRowPane.uiObserverListener != null) { |
|
columnRowPane.uiObserverListener.doChange(); |
|
} |
|
} |
|
elementCasePane.removeSelectionChangeListener(gridSelectionChangeListener); |
|
isAlreadyAddListener = false; |
|
elementCasePane.getGrid().setNotShowingTableSelectPane(true); |
|
elementCasePane.setEditable(true); |
|
elementCasePane.repaint(); |
|
} |
|
}; |
|
elementCasePane.addSelectionChangeListener(gridSelectionChangeListener); |
|
isAlreadyAddListener = true; |
|
} |
|
} |
|
|
|
private ElementCasePane getCurrentElementCase() { |
|
try { |
|
TargetComponent targetComponent |
|
= HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane(); |
|
if (targetComponent instanceof ElementCasePane) { |
|
return (ElementCasePane) targetComponent; |
|
} |
|
} catch (Exception e) { |
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
} |
|
return null; |
|
} |
|
|
|
public void addListener(UIObserverListener uiObserverListener) { |
|
this.uiObserverListener = uiObserverListener; |
|
} |
|
|
|
public void removeListener(UIObserverListener uiObserverListener) { |
|
this.uiObserverListener = null; |
|
} |
|
|
|
protected void refresh() { |
|
validate(); |
|
repaint(); |
|
revalidate(); |
|
} |
|
} |