List of usage examples for java.awt Color getBlue
public int getBlue()
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param color/* w w w . ja v a2 s .c o m*/ * @return */ public static String getRGBHexFromColor(final Color color) { return getHexStr(color.getRed()) + getHexStr(color.getGreen()) + getHexStr(color.getBlue()); }
From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java
public void exportFrame(JRPrintFrame frame) throws DocumentException, IOException, JRException { if (frame.getModeValue() == ModeEnum.OPAQUE) { int x = frame.getX() + getOffsetX(); int y = frame.getY() + getOffsetY(); Color backcolor = frame.getBackcolor(); pdfContentByte.setRGBColorFill(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue()); pdfContentByte.rectangle(x, pageFormat.getPageHeight() - y, frame.getWidth(), -frame.getHeight()); pdfContentByte.fill();/*from ww w .j a v a 2 s .c o m*/ } setFrameElementsOffset(frame, false); try { exportElements(frame.getElements()); } finally { restoreElementOffsets(); } exportBox(frame.getLineBox(), frame); }
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>//from w ww. j av a2 s .co 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:net.sf.jasperreports.engine.export.JRPdfExporter.java
/** * *//*from ww w. j a v a 2 s. c o m*/ public void exportText(JRPrintText text) throws DocumentException { JRStyledText styledText = styledTextUtil.getProcessedStyledText(text, noBackcolorSelector, null); if (styledText == null) { return; } AbstractPdfTextRenderer textRenderer = getTextRenderer(text, styledText); textRenderer.initialize(this, pdfContentByte, text, styledText, getOffsetX(), getOffsetY()); double angle = 0; switch (text.getRotationValue()) { case LEFT: { angle = Math.PI / 2; break; } case RIGHT: { angle = -Math.PI / 2; break; } case UPSIDE_DOWN: { angle = Math.PI; break; } case NONE: default: { } } AffineTransform atrans = new AffineTransform(); atrans.rotate(angle, textRenderer.getX(), pageFormat.getPageHeight() - textRenderer.getY()); pdfContentByte.transform(atrans); if (text.getModeValue() == ModeEnum.OPAQUE) { Color backcolor = text.getBackcolor(); pdfContentByte.setRGBColorFill(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue()); pdfContentByte.rectangle(textRenderer.getX(), pageFormat.getPageHeight() - textRenderer.getY(), textRenderer.getWidth(), -textRenderer.getHeight()); pdfContentByte.fill(); } if (glyphRendererAddActualText && textRenderer instanceof PdfGlyphRenderer) { tagHelper.startText(styledText.getText(), text.getLinkType() != null); } else { tagHelper.startText(text.getLinkType() != null); } /* rendering only non empty texts */ if (styledText.length() > 0) { textRenderer.render(); } tagHelper.endText(); atrans = new AffineTransform(); atrans.rotate(-angle, textRenderer.getX(), pageFormat.getPageHeight() - textRenderer.getY()); pdfContentByte.transform(atrans); /* */ exportBox(text.getLineBox(), text); }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param color//from w w w.j a v a2 s . co m * @param delta * @return */ public static Color changeColorBrightness(final Color color, final double delta) { int r = (int) Math.min(color.getRed() * delta, 255.0); int g = (int) Math.min(color.getGreen() * delta, 255.0); int b = (int) Math.min(color.getBlue() * delta, 255.0); 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;//from www .ja v a2 s . co 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:edu.ku.brc.ui.UIHelper.java
/** * @param color The color to lighten/* ww w. jav a 2 s .c o m*/ * @param percentage to be added to the current value 0.0 > val < 1.0 * @return */ public static Color makeDarker(final Color color, final double percentage) { int r = Math.max(color.getRed() - (int) (color.getRed() * percentage), 0); int g = Math.max(color.getGreen() - (int) (color.getGreen() * percentage), 0); int b = Math.max(color.getBlue() - (int) (color.getBlue() * percentage), 0); return new Color(r, g, b); }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param color The color to lighten/* w ww . java2s . c o 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: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 www . j a v a 2 s. co m //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 ww w. j av a2s. 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; }