Skip to content

Commit 63894c7

Browse files
committed
Fixed some bugs for v3.4
1 parent c9cd10f commit 63894c7

File tree

8 files changed

+142
-48
lines changed

8 files changed

+142
-48
lines changed

src/gui/GuiHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static MatteBorder getSelectedBorder()
9999
*/
100100
public static Border getEmptyBorder()
101101
{
102-
return BorderFactory.createEmptyBorder();
102+
return BorderFactory.createEmptyBorder(0,0,0,0);
103103
}
104104

105105
/**

src/gui/MainGui.java

Lines changed: 79 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
11
package gui;
2-
import java.awt.Dimension;
3-
import java.awt.Font;
4-
import java.awt.GridLayout;
5-
import java.awt.Toolkit;
6-
import java.awt.event.WindowAdapter;
7-
import java.awt.event.WindowEvent;
8-
import java.io.File;
9-
import java.io.FileNotFoundException;
10-
import java.io.PrintStream;
11-
import java.util.ArrayList;
2+
3+
import java.awt.*;
4+
import java.awt.event.*;
5+
import java.io.*;
6+
import java.util.*;
127
import java.util.regex.Pattern;
138

14-
import javax.swing.BoxLayout;
15-
import javax.swing.JCheckBoxMenuItem;
16-
import javax.swing.JDialog;
17-
import javax.swing.JFrame;
18-
import javax.swing.JPanel;
19-
import javax.swing.JScrollPane;
20-
import javax.swing.ScrollPaneConstants;
21-
import javax.swing.SwingUtilities;
22-
import javax.swing.UIManager;
23-
import javax.swing.WindowConstants;
9+
import javax.swing.*;
2410

25-
import edit.CellEditDialog;
26-
import edit.SectionManagerDialog;
27-
import logic.FileOperations;
28-
import logic.Hotkeys;
29-
import logic.LiveSplitConnection;
30-
import logic.MouseAdapters;
31-
import logic.Section;
32-
import logic.Updates;
11+
import edit.*;
12+
import logic.*;
3313

3414
public class MainGui {
3515
public static Font font = new Font("Serif", Font.PLAIN, 20);
@@ -39,6 +19,7 @@ public class MainGui {
3919
public static CellEditDialog cellEditDialog;
4020

4121
public static JFrame window;
22+
//public static JFrame content_window;
4223
public static JScrollPane scrollPane;
4324
public static JPanel mainPanel;
4425

@@ -52,7 +33,11 @@ public class MainGui {
5233

5334
public static Dimension screensize;
5435

55-
public static String currentVersionTag = "v3.3";
36+
public static String currentVersionTag = "v3.4";
37+
38+
public final static int moveToSectionAbove = -1;
39+
public final static int removeSection = 0;
40+
public final static int moveToSectionBelow = 1;
5641

5742
private static void prepareGui()
5843
{
@@ -66,15 +51,41 @@ private static void prepareGui()
6651
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
6752
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
6853

69-
window = new JFrame();
54+
JPanel colorPanel = new JPanel();
55+
colorPanel.setBackground(ColorSettings.getBackgroundColor() );
56+
colorPanel.setBorder(GuiHelper.getEmptyBorder() );
57+
58+
window = new JFrame() /*{
59+
private static final long serialVersionUID = -1303115076804508497L;
60+
61+
@Override
62+
public Insets getInsets()
63+
{
64+
return new Insets(0, 0, 0, 0);
65+
}
66+
}//*/;
7067
window.setJMenuBar(MenuItems.createMenuBar() );
7168
window.setLayout(new BoxLayout(window.getContentPane(), BoxLayout.Y_AXIS) );
7269
window.add(scrollPane);
70+
//window.setContentPane(colorPanel);
7371
window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
7472
window.addWindowListener(MouseAdapters.windowOnCloseAdapter);
7573
window.setTitle("");
7674
window.pack();
7775
window.setVisible(true);
76+
77+
/*
78+
content_window = new JFrame();
79+
content_window.setUndecorated(true);
80+
content_window.setLayout(new BoxLayout(content_window.getContentPane(), BoxLayout.Y_AXIS) );
81+
content_window.add(scrollPane);
82+
content_window.setTitle("Notes-creator-capture-frame");
83+
content_window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
84+
content_window.addWindowListener(MouseAdapters.windowOnCloseAdapter);
85+
content_window.pack();
86+
content_window.setVisible(true);
87+
System.out.println("Main:" + window.getInsets() + ", content:" + content_window.getInsets() );
88+
//*/
7889
}
7990

