-
-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scale the clipart when resizing the dialog (#2538)
- Loading branch information
Showing
37 changed files
with
187 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/clipart/ClipartLabel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.willwinder.ugs.nbp.designer.gui.clipart; | ||
|
||
import javax.swing.JLabel; | ||
import java.awt.event.ComponentAdapter; | ||
import java.awt.event.ComponentEvent; | ||
import java.awt.font.FontRenderContext; | ||
import java.awt.geom.AffineTransform; | ||
import java.awt.geom.Rectangle2D; | ||
|
||
public class ClipartLabel extends JLabel { | ||
public ClipartLabel(String text) { | ||
super(text); | ||
AffineTransform affinetransform = new AffineTransform(); | ||
FontRenderContext frc = new FontRenderContext(affinetransform, true, true); | ||
|
||
addComponentListener(new ComponentAdapter() { | ||
@Override | ||
public void componentResized(ComponentEvent e) { | ||
Rectangle2D stringBounds = getFont().getStringBounds(getText(), frc); | ||
int currentSize = (int) Math.round(Math.max(stringBounds.getWidth(), stringBounds.getHeight())); | ||
float sizeChange = (float) Math.min(getWidth(), getHeight()) / (float) currentSize; | ||
if (sizeChange < 1f || sizeChange > 1.1f) { | ||
int newFontSize = Math.min(Math.round((getFont().getSize() * sizeChange)), getHeight()); | ||
setFont(getFont().deriveFont((float) newFontSize)); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../main/java/com/willwinder/ugs/nbp/designer/gui/clipart/sources/AbstractClipartSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.willwinder.ugs.nbp.designer.gui.clipart.sources; | ||
|
||
import com.willwinder.ugs.nbp.designer.gui.clipart.Category; | ||
import com.willwinder.ugs.nbp.designer.gui.clipart.Clipart; | ||
import com.willwinder.ugs.nbp.designer.gui.clipart.ClipartSource; | ||
|
||
import java.util.List; | ||
|
||
public abstract class AbstractClipartSource implements ClipartSource { | ||
public abstract List<? extends Clipart> getCliparts(); | ||
|
||
@Override | ||
public List<? extends Clipart> getCliparts(Category category) { | ||
return getCliparts() | ||
.stream() | ||
.filter(clipart -> clipart.getCategory() == category || category == Category.ALL) | ||
.toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.