Skip to content

Commit

Permalink
GUI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AnanasikDev committed Apr 11, 2024
1 parent 577248c commit df32c2c
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions src/calculator/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class Calculator extends JFrame {
private JPanel keyboardPanel; // includes all keys of calculator, exluding ANS
private JPanel buttonPanel; // includes keyboard panel and ansPanel
private JPanel historyPanel;
private JScrollBar historyScrollBar;
private int historyScrollBarLastValue;

private int historyFontSize = 25;
private final String fontName = "Arial";
Expand All @@ -27,7 +25,6 @@ public class Calculator extends JFrame {
public static final Calculator calculator = new Calculator();

private void UpdateOnWindowResize(){
System.out.println(mainPanel.getWidth());
if (mainPanel.getWidth() < 500){
historyPanel.setPreferredSize(new Dimension(0, mainPanel.getHeight()));
historyPanel.setVisible(false);
Expand All @@ -43,8 +40,6 @@ private void UpdateOnWindowResize(){

textField.requestFocus();
adjustHistoryPanel();

historyScrollBar.setBounds(this.getWidth() - 60, 0, 60, this.getHeight());
}
private void UpdateOnHistoryResize(){
UpdateOnWindowResize();
Expand Down Expand Up @@ -74,7 +69,6 @@ public void componentResized(ComponentEvent e) {
}
public void UpdateHistoryScroll(int scrollValue){
int shift = -scrollValue * historyFontSize;
System.out.println("Shift = " + shift);
if (history.getFirst().getLabel().getY() + shift > 20) return;
if (history.getLast().getLabel().getY() + shift < historyPanel.getHeight() - 20) return;
for (HistoryToken token : history){
Expand Down Expand Up @@ -131,35 +125,16 @@ private void InitHistory(){
historyPanel = new JPanel();
historyPanel.setBackground(Color.LIGHT_GRAY);
historyPanel.setPreferredSize(new Dimension(50, getHeight()));
historyPanel.setMinimumSize(new Dimension(0, 0));
historyPanel.setLayout(new BoxLayout(historyPanel, BoxLayout.Y_AXIS));

// JTextArea textArea = new JTextArea();
// textArea.setText("12wqerdfio wlhgyfqwo;lekgidcyfukbhwksjdghcnjka chdsf;nxjsd han");
// historyPanel.add(textArea);
//
// JScrollPane scroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// add(scroll);

historyPanel.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
calculator.UpdateHistoryScroll(e.getWheelRotation());
}
});

historyScrollBar = new JScrollBar();
historyScrollBar.setBounds(this.getWidth() - 60, 0, 60, this.getHeight());
int a = historyScrollBar.getMaximum();
historyScrollBar.addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
calculator.UpdateHistoryScroll(historyScrollBarLastValue - e.getValue());
//System.out.println(a + " " + e.getValue());
historyScrollBarLastValue = e.getValue();
}
});
this.add(historyScrollBar);

historyPanel.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) { UpdateOnHistoryResize(); }
Expand Down

0 comments on commit df32c2c

Please sign in to comment.