diff options
Diffstat (limited to 'openstack-console/src/main/java/com/woorea/openstack/console/utils')
4 files changed, 0 insertions, 282 deletions
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/utils/Column.java b/openstack-console/src/main/java/com/woorea/openstack/console/utils/Column.java deleted file mode 100644 index 755ac17..0000000 --- a/openstack-console/src/main/java/com/woorea/openstack/console/utils/Column.java +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.console.utils; - -public class Column { - - public static final int ALIGN_LEFT = -1; - public static final int ALIGN_RIGHT = 1; - - private String name; - - private int size; - - private int align; - - public Column(String name, int size, int align) { - super(); - this.name = name; - this.size = size; - this.align = align; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the size - */ - public int getSize() { - return size; - } - - /** - * @param size the size to set - */ - public void setSize(int size) { - this.size = size; - } - - /** - * @return the align - */ - public int getAlign() { - return align; - } - - /** - * @param align the align to set - */ - public void setAlign(int align) { - this.align = align; - } - - - -} diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/utils/ConsoleUtils.java b/openstack-console/src/main/java/com/woorea/openstack/console/utils/ConsoleUtils.java deleted file mode 100644 index 8166217..0000000 --- a/openstack-console/src/main/java/com/woorea/openstack/console/utils/ConsoleUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.console.utils; - -public class ConsoleUtils { - - public static final String RED = "\u001B[31m"; - - public static final String GREEN = "\u001B[32m"; - - public static final String YELLOW = "\u001B[33m"; - - public static final String END = "\u001B[0m"; - - private StringBuilder sb = new StringBuilder(); - - public ConsoleUtils append(String text) { - sb.append(text); - return this; - } - - public ConsoleUtils red(String text) { - sb.append(ConsoleUtils.RED).append(text).append(END); - return this; - } - - public ConsoleUtils green(String text) { - sb.append(ConsoleUtils.GREEN).append(text).append(END); - return this; - } - - public ConsoleUtils yellow(String text) { - sb.append(ConsoleUtils.YELLOW).append(text).append(END); - return this; - } - - public static void log(String text) { - System.out.println(new ConsoleUtils().yellow("| ").append(text)); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return sb.toString(); - } - -} diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/utils/Table.java b/openstack-console/src/main/java/com/woorea/openstack/console/utils/Table.java deleted file mode 100644 index d25d16d..0000000 --- a/openstack-console/src/main/java/com/woorea/openstack/console/utils/Table.java +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.console.utils; - - -public class Table { - - private StringBuilder sb = new StringBuilder(); - - private TableModel<?> model; - - public Table(TableModel<?> model) { - this.model = model; - } - - public StringBuilder render() { - header(); - for(String[] row : model.getRows()) { - int i = 0; - for(String column : row) { - Column columnModel = model.getHeaders()[i]; - sb.append("| "); - if(column != null) { - if(Column.ALIGN_RIGHT == columnModel.getAlign()) { - for(int j = 0; j < columnModel.getSize() - column.length(); j++) { - sb.append(" "); - } - } - sb.append(column.length() <= columnModel.getSize() ? column : column.substring(0, columnModel.getSize())); - if(Column.ALIGN_LEFT == columnModel.getAlign()) { - for(int j = 0; j < columnModel.getSize() - column.length(); j++) { - sb.append(" "); - } - } - } else { - for(int k = 0; k < columnModel.getSize(); k++) { - sb.append(" "); - } - } - sb.append(" "); - i++; - } - sb.append("|\n"); - } - for(Column c : model.getHeaders()) { - sb.append("+"); - for(int i = 0; i < c.getSize() + 2; i++) { - sb.append("-"); - } - } - sb.append("+\n"); - return sb; - } - - public void header() { - for(Column c : model.getHeaders()) { - sb.append("+"); - for(int i = 0; i < c.getSize() + 2; i++) { - sb.append("-"); - } - } - sb.append("+\n"); - - for(Column c : model.getHeaders()) { - sb.append("| "); - sb.append(c.getName()); - for(int i = 0; i < c.getSize() - c.getName().length(); i++) { - sb.append(" "); - } - sb.append(" "); - } - sb.append("|\n"); - - for(Column c : model.getHeaders()) { - sb.append("+"); - for(int i = 0; i < c.getSize() + 2; i++) { - sb.append("-"); - } - } - sb.append("+\n"); - } - -} diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/utils/TableModel.java b/openstack-console/src/main/java/com/woorea/openstack/console/utils/TableModel.java deleted file mode 100644 index 3715c85..0000000 --- a/openstack-console/src/main/java/com/woorea/openstack/console/utils/TableModel.java +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.console.utils; - -import java.util.List; - -public abstract class TableModel<T> { - - protected List<T> data; - - public TableModel(List<T> data) { - this.data = data; - } - - public abstract Column[] getHeaders(); - - public final String[][] getRows() { - String[][] rows = new String[data.size()][]; - for(int i = 0; i < data.size(); i++) { - rows[i] = getRow(data.get(i)); - } - return rows; - } - - public abstract String[] getRow(T data); - -} |