I am drawing blocks of various amino acids (array of aminoacid objects), where one line of amino acids represents one sequence.
aminoacid class:
public void renderShape() {
shaperenderer.setProjectionMatrix(cam.combined);
shaperenderer.begin(ShapeType.Filled);
shaperenderer.setColor(cc.getR(), cc.getG(), cc.getB(), 0);
shaperenderer.rect(xpos, ypos, aawidth, aaheight);
shaperenderer.end();
}
public void renderBatch() {
batch.setProjectionMatrix(cam.combined);
batch.begin();
font.setColor(Color.BLACK);
font.draw(batch, name, xpos+Game.AAFONTOFFSETX, ypos+Game.AAFONTOFFSETY);
batch.end();
}
Now I need a way to drag and drop feature to move the individual blocks. How can I do this? Can I use the DragAndDrop class of libGDX? If so, how should I do it??
As a side note, I found a way to do it without libGDX:
public class AminoAcidDragAndDrop extends JFrame {
private String brr_A = "EAQITAPFELSAFTGRPEWI";
private JTable table;
private DefaultTableModel tableModel;
private DefaultTableModel getDefaultTableModel() {
String[] cols = new String[brr_A.length()];
for (int i = 0; i < brr_A.length(); i++) {
String currentAminoAcid = String.valueOf(brr_A.charAt(i));
cols[i] = currentAminoAcid;
}
return new DefaultTableModel(null, cols);
}
public AminoAcidDragAndDrop() {
super("Amino Acid Drag and Drop Demo");
tableModel = getDefaultTableModel();
table = new JTable(tableModel);
JScrollPane sp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
getContentPane().add(sp, BorderLayout.CENTER);
getContentPane().setPreferredSize(new Dimension(1024, 768));
}
private static void createAndShowGUI() {
// Create and set up the window.
AminoAcidDragAndDrop test = new AminoAcidDragAndDrop();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Display the window.
test.pack();
test.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// Turn off metal's use of bold fonts
// UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
}
Can I convert it for libGDX? If so, how?
I also tried it with Actors but how can I use an Actor array? Would an ArrayList<> work?
Now I can move the first aminoacid, but DragAnDrop needs a final int. How can I solve this for all aminoacids?
public void drop (Source source, Payload payload, float x, float y, int pointer) {
aminoacidlist.get(aaiddnd).setBounds(aminoacidlist.get(aaiddnd).getXpos()+Game.AAWIDTH, aminoacidlist.get(aaiddnd).getYpos(), Game.AAWIDTH, Game.AAHEIGHT);
minoacidlist.get(aaiddnd+1).setBounds(aminoacidlist.get(aaiddnd+1).getXpos()-Game.AAWIDTH, aminoacidlist.get(aaiddnd+1).getYpos(), Game.AAWIDTH, Game.AAHEIGHT);
}
The compiler tells me:
aaiddnd cannot refer to a non-final local variable.
