Skip to content

Commit

Permalink
Added Separate MonthAndDay
Browse files Browse the repository at this point in the history
Moved MonthAndDay into OneLineMonthAndDay
Removed Moveaway of Images (WFTool 1.3.9 does that automatically)
Create dir on Import if not existing
Fixed negative size
  • Loading branch information
MonsterDruide1 committed Aug 30, 2019
1 parent 42d0af7 commit 33da4ea
Show file tree
Hide file tree
Showing 17 changed files with 502 additions and 154 deletions.
25 changes: 12 additions & 13 deletions MiBand4Editor/src/display/EditMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import elements.activity.Steps;
import elements.activity.StepsGoal;
import elements.date.AmPm;
import elements.date.MonthAndDay;
import elements.date.OneLineMonthAndDay;
import elements.date.WeekDay;
import elements.status.BatteryIcon;
Expand Down Expand Up @@ -248,8 +247,8 @@ else if(element instanceof SecondsGroup) {
((SecondsGroup)element).changeImageIndex(imageIndex);
main.addElement(element);
}
else if(element instanceof MonthAndDay) {
((MonthAndDay)element).changeImageIndex(imageIndex);
else if(element instanceof OneLineMonthAndDay) {
((OneLineMonthAndDay)element).changeImageIndex(imageIndex);
main.addElement(element,parent.getWidth(),parent.getHeight());
}
else if(element instanceof WeekDay) {
Expand Down Expand Up @@ -313,8 +312,8 @@ else if(element instanceof SecondsGroup) {
((SecondsGroup)element).changeImageCount(imageCount);
main.addElement(element);
}
else if(element instanceof MonthAndDay) {
((MonthAndDay)element).changeImageCount(imageCount);
else if(element instanceof OneLineMonthAndDay) {
((OneLineMonthAndDay)element).changeImageCount(imageCount);
main.addElement(element,parent.getWidth(),parent.getHeight());
}
else if(element instanceof WeekDay) {
Expand Down Expand Up @@ -430,8 +429,8 @@ private void editAlignment() {
try {
parent.getParent().remove(parent);
main.elements.remove(element);
if(element instanceof MonthAndDay) {
((MonthAndDay)element).changeAlignment(alignment);
if(element instanceof OneLineMonthAndDay) {
((OneLineMonthAndDay)element).changeAlignment(alignment);
}
else if(element instanceof Steps) {
((Steps)element).changeAlignment(alignment);
Expand Down Expand Up @@ -469,8 +468,8 @@ private void editSpacing() {
try {
parent.getParent().remove(parent);
main.elements.remove(element);
if(element instanceof MonthAndDay) {
((MonthAndDay)element).changeSpacing(spacing);
if(element instanceof OneLineMonthAndDay) {
((OneLineMonthAndDay)element).changeSpacing(spacing);
}
else if(element instanceof Steps) {
((Steps)element).changeSpacing(spacing);
Expand Down Expand Up @@ -505,8 +504,8 @@ private void editDelimiterIndex() {
try {
parent.getParent().remove(parent);
main.elements.remove(element);
if(element instanceof MonthAndDay) {
((MonthAndDay)element).changeDelimiterIndex(delimiterIndex);
if(element instanceof OneLineMonthAndDay) {
((OneLineMonthAndDay)element).chageDelimiterIndex(delimiterIndex);
}
main.addElement(element,parent.getWidth(),parent.getHeight());
} catch (FileNotFoundException e1) {
Expand Down Expand Up @@ -541,7 +540,7 @@ private void editTwoDigitsMonth() {
try {
parent.getParent().remove(parent);
main.elements.remove(element);
((MonthAndDay)element).changeTwoDigitsMonth(twoDigitsMonth);
((OneLineMonthAndDay)element).changeTwoDigitsMonth(twoDigitsMonth);
main.addElement(element,parent.getWidth(),parent.getHeight());
} catch (FileNotFoundException e1) {
JOptionPane.showMessageDialog(null, main.getInLang("error_imageNotFound_multi_title")+e1.getMessage(), main.getInLang("error_imageNotFound_multi_title"), JOptionPane.ERROR_MESSAGE);
Expand All @@ -557,7 +556,7 @@ private void editTwoDigitsDay() {
try {
parent.getParent().remove(parent);
main.elements.remove(element);
((MonthAndDay)element).changeTwoDigitsDay(twoDigitsDay);
((OneLineMonthAndDay)element).changeTwoDigitsDay(twoDigitsDay);
main.addElement(element,parent.getWidth(),parent.getHeight());
} catch (FileNotFoundException e1) {
JOptionPane.showMessageDialog(null, main.getInLang("error_imageNotFound_multi_title")+e1.getMessage(), main.getInLang("error_imageNotFound_multi_title"), JOptionPane.ERROR_MESSAGE);
Expand Down
10 changes: 5 additions & 5 deletions MiBand4Editor/src/display/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import elements.activity.Steps;
import elements.activity.StepsGoal;
import elements.date.AmPm;
import elements.date.MonthAndDay;
import elements.date.OneLineMonthAndDay;
import elements.date.WeekDay;
import elements.status.BatteryIcon;
import elements.status.BatteryText;
Expand Down Expand Up @@ -273,7 +273,7 @@ private void addDateMonthAndDay() {
boolean twoDigitsMonth = StaticConfigurators.askForBoolean(parent.getInLang("edit_twoDigitsMonth_title"),parent.getInLang("edit_twoDigitsMonth"),parent.getInLang("edit_accept"));
boolean twoDigitsDay = StaticConfigurators.askForBoolean(parent.getInLang("edit_twoDigitsDay_title"),parent.getInLang("edit_twoDigitsDay"),parent.getInLang("edit_accept"));
try {
MonthAndDay group = new MonthAndDay(parent.lastClick.x/3, parent.lastClick.y/3, alignment, spacing, imageIndex, imageCount, delimiterIndex, twoDigitsMonth, twoDigitsDay);
OneLineMonthAndDay group = new OneLineMonthAndDay(parent.lastClick.x/3, parent.lastClick.y/3, alignment, spacing, imageIndex, imageCount, delimiterIndex, twoDigitsMonth, twoDigitsDay);
parent.addElement(group);
JPopupMenu date = (JPopupMenu) menu.getSubElements()[0].getSubElements()[0].getSubElements()[1].getSubElements()[0];
((JMenuItem)date.getSubElements()[0]).setEnabled(false);
Expand Down Expand Up @@ -538,9 +538,9 @@ private void generate() {
Builder builder = new Builder();
builder.generateBackground(parent.bgItems.toArray(new BGItem[0]));
builder.generateJSON(parent.elements,parent.panel.getBGX(),parent.panel.getBGY());
File[][] disabled = builder.disableUnneededImgs(parent.elements);
//File[][] disabled = builder.disableUnneededImgs(parent.elements);
builder.runBuilder();
builder.reenableImgs(disabled);
//builder.reenableImgs(disabled);
} catch (IOException | InterruptedException e1) {
e1.printStackTrace();
}
Expand All @@ -567,7 +567,7 @@ else if(element instanceof SecondsGroup) {
else if(element instanceof AmPm) {
((JMenuItem)date.getSubElements()[2]).setEnabled(enabled);
}
else if(element instanceof MonthAndDay) {
else if(element instanceof OneLineMonthAndDay) {
((JMenuItem)date.getSubElements()[0]).setEnabled(enabled);
}
else if(element instanceof WeekDay) {
Expand Down
3 changes: 1 addition & 2 deletions MiBand4Editor/src/display/Mover.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import elements.activity.Steps;
import elements.activity.StepsGoal;
import elements.date.AmPm;
import elements.date.MonthAndDay;
import elements.date.OneLineMonthAndDay;
import elements.date.WeekDay;
import elements.status.BatteryIcon;
Expand Down Expand Up @@ -138,7 +137,7 @@ public void mouseReleased(MouseEvent arg0) {
Point p = new Point((int)((((double)arg0.getPoint().getX())+((double)component.getX()))/3),(int)(((double)arg0.getPoint().getY())+((double)component.getY()))/3);
System.out.println(p);
if(component.getName().startsWith(OneLineMonthAndDay.class.toString())) {
MonthAndDay e = (MonthAndDay)parent.elements.get(Integer.parseInt(component.getName().split("\\|\\|")[1]));
OneLineMonthAndDay e = (OneLineMonthAndDay)parent.elements.get(Integer.parseInt(component.getName().split("\\|\\|")[1]));
component.getParent().remove(component);
try {
JPanel panel = (JPanel) e.getPreview((int)arg0.getPoint().getX(),(int)arg0.getPoint().getY());
Expand Down
8 changes: 4 additions & 4 deletions MiBand4Editor/src/display/TopMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,12 @@ public String getDescription() {
});
f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
f.setAcceptAllFileFilterUsed(false);
f.showOpenDialog(null);
f.showSaveDialog(null);
StaticHelpers.setJavaLookAndFeel();
File dest = f.getSelectedFile();
if(!dest.exists()) {
dest.mkdirs();
}
for(File toMove : selected.listFiles()) {
String fileName = dest.getAbsolutePath()+"\\"+toMove.getName();
try {
Expand All @@ -359,11 +362,8 @@ public String getDescription() {
File[] jsons = selected.listFiles(new FilenameFilter() {
@Override
public boolean accept(File f, String fName) {
System.out.println(fName);
String[] name = fName.split("\\.");
System.out.println(name[name.length-1]);
if(name[name.length-1].equals("json")) {
System.out.println("YES");
return true;
}
return false;
Expand Down
4 changes: 3 additions & 1 deletion MiBand4Editor/src/elements/activity/Calories.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public JPanel getPreview(int w, int h) throws IOException {
mainPanel.setName(panel.getName());

if(w!=0 && h!=0) {
mainPanel.setSize(new Dimension(w,h));
Dimension preferred = layout.preferredLayoutSize(panel);
Dimension finalD = new Dimension(Math.max(preferred.width, w),Math.max(preferred.height, h));
mainPanel.setSize(finalD);
}
else {
mainPanel.setSize(layout.preferredLayoutSize(panel));
Expand Down
4 changes: 3 additions & 1 deletion MiBand4Editor/src/elements/activity/Distance.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public JPanel getPreview(int w, int h) throws IOException {
mainPanel.setName(panel.getName());

if(w!=0 && h!=0) {
mainPanel.setSize(new Dimension(w,h));
Dimension preferred = layout.preferredLayoutSize(panel);
Dimension finalD = new Dimension(Math.max(preferred.width, w),Math.max(preferred.height, h));
mainPanel.setSize(finalD);
}
else {
mainPanel.setSize(layout.preferredLayoutSize(panel));
Expand Down
4 changes: 3 additions & 1 deletion MiBand4Editor/src/elements/activity/Pulse.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public JPanel getPreview(int w, int h) throws IOException {
mainPanel.setName(panel.getName());

if(w!=0 && h!=0) {
mainPanel.setSize(new Dimension(w,h));
Dimension preferred = layout.preferredLayoutSize(panel);
Dimension finalD = new Dimension(Math.max(preferred.width, w),Math.max(preferred.height, h));
mainPanel.setSize(finalD);
}
else {
mainPanel.setSize(layout.preferredLayoutSize(panel));
Expand Down
4 changes: 3 additions & 1 deletion MiBand4Editor/src/elements/activity/Steps.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public JPanel getPreview(int w, int h) throws IOException {
mainPanel.setName(panel.getName());

if(w!=0 && h!=0) {
mainPanel.setSize(new Dimension(w,h));
Dimension preferred = layout.preferredLayoutSize(panel);
Dimension finalD = new Dimension(Math.max(preferred.width, w),Math.max(preferred.height, h));
mainPanel.setSize(finalD);
}
else {
mainPanel.setSize(layout.preferredLayoutSize(panel));
Expand Down
4 changes: 3 additions & 1 deletion MiBand4Editor/src/elements/activity/StepsGoal.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public JPanel getPreview(int w, int h) throws IOException {
mainPanel.setName(panel.getName());

if(w!=0 && h!=0) {
mainPanel.setSize(new Dimension(w,h));
Dimension preferred = layout.preferredLayoutSize(panel);
Dimension finalD = new Dimension(Math.max(preferred.width, w),Math.max(preferred.height, h));
mainPanel.setSize(finalD);
}
else {
mainPanel.setSize(layout.preferredLayoutSize(panel));
Expand Down
105 changes: 0 additions & 105 deletions MiBand4Editor/src/elements/date/MonthAndDay.java

This file was deleted.

27 changes: 24 additions & 3 deletions MiBand4Editor/src/elements/date/OneLineMonthAndDay.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@ public class OneLineMonthAndDay extends Element{

Number number;
int delimiterImageIndex;
boolean twoDigitsMonth;
boolean twoDigitsDay;

public OneLineMonthAndDay(int x, int y, String textAlignment, int spacing, int imageIndex,
int imageCount, int delimiterImageIndex) throws IOException, UnequalDimensionsException {
int imageCount, int delimiterImageIndex, boolean twoDigitsDay, boolean twoDigitsMonth) throws IOException, UnequalDimensionsException {
this.delimiterImageIndex=delimiterImageIndex;
number = new Number(x,y,textAlignment,spacing,imageIndex,imageCount,5);
String absolutePath = MiBand4Editor.currentPath.getAbsolutePath();

String iFormatted = String.format("%04d", delimiterImageIndex);
File delimiter = new File(absolutePath+"\\"+iFormatted+".png");
number.resizeToCoords(number.getBottomRightPoint().x+(number.getSize().width*3)+StaticHelpers.getImageDimension(delimiter).width, number.getBottomRightPoint().y);
this.twoDigitsDay = twoDigitsDay;
this.twoDigitsMonth = twoDigitsMonth;
}

public OneLineMonthAndDay(JSONObject jsonObject) {
public OneLineMonthAndDay(JSONObject fullObj) {
JSONObject jsonObject = fullObj.getJSONObject("OneLine");
number = new Number(jsonObject.getJSONObject("Number"));
delimiterImageIndex = jsonObject.getInt("DelimiterImageIndex");
twoDigitsMonth = fullObj.getBoolean("TwoDigitsMonth");
twoDigitsDay = fullObj.getBoolean("TwoDigitsDay");
}

public JPanel getPreview(int w, int h) throws IOException {
Expand Down Expand Up @@ -84,7 +91,9 @@ public JPanel getPreview(int w, int h) throws IOException {
mainPanel.setName(panel.getName());

if(w!=0 && h!=0) {
mainPanel.setSize(new Dimension(w,h));
Dimension preferred = layout.preferredLayoutSize(panel);
Dimension finalD = new Dimension(Math.max(preferred.width, w),Math.max(preferred.height, h));
mainPanel.setSize(finalD);
}
else {
mainPanel.setSize(layout.preferredLayoutSize(panel));
Expand All @@ -101,10 +110,14 @@ public void setCoords(int x, int y) {
@Override
public String getJSON() {
StringBuilder builder = new StringBuilder();
builder.append(" \"MonthAndDay\": {\r\n");
builder.append(" \"OneLine\": {\r\n");
builder.append(number.getJSON());
builder.append(",\r\n \"DelimiterImageIndex\": "+delimiterImageIndex+"\r\n");
builder.append(" }\r\n");
builder.append(",\r\n \"TwoDigitsMonth\": "+twoDigitsMonth+",\r\n");
builder.append(" \"TwoDigitsDay\": "+twoDigitsDay+"\r\n");
builder.append(" }\r\n");
return builder.toString();
}

Expand Down Expand Up @@ -160,4 +173,12 @@ public Point getLocation() {
return number.getLocation();
}

public void changeTwoDigitsMonth(boolean twoDigitsMonth) {
this.twoDigitsMonth=twoDigitsMonth;
}

public void changeTwoDigitsDay(boolean twoDigitsDay) {
this.twoDigitsDay=twoDigitsDay;
}

}
Loading

0 comments on commit 33da4ea

Please sign in to comment.