I want to display my data in a table using scala GUI. But I need the contents of the table are read only. I know there is class Table(mutable) and ListView (read-only) in scala GUI.
My problem is I do not know how to combine them.
Thanks
See http://www.coderanch.com/t/334323/GUI/java/create-read-JTable which says
a JTable has a model behind, a TableModel. You can either implement this or you extend from the DefaultTableModel. Anyway, there is a function isCellEditable(int row, int col). This function should return false in every case, then your table is not editable, but selectable.
Ta have a good starting point, you should read the Table section of the Java Tutorial of SUN.
The Java tutorial being referred to here is this.
Related
Is there a way to update a chart based on the user input on text field? I'm not familiar with both Swing and JFreeChart but I need to virtualize some data. So far I'm able to display simple graph but only with hardcoded data.
Thank you
Yes, of course that is possible. First of all, I recommend looking at Scala-Chart which is a nice wrapper around JFreeChart.
JFreeChart lets you alter and update any parameter. For example if you have a data-set, you can clear it and add new data, you can readjust the axes, etc. Here is an example from a project I'm working on, where a "series" (JFreeChart speak) is removed from a "dataset", then a new series is calculated and added again:
https://github.com/iem-projects/sysson/blob/70829bf80ad22dfc0b6020e00dd07397b100e401/src/main/scala/at/iem/sysson/gui/impl/PlotChartImpl.scala#L222
In the excellent mvvmcross-library I can use RIO binding to prevent unreadable code:
public INC<String>Title = new NC<String>();
Then I can read and write values using Title.Value. Makes the models much more readable.
Normally, this property would be written as:
private string _title;
public string Title
{
get { return _title; }
set
{
_title = value;
RaisePropertyChanged("Title");
}
}
But when I want to use sqlite-net, these fields cannot be streamed to the database because they are not basic types with a getter and setter.
I can think of a few options how to get around that:
Make a new simple object that is similar to the model, but only with
the direct db-fields. And create a simple import-export static
method on the model. This also could prevent struggling with complex
model-code that never needs to relate to the actual database.
Make sqlite-net understand reading NC-fields. I read into the code of the mapper, but it looks like this is going to be a lot of work because it relies on the getter-setter. I did not find a way to insert custom mapping to a type, that could be generic.
Remove RIO and just put in all the code myself instead of relying on RIO.
Maybe someone has some advice?
Thanks Stuart. It was exactly my thought, so I did implement it that way: my (DB) Models do not contain RIO. Only my viewmodels do, and they reference a Model that is DB-compatible.
So, for posterity the following tips:
- Do not use RIO in your models that need to be database-backed.
- Reference models in your viewmodels. In the binding you can use the . (dot) to reference this model.
This keeps them nicely separated. This gives you also another advantage: if you need to reuse a model (because the same object might be displayed twice on the screen), but under different circumstances, it is much easier to handle this situaties to find this already instantiated model.
I use SharpLua with MonoDevelop. I created a class on C# side, which should be usable from Lua. That's works fine, I can access all fields from Lua. It's very easy.
public class Test {
public string Name;
}
could be access from Lua with
print(test.Name)
Now, I want to create new fields by Lua. In Lua it should look like
test.abc = "A string"
print(test.abc)
But this didn't work. I get an error in the ObjectTranslator. So I couldn't extend the table from Lua. I didn't want to access this new entries from C#. It should only be possible to create them.
Is there an other way to achieve this? Could I create a class from LuaTable and insert this to Lua?
lua["NewLuaTable"] = new ClassFromLuaTable;
and than use in Lua
NewLuaTable.abc = "A string"
print(NewLuaTable.abc);
But than, how did I get notifications, that something I want to know is changed in the LuaTable (NewLuaTable.Name is changed)?
Thank you for your help.
Ok, I found it by myself.
You could extend C# classes from Lua with the functions get_Item() and set_Item(). These both functions are the same as __index and __newindex in Lua metatables. So you could create a Dictionary table in C# and fill it in the set_Item() function. If LuaInterface didn't find an entry in the class, it calls get_Item() to look, if it could get the value on this way. There you could look into your table, if it is a valid key-value-pair.
I have created a class that I've been using as the storage for all listings in my applications. The class allows me to "sign" an object to a listing (which can be created on the fly via the sign() method like so):
manager.sign(myObject, "someList");
This stores the index of the element (using it's unique id) in the newly created or previously created listing "someList" as well as the object in a 2D array. So for example, I might end up with this:
trace(_indexes["someList"][objectId]); // 0 - the object is the first in this list
trace(_instances["someList"]); // [object MyObject]
The class has another two methods:
find(signature:String):Array
This method returns an array via slice() containing all of the elements signed with the given signature.
findFirst(signature:String):Object
This method just returns the first object in a given listing
So to retrieve myObject I can either go:
trace(find("someList")[0]); or trace(findFirst("someList"));
Finally, there is an unsign() function which will remove an object from a given listing. This function basically:
Stores the result of pop() in the specified listing against a variable.
Uses the stored index to quickly replace the specified object with the pop()'d item.
Deletes the stored index for the specified object and updates the index for the pop()'d item.
Through all this, using unsign() will remove an object extremely quickly from a listing of any size.
Now this is all well and good, but I've had some thoughts which are making me consider how good this really is? I mean being able to easily list, remove and access lists of anything I want throughout the application like this is awesome - but is there a catch?
A couple of starting thoughts I have had are:
So far I haven't implemented support for listings that are private and only accessible via a given class.
Memory - this doesn't seem very memory efficient. Then again, neither is creating arrays for everything I want to store individually either. Just seems.. Larger.. Somehow.
Any insights?
I've uploaded the class here in case the above doesn't make much sense: https://projectavian.com/AviManager.as
Your solution seems pretty solid. If you're looking to modify it to be a bit more extensible and handle rights management, you might consider moving all those individually indexed properties to a value object for your AV elements. You could perform operations like "sign" and "unsign" internally in the VOs, or check for access rights. Your management class could monitor the collection of these VOs, pass them around, perform the method calls, and the objects would hold the state in a bit more readable format.
Really, though, this is entering into a coding style discussion. Your method works and it's not particularly inefficient. Just make sure the code is readable, encapsulated, and extensible and you're good.
How can I validate the cells in a DataGridColumn individually? (ActionScript 3.5) The validation is configured per-cell, based on fields in the given row. For example
FIELD VALUE TYPE
age 13 Integer
height 13x3 Integer
registered true Boolean
temperature 98.G6 Float
In this case, of course 13x3 and 98.G6 would be invalid.
It's easy to write a Validator ; and to access the data provider objects.
But how do I get individual access to the GUI cell objects so I can set the errorString on an individual cell, either directly or through a Validator?
The itemRenderer/ TextInput control is re-used across the cells for performance reasons, so accessing the GUI-level objects is tricky.
Edit
Answers:
One way to validate and display the invalidation markings, but not per-cell, is to validate all data-provider objects and then set the errorString on the entire grid.
One way to validate per-cell is on the itemEditEnd event handler. (See these pages A B C D). One disadvantage is that it only allows access to the cells from the "inside", not in an action that validates the grid on command.
A custom itemRenderer is another possibility, as in the answer below, but like 3 above, it only allows access to the cells from the "inside", not in an action that validates the grid on command.
See Richard Haven's answer below.
And here's how to access the GUI objects: The list of relevant GUI objects is a protected field; so you can access it by subclassing, then iterate over the GUI-components which represent the cells and set the errorString on each one.
This website at BigResource asks how to access an individual cell. The third post answers there question and provides a link to a better resource than this. Figured you would want both. Hopefully this helps.
If you are looking for arbitrary validation (e.g. on a button or page navigation) rather than immediate navigation (e.g. on cell exit or end-of-edit), then the data is in the underlying dataProvider. I would do validations there rather than dig around inside the grid.
You can add a flag to the data item so the item renderer displays it as an error (or use an external list to flag it).
Cheers
Are you sure you actually want to access the individual cells' DisplayObjects? The component manages instances so that it only creates as many as it needs to display (so that huge datasets don't require a huge number of DisplayObjects on screen).
I think a better alternative would be to provide your DataGridColumn with a custom itemRenderer. You can write this class to accept a validator and update its appearance, and there are a bunch of great tutorials around about that.