8091
public static void arrangeContent()
@@ -90,12 +101,15 @@ public static void arrangeContent()
90101
if (inEditMode) sectionManagerDialog.updateSectionManagerDialog();
91102

92103
window.remove(scrollPane);
104+
//content_window.remove(scrollPane);
93105
window.setPreferredSize(null);
106+
//content_window.setPreferredSize(null);
94107
window.setTitle(FileOperations.getWindowTitle() );
95108

96109
mainPanel = new JPanel();
97110
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS) );
98111
mainPanel.setBackground(ColorSettings.getBackgroundColor() );
112+
mainPanel.setOpaque(false);
99113

100114
for (Section section : sectionsList)
101115
mainPanel.add(section);
@@ -104,12 +118,20 @@ public static void arrangeContent()
104118
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
105119
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
106120
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
121+
//scrollPane.getViewport().setOpaque(false);
122+
//scrollPane.setOpaque(false);
123+
scrollPane.getViewport().setBackground(ColorSettings.getBackgroundColor() );
107124

108125
window.add(scrollPane);
126+
//content_window.add(scrollPane);
127+
//content_window.setBackground(new Color(0, 0, 0, 0) );
109128
window.pack();
129+
//content_window.pack();
110130
window.setVisible(true);
131+
//content_window.setVisible(true);
111132
resizeWindow();
112133
window.pack();
134+
//content_window.pack();
113135

114136
sectionsList.forEach(section -> section.setLocation() );
115137
}
@@ -133,6 +155,7 @@ private static void resizeWindow()
133155
height = window.getHeight();
134156
if (window.getWidth() < width)
135157
width = window.getWidth();
158+
//content_window.setPreferredSize(new Dimension(width + 100, height) );
136159
window.setPreferredSize(new Dimension(width + 100, height) );
137160
}
138161

@@ -154,6 +177,10 @@ public static void spaceColums()
154177
window.setVisible(true);
155178
window.repaint();
156179
window.setMaximumSize(screensize);
180+
//content_window.pack();
181+
//content_window.setVisible(true);
182+
//content_window.repaint();
183+
//content_window.setMaximumSize(screensize);
157184

158185
// determining the maximal width for each column
159186
Section.maxWidths = new int[FileOperations.numberOfColumns + 2];
@@ -165,6 +192,7 @@ public static void spaceColums()
165192
scrollPane.setPreferredSize(new Dimension(scrollPane.getWidth() + 100, keepGuiSize ? height : scrollPane.getHeight() ) );
166193

167194
window.pack();
195+
//content_window.pack();
168196
scrollPane.getVerticalScrollBar().setValue(scrollValue);
169197

170198
keepGuiSize = true;
@@ -200,6 +228,7 @@ public void run()
200228
try
201229
{
202230
e.printStackTrace(new PrintStream(new File("log.txt") ) );
231+
e.printStackTrace();
203232
} catch (FileNotFoundException e1)
204233
{
205234
// TODO Auto-generated catch block
@@ -252,8 +281,27 @@ public static void addSection(int section_index, Section new_section)
252281
sectionManagerDialog.updateSectionManagerDialog();
253282
}
254283

