diff --git a/JTablePagination.iml b/JTablePagination.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/JTablePagination.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/spiral_desktop_version/CircleButton$1.class b/out/production/spiral_desktop_version/CircleButton$1.class new file mode 100644 index 0000000..55c7224 Binary files /dev/null and b/out/production/spiral_desktop_version/CircleButton$1.class differ diff --git a/out/production/spiral_desktop_version/CircleButton.class b/out/production/spiral_desktop_version/CircleButton.class new file mode 100644 index 0000000..674fbf8 Binary files /dev/null and b/out/production/spiral_desktop_version/CircleButton.class differ diff --git a/spiral_desktop_version-main.iml b/spiral_desktop_version-main.iml index fb578ef..1536cb3 100644 --- a/spiral_desktop_version-main.iml +++ b/spiral_desktop_version-main.iml @@ -8,5 +8,6 @@ + \ No newline at end of file diff --git a/spiral_desktop_version.iml b/spiral_desktop_version.iml index ab3c14e..5dcfa0f 100644 --- a/spiral_desktop_version.iml +++ b/spiral_desktop_version.iml @@ -7,6 +7,12 @@ +<<<<<<< HEAD + + + + +======= @@ -19,5 +25,6 @@ +>>>>>>> 75f045b07f5a12579a38f90da84f0dddeddaf624 \ No newline at end of file diff --git a/src/CircleButton.java b/src/CircleButton.java new file mode 100644 index 0000000..7675581 --- /dev/null +++ b/src/CircleButton.java @@ -0,0 +1,107 @@ +import javax.swing.JButton; +import java.awt.Graphics; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.geom.Point2D; +import java.awt.FontMetrics; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class CircleButton extends JButton { + + private boolean mouseOver = false; + private boolean mousePressed = false; + + public CircleButton(String text){ + super(text); + setOpaque(false); + setFocusPainted(false); + setBorderPainted(false); + + MouseAdapter mouseListener = new MouseAdapter(){ + + @Override + public void mousePressed(MouseEvent me){ + if(contains(me.getX(), me.getY())){ + mousePressed = true; + repaint(); + } + } + + @Override + public void mouseReleased(MouseEvent me){ + mousePressed = false; + repaint(); + } + + @Override + public void mouseExited(MouseEvent me){ + mouseOver = false; + mousePressed = false; + repaint(); + } + + @Override + public void mouseMoved(MouseEvent me){ + mouseOver = contains(me.getX(), me.getY()); + repaint(); + } + }; + + addMouseListener(mouseListener); + addMouseMotionListener(mouseListener); + } + + private int getDiameter(){ + int diameter = Math.min(getWidth(), getHeight()); + return diameter; + } + + @Override + public Dimension getPreferredSize(){ + FontMetrics metrics = getGraphics().getFontMetrics(getFont()); + int minDiameter = 15 + Math.max(metrics.stringWidth(getText()), metrics.getHeight()); + return new Dimension(minDiameter, minDiameter); + } + + @Override + public boolean contains(int x, int y){ + int radius = getDiameter()/2; + return Point2D.distance(x, y, getWidth()/2, getHeight()/2) < radius; + } + + @Override + public void paintComponent(Graphics g){ + + int diameter = getDiameter(); + int radius = diameter/2; + + if(mousePressed){ + g.setColor(Color.blue); +// g.getText().setForeground(Color.white); + } + else{ + g.setColor(Color.lightGray); + } + g.fillOval(getWidth()/2 - radius, getHeight()/2 - radius, diameter, diameter); + + if(mouseOver){ + g.setColor(Color.BLUE); + } + else{ + g.setColor(Color.lightGray); + } + g.drawOval(getWidth()/2 - radius, getHeight()/2 - radius, diameter, diameter); + + if(mousePressed) + g.setColor(Color.white); + else + g.setColor(Color.BLACK); + + g.setFont(getFont()); + FontMetrics metrics = g.getFontMetrics(getFont()); + int stringWidth = metrics.stringWidth(getText()); + int stringHeight = metrics.getHeight(); + g.drawString(getText(), getWidth()/2 - stringWidth/2, getHeight()/2 + stringHeight/4); + } +} \ No newline at end of file diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..ac3722c --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,38 @@ +public class Employee { + private long id; + private String name; + private String phoneNumber; + private String address; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } +} \ No newline at end of file diff --git a/src/ObjectTableModel.java b/src/ObjectTableModel.java new file mode 100644 index 0000000..dd48a23 --- /dev/null +++ b/src/ObjectTableModel.java @@ -0,0 +1,41 @@ + +import javax.swing.table.AbstractTableModel; +import java.util.ArrayList; +import java.util.List; + +public abstract class ObjectTableModel extends AbstractTableModel { + private List objectRows = new ArrayList<>(); + + public List getObjectRows() { + return objectRows; + } + + public void setObjectRows(List objectRows) { + this.objectRows = objectRows; + } + + @Override + public int getRowCount() { + return objectRows.size(); + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + T t = objectRows.get(rowIndex); + return getValueAt(t, columnIndex); + } + + @Override + public Class getColumnClass(int columnIndex) { + if (objectRows.isEmpty()) { + return Object.class; + } + Object valueAt = getValueAt(0, columnIndex); + return valueAt != null ? valueAt.getClass() : Object.class; + } + + public abstract Object getValueAt(T t, int columnIndex); + + @Override + public abstract String getColumnName(int column); +} \ No newline at end of file diff --git a/src/PaginatedTableDecorator.java b/src/PaginatedTableDecorator.java new file mode 100644 index 0000000..c236f2f --- /dev/null +++ b/src/PaginatedTableDecorator.java @@ -0,0 +1,158 @@ +import javax.swing.*; +import javax.swing.event.TableModelEvent; +import javax.swing.table.TableModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.Arrays; +import java.util.List; + +public class PaginatedTableDecorator { + private JTable table; + private PaginationDataProvider dataProvider; + private int[] pageSizes; + private JPanel contentPanel; + private int currentPageSize; + private int currentPage = 1; + private JPanel pageLinkPanel; + private ObjectTableModel objectTableModel; + private static final int MaxPagingCompToShow = 9; + private static final String Ellipses = "..."; + + private PaginatedTableDecorator(JTable table, PaginationDataProvider dataProvider, + int[] pageSizes, int defaultPageSize) { + this.table = table; + this.dataProvider = dataProvider; + this.pageSizes = pageSizes; + this.currentPageSize = defaultPageSize; + } + + public static PaginatedTableDecorator decorate(JTable table, + PaginationDataProvider dataProvider, + int[] pageSizes, int defaultPageSize) { + PaginatedTableDecorator decorator = new PaginatedTableDecorator<>(table, dataProvider, + pageSizes, defaultPageSize); + decorator.init(); + return decorator; + } + + public JPanel getContentPanel() { + return contentPanel; + } + + private void init() { + initDataModel(); + initPaginationComponents(); + initListeners(); + paginate(); + } + + private void initListeners() { + objectTableModel.addTableModelListener(this::refreshPageButtonPanel); + } + + private void initDataModel() { + TableModel model = table.getModel(); + if (!(model instanceof ObjectTableModel)) { + throw new IllegalArgumentException("TableModel must be a subclass of ObjectTableModel"); + } + objectTableModel = (ObjectTableModel) model; + } + + private void initPaginationComponents() { + contentPanel = new JPanel(new BorderLayout()); + JPanel paginationPanel = createPaginationPanel(); + contentPanel.add(paginationPanel, BorderLayout.NORTH); + contentPanel.add(new JScrollPane(table)); + } + + private JPanel createPaginationPanel() { + JPanel paginationPanel = new JPanel(); + pageLinkPanel = new JPanel(new GridLayout(1, MaxPagingCompToShow, 3, 3)); + paginationPanel.add(pageLinkPanel); + + if (pageSizes != null) { + JComboBox pageComboBox = new JComboBox<>( + Arrays.stream(pageSizes).boxed() + .toArray(Integer[]::new)); + pageComboBox.addActionListener((ActionEvent e) -> { + //to preserve current rows position + int currentPageStartRow = ((currentPage - 1) * currentPageSize) + 1; + currentPageSize = (Integer) pageComboBox.getSelectedItem(); + currentPage = ((currentPageStartRow - 1) / currentPageSize) + 1; + paginate(); + }); + paginationPanel.add(Box.createHorizontalStrut(15)); + paginationPanel.add(new JLabel("Page Size: ")); + paginationPanel.add(pageComboBox); + pageComboBox.setSelectedItem(currentPageSize); + } + return paginationPanel; + } + + private void refreshPageButtonPanel(TableModelEvent tme) { + pageLinkPanel.removeAll(); + int totalRows = dataProvider.getTotalRowCount(); + int pages = (int) Math.ceil((double) totalRows / currentPageSize); + ButtonGroup buttonGroup = new ButtonGroup(); + if (pages > MaxPagingCompToShow) { + addPageButton(pageLinkPanel, buttonGroup, 1); + if (currentPage > (pages - ((MaxPagingCompToShow + 1) / 2))) { + //case: 1 ... n->lastPage + pageLinkPanel.add(createEllipsesComponent()); + addPageButtonRange(pageLinkPanel, buttonGroup, pages - MaxPagingCompToShow + 3, pages); + } else if (currentPage <= (MaxPagingCompToShow + 1) / 2) { + //case: 1->n ...lastPage + addPageButtonRange(pageLinkPanel, buttonGroup, 2, MaxPagingCompToShow - 2); + pageLinkPanel.add(createEllipsesComponent()); + addPageButton(pageLinkPanel, buttonGroup, pages); + } else {//case: 1 .. x->n .. lastPage + pageLinkPanel.add(createEllipsesComponent());//first ellipses + //currentPage is approx mid point among total max-4 center links + int start = currentPage - (MaxPagingCompToShow - 4) / 2; + int end = start + MaxPagingCompToShow - 5; + addPageButtonRange(pageLinkPanel, buttonGroup, start, end); + pageLinkPanel.add(createEllipsesComponent());//last ellipsis + addPageButton(pageLinkPanel, buttonGroup, pages);//last page link + } + } else { + addPageButtonRange(pageLinkPanel, buttonGroup, 1, pages); + } + pageLinkPanel.getParent().validate(); + pageLinkPanel.getParent().repaint(); + } + + private Component createEllipsesComponent() { + return new JLabel(Ellipses, SwingConstants.CENTER); + } + + private void addPageButtonRange(JPanel parentPanel, ButtonGroup buttonGroup, int start, int end) { + for (; start <= end; start++) { + addPageButton(parentPanel, buttonGroup, start); + } + } + + private void addPageButton(JPanel parentPanel, ButtonGroup buttonGroup, int pageNumber) { + JToggleButton toggleButton = new JToggleButton(Integer.toString(pageNumber)); + toggleButton.setMargin(new Insets(1, 3, 1, 3)); + buttonGroup.add(toggleButton); + parentPanel.add(toggleButton); + if (pageNumber == currentPage) { + toggleButton.setSelected(true); + } + toggleButton.addActionListener(ae -> { + currentPage = Integer.parseInt(ae.getActionCommand()); + paginate(); + }); + } + + private void paginate() { + int startIndex = (currentPage - 1) * currentPageSize; + int endIndex = startIndex + currentPageSize; + if (endIndex > dataProvider.getTotalRowCount()) { + endIndex = dataProvider.getTotalRowCount(); + } + List rows = dataProvider.getRows(startIndex, endIndex); + objectTableModel.setObjectRows(rows); + objectTableModel.fireTableDataChanged(); + } +} \ No newline at end of file diff --git a/src/PaginationDataProvider.java b/src/PaginationDataProvider.java new file mode 100644 index 0000000..1739797 --- /dev/null +++ b/src/PaginationDataProvider.java @@ -0,0 +1,6 @@ +import java.util.List; + +public interface PaginationDataProvider { + int getTotalRowCount(); + List getRows(int startIndex, int endIndex); +} \ No newline at end of file diff --git a/src/PaginationExampleMain.java b/src/PaginationExampleMain.java new file mode 100644 index 0000000..b830257 --- /dev/null +++ b/src/PaginationExampleMain.java @@ -0,0 +1,96 @@ +/* +Author: Cyebukayire Peace +Description: +.Creating frame +. Generating and inserting data into the table +* */ +import javax.swing.*; +import javax.swing.table.TableModel; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +public class PaginationExampleMain { + public static void main(String[] args) { + JFrame frame = createFrame(); + JTable table = new JTable(createObjectDataModel()); + table.setAutoCreateRowSorter(true); + PaginationDataProvider dataProvider = createDataProvider(); + PaginatedTableDecorator paginatedDecorator = PaginatedTableDecorator.decorate(table, + dataProvider, new int[]{5, 10, 20, 50, 75, 100}, 10); + frame.add(paginatedDecorator.getContentPanel()); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + private static TableModel createObjectDataModel() { + return new ObjectTableModel() { + @Override + public Object getValueAt(Employee employee, int columnIndex) { + switch (columnIndex) { + case 0: + return employee.getId(); + case 1: + return employee.getName(); + case 2: + return employee.getPhoneNumber(); + case 3: + return employee.getAddress(); + } + return null; + } + + @Override + public int getColumnCount() { + return 4; + } + @Override + public String getColumnName(int column) { + switch (column) { + case 0: + return "Id"; + case 1: + return "Name"; + case 2: + return "Phone"; + case 3: + return "Address"; + } + return null; + } + }; + } + + //Inserting data into the table + private static PaginationDataProvider createDataProvider() { + + final List list = new ArrayList<>(); + for (int i = 1; i <= 500; i++) { + Employee e = new Employee(); + e.setId(i); + e.setName("name" + i); + e.setPhoneNumber("phone" + i); + e.setAddress("address " + i); + list.add(e); + } + + return new PaginationDataProvider() { + @Override + public int getTotalRowCount() { + return list.size(); + } + + @Override + public List getRows(int startIndex, int endIndex) { + return list.subList(startIndex, endIndex); + } + }; + } + + private static JFrame createFrame() { + JFrame frame = new JFrame("JTable Pagination"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(new Dimension(600, 300)); + return frame; + } +} \ No newline at end of file diff --git a/src/TablePagination.java b/src/TablePagination.java new file mode 100644 index 0000000..ca91f5b --- /dev/null +++ b/src/TablePagination.java @@ -0,0 +1,188 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +public class TablePagination extends JPanel { + public TablePagination(){dataTable(); paginationBtn();} + public void dataTable() { + + String[] columnNames = {"First Name", + "Last Name", + "Sport", + "# of Years", + "Vegetarian"}; + + Object[][] data = { + {"Kathy", "Smith", + "Snowboarding", new Integer(5), new Boolean(false)}, + {"John", "Doe", + "Rowing", new Integer(3), new Boolean(true)}, + {"Sue", "Black", + "Knitting", new Integer(2), new Boolean(false)}, + {"Jane", "White", + "Speed reading", new Integer(20), new Boolean(true)}, + {"Kathy", "Smith", + "Snowboarding", new Integer(5), new Boolean(false)}, + {"John", "Doe", + "Rowing", new Integer(3), new Boolean(true)}, + {"Sue", "Black", + "Knitting", new Integer(2), new Boolean(false)}, + {"Jane", "White", + "Speed reading", new Integer(20), new Boolean(true)}, + {"Kathy", "Smith", + "Snowboarding", new Integer(5), new Boolean(false)}, + {"John", "Doe", + "Rowing", new Integer(3), new Boolean(true)}, + {"Sue", "Black", + "Knitting", new Integer(2), new Boolean(false)}, + {"Jane", "White", + "Speed reading", new Integer(20), new Boolean(true)}, + {"Kathy", "Smith", + "Snowboarding", new Integer(5), new Boolean(false)}, + {"John", "Doe", + "Rowing", new Integer(3), new Boolean(true)}, + {"Sue", "Black", + "Knitting", new Integer(2), new Boolean(false)}, + {"Jane", "White", + "Speed reading", new Integer(20), new Boolean(true)},{"Kathy", "Smith", + "Snowboarding", new Integer(5), new Boolean(false)}, + {"John", "Doe", + "Rowing", new Integer(3), new Boolean(true)}, + {"Sue", "Black", + "Knitting", new Integer(2), new Boolean(false)}, + {"Jane", "White", + "Speed reading", new Integer(20), new Boolean(true)}, + + {"Joe", "Brown", + "Pool", new Integer(10), new Boolean(false)} + }; + + final JTable table = new JTable(data, columnNames); + table.setPreferredScrollableViewportSize(new Dimension(700, 150)); + table.setFillsViewportHeight(false); + + //Create the scroll pane and add the table to it. + JScrollPane scrollPane = new JScrollPane(table); + + //Add the scroll pane to this panel. + add(scrollPane); + } + + public class ButtonActionListener implements ActionListener { + public void actionPerformed (ActionEvent e){ + String actionCommand = e.getActionCommand(); + System.out.println("Action Command: "+ actionCommand); + if(actionCommand.equals("Go to first page")){ + + }else if(actionCommand.equals("Go to previous page")){ + + }else if(actionCommand.equals("Go to page 1")){ + + }else if(actionCommand.equals("Go to page 2")){ + + }else if(actionCommand.equals("Go to page 3")){ + + }else if(actionCommand.equals("Go to page 4")){ + + }else if(actionCommand.equals("Go to next page")){ + + }else if(actionCommand.equals("Go to last page")){ + + }else{ + + } + } + } + + public void paginationBtn(){ + + //Declaring buttons + JButton first = new JButton("First"); + JButton previous = new JButton("Previous"); + JButton page1 = new JButton("1"); + JButton page2 = new JButton("2"); + JButton page3 = new JButton("3"); + JButton page4 = new JButton("4"); + JButton next = new JButton("Next"); + JButton last = new JButton("Last"); + + //Removing background from buttons + first.setContentAreaFilled(false); + previous.setContentAreaFilled(false); + page1.setContentAreaFilled(false); + page2.setContentAreaFilled(false); + page3.setContentAreaFilled(false); + page4.setContentAreaFilled(false); + next.setContentAreaFilled(false); + last.setContentAreaFilled(false); + + //Attaching listener to buttons + //Setting action commands + first.setActionCommand("Go to first page"); + previous.setActionCommand("Go to previous page"); + page1.setActionCommand("Go to page 1"); + page2.setActionCommand("Go to page 2"); + page3.setActionCommand("Go to page 3"); + page4.setActionCommand("Go to page 4"); + next.setActionCommand("Go to page next page"); + last.setActionCommand("Go to last page"); + + //Adding action listener to buttons + first.addActionListener(new ButtonActionListener()); + previous.addActionListener(new ButtonActionListener()); + page1.addActionListener(new ButtonActionListener()); + page2.addActionListener(new ButtonActionListener()); + page3.addActionListener(new ButtonActionListener()); + page4.addActionListener(new ButtonActionListener()); + next.addActionListener(new ButtonActionListener()); + last.addActionListener(new ButtonActionListener()); + + + //Add buttons to page + add(first); + add(previous); + add(page1); + add(page2); + add(page3); + add(page4); + add(next); + add(last); + } + + private static void ShowGUI() { + //Create and set up the window. + JFrame frame = new JFrame("PaginationTesting"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + //Create and set up the content pane. + TablePagination newContentPane = new TablePagination(); + newContentPane.setOpaque(true); //content panes must be opaque + frame.setContentPane(newContentPane); + + //adding window listener + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + + //Display the window. + frame.pack(); + frame.setSize(800,500); + frame.setVisible(true); + } + + + + public static void main(String[] args) { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + ShowGUI(); + } + }); + } +} \ No newline at end of file diff --git a/src/client/CircleButton.java b/src/client/CircleButton.java new file mode 100644 index 0000000..1e74af3 --- /dev/null +++ b/src/client/CircleButton.java @@ -0,0 +1,106 @@ +package client; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.geom.Point2D; + +public class CircleButton extends JButton { + + private boolean mouseOver = false; + private boolean mousePressed = false; + + public CircleButton(String text){ + super(text); + setOpaque(false); + setFocusPainted(false); + setBorderPainted(false); + + MouseAdapter mouseListener = new MouseAdapter(){ + + @Override + public void mousePressed(MouseEvent me){ + if(contains(me.getX(), me.getY())){ + mousePressed = true; + repaint(); + } + } + + @Override + public void mouseReleased(MouseEvent me){ + mousePressed = false; + repaint(); + } + + @Override + public void mouseExited(MouseEvent me){ + mouseOver = false; + mousePressed = false; + repaint(); + } + + @Override + public void mouseMoved(MouseEvent me){ + mouseOver = contains(me.getX(), me.getY()); + repaint(); + } + }; + + addMouseListener(mouseListener); + addMouseMotionListener(mouseListener); + } + + private int getDiameter(){ + int diameter = Math.min(getWidth(), getHeight()); + return diameter; + } + + @Override + public Dimension getPreferredSize(){ + FontMetrics metrics = getGraphics().getFontMetrics(getFont()); + int minDiameter = 15 + Math.max(metrics.stringWidth(getText()), metrics.getHeight()); + return new Dimension(minDiameter, minDiameter); + } + + @Override + public boolean contains(int x, int y){ + int radius = getDiameter()/2; + return Point2D.distance(x, y, getWidth()/2, getHeight()/2) < radius; + } + + @Override + public void paintComponent(Graphics g){ + + int diameter = getDiameter(); + int radius = diameter/2; + + if(mousePressed){ + g.setColor(Color.blue); +// g.getText().setForeground(Color.white); + } + else{ + g.setColor(Color.lightGray); + } + g.fillOval(getWidth()/2 - radius, getHeight()/2 - radius, diameter, diameter); + + if(mouseOver){ + g.setColor(Color.BLUE); + } + else{ + g.setColor(Color.lightGray); + } + g.drawOval(getWidth()/2 - radius, getHeight()/2 - radius, diameter, diameter); + + if(mousePressed) + g.setColor(Color.white); + else + g.setColor(Color.BLACK); + + g.setFont(getFont()); + FontMetrics metrics = g.getFontMetrics(getFont()); + int stringWidth = metrics.stringWidth(getText()); + int stringHeight = metrics.getHeight(); + g.drawString(getText(), getWidth()/2 - stringWidth/2, getHeight()/2 + stringHeight/4); + } +} \ No newline at end of file diff --git a/src/client/Pagination.java b/src/client/Pagination.java index 8d387d2..150a159 100644 --- a/src/client/Pagination.java +++ b/src/client/Pagination.java @@ -8,80 +8,13 @@ import java.awt.event.WindowEvent; public class Pagination extends JPanel { - public Pagination(){dataTable(); paginationBtn();} - public void dataTable() { - - String[] columnNames = {"First Name", - "Last Name", - "Sport", - "# of Years", - "Vegetarian"}; - - Object[][] data = { - {"Kathy", "Smith", - "Snowboarding", new Integer(5), new Boolean(false)}, - {"John", "Doe", - "Rowing", new Integer(3), new Boolean(true)}, - {"Sue", "Black", - "Knitting", new Integer(2), new Boolean(false)}, - {"Jane", "White", - "Speed reading", new Integer(20), new Boolean(true)}, - {"Kathy", "Smith", - "Snowboarding", new Integer(5), new Boolean(false)}, - {"John", "Doe", - "Rowing", new Integer(3), new Boolean(true)}, - {"Sue", "Black", - "Knitting", new Integer(2), new Boolean(false)}, - {"Jane", "White", - "Speed reading", new Integer(20), new Boolean(true)}, - {"Kathy", "Smith", - "Snowboarding", new Integer(5), new Boolean(false)}, - {"John", "Doe", - "Rowing", new Integer(3), new Boolean(true)}, - {"Sue", "Black", - "Knitting", new Integer(2), new Boolean(false)}, - {"Jane", "White", - "Speed reading", new Integer(20), new Boolean(true)}, - {"Kathy", "Smith", - "Snowboarding", new Integer(5), new Boolean(false)}, - {"John", "Doe", - "Rowing", new Integer(3), new Boolean(true)}, - {"Sue", "Black", - "Knitting", new Integer(2), new Boolean(false)}, - {"Jane", "White", - "Speed reading", new Integer(20), new Boolean(true)},{"Kathy", "Smith", - "Snowboarding", new Integer(5), new Boolean(false)}, - {"John", "Doe", - "Rowing", new Integer(3), new Boolean(true)}, - {"Sue", "Black", - "Knitting", new Integer(2), new Boolean(false)}, - {"Jane", "White", - "Speed reading", new Integer(20), new Boolean(true)}, - - {"Joe", "Brown", - "Pool", new Integer(10), new Boolean(false)} - }; - - final JTable table = new JTable(data, columnNames); - table.setPreferredScrollableViewportSize(new Dimension(700, 150)); - table.setFillsViewportHeight(false); - - //Create the scroll pane and add the table to it. - JScrollPane scrollPane = new JScrollPane(table); - - //Add the scroll pane to this panel. - add(scrollPane); - } + public Pagination(){paginationBtn();} public class ButtonActionListener implements ActionListener { public void actionPerformed (ActionEvent e){ String actionCommand = e.getActionCommand(); System.out.println("Action Command: "+ actionCommand); - if(actionCommand.equals("Go to first page")){ - - }else if(actionCommand.equals("Go to previous page")){ - - }else if(actionCommand.equals("Go to page 1")){ + if(actionCommand.equals("Go to page 1")){ }else if(actionCommand.equals("Go to page 2")){ @@ -89,9 +22,7 @@ public void actionPerformed (ActionEvent e){ }else if(actionCommand.equals("Go to page 4")){ - }else if(actionCommand.equals("Go to next page")){ - - }else if(actionCommand.equals("Go to last page")){ + }else if(actionCommand.equals("More pages")){ }else{ @@ -102,56 +33,51 @@ public void actionPerformed (ActionEvent e){ public void paginationBtn(){ //Declaring buttons - JButton first = new JButton("First"); - JButton previous = new JButton("Previous"); - JButton page1 = new JButton("1"); - JButton page2 = new JButton("2"); - JButton page3 = new JButton("3"); - JButton page4 = new JButton("4"); - JButton next = new JButton("Next"); - JButton last = new JButton("Last"); - - //Removing background from buttons - first.setContentAreaFilled(false); - previous.setContentAreaFilled(false); + CircleButton page1 = new CircleButton("1"); + CircleButton page2 = new CircleButton("2"); + CircleButton page3 = new CircleButton("3"); + CircleButton page4 = new CircleButton("4"); + JButton etc = new JButton("..."); + + //Removing background from buttons and other styles page1.setContentAreaFilled(false); page2.setContentAreaFilled(false); page3.setContentAreaFilled(false); page4.setContentAreaFilled(false); - next.setContentAreaFilled(false); - last.setContentAreaFilled(false); + etc.setContentAreaFilled(false); + etc.setBorderPainted(false);//Removing border + etc.setMargin(new Insets(0,0,15,0));//Set margin + etc.setFont(new Font("Arial", Font.PLAIN, 30));//Set font size + etc.setForeground(Color.blue); + + //Removing focus painted + page1.setFocusPainted(false); + page2.setFocusPainted(false); + page3.setFocusPainted(false); + page4.setFocusPainted(false); + etc.setFocusPainted(false); //Attaching listener to buttons //Setting action commands - first.setActionCommand("Go to first page"); - previous.setActionCommand("Go to previous page"); page1.setActionCommand("Go to page 1"); page2.setActionCommand("Go to page 2"); page3.setActionCommand("Go to page 3"); page4.setActionCommand("Go to page 4"); - next.setActionCommand("Go to page next page"); - last.setActionCommand("Go to last page"); + etc.setActionCommand("More pages"); //Adding action listener to buttons - first.addActionListener(new ButtonActionListener()); - previous.addActionListener(new ButtonActionListener()); page1.addActionListener(new ButtonActionListener()); page2.addActionListener(new ButtonActionListener()); page3.addActionListener(new ButtonActionListener()); page4.addActionListener(new ButtonActionListener()); - next.addActionListener(new ButtonActionListener()); - last.addActionListener(new ButtonActionListener()); - + etc.addActionListener(new ButtonActionListener()); //Add buttons to page - add(first); - add(previous); add(page1); add(page2); add(page3); add(page4); - add(next); - add(last); + add(etc); } private static void ShowGUI() { @@ -174,7 +100,7 @@ public void windowClosing(WindowEvent e) { //Display the window. frame.pack(); - frame.setSize(800,500); + frame.setSize(400,200); frame.setVisible(true); } diff --git a/src/client/resultDetails/ResultDetails.java b/src/client/resultDetails/ResultDetails.java index 40fd090..fe932d5 100644 --- a/src/client/resultDetails/ResultDetails.java +++ b/src/client/resultDetails/ResultDetails.java @@ -6,7 +6,7 @@ // class GridLayout extends JFrame public class ResultDetails extends JFrame { - ResultDetails() { + public ResultDetails() { // Creating Object P1 of JPanel class JPanel p1 = new JPanel(); // set the layout @@ -58,13 +58,13 @@ public class ResultDetails extends JFrame { final Font f = CommentField.getFont(); CommentField.setFont(new Font(f.getName(), f.getStyle(), 12)); - JButton sendComment=new JButton("SEND"); - sendComment.setBounds(300,50,100,55); - sendComment.setBackground(Color.decode("#C4C4C4")); - sendComment.setBorder(null); - sendComment.setFont(new Font("Nunito", Font.BOLD, 15)); - lastPanel.add(CommentField); - lastPanel.add(sendComment); + JButton sendComment=new JButton("SEND"); + sendComment.setBounds(300,50,100,55); + sendComment.setBackground(Color.decode("#C4C4C4")); + sendComment.setBorder(null); + sendComment.setFont(new Font("Nunito", Font.BOLD, 15)); + lastPanel.add(CommentField); + lastPanel.add(sendComment); p1.add(lastPanel); diff --git a/src/client/result_list/ResultDetails.java b/src/client/result_list/ResultDetails.java index 5571a32..1a777a9 100644 --- a/src/client/result_list/ResultDetails.java +++ b/src/client/result_list/ResultDetails.java @@ -9,6 +9,256 @@ import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +<<<<<<< HEAD + +import static javax.swing.WindowConstants.EXIT_ON_CLOSE; +public class ResultDetails { + private JFrame window; + + private Container container; + private JLabel title; + private JLabel subTitle; + private JLabel description; + private JLabel lsubTitle; + + + private JLabel title2; + private JLabel subTitle2; + private JLabel description2; + private JLabel lsubTitle2; + + private JLabel title3; + private JLabel subTitle3; + private JLabel description3; + private JLabel lsubTitle3; + + public JFrame getWindow() { + return window; + } + + public void setWindow(JFrame window) { + this.window = window; + } + + public Container getContainer() { + return container; + } + + public void setContainer(Container container) { + this.container = container; + } + + public JLabel getTitle() { + return title; + } + + public void setTitle(JLabel title) { + this.title = title; + } + + public JLabel getSubTitle() { + return subTitle; + } + + public void setSubTitle(JLabel subTitle) { + this.subTitle = subTitle; + } + + public JLabel getDescription() { + return description; + } + + public void setDescription(JLabel description) { + this.description = description; + } + + public JLabel getLsubTitle() { + return lsubTitle; + } + + public void setLsubTitle(JLabel lsubTitle) { + this.lsubTitle = lsubTitle; + } + + public JLabel getTitle2() { + return title2; + } + + public void setTitle2(JLabel title2) { + this.title2 = title2; + } + + public JLabel getSubTitle2() { + return subTitle2; + } + + public void setSubTitle2(JLabel subTitle2) { + this.subTitle2 = subTitle2; + } + + public JLabel getDescription2() { + return description2; + } + + public void setDescription2(JLabel description2) { + this.description2 = description2; + } + + public JLabel getLsubTitle2() { + return lsubTitle2; + } + + public void setLsubTitle2(JLabel lsubTitle2) { + this.lsubTitle2 = lsubTitle2; + } + + public JLabel getTitle3() { + return title3; + } + + public void setTitle3(JLabel title3) { + this.title3 = title3; + } + + public JLabel getSubTitle3() { + return subTitle3; + } + + public void setSubTitle3(JLabel subTitle3) { + this.subTitle3 = subTitle3; + } + + public JLabel getDescription3() { + return description3; + } + + public void setDescription3(JLabel description3) { + this.description3 = description3; + } + + public JLabel getLsubTitle3() { + return lsubTitle3; + } + + public void setLsubTitle3(JLabel lsubTitle3) { + this.lsubTitle3 = lsubTitle3; + } + + public ResultDetails() { + + + window= new JFrame(); + window.setTitle("Result Details"); + window.setBounds(300, 10, 800, 800); + window.setDefaultCloseOperation(EXIT_ON_CLOSE); + window.setResizable(true); + container = window.getContentPane(); + container.setBackground(Color.white); + container.setLayout(null); + + + title= new JLabel("Amakosi-Ish Kevin (Lyrics) "); + title.setFont(new Font("Arial", Font.BOLD, 23)); + title.setSize(500, 30); + title.setLocation(60, 40); + title.setForeground(Color.decode("#0074DB")); + JButton etc = new JButton("..."); + etc.setActionCommand("peace dfsd"); + + subTitle= new JLabel("http://www.ecosia.org >"); + subTitle.setFont(new Font("Arial", Font.ITALIC, 14)); + subTitle.setSize(500, 30); + subTitle.setLocation(60, 68); + subTitle.setForeground(Color.lightGray); + + description= new JLabel(); + description.setText(convertToMultiline("Lorem Ipsum is simply dummy text of the printing and typesetting\nindustry. Lorem Ipsum has been the industry's standard dummy \n text ever since the 1500s, when an unknown printer took a galley\nof type and scrambled it to make a type specimen book. It has\nsurvived not only five centuries, but also the leap into electronic\ntypesetting, remaining essentially unchanged.")); + description.setFont(new Font("Arial", Font.CENTER_BASELINE, 15)); + description.setSize(700, 130); + description.setLocation(60, 100); + + lsubTitle= new JLabel("Related: Lorem Ipsum... Mto mto-Ish Kevin"); + lsubTitle.setFont(new Font("Arial", Font.ITALIC, 14)); + lsubTitle.setSize(500, 30); + lsubTitle.setLocation(60, 220); + +// Adding a mouse listener + title.addMouseListener(new MouseAdapter() + { + public void mouseClicked(MouseEvent e) + { +// System.exit(0); + new client.resultDetails.ResultDetails(); + } + }); + +// Adding content to container + container.add(title); + container.add(subTitle); + container.add(description); + container.add(lsubTitle); + + + //Second Div + + title2= new JLabel("Amakosi-Ish Kevin (Lyrics) "); + title2.setFont(new Font("Arial", Font.BOLD, 23)); + title2.setSize(500, 30); + title2.setLocation(60, 280); + title2.setForeground(Color.decode("#0074DB")); + container.add(title2); + + + subTitle2= new JLabel("http://www.ecosia.org >"); + subTitle2.setFont(new Font("Arial", Font.ITALIC, 14)); + subTitle2.setSize(500, 30); + subTitle2.setLocation(60, 308); + subTitle2.setForeground(Color.lightGray); + container.add(subTitle2); + + description2= new JLabel(); + description2.setText(convertToMultiline("Lorem Ipsum is simply dummy text of the printing and typesetting\nindustry. Lorem Ipsum has been the industry's standard dummy \n text ever since the 1500s, when an unknown printer took a galley\nof type and scrambled it to make a type specimen book. It has\nsurvived not only five centuries, but also the leap into electronic\ntypesetting, remaining essentially unchanged.")); + description2.setFont(new Font("Arial", Font.CENTER_BASELINE, 15)); + description2.setSize(700, 130); + description2.setLocation(60, 340); + container.add(description2); + + lsubTitle2= new JLabel("Related: Lorem Ipsum... Mto mto-Ish Kevin"); + lsubTitle2.setFont(new Font("Arial", Font.ITALIC, 14)); + lsubTitle2.setSize(500, 30); + lsubTitle2.setLocation(60, 460); + container.add(lsubTitle2); + + + title3= new JLabel("Amakosi-Ish Kevin (Lyrics) "); + title3.setFont(new Font("Arial", Font.BOLD, 23)); + title3.setSize(500, 30); + title3.setLocation(60, 520); + title3.setForeground(Color.decode("#0074DB")); + container.add(title3); + + + subTitle3= new JLabel("http://www.ecosia.org >"); + subTitle3.setFont(new Font("Arial", Font.ITALIC, 14)); + subTitle3.setSize(500, 30); + subTitle3.setLocation(60, 548); + subTitle3.setForeground(Color.lightGray); + container.add(subTitle3); + + description3= new JLabel(); + description3.setText(convertToMultiline("Lorem Ipsum is simply dummy text of the printing and typesetting\nindustry. Lorem Ipsum has been the industry's standard dummy \n text ever since the 1500s, when an unknown printer took a galley\nof type and scrambled it to make a type specimen book. It has\nsurvived not only five centuries, but also the leap into electronic\ntypesetting, remaining essentially unchanged.")); + description3.setFont(new Font("Arial", Font.CENTER_BASELINE, 15)); + description3.setSize(700, 130); + description3.setLocation(60, 580); + container.add(description3); + window.setVisible(false); + + } + public static String convertToMultiline(String orig) + { + return "" + orig.replaceAll("\n", "
"); + } +======= import java.util.ArrayList; import java.util.List; @@ -205,4 +455,5 @@ public static String convertToMultiline(String orig) { return "" + orig.replaceAll("\n", "
"); } +>>>>>>> 75f045b07f5a12579a38f90da84f0dddeddaf624 } \ No newline at end of file