@ -1,5 +1,6 @@
package com.fr.design.mainframe.share.ui.block ;
import com.fr.base.GraphHelper ;
import com.fr.base.iofile.attr.SharableAttrMark ;
import com.fr.design.DesignerEnvManager ;
import com.fr.design.base.mode.DesignModeContext ;
@ -30,11 +31,13 @@ import com.fr.form.share.Group;
import com.fr.form.share.utils.ShareUtils ;
import com.fr.form.ui.AbstractBorderStyleWidget ;
import com.fr.form.ui.Widget ;
import com.fr.general.FRFont ;
import com.fr.general.IOUtils ;
import com.fr.log.FineLoggerFactory ;
import com.fr.stable.StableUtils ;
import com.fr.stable.StringUtils ;
import javax.swing.Icon ;
import javax.swing.JPanel ;
import javax.swing.JPopupMenu ;
import javax.swing.SwingConstants ;
@ -47,6 +50,7 @@ import java.awt.Color;
import java.awt.Composite ;
import java.awt.Cursor ;
import java.awt.Dimension ;
import java.awt.Font ;
import java.awt.Graphics ;
import java.awt.Graphics2D ;
import java.awt.Rectangle ;
@ -54,6 +58,8 @@ import java.awt.RenderingHints;
import java.awt.Stroke ;
import java.awt.dnd.DnDConstants ;
import java.awt.event.MouseEvent ;
import java.awt.font.FontRenderContext ;
import java.awt.geom.Dimension2D ;
import java.awt.image.BufferedImage ;
import java.io.File ;
import java.io.IOException ;
@ -73,6 +79,7 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
private static final BufferedImage WIDGET_INSTALLED_ICON = IOUtils . readImage ( "/com/fr/base/images/share/widget_installed.png" ) ;
private static final BufferedImage WIDGET_DOWNLOAD_ICON = IOUtils . readImage ( "/com/fr/base/images/share/download.png" ) ;
private static final BufferedImage WIDGET_DOWNLOADING_ICON = IOUtils . readImage ( "/com/fr/base/images/share/downloading.png" ) ;
private static final Icon incompatibleMarker = IOUtils . readIcon ( "/com/fr/base/images/share/marker_incompatible.png" ) ;
public OnlineWidgetBlock ( OnlineShareWidget widget , AbstractOnlineWidgetSelectPane parentPane ) {
super ( widget , parentPane ) ;
@ -117,6 +124,9 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
@Override
public void mouseEntered ( MouseEvent e ) {
if ( ! getWidget ( ) . isCompatibleWithCurrentEnv ( ) ) {
return ;
}
super . mouseEntered ( e ) ;
this . isMouseEnter = true ;
this . repaint ( ) ;
@ -124,6 +134,9 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
@Override
public void mouseExited ( MouseEvent e ) {
if ( ! getWidget ( ) . isCompatibleWithCurrentEnv ( ) ) {
return ;
}
super . mouseExited ( e ) ;
this . isMouseEnter = false ;
this . repaint ( ) ;
@ -131,12 +144,18 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
@Override
public void mousePressed ( MouseEvent e ) {
if ( ! getWidget ( ) . isCompatibleWithCurrentEnv ( ) ) {
return ;
}
super . mousePressed ( e ) ;
this . lastPressEvent = e ;
}
@Override
public void mouseClicked ( MouseEvent e ) {
if ( ! getWidget ( ) . isCompatibleWithCurrentEnv ( ) ) {
return ;
}
super . mouseClicked ( e ) ;
boolean isLeftClickDownloadIcon = e . getButton ( ) ! = MouseEvent . BUTTON3 & & getDownloadIconRec ( ) . contains ( e . getX ( ) , e . getY ( ) ) ;
if ( ! isRightClickPopupMenuVisible ( ) & & isLeftClickDownloadIcon & & ! checkWidgetInstalled ( ) ) {
@ -146,6 +165,9 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
@Override
public void mouseDragged ( MouseEvent e ) {
if ( ! getWidget ( ) . isCompatibleWithCurrentEnv ( ) ) {
return ;
}
super . mouseDragged ( e ) ;
if ( DesignModeContext . isAuthorityEditing ( ) | | ! checkWidgetInstalled ( ) ) {
return ;
@ -184,6 +206,21 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
}
}
@Override
public void mouseMoved ( MouseEvent e ) {
if ( ! getWidget ( ) . isCompatibleWithCurrentEnv ( ) ) {
return ;
}
super . mouseMoved ( e ) ;
if ( checkWidgetInstalled ( ) ) {
this . setCursor ( Cursor . getPredefinedCursor ( Cursor . MOVE_CURSOR ) ) ;
} else if ( getDownloadIconRec ( ) . contains ( e . getX ( ) , e . getY ( ) ) ) {
this . setCursor ( Cursor . getPredefinedCursor ( Cursor . HAND_CURSOR ) ) ;
} else {
this . setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
}
}
private void downLoadWidget ( ) {
CarouselStateManger . getInstance ( ) . suspend ( CarouselStateManger . DOWNLOAD_COMPONENT ) ;
if ( OnlineWidgetRepoPane . getInstance ( ) . isShowPackagePanel ( ) ) {
@ -249,19 +286,6 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
} . execute ( ) ;
}
@Override
public void mouseMoved ( MouseEvent e ) {
super . mouseMoved ( e ) ;
if ( checkWidgetInstalled ( ) ) {
this . setCursor ( Cursor . getPredefinedCursor ( Cursor . MOVE_CURSOR ) ) ;
} else if ( getDownloadIconRec ( ) . contains ( e . getX ( ) , e . getY ( ) ) ) {
this . setCursor ( Cursor . getPredefinedCursor ( Cursor . HAND_CURSOR ) ) ;
} else {
this . setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
}
}
private Rectangle getDownloadIconRec ( ) {
return new Rectangle ( ShareComponentConstants . SHARE_THUMB_WIDTH / 2 - 12 , ShareComponentConstants . SHARE_BLOCK_HEIGHT / 2 - 16 , 24 , 24 ) ;
}
@ -328,6 +352,47 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
g2d . setColor ( Color . WHITE ) ;
g2d . setStroke ( oldStroke ) ;
}
boolean isUnusable = ! getWidget ( ) . isCompatibleWithCurrentEnv ( ) ;
if ( isUnusable ) {
paintUnusableMask ( ( Graphics2D ) g ) ;
}
}
protected void paintUnusableMask ( Graphics2D g2d ) {
Color oldColor = g2d . getColor ( ) ;
Font oldFont = g2d . getFont ( ) ;
g2d . setRenderingHint ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ;
Dimension coverDim = getCoverDimension ( ) ;
double canvasX = 0 ;
double canvasY = 0 ;
double canvasW = coverDim . getWidth ( ) ;
double canvasH = coverDim . getHeight ( ) ;
g2d . setColor ( new Color ( 0 . 0F , 0 . 0F , 0 . 0F , 0 . 4F ) ) ;
GraphHelper . fillRect ( g2d , canvasX , canvasY , canvasW , canvasH - 16 ) ;
g2d . setColor ( new Color ( 0 . 0F , 0 . 0F , 0 . 0F , 0 . 5F ) ) ;
GraphHelper . fillRect ( g2d , canvasX , canvasH - 16 , canvasW , 16 ) ;
String tipText = Toolkit . i18nText ( "Fine-Design_Share_Incompatible_Version_Tip" ) ;
Font tipFont = FRFont . getInstance ( ) . deriveFont ( 8F ) ;
FontRenderContext frc = g2d . getFontRenderContext ( ) ;
double tipTextWidth = GraphHelper . stringWidth ( tipText , tipFont , frc ) ;
Dimension2D dim = GraphHelper . stringDimensionWithRotation ( tipText , tipFont , 0 , frc ) ;
double tipTextHeight = dim . getHeight ( ) ;
g2d . setColor ( Color . WHITE ) ;
g2d . setFont ( tipFont ) ;
GraphHelper . drawString ( g2d , tipText , canvasX + ( canvasW - tipTextWidth ) / 2 . 0F , canvasY + canvasH - ( 16 - tipTextHeight ) / 2 . 0F ) ;
int markerX = ( int ) ( canvasX + ( canvasW - incompatibleMarker . getIconWidth ( ) ) / 2 ) ;
int markerY = ( int ) ( canvasY + ( canvasH - incompatibleMarker . getIconHeight ( ) ) / 2 ) ;
incompatibleMarker . paintIcon ( this , g2d , markerX , markerY ) ;
g2d . setColor ( oldColor ) ;
g2d . setFont ( oldFont ) ;
}
@Override