255-
public static void removeSection(int section_index)
284+
public static void removeSection(int section_index, int moveContent)
256285
{
286+
if (moveContent < -1 || moveContent > 1)
287+
throw new IllegalArgumentException("moveContent has to be between -1 and 1, got " + moveContent);
288+
289+
if (moveContent == removeSection)
290+
sectionsList.remove(section_index);
291+
else
292+
{
293+
ArrayList<Row> rows = sectionsList.remove(section_index).getRows();
294+
rows.remove(rows.size() - 1);
295+
296+
try
297+
{
298+
if (moveContent == moveToSectionAbove)
299+
sectionsList.get(section_index - 1).addRowsAtEnd(rows);
300+
else if(moveContent == moveToSectionBelow)
301+
sectionsList.get(section_index).addRowsAtStart(rows); // the section was already removed, so the next section has the same index as the one that was removed.
302+
} catch (IndexOutOfBoundsException e)
303+
{ return; }
304+
}
257305
arrangeContent();
258306
spaceColums();
259307
sectionManagerDialog.updateSectionManagerDialog();

src/gui/MenuItems.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@ static JMenuBar createMenuBar()
107107
about_update.addActionListener(action -> { Updates.checkForUpdates(true); });
108108

109109
// Shortcuts
110-
file_open .setAccelerator(KeyStroke.getKeyStroke("control O") );
111-
file_reload .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0) );
112-
file_save .setAccelerator(KeyStroke.getKeyStroke("control S") );
113-
file_save_as.setAccelerator(KeyStroke.getKeyStroke("control alt S") );
110+
file_open .setAccelerator(KeyStroke.getKeyStroke("control O") );
111+
file_reload .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0) );
112+
file_save .setAccelerator(KeyStroke.getKeyStroke("control S") );
113+
file_save_as .setAccelerator(KeyStroke.getKeyStroke("control alt S") );
114+
file_new .setAccelerator(KeyStroke.getKeyStroke("control N") );
115+
edit_enabled .setAccelerator(KeyStroke.getKeyStroke("control E") );
116+
edit_abbr_edit.setAccelerator(KeyStroke.getKeyStroke("control A") );
114117

115118
// Filling Menus
116119
// Fill File Menu

src/logic/AddRemoveControl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ private AddRemoveControl(Row row, int section_index, boolean only_add)
2424
this.row = row;
2525
this.sectionIndex = section_index;
2626

27+
boolean section_control = row == null;
28+
2729
add = GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors(" + ", GuiHelper.CENTER);
2830
add.setForeground(MainGui.inEditMode ? ColorSettings.getTextColor() : ColorSettings.getBackgroundColor() );
29-
add.addMouseListener(row == null ? MouseAdapters.addSectionAdapter : MouseAdapters.addRowAdapter);
31+
add.addMouseListener(section_control ? MouseAdapters.addSectionAdapter : MouseAdapters.addRowAdapter);
3032

3133
this.add(new JLabel());
3234
this.add(add);
@@ -35,8 +37,11 @@ private AddRemoveControl(Row row, int section_index, boolean only_add)
3537
{
3638
remove = GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors(" - ", GuiHelper.CENTER);
3739
remove.setForeground(MainGui.inEditMode ? ColorSettings.getTextColor() : ColorSettings.getBackgroundColor() );
38-
remove.addMouseListener(row == null ? MouseAdapters.removeSectionAdapter : MouseAdapters.removeRowAdapter);
39-
40+
remove.addMouseListener(section_control ? MouseAdapters.removeSectionAdapter : MouseAdapters.removeRowAdapter);
41+
if (section_control)
42+
remove.setToolTipText("<html>Removes the whole section and its content.<br/>"
43+
+ "Shift: append the content to the section above.<br/>"
44+
+ "Control: prepend the content to the section below.</html>");
4045
this.add(remove);
4146
this.add(new JLabel());
4247
}

