Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
af3
kernel
Commits
69acbf98
Commit
69acbf98
authored
8 years ago
by
Florian Hölzl
Browse files
Options
Downloads
Patches
Plain Diff
Added utility class for managing SWT graphics context state more easily.
refs 2589
parent
04476774
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCUtils.java
+126
-0
126 additions, 0 deletions
.../trunk/src/org/fortiss/tooling/base/ui/utils/GCUtils.java
with
126 additions
and
0 deletions
org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCUtils.java
0 → 100644
+
126
−
0
View file @
69acbf98
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2016 fortiss GmbH |
| |
| 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. |
+--------------------------------------------------------------------------*/
package
org.fortiss.tooling.base.ui.utils
;
import
java.util.Deque
;
import
java.util.LinkedList
;
import
org.eclipse.swt.graphics.Color
;
import
org.eclipse.swt.graphics.Font
;
import
org.eclipse.swt.graphics.FontData
;
import
org.eclipse.swt.graphics.GC
;
import
org.eclipse.swt.graphics.RGB
;
import
org.eclipse.swt.widgets.Display
;
/**
* Utility class for handling of {@link GC SWT graphics context} state and data.
* <P>
* Currently, this class only encapsulates the {@link GCStateManager} class, which can be used to
* store and restore attributes of the graphics context.
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: A85DD64B7EDBBAD1E1E3E8699FF2B4AD
*/
public
final
class
GCUtils
{
/** Creates the state manager for the given graphics context. */
public
static
GCUtils
.
GCStateManager
createGraphicsContextManager
(
GC
gc
)
{
return
new
GCUtils
.
GCStateManager
(
gc
);
}
/**
* Utility class managing SWT graphics context state by storing and restoring state attributes
* of the underlying graphics context using the provided public methods.
* <P>
* Note that it is the obligation of the user of this class to ensure that methods are called in
* order of the stack principle. Otherwise, {@link ClassCastException}s will occur.
*/
public
static
final
class
GCStateManager
{
/** The graphics context to be managed. */
private
final
GC
gc
;
/** The stack used to store the current gc state attributes. */
private
final
Deque
<
Object
>
state
=
new
LinkedList
<
Object
>();
/** Constructor. */
public
GCStateManager
(
GC
gc
)
{
this
.
gc
=
gc
;
}
/** Returns the graphics context. */
public
GC
GC
()
{
return
gc
;
}
/** Stores the alpha value. */
public
GCStateManager
alphaStoreAndSet
(
int
alpha
)
{
state
.
push
(
new
Integer
(
gc
.
getAlpha
()));
gc
.
setAlpha
(
alpha
);
return
this
;
}
/** Restores the alpha value. */
public
GCStateManager
alphaRestore
()
{
gc
.
setAlpha
((
Integer
)
state
.
pop
());
return
this
;
}
/** Stores the current foreground color and creates and activates the given color. */
public
GCStateManager
foregroundStoreAndCreate
(
RGB
rgb
)
{
state
.
push
(
gc
.
getForeground
());
gc
.
setForeground
(
new
Color
(
Display
.
getCurrent
(),
rgb
));
return
this
;
}
/** Restores the previous foreground color and disposes the current one. */
public
GCStateManager
foregroundRestoreAndDispose
()
{
gc
.
getForeground
().
dispose
();
gc
.
setForeground
((
Color
)
state
.
pop
());
return
this
;
}
/** Stores the current background color and creates and activates the given color. */
public
GCStateManager
backgroundStoreAndCreate
(
RGB
rgb
)
{
state
.
push
(
gc
.
getBackground
());
gc
.
setBackground
(
new
Color
(
Display
.
getCurrent
(),
rgb
));
return
this
;
}
/** Restores the previous background color and disposes the current one. */
public
GCStateManager
backgroundRestoreAndDispose
()
{
gc
.
getBackground
().
dispose
();
gc
.
setBackground
((
Color
)
state
.
pop
());
return
this
;
}
/** Stores the current font and creates and activates the given font. */
public
GCStateManager
fontStoreAndCreate
(
FontData
fontData
)
{
state
.
push
(
gc
.
getFont
());
gc
.
setFont
(
new
Font
(
Display
.
getCurrent
(),
fontData
));
return
this
;
}
/** Restores the previous font and disposes the current one. */
public
GCStateManager
fontRestoreAndDispose
()
{
gc
.
getFont
().
dispose
();
gc
.
setFont
((
Font
)
state
.
pop
());
return
this
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment