Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MultiCube
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lafabregue
MultiCube
Commits
afdfc085
Commit
afdfc085
authored
Aug 18, 2017
by
lafabregue
Browse files
Options
Browse Files
Download
Plain Diff
merge constraints dialog branch
parents
bfa9b9a0
e67fc75b
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
3059 additions
and
404 deletions
+3059
-404
cursor_icon.png
cursor_icon.png
+0
-0
resources/icons/icon-pince.png
resources/icons/icon-pince.png
+0
-0
src/mustic/gui/MainFrame.java
src/mustic/gui/MainFrame.java
+44
-12
src/mustic/gui/dialog/classifier/ConstraintsColor.java
src/mustic/gui/dialog/classifier/ConstraintsColor.java
+211
-0
src/mustic/gui/dialog/classifier/ConstraintsSelectionDialog.java
...tic/gui/dialog/classifier/ConstraintsSelectionDialog.java
+779
-392
src/mustic/gui/dialog/classifier/ConstraintsSelectionDialog.java.orig
...ui/dialog/classifier/ConstraintsSelectionDialog.java.orig
+1675
-0
src/mustic/gui/dialog/classifier/messages_en.properties
src/mustic/gui/dialog/classifier/messages_en.properties
+3
-0
src/mustic/gui/dialog/classifier/messages_fr.properties
src/mustic/gui/dialog/classifier/messages_fr.properties
+2
-0
src/mustic/gui/tools/ZoomBoxPanel.java
src/mustic/gui/tools/ZoomBoxPanel.java
+306
-0
src/mustic/gui/tools/Zoomable.java
src/mustic/gui/tools/Zoomable.java
+39
-0
No files found.
cursor_icon.png
0 → 100644
View file @
afdfc085
16.7 KB
resources/icons/icon-pince.png
0 → 100644
View file @
afdfc085
46.3 KB
src/mustic/gui/MainFrame.java
View file @
afdfc085
...
...
@@ -1353,7 +1353,7 @@ public class MainFrame extends JFrame {
menuItemConfig.setText(Messages.getString("MainFrame.11"));
menuItemQuit.setText(Messages.getString("MainFrame.12"));
menuItemClustering.setText(Messages.getString("MainFrame.14"));
menuItemData.setText(Messages.getString("MainFrame.010"));
menuItemData.setText(Messages.getString("MainFrame.010"));
menuItemSegmentation.setText(Messages.getString("MainFrame.17"));
menuItemROI.setText(Messages.getString("MainFrame.21"));
menuItemRoiEval.setText(Messages.getString("MainFrame.22"));
...
...
@@ -1415,7 +1415,7 @@ public class MainFrame extends JFrame {
JPanel westPanel = new JPanel(new BorderLayout());
/** Panel West : default */
// C
e
reation of the Project Tree Interface for datas
// Creation of the Project Tree Interface for datas
JPanel treeDataPanel = new JPanel(new BorderLayout());
JScrollPane treeDataScrollPane = new JScrollPane(this.mDataProjectTree);
treeDataScrollPane.setPreferredSize(new Dimension(180, 100));
...
...
@@ -1425,7 +1425,7 @@ public class MainFrame extends JFrame {
sif_treeDataPanel.setPreferredSize(new Dimension(160, 50));
sif_treeDataPanel.add(treeDataPanel);
// C
e
reation of the Project Tree Interface for images
// Creation of the Project Tree Interface for images
JPanel treeImagePanel = new JPanel(new BorderLayout());
JScrollPane treeImageScrollPane = new JScrollPane(this.mImageProjectTree);
treeImageScrollPane.setPreferredSize(new Dimension(180, 100));
...
...
@@ -1442,7 +1442,7 @@ public class MainFrame extends JFrame {
sif_infosPanel.setPreferredSize(new Dimension(160, 180));
sif_infosPanel.add(this.infosPanel);
// Creation of the Bi
t
d View Interface
// Creation of the Bi
r
d View Interface
this.birdPanel = new JPanel(new BorderLayout());
this.birdPanel.setPreferredSize(new Dimension(160, 100));
...
...
@@ -1480,7 +1480,7 @@ public class MainFrame extends JFrame {
// =============== Creation of the Desktop ================
JPanel panel_desktop = new JPanel(new BorderLayout());
panel_desktop.setOpaque(false);
panel_desktop.setBorder(Borders.DIALOG
_BORDER
);
panel_desktop.setBorder(Borders.DIALOG);
panel_desktop.add(this.desktop);
sif_desktop = new SimpleInternalFrame(Messages.getString("MainFrame.72")); //$NON-NLS-1$
...
...
@@ -1494,7 +1494,7 @@ public class MainFrame extends JFrame {
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(false);
panel.setBorder(Borders.DIALOG
_BORDER
);
panel.setBorder(Borders.DIALOG);
panel.add(pane);
// =============== Creation of the Progress Panel => South
...
...
@@ -1529,6 +1529,37 @@ public class MainFrame extends JFrame {
// Selection par defaut
this.birdPanel.requestFocus();
}
//TODO to remove
// method for resizing an image while keeping aspect ratio
private static BufferedImage resizeImage(BufferedImage originalImage, int type, int frameWidth, int frameHeight) {
double height = originalImage.getHeight();
double width = originalImage.getWidth();
int newWidth, newHeight;
// if image size smaller than window size, do not resize
if (height < frameHeight && width < frameWidth) {
newWidth = (int) width;
newHeight = (int) height;
}
// else resize
else {
double scaleX = (frameWidth / width);
double scaleY = (frameHeight / height);
double scale = Math.min(scaleX, scaleY);
newWidth = (int) (width * scale);
newHeight = (int) (height * scale);
}
BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
g.dispose();
return resizedImage;
}
// 20120309_MBH-Test-Fin
/**
...
...
@@ -1548,7 +1579,7 @@ public class MainFrame extends JFrame {
JPanel westPanel = new JPanel(new BorderLayout());
/** Panel West : default */
// C
e
reation of the Project Tree Interface for datas
// Creation of the Project Tree Interface for datas
JPanel treeDataPanel = new JPanel(new BorderLayout());
JScrollPane treeDataScrollPane = new JScrollPane(this.mDataProjectTree);
treeDataScrollPane.setPreferredSize(new Dimension(180, 100));
...
...
@@ -1558,7 +1589,7 @@ public class MainFrame extends JFrame {
sif_treeDataPanel.setPreferredSize(new Dimension(160, 50));
sif_treeDataPanel.add(treeDataPanel);
// C
e
reation of the Project Tree Interface for images
// Creation of the Project Tree Interface for images
JPanel treeImagePanel = new JPanel(new BorderLayout());
JScrollPane treeImageScrollPane = new JScrollPane(this.mImageProjectTree);
treeImageScrollPane.setPreferredSize(new Dimension(180, 100));
...
...
@@ -1567,6 +1598,7 @@ public class MainFrame extends JFrame {
sif_treeImagePanel = new SimpleInternalFrame(Messages.getString("MainFrame.691")); //$NON-NLS-1$
sif_treeImagePanel.setPreferredSize(new Dimension(160, 50));
sif_treeImagePanel.add(treeImagePanel);
// Creation of the Informations Panel Interface
this.infosPanel = new JPanel(new BorderLayout());
...
...
@@ -1575,7 +1607,7 @@ public class MainFrame extends JFrame {
sif_infosPanel.setPreferredSize(new Dimension(160, 180));
sif_infosPanel.add(this.infosPanel);
// Creation of the Bi
t
d View Interface
// Creation of the Bi
r
d View Interface
this.birdPanel = new JPanel(new BorderLayout());
this.birdPanel.setPreferredSize(new Dimension(160, 100));
...
...
@@ -1595,7 +1627,7 @@ public class MainFrame extends JFrame {
JSplitPane pane4 = Factory.createStrippedSplitPane(JSplitPane.VERTICAL_SPLIT,
pane3, sif_birdPanel, 1f);
pane3.setOpaque(false);
westPanel.add(pane4, BorderLayout.CENTER);
/** End of operation => Panel West : default */
...
...
@@ -1615,7 +1647,7 @@ public class MainFrame extends JFrame {
// =============== Creation of the Desktop ================
JPanel panel_desktop = new JPanel(new BorderLayout());
panel_desktop.setOpaque(false);
panel_desktop.setBorder(Borders.DIALOG
_BORDER
);
panel_desktop.setBorder(Borders.DIALOG);
panel_desktop.add(this.desktop);
sif_desktop = new SimpleInternalFrame(Messages.getString("MainFrame.72")); //$NON-NLS-1$
...
...
@@ -1629,7 +1661,7 @@ public class MainFrame extends JFrame {
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(false);
panel.setBorder(Borders.DIALOG
_BORDER
);
panel.setBorder(Borders.DIALOG);
panel.add(pane);
// =============== Creation of the Progress Panel => South
...
...
src/mustic/gui/dialog/classifier/ConstraintsColor.java
0 → 100644
View file @
afdfc085
package
mustic.gui.dialog.classifier
;
import
java.awt.BorderLayout
;
import
java.awt.Color
;
import
java.awt.Dimension
;
import
java.awt.GridLayout
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.util.Vector
;
import
javax.swing.BorderFactory
;
import
javax.swing.JButton
;
import
javax.swing.JColorChooser
;
import
javax.swing.JDialog
;
import
javax.swing.JLabel
;
import
javax.swing.JPanel
;
import
javax.swing.JScrollPane
;
import
javax.swing.ScrollPaneConstants
;
import
javax.swing.border.EtchedBorder
;
import
javax.swing.border.TitledBorder
;
/**
* Dialog that allows the user to change the color of the constraints
*/
public
class
ConstraintsColor
extends
JDialog
{
private
static
final
long
serialVersionUID
=
1L
;
/** constraints colors */
private
Color
mustLinkColor
=
new
Color
(
124
,
252
,
0
);
private
Color
cannotLinkColor
=
new
Color
(
255
,
0
,
255
);
private
Vector
<
Color
>
labelConstraintColor
=
new
Vector
<
Color
>();
/** constraints buttons */
private
JButton
jb_mustLinkChooseColor
=
new
JButton
();
private
JButton
jb_cannotLinkChooseColor
=
new
JButton
();
private
Vector
<
JButton
>
jb_labelConstraintClassChooseColor
=
new
Vector
<
JButton
>();
/** dynamic JPanel Colors of Label Constraints Classes*/
JPanel
labelColorConstraintPanel
=
new
JPanel
(
new
GridLayout
(
0
,
1
));
private
ConstraintsSelectionDialog
dialog
=
null
;
/**
* @brief Constructor dialog window that allows the user to change the color of the constraints
* @param d
* @param colorML
* @param colorCL
* @param colorVectorLabel
*/
public
ConstraintsColor
(
ConstraintsSelectionDialog
d
,
Color
colorML
,
Color
colorCL
,
Vector
<
Color
>
colorVectorLabel
)
{
this
.
dialog
=
d
;
this
.
mustLinkColor
=
colorML
;
this
.
cannotLinkColor
=
colorCL
;
this
.
labelConstraintColor
=
colorVectorLabel
;
//buttons action listeners that allow the user to choose the color of the constraint
jb_cannotLinkChooseColor
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
chooseCannotLinkColor
();
}
});
jb_mustLinkChooseColor
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
chooseMustLinkColor
();
}
});
// creates the panel for the label constraints
for
(
int
i
=
0
;
i
<
dialog
.
getClassCounter
();
i
++)
{
JButton
jb
=
new
JButton
();
jb_labelConstraintClassChooseColor
.
add
(
jb
);
jb_labelConstraintClassChooseColor
.
get
(
i
).
putClientProperty
(
"index"
,
i
);
jb_labelConstraintClassChooseColor
.
get
(
i
).
setBackground
(
labelConstraintColor
.
get
(
i
));
createLabelColorConstraintsPanel
(
i
);
}
this
.
setTitle
(
"Choose Constraints Colors"
);
chooseConstraintColors
();
}
/**
* Add the last created label constraint class name(number) and its color
* button to the panel labelColorConstraintPanel. The button allows user to
* choose the label constraint class color.
**/
protected
void
createLabelColorConstraintsPanel
(
int
index
)
{
JPanel
classNameButtonPanel
=
new
JPanel
(
new
GridLayout
(
1
,
2
));
classNameButtonPanel
.
setBorder
(
BorderFactory
.
createEmptyBorder
(
3
,
3
,
3
,
3
));
classNameButtonPanel
.
add
(
new
JLabel
(
"Class "
+
(
index
+
1
)
+
":"
));
jb_labelConstraintClassChooseColor
.
get
(
index
).
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
event
)
{
JButton
lblClassColorButtonClicked
=
(
JButton
)
event
.
getSource
();
int
buttonIndex
=
(
int
)
lblClassColorButtonClicked
.
getClientProperty
(
"index"
);
chooseLabelClassColor
(
buttonIndex
);
}
});
classNameButtonPanel
.
add
(
jb_labelConstraintClassChooseColor
.
get
(
index
));
labelColorConstraintPanel
.
add
(
classNameButtonPanel
);
}
/** Opens a JDialog for choosing the Constraints Colors*/
protected
void
chooseConstraintColors
()
{
JPanel
constraintsPanel
=
new
JPanel
(
new
BorderLayout
());
JPanel
mlConstraintsPanel
=
new
JPanel
();
JPanel
clConstraintsPanel
=
new
JPanel
();
JPanel
mlclConstraintsPanel
=
new
JPanel
(
new
GridLayout
(
2
,
1
));
JPanel
supportPanel
=
new
JPanel
(
new
BorderLayout
());
supportPanel
.
add
(
labelColorConstraintPanel
,
BorderLayout
.
NORTH
);
JScrollPane
lblConstraintsPane
=
new
JScrollPane
(
supportPanel
,
ScrollPaneConstants
.
VERTICAL_SCROLLBAR_ALWAYS
,
ScrollPaneConstants
.
HORIZONTAL_SCROLLBAR_NEVER
);
TitledBorder
lblcBorder
=
BorderFactory
.
createTitledBorder
(
BorderFactory
.
createEtchedBorder
(
EtchedBorder
.
LOWERED
),
"Label Constraints Color"
,
TitledBorder
.
LEFT
,
TitledBorder
.
TOP
);
lblConstraintsPane
.
setBorder
(
lblcBorder
);
// must-link constraints panel
mlConstraintsPanel
.
setLayout
(
new
BorderLayout
());
TitledBorder
mlcBorder
=
BorderFactory
.
createTitledBorder
(
BorderFactory
.
createEtchedBorder
(
EtchedBorder
.
LOWERED
),
"Must-Link Constraints Color"
,
TitledBorder
.
LEFT
,
TitledBorder
.
TOP
);
mlConstraintsPanel
.
setBorder
(
mlcBorder
);
mlConstraintsPanel
.
add
(
jb_mustLinkChooseColor
,
BorderLayout
.
CENTER
);
mlclConstraintsPanel
.
add
(
mlConstraintsPanel
);
// cannot-link constraints panel
clConstraintsPanel
.
setLayout
(
new
BorderLayout
());
TitledBorder
clcBorder
=
BorderFactory
.
createTitledBorder
(
BorderFactory
.
createEtchedBorder
(
EtchedBorder
.
LOWERED
),
"Cannot-Link Constraints Color"
,
TitledBorder
.
LEFT
,
TitledBorder
.
TOP
);
clConstraintsPanel
.
setBorder
(
clcBorder
);
clConstraintsPanel
.
add
(
jb_cannotLinkChooseColor
,
BorderLayout
.
CENTER
);
mlclConstraintsPanel
.
add
(
clConstraintsPanel
);
// button panel
JPanel
buttonPanel
=
new
JPanel
();
JButton
ok
=
new
JButton
(
"OK"
);
// update color changes on ok, update only fields that have changed
ok
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
event
)
{
dialog
.
setColorML
(
mustLinkColor
);
dialog
.
setColorCL
(
cannotLinkColor
);
dialog
.
setColorLabels
(
labelConstraintColor
);
ConstraintsColor
.
this
.
dispose
();
}
});
// exit dialog on cancel
JButton
cancel
=
new
JButton
(
"Cancel"
);
cancel
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
event
)
{
ConstraintsColor
.
this
.
dispose
();
}
});
jb_mustLinkChooseColor
.
setBackground
(
mustLinkColor
);
jb_cannotLinkChooseColor
.
setBackground
(
cannotLinkColor
);
buttonPanel
.
add
(
ok
);
buttonPanel
.
add
(
cancel
);
constraintsPanel
.
add
(
mlclConstraintsPanel
,
BorderLayout
.
NORTH
);
constraintsPanel
.
add
(
lblConstraintsPane
,
BorderLayout
.
CENTER
);
constraintsPanel
.
add
(
buttonPanel
,
BorderLayout
.
SOUTH
);
this
.
add
(
constraintsPanel
,
BorderLayout
.
CENTER
);
this
.
setPreferredSize
(
new
Dimension
(
270
,
270
));
this
.
pack
();
this
.
setLocationRelativeTo
(
null
);
this
.
setModal
(
true
);
this
.
setVisible
(
true
);
}
/**
* Color Chooser for Must-Link constraints\n Sets the temporary color and
* button indicating the chosen color.
*/
protected
void
chooseMustLinkColor
()
{
mustLinkColor
=
JColorChooser
.
showDialog
(
this
,
"Must-Link Color Chooser"
,
Color
.
red
);
this
.
jb_mustLinkChooseColor
.
setBackground
(
mustLinkColor
);
}
/**
* Color Chooser for Cannot-Link constraints\n Sets the temporary color and
* button indicating the chosen color.
**/
protected
void
chooseCannotLinkColor
()
{
this
.
cannotLinkColor
=
JColorChooser
.
showDialog
(
this
,
"Cannot-Link Color Chooser"
,
//$NON-NLS-1$
cannotLinkColor
);
this
.
jb_cannotLinkChooseColor
.
setBackground
(
cannotLinkColor
);
}
/**
* Color Chooser for a Label constraint of the class "classID" \n Sets the
* temporary color and button indicating the chosen color for the class.
**/
protected
void
chooseLabelClassColor
(
int
indexClass
)
{
Color
lblCColorTemp
=
JColorChooser
.
showDialog
(
this
,
"Label Class Color Chooser"
,
Color
.
red
);
//$NON-NLS-1$
this
.
labelConstraintColor
.
set
(
indexClass
,
lblCColorTemp
);
this
.
jb_labelConstraintClassChooseColor
.
get
(
indexClass
).
setBackground
(
lblCColorTemp
);
}
}
src/mustic/gui/dialog/classifier/ConstraintsSelectionDialog.java
View file @
afdfc085
This diff is collapsed.
Click to expand it.
src/mustic/gui/dialog/classifier/ConstraintsSelectionDialog.java.orig
0 → 100644
View file @
afdfc085
This diff is collapsed.
Click to expand it.
src/mustic/gui/dialog/classifier/messages_en.properties
View file @
afdfc085
...
...
@@ -62,5 +62,8 @@ ConstraintsSelectionDialog.526=Export
ConstraintsSelectionDialog.53
=
Unknown file format for import
ConstraintsSelectionDialog.54
=
Error
ConstraintsSelectionDialog.55
=
Cancel
ConstraintsSelectionDialog.56
=
Constraints Colors
ConstraintsSelectionDialog.57
=
Hide Constraints
ConstraintsSelectionDialog.58
=
Zoom Box
ConstraintsSelectionDialog.7
=
Image
ConstraintsSelectionDialog.8
=
Constraint selection
src/mustic/gui/dialog/classifier/messages_fr.properties
View file @
afdfc085
...
...
@@ -62,5 +62,7 @@ ConstraintsSelectionDialog.526=Export
ConstraintsSelectionDialog.53
=
Format de fichier inconnu lors de l'import
ConstraintsSelectionDialog.54
=
Erreur
ConstraintsSelectionDialog.55
=
Annuler
ConstraintsSelectionDialog.56
=
Couleurs de contraintes
ConstraintsSelectionDialog.57
=
Cacher les contraintes
ConstraintsSelectionDialog.7
=
Image
ConstraintsSelectionDialog.8
=
Slection des contraintes
src/mustic/gui/tools/ZoomBoxPanel.java
0 → 100644
View file @
afdfc085
package
mustic.gui.tools
;
import
java.awt.Color
;
import
java.awt.Graphics
;
import
java.awt.Graphics2D
;
import
java.awt.Image
;
import
java.awt.Point
;
import
java.awt.Rectangle
;
import
java.awt.event.MouseAdapter
;
import
java.awt.event.MouseEvent
;
import
java.awt.image.BufferedImage
;
import
javax.swing.JPanel
;
/**
* Creates a zoom box over a displayed image
*
* @author Marija Kirandjiska
*
*/
public
class
ZoomBoxPanel
extends
JPanel
{
/** */
private
static
final
long
serialVersionUID
=
1L
;
private
Point
zoomPoint
;
private
Zoomable
dialog
;
private
float
zoomMin
=
1.5f
;
private
float
zoom
=
2.0f
;
private
final
float
zoomStep
=
0.1f
;
private
final
int
zoomAreaAdd
=
5
;
private
final
int
zoomAreaMin
=
50
;
private
final
int
zoomAreaMax
=
300
;
private
int
zoomArea
=
120
;
private
boolean
zoomBoxEnabled
=
false
;
public
ZoomBoxPanel
(
Zoomable
dialog
,
float
zoom
,
int
zoomArea
)
{
this
(
dialog
);
this
.
zoom
=
zoom
;
this
.
zoomArea
=
zoomArea
;
}
public
ZoomBoxPanel
(
Zoomable
dialog
)
{
this
.
dialog
=
dialog
;
addMouseMotionListener
(
new
MouseAdapter
()
{
@Override
public
void
mouseMoved
(
MouseEvent
e
)
{
zoomPoint
=
e
.
getPoint
();
// method paintComponent() called
repaint
();
}
});
addMouseListener
(
new
MouseAdapter
()
{
@Override
public
void
mouseEntered
(
MouseEvent
e
)
{
// method paintComponent() called
repaint
();
}
@Override
public
void
mouseExited
(
MouseEvent
e
)
{
zoomPoint
=
null
;
// method paintComponent() called
repaint
();
}
});
}
/**
* This method paints the image and the zoom box.
* If the mouse point is out of the image bounds the zoom box is not displayed
*/
@Override
protected
void
paintComponent
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
if
(
dialog
.
getDisplayedImage
()
!=
null
)
{
Graphics2D
g2d
=
(
Graphics2D
)
g
.
create
();
Point
offset
=
getOffset
();
g2d
.
drawImage
(
dialog
.
getDisplayedImage
(),
offset
.
x
,
offset
.
y
,
this
);
if
(
zoomBoxEnabled
&&
zoomPoint
!=
null
)
{
BufferedImage
zoomBuffer
=
updateBuffer
(
zoomPoint
);
if
(
zoomBuffer
!=
null
)
{
Rectangle
bounds
=
getZoomBounds
();
Rectangle
imgBounds
=
getImageBounds
();
if
(
zoomPoint
.
x
>
imgBounds
.
x
&&
zoomPoint
.
x
<
offset
.
x
+
imgBounds
.
width
&&
zoomPoint
.
y
>
offset
.
y
&&
zoomPoint
.
y
<
offset
.
y
+
imgBounds
.
height
)
{
g2d
.
drawImage
(
zoomBuffer
,
bounds
.
x
,
bounds
.
y
,
this
);
g2d
.
setColor
(
Color
.
RED
);
g2d
.
draw
(
bounds
);
}
}
}
g2d
.
dispose
();
}
}
/**
* Getter of the zoom box visibility
* @return true if the zoom box is enabled,
* false otherwise
*/
public
boolean
zoomBoxEnabled
()
{
return
zoomBoxEnabled
;
}
/**
* Setter for the visibility of the zoom box.
*/
public
void
setZoomBoxEnabled
(
boolean
zoomBoxEnabled
)
{
this
.
zoomBoxEnabled
=
zoomBoxEnabled
;
repaint
();
}
/**
* Setter for the rate of zoom in the zoom box.
*/
public
void
setZoom
(
float
zoom
)
{
this
.
zoom
=
zoom
;
repaint
();
}
/**
* Zoom in the zoom box.
*/
public
void
zoomInBox
()
{
this
.
zoom
+=
zoomStep
;
repaint
();
}
/**
* Zoom out of the zoom box.
*/
public
void
zoomOutBox
()
{
if
(
this
.
zoom
-
this
.
zoomStep
>
zoomMin
)
{
this
.
zoom
-=
this
.
zoomStep
;
}
repaint
();
}
/**
* Increase the zoom box area by ZOOM_AREA_ADD.
*/
public
void
increaseZoomBoxArea
()
{
if
(
this
.
zoomArea
+
this
.
zoomAreaAdd
<=
zoomAreaMax
)
{
this
.
zoomArea
+=
this
.
zoomAreaAdd
;
}
repaint
();
}
/**
* Decrease the zoom box area by ZOOM_AREA_ADD.
*/
public
void
decreaseZoomBoxArea
()
{
if
(
this
.
zoomArea
-
this
.
zoomAreaAdd
>=
zoomAreaMin
)
{
this
.
zoomArea
-=
this
.
zoomAreaAdd
;
}
repaint
();
}
/**
* @return the offset of the image displayed in the panel
*/
protected
Point
getOffset
()
{
if
(
dialog
.
getDisplayedImage
()
==
null
)
{
return
new
Point
(
0
,
0
);
}
int
x
=
(
getWidth
()
-
dialog
.
getDisplayedImage
().
getWidth
())
/
2
;
int
y
=
(
getHeight
()
-
dialog
.
getDisplayedImage
().
getHeight
())
/
2
;
return
new
Point
(
x
,
y
);
}
/**
* @return the bounds around the image displayed in the panel
*/
protected
Rectangle
getImageBounds
()
{
Rectangle
bounds
=
new
Rectangle
(
0
,
0
,
0
,
0
);
if
(
dialog
.
getDisplayedImage
()
!=
null
)
{
bounds
.
setLocation
(
getOffset
());
bounds
.
setSize
(
dialog
.
getDisplayedImage
().
getWidth
(),
dialog
.
getDisplayedImage
().
getHeight
());
}
return
bounds
;
}
/**
* This method creates the zoomed image around the mouse point.
*
* @param p
* mouse point coordinates relative to the panel
*
* @return the zoomed image that fits the zoom box
*/
protected
BufferedImage
updateBuffer
(
Point
p
)
{
if
(
zoomPoint
==
null
)
{
return
null
;
}
Rectangle
bounds
=
getZoomBounds
();
Point
offset
=
getOffset
();
Image
scaled
;
// coordinates relative to image
bounds
.
x
=
bounds
.
x
-
offset
.
x
;
bounds
.
y
=
bounds
.
y
-
offset
.
y
;
// if out of bounds
if
(
bounds
.
x
<
0
||
bounds
.
y
<
0
||
bounds
.
width
<=
0
||
bounds
.
height
<=
0
)
{
return
null
;
}
BufferedImage
zoomBuffer
=
new
BufferedImage
(
bounds
.
width
,
bounds
.
height
,
BufferedImage
.
TYPE_INT_ARGB
);
Graphics2D
g2d
=
zoomBuffer
.
createGraphics
();
scaled
=
dialog
.
getMatchingImage
(
bounds
.
x
,
bounds
.
y
,
bounds
.
width
,
bounds
.
height
,
zoom
);
// if the zoom box is within image area
if
(
bounds
.
width
==
zoomArea
&&
bounds
.
height
==
zoomArea
)
{
int
srcx
=
(
scaled
.
getWidth
(
null
)-
bounds
.
width
)/
2
;
int
srcy
=
(
scaled
.
getHeight
(
null
)-
bounds
.
height
)/
2
;
g2d
.
drawImage
(
scaled
,
0
,
0
,
bounds
.
width
,
bounds
.
height
,
srcx
,
srcy
,
srcx
+
bounds
.
width
,
srcy
+
bounds
.
height
,
this
);