|
|
|
package com.fr.design.mainframe;
|
|
|
|
|
|
|
|
import com.fr.design.file.HistoryTemplateListCache;
|
|
|
|
import com.fr.design.gui.ilable.UILabel;
|
|
|
|
import com.fr.design.i18n.DesignSizeI18nManager;
|
|
|
|
import com.fr.design.i18n.Toolkit;
|
|
|
|
import com.fr.design.mainframe.guide.base.GuideView;
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils;
|
|
|
|
import com.fr.general.IOUtils;
|
|
|
|
import com.fr.log.FineLoggerFactory;
|
|
|
|
import com.fr.workspace.WorkContext;
|
|
|
|
import com.fr.report.lock.LockInfoOperator;
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Component;
|
|
|
|
import java.awt.Container;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Font;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.Graphics2D;
|
|
|
|
import java.awt.LayoutManager;
|
|
|
|
import java.awt.RenderingHints;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
import javax.swing.ImageIcon;
|
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JDialog;
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.SwingWorker;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author hades
|
|
|
|
* @version 11.0
|
|
|
|
* Created by hades on 2021/12/6
|
|
|
|
*/
|
|
|
|
public class ForbiddenPane extends JPanel {
|
|
|
|
|
|
|
|
private static final ImageIcon LOCK_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/mainframe/lock_template.png"));
|
|
|
|
private static final Color TIP_COLOR = new Color(108, 174, 235);
|
|
|
|
private static final Color BUTTON_COLOR = new Color(63, 155, 249);
|
|
|
|
private static final int Y_GAP = 10;
|
|
|
|
private static final int X_GAP = 10;
|
|
|
|
private static final int ARC = 4;
|
|
|
|
|
|
|
|
private final UILabel lockLabel;
|
|
|
|
private final UILabel tipLabel;
|
|
|
|
private final JButton refreshButton;
|
|
|
|
|
|
|
|
public ForbiddenPane() {
|
|
|
|
|
|
|
|
setLayout(new LayoutManager() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeLayoutComponent(Component comp) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Dimension preferredLayoutSize(Container parent) {
|
|
|
|
return parent.getPreferredSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Dimension minimumLayoutSize(Container parent) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void layoutContainer(Container parent) {
|
|
|
|
int width = parent.getParent().getWidth();
|
|
|
|
int height = parent.getParent().getHeight();
|
|
|
|
int lockLabelWidth = lockLabel.getPreferredSize().width;
|
|
|
|
int lockLabelHeight = lockLabel.getPreferredSize().height;
|
|
|
|
int lockLabelX = (width - lockLabelWidth) / 2;
|
|
|
|
int lockLabelY = (height - lockLabelHeight) / 2;
|
|
|
|
int tipLabelWidth = tipLabel.getPreferredSize().width;
|
|
|
|
int tipLabelHeight = tipLabel.getPreferredSize().height;
|
|
|
|
int tipLabelX = (width - tipLabelWidth) / 2 + X_GAP;
|
|
|
|
int tipLabelY = lockLabelY + lockLabelHeight;
|
|
|
|
int refreshButtonWidth = refreshButton.getPreferredSize().width;
|
|
|
|
int refreshButtonHeight = refreshButton.getPreferredSize().height;
|
|
|
|
int refreshButtonX = (width - refreshButtonWidth) / 2 + X_GAP;
|
|
|
|
int refreshButtonY = tipLabelY + refreshButtonHeight + Y_GAP;
|
|
|
|
lockLabel.setBounds(lockLabelX, lockLabelY, lockLabelWidth, lockLabelHeight);
|
|
|
|
tipLabel.setBounds(tipLabelX, tipLabelY, tipLabelWidth, tipLabelHeight);
|
|
|
|
refreshButton.setBounds(refreshButtonX, refreshButtonY, refreshButtonWidth, refreshButtonHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addLayoutComponent(String name, Component comp) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setBackground(Color.WHITE);
|
|
|
|
lockLabel = new UILabel(LOCK_ICON);
|
|
|
|
tipLabel = new UILabel(Toolkit.i18nText("Fine_Design_Template_Has_Been_Locked_Tip"));
|
|
|
|
Font labelFont = tipLabel.getFont();
|
|
|
|
tipLabel.setFont(new Font(labelFont.getName(), labelFont.getStyle(), 14));
|
|
|
|
tipLabel.setForeground(TIP_COLOR);
|
|
|
|
refreshButton = new JButton(Toolkit.i18nText("Fine-Design_Basic_Refresh")) {
|
|
|
|
@Override
|
|
|
|
public void paintComponent(Graphics g) {
|
|
|
|
Graphics2D g2d = (Graphics2D) g;
|
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
g2d.setColor(BUTTON_COLOR);
|
|
|
|
g2d.fillRoundRect(0, 0, getWidth(), getHeight(), ARC, ARC);
|
|
|
|
super.paintComponent(g2d);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
refreshButton.setPreferredSize(DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.mainframe.ForbiddenPane.refreshButton"));
|
|
|
|
refreshButton.setForeground(Color.WHITE);
|
|
|
|
refreshButton.setBorderPainted(false);
|
|
|
|
refreshButton.setContentAreaFilled(false);
|
|
|
|
refreshButton.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
final JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
|
|
|
|
if (template == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 展示下画面
|
|
|
|
LoadingDialog loadingDialog = new LoadingDialog();
|
|
|
|
loadingDialog.showDialog();
|
|
|
|
new SwingWorker<Boolean, Void>(){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground() throws Exception {
|
|
|
|
return WorkContext.getCurrent().get(LockInfoOperator.class).isTplLocked(template.getEditingFILE().getPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void done() {
|
|
|
|
boolean unLocked;
|
|
|
|
loadingDialog.hideDialog();
|
|
|
|
try {
|
|
|
|
unLocked = !get();
|
|
|
|
if (unLocked) {
|
|
|
|
template.whenClose();
|
|
|
|
JTemplate<?, ?> newTemplate = JTemplateFactory.createJTemplate(template.getEditingFILE());
|
|
|
|
HistoryTemplateListCache.getInstance().replaceCurrentEditingTemplate(newTemplate);
|
|
|
|
DesignerContext.getDesignerFrame().addAndActivateJTemplate(newTemplate);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
loadingDialog.hideDialog();
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
add(lockLabel);
|
|
|
|
add(tipLabel);
|
|
|
|
add(refreshButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LoadingDialog extends JDialog {
|
|
|
|
|
|
|
|
private static final ImageIcon LOADING_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/mainframe/refreh_icon.png"));
|
|
|
|
|
|
|
|
private GuideView guideView;
|
|
|
|
|
|
|
|
public LoadingDialog() {
|
|
|
|
super(DesignerContext.getDesignerFrame());
|
|
|
|
setLayout(new BorderLayout());
|
|
|
|
this.getContentPane().setBackground(Color.WHITE);
|
|
|
|
this.setResizable(false);
|
|
|
|
this.setUndecorated(true);
|
|
|
|
this.setAlwaysOnTop(true);
|
|
|
|
this.setModal(false);
|
|
|
|
this.setSize(new Dimension(400, 100));
|
|
|
|
this.add(new UILabel(LOADING_ICON, UILabel.CENTER), BorderLayout.NORTH);
|
|
|
|
this.add(new UILabel(Toolkit.i18nText(Toolkit.i18nText("Fine_Design_Template_Refresh")), UILabel.CENTER), BorderLayout.CENTER);
|
|
|
|
GUICoreUtils.centerWindow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showDialog() {
|
|
|
|
DesignerContext.getDesignerFrame().setExtendedState(JFrame.MAXIMIZED_BOTH);
|
|
|
|
guideView = new GuideView(DesignerContext.getDesignerFrame());
|
|
|
|
GUICoreUtils.centerWindow(DesignerContext.getDesignerFrame(), guideView);
|
|
|
|
guideView.setBounds(DesignerContext.getDesignerFrame().getBounds());
|
|
|
|
guideView.setVisible(true);
|
|
|
|
this.setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideDialog() {
|
|
|
|
this.dispose();
|
|
|
|
guideView.dismissGuide();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|