Automatically read a file - easy - graph

This should be a really easy question, but I just cant seem to get it done, I have a section of code calculating X Y points on a graph, then saving them to file.
If a certain condition is met I want to plot the values on a graph, I am using this code to plot the graph- http://www.kodejava.org/examples/805.html
But I don't want it to ask for the user to point to the file location, I just want it to open a file which has a directory hard coded in, and plot it automatically. So basically remove the buttons at the top and carry out the commands of the buttons automatically.
Would be fantastic if somebody could point me in the right direction, I'm a physicist not a coding expert so as much help as possible would be excellent.
Hope I can help one of you in return sometime.

1) Inside public static void main, just above frame.setVisible(true); insert openButton.setVisible(false);
2) Inside class GraphPanel, inside the method public void actionPerformed(ActionEvent e) insert datapanel.actionPerformed(e); as the first line.
3) Inside class DataPanel inside public void actionPerformed comment out from the beginning JFrame fileFrame = new JFrame(); to initialized = readFile(datafile);
4) Just after the comment, insert initialized = readFile(new File("path_to_data_file"));
Now if you open, and press plot, the hard coded file will be read and plot will be drawn.
Heck,, I don't care if this gets downvoted :). I've never touched Java. After reading your problem, specially I'm a physicist not a coding expert first i searched in google how to compile and run a java file. Then started reading the java program. I even made another version which does not need the button press also, Just open and your graph will be drawn. But that's only if needed, then provided. "Welcome to my java attempt" :)
Update:
For doing without pressing plot, in GraphPanel and DataPanel, and rename the actionPerformed methods to something else like GraphPanel::start_working and DataPanel::start_working Now inside GraphPanel::start_working call DataPanel::start_working instead of earlier datapanel.actionPerformed(e); . If compiler cribs, add some empty actionPerformed for compilation. (perhaps we can remove the implements ) Now your flow is ready without any user action. you just need to start it. So you set plotButton.setVisible(false); to hide the plot button and call graphpanel.start_work(); to start the flow in main.
Update:
Inside GraphPanel
public void start_working() {
datapanel.start_working()
if (!datapanel.isInitialized()) {
return;
}
datapanel.refreshData();
panel.setDisplayPlot(true);
panel.update(panel.getGraphics());
frame.setSize(700, 600);
frame.setVisible(true);
frame.pack();
}
And inside DataPanel
public void start_working(ActionEvent e) {
initialized = readFile(new File("PATH_TO_FILE");
panel.update(panel.getGraphics());
frame.pack();
frame.setVisible(true);
}
in main last 5 lines
openButton.setVisible(false);
plotButton.setVisible(false);
graphpanel.start_working();
frame.setVisible(true);
frame.pack();

Related

Block FormRun task from executing in DetailsTransaction pattern

I am building a simple journal form based on the form pattern DetailsTransaction. In this pattern it has the standard two view layout, the header/*journalTable grid and a lines/*journalTrans grid.
However, when I click the New button two create a new header/journal, it automatically invokes the taskSwitchToDetailsView task and switches to the lines. I wish to block this from happening, but I am unsure on how to do it. Is there a way to block this task from being invoked?
Have you experimented with the viewEditModeHelper() and other form event handlers?
I don't have an environment in front of me now, but here's a little snip that might give you an idea where to look. I know it's not exactly what you're looking for but the same style is what I would think.
[FormEventHandler(formStr(LogisticsPostalAddress), FormEventType::Initialized)]
public static void MyForm_OnInitialized(xFormRun sender, FormEventArgs e)
{
// Subscribe event handlers
FormRun formRun = sender as FormRun;
formRun.viewEditModeHelper().EditModeSwitched += eventhandler(MyEventHandler.ViewEditModeSwitched);
}
There is a lot of complexity around the OOTB journals, and if I needed a robust journal implementation I would have created classes that derived from JournalFormController and JournalFormTable/JournalFormTrans which provide number sequence generation, blocking/locking, validation, and much more very useful and powerful functionality to a journal form + table structure.
However, I don't need any of that. So to solve my specific problem I added this to the create method of the *journalTable datasource's create method (which the super call changes the context of the form to the lines by calling task(#taskSwitchToDetailsView). To counter this, I simply call task(#taskSwitchToGridView) immediately after the super.
[DataSource]
class CustomJournalTable
{
public void create(boolean _append = false)
{
#Task
super(_append);
element.task(#taskSwitchToGridView);
}
}

Unity - GameObject.Find() works only on server

I am making a simple networking game. The scene has a button named 'ReloadButton' and i am trying to find this button and add a listener to it through my script attached on the player.
private Button reloadBtn;
void Start()
{
GameObject tempGO = GameObject.Find("ReloadButton");
if (tempGO != null)
{
reloadBtn = tempGO.GetComponent<Button>();
reloadBtn.onClick.AddListener(weaponManager.Reload);
}
}
I am doing it this way because direct referencing of 'ReloadButton' to the script through public Buttonvariable is not possible.
The code works fine on the server, the listener is also added correctly. but on the client, the GameObject.Find("ReloadButton") throws a NullReferenceException.
Seems like the client cannot find the Button itself.
I cannot proceed further in my project without solving this problem, I hope some of you can point me towards the problem.

Reading input inside assign activity in workflow4.0

I am new to Workflow. I am creating a guessing game using sequence and flowchart. Inside the sequennce I have a Flowchart Activity.I invoked the flowchart activity inside the .completed event of sequence activity. But this code giving me unpredictable outputs,means after entering the input it is again showing me the new console line in prompt, if i enter any button it leading to exit. So next flowchart activity is not invoked at all. I found that where i used assign activity with console.readline() at that stage mainly giving me the unintended results. I am new to WF , I don't know main functionality and properties of Assign Activity. Some one please give me the clarity, thanks in Advance.
Sequence activity contains only Welcome writeline and assign activity for asking name and then other write line that's it.
In flowchart there are no. of flow decisions and writelines.Sometimes it is going to flowchart but in flowchart activity also where i have the assign activity with console line , fishy is happening there.
Here my code
class Program
{
static void Main(string[] args)
{
var a = new WorkflowApplication(new Workflow1());
a.Completed = e =>
{
WorkflowInvoker.Invoke(new Flowchart(){guess=new System.Random().Next(1,100) });
};
a.Run();
Console.ReadLine();
}
}
}

how to save image onSaveInstanceState when rotate screen ?

I'm downloading an image to image view by AsyncTask and I want to save my image when I'm rotate my phone and not to download again to image view...
public void onSaveInstanceState(Bundle toSave) {
super.onSaveInstanceState(toSave);
my_image.buildDrawingCache();
Parcelable bm = my_image.getDrawingCache();
toSave.putParcelable("savedImage", bm);
}
i'm trying to understand if I'm doing something wrong with onSaveInstanceState or not, and how do I retrieve this state onRestoreInstanceState and place the image without downloading again ...
onSaveInstanceState() function has to be used for saving small objects, not for heavy objects.
If you want to save heavy images on phone rotation, then use any of below techniques:
If you want to save large objects use onRetainNonConfigurationInstance() function.
Or else we can make that image as static, so that the image will be loaded only once.
Meaning: On downloading an image from network, make it pointed by a static variable.
If user rotates the phone, since android kills that activity and recreates it, just
put a if condition check if that static variable is not null, then only download again.
As you know static variables will be created only once, it will not download again.
But preferably go for 1st option.
Ref : developer android official tutorial
First of all super.onSaveInstanceState(toSave) should be at the last place in method onSaveInstanceState(Bundle toSave).
In onCreate(Bundle savedInstanceState) check, if savedInstanceState is not null and get what you want:
#Override
protected void onCreate(Bundle savedInstanceState) {
...
if(savedInstanceState != null){
...
...savedInstanceState.getParcerable(...);
...
}
}
Don't use static variables to hold onto bitmaps.

Flex 4 Desktop App TooltipManager

I have a flex app that used to be an internet based app. In it I have a function that creates tooltip error messages when I tell it to create an error message. I pulled this app out verbatim to a desktop app and restructured things a bit to get it to run, but I did not mess with the core fundamentals of the mxml file that utilizes this aside from changing the root tag from a type of 's:Group' to 's:Window'
Everything runs correctly, but the tooltips are not displaying. I can't seem to figure out why, so I thought I'd run this by you guys. Here's the tooltip code (inline mxml code in the fx:script cdata tag):
import mx.controls.ToolTip;
import mx.managers.ToolTipManager;
public var errorTip:ToolTip;
private function createErrorMsg(errorMsg:String, object:Object):void {
if (errorTip){ToolTipManager.destroyToolTip(errorTip);};
errorTip = ToolTipManager.createToolTip(errorMsg,object.getBounds(root).x + object.width,object.getBounds(root).y) as ToolTip;
errorTip.setStyle("styleName", "errorTip");
errorTip.visible = true;
errorTip.enabled = true;
}
Basically, I pass the function a string and an object (text input, checkbox, button, etc...etc...) and it positions it and displays the error message. This fully works in my web version, but not in my desktop version.
Here's the code that instantiates the window:
var window:LoginWindow = new LoginWindow();
Window.systemChrome = NativeWindowSystemChrome.NONE;
Window.transparent = true;
Window.open(true);
Window.maximize()
Any ideas?
On a side note, I check to see if the errorTip exists at the beginning of the function and then destroy it so that the higher scoped variable 'errorTip' always equals the reference to the currently displayed error. This allows me to just destroy that error tip on form validation and then error check again, but it only allows one tooltip to be displayed at a time. Is there a better way to query the tooltip manager for all of it's currently displayed tooltips and destroy them all?
To resolve this you must change the line that calls 'createTooltip' to the following:
errorTip = ToolTipManager.createToolTip(errorMsg,object.getBounds(root).x + object.width,object.getBounds(root).y, null, object as IUIComponent) as ToolTip;
The idea behind this is that you can now just call 'createErrorMsg("myError",myComponent)' and it'll display an error message there, which you can then add another function:
private function clearError():void
{
if(errorTip) errorTip.visible = false;
}
to actually remove the error message. The down side of this is that it only displays one message at a time but I'll tweak it a bit to change that up. So here's my better resolution:
Error messages will (traditionally) only be displayed in a batch set. (Basically you will only have a handful of tooltips displayed at one point in time and they will all be related to the form you are on). This won't always be true, but that's not my concern here. I created a utility class that performs error message handling:
package Utils
{
import mx.controls.ToolTip;
import mx.core.IUIComponent;
import mx.managers.ToolTipManager;
public class ErrorUtils
{
private static var errorCache:Array = new Array();
public function ErrorUtils()
{
}
public static function createErrorMsg(errorMsg:String, object:Object):void {
var errorTip:ToolTip = ToolTipManager.createToolTip(errorMsg,object.getBounds(object.root).x + object.width,object.getBounds(object.root).y, null, object as IUIComponent) as ToolTip
errorTip.setStyle("styleName", "errorTip");
errorTip.visible = true;
errorTip.enabled = true;
var position:int = errorCache.length;
errorCache.push(errorTip);
}
public static function clearAllErrors():void
{
for each(var error:ToolTip in errorCache)
{
ToolTipManager.destroyToolTip(error);
}
}
}
}
To use the class you simply call ErrorUtils.createErrorMsg("my message",invalidComponent), and to clear the errors you simply call ErrorUtils.clearAllErrors()
That way if you have a form and you have a validation function for it, you simply call that function every time it comes back as invalid. The only thing that this is missing is any kind of way to clear a specific error, but to handle that you could place all of the creation calls inside of a master validation function that validates all the fields in your form, then call that each time you gain or loose focus on a field and call 'ErrorUtils.clearAllErrors()' at the beginning of the function.
BTW:
this is the source of the original tutorial I received to do this, I just abstracted it a bit
http://aralbalkan.com/1125
so credits go to the above site for the original code

Resources