List of usage examples for java.awt Color getGreen
public int getGreen()
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param color The color to lighten/*from w w w. j ava2s . co m*/ * @param percentage to be added to the current value 0.0 > val < 1.0 * @return */ public static Color makeLighter(final Color color, final double percentage) { int r = Math.min(color.getRed() + (int) (color.getRed() * percentage), 255); int g = Math.min(color.getGreen() + (int) (color.getGreen() * percentage), 255); int b = Math.min(color.getBlue() + (int) (color.getBlue() * percentage), 255); return new Color(r, g, b); }
From source file:monitor.processing.OLD.Drawing3D.java
public void drawTree(BaseNode n, RealVector v) { Color c = Color.WHITE; if (n instanceof TransformNode) { //v = ((TransformNode) n).getTrasformMatrix().getColumnVector(3); v = ((TransformNode) n).getTrasformMatrix().operate(v); //stroke(0, 0, 255); // line((float) bef[0] * scale, (float) bef[1] * scale, (float) bef[2] * scale, (float) att[0] * scale, (float) att[1] * scale, (float) att[2] * scale); c = Color.BLACK;/* w w w. j a va 2 s . c o m*/ } else if (n instanceof StaticMesh) { StaticMesh sm = (StaticMesh) n; if (sm.isTransparent()) { c = Color.BLUE; } else if (sm.isVisible()) { // System.out.println(n.getInfo()); // System.out.println(v); c = Color.RED; if (sm.getModel().contains("naohead") || sm.getModel().contains("naobody")) { c = Color.PINK; } } else { c = Color.CYAN; } } else if (n instanceof StaticMeshNode) { StaticMeshNode smn = (StaticMeshNode) n; if (smn.isTransparent()) { c = Color.GREEN; // cameraSceneX = (float)v.getEntry(0); // cameraSceneY = (float)v.getEntry(1); // cameraSceneZ = (float)v.getEntry(2); } else if (smn.isVisible()) { c = Color.YELLOW; } else { c = Color.MAGENTA; } } // if (n.getInfo().contains("naohead")){ // c = Color.CYAN; // pushMatrix(); // fill(c.getRed(), c.getGreen(), c.getBlue()); // // noStroke(); // translate((float) (scale * v.getEntry(0)), (float) (-scale * v.getEntry(1)), (float) (scale * v.getEntry(2))); // box(50); // popMatrix(); // } pushMatrix(); fill(c.getRed(), c.getGreen(), c.getBlue()); noStroke(); translate((float) (scale * v.getEntry(0)), (float) (-scale * v.getEntry(1)), (float) (scale * v.getEntry(2))); box(0.05f * scale); popMatrix(); if (n.getAddress() == selected) { path.add(v); pushMatrix(); fill(0, 255, 255, selectedAlpha); selectedAlpha += (selectedAlpha >= 255) ? -255 : 10; noStroke(); translate((float) (scale * v.getEntry(0)), (float) (-scale * v.getEntry(1)), (float) (scale * v.getEntry(2))); pushMatrix(); //rotateX(t); rotateZ(selectedTheta); selectedTheta += 1 / 8f; box(0.1f * scale); popMatrix(); // info rotateZ(PI / 2); rotateX(-PI / 2); translate(0.1f * scale, -0.1f * scale); fill(0); textSize(0.1f * scale); text(n.getInfo(), 0, 0, 0); popMatrix(); RealVector ant = null; int o = 0; for (RealVector w : path) { if (ant != null) { stroke(o, 255 - o, 0, 200); // System.out.println(ant); // System.out.println(w); line((float) ant.getEntry(0) * scale, (float) ant.getEntry(1) * -scale, (float) ant.getEntry(2) * scale, (float) w.getEntry(0) * scale, (float) w.getEntry(1) * -scale, (float) w.getEntry(2)); o += (o >= 255) ? -200 : 10; } ant = w; pushMatrix(); stroke(255, 255, 0, 200); translate((float) (scale * w.getEntry(0)), (float) (-scale * w.getEntry(1)), (float) (scale * w.getEntry(2))); box(2); popMatrix(); } } for (int a = n.getChildren().size() - 1; a >= 0; a--) { drawTree(((ArrayList<BaseNode>) n.getChildren()).get(a), v); } }
From source file:ca.sqlpower.wabit.dao.WorkspaceSAXHandler.java
/** * Throws a {@link CancellationException} if either the loading of the file * was cancelled by a method call or cancelled internally due to a problem * in the file. If there was a problem with the file this method will notify * the user and another notification does not need to be sent. * <p>/* www . j a v a 2 s .c o m*/ * * @see WorkspaceXMLDAO#FILE_VERSION */ private void startElementImpl(final String uri, final String localName, final String name, Attributes attributes) throws SAXException { if (isCancelled()) { return; } xmlContext.push(name); final WabitObject createdObject; if (name.equals("wabit")) { createdObject = null; String versionString = attributes.getValue("export-format"); //NOTE: For correct versioning behaviour see WorkspaceXMLDAO.FILE_VERSION. if (versionString == null) { UserPrompter up = promptFactory.createUserPrompter( "This Wabit workspace file is very old. It may not read correctly, but I will try my best.", UserPromptType.MESSAGE, UserPromptOptions.OK, UserPromptResponse.OK, null, "OK"); up.promptUser(); } else { Version fileVersion = new Version(versionString); Version fileMajorMinorVersion = new Version(fileVersion, 2); Version currentMajorMinorVersion = new Version(WorkspaceXMLDAO.FILE_VERSION, 2); Version fileMajorVersion = new Version(fileVersion, 1); Version currentMajorVersion = new Version(WorkspaceXMLDAO.FILE_VERSION, 1); String message = null; boolean displayMessage = true; if (fileMajorVersion.compareTo(currentMajorVersion) < 0) { message = "The Wabit workspace you are opening is too old to be successfully loaded.\n" + "An older version of Wabit is required to view the saved workspace."; setCancelled(true); } else if (fileVersion.equals(new Version("1.0.0"))) { message = "The Wabit workspace you are opening is an old version that does not record\n" + "information about page orientation. All pages will default to portrait orientation."; } else if (fileVersion.compareTo(new Version("1.1.0")) < 0) { message = "The Wabit workspace you are opening contains OLAP and/or reports from an.\n" + "old version of the wabit. These items cannot be loaded and need to be updated\n" + "to the latest version."; } else if (fileVersion.compareTo(new Version("1.2.0")) < 0) { message = "The Wabit workspace you are opening was created in an older version of Wabit\n" + "which stored charts within reports rather than sharing them within the Workspace.\n" + "Your charts will appear as empty boxes; you will have to re-create them."; } else if (fileMajorMinorVersion.compareTo(currentMajorMinorVersion) > 0) { message = "The Wabit workspace you are opening was created in a newer version of Wabit.\n" + "Due to large changes in the file format this file cannot be loaded without updating " + "Wabit."; setCancelled(true); } else if (fileVersion.compareTo(WorkspaceXMLDAO.FILE_VERSION) > 0) { message = "The Wabit workspace you are opening was created in a newer version of Wabit.\n" + "I will attempt to load this workspace but it is recommended to update Wabit\n" + "to the latest version."; } else { displayMessage = false; } if (fileVersion.compareTo(new Version("1.2.5")) >= 0) { nameMandatory = true; uuidMandatory = true; } else { nameMandatory = false; uuidMandatory = false; } if (displayMessage) { UserPrompter up = promptFactory.createUserPrompter(message, UserPromptType.MESSAGE, UserPromptOptions.OK, UserPromptResponse.OK, null, "OK"); up.promptUser(); } if (isCancelled()) throw new CancellationException(); } } else if (name.equals("project")) { createdObject = session.getWorkspace(); } else if (name.equals("data-source")) { String dsName = attributes.getValue("name"); checkMandatory("name", dsName); progressMessage = session.getWorkspace().getName() + ": loading data source " + dsName; SPDataSource ds = dsCollection.getDataSource(dsName); if (ds == null) { List<Class<? extends SPDataSource>> dsTypes = new ArrayList<Class<? extends SPDataSource>>(); dsTypes.add(JDBCDataSource.class); dsTypes.add(Olap4jDataSource.class); //Note: the new prompt here is so that on the server side the user still has the //option of creating a new datasource UserPrompter prompter = promptFactory.createDatabaseUserPrompter( "The data source \"" + dsName + "\" does not exist. Please select a replacement.", dsTypes, UserPromptOptions.OK_NEW_NOTOK_CANCEL, UserPromptResponse.NOT_OK, null, dsCollection, "Select Data Source", "New...", "Skip Data Source", "Cancel Load"); UserPromptResponse response = prompter.promptUser(); if (response == UserPromptResponse.OK || response == UserPromptResponse.NEW) { ds = (SPDataSource) prompter.getUserSelectedResponse(); createdObject = new WabitDataSource(ds); if (!session.getWorkspace().dsAlreadyAdded(ds)) { session.getWorkspace().addDataSource(ds); } oldToNewDSNames.put(dsName, ds.getName()); } else if (response == UserPromptResponse.NOT_OK) { ds = null; createdObject = null; } else { setCancelled(true); createdObject = null; } } else if (!session.getWorkspace().dsAlreadyAdded(ds)) { session.getWorkspace().addDataSource(ds); createdObject = new WabitDataSource(ds); } else { createdObject = null; } } else if (name.equals("query")) { cache = new QueryCache(session.getContext(), false); createdObject = cache; String queryName = attributes.getValue("name"); cache.setName(queryName); progressMessage = session.getWorkspace().getName() + " : loading query " + queryName; for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid")) { // already loaded } else if (aname.equals("name")) { // already loaded } else if (aname.equals("data-source")) { JDBCDataSource ds = session.getWorkspace().getDataSource(aval, JDBCDataSource.class); if (ds == null) { String newDSName = oldToNewDSNames.get(aval); if (newDSName != null) { ds = session.getWorkspace().getDataSource(newDSName, JDBCDataSource.class); if (ds == null) { logger.debug("Data source " + aval + " is not in the workspace. Attempted to replace with new data source " + newDSName + ". Query " + aname + " was connected to it previously."); throw new NullPointerException( "Data source " + newDSName + " was not found in the workspace."); } } logger.debug("Workspace has data sources " + session.getWorkspace().getDataSources()); } cache.setDataSourceWithoutSideEffects(ds); } else if (aname.equals("zoom")) { cache.setZoomLevel(Integer.parseInt(aval)); } else if (aname.equals("streaming-row-limit")) { cache.setStreamingRowLimit(Integer.parseInt(aval)); } else if (aname.equals("row-limit")) { cache.setRowLimit(Integer.parseInt(aval)); } else if (aname.equals("grouping-enabled")) { cache.setGroupingEnabled(Boolean.parseBoolean(aval)); } else if (aname.equals("prompt-for-cross-joins")) { cache.setPromptForCrossJoins(Boolean.parseBoolean(aval)); } else if (aname.equals("execute-queries-with-cross-joins")) { cache.setExecuteQueriesWithCrossJoins(Boolean.parseBoolean(aval)); } else if (aname.equals("automatically-executing")) { cache.setAutomaticallyExecuting(Boolean.parseBoolean(aval)); } else if (aname.equals("streaming")) { cache.setStreaming(Boolean.parseBoolean(aval)); } else { logger.warn("Unexpected attribute of <query>: " + aname + "=" + aval); } } session.getWorkspace().addQuery(cache, session); } else if (name.equals("constants")) { createdObject = null; String uuid = attributes.getValue("uuid"); checkMandatory("uuid", uuid); cache.getConstantsContainer().setUUID(uuid); Container constants = cache.getConstantsContainer(); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid")) { // already loaded } else if (aname.equals("xpos")) { constants.setPosition( new Point2D.Double(Double.parseDouble(aval), constants.getPosition().getY())); logger.debug("Constants container is at position " + constants.getPosition()); } else if (aname.equals("ypos")) { constants.setPosition( new Point2D.Double(constants.getPosition().getX(), Double.parseDouble(aval))); } else { logger.warn("Unexpected attribute of <constants>: " + aname + "=" + aval); } } } else if (name.equals("table")) { createdObject = null; String tableName = attributes.getValue("name"); String schema = attributes.getValue("schema"); String catalog = attributes.getValue("catalog"); String uuid = attributes.getValue("uuid"); checkMandatory("uuid", uuid); checkMandatory("name", tableName); TableContainer table = new TableContainer(uuid, cache.getDatabase(), tableName, schema, catalog, new ArrayList<SQLObjectItem>()); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name") || aname.equals("schema") || aname.equals("catalog") || aname.equals("uuid")) { // already loaded. } else if (aname.equals("xpos")) { table.setPosition(new Point2D.Double(Double.parseDouble(aval), table.getPosition().getY())); } else if (aname.equals("ypos")) { table.setPosition(new Point2D.Double(table.getPosition().getX(), Double.parseDouble(aval))); } else if (aname.equals("alias")) { table.setAlias(aval); } else { logger.warn("Unexpected attribute of <table>: " + aname + "=" + aval); } } container = table; containerItems = new ArrayList<SQLObjectItem>(); } else if (name.equals("column")) { createdObject = null; if (parentIs("constants")) { String itemName = attributes.getValue("name"); String uuid = attributes.getValue("id"); checkMandatory("name", itemName); checkMandatory("id", uuid); Item item = new StringItem(itemName, uuid); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name") || aname.equals("id")) { //already loaded. } else if (aname.equals("alias")) { item.setAlias(aval); } else if (aname.equals("where-text")) { item.setWhere(aval); } else if (aname.equals("group-by")) { item.setGroupBy(SQLGroupFunction.valueOf(aval)); } else if (aname.equals("having")) { item.setHaving(aval); } else if (aname.equals("order-by")) { item.setOrderBy(OrderByArgument.valueOf(aval)); } else { logger.warn("Unexpected attribute of <constant-column>: " + aname + "=" + aval); } } cache.getConstantsContainer().addItem(item); uuidToItemMap.put(uuid, item); } else if (parentIs("table")) { String itemName = attributes.getValue("name"); String uuid = attributes.getValue("id"); checkMandatory("name", itemName); checkMandatory("id", uuid); SQLObjectItem item = new SQLObjectItem(itemName, uuid); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name") || aname.equals("id")) { //already loaded. } else if (aname.equals("alias")) { item.setAlias(aval); } else if (aname.equals("where-text")) { item.setWhere(aval); } else if (aname.equals("group-by")) { item.setGroupBy(SQLGroupFunction.valueOf(aval)); } else if (aname.equals("having")) { item.setHaving(aval); } else if (aname.equals("order-by")) { item.setOrderBy(OrderByArgument.valueOf(aval)); } else { logger.warn("Unexpected attribute of <constant-column>: " + aname + "=" + aval); } } containerItems.add(item); uuidToItemMap.put(uuid, item); } else if (parentIs("select")) { String uuid = attributes.getValue("id"); checkMandatory("id", uuid); if (uuidToItemMap.get(uuid) == null) { throw new IllegalStateException( "Cannot find a column with id " + uuid + " to add to the select statement."); } cache.selectItem(uuidToItemMap.get(uuid)); } else { throw new IllegalStateException( "A column is being loaded that is not contained by any tables. Parent is " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("join")) { createdObject = null; String leftUUID = attributes.getValue("left-item-id"); String rightUUID = attributes.getValue("right-item-id"); checkMandatory("left-item-id", leftUUID); checkMandatory("right-item-id", rightUUID); Item leftItem = uuidToItemMap.get(leftUUID); Item rightItem = uuidToItemMap.get(rightUUID); if (leftItem == null) { throw new IllegalStateException( "The left side of a join was not found. Trying to match UUID " + leftUUID); } if (rightItem == null) { throw new IllegalStateException( "The right side of a join was not found. Trying to match UUID " + rightUUID); } SQLJoin join = new SQLJoin(leftItem, rightItem); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("left-item-id") || aname.equals("right-item-id")) { // already loaded } else if (aname.equals("left-is-outer")) { join.setLeftColumnOuterJoin(Boolean.parseBoolean(aval)); } else if (aname.equals("right-is-outer")) { join.setRightColumnOuterJoin(Boolean.parseBoolean(aval)); } else if (aname.equals("comparator")) { join.setComparator(aval); } else { logger.warn("Unexpected attribute of <join>: " + aname + "=" + aval); } } cache.addJoin(join); } else if (name.equals("select")) { createdObject = null; // Select portion loaded in the "column" part above. } else if (name.equals("global-where")) { createdObject = null; cache.setGlobalWhereClause(attributes.getValue("text")); } else if (name.equals("group-by-aggregate")) { // For backwards compatibility to Wabit 0.9.6 and older createdObject = null; String uuid = attributes.getValue("column-id"); String aggregate = attributes.getValue("aggregate"); checkMandatory("column-id", uuid); checkMandatory("aggregate", aggregate); Item item = uuidToItemMap.get(uuid); if (item == null) { throw new IllegalStateException( "Could not get a column for grouping. Trying to match UUID " + uuid); } cache.setGroupingEnabled(true); item.setGroupBy(SQLGroupFunction.getGroupType(aggregate)); } else if (name.equals("having")) { // For backwards compatibility to Wabit 0.9.6 and older createdObject = null; String uuid = attributes.getValue("column-id"); String text = attributes.getValue("text"); checkMandatory("column-id", uuid); checkMandatory("text", text); Item item = uuidToItemMap.get(uuid); if (item == null) { throw new IllegalStateException( "Could not get a column to add a having filter. Trying to match UUID " + uuid); } cache.setGroupingEnabled(true); item.setHaving(text); } else if (name.equals("order-by")) { createdObject = null; String uuid = attributes.getValue("column-id"); checkMandatory("column-id", uuid); Item item = uuidToItemMap.get(uuid); if (item == null) { throw new IllegalStateException( "Could not get a column to add order by to the select statement. Trying to match UUID " + uuid); } for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("column-id")) { //already loaded. } if (aname.equals("direction")) {// For backwards compatibility to Wabit 0.9.6 and older item.setOrderBy(OrderByArgument.valueOf(aval)); } else { logger.warn("Unexpected attribute of <order-by>: " + aname + " = " + aval); } } //Reinserting the items for cases where when the items were first created they defined a sort //order and were placed in the query in an incorrect order to sort the columns in. cache.moveOrderByItemToEnd(item); } else if (name.equals("query-string")) { createdObject = null; String queryString = attributes.getValue("string"); checkMandatory("string", queryString); cache.setUserModifiedQuery(queryString); } else if (name.equals("text") && parentIs("query")) { createdObject = null; } else if (name.equals("olap-query")) { olapName = attributes.getValue("name"); olapID = attributes.getValue("uuid"); String dsName = attributes.getValue("data-source"); olapDataSource = session.getWorkspace().getDataSource(dsName, Olap4jDataSource.class); if (olapDataSource == null) { String newDSName = oldToNewDSNames.get(dsName); if (newDSName != null) { olapDataSource = session.getWorkspace().getDataSource(newDSName, Olap4jDataSource.class); if (olapDataSource == null) { logger.debug("Data source " + dsName + " is not in the workspace or was not of the correct type. Attempted to replace with new data source " + newDSName + ". Query " + "data-source" + " was connected to it previously."); throw new NullPointerException("Data source " + newDSName + " was not found in the workspace or was not an Olap4j Datasource."); } } logger.debug("Workspace has data sources " + session.getWorkspace().getDataSources()); } createdObject = null; } else if (name.equals("olap-cube")) { catalogName = attributes.getValue("catalog"); schemaName = attributes.getValue("schema"); cubeName = attributes.getValue("cube-name"); createdObject = null; } else if (name.equals("olap4j-query")) { olapQuery = new OlapQuery(olapID, session.getContext(), attributes.getValue("name"), attributes.getValue("name"), catalogName, schemaName, cubeName, attributes.getValue("modifiedOlapQuery"), !isInLayout); olapQuery.setName(olapName); olapQuery.setOlapDataSource(olapDataSource); if (cellSetRenderer == null) { session.getWorkspace().addOlapQuery(olapQuery); } else { cellSetRenderer.setModifiedOlapQuery(olapQuery); } createdObject = null; } else if (name.equals("olap4j-axis")) { olapAxis = new WabitOlapAxis( org.olap4j.Axis.Factory.forOrdinal(Integer.parseInt(attributes.getValue("ordinal")))); olapQuery.addAxis(olapAxis); createdObject = olapAxis; } else if (name.equals("olap4j-dimension")) { olapDimension = new WabitOlapDimension(attributes.getValue("dimension-name")); olapAxis.addDimension(olapDimension); createdObject = olapDimension; } else if (name.equals("olap4j-selection")) { WabitOlapInclusion olapInclusion = new WabitOlapInclusion( Operator.valueOf(attributes.getValue("operator")), attributes.getValue("unique-member-name")); olapDimension.addInclusion(olapInclusion); createdObject = olapInclusion; } else if (name.equals("olap4j-exclusion")) { WabitOlapExclusion olapExclusion = new WabitOlapExclusion( Operator.valueOf(attributes.getValue("operator")), attributes.getValue("unique-member-name")); olapDimension.addExclusion(olapExclusion); createdObject = olapExclusion; } else if (name.equals("wabit-image")) { currentWabitImage = new WabitImage(); createdObject = currentWabitImage; session.getWorkspace().addImage(currentWabitImage); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //already loaded } else { logger.warn("Unexpected attribute of <wabit-image>: " + aname + "=" + aval); } } } else if (name.equals("chart")) { chart = new Chart(); createdObject = chart; session.getWorkspace().addChart(chart); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid")) { //already loaded } else if (aname.equals("y-axis-name")) { chart.setYaxisName(aval); } else if (aname.equals("x-axis-name")) { chart.setXaxisName(aval); } else if (aname.equals("x-axis-label-rotation")) { chart.setXAxisLabelRotation(Double.parseDouble(aval)); } else if (aname.equals("type")) { chart.setType(ChartType.valueOf(aval)); } else if (aname.equals("legend-position")) { chart.setLegendPosition(LegendPosition.valueOf(aval)); } else if (aname.equals("gratuitous-animation")) { chart.setGratuitouslyAnimated(Boolean.parseBoolean(aval)); } else if (aname.equals("auto-x-axis")) { chart.setAutoXAxisRange(Boolean.parseBoolean(aval)); } else if (aname.equals("auto-y-axis")) { chart.setAutoXAxisRange(Boolean.parseBoolean(aval)); } else if (aname.equals("x-axis-max")) { chart.setXAxisMaxRange(Double.parseDouble(aval)); } else if (aname.equals("y-axis-max")) { chart.setYAxisMaxRange(Double.parseDouble(aval)); } else if (aname.equals("x-axis-min")) { chart.setXAxisMinRange(Double.parseDouble(aval)); } else if (aname.equals("y-axis-min")) { chart.setYAxisMinRange(Double.parseDouble(aval)); } else if (aname.equals("query-id")) { QueryCache query = null; for (QueryCache q : session.getWorkspace().getQueries()) { if (q.getUUID().equals(aval)) { query = q; break; } } if (query != null) { chart.setQuery(query); } OlapQuery olapQuery = null; for (OlapQuery q : session.getWorkspace().getOlapQueries()) { if (q.getUUID().equals(aval)) { olapQuery = q; break; } } if (olapQuery != null) { try { chart.setMagicEnabled(false); chart.setQuery(olapQuery); } finally { chart.setMagicEnabled(true); } } if (query == null && olapQuery == null) { throw new IllegalArgumentException( "The query with UUID " + aval + " is missing from this project."); } } else { logger.warn("Unexpected attribute of <chart>: " + aname + "=" + aval); } } } else if (name.equals("chart-column")) { ChartColumn colIdentifier = loadColumnIdentifier(attributes, ""); createdObject = colIdentifier; if (colIdentifier == null) { throw new IllegalStateException("The chart " + chart.getName() + " with uuid " + chart.getUUID() + " has a missing column identifier when ordering columns and cannot be loaded."); } for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //already handled } else if (aname.equals("role")) { colIdentifier.setRoleInChart(ColumnRole.valueOf(aval)); } else if (aname.matches("x-axis-.*")) { ChartColumn xAxisIdentifier = loadColumnIdentifier(attributes, "x-axis-"); colIdentifier.setXAxisIdentifier(xAxisIdentifier); } } if (readingMissingChartCols) { chart.addMissingIdentifier(colIdentifier); } else { chart.addChartColumn(colIdentifier); } } else if (name.equals("missing-columns")) { readingMissingChartCols = true; createdObject = null; } else if (name.equals("layout")) { this.isInLayout = true; String layoutName = attributes.getValue("name"); checkMandatory("name", layoutName); if (attributes.getValue("template") == null || !Boolean.parseBoolean(attributes.getValue("template"))) { layout = new Report(layoutName); session.getWorkspace().addReport((Report) layout); } else { layout = new Template(layoutName); session.getWorkspace().addTemplate((Template) layout); } createdObject = layout; selectorContainer = layout; for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //already loaded } else if (aname.equals("zoom")) { layout.setZoomLevel(Integer.parseInt(aval)); } else { logger.warn("Unexpected attribute of <layout>: " + aname + "=" + aval); } } } else if (name.equals("layout-page")) { Page page = layout.getPage(); createdObject = page; //Remove all guides from the page as they will be loaded in a later //part of this handler. for (WabitObject object : page.getChildren()) { if (object instanceof Guide) { page.removeGuide((Guide) object); } } //This sets the orientation before setting the width and height to prevent //a change in the orientation from switching the width and height. If the //orientation changes between portrait and landscape the width and height //values are swapped. String orientation = attributes.getValue("orientation"); if (orientation != null) { // XXX the null check is for compatibility with export-format 1.0.0 page.setOrientation(PageOrientation.valueOf(orientation)); } for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { // already loaded } else if (aname.equals("height")) { page.setHeight(Integer.parseInt(aval)); } else if (aname.equals("width")) { page.setWidth(Integer.parseInt(aval)); } else if (aname.equals("orientation")) { //already loaded } else { logger.warn("Unexpected attribute of <layout-page>: " + aname + "=" + aval); } } } else if (name.equals("content-box")) { contentBox = new ContentBox(); createdObject = contentBox; selectorContainer = contentBox; layout.getPage().addContentBox(contentBox); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { // already loaded } else if (aname.equals("width")) { contentBox.setWidth(Double.parseDouble(aval)); } else if (aname.equals("height")) { contentBox.setHeight(Double.parseDouble(aval)); } else if (aname.equals("xpos")) { contentBox.setX(Double.parseDouble(aval)); } else if (aname.equals("ypos")) { contentBox.setY(Double.parseDouble(aval)); } else { logger.warn("Unexpected attribute of <content-box>: " + aname + "=" + aval); } } } else if (name.equals("content-label")) { WabitLabel label = new WabitLabel(); createdObject = label; contentBox.setContentRenderer(label); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //handled elsewhere } else if (aname.equals("text")) { label.setText(aval); } else if (aname.equals("horizontal-align")) { label.setHorizontalAlignment(HorizontalAlignment.valueOf(aval)); } else if (aname.equals("vertical-align")) { label.setVerticalAlignment(VerticalAlignment.valueOf(aval)); } else if (aname.equals("bg-colour")) { label.setBackgroundColour(new Color(Integer.parseInt(aval))); } else { logger.warn("Unexpected attribute of <content-label>: " + aname + "=" + aval); } } } else if (name.equals("text") && parentIs("content-label")) { createdObject = null; } else if (name.equals("image-renderer")) { imageRenderer = new ImageRenderer(); createdObject = imageRenderer; //Old image renderers always had the image in the top left. If //the file is new it will have the horizontal and vertical alignments //set. imageRenderer.setHAlign(HorizontalAlignment.LEFT); imageRenderer.setVAlign(VerticalAlignment.TOP); contentBox.setContentRenderer(imageRenderer); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //Handled elsewhere } else if (aname.equals("wabit-image-uuid")) { for (WabitImage image : session.getWorkspace().getImages()) { if (image.getUUID().equals(aval)) { imageRenderer.setImage(image); break; } } if (imageRenderer.getImage() == null) { throw new IllegalStateException("Could not load the workspace as the report " + layout.getName() + " is missing the image " + aval); } } else if (aname.equals("preserving-aspect-ratio")) { imageRenderer.setPreservingAspectRatio(Boolean.valueOf(aval)); } else if (aname.equals("h-align")) { imageRenderer.setHAlign(HorizontalAlignment.valueOf(aval)); } else if (aname.equals("v-align")) { imageRenderer.setVAlign(VerticalAlignment.valueOf(aval)); } else { logger.warn("Unexpected attribute of <image-renderer>: " + aname + "=" + aval); } } } else if (name.equals("chart-renderer")) { String chartUuid = attributes.getValue("chart-uuid"); Chart chart = session.getWorkspace().findByUuid(chartUuid, Chart.class); if (chart == null) { throw new IllegalStateException("Missing chart with UUID " + chartUuid + ", which is supposed" + " to be attached to a chart renderer"); } final ChartRenderer chartRenderer = new ChartRenderer(chart); createdObject = chartRenderer; contentBox.setContentRenderer(chartRenderer); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid")) { // handled elsewhere } else if (aname.equals("chart-uuid")) { // already handled } else if (aname.equals("name")) { // handled elsewhere } else { logger.warn("Unexpected attribute of <chart-renderer>: " + aname + "=" + aval); } } } else if (name.equals("content-result-set")) { String queryID = attributes.getValue("query-id"); checkMandatory("query-id", queryID); WabitResultSetProducer query = session.getWorkspace().findByUuid(queryID, WabitResultSetProducer.class); rsRenderer = new ResultSetRenderer(query); createdObject = rsRenderer; for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("query-id")) { // handled elsewhere } else if (aname.equals("name")) { // handled elsewhere } else if (aname.equals("null-string")) { rsRenderer.setNullString(aval); } else if (aname.equals("bg-colour")) { Color color = new Color(Integer.parseInt(aval)); logger.debug("Renderer has background " + color.getRed() + ", " + color.getBlue() + ", " + color.getGreen()); rsRenderer.setBackgroundColour(color); } else if (aname.equals("data-colour")) { Color color = new Color(Integer.parseInt(aval)); rsRenderer.setDataColour(color); } else if (aname.equals("header-colour")) { Color color = new Color(Integer.parseInt(aval)); rsRenderer.setHeaderColour(color); } else if (aname.equals("border")) { rsRenderer.setBorderType(BorderStyles.valueOf(aval)); } else if (aname.equals("grand-totals")) { rsRenderer.setPrintingGrandTotals(Boolean.parseBoolean(aval)); } else { logger.warn("Unexpected attribute of <content-result-set>: " + aname + "=" + aval); } } //columnInfoList.clear(); contentBox.setContentRenderer(rsRenderer); } else if (name.equals("header-font")) { if (parentIs("content-result-set")) { rsRenderer.setHeaderFont(loadFont(attributes)); createdObject = null; } else { throw new IllegalStateException("There are no header fonts defined for the parent " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("body-font")) { if (parentIs("content-result-set")) { createdObject = null; rsRenderer.setBodyFont(loadFont(attributes)); } else { throw new IllegalStateException( "There are no body fonts defined for the parent " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("column-info")) { colInfo = null; createdObject = null; //Not going to set name later, as this may break alias association String colInfoName = attributes.getValue("name"); String colInfoItem = attributes.getValue("column-info-item-id"); /* * XXX This retro compatibility fix forces us to violate * proper encapsulation and cannot be maintained if we want to * display OLAP queries in a RSRenderer. Imma comment it * out for now and evaluate later if we want to keep it. * It is for retrocompatibility with 0.9.1, which is a terribly * old version anyways. I'm not even sure we can load those files * now anyways. */ // //For backwards compatability with 0.9.1 // String colInfoKey = attributes.getValue("column-info-key"); // if (colInfoKey != null && colInfoItem == null) { // Query q = rsRenderer.getContent(); // for (Map.Entry<String, Item> entry : uuidToItemMap.entrySet()) { // Item item = entry.getValue(); // if (q.getSelectedColumns().contains(item) && (item.getAlias().equals(colInfoKey) || item.getName().equals(colInfoKey))) { // colInfoItem = entry.getKey(); // break; // } // } // if (colInfoItem == null) { // colInfo = new ColumnInfo(colInfoKey, colInfoName); // } // } String colAlias = attributes.getValue("column-alias"); if (colInfo == null && colAlias != null && colInfoItem == null) { colInfo = new ColumnInfo(colAlias, colInfoName); } checkMandatory("name", colInfoName); if (colInfo == null) { colInfo = new ColumnInfo(uuidToItemMap.get(colInfoItem), colInfoName); } for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("column-info-key") || aname.equals("name")) { //already loaded } else if (aname.equals("uuid")) { colInfo.setUUID(aval); } else if (aname.equals("width")) { colInfo.setWidth(Integer.parseInt(aval)); } else if (aname.equals("horizontal-align")) { colInfo.setHorizontalAlignment(HorizontalAlignment.valueOf(aval)); } else if (aname.equals("data-type")) { colInfo.setDataType(DataType.valueOf(aval)); } else if (aname.equals("break-on-column")) { if (Boolean.parseBoolean(aval)) { colInfo.setWillGroupOrBreak(GroupAndBreak.GROUP); } else { colInfo.setWillGroupOrBreak(GroupAndBreak.NONE); } } else if (aname.equals("group-or-break")) { colInfo.setWillGroupOrBreak(GroupAndBreak.valueOf(aval)); } else if (aname.equals("will-subtotal")) { colInfo.setWillSubtotal(Boolean.parseBoolean(aval)); } else { logger.warn("Unexpected attribute of <column-info>: " + aname + "=" + aval); } } rsRenderer.addChild(colInfo, rsRenderer.getChildren().size()); } else if (name.equals("date-format")) { createdObject = null; if (parentIs("column-info")) { String format = attributes.getValue("format"); checkMandatory("format", format); colInfo.setFormat(new SimpleDateFormat(format)); } else { throw new IllegalStateException( "There is no date format defined for the parent " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("decimal-format")) { createdObject = null; if (parentIs("column-info")) { String format = attributes.getValue("format"); checkMandatory("format", format); colInfo.setFormat(new DecimalFormat(format)); } else { throw new IllegalStateException( "There is no date format defined for the parent " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("selector")) { String type = attributes.getValue("type"); if (type.equals(ComboBoxSelector.class.getSimpleName())) { this.selector = new ComboBoxSelector(); } else if (type.equals(TextBoxSelector.class.getSimpleName())) { this.selector = new TextBoxSelector(); } else if (type.equals(DateSelector.class.getSimpleName())) { this.selector = new DateSelector(); } else { throw new IllegalStateException("Cannot create a selector of type " + type); } if (selectorContainer == null) { throw new AssertionError("Program error. 'selectorContainer' not set."); } else if (selectorContainer instanceof Report || selectorContainer instanceof ContentBox) { selectorContainer.addChild(selector, selectorContainer.getChildren(Selector.class).size()); } else { throw new IllegalStateException("Selectors can only be added to reports and content boxes.."); } createdObject = this.selector; } else if (name.equals("selector-config")) { if (selector instanceof ComboBoxSelector) { ((ComboBoxSelector) selector).setSourceKey(attributes.getValue("sourceKey")); ((ComboBoxSelector) selector).setStaticValues(attributes.getValue("staticValues")); ((ComboBoxSelector) selector).setDefaultValue(attributes.getValue("defaultValue")); ((ComboBoxSelector) selector).setAlwaysIncludeDefaultValue( Boolean.valueOf(attributes.getValue("alwaysIncludeDefaultValue"))); } else if (selector instanceof TextBoxSelector) { ((TextBoxSelector) selector).setDefaultValue(attributes.getValue("defaultValue")); } else if (selector instanceof DateSelector) { String defValueS = attributes.getValue("defaultValue"); final Date defValue; if (defValueS == null) { defValue = null; } else { defValue = new DateConverter().convertToComplexType(defValueS); } ((DateSelector) selector).setDefaultValue(defValue); } else { throw new IllegalStateException("Cannot configure selector."); } createdObject = null; } else if (name.equals("cell-set-renderer")) { String queryUUID = attributes.getValue("olap-query-uuid"); OlapQuery newQuery = null; for (OlapQuery query : session.getWorkspace().getOlapQueries()) { if (query.getUUID().equals(queryUUID)) { newQuery = query; break; } } if (newQuery == null) { throw new NullPointerException("Cannot load workspace due to missing olap query in report."); } cellSetRenderer = new CellSetRenderer(newQuery); createdObject = cellSetRenderer; contentBox.setContentRenderer(cellSetRenderer); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid") || aname.equals("olap-query-uuid")) { // handled elsewhere } else if (aname.equals("name")) { // handled elsewhere } else if (aname.equals("body-alignment")) { cellSetRenderer.setBodyAlignment(HorizontalAlignment.valueOf(aval)); } else if (aname.equals("body-format-pattern")) { cellSetRenderer.setBodyFormat(new DecimalFormat(aval)); } else { logger.warn("Unexpected attribute of <cell-set-renderer>: " + aname + "=" + aval); } } } else if (name.equals("olap-header-font")) { createdObject = null; cellSetRenderer.setHeaderFont(loadFont(attributes)); } else if (name.equals("olap-body-font")) { createdObject = null; cellSetRenderer.setBodyFont(loadFont(attributes)); } else if (name.equals("guide")) { String axisName = attributes.getValue("axis"); String offsetAmount = attributes.getValue("offset"); checkMandatory("axis", axisName); checkMandatory("offset", offsetAmount); Guide guide = new Guide(Axis.valueOf(axisName), Double.parseDouble(offsetAmount)); createdObject = guide; layout.getPage().addGuide(guide); } else if (name.equals("font")) { createdObject = null; Font font = loadFont(attributes); if (parentIs("layout-page")) { layout.getPage().setDefaultFont(font); } else if (parentIs("content-box")) { contentBox.setFont(font); } else if (parentIs("content-label")) { ((WabitLabel) contentBox.getContentRenderer()).setFont(font); } } else { createdObject = null; logger.warn("Unknown object type: " + name); } if (createdObject != null) { String valName = attributes.getValue("name"); String valUUID = attributes.getValue("uuid"); if (nameMandatory) { checkMandatory("name", valName); } if (uuidMandatory) { checkMandatory("uuid", valUUID); } if (valName != null) { createdObject.setName(valName); } if (valUUID != null) { createdObject.setUUID(valUUID); } progressMessage = session.getWorkspace().getName() + ": reading " + valName; } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.TemplateEditor.java
@Override public void createUI() { super.createUI(); databaseSchema = WorkbenchTask.getDatabaseSchema(); int disciplineeId = AppContextMgr.getInstance().getClassObject(Discipline.class).getDisciplineId(); SchemaI18NService.getInstance().loadWithLocale(SpLocaleContainer.WORKBENCH_SCHEMA, disciplineeId, databaseSchema, SchemaI18NService.getCurrentLocale()); // Create the Table List Vector<TableInfo> tableInfoList = new Vector<TableInfo>(); for (DBTableInfo ti : databaseSchema.getTables()) { if (StringUtils.isNotEmpty(ti.toString())) { TableInfo tableInfo = new TableInfo(ti, IconManager.STD_ICON_SIZE); tableInfoList.add(tableInfo); Vector<FieldInfo> fldList = new Vector<FieldInfo>(); for (DBFieldInfo fi : ti.getFields()) { String fldTitle = fi.getTitle().replace(" ", ""); if (fldTitle.equalsIgnoreCase(fi.getName())) { //get title from mapped field UploadInfo upInfo = getUploadInfo(fi); DBFieldInfo mInfo = getMappedFieldInfo(fi); if (mInfo != null) { String title = mInfo.getTitle(); if (upInfo != null && upInfo.getSequence() != -1) { title += " " + (upInfo.getSequence() + 1); }//from w w w . j a v a 2s . c om //if mapped-to table is different than the container table used // in the wb, add the mapped-to table's title if (mInfo.getTableInfo().getTableId() != ti.getTableId()) { title = mInfo.getTableInfo().getTitle() + " " + title; } fi.setTitle(title); } } fldList.add(new FieldInfo(ti, fi)); } //Collections.sort(fldList); tableInfo.setFieldItems(fldList); } } Collections.sort(tableInfoList); fieldModel = new DefaultModifiableListModel<FieldInfo>(); tableModel = new DefaultModifiableListModel<TableInfo>(); for (TableInfo ti : tableInfoList) { tableModel.add(ti); // only added for layout for (FieldInfo fi : ti.getFieldItems()) { fieldModel.add(fi); } } tableList = new JList(tableModel); tableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tableList.setCellRenderer(tableInfoListRenderer = new TableInfoListRenderer(IconManager.STD_ICON_SIZE)); JScrollPane tableScrollPane = new JScrollPane(tableList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); tableList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Object selObj = tableList.getSelectedValue(); if (selObj != null) { fillFieldList((TableInfo) selObj); } updateEnabledState(); } } }); fieldList = new JList(fieldModel); fieldList.setCellRenderer(tableInfoListRenderer = new TableInfoListRenderer(IconManager.STD_ICON_SIZE)); fieldList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JScrollPane fieldScrollPane = new JScrollPane(fieldList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); fieldList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { updateEnabledState(); updateFieldDescription(); } } }); mapModel = new DefaultModifiableListModel<FieldMappingPanel>(); mapList = new JList(mapModel); mapList.setCellRenderer(new MapCellRenderer()); mapList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); mapScrollPane = new JScrollPane(mapList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); mapList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { FieldMappingPanel fmp = (FieldMappingPanel) mapList.getSelectedValue(); if (fmp != null) { ignoreMapListUpdate = true; FieldInfo fldInfo = fmp.getFieldInfo(); if (fldInfo != null) { for (int i = 0; i < tableModel.size(); i++) { TableInfo tblInfo = (TableInfo) tableModel.get(i); if (fldInfo.getTableinfo() == tblInfo.getTableInfo()) { tableList.setSelectedValue(tblInfo, true); fillFieldList(tblInfo); //System.out.println(fldInfo.hashCode()+" "+fldInfo.getFieldInfo().hashCode()); fieldList.setSelectedValue(fldInfo, true); updateFieldDescription(); break; } } } ignoreMapListUpdate = false; updateEnabledState(); } } } }); upBtn = createIconBtn("ReorderUp", "WB_MOVE_UP", new ActionListener() { public void actionPerformed(ActionEvent ae) { int inx = mapList.getSelectedIndex(); FieldMappingPanel fmp = mapModel.getElementAt(inx); mapModel.remove(fmp); mapModel.insertElementAt(fmp, inx - 1); mapList.setSelectedIndex(inx - 1); updateEnabledState(); setChanged(true); } }); downBtn = createIconBtn("ReorderDown", "WB_MOVE_DOWN", new ActionListener() { public void actionPerformed(ActionEvent ae) { int inx = mapList.getSelectedIndex(); FieldMappingPanel fmp = mapModel.getElementAt(inx); mapModel.remove(fmp); mapModel.insertElementAt(fmp, inx + 1); mapList.setSelectedIndex(inx + 1); updateEnabledState(); setChanged(true); } }); JButton dumpMappingBtn = createIconBtn("BlankIcon", IconManager.IconSize.Std16, "WB_MAPPING_DUMP", new ActionListener() { public void actionPerformed(ActionEvent ae) { dumpMapping(); } }); dumpMappingBtn.setEnabled(true); dumpMappingBtn.setFocusable(false); dumpMappingBtn.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { ((JButton) e.getSource()).setIcon(IconManager.getIcon("Save", IconManager.IconSize.Std16)); super.mouseEntered(e); } @Override public void mouseExited(MouseEvent e) { ((JButton) e.getSource()).setIcon(IconManager.getIcon("BlankIcon", IconManager.IconSize.Std16)); super.mouseExited(e); } }); mapToBtn = createIconBtn("Map", "WB_ADD_MAPPING_ITEM", new ActionListener() { public void actionPerformed(ActionEvent ae) { map(); } }); unmapBtn = createIconBtn("Unmap", "WB_REMOVE_MAPPING_ITEM", new ActionListener() { public void actionPerformed(ActionEvent ae) { unmap(); } }); // Adjust all Labels depending on whether we are creating a new template or not // and whether it is from a file or not String mapListLeftLabel; String mapListRightLabel; // Note: if workbenchTemplate is null then it is String dataTypeLabel = getResourceString("WB_DATA_TYPE"); String fieldsLabel = getResourceString("WB_FIELDS"); mapListLeftLabel = fieldsLabel; mapListRightLabel = getResourceString("WB_COLUMNS"); CellConstraints cc = new CellConstraints(); JPanel mainLayoutPanel = new JPanel(); PanelBuilder labelsBldr = new PanelBuilder(new FormLayout("p, f:p:g, p", "p")); labelsBldr.add(createLabel(mapListLeftLabel, SwingConstants.LEFT), cc.xy(1, 1)); labelsBldr.add(createLabel(mapListRightLabel, SwingConstants.RIGHT), cc.xy(3, 1)); PanelBuilder upDownPanel = new PanelBuilder(new FormLayout("p", "p,f:p:g, p, 2px, p, f:p:g")); upDownPanel.add(dumpMappingBtn, cc.xy(1, 1)); upDownPanel.add(upBtn, cc.xy(1, 3)); upDownPanel.add(downBtn, cc.xy(1, 5)); PanelBuilder middlePanel = new PanelBuilder(new FormLayout("c:p:g", "p, 2px, p")); middlePanel.add(mapToBtn, cc.xy(1, 1)); middlePanel.add(unmapBtn, cc.xy(1, 3)); btnPanel = middlePanel.getPanel(); btnPanel.setOpaque(false); PanelBuilder outerMiddlePanel = new PanelBuilder(new FormLayout("c:p:g", "f:p:g, p, f:p:g")); outerMiddlePanel.add(btnPanel, cc.xy(1, 2)); outerMiddlePanel.getPanel().setOpaque(false); // Main Pane Layout PanelBuilder builder = new PanelBuilder( new FormLayout("f:max(200px;p):g, 5px, max(200px;p), 5px, p:g, 5px, f:max(250px;p):g, 2px, p", "p, 2px, f:max(350px;p):g"), mainLayoutPanel); builder.add(createLabel(dataTypeLabel, SwingConstants.CENTER), cc.xy(1, 1)); builder.add(createLabel(fieldsLabel, SwingConstants.CENTER), cc.xy(3, 1)); builder.add(labelsBldr.getPanel(), cc.xy(7, 1)); builder.add(tableScrollPane, cc.xy(1, 3)); builder.add(fieldScrollPane, cc.xy(3, 3)); builder.add(outerMiddlePanel.getPanel(), cc.xy(5, 3)); builder.add(mapScrollPane, cc.xy(7, 3)); builder.add(upDownPanel.getPanel(), cc.xy(9, 3)); mainLayoutPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel megaPanel = new JPanel(new BorderLayout()); megaPanel.add(mainLayoutPanel, BorderLayout.CENTER); descriptionLbl = createLabel(" ", SwingConstants.LEFT); //PanelBuilder descBuilder = new PanelBuilder(new FormLayout("f:p:g, 3dlu","p")); //descBuilder.add(descriptionLbl, cc.xy(1, 1)); //megaPanel.add(descBuilder.getPanel(), BorderLayout.SOUTH); megaPanel.add(descriptionLbl, BorderLayout.SOUTH); //contentPanel = mainLayoutPanel; contentPanel = megaPanel; Color bgColor = btnPanel.getBackground(); int inc = 16; btnPanelColor = new Color(Math.min(255, bgColor.getRed() + inc), Math.min(255, bgColor.getGreen() + inc), Math.min(255, bgColor.getBlue() + inc)); btnPanel.setBackground(btnPanelColor); btnPanel.setBorder(BorderFactory.createEmptyBorder(4, 6, 4, 6)); okBtn.setEnabled(false); HelpMgr.registerComponent(helpBtn, helpContext); if (dataFileInfo != null) { autoMapFromDataFile(dataFileInfo.getColInfo()); } if (workbenchTemplate != null) { fillFromTemplate(); setChanged(false); } mainPanel.add(contentPanel, BorderLayout.CENTER); if (dataFileInfo == null) //can't add new mappings when importing. { FieldMappingPanel fmp = addMappingItem(null, IconManager.getIcon("BlankIcon", IconManager.STD_ICON_SIZE), null); fmp.setAdded(true); fmp.setNew(true); } pack(); SwingUtilities.invokeLater(new Runnable() { @SuppressWarnings("synthetic-access") public void run() { cancelBtn.requestFocus(); fieldModel.clear(); fieldList.clearSelection(); updateFieldDescription(); updateEnabledState(); if (mapModel.size() > 1) { mapList.clearSelection(); } } }); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
private Map<String, Long> averageColor(BufferedImage bi) { int x0 = 0;//from w ww. ja va 2 s . c om int y0 = 0; int w = bi.getWidth(); int h = bi.getHeight(); int x1 = x0 + w; int y1 = y0 + h; long sumr = 0, sumg = 0, sumb = 0; for (int x = x0; x < x1; x++) { for (int y = y0; y < y1; y++) { Color pixel = new Color(bi.getRGB(x, y)); sumr += pixel.getRed(); sumg += pixel.getGreen(); sumb += pixel.getBlue(); } } int num = w * h; Map<String, Long> colorMap = new HashMap<>(); colorMap.put("r", (long) (sumr / num)); colorMap.put("g", (long) (sumg / num)); colorMap.put("b", (long) (sumb / num)); return colorMap; }
From source file:edu.ku.brc.af.ui.forms.ViewFactory.java
/** * @param props//w w w . j a v a2s . co m * @param bgColor * @return */ protected Color getBackgroundColor(final Properties props, final Color bgColor) { if (props != null) { String colorStr = props.getProperty("bgcolor"); if (StringUtils.isNotEmpty(colorStr)) { if (colorStr.endsWith("%")) { try { int percent = Integer.parseInt(colorStr.substring(0, colorStr.length() - 1)); double per = (percent / 100.0); int r = Math.min((int) (bgColor.getRed() * per), 255); int g = Math.min((int) (bgColor.getGreen() * per), 255); int b = Math.min((int) (bgColor.getBlue() * per), 255); return new Color(r, g, b); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ViewFactory.class, ex); log.error(ex); } } else { try { return UIHelper.parseRGB(colorStr); } catch (ConfigurationException ex) { log.error(ex); } } } } return bgColor; }
From source file:forge.toolbox.FSkin.java
/** Returns RGB components of a color, with a new * value for alpha. 0 = transparent, 255 = opaque. * * @param clr0 {@link java.awt.Color}/*from w w w. j a v a2s . c om*/ * @param alpha int * @return {@link java.awt.Color} */ public static Color alphaColor(final Color clr0, final int alpha) { return new Color(clr0.getRed(), clr0.getGreen(), clr0.getBlue(), alpha); }
From source file:forge.toolbox.FSkin.java
/** * @see <a href="http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx"> * http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx</a> *///from w ww. j a v a 2 s . c o m public static boolean isColorBright(final Color c) { final int v = (int) Math.sqrt(c.getRed() * c.getRed() * 0.241 + c.getGreen() * c.getGreen() * 0.691 + c.getBlue() * c.getBlue() * 0.068); return v >= 130; }
From source file:forge.toolbox.FSkin.java
/** Steps RGB components of a color up or down. * Returns opaque (non-alpha) stepped color. * Plus for lighter, minus for darker.// w w w . ja va2s . com * * @param clr0 {@link java.awt.Color} * @param step int * @return {@link java.awt.Color} */ public static Color stepColor(final Color clr0, final int step) { int r = clr0.getRed(); int g = clr0.getGreen(); int b = clr0.getBlue(); // Darker if (step < 0) { r = ((r + step > 0) ? r + step : 0); g = ((g + step > 0) ? g + step : 0); b = ((b + step > 0) ? b + step : 0); } else { r = ((r + step < 255) ? r + step : 255); g = ((g + step < 255) ? g + step : 255); b = ((b + step < 255) ? b + step : 255); } return new Color(r, g, b); }
From source file:plugins.tprovoost.Microscopy.MicroManagerForIcy.MMMainFrame.java
/** * Singleton pattern : private constructor Use instead. *//*from w w w .j a v a 2 s.co m*/ private MMMainFrame() { super(NODE_NAME, false, true, false, true); instancing = true; // -------------- // INITIALIZATION // -------------- _sysConfigFile = ""; _isConfigLoaded = false; _root = PluginPreferences.getPreferences().node(NODE_NAME); final MainFrame mainFrame = Icy.getMainInterface().getMainFrame(); // -------------- // PROGRESS FRAME // -------------- ThreadUtil.invokeLater(new Runnable() { @Override public void run() { _progressFrame = new IcyFrame("", false, false, false, false); _progressBar = new JProgressBar(); _progressBar.setString("Please wait while loading..."); _progressBar.setStringPainted(true); _progressBar.setIndeterminate(true); _progressBar.setMinimum(0); _progressBar.setMaximum(1000); _progressBar.setBounds(50, 50, 100, 30); _progressFrame.setSize(300, 100); _progressFrame.setResizable(false); _progressFrame.add(_progressBar); _progressFrame.addToMainDesktopPane(); loadConfig(true); if (_sysConfigFile == "") { instancing = false; return; } ThreadUtil.bgRun(new Runnable() { @Override public void run() { while (!_isConfigLoaded) { if (!instancing) return; try { Thread.sleep(10); } catch (InterruptedException e) { } } ThreadUtil.invokeLater(new Runnable() { @Override public void run() { // -------------------- // START INITIALIZATION // -------------------- if (_progressBar != null) getContentPane().remove(_progressBar); if (mCore == null) { close(); return; } // ReportingUtils.setCore(mCore); _afMgr = new AutofocusManager(MMMainFrame.this); acqMgr = new AcquisitionManager(); PositionList posList = new PositionList(); _camera_label = MMCoreJ.getG_Keyword_CameraName(); if (_camera_label == null) _camera_label = ""; try { setPositionList(posList); } catch (MMScriptException e1) { e1.printStackTrace(); } posListDlg_ = new PositionListDlg(mCore, MMMainFrame.this, _posList, null, dlg); posListDlg_.setModalityType(ModalityType.APPLICATION_MODAL); callback = new EventCallBackManager(); mCore.registerCallback(callback); engine_ = new AcquisitionWrapperEngineIcy(); engine_.setParentGUI(MMMainFrame.this); engine_.setCore(mCore, getAutofocusManager()); engine_.setPositionList(getPositionList()); setSystemMenuCallback(new MenuCallback() { @Override public JMenu getMenu() { JMenu toReturn = MMMainFrame.this.getDefaultSystemMenu(); JMenuItem hconfig = new JMenuItem("Configuration Wizard"); hconfig.setIcon(new IcyIcon("cog", MENU_ICON_SIZE)); hconfig.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!_pluginListEmpty && !ConfirmDialog.confirm("Are you sure ?", "<html>Loading the Configuration Wizard will unload all the devices and pause all running acquisitions.</br> Are you sure you want to continue ?</html>")) return; notifyConfigAboutToChange(null); try { mCore.unloadAllDevices(); } catch (Exception e1) { e1.printStackTrace(); } String previous_config = _sysConfigFile; ConfiguratorDlg2 configurator = new ConfiguratorDlg2(mCore, _sysConfigFile); configurator.setVisible(true); String res = configurator.getFileName(); if (_sysConfigFile == "" || _sysConfigFile == res || res == "") { _sysConfigFile = previous_config; loadConfig(); } refreshGUI(); notifyConfigChanged(null); } }); JMenuItem menuPxSizeConfigItem = new JMenuItem("Pixel Size Config"); menuPxSizeConfigItem.setIcon(new IcyIcon("link", MENU_ICON_SIZE)); menuPxSizeConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); menuPxSizeConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CalibrationListDlg dlg = new CalibrationListDlg(mCore); dlg.setDefaultCloseOperation(2); dlg.setParentGUI(MMMainFrame.this); dlg.setVisible(true); dlg.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { super.windowClosed(e); notifyConfigChanged(null); } }); notifyConfigAboutToChange(null); } }); JMenuItem loadConfigItem = new JMenuItem("Load Configuration"); loadConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); loadConfigItem.setIcon(new IcyIcon("folder_open", MENU_ICON_SIZE)); loadConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loadConfig(); initializeGUI(); refreshGUI(); } }); JMenuItem saveConfigItem = new JMenuItem("Save Configuration"); saveConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); saveConfigItem.setIcon(new IcyIcon("save", MENU_ICON_SIZE)); saveConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveConfig(); } }); JMenuItem advancedConfigItem = new JMenuItem("Advanced Configuration"); advancedConfigItem.setIcon(new IcyIcon("wrench_plus", MENU_ICON_SIZE)); advancedConfigItem.addActionListener(new ActionListener() { /** */ @Override public void actionPerformed(ActionEvent e) { new ToolTipFrame( "<html><h3>About Advanced Config</h3><p>Advanced Configuration is a tool " + "in which you fill some data <br/>about your configuration that some " + "plugins may need to access to.<br/> Exemple: the real values of the magnification" + "of your objectives.</p></html>", "MM4IcyAdvancedConfig"); if (advancedDlg == null) advancedDlg = new AdvancedConfigurationDialog(); advancedDlg.setVisible(!advancedDlg.isVisible()); advancedDlg.setLocationRelativeTo(mainFrame); } }); JMenuItem loadPresetConfigItem = new JMenuItem( "Load Configuration Presets"); loadPresetConfigItem.setIcon(new IcyIcon("doc_import", MENU_ICON_SIZE)); loadPresetConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { notifyConfigAboutToChange(null); loadPresets(); notifyConfigChanged(null); } }); JMenuItem savePresetConfigItem = new JMenuItem( "Save Configuration Presets"); savePresetConfigItem.setIcon(new IcyIcon("doc_export", MENU_ICON_SIZE)); savePresetConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { savePresets(); } }); JMenuItem aboutItem = new JMenuItem("About"); aboutItem.setIcon(new IcyIcon("info", MENU_ICON_SIZE)); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JDialog dialog = new JDialog(mainFrame, "About"); JPanel panel_container = new JPanel(); panel_container .setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); JPanel center = new JPanel(new BorderLayout()); final JLabel value = new JLabel("<html><body>" + "<h2>About</h2><p>Micro-Manager for Icy is being developed by Thomas Provoost." + "<br/>Copyright 2011, Institut Pasteur</p><br/>" + "<p>This plugin is based on Micro-Manager v1.4.6. which is developed under the following license:<br/>" + "<i>This software is distributed free of charge in the hope that it will be<br/>" + "useful, but WITHOUT ANY WARRANTY; without even the implied<br/>" + "warranty of merchantability or fitness for a particular purpose. In no<br/>" + "event shall the copyright owner or contributors be liable for any direct,<br/>" + "indirect, incidental spacial, examplary, or consequential damages.<br/>" + "Copyright University of California San Francisco, 2007, 2008, 2009,<br/>" + "2010. All rights reserved.</i>" + "</p>" + "</body></html>"); JLabel link = new JLabel( "<html><a href=\"\">For more information, please follow this link.</a></html>"); link.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseevent) { NetworkUtil.openBrowser( "http://valelab.ucsf.edu/~MM/MMwiki/index.php/Micro-Manager"); } }); value.setSize(new Dimension(50, 18)); value.setAlignmentX(SwingConstants.HORIZONTAL); value.setBorder(BorderFactory.createEmptyBorder(0, 0, 20, 0)); center.add(value, BorderLayout.CENTER); center.add(link, BorderLayout.SOUTH); JPanel panel_south = new JPanel(); panel_south.setLayout(new BoxLayout(panel_south, BoxLayout.X_AXIS)); JButton btn = new JButton("OK"); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionevent) { dialog.dispose(); } }); panel_south.add(Box.createHorizontalGlue()); panel_south.add(btn); panel_south.add(Box.createHorizontalGlue()); dialog.setLayout(new BorderLayout()); panel_container.setLayout(new BorderLayout()); panel_container.add(center, BorderLayout.CENTER); panel_container.add(panel_south, BorderLayout.SOUTH); dialog.add(panel_container, BorderLayout.CENTER); dialog.setResizable(false); dialog.setVisible(true); dialog.pack(); dialog.setLocation( (int) mainFrame.getSize().getWidth() / 2 - dialog.getWidth() / 2, (int) mainFrame.getSize().getHeight() / 2 - dialog.getHeight() / 2); dialog.setLocationRelativeTo(mainFrame); } }); JMenuItem propertyBrowserItem = new JMenuItem("Property Browser"); propertyBrowserItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, SHORTCUTKEY_MASK)); propertyBrowserItem.setIcon(new IcyIcon("db", MENU_ICON_SIZE)); propertyBrowserItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editor.setVisible(!editor.isVisible()); } }); int idx = 0; toReturn.insert(hconfig, idx++); toReturn.insert(loadConfigItem, idx++); toReturn.insert(saveConfigItem, idx++); toReturn.insert(advancedConfigItem, idx++); toReturn.insertSeparator(idx++); toReturn.insert(loadPresetConfigItem, idx++); toReturn.insert(savePresetConfigItem, idx++); toReturn.insertSeparator(idx++); toReturn.insert(propertyBrowserItem, idx++); toReturn.insert(menuPxSizeConfigItem, idx++); toReturn.insertSeparator(idx++); toReturn.insert(aboutItem, idx++); return toReturn; } }); saveConfigButton_ = new JButton("Save Button"); // SETUP _groupPad = new ConfigGroupPad(); _groupPad.setParentGUI(MMMainFrame.this); _groupPad.setFont(new Font("", 0, 10)); _groupPad.setCore(mCore); _groupPad.setParentGUI(MMMainFrame.this); _groupButtonsPanel = new ConfigButtonsPanel(); _groupButtonsPanel.setCore(mCore); _groupButtonsPanel.setGUI(MMMainFrame.this); _groupButtonsPanel.setConfigPad(_groupPad); // LEFT PART OF INTERFACE _panelConfig = new JPanel(); _panelConfig.setLayout(new BoxLayout(_panelConfig, BoxLayout.Y_AXIS)); _panelConfig.add(_groupPad, BorderLayout.CENTER); _panelConfig.add(_groupButtonsPanel, BorderLayout.SOUTH); _panelConfig.setPreferredSize(new Dimension(300, 300)); // MIDDLE PART OF INTERFACE _panel_cameraSettings = new JPanel(); _panel_cameraSettings.setLayout(new GridLayout(5, 2)); _panel_cameraSettings.setMinimumSize(new Dimension(100, 200)); _txtExposure = new JTextField(); try { mCore.setExposure(90.0D); _txtExposure.setText(String.valueOf(mCore.getExposure())); } catch (Exception e2) { _txtExposure.setText("90"); } _txtExposure.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20)); _txtExposure.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent keyevent) { if (keyevent.getKeyCode() == KeyEvent.VK_ENTER) setExposure(); } }); _panel_cameraSettings.add(new JLabel("Exposure [ms]: ")); _panel_cameraSettings.add(_txtExposure); _combo_binning = new JComboBox(); _combo_binning.setMaximumRowCount(4); _combo_binning.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25)); _combo_binning.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { changeBinning(); } }); _panel_cameraSettings.add(new JLabel("Binning: ")); _panel_cameraSettings.add(_combo_binning); _combo_shutters = new JComboBox(); _combo_shutters.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { if (_combo_shutters.getSelectedItem() != null) { mCore.setShutterDevice((String) _combo_shutters.getSelectedItem()); _prefs.put(PREF_SHUTTER, (String) _combo_shutters .getItemAt(_combo_shutters.getSelectedIndex())); } } catch (Exception e) { e.printStackTrace(); } } }); _combo_shutters.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25)); _panel_cameraSettings.add(new JLabel("Shutter : ")); _panel_cameraSettings.add(_combo_shutters); ActionListener action_listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateHistogram(); } }; _cbAbsoluteHisto = new JCheckBox(); _cbAbsoluteHisto.addActionListener(action_listener); _cbAbsoluteHisto.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionevent) { _comboBitDepth.setEnabled(_cbAbsoluteHisto.isSelected()); _prefs.putBoolean(PREF_ABS_HIST, _cbAbsoluteHisto.isSelected()); } }); _panel_cameraSettings.add(new JLabel("Display absolute histogram ?")); _panel_cameraSettings.add(_cbAbsoluteHisto); _comboBitDepth = new JComboBox(new String[] { "8-bit", "9-bit", "10-bit", "11-bit", "12-bit", "13-bit", "14-bit", "15-bit", "16-bit" }); _comboBitDepth.addActionListener(action_listener); _comboBitDepth.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionevent) { _prefs.putInt(PREF_BITDEPTH, _comboBitDepth.getSelectedIndex()); } }); _comboBitDepth.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20)); _comboBitDepth.setEnabled(false); _panel_cameraSettings.add(new JLabel("Select your bit depth for abs. hitogram: ")); _panel_cameraSettings.add(_comboBitDepth); // Acquisition _panelAcquisitions = new JPanel(); _panelAcquisitions.setLayout(new BoxLayout(_panelAcquisitions, BoxLayout.Y_AXIS)); // Color settings _panelColorChooser = new JPanel(); _panelColorChooser.setLayout(new BoxLayout(_panelColorChooser, BoxLayout.Y_AXIS)); painterPreferences = MicroscopePainterPreferences.getInstance(); painterPreferences.setPreferences(_prefs.node("paintersPreferences")); painterPreferences.loadColors(); HashMap<String, Color> allColors = painterPreferences.getColors(); String[] allKeys = (String[]) allColors.keySet().toArray(new String[0]); String[] columnNames = { "Painter", "Color", "Transparency" }; Object[][] data = new Object[allKeys.length][3]; for (int i = 0; i < allKeys.length; ++i) { final int actualRow = i; String actualKey = allKeys[i].toString(); data[i][0] = actualKey; data[i][1] = allColors.get(actualKey); final JSlider slider = new JSlider(0, 255, allColors.get(actualKey).getAlpha()); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent changeevent) { painterTable.setValueAt(slider, actualRow, 2); } }); data[i][2] = slider; } final AbstractTableModel tableModel = new JTableEvolvedModel(columnNames, data); painterTable = new JTable(tableModel); painterTable.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent tablemodelevent) { if (tablemodelevent.getType() == TableModelEvent.UPDATE) { int row = tablemodelevent.getFirstRow(); int col = tablemodelevent.getColumn(); String columnName = tableModel.getColumnName(col); String painterName = (String) tableModel.getValueAt(row, 0); if (columnName.contains("Color")) { // New color value int alpha = painterPreferences.getColor(painterName).getAlpha(); Color coloNew = (Color) tableModel.getValueAt(row, 1); painterPreferences.setColor(painterName, new Color(coloNew.getRed(), coloNew.getGreen(), coloNew.getBlue(), alpha)); } else if (columnName.contains("Transparency")) { // New alpha value Color c = painterPreferences.getColor(painterName); int alphaValue = ((JSlider) tableModel.getValueAt(row, 2)) .getValue(); painterPreferences.setColor(painterName, new Color(c.getRed(), c.getGreen(), c.getBlue(), alphaValue)); } /* * for (int i = 0; i < * tableModel.getRowCount(); ++i) { try { * String painterName = (String) * tableModel.getValueAt(i, 0); Color c = * (Color) tableModel.getValueAt(i, 1); int * alphaValue; if (ASpinnerChanged && * tablemodelevent.getFirstRow() == i) { * alphaValue = ((JSlider) * tableModel.getValueAt(i, 2)).getValue(); * } else { alphaValue = * painterPreferences.getColor * (painterPreferences * .getPainterName(i)).getAlpha(); } * painterPreferences.setColor(painterName, * new Color(c.getRed(), c.getGreen(), * c.getBlue(), alphaValue)); } catch * (Exception e) { System.out.println( * "error with painter table update"); } } */ } } }); painterTable.setPreferredScrollableViewportSize(new Dimension(500, 70)); painterTable.setFillsViewportHeight(true); // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(painterTable); // Set up renderer and editor for the Favorite Color // column. painterTable.setDefaultRenderer(Color.class, new ColorRenderer(true)); painterTable.setDefaultEditor(Color.class, new ColorEditor()); painterTable.setDefaultRenderer(JSlider.class, new SliderRenderer(0, 255)); painterTable.setDefaultEditor(JSlider.class, new SliderEditor()); _panelColorChooser.add(scrollPane); _panelColorChooser.add(Box.createVerticalGlue()); _mainPanel = new JPanel(); _mainPanel.setLayout(new BorderLayout()); // EDITOR // will refresh the data and verify if any change // occurs. // editor = new PropertyEditor(MMMainFrame.this); // editor.setCore(mCore); // editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); // editor.addToMainDesktopPane(); // editor.refresh(); // editor.start(); editor = new PropertyEditor(); editor.setGui(MMMainFrame.this); editor.setCore(mCore); editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); // editor.addToMainDesktopPane(); // editor.refresh(); // editor.start(); add(_mainPanel); initializeGUI(); loadPreferences(); refreshGUI(); setResizable(true); addToMainDesktopPane(); instanced = true; instancing = false; _singleton = MMMainFrame.this; setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addFrameListener(new IcyFrameAdapter() { @Override public void icyFrameClosing(IcyFrameEvent e) { customClose(); } }); acceptListener = new AcceptListener() { @Override public boolean accept(Object source) { close(); return _pluginListEmpty; } }; adapter = new MainAdapter() { @Override public void sequenceOpened(MainEvent event) { updateHistogram(); } }; Icy.getMainInterface().addCanExitListener(acceptListener); Icy.getMainInterface().addListener(adapter); } }); } }); } }); }