|
|
@ -37,18 +37,33 @@ import com.fr.stable.StableUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.project.ProjectConstants; |
|
|
|
import com.fr.stable.project.ProjectConstants; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
import javax.swing.BorderFactory; |
|
|
|
|
|
|
|
import javax.swing.JComponent; |
|
|
|
|
|
|
|
import javax.swing.JFileChooser; |
|
|
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.plaf.basic.BasicButtonUI; |
|
|
|
import javax.swing.plaf.basic.BasicButtonUI; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
|
|
|
|
import java.awt.Cursor; |
|
|
|
|
|
|
|
import java.awt.Desktop; |
|
|
|
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
|
|
|
import java.awt.FlowLayout; |
|
|
|
|
|
|
|
import java.awt.FontMetrics; |
|
|
|
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
|
|
|
import java.awt.Image; |
|
|
|
|
|
|
|
import java.awt.Point; |
|
|
|
|
|
|
|
import java.awt.Toolkit; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
import java.awt.event.MouseMotionListener; |
|
|
|
import java.awt.event.MouseMotionListener; |
|
|
|
|
|
|
|
import java.awt.geom.Line2D; |
|
|
|
import java.awt.geom.RoundRectangle2D; |
|
|
|
import java.awt.geom.RoundRectangle2D; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URI; |
|
|
@ -65,7 +80,7 @@ import java.util.Arrays; |
|
|
|
public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
private final int SETTING_LABEL_WIDTH = LayoutStylePane.SETTING_LABEL_WIDTH; |
|
|
|
private final int SETTING_LABEL_WIDTH = LayoutStylePane.SETTING_LABEL_WIDTH; |
|
|
|
private final Style DEFAULT_IMAGE_LAYOUT_STYLE = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_DEFAULT); |
|
|
|
private final Style DEFAULT_IMAGE_LAYOUT_STYLE = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_DEFAULT); |
|
|
|
private final String TWEAK_NINE_POINT_HELP_URL = ""; |
|
|
|
private final String TWEAK_NINE_POINT_HELP_URL = "https://help.fanruan.com/finereport/doc-view-4135.html"; |
|
|
|
|
|
|
|
|
|
|
|
private UIObserverListener uiObserverListener; |
|
|
|
private UIObserverListener uiObserverListener; |
|
|
|
|
|
|
|
|
|
|
@ -415,18 +430,11 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
|
|
|
|
|
|
|
|
private void initComponents() { |
|
|
|
private void initComponents() { |
|
|
|
setLayout(new BorderLayout()); |
|
|
|
setLayout(new BorderLayout()); |
|
|
|
setBorder(BorderFactory.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Border_Image_Config_Nine_Point_Fill_Preview"))); |
|
|
|
setBorder(BorderFactory.createEmptyBorder()); |
|
|
|
|
|
|
|
add(previewPane, BorderLayout.CENTER); |
|
|
|
|
|
|
|
|
|
|
|
JPanel content = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
previewPane.setPreferredSize(new Dimension(615, 462)); |
|
|
|
content.setBorder(BorderFactory.createEmptyBorder( |
|
|
|
previewPane.setBorder(BorderFactory.createEmptyBorder()); |
|
|
|
IntervalConstants.INTERVAL_W1, |
|
|
|
|
|
|
|
IntervalConstants.INTERVAL_W1, |
|
|
|
|
|
|
|
IntervalConstants.INTERVAL_W1, |
|
|
|
|
|
|
|
IntervalConstants.INTERVAL_W1)); |
|
|
|
|
|
|
|
content.add(previewPane); |
|
|
|
|
|
|
|
previewPane.setPreferredSize(new Dimension(611, 457)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add(content, BorderLayout.CENTER); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -436,27 +444,61 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private class NinePointLinePreviewPane extends JPanel implements MouseMotionListener, MouseListener { |
|
|
|
private class NinePointLinePreviewPane extends JPanel implements MouseMotionListener, MouseListener { |
|
|
|
private final BufferedImage transparentImage = IOUtils.readImage("/com/fr/design/images/transparent_background.jpg"); |
|
|
|
public final Color BACKGROUND_PANE_COLOR = Color.WHITE; |
|
|
|
|
|
|
|
public final Color BACKGROUND_IMG_COLOR = Color.lightGray; |
|
|
|
public final Color PATCH_COLOR = new Color(0, 0, 0, 38); |
|
|
|
public final Color DIVIDER_BACKGROUND_COLOR = new Color(235, 29, 31); |
|
|
|
public final Color DIVIDER_COLOR = new Color(250, 250, 250); |
|
|
|
public final Color DIVIDER_FOREGROUND_COLOR = Color.WHITE; |
|
|
|
public final Color TEXT_COLOR = Color.WHITE; |
|
|
|
public final Color HINT_BACKGROUND_COLOR = new Color(0, 215, 215); |
|
|
|
public final int PADDING = 15; |
|
|
|
public final Color HINT_FOREGROUND_COLOR = Color.WHITE; |
|
|
|
|
|
|
|
public final int HINT_GAP = 5; |
|
|
|
|
|
|
|
public final int PADDING = 20; |
|
|
|
|
|
|
|
public final Cursor E_DRAG_CURSOR = Toolkit.getDefaultToolkit().createCustomCursor( |
|
|
|
|
|
|
|
IOUtils.readImage("/com/fr/design/images/control/icon_cursor_drag_e.png"), |
|
|
|
|
|
|
|
new Point(8, 8), "E_DRAG_CURSOR"); |
|
|
|
|
|
|
|
public final Cursor S_DRAG_CURSOR = Toolkit.getDefaultToolkit().createCustomCursor( |
|
|
|
|
|
|
|
IOUtils.readImage("/com/fr/design/images/control/icon_cursor_drag_s.png"), |
|
|
|
|
|
|
|
new Point(8, 8), "S_DRAG_CURSOR"); |
|
|
|
|
|
|
|
public final Cursor W_DRAG_CURSOR = Toolkit.getDefaultToolkit().createCustomCursor( |
|
|
|
|
|
|
|
IOUtils.readImage("/com/fr/design/images/control/icon_cursor_drag_w.png"), |
|
|
|
|
|
|
|
new Point(8, 8), "W_DRAG_CURSOR"); |
|
|
|
|
|
|
|
public final Cursor N_DRAG_CURSOR = Toolkit.getDefaultToolkit().createCustomCursor( |
|
|
|
|
|
|
|
IOUtils.readImage("/com/fr/design/images/control/icon_cursor_drag_n.png"), |
|
|
|
|
|
|
|
new Point(8, 8), "N_DRAG_CURSOR"); |
|
|
|
|
|
|
|
public final Cursor NE_DRAG_CURSOR = Toolkit.getDefaultToolkit().createCustomCursor( |
|
|
|
|
|
|
|
IOUtils.readImage("/com/fr/design/images/control/icon_cursor_drag_ne.png"), |
|
|
|
|
|
|
|
new Point(8, 8), "NE_DRAG_CURSOR"); |
|
|
|
|
|
|
|
public final Cursor NW_DRAG_CURSOR = Toolkit.getDefaultToolkit().createCustomCursor( |
|
|
|
|
|
|
|
IOUtils.readImage("/com/fr/design/images/control/icon_cursor_drag_nw.png"), |
|
|
|
|
|
|
|
new Point(8, 8), "NW_DRAG_CURSOR"); |
|
|
|
|
|
|
|
public final Cursor SE_DRAG_CURSOR = Toolkit.getDefaultToolkit().createCustomCursor( |
|
|
|
|
|
|
|
IOUtils.readImage("/com/fr/design/images/control/icon_cursor_drag_se.png"), |
|
|
|
|
|
|
|
new Point(8, 8), "SE_DRAG_CURSOR"); |
|
|
|
|
|
|
|
public final Cursor SW_DRAG_CURSOR = Toolkit.getDefaultToolkit().createCustomCursor( |
|
|
|
|
|
|
|
IOUtils.readImage("/com/fr/design/images/control/icon_cursor_drag_sw.png"), |
|
|
|
|
|
|
|
new Point(8, 8), "SW_DRAG_CURSOR"); |
|
|
|
|
|
|
|
|
|
|
|
private int ninePointLeft = -1; |
|
|
|
private int ninePointLeft = -1; |
|
|
|
private int ninePointTop = -1; |
|
|
|
private int ninePointTop = -1; |
|
|
|
private int ninePointRight = -1; |
|
|
|
private int ninePointRight = -1; |
|
|
|
private int ninePointBottom = -1; |
|
|
|
private int ninePointBottom = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int MIN_NINE_POINT = 0; |
|
|
|
|
|
|
|
|
|
|
|
private int imgWidth; |
|
|
|
private int imgWidth; |
|
|
|
private int imgHeight; |
|
|
|
private int imgHeight; |
|
|
|
private int scaleImgWidth; |
|
|
|
private int scaleImgWidth; |
|
|
|
private int scaleImgHeight; |
|
|
|
private int scaleImgHeight; |
|
|
|
private int scaleImgX; |
|
|
|
private int scaleImgX; |
|
|
|
private int scaleImgY; |
|
|
|
private int scaleImgY; |
|
|
|
private double scale = 1.0; |
|
|
|
private double imageScale = 1.0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean draggingLeftDivider = false; |
|
|
|
|
|
|
|
private boolean draggingRightDivider = false; |
|
|
|
|
|
|
|
private boolean draggingTopDivider = false; |
|
|
|
|
|
|
|
private boolean draggingBottomDivider = false; |
|
|
|
|
|
|
|
|
|
|
|
public NinePointLinePreviewPane() { |
|
|
|
public NinePointLinePreviewPane() { |
|
|
|
|
|
|
|
this.setLayout(null); |
|
|
|
this.addMouseMotionListener(this); |
|
|
|
this.addMouseMotionListener(this); |
|
|
|
this.addMouseListener(this); |
|
|
|
this.addMouseListener(this); |
|
|
|
} |
|
|
|
} |
|
|
@ -466,7 +508,9 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
super.paintComponent(g); |
|
|
|
super.paintComponent(g); |
|
|
|
|
|
|
|
|
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
g2d.drawImage(transparentImage, 0, 0, getWidth(), getHeight(), null); |
|
|
|
|
|
|
|
|
|
|
|
g2d.setColor(BACKGROUND_PANE_COLOR); |
|
|
|
|
|
|
|
g2d.fillRect(0, 0, getWidth(), getHeight()); |
|
|
|
|
|
|
|
|
|
|
|
Image image = imagePreviewPane.getImage(); |
|
|
|
Image image = imagePreviewPane.getImage(); |
|
|
|
|
|
|
|
|
|
|
@ -482,90 +526,138 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
scaleImgHeight = (int) (1.0F * scaleImgWidth * imgHeight / imgWidth); |
|
|
|
scaleImgHeight = (int) (1.0F * scaleImgWidth * imgHeight / imgWidth); |
|
|
|
scaleImgX = autoFixAreaX; |
|
|
|
scaleImgX = autoFixAreaX; |
|
|
|
scaleImgY = (autoFixAreaHeight - scaleImgHeight) / 2 + autoFixAreaY; // 垂直居中
|
|
|
|
scaleImgY = (autoFixAreaHeight - scaleImgHeight) / 2 + autoFixAreaY; // 垂直居中
|
|
|
|
scale = 1.0 * scaleImgWidth / imgWidth; |
|
|
|
imageScale = 1.0 * scaleImgWidth / imgWidth; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
scaleImgHeight = autoFixAreaHeight; |
|
|
|
scaleImgHeight = autoFixAreaHeight; |
|
|
|
scaleImgWidth = (int) (1.0F * scaleImgHeight * imgWidth / imgHeight); |
|
|
|
scaleImgWidth = (int) (1.0F * scaleImgHeight * imgWidth / imgHeight); |
|
|
|
scaleImgX = (autoFixAreaWidth - scaleImgWidth) / 2 + autoFixAreaX; // 水平居中
|
|
|
|
scaleImgX = (autoFixAreaWidth - scaleImgWidth) / 2 + autoFixAreaX; // 水平居中
|
|
|
|
scaleImgY = autoFixAreaY; |
|
|
|
scaleImgY = autoFixAreaY; |
|
|
|
scale = 1.0 * scaleImgHeight / imgHeight; |
|
|
|
imageScale = 1.0 * scaleImgHeight / imgHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g2d.setColor(BACKGROUND_IMG_COLOR); |
|
|
|
|
|
|
|
g2d.fillRect(scaleImgX, scaleImgY, scaleImgWidth, scaleImgHeight); |
|
|
|
g2d.drawImage(image, scaleImgX, scaleImgY, scaleImgWidth, scaleImgHeight, null); |
|
|
|
g2d.drawImage(image, scaleImgX, scaleImgY, scaleImgWidth, scaleImgHeight, null); |
|
|
|
|
|
|
|
|
|
|
|
int scaleLeft = (int) (ninePointLeft * scale); |
|
|
|
int scaleLeft = (int) (ninePointLeft * imageScale); |
|
|
|
int scaleTop = (int) (ninePointTop * scale); |
|
|
|
int scaleTop = (int) (ninePointTop * imageScale); |
|
|
|
int scaleRight = (int) (ninePointRight * scale); |
|
|
|
int scaleRight = (int) (ninePointRight * imageScale); |
|
|
|
int scaleBottom = (int) (ninePointBottom * scale); |
|
|
|
int scaleBottom = (int) (ninePointBottom * imageScale); |
|
|
|
|
|
|
|
|
|
|
|
double topYInPane = scaleImgY + scaleTop; |
|
|
|
double topYInPane = scaleImgY + scaleTop; |
|
|
|
double bottomYInPane = scaleImgY + scaleImgHeight - scaleBottom; |
|
|
|
double bottomYInPane = scaleImgY + scaleImgHeight - scaleBottom; |
|
|
|
double leftXInPane = scaleImgX + scaleLeft; |
|
|
|
double leftXInPane = scaleImgX + scaleLeft; |
|
|
|
double rightXInPane = scaleImgX + scaleImgWidth - scaleRight; |
|
|
|
double rightXInPane = scaleImgX + scaleImgWidth - scaleRight; |
|
|
|
|
|
|
|
|
|
|
|
g2d.setColor(PATCH_COLOR); |
|
|
|
// 顶部分割线
|
|
|
|
// draw horizontal patch
|
|
|
|
drawDivider(g2d, scaleImgX, topYInPane, scaleImgX + scaleImgWidth, topYInPane, draggingTopDivider); |
|
|
|
GraphDrawHelper.fillRect(g2d, 0, topYInPane, getWidth(), scaleImgHeight - scaleTop - scaleBottom); |
|
|
|
if (draggingTopDivider) { |
|
|
|
// draw vertical patch
|
|
|
|
// 顶部提示
|
|
|
|
GraphDrawHelper.fillRect(g2d, scaleImgX + scaleLeft, 0,scaleImgWidth - scaleLeft - scaleRight, getHeight()); |
|
|
|
drawHint(g2d, ninePointTop + "px", leftXInPane, scaleImgY, scaleImgWidth - scaleLeft - scaleRight, scaleTop, false); |
|
|
|
|
|
|
|
} |
|
|
|
g2d.setColor(DIVIDER_COLOR); |
|
|
|
// 底部分割线
|
|
|
|
// draw top divider
|
|
|
|
drawDivider(g2d, scaleImgX, bottomYInPane, scaleImgX + scaleImgWidth, bottomYInPane, draggingBottomDivider); |
|
|
|
GraphDrawHelper.drawLine(g2d, 0, topYInPane, getWidth(), topYInPane); |
|
|
|
if (draggingBottomDivider) { |
|
|
|
// draw bottom divider
|
|
|
|
// 底部提示
|
|
|
|
GraphDrawHelper.drawLine(g2d, 0, bottomYInPane, getWidth(), bottomYInPane); |
|
|
|
drawHint(g2d, ninePointBottom + "px", leftXInPane, bottomYInPane, scaleImgWidth - scaleLeft - scaleRight, scaleBottom, false); |
|
|
|
// draw left divider
|
|
|
|
} |
|
|
|
GraphDrawHelper.drawLine(g2d, leftXInPane, 0, leftXInPane, getHeight()); |
|
|
|
// 左侧分割线
|
|
|
|
// draw right divider
|
|
|
|
drawDivider(g2d, leftXInPane, scaleImgY, leftXInPane, scaleImgY + scaleImgHeight, draggingLeftDivider); |
|
|
|
GraphDrawHelper.drawLine(g2d, rightXInPane, 0, rightXInPane, getHeight()); |
|
|
|
if (draggingLeftDivider) { |
|
|
|
|
|
|
|
// 左侧提示
|
|
|
|
g2d.setColor(TEXT_COLOR); |
|
|
|
drawHint(g2d, ninePointLeft + "px", scaleImgX, topYInPane, scaleLeft, scaleImgHeight - scaleTop - scaleBottom, true); |
|
|
|
// draw nine point info
|
|
|
|
} |
|
|
|
GraphDrawHelper.drawString(g2d, Integer.toString(ninePointTop), (leftXInPane + rightXInPane) / 2.0F, topYInPane / 2.0); |
|
|
|
// 右侧分割线
|
|
|
|
GraphDrawHelper.drawString(g2d, Integer.toString(ninePointBottom), (leftXInPane + rightXInPane) / 2.0F, (bottomYInPane + getHeight()) / 2.0); |
|
|
|
drawDivider(g2d, rightXInPane, scaleImgY, rightXInPane, scaleImgY + scaleImgHeight, draggingRightDivider); |
|
|
|
GraphDrawHelper.drawString(g2d, Integer.toString(ninePointLeft), leftXInPane / 2.0, (topYInPane + bottomYInPane) / 2.0); |
|
|
|
if (draggingRightDivider) { |
|
|
|
GraphDrawHelper.drawString(g2d, Integer.toString(ninePointRight), (rightXInPane + getWidth()) / 2.0, (topYInPane + bottomYInPane) / 2.0); |
|
|
|
// 右侧提示
|
|
|
|
|
|
|
|
drawHint(g2d, ninePointRight + "px", rightXInPane, topYInPane, scaleRight, scaleImgHeight - scaleTop - scaleBottom, true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
private void drawHint(Graphics2D g2d, String hint, double x, double y, double width, double height, boolean horizontal) { |
|
|
|
public void mouseDragged(MouseEvent e) { |
|
|
|
FontMetrics metrics = GraphDrawHelper.getFontMetrics(g2d.getFont()); |
|
|
|
int x = e.getX(); |
|
|
|
double hintTextHeight = Math.max(metrics.getAscent() + metrics.getDescent(), 16); |
|
|
|
int y = e.getY(); |
|
|
|
double hintTextWidth = Math.max(metrics.stringWidth(hint), metrics.stringWidth("123")); |
|
|
|
|
|
|
|
double hintFrameRadius = hintTextHeight / 2; |
|
|
|
|
|
|
|
double hintFrameHeight = hintTextHeight; |
|
|
|
|
|
|
|
double hintFrameWidth = hintTextWidth + 2 * hintFrameRadius; |
|
|
|
|
|
|
|
|
|
|
|
int cursorType = getCursor().getType(); |
|
|
|
double centerX = x + width / 2; |
|
|
|
|
|
|
|
double centerY = y + height / 2; |
|
|
|
|
|
|
|
|
|
|
|
switch (cursorType) { |
|
|
|
double indent = 1.0; |
|
|
|
case Cursor.W_RESIZE_CURSOR: { |
|
|
|
double shortLine = 4.0; |
|
|
|
int nextLeft = (int) ((x - scaleImgX) / scale); |
|
|
|
|
|
|
|
if (1 <= nextLeft && nextLeft < imgWidth - ninePointRight) { |
|
|
|
if (horizontal) { |
|
|
|
ninePointLeft = nextLeft; |
|
|
|
if (width > hintFrameWidth) { |
|
|
|
repaint(); |
|
|
|
g2d.setColor(HINT_BACKGROUND_COLOR); |
|
|
|
} |
|
|
|
GraphDrawHelper.draw(g2d, new Line2D.Double(x + indent, centerY, x + width - indent, centerY), Constants.LINE_THIN, 1.0F); |
|
|
|
return; |
|
|
|
GraphDrawHelper.draw(g2d, new Line2D.Double(x + indent, centerY - shortLine, x + indent, centerY + shortLine), Constants.LINE_THIN, 1.0F); |
|
|
|
|
|
|
|
GraphDrawHelper.draw(g2d, new Line2D.Double(x + width - indent, centerY - shortLine, x + width - indent, centerY + shortLine), Constants.LINE_THIN, 1.0F); |
|
|
|
} |
|
|
|
} |
|
|
|
case Cursor.E_RESIZE_CURSOR: { |
|
|
|
|
|
|
|
int nextRight = (int) ((scaleImgX + scaleImgWidth - x) / scale); |
|
|
|
double hintFrameX = centerX - hintFrameWidth / 2; |
|
|
|
if (1 <= nextRight && nextRight < imgWidth - ninePointLeft) { |
|
|
|
double hintFrameY = centerY + HINT_GAP; |
|
|
|
ninePointRight = nextRight; |
|
|
|
|
|
|
|
repaint(); |
|
|
|
g2d.setColor(HINT_BACKGROUND_COLOR); |
|
|
|
|
|
|
|
GraphDrawHelper.fill(g2d, new RoundRectangle2D.Double(hintFrameX, hintFrameY, hintFrameWidth, hintFrameHeight, hintFrameRadius * 2, hintFrameRadius * 2)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g2d.setColor(HINT_FOREGROUND_COLOR); |
|
|
|
|
|
|
|
GraphDrawHelper.drawString(g2d, hint, hintFrameX + (hintFrameWidth - hintTextWidth) / 2, hintFrameY + (hintFrameHeight + hintTextHeight) / 2.0 - metrics.getDescent()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (height > hintFrameHeight) { |
|
|
|
|
|
|
|
g2d.setColor(HINT_BACKGROUND_COLOR); |
|
|
|
|
|
|
|
GraphDrawHelper.draw(g2d, new Line2D.Double(centerX, y + indent, centerX, y + height - indent), Constants.LINE_THIN, 1.0F); |
|
|
|
|
|
|
|
GraphDrawHelper.draw(g2d, new Line2D.Double(centerX - shortLine, y + indent, centerX + shortLine, y + indent), Constants.LINE_THIN, 1.0F); |
|
|
|
|
|
|
|
GraphDrawHelper.draw(g2d, new Line2D.Double(centerX - shortLine, y + height - indent, centerX + shortLine, y + height - indent), Constants.LINE_THIN, 1.0F); |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
double hintFrameX = centerX + HINT_GAP; |
|
|
|
|
|
|
|
double hintFrameY = centerY - hintFrameHeight / 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g2d.setColor(HINT_BACKGROUND_COLOR); |
|
|
|
|
|
|
|
GraphDrawHelper.fill(g2d, new RoundRectangle2D.Double(hintFrameX, hintFrameY, hintFrameWidth, hintFrameHeight, hintFrameRadius * 2, hintFrameRadius * 2)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g2d.setColor(HINT_FOREGROUND_COLOR); |
|
|
|
|
|
|
|
GraphDrawHelper.drawString(g2d, hint, hintFrameX + (hintFrameWidth - hintTextWidth) / 2, hintFrameY + (hintFrameHeight + hintTextHeight) / 2.0 - metrics.getDescent()); |
|
|
|
} |
|
|
|
} |
|
|
|
case Cursor.N_RESIZE_CURSOR: { |
|
|
|
|
|
|
|
int nextTop = (int) ((y - scaleImgY) / scale); |
|
|
|
|
|
|
|
if (1 <= nextTop && nextTop < imgHeight - ninePointBottom) { |
|
|
|
|
|
|
|
ninePointTop = nextTop; |
|
|
|
|
|
|
|
repaint(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
private void drawDivider(Graphics2D g2d, double x1, double y1, double x2, double y2, boolean dragging) { |
|
|
|
|
|
|
|
if (dragging) { |
|
|
|
|
|
|
|
g2d.setColor(DIVIDER_BACKGROUND_COLOR); |
|
|
|
|
|
|
|
GraphDrawHelper.draw(g2d, new Line2D.Double(x1, y1, x2, y2), Constants.LINE_THIN, 2.0F); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g2d.setColor(DIVIDER_FOREGROUND_COLOR); |
|
|
|
|
|
|
|
GraphDrawHelper.draw(g2d, new Line2D.Double(x1, y1, x2, y2), Constants.LINE_THIN, 1.0F); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
g2d.setColor(DIVIDER_BACKGROUND_COLOR); |
|
|
|
|
|
|
|
GraphDrawHelper.draw(g2d, new Line2D.Double(x1, y1, x2, y2), Constants.LINE_DASH, 1.0F); |
|
|
|
} |
|
|
|
} |
|
|
|
case Cursor.S_RESIZE_CURSOR: { |
|
|
|
|
|
|
|
int nextBottom = (int) ((scaleImgY + scaleImgHeight - y) / scale); |
|
|
|
|
|
|
|
if (1 <= nextBottom && nextBottom < imgHeight - ninePointTop) { |
|
|
|
|
|
|
|
ninePointBottom = nextBottom; |
|
|
|
|
|
|
|
repaint(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void mouseDragged(MouseEvent e) { |
|
|
|
|
|
|
|
int x = e.getX(); |
|
|
|
|
|
|
|
int y = e.getY(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cursor cursor = getCursor(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cursor == W_DRAG_CURSOR || cursor == NW_DRAG_CURSOR || cursor == SW_DRAG_CURSOR) { |
|
|
|
|
|
|
|
int nextLeft = (int) ((x - scaleImgX) / imageScale); |
|
|
|
|
|
|
|
this.onNinePointLeftChanged(nextLeft); |
|
|
|
|
|
|
|
} else if (cursor == E_DRAG_CURSOR || cursor == NE_DRAG_CURSOR || cursor == SE_DRAG_CURSOR) { |
|
|
|
|
|
|
|
int nextRight = (int) ((scaleImgX + scaleImgWidth - x) / imageScale); |
|
|
|
|
|
|
|
this.onNinePointRightChanged(nextRight); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cursor == N_DRAG_CURSOR || cursor == NE_DRAG_CURSOR || cursor == NW_DRAG_CURSOR) { |
|
|
|
|
|
|
|
int nextTop = (int) ((y - scaleImgY) / imageScale); |
|
|
|
|
|
|
|
this.onNinePointTopChanged(nextTop); |
|
|
|
|
|
|
|
} else if (cursor == S_DRAG_CURSOR || cursor == SE_DRAG_CURSOR || cursor == SW_DRAG_CURSOR) { |
|
|
|
|
|
|
|
int nextBottom = (int) ((scaleImgY + scaleImgHeight - y) / imageScale); |
|
|
|
|
|
|
|
this.onNinePointBottomChanged(nextBottom); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -576,31 +668,51 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
int x = e.getX(); |
|
|
|
int x = e.getX(); |
|
|
|
int y = e.getY(); |
|
|
|
int y = e.getY(); |
|
|
|
|
|
|
|
|
|
|
|
double scaleLeft = ninePointLeft * scale; |
|
|
|
double scaleLeft = ninePointLeft * imageScale; |
|
|
|
double scaleTop = ninePointTop * scale; |
|
|
|
double scaleTop = ninePointTop * imageScale; |
|
|
|
double scaleRight = ninePointRight * scale; |
|
|
|
double scaleRight = ninePointRight * imageScale; |
|
|
|
double scaleBottom = ninePointBottom * scale; |
|
|
|
double scaleBottom = ninePointBottom * imageScale; |
|
|
|
|
|
|
|
|
|
|
|
// determine cursor
|
|
|
|
// determine cursor
|
|
|
|
int cursorType = Cursor.DEFAULT_CURSOR; |
|
|
|
Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); |
|
|
|
|
|
|
|
|
|
|
|
boolean hoveringLeftDivider = Math.abs(x - (scaleImgX + scaleLeft)) < 2; |
|
|
|
boolean hoveringLeftDivider = false; |
|
|
|
boolean hoveringRightDivider = Math.abs(x - (scaleImgX + scaleImgWidth - scaleRight)) < 2; |
|
|
|
boolean hoveringRightDivider = false; |
|
|
|
boolean hoveringTopDivider = Math.abs(y - (scaleImgY + scaleTop)) < 2; |
|
|
|
boolean hoveringTopDivider = false; |
|
|
|
boolean hoveringBottomDivider = Math.abs(y - (scaleImgY + scaleImgHeight - scaleBottom)) < 2; |
|
|
|
boolean hoveringBottomDivider = false; |
|
|
|
|
|
|
|
|
|
|
|
if (hoveringLeftDivider) { |
|
|
|
if (scaleImgX - 2 <= x && x <= scaleImgX + scaleImgWidth + 2 && scaleImgY - 2 <= y && y <= scaleImgY + scaleImgHeight + 2) { |
|
|
|
cursorType = Cursor.W_RESIZE_CURSOR; |
|
|
|
hoveringLeftDivider = Math.abs(x - (scaleImgX + scaleLeft)) < 2; |
|
|
|
|
|
|
|
hoveringRightDivider = Math.abs(x - (scaleImgX + scaleImgWidth - scaleRight)) < 2; |
|
|
|
|
|
|
|
hoveringTopDivider = Math.abs(y - (scaleImgY + scaleTop)) < 2; |
|
|
|
|
|
|
|
hoveringBottomDivider = Math.abs(y - (scaleImgY + scaleImgHeight - scaleBottom)) < 2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hoveringLeftDivider && hoveringTopDivider) { |
|
|
|
|
|
|
|
cursor = NW_DRAG_CURSOR; |
|
|
|
|
|
|
|
} else if (hoveringLeftDivider && hoveringBottomDivider) { |
|
|
|
|
|
|
|
cursor = SW_DRAG_CURSOR; |
|
|
|
|
|
|
|
} else if (hoveringRightDivider && hoveringTopDivider) { |
|
|
|
|
|
|
|
cursor = NE_DRAG_CURSOR; |
|
|
|
|
|
|
|
} else if (hoveringRightDivider && hoveringBottomDivider) { |
|
|
|
|
|
|
|
cursor = SE_DRAG_CURSOR; |
|
|
|
|
|
|
|
} else if (hoveringLeftDivider) { |
|
|
|
|
|
|
|
cursor = W_DRAG_CURSOR; |
|
|
|
} else if (hoveringRightDivider) { |
|
|
|
} else if (hoveringRightDivider) { |
|
|
|
cursorType = Cursor.E_RESIZE_CURSOR; |
|
|
|
cursor = E_DRAG_CURSOR; |
|
|
|
} else if (hoveringTopDivider) { |
|
|
|
} else if (hoveringTopDivider) { |
|
|
|
cursorType = Cursor.N_RESIZE_CURSOR; |
|
|
|
cursor = N_DRAG_CURSOR; |
|
|
|
} else if (hoveringBottomDivider) { |
|
|
|
} else if (hoveringBottomDivider) { |
|
|
|
cursorType = Cursor.S_RESIZE_CURSOR; |
|
|
|
cursor = S_DRAG_CURSOR; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
needRepaint = getCursor().getType() != cursorType; |
|
|
|
draggingLeftDivider = hoveringLeftDivider; |
|
|
|
this.setCursor(Cursor.getPredefinedCursor(cursorType)); |
|
|
|
draggingRightDivider = hoveringRightDivider; |
|
|
|
|
|
|
|
draggingTopDivider = hoveringTopDivider; |
|
|
|
|
|
|
|
draggingBottomDivider = hoveringBottomDivider; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
needRepaint = getCursor() != cursor; |
|
|
|
|
|
|
|
this.setCursor(cursor); |
|
|
|
|
|
|
|
|
|
|
|
if (needRepaint) { |
|
|
|
if (needRepaint) { |
|
|
|
repaint(); |
|
|
|
repaint(); |
|
|
@ -609,7 +721,7 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
|
|
|
|
|
requestFocus(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -620,6 +732,10 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
|
|
|
this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
|
|
|
|
|
|
|
this.draggingLeftDivider = false; |
|
|
|
|
|
|
|
this.draggingRightDivider = false; |
|
|
|
|
|
|
|
this.draggingTopDivider = false; |
|
|
|
|
|
|
|
this.draggingBottomDivider = false; |
|
|
|
|
|
|
|
|
|
|
|
repaint(); |
|
|
|
repaint(); |
|
|
|
} |
|
|
|
} |
|
|
@ -634,6 +750,45 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onNinePointTopChanged(int value) { |
|
|
|
|
|
|
|
if (value < MIN_NINE_POINT) { |
|
|
|
|
|
|
|
value = MIN_NINE_POINT; |
|
|
|
|
|
|
|
} else if (value >= imgHeight - ninePointBottom) { |
|
|
|
|
|
|
|
value = imgHeight - ninePointBottom - MIN_NINE_POINT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.ninePointTop = value; |
|
|
|
|
|
|
|
repaint(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onNinePointBottomChanged(int value) { |
|
|
|
|
|
|
|
if (value < MIN_NINE_POINT) { |
|
|
|
|
|
|
|
value = MIN_NINE_POINT; |
|
|
|
|
|
|
|
} else if (value >= imgHeight - ninePointTop) { |
|
|
|
|
|
|
|
value = imgHeight - ninePointTop - MIN_NINE_POINT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.ninePointBottom = value; |
|
|
|
|
|
|
|
repaint(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onNinePointLeftChanged(int value) { |
|
|
|
|
|
|
|
if (value < MIN_NINE_POINT) { |
|
|
|
|
|
|
|
value = MIN_NINE_POINT; |
|
|
|
|
|
|
|
} else if (value >= imgWidth - ninePointRight) { |
|
|
|
|
|
|
|
value = imgWidth - ninePointRight - MIN_NINE_POINT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.ninePointLeft = value; |
|
|
|
|
|
|
|
repaint(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onNinePointRightChanged(int value) { |
|
|
|
|
|
|
|
if (value < MIN_NINE_POINT) { |
|
|
|
|
|
|
|
value = MIN_NINE_POINT; |
|
|
|
|
|
|
|
} else if (value >= imgWidth - ninePointLeft) { |
|
|
|
|
|
|
|
value = imgWidth - ninePointLeft - MIN_NINE_POINT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.ninePointRight = value; |
|
|
|
|
|
|
|
repaint(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setNinePoint(int[] ninePoint) { |
|
|
|
public void setNinePoint(int[] ninePoint) { |
|
|
|
ninePointLeft = ninePoint[0]; |
|
|
|
ninePointLeft = ninePoint[0]; |
|
|
|