Skip to content

Commit

Permalink
InDev 2 - Adaptive GUI / Edit entry / Realtime list update
Browse files Browse the repository at this point in the history
  • Loading branch information
410 committed Dec 14, 2021
1 parent 0531ae7 commit 09f3d46
Show file tree
Hide file tree
Showing 11 changed files with 713 additions and 142 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Vault is a secure, encrypted file database. It is written in Java, with combinat
- [x] Home View
- [x] Entry detail window
- [x] Create entry window
- [ ] Adaptive GUI
- [x] Adaptive GUI
- [x] Realtime list update
- [ ] Cleaner / Structured GUI
- [ ] Edit entry info in entry detail window
- [x] Edit entry info in entry detail window
- [ ] Searching system
- [ ] Create SQLite3 DB on start if not exists
70 changes: 42 additions & 28 deletions src/database/SQLStatementBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class SQLStatementBuilder {
private ArrayList<SQLParameter> filters = new ArrayList<>();
private ArrayList<SQLParameter> filters2 = new ArrayList<>();

private String tableName;
private String command;
Expand All @@ -22,6 +23,10 @@ public void addParameter(SQLParameter filter) {
filters.add(filter);
}

public void addParameter2(SQLParameter filter) {
filters2.add(filter);
}

public String build() {
StringBuilder builder = new StringBuilder();
builder.append(command);
Expand Down Expand Up @@ -71,33 +76,6 @@ public String build() {
}
builder.append(";");
}
} else if (command.equals(UPDATE)) {
builder.append(" ").append(tableName);
if (filters.size() > 0) {
builder.append(" SET ");
for (int i = 0; i < filters.size(); i++) {
// builder.append(filters.get(i).column)
// .append(" = \"")
// .append(filters.get(i).value)
// .append("\"");
builder.append(filters.get(i).column)
.append(" ")
.append(filters.get(i).operator)
.append(" \"");
if (filters.get(i).operator.equals(SQLParameter.LIKE)) {
builder.append("%");
}
builder.append(filters.get(i).value);
if (filters.get(i).operator.equals(SQLParameter.LIKE)) {
builder.append("%");
}
builder.append("\"");
if (i < filters.size() - 1 && !filters.get(i).nextOperand.equals("")) {
builder.append(" " + filters.get(i).nextOperand + " ");
}
}
builder.append(";");
}
} else if (command.equals(INSERT)) {
builder.append(" INTO ").append(tableName);
if (filters.size() > 0) {
Expand All @@ -119,8 +97,44 @@ public String build() {
}
builder.append(");");
}
}
}else if (command.equals(UPDATE)) {
builder.append(" ").append(tableName);
if (filters.size() > 0) {
builder.append(" SET ");
for (int i = 0; i < filters.size(); i++) {
builder.append(filters.get(i).column)
.append(" = \"")
.append(filters.get(i).value)
.append("\"");
if (i < filters.size() - 1 && !filters.get(i).nextOperand.equals("")) {
builder.append(" " + filters.get(i).nextOperand + " ");
}
}
}

if (filters2.size() > 0) {
builder.append(" WHERE ");
for (int i = 0; i < filters2.size(); i++) {
builder.append(filters2.get(i).column)
.append(" ")
.append(filters2.get(i).operator)
.append(" \"");
if (filters2.get(i).operator.equals(SQLParameter.LIKE)) {
builder.append("%");
}
builder.append(filters2.get(i).value);
if (filters2.get(i).operator.equals(SQLParameter.LIKE)) {
builder.append("%");
}
builder.append("\"");
if (i < filters2.size() - 1 && !filters2.get(i).nextOperand.equals("")) {
builder.append(" " + filters2.get(i).nextOperand + " ");
}
}
}
builder.append(";");
}
System.out.println("SQL: " + builder.toString());
return builder.toString();
}
}
1 change: 1 addition & 0 deletions src/screens/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static void createFrame() {
frame = new JFrame("Vault (" + Static.VERSION + ")");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setMinimumSize(new java.awt.Dimension(400, 400));
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.addWindowListener(new java.awt.event.WindowAdapter() {
Expand Down
90 changes: 85 additions & 5 deletions src/screens/ViewDimension.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,88 @@
package screens;

public class ViewDimension {
public int x;
public int y;
public int width;
public int height;
import java.awt.*;
import java.io.Serializable;

public class ViewDimension implements Serializable {

// X, Y, Width, Height 를 포함
public int x;
public int y;
public int width;
public int height;

public void useDisplayDimension() {
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
width = size.width;
height = size.height;
x = 0;
y = 0;
}

// JSON 형태로 반환
public String toString() {
String s = "{\"X\":" + x + ",\"Y\":" + y + ", \"WIDTH\":" + width + ", \"HEIGHT\":" + height + "}";
return s;
}

public ViewDimension(){}

public ViewDimension(int width, int height) {
this.width = width;
this.height = height;
}

public ViewDimension(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}

private ViewDimension getNewWindowPosition(int xPositionOfCenter, int yPositionOfCenter) {
ViewDimension vd = new ViewDimension();
vd.x = xPositionOfCenter - (width/2);
vd.y = yPositionOfCenter - (height/2);
vd.width = width;
vd.height = height;
return vd;
}

// 화면의 센터로 위치
public void alignCenter(ViewDimension parentDimension) {
ViewDimension vd = getNewWindowPosition(parentDimension.width / 2, parentDimension.height / 2);
x = vd.x;
y = vd.y;
width = vd.width;
height = vd.height;
}

public void moveByPercent(ViewDimension screenDimension, int percentInX, int percentInY) {
int onePercentForX = screenDimension.width / 100;
int onePercentForY = screenDimension.height / 100;

x += percentInX * onePercentForX;
y -= percentInY * onePercentForY;
}

public void toLeft(ViewDimension screenDimension) {
x = 0;
}

public void toRight(ViewDimension screenDimension) {
x = screenDimension.width - width;
}

public void toBottom(ViewDimension screenDimension) {
y = screenDimension.height - height;
}

public void toTop(ViewDimension screenDimension) {
y = 0;
}

public void scale(float scale) {
width *= scale;
height *= scale;
}
}
79 changes: 68 additions & 11 deletions src/screens/views/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.MouseInputAdapter;

import java.awt.event.MouseEvent;
Expand All @@ -20,6 +21,7 @@
import screens.ColorScheme;
import screens.Frame;
import screens.UpdatableColor;
import screens.ViewDimension;
import screens.views.subviews.About;
import screens.views.subviews.NewEntry;
import screens.views.subviews.ViewEntry;
Expand All @@ -29,18 +31,19 @@
import utils.data.Entry;
import utils.data.UserInfo;

// TODO: Create realtime list update


public class Home extends JPanel implements UpdatableColor {

private UserInfo userInfo;

private static boolean decryptionComplete = false;
private static boolean fileListReady = false;
private static ViewDimension frameDimension = new ViewDimension();

private JList fileLists;

private JButton addButton = new JButton("Add");
private JButton aboutButton = new JButton("About");
private JButton searchButton = new JButton("Search...");

public Home(UserInfo user) {
super();
Expand Down Expand Up @@ -77,6 +80,61 @@ public void run() {
}


private void asyncAdaptiveGUI() {
Thread t = new Thread() {
public void run() {
while(true) {
frameDimension.height = Frame.frame.getHeight();
frameDimension.width = Frame.frame.getWidth();

ViewDimension addButtonDimension = new ViewDimension();
addButtonDimension.width = 100;
addButtonDimension.height = 30;

ViewDimension aboutButtonDimension = new ViewDimension();
aboutButtonDimension.width = 100;
aboutButtonDimension.height = 30;

ViewDimension searchButtonDimension = new ViewDimension();
searchButtonDimension.width = 100;
searchButtonDimension.height = 30;

addButtonDimension.alignCenter(frameDimension);
aboutButtonDimension.alignCenter(frameDimension);
searchButtonDimension.alignCenter(frameDimension);

addButtonDimension.toBottom(frameDimension);
aboutButtonDimension.toBottom(frameDimension);
searchButtonDimension.toBottom(frameDimension);

addButtonDimension.toRight(frameDimension);
aboutButtonDimension.toLeft(frameDimension);

addButtonDimension.y -= addButtonDimension.height + 10;
aboutButtonDimension.y -= aboutButtonDimension.height + 10;
searchButtonDimension.y -= searchButtonDimension.height + 10;

addButton.setBounds(addButtonDimension.x, addButtonDimension.y, addButtonDimension.width, addButtonDimension.height);
aboutButton.setBounds(aboutButtonDimension.x, aboutButtonDimension.y, aboutButtonDimension.width, aboutButtonDimension.height);
searchButton.setBounds(searchButtonDimension.x, searchButtonDimension.y, searchButtonDimension.width, searchButtonDimension.height);

add(addButton);
add(aboutButton);
add(searchButton);
repaint();

try{
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};

t.start();
}

private void asyncFileListUpdate() {
Thread t = new Thread() {
public void run() {
Expand All @@ -101,7 +159,6 @@ public void run() {
entryNames.add(typePrefix + entry.getName() + " " + tags + " (" + entry.getAddedDate() + ")");
}
fileLists = new JList(entryNames.toArray());
fileLists.setBounds(0, 0, Frame.frame.getWidth(), Frame.frame.getHeight() - 100);
fileLists.addMouseListener(new MouseInputAdapter() {
public void mouseClicked(MouseEvent evt) {
JList list = (JList)evt.getSource();
Expand All @@ -110,7 +167,7 @@ public void mouseClicked(MouseEvent evt) {
if (index >= 0) {
JFrame frame = new JFrame(Entries.getEntries().get(index).getName());
frame.setResizable(true);
frame.setSize(300, 300);
frame.setSize(500, 600);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

Expand All @@ -123,6 +180,7 @@ public void mouseClicked(MouseEvent evt) {
add(fileLists);
repaint();
}
fileLists.setBounds(0, 0, frameDimension.width, frameDimension.height - 100);

try {
Thread.sleep(500);
Expand All @@ -138,8 +196,7 @@ public void mouseClicked(MouseEvent evt) {

private void buildUI() {
// Create components
JButton addButton = new JButton("Add");
JButton aboutButton = new JButton("About");


// TODO: Add more buttons and functionalities
asyncFileListUpdate();
Expand All @@ -155,9 +212,9 @@ private void buildUI() {
}
}

asyncAdaptiveGUI();

// Place components
addButton.setBounds(Frame.frame.getWidth() - 100, Frame.frame.getHeight() - 100, 100, 50);
aboutButton.setBounds(Frame.frame.getWidth() - 100, Frame.frame.getHeight() - 50, 100, 50);
fileLists.setBounds(0, 0, Frame.frame.getWidth(), Frame.frame.getHeight() - 100);

// On addButton click
Expand All @@ -178,6 +235,8 @@ public void mouseClicked(MouseEvent e) {
aboutButton.addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (About.isOpen) return;
About.isOpen = true;
JFrame frame = new JFrame("About");
frame.setResizable(false);
frame.setSize(600, 200);
Expand All @@ -189,8 +248,6 @@ public void mouseClicked(MouseEvent e) {
});

// Add components
this.add(addButton);
this.add(aboutButton);
this.add(fileLists);
}

Expand Down
1 change: 1 addition & 0 deletions src/screens/views/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Login() {
// Configure the panel
super();
this.setBounds(0, 0, Frame.frame.getWidth(), Frame.frame.getHeight());
Frame.frame.setResizable(false);
this.setLayout(null);
this.setBackground(ColorScheme.background);

Expand Down
1 change: 1 addition & 0 deletions src/screens/views/Signup.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public Signup() {
super();
this.setBackground(ColorScheme.background);
this.setBounds(0, 0, Frame.frame.getWidth(), Frame.frame.getHeight());
Frame.frame.setResizable(false);
this.setLayout(null);

// Set bounds for components
Expand Down
Loading

0 comments on commit 09f3d46

Please sign in to comment.