Skip to content

Commit

Permalink
Remove custom sizing and drawing code for VBasicArrowButton, `VScro…
Browse files Browse the repository at this point in the history
…llBarUI`, and `VScrollPaneUI`
  • Loading branch information
Valkryst committed Nov 24, 2024
1 parent 6c0cf04 commit da41888
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 126 deletions.
90 changes: 0 additions & 90 deletions src/main/java/com/valkryst/VTerminal/plaf/VBasicArrowButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,94 +15,4 @@ public VBasicArrowButton(final int direction) {
super.setBackground(UIManager.getColor("ScrollBar.background"));
super.setForeground(UIManager.getColor("ScrollBar.foreground"));
}

@Override
public void paint(final Graphics graphics) {
int width = super.getWidth();
int height = super.getHeight();

final var isPressed = super.getModel().isPressed();

graphics.setColor(UIManager.getColor("ScrollBar.track"));
graphics.fillRect(0, 0, super.getWidth(), super.getHeight());

graphics.setColor(isPressed ? super.getForeground() : super.getBackground());
switch (super.getDirection()) {
case SwingConstants.NORTH: {
graphics.fillRect(0, 0, width, height - 2);
graphics.setColor(super.getForeground());
graphics.drawLine(0, 0, 0, height);
graphics.drawLine(1, height - 2, width - 1, height - 2);
break;
}
case SwingConstants.SOUTH: {
graphics.fillRect(0, 2, width, height - 2);
graphics.setColor(super.getForeground());
graphics.drawLine(0, 0, 0, height);
graphics.drawLine(1, 1, width - 1, 1);
graphics.drawLine(1, height - 1, width - 1, height - 1);
break;
}
case SwingConstants.WEST: {
graphics.fillRect(0, 0, width - 2, height);
graphics.setColor(super.getForeground());
graphics.drawLine(0, 0, width, 0);
graphics.drawLine(width - 2, 0, width - 2, height - 1);
break;
}
case SwingConstants.EAST: {
graphics.fillRect(2, 0, width, height);
graphics.setColor(super.getForeground());
graphics.drawLine(0, 0, width, 0);
graphics.drawLine(1, 0, 1, height - 1);
graphics.drawLine(width - 1, 0, width - 1, height - 1);
break;
}
}

// If there's no room to draw arrow, bail
if (height < 5 || width < 5) {
return;
}

if (isPressed) {
graphics.translate(1, 1);
}

// Draw the arrow
int size = Math.min((height - 4) / 3, (width - 4) / 3);
size = Math.max(size, 2);
paintTriangle(graphics, (width - size) / 2, (height - size) / 2,
size, direction, super.isEnabled());

// Reset the Graphics back to its original settings
if (isPressed) {
graphics.translate(-1, -1);
}
}

@Override
public Dimension getMaximumSize() {
return getPreferredSize();
}

@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}

@Override
public Dimension getPreferredSize() {
final var laf = VTerminalLookAndFeel.getInstance();

switch (super.getDirection()) {
case SwingConstants.EAST:
case SwingConstants.WEST: {
return new Dimension(laf.getTileWidth() * 2, laf.getTileHeight());
}
default: {
return new Dimension(laf.getTileWidth(), laf.getTileHeight());
}
}
}
}
18 changes: 0 additions & 18 deletions src/main/java/com/valkryst/VTerminal/plaf/VScrollBarUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,4 @@ protected JButton createDecreaseButton(final int orientation) {
protected JButton createIncreaseButton(final int orientation) {
return new VBasicArrowButton(orientation);
}

@Override
public Dimension getMaximumSize(final JComponent component) {
final var laf = VTerminalLookAndFeel.getInstance();
return laf.clampDimensionToTileMultiples(super.getMaximumSize(component));
}

@Override
public Dimension getMinimumSize(final JComponent component) {
final var laf = VTerminalLookAndFeel.getInstance();
return laf.clampDimensionToTileMultiples(super.getMinimumSize(component));
}

@Override
public Dimension getPreferredSize(final JComponent component) {
final var laf = VTerminalLookAndFeel.getInstance();
return laf.clampDimensionToTileMultiples(super.getPreferredSize(component));
}
}
18 changes: 0 additions & 18 deletions src/main/java/com/valkryst/VTerminal/plaf/VScrollPaneUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,4 @@ public void keyPressed(final KeyEvent e) {

return new VScrollPaneUI();
}

@Override
public Dimension getMaximumSize(final JComponent component) {
final var laf = VTerminalLookAndFeel.getInstance();
return laf.clampDimensionToTileMultiples(super.getMaximumSize(component));
}

@Override
public Dimension getMinimumSize(final JComponent component) {
final var laf = VTerminalLookAndFeel.getInstance();
return laf.clampDimensionToTileMultiples(super.getMinimumSize(component));
}

@Override
public Dimension getPreferredSize(final JComponent component) {
final var laf = VTerminalLookAndFeel.getInstance();
return laf.clampDimensionToTileMultiples(super.getPreferredSize(component));
}
}

0 comments on commit da41888

Please sign in to comment.