Skip to content

Commit 4ae1390

Browse files
committed
Allow box insert into empty box file
1 parent c97284e commit 4ae1390

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/net/sourceforge/tessboxeditor/GuiWithEdit.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,35 @@ void jMenuItemInsertActionPerformed(java.awt.event.ActionEvent evt) {
160160
if (boxes == null) {
161161
return;
162162
}
163-
List<TessBox> selected = boxes.getSelectedBoxes();
164-
if (selected.size() <= 0) {
165-
JOptionPane.showMessageDialog(this, "Please select the box to insert after.");
166-
return;
167-
} else if (selected.size() > 1) {
168-
JOptionPane.showMessageDialog(this, "Please select only one box for Insert operation.");
169-
return;
163+
TessBox newBox;
164+
Rectangle newRect;
165+
int index;
166+
167+
if (boxes.toList().isEmpty()) {
168+
newRect = new Rectangle(0, 0, 20, 30);
169+
newBox = new TessBox(" ", newRect, (short) 0);
170+
boxes.add(newBox);
171+
index = 0;
172+
} else {
173+
List<TessBox> selected = boxes.getSelectedBoxes();
174+
if (selected.size() <= 0) {
175+
JOptionPane.showMessageDialog(this, "Please select the box to insert after.");
176+
return;
177+
} else if (selected.size() > 1) {
178+
JOptionPane.showMessageDialog(this, "Please select only one box for Insert operation.");
179+
return;
180+
}
181+
182+
TessBox box = selected.get(0);
183+
index = this.boxes.toList().indexOf(box);
184+
index++;
185+
newBox = new TessBox(" ", new Rectangle(box.getRect()), box.getPage());
186+
newBox.setSelected(true);
187+
boxes.add(index, newBox);
188+
newRect = newBox.getRect();
189+
newRect.x += 15; // offset the new box 15 pixel from the base one
170190
}
171191

172-
TessBox box = selected.get(0);
173-
int index = this.boxes.toList().indexOf(box);
174-
index++;
175-
TessBox newBox = new TessBox(" ", new Rectangle(box.getRect()), box.getPage());
176-
newBox.setSelected(true);
177-
boxes.add(index, newBox);
178-
Rectangle newRect = newBox.getRect();
179-
newRect.x += 15; // offset the new box 15 pixel from the base one
180192
Object[] newRow = {newBox.getChrs(), newRect.x, newRect.y, newRect.width, newRect.height};
181193
tableModel.insertRow(index, newRow);
182194
jTable.setRowSelectionInterval(index, index);

versionchanges.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,6 @@ Version 2.3.0 (21 March 2020)
142142
- Upgrade Tesseract training executable 5.0.0-alpha (2020-02-23)
143143
- Update dependencies
144144

145-
Version 2.3.1 (10 June 2020)
145+
Version 2.3.1 (17 June 2020)
146+
- Allow box insert into empty box file
146147
- Add Python script to merge all box files

0 commit comments

Comments
 (0)