Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • xhrdlic3/pb168-01-todo
1 result
Show changes
Commits on Source (8)
Showing
with 119 additions and 52 deletions
package cz.muni.fi.pv168.project.ui.main;
import cz.muni.fi.pv168.project.data.task.TaskStatus;
import cz.muni.fi.pv168.project.ui.resources.Icons;
import javax.swing.*;
public class MainToolBar extends JToolBar {
private final JButton addTaskButton;
private final JButton addCategoryButton;
private final JButton removeTaskButton;
private final JButton removeCategoryButton;
private final JButton editTaskButton;
private JCheckBox isJustToday;
private JComboBox<TaskStatus> taskTypes;
public MainToolBar() {
super(JToolBar.HORIZONTAL);
addTaskButton = Icons.createIconButton(Icons.ADD_TASK_ICON, "Add task");
addCategoryButton = Icons.createIconButton(Icons.ADD_CATEGORY_ICON, "Add category");
removeTaskButton = Icons.createIconButton(Icons.REMOVE_TASK_BIN_ICON, "Remove task");
removeCategoryButton = Icons.createIconButton(Icons.REMOVE_CATEGORY_BIN_ICON, "Remove category");
editTaskButton = Icons.createIconButton(Icons.EDIT_ICON, "Edit task");
isJustToday = new JCheckBox("Only today's tasks", true);
taskTypes = new JComboBox<>(TaskStatus.values());
this.add(addTaskButton);
this.add(addCategoryButton);
this.addSeparator();
this.add(removeTaskButton);
this.add(removeCategoryButton);
this.addSeparator();
this.add(editTaskButton);
this.add(Box.createHorizontalGlue());
this.add(isJustToday);
this.add(Box.createHorizontalStrut(10));
this.add(taskTypes);
}
public void setTaskViewButtonsVisible(boolean shouldBeVisible) {
isJustToday.setVisible(shouldBeVisible);
taskTypes.setVisible(shouldBeVisible);
}
}
package cz.muni.fi.pv168.project.ui.main;
import cz.muni.fi.pv168.project.ui.main.statistic.StatisticsTable;
import cz.muni.fi.pv168.project.ui.resources.Icons;
import cz.muni.fi.pv168.project.utils.TemporaryValueProvider;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.EtchedBorder;
......@@ -23,12 +23,7 @@ import java.awt.event.ComponentEvent;
public class MainWindow {
private JFrame mainFrame;
private JPanel mainPanel;
private JToolBar mainToolBar;
private JButton addTaskButton;
private JButton addCategoryButton;
private JButton removeTaskButton;
private JButton removeCategoryButton;
private JButton editTaskButton;
private MainToolBar mainToolBar;
private JTabbedPane tabbedPane;
private TaskView taskView;
private JTable categoryStatisticsTable;
......@@ -36,8 +31,7 @@ public class MainWindow {
public MainWindow() {
mainFrame = new JFrame();
mainPanel = new JPanel(new BorderLayout());
mainToolBar = createToolBar();
mainToolBar = new MainToolBar();
createTabbedPane();
......@@ -51,6 +45,7 @@ public class MainWindow {
mainFrame.setLayout(new BorderLayout());
mainFrame.add(mainPanel, BorderLayout.CENTER);
mainFrame.setVisible(true);
mainFrame.setIconImage(((ImageIcon) Icons.LOGO_ICON).getImage());
}
private void createTabbedPane() {
......@@ -78,25 +73,11 @@ public class MainWindow {
}
}
});
}
private JToolBar createToolBar() {
// @kika TODO make image icon buttons
addTaskButton = new JButton("T+");
addCategoryButton = new JButton("C+");
removeTaskButton = new JButton("T-");
removeCategoryButton = new JButton("C-");
editTaskButton = new JButton("T");
JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL);
toolbar.add(addTaskButton);
toolbar.add(addCategoryButton);
toolbar.addSeparator();
toolbar.add(removeTaskButton);
toolbar.add(removeCategoryButton);
toolbar.addSeparator();
toolbar.add(editTaskButton);
tabbedPane.addChangeListener(e -> mainToolBar.setTaskViewButtonsVisible(isTaskViewVisible()));
}
return toolbar;
private boolean isTaskViewVisible() {
return tabbedPane.getSelectedIndex() == 0;
}
}
package cz.muni.fi.pv168.project.ui.main;
import cz.muni.fi.pv168.project.data.task.Task;
import cz.muni.fi.pv168.project.data.task.TaskStatus;
import cz.muni.fi.pv168.project.ui.renderer.TaskListRenderer;
import cz.muni.fi.pv168.project.utils.TemporaryValueProvider;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;
public class TaskView extends JPanel {
private JPanel filterPanel;
private JCheckBox isJustToday;
private JComboBox<TaskStatus> taskTypes;
private JList<Task> taskList;
public class TaskView extends JList<Task> {
public TaskView() {
super(new BorderLayout());
isJustToday = new JCheckBox("Only today's tasks", true);
taskTypes = new JComboBox<>(TaskStatus.values());
filterPanel = new JPanel(new BorderLayout());
filterPanel.add(isJustToday, BorderLayout.WEST);
filterPanel.add(taskTypes, BorderLayout.EAST);
taskList = new JList<>();
taskList.setCellRenderer(new TaskListRenderer());
this.setCellRenderer(new TaskListRenderer());
// TODO milestone02 connect with database
taskList.setListData(TemporaryValueProvider.getTaskList().toArray(new Task[0]));
taskList.setBorder(new EtchedBorder());
this.add(filterPanel, BorderLayout.NORTH);
this.add(taskList, BorderLayout.CENTER);
this.setListData(TemporaryValueProvider.getTaskList().toArray(new Task[0]));
this.setBorder(new EtchedBorder());
}
}
package cz.muni.fi.pv168.project.ui.resources;
import javax.swing.*;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
public final class Icons {
public static final Icon REMOVE_BIN_ICON = createIcon("remove_icon_simple_32x32.png");
public static final Icon REMOVE_CATEGORY_BIN_ICON = createIcon("remove_category_32x32.png");
public static final Icon REMOVE_TASK_BIN_ICON = createIcon("remove_task_32x32.png");
public static final Icon CANCEL_CIRCLE_ICON = createIcon("cancel_circle_32x32.png");
public static final Icon CANCEL_SQUARE_ICON = createIcon("cancel_square_32x32.png");
public static final Icon EDIT_ICON = createIcon("edit_icon_32x32.png");
public static final Icon ADD_CIRCLE_ICON = createIcon("add_circle_32x32.png");
public static final Icon ADD_SQUARE_ICON = createIcon("add_square_32x32.png");
public static final Icon ADD_TASK_ICON = createIcon("add_task_32x32.png");
public static final Icon ADD_CATEGORY_ICON = createIcon("add_category_32x32.png");
public static final Icon LOGO_ICON = createIcon("logo_simple_32x32.png");
private Icons() {
throw new AssertionError("This class is not instantiable.");
}
private static ImageIcon createIcon(String name) {
URL url = Icons.class.getResource(name);
if (url == null) {
Logger.getLogger(Icon.class.getName()).log(Level.WARNING, "Icon resource '" + name + "'not found on classpath.");
return null;
}
return new ImageIcon(url);
}
public static JButton createIconButton(Icon icon, String textAndTooltip) {
return createIconButton(icon, textAndTooltip, textAndTooltip);
}
public static JButton createIconButton(Icon icon, String backupText, String toolTip) {
JButton button;
if (icon == null) {
button = new JButton(backupText);
} else {
button = new JButton(icon);
}
button.setToolTipText(toolTip);
return button;
}
}