@@ -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 );
0 commit comments