Browse Source

REPORT-6700 REPORT-8957 REPORT-8941 REPORT-7941 REPORT-8392

master
yaoh.wu 6 years ago
parent
commit
952b2c7102
  1. 65
      designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java
  2. 53
      designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java
  3. 15
      designer-base/src/main/java/com/fr/design/gui/itree/checkboxtree/CheckBoxTreeCellRenderer.java
  4. 14
      designer-base/src/main/java/com/fr/design/gui/itree/checkboxtree/NullTristateCheckBox.java
  5. 201
      designer-base/src/main/java/com/fr/design/gui/itree/checkboxtree/TristateCheckBox.java
  6. 133
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/EnvFileTree.java
  7. 32
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileTreeIcon.java
  8. 29
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java
  9. 27
      designer-base/src/main/java/com/fr/design/gui/itree/refreshabletree/ExpandMutableTreeNode.java
  10. 52
      designer-base/src/main/java/com/fr/design/gui/itree/refreshabletree/RefreshableJTree.java
  11. 4
      designer-base/src/main/java/com/fr/design/remote/ui/AuthorityEditorPane.java
  12. BIN
      designer-base/src/main/resources/com/fr/design/images/gui/filetree_folder_half_authority_normal.png

65
designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java

@ -23,9 +23,13 @@ import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import javax.swing.*; import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.ToolTipManager;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
@ -59,9 +63,27 @@ public class TemplateTreePane extends JPanel implements FileOperations {
scrollPane.setBorder(null); scrollPane.setBorder(null);
contentPane.add(scrollPane, BorderLayout.CENTER); contentPane.add(scrollPane, BorderLayout.CENTER);
this.reportletsTree.addMouseListener(mouseFileTreeListener);// lx: add /*
// mouse * Tree.MouseAdapter
// listener */
MouseListener mouseFileTreeListener = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent evt) {
if (evt.getClickCount() == 2) {
openSelectedReport();
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (toobarStateChangeListener != null) {
toobarStateChangeListener.stateChange();
}
}
};
// lx: add mouse listener
this.reportletsTree.addMouseListener(mouseFileTreeListener);
this.reportletsTree.addKeyListener(new KeyListener() { this.reportletsTree.addKeyListener(new KeyListener() {
@Override @Override
@ -102,42 +124,21 @@ public class TemplateTreePane extends JPanel implements FileOperations {
reportletsTree.refreshEnv(); reportletsTree.refreshEnv();
} }
/*
* Tree.MouseAdapter
*/
MouseListener mouseFileTreeListener = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent evt) {
if (SwingUtilities.isRightMouseButton(evt)) {
return;
} else if (evt.getClickCount() == 2) {
openSelectedReport();
}
}
public void mouseReleased(MouseEvent e) {
if (toobarStateChangeListener != null) {
toobarStateChangeListener.stateChange();
}
}
};
/** /**
* 打开选中的报表文件 * 打开选中的报表文件
*/ */
@Override
public void openSelectedReport() { public void openSelectedReport() {
String reportPath = reportletsTree.getSelectedTemplatePath(); String reportPath = reportletsTree.getSelectedTemplatePath();
final String selectedFilePath = StableUtils.pathJoin(new String[]{ProjectConstants.REPORTLETS_NAME, reportPath}); final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath);
DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(selectedFilePath, false))); DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(selectedFilePath, false)));
} }
/** /**
* 打开文件夹 * 打开文件夹
*/ */
@Override
public void openContainerFolder() { public void openContainerFolder() {
FileNode fn = TemplateTreePane.this.reportletsTree.getSelectedFileNode(); FileNode fn = TemplateTreePane.this.reportletsTree.getSelectedFileNode();
String filePath = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), fn.getEnvPath()); String filePath = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), fn.getEnvPath());
@ -152,6 +153,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
/** /**
* 刷新 * 刷新
*/ */
@Override
public void refresh() { public void refresh() {
reportletsTree.refresh(); reportletsTree.refresh();
FineLoggerFactory.getLogger().info(Inter.getLocText(new String[]{"File-tree", "Refresh_Successfully"}) + "!"); FineLoggerFactory.getLogger().info(Inter.getLocText(new String[]{"File-tree", "Refresh_Successfully"}) + "!");
@ -160,6 +162,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
/** /**
* 删除文件 * 删除文件
*/ */
@Override
public void deleteFile() { public void deleteFile() {
String[] reportPaths = reportletsTree.getSelectedTemplatePaths(); String[] reportPaths = reportletsTree.getSelectedTemplatePaths();
if (reportPaths.length == 0) { if (reportPaths.length == 0) {
@ -169,7 +172,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
return; return;
} }
for (String reportPath : reportPaths) { for (String reportPath : reportPaths) {
FileNodeFILE nodeFile = new FileNodeFILE(new FileNode(StableUtils.pathJoin(new String[]{ProjectConstants.REPORTLETS_NAME, reportPath}), false)); FileNodeFILE nodeFile = new FileNodeFILE(new FileNode(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath), false));
if (nodeFile.isLocked()) { if (nodeFile.isLocked()) {
if (JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("fileLocked_undeleted"), if (JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("fileLocked_undeleted"),
@ -226,6 +229,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
} }
@Override
public String getSelectedTemplatePath() { public String getSelectedTemplatePath() {
return reportletsTree.getSelectedTemplatePath(); return reportletsTree.getSelectedTemplatePath();
} }
@ -242,6 +246,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
* @param suffix 后缀名 * @param suffix 后缀名
* @return 是否存在 * @return 是否存在
*/ */
@Override
public boolean isNameAlreadyExist(String newName, String oldName, String suffix) { public boolean isNameAlreadyExist(String newName, String oldName, String suffix) {
boolean isNameAlreadyExist = false; boolean isNameAlreadyExist = false;

53
designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java

@ -5,16 +5,27 @@ import com.fr.design.event.GlobalNameListener;
import com.fr.design.event.GlobalNameObserver; import com.fr.design.event.GlobalNameObserver;
import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener; import com.fr.design.event.UIObserverListener;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.design.utils.gui.GUIPaintUtils; import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
import javax.swing.*; import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.plaf.basic.BasicHTML; import javax.swing.plaf.basic.BasicHTML;
import javax.swing.plaf.metal.MetalCheckBoxUI; import javax.swing.plaf.metal.MetalCheckBoxUI;
import javax.swing.text.View; import javax.swing.text.View;
import java.awt.*; import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
@ -70,11 +81,13 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser
* *
* @param listener 观察者监听事件 * @param listener 观察者监听事件
*/ */
@Override
public void registerChangeListener(UIObserverListener listener) { public void registerChangeListener(UIObserverListener listener) {
this.uiObserverListener = listener; this.uiObserverListener = listener;
} }
@Override
public void setGlobalName(String name) { public void setGlobalName(String name) {
checkboxName = name; checkboxName = name;
} }
@ -84,27 +97,33 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser
* *
* @return 如果需要响应观察者事件则返回true否则返回false * @return 如果需要响应观察者事件则返回true否则返回false
*/ */
@Override
public boolean shouldResponseChangeListener() { public boolean shouldResponseChangeListener() {
return true; return true;
} }
/** /**
* 注册观察者监听事件 * 注册观察者监听事件
*
* @param listener 观察者监听事件 * @param listener 观察者监听事件
*/ */
@Override
public void registerNameListener(GlobalNameListener listener) { public void registerNameListener(GlobalNameListener listener) {
globalNameListener = listener; globalNameListener = listener;
} }
/** /**
* 组件是否需要响应观察者事件 * 组件是否需要响应观察者事件
*
* @return 如果需要响应观察者事件则返回true否则返回false * @return 如果需要响应观察者事件则返回true否则返回false
*/ */
@Override
public boolean shouldResponseNameListener() { public boolean shouldResponseNameListener() {
return true; return true;
} }
private class UICheckBoxUI extends MetalCheckBoxUI { private class UICheckBoxUI extends MetalCheckBoxUI {
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
synchronized (this) { synchronized (this) {
AbstractButton b = (AbstractButton) c; AbstractButton b = (AbstractButton) c;
@ -140,13 +159,13 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if ( model.isSelected()) { if (model.isSelected()) {
GUIPaintUtils.fillPaint(g2d, iconRect.x, iconRect.y, iconRect.width, iconRect.height,false, Constants.NULL, GUIPaintUtils.fillPaint(g2d, iconRect.x, iconRect.y, iconRect.width, iconRect.height, false, Constants.NULL,
model.isEnabled() ? UIConstants.CHECKBOX_HOVER_SELECTED : UIConstants.DISABLED_ICON_COLOR, 0); model.isEnabled() ? UIConstants.CHECKBOX_HOVER_SELECTED : UIConstants.DISABLED_ICON_COLOR, 0);
} else if (model.isRollover() && ! model.isSelected()) { } else if (model.isRollover() && !model.isSelected()) {
g.setColor(UIConstants.CHECKBOX_HOVER_SELECTED); g.setColor(UIConstants.CHECKBOX_HOVER_SELECTED);
g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC); g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC);
}else{ } else {
g.setColor(UIConstants.LINE_COLOR); g.setColor(UIConstants.LINE_COLOR);
g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC); g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC);
} }
@ -180,24 +199,4 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser
} }
} }
/**
* 测试
* @param args 参数
*/
public static void main(String... args) {
LayoutManager layoutManager = null;
JFrame jf = new JFrame("test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel content = (JPanel) jf.getContentPane();
content.setLayout(layoutManager);
UICheckBox bb = new UICheckBox("sdf");
bb.setEnabled(false);
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height);
content.add(bb);
GUICoreUtils.centerWindow(jf);
jf.setSize(400, 400);
jf.setVisible(true);
}
} }

15
designer-base/src/main/java/com/fr/design/gui/itree/checkboxtree/CheckBoxTreeCellRenderer.java

@ -10,12 +10,17 @@ import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.*; import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JTree;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.Serializable; import java.io.Serializable;
@ -77,10 +82,10 @@ public class CheckBoxTreeCellRenderer extends NullPanel implements TreeCellRende
_checkBox.setEnabled(((CheckBoxTree) tree).isCheckBoxEnabled() && ((CheckBoxTree) tree).isCheckBoxEnabled(path)); _checkBox.setEnabled(((CheckBoxTree) tree).isCheckBoxEnabled() && ((CheckBoxTree) tree).isCheckBoxEnabled(path));
if (selectionModel.isPathSelected(path, selectionModel.isDigIn())) { if (selectionModel.isPathSelected(path, selectionModel.isDigIn())) {
_checkBox.setState(TristateCheckBox.SELECTED); _checkBox.setState(TristateCheckBox.SELECTED);
_checkBox.setSelected(true); } else if (selectionModel.isDigIn() && selectionModel.isPartiallySelected(path)) {
_checkBox.setState(TristateCheckBox.DO_NOT_CARE);
} else { } else {
_checkBox.setState(selectionModel.isDigIn() && selectionModel.isPartiallySelected(path) ? null : TristateCheckBox.NOT_SELECTED); _checkBox.setState(TristateCheckBox.NOT_SELECTED);
_checkBox.setSelected(false);
} }
} }
} }

