Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

49
LINES

< > BotCompany Repo | #1007501 // ForwardAndBackButtons

JavaX fragment (include)

sclass ForwardAndBackButtons {
  JTextField tf;
  O onClick; // runnable
  JButton btnBack, btnForw;
  new L<S> history;
  int historyIdx;
  
  *(JTextField *tf, O *onClick) {
    btnBack = jbutton(resizeImage(loadImage2(#1007466), 32), r { back() });
    btnForw = jbutton(resizeImage(
      img_getCenterPortion(loadImage2(#1007467), 198, 198), 32), r { forward() });
    update();
  }
  
  JPanel buttons() {
    ret hstackWithSpacing(6, btnBack, btnForw);
  }
  
  void back {
    if (historyIdx <= 1) ret;
    --historyIdx;
    tf.setText(history.get(historyIdx-1));
    go();
  }

  void forward {
    if (historyIdx >= l(history)) ret;
    ++historyIdx;
    tf.setText(history.get(historyIdx-1));
    go();
  }
  
  void go {
    update();
    pcallF(onClick);
  }
  
  void submitted {
    subList(history, historyIdx).clear();
    history.add(getTextTrim(tf));
    ++historyIdx;
    update();
  }
  
  void update {
    btnBack.setEnabled(historyIdx > 1);
    btnForw.setEnabled(historyIdx < l(history));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1007501
Snippet name: ForwardAndBackButtons
Eternal ID of this version: #1007501/3
Text MD5: a4de75988fe3e8d642d65b76744b338d
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-25 17:13:23
Source code size: 1067 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 647 / 1207
Version history: 2 change(s)
Referenced in: [show references]