<The previous article in this series | The table of contents of this series | The next article in this series>
We Created a Spread Sheet Cell Editor
About: UNO (Universal Network Objects)
About: LibreOffice
About: Apache OpenOffice
About: Java Programming Language
Here are -Hypothesizer and -Rebutter sitting in front of a computer screen in a room on a brook among some mountains on the Bias planet.
As we know how to implement GUIs in our UNO Extensions, we will create a cell editor. A cell editor is an editor that edits the contents of any spread sheet cell.
So, our cell editor is to spread sheet cells as usual editors are to files.
Yes. As it is cumbersome to handle long texts inside cells, such a cell editor will be handy when our cells have long texts. You know, a long text doesn't fit even in the pop-up window that is shown by our double-clicking the cell.
Will we have such long texts in our cells?
Well, . . . I think we can. I mean, if we can handily handle long texts on spread sheets, we can use spread sheets in wider use. That is, we can use spread sheets in any case in which want to organize and handle data in a grid: a long text doesn't need to be fully visible inside the small box of a cell.
Isn't saying "in any case" an exaggeration?
At this stage, it may, but we could expand our cell editor to make it handle, say images.
Well, we should say just "wider use" at this stage.
The same with the previous scene.
What features will our cell editor have?
We can show the contents of the cell in a wide area, can scroll the text, can see line numbers, can search any specified phrase in the text, can replace any specified phrase in the text with another any specified phrase, can jump to the top or the bottom of the text, can do copying, cutting, pasting, undoing, and redoing, can select the whole of the text, can go to the upper, the lower, the left, or the right cell, . . .
Are we going to let multiple cell editor windows be shown at the same time?
Well, . . . I thought we would let only one cell editor window be shown at a time: many cell editor windows could clutter the screen . . .
Two cell editors wouldn't do much harm. I think, it isn't rare that we want to show two cell editor windows at a time, like when we compare the contents of two cells.
Well, if you say so . . .
On the other hand, we don't have to open a new cell editor window just because we want to edit another cell, do we?
Like I said, we can go to neighboring cells in the existing cell editor window.
Only neighboring cells?
Well, . . . of course we will also have to able to jump to an arbitrary cell. . . . We will implement a reconnect button, which reconnects the cell editor window to the current cell on the spread sheet.
Please elaborate on the relationship between the current cell on the spread sheet and the cell that a cell editor window is connected to.
When a cell editor window is newly opened, the cell editor window is connected to the current cell on the spread sheet. Just selecting another cell on the spread sheet doesn't make the cell editor window reconnect to the new current cell. Doing certain operations on the cell editor window make the cell editor reconnect to another cell.
By certain operations you mean, say clicking a 'Go to the Right Cell' or the reconnect button?
Yes. Clicking a 'Save' button saves the contents to the connected cell, which isn't necessarily the current cell on the spread sheet.
Can't you let a cell editor window automatically reconnect to the current cell on the spread sheet as the cell selection on the spread sheet is changed?
That would be meaningless when multiple cell editor windows are shown: all the cell editor window would connect to the same cell.
I didn't tell you to make all the cell editor windows reconnect to the current cell on the spread sheet without question.
Um? . . . Ah, we can implement a check box that specifies whether the cell editor window should automatically reconnect to the current cell on the spread sheet . . .
Well, I would be able to do so, but . . . I would like to put off that feature to the future. I mean, we have to investigate how best we can detect changes of the selection of cells.
All right.
I wonder whether the cell editor window shouldn't be able to set the contents to a cell that isn't the connected cell . . .
Um? Why won't we reconnect to the cell to which we want to set the contents?
That will clear the contents of the previously-connected cell on the cell editor window, won't it?
Ah, so, you want to copy the value of a cell to another cell . . .
I don't particularly want to do so. I just thought that there might be such necessity, in general.
OK. We will implement that feature. Maybe, our cell editor should be able to set the selected text on the cell editor window to the current cell on the spread sheet. If nothing is selected on the cell editor window, the whole text will be set to the current cell on the spread sheet.
At this stage, the outward appearance of our cell editor is this.
-Hypothesizer shows an image of the cell editor on the computer screen.
. . . It seems difficult to identify which button is of which function . . .
I know. I don't particularly boast that the appearance is slick. Usually, buttons have icons, but I didn't take time to draw appropriate icons. . . . Well, maybe, we would put icons on those buttons, in future.
There is a button whose caption is 'Go to ...' . . .. Go to where? Where would I be taken to, if I dare to push such an enigmatic button? And there is another button of the same caption beneath it . . .
Ah, I brutally cut short long explanations of buttons. It's a temporary measure before we put on icons. . . . Anyway, hover the mouse cursor over the buttons, and see the tool tips.
Well, then, I will have to wait until I see the real window.
The same with the previous scene.
As for the implementation, there is nothing to say in respect to UNO: how to read from and write to spread sheet cells are already dealt with; the rest is about just Java, especially Swing, programming. As for some observations we had in the implementation process, we would note them in the series, 'Java Tips'.
All right.
Our program is here. That is the project we used in the preceding article. How to use the zip file is written there.
You have replaced the dummy window in the preceding article with the one you have created in this article.
Let's build the projects, and test the cell editor.
-Hypothesizer runs the gradle command, which finishes successfully. -Hypothesizer opens the 'TestSpreadSheetsDocumentForExecutingTests.ods' spread sheets document file. -Hypothesizer clicks the 'Show Test Control Panel' button; a tiny dialog box shows adjacent to the left border of the current LibreOffice frame. -Hypothesizer clicks the 'Edit Cell' button; a cell editor window opens.
Well, it showed.
Of course . . .
-Rebutter does some operations on the cell editor window.
Hmm . . .
What?
When the cell editor window is connected to a date type cell and I edit and save the contents of a legal date, it is saved as a date.
Yes. That is my intention.
But when I edit and save the contents of an illegal date, for example '2017-13-01', it is saved as a string.
Ah, as we can't convert the text to a date, it is inevitable.
Warning may be kinder than brutally changing it to a string cell.
Well, it may.
And when I save a number text, for example '123', to an empty cell, it is saved as a string value.
Well, it is. Any empty cell is treated as a string cell . . .
Hmm, as I have intended our cell editor basically for editing long texts, wanting to save contents as date cells, number cells, etc, wasn't in my expectations, much. Certainly, our cell editor can edit cells that have already date values, etc, with the cell types preserved, but making an empty cell, say a number cell wasn't in my scope. . . . Well, we will improve the cell editor in that respect in future.
This is just a first version; we can improve it gradually.
By the way, what is this button that has the tool tip of 'Save Compressed'?
That is a button that will save the contents text to the cell with the contents compressed. You know, when a cell has a very long text, LibreOffice program instance can slow down, greatly.
The button is disabled. Whey will it be enabled?
In future. It isn't implemented yet.
<The previous article in this series | The table of contents of this series | The next article in this series>