14
designer-base/src/main/java/com/fr/design/gui/itree/checkboxtree/NullTristateCheckBox.java

@ -42,10 +42,7 @@ import javax.swing.Icon;
* </code></pre> * </code></pre>
* *
* @see NullPanel * @see NullPanel
* @see NullButton
* @see NullJideButton
* @see NullLabel * @see NullLabel
* @see NullRadioButton
*/ */
public class NullTristateCheckBox extends TristateCheckBox { public class NullTristateCheckBox extends TristateCheckBox {
public NullTristateCheckBox() { public NullTristateCheckBox() {
@ -63,7 +60,7 @@ public class NullTristateCheckBox extends TristateCheckBox {
super(text, icon, initial); super(text, icon, initial);
} }
// @Override @Override
public void updateUI() { public void updateUI() {
clearAttribute(); clearAttribute();
} }
@ -73,4 +70,13 @@ public class NullTristateCheckBox extends TristateCheckBox {
setBackground(null); setBackground(null);
setForeground(null); setForeground(null);
} }
@Override
protected State getNextState(State current) {
if (SELECTED.equals(current)) {
return NOT_SELECTED;
} else {
return SELECTED;
}
}
} }

201
designer-base/src/main/java/com/fr/design/gui/itree/checkboxtree/TristateCheckBox.java

