public void closeDB() { cliDB.closeScript(); log.dbg(2, "processOneFile", "storing in DB"); cliDB.runSQL(cached.dbName); log.dbg(2, "processOneFile", "finished"); cliDB = null; }
public TextFile openDBforFile(String dbName, String fileName, String tablePrefix) { perFile = new perFileStruc(); cliDB = new sqlSolver(); initialScript(dbName, tablePrefix); if (checkMisprog(cliDB == null, "cliDB")) return null; if (checkMisprog(cached == null, "cached")) return null; cliDB.openScript(); out( "INSERT INTO " + cached.tabPrefix + "_files VALUES (" + cached.fileID + ", '" + cliDB.escapeString(DateFormat.getTodayStr()) + "', '" + fileName + "');"); log.dbg(2, "processOneFile", "start parsing [" + fileName + "]"); TextFile tf = new TextFile(); if (!tf.fopen(fileName, "rb")) // mode "rb" to be able to get the InputStream! { log.err("processOneFile", "file to parse [" + fileName + "] cannot be openned!"); return null; } return tf; }
/** * Calculates the minimum size dimensions for the specified panel given the components in the * specified parent container. * * @param parent the component to be laid out */ public Dimensio minimumLayoutSize(int posX0, int posY0, int posX1, int posY1) { Dimensio di = getLayoutSize(posX0, posY0, posX1, posY1, false); log.dbg( 2, "minimumLayoutSize", lay.getName() + " minimumLayoutSize (" + di.width + ", " + di.height + ")"); return di; }
private LayoutParams theComponent(String cellName) { if (cellName.length() == 0 || cellName.equals(EXPAND_HORIZONTAL) || cellName.equals(EXPAND_VERTICAL)) return null; EvaLayout.LayoutParams lp; for (int ii = 0; ii < getChildCount(); ii++) { lp = (EvaLayout.LayoutParams) getChildAt(ii).getLayoutParams(); if (lp.name.equals(cellName)) return lp; } log.severe( "theComponent", "Component " + cellName + " not found in the container laying out " + lay.getName() + "!"); return null; }
/** * Calculates the preferred size dimensions for the specified panel given the components in the * specified parent container. * * @param parent the component to be laid out */ public Dimensio preferredLayoutSize(int posX0, int posY0, int posX1, int posY1) { /// *EXPERIMENT!!!*/invalidatePreCalc (); Dimensio di = getLayoutSize(posX0, posY0, posX1, posY1, true); log.dbg( 2, "preferredLayoutSize", lay.getName() + " preferredLayoutSize (" + di.width + ", " + di.height + ")"); // (o) TODO_javaj_layingOut Problem: preferredLayoutSize // 19.04.2009 19:50 Problem: preferredLayoutSize is called when pack and after that no more // layouts data dependent like slider (don't know if horizontal or vertical) // have problems // Note: this is not just a problem of EvaLayout but of all layout managers // log.severe ("SEVERINIO!"); return di; }
public boolean checkMisprog(boolean sayAgain, String varName) { if (sayAgain) log.severe("out", varName + " is null during operation, is xmelonSchema misprogrammed?"); return sayAgain; }
public void clearCache() { cached = new cacheableStruct(); log.dbg(2, "clearCache", "cache cleared"); }
/** * NOTE: Only call this function if a record is going to be stored * * <p>When calling this function with the current path WE KNOW that there is data to be stored * using this pathID, therefore we set HASDATA = 1 for this path */ public long getPathTypeIdentifier() { if (checkMisprog(perFile == null, "perFile")) return -1; if (checkMisprog(cached == null, "cached")) return -1; // form path and search for its index // int currentPathIndx = perFile.currentPath.rows() - 1; String pathStr = ""; String lastNode = perFile.currentPath.getValue(currentPathIndx, cNODE); for (int ii = 0; ii <= currentPathIndx; ii++) { pathStr += "/" + perFile.currentPath.getValue(ii, cNODE); } long indx = cached.patIDList.indexOf(pathStr); log.dbg( 2, "getPathTypeIdentifier pathStr [" + pathStr + "] currentPathIndx = " + currentPathIndx + " index = " + indx); // SET has data flag if (currentPathIndx >= 0) { perFile.currentPath.setValue("1", currentPathIndx, cHASDATA); } if (indx == -1) { cached.patIDList.add(pathStr); indx = cached.patIDList.size() - 1; // (o) TOSEE_XMeLon is this record convenient ? 14.02.2010 02:46 if (indx == 0) { // first one, insert path root (one per file) out("INSERT OR IGNORE INTO " + cached.tabPrefix + "_pathDef VALUES (0, 0, '', '', '', 0);"); } long parentIndx = getPathParentIndex(pathStr); log.dbg(2, "getPathTypeIdentifier a insert con parentIndx = " + parentIndx); out( "INSERT INTO " + cached.tabPrefix + "_pathDef VALUES (" + (MIN_PAT_ID + indx) + ", " + (parentIndx != -1 ? (MIN_PAT_ID + parentIndx) : 0) + ", '" + utilEscapeStr.escapeStr(pathStr) + "', '" + utilEscapeStr.escapeStr(naming.toVariableName(pathStr)) + "', '" + utilEscapeStr.escapeStr(lastNode) + "', " + perFile.currentPath.rows() + ");"); } return MIN_PAT_ID + indx; }
protected void initialScript(String dbName, String prefix) { if (checkMisprog(cliDB == null, "cliDB")) return; if (checkMisprog(cached == null, "cached")) return; // (o) listix_sql_schemas XMELON schema creation if (cached.dbName == null || !cached.dbName.equals(dbName) || cached.tabPrefix == null || !cached.tabPrefix.equals(prefix)) { cached.tabPrefix = prefix; cached.dbName = dbName; log.dbg( 2, "initialScript", "ensure tables creation for prefix " + cached.tabPrefix + " in database " + cached.dbName); cliDB.openScript(); // // table: xmelon_files (fileID, timeParse, fullPath) // table: xmelon_tagDef (tagID, tagStr, tagStrNormal) // table: xmelon_pathDef (patID, parentPatID, pathStr, pathStrNormal, lastNode, level) // table: xmelon_data (fileID, dataCnt, patCnt, parentPatCnt, patID, tagID, dataPlace, // value) // String tTAG = cached.tabPrefix + "_tagDef"; String tPATH = cached.tabPrefix + "_pathDef"; String tFILE = cached.tabPrefix + "_files"; String tDATA = cached.tabPrefix + "_data"; String tLOG = cached.tabPrefix + "_log"; cliDB.writeScript( "CREATE TABLE IF NOT EXISTS " + tTAG + " (tagID int, tagStr text, tagStrNormal text, UNIQUE(tagID));"); cliDB.writeScript( "CREATE TABLE IF NOT EXISTS " + tPATH + " (patID int, parentPatID int, pathStr text, pathStrNormal text, lastNode text, level int, UNIQUE(patID));"); cliDB.writeScript( "CREATE TABLE IF NOT EXISTS " + tFILE + " (fileID int, timeParse text, fullPath text, UNIQUE(fileID));"); cliDB.writeScript( "CREATE TABLE IF NOT EXISTS " + tDATA + " (fileID int, dataCnt int, patCnt int, parentPatCnt int, patID int, tagID int, dataPlace text, value text, UNIQUE(fileID, dataCnt));"); cliDB.writeScript( "CREATE INDEX IF NOT EXISTS " + tDATA + "_indx1 ON " + tDATA + " (fileID, patCnt);"); cliDB.writeScript( "CREATE INDEX IF NOT EXISTS " + tDATA + "_indx2 ON " + tDATA + " (fileID, parentPatCnt);"); cliDB.writeScript( "CREATE INDEX IF NOT EXISTS " + tDATA + "_indx3 ON " + tDATA + " (patID, tagID);"); // relevant for <SQL calc_PathTag> in util.lsx cliDB.writeScript( "CREATE INDEX IF NOT EXISTS " + tDATA + "_indx4 ON " + tDATA + " (fileID, patID, patCnt);"); cliDB.writeScript("CREATE TABLE IF NOT EXISTS " + tLOG + " (fileID int, logMessage text);"); // o-o Add dbMore connections info // // connexiones directas // // conn, srcTab, srcKey, targTab, targKey // // file , xmelon_data, fileID, xmelon_files, fileID // path , xmelon_data, patID, xmelon_pathDef, patID // tag , xmelon_data, tagID, xmelon_tagDef, tagID // parent, xmelon_data, parentPatCnt, xmelon_data, patCnt // cliDB.writeScript(deepSqlUtil.getSQL_CreateTableConnections()); cliDB.writeScript( deepSqlUtil.getSQL_InsertConnection("parentPath", tPATH, "parentPatID", tPATH, "patID")); cliDB.writeScript( deepSqlUtil.getSQL_InsertConnection("file", tDATA, "fileID", tFILE, "fileID")); cliDB.writeScript( deepSqlUtil.getSQL_InsertConnection("path", tDATA, "patID", tPATH, "patID")); cliDB.writeScript(deepSqlUtil.getSQL_InsertConnection("tag", tDATA, "tagID", tTAG, "tagID")); // NO! es N->N ! // cliDB.writeScript (deepSqlUtil.getSQL_InsertConnection("parent" , tDATA, "parentPatCnt", // tDATA, "patCnt")); cliDB.closeScript(); cliDB.runSQL(cached.dbName); // reset patIDList cache cached.patIDList = null; cached.tagIDList = null; // get last fileID cached.fileID = sqlUtil.getNextID(cached.dbName, cached.tabPrefix + "_files", "fileID", MIN_FILE_ID); } else cached.fileID++; if (cached.patIDList != null) return; // ok, need the list if given // get the list id path ID's // cached.patIDList = cliDB.getSQL( dbName, ".headers off\nSELECT pathStr FROM " + cached.tabPrefix + "_pathDef ORDER BY patID;"); log.dbg( 2, "initialScript", "obtained pathDef list of " + cached.patIDList.size() + " elements"); // get the list id tag ID's // cached.tagIDList = cliDB.getSQL( dbName, ".headers off\nSELECT tagStr FROM " + cached.tabPrefix + "_tagDef ORDER BY tagID;"); log.dbg(2, "initialScript", "obtained tagDef list of " + cached.tagIDList.size() + " elements"); }
/** * Lays out the container in the specified container. * * @param parent the component which needs to be laid out */ public void layoutContainer(int posX0, int posY0, int posX1, int posY1) { // isPrecalculated = false; if (log.isDebugging(4)) log.dbg(4, "layoutContainer", lay.getName()); precalculateAll(); // synchronized (parent.getTreeLock()) { // if (log.isDebugging(4)) // log.dbg (4, "layoutContainer", "insets left right =" + insets.left + ", " + insets.right // + " top bottom " + insets.top + ", " + insets.bottom); // Total parent dimensions int parDx = posX1 - posX0; int parDy = posY1 - posY0; if (log.isDebugging(4)) log.dbg(4, "layoutContainer", "parent size =" + parDx + ", " + parDy); int repartH = parDx - fijoH; int repartV = parDy - fijoV; int[] HextraPos = new int[HdimPref.length]; int[] VextraPos = new int[VdimPref.length]; if (log.isDebugging(4)) log.dbg(4, "layoutContainer", "repartH=" + repartH + " repartV=" + repartV); // repartir H if (columnsReparto.size() > 0) { repartH /= columnsReparto.size(); for (int ii = 0; ii < columnsReparto.size(); ii++) { int indx = ((int[]) columnsReparto.get(ii))[0]; HdimPref[indx] = repartH; for (int res = indx + 1; res < nColumns(); res++) HextraPos[res] += repartH; } } // repartir V if (rowsReparto.size() > 0) { repartV /= rowsReparto.size(); for (int ii = 0; ii < rowsReparto.size(); ii++) { int indx = ((int[]) rowsReparto.get(ii))[0]; VdimPref[indx] = repartV; for (int res = indx + 1; res < nRows(); res++) VextraPos[res] += repartV; } } for (int co = 0; co < getChildCount(); co++) { View vi = getChildAt(co); LayoutParams lp = (EvaLayout.LayoutParams) vi.getLayoutParams(); if (log.isDebugging(4)) log.dbg(4, "layoutContainer", "element [" + lp.name + "]"); // System.out.println ("componente " + lp.name); if (!lp.isLaidOut) continue; // System.out.println (" indices " + lp.posCol0 + " (" + Hpos[lp.posCol0] + " extras " + // HextraPos[lp.posCol0] + ")"); int x = Hpos[lp.posCol0] + HextraPos[lp.posCol0]; int y = Vpos[lp.posRow0] + VextraPos[lp.posRow0]; int dx = 0; int dy = 0; // if (log.isDebugging(4)) // log.dbg (4, "SIGUEY", "1) y = " + y + " Vpos[lp.posRow0] = " + Vpos[lp.posRow0] + " // VextraPos[lp.posRow0] = " + VextraPos[lp.posRow0]); for (int mm = lp.posCol0; mm <= lp.posCol1; mm++) { if (mm != lp.posCol0) dx += Hgap; dx += HdimPref[mm]; } for (int mm = lp.posRow0; mm <= lp.posRow1; mm++) { if (mm != lp.posRow0) dy += Vgap; dy += VdimPref[mm]; } if (x < 0 || y < 0 || dx < 0 || dy < 0) { // Disable this warning because it happens very often when minimizing the window etc // log.warn ("layoutContainer", "component not laid out! [" + lp.name + "] (" + x + ", " + // y + ") (" + dx + ", " + dy + ")"); continue; } // vi.setWidth (dx); // vi.setHeight (dy); setMeasuredDimension(dx, dy); vi.layout(x, y, x + dx, y + dy); if (log.isDebugging(4)) log.dbg( 4, "layoutContainer", "vi.name [" + lp.name + "] (" + x + ", " + y + ") (" + dx + ", " + dy + ")"); } } // end synchronized }
/** calculating layout size (minimum or preferred). */ protected Dimensio getLayoutSize( int posX0, int posY0, int posX1, int posY1, boolean isPreferred) { log.dbg(2, "getLayoutSize", lay.getName()); precalculateAll(); // In precalculateAll the methods minWidthOfColumn and minHeightOfRow // does not evaluate expandable components since these might use other columns. // But in order to calculate the minimum or preferred total size we need this information. // In these cases we have to calculate following : if the sum of the sizes of the // columns that the component occupies is less that the minimum/preferred size of // the component then we add the difference to the total width // We evaluate this ONLY for those components that could be expanded! // for example // // NO COMPONENT HAS TO COMPONENTS comp1 and comp3 // BE RECALCULED HAS TO BE RECALCULED // --------------------- ------------------------ // grid, 160 , A grid, 160 , X // A , comp1 , - A , comp1 , - // A , comp2 , comp3 X , comp2 , comp3 // int[] extraCol = new int[nColumns()]; int[] extraRow = new int[nRows()]; int[] Hdim = isPreferred ? HdimPref : HdimMin; int[] Vdim = isPreferred ? VdimPref : VdimMin; // System.err.println ("PARLANT DE " + lay.getName () + " !!!"); // for all components ... for (int ii = 0; ii < getChildCount(); ii++) { View vi = getChildAt(ii); LayoutParams lp = (EvaLayout.LayoutParams) vi.getLayoutParams(); boolean someExpan = false; if (!lp.isLaidOut) continue; // log.dbg (2, "getLayoutSize", lp.name + " mea (" + vi.getMeasuredWidth() + ", " + // vi.getMeasuredHeight() + ")"); // log.dbg (2, "getLayoutSize", lp.name + " haz (" + vi.getWidth() + ", " + // vi.getHeight() + ")"); // // int csizWidth = (isPreferred) ? vi.getMeasuredWidth(): vi.getWidth(); // int csizHeight = (isPreferred) ? vi.getMeasuredHeight(): vi.getHeight(); int csizWidth = (vi instanceof izWidget) ? ((izWidget) vi).getDefaultWidth() : 300; int csizHeight = (vi instanceof izWidget) ? ((izWidget) vi).getDefaultHeight() : 400; log.dbg(2, "getLayoutSize", lp.name + " dim (" + csizWidth + ", " + csizHeight + ")"); // some column expandable ? // someExpan = false; for (int cc = lp.posCol0; cc <= lp.posCol1; cc++) if (headType(columnHeader(cc)) == HEADER_EXPAND) { someExpan = true; break; } if (someExpan) { // sum of all columns that this component occupy int sum = 0; for (int cc = lp.posCol0; cc <= lp.posCol1; cc++) sum += (Hdim[cc] + extraCol[cc]); // distribute it in all columns to be salomonic int resto = csizWidth - sum; if (resto > 0) { if (lp.posCol0 == lp.posCol1) { // System.err.println ("Resto X " + resto + " de " + lp.name + " en la " + lp.posCol0 + // " veniendo de csiz.width " + csiz.width + " y sum " + sum + " que repahartimos en " + // (1 + lp.posCol1 - lp.posCol0) + " parates tenahamos una estra de " + // extraCol[lp.posCol0]); } for (int cc = lp.posCol0; cc <= lp.posCol1; cc++) extraCol[cc] = resto / (1 + lp.posCol1 - lp.posCol0); } } // some row expandable ? // someExpan = false; for (int rr = lp.posRow0; rr <= lp.posRow1; rr++) if (headType(rowHeader(rr)) == HEADER_EXPAND) { someExpan = true; break; } if (someExpan) { // sum of all height (rows) that this component occupy int sum = 0; for (int rr = lp.posRow0; rr <= lp.posRow1; rr++) sum += (Vdim[rr] + extraRow[rr]); // distribute it in all columns to be salomonic int resto = csizHeight - sum; if (resto > 0) { for (int rr = lp.posRow0; rr <= lp.posRow1; rr++) extraRow[rr] = resto / (1 + lp.posRow1 - lp.posRow0); } } } int tot_width = 0; for (int cc = 0; cc < nColumns(); cc++) { tot_width += (Hdim[cc] + extraCol[cc]); } int tot_height = 0; for (int rr = 0; rr < nRows(); rr++) { tot_height += Vdim[rr] + extraRow[rr]; } // Insets insets = (parent != null) ? parent.getInsets(): new Insets(0,0,0,0); tot_width += Hgap * (nColumns() - 1) + 2 * Hmargin; tot_height += Vgap * (nRows() - 1) + 2 * Vmargin; log.dbg(2, "getLayoutSize", "returning tot_width " + tot_width + ", tot_height " + tot_height); // System.out.println ("getLayoutSize pref=" + isPreferred + " nos sale (" + tot_width + ", " + // tot_height + ")"); return new Dimensio(tot_width > 0 ? tot_width : 100, tot_height > 0 ? tot_height : 100); }
private void precalculateAll() { if (isPrecalculated) return; if (!checkLayoutInfo()) { log.err("checkLayoutInfo", "layout [" + lay.getName() + "] is not of type EVA"); // do not return! some variables has to be initialized anyway } log.dbg(2, "precalculateAll", "layout " + lay.getName() + " perform precalculation."); Hmargin = Math.max(0, stdlib.atoi(lay.getValue(0, 1))); Vmargin = Math.max(0, stdlib.atoi(lay.getValue(0, 2))); Hgap = Math.max(0, stdlib.atoi(lay.getValue(0, 3))); Vgap = Math.max(0, stdlib.atoi(lay.getValue(0, 4))); log.dbg(4, "precalculateAll", nColumns() + " columns x " + nRows() + " rows"); log.dbg( 4, "precalculateAll", "margins xm=" + Hmargin + ", ym=" + Vmargin + ", yg=" + Hgap + ", yg=" + Vgap); mnCols = -1; // reset cached number of cols mnRows = -1; // reset cached number of rows HdimMin = new int[nColumns()]; HdimPref = new int[nColumns()]; Hpos = new int[nColumns()]; VdimMin = new int[nRows()]; VdimPref = new int[nRows()]; Vpos = new int[nRows()]; columnsReparto = new Vector(); rowsReparto = new Vector(); // for all components ... int count = getChildCount(); for (int i = 0; i < count; i++) { View child = getChildAt(i); // if (child.getVisibility() != GONE) EvaLayout.LayoutParams lp = (EvaLayout.LayoutParams) child.getLayoutParams(); lp.isLaidOut = false; } // compute Vdim (Note: it might be precalculated if needed) fijoV = Vmargin; for (int rr = 0; rr < nRows(); rr++) { String heaRow = rowHeader(rr); int typ = headType(heaRow); int gap = (rr == 0) ? 0 : Vgap; if (typ == HEADER_ORIGINAL) { // maximum-minimum of the row VdimPref[rr] = minHeightOfRow(rr, true); VdimMin[rr] = minHeightOfRow(rr, false); log.dbg(2, "precalculateAll", "Adaption... VdimPref[rr] = " + VdimPref[rr]); } else if (typ == HEADER_EXPAND) { rowsReparto.add(new int[] {rr}); // compute later log.dbg(2, "precalculateAll", "Expand... VdimPref[rr] = " + VdimPref[rr]); } else { // indicated size VdimPref[rr] = VdimMin[rr] = stdlib.atoi(heaRow); log.dbg(2, "precalculateAll", "Explicit... VdimPref[rr] = " + VdimPref[rr]); } Vpos[rr] = fijoV + gap; fijoV += VdimPref[rr]; fijoV += gap; } fijoV += Vmargin; log.dbg(2, "precalculateAll", "fijoV = " + fijoV + " Vmargin = " + Vmargin + " Vgap = " + Vgap); // DEBUG .... if (log.isDebugging(2)) { String vertical = "Vertical array (posY/prefHeight/minHeight)"; for (int rr = 0; rr < Vpos.length; rr++) vertical += " " + rr + ") " + Vpos[rr] + "/" + VdimPref[rr] + "/" + VdimMin[rr]; log.dbg(2, "precalculateAll", vertical); } // compute Hdim (Note: it might be precalculated if needed) fijoH = Hmargin; for (int cc = 0; cc < nColumns(); cc++) { String heaCol = columnHeader(cc); int typ = headType(heaCol); int gap = (cc == 0) ? 0 : Hgap; if (typ == HEADER_ORIGINAL) { // maximum-minimum of the column HdimPref[cc] = minWidthOfColumn(cc, true); HdimMin[cc] = minWidthOfColumn(cc, false); } else if (typ == HEADER_EXPAND) columnsReparto.add(new int[] {cc}); // compute later else HdimPref[cc] = HdimMin[cc] = stdlib.atoi(heaCol); // indicated size Hpos[cc] = fijoH + gap; fijoH += HdimPref[cc]; fijoH += gap; } fijoH += Hmargin; log.dbg(2, "precalculateAll", "fijoH = " + fijoH); // DEBUG .... if (log.isDebugging(2)) { String horizontal = "Horizontal array (posX/prefWidth/minWidth)"; for (int cc = 0; cc < Hpos.length; cc++) horizontal += " " + cc + ") " + Hpos[cc] + "/" + HdimPref[cc] + "/" + HdimMin[cc]; log.dbg(2, "precalculateAll", horizontal); } // finding all components in the layout array for (int cc = 0; cc < nColumns(); cc++) { for (int rr = 0; rr < nRows(); rr++) { String name = widgetAt(rr, cc); LayoutParams wid = theComponent(name); if (wid == null) continue; // set position x,y wid.posCol0 = cc; wid.posRow0 = rr; // set position x2,y2 int ava = cc; while (ava + 1 < nColumns() && widgetAt(rr, ava + 1).equals(EXPAND_HORIZONTAL)) ava++; wid.posCol1 = ava; ava = rr; while (ava + 1 < nRows() && widgetAt(ava + 1, cc).equals(EXPAND_VERTICAL)) ava++; wid.posRow1 = ava; wid.isLaidOut = true; // DEBUG .... if (log.isDebugging(2)) { log.dbg( 2, "precalculateAll", wid.name + " leftTop (" + wid.posCol0 + ", " + wid.posRow0 + ") rightBottom (" + wid.posCol1 + ", " + wid.posRow1 + ")"); } } } isPrecalculated = true; }
/** * Switches to another layout : note that the components used in this new layout has to exists * (added to the layout using add method) */ public void switchLayout(Eva layarray) { log.dbg(2, "switchLayout", "switch new layout info " + layarray.getName()); lay = layarray; invalidatePreCalc(); }