src/logic/Cell.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ private void fillCellPanel()
185185
*/
186186
public Cell[] getNeighbours()
187187
{
188+
System.out.println("index: " + row.getRowIndex() + ", rows: " + row.getSection().getRows().size() );
188189
Cell[] res = new Cell[4];
189-
res[0] = row.getRowIndex() == 0 ? null : row.getSection().getRows().get(row.getRowIndex() - 1).getCells().get(col);
190-
res[1] = row.getRowIndex() == row.getSection().getRows().size() - 1 ? null : row.getSection().getRows().get(row.getRowIndex() + 1).getCells().get(col);
190+
res[0] = row.getRowIndex() == 0 ? null : row.getSection().getRows().get(row.getRowIndex() - 1).getCells().get(col);
191+
res[1] = row.getRowIndex() == row.getSection().numberOfContentRows() - 1 ? null : row.getSection().getRows().get(row.getRowIndex() + 1).getCells().get(col);
191192
res[2] = col == 0 ? null : row.getCells().get(col - 1);
192193
res[3] = col == row.getCells().size() - 1 ? null : row.getCells().get(col + 1);
193194
return res;

src/logic/MouseAdapters.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.awt.datatransfer.StringSelection;
55
import java.awt.event.ActionEvent;
66
import java.awt.event.ActionListener;
7+
import java.awt.event.KeyEvent;
78
import java.awt.event.MouseEvent;
89
import java.awt.event.WindowAdapter;
910
import java.awt.event.WindowEvent;
@@ -31,12 +32,11 @@ public void mouseClicked(MouseEvent e)
3132

3233
int buttonPressed = e.getButton();
3334

34-
if (buttonPressed == 1 || buttonPressed == 3)
35-
{
35+
if (buttonPressed == MouseEvent.BUTTON1)
3636
MainGui.cellEditDialog.processCell( (Cell) e.getComponent() );
37-
if (buttonPressed == 3)
38-
PopupMenues.processCellRightClick(e);
39-
}
37+
38+
if (buttonPressed == MouseEvent.BUTTON3)
39+
PopupMenues.processCellRightClick(e);
4040
}
4141
};
4242

@@ -69,13 +69,20 @@ public void mouseClicked(MouseEvent e)
6969
final static MouseInputAdapter removeSectionAdapter = new MouseInputAdapter()
7070
{
7171
@Override
72-
public void mouseClicked(MouseEvent e)
72+
public void mousePressed(MouseEvent e)
7373
{
7474
if (MainGui.inEditMode)
7575
{
7676
FileOperations.unsavedChanges = true;
7777
int section_index = ( (AddRemoveControl) e.getComponent().getParent() ).getSectionIndex();
78-
MainGui.removeSection(section_index);
78+
int key_mask = e.getModifiersEx();
79+
System.out.println(key_mask);
80+
if (key_mask == KeyEvent.BUTTON1_DOWN_MASK)
81+
MainGui.removeSection(section_index, MainGui.removeSection);
82+
if (key_mask == (KeyEvent.BUTTON1_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK) )
83+
MainGui.removeSection(section_index, MainGui.moveToSectionAbove);
84+
if (key_mask == (KeyEvent.BUTTON1_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK) )
85+
MainGui.removeSection(section_index, MainGui.moveToSectionBelow);
7986
}
8087
}
8188
};

src/logic/Row.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public class Row
8585
cells.add(new Cell(this, col, (Element) cellNodes.item(col) ) );
8686
}
8787

88+
public void setIndex(int new_index)
89+
{
90+
this.rowIndex = new_index;
91+
}
92+
8893
void reloadImages()
8994
{
9095
for (Cell cell : cells) cell.relaodImages();

src/logic/Section.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class Section extends JPanel
3434
public String getTitle() { return title; }
3535
public int getScrollLocation() { return scrollLocation; }
3636
public ArrayList<Row> getRows() { return rows; }
37+
public int numberOfContentRows() { return rows.size() - 1; }
3738

3839
/**
3940
* Creates an empty section containing an empty row.
@@ -86,6 +87,30 @@ private void addLastRow()
8687
rows.add(new Row(this, rows.size(), Row.LAST) );
8788
}
8889

90+
public void addRowsAtStart(ArrayList<Row> new_rows)
91+
{
92+
System.out.println(this.title + ": " + rows.size() );
93+
rows.addAll(0, new_rows);
94+
System.out.println(rows.size() );
95+
updateRowIndices();
96+
97+
fillPanel();
98+
}
99+
100+
public void addRowsAtEnd(ArrayList<Row> new_rows)
101+
{
102+
rows.addAll(rows.size() - 1, new_rows);
103+
updateRowIndices();
104+
105+
fillPanel();
106+
}
107+
108+
private void updateRowIndices()
109+
{
110+
for (int i = 0; i < rows.size(); i ++)
111+
rows.get(i).setIndex(i);
112+
}
113+
89114
public void reloadImages()
90115
{
91116
for (Row row : rows) row.reloadImages();

0 commit comments

Comments
 (0)