@ -1,28 +1,44 @@
package com.fr.design.gui.itree.checkboxtree; package com.fr.design.gui.itree.checkboxtree;
import java.awt.event.ActionEvent; import com.fr.design.constants.UIConstants;
import java.awt.event.ActionListener; import com.fr.design.gui.icheckbox.UICheckBox;
import java.awt.event.ItemListener; import com.fr.design.utils.gui.GUIPaintUtils;
import java.awt.event.MouseAdapter; import com.fr.stable.Constants;
import java.awt.event.MouseEvent; import sun.swing.SwingUtilities2;
import java.awt.event.MouseListener;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.ActionMap; import javax.swing.ActionMap;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
import javax.swing.ButtonModel; import javax.swing.ButtonModel;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.plaf.ActionMapUIResource; import javax.swing.plaf.ActionMapUIResource;
import javax.swing.plaf.basic.BasicHTML;
import com.fr.design.gui.icheckbox.UICheckBox; import javax.swing.plaf.metal.MetalCheckBoxUI;
import javax.swing.text.View;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/** /**
* Maintenance tip - There were some tricks to getting this code * Maintenance tip - There were some tricks to getting this code
* working: * working:
* <p/> * <p/>
* 1. You have to overwite addMouseListener() to do nothing * 1. You have to overwrite addMouseListener() to do nothing
* 2. You have to add a mouse event on mousePressed by calling * 2. You have to add a mouse event on mousePressed by calling
* super.addMouseListener() * super.addMouseListener()
* 3. You have to replace the UIActionMap for the keyboard event * 3. You have to replace the UIActionMap for the keyboard event
@ -41,21 +57,30 @@ public class TristateCheckBox extends UICheckBox {
* This is a type-safe enumerated type * This is a type-safe enumerated type
*/ */
public static class State { public static class State {
private State() { private String type;
private State(String type) {
this.type = type;
}
@Override
public String toString() {
return this.type;
} }
} }
public static final State NOT_SELECTED = new State(); public static final State NOT_SELECTED = new State("NOT_SELECTED");
public static final State SELECTED = new State(); public static final State SELECTED = new State("SELECTED");
public static final State DONT_CARE = new State(); public static final State DO_NOT_CARE = new State("DO_NOT_CARE");
private final TristateDecorator model; private final TristateDecorator model;
public TristateCheckBox(String text, Icon icon, State initial) { public TristateCheckBox(String text, Icon icon, State initial) {
super(text, icon); super(text, icon);
setUI(new TristateUICheckBoxUI());
// Add a listener for when the mouse is pressed // Add a listener for when the mouse is pressed
super.addMouseListener(new MouseAdapter() { super.addMouseListener(new MouseAdapter() {
// @Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
grabFocus(); grabFocus();
model.setState(getNextState(model.getState())); model.setState(getNextState(model.getState()));
@ -64,6 +89,7 @@ public class TristateCheckBox extends UICheckBox {
// Reset the keyboard action map // Reset the keyboard action map
ActionMap map = new ActionMapUIResource(); ActionMap map = new ActionMapUIResource();
map.put("pressed", new AbstractAction() { map.put("pressed", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
grabFocus(); grabFocus();
model.setState(getNextState(model.getState())); model.setState(getNextState(model.getState()));
@ -79,26 +105,29 @@ public class TristateCheckBox extends UICheckBox {
public TristateCheckBox(String text, State initial) { public TristateCheckBox(String text, State initial) {
this(text, null, initial); this(text, null, initial);
setUI(new TristateUICheckBoxUI());
} }
public TristateCheckBox(String text) { public TristateCheckBox(String text) {
this(text, DONT_CARE); this(text, DO_NOT_CARE);
setUI(new TristateUICheckBoxUI());
} }
public TristateCheckBox() { public TristateCheckBox() {
this(null); this(null);
setUI(new TristateUICheckBoxUI());
} }
/** /**
* No one may add mouse listeners, not even Swing! * No one may add mouse listeners, not even Swing!
*/ */
// @Override @Override
public void addMouseListener(MouseListener l) { public void addMouseListener(MouseListener l) {
} }
/** /**
* Set the new state to either SELECTED, NOT_SELECTED or * Set the new state to either SELECTED, NOT_SELECTED or
* DONT_CARE. If state == null, it is treated as DONT_CARE. * DO_NOT_CARE. If state == null, it is treated as DO_NOT_CARE.
*/ */
public void setState(State state) { public void setState(State state) {
model.setState(state); model.setState(state);
@ -112,15 +141,6 @@ public class TristateCheckBox extends UICheckBox {
return model.getState(); return model.getState();
} }
// @Override
public void setSelected(boolean b) {
if (b) {
setState(SELECTED);
}
else {
setState(NOT_SELECTED);
}
}
/** /**
* Exactly which Design Pattern is this? Is it an Adapter, * Exactly which Design Pattern is this? Is it an Adapter,
@ -140,13 +160,13 @@ public class TristateCheckBox extends UICheckBox {
other.setArmed(false); other.setArmed(false);
setPressed(false); setPressed(false);
setSelected(false); setSelected(false);
} } else if (state == SELECTED) {
else if (state == SELECTED) {
other.setArmed(false); other.setArmed(false);
setPressed(false); setPressed(false);
setSelected(true); setSelected(true);
} }
else { // either "null" or DONT_CARE // either "null" or DO_NOT_CARE
else {
other.setArmed(true); other.setArmed(true);
setPressed(true); setPressed(true);
setSelected(true); setSelected(true);
@ -158,7 +178,7 @@ public class TristateCheckBox extends UICheckBox {
* state of the model. * state of the model.
* <p/> * <p/>
* We return the SELECTED state when the checkbox is selected * We return the SELECTED state when the checkbox is selected
* but not armed, DONT_CARE state when the checkbox is * but not armed, DO_NOT_CARE state when the checkbox is
* selected and armed (grey) and NOT_SELECTED when the * selected and armed (grey) and NOT_SELECTED when the
* checkbox is deselected. * checkbox is deselected.
*/ */
@ -166,12 +186,10 @@ public class TristateCheckBox extends UICheckBox {
if (isSelected() && !isArmed()) { if (isSelected() && !isArmed()) {
// normal black tick // normal black tick
return SELECTED; return SELECTED;
} } else if (isSelected() && isArmed()) {
else if (isSelected() && isArmed()) {
// don't care grey tick // don't care grey tick
return DONT_CARE; return DO_NOT_CARE;
} } else {
else {
// normal deselected // normal deselected
return NOT_SELECTED; return NOT_SELECTED;
} }
@ -180,6 +198,7 @@ public class TristateCheckBox extends UICheckBox {
/** /**
* Filter: No one may change the armed status except us. * Filter: No one may change the armed status except us.
*/ */
@Override
public void setArmed(boolean b) { public void setArmed(boolean b) {
} }
@ -187,6 +206,7 @@ public class TristateCheckBox extends UICheckBox {
* We disable focusing on the component when it is not * We disable focusing on the component when it is not
* enabled. * enabled.
*/ */
@Override
public void setEnabled(boolean b) { public void setEnabled(boolean b) {
setFocusable(b); setFocusable(b);
other.setEnabled(b); other.setEnabled(b);
@ -196,89 +216,109 @@ public class TristateCheckBox extends UICheckBox {
* All these methods simply delegate to the "other" model * All these methods simply delegate to the "other" model
* that is being decorated. * that is being decorated.
*/ */
@Override
public boolean isArmed() { public boolean isArmed() {
return other.isArmed(); return other.isArmed();
} }
@Override
public boolean isSelected() { public boolean isSelected() {
return other.isSelected(); return other.isSelected();
} }
@Override
public boolean isEnabled() { public boolean isEnabled() {
return other.isEnabled(); return other.isEnabled();
} }
@Override
public boolean isPressed() { public boolean isPressed() {
return other.isPressed(); return other.isPressed();
} }
@Override
public boolean isRollover() { public boolean isRollover() {
return other.isRollover(); return other.isRollover();
} }
@Override
public void setSelected(boolean b) { public void setSelected(boolean b) {
other.setSelected(b); other.setSelected(b);
} }
@Override
public void setPressed(boolean b) { public void setPressed(boolean b) {
other.setPressed(b); other.setPressed(b);
} }
@Override
public void setRollover(boolean b) { public void setRollover(boolean b) {
other.setRollover(b); other.setRollover(b);
} }
@Override
public void setMnemonic(int key) { public void setMnemonic(int key) {
other.setMnemonic(key); other.setMnemonic(key);
} }
@Override
public int getMnemonic() { public int getMnemonic() {
return other.getMnemonic(); return other.getMnemonic();
} }
@Override
public void setActionCommand(String s) { public void setActionCommand(String s) {
other.setActionCommand(s); other.setActionCommand(s);
} }
@Override
public String getActionCommand() { public String getActionCommand() {
return other.getActionCommand(); return other.getActionCommand();
} }
@Override
public void setGroup(ButtonGroup group) { public void setGroup(ButtonGroup group) {
other.setGroup(group); other.setGroup(group);
} }
@Override
public void addActionListener(ActionListener l) { public void addActionListener(ActionListener l) {
other.addActionListener(l); other.addActionListener(l);
} }
@Override
public void removeActionListener(ActionListener l) { public void removeActionListener(ActionListener l) {
other.removeActionListener(l); other.removeActionListener(l);
} }
@Override
public void addItemListener(ItemListener l) { public void addItemListener(ItemListener l) {
other.addItemListener(l); other.addItemListener(l);
} }
@Override
public void removeItemListener(ItemListener l) { public void removeItemListener(ItemListener l) {
other.removeItemListener(l); other.removeItemListener(l);
} }
@Override
public void addChangeListener(ChangeListener l) { public void addChangeListener(ChangeListener l) {
other.addChangeListener(l); other.addChangeListener(l);
} }
@Override
public void removeChangeListener(ChangeListener l) { public void removeChangeListener(ChangeListener l) {
other.removeChangeListener(l); other.removeChangeListener(l);
} }
@Override
public Object[] getSelectedObjects() { public Object[] getSelectedObjects() {
return other.getSelectedObjects(); return other.getSelectedObjects();
} }
} }
/** /**
* We rotate between NOT_SELECTED, SELECTED and DONT_CARE. Subclass can * We rotate between NOT_SELECTED, SELECTED and DO_NOT_CARE. Subclass can
* override this method to tell the check box what next state is. Here is * override this method to tell the check box what next state is. Here is
* the default implementation. * the default implementation.
* <code><pre> * <code><pre>
@ -286,7 +326,7 @@ public class TristateCheckBox extends UICheckBox {
* return SELECTED; * return SELECTED;
* } * }
* else if (current == SELECTED) { * else if (current == SELECTED) {
* return DONT_CARE; * return DO_NOT_CARE;
* } * }
* else { * else {
* return NOT_SELECTED; * return NOT_SELECTED;
@ -296,12 +336,91 @@ public class TristateCheckBox extends UICheckBox {
protected State getNextState(State current) { protected State getNextState(State current) {
if (current == NOT_SELECTED) { if (current == NOT_SELECTED) {
return SELECTED; return SELECTED;
} else if (current == SELECTED) {
return DO_NOT_CARE;
} else {
return NOT_SELECTED;
} }
else if (current == SELECTED) {
return DONT_CARE;
} }
else /*if (current == DONT_CARE)*/ {
return NOT_SELECTED; private class TristateUICheckBoxUI extends MetalCheckBoxUI {
@Override
public void paint(Graphics g, JComponent c) {
synchronized (this) {
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
Dimension size = c.getSize();
Font f = c.getFont();
g.setFont(f);
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
Rectangle viewRect = new Rectangle(size);
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
Insets i = c.getInsets();
viewRect.x += i.left;
viewRect.y += i.top;
viewRect.width -= (i.right + viewRect.x);
viewRect.height -= (i.bottom + viewRect.y);
Icon altIcon = b.getIcon();
String text = SwingUtilities.layoutCompoundLabel(
c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(),
b.getVerticalAlignment(), b.getHorizontalAlignment(),
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
viewRect, iconRect, textRect, b.getIconTextGap());
// fill background
if (c.isOpaque()) {
g.setColor(b.getBackground());
g.fillRect(0, 0, size.width, size.height);
}
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (SELECTED.equals(getState())) {
GUIPaintUtils.fillPaint(g2d, iconRect.x, iconRect.y, iconRect.width, iconRect.height, false, Constants.NULL,
model.isEnabled() ? UIConstants.CHECKBOX_HOVER_SELECTED : UIConstants.DISABLED_ICON_COLOR, 0);
} else if (model.isRollover() && !SELECTED.equals(getState())) {
g.setColor(UIConstants.CHECKBOX_HOVER_SELECTED);
g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC);
} else {
g.setColor(UIConstants.LINE_COLOR);
g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC);
}
if (SELECTED.equals(getState())) {
UIConstants.YES_ICON.paintIcon(c, g, iconRect.x + 2, iconRect.y + 2);
} else if (DO_NOT_CARE.equals(getState())) {
g.setColor(UIConstants.CHECKBOX_HOVER_SELECTED);
g2d.fillRoundRect(iconRect.x + 2, iconRect.y + 2, iconRect.width - 4, iconRect.height - 4, UIConstants.ARC, UIConstants.ARC);
}
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
// Draw the Text
drawLine(text, g, b, c, textRect, fm);
}
} }
private void drawLine(String text, Graphics g, AbstractButton b, JComponent c, Rectangle textRect, FontMetrics fm) {
if (text != null) {
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
int mnemIndex = b.getDisplayedMnemonicIndex();
if (model.isEnabled()) {
g.setColor(b.getForeground());
} else {
g.setColor(getDisabledTextColor());
}
SwingUtilities2.drawStringUnderlineCharAt(c, g, text,
mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
}
}
} }
} }

133
designer-base/src/main/java/com/fr/design/gui/itree/filetree/EnvFileTree.java

@ -8,16 +8,19 @@ import com.fr.design.gui.itree.refreshabletree.RefreshableJTree;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.file.filetree.FileNodeFilter; import com.fr.file.filetree.FileNodeFilter;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.Inter; import com.fr.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.CoreConstants; import com.fr.stable.CoreConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import javax.swing.*; import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.*; import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -29,47 +32,29 @@ public class EnvFileTree extends RefreshableJTree {
protected FileNodeFilter filter; protected FileNodeFilter filter;
protected String treeRootPath = ""; protected String treeRootPath = "";
protected String[] subPathes; protected String[] subPaths;
public EnvFileTree() { public EnvFileTree() {
this(null, null); this(null, null);
} }
public EnvFileTree(String[] subPathes, FileNodeFilter filter) { public EnvFileTree(String[] subPaths, FileNodeFilter filter) {
this("", subPathes, filter); this("", subPaths, filter);
} }
public EnvFileTree(String treeRootPath, String[] subPathes, FileNodeFilter filter) { public EnvFileTree(String treeRootPath, String[] subPaths, FileNodeFilter filter) {
super(new FileNode(treeRootPath, true)); super(new FileNode(treeRootPath, true));
this.setTreeRootPath(treeRootPath); this.setTreeRootPath(treeRootPath);
this.setFileNodeFilter(filter); this.setFileNodeFilter(filter);
this.setSubPathes(subPathes); this.setSubPaths(subPaths);
/*一些自己的 init 放在这里,防止直接错误重写了父类的 init 方法导致子类不能使用 CheckBoxTree 的一些特性。*/ /*一些自己的 init 放在这里,防止直接错误重写了父类的 init 方法导致子类不能使用 CheckBoxTree 的一些特性。*/
this.putClientProperty("JTree.lineStyle", "Angled"); this.putClientProperty("JTree.lineStyle", "Angled");
this.setCellRenderer(fileTreeCellRenderer);
this.setRootVisible(false);
this.setShowsRootHandles(true);
this.setEditable(false);
}
private void setTreeRootPath(String path) {
if (path == null) {
path = "";
}
this.treeRootPath = path;
}
public void setFileNodeFilter(FileNodeFilter filter) {
this.filter = filter;
}
// CellRenderer // CellRenderer
private DefaultTreeCellRenderer fileTreeCellRenderer = new DefaultTreeCellRenderer() { // 这里新建一个Label作为render是因为JTree在动态刷新的时候,节点上render画布的的宽度不会变,会使得一部分比较长的数据显示为
DefaultTreeCellRenderer fileTreeCellRenderer = new DefaultTreeCellRenderer() {
@Override @Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row,
@ -81,12 +66,16 @@ public class EnvFileTree extends RefreshableJTree {
FileNode node = (FileNode) userObj; FileNode node = (FileNode) userObj;
String lock = node.getLock(); String lock = node.getLock();
String name = node.getName(); String name = node.getName();
if (treeNode.hasFullAuthority()) {
if (lock != null && !node.getUserID().equals(lock)) { if (lock != null && !node.getUserID().equals(lock)) {
name = name + Inter.getLocText("Locked"); name = name + InterProviderFactory.getProvider().getLocText("Locked");
this.setIcon(FileTreeIcon.getIcon(node)); this.setIcon(FileTreeIcon.getIcon(node));
}else { } else {
this.setIcon(FileTreeIcon.getIcon(node, false)); this.setIcon(FileTreeIcon.getIcon(node, false));
} }
} else {
this.setIcon(FileTreeIcon.getFolderHalfImageIcon());
}
this.setText(name); this.setText(name);
} else if (userObj == PENDING) { } else if (userObj == PENDING) {
this.setIcon(null); this.setIcon(null);
@ -106,6 +95,24 @@ public class EnvFileTree extends RefreshableJTree {
return this; return this;
} }
}; };
this.setCellRenderer(fileTreeCellRenderer);
this.setRootVisible(false);
this.setShowsRootHandles(true);
this.setEditable(false);
}
private void setTreeRootPath(String path) {
if (path == null) {
path = "";
}
this.treeRootPath = path;
}
public void setFileNodeFilter(FileNodeFilter filter) {
this.filter = filter;
}
/* /*
* 在当前tree中选中currentPath * 在当前tree中选中currentPath
@ -148,7 +155,8 @@ public class EnvFileTree extends RefreshableJTree {
if (ComparatorUtils.equals(new File(currentTreePath), new File(filePath))) { if (ComparatorUtils.equals(new File(currentTreePath), new File(filePath))) {
this.setSelectionPath(new TreePath(m_model.getPathToRoot(currentTreeNode))); this.setSelectionPath(new TreePath(m_model.getPathToRoot(currentTreeNode)));
return true; return true;
} // 如果当前路径是currentFilePath的ParnetFile,则expandTreeNode,并继续往下找 }
// 如果当前路径是currentFilePath的ParentFile,则expandTreeNode,并继续往下找
else if (EnvFileTree.isParentFile(currentTreePath, filePath)) { else if (EnvFileTree.isParentFile(currentTreePath, filePath)) {
this.loadPendingChildTreeNode(currentTreeNode); this.loadPendingChildTreeNode(currentTreeNode);
@ -187,33 +195,33 @@ public class EnvFileTree extends RefreshableJTree {
* 求filePath这个String,求其路径下面的所有的FileNode * 求filePath这个String,求其路径下面的所有的FileNode
*/ */
private FileNode[] listFileNodes(String filePath) { private FileNode[] listFileNodes(String filePath) {
FileNode[] res_fns = null; FileNode[] resFns = null;
try { try {
res_fns = WorkContext.getCurrent() == null ? new FileNode[0] : FRContext.getFileNodes().list(filePath); resFns = WorkContext.getCurrent() == null ? new FileNode[0] : FRContext.getFileNodes().list(filePath);
} catch (Exception e) { } catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
if (res_fns == null) { if (resFns == null) {
res_fns = new FileNode[0]; resFns = new FileNode[0];
} }
// 用FileNodeFilter过滤一下 // 用FileNodeFilter过滤一下
if (filter != null) { if (filter != null) {
java.util.List<FileNode> t_list = new ArrayList<FileNode>(); java.util.List<FileNode> tList = new ArrayList<FileNode>();
for (int i = 0; i < res_fns.length; i++) { for (int i = 0; i < resFns.length; i++) {
if (filter.accept(res_fns[i])) { if (filter.accept(resFns[i])) {
t_list.add(res_fns[i]); tList.add(resFns[i]);
} }
} }
res_fns = t_list.toArray(new FileNode[t_list.size()]); resFns = tList.toArray(new FileNode[tList.size()]);
} }
Arrays.sort(res_fns, new FileNodeComparator()); Arrays.sort(resFns, new FileNodeComparator());
return res_fns; return resFns;
} }
/* /*
@ -236,7 +244,7 @@ public class EnvFileTree extends RefreshableJTree {
} }
/* /*
* 改变Env后,根据构造函数时设置的RootPathes,重新加载 * 改变Env后,根据构造函数时设置的RootPaths,重新加载
*/ */
public void refreshEnv() { public void refreshEnv() {
@ -247,21 +255,21 @@ public class EnvFileTree extends RefreshableJTree {
FileNode[] fns; FileNode[] fns;
// 如果rootPaths是null的话列出所有文件 // 如果rootPaths是null的话列出所有文件
if (subPathes == null) { if (subPaths == null) {
fns = listFileNodes(this.treeRootPath); fns = listFileNodes(this.treeRootPath);
} else { } else {
// 重新加载新的FileDirectoryNode // 重新加载新的FileDirectoryNode
fns = new FileNode[subPathes.length]; fns = new FileNode[subPaths.length];
for (int i = 0; i < subPathes.length; i++) { for (int i = 0; i < subPaths.length; i++) {
fns[i] = new FileNode(StableUtils.pathJoin(new String[]{this.treeRootPath, subPathes[i]}), true); fns[i] = new FileNode(StableUtils.pathJoin(this.treeRootPath, subPaths[i]), true);
} }
} }
ExpandMutableTreeNode[] sub_tree_node_array = fileNodeArray2TreeNodeArray(fns); ExpandMutableTreeNode[] subTreeNodeArray = fileNodeArray2TreeNodeArray(fns);
for (int i = 0; i < sub_tree_node_array.length; i++) { for (int i = 0; i < subTreeNodeArray.length; i++) {
ExpandMutableTreeNode node = sub_tree_node_array[i]; ExpandMutableTreeNode node = subTreeNodeArray[i];
rootTreeNode.add(node); rootTreeNode.add(node);
} }
@ -269,10 +277,10 @@ public class EnvFileTree extends RefreshableJTree {
} }
/* /*
* 设置当前Tree的rootPathes * 设置当前Tree的rootPaths
*/ */
private void setSubPathes(String[] subPathes) { private void setSubPaths(String[] subPaths) {
this.subPathes = subPathes; this.subPaths = subPaths;
} }
/** /**
@ -288,7 +296,8 @@ public class EnvFileTree extends RefreshableJTree {
if (flag == null || flag.getUserObject() != PENDING) { if (flag == null || flag.getUserObject() != PENDING) {
return; return;
} }
currentTreeNode.removeAllChildren(); // 删除所有的节点. // 删除所有的节点.
currentTreeNode.removeAllChildren();
ExpandMutableTreeNode[] children = loadChildTreeNodes(currentTreeNode); ExpandMutableTreeNode[] children = loadChildTreeNodes(currentTreeNode);
for (ExpandMutableTreeNode c : children) { for (ExpandMutableTreeNode c : children) {
@ -299,6 +308,7 @@ public class EnvFileTree extends RefreshableJTree {
/* /*
* 判断eTreeNode是否需要Refresh,可提前中止,返回true则表示提前中止,不需要Refresh * 判断eTreeNode是否需要Refresh,可提前中止,返回true则表示提前中止,不需要Refresh
*/ */
@Override
protected boolean interceptRefresh(ExpandMutableTreeNode eTreeNode) { protected boolean interceptRefresh(ExpandMutableTreeNode eTreeNode) {
Object userObject = eTreeNode.getUserObject(); Object userObject = eTreeNode.getUserObject();
if (userObject instanceof FileNode && !((FileNode) userObject).isDirectory()) { if (userObject instanceof FileNode && !((FileNode) userObject).isDirectory()) {
@ -311,10 +321,11 @@ public class EnvFileTree extends RefreshableJTree {
/* /*
* 得到treeNode的子节点ExpandMutableTreeNode的数组 * 得到treeNode的子节点ExpandMutableTreeNode的数组
*/ */
@Override
protected ExpandMutableTreeNode[] loadChildTreeNodes(ExpandMutableTreeNode treeNode) { protected ExpandMutableTreeNode[] loadChildTreeNodes(ExpandMutableTreeNode treeNode) {
FileNode[] fn_array = listFileNodes(treeNode); FileNode[] fnArray = listFileNodes(treeNode);
return fileNodeArray2TreeNodeArray(fn_array); return fileNodeArray2TreeNodeArray(fnArray);
} }
/* /*
@ -340,16 +351,12 @@ public class EnvFileTree extends RefreshableJTree {
File parentFile = new File(parentFilePath); File parentFile = new File(parentFilePath);
File childFile = new File(childFilePath); File childFile = new File(childFilePath);
while (true) { do {
if (ComparatorUtils.equals(parentFile, childFile)) { if (ComparatorUtils.equals(parentFile, childFile)) {
return true; return true;
} }
childFile = childFile.getParentFile(); childFile = childFile.getParentFile();
if (childFile == null) { } while (childFile != null);
break;
}
}
return false; return false;
} }

32
designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileTreeIcon.java

@ -1,22 +1,26 @@
package com.fr.design.gui.itree.filetree; package com.fr.design.gui.itree.filetree;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.design.icon.LockIcon; import com.fr.design.icon.LockIcon;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import javax.swing.*; import javax.swing.Icon;
import javax.swing.UIManager;
import javax.swing.filechooser.FileSystemView; import javax.swing.filechooser.FileSystemView;
import java.io.File; import java.io.File;
public class FileTreeIcon { public class FileTreeIcon {
private FileTreeIcon() {} private FileTreeIcon() {
}
public static final Icon BLANK_IMAGE_ICON = BaseUtils.readIcon("/com/fr/design/images/gui/blank.gif"); public static final Icon BLANK_IMAGE_ICON = BaseUtils.readIcon("/com/fr/design/images/gui/blank.gif");
public static final Icon FOLDER_IMAGE_ICON = BaseUtils.readIcon("/com/fr/design/images/gui/folder.png"); public static final Icon FOLDER_IMAGE_ICON = BaseUtils.readIcon("/com/fr/design/images/gui/folder.png");
public static final Icon FOLDER_HALF_IMAGE_ICON =
BaseUtils.readIcon("/com/fr/design/images/gui/filetree_folder_half_authority_normal.png");
public static final Icon FILE_IMAGE_ICON = UIManager.getIcon("FileView.fileIcon"); public static final Icon FILE_IMAGE_ICON = UIManager.getIcon("FileView.fileIcon");
public static final Icon JAVA_FILE_IMAGE_ICON = BaseUtils.readIcon("/com/fr/design/images/gui/javaFile.gif"); public static final Icon JAVA_FILE_IMAGE_ICON = BaseUtils.readIcon("/com/fr/design/images/gui/javaFile.gif");
@ -110,22 +114,26 @@ public class FileTreeIcon {
return FileTreeIcon.getIcon(FileTreeIcon.getFileType(file.getName()), isLocked); return FileTreeIcon.getIcon(FileTreeIcon.getFileType(file.getName()), isLocked);
} }
public static Icon getFolderHalfImageIcon() {
return FOLDER_HALF_IMAGE_ICON;
}
public static Icon getIcon(FileNode node) { public static Icon getIcon(FileNode node) {
return getIcon(node, node.getLock() != null); return getIcon(node, node.getLock() != null);
} }
public static Icon getIcon(FileNode node, boolean isShowLock) { public static Icon getIcon(FileNode node, boolean isShowLock) {
String path = StableUtils.pathJoin(new String[]{WorkContext.getCurrent().getPath(), node.getEnvPath()}); String path = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), node.getEnvPath());
if (WorkContext.getCurrent().isLocal()) { if (WorkContext.getCurrent().isLocal()) {
File ff = new File(path); File ff = new File(path);
if (ff.exists()) { if (ff.exists()) {
if(node.isDirectory()){ if (node.isDirectory()) {
return FileTreeIcon.FOLDER_IMAGE_ICON; return FileTreeIcon.FOLDER_IMAGE_ICON;
} }
return FileSystemView.getFileSystemView().getSystemIcon(new File(path)); return FileSystemView.getFileSystemView().getSystemIcon(new File(path));
} }
} }
if(node.isDirectory()) { if (node.isDirectory()) {
return FileTreeIcon.FOLDER_IMAGE_ICON; return FileTreeIcon.FOLDER_IMAGE_ICON;
} else { } else {
return FileTreeIcon.getIcon(FileTreeIcon.getFileType(node.getName()), isShowLock); return FileTreeIcon.getIcon(FileTreeIcon.getFileType(node.getName()), isShowLock);
@ -249,21 +257,21 @@ public class FileTreeIcon {
return CLASS_FILE; return CLASS_FILE;
} else if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) { } else if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) {
return ZIP_FILE; return ZIP_FILE;
} else if( fileName.endsWith(".ear") || fileName.endsWith(".war")){ } else if (fileName.endsWith(".ear") || fileName.endsWith(".war")) {
return ZIP_FILE; return ZIP_FILE;
}else if (fileName.endsWith(".gif")) { } else if (fileName.endsWith(".gif")) {
return GIF_FILE; return GIF_FILE;
} else if (fileName.endsWith(".jpg") || fileName.endsWith(".jpe")) { } else if (fileName.endsWith(".jpg") || fileName.endsWith(".jpe")) {
return JPG_FILE; return JPG_FILE;
} else if( fileName.endsWith(".jpeg")){ } else if (fileName.endsWith(".jpeg")) {
return JPG_FILE; return JPG_FILE;
}else if (fileName.endsWith(".bmp")) { } else if (fileName.endsWith(".bmp")) {
return BMP_FILE; return BMP_FILE;
} else if (fileName.endsWith(".cpt")) { } else if (fileName.endsWith(".cpt")) {
return CPT_FILE; return CPT_FILE;
} else if (fileName.endsWith(".frm") || fileName.endsWith(".form")){ } else if (fileName.endsWith(".frm") || fileName.endsWith(".form")) {
return FRM_FILE; return FRM_FILE;
} else if (fileName.endsWith(".cht") || fileName.endsWith(".chart")){ } else if (fileName.endsWith(".cht") || fileName.endsWith(".chart")) {
return CHT_FILE; return CHT_FILE;
} else { } else {
return TEXT_FILE; return TEXT_FILE;

29
designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java

@ -8,6 +8,7 @@ import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext;
import javax.swing.text.Position; import javax.swing.text.Position;
import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultTreeModel;
@ -73,6 +74,7 @@ public class TemplateFileTree extends EnvFileTree {
return selectedPathList.toArray(new String[0]); return selectedPathList.toArray(new String[0]);
} }
@Override
public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias) { public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias) {
int max = getRowCount(); int max = getRowCount();
@ -100,15 +102,16 @@ public class TemplateFileTree extends EnvFileTree {
return null; return null;
} }
public FileNode[] listFile(String path) throws Exception { public FileNode[] listFile(String path) {
return FRContext.getFileNodes().list( return FRContext.getFileNodes().list(
path, path,
new FileExtension[]{FileExtension.CPT, FileExtension.FRM, FileExtension.CHT,FileExtension.XLS,FileExtension.XLSX}); new FileExtension[]{FileExtension.CPT, FileExtension.FRM, FileExtension.CHT, FileExtension.XLS, FileExtension.XLSX});
} }
/* /*
* 改变Env后,根据构造函数时设置的RootPaths,重新加载 * 改变Env后,根据构造函数时设置的RootPaths,重新加载
*/ */
@Override
public void refreshEnv() { public void refreshEnv() {
DefaultTreeModel defaultTreeModel = (DefaultTreeModel) this.getModel(); DefaultTreeModel defaultTreeModel = (DefaultTreeModel) this.getModel();
@ -118,13 +121,13 @@ public class TemplateFileTree extends EnvFileTree {
FileNode[] fns; FileNode[] fns;
// 如果rootPaths是null的话列出所有文件 // 如果rootPaths是null的话列出所有文件
if (subPathes == null) { if (subPaths == null) {
fns = listFileNodes(this.treeRootPath); fns = listFileNodes(this.treeRootPath);
} else { } else {
// 重新加载新的FileDirectoryNode // 重新加载新的FileDirectoryNode
fns = new FileNode[subPathes.length]; fns = new FileNode[subPaths.length];
for (int i = 0; i < subPathes.length; i++) { for (int i = 0; i < subPaths.length; i++) {
fns[i] = new FileNode(StableUtils.pathJoin(this.treeRootPath, subPathes[i]), true); fns[i] = new FileNode(StableUtils.pathJoin(this.treeRootPath, subPaths[i]), true);
} }
} }
@ -137,22 +140,32 @@ public class TemplateFileTree extends EnvFileTree {
defaultTreeModel.reload(rootTreeNode); defaultTreeModel.reload(rootTreeNode);
} }
@Override
protected ExpandMutableTreeNode[] loadChildTreeNodes(ExpandMutableTreeNode treeNode) { protected ExpandMutableTreeNode[] loadChildTreeNodes(ExpandMutableTreeNode treeNode) {
FileNode[] fn_array = listFileNodes(treeNode); FileNode[] fnArray = listFileNodes(treeNode);
return fileNodeArray2TreeNodeArray(fn_array); return fileNodeArray2TreeNodeArray(fnArray);
} }
/* /*
* 把FileNode[]转成ExpandMutableTreeNode[] * 把FileNode[]转成ExpandMutableTreeNode[]
*/ */
private ExpandMutableTreeNode[] fileNodeArray2TreeNodeArray(FileNode[] fileNodes) { private ExpandMutableTreeNode[] fileNodeArray2TreeNodeArray(FileNode[] fileNodes) {
boolean isLocal = WorkContext.getCurrent().isLocal();
String username = WorkContext.getConnector().currentUser();
ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[fileNodes.length]; ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[fileNodes.length];
for (int i = 0; i < res.length; i++) { for (int i = 0; i < res.length; i++) {
FileNode fn = fileNodes[i]; FileNode fn = fileNodes[i];
res[i] = new ExpandMutableTreeNode(fn); res[i] = new ExpandMutableTreeNode(fn);
if (fn.isDirectory()) { if (fn.isDirectory()) {
res[i].add(new ExpandMutableTreeNode()); res[i].add(new ExpandMutableTreeNode());
if (isLocal) {
res[i].setFullAuthority(true);
} else {
// todo 判断权限
boolean hasFullAuthority = false;
res[i].setFullAuthority(hasFullAuthority);
}
} }
} }

27
designer-base/src/main/java/com/fr/design/gui/itree/refreshabletree/ExpandMutableTreeNode.java

@ -1,17 +1,25 @@
package com.fr.design.gui.itree.refreshabletree; package com.fr.design.gui.itree.refreshabletree;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import com.fr.design.utils.gui.GUICoreUtils;
/** /**
* Enhanced, expand state and get treepath from node. * Enhanced, expand state and get treepath from node.
*/ */
public class ExpandMutableTreeNode extends DefaultMutableTreeNode { public class ExpandMutableTreeNode extends DefaultMutableTreeNode {
private boolean isExpanded = false; //the expend state /**
* the expend state
*/
private boolean isExpanded = false;
private boolean hasFullAuthority = true;
//默认显示:“正在加载”,如需要显示tree,则传入相应userobject /**
* 默认显示:正在加载如需要显示tree则传入相应userobject
*/
public ExpandMutableTreeNode() { public ExpandMutableTreeNode() {
this(RefreshableJTree.PENDING); this(RefreshableJTree.PENDING);
} }
@ -24,6 +32,15 @@ public class ExpandMutableTreeNode extends DefaultMutableTreeNode {
super(userObject); super(userObject);
this.setExpanded(isExpanded); this.setExpanded(isExpanded);
} }
public boolean hasFullAuthority() {
return hasFullAuthority;
}
public void setFullAuthority(boolean hasFullAuthority) {
this.hasFullAuthority = hasFullAuthority;
}
public boolean isExpanded() { public boolean isExpanded() {
return this.isExpanded; return this.isExpanded;
} }
@ -71,7 +88,7 @@ public class ExpandMutableTreeNode extends DefaultMutableTreeNode {
} }
public void addChildTreeNodes(ExpandMutableTreeNode[] newChildNodes) { public void addChildTreeNodes(ExpandMutableTreeNode[] newChildNodes) {
for (int i = 0; i < newChildNodes.length; i ++) { for (int i = 0; i < newChildNodes.length; i++) {
this.add(newChildNodes[i]); this.add(newChildNodes[i]);
} }
} }

52
designer-base/src/main/java/com/fr/design/gui/itree/refreshabletree/RefreshableJTree.java

@ -4,16 +4,28 @@ import com.fr.design.constants.UIConstants;
import com.fr.design.gui.itooltip.UIToolTip; import com.fr.design.gui.itooltip.UIToolTip;
import com.fr.design.gui.itree.checkboxtree.CheckBoxTree; import com.fr.design.gui.itree.checkboxtree.CheckBoxTree;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.general.NameObject; import com.fr.general.NameObject;
import com.fr.locale.InterProviderFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JToolTip;
import javax.swing.SwingWorker;
import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener; import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeWillExpandListener; import javax.swing.event.TreeWillExpandListener;
import javax.swing.tree.*; import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*; import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.ExpandVetoException;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.awt.Component;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public abstract class RefreshableJTree extends CheckBoxTree { public abstract class RefreshableJTree extends CheckBoxTree {
@ -24,16 +36,19 @@ public abstract class RefreshableJTree extends CheckBoxTree {
@Override @Override
public String toString() { public String toString() {
return Inter.getLocText("Loading") + "..."; return InterProviderFactory.getProvider().getLocText("Loading") + "...";
} }
}; };
public RefreshableJTree() { public RefreshableJTree() {
this(null); this(null);
} }
@Override
public boolean isCheckBoxVisible(TreePath path) { public boolean isCheckBoxVisible(TreePath path) {
return false; return false;
} }
public RefreshableJTree(Object rootObj) { public RefreshableJTree(Object rootObj) {
super(new DefaultTreeModel(new ExpandMutableTreeNode(rootObj))); super(new DefaultTreeModel(new ExpandMutableTreeNode(rootObj)));
DefaultTreeModel model = (DefaultTreeModel) getModel(); DefaultTreeModel model = (DefaultTreeModel) getModel();
@ -101,8 +116,7 @@ public abstract class RefreshableJTree extends CheckBoxTree {
treeNode.remove(0); treeNode.remove(0);
} }
treeModel.nodeStructureChanged(treeNode); treeModel.nodeStructureChanged(treeNode);
long usedTime = System.currentTimeMillis() - startTime; return System.currentTimeMillis() - startTime;
return usedTime;
} }
@Override @Override
@ -118,10 +132,10 @@ public abstract class RefreshableJTree extends CheckBoxTree {
}; };
/** /**
* @return * @return is template showing
*/ */
public boolean isTemplateShowing() { public boolean isTemplateShowing() {
return ((ExpandMutableTreeNode) this.getModel().getRoot()).getChildCount() == 0 ? false : true; return ((ExpandMutableTreeNode) this.getModel().getRoot()).getChildCount() != 0;
} }
/* /*
@ -161,7 +175,7 @@ public abstract class RefreshableJTree extends CheckBoxTree {
} }
// 刷新当前eTreeNode下面的子节点的UserObject的数组 // 刷新当前eTreeNode下面的子节点的UserObject的数组
ExpandMutableTreeNode[] new_nodes = loadChildTreeNodes(eTreeNode); ExpandMutableTreeNode[] newNodes = loadChildTreeNodes(eTreeNode);
/* /*
* 保存下当前eTreeNode下的ChildTreeNode于childTreeNodeList 移除所有ChildTreeNode * 保存下当前eTreeNode下的ChildTreeNode于childTreeNodeList 移除所有ChildTreeNode
@ -178,18 +192,18 @@ public abstract class RefreshableJTree extends CheckBoxTree {
eTreeNode.removeAllChildren(); eTreeNode.removeAllChildren();
for (int ci = 0; ci < new_nodes.length; ci++) { for (int ci = 0; ci < newNodes.length; ci++) {
Object cUserObject = new_nodes[ci].getUserObject(); Object cUserObject = newNodes[ci].getUserObject();
for (int ni = 0, nlen = childTreeNodeList.size(); ni < nlen; ni++) { for (int ni = 0, len = childTreeNodeList.size(); ni < len; ni++) {
ExpandMutableTreeNode cTreeNode = (ExpandMutableTreeNode) childTreeNodeList.get(ni); ExpandMutableTreeNode cTreeNode = (ExpandMutableTreeNode) childTreeNodeList.get(ni);
if (ComparatorUtils.equals(cTreeNode.getUserObject(), cUserObject)) { if (ComparatorUtils.equals(cTreeNode.getUserObject(), cUserObject)) {
new_nodes[ci].setExpanded(cTreeNode.isExpanded()); newNodes[ci].setExpanded(cTreeNode.isExpanded());
break; break;
} }
} }
eTreeNode.add(new_nodes[ci]); eTreeNode.add(newNodes[ci]);
} }
} }
@ -223,6 +237,7 @@ public abstract class RefreshableJTree extends CheckBoxTree {
return null; return null;
} }
@Override
public String getToolTipText(MouseEvent event) { public String getToolTipText(MouseEvent event) {
String tip = null; String tip = null;
icon = new ImageIcon(); icon = new ImageIcon();
@ -238,7 +253,7 @@ public abstract class RefreshableJTree extends CheckBoxTree {
Object lastPath = path.getLastPathComponent(); Object lastPath = path.getLastPathComponent();
if (lastPath instanceof TreeNode) { if (lastPath instanceof TreeNode) {
TreeNode treeNode = (TreeNode) lastPath; TreeNode treeNode = (TreeNode) lastPath;
while (treeNode.getParent() instanceof TreeNode) { while (treeNode.getParent() != null) {
i++; i++;
treeNode = treeNode.getParent(); treeNode = treeNode.getParent();
} }
@ -260,6 +275,7 @@ public abstract class RefreshableJTree extends CheckBoxTree {
return tip; return tip;
} }
@Override
public Point getToolTipLocation(MouseEvent event) { public Point getToolTipLocation(MouseEvent event) {
if (event != null) { if (event != null) {
Point p = event.getPoint(); Point p = event.getPoint();
@ -268,12 +284,16 @@ public abstract class RefreshableJTree extends CheckBoxTree {
if (selRow != -1 && r != null) { if (selRow != -1 && r != null) {
TreePath path = getPathForRow(selRow); TreePath path = getPathForRow(selRow);
Rectangle pathBounds = getPathBounds(path); Rectangle pathBounds = getPathBounds(path);
if (pathBounds != null) {
return new Point(pathBounds.x - 2, pathBounds.y - 1); return new Point(pathBounds.x - 2, pathBounds.y - 1);
} }
return null;
}
} }
return null; return null;
} }
@Override
public JToolTip createToolTip() { public JToolTip createToolTip() {
UIToolTip tip = new UIToolTip(icon); UIToolTip tip = new UIToolTip(icon);
tip.setComponent(this); tip.setComponent(this);

4
designer-base/src/main/java/com/fr/design/remote/ui/AuthorityEditorPane.java

@ -12,10 +12,10 @@ import com.fr.general.Inter;
import com.fr.report.DesignAuthority; import com.fr.report.DesignAuthority;
import com.fr.stable.CoreConstants; import com.fr.stable.CoreConstants;
import javax.swing.*; import javax.swing.BorderFactory;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.*; import java.awt.BorderLayout;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

BIN
designer-base/src/main/resources/com/fr/design/images/gui/filetree_folder_half_authority_normal.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Loading…
Cancel
Save