Last active
March 10, 2019 12:24
-
-
Save ezhov-da/002d3a95a6a9070f6d9ef414716c4c9b to your computer and use it in GitHub Desktop.
test
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
package ru.ezhov.runner; | |
import javax.swing.*; | |
import java.awt.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class App { | |
public static void main(String[] args) { | |
SwingUtilities.invokeLater(() -> { | |
try { | |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |
} catch (Throwable ex) { | |
// | |
} | |
ApplicationItemDao applicationItemDao = new ApplicationItemDao(); | |
ApplicationContainerPanel applicationContainerPanel = new ApplicationContainerPanel(); | |
List<ApplicationItem> applicationItems = applicationItemDao.getAll(); | |
JPopupMenu popupMenu = new JPopupMenu(); | |
applicationItems.forEach(ai -> applicationContainerPanel.addApplicationPanel(new ApplicationPanel(ai))); | |
applicationItems.forEach(ai -> popupMenu.add(new ApplicationPanel(ai))); | |
applicationContainerPanel.reload(); | |
JFrame frame = new JFrame("_________"); | |
frame.add(new JScrollPane(applicationContainerPanel), BorderLayout.CENTER); | |
JButton button = new JButton("TEST"); | |
button.addActionListener(e -> { | |
popupMenu.show(button, 0, 0); | |
}); | |
// frame.add(button, BorderLayout.NORTH); | |
frame.setSize(500, 500); | |
frame.setLocationRelativeTo(null); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.setVisible(true); | |
}); | |
} | |
} | |
class ApplicationContainerPanel extends JPanel { | |
private List<ApplicationPanel> applicationPanels = new ArrayList<>(); | |
public ApplicationContainerPanel() { | |
init(); | |
} | |
private void init() { | |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); | |
} | |
public void addApplicationPanel(ApplicationPanel applicationPanel) { | |
applicationPanels.add(applicationPanel); | |
} | |
public void reload() { | |
SwingUtilities.invokeLater(() -> { | |
removeAll(); | |
for (ApplicationPanel applicationPanel : applicationPanels) { | |
add(applicationPanel); | |
} | |
revalidate(); | |
}); | |
} | |
} | |
class ApplicationPanel extends JPanel { | |
private ApplicationItem applicationItem; | |
private JButton buttonUp; | |
private JButton buttonDown; | |
private JLabel labelName; | |
private JButton buttonDelete; | |
public ApplicationPanel(ApplicationItem applicationItem) { | |
// setLayout(new FlowLayout()); | |
this.applicationItem = applicationItem; | |
buttonUp = new JButton("U"); | |
buttonDown = new JButton("D"); | |
labelName = new JLabel(this.applicationItem.getName()); | |
buttonDelete = new JButton("DELETE"); | |
add(buttonUp); | |
add(buttonDown); | |
add(labelName); | |
add(buttonDelete); | |
} | |
} | |
class ApplicationItemDao { | |
private List<ApplicationItem> applicationItemList = new ArrayList(); | |
public ApplicationItemDao() { | |
applicationItemList.add(new ApplicationItem("1", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("2", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("3", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
applicationItemList.add(new ApplicationItem("4", applicationItemList.size())); | |
} | |
public List<ApplicationItem> getAll() { | |
return applicationItemList; | |
} | |
public void save(String name, int number) { | |
ApplicationItem applicationItem = new ApplicationItem(name, applicationItemList.size()); | |
applicationItemList.add(applicationItem); | |
} | |
} | |
class ApplicationItem { | |
private String name; | |
private int number; | |
private int waitePre; | |
private int waitePost; | |
public ApplicationItem(String name, int number) { | |
this(name, number, 0, 0); | |
} | |
public ApplicationItem(String name, int number, int waitePre, int waitePost) { | |
this.name = name; | |
this.number = number; | |
this.waitePre = waitePre; | |
this.waitePost = waitePost; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public int getNumber() { | |
return number; | |
} | |
public void setNumber(int number) { | |
this.number = number; | |
} | |
public int getWaitePre() { | |
return waitePre; | |
} | |
public void setWaitePre(int waitePre) { | |
this.waitePre = waitePre; | |
} | |
public int getWaitePost() { | |
return waitePost; | |
} | |
public void setWaitePost(int waitePost) { | |
this.waitePost = waitePost; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment